void BaseShapeUI::draw( const MDrawRequest & request, M3dView & view ) const { if (s_drawData.failure) return; MStatus status; view.beginGL(); if (!s_drawData.initialized) initializeDraw(); BaseShape *shape = (BaseShape *) surfaceShape(); Model::Base base(MFnDagNode(shape->thisMObject()).parent(0, &status)); if (!status) { status.perror("MFnDagNode::parent"); return; } //MDagPath path = request.multiPath(); MMaterial material = request.material(); MColor color, borderColor; if (!(status = material.getDiffuse(color))) { status.perror("MMaterial::getDiffuse"); return; } bool wireframe = (M3dView::DisplayStyle) request.token() == M3dView::kWireFrame; if (wireframe) { glPushAttrib(GL_POLYGON_BIT); glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); } glUseProgram(s_drawData.program); switch (request.displayStatus()) { case M3dView::kLead : borderColor = view.colorAtIndex( LEAD_COLOR); //glUniform1f(s_drawData.border_uniform, 1.0f); s_drawData.updateBorderUniform(1.0f); //glUniform3f(s_drawData.borderColor_uniform, borderColor.r, borderColor.g, borderColor.b); s_drawData.updateBorderColorUniform(borderColor.r, borderColor.g, borderColor.b); break; case M3dView::kActive : borderColor = view.colorAtIndex( ACTIVE_COLOR); //glUniform1f(s_drawData.border_uniform, 1.0f); s_drawData.updateBorderUniform(1.0f); //glUniform3f(s_drawData.borderColor_uniform, borderColor.r, borderColor.g, borderColor.b); s_drawData.updateBorderColorUniform(borderColor.r, borderColor.g, borderColor.b); break; case M3dView::kActiveAffected : borderColor = view.colorAtIndex( ACTIVE_AFFECTED_COLOR); //glUniform1f(s_drawData.border_uniform, 0.0f); s_drawData.updateBorderUniform(0.0f); break; case M3dView::kDormant : borderColor = view.colorAtIndex( DORMANT_COLOR, M3dView::kDormantColors); //glUniform1f(s_drawData.border_uniform, 0.0f); s_drawData.updateBorderUniform(0.0f); break; case M3dView::kHilite : borderColor = view.colorAtIndex( HILITE_COLOR); //glUniform1f(s_drawData.border_uniform, 1.0f); s_drawData.updateBorderUniform(1.0f); //glUniform3f(s_drawData.borderColor_uniform, borderColor.r, borderColor.g, borderColor.b); s_drawData.updateBorderColorUniform(borderColor.r, borderColor.g, borderColor.b); break; } //glUniform3f(s_drawData.color_uniform, color.r, color.g, color.b); s_drawData.updateColorUniform(color.r, color.g, color.b); glCallList(s_drawData.display_list); if (wireframe) glPopAttrib(); view.endGL(); }
/* virtual */ MStatus pnTriangles::bind(const MDrawRequest& request, M3dView& view) // // Description: // This bind demonstrates the usage of internal material // and texture properties. This shader must be connected // to the "hardwareShader" attribute of a lambert derived // shader. // { // Setup the view view.beginGL(); glPushAttrib( GL_ALL_ATTRIB_BITS ); glPushClientAttrib(GL_CLIENT_VERTEX_ARRAY_BIT); MColor diffuse(1.0F, 1.0F, 0.0F, 1.0F); MColor specular(1.0F, 1.0F, 1.0F, 1.0F); MColor emission(0.0F, 0.0F, 0.0F, 1.0F); MColor ambient(0.2F, 0.2F, 0.2F, 1.0F); // Get the diffuse and specular colors // float shininess; bool hasTransparency = false; MMaterial material = request.material(); fInTexturedMode = material.materialIsTextured(); // Setting this to true will get the default "green" material back // since it will try and evaluate this shader, which internally // Maya does not understand -> thus giving the "green" material back bool useInternalMaterialSetting = false; if (!useInternalMaterialSetting) { material.getEmission( emission ); material.getSpecular( specular ); shininess = 13.0; } material.getHasTransparency( hasTransparency ); if (!fInTexturedMode) { if (!fTestVertexProgram && !useInternalMaterialSetting) material.getDiffuse( diffuse ); } // In textured mode. Diffuse material is always white // for texture blends else { if (!useInternalMaterialSetting) diffuse.r = diffuse.g = diffuse.b = diffuse.a = 1.0; } // Use a vertex program to set up shading // if (fTestVertexProgram) { bindVertexProgram(diffuse, specular, emission, ambient); } else if (fTestFragmentProgram) { bindFragmentProgram(); } // Don't use a vertex program to set up shading // else { // Set up the material state // glEnable(GL_COLOR_MATERIAL); glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT); glColor4fv(&ambient.r); if (fInTexturedMode) { glEnable( GL_TEXTURE_2D ); MDrawData drawData = request.drawData(); material.applyTexture( view, drawData ); float scaleS, scaleT, translateS, translateT, rotate; material.getTextureTransformation(scaleS, scaleT, translateS, translateT, rotate); rotate = DEG_TO_RAD(-rotate); float c = cosf(rotate); float s = sinf(rotate); translateS += ((c+s)/2.0F); translateT += ((c-s)/2.0F); glMatrixMode(GL_TEXTURE); glPushMatrix(); glLoadIdentity(); if(scaleS != 1.0f || scaleT != 1.0f) glScalef(1.0f/scaleS, 1.0f/scaleT, 1.0f); if(translateS != 0.0f || translateT != 0.0f) glTranslatef(0.5f-translateS, 0.5f-translateT, 0.0f); else glTranslatef(0.5f, 0.5f, 0.0f); if(rotate != 0.0f) glRotatef(-rotate, 0.0f, 0.0f, 1.0f); glMatrixMode(GL_MODELVIEW); } if (!useInternalMaterialSetting) { glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE); glColor4fv(&diffuse.r); glColorMaterial(GL_FRONT_AND_BACK, GL_SPECULAR); glColor4fv(&specular.r); glColorMaterial(GL_FRONT_AND_BACK, GL_EMISSION); glColor4fv(&emission.r); glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, shininess); } else { const MDagPath dagPath = request.multiPath(); material.evaluateMaterial( view, dagPath ); material.setMaterial(dagPath, hasTransparency); } } // Do PN triangles in hardware, or do nothing // if LOD = 0 if (fExtensionSupported[kPNTriangesEXT] || (fSubdivisions == 0)) { if (fSubdivisions != 0) { glEnable( GL_PN_TRIANGLES_ATI ); // Set point mode // if (fPointMode == kPointLinear) glPNTrianglesiATI( GL_PN_TRIANGLES_POINT_MODE_ATI, GL_PN_TRIANGLES_POINT_MODE_LINEAR_ATI); else glPNTrianglesiATI( GL_PN_TRIANGLES_POINT_MODE_ATI, GL_PN_TRIANGLES_POINT_MODE_CUBIC_ATI); // Set normal mode // if (fNormalMode == kNormalLinear) glPNTrianglesiATI( GL_PN_TRIANGLES_NORMAL_MODE_ATI, GL_PN_TRIANGLES_NORMAL_MODE_LINEAR_ATI); else glPNTrianglesiATI( GL_PN_TRIANGLES_NORMAL_MODE_ATI, GL_PN_TRIANGLES_NORMAL_MODE_QUADRATIC_ATI); // Set tessellation level // glPNTrianglesiATI( GL_PN_TRIANGLES_TESSELATION_LEVEL_ATI, fSubdivisions ); } } view.endGL(); return MS::kSuccess; }