MStatus sgMeshIntersect::compute( const MPlug& plug, MDataBlock& data ) { MStatus status; if( m_isDirtyMeshMatrix ) { MDataHandle hInputMeshMatrix = data.inputValue( aInputMeshMatrix ); m_mtxMesh = hInputMeshMatrix.asMatrix(); m_mtxInvMesh = m_mtxMesh.inverse(); } if( m_isDirtyMesh ) { MDataHandle hInputMesh = data.inputValue( aInputMesh ); m_fnMesh.setObject( hInputMesh.asMesh() ); } if( m_isDirtyPointDest ) { MDataHandle hPointDest = data.inputValue( aPointDest ); m_pointDest = MPoint( hPointDest.asVector() ) * m_mtxInvMesh; } if( m_isDirtyPointSrc ) { MDataHandle hPointSource = data.inputValue( aPointSource ); m_pointSource = MPoint( hPointSource.asVector() ) * m_mtxInvMesh; } m_rayDirection = m_pointDest - m_pointSource; m_fnMesh.intersect( m_pointSource, m_rayDirection, m_pointsIntersect, &status ); if( !status ) return MS::kSuccess; MDataHandle hParentInverse = data.inputValue( aParentInverseMatrix ); m_mtxParentInverse = hParentInverse.asMatrix(); MDataHandle hOutPoint = data.outputValue( aOutPoint ); hOutPoint.setMVector( m_pointsIntersect[0]*m_mtxMesh*m_mtxParentInverse ); return MS::kSuccess; }
Layout::Layout(std::string name) : Item(name) { //ctor mouse = MPoint(); handleKey = true; verticalAlign = LVA_Middle; horizontalAlign = LHA_Center; childsChanged = false; drawBorder = true; }
MBoundingBox curvedArrows::boundingBox() const { MBoundingBox bbox; unsigned int i; for ( i = 0; i < fsVertexListSize; i ++ ) { double *pt = fsVertexList[i]; bbox.expand( MPoint( pt[0], pt[1], pt[2] ) ); } return bbox; }
MStatus MVGMesh::getBlindData(const int vertexId, std::map<int, MPoint>& cameraToClickedCSPoints) const { MStatus status; std::vector<ClickedCSPosition> data; if(!getBlindData(vertexId, data)) return MS::kFailure; std::vector<ClickedCSPosition>::const_iterator it = data.begin(); for(; it != data.end(); ++it) cameraToClickedCSPoints[it->cameraId] = MPoint(it->x, it->y); return status; }
MBoundingBox sphericalBlendShapeVisualizerDrawOverride::boundingBox( const MDagPath& objPath, const MDagPath& cameraPath) const { MBoundingBox bbox; double radius = 1.0; MMatrix spaceMatrix = getSpaceMatrix(objPath); /*for(unsigned int i=0; i<bboxPoints.length(); i++) { bbox.expand(bboxPoints[i]); }*/ bbox.expand(MPoint(-radius, 0.0, 0.0) * spaceMatrix); bbox.expand(MPoint(radius, 0.0, 0.0) * spaceMatrix); bbox.expand(MPoint(0.0, -radius, 0.0) * spaceMatrix); bbox.expand(MPoint(0.0, radius, 0.0) * spaceMatrix); bbox.expand(MPoint(0.0, 0.0, -radius) * spaceMatrix); bbox.expand(MPoint(0.0, 0.0, radius) * spaceMatrix); return bbox; }
void VMesh::getBBox(MPoint& corner1, MPoint& corner2) { if(!has_mesh) return; corner1 = MPoint(10e6, 10e6, 10e6); corner2 = MPoint(-10e6, -10e6, -10e6); MStatus status; MItMeshVertex vertIter(pgrow, &status); MPoint S; for(; !vertIter.isDone(); vertIter.next()) { S = vertIter.position(MSpace::kWorld); if( S.x < corner1.x ) corner1.x = S.x; if( S.y < corner1.y ) corner1.y = S.y; if( S.z < corner1.z ) corner1.z = S.z; if( S.x > corner2.x ) corner2.x = S.x; if( S.y > corner2.y ) corner2.y = S.y; if( S.z > corner2.z ) corner2.z = S.z; } }
/***************************************************** ** ** Painter --- getTextExtent ** ******************************************************/ MPoint Painter::getTextExtent( const MString &f ) { double x = 0, y = 0; MPoint p; for( list<MToken>::const_iterator iter = f.tokens.begin(); iter != f.tokens.end(); iter++ ) { p = getTextExtent( *iter ); x += p.real(); y = Max( y, p.imag()); } return MPoint( x, y ); }
MStatus grabUVContext::drawFeedback(MHWRender::MUIDrawManager& drawMgr, const MHWRender::MFrameContext& context) { // to draw the brush ring. drawMgr.beginDrawable(); { drawMgr.setColor( MColor(1.f, 1.f, 1.f) ); drawMgr.setLineWidth( 2.0f ); drawMgr.circle2d(MPoint(fBrushCenterScreenPoint.x, fBrushCenterScreenPoint.y), fBrushConfig.size()); } drawMgr.endDrawable(); return MS::kSuccess; }
MStatus marqueeContext::doDrag ( MEvent & event, MHWRender::MUIDrawManager& drawMgr, const MHWRender::MFrameContext& context) { // Get the marquee's new end position. event.getPosition( last_x, last_y ); // Draw the marquee at its new position. drawMgr.beginDrawable(); drawMgr.setColor( MColor(1.0f, 1.0f, 0.0f) ); drawMgr.line2d( MPoint( start_x, start_y), MPoint(last_x, start_y) ); drawMgr.line2d( MPoint( last_x, start_y), MPoint(last_x, last_y) ); drawMgr.line2d( MPoint( last_x, last_y), MPoint(start_x, last_y) ); drawMgr.line2d( MPoint( start_x, last_y), MPoint(start_x, start_y) ); double len = (last_y - start_y) * (last_y - start_y) + (last_x - start_x) * (last_x - start_x) * 0.01; drawMgr.line(MPoint(0,0,0), MPoint(len, len, len)); drawMgr.endDrawable(); return MS::kSuccess; }
//DeclareSimpleCommand( helix, "Gary Tse", "3.0"); //the command, the author, the min version # MStatus DoHelix::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; } // Set up CVs and knots for the helix MPointArray controlVertices; MDoubleArray knotSequences; 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 ); // Create the curve MFnNurbsCurve curveFn; MObject curve = curveFn.create(controlVertices, knotSequences, deg, MFnNurbsCurve::kOpen, false, false, MObject::kNullObj, &stat ); if ( MS::kSuccess != stat ) cout << "Error creating curve.\n"; return stat; }
sgMeshIntersect::sgMeshIntersect() { m_isDirtyPointSrc = true; m_isDirtyPointDest = true; m_isDirtyMesh = true; m_isDirtyMeshMatrix = true; m_pointsIntersect.append( MPoint( 0,0,0 ) ); /* m_thisNodeNumber = m_nodeNumber; m_existingNodeNumbers.append( m_thisNodeNumber ); m_existingNodeNumbersMap.setLength( m_thisNodeNumber+1 ); m_existingNodeNumbersMap[ m_thisNodeNumber ] = m_existingNodeNumbers.length()-1; m_nodeNumber++; */ }
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() ); } }
void OnSize(HWND hWnd) { if (!g_bInited) return; g_sv.clear(); MRect rcClient; ::GetClientRect(hWnd, &rcClient); for (int i = 0; i < c_nCtrls; ++i) { MRect rcCtrl(MPoint(0, c_height * i), MSize(rcClient.Width(), c_height)); g_sv.AddCtrlInfo(g_ahwndCtrls[i], rcCtrl); } g_sv.SetExtentForAllCtrls(); g_sv.UpdateAll(); }
MStatus helix2::redoIt() { unsigned i, numCVs; MStatus status; MFnNurbsCurve curveFn( fDagPath ); numCVs = curveFn.numCVs(); status = curveFn.getCVs( fCVs ); if ( MS::kSuccess != status ) { cerr << "redoIt: could not get cvs status: " << status << endl; return MS::kFailure; } MPointArray points(fCVs); for (i = 0; i < numCVs; i++) points[i] = MPoint( radius * cos( (double)i ), pitch * (double)i, radius * sin( (double)i ) ); status = curveFn.setCVs( points ); if ( MS::kSuccess != status ) { cerr << "redoIt: could not setCVs status: " << status << endl; fCVs.clear(); return status; } status = curveFn.updateCurve(); if ( MS::kSuccess != status ) { cerr << "redoIt: updateCurve() failed status: " << status << endl; return status; } return MS::kSuccess; }
MStatus LSSolverNode::compute(const MPlug& plug, MDataBlock& data) { MStatus stat; if( plug == deformed) { MDataHandle tetWorldMatrixData = data.inputValue(tetWorldMatrix, &returnStatus); McheckErr(returnStatus, "Error getting tetWorldMatrix data handle\n"); MDataHandle restShapeData = data.inputValue(restShape, &returnStatus); McheckErr(returnStatus, "Error getting step data handle\n"); MDataHandle restVerticesData = data.inputValue(restVertices, &returnStatus); McheckErr(returnStatus, "Error getting step data handle\n"); MDataHandle restElementsData = data.inputValue(restElements, &returnStatus); McheckErr(returnStatus, "Error getting step data handle\n"); MDataHandle selectedConstraintVertsData = data.inputValue(selectedConstraintVerts, &returnStatus); McheckErr(returnStatus, "Error getting step data handle\n"); MDataHandle selectedForceVertsData = data.inputValue(selectedForceVerts, &returnStatus); McheckErr(returnStatus, "Error getting step data handle\n"); MDataHandle timeData = data.inputValue(time, &returnStatus); McheckErr(returnStatus, "Error getting step data handle\n"); MDataHandle outputMeshData = data.outputValue(deformed, &returnStatus); McheckErr(returnStatus, "Error getting outputMesh data handle\n"); MMatrix twmat = tetWorldMatrixData.asMatrix(); MObject rs = restShapeData.asMesh(); double t = timeData.asDouble(); MDataHandle poissonRatioData = data.inputValue(poissonRatio, &returnStatus); McheckErr(returnStatus, "Error getting poissonRatio data handle\n"); MDataHandle youngsModulusData = data.inputValue(youngsModulus, &returnStatus); McheckErr(returnStatus, "Error getting youngsmodulus data handle\n"); MDataHandle objectDensityData = data.inputValue(objectDensity, &returnStatus); McheckErr(returnStatus, "Error getting objectDensity data handle\n"); MDataHandle frictionData = data.inputValue(friction, &returnStatus); McheckErr(returnStatus, "Error getting friction data handle\n"); MDataHandle restitutionData = data.inputValue(restitution, &returnStatus); McheckErr(returnStatus, "Error getting restitution data handle\n"); MDataHandle dampingData = data.inputValue(damping, &returnStatus); McheckErr(returnStatus, "Error getting damping data handle\n"); MDataHandle userSuppliedDtData = data.inputValue(userSuppliedDt, &returnStatus); McheckErr(returnStatus, "Error getting user supplied dt data handle\n"); MDataHandle integrationTypeData = data.inputValue(integrationType, &returnStatus); McheckErr(returnStatus, "Error getting user integrationTypeData\n"); MDataHandle forceModelTypeData = data.inputValue(forceModelType, &returnStatus); McheckErr(returnStatus, "Error getting user forceModelTypeData\n"); MDataHandle forceApplicationTimeData = data.inputValue(forceApplicationTime, &returnStatus); McheckErr(returnStatus, "Error getting user forceApplicationTime\n"); MDataHandle forceReleasedTimeData = data.inputValue(forceReleasedTime, &returnStatus); McheckErr(returnStatus, "Error getting user forceReleasedTime\n"); MDataHandle forceIncrementTimeData = data.inputValue(forceIncrementTime, &returnStatus); McheckErr(returnStatus, "Error getting user forceIncrementTime\n"); MDataHandle forceStartTimeData = data.inputValue(forceStartTime, &returnStatus); McheckErr(returnStatus, "Error getting user forceStartTime\n"); MDataHandle forceStopTimeData = data.inputValue(forceStopTime, &returnStatus); McheckErr(returnStatus, "Error getting user forceStopTime\n"); MDataHandle forceMagnitudeData = data.inputValue(forceMagnitude, &returnStatus); McheckErr(returnStatus, "Error getting user forceIdleTime\n"); MDataHandle useSuppliedForceData = data.inputValue(useSuppliedForce, &returnStatus); McheckErr(returnStatus, "Error getting user forceIdleTime\n"); MDataHandle useSuppliedConstraintsData = data.inputValue(useSuppliedConstraints, &returnStatus); McheckErr(returnStatus, "Error getting user forceIdleTime\n"); MDataHandle forceDirectionData = data.inputValue(forceDirection, &returnStatus); McheckErr(returnStatus, "Error getting user forceDirection\n"); MDataHandle contactKsData = data.inputValue(contactKs, &returnStatus); McheckErr(returnStatus, "Error getting user forceDirection\n"); MDataHandle contactKdData = data.inputValue(contactKd, &returnStatus); McheckErr(returnStatus, "Error getting user forceDirection\n"); MTime currentTime, maxTime; currentTime = MAnimControl::currentTime(); maxTime = MAnimControl::maxTime(); if (currentTime == MAnimControl::minTime()) { // retrive restVertices and restElements MFnDoubleArrayData restVertArrayData(restVerticesData.data()); MDoubleArray verts = restVertArrayData.array(); int vertArrayLen = verts.length(); double *vertArray = new double[vertArrayLen]; verts.get(vertArray); for(int v=0;v<vertArrayLen;v=v+3) { MPoint mpoint = MPoint(vertArray[v],vertArray[v+1],vertArray[v+2])*twmat; vertArray[v] = mpoint.x; vertArray[v+1] = mpoint.y; vertArray[v+2] = mpoint.z; } MFnIntArrayData restEleArrayData(restElementsData.data()); MIntArray ele = restEleArrayData.array(); int eleArrayLen = ele.length(); int *eleArray = new int[eleArrayLen]; ele.get(eleArray); MFnIntArrayData selectedConstraintVertsArrayData(selectedConstraintVertsData.data()); MIntArray sv = selectedConstraintVertsArrayData.array(); // building selectedConstraintVerts vector<int> selectedConstraintVertIndices; for (int i = 0 ; i < sv.length() ; i++) { selectedConstraintVertIndices.push_back(sv[i]); } MFnIntArrayData selectedForceVertsArrayData(selectedForceVertsData.data()); MIntArray sf = selectedForceVertsArrayData.array(); vector<int> selectedForceVertIndices; for (int i = 0 ; i < sf.length() ; i++) { selectedForceVertIndices.push_back(sf[i]); } // temporarily create force direction vector double *forceDir = forceDirectionData.asDouble3(); vector<double> dir; dir.push_back(forceDir[0]); dir.push_back(forceDir[1]);dir.push_back(forceDir[2]); prevDeformed = 0; double youngsModulusDouble = youngsModulusData.asDouble(); double poissonRatioDouble = poissonRatioData.asDouble(); double objectDensityDouble = objectDensityData.asDouble(); double frictionDouble = frictionData.asDouble(); double restitutionDouble = restitutionData.asDouble(); double dampingDouble = dampingData.asDouble(); double userSuppliedDtDouble = userSuppliedDtData.asDouble(); double forceMagnitudeDouble = forceMagnitudeData.asDouble(); int fAppT = forceApplicationTimeData.asInt(); int fReleasedT = forceReleasedTimeData.asInt(); int fIncT = forceIncrementTimeData.asInt(); int fStartT = forceStartTimeData.asInt(); int fStopT = forceStopTimeData.asInt(); int integrationTypeInt = integrationTypeData.asShort(); int forceModelTypeInt = forceModelTypeData.asShort(); bool useSuppliedForceBool = useSuppliedForceData.asBool(); bool useSuppliedConstraintsBool = useSuppliedConstraintsData.asBool(); double contactKs = contactKsData.asDouble(); double contactKd = contactKdData.asDouble(); if( sm) { delete sm; } sm = new SoftBodySim(youngsModulusDouble,poissonRatioDouble,objectDensityDouble, frictionDouble,restitutionDouble,dampingDouble, eleArrayLen, eleArray, vertArrayLen, vertArray,integrationTypeInt,forceModelTypeInt); sm->setContactAttributes(contactKs,contactKd); if (useSuppliedConstraintsBool) sm->initialize("",userSuppliedDtDouble, selectedConstraintVertIndices); else { vector<int> empty; sm->initialize("",userSuppliedDtDouble, empty); } if (useSuppliedForceBool) sm->setUserForceAttributes(forceMagnitudeDouble, dir,selectedForceVertIndices,fAppT,fReleasedT,fIncT,fStartT,fStopT); } else { sm->update(); } MFnMesh surfFn(rs,&stat); McheckErr( stat, "compute - MFnMesh error" ); MFnMeshData ouputMeshDataCreator; MObject oMesh = ouputMeshDataCreator.create(&stat); buildOutputMesh(surfFn, sm->m_vertices,oMesh); outputMeshData.set(oMesh); data.setClean(plug); } else stat = MS::kUnknownParameter; return stat; }
MStatus TestDeformer::deform(MDataBlock& data, MItGeometry& iter, const MMatrix& localToWorldMatrix, unsigned int mIndex) { MStatus status; // get the current node state short initialized_mapping = data.inputValue( initialized_data, &status).asShort(); CHECK_MSTATUS(status); __debug("%s(), initialized_mapping=%d, mIndex=%d", __FUNCTION__, initialized_mapping, mIndex); if( initialized_mapping == 1 ) { initVertMapping(data, iter, localToWorldMatrix, mIndex); // set initialized_data to 2 automatically. User don't have to set it manully. MObject tObj = thisMObject(); MPlug setInitMode = MPlug( tObj, initialized_data ); setInitMode.setShort( 2 ); // and sync initialized_mapping from initialized_data // so, the code section: // if (initialized_mapping == 2) // { // ... // } // will be executed when this deform() function is called next time. initialized_mapping = data.inputValue( initialized_data, &status ).asShort(); CHECK_MSTATUS(status); } if( initialized_mapping == 2 ) { envelope = MPxDeformerNode::envelope; MDataHandle envelopeHandle = data.inputValue( envelope, &status ); CHECK_MSTATUS( status ); MArrayDataHandle vertMapArrayData = data.inputArrayValue( vert_map, &status ); CHECK_MSTATUS( status ); MArrayDataHandle meshAttrHandle = data.inputArrayValue( driver_mesh, &status ); CHECK_MSTATUS( status ); /// 1. init tempOutputPts to zero points MPointArray tempOutputPts; iter.reset(); while( !iter.isDone(&status) ) { CHECK_MSTATUS(tempOutputPts.append(MPoint(0, 0, 0))); CHECK_MSTATUS(iter.next()); } assert(tempOutputPts.length() == iter.count()); /// 2. set tempOutputPts to deform values which comes from each driver mesh iter.reset(); int numMeshes = meshAttrHandle.elementCount(); __debug("%s(), numMeshes=%d", __FUNCTION__, numMeshes); CHECK_MSTATUS(meshAttrHandle.jumpToElement(0)); // for each driver mesh for( int count=0; count < numMeshes; ++count ) { __debug("%s(), count=%d", __FUNCTION__, count); // for one driver mesh: currentMesh MDataHandle currentMesh = meshAttrHandle.inputValue(&status); CHECK_MSTATUS( status ); MObject meshMobj = currentMesh.asMesh(); __debugMeshInfo(__FUNCTION__, meshMobj); // accumulate deform values of currentMesh to tempOutputPts _deform_on_one_mesh(data, iter, localToWorldMatrix, mIndex, meshMobj, envelopeHandle, vertMapArrayData, tempOutputPts ); if( !meshAttrHandle.next() ) { break; } }// for each driver mesh /// 3. add deform value to this geometry(driven mesh) int i = 0; iter.reset(); while( !iter.isDone(&status) ) { MPoint p = iter.position(MSpace::kObject, &status); CHECK_MSTATUS(status); // add the deform value to this vertex CHECK_MSTATUS(iter.setPosition( p + tempOutputPts[i]/numMeshes )); CHECK_MSTATUS(iter.next()); ++i; } assert(tempOutputPts.length() == iter.count()); }// if return( MS::kSuccess ); }
// used when ray does not intersect object // to account for perspective, all edges are flattened onto // a plane defined by the raySource and rayDirection double gpuCacheIsectUtil::getEdgeSnapPointOnBox(const MPoint& raySource, const MVector& rayDirection, const MBoundingBox& bbox, MPoint& snapPoint){ //if ray intersects bbox MPoint boxIntersectionPt; if(firstRayIntersection(bbox.min(), bbox.max(), raySource, rayDirection, NULL, &boxIntersectionPt)) { // ray intersects bounding box, so snapPoint is // closest hit on the outside of the box // and distance to box is 0 (for snapping purposes) snapPoint = boxIntersectionPt; return 0.0; } MPointArray verts; MPoint vmin = bbox.min(); MPoint vmax = bbox.max(); verts.insert(vmin,0); verts.insert(MPoint(vmax[0],vmin[1],vmin[2]),1); verts.insert(MPoint(vmax[0],vmax[1],vmin[2]),2); verts.insert(MPoint(vmin[0],vmax[1],vmin[2]),3); verts.insert(MPoint(vmin[0],vmin[1],vmax[2]),4); verts.insert(MPoint(vmax[0],vmin[1],vmax[2]),5); verts.insert(vmax,6); verts.insert(MPoint(vmin[0],vmax[1],vmax[2]),7); int edgeIndices[12][2]={{0,1},{1,2},{2,3},{3,0},{4,5},{5,6},{6,7},{7,4},{0,4},{1,5},{3,7},{2,6}}; double minDistRect = std::numeric_limits<double>::max(); for(int edge=0; edge<12;edge++){ MPoint vertex1Org = verts[edgeIndices[edge][0]]; MPoint vertex2Org = verts[edgeIndices[edge][1]]; double coef_plane = rayDirection * raySource; double d = coef_plane - rayDirection * vertex1Org; MPoint vertex1 = vertex1Org + rayDirection * d; d = coef_plane - rayDirection * vertex2Org; MPoint vertex2 = vertex2Org + rayDirection * d; MVector edgeDir = vertex2 - vertex1; if (edgeDir.length()<0.0000001){ double dist = vertex1.distanceTo(raySource); if (dist < minDistRect) { minDistRect = dist; snapPoint = vertex1Org; } } else { MPoint edgePt; // Compute the closest point from the edge to cursor Ray. double percent = gpuCacheIsectUtil::getClosestPointOnLine(raySource, vertex1, vertex2, edgePt); double dist = edgePt.distanceTo(raySource); if (dist < minDistRect) { minDistRect = dist; snapPoint = (vertex1Org + percent * (vertex2Org - vertex1Org)); } } } return minDistRect; }
MObject VMesh::createFeather() { MStatus stat; MFnMeshData dataCreator; MObject outMeshData = dataCreator.create(&stat); int numVertex = 0; int numPolygon = 0; MPointArray vertexArray; MFloatArray uArray, vArray; MIntArray polygonCounts, polygonConnects, polygonUVs; MFnMesh meshFn(pgrow, &stat); MItMeshVertex vertIter(pgrow, &stat); MItMeshPolygon faceIter(pgrow, &stat); MPoint S; MVector N, tang, ttang, binormal, dir, hair_up; MColor Cscale, Cerect, Crotate, Ccurl, Cwidth; float rot, lengreal; MATRIX44F hair_space; MString setScale("fb_scale"); MString setErect("fb_erect"); MString setRotate("fb_rotate"); MString setCurl("fb_curl"); MString setWidth("fb_width"); MIntArray conn_face; for( int i=0; !vertIter.isDone(); vertIter.next(), i++ ) { if(vertIter.onBoundary()) continue; vertIter.getNormal(N, MSpace::kWorld); N.normalize(); vertIter.getColor(Cscale, &setScale); vertIter.getColor(Cerect, &setErect); vertIter.getColor(Crotate, &setRotate); vertIter.getColor(Ccurl, &setCurl); vertIter.getColor(Cwidth, &setWidth); vertIter.getConnectedFaces(conn_face); tang = MVector(0,0,0); for(int j=0; j<conn_face.length(); j++) { meshFn.getFaceVertexTangent (conn_face[j], i, ttang, MSpace::kWorld); ttang.normalize(); tang += ttang; } tang /= conn_face.length(); conn_face.clear(); tang.normalize(); tang = N^tang; tang.normalize(); binormal = N^tang; if(Crotate.r<0.5) { rot = (0.5 - Crotate.r)*2; tang = tang + (binormal-tang)*rot; tang.normalize(); binormal = N^tang; } else { rot = (Crotate.r-0.5)*2; tang = tang + (binormal*-1-tang)*rot; tang.normalize(); binormal = N^tang; } dir = tang + (N - tang)*Cerect.r; dir.normalize(); //S = S+dir*Cscale.r*m_scale; //glVertex3f(S.x, S.y, S.z); hair_up = dir^binormal; hair_space.setIdentity(); hair_space.setOrientations(XYZ(binormal.x, binormal.y, binormal.z), XYZ(hair_up.x, hair_up.y, hair_up.z), XYZ(dir.x, dir.y, dir.z)); S = vertIter.position(MSpace::kWorld); hair_space.setTranslation(XYZ(S.x, S.y, S.z)); lengreal = Cscale.r*m_scale; fb->create(lengreal, 0, lengreal*(Ccurl.r-0.5)*2); XYZ pw; MPoint pvx; MPoint pright = S + binormal*Cwidth.r*m_width*lengreal; MPoint pleft = S - binormal*Cwidth.r*m_width*lengreal; MPoint phit; int polyhit; meshFn.getClosestPoint (pright, phit, MSpace::kObject, &polyhit); MVector topright = phit - S; topright.normalize(); topright *= Cwidth.r*m_width*lengreal; meshFn.getClosestPoint (pleft, phit, MSpace::kObject, &polyhit); MVector topleft = phit - S; topleft.normalize(); topleft *= Cwidth.r*m_width*lengreal; //tws_binormal = binormal*cos(0.2) + hair_up*sin(0.2); for(int j=0; j<NUMBENDSEG+1; j++) { fb->getPoint(j, pw); hair_space.transform(pw); pvx = MPoint(pw.x, pw.y, pw.z) + topleft;//- tws_binormal*Cwidth.r*m_width*lengreal; vertexArray.append(pvx); pvx = MPoint(pw.x, pw.y, pw.z); vertexArray.append(pvx); pvx = MPoint(pw.x, pw.y, pw.z) + topright;//tws_binormal*Cwidth.r*m_width*lengreal; vertexArray.append(pvx); uArray.append(0.0); vArray.append((float)j/NUMBENDSEG); uArray.append(0.5); vArray.append((float)j/NUMBENDSEG); uArray.append(1.0); vArray.append((float)j/NUMBENDSEG); } for(int j=0; j<NUMBENDSEG; j++) { polygonConnects.append(j*3 + numVertex); polygonConnects.append(j*3+3 + numVertex); polygonConnects.append(j*3+4 + numVertex); polygonConnects.append(j*3+1 + numVertex); polygonCounts.append(4); polygonConnects.append(j*3+1 + numVertex); polygonConnects.append(j*3+4 + numVertex); polygonConnects.append(j*3+5 + numVertex); polygonConnects.append(j*3+2 + numVertex); polygonCounts.append(4); polygonUVs.append(j*3 + numVertex); polygonUVs.append(j*3+3 + numVertex); polygonUVs.append(j*3+4 + numVertex); polygonUVs.append(j*3+1 + numVertex); polygonUVs.append(j*3+1 + numVertex); polygonUVs.append(j*3+4 + numVertex); polygonUVs.append(j*3+5 + numVertex); polygonUVs.append(j*3+2 + numVertex); } numVertex += (NUMBENDSEG+1)*3; numPolygon += NUMBENDSEG*2; } MIntArray connvert; int idxpre; float averg_scale, averg_erect, averg_rotate, averg_curl, averg_width; for( int i=0; !faceIter.isDone(); faceIter.next(), i++ ) { if(faceIter.onBoundary()) continue; faceIter.getNormal(N, MSpace::kWorld); N.normalize(); faceIter.getVertices(connvert); averg_scale=averg_erect=averg_rotate=averg_curl=0; for(int j=0; j<connvert.length(); j++) { vertIter.setIndex(connvert[j], idxpre); vertIter.getColor(Cscale, &setScale); vertIter.getColor(Cerect, &setErect); vertIter.getColor(Crotate, &setRotate); vertIter.getColor(Ccurl, &setCurl); vertIter.getColor(Cwidth, &setWidth); averg_scale += Cscale.r; averg_erect += Cerect.r; averg_rotate += Crotate.r; averg_curl += Ccurl.r; averg_width += Cwidth.r; } averg_scale /= connvert.length(); averg_erect /= connvert.length(); averg_rotate /= connvert.length(); averg_curl /= connvert.length(); averg_width /= connvert.length(); tang = MVector(0,0,0); for(int j=0; j<connvert.length(); j++) { meshFn.getFaceVertexTangent (i, connvert[j], ttang, MSpace::kWorld); ttang.normalize(); tang += ttang; } //tang /= conn_face.length(); connvert.clear(); tang.normalize(); tang = N^tang; tang.normalize(); binormal = N^tang; if(averg_rotate<0.5) { rot = (0.5 - averg_rotate)*2; tang = tang + (binormal-tang)*rot; tang.normalize(); binormal = N^tang; } else { rot = (averg_rotate-0.5)*2; tang = tang + (binormal*-1-tang)*rot; tang.normalize(); binormal = N^tang; } dir = tang + (N - tang)*averg_erect; dir.normalize(); //S = S+dir*Cscale.r*m_scale; //glVertex3f(S.x, S.y, S.z); hair_up = dir^binormal; hair_space.setIdentity(); hair_space.setOrientations(XYZ(binormal.x, binormal.y, binormal.z), XYZ(hair_up.x, hair_up.y, hair_up.z), XYZ(dir.x, dir.y, dir.z)); S = faceIter.center(MSpace::kWorld); hair_space.setTranslation(XYZ(S.x, S.y, S.z)); lengreal = Cscale.r*m_scale; fb->create(lengreal, 0, lengreal*(averg_curl-0.5)*2); MPoint pright = S + binormal*Cwidth.r*m_width*lengreal; MPoint pleft = S - binormal*Cwidth.r*m_width*lengreal; XYZ pw; MPoint pvx; MPoint phit; int polyhit; meshFn.getClosestPoint (pright, phit, MSpace::kObject, &polyhit); MVector topright = phit - S; topright.normalize(); topright *= Cwidth.r*m_width*lengreal; meshFn.getClosestPoint (pleft, phit, MSpace::kObject, &polyhit); MVector topleft = phit - S; topleft.normalize(); topleft *= Cwidth.r*m_width*lengreal; //tws_binormal = binormal*cos(0.2) + hair_up*sin(0.2); for(int j=0; j<NUMBENDSEG+1; j++) { fb->getPoint(j, pw); hair_space.transform(pw); pvx = MPoint(pw.x, pw.y, pw.z) + topleft;//- tws_binormal*averg_width*m_width*lengreal; vertexArray.append(pvx); pvx = MPoint(pw.x, pw.y, pw.z); vertexArray.append(pvx); pvx = MPoint(pw.x, pw.y, pw.z) + topright;//tws_binormal*averg_width*m_width*lengreal; vertexArray.append(pvx); uArray.append(0.0); vArray.append((float)j/NUMBENDSEG); uArray.append(0.5); vArray.append((float)j/NUMBENDSEG); uArray.append(1.0); vArray.append((float)j/NUMBENDSEG); } for(int j=0; j<NUMBENDSEG; j++) { polygonConnects.append(j*3 + numVertex); polygonConnects.append(j*3+3 + numVertex); polygonConnects.append(j*3+4 + numVertex); polygonConnects.append(j*3+1 + numVertex); polygonCounts.append(4); polygonConnects.append(j*3+1 + numVertex); polygonConnects.append(j*3+4 + numVertex); polygonConnects.append(j*3+5 + numVertex); polygonConnects.append(j*3+2 + numVertex); polygonCounts.append(4); polygonUVs.append(j*3 + numVertex); polygonUVs.append(j*3+3 + numVertex); polygonUVs.append(j*3+4 + numVertex); polygonUVs.append(j*3+1 + numVertex); polygonUVs.append(j*3+1 + numVertex); polygonUVs.append(j*3+4 + numVertex); polygonUVs.append(j*3+5 + numVertex); polygonUVs.append(j*3+2 + numVertex); } numVertex += (NUMBENDSEG+1)*3; numPolygon += NUMBENDSEG*2; } MFnMesh meshCreateFn; meshCreateFn.create( numVertex, numPolygon, vertexArray, polygonCounts, polygonConnects, outMeshData, &stat ); meshCreateFn.setUVs ( uArray, vArray ); meshCreateFn.assignUVs ( polygonCounts, polygonUVs ); return outMeshData; }
/************************************************************** *** ** BasicVedicChart --- OnResponsiveChartEvent *** ***************************************************************/ bool BasicVedicChart::OnResponsiveChartEvent( const MPoint p, const int /* keyMod */ ) { bool changed = false; uint f = UINT_FOR_NOT_FOUND; int status = 0; if ( p != MPoint( -1, -1 )) { f = getFieldForScreenPos( p ); //printf( "F %d\n", f ); } //printf( "Marked field is %d f is %d markedFieldStatus %d offset %d\n", markedField, f, markedFieldStatus, positionOffset ); if ( markedField != f ) changed = true; markedField = f; if ( f == UINT_FOR_NOT_FOUND ) { markedFieldStatus = 0; } else { const VedicChartBehaviorConfig &bcfg = chartprops->getVedicChartBehaviorConfig(); if ( bcfg.highlightOnMouseOver ) status |= CHART_FIELD_STATUS_MARKUP; if ( bcfg.zoomOnMouseOver ) status |= CHART_FIELD_STATUS_ZOOM; if ( bcfg.aspectingObjectsMode == 1 ) status |= CHART_FIELD_STATUS_ASPECTING; if ( bcfg.aspectedObjectsMode == 1 ) status |= CHART_FIELD_STATUS_ASPECTED; if ( bcfg.allAspectsMode == 1 && charttype != CT_PARTNER ) status |= CHART_FIELD_STATUS_ALL_ASPECTS; if ( wxGetKeyState( WXK_SHIFT )) { if ( bcfg.aspectingObjectsMode == 2 ) status |= CHART_FIELD_STATUS_ASPECTING; if ( bcfg.aspectedObjectsMode == 2 ) status |= CHART_FIELD_STATUS_ASPECTED; if ( bcfg.allAspectsMode == 2 && charttype != CT_PARTNER ) status |= CHART_FIELD_STATUS_ALL_ASPECTS; } if ( wxGetKeyState( WXK_CONTROL )) { if ( bcfg.aspectingObjectsMode == 3 ) status |= CHART_FIELD_STATUS_ASPECTING; if ( bcfg.aspectedObjectsMode == 3 ) status |= CHART_FIELD_STATUS_ASPECTED; if ( bcfg.allAspectsMode == 3 && charttype != CT_PARTNER ) status |= CHART_FIELD_STATUS_ALL_ASPECTS; } if ( wxGetKeyState( WXK_ALT )) { if ( bcfg.aspectingObjectsMode == 4 ) status |= CHART_FIELD_STATUS_ASPECTING; if ( bcfg.aspectedObjectsMode == 4 ) status |= CHART_FIELD_STATUS_ASPECTED; if ( bcfg.allAspectsMode == 4 && charttype != CT_PARTNER ) status |= CHART_FIELD_STATUS_ALL_ASPECTS; } // test if mouse position is within transit rect (used for non cummutative partner aspects) if ( charttype == CT_RADIX || charttype == CT_TRANSIT ) status |= CHART_FIELD_STATUS_POS_FULL; else { if ( pointInRect( p, transitrect )) status |= CHART_FIELD_STATUS_POS_INNER; else status |= CHART_FIELD_STATUS_POS_OUTER; } //printf( "Status now %d\n", status ); if ( status != markedFieldStatus ) changed = true; markedFieldStatus = status; } //printf( "Ende BasicVedicChart::OnResponsiveChartEvent point %f %f markedField %d markedFieldStatus %d status %d changed %d\n", p.real(), p.imag(), markedField, markedFieldStatus, status, changed ); return changed; }
/***************************************************** ** ** BasicVedicChart --- paintAspectsForFieldPair ** ******************************************************/ void BasicVedicChart::paintAspectsForFieldPair( const int &f1, const int &f2 ) { const double dist = 4; MPoint p1, p2; MRect rect; int acount = 0; list<AspectEvent> &al = aexpert->getAspectList(); list<AspectEvent>::iterator iter; AspectEvent *event = (AspectEvent*)NULL; //printf( "BasicVedicChart::paintAspectsForFieldPair %d %d\n", f1, f2 ); // first step determine field parts and whether apsect relation has to swapped FIELD_PART part1 = FP_ALL; FIELD_PART part2 = FP_ALL; bool swap = false; if ( charttype == CT_TRANSIT ) { part1 = FP_OUTER; part2 = FP_INNER; } else if ( charttype == CT_PARTNER ) { const bool aspecting = markedFieldStatus & CHART_FIELD_STATUS_ASPECTING; const bool aspected = markedFieldStatus & CHART_FIELD_STATUS_ASPECTED; //printf( "aspecting %d aspected %d\n", aspecting, aspected ); //const bool markedFull = markedFieldStatus & CHART_FIELD_STATUS_POS_FULL; const bool markedInner = markedFieldStatus & CHART_FIELD_STATUS_POS_INNER; const bool markedOuter = markedFieldStatus & CHART_FIELD_STATUS_POS_OUTER; //assert( markedFull ^ markedInner ^ markedOuter ); if (( markedInner && aspected ) || ( markedOuter && aspecting )) { part1 = FP_INNER; part2 = FP_OUTER; } else if (( markedInner && aspecting ) || ( markedOuter && aspected )) { part1 = FP_OUTER; part2 = FP_INNER; swap = true; } } // second step: find number of matching aspects for ( iter = al.begin(); iter != al.end(); iter++ ) { if ( (*iter).field1 == f1 && (*iter).field2 == f2 && (*iter).swapCharts == swap ) { event = (AspectEvent*)&(*iter); acount++; } } //printf( "ACOUNT %d H2SET %d\n", acount, h2set ); if ( acount > 0 ) { // correct field index for north indian chart int g1 = f1; int g2 = f2; if ( positionOffset != 0 ) { g1 = a_red( f1 - positionOffset, field_count ); g2 = a_red( f2 - positionOffset, field_count ); } if ( part1 != FP_ALL ) { rect = fields[g1].calculateModifiedRect( part1, MPoint( xr - 0.5 * transitrect.width, yr - 0.5 * transitrect.height )); p1 = rect.getCenter(); rect = fields[g2].calculateModifiedRect( part2, MPoint( xr - 0.5 * transitrect.width, yr - 0.5 * transitrect.height )); p2 = rect.getCenter(); } else { p1 = fields[g1].getCenter(); p2 = fields[g2].getCenter(); } if ( acount == 1 ) { assert( event ); setAspectPainterStyle( event->strength, event->benefic ); paintArrow( p1, p2 ); } else // acount > 1, draw aspects in parallele style { MPoint c = findOrthogonalPoint( p1 - p2, acount * dist ); int i = 0; for ( iter = al.begin(); iter != al.end(); iter++ ) { if ( (*iter).field1 == f1 && (*iter).field2 == f2 && (*iter).swapCharts == swap ) { double lambda = i++; lambda /= (double)( acount - 1 ); MPoint q1 = lambda * ( p1 - c ) + ( 1 - lambda ) * ( p1 + c ); MPoint q2 = lambda * ( p2 - c ) + ( 1 - lambda ) * ( p2 + c ); setAspectPainterStyle( (*iter).strength, (*iter).benefic ); paintArrow( q1, q2 ); } } } } }
// called by legacy default viewport void footPrint::draw( M3dView & view, const MDagPath & /*path*/, M3dView::DisplayStyle style, M3dView::DisplayStatus status ) { // Get the size // MObject thisNode = thisMObject(); MPlug plug( thisNode, size ); MDistance sizeVal; plug.getValue( sizeVal ); float multiplier = (float) sizeVal.asCentimeters(); view.beginGL(); if ( ( style == M3dView::kFlatShaded ) || ( style == M3dView::kGouraudShaded ) ) { // Push the color settings // glPushAttrib( GL_CURRENT_BIT ); if ( status == M3dView::kActive ) { view.setDrawColor( 13, M3dView::kActiveColors ); } else { view.setDrawColor( 13, M3dView::kDormantColors ); } glBegin( GL_TRIANGLE_FAN ); int i; int last = soleCount - 1; for ( i = 0; i < last; ++i ) { glVertex3f( sole[i][0] * multiplier, sole[i][1] * multiplier, sole[i][2] * multiplier ); } glEnd(); glBegin( GL_TRIANGLE_FAN ); last = heelCount - 1; for ( i = 0; i < last; ++i ) { glVertex3f( heel[i][0] * multiplier, heel[i][1] * multiplier, heel[i][2] * multiplier ); } glEnd(); glPopAttrib(); } // Draw the outline of the foot // glBegin( GL_LINES ); int i; int last = soleCount - 1; for ( i = 0; i < last; ++i ) { glVertex3f( sole[i][0] * multiplier, sole[i][1] * multiplier, sole[i][2] * multiplier ); glVertex3f( sole[i+1][0] * multiplier, sole[i+1][1] * multiplier, sole[i+1][2] * multiplier ); } last = heelCount - 1; for ( i = 0; i < last; ++i ) { glVertex3f( heel[i][0] * multiplier, heel[i][1] * multiplier, heel[i][2] * multiplier ); glVertex3f( heel[i+1][0] * multiplier, heel[i+1][1] * multiplier, heel[i+1][2] * multiplier ); } glEnd(); view.endGL(); // Draw the name of the footPrint view.setDrawColor( MColor( 0.1f, 0.8f, 0.8f, 1.0f ) ); view.drawText( MString("Footprint"), MPoint( 0.0, 0.0, 0.0 ), M3dView::kCenter ); }
MPoint DrawLab::toMilli(Point point) const { return MPoint(toMilli(point.x),toMilli(point.y)); }
MStatus LSSolverNode::compute(const MPlug& plug, MDataBlock& data) { MStatus stat; if( plug == deformed) { MDataHandle tetWorldMatrixData = data.inputValue(tetWorldMatrix, &returnStatus); McheckErr(returnStatus, "Error getting tetWorldMatrix data handle\n"); MDataHandle restShapeData = data.inputValue(restShape, &returnStatus); McheckErr(returnStatus, "Error getting step data handle\n"); MDataHandle restVerticesData = data.inputValue(restVertices, &returnStatus); McheckErr(returnStatus, "Error getting step data handle\n"); MDataHandle restElementsData = data.inputValue(restElements, &returnStatus); McheckErr(returnStatus, "Error getting step data handle\n"); MDataHandle selectedConstraintVertsData = data.inputValue(selectedConstraintVerts, &returnStatus); McheckErr(returnStatus, "Error getting step data handle\n"); MDataHandle selectedForceVertsData = data.inputValue(selectedForceVerts, &returnStatus); McheckErr(returnStatus, "Error getting step data handle\n"); MDataHandle timeData = data.inputValue(time, &returnStatus); McheckErr(returnStatus, "Error getting step data handle\n"); MDataHandle outputMeshData = data.outputValue(deformed, &returnStatus); McheckErr(returnStatus, "Error getting outputMesh data handle\n"); MMatrix twmat = tetWorldMatrixData.asMatrix(); MObject rs = restShapeData.asMesh(); double t = timeData.asDouble(); MDataHandle poissonRatioData = data.inputValue(poissonRatio, &returnStatus); McheckErr(returnStatus, "Error getting poissonRatio data handle\n"); MDataHandle youngsModulusData = data.inputValue(youngsModulus, &returnStatus); McheckErr(returnStatus, "Error getting youngsmodulus data handle\n"); MDataHandle objectDensityData = data.inputValue(objectDensity, &returnStatus); McheckErr(returnStatus, "Error getting objectDensity data handle\n"); MDataHandle frictionData = data.inputValue(friction, &returnStatus); McheckErr(returnStatus, "Error getting friction data handle\n"); MDataHandle restitutionData = data.inputValue(restitution, &returnStatus); McheckErr(returnStatus, "Error getting restitution data handle\n"); MDataHandle dampingData = data.inputValue(damping, &returnStatus); McheckErr(returnStatus, "Error getting damping data handle\n"); MDataHandle userSuppliedDtData = data.inputValue(userSuppliedDt, &returnStatus); McheckErr(returnStatus, "Error getting user supplied dt data handle\n"); MDataHandle integrationTypeData = data.inputValue(integrationType, &returnStatus); McheckErr(returnStatus, "Error getting user integrationTypeData\n"); MDataHandle forceModelTypeData = data.inputValue(forceModelType, &returnStatus); McheckErr(returnStatus, "Error getting user forceModelTypeData\n"); MDataHandle forceApplicationTimeData = data.inputValue(forceApplicationTime, &returnStatus); McheckErr(returnStatus, "Error getting user forceApplicationTime\n"); MDataHandle forceReleasedTimeData = data.inputValue(forceReleasedTime, &returnStatus); McheckErr(returnStatus, "Error getting user forceReleasedTime\n"); MDataHandle forceIncrementTimeData = data.inputValue(forceIncrementTime, &returnStatus); McheckErr(returnStatus, "Error getting user forceIncrementTime\n"); MDataHandle forceStartTimeData = data.inputValue(forceStartTime, &returnStatus); McheckErr(returnStatus, "Error getting user forceStartTime\n"); MDataHandle forceStopTimeData = data.inputValue(forceStopTime, &returnStatus); McheckErr(returnStatus, "Error getting user forceStopTime\n"); MDataHandle forceMagnitudeData = data.inputValue(forceMagnitude, &returnStatus); McheckErr(returnStatus, "Error getting user forceIdleTime\n"); MDataHandle useSuppliedForceData = data.inputValue(useSuppliedForce, &returnStatus); McheckErr(returnStatus, "Error getting user forceIdleTime\n"); MDataHandle useSuppliedConstraintsData = data.inputValue(useSuppliedConstraints, &returnStatus); McheckErr(returnStatus, "Error getting user forceIdleTime\n"); MDataHandle forceDirectionData = data.inputValue(forceDirection, &returnStatus); McheckErr(returnStatus, "Error getting user forceDirection\n"); MDataHandle contactKsData = data.inputValue(contactKs, &returnStatus); McheckErr(returnStatus, "Error getting user forceDirection\n"); MDataHandle contactKdData = data.inputValue(contactKd, &returnStatus); McheckErr(returnStatus, "Error getting user forceDirection\n"); MTime currentTime, maxTime; currentTime = MAnimControl::currentTime(); maxTime = MAnimControl::maxTime(); if (currentTime == MAnimControl::minTime()) { // retrive restVertices and restElements sTime=0; MFnDoubleArrayData restVertArrayData(restVerticesData.data()); MDoubleArray verts = restVertArrayData.array(); int vertArrayLen = verts.length(); double *vertArray = new double[vertArrayLen]; verts.get(vertArray); for(int v=0;v<vertArrayLen;v=v+3) { MPoint mpoint = MPoint(vertArray[v],vertArray[v+1],vertArray[v+2])*twmat; vertArray[v] = mpoint.x; vertArray[v+1] = mpoint.y; vertArray[v+2] = mpoint.z; } MFnIntArrayData restEleArrayData(restElementsData.data()); MIntArray ele = restEleArrayData.array(); int eleArrayLen = ele.length(); int *eleArray = new int[eleArrayLen]; ele.get(eleArray); MFnIntArrayData selectedConstraintVertsArrayData(selectedConstraintVertsData.data()); MIntArray sv = selectedConstraintVertsArrayData.array(); // building selectedConstraintVerts vector<int> selectedConstraintVertIndices; for (int i = 0 ; i < sv.length() ; i++) { selectedConstraintVertIndices.push_back(sv[i]); } MGlobal::displayInfo("!!!!!"); //std::string tmp=std::to_string((long double)selectedConstraintVertIndices.size()); //MGlobal::displayInfo(MString(tmp.c_str())); //std::cout<<currentConstriant<<" up"<<std::endl; for(int i=0;i<constraintIndex[currentConstriant].size();i++){ if(domainParentIndex[currentConstriant]==-1) selectedConstraintVertIndices.push_back(constraintIndex[currentConstriant][i]); //std::cout<<constraintIndex[currentConstriant][i]<<std::endl; } //std::cout<<currentConstriant<<" up"<<std::endl; /*for(int i=0;i<10;i++){ selectedConstraintVertIndices.push_back(i+1); }*/ MFnIntArrayData selectedForceVertsArrayData(selectedForceVertsData.data()); MIntArray sf = selectedForceVertsArrayData.array(); vector<int> selectedForceVertIndices; for (int i = 0 ; i < sf.length() ; i++) { selectedForceVertIndices.push_back(sf[i]); } // temporarily create force direction vector double *forceDir = forceDirectionData.asDouble3(); vector<double> dir; dir.push_back(forceDir[0]); dir.push_back(forceDir[1]);dir.push_back(forceDir[2]); prevDeformed = 0; double youngsModulusDouble = youngsModulusData.asDouble(); double poissonRatioDouble = poissonRatioData.asDouble(); double objectDensityDouble = objectDensityData.asDouble(); double frictionDouble = frictionData.asDouble(); double restitutionDouble = restitutionData.asDouble(); double dampingDouble = dampingData.asDouble(); double userSuppliedDtDouble = userSuppliedDtData.asDouble(); double forceMagnitudeDouble = forceMagnitudeData.asDouble(); int fAppT = forceApplicationTimeData.asInt(); int fReleasedT = forceReleasedTimeData.asInt(); int fIncT = forceIncrementTimeData.asInt(); int fStartT = forceStartTimeData.asInt(); int fStopT = forceStopTimeData.asInt(); int integrationTypeInt = integrationTypeData.asShort(); int forceModelTypeInt = forceModelTypeData.asShort(); bool useSuppliedForceBool = useSuppliedForceData.asBool(); bool useSuppliedConstraintsBool = useSuppliedConstraintsData.asBool(); double contactKs = contactKsData.asDouble(); double contactKd = contactKdData.asDouble(); if( sm) { delete sm; } sm = new SoftBodySim(youngsModulusDouble,poissonRatioDouble,objectDensityDouble, frictionDouble,restitutionDouble,dampingDouble, eleArrayLen, eleArray, vertArrayLen, vertArray,integrationTypeInt,forceModelTypeInt); sm->setContactAttributes(contactKs,contactKd); if (useSuppliedConstraintsBool) sm->initialize("",userSuppliedDtDouble, selectedConstraintVertIndices); else { vector<int> empty; sm->initialize("",userSuppliedDtDouble, empty); } if (useSuppliedForceBool) sm->setUserForceAttributes(forceMagnitudeDouble, dir,selectedForceVertIndices,fAppT,fReleasedT,fIncT,fStartT,fStopT); std::vector<int> childList=fdg.GetDomainChild(currentConstriant); if(childList.size()!=0){//not the root for(int i=0;i<childList.size();i++){ int childIndex=-1; for(int j=0;j<fdomain_list.size();j++){ if(fdomain_list[j]->index==childList[i]){ childIndex=j; } }//j glm::dvec3 oldPos=glm::dvec3(0,0,0); for(int j=0;j<parentConstraintIndex[childIndex].size();j++){ int index=3*parentConstraintIndex[childIndex][j]; oldPos.x+=sm->m_vertices[index]; oldPos.y+=sm->m_vertices[index+1]; oldPos.z+=sm->m_vertices[index+2]; } oldPos=oldPos*(1.0/parentConstraintIndex[childIndex].size()); parentLastPosOld[childIndex]=oldPos; parentLastPosNew[childIndex]=oldPos; }//i } domainID=currentConstriant; currentConstriant++; if(currentConstriant==fdomain_list.size()) currentConstriant=0; } else { std::vector<int> childList=fdg.GetDomainChild(domainID); if(childList.size()!=0){//not the root for(int i=0;i<childList.size();i++){ int childIndex=-1; for(int j=0;j<fdomain_list.size();j++){ if(fdomain_list[j]->index==childList[i]){ childIndex=j; } }//j glm::dvec3 newPos=glm::dvec3(0,0,0); for(int j=0;j<parentConstraintIndex[childIndex].size();j++){ int index=3*parentConstraintIndex[childIndex][j]; newPos.x+=sm->m_vertices[index]; newPos.y+=sm->m_vertices[index+1]; newPos.z+=sm->m_vertices[index+2]; } //std::cout<<newPos.x<<","<<newPos.y<<","<<newPos.z<<std::endl; newPos=newPos*(1.0/parentConstraintIndex[childIndex].size()); parentLastPosOld[childIndex]=parentLastPosNew[childIndex]; parentLastPosNew[childIndex]=newPos; }//i } //update the parents' fixed point moving distance std::vector<float> pos; int num=0; if(domainParentIndex[domainID]!=-1){//has parent for(int i=0;i<constraintIndex[domainID].size();i++){ int index=3*constraintIndex[domainID][i]; pos.push_back(sm->m_vertices[index]); pos.push_back(sm->m_vertices[index+1]); pos.push_back(sm->m_vertices[index+2]); } } sm->update(sTime); sTime++; if(domainParentIndex[domainID]!=-1){//has parent //std::cout<<sm->numOfVertices<<std::endl; for(int i=0;i<constraintIndex[domainID].size();i++){ int index=3*constraintIndex[domainID][i]; if(index>3*sm->numOfVertices) std::cout<<index-3*sm->numOfVertices<<"big "<<currentConstriant<<std::endl; glm::dvec3 movePos=parentLastPosNew[domainID]-parentLastPosOld[domainID]; //std::cout<<sm->m_vertices[index]<<","<<sm->m_vertices[index+1]<<","<<sm->m_vertices[index+2]<<std::endl; sm->m_vertices[index]=pos[num++]+movePos.x; sm->m_vertices[index+1]=pos[num++]+movePos.y; sm->m_vertices[index+2]=pos[num++]+movePos.z; //std::cout<<sm->m_vertices[index]<<","<<sm->m_vertices[index+1]<<","<<sm->m_vertices[index+2]<<"end"<<std::endl; //std::cout<<constraintIndex[domainID][i]<<std::endl; } } } MFnMesh surfFn(rs,&stat); McheckErr( stat, "compute - MFnMesh error" ); MFnMeshData ouputMeshDataCreator; MObject oMesh = ouputMeshDataCreator.create(&stat); buildOutputMesh(surfFn, sm->m_vertices,oMesh); outputMeshData.set(oMesh); data.setClean(plug); } else stat = MS::kUnknownParameter; return stat; }
/***************************************************** ** ** BasicVedicChart --- paintField ** ******************************************************/ void BasicVedicChart::paintField( const int &i ) { MRect rr = fields[i].rect; //const wxLongLong starttime = wxGetLocalTimeMillis(); //printf( "ZOOM %d while %f and %f\n", config->vedicChartBehavior->zoomFactor, .5 * ( rr.width + rr.height ), a ); if ( isFieldZoomed( i )) { const double avgSize = .5 * ( rr.width + rr.height ); double newSize = avgSize * chartprops->getVedicChartBehaviorConfig().zoomFactor; newSize /= 100.0; const double a = newSize - avgSize; rr.x -= .5 * a; rr.y -= .5 * a; rr.width += a; rr.height += a; } switch( fields[i].fieldtype ) { case FIELD_TYPE_FULL: // all fields in south indian chart, sbc, fixed rasis in east indian chart painter->drawRectangle( rr ); break; case FIELD_TYPE_NE: // east: taurus and sag { MPoint mp[3] = { MPoint( rr.x, rr.y ), MPoint( rr.x + rr.width, rr.y ), MPoint( rr.x + rr.width, rr.y + rr.height ) }; painter->drawPolygon( 3, mp ); } break; case FIELD_TYPE_SW: // east: gemini and scorpio { MPoint mp[3] = { MPoint( rr.x, rr.y ), MPoint( rr.x, rr.y + rr.height ), MPoint( rr.x + rr.width, rr.y + rr.height ) }; painter->drawPolygon( 3, mp ); } break; case FIELD_TYPE_NW: // east: leo and pisces { MPoint mp[3] = { MPoint( rr.x, rr.y ), MPoint( rr.x, rr.y + rr.height ), MPoint( rr.x + rr.width, rr.y ) }; painter->drawPolygon( 3, mp ); } break; case FIELD_TYPE_SE: // east: virgo and aquarius { MPoint mp[3] = { MPoint( rr.x, rr.y + rr.height ), MPoint( rr.x + rr.width, rr.y ), MPoint( rr.x + rr.width, rr.y + rr.height ) }; painter->drawPolygon( 3, mp ); } break; case FIELD_TYPE_N: // north: houses 2 and 12 { MPoint mp[3] = { MPoint( rr.x, rr.y ), MPoint( rr.x + rr.width, rr.y ), MPoint( rr.x + 0.5 * rr.width, rr.y + rr.height ) }; painter->drawPolygon( 3, mp ); } break; case FIELD_TYPE_W: // north: houses 3 and 5 { MPoint mp[3] = { MPoint( rr.x, rr.y ), MPoint( rr.x, rr.y + rr.height ), MPoint( rr.x + rr.width, rr.y + 0.5 * rr.height ) }; painter->drawPolygon( 3, mp ); } break; case FIELD_TYPE_S: // north: houses 6 and 8 { MPoint mp[3] = { MPoint( rr.x, rr.y + rr.height ), MPoint( rr.x + rr.width, rr.y + rr.height ), MPoint( rr.x + 0.5 * rr.width, rr.y ) }; painter->drawPolygon( 3, mp ); } break; case FIELD_TYPE_E: // north: houses 9 and 11 { MPoint mp[3] = { MPoint( rr.x + rr.width, rr.y ), MPoint( rr.x + rr.width, rr.y + rr.height ), MPoint( rr.x, rr.y + 0.5 * rr.height ) }; painter->drawPolygon( 3, mp ); } break; case FIELD_TYPE_DIAMOND:// north: houses 1: 4: 7: 10 { MPoint mp[4] = { MPoint( rr.x + 0.5 * rr.width, rr.y ), MPoint( rr.x + rr.width, rr.y + 0.5 * rr.height ), MPoint( rr.x + 0.5 * rr.width, rr.y + rr.height ), MPoint( rr.x, rr.y + 0.5 * rr.height ) }; painter->drawPolygon( 4, mp ); } break; default: printf( "WARN: invalid field type %d in BasicVedicChart::paintField\n", fields[i].fieldtype ); painter->drawRectangle( rr ); break; } //printf( "BasicVedicChart::paintField mark 10 %ld millisec\n", (wxGetLocalTimeMillis() - starttime).ToLong()); }
MStatus geometrySurfaceConstraint::compute( const MPlug& plug, MDataBlock& block ) { MStatus returnStatus; if(plug == constraintTranslateX || plug == constraintTranslateY || plug == constraintTranslateZ) { if(!m_isInitd) { // read rest position MDataHandle htgo = block.inputValue(targetRestP); double3 & tgo = htgo.asDouble3(); MGlobal::displayInfo(MString("target rest p ")+tgo[0]+" "+tgo[1]+" "+tgo[2]); m_restPos = MPoint(tgo[0],tgo[1],tgo[2]); m_isInitd = true; } MArrayDataHandle targetArray = block.inputArrayValue( compoundTarget ); const unsigned int targetArrayCount = targetArray.elementCount(); MMatrix tm; tm.setToIdentity(); unsigned int i; for ( i = 0; i < targetArrayCount; i++ ) { MDataHandle targetElement = targetArray.inputValue(&returnStatus); if(!returnStatus) { MGlobal::displayInfo("failed to get input value target element"); } MDataHandle htm = targetElement.child(targetTransform); MFnMatrixData ftm(htm.data(), &returnStatus); if(!returnStatus) { MGlobal::displayInfo("failed to get matrix data"); } tm = ftm.matrix(); targetArray.next(); } MDataHandle hparentInvMat = block.inputValue(constraintParentInverseMatrix); MMatrix parentInvMat = hparentInvMat.asMatrix(); // world position MPoint curPos(tm(3,0), tm(3,1), tm(3,2)); // offset in local space m_offsetToRest = m_restPos - curPos; // object position in world space MPoint localP = m_offsetToRest * tm + curPos; // in local space localP *= parentInvMat; MDataHandle hout; if(plug == constraintTranslateX) { hout = block.outputValue(constraintTranslateX); hout.set(localP.x); } else if(plug == constraintTranslateY) { hout = block.outputValue(constraintTranslateY); hout.set(localP.y); } else if(plug == constraintTranslateZ) { hout = block.outputValue(constraintTranslateZ); hout.set(localP.z); } //MPlug pgTx(thisMObject(), constraintTargetX); //pgTx.setValue(m_lastPos.x); //MPlug pgTy(thisMObject(), constraintTargetY); //pgTy.setValue(m_lastPos.y); //MPlug pgTz(thisMObject(), constraintTargetZ); //pgTz.setValue(m_lastPos.z); MPlug pgOx(thisMObject(), constraintObjectX); pgOx.setValue(m_offsetToRest.x); MPlug pgOy(thisMObject(), constraintObjectY); pgOy.setValue(m_offsetToRest.y); MPlug pgOz(thisMObject(), constraintObjectZ); pgOz.setValue(m_offsetToRest.z); // MFnNumericData nd; //MObject offsetData = nd.create( MFnNumericData::k3Double); //nd.setData3Double(m_lastPos.x, m_lastPos.y, m_lastPos.z); //MPlug pgTgo(thisMObject(), targetOffset); //pgTgo.setValue(offsetData); } else return MS::kUnknownParameter; return MS::kSuccess; }
/***************************************************** ** ** BasicVedicChart --- drawFieldText ** ******************************************************/ void BasicVedicChart::drawFieldText( const uint &f, const FIELD_PART &part ) { assert( f < field_count ); //const wxLongLong starttime = wxGetLocalTimeMillis(); //printf( "BasicVedicChart::drawFieldText field %d mode %d\n", f, mode ); ChartField &field = fields[f]; const double zoomfactor = isFieldZoomed( f ) ? chartprops->getVedicChartBehaviorConfig().zoomFactor / 100.0 : 1.0; wxString s; assert( part == FP_ALL || part == FP_INNER || part == FP_OUTER ); ChartContents &cc = field.getContents( part == FP_OUTER ? 1 : 0 ); const int align = field.align; MRect rect = field.calculateModifiedRect( part, MPoint( xr - 0.5 * transitrect.width, yr - 0.5 * transitrect.height )); const double border = rect.width / 15.0; if ( align & Align::Left ) { rect.x += border; rect.width -= border; } else if ( align & Align::Right ) { rect.width -= border; } if ( align & Align::Top ) { rect.y += border; rect.height -= border; } else if ( align & Align::Bottom ) { rect.height -= border; } // number of text items uint titems = cc.textitems.size(); // number of graphic items uint gitems = cc.graphicitems.size(); if ( titems == 0 && gitems == 0 ) return; // nothing to do // Maximum number of lines for complete contents int max_lines = (int)Max(rect.height/ text_height, 1 ); //printf( "rect.height %f text_height %f max_lines %d\n", rect.height, text_height, max_lines ); int total_lines = 0; // grahic items per line: put them into one line if more than 3, else 2 lines int gitems_pline = 0; if ( gitems > 3 ) { total_lines = 2; gitems_pline = ( gitems + 1 ) / 2; } else if ( gitems > 0 ) { total_lines = 1; gitems_pline = gitems; } // text items per line int titems_pline = 0; //printf( "BasicVedicChart::drawFieldText mark 4 %ld millisec\n", (wxGetLocalTimeMillis() - starttime).ToLong()); if ( titems > 0 ) { const int left_lines = max_lines - total_lines; if ( left_lines <= 1 ) { // put all items in one line, no place left titems_pline = titems; total_lines++; } else { // distribute the items over the left lines titems_pline = 1 + titems / left_lines; total_lines = total_lines + titems / titems_pline; } } int total_height = total_lines * text_height; int starty = rect.y; if ( align & Align::Bottom ) starty = rect.y + rect.height - total_height; else if ( align & Align::VCenter ) starty = rect.y + ( rect.height - total_height ) / 2; MRect trect = rect; trect.y = starty; trect.height = text_height; // paint graphic items vector<ChartGraphicItem> g; uint i = 0; int j = 0; //printf( "BasicVedicChart::drawFieldText mark 4a %ld millisec\n", (wxGetLocalTimeMillis() - starttime).ToLong()); if ( gitems > 0 ) { setSymbolFontZoom( zoomfactor ); } //printf( "BasicVedicChart::drawFieldText mark 5 %ld millisec\n", (wxGetLocalTimeMillis() - starttime).ToLong()); while ( i < gitems ) { g.push_back( cc.graphicitems[i++] ); if ( ++j >= gitems_pline ) { drawGraphicItemLine( trect, g, align, part ); j = 0; trect.y += text_height; g.clear(); } } if ( g.size() > 0 ) { drawGraphicItemLine( trect, g, align, part ); trect.y += text_height; } // paint text items setGraphicFontZoom( zoomfactor ); i = 0; j = 0; s.Clear(); //printf( "BasicVedicChart::drawFieldText mark 9 %ld millisec\n", (wxGetLocalTimeMillis() - starttime).ToLong()); while ( i < titems ) { if ( s.Len() > 0 ) s << wxT( " " ); if ( titems_pline == 1 && cc.textitems[i].longname.Len() * text_width < rect.width ) { s << cc.textitems[i++].longname; } else s << cc.textitems[i++].shortname; if ( ++j >= titems_pline ) { drawTextItemLine( trect, s, align, part ); j = 0; trect.y += text_height; s.Clear(); } } if ( s.Len() > 0 ) drawTextItemLine( trect, s, align, part ); //printf( "BasicVedicChart::drawFieldText mark 10 %ld millisec\n", (wxGetLocalTimeMillis() - starttime).ToLong()); }
GLuint OpenSubdivPtexShader::bindProgram(const MHWRender::MDrawContext & mDrawContext, OpenSubdiv::OsdGLDrawContext *osdDrawContext, const OpenSubdiv::OsdPatchArray & patch) { CHECK_GL_ERROR("bindProgram begin\n"); // Build shader Effect effect; effect.color = _enableColor; effect.occlusion = _enableOcclusion; effect.displacement = _enableDisplacement; effect.normal = _enableNormal; EffectDesc effectDesc( patch.desc, effect ); EffectDrawRegistry::ConfigType * config = effectRegistry.GetDrawConfig(effectDesc); // Install shader GLuint program = config->program; glUseProgram(program); // Update and bind transform state struct Transform { float ModelViewMatrix[16]; float ProjectionMatrix[16]; float ModelViewProjectionMatrix[16]; } transformData; setMatrix(mDrawContext.getMatrix(MHWRender::MDrawContext::kWorldViewMtx), transformData.ModelViewMatrix); setMatrix(mDrawContext.getMatrix(MHWRender::MDrawContext::kProjectionMtx), transformData.ProjectionMatrix); setMatrix(mDrawContext.getMatrix(MHWRender::MDrawContext::kWorldViewProjMtx), transformData.ModelViewProjectionMatrix); if (!g_transformUB) { glGenBuffers(1, &g_transformUB); glBindBuffer(GL_UNIFORM_BUFFER, g_transformUB); glBufferData(GL_UNIFORM_BUFFER, sizeof(transformData), NULL, GL_STATIC_DRAW); }; glBindBuffer(GL_UNIFORM_BUFFER, g_transformUB); glBufferSubData(GL_UNIFORM_BUFFER, 0, sizeof(transformData), &transformData); glBindBuffer(GL_UNIFORM_BUFFER, 0); glBindBufferBase(GL_UNIFORM_BUFFER, g_transformBinding, g_transformUB); // Update and bind tessellation state struct Tessellation { float TessLevel; int GregoryQuadOffsetBase; int PrimitiveIdBase; } tessellationData; tessellationData.TessLevel = static_cast<float>(1 << _tessFactor); tessellationData.GregoryQuadOffsetBase = patch.GetQuadOffsetBase; tessellationData.PrimitiveIdBase = patch.GetPatchIndex();; if (!g_tessellationUB) { glGenBuffers(1, &g_tessellationUB); glBindBuffer(GL_UNIFORM_BUFFER, g_tessellationUB); glBufferData(GL_UNIFORM_BUFFER, sizeof(tessellationData), NULL, GL_STATIC_DRAW); }; glBindBuffer(GL_UNIFORM_BUFFER, g_tessellationUB); glBufferSubData(GL_UNIFORM_BUFFER, 0, sizeof(tessellationData), &tessellationData); glBindBuffer(GL_UNIFORM_BUFFER, 0); glBindBufferBase(GL_UNIFORM_BUFFER, g_tessellationBinding, g_tessellationUB); #ifdef USE_NON_IMAGE_BASED_LIGHTING // Update and bind lighting state int numLights = mDrawContext.numberOfActiveLights(); struct Lighting { struct Light { float position[4]; float diffuse[4]; float ambient[4]; float specular[4]; } lightSource[2]; } lightingData; memset(&lightingData, 0, sizeof(lightingData)); for (int i = 0; i < numLights && i < 1; ++i) { MFloatPointArray positions; MFloatVector direction; float intensity; MColor color; bool hasDirection, hasPosition; mDrawContext.getLightInformation(i, positions, direction, intensity, color, hasDirection, hasPosition); Lighting::Light &light = lightingData.lightSource[i]; if (hasDirection) { light.position[0] = -direction[0]; light.position[1] = -direction[1]; light.position[2] = -direction[2]; for (int j = 0; j < 4; ++j) { light.diffuse[j] = color[j] * intensity; light.ambient[j] = color[j] * intensity; light.specular[j] = color[j] * intensity; } } } if (!g_lightingUB) { glGenBuffers(1, &g_lightingUB); glBindBuffer(GL_UNIFORM_BUFFER, g_lightingUB); glBufferData(GL_UNIFORM_BUFFER, sizeof(lightingData), NULL, GL_STATIC_DRAW); }; glBindBuffer(GL_UNIFORM_BUFFER, g_lightingUB); glBufferSubData(GL_UNIFORM_BUFFER, 0, sizeof(lightingData), &lightingData); glBindBuffer(GL_UNIFORM_BUFFER, 0); glBindBufferBase(GL_UNIFORM_BUFFER, g_lightingBinding, g_lightingUB); #endif GLint eye = glGetUniformLocation(program, "eyePositionInWorld"); MPoint e = MPoint(0, 0, 0) * mDrawContext.getMatrix(MHWRender::MDrawContext::kWorldViewInverseMtx); glProgramUniform3f(program, eye, static_cast<float>(e.x), static_cast<float>(e.y), static_cast<float>(e.z)); // update other uniforms float color[4] = { 0, 0, 0, 1 }; _diffuse.get(color); glProgramUniform4fv(program, glGetUniformLocation(program, "diffuseColor"), 1, color); _ambient.get(color); glProgramUniform4fv(program, glGetUniformLocation(program, "ambientColor"), 1, color); _specular.get(color); glProgramUniform4fv(program, glGetUniformLocation(program, "specularColor"), 1, color); glProgramUniform1f(program, glGetUniformLocation(program, "fresnelBias"), _fresnelBias); glProgramUniform1f(program, glGetUniformLocation(program, "fresnelScale"), _fresnelScale); glProgramUniform1f(program, glGetUniformLocation(program, "fresnelPower"), _fresnelPower); // Ptex bindings // color ptex if (effectRegistry.getPtexColorValid()) { GLint texData = glGetUniformLocation(program, "textureImage_Data"); glProgramUniform1i(program, texData, CLR_TEXTURE_UNIT + 0); GLint texPacking = glGetUniformLocation(program, "textureImage_Packing"); glProgramUniform1i(program, texPacking, CLR_TEXTURE_UNIT + 1); GLint texPages = glGetUniformLocation(program, "textureImage_Pages"); glProgramUniform1i(program, texPages, CLR_TEXTURE_UNIT + 2); } // displacement ptex if (effectRegistry.getPtexDisplacementValid()) { GLint texData = glGetUniformLocation(program, "textureDisplace_Data"); glProgramUniform1i(program, texData, DISP_TEXTURE_UNIT + 0); GLint texPacking = glGetUniformLocation(program, "textureDisplace_Packing"); glProgramUniform1i(program, texPacking, DISP_TEXTURE_UNIT + 1); GLint texPages = glGetUniformLocation(program, "textureDisplace_Pages"); glProgramUniform1i(program, texPages, DISP_TEXTURE_UNIT + 2); } // occlusion ptex if (effectRegistry.getPtexOcclusionValid()) { GLint texData = glGetUniformLocation(program, "textureOcclusion_Data"); glProgramUniform1i(program, texData, OCC_TEXTURE_UNIT + 0); GLint texPacking = glGetUniformLocation(program, "textureOcclusion_Packing"); glProgramUniform1i(program, texPacking, OCC_TEXTURE_UNIT + 1); GLint texPages = glGetUniformLocation(program, "textureOcclusion_Pages"); glProgramUniform1i(program, texPages, OCC_TEXTURE_UNIT + 2); } // diffuse environment map if (effectRegistry.getDiffuseEnvironmentId() != 0) { GLint difmap = glGetUniformLocation(program, "diffuseEnvironmentMap"); glProgramUniform1i(program, difmap, DIFF_TEXTURE_UNIT); } // specular environment map if (effectRegistry.getSpecularEnvironmentId() != 0) { GLint envmap = glGetUniformLocation(program, "specularEnvironmentMap"); glProgramUniform1i(program, envmap, ENV_TEXTURE_UNIT); } glActiveTexture(GL_TEXTURE0); CHECK_GL_ERROR("bindProgram leave\n"); return program; }
MStatus clusterControledCurve::compute( const MPlug& plug, MDataBlock& data ) { //MFnDependencyNode thisNode( thisMObject() ); //cout << thisNode.name() << ", start" << endl; MStatus status; MDataHandle hInputCurve = data.inputValue( aInputCurve, &status ); CHECK_MSTATUS_AND_RETURN_IT( status ); MDataHandle hInputCurveMatrix = data.inputValue( aInputCurveMatrix, &status ); CHECK_MSTATUS_AND_RETURN_IT( status ); MDataHandle hOutputCurve = data.outputValue( aOutputCurve, &status ); CHECK_MSTATUS_AND_RETURN_IT( status ); MArrayDataHandle hArrBindPreMatrix = data.inputArrayValue( aBindPreMatrix, &status ); CHECK_MSTATUS_AND_RETURN_IT( status ); MArrayDataHandle hArrMatrix = data.inputArrayValue( aMatrix, &status ); CHECK_MSTATUS_AND_RETURN_IT( status ); MArrayDataHandle hArrWeightList = data.inputArrayValue( aWeightList, &status ); CHECK_MSTATUS_AND_RETURN_IT( status ); MDataHandle hUpdate = data.inputValue( aUpdate, &status ); CHECK_MSTATUS_AND_RETURN_IT( status ); MObject oInputCurve = hInputCurve.asNurbsCurve(); int bindPreMatrixLength = hArrBindPreMatrix.elementCount(); int matrixLength = hArrMatrix.elementCount(); MFnNurbsCurve fnInputCurve = oInputCurve; int numCVs = fnInputCurve.numCVs(); int weightListLength = hArrWeightList.elementCount(); if( weightListLength > 100 ) { cout << "WeightList Count Error : " << weightListLength << endl; return MS::kFailure; } MPointArray inputCvPoints; MPointArray outputCvPoints; fnInputCurve.getCVs( inputCvPoints ); outputCvPoints.setLength( numCVs ); MMatrix matrix; MMatrix inputCurveMatrix = hInputCurveMatrix.asMatrix(); MMatrix inputCurveMatrixInverse = inputCurveMatrix.inverse(); if( requireUpdate ) CHECK_MSTATUS_AND_RETURN_IT( updateBindPreMatrix( oInputCurve, inputCurveMatrixInverse, hArrMatrix, hArrBindPreMatrix, hUpdate.asBool() ) ); for( int i=0; i< numCVs; i++ ) { inputCvPoints[i] *= inputCurveMatrix; } for( int i=0; i< numCVs; i++ ) { outputCvPoints[i] = MPoint( 0,0,0 ); double weight; for( int j=0; j< matrixLength; j++ ) { weight = setWeights[i][j]; hArrMatrix.jumpToElement( j ); matrix = hArrMatrix.inputValue().asMatrix(); outputCvPoints[i] += inputCvPoints[i]*bindPreMatrix[j]*matrix*weight; } } for( int i=0; i< numCVs; i++ ) { outputCvPoints[i] *= inputCurveMatrixInverse; } MFnNurbsCurveData outputCurveData; MObject oOutputCurve = outputCurveData.create(); fnInputCurve.copy( oInputCurve, oOutputCurve ); MFnNurbsCurve fnOutputCurve( oOutputCurve, &status ); CHECK_MSTATUS_AND_RETURN_IT( status ); fnOutputCurve.setCVs( outputCvPoints ); hOutputCurve.set( oOutputCurve ); data.setClean( plug ); //cout << thisNode.name() << ", end" << endl; return status; }
MPoint convert( const Imath::V3d &from ) { return MPoint( from[0], from[1], from[2] ); }
bool CSGSlicer::slice( const Cell& cell, const MeshSlicerInfo& info, MFnMesh& outMesh ) { // copy maya mesh to csg.js model csgjs_model jsModel; MItMeshVertex it(_sourceMesh); while( !it.isDone() ) { csgjs_vertex vtx; // get position MPoint pos = it.position(MSpace::kWorld); vtx.pos = csgjs_vector(static_cast<float>(pos.x), static_cast<float>(pos.y), static_cast<float>(pos.z)); // add position jsModel.vertices.push_back(vtx); it.next(); } MIntArray triangleCounts; MIntArray triangleVertices; MFnMesh(_sourceMesh).getTriangles(triangleCounts, triangleVertices); for( unsigned int i = 0; i < triangleVertices.length(); ++i ) { jsModel.indices.push_back(triangleVertices[i]); } // convert cell into csgjs_model csgjs_model cellModel; int indexOffset = 0; const auto& planePoints = cell.getPlanePoints(); for( const auto& points : planePoints ) { for( const auto& pnt : points ) { csgjs_vertex vtx; vtx.pos = csgjs_vector(pnt.x, pnt.y, pnt.z); cellModel.vertices.push_back(vtx); } const auto& indices = HadanConvexTriangulate(points); for( const auto& idx : indices ) { cellModel.indices.push_back(indexOffset + idx[0]); cellModel.indices.push_back(indexOffset + idx[1]); cellModel.indices.push_back(indexOffset + idx[2]); } indexOffset += static_cast<int>(points.size()); } // perform intersection const csgjs_model result = csgjs_intersection(jsModel, cellModel); // copy back to maya mesh MPointArray pointArray; for( const auto& vtx : result.vertices ) { pointArray.append(MPoint(vtx.pos.x, vtx.pos.y, vtx.pos.z)); } MIntArray faceConnects; for( const auto& idx : result.indices ) { faceConnects.append(idx); } MIntArray faceCounts; for( size_t i = 0; i < result.indices.size() / 3; ++i ) { faceCounts.append(3); } { std::unique_lock<std::mutex> lock(CSGJS_CREATEMESH_MUTEX); outMesh.create(pointArray.length(), faceCounts.length(), pointArray, faceCounts, faceConnects); } return true; }