MStatus TCC::setErrorColors(MFnMesh &meshFn, TCCData &tccData) { MStatus stat; if ((tccData.err.length()>0) && (tccData.err.length()==tccData.nFV.length())) { for (size_t k=0; k<tccData.err.length(); k++) { int err = tccData.err[k]; if (err>0) { MColor col(1.0, 1.0, 1.0); switch(err) { case 1: col = MColor(1.0, 0.0, 0.0); break; // bad topology / inconsistent eqc case 2: col = MColor(1.0, 0.0, 1.0); break; // mismatched itv case 3: col = MColor(0.0, 0.0, 1.0); break; // unassigned itvs case 4: col = MColor(0.5, 0.5, 1.0); break; // unassigned T-joint default: break; } stat = meshFn.setFaceColor(col, k); if (stat!=MS::kSuccess) { char bla[] = "bla"; stat.perror(bla); } } } } return stat; }
void UsdMayaGLSoftSelectHelper::_PopulateSoftSelectColorRamp() { // Since in we are not able to get the real distance/weight value, we don't // yet store the full color ramp. We just get the first color which at // least gives feedback over which things will be influenced. bool success = false; MString commandResult; // it's really unfortunate that we have to go through this instead of having // direct access to this. if (MGlobal::executeCommand("softSelect -query -softSelectColorCurve", commandResult)) { // parse only the first tuple. int interp; float r, g, b; float position; if (sscanf(commandResult.asChar(), "%f,%f,%f,%f,%d", &r, &g, &b, &position, &interp) == 5) { _wireColor = MColor(r,g,b); success = true; } } if (!success) { _wireColor = MColor(0.f, 0.f, 1.f); } }
sgBLocator_fromGeo::sgBLocator_fromGeo() { m_pointArr.setLength(6); m_pointArr[0] = MFloatPoint( 1, 0, 0 ); m_pointArr[1] = MFloatPoint( -1, 0, 0 ); m_pointArr[2] = MFloatPoint( 0, -1, 0 ); m_pointArr[3] = MFloatPoint( 0, 1, 0 ); m_pointArr[4] = MFloatPoint( 0, 0, 1 ); m_pointArr[5] = MFloatPoint( 0, 0, -1 ); m_boundingBox.clear(); m_boundingBox.expand( MVector( 1.0, 1.0, 1.0 ) ); m_boundingBox.expand( MVector( -1.0, -1.0, -1.0 ) ); m_colorActive = MColor( 1.0f, 1.0f, 1.0f ); m_colorLead = MColor( .26f, 1.0f, .64f ); m_colorDefault = MColor( 1.0f, 1.0f, 0.0f ); m_lineWidth = 1; MFnDependencyNode fnNode( thisMObject() ); MPlug plugOutput = fnNode.findPlug( aOutputValue ); MPlug plugVis =fnNode.findPlug( "v" ); MDGModifier dgModifier; dgModifier.connect( plugOutput, plugVis ); }
MayaMaterialSet::MayaMaterialSet() { m_defaultMaterial = new MayaMaterial(); m_defaultMaterial->m_type = MT_LAMBERT; m_defaultMaterial->m_name = "defaultLambert"; m_defaultMaterial->m_ambient = MColor(0,0,0,1); m_defaultMaterial->m_emissive = MColor(0,0,0,1); m_defaultMaterial->m_diffuse = MColor(0.5,0.5,0.5,1); }
// load a cgFx shader MStatus Material::loadCgFxShader(MFnDependencyNode *pShader) { m_type = MT_CGFX; // Create a default white lambert m_isTextured = false; m_isMultiTextured = false; m_diffuse = MColor(1.0,1.0,1.0,1.0); m_specular = MColor(0,0,0,1); m_emissive = MColor(0,0,0,1); m_ambient = MColor(0,0,0,1); return MS::kSuccess; }
// Clear data void Material::clear() { m_name = ""; m_type = MT_LAMBERT; m_lightingOff = false; m_isTransparent = false; m_isTextured = false; m_isMultiTextured = false; m_ambient = MColor(0,0,0,0); m_diffuse = MColor(0,0,0,0); m_specular = MColor(0,0,0,0); m_emissive = MColor(0,0,0,0); m_textures.clear(); }
void viewRenderUserOperation::addUIDrawables( MHWRender::MUIDrawManager& drawManager, const MHWRender::MFrameContext& frameContext ) { drawManager.beginDrawable(); drawManager.setColor( MColor( 0.95f, 0.5f, 0.1f ) ); drawManager.text( MPoint( 0, 2, 0 ), MString("UI draw test in user operation") ); drawManager.line( MPoint( 0, 0, 0), MPoint( 0, 2, 0 ) ); drawManager.setColor( MColor( 1.0f, 1.0f, 1.0f ) ); drawManager.sphere( MPoint( 0, 2, 0 ), 0.8, false ); drawManager.setColor( MColor( 0.95f, 0.5f, 0.1f, 0.4f ) ); drawManager.sphere( MPoint( 0, 2, 0 ), 0.8, true ); drawManager.endDrawable(); }
Texture2d::Texture2d(const MString& name, const MString& type) : MaterialNode(name, type) { createProperty("defaultColor", MaterialProperty::kRGB, DefaultColor); createProperty("outColor", MaterialProperty::kRGB, OutColor); createProperty("outAlpha", MaterialProperty::kFloat, OutAlpha); DefaultColor->setDefault(MColor(0.5f, 0.5f, 0.5f)); }
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); } }
// Load a lambert shader MStatus Material::loadLambert(MFnDependencyNode *pShader) { MPlugArray colorSrcPlugs; m_type = MT_LAMBERT; MFnLambertShader* pLambert = new MFnLambertShader(pShader->object()); // Check if material is textured pLambert->findPlug("color").connectedTo(colorSrcPlugs,true,false); for (int i=0; i<colorSrcPlugs.length(); i++) { if (colorSrcPlugs[i].node().hasFn(MFn::kFileTexture)) { m_isTextured = true; continue; } else if (colorSrcPlugs[i].node().hasFn(MFn::kLayeredTexture)) { m_isTextured = true; m_isMultiTextured = true; continue; } } // Check if material is transparent if (pLambert->findPlug("transparency").isConnected() || pLambert->transparency().r>0.0f) m_isTransparent = true; // Get material colours //diffuse colour if (m_isTextured) m_diffuse = MColor(1.0,1.0,1.0,1.0); else { m_diffuse = pLambert->color(); m_diffuse.a = 1.0 - pLambert->transparency().r; } //ambient colour m_ambient = pLambert->ambientColor(); //emissive colour m_emissive = pLambert->incandescence(); //specular colour m_specular = MColor(0,0,0,1); delete pLambert; return MS::kSuccess; }
// Load a surface shader MStatus Material::loadSurfaceShader(MFnDependencyNode *pShader) { m_type = MT_SURFACE_SHADER; MPlugArray colorSrcPlugs; // Check if material is textured pShader->findPlug("outColor").connectedTo(colorSrcPlugs,true,false); for (int i=0; i<colorSrcPlugs.length(); i++) { if (colorSrcPlugs[i].node().hasFn(MFn::kFileTexture)) { m_isTextured = true; continue; } else if (colorSrcPlugs[i].node().hasFn(MFn::kLayeredTexture)) { m_isTextured = true; m_isMultiTextured = true; continue; } } // Check if material is transparent float trasp; pShader->findPlug("outTransparencyR").getValue(trasp); if (pShader->findPlug("outTransparency").isConnected() || trasp>0.0f) m_isTransparent = true; // Get material colours if (m_isTextured) m_diffuse = MColor(1.0,1.0,1.0,1.0); else { pShader->findPlug("outColorR").getValue(m_diffuse.r); pShader->findPlug("outColorG").getValue(m_diffuse.g); pShader->findPlug("outColorB").getValue(m_diffuse.b); float trasp; pShader->findPlug("outTransparencyR").getValue(trasp); m_diffuse.a = 1.0 - trasp; } m_ambient = MColor(0,0,0,1); m_emissive = MColor(0,0,0,1); m_specular = MColor(0,0,0,1); return MS::kSuccess; }
JTLine::JTLine(int xx,int yy){ x=xx; y=yy; x2 = ofGetScreenWidth() * ofRandomuf(); y2 = ofGetScreenHeight() * ofRandomuf(); dest_x2 = ofGetScreenWidth() * ofRandomuf(); dest_y2 = ofGetScreenHeight() * ofRandomuf(); ticks=0; death = -1; color = MColor( ofRandomuf() * HALF_PI + PI, 0.5, 0.5, "HSB"); ballColor = MColor( ofRandomuf() * PI, 1.0f, 1.0f, "HSB"); lineWidth = ofRandomuf() * 10; ballSpeed = ofRandomuf() * 100.0f + 200; ballX = ballY = 0; x3 = y3 = x4 = y4 = 0; radius = lineWidth; pluckCounter = 0; }
void CreateMungos() { Coords c1( -1.0, 0.0 ); Coords c2( 1.0, 0.5 ); Coords d1( 0.5, 1.0 ); Coords d2( -.25, -1.0); Coords e1( 0.75, -0.5 ); Coords e2( 0.55, 0.65 ); MungoCPtr static1 = MungoFactory::CreateStaticMungo( c1 ); s_MungoManager.AddMungo( static1 ); s_MungoManager.AddMungo( MungoFactory::CreateStaticMungo( c2 ) ); MungoCPtr firstMover = MungoFactory::CreateLinearMungo( c1, c2, 1.0, 3.0 ); MungoCPtr secondMover = MungoFactory::CreateLinearMungo( d1, d2, 0.0, 10.0 ); MungoCPtr thirdMover = MungoFactory::CreateLinearMungo( e1, e2, 0.0, 5.0 ); secondMover->AssignColor( MColor( 0.7, 0.7, 0.7 ) ); thirdMover->AssignColor( MColor( 1.0, 0.4, 0.4 ) ); s_MungoManager.AddMungo( firstMover ); s_MungoManager.AddMungo( secondMover ); s_MungoManager.AddMungo( thirdMover ); s_MungoManager.AddMungo( MungoFactory::CreateTemporalOffset( firstMover, 0.4 ) ); s_MungoManager.AddMungo( MungoFactory::CreateTemporalOffset( firstMover, 0.8 ) ); MungoCPtr firstHalfway = MungoFactory::CreateHalfWayBetween( firstMover, secondMover); firstHalfway->AssignColor( MColor( 0.2, 0.4, 1.0 ) ); s_MungoManager.AddMungo( firstHalfway ); s_MungoManager.AddMungo( MungoFactory::CreateHalfWayBetween( firstMover, thirdMover)); MungoCPtr orbiter = MungoFactory::CreateOrbitAroundMungo(thirdMover, 0.25, 3.0); orbiter->AssignColor( MColor( 0.2, 1.0, 0.35 ) ); s_MungoManager.AddMungo( orbiter ); MungoCPtr orbiter2 = MungoFactory::CreateTemporalOffset( orbiter, -0.5 ); MungoCPtr orbiter3 = MungoFactory::CreateTemporalOffset( orbiter, -1.0 ); s_MungoManager.AddMungo( orbiter2 ); s_MungoManager.AddMungo( orbiter3 ); MungoCPtr metaorbiter = MungoFactory::CreateOrbitAroundMungo(orbiter, 0.1, 1.0); metaorbiter->AssignColor( MColor( 0.5, 0.1, 0.1 ) ); s_MungoManager.AddMungo( metaorbiter ); MungoCPtr crazyorbiter = MungoFactory::CreateCrazyOrbitAround(secondMover, 0.3, 2.0); crazyorbiter->AssignColor( MColor( 0.9, 0.9, 0.6 ) ); s_MungoManager.AddMungo( crazyorbiter ); MungoCPtr zinger = MungoFactory::CreateHalfWayBetween( crazyorbiter, static1); zinger->AssignColor( MColor( 1.0, 1.0, 1.0 ) ); s_MungoManager.AddMungo( zinger ); }
PhongMaterial::PhongMaterial(const MString& name, const MString& type) : LambertMaterial(name, type) { createProperty("cosinePower", MaterialProperty::kFloat, CosinePower); createProperty("specularColor", MaterialProperty::kRGB, SpecularColor); createProperty("reflectivity", MaterialProperty::kFloat, Reflectivity); createProperty("reflectedColor", MaterialProperty::kRGB, ReflectedColor); CosinePower->setDefault(20.0f); SpecularColor->setDefault(MColor(0.5f, 0.5f, 0.5f)); Reflectivity->setDefault(0.5f); }
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; }
Star::Star(ofVec2f p){ loaded = false; pos = p; ticks = 0; rad = 0.001;//+0.01 * ofRandomuf(); float randomVal = ofRandomuf(); color = MColor(randomVal*TWO_PI,1.0,1.0,"HSB"); char fname[64]; soundIndex = (int)(randomVal * 4); strength = 1; loaded = true; rotation = (ofRandomuf()-0.5) * 0.05; }
BlinnMaterial::BlinnMaterial(const MString& name, const MString& type) : LambertMaterial(name, type) { createProperty("eccentricity", MaterialProperty::kFloat, Eccentricity); createProperty("specularRollOff",MaterialProperty::kFloat, SpecularRollOff); createProperty("specularColor", MaterialProperty::kRGB, SpecularColor); createProperty("reflectivity", MaterialProperty::kFloat, Reflectivity); createProperty("reflectedColor", MaterialProperty::kRGB, ReflectedColor); Eccentricity->setDefault(0.3f); SpecularRollOff->setDefault(0.7f); SpecularColor->setDefault(MColor(0.5f, 0.5f, 0.5f)); Reflectivity->setDefault(0.5f); }
void SGNormalManip::draw( int manipIndex, bool hideMode ) { if (!intersector.exists) { return; } int lineWidth = 2; MColor color(0.1f, 0.1f, 0.9f); if (intersectType == SGNormalManipIntersector::kNormal) color = MColor(1.0f, 1.0f, 0.2f); if (!hideMode) { manip->pushLine(manipIndex, intersector.normalLine, color, 1); manip->pushShape(manipIndex, coneNormal.shape, intersector.coneMatrix, color); } else { GLushort linePattern = 0x5555; manip->pushLine(manipIndex, intersector.normalLine, color, 1, &linePattern ); } }
LambertMaterial::LambertMaterial(const MString& name, const MString& type) : SurfaceMaterial(name, type) { createProperty("color", MaterialProperty::kRGB, Color); createProperty("transparency", MaterialProperty::kRGB, Transparency); createProperty("ambientColor", MaterialProperty::kRGB, AmbientColor); createProperty("incandescence", MaterialProperty::kRGB, Incandescence); createProperty("diffuse", MaterialProperty::kFloat, Diffuse); createProperty("translucence", MaterialProperty::kFloat, Translucence); createProperty("translucenceDepth", MaterialProperty::kFloat, TranslucenceDepth); createProperty("translucenceFocus", MaterialProperty::kFloat, TranslucenceFocus); createProperty("hideSource", MaterialProperty::kBool, HideSource); createProperty("glowIntensity", MaterialProperty::kFloat, GlowIntensity); Color->setDefault(MColor(0.5f, 0.5f, 0.5f)); Diffuse->setDefault(0.8f); TranslucenceDepth->setDefault(0.5f); TranslucenceFocus->setDefault(0.5f); }
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; }
void sh_lua_syntax(const char *string, map<unsigned int, MColor> *coloring) { MEditor *editor = MEditor::getInstance(); MPreferences *pref = editor->getPreferences(); int mode = -1; // 0, comment, instruction, number, string, alphanum int i = 0; char *s = (char *)string; coloring->clear(); for (; *s; s++, i++) { int res; // comment if (mode == 1) { if (*s != '\n') continue; } else if (sh_compare_key(s, "--", 2)) { (*coloring)[i] = MColor(pref->getColor("lua comment")); mode = 1; s++; i++; continue; } // string if (mode == 4) { if (! sh_isquote(*s)) continue; else { mode = -1; continue; } } else if (sh_isquote(*s)) { (*coloring)[i] = MColor(pref->getColor("lua string")); mode = 4; continue; } // instruction res = sh_lua_instruction(s); if (mode != 5 && res > 0) { (*coloring)[i] = MColor(pref->getColor("lua instruction")); s += res - 1; i += res - 1; mode = 2; continue; } // alphanum if (mode == 5) { if (sh_isalnum_special(*s)) continue; } else if (sh_isalpha_special(*s)) { mode = 5; continue; } // number if (mode == 3) { if (sh_isdigit(*s)) continue; } else if (sh_isdigit(*s)) { (*coloring)[i] = MColor(pref->getColor("lua number")); mode = 3; continue; } // default if (mode != 0) { (*coloring)[i] = MColor(pref->getColor("lua default")); mode = 0; } } }
//! Caller is expected to delete the returned value static OpenSubdiv::Far::TopologyRefiner * gatherTopology( MFnMesh & inMeshFn, MItMeshPolygon & inMeshItPolygon, OpenSubdiv::Sdc::SchemeType type, OpenSubdiv::Sdc::Options options, bool * hasUVs, bool * hasColors, std::vector<MFloatArray> & uvSet_uCoords, std::vector<MFloatArray> & uvSet_vCoords, std::vector<MColorArray> & colorSet_colors, float * maxCreaseSharpness=0 ) { MStatus returnStatus; // Gather FVarData MStringArray uvSetNames; MStringArray colorSetNames; std::vector<int> colorSetChannels; std::vector<MFnMesh::MColorRepresentation> colorSetReps; int totalColorSetChannels = 0; returnStatus = getMayaFvarFieldParams(inMeshFn, uvSetNames, colorSetNames, colorSetChannels, colorSetReps, totalColorSetChannels); MWARNERR(returnStatus, "Failed to retrieve Maya face-varying parameters"); // Storage for UVs and ColorSets for face-vertex MIntArray fvArray; // face vertex array uvSet_uCoords.clear(); uvSet_uCoords.resize(uvSetNames.length()); uvSet_vCoords.clear(); uvSet_vCoords.resize(uvSetNames.length()); colorSet_colors.clear();colorSet_colors.resize(colorSetNames.length()); // Put the data in the format needed for OSD Descriptor desc; int numFaceVertices = inMeshFn.numFaceVertices(); desc.numVertices = inMeshFn.numVertices(); desc.numFaces = inMeshItPolygon.count(); int * vertsPerFace = new int[desc.numFaces], * vertIndices = new int[numFaceVertices]; desc.numVertsPerFace = vertsPerFace; desc.vertIndicesPerFace = vertIndices; // Create Topology for (inMeshItPolygon.reset(); !inMeshItPolygon.isDone(); inMeshItPolygon.next()) { inMeshItPolygon.getVertices(fvArray); int nverts = fvArray.length(); vertsPerFace[inMeshItPolygon.index()] = nverts; for (int i=0; i<nverts; ++i) { *vertIndices++ = fvArray[i]; } } // Add Face-Varying data to the descriptor Descriptor::FVarChannel * channels = NULL; *hasUVs = uvSet_uCoords.size() > 0 && uvSet_vCoords.size() > 0; *hasColors = colorSet_colors.size() > 0; // Note : Only supports 1 channel of UVs and 1 channel of color if (*hasUVs || *hasColors) { // Create 2 face-varying channel descriptor that will hold UVs and color desc.numFVarChannels = 2; channels = new Descriptor::FVarChannel[desc.numFVarChannels]; desc.fvarChannels = channels; int * uvIndices = new int[numFaceVertices]; channels[CHANNELUV].valueIndices = uvIndices; channels[CHANNELUV].numValues = 0; int * colorIndices = new int[numFaceVertices]; channels[CHANNELCOLOR].valueIndices = colorIndices; channels[CHANNELCOLOR].numValues = 0; // Obtain UV information if (*hasUVs) { inMeshFn.getUVs(uvSet_uCoords[0], uvSet_vCoords[0], &uvSetNames[0]); assert( uvSet_uCoords[0].length() == uvSet_vCoords[0].length() ); int uvId = 0, nUVs = 0; for (int faceIndex = 0; faceIndex < inMeshFn.numPolygons(); ++faceIndex) { int numVertices = inMeshFn.polygonVertexCount(faceIndex); for (int v = 0; v < numVertices; v++) { inMeshFn.getPolygonUVid(faceIndex, v, uvId, &uvSetNames[0]); uvIndices[nUVs++] = uvId; } } channels[CHANNELUV].numValues = uvSet_uCoords[0].length(); } // Obtain color information if (*hasColors) { inMeshFn.getColors(colorSet_colors[0], &colorSetNames[0]); int colorId = 0, nColors = 0; bool addDefaultColor = true; for (int faceIndex = 0; faceIndex < inMeshFn.numPolygons(); ++faceIndex) { int numVertices = inMeshFn.polygonVertexCount(faceIndex); for ( int v = 0 ; v < numVertices; v++ ) { inMeshFn.getColorIndex(faceIndex, v, colorId, &colorSetNames[0]); if (colorId == -1) { if (addDefaultColor) { addDefaultColor = false; colorSet_colors[0].append(MColor(1.0, 1.0, 1.0, 1.0)); } colorId = colorSet_colors[0].length() - 1; } colorIndices[nColors ++] = colorId; } } channels[CHANNELCOLOR].numValues = colorSet_colors[0].length(); } } // Apply Creases float maxEdgeCrease = getCreaseEdges( inMeshFn, desc ); float maxVertexCrease = getCreaseVertices( inMeshFn, desc ); OpenSubdiv::Far::TopologyRefiner * refiner = OpenSubdiv::Far::TopologyRefinerFactory<Descriptor>::Create(desc, OpenSubdiv::Far::TopologyRefinerFactory<Descriptor>::Options(type, options)); delete [] desc.numVertsPerFace; delete [] desc.vertIndicesPerFace; delete [] desc.creaseVertexIndexPairs; delete [] desc.creaseWeights; delete [] desc.cornerVertexIndices; delete [] desc.cornerWeights; if (*hasUVs || *hasColors) { for(int i = 0 ; i < desc.numFVarChannels ; i ++) { delete [] channels[i].valueIndices; } delete [] channels; } if (maxCreaseSharpness) { *maxCreaseSharpness = std::max(maxEdgeCrease, maxVertexCrease); } return refiner; }
MStatus Mesh::load(MDagPath& meshDag,MDagPath *pDagPath) { MStatus stat; std::vector<MFloatArray> weights; std::vector<MIntArray> Ids; std::vector<MIntArray> jointIds; unsigned int numJoints = 0; std::vector<vertexInfo> vertices; MFloatPointArray points; MFloatVectorArray normals; if (!meshDag.hasFn(MFn::kMesh)) return MS::kFailure; MFnMesh mesh(meshDag); /*{ mesh.getPoints(points,MSpace::kWorld); MPoint pos; mesh.getPoint(1,pos,MSpace::kWorld); for(unsigned i = 0;i < points.length();i++) { MFloatPoint fp = points[i]; float x = fp.x; float y = fp.y; float z = fp.z; fp = fp; } }*/ int numVertices = mesh.numVertices(); vertices.resize(numVertices); weights.resize(numVertices); Ids.resize(numVertices); jointIds.resize(numVertices); // 获取UV坐标集的名称 MStringArray uvsets; int numUVSets = mesh.numUVSets(); if (numUVSets > 0) { stat = mesh.getUVSetNames(uvsets); if (MS::kSuccess != stat) { std::cout << "Error retrieving UV sets names\n"; return MS::kFailure; } } // 保存UV集信息 for (int i=m_uvsets.size(); i<uvsets.length(); i++) { uvset uv; uv.size = 2; uv.name = uvsets[i].asChar(); m_uvsets.push_back(uv); } MStringArray colorSetsNameArray; m_colorSets.clear(); int numColorSets = mesh.numColorSets(); if (numColorSets > 0) { mesh.getColorSetNames(colorSetsNameArray); } for (int i = 0; i != colorSetsNameArray.length(); ++i) { std::string name = colorSetsNameArray[i].asChar(); m_colorSets.push_back(name); } // 检查法线是否反 bool opposite = false; mesh.findPlug("opposite",true).getValue(opposite); // get connected skin cluster (if present) bool foundSkinCluster = false; MItDependencyNodes kDepNodeIt( MFn::kSkinClusterFilter ); for( ;!kDepNodeIt.isDone() && !foundSkinCluster; kDepNodeIt.next()) { MObject kObject = kDepNodeIt.item(); m_pSkinCluster = new MFnSkinCluster(kObject); unsigned int uiNumGeometries = m_pSkinCluster->numOutputConnections(); for(unsigned int uiGeometry = 0; uiGeometry < uiNumGeometries; ++uiGeometry ) { unsigned int uiIndex = m_pSkinCluster->indexForOutputConnection(uiGeometry); MObject kOutputObject = m_pSkinCluster->outputShapeAtIndex(uiIndex); if(kOutputObject == mesh.object()) { foundSkinCluster = true; } else { delete m_pSkinCluster; m_pSkinCluster = NULL; } } // load connected skeleton (if present) if (m_pSkinCluster) { if (!m_pSkeleton) m_pSkeleton = new skeleton(); stat = m_pSkeleton->load(m_pSkinCluster); if (MS::kSuccess != stat) std::cout << "Error loading skeleton data\n"; } else { // breakable; } } // get connected shaders MObjectArray shaders; MIntArray shaderPolygonMapping; stat = mesh.getConnectedShaders(0,shaders,shaderPolygonMapping); if (MS::kSuccess != stat) { std::cout << "Error getting connected shaders\n"; return MS::kFailure; } if (shaders.length() <= 0) { std::cout << "No connected shaders, skipping mesh\n"; return MS::kFailure; } // create a series of arrays of faces for each different submesh std::vector<faceArray> polygonSets; polygonSets.resize(shaders.length()); // Get faces data // prepare vertex table for (int i=0; i<vertices.size(); i++) vertices[i].next = -2; //get vertex positions from mesh data mesh.getPoints(points,MSpace::kWorld); mesh.getNormals(normals,MSpace::kWorld); //get list of vertex weights if (m_pSkinCluster) { MItGeometry iterGeom(meshDag); for (int i=0; !iterGeom.isDone(); iterGeom.next(), i++) { weights[i].clear(); Ids[i].clear(); MObject component = iterGeom.component(); MFloatArray vertexWeights; stat=m_pSkinCluster->getWeights(meshDag,component,vertexWeights,numJoints); int nWeights = vertexWeights.length(); for(int j = 0;j<nWeights;j++) { if(vertexWeights[j] >= 0.00001f || vertexWeights[j] <= -0.00001f ) { // 记录该节点j Ids[i].append(j); weights[i].append(vertexWeights[j]); } } //weights[i]= vertexWeights; if (MS::kSuccess != stat) { std::cout << "Error retrieving vertex weights\n"; } // get ids for the joints if (m_pSkeleton) { jointIds[i].clear(); if(weights[i].length() > 0 ) { MDagPathArray influenceObjs; m_pSkinCluster->influenceObjects(influenceObjs,&stat); if (MS::kSuccess != stat) { std::cout << "Error retrieving influence objects for given skin cluster\n"; } jointIds[i].setLength(weights[i].length()); for (int j=0; j<jointIds[i].length(); j++) { bool foundJoint = false; for (int k=0; k<m_pSkeleton->getJoints().size() && !foundJoint; k++) { if (influenceObjs[Ids[i][j]].partialPathName() == m_pSkeleton->getJoints()[k].name) { foundJoint=true; jointIds[i][j] = m_pSkeleton->getJoints()[k].id; } } } } } } } // create an iterator to go through mesh polygons if (mesh.numPolygons() > 0) { const char *name = mesh.name().asChar(); MItMeshPolygon faceIter(mesh.object(),&stat); if (MS::kSuccess != stat) { std::cout << "Error accessing mesh polygons\n"; return MS::kFailure; } // iterate over mesh polygons for (; !faceIter.isDone(); faceIter.next()) { int numTris=0; faceIter.numTriangles(numTris); // for every triangle composing current polygon extract triangle info for (int iTris=0; iTris<numTris; iTris++) { MPointArray triPoints; MIntArray tempTriVertexIdx,triVertexIdx; int idx; // create a new face to store triangle info face newFace; // extract triangle vertex indices faceIter.getTriangle(iTris,triPoints,tempTriVertexIdx); // convert indices to face-relative indices MIntArray polyIndices; faceIter.getVertices(polyIndices); unsigned int iPoly, iObj; for (iObj=0; iObj < tempTriVertexIdx.length(); ++iObj) { // iPoly is face-relative vertex index for (iPoly=0; iPoly < polyIndices.length(); ++iPoly) { if (tempTriVertexIdx[iObj] == polyIndices[iPoly]) { triVertexIdx.append(iPoly); break; } } } // iterate over triangle's vertices for (int i=0; i<3; i++) { bool different = true; int vtxIdx = faceIter.vertexIndex(triVertexIdx[i]); int nrmIdx = faceIter.normalIndex(triVertexIdx[i]); // get vertex color MColor color; if (faceIter.hasColor(triVertexIdx[i])) { //This method gets the average color of the all the vertices in this face stat = faceIter.getColor(color,triVertexIdx[i]); if (MS::kSuccess != stat) { color = MColor(1,1,1,1); } if (color.r > 1) color.r = 1; if (color.g > 1) color.g = 1; if (color.b > 1) color.b = 1; if (color.a > 1) color.a = 1; } else { color = MColor(1,1,1,1); } if (vertices[vtxIdx].next == -2) // first time we encounter a vertex in this position { // save vertex position points[vtxIdx].cartesianize(); vertices[vtxIdx].pointIdx = vtxIdx; // save vertex normal vertices[vtxIdx].normalIdx = nrmIdx; // save vertex colour vertices[vtxIdx].r = color.r; vertices[vtxIdx].g = color.g; vertices[vtxIdx].b = color.b; vertices[vtxIdx].a = color.a; // save vertex texture coordinates vertices[vtxIdx].u.resize(uvsets.length()); vertices[vtxIdx].v.resize(uvsets.length()); // save vbas vertices[vtxIdx].vba.resize(weights[vtxIdx].length()); for (int j=0; j<weights[vtxIdx].length(); j++) { vertices[vtxIdx].vba[j] = (weights[vtxIdx])[j]; } // save joint ids vertices[vtxIdx].jointIds.resize(jointIds[vtxIdx].length()); for (int j=0; j<jointIds[vtxIdx].length(); j++) { vertices[vtxIdx].jointIds[j] = (jointIds[vtxIdx])[j]; } // save uv sets data for (int j=0; j<uvsets.length(); j++) { float2 uv; stat = faceIter.getUV(triVertexIdx[i],uv,&uvsets[j]); if (MS::kSuccess != stat) { uv[0] = 0; uv[1] = 0; } vertices[vtxIdx].u[j] = uv[0]; vertices[vtxIdx].v[j] = (-1)*(uv[1]-1); } // save vertex index in face info newFace.v[i] = vtxIdx; // update value of index to next vertex info (-1 means nothing next) vertices[vtxIdx].next = -1; } else // already found at least 1 vertex in this position { // check if a vertex with same attributes has been saved already for (int k=vtxIdx; k!=-1 && different; k=vertices[k].next) { different = false; MFloatVector n1 = normals[vertices[k].normalIdx]; MFloatVector n2 = normals[nrmIdx]; if (n1.x!=n2.x || n1.y!=n2.y || n1.z!=n2.z) { different = true; } if (vertices[k].r!=color.r || vertices[k].g!=color.g || vertices[k].b!= color.b || vertices[k].a!=color.a) { different = true; } for (int j=0; j<uvsets.length(); j++) { float2 uv; stat = faceIter.getUV(triVertexIdx[i],uv,&uvsets[j]); if (MS::kSuccess != stat) { uv[0] = 0; uv[1] = 0; } uv[1] = (-1)*(uv[1]-1); if (vertices[k].u[j]!=uv[0] || vertices[k].v[j]!=uv[1]) { different = true; } } idx = k; } // if no identical vertex has been saved, then save the vertex info if (different) { vertexInfo vtx; // save vertex position vtx.pointIdx = vtxIdx; // save vertex normal vtx.normalIdx = nrmIdx; // save vertex colour vtx.r = color.r; vtx.g = color.g; vtx.b = color.b; vtx.a = color.a; // save vertex vba vtx.vba.resize(weights[vtxIdx].length()); for (int j=0; j<weights[vtxIdx].length(); j++) { vtx.vba[j] = (weights[vtxIdx])[j]; } // save joint ids vtx.jointIds.resize(jointIds[vtxIdx].length()); for (int j=0; j<jointIds[vtxIdx].length(); j++) { vtx.jointIds[j] = (jointIds[vtxIdx])[j]; } // save vertex texture coordinates vtx.u.resize(uvsets.length()); vtx.v.resize(uvsets.length()); for (int j=0; j<uvsets.length(); j++) { float2 uv; stat = faceIter.getUV(triVertexIdx[i],uv,&uvsets[j]); if (MS::kSuccess != stat) { uv[0] = 0; uv[1] = 0; } vtx.u[j] = uv[0]; vtx.v[j] = (-1)*(uv[1]-1); } vtx.next = -1; vertices.push_back(vtx); // save vertex index in face info newFace.v[i] = vertices.size()-1; vertices[idx].next = vertices.size()-1; } else { newFace.v[i] = idx; } } } // end iteration of triangle vertices // add face info to the array corresponding to the submesh it belongs // skip faces with no shaders assigned if (shaderPolygonMapping[faceIter.index()] >= 0) polygonSets[shaderPolygonMapping[faceIter.index()]].push_back(newFace); } // end iteration of triangles } } std::cout << "done reading mesh triangles\n"; // create a submesh for every different shader linked to the mesh unsigned shaderLength = shaders.length(); for (int i=0; i<shaderLength; i++) { // check if the submesh has at least 1 triangle if (polygonSets[i].size() > 0) { //create new submesh SubMesh* pSubmesh = new SubMesh(); const char *nm = mesh.name().asChar(); const char *nm1 = mesh.partialPathName().asChar(); const char *nm2 = mesh.parentNamespace().asChar(); const char *nm3 = mesh.fullPathName().asChar(); const char *nm4 = meshDag.fullPathName().asChar(); pSubmesh->m_name = meshDag.partialPathName(); if(pDagPath) pSubmesh->m_name = pDagPath->partialPathName(); const char *szName = pSubmesh->m_name.asChar(); if(shaderLength > 1) { char a[256]; sprintf(a,"%d",i); pSubmesh->m_name += a; } OutputDebugString(pSubmesh->m_name.asChar()); OutputDebugString("\n"); //OutputDebugString(szName); //OutputDebugString("\n"); //load linked shader stat = pSubmesh->loadMaterial(shaders[i],uvsets); if (stat != MS::kSuccess) { MFnDependencyNode shadingGroup(shaders[i]); std::cout << "Error loading submesh linked to shader " << shadingGroup.name().asChar() << "\n"; return MS::kFailure; } //load vertex and face data stat = pSubmesh->load(polygonSets[i],vertices,points,normals,opposite); //add submesh to current mesh m_submeshes.push_back(pSubmesh); } } return MS::kSuccess; }
MStatus volumeLight::doIt( const MArgList& args ) { MStatus stat; double arc = 180.0f; double coneEndRadius = 0.0f; MFnVolumeLight::MLightDirection volumeLightDirection = MFnVolumeLight::kOutward; MFnVolumeLight::MLightShape lightShape = MFnVolumeLight::kConeVolume; bool emitAmbient = true; unsigned i; // Parse the arguments. for ( i = 0; i < args.length(); i++ ) { if ( MString( "-a" ) == args.asString( i, &stat ) && MS::kSuccess == stat) { double tmp = args.asDouble( ++i, &stat ); if ( MS::kSuccess == stat ) arc = tmp; } else if ( MString( "-c" ) == args.asString( i, &stat ) && MS::kSuccess == stat) { double tmp = args.asDouble( ++i, &stat ); if ( MS::kSuccess == stat ) coneEndRadius = tmp; } else if ( MString( "-e" ) == args.asString( i, &stat ) && MS::kSuccess == stat) { bool tmp = args.asBool( ++i, &stat ); if ( MS::kSuccess == stat ) emitAmbient = tmp; } } MFnVolumeLight light; light.create( true, &stat); cout<<"What's up?"; if ( MS::kSuccess != stat ) { cout<<"Error creating light."<<endl; return stat; } stat = light.setArc ((float)arc); if ( MS::kSuccess != stat ) { cout<<"Error setting \"arc\" attribute."<<endl; return stat; } stat = light.setVolumeLightDirection (volumeLightDirection); if ( MS::kSuccess != stat ) { cout<<"Error setting \"volumeLightDirection\" attribute."<<endl; return stat; } stat = light.setConeEndRadius ((float)coneEndRadius); if ( MS::kSuccess != stat ) { cout<<"Error setting \"coneEndRadius\" attribute."<<endl; return stat; } stat = light.setEmitAmbient (emitAmbient); if ( MS::kSuccess != stat ) { cout<<"Error setting \"emitAmbient\" attribute."<<endl; return stat; } stat = light.setLightShape (lightShape); if ( MS::kSuccess != stat ) { cout<<"Error setting \"lightShape\" attribute."<<endl; return stat; } double arcGet = light.arc (&stat); if ( MS::kSuccess != stat || arcGet != arc) { cout<<"Error getting \"arc\" attribute."<<endl; return stat; } MFnVolumeLight::MLightDirection volumeLightDirectionGet = light.volumeLightDirection (&stat); if ( MS::kSuccess != stat || volumeLightDirectionGet != volumeLightDirection) { cout<<"Error getting \"volumeLightDirection\" attribute."<<endl; return stat; } double coneEndRadiusGet = light.coneEndRadius (&stat); if ( MS::kSuccess != stat || coneEndRadiusGet != coneEndRadius) { cout<<"Error getting \"coneEndRadius\" attribute."<<endl; return stat; } bool emitAmbientGet = light.emitAmbient (&stat); if ( MS::kSuccess != stat || emitAmbientGet != emitAmbient) { cout<<"Error getting \"emitAmbient\" attribute."<<endl; return stat; } MFnVolumeLight::MLightShape lightShapeGet = light.lightShape (&stat); if ( MS::kSuccess != stat || lightShapeGet != lightShape) { cout<<"Error getting \"lightShape\" attribute."<<endl; return stat; } // Get reference to the penumbra ramp. MRampAttribute ramp = light.penumbraRamp (&stat); if ( MS::kSuccess != stat ) { cout<<"Error getting \"penumbraRamp\" attribute."<<endl; return stat; } MFloatArray a, b; MIntArray c,d; // Get the entries in the ramp ramp.getEntries (d, a, b, c, &stat); if ( MS::kSuccess != stat ) { cout<<"Error getting entries from \"penumbraRamp\" attribute."<<endl; return stat; } // There should be 2 entries by default. if (d.length() != 2) { cout<<"Invalid number of entries in \"penumbraRamp\" attribute."<<endl; return stat; } MFloatArray a1, b1; MIntArray c1; // Prepare an array of entries to add. // In this case we are just adding 1 more entry // at position 0.5 with a curve value of 0.25 and a linear interpolation. a1.append (0.5f); b1.append (0.25f); c1.append (MRampAttribute::kLinear); // Add it to the curve ramp ramp.addEntries (a1, b1, c1, &stat); if ( MS::kSuccess != stat) { cout<<"Error adding entries to \"penumbraRamp\" attribute."<<endl; return stat; } // Get the entries to make sure that the above add actually worked. MFloatArray a2, b2; MIntArray c2,d2; ramp.getEntries (d2, a2, b2, c2, &stat); if ( MS::kSuccess != stat ) { cout<<"Error getting entries from \"penumbraRamp\" attribute."<<endl; return stat; } if ( a.length() + a1.length() != a2.length()) { cout<<"Invalid number of entries in \"penumbraRamp\" attribute."<<endl; return stat; } // Now try to interpolate the value at a point float newVal = -1; ramp.getValueAtPosition(.3f, newVal, &stat); if ( MS::kSuccess != stat ) { cout<<"Error interpolating value from \"penumbraRamp\" attribute."<<endl; return stat; } if ( !EQUAL(newVal, .15f)) { cout<<"Invalid interpolation in \"penumbraRamp\" expected .15 got "<<newVal <<" ."<<endl; } // Try to delete an entry in an incorrect manner. // This delete will work because there is an entry at 0, // However we should never do it this way, because the entries // array can become sparse, so trying to delete an entry without // checking whether an entry exists at that index can cause a failure. MIntArray entriesToDelete; entriesToDelete.append (0); ramp.deleteEntries (entriesToDelete, &stat); if ( MS::kSuccess != stat ) { cout<<"Error deleting entries from \"penumbraRamp\" attribute."<<endl; return stat; } // Check to see whether the above delete worked. // As mentioned earlier it did work, but we shouldn't do it this way. // To illustrate why we shouldn't do it this way, we'll try to delete // entry at index 0 ( this no longer exists) ramp.getEntries (d2, a2, b2, c2, &stat); if ( a2.length() != 2) { cout<<"Invalid number of entries in \"penumbraRamp\" attribute."<<endl; return stat; } // Trying to delete entry at 0. entriesToDelete.clear(); entriesToDelete.append (0); ramp.deleteEntries (entriesToDelete, &stat); // It will fail because no entry exists. if ( MS::kSuccess == stat) { cout<<"Error deleting entries from \"penumbraRamp\" attribute."<<endl; return stat; } if ( a2.length() != 2) { cout<<"Invalid number of entries in \"penumbraRamp\" attribute."<<endl; return stat; } // The proper way to delete is to retrieve the index by calling "getEntries" ramp.getEntries (d2, a2, b2, c2, &stat); entriesToDelete.clear(); entriesToDelete.append (d2[0]); // Delete the first logical entry in the entry array. ramp.deleteEntries (entriesToDelete, &stat); if ( MS::kSuccess != stat) { cout<<"Error deleting entries from \"penumbraRamp\" attribute."<<endl; return stat; } // There should be only 1 entry left. ramp.getEntries (d2, a2, b2, c2, &stat); if ( MS::kSuccess != stat) { cout<<"Error getting entries from \"penumbraRamp\" attribute."<<endl; return stat; } entriesToDelete.clear(); entriesToDelete.append (d2[0]); // Can't delete the last entry, should return failure. ramp.deleteEntries (entriesToDelete, &stat); if ( MS::kSuccess == stat) { cout<<"Error deleting entries from \"penumbraRamp\" attribute."<<endl; return stat; } ramp.setPositionAtIndex (0.0f, d2[0], &stat); if ( MS::kSuccess != stat) { printf("Error setting position at index: %d, of \"penumbraRamp\" attribute.\n", d2[0]); return stat; } ramp.setValueAtIndex (1.0f, d2[0], &stat); if ( MS::kSuccess != stat) { printf("Error setting value at index: %d, of \"penumbraRamp\" attribute.\n", d2[0]); return stat; } ramp.setInterpolationAtIndex (MRampAttribute::kNone, d2[0], &stat); if ( MS::kSuccess != stat) { printf("Error setting interpolation at index: %d, of \"penumbraRamp\" attribute.\n", d2[0]); return stat; } MRampAttribute ramp2 = light.colorRamp (&stat); if ( MS::kSuccess != stat) { cout<<"Error getting \"colorRamp\" attribute."<<endl; return stat; } MFloatArray a3; MColorArray b3; MIntArray c3,d3; // Get the entries in the ramp ramp2.getEntries (d3, a3, b3, c3, &stat); if ( MS::kSuccess != stat) { cout<<"Error getting entries from \"colorRamp\" attribute."<<endl; return stat; } // There should be 2 entries by default. if ( d3.length() != 2) { cout<<"Invalid number of entries in \"colorRamp\" attribute."<<endl; return stat; } MFloatArray a4; MColorArray b4; MIntArray c4; // Prepare an array of entries to add. // In this case we are just adding 1 more entry // at position 0.5 withe curve value of 0.5 and a linear interpolation. a4.append (0.5f); b4.append (MColor (0.0f, 0.0f, 0.75f)); c4.append (MRampAttribute::kLinear); // Add it to the curve ramp ramp2.addEntries (a4, b4, c4, &stat); if ( MS::kSuccess != stat) { cout<<"Error adding entries to \"colorRamp\" attribute."<<endl; return stat; } // Get the entries to make sure that the above add actually worked. MFloatArray a5; MColorArray b5; MIntArray c5,d5; ramp2.getEntries (d5, a5, b5, c5, &stat); if ( MS::kSuccess != stat) { cout<<"Error getting entries from \"colorRamp\" attribute."<<endl; return stat; } if ( a3.length() + a4.length() != a5.length()) { cout<<"Invalid number of entries in \"colorRamp\" attribute."<<endl; return stat; } // Now try to interpolate the color at a point MColor newCol(0.0, 0.0, 0.0); ramp2.getColorAtPosition(.3f, newCol, &stat); if ( MS::kSuccess != stat ) { cout<<"Error interpolating color from \"penumbraRamp\" attribute."<<endl; return stat; } if ( !EQUAL(newCol[2], .45)) { cout<<"Invalid color interpolation in \"colorRamp\" expected .45 got "<<newCol[2]<<endl; } MColor clr (0.5, 0.5, 0.0); ramp2.setColorAtIndex (clr, d5[0], &stat); if ( MS::kSuccess != stat) { cout<<"Error setting color at index: "<<d5[0] <<", of \"colorRamp\" attribute."<<endl; return stat; } ramp2.setInterpolationAtIndex (MRampAttribute::kSpline, d5[1], &stat); if ( MS::kSuccess != stat) { cout<<"Error setting interpolation at index: "<<d5[1] <<", of \"colorRamp\" attribute."<<endl; return stat; } return stat; }
MStatus Point::initialize() { MFnNumericAttribute nAttr; input_display = nAttr.create("display", "display", MFnNumericData::kInt, 1); nAttr.setKeyable(true); nAttr.setMin(0); nAttr.setMax(1); addAttribute(input_display); input_box = nAttr.create("box", "box", MFnNumericData::kInt, 0); nAttr.setKeyable(true); nAttr.setMin(0); nAttr.setMax(1); addAttribute(input_box); input_cross = nAttr.create("cross", "cross", MFnNumericData::kInt, 1); nAttr.setKeyable(true); nAttr.setMin(0); nAttr.setMax(1); addAttribute(input_cross); input_tick = nAttr.create("tick", "tick", MFnNumericData::kInt, 0); nAttr.setKeyable(true); nAttr.setMin(0); nAttr.setMax(1); addAttribute(input_tick); input_axis = nAttr.create("axis", "axis", MFnNumericData::kInt, 0); nAttr.setKeyable(true); nAttr.setMin(0); nAttr.setMax(1); addAttribute(input_axis); MFnEnumAttribute eAttr; input_color = eAttr.create("color", "color", MFnData::kNumeric); eAttr.addField("Black", 0); eAttr.addField("Grey", 1); eAttr.addField("White", 2); eAttr.addField("Red", 3); eAttr.addField("Light red", 4); eAttr.addField("Dark red", 5); eAttr.addField("Green", 6); eAttr.addField("Light green", 7); eAttr.addField("Dark green", 8); eAttr.addField("Blue", 9); eAttr.addField("Light blue", 10); eAttr.addField("Dark blue", 11); eAttr.addField("Purple", 12); eAttr.addField("Magenta", 13); eAttr.addField("Brown", 14); eAttr.addField("Yellow", 15); eAttr.addField("Dark yellow", 16); eAttr.addField("Orange", 17); eAttr.setDefault(8); eAttr.setKeyable(true); eAttr.setStorable(true); addAttribute(input_color); colors.append(MColor(0.0f, 0.0f, 0.0f)); // black colors.append(MColor(0.5f, 0.5f, 0.5f)); // grey colors.append(MColor(1.0f, 1.0f, 1.0f)); // white colors.append(MColor(1.0f, 0.0f, 0.0f)); // red colors.append(MColor(1.0f, 0.6899999976158142f, 0.6899999976158142f)); // light_red colors.append(MColor(0.5f, 0.0f, 0.0f)); // dark_red colors.append(MColor(0.0f, 1.0f, 0.0f)); // green colors.append(MColor(0.5f, 1.0f, 0.5f)); // light_green colors.append(MColor(0.0f, 0.25f, 0.0f)); // dark_green colors.append(MColor(0.1889999955892563f, 0.6299999952316284f, 0.6299999952316284f)); // blue colors.append(MColor(0.3919999897480011f, 0.8629999756813049f, 1.0f)); // light_blue colors.append(MColor(0.0f, 0.01600000075995922f, 0.37599998712539673f)); // dark_blue colors.append(MColor(0.25f, 0.0f, 0.25f)); // purple colors.append(MColor(1.0f, 0.0f, 1.0f)); // magenta colors.append(MColor(0.75f, 0.2f, 0.0f)); // brown colors.append(MColor(1.0f, 1.0f, 0.0f)); // yellow colors.append(MColor(0.62117999792099f, 0.6299999952316284f, 0.1889999955892563f)); // dark_yellow colors.append(MColor(1.0f, 0.5f, 0.0f)); // orange return MS::kSuccess; }
MColor convert( const Imath::Color3f &from ) { return MColor( from[0], from[1], from[2], 1.0 ); }
// 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 ); }
void BasicLocator::draw(M3dView& view, const MDagPath&, M3dView::DisplayStyle style, M3dView::DisplayStatus status) { MPlug pDrawit(thisMObject(), aIsDrawing); bool drawItV; pDrawit.getValue(drawItV); if (drawItV == false) return; MPlug pTransparent(thisMObject(), aIsTransparent); MPlug pShapeColor(thisMObject(), aShapeColor); MPlug pShapeType(thisMObject(), aShapeType); float r, g, b, a; MObject color; //glStart view.beginGL(); //setup states glPushAttrib(GL_CURRENT_BIT); glDepthMask(GL_FALSE); //setup for draw colors for maya(active, lead etc) MColor solidColor, wireColor; switch (status) { case M3dView::kActive: //white solidColor = MColor(1.0f, 1.0f, 1.0f, 0.1f); break; case M3dView::kLead: //green solidColor = MColor(0.26f, 1.0f, 0.64f, 0.1f); break; case M3dView::kActiveAffected: // maya magenta solidColor = MColor(0.78f, 1.0f, 0.78f); break; case M3dView::kTemplate: // maya template gray solidColor = MColor(0.47f, 0.47f, 0.47f); break; case M3dView::kActiveTemplate: // maya selected template pink solidColor = MColor(1.0f, 0.47f, 0.47f); break; default: pShapeColor.getValue(color); MFnNumericData data(color); data.getData(r, g, b); pTransparent.getValue(a); if (a < 1.0f) { glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); } solidColor = MColor(r, g, b, a); //draw the solidColor glColor4f(solidColor.r, solidColor.g, solidColor.b, solidColor.a); } int sType; pShapeType.getValue(sType); switch (sType) { case 0: drawArrow(); case 1: drawDisc(1.0, 32, true); default : drawArrow(); } glDepthMask(GL_TRUE); glDisable(GL_BLEND); glPopAttrib(); view.endGL(); }
MColor convert( const Imath::Color4f &from ) { return MColor( from[0], from[1], from[2], from[3] ); }
void Point::draw(M3dView& view, const MDagPath& mdag_path, M3dView::DisplayStyle display_style, M3dView::DisplayStatus display_status) { MObject self = thisMObject(); int display = MPlug(self, input_display).asInt(); if (display == 0) { return; } int use_box = MPlug(self, input_box).asInt(); int use_cross = MPlug(self, input_cross).asInt(); int use_tick = MPlug(self, input_tick).asInt(); int use_axis = MPlug(self, input_axis).asInt(); int color_index = MPlug(self, input_color).asInt(); float tx = MPlug(self, Point::localPositionX).asFloat(); float ty = MPlug(self, Point::localPositionY).asFloat(); float tz = MPlug(self, Point::localPositionZ).asFloat(); float sx = MPlug(self, Point::localScaleX).asFloat(); float sy = MPlug(self, Point::localScaleY).asFloat(); float sz = MPlug(self, Point::localScaleZ).asFloat(); MColor color; switch (display_status) { case M3dView::kActive: color = MColor(1.0f, 1.0f, 1.0f); break; case M3dView::kLead: color = MColor(0.26f, 1.0f, 0.64f); break; case M3dView::kActiveAffected: color = MColor(0.783999979496f, 0.0f, 0.783999979496f); break; case M3dView::kTemplate: color = MColor(0.469999998808f, 0.469999998808f, 0.469999998808f); break; case M3dView::kActiveTemplate: color = MColor(1.0f, 0.689999997616f, 0.689999997616f); break; default: color = colors[color_index]; } view.beginGL(); if (use_axis == 1) { view.setDrawColor(MColor(1.0, 0, 0)); view.drawText("x", MPoint(sx + tx, ty, tz), M3dView::kCenter); view.setDrawColor(MColor(0, 1.0, 0)); view.drawText("y", MPoint(tx, sy + ty, tz), M3dView::kCenter); view.setDrawColor(MColor(0, 0, 1.0)); view.drawText("z", MPoint(tx, ty, sz + tz), M3dView::kCenter); } glPushAttrib(GL_CURRENT_BIT); glEnable(GL_BLEND); glBegin(GL_LINES); if (use_box == 1) { glColor3f(color.r, color.g, color.b); // Top glVertex3f(-sx + tx, sy + ty, -sz + tz); glVertex3f(sx + tx, sy + ty, -sz + tz); glVertex3f(sx + tx, sy + ty, -sz + tz); glVertex3f(sx + tx, sy + ty, sz + tz); glVertex3f(sx + tx, sy + ty, sz + tz); glVertex3f(-sx + tx, sy + ty, sz + tz); glVertex3f(-sx + tx, sy + ty, sz + tz); glVertex3f(-sx + tx, sy + ty, -sz + tz); // Bottom glVertex3f(-sx + tx, -sy + ty, -sz + tz); glVertex3f(sx + tx, -sy + ty, -sz + tz); glVertex3f(sx + tx, -sy + ty, -sz + tz); glVertex3f(sx + tx, -sy + ty, sz + tz); glVertex3f(sx + tx, -sy + ty, sz + tz); glVertex3f(-sx + tx, -sy + ty, sz + tz); glVertex3f(-sx + tx, -sy + ty, sz + tz); glVertex3f(-sx + tx, -sy + ty, -sz + tz); // Left glVertex3f(-sx + tx, -sy + ty, -sz + tz); glVertex3f(-sx + tx, sy + ty, -sz + tz); glVertex3f(-sx + tx, sy + ty, -sz + tz); glVertex3f(-sx + tx, sy + ty, sz + tz); glVertex3f(-sx + tx, sy + ty, sz + tz); glVertex3f(-sx + tx, -sy + ty, sz + tz); glVertex3f(-sx + tx, -sy + ty, sz + tz); glVertex3f(-sx + tx, -sy + ty, -sz + tz); // Right glVertex3f(sx + tx, -sy + ty, -sz + tz); glVertex3f(sx + tx, sy + ty, -sz + tz); glVertex3f(sx + tx, sy + ty, -sz + tz); glVertex3f(sx + tx, sy + ty, sz + tz); glVertex3f(sx + tx, sy + ty, sz + tz); glVertex3f(sx + tx, -sy + ty, sz + tz); glVertex3f(sx + tx, -sy + ty, sz + tz); glVertex3f(sx + tx, -sy + ty, -sz + tz); } if (use_cross == 1) { glColor3f(color.r, color.g, color.b); glVertex3f(tx, -sy + ty, tz); glVertex3f(tx, sy + ty, tz); glVertex3f(-sx + tx, ty, tz); glVertex3f(sx + tx, ty, tz); glVertex3f(tx, ty, -sz + tz); glVertex3f(tx, ty, sz + tz); } if (use_tick == 1) { glColor3f(color.r, color.g, color.b); glVertex3f((-sx*0.05f) + tx, (sy*0.05f) + ty, tz); glVertex3f((sx*0.05f) + tx, (-sy*0.05f) + ty, tz); glVertex3f((sx*0.05f) + tx, (sy*0.05f) + ty, tz); glVertex3f((-sx*0.05f) + tx, (-sy*0.05f) + ty, tz); glVertex3f(tx, (sy*0.05f) + ty, (-sz*0.05f) + tz); glVertex3f(tx, (-sy*0.05f) + ty, (sz*0.05f) + tz); glVertex3f(tx, (sy*0.05f) + ty, (sz*0.05f) + tz); glVertex3f(tx, (-sy*0.05f) + ty, (-sz*0.05f) + tz); glVertex3f((sx*0.05f) + tx, ty, (-sz*0.05f) + tz); glVertex3f((-sx*0.05f) + tx, ty, (sz*0.05f) + tz); glVertex3f((sx*0.05f) + tx, ty, (sz*0.05f) + tz); glVertex3f((-sx*0.05f) + tx, ty, (-sz*0.05f) + tz); } if (use_axis == 1) { glColor3f(color.r, color.g, color.b); if (display_status == M3dView::kDormant) { glColor3f(1.0f, 0.0f, 0.0f); } glVertex3f(tx, ty, tz); glVertex3f(sx + tx, ty, tz); if (display_status == M3dView::kDormant) { glColor3f(0.0f, 1.0f, 0.0f); } glVertex3f(tx, ty, tz); glVertex3f(tx, sy + ty, tz); if (display_status == M3dView::kDormant) { glColor3f(0.0f, 0.0f, 1.0f); } glVertex3f(tx, ty, tz); glVertex3f(tx, ty, sz + tz); } glEnd(); glDisable(GL_BLEND); glPopAttrib(); view.endGL(); }