123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537 |
- //===========================================================================//
- // Copyright (C) Microsoft Corporation. All rights reserved. //
- //===========================================================================//
- #include "MLRHeaders.hpp"
- #if defined(TRACE_ENABLED) && defined(MLR_TRACE)
- BitTrace *MLR_I_MT_PMesh_Clip;
- #endif
- //#############################################################################
- //###### MLRIndexedPolyMesh with no color no lighting two texture layer ######
- //#############################################################################
- MLR_I_MT_PMesh::ClassData*
- MLR_I_MT_PMesh::DefaultData = NULL;
- DynamicArrayOf<DynamicArrayOf<Vector2DScalar> >
- *MLR_I_MT_PMesh::clipExtraMultiTexCoords;
- DynamicArrayOf<DynamicArrayOf<Vector2DScalar> >
- *MLR_I_MT_PMesh::extraMultiTexCoords;
- //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- //
- void
- MLR_I_MT_PMesh::InitializeClass()
- {
- Verify(!DefaultData);
- Verify(gos_GetCurrentHeap() == StaticHeap);
- DefaultData =
- new ClassData(
- MLR_I_MT_PMeshClassID,
- "MidLevelRenderer::MLR_I_MT_PMesh",
- MLR_I_PMesh::DefaultData,
- (MLRPrimitiveBase::Factory)&Make
- );
- Register_Object(DefaultData);
-
- clipExtraMultiTexCoords = new DynamicArrayOf<DynamicArrayOf<Vector2DScalar> >;
- Register_Object(clipExtraMultiTexCoords);
- clipExtraMultiTexCoords->SetLength(Limits::Max_Number_Of_Multitextures);
-
- extraMultiTexCoords = new DynamicArrayOf<DynamicArrayOf<Vector2DScalar> >;
- Register_Object(extraMultiTexCoords);
- extraMultiTexCoords->SetLength(Limits::Max_Number_Of_Multitextures);
- for(int i=0;i<clipExtraMultiTexCoords->GetLength();i++)
- {
- (*clipExtraMultiTexCoords)[i].SetLength(Limits::Max_Number_Vertices_Per_Mesh);
- (*extraMultiTexCoords)[i].SetLength(Limits::Max_Number_Vertices_Per_Mesh);
- }
- #if defined(TRACE_ENABLED) && defined(MLR_TRACE)
- MLR_I_MT_PMesh_Clip = new BitTrace("MLR_I_MT_PMesh_Clip");
- Register_Object(MLR_I_MT_PMesh_Clip);
- #endif
- }
- //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- //
- void
- MLR_I_MT_PMesh::TerminateClass()
- {
- for(int i=0;i<clipExtraMultiTexCoords->GetLength();i++)
- {
- (*clipExtraMultiTexCoords)[i].SetLength(0);
- (*extraMultiTexCoords)[i].SetLength(0);
- }
- Unregister_Object(clipExtraMultiTexCoords);
- delete clipExtraMultiTexCoords;
- Unregister_Object(extraMultiTexCoords);
- delete extraMultiTexCoords;
- Unregister_Object(DefaultData);
- delete DefaultData;
- DefaultData = NULL;
- #if defined(TRACE_ENABLED) && defined(MLR_TRACE)
- Unregister_Object(MLR_I_MT_PMesh_Clip);
- delete MLR_I_MT_PMesh_Clip;
- #endif
- }
- //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- //
- MLR_I_MT_PMesh::MLR_I_MT_PMesh(
- ClassData *class_data,
- MemoryStream *stream,
- int version
- ):
- MLR_I_PMesh(class_data, stream, version)
- {
- Check_Pointer(this);
- Check_Pointer(stream);
- Verify(gos_GetCurrentHeap() == Heap);
- multiTexCoords.SetLength(Limits::Max_Number_Of_Multitextures);
- multiTexCoordsPointers.SetLength(Limits::Max_Number_Of_Multitextures);
- multiState.SetLength(Limits::Max_Number_Of_Multitextures);
- multiReferenceState.SetLength(Limits::Max_Number_Of_Multitextures);
- multiTexCoords[0] = &texCoords;
- multiTexCoordsPointers[0] = texCoords.GetData();
- multiReferenceState[0] = referenceState;
- *stream >> passes;
- for(int i=1;i<passes;i++)
- {
- multiReferenceState[i].Save(stream);
- multiTexCoords[i] = new DynamicArrayOf<Vector2DScalar>;
- Register_Object(multiTexCoords[i]);
- MemoryStreamIO_Read(stream, multiTexCoords[i]);
- multiTexCoordsPointers[i] = multiTexCoords[i]->GetData();
- }
- currentNrOfPasses = passes;
- }
- //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- //
- MLR_I_MT_PMesh::MLR_I_MT_PMesh(ClassData *class_data):
- MLR_I_PMesh(class_data)
- {
- Check_Pointer(this);
- Verify(gos_GetCurrentHeap() == Heap);
- multiTexCoords.SetLength(Limits::Max_Number_Of_Multitextures);
- multiTexCoordsPointers.SetLength(Limits::Max_Number_Of_Multitextures);
- multiTexCoords[0] = &texCoords;
- multiTexCoordsPointers[0] = texCoords.GetData();
- multiState.SetLength(Limits::Max_Number_Of_Multitextures);
- multiReferenceState.SetLength(Limits::Max_Number_Of_Multitextures);
- passes = 1;
- currentNrOfPasses = passes;
- }
- //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- //
- void
- MLR_I_MT_PMesh::Copy(MLR_I_PMesh *pMesh)
- {
- Check_Pointer(this);
- Verify(gos_GetCurrentHeap() == Heap);
- int num;
- Point3D *points;
- referenceState = pMesh->GetReferenceState();
- multiReferenceState[0] = referenceState;
- pMesh->GetCoordData(&points, &num);
- SetCoordData(points, num);
- Vector2DScalar *tex;
- pMesh->GetTexCoordData(&tex, &num);
- SetTexCoordData(tex, num);
- multiTexCoords[0] = &texCoords;
- multiTexCoordsPointers[0] = texCoords.GetData();
- unsigned char *length_array;
- pMesh->GetSubprimitiveLengths(&length_array, &num);
- SetSubprimitiveLengths(length_array, num);
- drawMode = pMesh->GetSortDataMode();
- unsigned short *index_array;
- pMesh->GetIndexData(&index_array, &num);
- SetIndexData(index_array, num);
- facePlanes.SetLength(GetNumPrimitives());
- testList.SetLength(GetNumPrimitives());
- FindFacePlanes();
- passes = 1;
- currentNrOfPasses = passes;
- }
- //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- //
- MLR_I_MT_PMesh::~MLR_I_MT_PMesh()
- {
- Check_Object(this);
- for(int i=1;i<passes;i++)
- {
- Unregister_Object(multiTexCoords[i]);
- delete multiTexCoords[i];
- }
- }
- //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- //
- MLR_I_MT_PMesh*
- MLR_I_MT_PMesh::Make(
- MemoryStream *stream,
- int version
- )
- {
- Check_Object(stream);
- gos_PushCurrentHeap(Heap);
- MLR_I_MT_PMesh *mesh = new MLR_I_MT_PMesh(DefaultData, stream, version);
- gos_PopCurrentHeap();
- return mesh;
- }
- //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- //
- void
- MLR_I_MT_PMesh::Save(MemoryStream *stream)
- {
- Check_Object(this);
- Check_Object(stream);
- MLR_I_PMesh::Save(stream);
- *stream << passes;
- for(int i=1;i<passes;i++)
- {
- multiReferenceState[i].Save(stream);
- MemoryStreamIO_Write(stream, multiTexCoords[i]);
- }
- }
-
- //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- //
- void
- MLR_I_MT_PMesh::TestInstance() const
- {
- Verify(IsDerivedFrom(DefaultData));
- }
- //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- //
- void
- MLR_I_MT_PMesh::InitializeDrawPrimitive(unsigned char vis, int parameter)
- {
- MLR_I_PMesh::InitializeDrawPrimitive(vis, parameter);
- currentNrOfPasses = passes;
- }
- //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- //
- void
- MLR_I_MT_PMesh::SetTexCoordData(
- const Vector2DScalar *data,
- int dataSize,
- int pass
- )
- {
- Check_Object(this);
- Check_Pointer(data);
- Verify(pass>=0 && pass<Limits::Max_Number_Of_Multitextures);
- Verify(coords.GetLength() == 0 || dataSize == coords.GetLength());
- if(pass == 0)
- {
- texCoords.AssignData((Vector2DScalar *)data, dataSize);
- multiTexCoordsPointers[0] = texCoords.GetData();
- }
- else
- {
- if(pass == passes)
- {
- Verify(dataSize == multiTexCoords[pass-1]->GetLength());
- gos_PushCurrentHeap(Heap);
- multiTexCoords[pass] = new DynamicArrayOf<Vector2DScalar>;
- Register_Object(multiTexCoords[pass]);
- multiTexCoords[pass]->AssignData((Vector2DScalar *)data, dataSize);
- gos_PopCurrentHeap();
- multiTexCoordsPointers[pass] = multiTexCoords[pass]->GetData();
-
- passes++;
- currentNrOfPasses++;
- }
- else
- {
- STOP(("Add texture layers only one by one !!!"));
- }
- }
- }
- //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- //
- void
- MLR_I_MT_PMesh::GetTexCoordData(
- const Vector2DScalar **data,
- int *dataSize,
- int pass
- )
- {
- Check_Object(this);
- Check_Pointer(data);
- Verify(pass>=0 && pass<passes);
- *data = multiTexCoords[pass]->GetData();
- *dataSize = multiTexCoords[pass]->GetLength();
- }
- //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- //
- void
- MLR_I_MT_PMesh::SetTexCoordDataPointer(const Vector2DScalar *data)
- {
- Check_Pointer(data);
- Verify(currentNrOfPasses>=passes);
- multiTexCoordsPointers[currentNrOfPasses++] = data;
- }
- #define I_SAY_YES_TO_MULTI_TEXTURES
- #undef I_SAY_YES_TO_DUAL_TEXTURES
- #undef I_SAY_YES_TO_COLOR
- #undef I_SAY_YES_TO_LIGHTING
- #define CLASSNAME MLR_I_MT_PMesh
- #if defined(TRACE_ENABLED) && defined(MLR_TRACE)
- #define SET_MLR_PMESH_CLIP() MLR_I_MT_PMesh_Clip->Set()
- #define CLEAR_MLR_PMESH_CLIP() MLR_I_MT_PMesh_Clip->Clear()
- #else
- #define SET_MLR_PMESH_CLIP()
- #define CLEAR_MLR_PMESH_CLIP()
- #endif
- //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- // This include contains follwing functions:
- // void MLR_I_MT_PMesh::TransformNoClip(Matrix4D*, GOSVertexPool*);
- // int MLR_I_MT_PMesh::Clip(MLRClippingState, GOSVertexPool*);
- //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- #include <MLR\MLRPrimitiveClipping.hpp>
- #undef I_SAY_YES_TO_MULTI_TEXTURES
- #undef CLASSNAME
- //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- //
- MLRShape*
- MidLevelRenderer::CreateIndexedIcosahedron_NoColor_NoLit_MultiTexture(
- IcoInfo& icoInfo,
- DynamicArrayOf<MLRState> *states
- )
- {
- gos_PushCurrentHeap(Heap);
- MLRShape *ret = new MLRShape(20);
- Register_Object(ret);
- int i, j, k;
- int nrOfPasses = states->GetLength();
- 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;i<nrTri;i++)
- {
- lengths[i] = 3;
- }
- Point3D *coords = new Point3D [nrTri*3];
- Register_Pointer(coords);
-
- Point3D *collapsedCoords = NULL;
- if(icoInfo.indexed==true)
- {
- collapsedCoords = new Point3D [nrTri*3];
- Register_Pointer(collapsedCoords);
- }
- DynamicArrayOf<Vector2DScalar *> texCoords(nrOfPasses);
- for(i=0;i<nrOfPasses;i++)
- {
- texCoords[i] = new Vector2DScalar[nrTri*3];
- Register_Pointer(texCoords[i]);
- }
- unsigned short *index = new unsigned short [nrTri*3];
- Register_Pointer(index);
- int uniquePoints = 0;
- for (k=0;k<20;k++)
- {
- triDrawn = 0;
- MLR_I_MT_PMesh *mesh = new MLR_I_MT_PMesh();
- Register_Object(mesh);
- // setup vertex position information
- for (j=0;j<3;j++)
- {
- v[j].x = vdata[tindices[k][j]][0];
- v[j].y = vdata[tindices[k][j]][1];
- v[j].z = vdata[tindices[k][j]][2];
- }
- subdivide (coords, v[0], v[1], v[2], icoInfo.depth, nrTri, icoInfo.radius);
- mesh->SetSubprimitiveLengths(lengths, nrTri);
- if(icoInfo.indexed==true)
- {
- uniquePoints = 1;
- collapsedCoords[0] = coords[0];
- index[0] = 0;
- for(i=1;i<nrTri*3;i++)
- {
- for(j=0;j<uniquePoints;j++)
- {
- if(coords[i] == collapsedCoords[j])
- {
- break;
- }
- }
- if(j==uniquePoints)
- {
- collapsedCoords[uniquePoints++] = coords[i];
- }
- index[i] = static_cast<unsigned short>(j);
- }
- mesh->SetCoordData(collapsedCoords, uniquePoints);
- }
- else
- {
- uniquePoints = nrTri*3;
- for(i=0;i<nrTri*3;i++)
- {
- index[i] = static_cast<unsigned short>(i);
- }
- mesh->SetCoordData(coords, nrTri*3);
- }
- mesh->SetIndexData(index, nrTri*3);
- mesh->FindFacePlanes();
- for(j=0;j<nrOfPasses;j++)
- {
- if(icoInfo.indexed==true)
- {
- for(i=0;i<uniquePoints;i++)
- {
- texCoords[j][i] =
- Vector2DScalar(
- (1.0f + collapsedCoords[i].x)/2.0f,
- (1.0f + collapsedCoords[i].y)/2.0f
- );
- }
- }
- else
- {
- for(i=0;i<nrTri;i++)
- {
- texCoords[j][3*i] =
- Vector2DScalar(
- (1.0f + coords[3*i].x)/2.0f,
- (1.0f + coords[3*i].y)/2.0f
- );
- texCoords[j][3*i+1] =
- Vector2DScalar(
- (1.0f + coords[3*i+1].x)/2.0f,
- (1.0f + coords[3*i+1].y)/2.0f
- );
- texCoords[j][3*i+2] =
- Vector2DScalar(
- (1.0f + coords[3*i+2].x)/2.0f,
- (1.0f + coords[3*i+2].y)/2.0f
- );
- }
- }
- mesh->SetTexCoordData(texCoords[j], uniquePoints, j);
- }
- for(i=0;i<nrOfPasses;i++)
- {
- mesh->SetReferenceState((*states)[i], i);
- }
- ret->Add(mesh);
- mesh->DetachReference();
- }
- for(i=0;i<nrOfPasses;i++)
- {
- Unregister_Pointer(texCoords[i]);
- delete [] texCoords[i];
- }
- 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;
- }
|