Just the functional assimp lib rather than the entire assimp repository unnecessarily.

This commit is contained in:
Areloch 2019-02-28 16:37:15 -06:00
parent bf170ffbca
commit 25ce4477ce
1747 changed files with 9012 additions and 925008 deletions

View file

@ -2,8 +2,7 @@
Open Asset Import Library (assimp)
----------------------------------------------------------------------
Copyright (c) 2006-2018, assimp team
Copyright (c) 2006-2017, assimp team
All rights reserved.
@ -41,9 +40,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <utility>
#include "MMDPmxParser.h"
#include <assimp/StringUtils.h>
#include "../contrib/utf8cpp/source/utf8.h"
#include <assimp/Exceptional.h>
#include "Exceptional.h"
namespace pmx
{
@ -94,15 +92,16 @@ namespace pmx
if (encoding == 0)
{
// UTF16 to UTF8
const uint16_t* sourceStart = (uint16_t*)buffer.data();
const unsigned int targetSize = size * 3; // enough to encode
char *targetStart = new char[targetSize];
std::memset(targetStart, 0, targetSize * sizeof(char));
utf8::utf16to8( sourceStart, sourceStart + size/2, targetStart );
std::string result;
std::string result(targetStart);
delete [] targetStart;
const char* sourceStart = buffer.data();
const unsigned int targetSize = size * 3; // enough to encode
char* targetStart = new char[targetSize]();
const char* targetReserved = targetStart;
utf8::utf16to8( sourceStart, sourceStart + size, targetStart );
result.assign(targetReserved, targetStart - targetReserved);
delete[] targetReserved;
return result;
}
else
@ -118,7 +117,7 @@ namespace pmx
stream->read((char*) &count, sizeof(uint8_t));
if (count < 8)
{
throw DeadlyImportError("MMD: invalid size");
throw;
}
stream->read((char*) &encoding, sizeof(uint8_t));
stream->read((char*) &uv, sizeof(uint8_t));
@ -395,7 +394,7 @@ namespace pmx
}
break;
default:
throw DeadlyImportError("MMD: unknown morth type");
throw;
}
}
@ -474,9 +473,10 @@ namespace pmx
void PmxSoftBody::Read(std::istream * /*stream*/, PmxSetting * /*setting*/)
{
// 未実装
std::cerr << "Not Implemented Exception" << std::endl;
throw DeadlyImportError("MMD: Not Implemented Exception");
}
throw;
}
void PmxModel::Init()
{
@ -509,27 +509,31 @@ namespace pmx
void PmxModel::Read(std::istream *stream)
{
// マジック
char magic[4];
stream->read((char*) magic, sizeof(char) * 4);
if (magic[0] != 0x50 || magic[1] != 0x4d || magic[2] != 0x58 || magic[3] != 0x20)
{
std::cerr << "invalid magic number." << std::endl;
throw DeadlyImportError("MMD: invalid magic number.");
}
throw;
}
// バージョン
stream->read((char*) &version, sizeof(float));
if (version != 2.0f && version != 2.1f)
{
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;
}
// ファイル設定
this->setting.Read(stream);
// モデル情報
this->model_name = ReadString(stream, setting.encoding);
this->model_english_name = ReadString(stream, setting.encoding);
this->model_comment = ReadString(stream, setting.encoding);
this->model_english_comment = ReadString(stream, setting.encoding);
// read vertices
// 頂点
stream->read((char*) &vertex_count, sizeof(int));
this->vertices = mmd::make_unique<PmxVertex []>(vertex_count);
for (int i = 0; i < vertex_count; i++)
@ -537,7 +541,7 @@ namespace pmx
vertices[i].Read(stream, &setting);
}
// read indices
//
stream->read((char*) &index_count, sizeof(int));
this->indices = mmd::make_unique<int []>(index_count);
for (int i = 0; i < index_count; i++)
@ -545,7 +549,7 @@ namespace pmx
this->indices[i] = ReadIndex(stream, setting.vertex_index_size);
}
// read texture names
// テクスチャ
stream->read((char*) &texture_count, sizeof(int));
this->textures = mmd::make_unique<std::string []>(texture_count);
for (int i = 0; i < texture_count; i++)
@ -553,7 +557,7 @@ namespace pmx
this->textures[i] = ReadString(stream, setting.encoding);
}
// read materials
// マテリアル
stream->read((char*) &material_count, sizeof(int));
this->materials = mmd::make_unique<PmxMaterial []>(material_count);
for (int i = 0; i < material_count; i++)
@ -561,7 +565,7 @@ namespace pmx
this->materials[i].Read(stream, &setting);
}
// read bones
// ボーン
stream->read((char*) &this->bone_count, sizeof(int));
this->bones = mmd::make_unique<PmxBone []>(this->bone_count);
for (int i = 0; i < this->bone_count; i++)
@ -569,7 +573,7 @@ namespace pmx
this->bones[i].Read(stream, &setting);
}
// read morphs
// モーフ
stream->read((char*) &this->morph_count, sizeof(int));
this->morphs = mmd::make_unique<PmxMorph []>(this->morph_count);
for (int i = 0; i < this->morph_count; i++)
@ -577,7 +581,7 @@ namespace pmx
this->morphs[i].Read(stream, &setting);
}
// read display frames
// 表示枠
stream->read((char*) &this->frame_count, sizeof(int));
this->frames = mmd::make_unique<PmxFrame []>(this->frame_count);
for (int i = 0; i < this->frame_count; i++)
@ -585,7 +589,7 @@ namespace pmx
this->frames[i].Read(stream, &setting);
}
// read rigid bodies
// 剛体
stream->read((char*) &this->rigid_body_count, sizeof(int));
this->rigid_bodies = mmd::make_unique<PmxRigidBody []>(this->rigid_body_count);
for (int i = 0; i < this->rigid_body_count; i++)
@ -593,12 +597,41 @@ namespace pmx
this->rigid_bodies[i].Read(stream, &setting);
}
// read joints
// ジョイント
stream->read((char*) &this->joint_count, sizeof(int));
this->joints = mmd::make_unique<PmxJoint []>(this->joint_count);
for (int i = 0; i < this->joint_count; i++)
{
this->joints[i].Read(stream, &setting);
}
//if (this->version == 2.1f)
//{
// stream->read((char*) &this->soft_body_count, sizeof(int));
// this->soft_bodies = mmd::make_unique<PmxSoftBody []>(this->soft_body_count);
// for (int i = 0; i < this->soft_body_count; i++)
// {
// this->soft_bodies[i].Read(stream, &setting);
// }
//}
}
//std::unique_ptr<PmxModel> ReadFromFile(const char *filename)
//{
// auto stream = std::ifstream(filename, std::ios_base::binary);
// auto pmx = PmxModel::ReadFromStream(&stream);
// if (!stream.eof())
// {
// std::cerr << "don't reach the end of file." << std::endl;
// }
// stream.close();
// return pmx;
//}
//std::unique_ptr<PmxModel> ReadFromStream(std::istream *stream)
//{
// auto pmx = mmd::make_unique<PmxModel>();
// pmx->Read(stream);
// return pmx;
//}
}