Пример #1
0
//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
void GetMeshMatrix( MItMeshPolygon &pIt, int nMeshFaceIndex, MMatrix &geoMatrix  )
{
	if ( nMeshFaceIndex < static_cast< int >( pIt.count() ) )
	{
		MPointArray facePoints;

		int nOldIndex;
		pIt.setIndex( nMeshFaceIndex, nOldIndex );

		pIt.getPoints( facePoints, MSpace::kWorld );

		// Calculate cheezy coordinate system, if any edges are 0 length then all hell breaks loose
		MVector x = ( facePoints[ 2 ] - facePoints[ 0 ] ).normal();
		MVector z = ( facePoints[ 1 ] - facePoints[ 0 ] ).normal();
		MVector y = ( z ^ x ).normal();
		z = x ^ y;

		memcpy( const_cast< double * >( geoMatrix[ 0 ] ), &x[ 0 ], 3 * sizeof( double ) );
		memcpy( const_cast< double * >( geoMatrix[ 1 ] ), &y[ 0 ], 3 * sizeof( double ) );
		memcpy( const_cast< double * >( geoMatrix[ 2 ] ), &z[ 0 ], 3 * sizeof( double ) );

		MPoint center = pIt.center( MSpace::kWorld );

		memcpy( const_cast< double * >( geoMatrix[ 3] ), &center[ 0 ], 3 * sizeof( double ) );

		pIt.setIndex( nOldIndex, nMeshFaceIndex );
	}
	else
	{
		merr << "Mesh face index " << nMeshFaceIndex << " out of range, only " << pIt.count() << " faces on mesh" << std::endl;
	}
}
Пример #2
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();


}