本文整理汇总了C++中MIntArray::setLength方法的典型用法代码示例。如果您正苦于以下问题:C++ MIntArray::setLength方法的具体用法?C++ MIntArray::setLength怎么用?C++ MIntArray::setLength使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MIntArray
的用法示例。
在下文中一共展示了MIntArray::setLength方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: compute_halfedge_indices
MStatus compute_halfedge_indices(MIntArray &nFV, MIntArray &F, MIntArray &selV, MIntArray &selF, MIntArray &selHE)
{
MIntArray F2H(nFV.length(), 0);
size_t cumsum = 0;
for (size_t k=0; k<nFV.length(); k++)
{
F2H[k] = cumsum;
cumsum += nFV[k];
}
selHE.setLength(selF.length());
for (size_t k=0; k<selF.length(); k++)
{
size_t cV = selV[k];
size_t cF = selF[k];
size_t cnFV = nFV[cF];
size_t cF2H = F2H[cF];
for (size_t kFV=0; kFV<cnFV; kFV++)
{
if (F[cF2H+kFV]==cV)
{
selHE[k] = cF2H + kFV; break;
}
}
}
return MS::kSuccess;
}
示例2: getPolygonVertexCount
// ----------------------------------------
bool GeometryPolygonExporter::getPolygonVertexCount(
MItMeshPolygon &meshPolygonsIter,
unsigned long &numVertices )
{
bool addVertexCount = false;
// Establish the number of vertexes in the polygon.
// We don't need the vertex count list for triangulation
if ( triangulated ) return addVertexCount;
// The number of vertices
numVertices = 0;
// Retrieve the vertices and increment polygon count
// Get the number of vertices in the current mesh's polygon
unsigned long polygonVertexCount = meshPolygonsIter.polygonVertexCount();
if ( polygonVertexCount >= 3 )
{
#ifdef VALIDATE_DATA
// Skip over any duplicate vertices in this face.
// Very rarely, a cunning user manages to corrupt
// a face entry on the mesh and somehow configure
// a face to include the same vertex multiple times.
// This will cause the read-back of this data to
// reject the face, and can crash other COLLADA
// consumers, so better to lose the data here
MIntArray vertexIndices;
vertexIndices.setLength ( polygonVertexCount );
for ( int pv = 0; pv < polygonVertexCount; ++pv )
{
vertexIndices[pv] = pv;
}
for ( uint n = 0; n < vertexIndices.length() - 1; ++n )
{
for ( uint m = n + 1; m < vertexIndices.length(); )
{
if ( vertexIndices[n] == vertexIndices[m] )
{
vertexIndices.remove ( m );
}
else ++m;
}
}
// Get the number of vertices of the current polygon.
numVertices = vertexIndices.length();
#else
// Get the number of vertices of the current polygon.
numVertices = polygonVertexCount;
#endif
addVertexCount = true;
}
return addVertexCount;
}
示例3: load_from_hds
void load_from_hds(HDS &hds, MFloatPointArray &points, MIntArray &nFV, MIntArray &F)
{
size_t nV = hds.nV();
size_t nF = hds.nF();
size_t nIHE = hds.nIHE();
points.setLength(nV);
for (size_t k=0; k<nV; k++)
{
points[k](0) = hds.V[3*k+0];
points[k](1) = hds.V[3*k+1];
points[k](2) = hds.V[3*k+2];
}
nFV.setLength(nF);
for (size_t k=0; k<nF; k++) nFV[k] = hds.nFV[k];
F.setLength(nIHE);
for (size_t k=0; k<nIHE; k++) F[k] = hds.tip[k];
}
示例4: create_subdivided_face
void create_subdivided_face(int sdRes, int nV, double *uvs, double *itv, int Tidx, MFloatArray &uA, MFloatArray &vA, MIntArray &uvIdx)
{
HDS hds;
hds.V.setDims(2, nV); memcpy(&hds.V.v[0], uvs, 2*nV*sizeof(double));
hds.nFV.setDims(1, 1); hds.nFV[0] = nV;
hds.tip.setDims(1, nV);
for (size_t k=0; k<nV; k++)
{
hds.tip[k] = k;
}
finalize_HDS(hds);
size_t nHE = hds.nHE(), nIHE = hds.nIHE();⟵
hds.T.setDims(1, nHE);
hds.itv.setDims(1, nHE);
memset(&hds.T.v[0], 0, nHE*sizeof(bool)); if (nV==5) hds.T[Tidx] = 1;
memcpy(&hds.itv.v[0], itv, nV*sizeof(double));
// border halfedge tags
for (size_t k=nIHE; k<nHE; k++)
{
hds.itv[k] = hds.itv[hds.twin[k]];
}
TCC_MAX::linear_subdivide(hds, sdRes);
int sd_nV = hds.nV();
int sd_nIHE = hds.nIHE();
uA.setLength(sd_nV);
vA.setLength(sd_nV);
for (int k=0; k<sd_nV; k++)
{
uA[k] = hds.V[2*k+0];
vA[k] = hds.V[2*k+1];
}
uvIdx.setLength(sd_nIHE);
for (int k=0; k<sd_nIHE; k++)
{
uvIdx[k]=hds.tip[k];
}
}
示例5: compFn
// Propagate objectGroups from inMesh to subdivided outMesh
// Note: Currently only supporting facet groups (for per-facet shading)
MStatus
createSmoothMesh_objectGroups(const MFnMeshData &inMeshDat,
int subdivisionLevel, MFnMeshData &newMeshDat) {
MStatus returnStatus;
int facesPerBaseFace = (int)(pow(4.0f, subdivisionLevel));
MIntArray newCompElems;
for(unsigned int gi=0; gi < inMeshDat.objectGroupCount(); gi++) {
unsigned int compId = inMeshDat.objectGroup(gi, &returnStatus);
MCHECKERR(returnStatus, "cannot get objectGroup() comp ID.");
MFn::Type compType = inMeshDat.objectGroupType(compId, &returnStatus);
MCHECKERR(returnStatus, "cannot get objectGroupType().");
// get elements from inMesh objectGroupComponent
MIntArray compElems;
MFnSingleIndexedComponent compFn(inMeshDat.objectGroupComponent(compId), &returnStatus );
MCHECKERR(returnStatus, "cannot get MFnSingleIndexedComponent for inMeshDat.objectGroupComponent().");
compFn.getElements(compElems);
// Only supporting kMeshPolygonComponent ObjectGroups at this time
// Skip the other types
if (compType == MFn::kMeshPolygonComponent) {
// convert/populate newCompElems from compElems of inMesh
// (with new face indices) to outMesh
newCompElems.setLength( compElems.length() * facesPerBaseFace );
for (unsigned int i=0; i < compElems.length(); i++) {
int startElemIndex = i * facesPerBaseFace;
int startElemValue = compElems[i] * facesPerBaseFace;
for (int j=0; j < facesPerBaseFace; j++) {
newCompElems[startElemIndex+j] = startElemValue+j;
}
}
// create comp
createComp(newMeshDat, compType, compId, newCompElems);
}
}
return MS::kSuccess;
}
示例6: getShapeIntersectDist
double SGIntersectFunction::getShapeIntersectDist(const SGShape& targetShape, const MMatrix& shapeMatrix, const MMatrix& camMatrix)
{
MPoint mousePoint(SGMouse::x, SGMouse::y, 0);
MMatrix worldToView = SGMatrix::getWorldToViewMatrix(camMatrix);
MPointArray points; points.setLength(targetShape.numPoints);
for (int i = 0; i < targetShape.numPoints; i++) {
float x = targetShape.points[i * 3 + 0];
float y = targetShape.points[i * 3 + 1];
float z = targetShape.points[i * 3 + 2];
MPoint point(x, y, z);
points[i] = SGMatrix::getViewPointFromWorld(point * shapeMatrix, camMatrix, &worldToView );
}
MIntArray indices; indices.setLength(targetShape.numPoly * targetShape.interval);
for (int i = 0; i < targetShape.numPoly * targetShape.interval; i++){
indices[i] = targetShape.indices[i];
}
double closeDist = 10000000.0;
for (int i = 0; i < targetShape.numPoly; i++){
int index1 = indices[i*3];
int index2 = indices[i*3+1];
int index3 = indices[i*3+2];
double dist1 = SGMatrix::getLineDist(points[index1], points[index2], mousePoint);
double dist2 = SGMatrix::getLineDist(points[index2], points[index3], mousePoint);
double dist3 = SGMatrix::getLineDist(points[index3], points[index1], mousePoint);
if (dist1 < closeDist)
closeDist = dist1;
if (dist2 < closeDist)
closeDist = dist2;
if (dist3 < closeDist)
closeDist = dist3;
}
return closeDist;
}
示例7: CalculateSampleWeights
void CalculateSampleWeights(const std::map<int, double>& distances, double radius,
MIntArray& vertexIds, MDoubleArray& weights) {
std::map<int, double>::const_iterator itDistance;
std::vector<std::pair<int, double> > samples;
for (itDistance = distances.begin();
itDistance != distances.end();
itDistance++) {
double x = itDistance->second;
double w = 1.0 - (x/radius);
samples.push_back(std::pair<int, double>(itDistance->first, w));
}
// Make the samples a multiple of 4 so we can use fast intrinsics!
int remainder = 4 - ((samples.size()-1) % 4);
if (remainder != 4) {
for (int i = 0; i < remainder; ++i) {
samples.push_back(std::pair<int, double>(0, 0.0));
}
}
unsigned int length = (unsigned int)samples.size();
weights.setLength(length);
vertexIds.setLength(length);
std::sort(samples.begin(), samples.end(), SampleSort);
std::vector<std::pair<int, double> >::iterator iter;
int ii = 0;
double sum = 0.0;
for (iter = samples.begin(); iter != samples.end(); ++iter, ++ii) {
vertexIds[ii] = (*iter).first;
weights[ii] = (*iter).second;
sum += (*iter).second;
}
assert(sum > 0.0);
// Normalize the weights
for (unsigned int i = 0; i < weights.length(); ++i) {
weights[i] /= sum;
}
}
示例8: calculate
bool tm_polygon_edgestoring::calculate( MIntArray &edgesArray)
{
if(!objectIsSet)
{
MGlobal::displayError("tm_polygon_edgestoring::calculate - Object is not set.");
return false;
}
MFnMesh meshFn( meshObject);
MItMeshEdge edgeIt(meshObject);
MItMeshPolygon faceIt(meshObject);
unsigned numInputEdges = edgesArray.length();
int *visitedEdges = new int[numInputEdges];
for( unsigned e = 0; e < numInputEdges; e++) visitedEdges[e] = 0;
std::list <int> ringEdgesList;
int prevIndex;
MIntArray faces;
MIntArray edgeFaces;
MIntArray faceEdges;
int edgeIndex = edgesArray[0];
ringEdgesList.push_back( edgeIndex);
visitedEdges[0] = 1;
edgeIt.setIndex( edgeIndex, prevIndex);
edgeIt.getConnectedFaces( faces);
unsigned numFaces = faces.length();
unsigned numFaceEdges;
for( unsigned face = 0; face < numFaces; face++)
{
edgeIndex = edgesArray[0];
int lastFace, newFace;
if( face == 1) lastFace = faces[0];
else lastFace = -1;
unsigned COUNTER = 0;
while( COUNTER < 32000)
{
COUNTER++;
edgeIt.setIndex( edgeIndex, prevIndex);
edgeIt.getConnectedFaces( edgeFaces);
if(edgeFaces.length() > 1)
{
if( edgeFaces[0] == lastFace)
newFace = edgeFaces[1];
else
newFace = edgeFaces[0];
}
else
newFace = edgeFaces[0];
faceIt.setIndex( newFace, prevIndex);
lastFace = newFace;
bool founded = false;
for( unsigned e = 0; e < numInputEdges; e++)
{
if( edgesArray[e] == edgeIndex) continue;
if( visitedEdges[e] == 1) continue;
faceIt.getEdges( faceEdges);
numFaceEdges = faceEdges.length();
for( unsigned fe = 0; fe < numFaceEdges; fe++)
{
if( faceEdges[fe] == edgesArray[e])
{
founded = true;
edgeIndex = edgesArray[e];
visitedEdges[e] = 1;
if( face == 0)
ringEdgesList.push_front( edgeIndex);
else
ringEdgesList.push_back( edgeIndex);
}
if( founded) break;
}
if( founded) break;
}
if(!founded) break;
}
}
if (visitedEdges != NULL) delete [] visitedEdges;
unsigned numRingEdges = (unsigned)ringEdgesList.size();
edgesArray.setLength( numRingEdges);
for( unsigned e = 0; e < numRingEdges; e++)
{
edgesArray[e] = *ringEdgesList.begin();
ringEdgesList.pop_front();
}
return true;
}
示例9: addUVSet
void ToMayaMeshConverter::addUVSet( MFnMesh &fnMesh, const MIntArray &polygonCounts, IECore::ConstMeshPrimitivePtr mesh, const std::string &sPrimVarName, const std::string &tPrimVarName, const std::string &stIdPrimVarName, MString *uvSetName ) const
{
IECore::PrimitiveVariableMap::const_iterator sIt = mesh->variables.find( sPrimVarName );
bool haveS = sIt != mesh->variables.end();
IECore::PrimitiveVariableMap::const_iterator tIt = mesh->variables.find( tPrimVarName );
bool haveT = tIt != mesh->variables.end();
IECore::PrimitiveVariableMap::const_iterator stIdIt = mesh->variables.find( stIdPrimVarName );
bool haveSTId = stIdIt != mesh->variables.end();
if ( haveS && haveT )
{
if ( sIt->second.interpolation != IECore::PrimitiveVariable::FaceVarying )
{
IECore::msg( IECore::Msg::Warning,"ToMayaMeshConverter::doConversion", boost::format( "PrimitiveVariable \"%s\" has unsupported interpolation (expected FaceVarying).") % sPrimVarName );
return;
}
if ( tIt->second.interpolation != IECore::PrimitiveVariable::FaceVarying )
{
IECore::msg( IECore::Msg::Warning, "ToMayaMeshConverter::doConversion", boost::format( "PrimitiveVariable \"%s\" has unsupported interpolation (expected FaceVarying).") % tPrimVarName);
return;
}
if ( !sIt->second.data )
{
IECore::msg( IECore::Msg::Warning, "ToMayaMeshConverter::doConversion", boost::format( "PrimitiveVariable \"%s\" has no data." ) % sPrimVarName );
}
if ( !tIt->second.data )
{
IECore::msg( IECore::Msg::Warning, "ToMayaMeshConverter::doConversion", boost::format( "PrimitiveVariable \"%s\" has no data." ) % tPrimVarName );
}
/// \todo Employ some M*Array converters to simplify this
int numUVs = mesh->variableSize( IECore::PrimitiveVariable::FaceVarying );
IECore::ConstFloatVectorDataPtr u = IECore::runTimeCast<const IECore::FloatVectorData>(sIt->second.data);
if ( !u )
{
IECore::msg( IECore::Msg::Warning, "ToMayaMeshConverter::doConversion", boost::format( "PrimitiveVariable \"%s\" has unsupported type \"%s\"." ) % sPrimVarName % sIt->second.data->typeName() );
return;
}
assert( (int)u->readable().size() == numUVs );
IECore::ConstFloatVectorDataPtr v = IECore::runTimeCast<const IECore::FloatVectorData>(tIt->second.data);
if ( !v )
{
IECore::msg( IECore::Msg::Warning, "ToMayaMeshConverter::doConversion", boost::format( "PrimitiveVariable \"%s\" has unsupported type \"%s\"." ) % tPrimVarName % tIt->second.data->typeName() );
return;
}
assert( (int)v->readable().size() == numUVs );
const std::vector<float> &uAll = u->readable();
const std::vector<float> &vAll = v->readable();
if ( uvSetName )
{
bool setExists = false;
MStringArray existingSets;
fnMesh.getUVSetNames( existingSets );
for ( unsigned i=0; i < existingSets.length(); ++i )
{
if ( *uvSetName == existingSets[i] )
{
fnMesh.clearUVs( uvSetName );
setExists = true;
break;
}
}
if ( !setExists )
{
MDagPath dag;
MStatus s = fnMesh.getPath( dag );
if ( s )
{
fnMesh.createUVSetWithName( *uvSetName );
}
else
{
fnMesh.createUVSetDataMeshWithName( *uvSetName );
}
}
}
MIntArray uvIds;
uvIds.setLength( numUVs );
MFloatArray uArray;
MFloatArray vArray;
if( haveSTId )
{
// Get compressed uv values by matching them with their uvId.
IECore::ConstIntVectorDataPtr uvId = IECore::runTimeCast<const IECore::IntVectorData>(stIdIt->second.data);
if ( !uvId )
{
IECore::msg( IECore::Msg::Warning, "ToMayaMeshConverter::doConversion", boost::format( "PrimitiveVariable \"%s\" has unsupported type \"%s\"." ) % stIdPrimVarName % stIdIt->second.data->typeName() );
//.........这里部分代码省略.........
示例10: doConversion
bool ToMayaMeshConverter::doConversion( IECore::ConstObjectPtr from, MObject &to, IECore::ConstCompoundObjectPtr operands ) const
{
MStatus s;
IECore::ConstMeshPrimitivePtr mesh = IECore::runTimeCast<const IECore::MeshPrimitive>( from );
assert( mesh );
if ( !mesh->arePrimitiveVariablesValid() )
{
return false;
}
MFloatPointArray vertexArray;
MIntArray polygonCounts;
MIntArray polygonConnects;
MFnMesh fnMesh;
int numVertices = 0;
IECore::PrimitiveVariableMap::const_iterator it = mesh->variables.find("P");
if ( it != mesh->variables.end() )
{
/// \todo Employ some M*Array converters to simplify this
IECore::ConstV3fVectorDataPtr p = IECore::runTimeCast<const IECore::V3fVectorData>(it->second.data);
if (p)
{
numVertices = p->readable().size();
vertexArray.setLength( numVertices );
for (int i = 0; i < numVertices; i++)
{
vertexArray[i] = IECore::convert<MFloatPoint, Imath::V3f>( p->readable()[i] );
}
}
else
{
IECore::ConstV3dVectorDataPtr p = IECore::runTimeCast<const IECore::V3dVectorData>(it->second.data);
if (p)
{
numVertices = p->readable().size();
vertexArray.setLength( numVertices );
for (int i = 0; i < numVertices; i++)
{
vertexArray[i] = IECore::convert<MFloatPoint, Imath::V3d>( p->readable()[i] );
}
}
else
{
// "P" is not convertible to an array of "points"
return false;
}
}
}
IECore::ConstIntVectorDataPtr verticesPerFace = mesh->verticesPerFace();
assert( verticesPerFace );
int numPolygons = verticesPerFace->readable().size();
polygonCounts.setLength( numPolygons );
for (int i = 0; i < numPolygons; i++)
{
polygonCounts[i] = verticesPerFace->readable()[i];
}
IECore::ConstIntVectorDataPtr vertexIds = mesh->vertexIds();
assert( vertexIds );
int numPolygonConnects = vertexIds->readable().size();
polygonConnects.setLength( numPolygonConnects );
for (int i = 0; i < numPolygonConnects; i++)
{
polygonConnects[i] = vertexIds->readable()[i];
}
MObject mObj = fnMesh.create( numVertices, numPolygons, vertexArray, polygonCounts, polygonConnects, to, &s );
if (!s)
{
return false;
}
it = mesh->variables.find("N");
if ( it != mesh->variables.end() )
{
if (it->second.interpolation == IECore::PrimitiveVariable::FaceVarying )
{
/// \todo Employ some M*Array converters to simplify this
MVectorArray vertexNormalsArray;
IECore::ConstV3fVectorDataPtr n = IECore::runTimeCast<const IECore::V3fVectorData>(it->second.data);
if (n)
{
int numVertexNormals = n->readable().size();
vertexNormalsArray.setLength( numVertexNormals );
for (int i = 0; i < numVertexNormals; i++)
{
vertexNormalsArray[i] = IECore::convert<MVector, Imath::V3f>( n->readable()[i] );
}
}
//.........这里部分代码省略.........
示例11: writeMeshStaticDataInCache
bool writeMeshStaticDataInCache(drn_writer_t * cache,
DRNTDagNode & node,
drn_scene::MeshContainer * meshContainer,
DRNTHardEdge & he, MeshExportMode mode)
{
uint32_t drnStatus = 0;
MStatus status;
MFnMesh mesh(node.dagPath);
if (mode == MESH_EXPORT_FULL_TOPOLOGY)
{
meshContainer->numPolygons = mesh.numPolygons(&status);
meshContainer->numVertices = mesh.numVertices(&status);
meshContainer->numNormals = mesh.numNormals(&status);
}
else
{
meshContainer->numPolygons = 0;
meshContainer->numVertices = 0;
meshContainer->numNormals = 0;
}
MIntArray vertexCount;
MIntArray vertexList;
MIntArray normalCount;
MIntArray normalList;
MIntArray uvCounts;
MIntArray uvIds;
mesh.getAssignedUVs(uvCounts, uvIds);
MIntArray triangleCount;
MIntArray triangleList;
MIntArray triangleNList;
MIntArray triangleUVList;
mesh.getVertices(vertexCount, vertexList);
mesh.getNormalIds(normalCount, normalList);
mesh.getTriangles(triangleCount, triangleList);
triangleNList.setLength(triangleList.length());
triangleUVList.setLength(triangleList.length());
meshContainer->numTriangles = triangleList.length() / 3;
int * vcarray = new int[vertexCount.length()];
int * vlarray = new int[vertexList.length()];
int * ncarray = new int[normalCount.length()];
int * nlarray = new int[normalList.length()];
// Triangulation
int poly_idx_offset = 0;
int tri_idx_offset = 0;
for (int i = 0; i < mesh.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)
mesh.getPolygonUVid(i, match, id);
triangleUVList[tri_idx_offset+j*3 + k] = id;
}
}
poly_idx_offset += vertexCount[i];
tri_idx_offset += 3 * triangleCount[i];
}
he.tlist.resize(triangleList.length(), -1);
//he.itlist.resize(triangleList.length());
he.itlist.resize(triangleList.length());
//std::map<std::pair<int, int>, int> h;
std::map<triplet, int> h;
int idx = 0;
for (int i = 0, n = triangleList.length(); i != n; ++i)
{
//std::pair<int, int> p = std::make_pair(triangleList[i], triangleNList[i]);
triplet p(triangleList[i], triangleNList[i], triangleUVList[i]);
//std::map<std::pair<int, int>, int>::const_iterator match = h.find(p);
std::map<triplet, int>::const_iterator match = h.find(p);
if (match != h.end())
{
he.tlist[i] = match->second;
he.itlist[i] = match->first;
}
else
{
h[p] = idx;
he.tlist[i] = idx;
he.itlist[i] = p;
++idx;
}
}
meshContainer->numHwVertices = he.idmax = idx;
if (mode == MESH_EXPORT_FULL_TOPOLOGY)
{
vertexCount.get(vcarray);
//.........这里部分代码省略.........
示例12: compFn
// Propagate objectGroups from inMesh to subdivided outMesh
// Note: Currently only supporting facet groups (for per-facet shading)
MStatus
createSmoothMesh_objectGroups( MFnMesh const & inMeshFn,
MFnMeshData const & inMeshDat, MFnMeshData &newMeshDat, int level, int numSubfaces ) {
MStatus status;
MIntArray newCompElems;
std::vector<unsigned int> offsets; // mapping of offsets for subdivided faces
for(unsigned int gi=0; gi<inMeshDat.objectGroupCount(); gi++) {
unsigned int compId = inMeshDat.objectGroup(gi, &status);
MCHECKERR(status, "cannot get objectGroup() comp ID.");
MFn::Type compType = inMeshDat.objectGroupType(compId, &status);
MCHECKERR(status, "cannot get objectGroupType().");
// Only supporting kMeshPolygonComponent ObjectGroups at this time
// Skip the other types
if (compType == MFn::kMeshPolygonComponent) {
// get elements from inMesh objectGroupComponent
MIntArray compElems;
MFnSingleIndexedComponent compFn(
inMeshDat.objectGroupComponent(compId), &status );
MCHECKERR(status, "cannot get MFnSingleIndexedComponent for inMeshDat.objectGroupComponent().");
compFn.getElements(compElems);
if (compElems.length()==0) {
continue;
}
// over-allocation to maximum possible length
newCompElems.setLength( numSubfaces );
if (offsets.empty()) {
// lazy population of the subface offsets table
int nfaces = inMeshFn.numPolygons();
offsets.resize(nfaces);
for (int i=0, count=0; i<nfaces; ++i) {
int nverts = inMeshFn.polygonVertexCount(i),
nsubfaces = computeNumSubfaces(nverts, level);
offsets[i] = count;
count+=nsubfaces;
}
}
unsigned int idx = 0;
// convert/populate newCompElems from compElems of inMesh
// (with new face indices) to outMesh
for (unsigned int i=0; i < compElems.length(); i++) {
int nverts = inMeshFn.polygonVertexCount(compElems[i]),
nsubfaces = computeNumSubfaces(nverts, level);
unsigned int subFaceOffset = offsets[compElems[i]];
for (int j=0; j<nsubfaces; ++j) {
newCompElems[idx++] = subFaceOffset++;
}
}
// resize to actual length
newCompElems.setLength( idx );
// create comp
createComp(newMeshDat, compType, compId, newCompElems);
}
}
return MS::kSuccess;
}
示例13:
//--------------------------------------------------------------------------------------
void componentConverter::vtxToConnectedFaceVtx(const MIntArray& vtxIDs,
MIntArray& outVtxIDs)
//--------------------------------------------------------------------------------------
{
// Wandelt die vtxSelection in die connecteten faceVtx um (die Vertizen der verbundenen Faces)
// Die gegebenen Vtx werden nicht mit hinzugefuegt
outVtxIDs.setLength(0);
outVtxIDs.setSizeIncrement(vtxIDs.length() / 4);
MItMeshVertex vertIter(mesh);
MItMeshPolygon polyIter(mesh);
BPT_BA allFaces(polyIter.count(), true);
BPT_BA allVtx(vertIter.count(), true); // BA mit den vtxIDs initialisieren
// Die vtxIds bereits jetzt false setzen
allVtx.setBits(vtxIDs, false);
MIntArray conFaces; // hlt die verbundenen Faces
MIntArray conVtx; // Im face enthaltene Vtx
uint i, x, y , l2,l3, l = vtxIDs.length();
for(i = 0; i < l; i++)
{
vertIter .setIndex(vtxIDs[i], tmp);
vertIter.getConnectedFaces(conFaces);
// Jetzt die gueltigen conFaces holen
conFaces = allFaces & conFaces;
// Jetzt die conFaces false setzen, danit diese nicht wieder bearbeitet werden
allFaces.setBits(conFaces, false);
l2 = conFaces.length();
// jetzt die restlichen Faces on the fly in Vtx umwandeln
for(x = 0; x < l2; x++)
{
// Jetzt die vertizen des Faces holen und auf Array packen, wenn sie einzigartig sind
polyIter.setIndex(conFaces[x], tmp);
polyIter.getVertices(conVtx);
// Checken, ob Vtx einzigartig sind
conVtx = allVtx & conVtx;
// Das was uebrig bleibt im BitArray deaktivieren und zum outArray hinzufuegen
allVtx.setBits(conVtx, false);
l3 = conVtx.length();
for(y = 0; y < l3; y++)
{
outVtxIDs.append(conVtx[y]);
}
}
}
}
示例14: 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;
}
示例15: getTweakedUVs
//
// Change the UVS for the given selection on this mesh object.
//
///////////////////////////////////////////////////////////////////////////////
MStatus flipUVCmd::getTweakedUVs(
const MObject & meshObj, // Object
MIntArray & uvList, // UVs to move
MFloatArray & uPos, // Moved UVs
MFloatArray & vPos ) // Moved UVs
{
MStatus status;
unsigned int i;
MFloatArray uArray;
MFloatArray vArray;
MFnMesh mesh( meshObj );
// Read all UVs from the poly object
status = mesh.getUVs(uArray, vArray);
CHECK_MSTATUS_AND_RETURN_IT(status);
unsigned int nbUvShells = 1;
MIntArray uvShellIds;
if ((!flipGlobal) || extendToShell)
{
// First, extract the UV shells.
status = mesh.getUvShellsIds(uvShellIds, nbUvShells);
CHECK_MSTATUS_AND_RETURN_IT(status);
}
if (extendToShell)
{
// Find all shells that have at least a selected UV.
bool *selected = new bool[nbUvShells];
for (i = 0 ; i<nbUvShells ; i++)
selected[i] = false;
for (i = 0 ; i<uvList.length() ; i++)
{
int indx = uvList[i];
selected[uvShellIds[indx]] = true;
}
// Now recompute a new list of UVs to modify.
unsigned int numUvs = mesh.numUVs();
unsigned int numSelUvs = 0;
// Preallocate a buffer, large enough to hold all Ids. This
// prevents multiple reallocation from happening when growing
// the array.
uvList.setLength(numUvs);
for (i = 0 ; i<numUvs ; i++)
{
if (selected[uvShellIds[i]])
uvList[numSelUvs++] = i;
}
// clamp the array to the proper size.
uvList.setLength(numSelUvs);
delete [] selected;
}
// For global flips, just pretend there is only one shell
if (flipGlobal) nbUvShells = 1;
float *minMax = new float[nbUvShells*4];
for (i = 0 ; i<nbUvShells ; i++)
{
minMax[4*i+0] = 1e30F; // Min U
minMax[4*i+1] = 1e30F; // Min V
minMax[4*i+2] = -1e30F; // Max U
minMax[4*i+3] = -1e30F; // Max V
}
// Get the bounding box of the UVs, for each shell if flipGlobal
// is true, or for the whole selection if false.
for (i = 0 ; i<uvList.length() ; i++)
{
int indx = uvList[i];
int shellId = 0;
if (!flipGlobal) shellId = uvShellIds[indx];
if (uArray[indx] < minMax[4*shellId+0])
minMax[4*shellId+0] = uArray[indx];
if (vArray[indx] < minMax[4*shellId+1])
minMax[4*shellId+1] = vArray[indx];
if (uArray[indx] > minMax[4*shellId+2])
minMax[4*shellId+2] = uArray[indx];
if (vArray[indx] > minMax[4*shellId+3])
minMax[4*shellId+3] = vArray[indx];
}
// Adjust the size of the output arrays
uPos.setLength(uvList.length());
vPos.setLength(uvList.length());
//.........这里部分代码省略.........