Jump to content

Web Asset Browser


Josh
 Share

Recommended Posts

Here is a basic skeleton for a downloader. The idea is to have one system with multiple content providers that can be plugged in to download assets from other sources.

image.thumb.png.35ef3281eb7f14be1a8cb3f689fbe7e9.png

local extension = {}
extension.providers = {}

function extension:Initialize()

    local sidepanelwidth = 280
    local x = 4
    local y = 4

    extension.window = CreateWindow("Asset Library", 0, 0, 1024, 768, program.window, WINDOW_HIDDEN | WINDOW_TITLEBAR | WINDOW_CENTER | WINDOW_RESIZABLE)
    extension.ui = CreateInterface(extension.window)
    extension.treeview = CreateTreeView(x, y, sidepanelwidth, extension.ui.background.size.y - y * 2, extension.ui.background)
    extension.treeview:SetLayout(1,0,1,1)
    extension.panel = CreatePanel(x + sidepanelwidth + 4, y, extension.ui.background.size.x - sidepanelwidth - 4 - 2 * x, extension.ui.background.size.y - 2 * y, extension.ui.background, PANEL_BORDER)
    extension.panel:SetLayout(1,1,1,1)
    --extension.panel:SetColor(extension.panel:GetColor(WIDGETCOLOR_SUNKEN))
    extension.panel:SetColor(0,0,0,1)

    --Set DPI scale if needed
    if program.window.display.scale ~= 1 then
        local scale = program.window.display.scale
        local pos = extension.window.position
        local size = extension.window.size
        extension.window:SetShape(pos.x, pos.y, size.x * scale, size.y * scale)
        extension.ui:SetScale(scale)
    end

    ListenEvent(EVENT_WINDOWCLOSE, extension.window, extension.ProcessEvent, extension)
    ListenEvent(EVENT_WINDOWSIZE, extension.window, extension.ProcessEvent, extension)

    local s = FetchUrl("https://ambientcg.com/api/v2/categories_json")
    local t = LoadTable(s)
    local n

    local groups = {}

    for n = 1, #t do
        local name = t[n].categoryName
        local group = t[n].defaultDataTypeId
        if groups[group] == nil then
            groups[group] = {}
        end
        groups[group][name] = t
        --extension.treeview.root:AddNode(name)
    end

    local k,v

    local base = extension.treeview.root:AddNode("AmbientCG")

    for k,v in pairs(groups) do
        local node = base:AddNode(k)
        local k2, v2
        for k2, v2 in pairs(v) do
            node:AddNode(k2)
        end
    end

    base:Expand()

end

function extension.ProcessEvent(event, extension)

    if event.id == EVENT_WIDGETACTION then

        if event.source == extension.menuitem then
            if extension.window == nil then
                extension:Initialize()
            end
            extension.window:SetHidden(false)
            extension.window:Activate()
            return false
        end

    elseif event.id == EVENT_WINDOWCLOSE then

        if event.source == extension.window then
            program.window:Activate()
            extension.window:SetHidden(true)
            return false
        end

    end
end

local submenu = program.menu:FindChild("Scripting")
if submenu == nil then
    Print("Error: Could not find script menu")
    return
end
extension.menuitem = CreateMenu("Asset Library", submenu)

ListenEvent(EVENT_WIDGETACTION, extension.menuitem, extension.ProcessEvent, extension)

--Add a content provider
local t = {}

function t:GetCategories()

end


table.insert(extension.providers, t)

 

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

I think I am going to make the interface in C++, built into the program, and then use Lua for the various integrations with different websites.

Here is the final version of the pure Lua approach. It doesn't download assets but it's a nice example of asynchronous behavior with Lua.

AssetLibrary.lua

image.thumb.jpeg.bda502b205d02df718ec13964b5b16a3.jpeg

  • Like 3

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

  • Josh changed the title to Web Asset Browser
  • 2 weeks later...
  • 3 months later...

I tried uploading an ambientcg.com material here to test with. There are two versions you can download, (although they are actually the same file with a different name).

There is a lot of good CC0 content out there that does not have any type of web API to access it. It might make more sense to take all this stuff and upload it into our website's system. Of course that process would need to be automated because there would be too much content to manage otherwise.

This would give us a single point of access for all this stuff. The PBR texture providers are usually not very motivated to create a web API because they make money through advertisements, but they still are releasing their stuff under CC0 license. I'm not sure why, but that license allows us to redistribute files any way we want, and it doesn't look like this is going to happen otherwise.

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...