//===========================================================================// // Copyright (C) Microsoft Corporation. All rights reserved. // //===========================================================================// #include "MLRHeaders.hpp" #if defined(TRACE_ENABLED) && defined(MLR_TRACE) BitTrace *MLR_I_L_DT_PMesh_Clip; #endif //############################################################################# //######## MLRIndexedPolyMesh with color and lighting two texture layer ###### //############################################################################# MLR_I_L_DT_PMesh::ClassData* MLR_I_L_DT_PMesh::DefaultData = NULL; //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // void MLR_I_L_DT_PMesh::InitializeClass() { Verify(!DefaultData); Verify(gos_GetCurrentHeap() == StaticHeap); DefaultData = new ClassData( MLR_I_L_DT_PMeshClassID, "MidLevelRenderer::MLR_I_L_DT_PMesh", MLR_I_C_DT_PMesh::DefaultData, (MLRPrimitiveBase::Factory)&Make ); Register_Object(DefaultData); #if defined(TRACE_ENABLED) && defined(MLR_TRACE) MLR_I_L_DT_PMesh_Clip = new BitTrace("MLR_I_L_DT_PMesh_Clip"); Register_Object(MLR_I_L_DT_PMesh_Clip); #endif } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // void MLR_I_L_DT_PMesh::TerminateClass() { Unregister_Object(DefaultData); delete DefaultData; DefaultData = NULL; #if defined(TRACE_ENABLED) && defined(MLR_TRACE) Unregister_Object(MLR_I_L_DT_PMesh_Clip); delete MLR_I_L_DT_PMesh_Clip; #endif } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // MLR_I_L_DT_PMesh::MLR_I_L_DT_PMesh( ClassData *class_data, MemoryStream *stream, int version ): MLR_I_C_DT_PMesh(DefaultData, stream, version) { Check_Pointer(this); Check_Pointer(stream); Verify(gos_GetCurrentHeap() == Heap); switch(version) { case 1: case 2: { STOP(("This class got created only after version 2 !")); } break; default: { MemoryStreamIO_Read(stream, &normals); } break; } litColors.SetLength(colors.GetLength()); actualColors = &colors; } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // MLR_I_L_DT_PMesh::MLR_I_L_DT_PMesh(ClassData *class_data): MLR_I_C_DT_PMesh(class_data), normals(0) { Check_Pointer(this); Verify(gos_GetCurrentHeap() == Heap); actualColors = &colors; } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // MLR_I_L_DT_PMesh::~MLR_I_L_DT_PMesh() { Check_Object(this); } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // MLR_I_L_DT_PMesh* MLR_I_L_DT_PMesh::Make( MemoryStream *stream, int version ) { Check_Object(stream); gos_PushCurrentHeap(Heap); MLR_I_L_DT_PMesh *mesh = new MLR_I_L_DT_PMesh(DefaultData, stream, version); gos_PopCurrentHeap(); return mesh; } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // void MLR_I_L_DT_PMesh::Save(MemoryStream *stream) { Check_Object(this); Check_Object(stream); MLR_I_C_DT_PMesh::Save(stream); MemoryStreamIO_Write(stream, &normals); } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // void MLR_I_L_DT_PMesh::TestInstance() const { Verify(IsDerivedFrom(DefaultData)); } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // void MLR_I_L_DT_PMesh::SetNormalData( const Vector3D *data, int dataSize ) { Check_Object(this); Check_Pointer(data); Verify(coords.GetLength() == 0 || dataSize == coords.GetLength()); Verify(colors.GetLength() == 0 || dataSize == colors.GetLength()); //Verify(texCoords.GetLength() == 0 || dataSize == texCoords.GetLength()); normals.AssignData(data, dataSize); } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // void MLR_I_L_DT_PMesh::GetNormalData( Vector3D **data, int *dataSize ) { Check_Object(this); *data = normals.GetData(); *dataSize = normals.GetLength(); } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // void MLR_I_L_DT_PMesh::SetColorData( #if COLOR_AS_DWORD const DWORD *data, #else const RGBAColor *data, #endif int dataSize ) { Check_Object(this); Check_Pointer(data); Verify(gos_GetCurrentHeap() == Heap); Verify(coords.GetLength() == 0 || dataSize == coords.GetLength()); litColors.SetLength(dataSize); colors.AssignData(data, dataSize); } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // void MLR_I_L_DT_PMesh::PaintMe( #if COLOR_AS_DWORD const DWORD *paintMe #else const RGBAColor *paintMe #endif ) { Check_Object(this); Verify(colors.GetLength() == litColors.GetLength()); int k, len = litColors.GetLength(); #if COLOR_AS_DWORD DWORD argb = GOSCopyColor(paintMe); for(k=0;kSet() #define CLEAR_MLR_PMESH_CLIP() MLR_I_L_DT_PMesh_Clip->Clear() #else #define SET_MLR_PMESH_CLIP() #define CLEAR_MLR_PMESH_CLIP() #endif //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // This include contains follwing functions: // void MLR_I_L_DT_PMesh::TransformNoClip(Matrix4D*, GOSVertexPool*); // int MLR_I_L_DT_PMesh::Clip(MLRClippingState, GOSVertexPool*); //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #include #undef I_SAY_YES_TO_DUAL_TEXTURES #undef I_SAY_YES_TO_COLOR #undef I_SAY_YES_TO_LIGHTING //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // This include contains follwing functions: // void Lighting (MLRLight**, int nrLights); //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #include #undef CLASSNAME //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // MLRShape* MidLevelRenderer::CreateIndexedIcosahedron_Color_Lit_2Tex( IcoInfo& icoInfo, MLRState *state, MLRState *state2 ) { gos_PushCurrentHeap(Heap); MLRShape *ret = new MLRShape(20); Register_Object(ret); int i, j, k; long nrTri = (long) ceil (icoInfo.all * pow (4.0f, icoInfo.depth)); Point3D v[3]; if(3*nrTri >= Limits::Max_Number_Vertices_Per_Mesh) { nrTri = Limits::Max_Number_Vertices_Per_Mesh/3; } unsigned char *lengths = new unsigned char [nrTri]; Register_Pointer(lengths); for(i=0;iSetSubprimitiveLengths(lengths, nrTri); if(icoInfo.indexed==true) { uniquePoints = 1; collapsedCoords[0] = coords[0]; index[0] = 0; for(i=1;i(j); } mesh->SetCoordData(collapsedCoords, uniquePoints); } else { uniquePoints = nrTri*3; for(i=0;i(i); } mesh->SetCoordData(coords, nrTri*3); } mesh->SetIndexData(index, nrTri*3); mesh->FindFacePlanes(); if(state == NULL) { for(i=0;iSetReferenceState(*state); if(state->GetTextureHandle() > 0) { if(icoInfo.indexed==true) { for(i=0;iSetTexCoordData(texCoords, 2*uniquePoints); if(icoInfo.indexed==true) { for(i=0;iSetColorData(colors, uniquePoints); mesh->SetNormalData(normals, uniquePoints); mesh->SetReferenceState(*state2, 1); ret->Add(mesh); mesh->DetachReference(); } Unregister_Pointer(normals); delete [] normals; Unregister_Pointer(colors); delete [] colors; Unregister_Pointer(texCoords); delete [] texCoords; Unregister_Pointer(index); delete [] index; if(icoInfo.indexed==true) { Unregister_Pointer(collapsedCoords); delete [] collapsedCoords; } Unregister_Pointer(coords); delete [] coords; Unregister_Pointer(lengths); delete [] lengths; gos_PopCurrentHeap(); return ret; }