def _outputWorldProcedural(self, scenePlug, renderer): import arnold node = arnold.AiNode("procedural") arnold.AiNodeSetStr(node, "dso", "ieProcedural.so") arnold.AiNodeSetPnt(node, "min", -1e30, -1e30, -1e30) arnold.AiNodeSetPnt(node, "max", 1e30, 1e30, 1e30) arnold.AiNodeDeclare(node, "className", "constant STRING") arnold.AiNodeDeclare(node, "classVersion", "constant INT") arnold.AiNodeDeclare(node, "parameterValues", "constant ARRAY STRING") arnold.AiNodeSetStr(node, "className", "gaffer/script") arnold.AiNodeSetInt(node, "classVersion", 1) scriptNode = scenePlug.node().scriptNode() parameterValues = [ "-fileName", scriptNode["fileName"].getValue(), "-node", scenePlug.node().relativeName(scriptNode), "-frame", str(Gaffer.Context.current().getFrame()), ] stringArray = arnold.AiArrayAllocate(len(parameterValues), 1, arnold.AI_TYPE_STRING) for i in range(0, len(parameterValues)): arnold.AiArraySetStr(stringArray, i, parameterValues[i]) arnold.AiNodeSetArray(node, "parameterValues", stringArray)
def createOutputArray(arrayType, elements, attributes): """ Method to create an outputArray This method takes the type,name,attributes and creates an outputArray Args: arrayType(ARNOLD STRING): The array type elements(string): The elements of the array attributes(dict): The dictionary with attribute name, (type,value) Returns: outputArray(AiNode): Returns the array created with the attributes set """ outputsArray = arnold.AiArrayAllocate(1, 1, arrayType) for element in elements: arnold.AiArraySetStr(outputsArray, elements.index(element), element) assignAttributes(outputsArray, attributes) return outputsArray
def list_to_array(self, python_list): arnold_array = ai.AiArrayAllocate(len(python_list), 1, ai.AI_TYPE_STRING) for i, element in enumerate(python_list): ai.AiArraySetStr(arnold_array, i, element) return arnold_array
def renderGeo(self): arnold.AiBegin() arnold.AiMsgSetLogFileName(self._logFile) arnold.AiMsgSetConsoleFlags(arnold.AI_LOG_ALL) # create a sphere geometric primitive sph = arnold.AiNode("sphere") arnold.AiNodeSetStr(sph, "name", "mysphere") arnold.AiNodeSetVec(sph, "center", 0.0, 4.0, 0.0) arnold.AiNodeSetFlt(sph, "radius", 5.0) # create a red standard shader shader1 = arnold.AiNode("standard") arnold.AiNodeSetStr(shader1, "name", "myshader1") arnold.AiNodeSetRGB(shader1, "Kd_color", self._color[0], self._color[1], self._color[2]) arnold.AiNodeSetFlt(shader1, "Ks", 0.05) # assign the shaders to the geometric objects arnold.AiNodeSetPtr(sph, "shader", shader1) # create a perspective camera camera = arnold.AiNode("persp_camera") arnold.AiNodeSetStr(camera, "name", "mycamera") # position the camera (alternatively you can set 'matrix') arnold.AiNodeSetVec(camera, "position", 0.0, 10.0, 35.0) arnold.AiNodeSetVec(camera, "look_at", 0.0, 3.0, 0.0) arnold.AiNodeSetFlt(camera, "fov", 45.0) # create a point light source light = arnold.AiNode("point_light") arnold.AiNodeSetStr(light, "name", "pointLight_A") # // position the light (alternatively use 'matrix') arnold.AiNodeSetVec(light, "position", 0.0, 30.0, 0.0) arnold.AiNodeSetFlt(light, "intensity", 10.0) # alternatively, use 'exposure' arnold.AiNodeSetFlt(light, "radius", 4.0) # for soft shadows # create a point light source light = arnold.AiNode("point_light") arnold.AiNodeSetStr(light, "name", "pointLight_B") # // position the light (alternatively use 'matrix') arnold.AiNodeSetVec(light, "position", 0.0, -30.0, 0.0) arnold.AiNodeSetFlt(light, "intensity", 10.0) # alternatively, use 'exposure' arnold.AiNodeSetFlt(light, "radius", 4.0) # for soft shadows # create a point light source light = arnold.AiNode("point_light") arnold.AiNodeSetStr(light, "name", "pointLight_C") # // position the light (alternatively use 'matrix') arnold.AiNodeSetVec(light, "position", 0.0, 4.0, 20.0) arnold.AiNodeSetFlt(light, "intensity", 5.0) # alternatively, use 'exposure' arnold.AiNodeSetFlt(light, "radius", 15.0) # for soft shadows # // get the global options node and set some options options = arnold.AiUniverseGetOptions() arnold.AiNodeSetInt(options, "AA_samples", 8) arnold.AiNodeSetInt(options, "xres", 480) arnold.AiNodeSetInt(options, "yres", 360) arnold.AiNodeSetInt(options, "GI_diffuse_depth", 4) # // set the active camera (optional, since there is only one camera) arnold.AiNodeSetPtr(options, "camera", camera) # create an output driver node driver = arnold.AiNode("driver_jpeg") arnold.AiNodeSetStr(driver, "name", "mydriver") arnold.AiNodeSetStr(driver, "filename", self._sceneName) arnold.AiNodeSetFlt(driver, "gamma", 2.2) # create a gaussian filter node filter = arnold.AiNode("gaussian_filter") arnold.AiNodeSetStr(filter, "name", "myfilter") # assign the driver and filter to the main (beauty) AOV, # which is called "RGBA" and is of type RGBA outputs_array = arnold.AiArrayAllocate(1, 1, arnold.AI_TYPE_STRING) arnold.AiArraySetStr(outputs_array, 0, "RGBA RGBA myfilter mydriver") arnold.AiNodeSetArray(options, "outputs", outputs_array) # finally, render the image! arnold.AiRender(arnold.AI_RENDER_MODE_CAMERA) # // Arnold session shutdown arnold.AiEnd()
def allocate(self, nelements, nkeys, type_string): self.data = arnold.AiArrayAllocate(nelements, nkeys, BTOA_TYPE_CONSTANTS[type_string])
def renderGeo(self): """ This method calls the arnold functions to setup and scene and render the image """ arnold.AiBegin() arnold.AiMsgSetLogFileName(self.log) arnold.AiMsgSetConsoleFlags(arnold.AI_LOG_ALL) attributes = { "Kd_color": ("rgb", (self._color[0], self._color[1], self._color[2])), "Ks": ("float", 0.05), "Ko": ("float", .5), } shader = createSimpleShader("standard", "myshader1", attributes) attributes = { "center": ("vector", (0.0, 4.0, 0.0)), "radius": ("float", 5.0), "shader": ("pointer", shader) } sph = createGeometry("sphere", "mysphere", attributes) # attributes["center"] = ("vector", (1.0, 2.0, 3.0)) # sph1 = createGeometry("sphere", "mysphere", attributes) # assignAttributes(sph, {"radius": ("float", 0.9)}) # arnold.AiNodeSetRGB(shader1, "Kd_color", self._color[0], self._color[1], self._color[2]) # arnold.AiNodeSetFlt(shader1, "Ks", 0.05) # # assign the shaders to the geometric objects # arnold.AiNodeSetPtr(sph, "shader", shader1) # create a perspective camera camera = arnold.AiNode("persp_camera") arnold.AiNodeSetStr(camera, "name", "mycamera") arnold.AiNodeSetVec(camera, "position", 0.0, 10.0, 35.0) arnold.AiNodeSetVec(camera, "look_at", 0.0, 3.0, 0.0) arnold.AiNodeSetFlt(camera, "fov", 45.0) # create a point light source light = arnold.AiNode("point_light") arnold.AiNodeSetStr(light, "name", "pointLight_A") arnold.AiNodeSetVec(light, "position", 0.0, 30.0, 0.0) arnold.AiNodeSetFlt(light, "intensity", 10.0) arnold.AiNodeSetFlt(light, "radius", 4.0) # create a point light source light = arnold.AiNode("point_light") arnold.AiNodeSetStr(light, "name", "pointLight_B") arnold.AiNodeSetVec(light, "position", 0.0, -30.0, 0.0) arnold.AiNodeSetFlt(light, "intensity", 10.0) arnold.AiNodeSetFlt(light, "radius", 4.0) # create a point light source light = arnold.AiNode("point_light") arnold.AiNodeSetStr(light, "name", "pointLight_C") arnold.AiNodeSetVec(light, "position", 0.0, 4.0, 20.0) arnold.AiNodeSetFlt(light, "intensity", 5.0) arnold.AiNodeSetFlt(light, "radius", 15.0) # get the global options node and set some options options = arnold.AiUniverseGetOptions() arnold.AiNodeSetInt(options, "AA_samples", 8) arnold.AiNodeSetInt(options, "xres", 480) arnold.AiNodeSetInt(options, "yres", 360) arnold.AiNodeSetInt(options, "GI_diffuse_depth", 4) arnold.AiNodeSetPtr(options, "camera", camera) # create an output driver node driver = arnold.AiNode("driver_jpeg") arnold.AiNodeSetStr(driver, "name", "mydriver") # arnold.AiNodeSetStr(driver, "filepath", os.path.dirname(self.image)) arnold.AiNodeSetStr(driver, "filename", os.path.basename(self.image)) arnold.AiNodeSetFlt(driver, "gamma", 2.2) # create a gaussian filter node filter = arnold.AiNode("gaussian_filter") arnold.AiNodeSetStr(filter, "name", "myfilter") # assign the driver and filter to the main (beauty) AOV, # which is called "RGBA" and is of type RGBA outputs_array = arnold.AiArrayAllocate(1, 1, arnold.AI_TYPE_STRING) arnold.AiArraySetStr(outputs_array, 0, "RGBA RGBA myfilter mydriver") arnold.AiNodeSetArray(options, "outputs", outputs_array) # finally, render the image! arnold.AiRender(arnold.AI_RENDER_MODE_CAMERA) # // Arnold session shutdown arnold.AiEnd()