mirror of
https://github.com/minetest/irrlicht.git
synced 2024-11-12 18:53:53 +01:00
Collada loader can now handle 32-bit meshbuffers
git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@6480 dfc29bdd-3216-0410-991c-e03cc46cb475
This commit is contained in:
parent
55e29d3347
commit
1b4912fcc4
@ -20,11 +20,12 @@
|
|||||||
#include "IAttributes.h"
|
#include "IAttributes.h"
|
||||||
#include "IMeshCache.h"
|
#include "IMeshCache.h"
|
||||||
#include "IMeshSceneNode.h"
|
#include "IMeshSceneNode.h"
|
||||||
#include "SMeshBufferLightMap.h"
|
#include "CDynamicMeshBuffer.h"
|
||||||
#include "irrMap.h"
|
#include "irrMap.h"
|
||||||
|
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
#define COLLADA_READER_DEBUG
|
// Lots of messages, with how slow some consoles are loading can then take minutes
|
||||||
|
// #define COLLADA_READER_DEBUG
|
||||||
#endif
|
#endif
|
||||||
namespace irr
|
namespace irr
|
||||||
{
|
{
|
||||||
@ -2123,16 +2124,16 @@ void CColladaFileLoader::readPolygonSection(io::IXMLReaderUTF8* reader,
|
|||||||
{
|
{
|
||||||
// standard mesh buffer
|
// standard mesh buffer
|
||||||
|
|
||||||
scene::SMeshBuffer* mbuffer = new SMeshBuffer();
|
scene::CDynamicMeshBuffer* mbuffer = new CDynamicMeshBuffer(video::EVT_STANDARD, IndexTypeHint == EITH_16BIT ? video::EIT_16BIT : video::EIT_32BIT);
|
||||||
buffer = mbuffer;
|
buffer = mbuffer;
|
||||||
|
|
||||||
core::map<video::S3DVertex, int> vertMap;
|
core::map<video::S3DVertex, int> vertMap;
|
||||||
|
|
||||||
for (u32 i=0; i<polygons.size(); ++i)
|
for (u32 i=0; i<polygons.size(); ++i)
|
||||||
{
|
{
|
||||||
core::array<u16> indices;
|
core::array<u32> indices;
|
||||||
const u32 vertexCount = polygons[i].Indices.size() / maxOffset;
|
const u32 vertexCount = polygons[i].Indices.size() / maxOffset;
|
||||||
mbuffer->Vertices.reallocate(mbuffer->Vertices.size()+vertexCount);
|
mbuffer->getVertexBuffer().reallocate(mbuffer->getVertexBuffer().size()+vertexCount);
|
||||||
|
|
||||||
// for all index/semantic groups
|
// for all index/semantic groups
|
||||||
for (u32 v=0; v<polygons[i].Indices.size(); v+=maxOffset)
|
for (u32 v=0; v<polygons[i].Indices.size(); v+=maxOffset)
|
||||||
@ -2208,7 +2209,7 @@ void CColladaFileLoader::readPolygonSection(io::IXMLReaderUTF8* reader,
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
indices.push_back(mbuffer->getVertexCount());
|
indices.push_back(mbuffer->getVertexCount());
|
||||||
mbuffer->Vertices.push_back(vtx);
|
mbuffer->getVertexBuffer().push_back(vtx);
|
||||||
vertMap.insert(vtx, mbuffer->getVertexCount()-1);
|
vertMap.insert(vtx, mbuffer->getVertexCount()-1);
|
||||||
}
|
}
|
||||||
} // end for all vertices
|
} // end for all vertices
|
||||||
@ -2221,9 +2222,9 @@ void CColladaFileLoader::readPolygonSection(io::IXMLReaderUTF8* reader,
|
|||||||
// as full tessellation is problematic
|
// as full tessellation is problematic
|
||||||
for (u32 ind = 0; ind+2 < indices.size(); ++ind)
|
for (u32 ind = 0; ind+2 < indices.size(); ++ind)
|
||||||
{
|
{
|
||||||
mbuffer->Indices.push_back(indices[0]);
|
mbuffer->getIndexBuffer().push_back(indices[0]);
|
||||||
mbuffer->Indices.push_back(indices[ind+2]);
|
mbuffer->getIndexBuffer().push_back(indices[ind+2]);
|
||||||
mbuffer->Indices.push_back(indices[ind+1]);
|
mbuffer->getIndexBuffer().push_back(indices[ind+1]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -2231,25 +2232,30 @@ void CColladaFileLoader::readPolygonSection(io::IXMLReaderUTF8* reader,
|
|||||||
// it's just triangles
|
// it's just triangles
|
||||||
for (u32 ind = 0; ind < indices.size(); ind+=3)
|
for (u32 ind = 0; ind < indices.size(); ind+=3)
|
||||||
{
|
{
|
||||||
mbuffer->Indices.push_back(indices[ind+2]);
|
mbuffer->getIndexBuffer().push_back(indices[ind+2]);
|
||||||
mbuffer->Indices.push_back(indices[ind+1]);
|
mbuffer->getIndexBuffer().push_back(indices[ind+1]);
|
||||||
mbuffer->Indices.push_back(indices[ind+0]);
|
mbuffer->getIndexBuffer().push_back(indices[ind+0]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} // end for all polygons
|
} // end for all polygons
|
||||||
|
|
||||||
|
if ( getIndexTypeHint() == EITH_OPTIMAL && mbuffer->getVertexCount() <= 65536 )
|
||||||
|
{
|
||||||
|
mbuffer->getIndexBuffer().setType(video::EIT_16BIT); // from 32 to 16 bit
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// lightmap mesh buffer
|
// lightmap mesh buffer
|
||||||
|
|
||||||
scene::SMeshBufferLightMap* mbuffer = new SMeshBufferLightMap();
|
scene::CDynamicMeshBuffer* mbuffer = new CDynamicMeshBuffer(video::EVT_2TCOORDS, IndexTypeHint == EITH_16BIT ? video::EIT_16BIT : video::EIT_32BIT);
|
||||||
buffer = mbuffer;
|
buffer = mbuffer;
|
||||||
|
|
||||||
for (u32 i=0; i<polygons.size(); ++i)
|
for (u32 i=0; i<polygons.size(); ++i)
|
||||||
{
|
{
|
||||||
const u32 vertexCount = polygons[i].Indices.size() / maxOffset;
|
const u32 vertexCount = polygons[i].Indices.size() / maxOffset;
|
||||||
mbuffer->Vertices.reallocate(mbuffer->Vertices.size()+vertexCount);
|
mbuffer->getVertexBuffer().reallocate(mbuffer->getVertexBuffer().size()+vertexCount);
|
||||||
// for all vertices in array
|
// for all vertices in array
|
||||||
for (u32 v=0; v<polygons[i].Indices.size(); v+=maxOffset)
|
for (u32 v=0; v<polygons[i].Indices.size(); v+=maxOffset)
|
||||||
{
|
{
|
||||||
@ -2321,31 +2327,34 @@ void CColladaFileLoader::readPolygonSection(io::IXMLReaderUTF8* reader,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mbuffer->Vertices.push_back(vtx);
|
mbuffer->getVertexBuffer().push_back(vtx);
|
||||||
|
|
||||||
} // end for all vertices
|
} // end for all vertices
|
||||||
|
|
||||||
// add vertex indices
|
// add vertex indices
|
||||||
const u32 oldVertexCount = mbuffer->Vertices.size() - vertexCount;
|
const u32 oldVertexCount = mbuffer->getVertexBuffer().size() - vertexCount;
|
||||||
for (u32 face=0; face<vertexCount-2; ++face)
|
for (u32 face=0; face<vertexCount-2; ++face)
|
||||||
{
|
{
|
||||||
mbuffer->Indices.push_back(oldVertexCount + 0);
|
mbuffer->getIndexBuffer().push_back(oldVertexCount + 0);
|
||||||
mbuffer->Indices.push_back(oldVertexCount + 1 + face);
|
mbuffer->getIndexBuffer().push_back(oldVertexCount + 1 + face);
|
||||||
mbuffer->Indices.push_back(oldVertexCount + 2 + face);
|
mbuffer->getIndexBuffer().push_back(oldVertexCount + 2 + face);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // end for all polygons
|
} // end for all polygons
|
||||||
|
|
||||||
|
if ( getIndexTypeHint() == EITH_OPTIMAL && mbuffer->getVertexCount() <= 65536 )
|
||||||
|
{
|
||||||
|
mbuffer->getIndexBuffer().setType(video::EIT_16BIT); // from 32 to 16 bit
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const SColladaMaterial* m = findMaterial(materialName);
|
const SColladaMaterial* m = findMaterial(materialName);
|
||||||
if (m)
|
if (m)
|
||||||
{
|
{
|
||||||
buffer->getMaterial() = m->Mat;
|
buffer->getMaterial() = m->Mat;
|
||||||
SMesh tmpmesh;
|
SceneManager->getMeshManipulator()->setVertexColors(buffer,m->Mat.DiffuseColor);
|
||||||
tmpmesh.addMeshBuffer(buffer);
|
|
||||||
SceneManager->getMeshManipulator()->setVertexColors(&tmpmesh,m->Mat.DiffuseColor);
|
|
||||||
if (m->Transparency != 1.0f)
|
if (m->Transparency != 1.0f)
|
||||||
SceneManager->getMeshManipulator()->setVertexColorAlpha(&tmpmesh,core::floor32(m->Transparency*255.0f));
|
SceneManager->getMeshManipulator()->setVertexColorAlpha(buffer,core::floor32(m->Transparency*255.0f));
|
||||||
}
|
}
|
||||||
// add future bind reference for the material
|
// add future bind reference for the material
|
||||||
core::stringc meshbufferReference = geometryId+"/"+materialName;
|
core::stringc meshbufferReference = geometryId+"/"+materialName;
|
||||||
|
@ -10,7 +10,6 @@
|
|||||||
#include "IVideoDriver.h"
|
#include "IVideoDriver.h"
|
||||||
#include "irrString.h"
|
#include "irrString.h"
|
||||||
#include "SMesh.h"
|
#include "SMesh.h"
|
||||||
#include "SMeshBuffer.h"
|
|
||||||
#include "ISceneManager.h"
|
#include "ISceneManager.h"
|
||||||
#include "irrMap.h"
|
#include "irrMap.h"
|
||||||
#include "CAttributes.h"
|
#include "CAttributes.h"
|
||||||
|
Loading…
Reference in New Issue
Block a user