---------------------------------------------------------------------------------------------------- -- Sets up a scripted graph with an animated texture. The images for the texture animation are -- fetched from a folder of images. -- -- @author Thomas Loockx -- @version 0.1 local GraphScript = {} -- input linker nodes local inputs = nil -- output linker nodes local outputs = nil -- list of textures paths, 1 for each time frame local textures = nil -- internal texture node with the image for the current time frame local texNode = nil -- comma seperated list used for image file wildcards local wildcards = "" -- Sorter function used to sort the list of image textures. local function imageSorter(image1, image2) if image1 < image2 then return true else return false end end function GraphScript.onInit(self, graph) texNode = octane.node.create { type = octane.NT_TEX_IMAGE, name = "Internal image texture", graphOwner = graph, } local inputLinkerInfos = { { type = octane.PT_STRING, label = "Textures directory", defaultNodeType = octane.NT_STRING }, } -- add the same pins as an image texture node for pinIx=1,texNode:getPinCount() do local pinInfo = texNode:getPinInfoIx(pinIx) local linkInfo = { type = pinInfo.type, defaultNodeType = pinInfo.defaultNodeType, label = pinInfo.label } table.insert(inputLinkerInfos, linkInfo) end inputs = self:setInputLinkers(inputLinkerInfos) local outputLinkerInfos = { { type = octane.PT_TEXTURE, label = "Output" } } outputs = graph:setOutputLinkers(outputLinkerInfos) outputs[1]:connectToIx(1, texNode) end function GraphScript.onEvaluate(self, graph) -- update to the new input directory if self:inputWasChanged(inputs[1]) then local outputDirectory = self:getInputValue(inputs[1]) if octane.file.isAbsolute(outputDirectory) and octane.file.isDirectory(outputDirectory) then -- clear the old textures textures = {} -- list of all texture files in the dir local files = octane.file.listDirectory(outputDirectory, true, false, true, false) -- re-read all the texture images in the directory for ix, file in ipairs(files) do print(string.format("textures-%04d: %s", ix, file)) table.insert(textures, file) end -- sort the images according to the desired animation table.sort(textures, imageSorter) -- update the animation interval according the number of textures self:setEvaluateTimeChanges(true, { 0, #textures }) return true end end -- if the time was changed -> update our internal texture node if self:timeWasChanged() then local texIx = math.ceil(graph.time) local tex = textures[texIx] if tex then texNode:setAttribute(octane.A_FILENAME, textures[texIx]) octane.changemanager.update() end end return false end return GraphScript