def imageToBlender(self): [sizeX, sizeY, bStartX, bStartY, bsizeX, bsizeY] = self.getRenderCoords() imageMem = yafrayinterface.new_floatArray(sizeX * sizeY * 4) memIO = yafrayinterface.memoryIO_t(sizeX, sizeY, imageMem) self.yi.getRenderedImage(memIO) self.memoryioToImage(imageMem, "yafRender", sizeX, sizeY, bStartX, bStartY, bsizeX, bsizeY) yafrayinterface.delete_floatArray(imageMem)
def startRender(self, renderCoords, frameNumber=None): yi = self.yi # sizeX/Y is the actual size of the image, b* is bordered stuff [sizeX, sizeY, bStartX, bStartY, bsizeX, bsizeY] = renderCoords autoSave = self.renderer.autoSave doAnimation = (frameNumber != None) ## saveToMem = renderprops["imageToBlender"] saveToMem = False closeAfterFinish = False ret = 0 if self.useXML: saveToMem = False co = yafrayinterface.outTga_t(0, 0, "") outputFile = self.getOutputFilename(None, False) outputFile += '.xml' print "INFO: Writing XML:", outputFile yi.render(co) # single frame output without GUI elif not self.haveQt: outputFile = self.getOutputFilename(frameNumber) outputFile += '.tga' print "INFO: Rendering to file:", outputFile co = yafrayinterface.outTga_t(sizeX, sizeY, outputFile) yi.render(co) else: import yafqt outputFile = self.getOutputFilename(frameNumber) outputFile += '.png' yafqt.initGui() guiSettings = yafqt.Settings() guiSettings.autoSave = autoSave guiSettings.closeAfterFinish = closeAfterFinish guiSettings.mem = None guiSettings.fileName = outputFile ## guiSettings.autoSaveAlpha = renderprops["autoalpha"] guiSettings.autoSaveAlpha = False if doAnimation: guiSettings.autoSave = True guiSettings.closeAfterFinish = True # will return > 0 if user canceled the rendering using ESC ret = yafqt.createRenderWidget(self.yi, sizeX, sizeY, bStartX, bStartY, guiSettings) if saveToMem and not doAnimation: imageMem = yafrayinterface.new_floatArray(sizeX * sizeY * 4) memIO = yafrayinterface.memoryIO_t(sizeX, sizeY, imageMem) yi.getRenderedImage(memIO) self.memoryioToImage(imageMem, "yafRender", sizeX, sizeY, bStartX, bStartY, bsizeX, bsizeY) yafrayinterface.delete_floatArray(imageMem) return ret
def writeMappingNode(self, name, texname, mtex): yi = self.yi yi.paramsPushList() yi.paramsSetString("element", "shader_node") yi.paramsSetString("type", "texture_mapper") yi.paramsSetString("name", name) yi.paramsSetString("texture", mtex.texture.name) switchTexCoords = { 'UV': 'uv', 'GLOBAL': 'global', 'ORCO': 'orco', 'WINDOW': 'window', 'NORMAL': 'normal', 'REFLECTION': 'reflect', 'STICKY': 'stick', 'STRESS': 'stress', 'TANGENT': 'tangent', 'OBJECT': 'transformed', } texco = switchTexCoords.get(mtex.texture_coords, 'orco') # get texture coords, default is 'orco' yi.paramsSetString("texco", texco) if mtex.object: texmat = mtex.object.matrix_local.inverted() rtmatrix = yafrayinterface.new_floatArray(4 * 4) for x in range(4): for y in range(4): idx = (y + x * 4) yafrayinterface.floatArray_setitem(rtmatrix, idx, texmat[x][y]) yi.paramsSetMemMatrix("transform", rtmatrix, True) yafrayinterface.delete_floatArray(rtmatrix) yi.paramsSetInt("proj_x", proj2int(mtex.mapping_x)) yi.paramsSetInt("proj_y", proj2int(mtex.mapping_y)) yi.paramsSetInt("proj_z", proj2int(mtex.mapping_z)) if mtex.mapping == 'FLAT': yi.paramsSetString("mapping", "plain") elif mtex.mapping == 'CUBE': yi.paramsSetString("mapping", "cube") elif mtex.mapping == 'TUBE': yi.paramsSetString("mapping", "tube") elif mtex.mapping == 'SPHERE': yi.paramsSetString("mapping", "sphere") yi.paramsSetPoint("offset", mtex.offset[0], mtex.offset[1], mtex.offset[2]) yi.paramsSetPoint("scale", mtex.scale[0], mtex.scale[1], mtex.scale[2]) if mtex.use_map_normal: # || mtex->maptoneg & MAP_NORM ) # scale up the normal factor, it resembles # blender a bit more nf = mtex.normal_factor * 2 yi.paramsSetFloat("bump_strength", nf)
def writeMappingNode(self, name, texname, mtex): yi = self.yi yi.paramsPushList() yi.paramsSetString("element", "shader_node") yi.paramsSetString("type", "texture_mapper") yi.paramsSetString("name", name) #yi.paramsSetString("texture", self.namehash(mtex.tex)) yi.paramsSetString("texture", mtex.texture.name) #'UV' 'GLOBAL' 'ORCO' , 'WINDOW', 'NORMAL' 'REFLECTION' 'STICKY' 'STRESS' 'TANGENT' # texture coordinates, have to disable 'sticky' in Blender #change to coord. type Blender, texture_coords. for test yi.paramsSetString("texco", "orco") if mtex.texture_coords == 'UV' : yi.paramsSetString("texco", "uv") elif mtex.texture_coords == 'GLOBAL' : yi.paramsSetString("texco", "global") elif mtex.texture_coords == 'ORCO' : yi.paramsSetString("texco", "orco") elif mtex.texture_coords == 'WINDOW' : yi.paramsSetString("texco", "window") elif mtex.texture_coords == 'NORMAL' : yi.paramsSetString("texco", "normal") elif mtex.texture_coords == 'REFLECTION': yi.paramsSetString("texco", "reflect") elif mtex.texture_coords == 'STICKY' : yi.paramsSetString("texco", "stick") elif mtex.texture_coords == 'STRESS' : yi.paramsSetString("texco", "stress") elif mtex.texture_coords == 'TANGENT' : yi.paramsSetString("texco", "tangent") elif mtex.texture_coords == 'OBJECT': yi.paramsSetString("texco", "transformed") if mtex.object is not None: texmat = mtex.object.matrix_local.copy().invert() rtmatrix = yafrayinterface.new_floatArray(4*4) for x in range(4): for y in range(4): idx = (y + x * 4) yafrayinterface.floatArray_setitem(rtmatrix, idx, texmat[x][y]) yi.paramsSetMemMatrix("transform", rtmatrix, True) yafrayinterface.delete_floatArray(rtmatrix) yi.paramsSetInt("proj_x", proj2int(mtex.mapping_x)) yi.paramsSetInt("proj_y", proj2int(mtex.mapping_y)) yi.paramsSetInt("proj_z", proj2int(mtex.mapping_z)) if mtex.mapping == 'FLAT' : yi.paramsSetString("mapping", "plain") elif mtex.mapping == 'CUBE' : yi.paramsSetString("mapping", "cube") elif mtex.mapping == 'TUBE' : yi.paramsSetString("mapping", "tube") elif mtex.mapping == 'SPHERE' : yi.paramsSetString("mapping", "sphere") if mtex.use_map_normal: #|| mtex->maptoneg & MAP_NORM ) # scale up the normal factor, it ressembles # blender a bit more nf = mtex.normal_factor * 5 yi.paramsSetFloat("bump_strength", nf)
def writeMappingNode(self, name, texname, mtex): yi = self.yi yi.paramsPushList() yi.paramsSetString("element", "shader_node") yi.paramsSetString("type", "texture_mapper") yi.paramsSetString("name", name) yi.paramsSetString("texture", texname) # get texture coords, default is 'orco' texco = switchTextureCoordinates.get(mtex.texture_coords, 'orco') yi.paramsSetString("texco", texco) if mtex.object: texmat = mtex.object.matrix_world.inverted() rtmatrix = yafrayinterface.new_floatArray(4 * 4) for x in range(4): for y in range(4): idx = (y + x * 4) yafrayinterface.floatArray_setitem(rtmatrix, idx, texmat[x][y]) yi.paramsSetMemMatrix("transform", rtmatrix, False) yafrayinterface.delete_floatArray(rtmatrix) yi.paramsSetInt("proj_x", proj2int(mtex.mapping_x)) yi.paramsSetInt("proj_y", proj2int(mtex.mapping_y)) yi.paramsSetInt("proj_z", proj2int(mtex.mapping_z)) mappingCoords = switchMappingCoords.get(mtex.mapping, 'plain') yi.paramsSetString("mapping", mappingCoords) yi.paramsSetPoint("offset", mtex.offset[0], mtex.offset[1], mtex.offset[2]) if self.preview: # check if it is a texture preview render mtex_X = mtex.scale[ 0] * 8.998 # tex preview fix: scale X value of tex size for the stretched Plane Mesh in preview scene mtex_Z = mtex.scale[ 2] * 0.00001 # and for Z value of texture size also... yi.paramsSetPoint("scale", mtex_X, mtex.scale[1], mtex_Z) else: yi.paramsSetPoint("scale", mtex.scale[0], mtex.scale[1], mtex.scale[2]) if mtex.use_map_normal: # || mtex->maptoneg & MAP_NORM ) # scale up the normal factor, it resembles # blender a bit more nf = mtex.normal_factor * 2 yi.paramsSetFloat("bump_strength", nf)
def writeMappingNode(self, name, texname, mtex): yi = self.yi yi.paramsPushList() yi.paramsSetString("element", "shader_node") yi.paramsSetString("type", "texture_mapper") yi.paramsSetString("name", name) yi.paramsSetString("texture", self.namehash(mtex.tex)) # texture coordinates, have to disable 'sticky' in Blender if mtex.texco == Blender.Texture.TexCo.UV: yi.paramsSetString("texco", "uv") elif mtex.texco == Blender.Texture.TexCo.GLOB: yi.paramsSetString("texco", "global") elif mtex.texco == Blender.Texture.TexCo.ORCO: yi.paramsSetString("texco", "orco") elif mtex.texco == Blender.Texture.TexCo.WIN: yi.paramsSetString("texco", "window") elif mtex.texco == Blender.Texture.TexCo.NOR: yi.paramsSetString("texco", "normal") elif mtex.texco == Blender.Texture.TexCo.REFL: yi.paramsSetString("texco", "reflect") elif mtex.texco == Blender.Texture.TexCo.STICK: yi.paramsSetString("texco", "stick") elif mtex.texco == Blender.Texture.TexCo.STRESS: yi.paramsSetString("texco", "stress") elif mtex.texco == Blender.Texture.TexCo.TANGENT: yi.paramsSetString("texco", "tangent") elif mtex.texco == Blender.Texture.TexCo.OBJECT: yi.paramsSetString("texco", "transformed") if mtex.object != None: texmat = mtex.object.getInverseMatrix() rtmatrix = yafrayinterface.new_floatArray(4*4) for x in range(4): for y in range(4): idx = (y + x * 4) yafrayinterface.floatArray_setitem(rtmatrix, idx, texmat[x][y]) yi.paramsSetMemMatrix("transform", rtmatrix, True) yafrayinterface.delete_floatArray(rtmatrix) yi.paramsSetInt("proj_x", proj2int(mtex.xproj)) yi.paramsSetInt("proj_y", proj2int(mtex.yproj)) yi.paramsSetInt("proj_z", proj2int(mtex.zproj)) # allow mapping with procedurals too, i don't see why i shouldn't... if mtex.mapping == Blender.Texture.Mappings.FLAT: yi.paramsSetString("mapping", "plain") elif mtex.mapping == Blender.Texture.Mappings.CUBE: yi.paramsSetString("mapping", "cube") elif mtex.mapping == Blender.Texture.Mappings.TUBE: yi.paramsSetString("mapping", "tube") elif mtex.mapping == Blender.Texture.Mappings.SPHERE: yi.paramsSetString("mapping", "sphere") yi.paramsSetPoint("offset", mtex.ofs[0], mtex.ofs[1], mtex.ofs[2]) yi.paramsSetPoint("scale", mtex.size[0], mtex.size[1], mtex.size[2]) if mtex.mapto == Blender.Texture.MapTo.NOR: #|| mtex->maptoneg & MAP_NORM ) nf = mtex.norfac yi.paramsSetFloat("bump_strength", nf)
def writeMappingNode(self, name, texname, mtex): yi = self.yi yi.paramsPushList() yi.paramsSetString("element", "shader_node") yi.paramsSetString("type", "texture_mapper") yi.paramsSetString("name", name) yi.paramsSetString("texture", texname) # get texture coords, default is 'orco' texco = switchTextureCoordinates.get(mtex.texture_coords, "orco") yi.paramsSetString("texco", texco) if mtex.object: texmat = mtex.object.matrix_world.inverted() rtmatrix = yafrayinterface.new_floatArray(4 * 4) for x in range(4): for y in range(4): idx = y + x * 4 yafrayinterface.floatArray_setitem(rtmatrix, idx, texmat[x][y]) yi.paramsSetMemMatrix("transform", rtmatrix, False) yafrayinterface.delete_floatArray(rtmatrix) yi.paramsSetInt("proj_x", proj2int(mtex.mapping_x)) yi.paramsSetInt("proj_y", proj2int(mtex.mapping_y)) yi.paramsSetInt("proj_z", proj2int(mtex.mapping_z)) mappingCoords = switchMappingCoords.get(mtex.mapping, "plain") yi.paramsSetString("mapping", mappingCoords) yi.paramsSetPoint("offset", mtex.offset[0], mtex.offset[1], mtex.offset[2]) if self.preview: # check if it is a texture preview render mtex_X = ( mtex.scale[0] * 8.998 ) # tex preview fix: scale X value of tex size for the stretched Plane Mesh in preview scene mtex_Z = mtex.scale[2] * 0.00001 # and for Z value of texture size also... yi.paramsSetPoint("scale", mtex_X, mtex.scale[1], mtex_Z) else: yi.paramsSetPoint("scale", mtex.scale[0], mtex.scale[1], mtex.scale[2]) if mtex.use_map_normal: # || mtex->maptoneg & MAP_NORM ) # scale up the normal factor, it resembles # blender a bit more nf = mtex.normal_factor * 2 yi.paramsSetFloat("bump_strength", nf)
def writeMappingNode(self, name, texname, mtex): yi = self.yi yi.paramsPushList() yi.paramsSetString("element", "shader_node") yi.paramsSetString("type", "texture_mapper") yi.paramsSetString("name", name) yi.paramsSetString("texture", texname) switchTexCoords = { 'UV': 'uv', 'GLOBAL': 'global', 'ORCO': 'orco', 'WINDOW': 'window', 'NORMAL': 'normal', 'REFLECTION': 'reflect', 'STICKY': 'stick', 'STRESS': 'stress', 'TANGENT': 'tangent', 'OBJECT': 'transformed', } texco = switchTexCoords.get( mtex.texture_coords, 'orco') # get texture coords, default is 'orco' yi.paramsSetString("texco", texco) if mtex.object: texmat = mtex.object.matrix_world.inverted() rtmatrix = yafrayinterface.new_floatArray(4 * 4) for x in range(4): for y in range(4): idx = (y + x * 4) yafrayinterface.floatArray_setitem(rtmatrix, idx, texmat[x][y]) yi.paramsSetMemMatrix("transform", rtmatrix, False) yafrayinterface.delete_floatArray(rtmatrix) yi.paramsSetInt("proj_x", proj2int(mtex.mapping_x)) yi.paramsSetInt("proj_y", proj2int(mtex.mapping_y)) yi.paramsSetInt("proj_z", proj2int(mtex.mapping_z)) switchMappingCoords = { 'FLAT': 'plain', 'CUBE': 'cube', 'TUBE': 'tube', 'SPHERE': 'sphere', } mappingCoords = switchMappingCoords.get(mtex.mapping, 'plain') yi.paramsSetString("mapping", mappingCoords) yi.paramsSetPoint("offset", mtex.offset[0], mtex.offset[1], mtex.offset[2]) if self.preview: # check if it is a texture preview render mtex_X = mtex.scale[ 0] * 8.998 # tex preview fix: scale X value of tex size for the stretched Plane Mesh in preview scene mtex_Z = mtex.scale[ 2] * 0.00001 # and for Z value of texture size also... yi.paramsSetPoint("scale", mtex_X, mtex.scale[1], mtex_Z) else: yi.paramsSetPoint("scale", mtex.scale[0], mtex.scale[1], mtex.scale[2]) if mtex.use_map_normal: # || mtex->maptoneg & MAP_NORM ) # scale up the normal factor, it resembles # blender a bit more nf = mtex.normal_factor * 2 yi.paramsSetFloat("bump_strength", nf)
def writeMappingNode(self, name, texname, mtex): yi = self.yi yi.paramsPushList() yi.paramsSetString("element", "shader_node") yi.paramsSetString("type", "texture_mapper") yi.paramsSetString("name", name) yi.paramsSetString("texture", texname) switchTexCoords = { 'UV': 'uv', 'GLOBAL': 'global', 'ORCO': 'orco', 'WINDOW': 'window', 'NORMAL': 'normal', 'REFLECTION': 'reflect', 'STICKY': 'stick', 'STRESS': 'stress', 'TANGENT': 'tangent', 'OBJECT': 'transformed', } texco = switchTexCoords.get(mtex.texture_coords, 'orco') # get texture coords, default is 'orco' yi.paramsSetString("texco", texco) if mtex.object: texmat = mtex.object.matrix_world.inverted() rtmatrix = yafrayinterface.new_floatArray(4 * 4) for x in range(4): for y in range(4): idx = (y + x * 4) yafrayinterface.floatArray_setitem(rtmatrix, idx, texmat[x][y]) yi.paramsSetMemMatrix("transform", rtmatrix, False) yafrayinterface.delete_floatArray(rtmatrix) yi.paramsSetInt("proj_x", proj2int(mtex.mapping_x)) yi.paramsSetInt("proj_y", proj2int(mtex.mapping_y)) yi.paramsSetInt("proj_z", proj2int(mtex.mapping_z)) switchMappingCoords = { 'FLAT': 'plain', 'CUBE': 'cube', 'TUBE': 'tube', 'SPHERE': 'sphere', } mappingCoords = switchMappingCoords.get(mtex.mapping, 'plain') yi.paramsSetString("mapping", mappingCoords) yi.paramsSetPoint("offset", mtex.offset[0], mtex.offset[1], mtex.offset[2]) if self.preview: # check if it is a texture preview render mtex_X = mtex.scale[0] * 8.998 # tex preview fix: scale X value of tex size for the stretched Plane Mesh in preview scene mtex_Z = mtex.scale[2] * 0.00001 # and for Z value of texture size also... yi.paramsSetPoint("scale", mtex_X, mtex.scale[1], mtex_Z) else: yi.paramsSetPoint("scale", mtex.scale[0], mtex.scale[1], mtex.scale[2]) if mtex.use_map_normal: # || mtex->maptoneg & MAP_NORM ) # scale up the normal factor, it resembles # blender a bit more nf = mtex.normal_factor * 2 yi.paramsSetFloat("bump_strength", nf)