Announcements

Between mid-October and November, the content on AREA will be relocated to the Autodesk Community M&E Hub and the Autodesk Community Gallery. Learn more HERE.

MpxNode merge input mesh and newpolygons

MpxNode merge input mesh and newpolygons

stuzzz
Collaborator Collaborator
561 Views
2 Replies
Message 1 of 3

MpxNode merge input mesh and newpolygons

stuzzz
Collaborator
Collaborator

hello,

 

I have a MPxNode which has a mesh as an input attribute.

My output mesh attribute is a copy of the input but with a large amount of polygons created implemented in the MPxNode::compute() method.

for now my code is like this sample:

 

 

		MDataHandle inHld = data.inputValue(inMeshAttr);
		MObject inObj = inHld.asMesh();

		MDataHandle meshOutHdl = data.outputValue(outputAttr);

		meshOutHdl.copy(inHld);
		MFnMesh inMeshFn(meshOutHdl.asMesh());		
		
		MObject res= inMeshFn.create(numVerts, numpolys, vertarray, polycount, polyconn, inObj);
		inMeshFn.updateSurface();

		CHECK_MSTATUS(meshOutHdl.set(res));
	
		data.setClean(plug);

 

 

 

The problem is that my input mesh is replace with the newly created one.

I'd like to merge/append the resulting operation of MFnMesh::create() and my input shape.

 

I tought about MFnMesh::addPolygon but there is a ton of polys to create.

 

thx

0 Likes
Accepted solutions (1)
562 Views
2 Replies
Replies (2)
Message 2 of 3

jmreinhart
Advisor
Advisor

So could get all of this data from your input shape.

(numVerts, numpolys, vertarray, polycount, polyconn, inObj);

And then you'd go in and "offset" the indices in polyconn of your new data by adding the number of vertices in your original shape to each integer in your polyconn MIntarray. The you could just append the new data to the original data.

0 Likes
Message 3 of 3

stuzzz
Collaborator
Collaborator
Accepted solution

Hey thanks for answering, I found my solution few hours ago, it's working. 

@jmreinhart indeed i took the same direction (append new datas to old one)

 

That's what I go so far:

MFnMesh meshFn(inObj);
meshFn.updateSurface();

// -- fetch input datas
int numverts2 = meshFn.numVertices();
int numpolys2 = meshFn.numPolygons();
MPointArray vertarray2;  meshFn.getPoints(vertarray2);
MIntArray polycount2; MIntArray polyconn2; meshFn.getVertices(polycount2, polyconn2);
	


// -- sum input datas with attribute datas
sumDatas(vertarray2, vertarray);
sumDatas(polycount2, polycount);
sumPolyconn(polyconn2, polyconn, numverts2);
appendNormals(normals, numverts);

// -- create new parentOwner
MFnMeshData meshDataFn;
MObject newMeshData = meshDataFn.create();
MFnMesh newFn(newMeshData);

newFn.create(
				numverts + numverts2, 
				numpolys + numpolys2, 
				vertarray2, 
				polycount2, 
				polyconn2, 
				newMeshData, 
				&stat);

if (!stat) { return MS::kInvalidParameter; }
newFn.updateSurface();

CHECK_MSTATUS(meshOutHdl.set(newMeshData));

The tricky thing is to get the correct owner and pass the valid data to the outputHandle.

I need to restore the UVs and edge hardness, then I'll be all set.

for some reason when I delete my node, the shape remain the still. I expected to have the previous shape back. I guess that I need to reevaluate the datablock or something

 

 

 

 

0 Likes