private void drawUVMapCoordNum(apiMeshGeom geom, M3dView view, MTextureEditorDrawInfo info, bool drawNumbers) // // Description: // Draw the UV points for all uvs on this surface shape. // { view.beginGL(); float[] ptSize = new float[1]; OpenGL.glGetFloatv(OpenGL.GL_POINT_SIZE, ptSize); OpenGL.glPointSize(UV_POINT_SIZE); int uv; uint uv_len = geom.uvcoords.uvcount(); for (uv = 0; uv < uv_len; uv++) { float du = 0.0f; float dv = 0.0f; geom.uvcoords.getUV(uv, ref du, ref dv); drawUVMapCoord(view, uv, du, dv, drawNumbers); } OpenGL.glPointSize(ptSize[0]); view.endGL(); }
// for userInteraction example code // public void drawRedPointAtCenter(MDrawRequest request, M3dView view) // // Description: // // Simple very fast draw routine // // Arguments: // // request - request to be drawn // view - view to draw into // { // Draw point // view.beginGL(); // save state // OpenGL.glPushAttrib(OpenGL.GL_CURRENT_BIT | OpenGL.GL_POINT_BIT); OpenGL.glPointSize(20.0f); OpenGL.glBegin(OpenGL.GL_POINTS); OpenGL.glColor3f(1.0f, 0.0f, 0.0f); OpenGL.glVertex3f(0.0f, 0.0f, 0.0f); OpenGL.glEnd(); // restore state // OpenGL.glPopAttrib(); view.endGL(); }
private void drawUVWireframe(apiMeshGeom geom, M3dView view, MTextureEditorDrawInfo info) // // Description: // Draws the UV layout in wireframe mode. // { view.beginGL(); // Draw the polygons // int vid = 0; int vid_start = 0; for (int i = 0; i < geom.faceCount; i++) { OpenGL.glBegin(OpenGL.GL_LINES); uint v; float du1 = 0.0f; float dv1 = 0.0f; float du2 = 0.0f; float dv2 = 0.0f; int uvId1, uvId2; vid_start = vid; for (v = 0; v < geom.face_counts[i] - 1; v++) { uvId1 = geom.uvcoords.uvId(vid); uvId2 = geom.uvcoords.uvId(vid + 1); geom.uvcoords.getUV(uvId1, ref du1, ref dv1); geom.uvcoords.getUV(uvId2, ref du2, ref dv2); OpenGL.glVertex3f(du1, dv1, 0.0f); OpenGL.glVertex3f(du2, dv2, 0.0f); vid++; } uvId1 = geom.uvcoords.uvId(vid); uvId2 = geom.uvcoords.uvId(vid_start); geom.uvcoords.getUV(uvId1, ref du1, ref dv1); geom.uvcoords.getUV(uvId2, ref du2, ref dv2); OpenGL.glVertex3f(du1, dv1, 0.0f); OpenGL.glVertex3f(du2, dv2, 0.0f); vid++; OpenGL.glEnd(); } view.endGL(); }
public override void draw(M3dView view, MDagPath path, M3dView.DisplayStyle style, M3dView.DisplayStatus status) { base.draw(view, path, style, status); // view.beginGL(); //MPoint textPos = new MPoint(nodeTranslation()); MPoint textPos = new MPoint(0, 0, 0); String distanceText = "Two custom line manipulators"; view.drawText(distanceText, textPos, M3dView.TextPosition.kLeft); // view.endGL(); }
// // Description: // // Wireframe drawing routine // // Arguments: // // request - request to be drawn // view - view to draw into // ///////////////////////////////////////////////////////////////////// // // Helper routines // ///////////////////////////////////////////////////////////////////// public void drawWireframe( MDrawRequest request, M3dView view ) { MDrawData data = request.drawData(); apiMeshGeom geom = (apiMeshGeom)data.geometry(); if (geom == null) return; int token = request.token; bool wireFrameOnShaded = false; if ((int)DrawToken.kDrawWireframeOnShaded == token) { wireFrameOnShaded = true; } view.beginGL(); // Query current state so it can be restored // bool lightingWasOn = OpenGL.glIsEnabled(OpenGL.GL_LIGHTING) != 0; if ( lightingWasOn ) { OpenGL.glDisable(OpenGL.GL_LIGHTING); } if ( wireFrameOnShaded ) { OpenGL.glDepthMask(0); } // Draw the wireframe mesh // int vid = 0; for ( int i=0; i<geom.faceCount; i++ ) { OpenGL.glBegin(OpenGL.GL_LINE_LOOP); for ( int v=0; v<geom.face_counts[i]; v++ ) { MPoint vertex = geom.vertices[ geom.face_connects[vid++] ]; OpenGL.glVertex3f((float)vertex[0], (float)vertex[1], (float)vertex[2]); } OpenGL.glEnd(); } // Restore the state // if ( lightingWasOn ) { OpenGL.glEnable(OpenGL.GL_LIGHTING); } if ( wireFrameOnShaded ) { OpenGL.glDepthMask(1); } view.endGL(); }
// // Description: // // Component (vertex) drawing routine // // Arguments: // // request - request to be drawn // view - view to draw into // public void drawVertices( MDrawRequest request, M3dView view ) { MDrawData data = request.drawData(); apiMeshGeom geom = (apiMeshGeom)data.geometry(); if (geom == null) return; view.beginGL(); // Query current state so it can be restored // bool lightingWasOn = OpenGL.glIsEnabled(OpenGL.GL_LIGHTING) != 0; if ( lightingWasOn ) { OpenGL.glDisable(OpenGL.GL_LIGHTING); } float[] lastPointSize = new float[1]; OpenGL.glGetFloatv(OpenGL.GL_POINT_SIZE, lastPointSize); // Set the point size of the vertices // OpenGL.glPointSize(POINT_SIZE); // If there is a component specified by the draw request // then loop over comp (using an MFnComponent class) and draw the // active vertices, otherwise draw all vertices. // MObject comp = request.component; if ( ! comp.isNull ) { MFnSingleIndexedComponent fnComponent = new MFnSingleIndexedComponent( comp ); for ( int i=0; i<fnComponent.elementCount; i++ ) { int index = fnComponent.element( i ); OpenGL.glBegin(OpenGL.GL_POINTS); MPoint vertex = geom.vertices[ index ]; OpenGL.glVertex3f((float)vertex[0], (float)vertex[1], (float)vertex[2] ); OpenGL.glEnd(); string annotation = index.ToString(); view.drawText( annotation, vertex ); } } else { int vid = 0; for ( int i=0; i<geom.faceCount; i++ ) { OpenGL.glBegin(OpenGL.GL_POINTS); for ( int v=0; v<geom.face_counts[i]; v++ ) { MPoint vertex = geom.vertices[ geom.face_connects[vid++] ]; OpenGL.glVertex3f((float)vertex[0], (float)vertex[1], (float)vertex[2] ); } OpenGL.glEnd(); } } // Restore the state // if ( lightingWasOn ) { OpenGL.glEnable(OpenGL.GL_LIGHTING); } OpenGL.glPointSize(lastPointSize[0]); view.endGL(); }
// // Description: // // Shaded drawing routine // // Arguments: // // request - request to be drawn // view - view to draw into // public void drawShaded( MDrawRequest request, M3dView view ) { MDrawData data = request.drawData(); apiMeshGeom geom = (apiMeshGeom)data.geometry(); if (geom == null) return; view.beginGL(); OpenGL.glEnable(OpenGL.GL_POLYGON_OFFSET_FILL); // Set up the material // MMaterial material = request.material; material.setMaterial( request.multiPath, request.isTransparent ); // Enable texturing ... // // Note, Maya does not enable texturing if useDefaultMaterial is enabled. // However, you can choose to ignore this in your draw routine. // bool drawTexture = material.materialIsTextured && !view.usingDefaultMaterial; if (drawTexture) { OpenGL.glEnable(OpenGL.GL_TEXTURE_2D); } // Apply the texture to the current view // if ( drawTexture ) { material.applyTexture( view, data ); } // Draw the polygons // int vid = 0; uint uv_len = geom.uvcoords.uvcount(); for ( int i=0; i<geom.faceCount; i++ ) { OpenGL.glBegin(OpenGL.GL_POLYGON); for ( int v=0; v < geom.face_counts[i]; v++ ) { MPoint vertex = geom.vertices[ geom.face_connects[vid] ]; MVector normal = geom.normals[ geom.face_connects[vid] ]; if (uv_len > 0) { // If we are drawing the texture, make sure the coord // arrays are in bounds. if ( drawTexture ) { int uvId1 = geom.uvcoords.uvId(vid); if ( uvId1 < uv_len ) { float tu = 0.0f; float tv = 0.0f; geom.uvcoords.getUV( uvId1, ref tu, ref tv ); OpenGL.glTexCoord2f( tu, tv ); } } } OpenGL.glNormal3f((float)normal[0], (float)normal[1], (float)normal[2]); OpenGL.glVertex3f((float)vertex[0], (float)vertex[1], (float)vertex[2]); vid++; } OpenGL.glEnd(); } // Turn off texture mode // if (drawTexture) { OpenGL.glDisable(OpenGL.GL_TEXTURE_2D); } view.endGL(); }
public void drawVertices(MDrawRequest request, M3dView view) { MDrawData data = request.drawData(); MVectorArray geom = data.geometry() as MVectorArray; view.beginGL(); // Query current state so it can be restored // bool lightingWasOn = OpenGL.glIsEnabled(OpenGL.GL_LIGHTING) != 0 ? true : false; if (lightingWasOn) { OpenGL.glDisable(OpenGL.GL_LIGHTING); } float lastPointSize; getLastPointSize(out lastPointSize); // Set the point size of the vertices // OpenGL.glPointSize(POINT_SIZE); // If there is a component specified by the draw request // then loop over comp (using an MFnComponent class) and draw the // active vertices, otherwise draw all vertices. // MObject comp = request.component; if (!comp.isNull) { MFnSingleIndexedComponent fnComponent = new MFnSingleIndexedComponent(comp); for (int i = 0; i < fnComponent.elementCount; i++) { int index = fnComponent.element(i); OpenGL.glBegin(OpenGL.GL_POINTS); MVector point = geom[index]; OpenGL.glVertex3f((float)point[0], (float)point[1], (float)point[2]); OpenGL.glEnd(); MPoint mp = new MPoint(point); view.drawText(String.Format("{0}", index), mp); } } else { for (int i = 0; i < geom.length; i++) { OpenGL.glBegin(OpenGL.GL_POINTS); MVector point = geom[i]; OpenGL.glVertex3f((float)point[0], (float)point[1], (float)point[2]); OpenGL.glEnd(); } } // Restore the state // if (lightingWasOn) { OpenGL.glEnable(OpenGL.GL_LIGHTING); } OpenGL.glPointSize(lastPointSize); view.endGL(); }
// // From the given draw request, get the draw data and determine // which quadric to draw and with what values. // public override void draw(MDrawRequest request, M3dView view) { MDrawData data = request.drawData(); quadricGeom geom = data.geometry() as quadricGeom; DrawShapeStyle token = (DrawShapeStyle)request.token; bool drawTexture = false; view.beginGL(); if ((token == DrawShapeStyle.kDrawSmoothShaded) || (token == DrawShapeStyle.kDrawFlatShaded)) { OpenGL.glEnable((uint)OpenGL.GL_POLYGON_OFFSET_FILL); // Set up the material // MMaterial material = request.material; material.setMaterial(request.multiPath, request.isTransparent); // Enable texturing // drawTexture = material.materialIsTextured; if (drawTexture) OpenGL.glEnable((uint)OpenGL.GL_TEXTURE_2D); // Apply the texture to the current view // if (drawTexture) { material.applyTexture(view, data); } } IntPtr qobj = GLUFunctionInvoker.gluNewQuadric(); switch (token) { case DrawShapeStyle.kDrawWireframe: case DrawShapeStyle.kDrawWireframeOnShaded: GLUFunctionInvoker.gluQuadricDrawStyle(qobj, GLU_LINE); break; case DrawShapeStyle.kDrawSmoothShaded: GLUFunctionInvoker.gluQuadricNormals(qobj, GLU_SMOOTH); GLUFunctionInvoker.gluQuadricTexture(qobj, GLtrue); GLUFunctionInvoker.gluQuadricDrawStyle(qobj, GLU_FILL); break; case DrawShapeStyle.kDrawFlatShaded: GLUFunctionInvoker.gluQuadricNormals(qobj, GLU_FLAT); GLUFunctionInvoker.gluQuadricTexture(qobj, GLtrue); GLUFunctionInvoker.gluQuadricDrawStyle(qobj, GLU_FILL); break; } switch (geom.shapeType) { case (short)DrawShapeType.kDrawCylinder: GLUFunctionInvoker.gluCylinder(qobj, geom.radius1, geom.radius2, geom.height, geom.slices, geom.stacks); break; case (short)DrawShapeType.kDrawDisk: GLUFunctionInvoker.gluDisk(qobj, geom.radius1, geom.radius2, geom.slices, geom.loops); break; case (short)DrawShapeType.kDrawPartialDisk: GLUFunctionInvoker.gluPartialDisk(qobj, geom.radius1, geom.radius2, geom.slices, geom.loops, geom.startAngle, geom.sweepAngle); break; case (short)DrawShapeType.kDrawSphere: default: GLUFunctionInvoker.gluSphere(qobj, geom.radius1, geom.slices, geom.stacks); break; } // Turn off texture mode // if (drawTexture) OpenGL.glDisable((uint)OpenGL.GL_TEXTURE_2D); view.endGL(); }
public override void draw(M3dView view, MDagPath path, M3dView.DisplayStyle style, M3dView.DisplayStatus status) { // Are we in the right view MDagPath dpath = new MDagPath(); view.getCamera(dpath); MFnCamera viewCamera = new MFnCamera(dpath); string nameBuffer = viewCamera.name; if (nameBuffer == null) return; if (nameBuffer.IndexOf("persp") == -1 && nameBuffer.IndexOf("front") == -1) return; // bool rightLine = !affectTranslate; // Populate the point arrays which are in local space MPoint top = lineGeometry.topPoint(); MPoint bottom = lineGeometry.bottomPoint(); // Depending on what's active, we modify the // end points with mouse deltas in local // space uint active = 0; try { glActiveName(ref active); } catch (System.Exception) { return; } if (active == lineName && active != 0) { top[0] += (float)mousePointGlName.x; top[1] += (float)mousePointGlName.y; top[2] += (float)mousePointGlName.z; bottom[0] += (float)mousePointGlName.x; bottom[1] += (float)mousePointGlName.y; bottom[2] += (float)mousePointGlName.z; } // Begin the drawing view.beginGL(); // Get the starting value of the pickable items uint glPickableItem = 0; glFirstHandle(ref glPickableItem); // Top lineName = glPickableItem; // Place before you draw the manipulator component that can // be pickable. colorAndName(view, glPickableItem, true, mainColor()); OpenGL.glBegin((uint)libOpenMayaRenderNet.MGL_LINES); OpenGL.glVertex3d(top.x, top.y, top.z); OpenGL.glVertex3d(bottom.x, bottom.y, bottom.z); OpenGL.glEnd(); // End the drawing view.endGL(); }
public void drawBoundingBox(MDrawRequest request, M3dView view) // // Description: // // Bounding box drawing routine // // Arguments: // // request - request to be drawn // view - view to draw into // { // Get the surface shape MPxSurfaceShape shape = (MPxSurfaceShape)surfaceShape; if (shape == null) { return; } // Get the bounding box MBoundingBox box = shape.boundingBox(); float w = (float)box.width; float h = (float)box.height; float d = (float)box.depth; view.beginGL(); // Below we just two sides and then connect // the edges together MPoint minVertex = box.min; // Draw first side OpenGL.glBegin(OpenGL.GL_LINE_LOOP); MPoint vertex = minVertex; OpenGL.glVertex3f((float)vertex[0], (float)vertex[1], (float)vertex[2]); OpenGL.glVertex3f((float)vertex[0] + w, (float)vertex[1], (float)vertex[2]); OpenGL.glVertex3f((float)vertex[0] + w, (float)vertex[1] + h, (float)vertex[2]); OpenGL.glVertex3f((float)vertex[0], (float)vertex[1] + h, (float)vertex[2]); OpenGL.glVertex3f((float)vertex[0], (float)vertex[1], (float)vertex[2]); OpenGL.glEnd(); // Draw second side MVector sideFactor = new MVector(0, 0, d); MPoint vertex2 = minVertex.plus(sideFactor); OpenGL.glBegin(OpenGL.GL_LINE_LOOP); OpenGL.glVertex3f((float)vertex2[0], (float)vertex2[1], (float)vertex2[2]); OpenGL.glVertex3f((float)vertex2[0] + w, (float)vertex2[1], (float)vertex2[2]); OpenGL.glVertex3f((float)vertex2[0] + w, (float)vertex2[1] + h, (float)vertex2[2]); OpenGL.glVertex3f((float)vertex2[0], (float)vertex2[1] + h, (float)vertex2[2]); OpenGL.glVertex3f((float)vertex2[0], (float)vertex2[1], (float)vertex2[2]); OpenGL.glEnd(); // Connect the edges together OpenGL.glBegin(OpenGL.GL_LINES); OpenGL.glVertex3f((float)vertex2[0], (float)vertex2[1], (float)vertex2[2]); OpenGL.glVertex3f((float)vertex[0], (float)vertex[1], (float)vertex[2]); OpenGL.glVertex3f((float)vertex2[0] + w, (float)vertex2[1], (float)vertex2[2]); OpenGL.glVertex3f((float)vertex[0] + w, (float)vertex[1], (float)vertex[2]); OpenGL.glVertex3f((float)vertex2[0] + w, (float)vertex2[1] + h, (float)vertex2[2]); OpenGL.glVertex3f((float)vertex[0] + w, (float)vertex[1] + h, (float)vertex[2]); OpenGL.glVertex3f((float)vertex2[0], (float)vertex2[1] + h, (float)vertex2[2]); OpenGL.glVertex3f((float)vertex[0], (float)vertex[1] + h, (float)vertex[2]); OpenGL.glEnd(); view.endGL(); }
public void drawVertices(MDrawRequest request, M3dView view) // // Description: // // Component (vertex) drawing routine // // Arguments: // // request - request to be drawn // view - view to draw into // { MDrawData data = request.drawData(); apiMeshGeom geom = (apiMeshGeom)data.geometry(); if (geom == null) { return; } view.beginGL(); // Query current state so it can be restored // bool lightingWasOn = OpenGL.glIsEnabled(OpenGL.GL_LIGHTING) != 0; if (lightingWasOn) { OpenGL.glDisable(OpenGL.GL_LIGHTING); } float[] lastPointSize = new float[1]; OpenGL.glGetFloatv(OpenGL.GL_POINT_SIZE, lastPointSize); // Set the point size of the vertices // OpenGL.glPointSize(POINT_SIZE); // If there is a component specified by the draw request // then loop over comp (using an MFnComponent class) and draw the // active vertices, otherwise draw all vertices. // MObject comp = request.component; if (!comp.isNull) { MFnSingleIndexedComponent fnComponent = new MFnSingleIndexedComponent(comp); for (int i = 0; i < fnComponent.elementCount; i++) { int index = fnComponent.element(i); OpenGL.glBegin(OpenGL.GL_POINTS); MPoint vertex = geom.vertices[index]; OpenGL.glVertex3f((float)vertex[0], (float)vertex[1], (float)vertex[2]); OpenGL.glEnd(); string annotation = index.ToString(); view.drawText(annotation, vertex); } } else { int vid = 0; for (int i = 0; i < geom.faceCount; i++) { OpenGL.glBegin(OpenGL.GL_POINTS); for (int v = 0; v < geom.face_counts[i]; v++) { MPoint vertex = geom.vertices[geom.face_connects[vid++]]; OpenGL.glVertex3f((float)vertex[0], (float)vertex[1], (float)vertex[2]); } OpenGL.glEnd(); } } // Restore the state // if (lightingWasOn) { OpenGL.glEnable(OpenGL.GL_LIGHTING); } OpenGL.glPointSize(lastPointSize[0]); view.endGL(); }
public void drawShaded(MDrawRequest request, M3dView view) // // Description: // // Shaded drawing routine // // Arguments: // // request - request to be drawn // view - view to draw into // { MDrawData data = request.drawData(); apiMeshGeom geom = (apiMeshGeom)data.geometry(); if (geom == null) { return; } view.beginGL(); OpenGL.glEnable(OpenGL.GL_POLYGON_OFFSET_FILL); // Set up the material // MMaterial material = request.material; material.setMaterial(request.multiPath, request.isTransparent); // Enable texturing ... // // Note, Maya does not enable texturing if useDefaultMaterial is enabled. // However, you can choose to ignore this in your draw routine. // bool drawTexture = material.materialIsTextured && !view.usingDefaultMaterial; if (drawTexture) { OpenGL.glEnable(OpenGL.GL_TEXTURE_2D); } // Apply the texture to the current view // if (drawTexture) { material.applyTexture(view, data); } // Draw the polygons // int vid = 0; uint uv_len = geom.uvcoords.uvcount(); for (int i = 0; i < geom.faceCount; i++) { OpenGL.glBegin(OpenGL.GL_POLYGON); for (int v = 0; v < geom.face_counts[i]; v++) { MPoint vertex = geom.vertices[geom.face_connects[vid]]; MVector normal = geom.normals[geom.face_connects[vid]]; if (uv_len > 0) { // If we are drawing the texture, make sure the coord // arrays are in bounds. if (drawTexture) { int uvId1 = geom.uvcoords.uvId(vid); if (uvId1 < uv_len) { float tu = 0.0f; float tv = 0.0f; geom.uvcoords.getUV(uvId1, ref tu, ref tv); OpenGL.glTexCoord2f(tu, tv); } } } OpenGL.glNormal3f((float)normal[0], (float)normal[1], (float)normal[2]); OpenGL.glVertex3f((float)vertex[0], (float)vertex[1], (float)vertex[2]); vid++; } OpenGL.glEnd(); } // Turn off texture mode // if (drawTexture) { OpenGL.glDisable(OpenGL.GL_TEXTURE_2D); } view.endGL(); }
///////////////////////////////////////////////////////////////////// // // Helper routines // ///////////////////////////////////////////////////////////////////// public void drawWireframe(MDrawRequest request, M3dView view) // // Description: // // Wireframe drawing routine // // Arguments: // // request - request to be drawn // view - view to draw into // { MDrawData data = request.drawData(); apiMeshGeom geom = (apiMeshGeom)data.geometry(); if (geom == null) { return; } int token = request.token; bool wireFrameOnShaded = false; if ((int)DrawToken.kDrawWireframeOnShaded == token) { wireFrameOnShaded = true; } view.beginGL(); // Query current state so it can be restored // bool lightingWasOn = OpenGL.glIsEnabled(OpenGL.GL_LIGHTING) != 0; if (lightingWasOn) { OpenGL.glDisable(OpenGL.GL_LIGHTING); } if (wireFrameOnShaded) { OpenGL.glDepthMask(0); } // Draw the wireframe mesh // int vid = 0; for (int i = 0; i < geom.faceCount; i++) { OpenGL.glBegin(OpenGL.GL_LINE_LOOP); for (int v = 0; v < geom.face_counts[i]; v++) { MPoint vertex = geom.vertices[geom.face_connects[vid++]]; OpenGL.glVertex3f((float)vertex[0], (float)vertex[1], (float)vertex[2]); } OpenGL.glEnd(); } // Restore the state // if (lightingWasOn) { OpenGL.glEnable(OpenGL.GL_LIGHTING); } if (wireFrameOnShaded) { OpenGL.glDepthMask(1); } view.endGL(); }
// // Description: // Draw the UV points for all uvs on this surface shape. // private void drawUVMapCoordNum( apiMeshGeom geom, M3dView view, MTextureEditorDrawInfo info, bool drawNumbers) { view.beginGL(); float[] ptSize = new float[1]; OpenGL.glGetFloatv(OpenGL.GL_POINT_SIZE, ptSize); OpenGL.glPointSize(UV_POINT_SIZE); int uv; uint uv_len = geom.uvcoords.uvcount(); for ( uv = 0; uv < uv_len; uv ++ ) { float du = 0.0f; float dv = 0.0f; geom.uvcoords.getUV( uv, ref du, ref dv ); drawUVMapCoord( view, uv, du, dv, drawNumbers ); } OpenGL.glPointSize(ptSize[0]); view.endGL(); }
// // Description: // Draws the UV layout in wireframe mode. // private void drawUVWireframe( apiMeshGeom geom, M3dView view, MTextureEditorDrawInfo info) { view.beginGL(); // Draw the polygons // int vid = 0; int vid_start = 0; for ( int i=0; i<geom.faceCount; i++ ) { OpenGL.glBegin(OpenGL.GL_LINES); uint v; float du1 = 0.0f; float dv1 = 0.0f; float du2 = 0.0f; float dv2 = 0.0f; int uvId1, uvId2; vid_start = vid; for ( v=0; v<geom.face_counts[i]-1; v++ ) { uvId1 = geom.uvcoords.uvId(vid); uvId2 = geom.uvcoords.uvId(vid + 1); geom.uvcoords.getUV( uvId1, ref du1, ref dv1 ); geom.uvcoords.getUV( uvId2, ref du2, ref dv2 ); OpenGL.glVertex3f( du1, dv1, 0.0f ); OpenGL.glVertex3f( du2, dv2, 0.0f ); vid++; } uvId1 = geom.uvcoords.uvId(vid); uvId2 = geom.uvcoords.uvId(vid_start); geom.uvcoords.getUV( uvId1, ref du1, ref dv1 ); geom.uvcoords.getUV( uvId2, ref du2, ref dv2 ); OpenGL.glVertex3f(du1, dv1, 0.0f); OpenGL.glVertex3f(du2, dv2, 0.0f); vid ++ ; OpenGL.glEnd(); } view.endGL(); }
public override void draw(M3dView view, MDagPath path, M3dView.DisplayStyle style, M3dView.DisplayStatus status) { base.draw(view, path, style, status); // view.beginGL(); //MPoint textPos = new MPoint(nodeTranslation()); MPoint textPos = new MPoint(0,0,0); String distanceText = "Two custom line manipulators"; view.drawText(distanceText, textPos, M3dView.TextPosition.kLeft); // view.endGL(); }
// // Description: // // Bounding box drawing routine // // Arguments: // // request - request to be drawn // view - view to draw into // public void drawBoundingBox( MDrawRequest request, M3dView view ) { // Get the surface shape MPxSurfaceShape shape = (MPxSurfaceShape)surfaceShape; if ( shape == null ) return; // Get the bounding box MBoundingBox box = shape.boundingBox(); float w = (float) box.width; float h = (float) box.height; float d = (float) box.depth; view.beginGL(); // Below we just two sides and then connect // the edges together MPoint minVertex = box.min; // Draw first side OpenGL.glBegin(OpenGL.GL_LINE_LOOP); MPoint vertex = minVertex; OpenGL.glVertex3f((float)vertex[0], (float)vertex[1], (float)vertex[2]); OpenGL.glVertex3f((float)vertex[0] + w, (float)vertex[1], (float)vertex[2]); OpenGL.glVertex3f((float)vertex[0] + w, (float)vertex[1] + h, (float)vertex[2]); OpenGL.glVertex3f((float)vertex[0], (float)vertex[1] + h, (float)vertex[2]); OpenGL.glVertex3f((float)vertex[0], (float)vertex[1], (float)vertex[2]); OpenGL.glEnd(); // Draw second side MVector sideFactor = new MVector(0, 0, d); MPoint vertex2 = minVertex.plus( sideFactor ); OpenGL.glBegin(OpenGL.GL_LINE_LOOP); OpenGL.glVertex3f((float)vertex2[0], (float)vertex2[1], (float)vertex2[2]); OpenGL.glVertex3f((float)vertex2[0] + w, (float)vertex2[1], (float)vertex2[2]); OpenGL.glVertex3f((float)vertex2[0] + w, (float)vertex2[1] + h, (float)vertex2[2]); OpenGL.glVertex3f((float)vertex2[0], (float)vertex2[1] + h, (float)vertex2[2]); OpenGL.glVertex3f((float)vertex2[0], (float)vertex2[1], (float)vertex2[2]); OpenGL.glEnd(); // Connect the edges together OpenGL.glBegin(OpenGL.GL_LINES); OpenGL.glVertex3f((float)vertex2[0], (float)vertex2[1], (float)vertex2[2]); OpenGL.glVertex3f((float)vertex[0], (float)vertex[1], (float)vertex[2]); OpenGL.glVertex3f((float)vertex2[0] + w, (float)vertex2[1], (float)vertex2[2]); OpenGL.glVertex3f((float)vertex[0] + w, (float)vertex[1], (float)vertex[2]); OpenGL.glVertex3f((float)vertex2[0] + w, (float)vertex2[1] + h, (float)vertex2[2]); OpenGL.glVertex3f((float)vertex[0] + w, (float)vertex[1] + h, (float)vertex[2]); OpenGL.glVertex3f((float)vertex2[0], (float)vertex2[1] + h, (float)vertex2[2]); OpenGL.glVertex3f((float)vertex[0], (float)vertex[1] + h, (float)vertex[2]); OpenGL.glEnd(); view.endGL(); }
public override void draw(M3dView view, MDagPath path, M3dView.DisplayStyle style, M3dView.DisplayStatus status) { // Are we in the right view MDagPath dpath = new MDagPath(); view.getCamera(dpath); MFnCamera viewCamera = new MFnCamera(dpath); string nameBuffer = viewCamera.name; if (nameBuffer == null) { return; } if (nameBuffer.IndexOf("persp") == -1 && nameBuffer.IndexOf("front") == -1) { return; } // bool rightLine = !affectTranslate; // Populate the point arrays which are in local space MPoint top = lineGeometry.topPoint(); MPoint bottom = lineGeometry.bottomPoint(); // Depending on what's active, we modify the // end points with mouse deltas in local // space uint active = 0; try { glActiveName(ref active); } catch (System.Exception) { return; } if (active == lineName && active != 0) { top[0] += (float)mousePointGlName.x; top[1] += (float)mousePointGlName.y; top[2] += (float)mousePointGlName.z; bottom[0] += (float)mousePointGlName.x; bottom[1] += (float)mousePointGlName.y; bottom[2] += (float)mousePointGlName.z; } // Begin the drawing view.beginGL(); // Get the starting value of the pickable items uint glPickableItem = 0; glFirstHandle(ref glPickableItem); // Top lineName = glPickableItem; // Place before you draw the manipulator component that can // be pickable. colorAndName(view, glPickableItem, true, mainColor()); OpenGL.glBegin((uint)libOpenMayaRenderNet.MGL_LINES); OpenGL.glVertex3d(top.x, top.y, top.z); OpenGL.glVertex3d(bottom.x, bottom.y, bottom.z); OpenGL.glEnd(); // End the drawing view.endGL(); }
// // Description: // // Simple very fast draw routine // // Arguments: // // request - request to be drawn // view - view to draw into // // for userInteraction example code // public void drawRedPointAtCenter( MDrawRequest request, M3dView view ) { // Draw point // view.beginGL(); // save state // OpenGL.glPushAttrib(OpenGL.GL_CURRENT_BIT | OpenGL.GL_POINT_BIT); OpenGL.glPointSize(20.0f); OpenGL.glBegin(OpenGL.GL_POINTS); OpenGL.glColor3f(1.0f, 0.0f, 0.0f); OpenGL.glVertex3f(0.0f, 0.0f, 0.0f); OpenGL.glEnd(); // restore state // OpenGL.glPopAttrib(); view.endGL(); }
public override void draw(MDrawRequest request, M3dView view) // // From the given draw request, get the draw data and determine // which quadric to draw and with what values. // { MDrawData data = request.drawData(); quadricGeom geom = data.geometry() as quadricGeom; DrawShapeStyle token = (DrawShapeStyle)request.token; bool drawTexture = false; view.beginGL(); if ((token == DrawShapeStyle.kDrawSmoothShaded) || (token == DrawShapeStyle.kDrawFlatShaded)) { OpenGL.glEnable((uint)OpenGL.GL_POLYGON_OFFSET_FILL); // Set up the material // MMaterial material = request.material; material.setMaterial(request.multiPath, request.isTransparent); // Enable texturing // drawTexture = material.materialIsTextured; if (drawTexture) { OpenGL.glEnable((uint)OpenGL.GL_TEXTURE_2D); } // Apply the texture to the current view // if (drawTexture) { material.applyTexture(view, data); } } IntPtr qobj = GLUFunctionInvoker.gluNewQuadric(); switch (token) { case DrawShapeStyle.kDrawWireframe: case DrawShapeStyle.kDrawWireframeOnShaded: GLUFunctionInvoker.gluQuadricDrawStyle(qobj, GLU_LINE); break; case DrawShapeStyle.kDrawSmoothShaded: GLUFunctionInvoker.gluQuadricNormals(qobj, GLU_SMOOTH); GLUFunctionInvoker.gluQuadricTexture(qobj, GLtrue); GLUFunctionInvoker.gluQuadricDrawStyle(qobj, GLU_FILL); break; case DrawShapeStyle.kDrawFlatShaded: GLUFunctionInvoker.gluQuadricNormals(qobj, GLU_FLAT); GLUFunctionInvoker.gluQuadricTexture(qobj, GLtrue); GLUFunctionInvoker.gluQuadricDrawStyle(qobj, GLU_FILL); break; } switch (geom.shapeType) { case (short)DrawShapeType.kDrawCylinder: GLUFunctionInvoker.gluCylinder(qobj, geom.radius1, geom.radius2, geom.height, geom.slices, geom.stacks); break; case (short)DrawShapeType.kDrawDisk: GLUFunctionInvoker.gluDisk(qobj, geom.radius1, geom.radius2, geom.slices, geom.loops); break; case (short)DrawShapeType.kDrawPartialDisk: GLUFunctionInvoker.gluPartialDisk(qobj, geom.radius1, geom.radius2, geom.slices, geom.loops, geom.startAngle, geom.sweepAngle); break; case (short)DrawShapeType.kDrawSphere: default: GLUFunctionInvoker.gluSphere(qobj, geom.radius1, geom.slices, geom.stacks); break; } // Turn off texture mode // if (drawTexture) { OpenGL.glDisable((uint)OpenGL.GL_TEXTURE_2D); } view.endGL(); }
// for userInteraction example code // public void drawRedPointAtCenter( MDrawRequest request, M3dView view ) // // Description: // // Simple very fast draw routine // // Arguments: // // request - request to be drawn // view - view to draw into // { // Draw point // view.beginGL(); // save state // OpenGL.glPushAttrib(OpenGL.GL_CURRENT_BIT | OpenGL.GL_POINT_BIT); OpenGL.glPointSize(20.0f); OpenGL.glBegin(OpenGL.GL_POINTS); OpenGL.glColor3f(1.0f, 0.0f, 0.0f); OpenGL.glVertex3f(0.0f, 0.0f, 0.0f); OpenGL.glEnd(); // restore state // OpenGL.glPopAttrib(); view.endGL(); }