Exemplo n.º 1
0
//-------------------------------------------------------------------------------------------------------------------------------------------
void	visualizeMeshNode::drawShadedTriangles(MItMeshPolygon& polyIter, MItMeshVertex& vertIter, M3dView::DisplayStyle style, meshStatus meshStat)
//-------------------------------------------------------------------------------------------------------------------------------------------
{

				//alles zeichnen
				glPushAttrib(GL_ALL_ATTRIB_BITS);
				
				
				glEnable(GL_POLYGON_OFFSET_FILL);
				
				
				glEnable(GL_BLEND);
				glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
				//glDepthMask(GL_FALSE);
				
				glPolygonMode(GL_BACK, GL_FILL);
				glShadeModel(GL_SMOOTH);
				
				
				
				//Dass muss ausßerhalb der displayList bleiben, weil dieser Wert nicht precompiliert werden darf
				float param1 = 0.45, param2 = 0.55;

				// im DebugMode werden die Params anhand der NodeParameter gesetzt

				if(style == M3dView::kWireFrame)
				{

						param1 = 0.45; param2 = 0.55;

				}
				else
				{
					switch(meshStat)
					{
					case kNone:
						{
							param1 = -0.5; param2 = -0.6;

							break;
						}
					case kHilited:
						{
							param1 = 0.45; param2 = 0.55;
							
							break;
						}
					}
				}


				#ifdef DEBUG
				MPlug tmpPlug(thisMObject(), pOffset1Obj);
				tmpPlug.getValue(param1);
				
				tmpPlug.setAttribute(pOffset2Obj);
				tmpPlug.getValue(param2);
				#endif

				glPolygonOffset( param1, param2 );
				
				//jedes Poly zeichnen
				
				uint numPolys = polyIter.count();
				uint i, x , l;
				MPoint	point;
				MColor	tmpCol;
				MPointArray triPoints;
				MIntArray	triVtx;
				//glColor4f(0.0f, 0.0f, 1.0f, 0.2);
				
				for(i = 0; i < numPolys; i++, polyIter.next())
				{
					

					polyIter.getTriangles(triPoints, triVtx);
					
					
					l = triVtx.length();
					
					
					glBegin(GL_TRIANGLES);
					
					for(x = 0; x < l ; x+=3)
					{
						//view.setDrawColor( getCalColor(vtxColor, MColor(1.0,0.0,0.0), vtxWeightArray[ polyVtx[x] ] ) );
						//view.setDrawColor( vtxColor *  vtxWeightArray[ polyVtx[x] ]);
						//glColor4f(0.0f, 0.0f, 1.0f, vtxWeightArray[ polyVtx[x] ]);
						
						tmpCol = getCalColor(vtxColor, vtxColor2 ,  vtxWeightArray[ triVtx[x] ]);
						glColor4f(tmpCol.r, tmpCol.g,tmpCol.b, vtxWeightArray[ triVtx[x] ]);
						glVertex3d(triPoints[x].x, triPoints[x].y, triPoints[x].z);
						
			
						tmpCol = getCalColor(vtxColor, vtxColor2 ,  vtxWeightArray[ triVtx[x+1] ]);
						glColor4f(tmpCol.r, tmpCol.g,tmpCol.b, vtxWeightArray[ triVtx[x+1] ]);
						glVertex3d(triPoints[x+1].x, triPoints[x+1].y, triPoints[x+1].z);

						tmpCol = getCalColor(vtxColor, vtxColor2 ,  vtxWeightArray[ triVtx[x+2] ]);
						glColor4f(tmpCol.r, tmpCol.g,tmpCol.b, vtxWeightArray[ triVtx[x+2] ]);
						glVertex3d(triPoints[x+2].x, triPoints[x+2].y, triPoints[x+2].z);

					}
					
					glEnd();
					
				}
				
				
			//	glDisable(GL_POLYGON_OFFSET_FILL);

				glPopAttrib();


}
// --------------------------------------------------------
void GeometryPolygonExporter::retrieveVertexIndices (
    MIntArray &vertexIndices,
    MItMeshPolygon &meshPolygonsIter,
    uint &numPolygons,
    uint &numVertices )
{
    // Get the number of vertices in the current mesh's polygon
    int polygonVertexCount = meshPolygonsIter.polygonVertexCount();
    if ( triangulated && polygonVertexCount > 3 )
    {
        int numTriangles;
        meshPolygonsIter.numTriangles ( numTriangles );
        if ( numTriangles > 0 )
        {
            numVertices = 3;
            MPointArray vertexPositions;
            MIntArray meshVertexIndices;
            meshPolygonsIter.getTriangles ( vertexPositions, meshVertexIndices );
            vertexIndices.setLength ( meshVertexIndices.length() );
            numPolygons = meshVertexIndices.length() / numVertices;

            // Map the vertex indices to iterator vertex indices so that we can
            // get information from the iterator about normals and such.
            uint meshVertexIndexCount = meshVertexIndices.length();
            for ( uint mvi = 0; mvi < meshVertexIndexCount; ++mvi )
            {
                int meshVertexIndex = meshVertexIndices[mvi];
                int polygonVertexCount = meshPolygonsIter.polygonVertexCount();
                int iteratorVertexIndex = 0;
                for ( int pv = 0; pv < polygonVertexCount; ++pv )
                {
                    if ( ( int ) meshPolygonsIter.vertexIndex ( pv ) == meshVertexIndex )
                    {
                        iteratorVertexIndex = pv;
                    }
                }
                vertexIndices[mvi] = iteratorVertexIndex;
            }
        }
        else numPolygons = 0;
    }
    else if ( polygonVertexCount >= 3 )
    {
        numPolygons = 1;
        vertexIndices.setLength ( polygonVertexCount );
        for ( int pv = 0; pv < polygonVertexCount; ++pv )
        {
            vertexIndices[pv] = pv;
        }

#ifdef VALIDATE_DATA
        // Skip over any duplicate vertices in this face.
        // Very rarely, a cunning user manages to corrupt
        // a face entry on the mesh and somehow configure
        // a face to include the same vertex multiple times.
        // This will cause the read-back of this data to
        // reject the face, and can crash other COLLADA
        // consumers, so better to lose the data here
        for ( uint n = 0; n < vertexIndices.length() - 1; ++n )            {
            for ( uint m = n + 1; m < vertexIndices.length(); )
            {
                if ( vertexIndices[n] == vertexIndices[m] )
                {
                    vertexIndices.remove ( m );
                }
                else ++m;
            }
        }
        // Get the number of vertices of the current polygon.
        numVertices = vertexIndices->length();
#else
        // Get the number of vertices of the current polygon.
        numVertices = polygonVertexCount;
#endif
    }
}