bool HesperisCurveCreator::CreateACurve(Vector3F * pos, unsigned nv, MObject &target) { MPointArray vertexArray; unsigned i=0; for(; i<nv; i++) vertexArray.append( MPoint( pos[i].x, pos[i].y, pos[i].z ) ); const int degree = 2; const int spans = nv - degree; const int nknots = spans + 2 * degree - 1; MDoubleArray knotSequences; knotSequences.append(0.0); for(i = 0; i < nknots-2; i++) knotSequences.append( (double)i ); knotSequences.append(nknots-3); MFnNurbsCurve curveFn; MStatus stat; curveFn.create(vertexArray, knotSequences, degree, MFnNurbsCurve::kOpen, false, false, target, &stat ); return stat == MS::kSuccess; }
void CBPoseSpaceCmd::saveVertexPosition(MObject& poseMesh) { MStatus status; MFnMesh poseFn(poseMesh, &status); MPointArray poseVertex; poseFn.getPoints ( poseVertex, MSpace::kObject ); unsigned numVert = poseVertex.length(); float* data = new float[numVert * 3]; for(unsigned i=0; i < numVert; i++) { data[i*3] = poseVertex[i].x; data[i*3+1] = poseVertex[i].y; data[i*3+2] = poseVertex[i].z; } io::filtering_ostream out; out.push(boost::iostreams::gzip_compressor()); MString filename = _cacheName + ".pose"; out.push(io::file_sink(filename.asChar(), ios::binary)); out.write((char*)data, numVert *3 * 4); out.flush(); delete[] data; MGlobal::displayInfo(MString("corrective blendshape write sculpt pose to ") + filename); }
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; }
void AlembicCurveAccumulator::save(const MObject &ref, double time) { MFnNurbsCurve node(ref); Abc::M44f globalXfo = GetGlobalMatrix(ref); if (!this->useGlobalCache) { Abc::M44f::multiply(globalXfo, this->mInverse, globalXfo); } MPointArray positions; node.getCVs(positions); int offset = (int)mPosVec.size(); const int posLen = positions.length(); mPosVec.resize(offset + posLen); for (unsigned int i = 0; i < (unsigned int)posLen; ++i, ++offset) { const MPoint &outPos = positions[i]; Imath::V3f &inPos = mPosVec[offset]; inPos.x = (float)outPos.x; inPos.y = (float)outPos.y; inPos.z = (float)outPos.z; globalXfo.multVecMatrix(inPos, inPos); bbox.extendBy(inPos); } if (firstSample) { this->mNbVertices.push_back(posLen); } }
void BasicLocator::draw( M3dView & view, const MDagPath & path, M3dView::DisplayStyle style, M3dView::DisplayStatus status ) { view.beginGL(); glPushAttrib( GL_CURRENT_BIT ); MPointArray pts; getCirclePoints( pts ); glBegin(GL_LINE_STRIP); for( unsigned int i=0; i < pts.length(); i++ ) glVertex3f( float(pts[i].x), float(pts[i].y), float(pts[i].z) ); glEnd(); glBegin(GL_LINES); glVertex3f( -0.5f, 0.0f, 0.0f ); glVertex3f( 0.5f, 0.0f, 0.0f ); glVertex3f( 0.0f, 0.0f, -0.5f ); glVertex3f( 0.0f, 0.0f, 0.5f ); glEnd(); glPopAttrib(); view.endGL(); }
bool ProxyViz::loadInternal(MDataBlock& block) { MDataHandle tmH = block.inputValue(aplantTransformCache); MFnPointArrayData tmFn(tmH.data()); MPointArray plantTms = tmFn.array(); if(plantTms.length() < 1) return false; MDataHandle idH = block.inputValue(aplantIdCache); MFnIntArrayData idFn(idH.data()); MIntArray plantIds = idFn.array(); if(plantIds.length() < 1) return false; MDataHandle triH = block.inputValue(aplantTriangleIdCache); MFnIntArrayData triFn(triH.data()); MIntArray plantTris = triFn.array(); if(plantTris.length() < 1) return false; MDataHandle crdH = block.inputValue(aplantTriangleCoordCache); MFnVectorArrayData crdFn(crdH.data()); MVectorArray plantCoords = crdFn.array(); if(plantCoords.length() < 1) return false; MDataHandle cotH = block.inputValue(aplantOffsetCache); MFnVectorArrayData cotFn(cotH.data()); MVectorArray plantOffsets = cotFn.array(); return loadPlants(plantTms, plantIds, plantTris, plantCoords, plantOffsets); }
MStatus ffdPlanar::getBoundingBox( MDataBlock& block, unsigned int multiIndex, MBoundingBox &boundingBoxOut ) { MStatus status = MS::kSuccess; MArrayDataHandle inputHandle = block.outputArrayValue( input ); inputHandle.jumpToElement( multiIndex ); MObject mesh = inputHandle.outputValue().child( inputGeom ).asMesh(); MBoundingBox boundingBox = MBoundingBox(); MFnMesh meshFn( mesh, &status ); MCheckErr( status, "Error getting mesh from mesh object\n" ); MPointArray pointArray = MPointArray(); meshFn.getPoints( pointArray, MSpace::kTransform ); for ( int i = 0; i < pointArray.length(); i++ ) { boundingBox.expand( pointArray[i] ); } boundingBoxOut = boundingBox; return status; }
MStatus makeSurf() { cout << ">>>> Start creation of test surface <<<<" << endl; // Set up knots // MDoubleArray knotArray; int i; // Add extra starting knots so that the first CV matches the curve start point // knotArray.append( 0.0 ); knotArray.append( 0.0 ); for ( i = 0; i <= NUM_SPANS; i++ ) { knotArray.append( (double)i ); } // Add extra ending knots so that the last CV matches the curve end point // knotArray.append( (double)i ); knotArray.append( (double)i ); // Now, Set up CVs // MPointArray cvArray; // We need a 2D array of CVs with NUM_SPANS + 3 CVs on a side // int last = NUM_SPANS + 3; for ( i = 0; i < last; i++ ) { for ( int j = 0; j < last; j++ ) { MPoint cv; cv.x = (((double)(j))/((double)(NUM_SPANS + 3)) * WIDTH) - (WIDTH/2.0); cv.z = (((double)(i))/((double)(NUM_SPANS + 3)) * WIDTH) - (WIDTH/2.0); double dist = sqrt( cv.x*cv.x + cv.z*cv.z ); cv.y = cos( dist ) * VERTICAL_SCALING; cvArray.append( cv ); } } // Create the surface // MFnNurbsSurface mfnNurbsSurf; MStatus stat; mfnNurbsSurf.create( cvArray, knotArray, knotArray, 3, 3, MFnNurbsSurface::kOpen, MFnNurbsSurface::kOpen, true, MObject::kNullObj, &stat ); if ( stat ) { cout << ">>>> Test Surface Creation Successfull <<<<\n"; } else { stat.perror("MFnNurbsSurface::create"); cout << ">>>> Test Surface Creation Failed <<<<\n"; } return stat; }
void ovalLocatorDrawOverride::draw (const MHWRender::MDrawContext &context, const MUserData *data) { MPointArray vertices =ovalLocator::vertices () ; // get cached data float color [3] ={ 0.0f, 1.0f, 0.0f } ; float multiplier =1.0f ; const ovalLocatorData *ovalData =dynamic_cast<const ovalLocatorData *>(data) ; if ( ovalData ) multiplier =ovalData->multiplier ; // get state data MStatus status ; const MMatrix transform =context.getMatrix (MHWRender::MDrawContext::kWorldViewMtx, &status) ; if ( status !=MStatus::kSuccess ) return ; const MMatrix projection =context.getMatrix (MHWRender::MDrawContext::kProjectionMtx, &status) ; if ( status !=MStatus::kSuccess ) return ; const int displayStyle =context.getDisplayStyle () ; // get renderer MHWRender::MRenderer *theRenderer =MHWRender::MRenderer::theRenderer () ; if ( !theRenderer ) return ; // GL Draw if ( theRenderer->drawAPIIsOpenGL () ) { // set colour glColor3fv (color) ; // set world matrix glMatrixMode (GL_MODELVIEW) ; glPushMatrix () ; glLoadMatrixd (transform.matrix [0]) ; // set projection matrix glMatrixMode (GL_PROJECTION) ; glPushMatrix () ; glLoadMatrixd (projection.matrix [0]) ; if ( displayStyle & MHWRender::MDrawContext::kGouraudShaded ) { // See myShadedDraw glPushAttrib (GL_CURRENT_BIT) ; glBegin (GL_TRIANGLE_FAN) ; glVertex3f (0, 0, 0) ; for ( int i =0 ; i < vertices.length () ; ++i ) glVertex3f (vertices [i].x * multiplier, vertices [i].y * multiplier, vertices [i].z * multiplier) ; glEnd () ; glPopAttrib () ; } if ( displayStyle & MHWRender::MDrawContext::kWireFrame ) { // See myWireFrameDraw glBegin (GL_LINES) ; for ( int i =0 ; i < vertices.length () - 1 ; ++i ) { glVertex3f (vertices [i].x * multiplier, vertices [i].y * multiplier, vertices [i].z * multiplier) ; glVertex3f (vertices [i + 1].x * multiplier, vertices [i + 1].y * multiplier, vertices [i + 1].z * multiplier) ; } glEnd () ; } glPopMatrix () ; glMatrixMode (GL_MODELVIEW) ; glPopMatrix () ; } }
MStatus helix::doIt( const MArgList& args ) { MStatus stat; const unsigned deg = 3; // Curve Degree const unsigned ncvs = 20; // Number of CVs const unsigned spans = ncvs - deg; // Number of spans const unsigned nknots = spans+2*deg-1;// Number of knots double radius = 4.0; // Helix radius double pitch = 0.5; // Helix pitch unsigned i; // Parse the arguments. for ( i = 0; i < args.length(); i++ ) if ( MString( "-p" ) == args.asString( i, &stat ) && MS::kSuccess == stat) { double tmp = args.asDouble( ++i, &stat ); if ( MS::kSuccess == stat ) pitch = tmp; } else if ( MString( "-r" ) == args.asString( i, &stat ) && MS::kSuccess == stat) { double tmp = args.asDouble( ++i, &stat ); if ( MS::kSuccess == stat ) radius = tmp; } MPointArray controlVertices; MDoubleArray knotSequences; // Set up cvs and knots for the helix // for (i = 0; i < ncvs; i++) controlVertices.append( MPoint( radius * cos( (double)i ), pitch * (double)i, radius * sin( (double)i ) ) ); for (i = 0; i < nknots; i++) knotSequences.append( (double)i ); // Now create the curve // MFnNurbsCurve curveFn; curveFn.create( controlVertices, knotSequences, deg, MFnNurbsCurve::kOpen, false, false, MObject::kNullObj, &stat ); if ( MS::kSuccess != stat ) cout<<"Error creating curve."<<endl; return stat; }
// Draw visible items void MVGManipulator::drawVisibleItems(M3dView& view) const { MPointArray visiblesItemsPositions; for(std::vector<MVGPointCloudItem>::const_iterator itemIt = _visiblePointCloudItems.begin(); itemIt != _visiblePointCloudItems.end(); ++itemIt) visiblesItemsPositions.append(MVGGeometryUtil::worldToViewSpace(view, itemIt->_position)); MColor red(1.0, 0.0, 0.0); MVGDrawUtil::drawPoints2D(visiblesItemsPositions, red, 2.f); }
foundation::auto_release_ptr<renderer::MeshObject> createMesh(const MObject& mobject) { MStatus stat = MStatus::kSuccess; MFnMesh meshFn(mobject, &stat); CHECK_MSTATUS(stat); MPointArray points; MFloatVectorArray normals; MFloatArray uArray, vArray; MIntArray triPointIds, triNormalIds, triUvIds, triMatIds, perFaceAssignments; getMeshData(mobject, points, normals, uArray, vArray, triPointIds, triNormalIds, triUvIds, triMatIds, perFaceAssignments); foundation::auto_release_ptr<renderer::MeshObject> mesh( renderer::MeshObjectFactory::create( makeGoodString(meshFn.fullPathName()).asChar(), renderer::ParamArray())); for (unsigned int i = 0; i < points.length(); i++) mesh->push_vertex(mPointToGVector3(points[i])); for (unsigned int i = 0; i < normals.length(); i++) mesh->push_vertex_normal(mPointToGVector3(normals[i])); for (unsigned int i = 0; i < uArray.length(); i++) { mesh->push_tex_coords( renderer::GVector2( static_cast<float>(uArray[i]), static_cast<float>(vArray[i]))); } const unsigned int numTris = triPointIds.length() / 3; for (unsigned int i = 0; i < numTris; i++) { const int perFaceShadingGroup = triMatIds[i]; const int vtxId0 = triPointIds[i * 3 + 0]; const int vtxId1 = triPointIds[i * 3 + 1]; const int vtxId2 = triPointIds[i * 3 + 2]; const int normalId0 = triNormalIds[i * 3 + 0]; const int normalId1 = triNormalIds[i * 3 + 1]; const int normalId2 = triNormalIds[i * 3 + 2]; const int uvId0 = triUvIds[i * 3 + 0]; const int uvId1 = triUvIds[i * 3 + 1]; const int uvId2 = triUvIds[i * 3 + 2]; mesh->push_triangle( renderer::Triangle( vtxId0, vtxId1, vtxId2, normalId0, normalId1, normalId2, uvId0, uvId1, uvId2, perFaceShadingGroup)); } return mesh; }
void ovalLocator::myShadedDraw () { MPlug plug (thisMObject (), ovalLocator::size) ; float multiplier =plug.asFloat () ; MPointArray vertices =ovalLocator::vertices () ; glBegin (GL_TRIANGLE_FAN) ; glVertex3f (0, 0, 0) ; for ( int i =0 ; i < vertices.length () ; i++ ) glVertex3f (vertices [i].x * multiplier, vertices [i].y * multiplier, vertices [i].z * multiplier) ; glEnd () ; }
MStatus MG_curve::compute(const MPlug& plug,MDataBlock& dataBlock) { if (plug==output) { //MStatus MStatus stat; //Point array for the curve MPointArray pointArray ; //Get data from inputs MDataHandle degreeH = dataBlock.inputValue(degree); int degreeValue = degreeH.asInt(); MDataHandle tmH = dataBlock.inputValue(transformMatrix); MMatrix tm = tmH.asMatrix(); MArrayDataHandle inputMatrixH = dataBlock.inputArrayValue(inputMatrix); inputMatrixH.jumpToArrayElement(0); //Loop to get matrix data and convert in points for (int unsigned i=0;i<inputMatrixH.elementCount();i++,inputMatrixH.next()) { MMatrix currentMatrix = inputMatrixH.inputValue(&stat).asMatrix() ; //Compensate the locator matrix MMatrix fixedMatrix = currentMatrix*tm.inverse(); MPoint matrixP (fixedMatrix[3][0],fixedMatrix[3][1],fixedMatrix[3][2]); pointArray.append(matrixP); } MFnNurbsCurve curveFn; MFnNurbsCurveData curveDataFn; MObject curveData= curveDataFn.create(); curveFn.createWithEditPoints(pointArray,degreeValue,MFnNurbsCurve::kOpen,0,0,0,curveData,&stat); MDataHandle outputH = dataBlock.outputValue(output); outputH.set(curveData); outputH.setClean(); } return MS::kSuccess; }
void ovalLocator::myWireFrameDraw () { MPlug plug (thisMObject (), ovalLocator::size) ; float multiplier =plug.asFloat () ; MPointArray vertices =ovalLocator::vertices () ; glBegin (GL_LINES) ; for ( int i =0 ; i < vertices.length () - 1 ; i++ ) { glVertex3f (vertices [i].x * multiplier, vertices [i].y * multiplier, vertices [i].z * multiplier) ; glVertex3f (vertices [i + 1].x * multiplier, vertices [i + 1].y * multiplier, vertices [i + 1].z * multiplier) ; } glEnd () ; }
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; }
bool BasicLocator::getCirclePoints( MPointArray &pts ) const { MStatus stat; MObject thisNode = thisMObject(); MFnDagNode dagFn( thisNode ); MPlug xWidthPlug = dagFn.findPlug( xWidth, &stat ); float xWidthValue; xWidthPlug.getValue( xWidthValue ); MPlug zWidthPlug = dagFn.findPlug( zWidth, &stat ); float zWidthValue; zWidthPlug.getValue( zWidthValue ); MPlug typePlug = dagFn.findPlug( dispType, &stat ); short typeValue; typePlug.getValue( typeValue ); unsigned int nCirclePts; switch( typeValue ) { case 0: nCirclePts = 4; break; case 1: nCirclePts = 5; break; default: nCirclePts = 20; break; } pts.clear(); pts.setSizeIncrement( nCirclePts ); MPoint pt; pt.y = 0.0; const double angleIncr = M_2PI / (nCirclePts - 1); double angle = 0.0; unsigned int i=0; for( ; i < nCirclePts; i++, angle+=angleIncr ) { pt.x = xWidthValue * cos( angle ); pt.z = zWidthValue * sin( angle ); pts.append( pt ); } return true; }
MBoundingBox BasicLocator::boundingBox() const // // N.B. It is important to have this bounding box function otherwise zoom selected and // zoom all won't work correctly. // { MPointArray pts; getCirclePoints( pts ); MBoundingBox bbox; for( unsigned int i=0; i < pts.length(); i++ ) bbox.expand( pts[i] ); return bbox; }
void cubeLocator::myShadedDraw () { MPlug plug (thisMObject (), cubeLocator::size) ; float multiplier =plug.asFloat () ; MPointArray vertices =cubeLocator::vertices () ; glBegin (GL_QUADS) ; for ( int i =0 ; i < vertices.length () - 3 ; i +=4 ) { glVertex3f (vertices [i].x * multiplier, vertices [i].y * multiplier, vertices [i].z * multiplier) ; glVertex3f (vertices [i + 1].x * multiplier, vertices [i + 1].y * multiplier, vertices [i + 1].z * multiplier) ; glVertex3f (vertices [i + 2].x * multiplier, vertices [i + 2].y * multiplier, vertices [i + 2].z * multiplier) ; glVertex3f (vertices [i + 3].x * multiplier, vertices [i + 3].y * multiplier, vertices [i + 3].z * multiplier) ; } glEnd () ; }
MStatus create(double iFrame, const Alembic::AbcGeom::IPoints & iNode, MObject & iParent, MObject & iObject) { MStatus status = MS::kSuccess; Alembic::AbcGeom::IPointsSchema schema = iNode.getSchema(); // object has no samples, bail early if (schema.getNumSamples() == 0) { return status; } Alembic::AbcGeom::IPointsSchema::Sample samp; Alembic::AbcCoreAbstract::index_t index = schema.getTimeSampling()->getNearIndex( iFrame, schema.getNumSamples()).first; schema.get(samp, index); size_t pSize = samp.getPositions()->size(); // bail early if there's no particle data at this frame if (pSize == 0) { return status; } // convert the data to Maya format MFnParticleSystem fnParticle; iObject = fnParticle.create(iParent, &status); fnParticle.setObject(iObject); fnParticle.setName(iNode.getName().c_str()); MPointArray pArray; Alembic::Abc::P3fArraySamplePtr v3ptr = samp.getPositions(); MVectorArray vArray; for (unsigned int pId = 0; pId < pSize; pId++) { pArray.append((*v3ptr)[pId].x, (*v3ptr)[pId].y, (*v3ptr)[pId].z); } status = fnParticle.emit(pArray); status = fnParticle.saveInitialState(); return status; }
MBoundingBox ovalLocator::boundingbox (float multiplier /*=1.0f*/) { static MBoundingBox boundingbox ; if ( boundingbox.min () == boundingbox.max () ) { MPointArray vert =ovalLocator::vertices () ; for ( unsigned int i =0 ; i < vert.length () ; i++ ) boundingbox.expand (vert [i]) ; } MBoundingBox bbox (boundingbox) ; if ( multiplier != 1.0f ) { double factors [3] ={ multiplier, multiplier, multiplier } ; MTransformationMatrix mat ; mat.setScale (factors, MSpace::kWorld) ; bbox.transformUsing (mat.asScaleMatrix ()) ; } return (bbox) ; }
void VoronoiShatter::getPolyFace(int faceId, MPointArray &a) {/* int startFaceId; int endFaceId; startFaceId = (int)VDpolyIndex.at(polyId); endFaceId = (int)VDpolyIndex.at(polyId+1); for(int i=startFaceId; i<endFaceId; i++) {*/ int startEdgeId, endEdgeId; startEdgeId = VDfaceIndex.at(faceId); endEdgeId = VDfaceIndex.at( faceId+1 ); for(int j=startEdgeId; j<endEdgeId; j++) { int startVertexId, endVertexId; startVertexId = VDedge.at(j).startVertexId; //endVertexId = VDedge.at(j).endVertexId; a.append(VDvertex.at(startVertexId).point); //a.append(VDvertex.at(endVertexId).point); } // //a.remove(a.length()-1); return; }
// static void MVGManipulator::drawIntersection2D(const MPointArray& intersectedVSPoints, const MFn::Type intersectionType) { const int arrayLength = intersectedVSPoints.length(); assert(arrayLength < 3); if(arrayLength <= 0) return; switch(intersectionType) { case MFn::kBlindData: assert(arrayLength == 1); MVGDrawUtil::drawEmptyCross(intersectedVSPoints[0], 7, 2, MVGDrawUtil::_intersectionColor, 1.5); break; case MFn::kMeshVertComponent: assert(arrayLength == 1); MVGDrawUtil::drawCircle2D(intersectedVSPoints[0], MVGDrawUtil::_intersectionColor, 10, 30); break; case MFn::kMeshEdgeComponent: assert(arrayLength == 2); MVGDrawUtil::drawLine2D(intersectedVSPoints[0], intersectedVSPoints[1], MVGDrawUtil::_intersectionColor); break; default: break; } }
/* ----------------------------------------- Make a degree 1 curve from the given CVs. ----------------------------------------- */ static void jMakeCurve( MPointArray cvs ) { MStatus stat; unsigned int deg = 1; MDoubleArray knots; unsigned int i; for ( i = 0; i < cvs.length(); i++ ) knots.append( (double) i ); // Now create the curve // MFnNurbsCurve curveFn; curveFn.create( cvs, knots, deg, MFnNurbsCurve::kOpen, false, false, MObject::kNullObj, &stat ); if ( MS::kSuccess != stat ) cout<<"Error creating curve."<<endl; }
/** * @brief Compute the parallelogram from one edge and one point (mouse position). * * [AB]: Input clicked edge * P: mouse position on press * M: moving mouse * [DC]: the computed edge keeping AB length and AP==DM * * A ____________ D * / / * P + + M * / / * B /___________/ C * * This computation is in 2D Camera Space. * * @param[in] view Viewort * @param[in] onPressEdgeData clicked edge information * @param[in] onPressCSMousePos clicked mouse position in Camera Space coordinates * @param[out] intermediateCSEdgePoints the 2 new points (D and C) of the parallelogram */ void MVGManipulator::getIntermediateCSEdgePoints( M3dView& view, const MVGManipulatorCache::EdgeData* onPressEdgeData, const MPoint& onPressCSMousePos, MPointArray& intermediateCSEdgePoints) { assert(onPressEdgeData != NULL); // vertex 1 MVector mouseToVertexCSOffset = MVGGeometryUtil::worldToCameraSpace(view, onPressEdgeData->vertex1->worldPosition) - onPressCSMousePos; intermediateCSEdgePoints.append(getMousePosition(view) + mouseToVertexCSOffset); // vertex 2 mouseToVertexCSOffset = MVGGeometryUtil::worldToCameraSpace(view, onPressEdgeData->vertex2->worldPosition) - onPressCSMousePos; intermediateCSEdgePoints.append(getMousePosition(view) + mouseToVertexCSOffset); }
void HelixButton::createHelix() { MStatus st; const unsigned deg = 3; // Curve Degree const unsigned ncvs = 20; // Number of CVs const unsigned spans = ncvs - deg; // Number of spans const unsigned nknots = spans + 2 * deg - 1; // Number of knots double radius = 4.0; // Helix radius double pitch = 0.5; // Helix pitch unsigned i; MPointArray controlVertices; MDoubleArray knotSequences; // Set up cvs and knots for the helix for (i = 0; i < ncvs; i++) { controlVertices.append( MPoint( radius * cos((double)i), pitch * (double)i, radius * sin((double)i) ) ); } for (i = 0; i < nknots; i++) knotSequences.append((double)i); // Now create the curve MFnNurbsCurve curveFn; MObject curve = curveFn.create( controlVertices, knotSequences, deg, MFnNurbsCurve::kOpen, false, false, MObject::kNullObj, &st ); MGlobal::displayInfo("Helix curve created!"); if (!st) { MGlobal::displayError( HelixQtCmd::commandName + " - could not create helix: " + st.errorString() ); } }
//----------------------------------------------------------------------------- MPointArray &cubeLocator::vertices () { static MPointArray vertices ; if ( vertices.length () != 0 ) return (vertices) ; // Cube data static float cube [] [3] ={ { -0.5f, -0.5f, -0.5f }, { 0.5f, -0.5f, -0.5f }, { 0.5f, 0.5f, -0.5f }, { -0.5f, 0.5f, -0.5f }, { -0.5f, 0.5f, -0.5f }, { -0.5f, 0.5f, 0.5f }, { -0.5f, -0.5f, 0.5f }, { -0.5f, -0.5f, -0.5f }, { -0.5f, 0.5f, 0.5f }, { -0.5f, -0.5f, 0.5f }, { 0.5f, -0.5f, 0.5f }, { 0.5f, 0.5f, 0.5f }, { 0.5f, 0.5f, 0.5f }, { 0.5f, -0.5f, 0.5f }, { 0.5f, -0.5f, -0.5f }, { 0.5f, 0.5f, -0.5f }, { 0.5f, -0.5f, 0.5f }, { 0.5f, -0.5f, -0.5f }, { -0.5f, -0.5f, -0.5f }, { -0.5f, -0.5f, 0.5f }, { -0.5f, 0.5f, -0.5f }, { -0.5f, 0.5f, 0.5f }, { 0.5f, 0.5f, 0.5f }, { 0.5f, 0.5f, -0.5f } } ; int len =sizeof (cube) / sizeof (cube [0]) ; for ( int i =0 ; i < len ; i++ ) vertices.append (cube [i] [0], cube [i] [1], cube [i] [2]) ; return (vertices) ; }
//----------------------------------------------------------------------------- MPointArray &ovalLocator::vertices () { static MPointArray vertices ; if ( vertices.length () != 0 ) return (vertices) ; // Oval data static float oval [] [3] ={ { -2.00f, 0.0f, 0.0f }, { -1.90f, 0.0f, 0.309f }, { -1.618f, 0.0f, 0.588f }, { -1.176f, 0.0f, 0.809f }, { -0.618f, 0.0f, 0.951f }, { 0.0f, 0.0f, 1.00f }, { 0.618f, 0.0f, 0.951f}, { 1.176f, 0.0f, 0.809f}, { 1.618f, 0.0f, 0.588f}, { 1.90f, 0.0f, 0.309f}, { 2.00f, 0.0f, 0.0f}, { 1.90f, 0.0f, -0.309f}, { 1.618f, 0.0f, -0.588f}, { 1.176f, 0.0f, -0.809f}, { 0.618f, 0.0f, -0.951f}, { 0.0f, 0.0f, -1.00f }, { -0.618f, 0.0f, -0.951f}, { -1.176f, 0.0f, -0.809f}, { -1.618f, 0.0f, -0.588f}, { -1.90f, 0.0f, -0.309f}, { -2.00f, 0.0f, 0.0f } } ; int len =sizeof (oval) / sizeof (oval [0]) ; for ( int i =0 ; i < len ; i++ ) vertices.append (oval [i] [0], oval [i] [1], oval [i] [2]) ; return (vertices) ; }
void retargetLocator::getRadPoints( MPointArray& radPoints ) { int div = discDivision; double angle = 360.0/div*0.01745327778; radPoints.setLength( div ); double axisList[3]; for( int i=0; i<div; i++ ) { axisList[0] = 0.0; axisList[1] = sin( angle*i + discAngle ); axisList[2] = cos( angle*i + discAngle ); radPoints.set( i, axisList[(discAxis+3)%3]*discSize.x, axisList[(discAxis+2)%3]*discSize.y, axisList[(discAxis+1)%3]*discSize.z ); } }
void SGTransformManip::draw(int manipIndex, bool hideMode ) { double manipSize = SGMatrix::getManipSizeFromWorldPoint( intersector.center, SGMatrix::getCamMatrix() ); double centerSize = intersector.centerSize / manipSize; GLushort linePattern = 0x5555; MColor xColor(1, 0, 0); MColor yColor(0, 1, 0); MColor zColor(0, 0, 1); MColor cColor(100/255.0f, 220/255.0f, 255/255.0f); if (intersectType == SGTransformManipIntersector::kCenter) cColor = MColor(1, 1, 0); else if (intersectType == SGTransformManipIntersector::kX) xColor = MColor(1, 1, 0); else if (intersectType == SGTransformManipIntersector::kY) yColor = MColor(1, 1, 0); else if (intersectType == SGTransformManipIntersector::kZ) zColor = MColor(1, 1, 0); MVector camX = SGMatrix::getCamVector(0).normal() * centerSize; MVector camY = SGMatrix::getCamVector(1).normal() * centerSize; MPointArray centerManipPoints; centerManipPoints.setLength(5); centerManipPoints[0] = camX + camY + intersector.center; centerManipPoints[1] = -camX + camY + intersector.center; centerManipPoints[2] = -camX - camY + intersector.center; centerManipPoints[3] = camX - camY + intersector.center; centerManipPoints[4] = centerManipPoints[0]; MPointArray xLine, yLine, zLine; xLine.setLength(2);yLine.setLength(2);zLine.setLength(2); xLine[0] = intersector.center; xLine[1] = intersector.axisX + xLine[0]; yLine[0] = intersector.center; yLine[1] = intersector.axisY + yLine[0]; zLine[0] = intersector.center; zLine[1] = intersector.axisZ + zLine[0]; manip->pushLine(manipIndex, xLine, xColor, 1, &linePattern); manip->pushLine(manipIndex, yLine, yColor, 1, &linePattern); manip->pushLine(manipIndex, zLine, zColor, 1, &linePattern); if (!hideMode) { manip->pushShape(manipIndex, cone.shape, intersector.coneXMatrix, xColor); manip->pushShape(manipIndex, cone.shape, intersector.coneYMatrix, yColor); manip->pushShape(manipIndex, cone.shape, intersector.coneZMatrix, zColor); manip->pushLine(manipIndex, centerManipPoints, cColor, 1, &linePattern); } }