View Full Version : creating mesh data

 caspermel05 May 2007, 07:35 AMHi there; is there a way to create mesh data by just supplying the vertices (the point information, x,y,z), or what is the minimum information that I need to supply for the creation of a mesh. I found out the MFnMesh class for creating but it want too many information about the design of the mesh, like the number of polygon faces and so on? It doesnt matter whether the solution is in mel or api, would like to hear both though :) Thanks a lot melis :)
dbsmith
05 May 2007, 03:36 AM
I don't see how you can just supply a list of verts and expect to get a mesh out of it - you need to supply how the verts connect up.

API:

Maya needs 3 things:

MPointArray &verts,
MIntArray &polyCounts,
MIntArray &polyConnects,

MPoint p;

//First, give Maya the actual vertices.

p.x = 0.0; p.y = 0.0; p.z = 0.0;
verts.append(p);

p.x = 0.0; p.y = 1.0; p.z = 0.0;
verts.append(p);

p.x = 1.0; p.y = 0.0; p.z = 0.0;
verts.append(p);

p.x = 1.0; p.y = 1.0; p.z = 0.0;
verts.append(p);

//Then, tell Maya in what order they connect up
polyConnects.append(0);
polyConnects.append(2);
polyConnects.append(3);
polyConnects.append(1);

//Then, how many vertices in this polygon (I think)
polyCounts.append(4);

//Repeat above for each polygon.

dbsmith
05 May 2007, 03:41 AM
MEL:

\$planey = `polyPlane -w 1 -h 1 -sx 1 -sy 1 -ax 0 0 1 -tx 1 -ch 1`;

\$xyz = GetPointFromSomewhere();
select (\$planey[0] + ".vtx[2]");
move -ws \$xyz[0] \$xyz[1] \$xyz[2];

\$xyz = GetPointFromSomewhere();
select (\$planey[0] + ".vtx[3]");
move -ws \$xyz[0] \$xyz[1] \$xyz[2];

\$xyz = GetPointFromSomewhere();
select (\$planey[0] + ".vtx[0]");
move -ws \$xyz[0] \$xyz[1] \$xyz[2];

\$xyz = GetPointFromSomewhere();
select (\$planey[0] + ".vtx[1]");
move -ws \$xyz[0] \$xyz[1] \$xyz[2];

//I guess you could do something similar for larger shapes - i.e. create a shape and just move its original vertices to match yours. It's all based on how Maya's shape creation scripts order their vertices and how you want your final mesh to be connected. For example, if you model is completely "solid" (no holes) you could try and create a sphere and traverse its vertices in order, moving them to your vertex locations. But API seems a better way to go

Robert Bateman
05 May 2007, 10:55 AM
definately one of those situations where it's easier in the API. In mel you can use polyCreateFacet for each poly, then combine them all. Be sure you disable the undo queue when you are doing that though, otherwise you'll quickly generate Gb's of undo info (stored in memory) for a relatively simple mesh.

Infernalspawn
01 January 2008, 08:33 AM
Sorry for kidnapping this thread, does anybody know how the UV Coordinates have to be formated when crating a mesh with the Create Method ? Or is it better to use one o the other functions ? (p.s. i wanna use this inside a node)

Cheers Infernal

Keilun
01 January 2008, 03:37 PM
The UV arrays will just create the data inside the mesh. Calling create with the U/V arrays will not attempt to assign UVs. You will need to manually assign the UVIds to the vertices following the create.

As long as you recall the order of your arrays (so you can extrapolate the UVIds for each value), you can re-use that ordering to assign them to the appropriate vertices.

CGTalk Moderation
01 January 2008, 03:37 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.

1