Use MEL Script to Create Cubes That Make Up Model?

Use MEL Script to Create Cubes That Make Up Model?

Anonymous
Not applicable
1,455 Views
2 Replies
Message 1 of 3

Use MEL Script to Create Cubes That Make Up Model?

Anonymous
Not applicable

Hi, I'm really new to Maya and I'm trying to use MEL script to create cubes so that the 3D model is made up of cubes instead (imagine creating a model using Lego).

 

My object is called polySurface1, but I have no idea how to construct my script.

 

I guess I have to first get the positons of the vertices and then create the cubes at those positions, but it seems like I keep getting 0 0 0 no matter what. Here is an example of the code I used (my model has 5366 vertices):

 

vector $pos = `getAttr polySurface1.vtx[3]`;
print ($pos);

Thank you in advance!

0 Likes
1,456 Views
2 Replies
Replies (2)
Message 2 of 3

saihtam
Collaborator
Collaborator

I don't think that's the right approach, as you'd get a lot of cubes intersecting and very uneven distribution depending on your model.

 

What you're querying is the tweak of that vertex. To get the position use xform. 

xform -q -ws -t pCone1.vtx[20]

There are voxalize script that has been done before. And if I had to do it right now off the top of my head I'd probably do something along the lines of getting the size of the bounding box, then move through that incramentally, check if the position was inside the mesh, if so, create a cube, if not, keep checking.

 

To check if you're inside a mesh you'd probably have to get a bit creative with the coding. You could possibly use this setup from the awesome Mr. Ehrenhaus to do this check at a very simple level. Depending on how complex your character is, this setup could probably give you wrong results at times. Some stuff to think about.

- Mathias
0 Likes
Message 3 of 3

saihtam
Collaborator
Collaborator
0 Likes