I would like to write a PyMel script that generates a single triangle mesh. Ultimately, I want to understand how to create a mesh in Maya via PyMell using raw verts and normals.
I know that I can create a sphere mesh like so
mySphere = pm.polySphere();
But if I want to make it in a more explicit fashion, I could to the following
What I have learned is that I need a Shape/Mesh node which holds all the raw verts/normals/face information.
However the polySphere node is the mesh generator. In other words, it calculates the position of the verts on the sphere based on parameters passed into the node such as the Sphere’s radius.
Basically I want to do the same thing except I want to inject my own raw vert/normals/faces into my shape node. I want to start by creating a simple triangle. How would I go about this? How do I pass my own vert/normals/faces into a Mesh’s inMesh property? Thanks!
For example, is there are way to do the following?
import pymel.core as pm;
mesh = pm.createNode( "mesh", "MyMesh" );
# The following line does not work but how can I assign the vertex position "0,0,0" to the first vertex slot in the "MyMesh" object?
mesh.vrts[0] = MeshVertex( [0,0,0] );
For those interested, I was able to come up with a round about way of creating a triangle by starting with a cube, triangulating it, and then deleting all the faces except for the first one.
polyCreateFacet is probably much closer to what I want so I am going to try to rewrite the code to use that function instead of stripping down a poly cube.
If you want to make a mesh, run a polyCreateFacet for each triangle, then grab the results, polyUnite them, polyMergeVert them, and delete their history.
Unfortunately this is slow
You can speed it up a bit by wrapping it in a no-undo block
[QUOTE=Theodox;27417]If you want to make a mesh, run a polyCreateFacet for each triangle, then grab the results, polyUnite them, polyMergeVert them, and delete their history.
Unfortunately this is slow
You can speed it up a bit by wrapping it in a no-undo block[/QUOTE]
You know, reading this makes me feel better about having to do that for a collision generator I made long ago.
You can make the stupid things the ‘right’ way in the API; it’s also much faster.-- but it has to be done via a plugin. If you run the exact same code outside an MPXPlugin you can never undo it. It’s such a wierd oversight in the maya command set
So polyCreateFacet just creates faces, which have normal values, the unite will turn them all into one shape node, and the merge will remove duplicate vertices.
Its been awhile since I’ve built a mesh like this, but I believe the edges will just be set to ‘hard’ shading, which would mean that none of the vertex normals get averaged, but you can mess around with the polySoftEdge to smooth / soften edges as you need.
the maya ascii file shows you how to assign data directly to mesh structures. i use this to assign skinweights, much faster than skinPercent. I have not tried this in python, probably works ok