Пример #1
0
static void TransformNormalAttribute( TQ3AttributeSet ioAtts,
										const TQ3Matrix4x4& inMatrix )
{
	if (ioAtts != NULL)
	{
		TQ3Vector3D		theNormal;
		if (kQ3Success == Q3AttributeSet_Get( ioAtts, kQ3AttributeTypeNormal,
			&theNormal ))
		{
			Q3Vector3D_Transform( &theNormal, &inMatrix, &theNormal );
			Q3FastVector3D_Normalize( &theNormal, &theNormal );
			Q3AttributeSet_Add( ioAtts, kQ3AttributeTypeNormal, &theNormal );
		}
	}
}
TQ3Status TriangulatorGeometry_Triangle(TQ3ViewObject View, void *PrivateData,
	TQ3GeometryObject Triangle, const TQ3TriangleData *TriangleData)
{
	// Just in case...
	if (!TriangleData) return kQ3Success;
	
	// Get the overall normal and color (DiffuseColor)
	TQ3Boolean OverallColorPresent =
		Q3AttributeSet_Contains(TriangleData->triangleAttributeSet,kQ3AttributeTypeDiffuseColor);
	
	TQ3ColorRGB OverallColor;
	if (OverallColorPresent);
		Q3AttributeSet_Get(TriangleData->triangleAttributeSet,kQ3AttributeTypeDiffuseColor,&OverallColor);
	
	// Load the triangle's contents into a vertex object
	for (int k=0; k<3; k++)
	{
		FullVertexData FullVertex;
		obj_clear(FullVertex);
		
		const TQ3Vertex3D& Vertex = TriangleData->vertices[k];
		GLfloat *FV_Pos = FullVertex.Data + FullVertexData::POS_BASE;
		FV_Pos[0] = Vertex.point.x;
		FV_Pos[1] = Vertex.point.y;
		FV_Pos[2] = Vertex.point.z;
		
		TQ3Param2D TxtrCoord;
		TQ3Boolean TxtrCoord_Present =
			Q3AttributeSet_Contains(Vertex.attributeSet,kQ3AttributeTypeShadingUV);
		if (TxtrCoord_Present)
			Q3AttributeSet_Get(Vertex.attributeSet,kQ3AttributeTypeShadingUV,&TxtrCoord);
		else
		{
			TxtrCoord_Present =
				Q3AttributeSet_Contains(Vertex.attributeSet,kQ3AttributeTypeSurfaceUV);
			if (TxtrCoord_Present)
				Q3AttributeSet_Get(Vertex.attributeSet,kQ3AttributeTypeSurfaceUV,&TxtrCoord);
			else
				TxtrCoordsPresent = false;
		}
		
		if (TxtrCoordsPresent)
		{
			GLfloat *FV_TC = FullVertex.Data + FullVertexData::TC_BASE;
			FV_TC[0] = TxtrCoord.u;
			FV_TC[1] = TxtrCoord.v;
		}
		
		TQ3Vector3D Normal;
		TQ3Boolean Normal_Present =
			Q3AttributeSet_Contains(Vertex.attributeSet,kQ3AttributeTypeNormal);
		if (Normal_Present)
			Q3AttributeSet_Get(Vertex.attributeSet,kQ3AttributeTypeNormal,&Normal);
		else
			NormalsPresent = false;
		
		if (NormalsPresent)
		{
			GLfloat *FV_Norm = FullVertex.Data + FullVertexData::NORM_BASE;
			FV_Norm[0] = Normal.x;
			FV_Norm[1] = Normal.y;
			FV_Norm[2] = Normal.z;
		}
		
		TQ3ColorRGB Color;
		TQ3Boolean Color_Present =
			Q3AttributeSet_Contains(Vertex.attributeSet,kQ3AttributeTypeDiffuseColor);
		if (Color_Present)
			Q3AttributeSet_Get(Vertex.attributeSet,kQ3AttributeTypeDiffuseColor,&Color);
		else if (OverallColorPresent)
			Color = OverallColor;
		else
			ColorsPresent = false;
		
		if (ColorsPresent)
		{
			GLfloat *FV_Color = FullVertex.Data + FullVertexData::COLOR_BASE;
			FV_Color[0] = Color.r;
			FV_Color[1] = Color.g;
			FV_Color[2] = Color.b;
		}
		FullVertexList.push_back(FullVertex);
	}
	
	return kQ3Success;
}