* Adjustment: Update Assimp version to 5.0.1.

This commit is contained in:
Robert MacGregor 2021-10-21 21:14:55 -04:00
parent 14ebeaf3eb
commit 4758f7bdaf
679 changed files with 50502 additions and 19698 deletions

View file

@ -2,7 +2,7 @@
Open Asset Import Library (assimp)
----------------------------------------------------------------------
Copyright (c) 2006-2020, assimp team
Copyright (c) 2006-2019, assimp team
All rights reserved.
@ -46,7 +46,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "glTF2/glTF2AssetWriter.h"
#include "PostProcessing/SplitLargeMeshes.h"
#include <assimp/commonMetaData.h>
#include <assimp/Exceptional.h>
#include <assimp/StringComparison.h>
#include <assimp/ByteSwapper.h>
@ -59,7 +58,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Header files, standard library.
#include <memory>
#include <limits>
#include <inttypes.h>
using namespace rapidjson;
@ -141,7 +139,10 @@ static void CopyValue(const aiMatrix4x4& v, mat4& o) {
}
static void CopyValue(const aiMatrix4x4& v, aiMatrix4x4& o) {
memcpy(&o, &v, sizeof(aiMatrix4x4));
o.a1 = v.a1; o.a2 = v.a2; o.a3 = v.a3; o.a4 = v.a4;
o.b1 = v.b1; o.b2 = v.b2; o.b3 = v.b3; o.b4 = v.b4;
o.c1 = v.c1; o.c2 = v.c2; o.c3 = v.c3; o.c4 = v.c4;
o.d1 = v.d1; o.d2 = v.d2; o.d3 = v.d3; o.d4 = v.d4;
}
static void IdentityMatrix4(mat4& o) {
@ -151,64 +152,8 @@ static void IdentityMatrix4(mat4& o) {
o[12] = 0; o[13] = 0; o[14] = 0; o[15] = 1;
}
template<typename T>
void SetAccessorRange(Ref<Accessor> acc, void* data, size_t count,
unsigned int numCompsIn, unsigned int numCompsOut)
{
ai_assert(numCompsOut <= numCompsIn);
// Allocate and initialize with large values.
for (unsigned int i = 0 ; i < numCompsOut ; i++) {
acc->min.push_back( std::numeric_limits<double>::max());
acc->max.push_back(-std::numeric_limits<double>::max());
}
size_t totalComps = count * numCompsIn;
T* buffer_ptr = static_cast<T*>(data);
T* buffer_end = buffer_ptr + totalComps;
// Search and set extreme values.
for (; buffer_ptr < buffer_end ; buffer_ptr += numCompsIn) {
for (unsigned int j = 0 ; j < numCompsOut ; j++) {
double valueTmp = buffer_ptr[j];
if (valueTmp < acc->min[j]) {
acc->min[j] = valueTmp;
}
if (valueTmp > acc->max[j]) {
acc->max[j] = valueTmp;
}
}
}
}
inline void SetAccessorRange(ComponentType compType, Ref<Accessor> acc, void* data,
size_t count, unsigned int numCompsIn, unsigned int numCompsOut)
{
switch (compType) {
case ComponentType_SHORT:
SetAccessorRange<short>(acc, data, count, numCompsIn, numCompsOut);
return;
case ComponentType_UNSIGNED_SHORT:
SetAccessorRange<unsigned short>(acc, data, count, numCompsIn, numCompsOut);
return;
case ComponentType_UNSIGNED_INT:
SetAccessorRange<unsigned int>(acc, data, count, numCompsIn, numCompsOut);
return;
case ComponentType_FLOAT:
SetAccessorRange<float>(acc, data, count, numCompsIn, numCompsOut);
return;
case ComponentType_BYTE:
SetAccessorRange<int8_t>(acc, data, count, numCompsIn, numCompsOut);
return;
case ComponentType_UNSIGNED_BYTE:
SetAccessorRange<uint8_t>(acc, data, count, numCompsIn, numCompsOut);
return;
}
}
inline Ref<Accessor> ExportData(Asset& a, std::string& meshName, Ref<Buffer>& buffer,
size_t count, void* data, AttribType::Value typeIn, AttribType::Value typeOut, ComponentType compType, BufferViewTarget target = BufferViewTarget_NONE)
size_t count, void* data, AttribType::Value typeIn, AttribType::Value typeOut, ComponentType compType, bool isIndices = false)
{
if (!count || !data) {
return Ref<Accessor>();
@ -231,7 +176,7 @@ inline Ref<Accessor> ExportData(Asset& a, std::string& meshName, Ref<Buffer>& bu
bv->byteOffset = offset;
bv->byteLength = length; //! The target that the WebGL buffer should be bound to.
bv->byteStride = 0;
bv->target = target;
bv->target = isIndices ? BufferViewTarget_ELEMENT_ARRAY_BUFFER : BufferViewTarget_ARRAY_BUFFER;
// accessor
Ref<Accessor> acc = a.accessors.Create(a.FindUniqueID(meshName, "accessor"));
@ -242,7 +187,33 @@ inline Ref<Accessor> ExportData(Asset& a, std::string& meshName, Ref<Buffer>& bu
acc->type = typeOut;
// calculate min and max values
SetAccessorRange(compType, acc, data, count, numCompsIn, numCompsOut);
{
// Allocate and initialize with large values.
float float_MAX = 10000000000000.0f;
for (unsigned int i = 0 ; i < numCompsOut ; i++) {
acc->min.push_back( float_MAX);
acc->max.push_back(-float_MAX);
}
// Search and set extreme values.
float valueTmp;
for (unsigned int i = 0 ; i < count ; i++) {
for (unsigned int j = 0 ; j < numCompsOut ; j++) {
if (numCompsOut == 1) {
valueTmp = static_cast<unsigned short*>(data)[i];
} else {
valueTmp = static_cast<aiVector3D*>(data)[i][j];
}
if (valueTmp < acc->min[j]) {
acc->min[j] = valueTmp;
}
if (valueTmp > acc->max[j]) {
acc->max[j] = valueTmp;
}
}
}
}
// copy the data
acc->WriteData(count, data, numCompsIn*bytesPerComp);
@ -348,11 +319,9 @@ void glTF2Exporter::GetMatTex(const aiMaterial* mat, Ref<Texture>& texture, aiTe
if (path[0] == '*') { // embedded
aiTexture* tex = mScene->mTextures[atoi(&path[1])];
texture->source->name = tex->mFilename.C_Str();
// The asset has its own buffer, see Image::SetData
texture->source->SetData(reinterpret_cast<uint8_t*> (tex->pcData), tex->mWidth, *mAsset);
uint8_t* data = reinterpret_cast<uint8_t*>(tex->pcData);
texture->source->SetData(data, tex->mWidth, *mAsset);
if (tex->achFormatHint[0]) {
std::string mimeType = "image/";
@ -744,7 +713,7 @@ void glTF2Exporter::ExportMeshes()
p.material = mAsset->materials.Get(aim->mMaterialIndex);
/******************* Vertices ********************/
Ref<Accessor> v = ExportData(*mAsset, meshId, b, aim->mNumVertices, aim->mVertices, AttribType::VEC3, AttribType::VEC3, ComponentType_FLOAT, BufferViewTarget_ARRAY_BUFFER);
Ref<Accessor> v = ExportData(*mAsset, meshId, b, aim->mNumVertices, aim->mVertices, AttribType::VEC3, AttribType::VEC3, ComponentType_FLOAT);
if (v) p.attributes.position.push_back(v);
/******************** Normals ********************/
@ -755,7 +724,7 @@ void glTF2Exporter::ExportMeshes()
}
}
Ref<Accessor> n = ExportData(*mAsset, meshId, b, aim->mNumVertices, aim->mNormals, AttribType::VEC3, AttribType::VEC3, ComponentType_FLOAT, BufferViewTarget_ARRAY_BUFFER);
Ref<Accessor> n = ExportData(*mAsset, meshId, b, aim->mNumVertices, aim->mNormals, AttribType::VEC3, AttribType::VEC3, ComponentType_FLOAT);
if (n) p.attributes.normal.push_back(n);
/************** Texture coordinates **************/
@ -773,14 +742,14 @@ void glTF2Exporter::ExportMeshes()
if (aim->mNumUVComponents[i] > 0) {
AttribType::Value type = (aim->mNumUVComponents[i] == 2) ? AttribType::VEC2 : AttribType::VEC3;
Ref<Accessor> tc = ExportData(*mAsset, meshId, b, aim->mNumVertices, aim->mTextureCoords[i], AttribType::VEC3, type, ComponentType_FLOAT, BufferViewTarget_ARRAY_BUFFER);
Ref<Accessor> tc = ExportData(*mAsset, meshId, b, aim->mNumVertices, aim->mTextureCoords[i], AttribType::VEC3, type, ComponentType_FLOAT, false);
if (tc) p.attributes.texcoord.push_back(tc);
}
}
/*************** Vertex colors ****************/
for (unsigned int indexColorChannel = 0; indexColorChannel < aim->GetNumColorChannels(); ++indexColorChannel) {
Ref<Accessor> c = ExportData(*mAsset, meshId, b, aim->mNumVertices, aim->mColors[indexColorChannel], AttribType::VEC4, AttribType::VEC4, ComponentType_FLOAT, BufferViewTarget_ARRAY_BUFFER);
Ref<Accessor> c = ExportData(*mAsset, meshId, b, aim->mNumVertices, aim->mColors[indexColorChannel], AttribType::VEC4, AttribType::VEC4, ComponentType_FLOAT, false);
if (c)
p.attributes.color.push_back(c);
}
@ -796,7 +765,7 @@ void glTF2Exporter::ExportMeshes()
}
}
p.indices = ExportData(*mAsset, meshId, b, indices.size(), &indices[0], AttribType::SCALAR, AttribType::SCALAR, ComponentType_UNSIGNED_INT, BufferViewTarget_ELEMENT_ARRAY_BUFFER);
p.indices = ExportData(*mAsset, meshId, b, indices.size(), &indices[0], AttribType::SCALAR, AttribType::SCALAR, ComponentType_UNSIGNED_INT, true);
}
switch (aim->mPrimitiveTypes) {
@ -814,47 +783,6 @@ void glTF2Exporter::ExportMeshes()
if(aim->HasBones()) {
ExportSkin(*mAsset, aim, m, b, skinRef, inverseBindMatricesData);
}
/*************** Targets for blendshapes ****************/
if (aim->mNumAnimMeshes > 0) {
p.targets.resize(aim->mNumAnimMeshes);
for (unsigned int am = 0; am < aim->mNumAnimMeshes; ++am) {
aiAnimMesh *pAnimMesh = aim->mAnimMeshes[am];
// position
if (pAnimMesh->HasPositions()) {
// NOTE: in gltf it is the diff stored
aiVector3D *pPositionDiff = new aiVector3D[pAnimMesh->mNumVertices];
for (unsigned int vt = 0; vt < pAnimMesh->mNumVertices; ++vt) {
pPositionDiff[vt] = pAnimMesh->mVertices[vt] - aim->mVertices[vt];
}
Ref<Accessor> v = ExportData(*mAsset, meshId, b,
pAnimMesh->mNumVertices, pPositionDiff,
AttribType::VEC3, AttribType::VEC3, ComponentType_FLOAT);
if (v) {
p.targets[am].position.push_back(v);
}
delete[] pPositionDiff;
}
// normal
if (pAnimMesh->HasNormals()) {
aiVector3D *pNormalDiff = new aiVector3D[pAnimMesh->mNumVertices];
for (unsigned int vt = 0; vt < pAnimMesh->mNumVertices; ++vt) {
pNormalDiff[vt] = pAnimMesh->mNormals[vt] - aim->mNormals[vt];
}
Ref<Accessor> v = ExportData(*mAsset, meshId, b,
pAnimMesh->mNumVertices, pNormalDiff,
AttribType::VEC3, AttribType::VEC3, ComponentType_FLOAT);
if (v) {
p.targets[am].normal.push_back(v);
}
delete[] pNormalDiff;
}
// tangent?
}
}
}
//----------------------------------------
@ -994,27 +922,8 @@ unsigned int glTF2Exporter::ExportNode(const aiNode* n, Ref<Node>& parent)
node->name = name;
if (!n->mTransformation.IsIdentity()) {
if (mScene->mNumAnimations > 0) {
aiQuaternion quaternion;
n->mTransformation.Decompose(*reinterpret_cast<aiVector3D *>(&node->scale.value), quaternion, *reinterpret_cast<aiVector3D *>(&node->translation.value));
aiVector3D vector(static_cast<ai_real>(1.0f), static_cast<ai_real>(1.0f), static_cast<ai_real>(1.0f));
if (!reinterpret_cast<aiVector3D *>(&node->scale.value)->Equal(vector)) {
node->scale.isPresent = true;
}
if (!reinterpret_cast<aiVector3D *>(&node->translation.value)->Equal(vector)) {
node->translation.isPresent = true;
}
node->rotation.isPresent = true;
node->rotation.value[0] = quaternion.x;
node->rotation.value[1] = quaternion.y;
node->rotation.value[2] = quaternion.z;
node->rotation.value[3] = quaternion.w;
node->matrix.isPresent = false;
} else {
node->matrix.isPresent = true;
CopyValue(n->mTransformation, node->matrix.value);
}
node->matrix.isPresent = true;
CopyValue(n->mTransformation, node->matrix.value);
}
for (unsigned int i = 0; i < n->mNumMeshes; ++i) {
@ -1050,16 +959,10 @@ void glTF2Exporter::ExportMetadata()
asset.version = "2.0";
char buffer[256];
ai_snprintf(buffer, 256, "Open Asset Import Library (assimp v%d.%d.%x)",
ai_snprintf(buffer, 256, "Open Asset Import Library (assimp v%d.%d.%d)",
aiGetVersionMajor(), aiGetVersionMinor(), aiGetVersionRevision());
asset.generator = buffer;
// Copyright
aiString copyright_str;
if (mScene->mMetaData != nullptr && mScene->mMetaData->Get(AI_METADATA_SOURCE_COPYRIGHT, copyright_str)) {
asset.copyright = copyright_str.C_Str();
}
}
inline Ref<Accessor> GetSamplerInputRef(Asset& asset, std::string& animId, Ref<Buffer>& buffer, std::vector<float>& times)