Jump to content

Recommended Posts

Posted

AmbientCG has about 3000 PBR materials and a simple REST web API.

List categories:
https://ambientcg.com/api/v2/categories_json

List files in category:
https://ambientcg.com/api/v2/full_json?include=imageData,downloadData&category=PavingStones

These URLs can be loaded with FetchURL. There is a JSON parsing library included in the Scripts/System folder, dkjson.lua. This is used by the debugger. I have not used it myself for anything.

More docs here:
https://docs.ambientcg.com/api/v2/

Let's build cool stuff and have fun. :)

Posted

Example:

local json = require 'System/dkjson'

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

local t = json.decode(s)

if type(t) == "table" then
    local n
    for n = 1, #t do
        if (type(t[n]) == "table") then
            if type(t[n]["categoryName"]) == "string" then
                Print(t[n]["categoryName"])
            end
        end
    end
end

Download and extract:

DownloadFile("https://ambientcg.com/get?file=PavingStones137_1K-JPG.zip", GetPath(PATH_DESKTOP).."/test.zip" )
local pak = LoadPackage(GetPath(PATH_DESKTOP).."/test.zip")
if pak then
    local dir = pak:LoadDir("")
    local n
    for n = 1, #dir do
        if pak:FileType(dir[n]) == 1 then
            pak:ExtractFile(dir[n], GetPath(PATH_DESKTOP).."/"..dir[n])
        end
    end
    pak:Close()
end

 

Let's build cool stuff and have fun. :)

Posted

Updated example that uses LoadTable() instead of the Lua JSON parser:

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

local t = LoadTable(s)

if type(t) == "table" then
    local n
    for n = 1, #t do
        if (type(t[n]) == "table") then
            if type(t[n]["categoryName"]) == "string" then
                Print(t[n]["categoryName"])
            end
        end
    end
end

 

Let's build cool stuff and have fun. :)

Posted

The Lua debugger is actually using Lua socket, not libcurl. A couple of things to note:

Let's build cool stuff and have fun. :)

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.

×
×
  • Create New...