Hey everyone,

I'm currently using the OpenMayaRender.MPxSubSceneOverride to visualize 
some custom data in the viewport. 

In the simplest terms what I'm looking for is to create a point cloud, with 
each point having a unique color. Kind of like rgbPP on particles.

What I want to do is create 1 MRenderItem, fill the vertex buffer with all 
my point positions. And then via one of the ShaderManger stock shaders 
assign some unique colors to each of the points.

I thought the "k3dCPVFatPointShader" would be the answer to my issue but it 
doesn't seem to work. The color of all my points stay the stock color of 
blue.

I feel like what I'm attempting to do is really simple, I'm just missing 
something. Anyone ever have any luck assigning colors to points that exist 
within the same render item? Is it possible using the stock shaders?

Here's what I have at the moment:
vboPosDesc = OpenMayaRender.MVertexBufferDescriptor("", OpenMayaRender.
MGeometry.kPosition, OpenMayaRender.MGeometry.kFloat, 3)
vboColorDesc = OpenMayaRender.MVertexBufferDescriptor("color", 
OpenMayaRender.MGeometry.kColor, OpenMayaRender.MGeometry.kFloat, 3)

def createPointCloud(self, container):
    shader = self.shaderMgr.getStockShader(OpenMayaRender.MShaderManager.
k3dCPVFatPointShader)  

    positions = VBO_Pos.acquire(numPoints, True)
    colors = VBO_Color.acquire(numPoints, True)
    
    numPoints = 1000
           
    VBO_Pos = OpenMayaRender.MVertexBuffer(vboPosDesc)
    VBO_Color = OpenMayaRender.MVertexBuffer(vboColorDesc)
    
    floatinc = sizeof(c_float)
    
    pid = 0
    for x in xrange(numPoints):
        c_float.from_address(positions + (pid) * floatinc).value   = random.
uniform(-500, 500)
        c_float.from_address(positions + (pid+1) * floatinc).value = 0.0
        c_float.from_address(positions + (pid+2) * floatinc).value = random.
uniform(-500, 500)
       
        c_float.from_address(colors + (pid) * floatinc).value   = random.
uniform(0,1)
        c_float.from_address(colors + (pid+1) * floatinc).value = random.
uniform(0,1)
        c_float.from_address(colors + (pid+2) * floatinc).value = random.
uniform(0,1)
       
        pid+=3
       
    VBO_Pos.commit(positions)
    VBO_Color.commit(colors)
   
    item = OpenMayaRender.MRenderItem.create("pointCloud", OpenMayaRender.
MRenderItem.DecorationItem, OpenMayaRender.MGeometry.kPoints)
    item.setShader(shader)
    container.add(item)

    buffers = OpenMayaRender.MVertexBufferArray()
    buffers.append(VBO_Color, "color")
    buffers.append(VBO_Pos, "positions")

    self.setGeometryForRenderItem(item, buffers, None, None)
   
    self.shaderMgr.releaseShader(shader)
   
    return item

P.S. I have successfully gotten what I want by creating a renderItem 
containing 1 point, instancing that point to all the positions I want, then 
overriding the "solidColor" attribute on the shader via the 
"setExtraInstanceData" method. But that seems to run about 4-5 times slower 
than having all the points within the same RenderItem

Thanks a lot in advance for any help on this :)

Cheers,
-Ryan

-- 
You received this message because you are subscribed to the Google Groups 
"Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/python_inside_maya/eb6a6936-5147-4027-ad1f-27041ca14296%40googlegroups.com.

Reply via email to