Make SPM loader more portable (for stk-editor later)
Also allow calculating normal if required
This commit is contained in:
parent
d698e62053
commit
a8e20101f8
@ -48,7 +48,7 @@ scene::IAnimatedMesh* SPMeshLoader::createMesh(io::IReadFile* f)
|
||||
m_joint_count = 0;
|
||||
//m_frame_count = 0;
|
||||
m_mesh = NULL;
|
||||
m_mesh = new scene::CSkinnedMesh();
|
||||
m_mesh = m_scene_manager->createSkinnedMesh();
|
||||
io::IFileSystem* fs = m_scene_manager->getFileSystem();
|
||||
std::string base_path = fs->getFileDir(f->getFileName()).c_str();
|
||||
std::string header;
|
||||
@ -325,6 +325,23 @@ void SPMeshLoader::decompress(irr::io::IReadFile* spm, unsigned vertices_count,
|
||||
mb->Indices[i] = tmp_idx[i];
|
||||
}
|
||||
}
|
||||
|
||||
if (!read_normal)
|
||||
{
|
||||
for (unsigned i = 0; i < mb->Indices.size(); i += 3)
|
||||
{
|
||||
core::plane3df p(mb->getVertex(mb->Indices[i])->Pos,
|
||||
mb->getVertex(mb->Indices[i + 1])->Pos,
|
||||
mb->getVertex(mb->Indices[i + 2])->Pos);
|
||||
mb->getVertex(mb->Indices[i])->Normal += p.Normal;
|
||||
mb->getVertex(mb->Indices[i + 1])->Normal += p.Normal;
|
||||
mb->getVertex(mb->Indices[i + 2])->Normal += p.Normal;
|
||||
}
|
||||
for (unsigned i = 0; i < mb->getVertexCount(); i++)
|
||||
{
|
||||
mb->getVertex(i)->Normal.normalize();
|
||||
}
|
||||
}
|
||||
} // decompress
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
@ -408,7 +425,7 @@ void SPMeshLoader::convertIrrlicht()
|
||||
{
|
||||
m_mesh->addJoint(NULL);
|
||||
}
|
||||
core::array<scene::CSkinnedMesh::SJoint*>& joints = m_mesh->getAllJoints();
|
||||
core::array<scene::ISkinnedMesh::SJoint*>& joints = m_mesh->getAllJoints();
|
||||
std::vector<int> used_joints_map;
|
||||
used_joints_map.resize(m_joint_count);
|
||||
total_joints = 0;
|
||||
@ -468,7 +485,7 @@ void SPMeshLoader::convertIrrlicht()
|
||||
{
|
||||
break;
|
||||
}
|
||||
scene::CSkinnedMesh::SWeight* w = m_mesh->addWeight
|
||||
scene::ISkinnedMesh::SWeight* w = m_mesh->addWeight
|
||||
(joints[used_joints_map[m_joints[i][j].first[k]]]);
|
||||
w->buffer_id = (uint16_t)i;
|
||||
w->vertex_id = j;
|
||||
|
@ -18,13 +18,12 @@
|
||||
#ifndef HEADER_SP_MESH_LOADER_HPP
|
||||
#define HEADER_SP_MESH_LOADER_HPP
|
||||
|
||||
#include "../lib/irrlicht/source/Irrlicht/CSkinnedMesh.h"
|
||||
#include "utils/types.hpp"
|
||||
|
||||
#include <IMeshLoader.h>
|
||||
#include <ISceneManager.h>
|
||||
#include <ISkinnedMesh.h>
|
||||
#include <IReadFile.h>
|
||||
#include <array>
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
|
||||
using namespace irr;
|
||||
@ -382,7 +381,7 @@ private:
|
||||
// ------------------------------------------------------------------------
|
||||
void convertIrrlicht();
|
||||
|
||||
scene::CSkinnedMesh* m_mesh;
|
||||
scene::ISkinnedMesh* m_mesh;
|
||||
|
||||
scene::ISceneManager* m_scene_manager;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user