---------------------------------------------------------------------------------------------------- -- Sets up a scripted graph with an animated texture. The images for the texture animation are -- loaded from the file name given. -- -- @author Jason Grimes -- @version 0.1 local AnimTexture = {} local frameTime = 0 -- Amount of time for each frame function getFrame(currentTime) return math.floor((currentTime + (frameTime / 2))/frameTime) end function AnimTexture.onInit(self, graph) graph:updateProperties({name = "Animated Texture"}) local inputInfos = { {type=octane.PT_STRING, label="File Name", defaultNodeType=octane.NT_FILE}, {type=octane.PT_INT, label="Number of Digits", defaultNodeType=octane.NT_INT, defaultValue=4}, {type=octane.PT_INT, label="Frames per Second", defaultNodeType=octane.NT_INT, defaultValue=24}, {type=octane.PT_TRANSFORM, label="UV Transform", defaultNodeType=octane.NT_TRANSFORM_2D}, {type=octane.PT_BOOL, label="Invert", defaultNodeType=octane.NT_BOOL} } local outputInfos = { {type=octane.PT_TEXTURE, label="Animated Texture"} } inputs = graph:setInputLinkers(inputInfos) outputs = graph:setOutputLinkers(outputInfos) self:setEvaluateTimeChanges(true) tex = octane.node.create{ type=octane.NT_TEX_IMAGE, name="Anim Texture", graphOwner=graph } outputs[1]:connectTo("input", tex) tex:connectTo(octane.P_TRANSFORM, inputs[4]) tex:connectTo(octane.P_INVERT, inputs[5]) end function AnimTexture.onEvaluate(self, graph) if self:timeWasChanged() then fileName = self:getInputValue(inputs[1]) numDigits = self:getInputValue(inputs[2]) sceneFps = self:getInputValue(inputs[3]) frameTime = 1.0/sceneFps local frameNum = getFrame(graph.time) parentPath = octane.file.getParentDirectory(fileName) baseFile = octane.file.getFileNameWithoutExtension(fileName) fileExt = octane.file.getFileExtension(fileName) cleanFile = string.sub(baseFile, 1, baseFile:len() - numDigits) numFormat = "%0"..numDigits.."u" finalFile = octane.file.join(parentPath, cleanFile..string.format(numFormat, frameNum)..fileExt) tex:setAttribute(octane.A_FILENAME, finalFile) tex:setAttribute(octane.A_RELOAD, true) end return true end return AnimTexture