本文整理汇总了C++中MFnMesh类的典型用法代码示例。如果您正苦于以下问题:C++ MFnMesh类的具体用法?C++ MFnMesh怎么用?C++ MFnMesh使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了MFnMesh类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: findEdgeInfo
void CXRayObjectExport:: CreateSMGEdgeAttrs ( MFnMesh& fnMesh )
{
int numPolygons = fnMesh.numPolygons();
for ( int pid=0; pid<numPolygons; pid++ )
{
MIntArray vertexList;
fnMesh.getPolygonVertices( pid, vertexList );
int vcount = vertexList.length();
if(vcount!=3)
Msg( "poly vertex count not equel 3(is not a tri) vertex count = %d", vcount );
for ( int vid=0; vid<vcount;vid++ )
{
int a = vertexList[vid];
int b = vertexList[ vid==(vcount-1) ? 0 : vid+1 ];
SXREdgeInfoPtr elem = findEdgeInfo( a, b );
if ( NULL != elem )
{
set_edge_smooth_flag( polySmoothingGroups[pid], vid, elem->smooth );
}
}
}
}
示例2: p1p
MObject MG_poseReader::makePlane(const MVector& p1,const MVector& p2,const MVector& p3){
MFnMesh meshFn;
MPoint p1p (p1);
MPoint p2p (p2);
MPoint p3p (p3);
MPointArray pArray;
pArray.append(p1p);
pArray.append(p2p);
pArray.append(p3p);
MIntArray polyCount;
polyCount.append(3);
MIntArray polyConnect;
polyConnect.append(0);
polyConnect.append(1);
polyConnect.append(2);
MFnMeshData data;
MObject polyData = data.create();
MStatus stat;
meshFn.create(3,1,pArray,polyCount,polyConnect,polyData,&stat);
return polyData;
}
示例3: dagPath
// grab the current mesh and setup the polygon sets
void Mesh::SetMesh(const MDagPath &dPath) {
MObjectArray fPolygonSets;
MObjectArray fPolygonComponents;
MDagPath dagPath(dPath);
polySets.clear();
MFnMesh fMesh = MFnMesh(dagPath);
//Have to make the path include the shape below it so that
//we can determine if the underlying shape node is instanced.
//By default, dag paths only include transform nodes.
dagPath.extendToShape();
//If the shape is instanced then we need to determine which instance this path refers to.
int instanceNum = 0;
if (dagPath.isInstanced())
instanceNum = dagPath.instanceNumber();
//Get the connected sets and members - these will be used to determine texturing of different faces
if (!fMesh.getConnectedSetsAndMembers(instanceNum, fPolygonSets, fPolygonComponents, true)) {
MGlobal::displayError("MFnMesh::getConnectedSetsAndMembers");
return;
}
unsigned int setCount = fPolygonSets.length();
if (setCount > 1)
setCount--;
for (unsigned int i=0; i < setCount; i++)
polySets.push_back(PolygonSet(dagPath, fPolygonComponents[i], fPolygonSets[i]));
}
示例4: createHelperMesh
void SoftBodyNode::createHelperMesh(MFnMesh &mayaMesh, std::vector<int> &triIndices, std::vector<float> &triVertices, MSpace::Space space)
{
MFloatPointArray ptArray;
mayaMesh.getPoints(ptArray, space);
// append vertex locations (x, y, z) into "flattened array"
for(int i = 0; i < ptArray.length(); i++)
{
MFloatPoint pt;
pt = ptArray[i];
pt.cartesianize();
triVertices.push_back(pt.x);
triVertices.push_back(pt.y);
triVertices.push_back(pt.z);
}
std::cout << std::endl;
// create vector of triangle indices
MIntArray tCounts;
MIntArray tVerts;
mayaMesh.getTriangles(tCounts, tVerts);
triIndices.resize(tVerts.length());
for(int i = 0; i < tVerts.length(); i ++)
{
triIndices[i] = tVerts[i];
}
}
示例5: getCreaseEdges
// Reference: OSD shape_utils.h:: applyTags() "crease"
static float
getCreaseEdges(MFnMesh const & inMeshFn, Descriptor & outDesc) {
MUintArray tEdgeIds;
MDoubleArray tCreaseData;
float maxCreaseValue = 0.0f;
if (inMeshFn.getCreaseEdges(tEdgeIds, tCreaseData)) {
assert( tEdgeIds.length() == tCreaseData.length() );
int ncreases = tEdgeIds.length();
int * vertPairs = new int[ncreases*2];
float * weights = new float[ncreases];
int2 edgeVerts;
for (unsigned int j=0; j < tEdgeIds.length(); j++) {
assert( tCreaseData[j] >= 0.0 );
inMeshFn.getEdgeVertices(tEdgeIds[j], edgeVerts);
vertPairs[j*2 ] = edgeVerts[0];
vertPairs[j*2+1] = edgeVerts[1];
weights[j] = float(tCreaseData[j]);
maxCreaseValue = std::max(float(tCreaseData[j]), maxCreaseValue);
}
outDesc.numCreases = ncreases;
outDesc.creaseVertexIndexPairs = vertPairs;
outDesc.creaseWeights = weights;
}
return maxCreaseValue;
}
示例6: M3dView
void SGToolContext::toolOnSetup(MEvent& evt)
{
MStatus status;
SGPermit permit;
SGKey::initializeKeys();
SGMouse::initializeButtons();
SGMesh::getSelection(SGToolCondition::option.symInfo);
SGSelection::sels.initialize(SGMesh::pMesh);
M3dView activeView = M3dView().active3dView();
manip = (SGManip*)SGManip::newManipulator(Names::manipName, m_oManip);
if (!manip) sgPrintf("manip is null");
this->addManipulator(m_oManip);
toolWidget = new SGWidget(MQtUtil::mainWindow());
toolWidget->startEvent();
this->setCursor( MCursor::editCursor );
if ( SGMesh::pMesh->dagPath.node().isNull() ) {
//MGlobal::displayWarning("Select mesh first");
}
else {
MFnMesh fnMesh = SGMesh::pMesh->dagPath;
MFnDagNode dagNode = fnMesh.parent(0);
char buffer[128];
sprintf(buffer, "maintainActiveChangeSelectMode %s", dagNode.partialPathName().asChar() );
MGlobal::executeCommand(buffer);
}
SGMarkingMenu::menu.setDefaultMenu();
SGToolCondition::toolIsOn = true;
}
示例7: Triangulation
int Triangulation(
MFnMesh &mfnMesh,
MIntArray &triangleCount, MIntArray &triangleList, MIntArray &triangleNList, MIntArray &triangleUVList,
MIntArray &vertexCount, MIntArray &vertexList, MIntArray &normalList, MIntArray &uvIds)
{
int poly_idx_offset = 0;
int tri_idx_offset = 0;
for (int i = 0; i < mfnMesh.numPolygons(); ++i)
{
for (int j = 0; j < triangleCount[i]; ++j)
{
for (unsigned int k = 0; k < 3; ++k)
{
int v_idx = triangleList[tri_idx_offset + j * 3 + k];
int match = -1;
int l = 0;
while (match < 0 && l < vertexCount[i])
{
if (vertexList[poly_idx_offset + l] == v_idx)
match = l;
++l;
}
triangleNList[tri_idx_offset + j * 3 + k] = normalList[poly_idx_offset + match];
int id = 0;
if (uvIds.length() != 0)
mfnMesh.getPolygonUVid(i, match, id);
triangleUVList[tri_idx_offset + j * 3 + k] = id;
}
}
poly_idx_offset += vertexCount[i];
tri_idx_offset += 3 * triangleCount[i];
}
return tri_idx_offset;
}
示例8: createMesh
MObject animCube::createMesh(const MTime& time,
MObject& outData,
MStatus& stat)
{
int numVertices, frame;
float cubeSize;
MFloatPointArray points;
MFnMesh meshFS;
// Scale the cube on the frame number, wrap every 10 frames.
frame = (int)time.as( MTime::kFilm );
if (frame == 0)
frame = 1;
cubeSize = 0.5f * (float)( frame % 10);
const int numFaces = 6;
numVertices = 8;
const int numFaceConnects = 24;
MFloatPoint vtx_1( -cubeSize, -cubeSize, -cubeSize );
MFloatPoint vtx_2( cubeSize, -cubeSize, -cubeSize );
MFloatPoint vtx_3( cubeSize, -cubeSize, cubeSize );
MFloatPoint vtx_4( -cubeSize, -cubeSize, cubeSize );
MFloatPoint vtx_5( -cubeSize, cubeSize, -cubeSize );
MFloatPoint vtx_6( -cubeSize, cubeSize, cubeSize );
MFloatPoint vtx_7( cubeSize, cubeSize, cubeSize );
MFloatPoint vtx_8( cubeSize, cubeSize, -cubeSize );
points.append( vtx_1 );
points.append( vtx_2 );
points.append( vtx_3 );
points.append( vtx_4 );
points.append( vtx_5 );
points.append( vtx_6 );
points.append( vtx_7 );
points.append( vtx_8 );
// Set up an array containing the number of vertices
// for each of the 6 cube faces (4 verticies per face)
//
int face_counts[numFaces] = { 4, 4, 4, 4, 4, 4 };
MIntArray faceCounts( face_counts, numFaces );
// Set up and array to assign vertices from points to each face
//
int face_connects[ numFaceConnects ] = { 0, 1, 2, 3,
4, 5, 6, 7,
3, 2, 6, 5,
0, 3, 5, 4,
0, 4, 7, 1,
1, 7, 6, 2 };
MIntArray faceConnects( face_connects, numFaceConnects );
MObject newMesh = meshFS.create(numVertices, numFaces,
points, faceCounts, faceConnects,
outData, &stat);
return newMesh;
}
示例9: exportPolygonSources
// --------------------------------------------------------
void GeometryPolygonExporter::exportPolygonSources (
MFnMesh& fnMesh,
const String& meshId,
MStringArray& uvSetNames,
MStringArray& colorSetNames,
Sources* polygonSources,
Sources* vertexSources,
const bool hasFaceVertexNorms )
{
// Initialize the members
mMeshId = meshId;
mUvSetNames = uvSetNames;
mPolygonSources = polygonSources;
mVertexSources = vertexSources;
mHasFaceVertexNormals = hasFaceVertexNorms;
mColorSetNames = colorSetNames;
// If triangulation is requested, verify that it is
// feasible by checking with all the mesh polygons
if ( ExportOptions::exportTriangles() )
{
triangulated = true;
for ( MItMeshPolygon polyIt ( fnMesh.object() ); triangulated && !polyIt.isDone(); polyIt.next() )
{
triangulated = polyIt.hasValidTriangulation();
}
}
// If we have a hole in a polygon, we can't write a <polylist>.
// Either we write <polygons> with holes or we write triangles.
// Get hole information from the mesh node.
// The format for the holes information is explained in the MFnMesh documentation.
MStatus status;
fnMesh.getHoles ( mHoleInfoArray, mHoleVertexArray, &status );
holeCount = ( status != MStatus::kSuccess ) ? 0 : ( mHoleInfoArray.length() / 3 );
// Find how many shaders are used by this instance of the mesh.
// Each instance may apply a number of different materials to different faces.
// We can use the getConnectedShaders member function of MFnMesh to find out
// this shader information for each instance.
mShaders.clear();
mShaderIndices.clear();
fnMesh.getConnectedShaders ( 0, mShaders, mShaderIndices );
// Find the polygons that correspond to each materials and export them.
uint realShaderCount = ( uint ) mShaders.length();
uint numShaders = ( uint ) std::max ( ( size_t ) 1, ( size_t ) mShaders.length() );
for ( uint shaderPosition=0; shaderPosition<numShaders; ++shaderPosition )
{
// Set the current shader position
mShaderPosition = shaderPosition;
// Export the polygons of the current shader
exportShaderPolygons ( fnMesh );
}
}
示例10: polyIt
// #### buildUVList
//
// Face-varying data expects a list of per-face per-vertex
// floats. This method reads the UVs from the mesh and
// concatenates them into such a list.
//
MStatus
OsdMeshData::buildUVList( MFnMesh& meshFn, std::vector<float>& uvList )
{
MStatus status = MS::kSuccess;
MItMeshPolygon polyIt( _meshDagPath );
MFloatArray uArray;
MFloatArray vArray;
// If user hasn't given us a UV set, use the current one
MString *uvSetPtr=NULL;
if ( _uvSet.numChars() > 0 ) {
if (uvSetNameIsValid(meshFn, _uvSet)) {
uvSetPtr = &_uvSet;
}
else {
MGlobal::displayWarning(MString("OpenSubdivShader: uvSet \""+_uvSet+"\" does not exist."));
}
} else {
uvSetPtr = NULL;
}
// pull UVs from Maya mesh
status = meshFn.getUVs( uArray, vArray, uvSetPtr );
MCHECK_RETURN(status, "OpenSubdivShader: Error reading UVs");
if ( uArray.length() == 0 || vArray.length() == 0 )
{
MGlobal::displayWarning("OpenSubdivShader: Mesh has no UVs");
return MS::kFailure;
}
// list of UV values
uvList.clear();
uvList.resize( meshFn.numFaceVertices()*2 );
int uvListIdx = 0;
// for each face-vertex copy UVs into list, adjusting for renderman orientation
for ( polyIt.reset(); !polyIt.isDone(); polyIt.next() )
{
int faceIdx = polyIt.index();
unsigned int numPolyVerts = polyIt.polygonVertexCount();
for ( unsigned int faceVertIdx = 0;
faceVertIdx < numPolyVerts;
faceVertIdx++ )
{
int uvIdx;
polyIt.getUVIndex( faceVertIdx, uvIdx, uvSetPtr );
// convert maya UV orientation to renderman orientation
uvList[ uvListIdx++ ] = uArray[ uvIdx ];
uvList[ uvListIdx++ ] = 1.0f - vArray[ uvIdx ];
}
}
return status;
}
示例11: m3dFloatViewProjection
MStatus PluginTestUserOperation::execute(const MHWRender::MDrawContext & drawContext)
{
//return MStatus::kSuccess;
M3dView view;
if(M3dView::getM3dViewFromModelPanel(panelName, view) == MStatus::kSuccess)
{
// Get the current viewport and scale it relative to that
//
int targetW, targetH;
drawContext.getRenderTargetSize(targetW, targetH);
// Some user drawing of scene bounding boxes
//
MDagPath cameraPath;
MFnCamera fnCamera;
view.getCamera(cameraPath);
MMatrix m3dViewProjection, m3dViewModelView;
view.projectionMatrix(m3dViewProjection);
view.modelViewMatrix(m3dViewModelView);
MFloatMatrix m3dFloatViewProjection(m3dViewProjection.matrix);
MFloatMatrix m3dFloatViewModelView(m3dViewModelView.matrix);
MFloatMatrix viewProjection = m3dFloatViewModelView * m3dFloatViewProjection;
SurfaceDrawTraversal traversal;
traversal.enableFiltering(true);
traversal.setFrustum(cameraPath, targetW, targetH);
traversal.traverse();
unsigned int numItems = traversal.numberOfItems();
MFnMesh fnMesh;
for (int i = 0; i < numItems; i++)
{
MDagPath path;
traversal.itemPath(i, path);
if (path.hasFn(MFn::kMesh))
{
fnMesh.setObject(path);
MFloatMatrix modelWorld(path.inclusiveMatrix().matrix);
MTransformationMatrix transformMatrix;
MFloatMatrix modelViewProjection = modelWorld * viewProjection;
modelViewProjection = modelViewProjection.transpose();
MIntArray triangleCounts;
MIntArray triangleVertices; // This is the index list for all the triangles in the mesh in one big list. Ie. first 3 are for tri 1 etc. Index into getPoints()
fnMesh.getTriangles(triangleCounts, triangleVertices);
//int indices[100];
//triangleVertices.get(indices);
MFloatPointArray vertexArray;
//float points[1000][4];
fnMesh.getPoints(vertexArray);
//vertexArray.get(points);
UserSceneRenderer::get()->render(triangleVertices, vertexArray, modelViewProjection);
}
}
}
return MStatus::kSuccess;
}
示例12: point
MStatus LSSolverNode::buildOutputMesh(MFnMesh& inputMesh, float* vertices, MObject &outputMesh)
{
MStatus stat;
MPointArray points;
unsigned vIndex = 0;
int numVertices = inputMesh.numVertices();
for(int i=0; i<numVertices;i++)
{
double x = vertices[vIndex++];
double y = vertices[vIndex++];
double z = vertices[vIndex++];
//std::cout<<"("<<x<<","<<y<<","<<z<<")"<<endl;
MPoint point(x,y,z);
points.append(point);
}
const int numFaces = inputMesh.numPolygons();
int *face_counts = new int[numFaces];
for(int i = 0 ; i < numFaces ; i++)
{
face_counts[i] = 3;
}
MIntArray faceCounts( face_counts, numFaces );
// Set up and array to assign vertices from points to each face
int numFaceConnects = numFaces * 3;
int *face_connects = new int[numFaceConnects];
int faceConnectsIdx = 0;
for ( int i=0; i<numFaces; i++ )
{
MIntArray polyVerts;
inputMesh.getPolygonVertices( i, polyVerts );
int pvc = polyVerts.length();
face_connects[faceConnectsIdx++] = polyVerts[0];
face_connects[faceConnectsIdx++]= polyVerts[1];
face_connects[faceConnectsIdx++] = polyVerts[2];
}
MIntArray faceConnects( face_connects, numFaceConnects );
MFnMesh meshFS;
MObject newMesh = meshFS.create(numVertices, numFaces,
points, faceCounts, faceConnects,
outputMesh, &stat);
return stat;
}
示例13: readFrame
MObject AniMesh::readFrame(const MTime& time,MObject& outData,MStatus& stat)
{
MFloatPointArray points;
MFnMesh meshFS;
int frame = (int)time.as( MTime::kFilm );
if (frame == 0)
frame = 1;
vector<size_t> face_v;
vector<double> points_v;
char cfilename[256];
sprintf(cfilename, "%s%d.vrml",import_prefix.c_str(),frame);
//sprintf(cfilename, "%s%d.vrml",import_prefix.c_str(),0);
string filename = string(cfilename);
fstream fp;
fp.open(filename,ios::in);
if (fp)
{
ImportVrml2 (filename, face_v, points_v);
}else{
sprintf(cfilename, "%s%d.vrml",import_prefix.c_str(),0);
string filename = string(cfilename);
ImportVrml2(filename,face_v,points_v);
}
size_t numVertices = points_v.size()/3;
size_t numFaces = face_v.size()/3;
for(vector<double>::const_iterator it = points_v.begin();it != points_v.end();it+=3) {
MFloatPoint vtx(*it,*(it+1),*(it+2));
points.append(vtx);
}
vector<int> face_count;
for(int i=0;i<numFaces;i++) {
face_count.push_back(3);
}
MIntArray faceCounts(&face_count[0],numFaces);
vector<int> face_connects;
face_connects.resize(face_v.size());
for(int i=0;i<face_v.size();++i)
{
face_connects[i] = face_v[i];
}
MIntArray faceConnects( &face_connects[0], face_connects.size() );
MObject newMesh=meshFS.create(numVertices, numFaces,points, faceCounts, faceConnects,outData,&stat);
return newMesh;
}
示例14: normals
IECoreScene::PrimitiveVariable FromMayaMeshConverter::normals() const
{
MFnMesh fnMesh;
const MDagPath *d = dagPath( true );
if( d )
{
fnMesh.setObject( *d );
}
else
{
fnMesh.setObject( object() );
}
V3fVectorDataPtr normalsData = new V3fVectorData;
normalsData->setInterpretation( GeometricData::Normal );
vector<V3f> &normals = normalsData->writable();
normals.reserve( fnMesh.numFaceVertices() );
int numPolygons = fnMesh.numPolygons();
V3f blankVector;
if( space() == MSpace::kObject )
{
const float* rawNormals = fnMesh.getRawNormals(0);
MIntArray normalIds;
for( int i=0; i<numPolygons; i++ )
{
fnMesh.getFaceNormalIds( i, normalIds );
for( unsigned j=0; j < normalIds.length(); ++j )
{
const float* normalIt = rawNormals + 3 * normalIds[j];
normals.push_back( blankVector );
V3f& nn = normals.back();
nn.x = *normalIt++;
nn.y = *normalIt++;
nn.z = *normalIt;
}
}
}
else
{
MFloatVectorArray faceNormals;
for( int i=0; i<numPolygons; i++ )
{
fnMesh.getFaceVertexNormals( i, faceNormals, space() );
for( unsigned j=0; j<faceNormals.length(); j++ )
{
MFloatVector& n = faceNormals[j];
normals.push_back( blankVector );
V3f& nn = normals.back();
nn.x = n.x;
nn.y = n.y;
nn.z = n.z;
}
}
}
return PrimitiveVariable( PrimitiveVariable::FaceVarying, normalsData );
}
示例15: setErrorColors
MStatus TCC::setErrorColors(MFnMesh &meshFn, TCCData &tccData)
{
MStatus stat;
if ((tccData.err.length()>0) && (tccData.err.length()==tccData.nFV.length()))
{
for (size_t k=0; k<tccData.err.length(); k++)
{
int err = tccData.err[k];
if (err>0)
{
MColor col(1.0, 1.0, 1.0);
switch(err)
{
case 1: col = MColor(1.0, 0.0, 0.0); break; // bad topology / inconsistent eqc
case 2: col = MColor(1.0, 0.0, 1.0); break; // mismatched itv
case 3: col = MColor(0.0, 0.0, 1.0); break; // unassigned itvs
case 4: col = MColor(0.5, 0.5, 1.0); break; // unassigned T-joint
default: break;
}
stat = meshFn.setFaceColor(col, k);
if (stat!=MS::kSuccess)
{
char bla[] = "bla";
stat.perror(bla);
}
}
}
}
return stat;
}