本文整理汇总了C++中MIntArray::length方法的典型用法代码示例。如果您正苦于以下问题:C++ MIntArray::length方法的具体用法?C++ MIntArray::length怎么用?C++ MIntArray::length使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MIntArray
的用法示例。
在下文中一共展示了MIntArray::length方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: selIter
MStatus SelectRingContext1::doRelease( MEvent &event )
{
// Get the mouse release position
event.getPosition( releaseX, releaseY );
// Didn't select a single point
if( abs(pressX - releaseX) > 1 || abs(pressY - releaseY) > 1 )
{
MGlobal::displayWarning( "Click on a single edge" );
return MS::kFailure;
}
// Set the selection surface area
int halfClickBoxSize = clickBoxSize / 2;
pressX -= halfClickBoxSize;
pressY -= halfClickBoxSize;
releaseX = pressX + clickBoxSize;
releaseY = pressY + clickBoxSize;
/*
// Record previous selection state
prevSelMode = MGlobal::selectionMode();
prevCompMask = MGlobal::componentSelectionMask();
*/
// Get the current selection
MSelectionList curSel;
MGlobal::getActiveSelectionList( curSel );
//MGlobal::displayInfo( MString("Dim: ") + start_x + " " + start_y + " " + last_x + " " + last_y );
// Change to object selection mode
MGlobal::setSelectionMode( MGlobal::kSelectObjectMode );
MGlobal::setComponentSelectionMask( MSelectionMask( MSelectionMask::kSelectObjectsMask ) );
// Select the object under the selection area
MGlobal::selectFromScreen( pressX, pressY, releaseX, releaseY, MGlobal::kReplaceList);
MGlobal::executeCommand( "hilite" );
// Change selection mode to mesh edges
MGlobal::setSelectionMode( MGlobal::kSelectComponentMode );
MGlobal::setComponentSelectionMask( MSelectionMask( MSelectionMask::kSelectMeshEdges ) );
// Select the edges
MGlobal::selectFromScreen( pressX, pressY, releaseX, releaseY, MGlobal::kReplaceList );
// Get the list of selected edges
MSelectionList origEdgesSel;
MGlobal::getActiveSelectionList( origEdgesSel );
MSelectionList newEdgesSel;
MDagPath dagPath;
MObject component;
// Only use the first edge in the selection
MItSelectionList selIter( origEdgesSel, MFn::kMeshEdgeComponent );
if( !selIter.isDone() )
{
selIter.getDagPath( dagPath, component );
MIntArray faces;
MItMeshEdge edgeIter( dagPath, component );
MIntArray edgesVisited, facesVisited;
int edgeIndex, faceIndex;
int prevIndex;
unsigned int i;
bool finished = false;
while( !finished )
{
edgeIndex = edgeIter.index();
edgesVisited.append( edgeIndex );
// Create an edge component the current edge
MFnSingleIndexedComponent indexedCompFn;
MObject newComponent = indexedCompFn.create( MFn::kMeshEdgeComponent );
indexedCompFn.addElement( edgeIndex );
newEdgesSel.add( dagPath, newComponent );
//MGlobal::displayInfo( MString("ADDING: ") + edgeIter.index() );
edgeIter.getConnectedFaces( faces );
faceIndex = faces[0];
if( faces.length() > 1 )
{
// Select the face that hasn't already been visited
for( i=0; i < facesVisited.length(); i++ )
{
if( faceIndex == facesVisited[i] )
{
faceIndex = faces[1];
break;
}
}
}
//MGlobal::displayInfo( MString("FACE: ") + faceIndex );
facesVisited.append( faceIndex );
MItMeshPolygon polyIter( dagPath );
//.........这里部分代码省略.........
示例2: compute
MStatus LSystemNode::compute(const MPlug& plug, MDataBlock& data)
{
MStatus returnStatus;
if (plug == outputMesh) {
/* Get time */
MDataHandle timeData = data.inputValue( time, &returnStatus );
McheckErr(returnStatus, "Error getting time data handle\n");
MTime time = timeData.asTime();
MDataHandle angleData = data.inputValue( angle, &returnStatus );
McheckErr(returnStatus, "Error getting time data handle\n");
double angle_value = angleData.asDouble();
MDataHandle stepsData = data.inputValue( steps, &returnStatus );
McheckErr(returnStatus, "Error getting time data handle\n");
double steps_value = stepsData.asDouble();
MDataHandle grammarData = data.inputValue( grammar, &returnStatus );
McheckErr(returnStatus, "Error getting time data handle\n");
MString grammar_value = grammarData.asString();
/* Get output object */
MDataHandle outputHandle = data.outputValue(outputMesh, &returnStatus);
McheckErr(returnStatus, "ERROR getting polygon data handle\n");
MFnMeshData dataCreator;
MObject newOutputData = dataCreator.create(&returnStatus);
McheckErr(returnStatus, "ERROR creating outputData");
MFnMesh myMesh;
MPointArray points;
MIntArray faceCounts;
MIntArray faceConnects;
//MString grammar = ("F\\nF->F[+F]F[-F]F");
CylinderMesh *cm;
LSystem system;
system.loadProgramFromString(grammar_value.asChar());
system.setDefaultAngle(angle_value);
system.setDefaultStep(steps_value);
std::vector<LSystem::Branch> branches;
system.process(time.value(), branches);
int k = branches.size();
for(int j = 0; j < branches.size(); j++)
{
//1. find the position for start and end point of current branch
//2. generate a cylinder
MPoint start(branches[j].first[0],branches[j].first[1],branches[j].first[2]);
MPoint end(branches[j].second[0],branches[j].second[1],branches[j].second[2]);
cm = new CylinderMesh(start, end);
cm->appendToMesh(points, faceCounts, faceConnects);
}
MObject newMesh = myMesh.create(points.length(), faceCounts.length(),
points, faceCounts, faceConnects,
newOutputData, &returnStatus);
McheckErr(returnStatus, "ERROR creating new mesh");
outputHandle.set(newOutputData);
data.setClean( plug );
} else
return MS::kUnknownParameter;
return MS::kSuccess;
}
示例3: writeMesh
// write a normal mesh
//
MStatus vxCache::writeMesh(const char* filename, MDagPath meshDag, const MObject& meshObj)
{
struct meshInfo mesh;
MString uvset("map1");
MStatus status;
MFnMesh meshFn(meshDag, &status );
MItMeshPolygon faceIter( meshDag, MObject::kNullObj, &status );
MItMeshVertex vertIter(meshDag, MObject::kNullObj, &status);
MItMeshEdge edgeIter(meshDag, MObject::kNullObj, &status);
mesh.numPolygons = meshFn.numPolygons();
mesh.numVertices = meshFn.numVertices();
mesh.numFaceVertices = meshFn.numFaceVertices();
mesh.numUVs = meshFn.numUVs(uvset, &status);
mesh.skip_interreflection = mesh.skip_scattering = 0;
//if(zWorks::hasNamedAttribute(meshObj, "_prt_ig_intr") == 1) mesh.skip_interreflection = 1;
//if(zWorks::hasNamedAttribute(meshObj, "_prt_ig_scat") == 1) mesh.skip_scattering = 1;
//zWorks::displayIntParam("N Face", mesh.numPolygons);
//zWorks::displayIntParam("N Vertex", mesh.numVertices);
//zWorks::displayIntParam("N Facevertex", mesh.numFaceVertices);
//zWorks::displayIntParam("N UV", mesh.numUVs);
int *fcbuf = new int[mesh.numPolygons];
faceIter.reset();
for( ; !faceIter.isDone(); faceIter.next() )
{
fcbuf[ faceIter.index() ] = faceIter.polygonVertexCount();
}
int* vertex_id = new int[mesh.numFaceVertices];
int* uv_id = new int[mesh.numFaceVertices];
// output face loop
int acc = 0;
faceIter.reset();
for( ; !faceIter.isDone(); faceIter.next() )
{
MIntArray vexlist;
faceIter.getVertices ( vexlist );
for( unsigned int i=0; i < vexlist.length(); i++ )
{
vertex_id[acc] = vexlist[i];
faceIter.getUVIndex ( i, uv_id[acc] );
acc++;
}
}
// output vertices
MPointArray pArray;
if(worldSpace) meshFn.getPoints ( pArray, MSpace::kWorld);
else meshFn.getPoints ( pArray, MSpace::kObject );
XYZ *pbuf = new XYZ[pArray.length()];
for( unsigned int i=0; i<pArray.length(); i++)
{
pbuf[i].x = pArray[i].x;
pbuf[i].y = pArray[i].y;
pbuf[i].z= pArray[i].z;
}
//output texture coordinate
MFloatArray uArray, vArray;
meshFn.getUVs ( uArray, vArray, &uvset );
double* ubuf = new double[mesh.numUVs];
double* vbuf = new double[mesh.numUVs];
for( unsigned int i=0; i<uArray.length(); i++)
{
ubuf[i] = uArray[i];
vbuf[i] = vArray[i];
}
/*
XYZ *norbuf = new XYZ[mesh.numVertices];
vertIter.reset();
MVector tnor;
for( unsigned int i=0; !vertIter.isDone(); vertIter.next(), i++ )
{
if(worldSpace) vertIter.getNormal(tnor, MSpace::kWorld);
else vertIter.getNormal(tnor, MSpace::kObject);
tnor.normalize();
norbuf[i].x = tnor.x;
norbuf[i].y = tnor.y;
norbuf[i].z = tnor.z;
}
MStatus hasAttr;
MString sColorSet("set_prt_attr");
meshFn.numColors( sColorSet, &hasAttr );
XYZ *colbuf = new XYZ[mesh.numVertices];
vertIter.reset();
//.........这里部分代码省略.........
示例4: getPolyNormals
void MayaMeshWriter::getPolyNormals(std::vector<float> & oNormals)
{
MStatus status = MS::kSuccess;
MFnMesh lMesh( mDagPath, &status );
if ( !status )
{
MGlobal::displayError( "MFnMesh() failed for MayaMeshWriter" );
}
// no normals bail early
if (mNoNormals)
{
return;
}
MPlug plug = lMesh.findPlug("noNormals", true, &status);
if (status == MS::kSuccess && plug.asBool() == true)
{
return;
}
// we need to check the locked state of the normals
else if ( status != MS::kSuccess )
{
bool userSetNormals = false;
// go through all per face-vertex normals and verify if any of them
// has been tweaked by users
unsigned int numFaces = lMesh.numPolygons();
for (unsigned int faceIndex = 0; faceIndex < numFaces; faceIndex++)
{
MIntArray normals;
lMesh.getFaceNormalIds(faceIndex, normals);
unsigned int numNormals = normals.length();
for (unsigned int n = 0; n < numNormals; n++)
{
if (lMesh.isNormalLocked(normals[n]))
{
userSetNormals = true;
break;
}
}
}
// we looped over all the normals and they were all calculated by Maya
// so we just need to check to see if any of the edges are hard
// before we decide not to write the normals.
if (!userSetNormals)
{
bool hasHardEdges = false;
// go through all edges and verify if any of them is hard edge
unsigned int numEdges = lMesh.numEdges();
for (unsigned int edgeIndex = 0; edgeIndex < numEdges; edgeIndex++)
{
if (!lMesh.isEdgeSmooth(edgeIndex))
{
hasHardEdges = true;
break;
}
}
// all the edges were smooth, we don't need to write the normals
if (!hasHardEdges)
{
return;
}
}
}
bool flipNormals = false;
plug = lMesh.findPlug("flipNormals", true, &status);
if ( status == MS::kSuccess )
flipNormals = plug.asBool();
// get the per vertex per face normals (aka vertex)
unsigned int numFaces = lMesh.numPolygons();
for (unsigned int faceIndex = 0; faceIndex < numFaces; faceIndex++ )
{
MIntArray vertexList;
lMesh.getPolygonVertices(faceIndex, vertexList);
// re-pack the order of normals in this vector before writing into prop
// so that Renderman can also use it
unsigned int numVertices = vertexList.length();
for ( int v = numVertices-1; v >=0; v-- )
{
unsigned int vertexIndex = vertexList[v];
MVector normal;
lMesh.getFaceVertexNormal(faceIndex, vertexIndex, normal);
if (flipNormals)
normal = -normal;
oNormals.push_back(static_cast<float>(normal[0]));
oNormals.push_back(static_cast<float>(normal[1]));
oNormals.push_back(static_cast<float>(normal[2]));
}
}
}
示例5: componentToVertexIDs
MStatus DDConvexHullUtils::componentToVertexIDs(MIntArray &outIndices,
const MObject &mesh,
const MObject &component)
{
// Create the funciton sets
MFnSingleIndexedComponent compFn(component);
MFnMesh meshFn(mesh);
MIntArray elems;
compFn.getElements(elems);
uint elemLen = elems.length();
// Convert the components to vertices based on component type
uint compType = compFn.componentType();
if (compType == MFn::kMeshVertComponent)
{
outIndices = elems;
}
else if (compType == MFn::kMeshEdgeComponent)
{
for (uint i=0; i < elemLen; i++)
{
int2 edgeVerts;
meshFn.getEdgeVertices(elems[i], edgeVerts);
outIndices.append(edgeVerts[0]);
outIndices.append(edgeVerts[1]);
}
}
else if (compType == MFn::kMeshPolygonComponent)
{
for (uint i=0; i < elemLen; i++)
{
// Grab verts for the current poly
MIntArray polyVerts;
meshFn.getPolygonVertices(elems[i], polyVerts);
uint polyVertsLen = polyVerts.length();
for (uint j=0; j < polyVertsLen; j++)
{
outIndices.append(polyVerts[j]);
}
}
}
else if (compType == MFn::kMeshFaceVertComponent)
{
// I think this is how you convert face to object
// relative vertices...
MIntArray faceCounts;
MIntArray faceVerts;
meshFn.getVertices(faceCounts, faceVerts);
for (uint j=0; j < elemLen; j++)
{
outIndices.append(faceVerts[j]);
}
}
else
{
// Not supported
return MStatus::kNotImplemented;
}
return MStatus::kSuccess;
}
示例6: initializeSetsAndLookupTables
bool CXRayObjectExport::initializeSetsAndLookupTables( bool exportAll )
//
// Description :
// Creates a list of all sets in Maya, a list of mesh objects,
// and polygon/vertex lookup tables that will be used to
// determine which sets are referenced by the poly components.
//
{
int i=0,j=0, length;
MStatus stat;
// Initialize class data.
// Note: we cannot do this in the constructor as it
// only gets called upon registry of the plug-in.
//
numSets = 0;
sets = NULL;
lastSets = NULL;
lastMaterials = NULL;
objectId = 0;
objectCount = 0;
polygonTable = NULL;
vertexTable = NULL;
polygonTablePtr = NULL;
vertexTablePtr = NULL;
objectGroupsTablePtr = NULL;
objectNodeNamesArray.clear();
transformNodeNameArray.clear();
//////////////////////////////////////////////////////////////////
//
// Find all sets in Maya and store the ones we care about in
// the 'sets' array. Also make note of the number of sets.
//
//////////////////////////////////////////////////////////////////
// Get all of the sets in maya and put them into
// a selection list
//
MStringArray result;
MGlobal::executeCommand( "ls -sets", result );
MSelectionList * setList = new MSelectionList();
length = result.length();
for ( i=0; i<length; i++ )
{
setList->add( result[i] );
}
// Extract each set as an MObject and add them to the
// sets array.
// We may be excluding groups, matierials, or ptGroups
// in which case we can ignore those sets.
//
MObject mset;
sets = new MObjectArray();
length = setList->length();
for ( i=0; i<length; i++ )
{
setList->getDependNode( i, mset );
MFnSet fnSet( mset, &stat );
if ( stat ) {
if ( MFnSet::kRenderableOnly == fnSet.restriction(&stat) ) {
sets->append( mset );
}
}
}
xr_delete(setList);
numSets = sets->length();
//////////////////////////////////////////////////////////////////
//
// Do a dag-iteration and for every mesh found, create facet and
// vertex look-up tables. These tables will keep track of which
// sets each component belongs to.
//
// If exportAll is false then iterate over the activeSelection
// list instead of the entire DAG.
//
// These arrays have a corrisponding entry in the name
// stringArray.
//
//////////////////////////////////////////////////////////////////
MIntArray vertexCounts;
MIntArray polygonCounts;
if ( exportAll ) {
MItDag dagIterator( MItDag::kBreadthFirst, MFn::kInvalid, &stat);
if ( MS::kSuccess != stat) {
fprintf(stderr,"Failure in DAG iterator setup.\n");
return false;
}
objectNames = new MStringArray();
for ( ; !dagIterator.isDone(); dagIterator.next() )
{
MDagPath dagPath;
//.........这里部分代码省略.........
示例7: doIt
//
// Main routine
///////////////////////////////////////////////////////////////////////////////
MStatus particleSystemInfoCmd::doIt( const MArgList& args )
{
MStatus stat = parseArgs( args );
if( stat != MS::kSuccess ) return stat;
if( particleNode.isNull() ) {
MObject parent;
MFnParticleSystem dummy;
particleNode = dummy.create(&stat);
CHECKRESULT(stat,"MFnParticleSystem::create(status) failed!");
MFnParticleSystem ps( particleNode, &stat );
CHECKRESULT(stat,"MFnParticleSystem::MFnParticleSystem(MObject,status) failed!");
MPointArray posArray;
posArray.append(MPoint(-5, 5, 0));
posArray.append(MPoint(-5, 10, 0));
MVectorArray velArray;
velArray.append(MPoint(1, 1, 0));
velArray.append(MPoint(1, 1, 0));
stat = ps.emit(posArray, velArray);
CHECKRESULT(stat,"MFnParticleSystem::emit(posArray,velArray) failed!");
stat = ps.emit(MPoint(5, 5, 0));
CHECKRESULT(stat,"MFnParticleSystem::emit(pos) failed!");
stat = ps.emit(MPoint(5, 10, 0));
CHECKRESULT(stat,"MFnParticleSystem::emit(pos) failed!");
stat = ps.saveInitialState();
CHECKRESULT(stat,"MFnParticleSystem::saveInitialState() failed!");
MVectorArray accArray;
accArray.setLength(4);
for( unsigned int i=0; i<accArray.length(); i++ )
{
MVector& acc = accArray[i];
acc.x = acc.y = acc.z = 3.0;
}
MString accName("acceleration");
ps.setPerParticleAttribute( accName, accArray, &stat );
CHECKRESULT(stat,"MFnParticleSystem::setPerParticleAttribute(vectorArray) failed!");
}
MFnParticleSystem ps( particleNode, &stat );
CHECKRESULT(stat,"MFnParticleSystem::MFnParticleSystem(MObject,status) failed!");
if( ! ps.isValid() )
{
MGlobal::displayError( "The function set is invalid!" );
return MS::kFailure;
}
const MString name = ps.particleName();
const MFnParticleSystem::RenderType psType = ps.renderType();
const unsigned int count = ps.count();
const char* typeString = NULL;
switch( psType )
{
case MFnParticleSystem::kCloud:
typeString = "Cloud";
break;
case MFnParticleSystem::kTube:
typeString = "Tube system";
break;
case MFnParticleSystem::kBlobby:
typeString = "Blobby";
break;
case MFnParticleSystem::kMultiPoint:
typeString = "MultiPoint";
break;
case MFnParticleSystem::kMultiStreak:
typeString = "MultiStreak";
break;
case MFnParticleSystem::kNumeric:
typeString = "Numeric";
break;
case MFnParticleSystem::kPoints:
typeString = "Points";
break;
case MFnParticleSystem::kSpheres:
typeString = "Spheres";
break;
case MFnParticleSystem::kSprites:
typeString = "Sprites";
break;
case MFnParticleSystem::kStreak:
typeString = "Streak";
break;
default:
typeString = "Particle system";
assert( false );
break;
}
char buffer[256];
//.........这里部分代码省略.........
示例8: extractFaces_Func
bool tm_polyExtract::extractFaces_Func( MSelectionList &selectionList, MStringArray &node_names)
{
MStatus status;
MObject meshObj;
status = selectionList.getDependNode( 0, meshObj);
if(!status){MGlobal::displayError("tm_polyExtract::extractFaces_Func: Can't find object !");return false;}
MFnMesh meshFn( meshObj, &status);
if(!status){MGlobal::displayError("tm_polyExtract::extractFaces_Func: Non mesh object founded !");return false;}
MDagPath meshDagPath_first, meshDagPath;
selectionList.getDagPath( 0, meshDagPath_first);
MObject multiFaceComponent;
MIntArray inputFacesArray;
inputFacesArray.clear();
inputFacesArray.setSizeIncrement( 4096);
MFnComponentListData compListFn;
compListFn.create();
for (MItSelectionList faceComponentIter(selectionList, MFn::kMeshPolygonComponent); !faceComponentIter.isDone(); faceComponentIter.next())
{
faceComponentIter.getDagPath(meshDagPath, multiFaceComponent);
if(!(meshDagPath_first == meshDagPath))
{
MGlobal::displayError("tm_polyExtract::extractFaces_Func: Different meshes faces founded !");
return false;
}
if (!multiFaceComponent.isNull())
{
for (MItMeshPolygon faceIter(meshDagPath, multiFaceComponent); !faceIter.isDone(); faceIter.next())
{
int faceIndex = faceIter.index();
#ifdef _DEBUG
infoMStr += faceIndex;
infoMStr += " ";
#endif
inputFacesArray.append( faceIndex);
compListFn.add( multiFaceComponent );
}
}
}
if( inputFacesArray.length() == 0)
{
MGlobal::displayError("tm_polyExtract::extractFaces_Func: No faces founded !");
return false;
}
#ifdef _DEBUG
MGlobal::displayInfo( infoMStr);
#endif
meshFn.setObject( meshDagPath_first);
meshObj = meshFn.object();
// MDagModifier dagModifier;
MFnDagNode meshDagNodeFn;
MFnDependencyNode depNodeFn;
meshDagNodeFn.setObject( meshDagPath_first);
MString meshName = meshDagNodeFn.name();
MObject outMesh_attrObject = meshDagNodeFn.attribute( "outMesh");
// ----------------------------------- duplicate shape
MObject duplicated_meshObjectA;
MObject duplicated_meshObjectB;
MObject inMesh_attrObjectA;
MObject inMesh_attrObjectB;
/*
MStringArray commandResult;
MSelectionList selList;
MGlobal::executeCommand( "duplicate " + meshDagNodeFn.name(), commandResult, 1, 1);
selList.add( commandResult[0]);
selList.getDependNode( 0, duplicated_meshObjectA);
meshDagNodeFn.setObject( duplicated_meshObjectA);
meshDagNodeFn.setName( meshName + "_tA");
duplicated_meshObjectA = meshDagNodeFn.child(0);
meshDagNodeFn.setObject( duplicated_meshObjectA);
meshDagNodeFn.setName( meshName + "_sA");
inMesh_attrObjectA = meshDagNodeFn.attribute( "inMesh");
meshDagNodeFn.setObject( meshDagPath_first);
selList.clear();
MGlobal::executeCommand( "duplicate " + meshDagNodeFn.name(), commandResult, 1, 1);
selList.add( commandResult[0]);
selList.getDependNode( 0, duplicated_meshObjectB);
meshDagNodeFn.setObject( duplicated_meshObjectB);
meshDagNodeFn.setName( meshName + "_tB");
duplicated_meshObjectB = meshDagNodeFn.child(0);
meshDagNodeFn.setObject( duplicated_meshObjectB);
meshDagNodeFn.setName( meshName + "_sB");
inMesh_attrObjectB = meshDagNodeFn.attribute( "inMesh");
*/
duplicated_meshObjectA = meshDagNodeFn.duplicate();
meshDagNodeFn.setObject( duplicated_meshObjectA);
meshDagNodeFn.setName( meshName + "_tA");
duplicated_meshObjectA = meshDagNodeFn.child(0);
meshDagNodeFn.setObject( duplicated_meshObjectA);
meshDagNodeFn.setName( meshName + "_sA");
inMesh_attrObjectA = meshDagNodeFn.attribute( "inMesh");
meshDagNodeFn.setObject( meshDagPath_first);
//.........这里部分代码省略.........
示例9: compute
MStatus testNpassiveNode::compute(const MPlug &plug, MDataBlock &data)
{
MStatus stat;
if ( plug == currentState )
{
// get old positions and numVerts
// if num verts is different, reset topo and zero velocity
// if num verts is the same, compute new velocity
int ii,jj;
// initialize MnCloth
MObject inMeshObj = data.inputValue(inputGeom).asMesh();
MFnMesh inputMesh(inMeshObj);
unsigned int numVerts = 0;
numVerts = inputMesh.numVertices();
unsigned int prevNumVerts;
fNObject.getNumVertices(prevNumVerts);
if(numVerts != prevNumVerts) {
int numPolygons = inputMesh.numPolygons();
int * faceVertCounts = new int[numPolygons];
int facesArrayLength = 0;
for(ii=0;ii<numPolygons;ii++) {
MIntArray verts;
inputMesh.getPolygonVertices(ii,verts);
faceVertCounts[ii] = verts.length();
facesArrayLength += verts.length();
}
int * faces = new int[facesArrayLength];
int currIndex = 0;
for(ii=0;ii<numPolygons;ii++) {
MIntArray verts;
inputMesh.getPolygonVertices(ii,verts);
for(jj=0;jj<(int)verts.length();jj++) {
faces[currIndex++] = verts[jj];
}
}
int numEdges = inputMesh.numEdges();
int * edges = new int[2*numEdges];
currIndex = 0;
for(ii=0;ii<numEdges;ii++) {
int2 edge;
inputMesh.getEdgeVertices(ii,edge);
edges[currIndex++] = edge[0];
edges[currIndex++] = edge[1];
}
// When you are doing the initialization, the first call must to be setTopology(). All other
// calls must come after this.
fNObject.setTopology(numPolygons, faceVertCounts, faces,numEdges, edges );
delete[] faceVertCounts;
delete[] faces;
delete[] edges;
MFloatPointArray vertexArray;
inputMesh.getPoints(vertexArray, MSpace::kWorld);
fNObject.setPositions(vertexArray,true);
MFloatPointArray velocitiesArray;
velocitiesArray.setLength(numVerts);
for(ii=0;ii<(int)numVerts;ii++) {
velocitiesArray[ii].x = 0.0f;
velocitiesArray[ii].y = 0.0f;
velocitiesArray[ii].z = 0.0f;
velocitiesArray[ii].w = 0.0f;
}
fNObject.setVelocities(velocitiesArray);
} else {
MFloatPointArray vertexArray;
MFloatPointArray prevVertexArray;
inputMesh.getPoints(vertexArray, MSpace::kWorld);
fNObject.getPositions(prevVertexArray);
// you may want to get the playback rate for the dt
// double dt = MAnimControl::playbackBy() \ 24.0;
// or get the real dt by caching the last eval time
double dt = 1.0/24.0;
MFloatPointArray velocitiesArray;
velocitiesArray.setLength(numVerts);
for(ii=0;ii<(int)numVerts;ii++) {
velocitiesArray[ii].x = (float)( (vertexArray[ii].x - prevVertexArray[ii].x)/dt);
velocitiesArray[ii].y = (float)( (vertexArray[ii].y - prevVertexArray[ii].y)/dt);
velocitiesArray[ii].z = (float)( (vertexArray[ii].x - prevVertexArray[ii].z)/dt);
velocitiesArray[ii].w = 0.0f;
}
fNObject.setVelocities(velocitiesArray);
fNObject.setPositions(vertexArray,true);
}
// in real life, you'd get these attribute values each frame and set them
fNObject.setThickness(0.1f);
fNObject.setBounce(0.0f);
fNObject.setFriction(0.1f);
fNObject.setCollisionFlags(true, true, true);
MFnNObjectData outputData;
MObject mayaNObjectData = outputData.create();
outputData.setObject(mayaNObjectData);
outputData.setObjectPtr(&fNObject);
outputData.setCached(false);
MDataHandle currStateOutputHandle = data.outputValue(currentState);
currStateOutputHandle.set(outputData.object());
}
//.........这里部分代码省略.........
示例10: fnRAttr
MStatus ColorSplineParameterHandler<S>::doSetValue( IECore::ConstParameterPtr parameter, MPlug &plug ) const
{
assert( parameter );
typename IECore::TypedParameter< S >::ConstPtr p = IECore::runTimeCast<const IECore::TypedParameter< S > >( parameter );
if( !p )
{
return MS::kFailure;
}
MRampAttribute fnRAttr( plug );
if ( !fnRAttr.isColorRamp() )
{
return MS::kFailure;
}
const S &spline = p->getTypedValue();
MStatus s;
MIntArray indicesToReuse;
plug.getExistingArrayAttributeIndices( indicesToReuse, &s );
assert( s );
int nextNewLogicalIndex = 0;
if( indicesToReuse.length() )
{
nextNewLogicalIndex = 1 + *std::max_element( MArrayIter<MIntArray>::begin( indicesToReuse ), MArrayIter<MIntArray>::end( indicesToReuse ) );
}
assert( indicesToReuse.length() == fnRAttr.getNumEntries() );
size_t pointsSizeMinus2 = spline.points.size() - 2;
unsigned pointIndex = 0;
unsigned numExpectedPoints = 0;
for ( typename S::PointContainer::const_iterator it = spline.points.begin(); it != spline.points.end(); ++it, ++pointIndex )
{
// we commonly double up the endpoints on cortex splines to force interpolation to the end.
// maya does this implicitly, so we skip duplicated endpoints when passing the splines into maya.
// this avoids users having to be responsible for managing the duplicates, and gives them some consistency
// with the splines they edit elsewhere in maya.
if( ( pointIndex==1 && *it == *spline.points.begin() ) || ( pointIndex==pointsSizeMinus2 && *it == *spline.points.rbegin() ) )
{
continue;
}
MPlug pointPlug;
if( indicesToReuse.length() )
{
pointPlug = plug.elementByLogicalIndex( indicesToReuse[0] );
indicesToReuse.remove( 0 );
}
else
{
pointPlug = plug.elementByLogicalIndex( nextNewLogicalIndex++ );
}
s = pointPlug.child( 0 ).setValue( it->first ); assert( s );
MPlug colorPlug = pointPlug.child( 1 );
colorPlug.child( 0 ).setValue( it->second[0] );
colorPlug.child( 1 ).setValue( it->second[1] );
colorPlug.child( 2 ).setValue( it->second[2] );
// hardcoding interpolation of 3 (spline) because the MRampAttribute::MInterpolation enum values don't actually
// correspond to the necessary plug values at all.
s = pointPlug.child( 2 ).setValue( 3 ); assert( s );
numExpectedPoints++;
}
// delete any of the original indices which we didn't reuse. we can't use MRampAttribute::deleteEntries
// here as it's utterly unreliable.
if( indicesToReuse.length() )
{
MString plugName = plug.name();
MObject node = plug.node();
MFnDagNode fnDAGN( node );
if( fnDAGN.hasObj( node ) )
{
plugName = fnDAGN.fullPathName() + "." + plug.partialName();
}
for( unsigned i=0; i<indicesToReuse.length(); i++ )
{
// using mel because there's no equivalant api method as far as i know.
MString command = "removeMultiInstance -b true \"" + plugName + "[" + indicesToReuse[i] + "]\"";
s = MGlobal::executeCommand( command );
assert( s );
if( !s )
{
return s;
}
}
}
#ifndef NDEBUG
{
assert( fnRAttr.getNumEntries() == numExpectedPoints );
MIntArray indices;
MFloatArray positions;
MColorArray colors;
MIntArray interps;
fnRAttr.getEntries( indices, positions, colors, interps, &s );
//.........这里部分代码省略.........
示例11: setEdgeVertexPositionListShear
//setEdgeVertexIndexListShear
//-----------------------------------------------
void TesselationVisualization::setEdgeVertexPositionListShear(MDataBlock &data)
{
//clear edgeVertexPositionList
drawData.edgeVertexPositionList.clear();
//inputGeo
MObject oInputGeo = data.inputValue(aInputGeo).asMesh();
//fnMeshInputGeo
MFnMesh fnMeshInputGeo(oInputGeo);
//vertexPositionList
MPointArray vertexPositionList;
fnMeshInputGeo.getPoints(vertexPositionList);
//itMeshPolyInputGeo
MItMeshPolygon itMeshPolyInputGeo(oInputGeo);
//for each poly
while(!itMeshPolyInputGeo.isDone())
{
//get edges
MIntArray edgeIndexList;
itMeshPolyInputGeo.getEdges(edgeIndexList);
//edgeVertexIndices
int2* edgeVertexIndices = new int2[4];
for(int index = 0; index < edgeIndexList.length(); index++)
{
fnMeshInputGeo.getEdgeVertices(edgeIndexList[index], edgeVertexIndices[index]);
};
//edgeVertexIndicesNoDuplicates
std::set<int> setEdgeVertexIndicesNoDuplicates;
for(int index = 0; index < edgeIndexList.length(); index++)
{
setEdgeVertexIndicesNoDuplicates.insert(edgeVertexIndices[index][0]);
setEdgeVertexIndicesNoDuplicates.insert(edgeVertexIndices[index][1]);
};
//vecEdgeVertexIndicesNoDuplicates
std::vector<int> vecEdgeVertexIndicesNoDuplicates(setEdgeVertexIndicesNoDuplicates.begin(), setEdgeVertexIndicesNoDuplicates.end());
//get faceVertexList
MPointArray faceVertexPointList = MPointArray(4);
for(int index = 0; index < edgeIndexList.length(); index++)
{
MPoint faceVertexPoint = vertexPositionList[vecEdgeVertexIndicesNoDuplicates[index]];
faceVertexPointList.set(faceVertexPoint, index);
};
//edge01
std::vector<float> edge01;
edge01.push_back(faceVertexPointList[0].x);edge01.push_back(faceVertexPointList[0].y);edge01.push_back(faceVertexPointList[0].z);
edge01.push_back(faceVertexPointList[1].x);edge01.push_back(faceVertexPointList[1].y);edge01.push_back(faceVertexPointList[1].z);
//edge13
std::vector<float> edge13;
edge13.push_back(faceVertexPointList[1].x);edge13.push_back(faceVertexPointList[1].y);edge13.push_back(faceVertexPointList[1].z);
edge13.push_back(faceVertexPointList[3].x);edge13.push_back(faceVertexPointList[3].y);edge13.push_back(faceVertexPointList[3].z);
//edge32
std::vector<float> edge32;
edge32.push_back(faceVertexPointList[3].x);edge32.push_back(faceVertexPointList[3].y);edge32.push_back(faceVertexPointList[3].z);
edge32.push_back(faceVertexPointList[2].x);edge32.push_back(faceVertexPointList[2].y);edge32.push_back(faceVertexPointList[2].z);
//edge20
std::vector<float> edge20;
edge20.push_back(faceVertexPointList[2].x);edge20.push_back(faceVertexPointList[2].y);edge20.push_back(faceVertexPointList[2].z);
edge20.push_back(faceVertexPointList[0].x);edge20.push_back(faceVertexPointList[0].y);edge20.push_back(faceVertexPointList[0].z);
//edge03
std::vector<float> edge03;
edge03.push_back(faceVertexPointList[0].x);edge03.push_back(faceVertexPointList[0].y);edge03.push_back(faceVertexPointList[0].z);
edge03.push_back(faceVertexPointList[3].x);edge03.push_back(faceVertexPointList[3].y);edge03.push_back(faceVertexPointList[3].z);
//edge12
std::vector<float> edge12;
edge12.push_back(faceVertexPointList[1].x);edge12.push_back(faceVertexPointList[1].y);edge12.push_back(faceVertexPointList[1].z);
edge12.push_back(faceVertexPointList[2].x);edge12.push_back(faceVertexPointList[2].y);edge12.push_back(faceVertexPointList[2].z);
//add to drawData.edgeVertexPositionList
drawData.edgeVertexPositionList.push_back(edge01);
drawData.edgeVertexPositionList.push_back(edge13);
drawData.edgeVertexPositionList.push_back(edge32);
drawData.edgeVertexPositionList.push_back(edge20);
drawData.edgeVertexPositionList.push_back(edge03);
drawData.edgeVertexPositionList.push_back(edge12);
//del edgeVertexIndices
delete [] edgeVertexIndices;
//.........这里部分代码省略.........
示例12: genRod
MStatus genRod(
const MPoint &p0,
const MPoint &p1,
const double radius,
const unsigned int nSegs,
int &nPolys,
MPointArray &verts,
MIntArray &polyCounts,
MIntArray &polyConnects
)
{
verts.clear();
polyCounts.clear();
polyConnects.clear();
unsigned int nCirclePts = nSegs;
unsigned int nVerts = 2 * nCirclePts;
// Calculate the local axiis of the rod
MVector vec( p1 - p0 );
MVector up( 0.0, 1.0, 0.0 );
MVector xAxis, yAxis, zAxis;
yAxis = vec.normal();
if( up.isParallel( yAxis, 0.1 ) )
up = MVector( 1.0, 0.0, 0.0 );
xAxis = yAxis ^ up;
zAxis = (xAxis ^ yAxis).normal();
xAxis = (yAxis ^ zAxis ).normal();
// Calculate the vertex positions
verts.setLength( nVerts );
double angleIncr = 2.0 * M_PI / nSegs;
double angle;
MPoint p;
double x, z;
unsigned int i;
for( i=0, angle=0; i < nCirclePts; i++, angle += angleIncr )
{
// Calculate position in circle
x = radius * cos( angle );
z = radius * sin( angle );
p = p0 + x * xAxis + z * zAxis;
verts[ i ] = p;
p += vec;
verts[ i + nCirclePts ] = p;
}
nPolys = nSegs;
// Generate polycounts
polyCounts.setLength( nPolys );
for( i=0; i < polyCounts.length(); i++ )
polyCounts[i] = 4;
// Generate polyconnects
polyConnects.setLength( nPolys * 4 );
polyConnects.clear();
for( i=0; i < nSegs; i++ )
{
polyConnects.append( linearIndex( 0, i, 2, nCirclePts ) );
polyConnects.append( linearIndex( 0, i+1, 2, nCirclePts ) );
polyConnects.append( linearIndex( 1, i+1, 2, nCirclePts ) );
polyConnects.append( linearIndex( 1, i, 2, nCirclePts ) );
}
return MS::kSuccess;
}
示例13: redoIt
MStatus skinClusterWeights::redoIt()
{
MStatus status;
unsigned int ptr = 0;
MSelectionList selList;
int geomLen = geometryArray.length();
fDagPathArray.setLength(geomLen);
fComponentArray.setLength(geomLen);
fInfluenceIndexArrayPtrArray = new MIntArray[geomLen];
fWeightsPtrArray = new MDoubleArray[geomLen];
for (int i = 0; i < geomLen; i++) {
MDagPath dagPath;
MObject component;
selList.clear();
selList.add(geometryArray[i]);
MStatus status = selList.getDagPath(0, dagPath, component);
if (status != MS::kSuccess) {
continue;
}
if (component.isNull()) dagPath.extendToShape();
MObject skinCluster = findSkinCluster(dagPath);
if (!isSkinClusterIncluded(skinCluster)) {
continue;
}
MFnSkinCluster skinClusterFn(skinCluster, &status);
if (status != MS::kSuccess) {
continue;
}
MIntArray influenceIndexArray;
populateInfluenceIndexArray(skinClusterFn, influenceIndexArray);
unsigned numInf = influenceIndexArray.length();
if (numInf == 0) continue;
unsigned numCV = 0;
if (dagPath.node().hasFn(MFn::kMesh)) {
MItMeshVertex polyIter(dagPath, component, &status);
if (status == MS::kSuccess) {
numCV = polyIter.count();
}
} else if (dagPath.node().hasFn(MFn::kNurbsSurface)) {
MItSurfaceCV nurbsIter(dagPath, component, true, &status);
if (status == MS::kSuccess) {
while (!nurbsIter.isDone()) {
numCV++;
nurbsIter.next();
}
}
} else if (dagPath.node().hasFn(MFn::kNurbsCurve)) {
MItCurveCV curveIter(dagPath, component, &status);
if (status == MS::kSuccess) {
while (!curveIter.isDone()) {
numCV++;
curveIter.next();
}
}
}
unsigned numEntry = numCV * numInf;
if (numEntry > 0) {
MDoubleArray weights(numEntry);
unsigned int numWeights = weightArray.length();
if (assignAllToSingle) {
if (numInf <= numWeights) {
for (unsigned j = 0; j < numEntry; j++) {
weights[j] = weightArray[j % numInf];
}
} else {
MGlobal::displayError("Not enough weights specified\n");
return MS::kFailure;
}
} else {
for (unsigned j = 0; j < numEntry; j++, ptr++) {
if (ptr < numWeights) {
weights[j] = weightArray[ptr];
} else {
MGlobal::displayError("Not enough weights specified\n");
return MS::kFailure;
}
}
}
// support for undo
fDagPathArray[i] = dagPath;
fComponentArray[i] = component;
fInfluenceIndexArrayPtrArray[i] = influenceIndexArray;
MDoubleArray oldWeights;
skinClusterFn.getWeights(dagPath, component, influenceIndexArray, oldWeights);
fWeightsPtrArray[i] = oldWeights;
skinClusterFn.setWeights(dagPath, component, influenceIndexArray, weights);
}
}
return MS::kSuccess;
//.........这里部分代码省略.........
示例14: save
void ExportACache::save(const char* filename, int frameNumber, char bfirst)
{
MStatus status;
FXMLScene xml_f;
xml_f.begin(filename, frameNumber, bfirst);
for(unsigned it=0; it<m_mesh_list.length(); it++) {
m_mesh_list[it].extendToShape();
MString surface = m_mesh_list[it].partialPathName();
AHelper::validateFilePath(surface);
MFnDependencyNode fnode(m_mesh_list[it].node());
MString smsg("prtMsg");
MStatus hasMsg;
MPlug pmsg = fnode.findPlug( smsg, 1, &hasMsg );
char bNoChange = 0;
if(hasMsg) {
MObject oattrib;
AHelper::getConnectedNode(oattrib, pmsg);
fnode.setObject(oattrib);
bool iattr = 0;
AHelper::getBoolAttributeByName(fnode, "noChange", iattr);
if(iattr) bNoChange = 1;
}
xml_f.meshBegin(surface.asChar(), bNoChange);
MFnMesh meshFn(m_mesh_list[it], &status );
MItMeshPolygon faceIter(m_mesh_list[it], MObject::kNullObj, &status );
MItMeshVertex vertIter(m_mesh_list[it], MObject::kNullObj, &status);
MItMeshEdge edgeIter(m_mesh_list[it], MObject::kNullObj, &status);
int n_tri = 0;
float f_area = 0;
double area;
faceIter.reset();
for( ; !faceIter.isDone(); faceIter.next() ) {
MIntArray vexlist;
faceIter.getVertices ( vexlist );
n_tri += vexlist.length() - 2;
faceIter.getArea( area, MSpace::kWorld );
f_area += (float)area;
}
xml_f.triangleInfo(n_tri, f_area);
float avg_grid = sqrt(f_area/n_tri)/2;
double light_intensity = 1.0;
if(hasMsg) {
MObject oattrib;
AHelper::getConnectedNode(oattrib, pmsg);
fnode.setObject(oattrib);
bool iattr = 0;
AHelper::getBoolAttributeByName(fnode, "noChange", iattr);
if(iattr) xml_f.addAttribute("noChange", 1);
AHelper::getBoolAttributeByName(fnode, "skipIndirect", iattr);
if(iattr) xml_f.addAttribute("skipIndirect", 1);
iattr = 0;
AHelper::getBoolAttributeByName(fnode, "skipScatter", iattr);
if(iattr) xml_f.addAttribute("skipScatter", 1);
iattr = 0;
AHelper::getBoolAttributeByName(fnode, "skipBackscatter", iattr);
if(iattr) xml_f.addAttribute("skipBackscatter", 1);
iattr = 0;
AHelper::getBoolAttributeByName(fnode, "asLightsource", iattr);
if(iattr) xml_f.addAttribute("asLightsource", 1);
iattr = 0;
AHelper::getBoolAttributeByName(fnode, "asGhost", iattr);
if(iattr) xml_f.addAttribute("invisible", 1);
iattr = 0;
AHelper::getBoolAttributeByName(fnode, "castNoShadow", iattr);
if(iattr) xml_f.addAttribute("noShadow", 1);
double td;
if(AHelper::getDoubleAttributeByName(fnode, "lightIntensity", td)) light_intensity = td;
fnode.setObject(m_mesh_list[it].node());
}
xml_f.staticBegin();
int n_poly = meshFn.numPolygons();
int n_vert = meshFn.numVertices();
int* polycount = new int[n_poly];
//.........这里部分代码省略.........
示例15: meshFn
// #### rebuildHbrMeshIfNeeded
//
// If the topology of the mesh changes, or any attributes that affect
// how the mesh is computed the original HBR needs to be rebuilt
// which will trigger a rebuild of the FAR mesh and subsequent buffers.
//
void
OsdMeshData::rebuildHbrMeshIfNeeded(OpenSubdivShader *shader)
{
MStatus status = MS::kSuccess;
if (!_meshTopoDirty && !shader->getHbrMeshDirty())
return;
MFnMesh meshFn(_meshDagPath);
// Cache attribute values
_level = shader->getLevel();
_kernel = shader->getKernel();
_adaptive = shader->isAdaptive();
_uvSet = shader->getUVSet();
// Get Maya vertex topology and crease data
MIntArray vertexCount;
MIntArray vertexList;
meshFn.getVertices(vertexCount, vertexList);
MUintArray edgeIds;
MDoubleArray edgeCreaseData;
meshFn.getCreaseEdges(edgeIds, edgeCreaseData);
MUintArray vtxIds;
MDoubleArray vtxCreaseData;
meshFn.getCreaseVertices(vtxIds, vtxCreaseData);
if (vertexCount.length() == 0) return;
// Copy Maya vectors into std::vectors
std::vector<int> numIndices(&vertexCount[0], &vertexCount[vertexCount.length()]);
std::vector<int> faceIndices(&vertexList[0], &vertexList[vertexList.length()]);
std::vector<int> vtxCreaseIndices(&vtxIds[0], &vtxIds[vtxIds.length()]);
std::vector<double> vtxCreases(&vtxCreaseData[0], &vtxCreaseData[vtxCreaseData.length()]);
std::vector<double> edgeCreases(&edgeCreaseData[0], &edgeCreaseData[edgeCreaseData.length()]);
// Edge crease index is stored as pairs of vertex ids
int nEdgeIds = edgeIds.length();
std::vector<int> edgeCreaseIndices;
edgeCreaseIndices.resize(nEdgeIds*2);
for (int i = 0; i < nEdgeIds; ++i) {
int2 vertices;
status = meshFn.getEdgeVertices(edgeIds[i], vertices);
if (status.error()) {
MERROR(status, "OpenSubdivShader: Can't get edge vertices");
continue;
}
edgeCreaseIndices[i*2] = vertices[0];
edgeCreaseIndices[i*2+1] = vertices[1];
}
// Convert attribute enums to HBR enums (this is why the enums need to match)
HbrMeshUtil::SchemeType hbrScheme = (HbrMeshUtil::SchemeType) shader->getScheme();
OsdHbrMesh::InterpolateBoundaryMethod hbrInterpBoundary =
(OsdHbrMesh::InterpolateBoundaryMethod) shader->getInterpolateBoundary();
OsdHbrMesh::InterpolateBoundaryMethod hbrInterpUVBoundary =
(OsdHbrMesh::InterpolateBoundaryMethod) shader->getInterpolateUVBoundary();
// clear any existing face-varying descriptor
if (_fvarDesc) {
delete _fvarDesc;
_fvarDesc = NULL;
}
// read UV data from maya and build per-face per-vert list of UVs for HBR face-varying data
std::vector< float > uvList;
status = buildUVList( meshFn, uvList );
if (! status.error()) {
// Create face-varying data descriptor. The memory required for indices
// and widths needs to stay alive as the HBR library only takes in the
// pointers and assumes the client will maintain the memory so keep _fvarDesc
// around as long as _hbrmesh is around.
int fvarIndices[] = { 0, 1 };
int fvarWidths[] = { 1, 1 };
_fvarDesc = new FVarDataDesc( 2, fvarIndices, fvarWidths, 2, hbrInterpUVBoundary );
}
if (_fvarDesc && hbrScheme != HbrMeshUtil::kCatmark) {
MGlobal::displayWarning("Face-varying not yet supported for Loop/Bilinear, using Catmull-Clark");
hbrScheme = HbrMeshUtil::kCatmark;
}
// Convert Maya mesh to internal HBR representation
_hbrmesh = ConvertToHBR(meshFn.numVertices(), numIndices, faceIndices,
vtxCreaseIndices, vtxCreases,
std::vector<int>(), std::vector<float>(),
edgeCreaseIndices, edgeCreases,
hbrInterpBoundary,
hbrScheme,
false, // no ptex
_fvarDesc,
//.........这里部分代码省略.........