void BaseShapeUI::getDrawRequests( const MDrawInfo & info, bool objectAndActiveOnly, MDrawRequestQueue & requests ) { MStatus status; MDrawData data; BaseShape *shape = (BaseShape *) surfaceShape(); MDrawRequest request = info.getPrototype(*this); M3dView view = info.view(); getDrawData(shape, data); request.setDrawData(data); MDagPath path = request.multiPath(); MMaterial material = MPxSurfaceShapeUI::material(path); if (!(status = material.evaluateMaterial(view, path))) status.perror("MMaterial::evaluateMaterial"); if (!(status = material.evaluateDiffuse())) status.perror("MMaterial::evaluateDiffuse"); request.setMaterial(material); request.setToken(info.displayStyle()); requests.add(request); }
/// \todo We should be firing off a separate drawRequest for the components, then we can be done with the "hiliteGroups" mechanism. void ProceduralHolderUI::getDrawRequests( const MDrawInfo &info, bool objectAndActiveOnly, MDrawRequestQueue &requests ) { // it's easy if noone want to look at us if( !info.objectDisplayStatus( M3dView::kDisplayMeshes ) ) { return; } // the node we're meant to be drawing ProceduralHolder *proceduralHolder = (ProceduralHolder *)surfaceShape(); // draw data encapsulating that node MDrawData drawData; getDrawData( proceduralHolder, drawData ); // a request for the bound if necessary MPlug pDrawBound( proceduralHolder->thisMObject(), ProceduralHolder::aDrawBound ); bool drawBound = true; pDrawBound.getValue( drawBound ); if( drawBound ) { MDrawRequest request = info.getPrototype( *this ); request.setDrawData( drawData ); request.setToken( BoundDrawMode ); request.setDisplayStyle( M3dView::kWireFrame ); setWireFrameColors( request, info.displayStatus() ); requests.add( request ); } // requests for the scene if necessary MPlug pGLPreview( proceduralHolder->thisMObject(), ProceduralHolder::aGLPreview ); bool glPreview = false; pGLPreview.getValue( glPreview ); if( glPreview ) { if( info.displayStyle()==M3dView::kGouraudShaded || info.displayStyle()==M3dView::kFlatShaded ) { // make a request for solid drawing with a material MDrawRequest solidRequest = info.getPrototype( *this ); solidRequest.setDrawData( drawData ); MDagPath path = info.multiPath(); M3dView view = info.view(); MMaterial material = MPxSurfaceShapeUI::material( path ); if( !material.evaluateMaterial( view, path ) ) { MString pathName = path.fullPathName(); IECore::msg( IECore::Msg::Warning, "ProceduralHolderUI::getDrawRequests", boost::format( "Failed to evaluate material for \"%s\"." ) % pathName.asChar() ); } if( material.materialIsTextured() ) { material.evaluateTexture( drawData ); } solidRequest.setMaterial( material ); // set the transparency request. we don't have a decent way of finding out // if shaders applied by the procedural are transparent, so we've got a transparency // attribute on the procedural holder for users to use. maya materials may also say // they're transparent. if either asks for transparency then we'll ask for it here bool transparent = false; material.getHasTransparency( transparent ); if( !transparent ) { MPlug pT( proceduralHolder->thisMObject(), ProceduralHolder::aTransparent ); bool transparent = false; pT.getValue( transparent ); } solidRequest.setIsTransparent( transparent ); solidRequest.setToken( SceneDrawMode ); requests.add( solidRequest ); // and add another request for wireframe drawing if we're selected if( info.displayStatus()==M3dView::kActive || info.displayStatus()==M3dView::kLead || info.displayStatus()==M3dView::kHilite ) { MDrawRequest wireRequest = info.getPrototype( *this ); wireRequest.setDrawData( drawData ); wireRequest.setDisplayStyle( M3dView::kWireFrame ); wireRequest.setToken( SceneDrawMode ); setWireFrameColors( wireRequest, info.displayStatus() ); wireRequest.setComponent( MObject::kNullObj ); if ( !objectAndActiveOnly ) { if ( proceduralHolder->hasActiveComponents() ) { MObjectArray components = proceduralHolder->activeComponents(); MObject component = components[0]; // Should filter list wireRequest.setComponent( component ); } } requests.add( wireRequest ); } } else { MDrawRequest request = info.getPrototype( *this ); request.setDrawData( drawData ); setWireFrameColors( request, info.displayStatus() ); request.setToken( SceneDrawMode ); request.setComponent( MObject::kNullObj ); if ( !objectAndActiveOnly ) { if ( proceduralHolder->hasActiveComponents() ) { MObjectArray components = proceduralHolder->activeComponents(); MObject component = components[0]; // Should filter list request.setComponent( component ); } } requests.add( request ); } } }
/* override */ void apiSimpleShapeUI::getDrawRequests( const MDrawInfo & info, bool objectAndActiveOnly, MDrawRequestQueue & queue ) // // Description: // // Add draw requests to the draw queue // // Arguments: // // info - current drawing state // objectsAndActiveOnly - no components if true // queue - queue of draw requests to add to // { // Get the data necessary to draw the shape // MDrawData data; apiSimpleShape* shape = (apiSimpleShape*) surfaceShape(); MVectorArray* geomPtr = shape->getControlPoints(); // This call creates a prototype draw request that we can fill // in and then add to the draw queue. // MDrawRequest request = info.getPrototype( *this ); // Stuff our data into the draw request, it'll be used when the drawing // actually happens getDrawData( geomPtr, data ); request.setDrawData( data ); // Decode the draw info and determine what needs to be drawn // M3dView::DisplayStyle appearance = info.displayStyle(); M3dView::DisplayStatus displayStatus = info.displayStatus(); switch ( appearance ) { case M3dView::kWireFrame : { request.setToken( kDrawWireframe ); M3dView::ColorTable activeColorTable = M3dView::kActiveColors; M3dView::ColorTable dormantColorTable = M3dView::kDormantColors; switch ( displayStatus ) { case M3dView::kLead : request.setColor( LEAD_COLOR, activeColorTable ); break; case M3dView::kActive : request.setColor( ACTIVE_COLOR, activeColorTable ); break; case M3dView::kActiveAffected : request.setColor( ACTIVE_AFFECTED_COLOR, activeColorTable ); break; case M3dView::kDormant : request.setColor( DORMANT_COLOR, dormantColorTable ); break; case M3dView::kHilite : request.setColor( HILITE_COLOR, activeColorTable ); break; default: break; } queue.add( request ); break; } case M3dView::kGouraudShaded : { // Create the smooth shaded draw request // request.setToken( kDrawSmoothShaded ); // Need to get the material info // MDagPath path = info.multiPath(); // path to your dag object M3dView view = info.view();; // view to draw to MMaterial material = MPxSurfaceShapeUI::material( path ); // Evaluate the material and if necessary, the texture. // if ( ! material.evaluateMaterial( view, path ) ) { cerr << "Couldnt evaluate\n"; } bool drawTexture = true; if ( drawTexture && material.materialIsTextured() ) { material.evaluateTexture( data ); } request.setMaterial( material ); // request.setDisplayStyle( appearance ); bool materialTransparent = false; material.getHasTransparency( materialTransparent ); if ( materialTransparent ) { request.setIsTransparent( true ); } queue.add( request ); // create a draw request for wireframe on shaded if // necessary. // if ( (displayStatus == M3dView::kActive) || (displayStatus == M3dView::kLead) || (displayStatus == M3dView::kHilite) ) { MDrawRequest wireRequest = info.getPrototype( *this ); wireRequest.setDrawData( data ); wireRequest.setToken( kDrawWireframeOnShaded ); wireRequest.setDisplayStyle( M3dView::kWireFrame ); M3dView::ColorTable activeColorTable = M3dView::kActiveColors; switch ( displayStatus ) { case M3dView::kLead : wireRequest.setColor( LEAD_COLOR, activeColorTable ); break; case M3dView::kActive : wireRequest.setColor( ACTIVE_COLOR, activeColorTable ); break; case M3dView::kHilite : wireRequest.setColor( HILITE_COLOR, activeColorTable ); break; default : break; } queue.add( wireRequest ); } break; } case M3dView::kFlatShaded : request.setToken( kDrawFlatShaded ); break; default: break; } // Add draw requests for components // if ( !objectAndActiveOnly ) { // Inactive components // if ( (appearance == M3dView::kPoints) || (displayStatus == M3dView::kHilite) ) { MDrawRequest vertexRequest = info.getPrototype( *this ); vertexRequest.setDrawData( data ); vertexRequest.setToken( kDrawVertices ); vertexRequest.setColor( DORMANT_VERTEX_COLOR, M3dView::kActiveColors ); queue.add( vertexRequest ); } // Active components // if ( surfaceShape()->hasActiveComponents() ) { MDrawRequest activeVertexRequest = info.getPrototype( *this ); activeVertexRequest.setDrawData( data ); activeVertexRequest.setToken( kDrawVertices ); activeVertexRequest.setColor( ACTIVE_VERTEX_COLOR, M3dView::kActiveColors ); MObjectArray clist = surfaceShape()->activeComponents(); MObject vertexComponent = clist[0]; // Should filter list activeVertexRequest.setComponent( vertexComponent ); queue.add( activeVertexRequest ); } } }
/* 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; }
void SceneShapeUI::getDrawRequests( const MDrawInfo &info, bool objectAndActiveOnly, MDrawRequestQueue &requests ) { // it's easy if no one want to look at us if( !info.objectDisplayStatus( M3dView::kDisplayMeshes ) ) { return; } // the node we're meant to be drawing SceneShape *sceneShape = (SceneShape *)surfaceShape(); if( !sceneShape->getSceneInterface() ) { return; } // draw data encapsulating that node MDrawData drawData; getDrawData( sceneShape, drawData ); // a request for the bound if necessary MPlug pDrawBound( sceneShape->thisMObject(), SceneShape::aDrawRootBound ); bool drawBound; pDrawBound.getValue( drawBound ); if( drawBound ) { bool doDrawBound = true; // If objectOnly is true, check for an object. If none found, no need to add the bound request. MPlug pObjectOnly( sceneShape->thisMObject(), SceneShape::aObjectOnly ); bool objectOnly; pObjectOnly.getValue( objectOnly ); if( objectOnly && !sceneShape->getSceneInterface()->hasObject() ) { doDrawBound = false; } if( doDrawBound ) { MDrawRequest request = info.getPrototype( *this ); request.setDrawData( drawData ); request.setToken( BoundDrawMode ); request.setDisplayStyle( M3dView::kWireFrame ); setWireFrameColors( request, info.displayStatus() ); requests.add( request ); } } MPlug pDrawAllBounds( sceneShape->thisMObject(), SceneShape::aDrawChildBounds ); bool drawAllBounds = false; pDrawAllBounds.getValue( drawAllBounds ); // requests for the scene if necessary MPlug pGLPreview( sceneShape->thisMObject(), SceneShape::aDrawGeometry ); bool glPreview; pGLPreview.getValue( glPreview ); if( glPreview || drawAllBounds ) { if( info.displayStyle()==M3dView::kGouraudShaded || info.displayStyle()==M3dView::kFlatShaded ) { // make a request for solid drawing with a material MDrawRequest solidRequest = info.getPrototype( *this ); solidRequest.setDrawData( drawData ); MDagPath path = info.multiPath(); M3dView view = info.view(); MMaterial material = MPxSurfaceShapeUI::material( path ); if( !material.evaluateMaterial( view, path ) ) { MString pathName = path.fullPathName(); IECore::msg( IECore::Msg::Warning, "SceneShapeUI::getDrawRequests", boost::format( "Failed to evaluate material for \"%s\"." ) % pathName.asChar() ); } if( material.materialIsTextured() ) { material.evaluateTexture( drawData ); } solidRequest.setMaterial( material ); // set the transparency request. we don't have a decent way of finding out // if shaders applied by the procedural are transparent, so we've got a transparency // attribute on the procedural holder for users to use. maya materials may also say // they're transparent. if either asks for transparency then we'll ask for it here bool transparent = false; material.getHasTransparency( transparent ); solidRequest.setIsTransparent( transparent ); solidRequest.setToken( SceneDrawMode ); requests.add( solidRequest ); if( info.displayStatus()==M3dView::kActive || info.displayStatus()==M3dView::kLead || info.displayStatus()==M3dView::kHilite ) { MDrawRequest wireRequest = info.getPrototype( *this ); wireRequest.setDrawData( drawData ); wireRequest.setDisplayStyle( M3dView::kWireFrame ); wireRequest.setToken( SceneDrawMode ); setWireFrameColors( wireRequest, info.displayStatus() ); wireRequest.setComponent( MObject::kNullObj ); if ( !objectAndActiveOnly ) { if ( sceneShape->hasActiveComponents() ) { MObjectArray components = sceneShape->activeComponents(); MObject component = components[0]; wireRequest.setComponent( component ); } } requests.add( wireRequest ); } } else { MDrawRequest request = info.getPrototype( *this ); request.setDrawData( drawData ); setWireFrameColors( request, info.displayStatus() ); request.setToken( SceneDrawMode ); request.setComponent( MObject::kNullObj ); if ( !objectAndActiveOnly ) { if ( sceneShape->hasActiveComponents() ) { MObjectArray components = sceneShape->activeComponents(); MObject component = components[0]; request.setComponent( component ); } } requests.add( request ); } } }