From: <re...@us...> - 2006-10-18 17:04:18
|
Revision: 25642 http://svn.sourceforge.net/crystal/?rev=25642&view=rev Author: res2002 Date: 2006-10-18 10:04:07 -0700 (Wed, 18 Oct 2006) Log Message: ----------- res merged r25600 into 1.0 (genmesh Compress() + submeshes). Modified Paths: -------------- CS/branches/release/V1.0/docs/history.txt CS/branches/release/V1.0/docs/history10.txt CS/branches/release/V1.0/plugins/mesh/genmesh/object/genmesh.cpp Modified: CS/branches/release/V1.0/docs/history.txt =================================================================== --- CS/branches/release/V1.0/docs/history.txt 2006-10-18 16:57:20 UTC (rev 25641) +++ CS/branches/release/V1.0/docs/history.txt 2006-10-18 17:04:07 UTC (rev 25642) @@ -14,6 +14,8 @@ - Jorrit fixed walktest for the removal of spiral. Simply removed the spiral command. It isn't that useful. 11-Oct-2006 + - res fixed genmesh to also support Compress() when submeshes are + present. - res fixed csConfigIterator::Rewind() not working properly. 10-Oct-2006 - mdmkolbe fixed searching of Cygwin paths. Modified: CS/branches/release/V1.0/docs/history10.txt =================================================================== --- CS/branches/release/V1.0/docs/history10.txt 2006-10-18 16:57:20 UTC (rev 25641) +++ CS/branches/release/V1.0/docs/history10.txt 2006-10-18 17:04:07 UTC (rev 25642) @@ -13,6 +13,7 @@ (configuration system). - res merged r25587:25589 into 1.0 (docs search). - res merged r25596, r25604, r25606 into 1.0 (cygwin paths). + - res merged r25600 into 1.0 (genmesh Compress() + submeshes). 12-Oct-2006 - Jorrit merged r25568 into 1.0 (RK45 ODE solver). - Jorrit merged r25590 into 1.0 (velocity-field effector). Modified: CS/branches/release/V1.0/plugins/mesh/genmesh/object/genmesh.cpp =================================================================== --- CS/branches/release/V1.0/plugins/mesh/genmesh/object/genmesh.cpp 2006-10-18 16:57:20 UTC (rev 25641) +++ CS/branches/release/V1.0/plugins/mesh/genmesh/object/genmesh.cpp 2006-10-18 17:04:07 UTC (rev 25642) @@ -1709,16 +1709,39 @@ } } -void csGenmeshMeshObjectFactory::Compress () +template<typename T> +static void RemapIndexBuffer (csRef<iRenderBuffer>& index_buffer, + csCompressVertexInfo* vt) { - if (subMeshes.GetSize () > 0) + csRef<iRenderBuffer> newBuffer; { - csReport (object_reg, CS_REPORTER_SEVERITY_WARNING, - "crystalspace.genmesh.compress", - "WARNING! Compress ignored because there are subMeshes!"); - return; + csRenderBufferLock<T> indices (index_buffer); + size_t rangeMin = (size_t)~0, rangeMax = 0; + for (size_t n = 0; n < indices.GetSize(); n++) + { + size_t index = size_t (indices[n]); + size_t newIndex = vt[index].new_idx; + if (newIndex < rangeMin) + rangeMin = newIndex; + else if (newIndex > rangeMax) + rangeMax = newIndex; + } + newBuffer = csRenderBuffer::CreateIndexRenderBuffer ( + index_buffer->GetElementCount(), index_buffer->GetBufferType(), + index_buffer->GetComponentType(), rangeMin, rangeMax); + csRenderBufferLock<T> newIndices (newBuffer); + for (size_t n = 0; n < indices.GetSize(); n++) + { + size_t index = size_t (indices[n]); + size_t newIndex = vt[index].new_idx; + newIndices[n] = T (newIndex); + } } + index_buffer = newBuffer; +} +void csGenmeshMeshObjectFactory::Compress () +{ size_t old_num = mesh_vertices.Length (); csCompressVertexInfo* vt = csVertexCompressor::Compress ( mesh_vertices, mesh_texels, mesh_normals, mesh_colors); @@ -1727,14 +1750,53 @@ printf ("From %d to %d\n", int (old_num), int (mesh_vertices.Length ())); fflush (stdout); - // Now we can remap the vertices in all triangles. - size_t i; - for (i = 0 ; i < mesh_triangles.Length () ; i++) + if (subMeshes.GetSize () == 0) { - mesh_triangles[i].a = (int)vt[mesh_triangles[i].a].new_idx; - mesh_triangles[i].b = (int)vt[mesh_triangles[i].b].new_idx; - mesh_triangles[i].c = (int)vt[mesh_triangles[i].c].new_idx; + // Now we can remap the vertices in all triangles. + size_t i; + for (i = 0 ; i < mesh_triangles.Length () ; i++) + { + mesh_triangles[i].a = (int)vt[mesh_triangles[i].a].new_idx; + mesh_triangles[i].b = (int)vt[mesh_triangles[i].b].new_idx; + mesh_triangles[i].c = (int)vt[mesh_triangles[i].c].new_idx; + } } + else + { + for (size_t s = 0; s < subMeshes.GetSize(); s++) + { + SubMesh* subMesh = subMeshes[s]; + csRenderBufferComponentType compType = + subMesh->index_buffer->GetComponentType (); + switch (compType) + { + case CS_BUFCOMP_BYTE: + RemapIndexBuffer<char> (subMesh->index_buffer, vt); + break; + case CS_BUFCOMP_UNSIGNED_BYTE: + RemapIndexBuffer<unsigned char> (subMesh->index_buffer, vt); + break; + case CS_BUFCOMP_SHORT: + RemapIndexBuffer<short> (subMesh->index_buffer, vt); + break; + case CS_BUFCOMP_UNSIGNED_SHORT: + RemapIndexBuffer<unsigned short> (subMesh->index_buffer, vt); + break; + case CS_BUFCOMP_INT: + RemapIndexBuffer<int> (subMesh->index_buffer, vt); + break; + case CS_BUFCOMP_UNSIGNED_INT: + RemapIndexBuffer<unsigned int> (subMesh->index_buffer, vt); + break; + case CS_BUFCOMP_FLOAT: + RemapIndexBuffer<float> (subMesh->index_buffer, vt); + break; + case CS_BUFCOMP_DOUBLE: + RemapIndexBuffer<double> (subMesh->index_buffer, vt); + break; + } + } + } delete[] vt; } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |