Merge branch 'master' into kimmi_dev

pull/2153/head
Kim Kulling 2018-09-22 15:52:22 +02:00 committed by GitHub
commit 72aa49c54f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 36 deletions

View File

@ -72,18 +72,16 @@ using namespace std;
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
// Default constructor // Default constructor
MMDImporter::MMDImporter() MMDImporter::MMDImporter()
: m_Buffer(), : m_Buffer()
// m_pRootObject( NULL ), , m_strAbsPath("") {
m_strAbsPath("") { DefaultIOSystem io;
DefaultIOSystem io; m_strAbsPath = io.getOsSeparator();
m_strAbsPath = io.getOsSeparator();
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
// Destructor. // Destructor.
MMDImporter::~MMDImporter() { MMDImporter::~MMDImporter() {
// delete m_pRootObject; // empty
// m_pRootObject = NULL;
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
@ -96,8 +94,7 @@ bool MMDImporter::CanRead(const std::string &pFile, IOSystem *pIOHandler,
} else // Check file Header } else // Check file Header
{ {
static const char *pTokens[] = {"PMX "}; static const char *pTokens[] = {"PMX "};
return BaseImporter::SearchFileHeaderForToken(pIOHandler, pFile, pTokens, return BaseImporter::SearchFileHeaderForToken(pIOHandler, pFile, pTokens, 1);
1);
} }
} }
@ -354,8 +351,11 @@ aiMaterial *MMDImporter::CreateMaterial(const pmx::PmxMaterial *pMat,
float shininess = pMat->specularlity; float shininess = pMat->specularlity;
mat->AddProperty(&shininess, 1, AI_MATKEY_SHININESS_STRENGTH); mat->AddProperty(&shininess, 1, AI_MATKEY_SHININESS_STRENGTH);
aiString texture_path(pModel->textures[pMat->diffuse_texture_index]); if(pMat->diffuse_texture_index >= 0) {
mat->AddProperty(&texture_path, AI_MATKEY_TEXTURE(aiTextureType_DIFFUSE, 0)); aiString texture_path(pModel->textures[pMat->diffuse_texture_index]);
mat->AddProperty(&texture_path, AI_MATKEY_TEXTURE(aiTextureType_DIFFUSE, 0));
}
int mapping_uvwsrc = 0; int mapping_uvwsrc = 0;
mat->AddProperty(&mapping_uvwsrc, 1, mat->AddProperty(&mapping_uvwsrc, 1,
AI_MATKEY_UVWSRC(aiTextureType_DIFFUSE, 0)); AI_MATKEY_UVWSRC(aiTextureType_DIFFUSE, 0));

View File

@ -94,16 +94,15 @@ namespace pmx
if (encoding == 0) if (encoding == 0)
{ {
// UTF16 to UTF8 // UTF16 to UTF8
std::string result; const uint16_t* sourceStart = (uint16_t*)buffer.data();
const char* sourceStart = buffer.data();
const unsigned int targetSize = size * 3; // enough to encode const unsigned int targetSize = size * 3; // enough to encode
char* targetStart = new char[targetSize](); char *targetStart = new char[targetSize];
const char* targetReserved = targetStart; std::memset(targetStart, 0, targetSize * sizeof(char));
utf8::utf16to8( sourceStart, sourceStart + size, targetStart );
utf8::utf16to8( sourceStart, sourceStart + size/2, targetStart );
result.assign(targetReserved, targetStart - targetReserved); std::string result(targetStart);
delete[] targetReserved; delete [] targetStart;
return result; return result;
} }
else else
@ -475,7 +474,6 @@ namespace pmx
void PmxSoftBody::Read(std::istream * /*stream*/, PmxSetting * /*setting*/) void PmxSoftBody::Read(std::istream * /*stream*/, PmxSetting * /*setting*/)
{ {
// 未実装
std::cerr << "Not Implemented Exception" << std::endl; std::cerr << "Not Implemented Exception" << std::endl;
throw DeadlyImportError("MMD: Not Implemented Exception"); throw DeadlyImportError("MMD: Not Implemented Exception");
} }
@ -511,31 +509,27 @@ namespace pmx
void PmxModel::Read(std::istream *stream) void PmxModel::Read(std::istream *stream)
{ {
// マジック
char magic[4]; char magic[4];
stream->read((char*) magic, sizeof(char) * 4); stream->read((char*) magic, sizeof(char) * 4);
if (magic[0] != 0x50 || magic[1] != 0x4d || magic[2] != 0x58 || magic[3] != 0x20) if (magic[0] != 0x50 || magic[1] != 0x4d || magic[2] != 0x58 || magic[3] != 0x20)
{ {
std::cerr << "invalid magic number." << std::endl; std::cerr << "invalid magic number." << std::endl;
throw DeadlyImportError("MMD: invalid magic number."); throw DeadlyImportError("MMD: invalid magic number.");
} }
// バージョン
stream->read((char*) &version, sizeof(float)); stream->read((char*) &version, sizeof(float));
if (version != 2.0f && version != 2.1f) if (version != 2.0f && version != 2.1f)
{ {
std::cerr << "this is not ver2.0 or ver2.1 but " << version << "." << std::endl; std::cerr << "this is not ver2.0 or ver2.1 but " << version << "." << std::endl;
throw DeadlyImportError("MMD: this is not ver2.0 or ver2.1 but " + to_string(version)); throw DeadlyImportError("MMD: this is not ver2.0 or ver2.1 but " + to_string(version));
} }
// ファイル設定
this->setting.Read(stream); this->setting.Read(stream);
// モデル情報
this->model_name = ReadString(stream, setting.encoding); this->model_name = ReadString(stream, setting.encoding);
this->model_english_name = ReadString(stream, setting.encoding); this->model_english_name = ReadString(stream, setting.encoding);
this->model_comment = ReadString(stream, setting.encoding); this->model_comment = ReadString(stream, setting.encoding);
this->model_english_comment = ReadString(stream, setting.encoding); this->model_english_comment = ReadString(stream, setting.encoding);
// 頂点 // read vertices
stream->read((char*) &vertex_count, sizeof(int)); stream->read((char*) &vertex_count, sizeof(int));
this->vertices = mmd::make_unique<PmxVertex []>(vertex_count); this->vertices = mmd::make_unique<PmxVertex []>(vertex_count);
for (int i = 0; i < vertex_count; i++) for (int i = 0; i < vertex_count; i++)
@ -543,7 +537,7 @@ namespace pmx
vertices[i].Read(stream, &setting); vertices[i].Read(stream, &setting);
} }
// // read indices
stream->read((char*) &index_count, sizeof(int)); stream->read((char*) &index_count, sizeof(int));
this->indices = mmd::make_unique<int []>(index_count); this->indices = mmd::make_unique<int []>(index_count);
for (int i = 0; i < index_count; i++) for (int i = 0; i < index_count; i++)
@ -551,7 +545,7 @@ namespace pmx
this->indices[i] = ReadIndex(stream, setting.vertex_index_size); this->indices[i] = ReadIndex(stream, setting.vertex_index_size);
} }
// テクスチャ // read texture names
stream->read((char*) &texture_count, sizeof(int)); stream->read((char*) &texture_count, sizeof(int));
this->textures = mmd::make_unique<std::string []>(texture_count); this->textures = mmd::make_unique<std::string []>(texture_count);
for (int i = 0; i < texture_count; i++) for (int i = 0; i < texture_count; i++)
@ -559,7 +553,7 @@ namespace pmx
this->textures[i] = ReadString(stream, setting.encoding); this->textures[i] = ReadString(stream, setting.encoding);
} }
// マテリアル // read materials
stream->read((char*) &material_count, sizeof(int)); stream->read((char*) &material_count, sizeof(int));
this->materials = mmd::make_unique<PmxMaterial []>(material_count); this->materials = mmd::make_unique<PmxMaterial []>(material_count);
for (int i = 0; i < material_count; i++) for (int i = 0; i < material_count; i++)
@ -567,7 +561,7 @@ namespace pmx
this->materials[i].Read(stream, &setting); this->materials[i].Read(stream, &setting);
} }
// ボーン // read bones
stream->read((char*) &this->bone_count, sizeof(int)); stream->read((char*) &this->bone_count, sizeof(int));
this->bones = mmd::make_unique<PmxBone []>(this->bone_count); this->bones = mmd::make_unique<PmxBone []>(this->bone_count);
for (int i = 0; i < this->bone_count; i++) for (int i = 0; i < this->bone_count; i++)
@ -575,7 +569,7 @@ namespace pmx
this->bones[i].Read(stream, &setting); this->bones[i].Read(stream, &setting);
} }
// モーフ // read morphs
stream->read((char*) &this->morph_count, sizeof(int)); stream->read((char*) &this->morph_count, sizeof(int));
this->morphs = mmd::make_unique<PmxMorph []>(this->morph_count); this->morphs = mmd::make_unique<PmxMorph []>(this->morph_count);
for (int i = 0; i < this->morph_count; i++) for (int i = 0; i < this->morph_count; i++)
@ -583,7 +577,7 @@ namespace pmx
this->morphs[i].Read(stream, &setting); this->morphs[i].Read(stream, &setting);
} }
// 表示枠 // read display frames
stream->read((char*) &this->frame_count, sizeof(int)); stream->read((char*) &this->frame_count, sizeof(int));
this->frames = mmd::make_unique<PmxFrame []>(this->frame_count); this->frames = mmd::make_unique<PmxFrame []>(this->frame_count);
for (int i = 0; i < this->frame_count; i++) for (int i = 0; i < this->frame_count; i++)
@ -591,7 +585,7 @@ namespace pmx
this->frames[i].Read(stream, &setting); this->frames[i].Read(stream, &setting);
} }
// 剛体 // read rigid bodies
stream->read((char*) &this->rigid_body_count, sizeof(int)); stream->read((char*) &this->rigid_body_count, sizeof(int));
this->rigid_bodies = mmd::make_unique<PmxRigidBody []>(this->rigid_body_count); this->rigid_bodies = mmd::make_unique<PmxRigidBody []>(this->rigid_body_count);
for (int i = 0; i < this->rigid_body_count; i++) for (int i = 0; i < this->rigid_body_count; i++)
@ -599,7 +593,7 @@ namespace pmx
this->rigid_bodies[i].Read(stream, &setting); this->rigid_bodies[i].Read(stream, &setting);
} }
// ジョイント // read joints
stream->read((char*) &this->joint_count, sizeof(int)); stream->read((char*) &this->joint_count, sizeof(int));
this->joints = mmd::make_unique<PmxJoint []>(this->joint_count); this->joints = mmd::make_unique<PmxJoint []>(this->joint_count);
for (int i = 0; i < this->joint_count; i++) for (int i = 0; i < this->joint_count; i++)