Commit 5f25e210 authored by hybrid's avatar hybrid

Removed some unnecessary arrays. Added shininess support. Added some additional sxmesh members.

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@921 dfc29bdd-3216-0410-991c-e03cc46cb475
parent b299e9c4
...@@ -217,6 +217,7 @@ bool CXMeshFileLoader::load(io::IReadFile* file) ...@@ -217,6 +217,7 @@ bool CXMeshFileLoader::load(io::IReadFile* file)
verticesLink[i]=0; verticesLink[i]=0;
} }
// store meshbuffer number per vertex
for (i=0;i<mesh->FaceMaterialIndices.size();++i) for (i=0;i<mesh->FaceMaterialIndices.size();++i)
{ {
for (u32 id=i*3+0;id<=i*3+2;++id) for (u32 id=i*3+0;id<=i*3+2;++id)
...@@ -225,6 +226,7 @@ bool CXMeshFileLoader::load(io::IReadFile* file) ...@@ -225,6 +226,7 @@ bool CXMeshFileLoader::load(io::IReadFile* file)
} }
} }
// store vertices in buffers and remember relation in verticesLink
for (i=0;i<mesh->Vertices.size();++i) for (i=0;i<mesh->Vertices.size();++i)
{ {
scene::SSkinMeshBuffer *buffer = mesh->Buffers[ verticesLinkBuffer[i] ]; scene::SSkinMeshBuffer *buffer = mesh->Buffers[ verticesLinkBuffer[i] ];
...@@ -233,11 +235,13 @@ bool CXMeshFileLoader::load(io::IReadFile* file) ...@@ -233,11 +235,13 @@ bool CXMeshFileLoader::load(io::IReadFile* file)
buffer->Vertices_Standard.push_back( mesh->Vertices[i] ); buffer->Vertices_Standard.push_back( mesh->Vertices[i] );
} }
// create indices per buffer
for (i=0;i<mesh->FaceMaterialIndices.size();++i) for (i=0;i<mesh->FaceMaterialIndices.size();++i)
{ {
scene::SSkinMeshBuffer *buffer=mesh->Buffers[ mesh->FaceMaterialIndices[i] ]; scene::SSkinMeshBuffer *buffer = mesh->Buffers[ mesh->FaceMaterialIndices[i] ];
buffer->Indices.reallocate(buffer->Indices.size()+3);
for (u32 id=i*3+0;id<=i*3+2;++id) for (u32 id=i*3+0;id!=i*3+3;++id)
{ {
buffer->Indices.push_back( verticesLink[ mesh->Indices[id] ] ); buffer->Indices.push_back( verticesLink[ mesh->Indices[id] ] );
} }
...@@ -783,7 +787,7 @@ bool CXMeshFileLoader::parseDataObjectMesh(SXMesh &mesh) ...@@ -783,7 +787,7 @@ bool CXMeshFileLoader::parseDataObjectMesh(SXMesh &mesh)
else else
if (objectName == "XSkinMeshHeader") if (objectName == "XSkinMeshHeader")
{ {
if (!parseDataObjectSkinMeshHeader()) if (!parseDataObjectSkinMeshHeader(mesh))
return false; return false;
} }
else else
...@@ -814,7 +818,7 @@ bool CXMeshFileLoader::parseDataObjectSkinWeights(SXMesh &mesh) ...@@ -814,7 +818,7 @@ bool CXMeshFileLoader::parseDataObjectSkinWeights(SXMesh &mesh)
if (!readHeadOfDataObject()) if (!readHeadOfDataObject())
{ {
os::Printer::log("No opening brace in Skin Weights found in x file", ELL_WARNING); os::Printer::log("No opening brace in Skin Weights found in .x file", ELL_WARNING);
return false; return false;
} }
...@@ -822,7 +826,7 @@ bool CXMeshFileLoader::parseDataObjectSkinWeights(SXMesh &mesh) ...@@ -822,7 +826,7 @@ bool CXMeshFileLoader::parseDataObjectSkinWeights(SXMesh &mesh)
if (!getNextTokenAsString(TransformNodeName)) if (!getNextTokenAsString(TransformNodeName))
{ {
os::Printer::log("Unknown syntax while reading transfrom node name string in x file", ELL_WARNING); os::Printer::log("Unknown syntax while reading transfrom node name string in .x file", ELL_WARNING);
return false; return false;
} }
...@@ -849,22 +853,23 @@ bool CXMeshFileLoader::parseDataObjectSkinWeights(SXMesh &mesh) ...@@ -849,22 +853,23 @@ bool CXMeshFileLoader::parseDataObjectSkinWeights(SXMesh &mesh)
joint->Name=TransformNodeName; joint->Name=TransformNodeName;
} }
core::array<u32> Weights_Index;
core::array<f32> Weights_Strength;
// read vertex weights // read vertex weights
const s32 nWeights = readInt(); const s32 nWeights = readInt();
Weights_Index.set_used(nWeights);
Weights_Strength.set_used(nWeights);
// read vertex indices // read vertex indices
s32 i; s32 i;
const u32 jointStart = joint->Weights.size();
joint->Weights.reallocate(jointStart+nWeights);
for (i=0; i<nWeights; ++i) for (i=0; i<nWeights; ++i)
Weights_Index[i] = readInt(); {
CSkinnedMesh::SWeight *weight=AnimatedMesh->createWeight(joint);
weight->buffer_id=0;
weight->vertex_id=readInt();
}
// read vertex weights // read vertex weights
...@@ -885,18 +890,14 @@ bool CXMeshFileLoader::parseDataObjectSkinWeights(SXMesh &mesh) ...@@ -885,18 +890,14 @@ bool CXMeshFileLoader::parseDataObjectSkinWeights(SXMesh &mesh)
} }
for (i=0; i<nWeights; ++i) for (i=0; i<nWeights; ++i)
Weights_Strength[i] = readFloat(); joint->Weights[i].strength = readFloat();
// sort weights
//weights.Weights.set_sorted(false);
//weights.Weights.sort();
// read matrix offset // read matrix offset
core::matrix4 MatrixOffset; // transforms the mesh vertices to the space of the bone // transforms the mesh vertices to the space of the bone
// When concatenated to the bone's transform, this provides the // When concatenated to the bone's transform, this provides the
// world space coordinates of the mesh as affected by the bone // world space coordinates of the mesh as affected by the bone
core::matrix4& MatrixOffset = joint->GlobalInversedMatrix;
for (i=0; i<4; ++i) for (i=0; i<4; ++i)
{ {
...@@ -904,17 +905,6 @@ bool CXMeshFileLoader::parseDataObjectSkinWeights(SXMesh &mesh) ...@@ -904,17 +905,6 @@ bool CXMeshFileLoader::parseDataObjectSkinWeights(SXMesh &mesh)
MatrixOffset(i,j) = readFloat(); MatrixOffset(i,j) = readFloat();
} }
joint->GlobalInversedMatrix=MatrixOffset;
for (i=0; i<nWeights; ++i)
{
CSkinnedMesh::SWeight *weight=AnimatedMesh->createWeight(joint);
weight->buffer_id=0;
weight->vertex_id=Weights_Index[i];
weight->strength=Weights_Strength[i];
}
if (!checkForTwoFollowingSemicolons()) if (!checkForTwoFollowingSemicolons())
{ {
os::Printer::log("No finishing semicolon in Skin Weights found in x file", ELL_WARNING); os::Printer::log("No finishing semicolon in Skin Weights found in x file", ELL_WARNING);
...@@ -931,7 +921,7 @@ bool CXMeshFileLoader::parseDataObjectSkinWeights(SXMesh &mesh) ...@@ -931,7 +921,7 @@ bool CXMeshFileLoader::parseDataObjectSkinWeights(SXMesh &mesh)
} }
bool CXMeshFileLoader::parseDataObjectSkinMeshHeader() bool CXMeshFileLoader::parseDataObjectSkinMeshHeader(SXMesh& mesh)
{ {
#ifdef _XREADER_DEBUG #ifdef _XREADER_DEBUG
os::Printer::log("CXFileReader: Reading skin mesh header"); os::Printer::log("CXFileReader: Reading skin mesh header");
...@@ -939,16 +929,18 @@ bool CXMeshFileLoader::parseDataObjectSkinMeshHeader() ...@@ -939,16 +929,18 @@ bool CXMeshFileLoader::parseDataObjectSkinMeshHeader()
if (!readHeadOfDataObject()) if (!readHeadOfDataObject())
{ {
os::Printer::log("No opening brace in Skin Mesh header found in x file", ELL_WARNING); os::Printer::log("No opening brace in Skin Mesh header found in .x file", ELL_WARNING);
return false; return false;
} }
readInt(); //MaxSkinWeightsPerVertex mesh.MaxSkinWeightsPerVertex = readInt();
readInt(); //MaxSkinWeightsPerFace mesh.MaxSkinWeightsPerFace = readInt();
readInt(); //BoneCount mesh.BoneCount = readInt();
if (!BinaryFormat) if (!BinaryFormat)
getNextToken(); // skip semicolon getNextToken(); // skip semicolon
core::stringc objectName = getNextToken();
const core::stringc objectName = getNextToken();
if (objectName != "}") if (objectName != "}")
{ {
...@@ -1271,7 +1263,7 @@ bool CXMeshFileLoader::parseDataObjectMaterial(video::SMaterial& material) ...@@ -1271,7 +1263,7 @@ bool CXMeshFileLoader::parseDataObjectMaterial(video::SMaterial& material)
if (!readHeadOfDataObject()) if (!readHeadOfDataObject())
{ {
os::Printer::log("No opening brace in Mesh Material found in x file", ELL_WARNING); os::Printer::log("No opening brace in Mesh Material found in .x file", ELL_WARNING);
return false; return false;
} }
...@@ -1295,8 +1287,7 @@ bool CXMeshFileLoader::parseDataObjectMaterial(video::SMaterial& material) ...@@ -1295,8 +1287,7 @@ bool CXMeshFileLoader::parseDataObjectMaterial(video::SMaterial& material)
readRGBA(material.DiffuseColor); checkForOneFollowingSemicolons(); readRGBA(material.DiffuseColor); checkForOneFollowingSemicolons();
// read power // read power
//material.Power = readFloat(); material.Shininess = readFloat();
readFloat();
// read specular // read specular
readRGB(material.SpecularColor); checkForOneFollowingSemicolons(); readRGB(material.SpecularColor); checkForOneFollowingSemicolons();
...@@ -1311,7 +1302,7 @@ bool CXMeshFileLoader::parseDataObjectMaterial(video::SMaterial& material) ...@@ -1311,7 +1302,7 @@ bool CXMeshFileLoader::parseDataObjectMaterial(video::SMaterial& material)
if (objectName.size() == 0) if (objectName.size() == 0)
{ {
os::Printer::log("Unexpected ending found in Mesh Material in x file.", ELL_WARNING); os::Printer::log("Unexpected ending found in Mesh Material in .x file.", ELL_WARNING);
return false; return false;
} }
else else
...@@ -1341,7 +1332,7 @@ bool CXMeshFileLoader::parseDataObjectMaterial(video::SMaterial& material) ...@@ -1341,7 +1332,7 @@ bool CXMeshFileLoader::parseDataObjectMaterial(video::SMaterial& material)
} }
else else
{ {
os::Printer::log("Unknown data object in material in x file", objectName.c_str(), ELL_WARNING); os::Printer::log("Unknown data object in material in .x file", objectName.c_str(), ELL_WARNING);
if (!parseUnknownDataObject()) if (!parseUnknownDataObject())
return false; return false;
} }
......
...@@ -46,6 +46,7 @@ public: ...@@ -46,6 +46,7 @@ public:
struct SXMesh struct SXMesh
{ {
SXMesh() : MaxSkinWeightsPerVertex(0), MaxSkinWeightsPerFace(0), BoneCount(0) {}
// this mesh contains triangulated texture data. // this mesh contains triangulated texture data.
// because in an .x file, faces can be made of more than 3 // because in an .x file, faces can be made of more than 3
// vertices, the indices data structure is triangulated during the // vertices, the indices data structure is triangulated during the
...@@ -56,6 +57,10 @@ public: ...@@ -56,6 +57,10 @@ public:
core::stringc Name; core::stringc Name;
s32 MaxSkinWeightsPerVertex;
s32 MaxSkinWeightsPerFace;
s32 BoneCount;
core::array< s32 > IndexCountPerFace; // default 3, but could be more core::array< s32 > IndexCountPerFace; // default 3, but could be more
core::array<scene::SSkinMeshBuffer*> Buffers; core::array<scene::SSkinMeshBuffer*> Buffers;
...@@ -90,7 +95,7 @@ private: ...@@ -90,7 +95,7 @@ private:
bool parseDataObjectSkinWeights(SXMesh &mesh); bool parseDataObjectSkinWeights(SXMesh &mesh);
bool parseDataObjectSkinMeshHeader(); bool parseDataObjectSkinMeshHeader(SXMesh &mesh);
bool parseDataObjectMeshNormals(SXMesh &mesh); bool parseDataObjectMeshNormals(SXMesh &mesh);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment