Jump to content

[HELP] (Auto-)Create textures for image files


Ceeser

Recommended Posts

Hey, for a UI lib I want to create textures for all image files included to the resource.
So when it starts, it calls the function to load the images, create and store textures for them.
My problem is now, how to get all image paths / names?
Since the meta.xml doesn't get downloaded, the client file cant open the meta.xml and search for file src's (like i tried in the example).
Manually use downloadFile("meta.xml") doesnt work and using the event "onClientFileDownloadComplete" to get the names of downloaded images doesn't work as well.

Example: (What ive tried)

function loadTextures()
    local sourceResource = sourceResource or getThisResource(); -- This is if the call comes from another resource to load in the images of that resource
    local strResourePath = ":" .. getResourceName(sourceResource) .. "/";
    local tblImages = loadMetaImages(strResourePath);

    if (tblImages) then
        for _, image in pairs(tblImages) do
            local strName = removeImagePath(image);

            if (ELIB.textures[strName]) then
                outputDebugString("@ELIB - loadTextures: Dublicated image name found in" .. strResourePath .. " old image overwritten!", 2);
            end

            ELIB.textures[strName] = dxCreateTexture(image, "dxt5", true, "clamp");
        end
    end
end

function loadMetaImages(strResourePath)
    local uFile = xmlLoadFile(strResourePath .. "meta.xml");

    if (uFile) then
        local tblImages = {};

        for _, node in ipairs(xmlNodeGetChildren(uFile)) do
            if (xmlNodeGetName(node) == "file") then
                local strImagePath = xmlNodeGetAttribute(node, "src");
                if (string.find(strImagePath, ".png") or string.find(strImagePath, ".jpg") or string.find(strImagePath, ".dds")) then
                    table.insert(tblImages, strImagePath);
                end
            end
        end

        return tblImages;
    end
end

function removeImagePath(strPath)
    while (string.find(strPath, "/")) do
        strPath = string.sub(strPath, 2);
    end
end

 

Edited by Ceeser
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...