Jump to content

AmbientCG Web API


Josh
 Share

Recommended Posts

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/

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

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

 

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

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

 

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

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

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...