I’m attempting to re-write a script made for Max that will take information over time (vertex animation or timeline animation) from a mesh and generate an array that is then relocated to pixels to output an image that other software can read (UE4 in this case).
The part I’m having trouble with is this:
global FinalTexture = bitmap numberofVerts (MorphVertOffsetArray.count) filename:TextureName hdr:true;--TextureName ;
for i=0 to (MorphVertOffsetArray.count-1) do (
setPixels FinalTexture [0, i] MorphVertOffsetArray[(i+1)]
)
It is using bitmap and setPixels to make a texture and set the values of pixels in the relevant positions.
I need to do the same in Maya, and I’ve got a solution in place using the Maya Python API, however none of the pixels are being set, or when I do out_image.setPixels() it is not setting it correctly there. I am at a loss.
This is the Maya Python attempt I have made thus far. The “pixels” variable comes from an “image” variable that was read in earlier, currently it just takes the width/height from there (correctly)
pixels = image.pixels()
depth = 3
array_len = len(self.morph_vert_offset_array[0])
print array_len # 66 in my test scene
for i in range(0, array_len, depth):
color = self.morph_vert_offset_array[0][i]
color[0] = color[0] if color[0] > 0 else 0
color[1] = color[1] if color[1] > 0 else 0
color[2] = color[2] if color[2] > 0 else 0
print int(math.floor(color[2])) # valid values ranging 0-255
om.MScriptUtil.setUcharArray(pixels, i+0, int(math.floor(color[0])))
om.MScriptUtil.setUcharArray(pixels, i+1, int(math.floor(color[1])))
om.MScriptUtil.setUcharArray(pixels, i+2, int(math.floor(color[2])))
out_image = om.MImage()
out_image.setPixels(pixels, width, height)
out_image.writeToFile("D:/01_Projects/texture3.jpg", ext)