mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-07-09 21:54:35 +00:00
update assimp to 6.0.5
This commit is contained in:
parent
2d2eb57e2e
commit
f5cf21cfeb
941 changed files with 22718 additions and 12240 deletions
|
|
@ -3,7 +3,7 @@
|
|||
Open Asset Import Library (assimp)
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2024, assimp team
|
||||
Copyright (c) 2006-2026, assimp team
|
||||
|
||||
All rights reserved.
|
||||
|
||||
|
|
@ -56,23 +56,27 @@ namespace Assimp {
|
|||
|
||||
static constexpr unsigned int NotSet = 0xcdcdcdcd;
|
||||
|
||||
using namespace D3DS;
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Setup final material indices, generae a default material if necessary
|
||||
// Setup final material indices, generate a default material if necessary
|
||||
void Discreet3DSImporter::ReplaceDefaultMaterial() {
|
||||
// Try to find an existing material that matches the
|
||||
// typical default material setting:
|
||||
// - no textures
|
||||
// - diffuse color (in grey!)
|
||||
// NOTE: This is here to workaround the fact that some
|
||||
// NOTE: This is here to work-around the fact that some
|
||||
// exporters are writing a default material, too.
|
||||
unsigned int idx(NotSet);
|
||||
for (unsigned int i = 0; i < mScene->mMaterials.size(); ++i) {
|
||||
std::string s = mScene->mMaterials[i].mName;
|
||||
auto s = mScene->mMaterials[i].mName;
|
||||
for (char &it : s) {
|
||||
it = static_cast<char>(::tolower(static_cast<unsigned char>(it)));
|
||||
}
|
||||
|
||||
if (std::string::npos == s.find("default")) continue;
|
||||
if (std::string::npos == s.find("default")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (mScene->mMaterials[i].mDiffuse.r !=
|
||||
mScene->mMaterials[i].mDiffuse.g ||
|
||||
|
|
@ -85,25 +89,22 @@ void Discreet3DSImporter::ReplaceDefaultMaterial() {
|
|||
idx = i;
|
||||
}
|
||||
if (NotSet == idx) {
|
||||
idx = (unsigned int)mScene->mMaterials.size();
|
||||
idx = static_cast<unsigned int>(mScene->mMaterials.size());
|
||||
}
|
||||
|
||||
// now iterate through all meshes and through all faces and
|
||||
// find all faces that are using the default material
|
||||
unsigned int cnt = 0;
|
||||
for (std::vector<D3DS::Mesh>::iterator
|
||||
i = mScene->mMeshes.begin();
|
||||
i != mScene->mMeshes.end(); ++i) {
|
||||
for (std::vector<unsigned int>::iterator
|
||||
a = (*i).mFaceMaterials.begin();
|
||||
a != (*i).mFaceMaterials.end(); ++a) {
|
||||
for (auto i = mScene->mMeshes.begin(); i != mScene->mMeshes.end(); ++i) {
|
||||
for (auto a = i->mFaceMaterials.begin(); a != i->mFaceMaterials.end(); ++a) {
|
||||
// NOTE: The additional check seems to be necessary,
|
||||
// some exporters seem to generate invalid data here
|
||||
if (0xcdcdcdcd == (*a)) {
|
||||
(*a) = idx;
|
||||
|
||||
if (NotSet == *a) {
|
||||
*a = idx;
|
||||
++cnt;
|
||||
} else if ((*a) >= mScene->mMaterials.size()) {
|
||||
(*a) = idx;
|
||||
*a = idx;
|
||||
ASSIMP_LOG_WARN("Material index overflow in 3DS file. Using default material");
|
||||
++cnt;
|
||||
}
|
||||
|
|
@ -111,7 +112,7 @@ void Discreet3DSImporter::ReplaceDefaultMaterial() {
|
|||
}
|
||||
if (cnt && idx == mScene->mMaterials.size()) {
|
||||
// We need to create our own default material
|
||||
D3DS::Material sMat("%%%DEFAULT");
|
||||
Material sMat("%%%DEFAULT");
|
||||
sMat.mDiffuse = aiColor3D(0.3f, 0.3f, 0.3f);
|
||||
mScene->mMaterials.push_back(sMat);
|
||||
|
||||
|
|
@ -121,17 +122,17 @@ void Discreet3DSImporter::ReplaceDefaultMaterial() {
|
|||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Check whether all indices are valid. Otherwise we'd crash before the validation step is reached
|
||||
void Discreet3DSImporter::CheckIndices(D3DS::Mesh &sMesh) {
|
||||
for (std::vector<D3DS::Face>::iterator i = sMesh.mFaces.begin(); i != sMesh.mFaces.end(); ++i) {
|
||||
void Discreet3DSImporter::CheckIndices(Mesh &sMesh) {
|
||||
for (auto i = sMesh.mFaces.begin(); i != sMesh.mFaces.end(); ++i) {
|
||||
// check whether all indices are in range
|
||||
for (unsigned int a = 0; a < 3; ++a) {
|
||||
if ((*i).mIndices[a] >= sMesh.mPositions.size()) {
|
||||
ASSIMP_LOG_WARN("3DS: Vertex index overflow)");
|
||||
(*i).mIndices[a] = (uint32_t)sMesh.mPositions.size() - 1;
|
||||
(*i).mIndices[a] = static_cast<uint32_t>(sMesh.mPositions.size() - 1);
|
||||
}
|
||||
if (!sMesh.mTexCoords.empty() && (*i).mIndices[a] >= sMesh.mTexCoords.size()) {
|
||||
ASSIMP_LOG_WARN("3DS: Texture coordinate index overflow)");
|
||||
(*i).mIndices[a] = (uint32_t)sMesh.mTexCoords.size() - 1;
|
||||
(*i).mIndices[a] = static_cast<uint32_t>(sMesh.mTexCoords.size() - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -139,7 +140,7 @@ void Discreet3DSImporter::CheckIndices(D3DS::Mesh &sMesh) {
|
|||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Generate out unique verbose format representation
|
||||
void Discreet3DSImporter::MakeUnique(D3DS::Mesh &sMesh) {
|
||||
void Discreet3DSImporter::MakeUnique(Mesh &sMesh) {
|
||||
// TODO: really necessary? I don't think. Just a waste of memory and time
|
||||
// to do it now in a separate buffer.
|
||||
|
||||
|
|
@ -150,7 +151,7 @@ void Discreet3DSImporter::MakeUnique(D3DS::Mesh &sMesh) {
|
|||
vNew2.resize(sMesh.mFaces.size() * 3);
|
||||
|
||||
for (unsigned int i = 0, base = 0; i < sMesh.mFaces.size(); ++i) {
|
||||
D3DS::Face &face = sMesh.mFaces[i];
|
||||
Face &face = sMesh.mFaces[i];
|
||||
|
||||
// Positions
|
||||
for (unsigned int a = 0; a < 3; ++a, ++base) {
|
||||
|
|
@ -167,10 +168,9 @@ void Discreet3DSImporter::MakeUnique(D3DS::Mesh &sMesh) {
|
|||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Convert a 3DS texture to texture keys in an aiMaterial
|
||||
void CopyTexture(aiMaterial &mat, D3DS::Texture &texture, aiTextureType type) {
|
||||
void CopyTexture(aiMaterial &mat, Texture &texture, aiTextureType type) {
|
||||
// Setup the texture name
|
||||
aiString tex;
|
||||
tex.Set(texture.mMapName);
|
||||
aiString tex(texture.mMapName);
|
||||
mat.AddProperty(&tex, AI_MATKEY_TEXTURE(type, 0));
|
||||
|
||||
// Setup the texture blend factor
|
||||
|
|
@ -178,7 +178,7 @@ void CopyTexture(aiMaterial &mat, D3DS::Texture &texture, aiTextureType type) {
|
|||
mat.AddProperty<ai_real>(&texture.mTextureBlend, 1, AI_MATKEY_TEXBLEND(type, 0));
|
||||
|
||||
// Setup the texture mapping mode
|
||||
int mapMode = static_cast<int>(texture.mMapMode);
|
||||
auto mapMode = static_cast<int>(texture.mMapMode);
|
||||
mat.AddProperty<int>(&mapMode, 1, AI_MATKEY_MAPPINGMODE_U(type, 0));
|
||||
mat.AddProperty<int>(&mapMode, 1, AI_MATKEY_MAPPINGMODE_V(type, 0));
|
||||
|
||||
|
|
@ -197,13 +197,11 @@ void CopyTexture(aiMaterial &mat, D3DS::Texture &texture, aiTextureType type) {
|
|||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Convert a 3DS material to an aiMaterial
|
||||
void Discreet3DSImporter::ConvertMaterial(D3DS::Material &oldMat,
|
||||
aiMaterial &mat) {
|
||||
void Discreet3DSImporter::ConvertMaterial(Material &oldMat, aiMaterial &mat) {
|
||||
// NOTE: Pass the background image to the viewer by bypassing the
|
||||
// material system. This is an evil hack, never do it again!
|
||||
if (0 != mBackgroundImage.length() && bHasBG) {
|
||||
aiString tex;
|
||||
tex.Set(mBackgroundImage);
|
||||
if (mBackgroundImage.empty() && bHasBG) {
|
||||
aiString tex(mBackgroundImage);
|
||||
mat.AddProperty(&tex, AI_MATKEY_GLOBAL_BACKGROUND_IMAGE);
|
||||
|
||||
// Be sure this is only done for the first material
|
||||
|
|
@ -215,8 +213,7 @@ void Discreet3DSImporter::ConvertMaterial(D3DS::Material &oldMat,
|
|||
oldMat.mAmbient.g += mClrAmbient.g;
|
||||
oldMat.mAmbient.b += mClrAmbient.b;
|
||||
|
||||
aiString name;
|
||||
name.Set(oldMat.mName);
|
||||
aiString name(oldMat.mName);
|
||||
mat.AddProperty(&name, AI_MATKEY_NAME);
|
||||
|
||||
// Material colors
|
||||
|
|
@ -226,10 +223,9 @@ void Discreet3DSImporter::ConvertMaterial(D3DS::Material &oldMat,
|
|||
mat.AddProperty(&oldMat.mEmissive, 1, AI_MATKEY_COLOR_EMISSIVE);
|
||||
|
||||
// Phong shininess and shininess strength
|
||||
if (D3DS::Discreet3DS::Phong == oldMat.mShading ||
|
||||
D3DS::Discreet3DS::Metal == oldMat.mShading) {
|
||||
if (Discreet3DS::Phong == oldMat.mShading || Discreet3DS::Metal == oldMat.mShading) {
|
||||
if (!oldMat.mSpecularExponent || !oldMat.mShininessStrength) {
|
||||
oldMat.mShading = D3DS::Discreet3DS::Gouraud;
|
||||
oldMat.mShading = Discreet3DS::Gouraud;
|
||||
} else {
|
||||
mat.AddProperty(&oldMat.mSpecularExponent, 1, AI_MATKEY_SHININESS);
|
||||
mat.AddProperty(&oldMat.mShininessStrength, 1, AI_MATKEY_SHININESS_STRENGTH);
|
||||
|
|
@ -251,40 +247,41 @@ void Discreet3DSImporter::ConvertMaterial(D3DS::Material &oldMat,
|
|||
// Shading mode
|
||||
aiShadingMode eShading = aiShadingMode_NoShading;
|
||||
switch (oldMat.mShading) {
|
||||
case D3DS::Discreet3DS::Flat:
|
||||
case Discreet3DS::Flat:
|
||||
eShading = aiShadingMode_Flat;
|
||||
break;
|
||||
|
||||
// I don't know what "Wire" shading should be,
|
||||
// assume it is simple lambertian diffuse shading
|
||||
case D3DS::Discreet3DS::Wire: {
|
||||
case Discreet3DS::Wire: {
|
||||
// Set the wireframe flag
|
||||
unsigned int iWire = 1;
|
||||
mat.AddProperty<int>((int *)&iWire, 1, AI_MATKEY_ENABLE_WIREFRAME);
|
||||
}
|
||||
[[fallthrough]];
|
||||
|
||||
case D3DS::Discreet3DS::Gouraud:
|
||||
case Discreet3DS::Gouraud:
|
||||
eShading = aiShadingMode_Gouraud;
|
||||
break;
|
||||
|
||||
// assume cook-torrance shading for metals.
|
||||
case D3DS::Discreet3DS::Phong:
|
||||
case Discreet3DS::Phong:
|
||||
eShading = aiShadingMode_Phong;
|
||||
break;
|
||||
|
||||
case D3DS::Discreet3DS::Metal:
|
||||
case Discreet3DS::Metal:
|
||||
eShading = aiShadingMode_CookTorrance;
|
||||
break;
|
||||
|
||||
// FIX to workaround a warning with GCC 4 who complained
|
||||
// about a missing case Blinn: here - Blinn isn't a valid
|
||||
// value in the 3DS Loader, it is just needed for ASE
|
||||
case D3DS::Discreet3DS::Blinn:
|
||||
case Discreet3DS::Blinn:
|
||||
eShading = aiShadingMode_Blinn;
|
||||
break;
|
||||
}
|
||||
int eShading_ = static_cast<int>(eShading);
|
||||
|
||||
const int eShading_ = eShading;
|
||||
mat.AddProperty<int>(&eShading_, 1, AI_MATKEY_SHADING_MODEL);
|
||||
|
||||
// DIFFUSE texture
|
||||
|
|
@ -333,10 +330,11 @@ void Discreet3DSImporter::ConvertMeshes(aiScene *pcOut) {
|
|||
aiString name;
|
||||
|
||||
// we need to split all meshes by their materials
|
||||
for (std::vector<D3DS::Mesh>::iterator i = mScene->mMeshes.begin(); i != mScene->mMeshes.end(); ++i) {
|
||||
for (auto i = mScene->mMeshes.begin(); i != mScene->mMeshes.end(); ++i) {
|
||||
std::unique_ptr<std::vector<unsigned int>[]> aiSplit(new std::vector<unsigned int>[mScene->mMaterials.size()]);
|
||||
|
||||
name.length = ASSIMP_itoa10(name.data, num++);
|
||||
name.length = ASSIMP_itoa10(name.data, num);
|
||||
++num;
|
||||
|
||||
unsigned int iNum = 0;
|
||||
for (std::vector<unsigned int>::const_iterator a = (*i).mFaceMaterials.begin();
|
||||
|
|
@ -348,7 +346,7 @@ void Discreet3DSImporter::ConvertMeshes(aiScene *pcOut) {
|
|||
if (aiSplit[p].empty()) {
|
||||
continue;
|
||||
}
|
||||
aiMesh *meshOut = new aiMesh();
|
||||
auto *meshOut = new aiMesh();
|
||||
meshOut->mName = name;
|
||||
meshOut->mPrimitiveTypes = aiPrimitiveType_TRIANGLE;
|
||||
|
||||
|
|
@ -360,7 +358,7 @@ void Discreet3DSImporter::ConvertMeshes(aiScene *pcOut) {
|
|||
avOutMeshes.push_back(meshOut);
|
||||
|
||||
// convert vertices
|
||||
meshOut->mNumFaces = (unsigned int)aiSplit[p].size();
|
||||
meshOut->mNumFaces = static_cast<unsigned int>(aiSplit[p].size());
|
||||
meshOut->mNumVertices = meshOut->mNumFaces * 3;
|
||||
|
||||
// allocate enough storage for faces
|
||||
|
|
@ -408,8 +406,7 @@ void Discreet3DSImporter::ConvertMeshes(aiScene *pcOut) {
|
|||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Add a node to the scenegraph and setup its final transformation
|
||||
void Discreet3DSImporter::AddNodeToGraph(aiScene *pcSOut, aiNode *pcOut,
|
||||
D3DS::Node *pcIn, aiMatrix4x4 & /*absTrafo*/) {
|
||||
void Discreet3DSImporter::AddNodeToGraph(aiScene *pcSOut, aiNode *pcOut, D3DS::Node *pcIn, aiMatrix4x4 & /*absTrafo*/) {
|
||||
std::vector<unsigned int> iArray;
|
||||
iArray.reserve(3);
|
||||
|
||||
|
|
@ -417,7 +414,7 @@ void Discreet3DSImporter::AddNodeToGraph(aiScene *pcSOut, aiNode *pcOut,
|
|||
|
||||
// Find all meshes with the same name as the node
|
||||
for (unsigned int a = 0; a < pcSOut->mNumMeshes; ++a) {
|
||||
const D3DS::Mesh *pcMesh = (const D3DS::Mesh *)pcSOut->mMeshes[a]->mColors[0];
|
||||
const auto *pcMesh = (const D3DS::Mesh *)pcSOut->mMeshes[a]->mColors[0];
|
||||
ai_assert(nullptr != pcMesh);
|
||||
|
||||
if (pcIn->mName == pcMesh->mName)
|
||||
|
|
@ -426,7 +423,7 @@ void Discreet3DSImporter::AddNodeToGraph(aiScene *pcSOut, aiNode *pcOut,
|
|||
if (!iArray.empty()) {
|
||||
// The matrix should be identical for all meshes with the
|
||||
// same name. It HAS to be identical for all meshes .....
|
||||
D3DS::Mesh *imesh = ((D3DS::Mesh *)pcSOut->mMeshes[iArray[0]]->mColors[0]);
|
||||
auto *imesh = ((D3DS::Mesh *)pcSOut->mMeshes[iArray[0]]->mColors[0]);
|
||||
|
||||
// Compute the inverse of the transformation matrix to move the
|
||||
// vertices back to their relative and local space
|
||||
|
|
@ -435,7 +432,7 @@ void Discreet3DSImporter::AddNodeToGraph(aiScene *pcSOut, aiNode *pcOut,
|
|||
mInvTransposed.Transpose();
|
||||
aiVector3D pivot = pcIn->vPivot;
|
||||
|
||||
pcOut->mNumMeshes = (unsigned int)iArray.size();
|
||||
pcOut->mNumMeshes = static_cast<unsigned int>(iArray.size());
|
||||
pcOut->mMeshes = new unsigned int[iArray.size()];
|
||||
for (unsigned int i = 0; i < iArray.size(); ++i) {
|
||||
const unsigned int iIndex = iArray[i];
|
||||
|
|
@ -454,7 +451,7 @@ void Discreet3DSImporter::AddNodeToGraph(aiScene *pcSOut, aiNode *pcOut,
|
|||
|
||||
// Handle negative transformation matrix determinant -> invert vertex x
|
||||
if (imesh->mMat.Determinant() < 0.0f) {
|
||||
/* we *must* have normals */
|
||||
// we *must* have normals
|
||||
for (pvCurrent = mesh->mVertices, t2 = mesh->mNormals; pvCurrent != pvEnd; ++pvCurrent, ++t2) {
|
||||
pvCurrent->x *= -1.f;
|
||||
t2->x *= -1.f;
|
||||
|
|
@ -481,7 +478,7 @@ void Discreet3DSImporter::AddNodeToGraph(aiScene *pcSOut, aiNode *pcOut,
|
|||
// Setup the name of the node
|
||||
// First instance keeps its name otherwise something might break, all others will be postfixed with their instance number
|
||||
if (pcIn->mInstanceNumber > 1) {
|
||||
char tmp[12];
|
||||
char tmp[12] = {'\0'};
|
||||
ASSIMP_itoa10(tmp, pcIn->mInstanceNumber);
|
||||
std::string tempStr = pcIn->mName + "_inst_";
|
||||
tempStr += tmp;
|
||||
|
|
@ -494,7 +491,7 @@ void Discreet3DSImporter::AddNodeToGraph(aiScene *pcSOut, aiNode *pcOut,
|
|||
if (pcIn->aRotationKeys.size()) {
|
||||
|
||||
// FIX to get to Assimp's quaternion conventions
|
||||
for (std::vector<aiQuatKey>::iterator it = pcIn->aRotationKeys.begin(); it != pcIn->aRotationKeys.end(); ++it) {
|
||||
for (auto it = pcIn->aRotationKeys.begin(); it != pcIn->aRotationKeys.end(); ++it) {
|
||||
(*it).mValue.w *= -1.f;
|
||||
}
|
||||
|
||||
|
|
@ -606,11 +603,11 @@ void Discreet3DSImporter::AddNodeToGraph(aiScene *pcSOut, aiNode *pcOut,
|
|||
}
|
||||
|
||||
// Allocate a new node anim and setup its name
|
||||
aiNodeAnim *nda = anim->mChannels[anim->mNumChannels++] = new aiNodeAnim();
|
||||
auto *nda = anim->mChannels[anim->mNumChannels++] = new aiNodeAnim();
|
||||
nda->mNodeName.Set(pcIn->mName);
|
||||
|
||||
// POSITION keys
|
||||
if (pcIn->aPositionKeys.size() > 0) {
|
||||
if (!pcIn->aPositionKeys.empty()) {
|
||||
nda->mNumPositionKeys = (unsigned int)pcIn->aPositionKeys.size();
|
||||
nda->mPositionKeys = new aiVectorKey[nda->mNumPositionKeys];
|
||||
::memcpy(nda->mPositionKeys, &pcIn->aPositionKeys[0],
|
||||
|
|
@ -618,7 +615,7 @@ void Discreet3DSImporter::AddNodeToGraph(aiScene *pcSOut, aiNode *pcOut,
|
|||
}
|
||||
|
||||
// ROTATION keys
|
||||
if (pcIn->aRotationKeys.size() > 0) {
|
||||
if (!pcIn->aRotationKeys.empty()) {
|
||||
nda->mNumRotationKeys = (unsigned int)pcIn->aRotationKeys.size();
|
||||
nda->mRotationKeys = new aiQuatKey[nda->mNumRotationKeys];
|
||||
|
||||
|
|
@ -634,7 +631,7 @@ void Discreet3DSImporter::AddNodeToGraph(aiScene *pcSOut, aiNode *pcOut,
|
|||
}
|
||||
|
||||
// SCALING keys
|
||||
if (pcIn->aScalingKeys.size() > 0) {
|
||||
if (!pcIn->aScalingKeys.empty()) {
|
||||
nda->mNumScalingKeys = (unsigned int)pcIn->aScalingKeys.size();
|
||||
nda->mScalingKeys = new aiVectorKey[nda->mNumScalingKeys];
|
||||
::memcpy(nda->mScalingKeys, &pcIn->aScalingKeys[0],
|
||||
|
|
@ -643,7 +640,7 @@ void Discreet3DSImporter::AddNodeToGraph(aiScene *pcSOut, aiNode *pcOut,
|
|||
}
|
||||
|
||||
// Allocate storage for children
|
||||
const unsigned int size = static_cast<unsigned int>(pcIn->mChildren.size());
|
||||
const auto size = static_cast<unsigned int>(pcIn->mChildren.size());
|
||||
|
||||
pcOut->mNumChildren = size;
|
||||
if (size == 0) {
|
||||
|
|
@ -653,7 +650,7 @@ void Discreet3DSImporter::AddNodeToGraph(aiScene *pcSOut, aiNode *pcOut,
|
|||
pcOut->mChildren = new aiNode *[pcIn->mChildren.size()];
|
||||
|
||||
// Recursively process all children
|
||||
|
||||
|
||||
for (unsigned int i = 0; i < size; ++i) {
|
||||
pcOut->mChildren[i] = new aiNode();
|
||||
pcOut->mChildren[i]->mParent = pcOut;
|
||||
|
|
@ -686,7 +683,7 @@ void CountTracks(D3DS::Node *node, unsigned int &cnt) {
|
|||
// Generate the output node graph
|
||||
void Discreet3DSImporter::GenerateNodeGraph(aiScene *pcOut) {
|
||||
pcOut->mRootNode = new aiNode();
|
||||
if (0 == mRootNode->mChildren.size()) {
|
||||
if (mRootNode->mChildren.empty()) {
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// It seems the file is so messed up that it has not even a hierarchy.
|
||||
// generate a flat hiearachy which looks like this:
|
||||
|
|
@ -708,7 +705,8 @@ void Discreet3DSImporter::GenerateNodeGraph(aiScene *pcOut) {
|
|||
// Build dummy nodes for all meshes
|
||||
unsigned int a = 0;
|
||||
for (unsigned int i = 0; i < pcOut->mNumMeshes; ++i, ++a) {
|
||||
aiNode *pcNode = pcOut->mRootNode->mChildren[a] = new aiNode();
|
||||
pcOut->mRootNode->mChildren[a] = new aiNode();
|
||||
auto *pcNode = pcOut->mRootNode->mChildren[a];
|
||||
pcNode->mParent = pcOut->mRootNode;
|
||||
pcNode->mMeshes = new unsigned int[1];
|
||||
pcNode->mMeshes[0] = i;
|
||||
|
|
@ -720,7 +718,7 @@ void Discreet3DSImporter::GenerateNodeGraph(aiScene *pcOut) {
|
|||
|
||||
// Build dummy nodes for all cameras
|
||||
for (unsigned int i = 0; i < (unsigned int)mScene->mCameras.size(); ++i, ++a) {
|
||||
aiNode *pcNode = pcOut->mRootNode->mChildren[a] = new aiNode();
|
||||
auto *pcNode = pcOut->mRootNode->mChildren[a] = new aiNode();
|
||||
pcNode->mParent = pcOut->mRootNode;
|
||||
|
||||
// Build a name for the node
|
||||
|
|
@ -729,7 +727,7 @@ void Discreet3DSImporter::GenerateNodeGraph(aiScene *pcOut) {
|
|||
|
||||
// Build dummy nodes for all lights
|
||||
for (unsigned int i = 0; i < (unsigned int)mScene->mLights.size(); ++i, ++a) {
|
||||
aiNode *pcNode = pcOut->mRootNode->mChildren[a] = new aiNode();
|
||||
auto *pcNode = pcOut->mRootNode->mChildren[a] = new aiNode();
|
||||
pcNode->mParent = pcOut->mRootNode;
|
||||
|
||||
// Build a name for the node
|
||||
|
|
@ -745,7 +743,7 @@ void Discreet3DSImporter::GenerateNodeGraph(aiScene *pcOut) {
|
|||
// Allocate a primary animation channel
|
||||
pcOut->mNumAnimations = 1;
|
||||
pcOut->mAnimations = new aiAnimation *[1];
|
||||
aiAnimation *anim = pcOut->mAnimations[0] = new aiAnimation();
|
||||
auto *anim = pcOut->mAnimations[0] = new aiAnimation();
|
||||
|
||||
anim->mName.Set("3DSMasterAnim");
|
||||
|
||||
|
|
@ -783,12 +781,12 @@ void Discreet3DSImporter::GenerateNodeGraph(aiScene *pcOut) {
|
|||
// Convert all meshes in the scene and generate the final output scene.
|
||||
void Discreet3DSImporter::ConvertScene(aiScene *pcOut) {
|
||||
// Allocate enough storage for all output materials
|
||||
pcOut->mNumMaterials = (unsigned int)mScene->mMaterials.size();
|
||||
pcOut->mNumMaterials = static_cast<unsigned int>(mScene->mMaterials.size());
|
||||
pcOut->mMaterials = new aiMaterial *[pcOut->mNumMaterials];
|
||||
|
||||
// ... and convert the 3DS materials to aiMaterial's
|
||||
for (unsigned int i = 0; i < pcOut->mNumMaterials; ++i) {
|
||||
aiMaterial *pcNew = new aiMaterial();
|
||||
auto *pcNew = new aiMaterial();
|
||||
ConvertMaterial(mScene->mMaterials[i], *pcNew);
|
||||
pcOut->mMaterials[i] = pcNew;
|
||||
}
|
||||
|
|
@ -797,17 +795,17 @@ void Discreet3DSImporter::ConvertScene(aiScene *pcOut) {
|
|||
ConvertMeshes(pcOut);
|
||||
|
||||
// Now copy all light sources to the output scene
|
||||
pcOut->mNumLights = (unsigned int)mScene->mLights.size();
|
||||
pcOut->mNumLights = static_cast<unsigned int>(mScene->mLights.size());
|
||||
if (pcOut->mNumLights) {
|
||||
pcOut->mLights = new aiLight *[pcOut->mNumLights];
|
||||
::memcpy(pcOut->mLights, &mScene->mLights[0], sizeof(void *) * pcOut->mNumLights);
|
||||
memcpy(pcOut->mLights, &mScene->mLights[0], sizeof(void *) * pcOut->mNumLights);
|
||||
}
|
||||
|
||||
// Now copy all cameras to the output scene
|
||||
pcOut->mNumCameras = (unsigned int)mScene->mCameras.size();
|
||||
pcOut->mNumCameras = static_cast<unsigned int>(mScene->mCameras.size());
|
||||
if (pcOut->mNumCameras) {
|
||||
pcOut->mCameras = new aiCamera *[pcOut->mNumCameras];
|
||||
::memcpy(pcOut->mCameras, &mScene->mCameras[0], sizeof(void *) * pcOut->mNumCameras);
|
||||
memcpy(pcOut->mCameras, &mScene->mCameras[0], sizeof(void *) * pcOut->mNumCameras);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,8 +2,7 @@
|
|||
Open Asset Import Library (assimp)
|
||||
----------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2024, assimp team
|
||||
|
||||
Copyright (c) 2006-2026, assimp team
|
||||
|
||||
All rights reserved.
|
||||
|
||||
|
|
@ -77,33 +76,33 @@ class ChunkWriter {
|
|||
|
||||
public:
|
||||
ChunkWriter(StreamWriterLE &writer, uint16_t chunk_type) :
|
||||
writer(writer) {
|
||||
chunk_start_pos = writer.GetCurrentPos();
|
||||
mWriter(writer) {
|
||||
mChunkStartPos = writer.GetCurrentPos();
|
||||
writer.PutU2(chunk_type);
|
||||
writer.PutU4((uint32_t)CHUNK_SIZE_NOT_SET);
|
||||
}
|
||||
|
||||
~ChunkWriter() {
|
||||
std::size_t head_pos = writer.GetCurrentPos();
|
||||
std::size_t head_pos = mWriter.GetCurrentPos();
|
||||
|
||||
ai_assert(head_pos > chunk_start_pos);
|
||||
const std::size_t chunk_size = head_pos - chunk_start_pos;
|
||||
ai_assert(head_pos > mChunkStartPos);
|
||||
const std::size_t chunk_size = head_pos - mChunkStartPos;
|
||||
|
||||
writer.SetCurrentPos(chunk_start_pos + SIZE_OFFSET);
|
||||
writer.PutU4(static_cast<uint32_t>(chunk_size));
|
||||
writer.SetCurrentPos(head_pos);
|
||||
mWriter.SetCurrentPos(mChunkStartPos + SIZE_OFFSET);
|
||||
mWriter.PutU4(static_cast<uint32_t>(chunk_size));
|
||||
mWriter.SetCurrentPos(head_pos);
|
||||
}
|
||||
|
||||
private:
|
||||
StreamWriterLE &writer;
|
||||
std::size_t chunk_start_pos;
|
||||
StreamWriterLE &mWriter;
|
||||
std::size_t mChunkStartPos;
|
||||
};
|
||||
|
||||
// Return an unique name for a given |mesh| attached to |node| that
|
||||
// preserves the mesh's given name if it has one. |index| is the index
|
||||
// of the mesh in |aiScene::mMeshes|.
|
||||
std::string GetMeshName(const aiMesh &mesh, unsigned int index, const aiNode &node) {
|
||||
static const char underscore = '_';
|
||||
static constexpr char underscore = '_';
|
||||
char postfix[10] = { 0 };
|
||||
ASSIMP_itoa10(postfix, index);
|
||||
|
||||
|
|
@ -123,8 +122,7 @@ std::string GetMaterialName(const aiMaterial &mat, unsigned int index) {
|
|||
char postfix[10] = { 0 };
|
||||
ASSIMP_itoa10(postfix, index);
|
||||
|
||||
aiString mat_name;
|
||||
if (AI_SUCCESS == mat.Get(AI_MATKEY_NAME, mat_name)) {
|
||||
if (aiString mat_name; AI_SUCCESS == mat.Get(AI_MATKEY_NAME, mat_name)) {
|
||||
return mat_name.C_Str() + underscore + postfix;
|
||||
}
|
||||
|
||||
|
|
@ -209,9 +207,6 @@ Discreet3DSExporter::Discreet3DSExporter(std::shared_ptr<IOStream> &outfile, con
|
|||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Discreet3DSExporter::~Discreet3DSExporter() = default;
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
int Discreet3DSExporter::WriteHierarchy(const aiNode &node, int seq, int sibling_level) {
|
||||
// 3DS scene hierarchy is serialized as in http://www.martinreddy.net/gfx/3d/3DS.spec
|
||||
|
|
@ -307,8 +302,7 @@ void Discreet3DSExporter::WriteMaterials() {
|
|||
WriteColor(color);
|
||||
}
|
||||
|
||||
aiShadingMode shading_mode = aiShadingMode_Flat;
|
||||
if (mat.Get(AI_MATKEY_SHADING_MODEL, shading_mode) == AI_SUCCESS) {
|
||||
if (aiShadingMode shading_mode = aiShadingMode_Flat; mat.Get(AI_MATKEY_SHADING_MODEL, shading_mode) == AI_SUCCESS) {
|
||||
ChunkWriter chunk(writer, Discreet3DS::CHUNK_MAT_SHADING);
|
||||
|
||||
Discreet3DS::shadetype3ds shading_mode_out;
|
||||
|
|
@ -336,7 +330,7 @@ void Discreet3DSExporter::WriteMaterials() {
|
|||
default:
|
||||
shading_mode_out = Discreet3DS::Flat;
|
||||
ai_assert(false);
|
||||
};
|
||||
}
|
||||
writer.PutU2(static_cast<uint16_t>(shading_mode_out));
|
||||
}
|
||||
|
||||
|
|
@ -350,8 +344,7 @@ void Discreet3DSExporter::WriteMaterials() {
|
|||
WritePercentChunk(f);
|
||||
}
|
||||
|
||||
int twosided;
|
||||
if (mat.Get(AI_MATKEY_TWOSIDED, twosided) == AI_SUCCESS && twosided != 0) {
|
||||
if (int twosided; mat.Get(AI_MATKEY_TWOSIDED, twosided) == AI_SUCCESS && twosided != 0) {
|
||||
ChunkWriter chunk(writer, Discreet3DS::CHUNK_MAT_TWO_SIDE);
|
||||
writer.PutI2(1);
|
||||
}
|
||||
|
|
@ -545,7 +538,7 @@ void Discreet3DSExporter::WriteFaceMaterialChunk(const aiMesh &mesh) {
|
|||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void Discreet3DSExporter::WriteString(const std::string &s) {
|
||||
for (std::string::const_iterator it = s.begin(); it != s.end(); ++it) {
|
||||
for (auto it = s.begin(); it != s.end(); ++it) {
|
||||
writer.PutI1(*it);
|
||||
}
|
||||
writer.PutI1('\0');
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
Open Asset Import Library (assimp)
|
||||
----------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2024, assimp team
|
||||
Copyright (c) 2006-2026, assimp team
|
||||
|
||||
All rights reserved.
|
||||
|
||||
|
|
@ -63,10 +63,10 @@ namespace Assimp {
|
|||
* @brief Helper class to export a given scene to a 3DS file.
|
||||
*/
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
class Discreet3DSExporter {
|
||||
class Discreet3DSExporter final {
|
||||
public:
|
||||
Discreet3DSExporter(std::shared_ptr<IOStream> &outfile, const aiScene* pScene);
|
||||
~Discreet3DSExporter();
|
||||
~Discreet3DSExporter() = default;
|
||||
|
||||
private:
|
||||
void WriteMeshes();
|
||||
|
|
@ -88,7 +88,6 @@ private:
|
|||
|
||||
using MeshesByNodeMap = std::multimap<const aiNode*, unsigned int>;
|
||||
MeshesByNodeMap meshes;
|
||||
|
||||
};
|
||||
|
||||
} // Namespace Assimp
|
||||
|
|
|
|||
|
|
@ -2,8 +2,7 @@
|
|||
Open Asset Import Library (assimp)
|
||||
----------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2024, assimp team
|
||||
|
||||
Copyright (c) 2006-2026, assimp team
|
||||
|
||||
All rights reserved.
|
||||
|
||||
|
|
@ -55,8 +54,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
#include <assimp/qnan.h>
|
||||
#include <cstdio> //sprintf
|
||||
|
||||
namespace Assimp {
|
||||
namespace D3DS {
|
||||
namespace Assimp::D3DS {
|
||||
|
||||
#include <assimp/Compiler/pushpack1.h>
|
||||
|
||||
|
|
@ -580,7 +578,6 @@ struct Scene {
|
|||
// Node* pcRootNode;
|
||||
};
|
||||
|
||||
} // end of namespace D3DS
|
||||
} // end of namespace Assimp
|
||||
} // end of namespace Assimp::D3DS
|
||||
|
||||
#endif // AI_XFILEHELPER_H_INC
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
Open Asset Import Library (assimp)
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2024, assimp team
|
||||
Copyright (c) 2006-2026, assimp team
|
||||
|
||||
All rights reserved.
|
||||
|
||||
|
|
@ -56,6 +56,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
|
||||
namespace Assimp {
|
||||
|
||||
using namespace D3DS;
|
||||
|
||||
static constexpr aiImporterDesc desc = {
|
||||
"Discreet 3DS Importer",
|
||||
"",
|
||||
|
|
@ -75,7 +77,7 @@ static constexpr aiImporterDesc desc = {
|
|||
// - computes its length
|
||||
#define ASSIMP_3DS_BEGIN_CHUNK() \
|
||||
while (true) { \
|
||||
if (stream->GetRemainingSizeToLimit() < sizeof(Discreet3DS::Chunk)) { \
|
||||
if (mStream->GetRemainingSizeToLimit() < sizeof(Discreet3DS::Chunk)) { \
|
||||
return; \
|
||||
} \
|
||||
Discreet3DS::Chunk chunk; \
|
||||
|
|
@ -83,30 +85,30 @@ static constexpr aiImporterDesc desc = {
|
|||
int chunkSize = chunk.Size - sizeof(Discreet3DS::Chunk); \
|
||||
if (chunkSize <= 0) \
|
||||
continue; \
|
||||
const unsigned int oldReadLimit = stream->SetReadLimit( \
|
||||
stream->GetCurrentPos() + chunkSize);
|
||||
const unsigned int oldReadLimit = mStream->SetReadLimit( \
|
||||
mStream->GetCurrentPos() + chunkSize);
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// End a parsing block
|
||||
// Must follow at the end of each parsing block, reset chunk end marker to previous value
|
||||
#define ASSIMP_3DS_END_CHUNK() \
|
||||
stream->SkipToReadLimit(); \
|
||||
stream->SetReadLimit(oldReadLimit); \
|
||||
if (stream->GetRemainingSizeToLimit() == 0) \
|
||||
mStream->SkipToReadLimit(); \
|
||||
mStream->SetReadLimit(oldReadLimit); \
|
||||
if (mStream->GetRemainingSizeToLimit() == 0) \
|
||||
return; \
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Constructor to be privately used by Importer
|
||||
Discreet3DSImporter::Discreet3DSImporter() :
|
||||
stream(), mLastNodeIndex(), mCurrentNode(), mRootNode(), mScene(), mMasterScale(), bHasBG(), bIsPrj() {
|
||||
mStream(nullptr), mLastNodeIndex(), mCurrentNode(), mRootNode(), mScene(), mMasterScale(), bHasBG(), bIsPrj() {
|
||||
// empty
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Returns whether the class can handle the format of the given file.
|
||||
bool Discreet3DSImporter::CanRead(const std::string &pFile, IOSystem *pIOHandler, bool /*checkSig*/) const {
|
||||
static const uint16_t token[] = { 0x4d4d, 0x3dc2 /*, 0x3daa */ };
|
||||
static constexpr uint16_t token[] = { 0x4d4d, 0x3dc2 /*, 0x3daa */ };
|
||||
return CheckMagicToken(pIOHandler, pFile, token, AI_COUNT_OF(token), 0, sizeof token[0]);
|
||||
}
|
||||
|
||||
|
|
@ -124,9 +126,7 @@ void Discreet3DSImporter::SetupProperties(const Importer * /*pImp*/) {
|
|||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Imports the given file into the given scene structure.
|
||||
void Discreet3DSImporter::InternReadFile(const std::string &pFile,
|
||||
aiScene *pScene, IOSystem *pIOHandler) {
|
||||
|
||||
void Discreet3DSImporter::InternReadFile(const std::string &pFile, aiScene *pScene, IOSystem *pIOHandler) {
|
||||
auto theFile = pIOHandler->Open(pFile, "rb");
|
||||
if (!theFile) {
|
||||
throw DeadlyImportError("3DS: Could not open ", pFile);
|
||||
|
|
@ -138,14 +138,14 @@ void Discreet3DSImporter::InternReadFile(const std::string &pFile,
|
|||
if (theStream.GetRemainingSize() < 16) {
|
||||
throw DeadlyImportError("3DS file is either empty or corrupt: ", pFile);
|
||||
}
|
||||
this->stream = &theStream;
|
||||
mStream = &theStream;
|
||||
|
||||
// Allocate our temporary 3DS representation
|
||||
D3DS::Scene _scene;
|
||||
Scene _scene;
|
||||
mScene = &_scene;
|
||||
|
||||
// Initialize members
|
||||
D3DS::Node _rootNode("UNNAMED");
|
||||
Node _rootNode("UNNAMED");
|
||||
mLastNodeIndex = -1;
|
||||
mCurrentNode = &_rootNode;
|
||||
mRootNode = mCurrentNode;
|
||||
|
|
@ -166,12 +166,12 @@ void Discreet3DSImporter::InternReadFile(const std::string &pFile,
|
|||
// vectors from the smoothing groups we read from the
|
||||
// file.
|
||||
for (auto &mesh : mScene->mMeshes) {
|
||||
if (mesh.mFaces.size() > 0 && mesh.mPositions.size() == 0) {
|
||||
if (!mesh.mFaces.empty() && mesh.mPositions.empty()) {
|
||||
throw DeadlyImportError("3DS file contains faces but no vertices: ", pFile);
|
||||
}
|
||||
CheckIndices(mesh);
|
||||
MakeUnique(mesh);
|
||||
ComputeNormalsWithSmoothingsGroups<D3DS::Face>(mesh);
|
||||
ComputeNormalsWithSmoothingsGroups<Face>(mesh);
|
||||
}
|
||||
|
||||
// Replace all occurrences of the default material with a
|
||||
|
|
@ -196,12 +196,12 @@ void Discreet3DSImporter::InternReadFile(const std::string &pFile,
|
|||
|
||||
AI_DEBUG_INVALIDATE_PTR(mRootNode);
|
||||
AI_DEBUG_INVALIDATE_PTR(mScene);
|
||||
AI_DEBUG_INVALIDATE_PTR(this->stream);
|
||||
AI_DEBUG_INVALIDATE_PTR(mStream);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Applies a master-scaling factor to the imported scene
|
||||
void Discreet3DSImporter::ApplyMasterScale(aiScene *pScene) {
|
||||
void Discreet3DSImporter::ApplyMasterScale(const aiScene *pScene) {
|
||||
// There are some 3DS files with a zero scaling factor
|
||||
if (!mMasterScale)
|
||||
mMasterScale = 1.0f;
|
||||
|
|
@ -223,14 +223,14 @@ void Discreet3DSImporter::ApplyMasterScale(aiScene *pScene) {
|
|||
void Discreet3DSImporter::ReadChunk(Discreet3DS::Chunk *pcOut) {
|
||||
ai_assert(pcOut != nullptr);
|
||||
|
||||
pcOut->Flag = stream->GetI2();
|
||||
pcOut->Size = stream->GetI4();
|
||||
pcOut->Flag = mStream->GetI2();
|
||||
pcOut->Size = mStream->GetI4();
|
||||
|
||||
if (pcOut->Size - sizeof(Discreet3DS::Chunk) > stream->GetRemainingSize()) {
|
||||
if (pcOut->Size - sizeof(Discreet3DS::Chunk) > mStream->GetRemainingSize()) {
|
||||
throw DeadlyImportError("Chunk is too large");
|
||||
}
|
||||
|
||||
if (pcOut->Size - sizeof(Discreet3DS::Chunk) > stream->GetRemainingSizeToLimit()) {
|
||||
if (pcOut->Size - sizeof(Discreet3DS::Chunk) > mStream->GetRemainingSizeToLimit()) {
|
||||
ASSIMP_LOG_ERROR("3DS: Chunk overflow");
|
||||
}
|
||||
}
|
||||
|
|
@ -241,8 +241,7 @@ void Discreet3DSImporter::SkipChunk() {
|
|||
Discreet3DS::Chunk psChunk;
|
||||
ReadChunk(&psChunk);
|
||||
|
||||
stream->IncPtr(psChunk.Size - sizeof(Discreet3DS::Chunk));
|
||||
return;
|
||||
mStream->IncPtr(psChunk.Size - sizeof(Discreet3DS::Chunk));
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
|
@ -259,7 +258,7 @@ void Discreet3DSImporter::ParseMainChunk() {
|
|||
case Discreet3DS::CHUNK_MAIN:
|
||||
ParseEditorChunk();
|
||||
break;
|
||||
};
|
||||
}
|
||||
|
||||
ASSIMP_3DS_END_CHUNK();
|
||||
#if defined(__clang__)
|
||||
|
|
@ -275,30 +274,29 @@ void Discreet3DSImporter::ParseMainChunk() {
|
|||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void Discreet3DSImporter::ParseEditorChunk() {
|
||||
ASSIMP_3DS_BEGIN_CHUNK();
|
||||
ASSIMP_3DS_BEGIN_CHUNK()
|
||||
|
||||
// get chunk type
|
||||
switch (chunk.Flag) {
|
||||
case Discreet3DS::CHUNK_OBJMESH:
|
||||
case Discreet3DS::CHUNK_OBJMESH:
|
||||
ParseObjectChunk();
|
||||
break;
|
||||
|
||||
ParseObjectChunk();
|
||||
// NOTE: In several documentations in the internet this
|
||||
// chunk appears at different locations
|
||||
case Discreet3DS::CHUNK_KEYFRAMER:
|
||||
ParseKeyframeChunk();
|
||||
break;
|
||||
|
||||
case Discreet3DS::CHUNK_VERSION: {
|
||||
// print the version number
|
||||
char buff[10];
|
||||
ASSIMP_itoa10(buff, mStream->GetI2());
|
||||
ASSIMP_LOG_INFO("3DS file format version: ", buff);
|
||||
}
|
||||
break;
|
||||
|
||||
// NOTE: In several documentations in the internet this
|
||||
// chunk appears at different locations
|
||||
case Discreet3DS::CHUNK_KEYFRAMER:
|
||||
|
||||
ParseKeyframeChunk();
|
||||
break;
|
||||
|
||||
case Discreet3DS::CHUNK_VERSION: {
|
||||
// print the version number
|
||||
char buff[10];
|
||||
ASSIMP_itoa10(buff, stream->GetI2());
|
||||
ASSIMP_LOG_INFO("3DS file format version: ", buff);
|
||||
} break;
|
||||
};
|
||||
ASSIMP_3DS_END_CHUNK();
|
||||
ASSIMP_3DS_END_CHUNK()
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
|
@ -309,10 +307,10 @@ void Discreet3DSImporter::ParseObjectChunk() {
|
|||
switch (chunk.Flag) {
|
||||
case Discreet3DS::CHUNK_OBJBLOCK: {
|
||||
unsigned int cnt = 0;
|
||||
const char *sz = (const char *)stream->GetPtr();
|
||||
const auto *sz = (const char *)mStream->GetPtr();
|
||||
|
||||
// Get the name of the geometry object
|
||||
while (stream->GetI1())
|
||||
while (mStream->GetI1())
|
||||
++cnt;
|
||||
ParseChunk(sz, cnt);
|
||||
} break;
|
||||
|
|
@ -340,8 +338,8 @@ void Discreet3DSImporter::ParseObjectChunk() {
|
|||
// Specifies the background image. The string should already be
|
||||
// properly 0 terminated but we need to be sure
|
||||
unsigned int cnt = 0;
|
||||
const char *sz = (const char *)stream->GetPtr();
|
||||
while (stream->GetI1())
|
||||
auto *sz = (const char *)mStream->GetPtr();
|
||||
while (mStream->GetI1())
|
||||
++cnt;
|
||||
mBackgroundImage = std::string(sz, cnt);
|
||||
} break;
|
||||
|
|
@ -352,7 +350,7 @@ void Discreet3DSImporter::ParseObjectChunk() {
|
|||
|
||||
case Discreet3DS::CHUNK_MASTER_SCALE:
|
||||
// Scene master scaling factor
|
||||
mMasterScale = stream->GetF4();
|
||||
mMasterScale = mStream->GetF4();
|
||||
break;
|
||||
};
|
||||
ASSIMP_3DS_END_CHUNK();
|
||||
|
|
@ -379,15 +377,15 @@ void Discreet3DSImporter::ParseChunk(const char *name, unsigned int num) {
|
|||
|
||||
case Discreet3DS::CHUNK_LIGHT: {
|
||||
// This starts a new light
|
||||
aiLight *light = new aiLight();
|
||||
auto *light = new aiLight();
|
||||
mScene->mLights.push_back(light);
|
||||
|
||||
light->mName.Set(std::string(name, num));
|
||||
|
||||
// First read the position of the light
|
||||
light->mPosition.x = stream->GetF4();
|
||||
light->mPosition.y = stream->GetF4();
|
||||
light->mPosition.z = stream->GetF4();
|
||||
light->mPosition.x = mStream->GetF4();
|
||||
light->mPosition.y = mStream->GetF4();
|
||||
light->mPosition.z = mStream->GetF4();
|
||||
|
||||
light->mColorDiffuse = aiColor3D(1.f, 1.f, 1.f);
|
||||
|
||||
|
|
@ -408,19 +406,19 @@ void Discreet3DSImporter::ParseChunk(const char *name, unsigned int num) {
|
|||
|
||||
case Discreet3DS::CHUNK_CAMERA: {
|
||||
// This starts a new camera
|
||||
aiCamera *camera = new aiCamera();
|
||||
auto *camera = new aiCamera();
|
||||
mScene->mCameras.push_back(camera);
|
||||
camera->mName.Set(std::string(name, num));
|
||||
|
||||
// First read the position of the camera
|
||||
camera->mPosition.x = stream->GetF4();
|
||||
camera->mPosition.y = stream->GetF4();
|
||||
camera->mPosition.z = stream->GetF4();
|
||||
camera->mPosition.x = mStream->GetF4();
|
||||
camera->mPosition.y = mStream->GetF4();
|
||||
camera->mPosition.z = mStream->GetF4();
|
||||
|
||||
// Then the camera target
|
||||
camera->mLookAt.x = stream->GetF4() - camera->mPosition.x;
|
||||
camera->mLookAt.y = stream->GetF4() - camera->mPosition.y;
|
||||
camera->mLookAt.z = stream->GetF4() - camera->mPosition.z;
|
||||
camera->mLookAt.x = mStream->GetF4() - camera->mPosition.x;
|
||||
camera->mLookAt.y = mStream->GetF4() - camera->mPosition.y;
|
||||
camera->mLookAt.z = mStream->GetF4() - camera->mPosition.z;
|
||||
ai_real len = camera->mLookAt.Length();
|
||||
if (len < 1e-5) {
|
||||
|
||||
|
|
@ -432,12 +430,12 @@ void Discreet3DSImporter::ParseChunk(const char *name, unsigned int num) {
|
|||
camera->mLookAt /= len;
|
||||
|
||||
// And finally - the camera rotation angle, in counter clockwise direction
|
||||
const ai_real angle = AI_DEG_TO_RAD(stream->GetF4());
|
||||
const ai_real angle = AI_DEG_TO_RAD(mStream->GetF4());
|
||||
aiQuaternion quat(camera->mLookAt, angle);
|
||||
camera->mUp = quat.GetMatrix() * aiVector3D(0.0, 1.0, 0.0);
|
||||
|
||||
// Read the lense angle
|
||||
camera->mHorizontalFOV = AI_DEG_TO_RAD(stream->GetF4());
|
||||
camera->mHorizontalFOV = AI_DEG_TO_RAD(mStream->GetF4());
|
||||
if (camera->mHorizontalFOV < 0.001f) {
|
||||
camera->mHorizontalFOV = float(AI_DEG_TO_RAD(45.f));
|
||||
}
|
||||
|
|
@ -463,34 +461,34 @@ void Discreet3DSImporter::ParseLightChunk() {
|
|||
light->mType = aiLightSource_SPOT;
|
||||
|
||||
// We wouldn't need to normalize here, but we do it
|
||||
light->mDirection.x = stream->GetF4() - light->mPosition.x;
|
||||
light->mDirection.y = stream->GetF4() - light->mPosition.y;
|
||||
light->mDirection.z = stream->GetF4() - light->mPosition.z;
|
||||
light->mDirection.x = mStream->GetF4() - light->mPosition.x;
|
||||
light->mDirection.y = mStream->GetF4() - light->mPosition.y;
|
||||
light->mDirection.z = mStream->GetF4() - light->mPosition.z;
|
||||
light->mDirection.Normalize();
|
||||
|
||||
// Now the hotspot and falloff angles - in degrees
|
||||
light->mAngleInnerCone = AI_DEG_TO_RAD(stream->GetF4());
|
||||
light->mAngleInnerCone = AI_DEG_TO_RAD(mStream->GetF4());
|
||||
|
||||
// FIX: the falloff angle is just an offset
|
||||
light->mAngleOuterCone = light->mAngleInnerCone + AI_DEG_TO_RAD(stream->GetF4());
|
||||
light->mAngleOuterCone = light->mAngleInnerCone + AI_DEG_TO_RAD(mStream->GetF4());
|
||||
break;
|
||||
|
||||
// intensity multiplier
|
||||
case Discreet3DS::CHUNK_DL_MULTIPLIER:
|
||||
light->mColorDiffuse = light->mColorDiffuse * stream->GetF4();
|
||||
light->mColorDiffuse = light->mColorDiffuse * mStream->GetF4();
|
||||
break;
|
||||
|
||||
// light color
|
||||
case Discreet3DS::CHUNK_RGBF:
|
||||
case Discreet3DS::CHUNK_LINRGBF:
|
||||
light->mColorDiffuse.r *= stream->GetF4();
|
||||
light->mColorDiffuse.g *= stream->GetF4();
|
||||
light->mColorDiffuse.b *= stream->GetF4();
|
||||
light->mColorDiffuse.r *= mStream->GetF4();
|
||||
light->mColorDiffuse.g *= mStream->GetF4();
|
||||
light->mColorDiffuse.b *= mStream->GetF4();
|
||||
break;
|
||||
|
||||
// light attenuation
|
||||
case Discreet3DS::CHUNK_DL_ATTENUATE:
|
||||
light->mAttenuationLinear = stream->GetF4();
|
||||
light->mAttenuationLinear = mStream->GetF4();
|
||||
break;
|
||||
};
|
||||
|
||||
|
|
@ -505,10 +503,10 @@ void Discreet3DSImporter::ParseCameraChunk() {
|
|||
// get chunk type
|
||||
switch (chunk.Flag) {
|
||||
// near and far clip plane
|
||||
case Discreet3DS::CHUNK_CAM_RANGES:
|
||||
camera->mClipPlaneNear = stream->GetF4();
|
||||
camera->mClipPlaneFar = stream->GetF4();
|
||||
break;
|
||||
case Discreet3DS::CHUNK_CAM_RANGES:
|
||||
camera->mClipPlaneNear = mStream->GetF4();
|
||||
camera->mClipPlaneFar = mStream->GetF4();
|
||||
break;
|
||||
}
|
||||
|
||||
ASSIMP_3DS_END_CHUNK();
|
||||
|
|
@ -555,14 +553,13 @@ void Discreet3DSImporter::InverseNodeSearch(D3DS::Node *pcNode, D3DS::Node *pcCu
|
|||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Find a node with a specific name in the import hierarchy
|
||||
D3DS::Node *FindNode(D3DS::Node *root, const std::string &name) {
|
||||
Node *FindNode(Node *root, const std::string &name) {
|
||||
if (root->mName == name) {
|
||||
return root;
|
||||
}
|
||||
|
||||
for (std::vector<D3DS::Node *>::iterator it = root->mChildren.begin(); it != root->mChildren.end(); ++it) {
|
||||
D3DS::Node *nd = FindNode(*it, name);
|
||||
if (nullptr != nd) {
|
||||
for (auto it = root->mChildren.begin(); it != root->mChildren.end(); ++it) {
|
||||
if (auto *nd = FindNode(*it, name); nullptr != nd) {
|
||||
return nd;
|
||||
}
|
||||
}
|
||||
|
|
@ -580,7 +577,7 @@ bool KeyUniqueCompare(const T &first, const T &second) {
|
|||
// ------------------------------------------------------------------------------------------------
|
||||
// Skip some additional import data.
|
||||
void Discreet3DSImporter::SkipTCBInfo() {
|
||||
unsigned int flags = stream->GetI2();
|
||||
unsigned int flags = mStream->GetI2();
|
||||
|
||||
if (!flags) {
|
||||
// Currently we can't do anything with these values. They occur
|
||||
|
|
@ -591,19 +588,19 @@ void Discreet3DSImporter::SkipTCBInfo() {
|
|||
}
|
||||
|
||||
if (flags & Discreet3DS::KEY_USE_TENS) {
|
||||
stream->IncPtr(4);
|
||||
mStream->IncPtr(4);
|
||||
}
|
||||
if (flags & Discreet3DS::KEY_USE_BIAS) {
|
||||
stream->IncPtr(4);
|
||||
mStream->IncPtr(4);
|
||||
}
|
||||
if (flags & Discreet3DS::KEY_USE_CONT) {
|
||||
stream->IncPtr(4);
|
||||
mStream->IncPtr(4);
|
||||
}
|
||||
if (flags & Discreet3DS::KEY_USE_EASE_FROM) {
|
||||
stream->IncPtr(4);
|
||||
mStream->IncPtr(4);
|
||||
}
|
||||
if (flags & Discreet3DS::KEY_USE_EASE_TO) {
|
||||
stream->IncPtr(4);
|
||||
mStream->IncPtr(4);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -622,15 +619,15 @@ void Discreet3DSImporter::ParseHierarchyChunk(uint16_t parent) {
|
|||
|
||||
// First of all: get the name of the object
|
||||
unsigned int cnt = 0;
|
||||
const char *sz = (const char *)stream->GetPtr();
|
||||
auto *sz = (const char *)mStream->GetPtr();
|
||||
|
||||
while (stream->GetI1())
|
||||
while (mStream->GetI1())
|
||||
++cnt;
|
||||
std::string name = std::string(sz, cnt);
|
||||
|
||||
// Now find out whether we have this node already (target animation channels
|
||||
// are stored with a separate object ID)
|
||||
D3DS::Node *pcNode = FindNode(mRootNode, name);
|
||||
Node *pcNode = FindNode(mRootNode, name);
|
||||
int instanceNumber = 1;
|
||||
|
||||
if (pcNode) {
|
||||
|
|
@ -646,10 +643,10 @@ void Discreet3DSImporter::ParseHierarchyChunk(uint16_t parent) {
|
|||
pcNode->mInstanceNumber = instanceNumber;
|
||||
|
||||
// There are two unknown values which we can safely ignore
|
||||
stream->IncPtr(4);
|
||||
mStream->IncPtr(4);
|
||||
|
||||
// Now read the hierarchy position of the object
|
||||
uint16_t hierarchy = stream->GetI2() + 1;
|
||||
uint16_t hierarchy = mStream->GetI2() + 1;
|
||||
pcNode->mHierarchyPos = hierarchy;
|
||||
pcNode->mHierarchyIndex = mLastNodeIndex;
|
||||
|
||||
|
|
@ -678,8 +675,8 @@ void Discreet3DSImporter::ParseHierarchyChunk(uint16_t parent) {
|
|||
|
||||
// This is the "real" name of a $$$DUMMY object
|
||||
{
|
||||
const char *sz = (const char *)stream->GetPtr();
|
||||
while (stream->GetI1())
|
||||
const char *sz = (const char *)mStream->GetPtr();
|
||||
while (mStream->GetI1())
|
||||
;
|
||||
|
||||
// If object name is DUMMY, take this one instead
|
||||
|
|
@ -698,16 +695,16 @@ void Discreet3DSImporter::ParseHierarchyChunk(uint16_t parent) {
|
|||
}
|
||||
|
||||
// Pivot = origin of rotation and scaling
|
||||
mCurrentNode->vPivot.x = stream->GetF4();
|
||||
mCurrentNode->vPivot.y = stream->GetF4();
|
||||
mCurrentNode->vPivot.z = stream->GetF4();
|
||||
mCurrentNode->vPivot.x = mStream->GetF4();
|
||||
mCurrentNode->vPivot.y = mStream->GetF4();
|
||||
mCurrentNode->vPivot.z = mStream->GetF4();
|
||||
break;
|
||||
|
||||
// ////////////////////////////////////////////////////////////////////
|
||||
// POSITION KEYFRAME
|
||||
case Discreet3DS::CHUNK_TRACKPOS: {
|
||||
stream->IncPtr(10);
|
||||
const unsigned int numFrames = stream->GetI4();
|
||||
mStream->IncPtr(10);
|
||||
const unsigned int numFrames = mStream->GetI4();
|
||||
bool sortKeys = false;
|
||||
|
||||
// This could also be meant as the target position for
|
||||
|
|
@ -720,16 +717,16 @@ void Discreet3DSImporter::ParseHierarchyChunk(uint16_t parent) {
|
|||
|
||||
l->reserve(numFrames);
|
||||
for (unsigned int i = 0; i < numFrames; ++i) {
|
||||
const unsigned int fidx = stream->GetI4();
|
||||
const unsigned int fidx = mStream->GetI4();
|
||||
|
||||
// Setup a new position key
|
||||
aiVectorKey v;
|
||||
v.mTime = (double)fidx;
|
||||
|
||||
SkipTCBInfo();
|
||||
v.mValue.x = stream->GetF4();
|
||||
v.mValue.y = stream->GetF4();
|
||||
v.mValue.z = stream->GetF4();
|
||||
v.mValue.x = mStream->GetF4();
|
||||
v.mValue.y = mStream->GetF4();
|
||||
v.mValue.z = mStream->GetF4();
|
||||
|
||||
// check whether we'll need to sort the keys
|
||||
if (!l->empty() && v.mTime <= l->back().mTime)
|
||||
|
|
@ -759,11 +756,11 @@ void Discreet3DSImporter::ParseHierarchyChunk(uint16_t parent) {
|
|||
bool sortKeys = false;
|
||||
std::vector<aiFloatKey> *l = &mCurrentNode->aCameraRollKeys;
|
||||
|
||||
stream->IncPtr(10);
|
||||
const unsigned int numFrames = stream->GetI4();
|
||||
mStream->IncPtr(10);
|
||||
const unsigned int numFrames = mStream->GetI4();
|
||||
l->reserve(numFrames);
|
||||
for (unsigned int i = 0; i < numFrames; ++i) {
|
||||
const unsigned int fidx = stream->GetI4();
|
||||
const unsigned int fidx = mStream->GetI4();
|
||||
|
||||
// Setup a new position key
|
||||
aiFloatKey v;
|
||||
|
|
@ -771,7 +768,7 @@ void Discreet3DSImporter::ParseHierarchyChunk(uint16_t parent) {
|
|||
|
||||
// This is just a single float
|
||||
SkipTCBInfo();
|
||||
v.mValue = stream->GetF4();
|
||||
v.mValue = mStream->GetF4();
|
||||
|
||||
// Check whether we'll need to sort the keys
|
||||
if (!l->empty() && v.mTime <= l->back().mTime)
|
||||
|
|
@ -798,26 +795,26 @@ void Discreet3DSImporter::ParseHierarchyChunk(uint16_t parent) {
|
|||
// ////////////////////////////////////////////////////////////////////
|
||||
// ROTATION KEYFRAME
|
||||
case Discreet3DS::CHUNK_TRACKROTATE: {
|
||||
stream->IncPtr(10);
|
||||
const unsigned int numFrames = stream->GetI4();
|
||||
mStream->IncPtr(10);
|
||||
const unsigned int numFrames = mStream->GetI4();
|
||||
|
||||
bool sortKeys = false;
|
||||
std::vector<aiQuatKey> *l = &mCurrentNode->aRotationKeys;
|
||||
l->reserve(numFrames);
|
||||
|
||||
for (unsigned int i = 0; i < numFrames; ++i) {
|
||||
const unsigned int fidx = stream->GetI4();
|
||||
const unsigned int fidx = mStream->GetI4();
|
||||
SkipTCBInfo();
|
||||
|
||||
aiQuatKey v;
|
||||
v.mTime = (double)fidx;
|
||||
|
||||
// The rotation keyframe is given as an axis-angle pair
|
||||
const float rad = stream->GetF4();
|
||||
const float rad = mStream->GetF4();
|
||||
aiVector3D axis;
|
||||
axis.x = stream->GetF4();
|
||||
axis.y = stream->GetF4();
|
||||
axis.z = stream->GetF4();
|
||||
axis.x = mStream->GetF4();
|
||||
axis.y = mStream->GetF4();
|
||||
axis.z = mStream->GetF4();
|
||||
|
||||
if (!axis.x && !axis.y && !axis.z)
|
||||
axis.y = 1.f;
|
||||
|
|
@ -842,16 +839,16 @@ void Discreet3DSImporter::ParseHierarchyChunk(uint16_t parent) {
|
|||
// ////////////////////////////////////////////////////////////////////
|
||||
// SCALING KEYFRAME
|
||||
case Discreet3DS::CHUNK_TRACKSCALE: {
|
||||
stream->IncPtr(10);
|
||||
const unsigned int numFrames = stream->GetI2();
|
||||
stream->IncPtr(2);
|
||||
mStream->IncPtr(10);
|
||||
const unsigned int numFrames = mStream->GetI2();
|
||||
mStream->IncPtr(2);
|
||||
|
||||
bool sortKeys = false;
|
||||
std::vector<aiVectorKey> *l = &mCurrentNode->aScalingKeys;
|
||||
l->reserve(numFrames);
|
||||
|
||||
for (unsigned int i = 0; i < numFrames; ++i) {
|
||||
const unsigned int fidx = stream->GetI4();
|
||||
const unsigned int fidx = mStream->GetI4();
|
||||
SkipTCBInfo();
|
||||
|
||||
// Setup a new key
|
||||
|
|
@ -859,9 +856,9 @@ void Discreet3DSImporter::ParseHierarchyChunk(uint16_t parent) {
|
|||
v.mTime = (double)fidx;
|
||||
|
||||
// ... and read its value
|
||||
v.mValue.x = stream->GetF4();
|
||||
v.mValue.y = stream->GetF4();
|
||||
v.mValue.z = stream->GetF4();
|
||||
v.mValue.x = mStream->GetF4();
|
||||
v.mValue.y = mStream->GetF4();
|
||||
v.mValue.z = mStream->GetF4();
|
||||
|
||||
// check whether we'll need to sort the keys
|
||||
if (!l->empty() && v.mTime <= l->back().mTime)
|
||||
|
|
@ -902,23 +899,23 @@ void Discreet3DSImporter::ParseFaceChunk() {
|
|||
if (num > mMesh.mFaces.size()) {
|
||||
throw DeadlyImportError("3DS: More smoothing groups than faces");
|
||||
}
|
||||
for (std::vector<D3DS::Face>::iterator i = mMesh.mFaces.begin(); m != num; ++i, ++m) {
|
||||
for (auto i = mMesh.mFaces.begin(); m != num; ++i, ++m) {
|
||||
// nth bit is set for nth smoothing group
|
||||
(*i).iSmoothGroup = stream->GetI4();
|
||||
i->iSmoothGroup = mStream->GetI4();
|
||||
}
|
||||
} break;
|
||||
|
||||
case Discreet3DS::CHUNK_FACEMAT: {
|
||||
// at fist an asciiz with the material name
|
||||
const char *sz = (const char *)stream->GetPtr();
|
||||
while (stream->GetI1())
|
||||
const char *sz = (const char *)mStream->GetPtr();
|
||||
while (mStream->GetI1())
|
||||
;
|
||||
|
||||
// find the index of the material
|
||||
unsigned int idx = 0xcdcdcdcd, cnt = 0;
|
||||
for (std::vector<D3DS::Material>::const_iterator i = mScene->mMaterials.begin(); i != mScene->mMaterials.end(); ++i, ++cnt) {
|
||||
for (auto i = mScene->mMaterials.begin(); i != mScene->mMaterials.end(); ++i, ++cnt) {
|
||||
// use case independent comparisons. hopefully it will work.
|
||||
if ((*i).mName.length() && !ASSIMP_stricmp(sz, (*i).mName.c_str())) {
|
||||
if (i->mName.length() && !ASSIMP_stricmp(sz, i->mName.c_str())) {
|
||||
idx = cnt;
|
||||
break;
|
||||
}
|
||||
|
|
@ -928,9 +925,9 @@ void Discreet3DSImporter::ParseFaceChunk() {
|
|||
}
|
||||
|
||||
// Now continue and read all material indices
|
||||
cnt = (uint16_t)stream->GetI2();
|
||||
cnt = (uint16_t)mStream->GetI2();
|
||||
for (unsigned int i = 0; i < cnt; ++i) {
|
||||
unsigned int fidx = (uint16_t)stream->GetI2();
|
||||
unsigned int fidx = (uint16_t)mStream->GetI2();
|
||||
|
||||
// check range
|
||||
if (fidx >= mMesh.mFaceMaterials.size()) {
|
||||
|
|
@ -955,59 +952,59 @@ void Discreet3DSImporter::ParseMeshChunk() {
|
|||
switch (chunk.Flag) {
|
||||
case Discreet3DS::CHUNK_VERTLIST: {
|
||||
// This is the list of all vertices in the current mesh
|
||||
int num = (int)(uint16_t)stream->GetI2();
|
||||
int num = (int)(uint16_t)mStream->GetI2();
|
||||
mMesh.mPositions.reserve(num);
|
||||
while (num-- > 0) {
|
||||
aiVector3D v;
|
||||
v.x = stream->GetF4();
|
||||
v.y = stream->GetF4();
|
||||
v.z = stream->GetF4();
|
||||
v.x = mStream->GetF4();
|
||||
v.y = mStream->GetF4();
|
||||
v.z = mStream->GetF4();
|
||||
mMesh.mPositions.push_back(v);
|
||||
}
|
||||
} break;
|
||||
case Discreet3DS::CHUNK_TRMATRIX: {
|
||||
// This is the RLEATIVE transformation matrix of the current mesh. Vertices are
|
||||
// pretransformed by this matrix wonder.
|
||||
mMesh.mMat.a1 = stream->GetF4();
|
||||
mMesh.mMat.b1 = stream->GetF4();
|
||||
mMesh.mMat.c1 = stream->GetF4();
|
||||
mMesh.mMat.a2 = stream->GetF4();
|
||||
mMesh.mMat.b2 = stream->GetF4();
|
||||
mMesh.mMat.c2 = stream->GetF4();
|
||||
mMesh.mMat.a3 = stream->GetF4();
|
||||
mMesh.mMat.b3 = stream->GetF4();
|
||||
mMesh.mMat.c3 = stream->GetF4();
|
||||
mMesh.mMat.a4 = stream->GetF4();
|
||||
mMesh.mMat.b4 = stream->GetF4();
|
||||
mMesh.mMat.c4 = stream->GetF4();
|
||||
mMesh.mMat.a1 = mStream->GetF4();
|
||||
mMesh.mMat.b1 = mStream->GetF4();
|
||||
mMesh.mMat.c1 = mStream->GetF4();
|
||||
mMesh.mMat.a2 = mStream->GetF4();
|
||||
mMesh.mMat.b2 = mStream->GetF4();
|
||||
mMesh.mMat.c2 = mStream->GetF4();
|
||||
mMesh.mMat.a3 = mStream->GetF4();
|
||||
mMesh.mMat.b3 = mStream->GetF4();
|
||||
mMesh.mMat.c3 = mStream->GetF4();
|
||||
mMesh.mMat.a4 = mStream->GetF4();
|
||||
mMesh.mMat.b4 = mStream->GetF4();
|
||||
mMesh.mMat.c4 = mStream->GetF4();
|
||||
} break;
|
||||
|
||||
case Discreet3DS::CHUNK_MAPLIST: {
|
||||
// This is the list of all UV coords in the current mesh
|
||||
int num = (int)(uint16_t)stream->GetI2();
|
||||
int num = (int)(uint16_t)mStream->GetI2();
|
||||
mMesh.mTexCoords.reserve(num);
|
||||
while (num-- > 0) {
|
||||
aiVector3D v;
|
||||
v.x = stream->GetF4();
|
||||
v.y = stream->GetF4();
|
||||
v.x = mStream->GetF4();
|
||||
v.y = mStream->GetF4();
|
||||
mMesh.mTexCoords.push_back(v);
|
||||
}
|
||||
} break;
|
||||
|
||||
case Discreet3DS::CHUNK_FACELIST: {
|
||||
// This is the list of all faces in the current mesh
|
||||
int num = (int)(uint16_t)stream->GetI2();
|
||||
int num = (int)(uint16_t)mStream->GetI2();
|
||||
mMesh.mFaces.reserve(num);
|
||||
while (num-- > 0) {
|
||||
// 3DS faces are ALWAYS triangles
|
||||
mMesh.mFaces.emplace_back();
|
||||
D3DS::Face &sFace = mMesh.mFaces.back();
|
||||
Face &sFace = mMesh.mFaces.back();
|
||||
|
||||
sFace.mIndices[0] = (uint16_t)stream->GetI2();
|
||||
sFace.mIndices[1] = (uint16_t)stream->GetI2();
|
||||
sFace.mIndices[2] = (uint16_t)stream->GetI2();
|
||||
sFace.mIndices[0] = (uint16_t)mStream->GetI2();
|
||||
sFace.mIndices[1] = (uint16_t)mStream->GetI2();
|
||||
sFace.mIndices[2] = (uint16_t)mStream->GetI2();
|
||||
|
||||
stream->IncPtr(2); // skip edge visibility flag
|
||||
mStream->IncPtr(2); // skip edge visibility flag
|
||||
}
|
||||
|
||||
// Resize the material array (0xcdcdcdcd marks the default material; so if a face is
|
||||
|
|
@ -1015,7 +1012,7 @@ void Discreet3DSImporter::ParseMeshChunk() {
|
|||
mMesh.mFaceMaterials.resize(mMesh.mFaces.size(), 0xcdcdcdcd);
|
||||
|
||||
// Larger 3DS files could have multiple FACE chunks here
|
||||
chunkSize = (int)stream->GetRemainingSizeToLimit();
|
||||
chunkSize = (int)mStream->GetRemainingSizeToLimit();
|
||||
if (chunkSize > (int)sizeof(Discreet3DS::Chunk))
|
||||
ParseFaceChunk();
|
||||
} break;
|
||||
|
|
@ -1032,9 +1029,9 @@ void Discreet3DSImporter::ParseMaterialChunk() {
|
|||
|
||||
{
|
||||
// The material name string is already zero-terminated, but we need to be sure ...
|
||||
const char *sz = (const char *)stream->GetPtr();
|
||||
const char *sz = (const char *)mStream->GetPtr();
|
||||
unsigned int cnt = 0;
|
||||
while (stream->GetI1())
|
||||
while (mStream->GetI1())
|
||||
++cnt;
|
||||
|
||||
if (!cnt) {
|
||||
|
|
@ -1102,7 +1099,7 @@ void Discreet3DSImporter::ParseMaterialChunk() {
|
|||
|
||||
case Discreet3DS::CHUNK_MAT_SHADING:
|
||||
// This is the material shading mode
|
||||
mScene->mMaterials.back().mShading = (D3DS::Discreet3DS::shadetype3ds)stream->GetI2();
|
||||
mScene->mMaterials.back().mShading = (Discreet3DS::shadetype3ds)mStream->GetI2();
|
||||
break;
|
||||
|
||||
case Discreet3DS::CHUNK_MAT_TWO_SIDE:
|
||||
|
|
@ -1178,31 +1175,31 @@ void Discreet3DSImporter::ParseTextureChunk(D3DS::Texture *pcOut) {
|
|||
switch (chunk.Flag) {
|
||||
case Discreet3DS::CHUNK_MAPFILE: {
|
||||
// The material name string is already zero-terminated, but we need to be sure ...
|
||||
const char *sz = (const char *)stream->GetPtr();
|
||||
const char *sz = (const char *)mStream->GetPtr();
|
||||
unsigned int cnt = 0;
|
||||
while (stream->GetI1())
|
||||
while (mStream->GetI1())
|
||||
++cnt;
|
||||
pcOut->mMapName = std::string(sz, cnt);
|
||||
} break;
|
||||
|
||||
case Discreet3DS::CHUNK_PERCENTD:
|
||||
// Manually parse the blend factor
|
||||
pcOut->mTextureBlend = ai_real(stream->GetF8());
|
||||
pcOut->mTextureBlend = ai_real(mStream->GetF8());
|
||||
break;
|
||||
|
||||
case Discreet3DS::CHUNK_PERCENTF:
|
||||
// Manually parse the blend factor
|
||||
pcOut->mTextureBlend = stream->GetF4();
|
||||
pcOut->mTextureBlend = mStream->GetF4();
|
||||
break;
|
||||
|
||||
case Discreet3DS::CHUNK_PERCENTW:
|
||||
// Manually parse the blend factor
|
||||
pcOut->mTextureBlend = (ai_real)((uint16_t)stream->GetI2()) / ai_real(100.0);
|
||||
pcOut->mTextureBlend = (ai_real)((uint16_t) mStream->GetI2()) / ai_real(100.0);
|
||||
break;
|
||||
|
||||
case Discreet3DS::CHUNK_MAT_MAP_USCALE:
|
||||
// Texture coordinate scaling in the U direction
|
||||
pcOut->mScaleU = stream->GetF4();
|
||||
pcOut->mScaleU = mStream->GetF4();
|
||||
if (0.0f == pcOut->mScaleU) {
|
||||
ASSIMP_LOG_WARN("Texture coordinate scaling in the x direction is zero. Assuming 1.");
|
||||
pcOut->mScaleU = 1.0f;
|
||||
|
|
@ -1210,7 +1207,7 @@ void Discreet3DSImporter::ParseTextureChunk(D3DS::Texture *pcOut) {
|
|||
break;
|
||||
case Discreet3DS::CHUNK_MAT_MAP_VSCALE:
|
||||
// Texture coordinate scaling in the V direction
|
||||
pcOut->mScaleV = stream->GetF4();
|
||||
pcOut->mScaleV = mStream->GetF4();
|
||||
if (0.0f == pcOut->mScaleV) {
|
||||
ASSIMP_LOG_WARN("Texture coordinate scaling in the y direction is zero. Assuming 1.");
|
||||
pcOut->mScaleV = 1.0f;
|
||||
|
|
@ -1219,21 +1216,21 @@ void Discreet3DSImporter::ParseTextureChunk(D3DS::Texture *pcOut) {
|
|||
|
||||
case Discreet3DS::CHUNK_MAT_MAP_UOFFSET:
|
||||
// Texture coordinate offset in the U direction
|
||||
pcOut->mOffsetU = -stream->GetF4();
|
||||
pcOut->mOffsetU = -mStream->GetF4();
|
||||
break;
|
||||
|
||||
case Discreet3DS::CHUNK_MAT_MAP_VOFFSET:
|
||||
// Texture coordinate offset in the V direction
|
||||
pcOut->mOffsetV = stream->GetF4();
|
||||
pcOut->mOffsetV = mStream->GetF4();
|
||||
break;
|
||||
|
||||
case Discreet3DS::CHUNK_MAT_MAP_ANG:
|
||||
// Texture coordinate rotation, CCW in DEGREES
|
||||
pcOut->mRotation = -AI_DEG_TO_RAD(stream->GetF4());
|
||||
pcOut->mRotation = -AI_DEG_TO_RAD(mStream->GetF4());
|
||||
break;
|
||||
|
||||
case Discreet3DS::CHUNK_MAT_MAP_TILING: {
|
||||
const uint16_t iFlags = stream->GetI2();
|
||||
const uint16_t iFlags = mStream->GetI2();
|
||||
|
||||
// Get the mapping mode (for both axes)
|
||||
if (iFlags & 0x2u)
|
||||
|
|
@ -1258,9 +1255,11 @@ ai_real Discreet3DSImporter::ParsePercentageChunk() {
|
|||
ReadChunk(&chunk);
|
||||
|
||||
if (Discreet3DS::CHUNK_PERCENTF == chunk.Flag) {
|
||||
return stream->GetF4() * ai_real(100) / ai_real(0xFFFF);
|
||||
} else if (Discreet3DS::CHUNK_PERCENTW == chunk.Flag) {
|
||||
return (ai_real)((uint16_t)stream->GetI2()) / (ai_real)0xFFFF;
|
||||
return mStream->GetF4() * ai_real(100) / ai_real(0xFFFF);
|
||||
}
|
||||
|
||||
if (Discreet3DS::CHUNK_PERCENTW == chunk.Flag) {
|
||||
return (ai_real)((uint16_t)mStream->GetI2()) / (ai_real)0xFFFF;
|
||||
}
|
||||
|
||||
return get_qnan();
|
||||
|
|
@ -1291,9 +1290,9 @@ void Discreet3DSImporter::ParseColorChunk(aiColor3D *out, bool acceptPercent) {
|
|||
*out = clrError;
|
||||
return;
|
||||
}
|
||||
out->r = stream->GetF4();
|
||||
out->g = stream->GetF4();
|
||||
out->b = stream->GetF4();
|
||||
out->r = mStream->GetF4();
|
||||
out->g = mStream->GetF4();
|
||||
out->b = mStream->GetF4();
|
||||
break;
|
||||
|
||||
case Discreet3DS::CHUNK_LINRGBB:
|
||||
|
|
@ -1305,15 +1304,15 @@ void Discreet3DSImporter::ParseColorChunk(aiColor3D *out, bool acceptPercent) {
|
|||
return;
|
||||
}
|
||||
const ai_real invVal = ai_real(1.0) / ai_real(255.0);
|
||||
out->r = (ai_real)(uint8_t)stream->GetI1() * invVal;
|
||||
out->g = (ai_real)(uint8_t)stream->GetI1() * invVal;
|
||||
out->b = (ai_real)(uint8_t)stream->GetI1() * invVal;
|
||||
out->r = (ai_real)(uint8_t)mStream->GetI1() * invVal;
|
||||
out->g = (ai_real)(uint8_t)mStream->GetI1() * invVal;
|
||||
out->b = (ai_real)(uint8_t)mStream->GetI1() * invVal;
|
||||
} break;
|
||||
|
||||
// Percentage chunks are accepted, too.
|
||||
case Discreet3DS::CHUNK_PERCENTF:
|
||||
if (acceptPercent && 4 <= diff) {
|
||||
out->g = out->b = out->r = stream->GetF4();
|
||||
out->g = out->b = out->r = mStream->GetF4();
|
||||
break;
|
||||
}
|
||||
*out = clrError;
|
||||
|
|
@ -1321,14 +1320,14 @@ void Discreet3DSImporter::ParseColorChunk(aiColor3D *out, bool acceptPercent) {
|
|||
|
||||
case Discreet3DS::CHUNK_PERCENTW:
|
||||
if (acceptPercent && 1 <= diff) {
|
||||
out->g = out->b = out->r = (ai_real)(uint8_t)stream->GetI1() / ai_real(255.0);
|
||||
out->g = out->b = out->r = (ai_real)(uint8_t)mStream->GetI1() / ai_real(255.0);
|
||||
break;
|
||||
}
|
||||
*out = clrError;
|
||||
return;
|
||||
|
||||
default:
|
||||
stream->IncPtr(diff);
|
||||
mStream->IncPtr(diff);
|
||||
// Skip unknown chunks, hope this won't cause any problems.
|
||||
return ParseColorChunk(out, acceptPercent);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,10 +1,8 @@
|
|||
|
||||
/*
|
||||
Open Asset Import Library (assimp)
|
||||
----------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2024, assimp team
|
||||
|
||||
Copyright (c) 2006-2026, assimp team
|
||||
|
||||
All rights reserved.
|
||||
|
||||
|
|
@ -51,20 +49,17 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
#include <assimp/BaseImporter.h>
|
||||
#include <assimp/types.h>
|
||||
|
||||
|
||||
#include "3DSHelper.h"
|
||||
#include <assimp/StreamReader.h>
|
||||
|
||||
struct aiNode;
|
||||
|
||||
namespace Assimp {
|
||||
|
||||
using namespace D3DS;
|
||||
namespace Assimp {
|
||||
|
||||
// ---------------------------------------------------------------------------------
|
||||
/** Importer class for 3D Studio r3 and r4 3DS files
|
||||
*/
|
||||
class Discreet3DSImporter : public BaseImporter {
|
||||
class Discreet3DSImporter final : public BaseImporter {
|
||||
public:
|
||||
Discreet3DSImporter();
|
||||
~Discreet3DSImporter() override = default;
|
||||
|
|
@ -101,15 +96,14 @@ protected:
|
|||
// -------------------------------------------------------------------
|
||||
/** Converts a temporary material to the outer representation
|
||||
*/
|
||||
void ConvertMaterial(D3DS::Material& p_cMat,
|
||||
aiMaterial& p_pcOut);
|
||||
void ConvertMaterial(D3DS::Material& p_cMat, aiMaterial& p_pcOut);
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
/** Read a chunk
|
||||
*
|
||||
* @param pcOut Receives the current chunk
|
||||
*/
|
||||
void ReadChunk(Discreet3DS::Chunk* pcOut);
|
||||
void ReadChunk(D3DS::Discreet3DS::Chunk* pcOut);
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
/** Parse a percentage chunk. mCurrent will point to the next
|
||||
|
|
@ -119,13 +113,10 @@ protected:
|
|||
ai_real ParsePercentageChunk();
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
/** Parse a color chunk. mCurrent will point to the next
|
||||
* chunk behind afterwards. If no color chunk is found
|
||||
* QNAN is returned in all members.
|
||||
*/
|
||||
void ParseColorChunk(aiColor3D* p_pcOut,
|
||||
bool p_bAcceptPercent = true);
|
||||
|
||||
/** Parse a color chunk. mCurrent will point to the next chunk behind
|
||||
* afterward. If no color chunk is found QNAN is returned in all members.
|
||||
*/
|
||||
void ParseColorChunk(aiColor3D* p_pcOut, bool p_bAcceptPercent = true);
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
/** Skip a chunk in the file
|
||||
|
|
@ -133,7 +124,7 @@ protected:
|
|||
void SkipChunk();
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
/** Generate the nodegraph
|
||||
/** Generate the node-graph
|
||||
*/
|
||||
void GenerateNodeGraph(aiScene* pcOut);
|
||||
|
||||
|
|
@ -229,19 +220,19 @@ protected:
|
|||
// -------------------------------------------------------------------
|
||||
/** Add a node to the node graph
|
||||
*/
|
||||
void AddNodeToGraph(aiScene* pcSOut,aiNode* pcOut,D3DS::Node* pcIn,
|
||||
void AddNodeToGraph(aiScene* pcSOut,aiNode* pcOut, D3DS::Node* pcIn,
|
||||
aiMatrix4x4& absTrafo);
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
/** Search for a node in the graph.
|
||||
* Called recursively
|
||||
*/
|
||||
void InverseNodeSearch(D3DS::Node* pcNode,D3DS::Node* pcCurrent);
|
||||
void InverseNodeSearch(D3DS::Node* pcNode, D3DS::Node* pcCurrent);
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
/** Apply the master scaling factor to the mesh
|
||||
*/
|
||||
void ApplyMasterScale(aiScene* pScene);
|
||||
void ApplyMasterScale(const aiScene* pScene);
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
/** Clamp all indices in the file to a valid range
|
||||
|
|
@ -253,31 +244,26 @@ protected:
|
|||
*/
|
||||
void SkipTCBInfo();
|
||||
|
||||
protected:
|
||||
|
||||
/** Stream to read from */
|
||||
StreamReaderLE* stream;
|
||||
|
||||
/** Last touched node index */
|
||||
private:
|
||||
/// Stream to read from
|
||||
StreamReaderLE* mStream;
|
||||
/// Last touched node index
|
||||
short mLastNodeIndex;
|
||||
|
||||
/** Current node, root node */
|
||||
D3DS::Node* mCurrentNode, *mRootNode;
|
||||
|
||||
/** Scene under construction */
|
||||
/// Current node
|
||||
D3DS::Node* mCurrentNode;
|
||||
/// Root node
|
||||
D3DS::Node *mRootNode;
|
||||
/// Scene under construction
|
||||
D3DS::Scene* mScene;
|
||||
|
||||
/** Ambient base color of the scene */
|
||||
/// Ambient base color of the scene
|
||||
aiColor3D mClrAmbient;
|
||||
|
||||
/** Master scaling factor of the scene */
|
||||
/// Master scaling factor of the scene
|
||||
ai_real mMasterScale;
|
||||
|
||||
/** Path to the background image of the scene */
|
||||
/// Path to the background image of the scene
|
||||
std::string mBackgroundImage;
|
||||
/// true for has a background
|
||||
bool bHasBG;
|
||||
|
||||
/** true if PRJ file */
|
||||
/// true if PRJ file
|
||||
bool bIsPrj;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
Open Asset Import Library (assimp)
|
||||
----------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2024, assimp team
|
||||
Copyright (c) 2006-2026, assimp team
|
||||
|
||||
All rights reserved.
|
||||
|
||||
|
|
@ -49,8 +49,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
struct aiMaterial;
|
||||
struct aiMesh;
|
||||
|
||||
namespace Assimp {
|
||||
namespace D3MF {
|
||||
namespace Assimp:: D3MF {
|
||||
|
||||
enum class ResourceType {
|
||||
RT_Object,
|
||||
|
|
@ -65,8 +64,7 @@ class Resource {
|
|||
public:
|
||||
int mId;
|
||||
|
||||
Resource(int id) :
|
||||
mId(id) {
|
||||
explicit Resource(int id) : mId(id) {
|
||||
// empty
|
||||
}
|
||||
|
||||
|
|
@ -77,7 +75,7 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
class EmbeddedTexture : public Resource {
|
||||
class EmbeddedTexture final : public Resource {
|
||||
public:
|
||||
std::string mPath;
|
||||
std::string mContentType;
|
||||
|
|
@ -85,12 +83,7 @@ public:
|
|||
std::string mTilestyleV;
|
||||
std::vector<char> mBuffer;
|
||||
|
||||
EmbeddedTexture(int id) :
|
||||
Resource(id),
|
||||
mPath(),
|
||||
mContentType(),
|
||||
mTilestyleU(),
|
||||
mTilestyleV() {
|
||||
explicit EmbeddedTexture(int id) : Resource(id) {
|
||||
// empty
|
||||
}
|
||||
|
||||
|
|
@ -101,13 +94,12 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
class Texture2DGroup : public Resource {
|
||||
class Texture2DGroup final : public Resource {
|
||||
public:
|
||||
std::vector<aiVector2D> mTex2dCoords;
|
||||
int mTexId;
|
||||
Texture2DGroup(int id) :
|
||||
Resource(id),
|
||||
mTexId(-1) {
|
||||
|
||||
explicit Texture2DGroup(int id) : Resource(id), mTexId(-1) {
|
||||
// empty
|
||||
}
|
||||
|
||||
|
|
@ -118,11 +110,11 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
class ColorGroup : public Resource {
|
||||
class ColorGroup final : public Resource {
|
||||
public:
|
||||
std::vector<aiColor4D> mColors;
|
||||
ColorGroup(int id) :
|
||||
Resource(id){
|
||||
|
||||
explicit ColorGroup(int id) : Resource(id) {
|
||||
// empty
|
||||
}
|
||||
|
||||
|
|
@ -133,13 +125,11 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
class BaseMaterials : public Resource {
|
||||
class BaseMaterials final : public Resource {
|
||||
public:
|
||||
std::vector<unsigned int> mMaterialIndex;
|
||||
|
||||
BaseMaterials(int id) :
|
||||
Resource(id),
|
||||
mMaterialIndex() {
|
||||
explicit BaseMaterials(int id) : Resource(id) {
|
||||
// empty
|
||||
}
|
||||
|
||||
|
|
@ -155,14 +145,14 @@ struct Component {
|
|||
aiMatrix4x4 mTransformation;
|
||||
};
|
||||
|
||||
class Object : public Resource {
|
||||
class Object final : public Resource {
|
||||
public:
|
||||
std::vector<aiMesh *> mMeshes;
|
||||
std::vector<unsigned int> mMeshIndex;
|
||||
std::vector<Component> mComponents;
|
||||
std::string mName;
|
||||
|
||||
Object(int id) :
|
||||
explicit Object(int id) :
|
||||
Resource(id),
|
||||
mName(std::string("Object_") + ai_to_string(id)) {
|
||||
// empty
|
||||
|
|
@ -175,5 +165,4 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
} // namespace D3MF
|
||||
} // namespace Assimp
|
||||
} // namespace Assimp::D3MF
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
Open Asset Import Library (assimp)
|
||||
----------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2024, assimp team
|
||||
Copyright (c) 2006-2026, assimp team
|
||||
|
||||
All rights reserved.
|
||||
|
||||
|
|
@ -40,85 +40,80 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
*/
|
||||
#pragma once
|
||||
|
||||
namespace Assimp {
|
||||
namespace D3MF {
|
||||
|
||||
namespace XmlTag {
|
||||
namespace Assimp::D3MF::XmlTag {
|
||||
// Root tag
|
||||
const char* const RootTag = "3MF";
|
||||
constexpr char RootTag[] = "3MF";
|
||||
|
||||
// Meta-data
|
||||
const char* const meta = "metadata";
|
||||
const char* const meta_name = "name";
|
||||
constexpr char meta[] = "metadata";
|
||||
constexpr char meta_name[] = "name";
|
||||
|
||||
// Model-data specific tags
|
||||
const char* const model = "model";
|
||||
const char* const model_unit = "unit";
|
||||
const char* const metadata = "metadata";
|
||||
const char* const resources = "resources";
|
||||
const char* const object = "object";
|
||||
const char* const mesh = "mesh";
|
||||
const char* const components = "components";
|
||||
const char* const component = "component";
|
||||
const char* const vertices = "vertices";
|
||||
const char* const vertex = "vertex";
|
||||
const char* const triangles = "triangles";
|
||||
const char* const triangle = "triangle";
|
||||
const char* const x = "x";
|
||||
const char* const y = "y";
|
||||
const char* const z = "z";
|
||||
const char* const v1 = "v1";
|
||||
const char* const v2 = "v2";
|
||||
const char* const v3 = "v3";
|
||||
const char* const id = "id";
|
||||
const char* const pid = "pid";
|
||||
const char* const pindex = "pindex";
|
||||
const char* const p1 = "p1";
|
||||
const char *const p2 = "p2";
|
||||
const char *const p3 = "p3";
|
||||
const char* const name = "name";
|
||||
const char* const type = "type";
|
||||
const char* const build = "build";
|
||||
const char* const item = "item";
|
||||
const char* const objectid = "objectid";
|
||||
const char* const transform = "transform";
|
||||
const char *const path = "path";
|
||||
constexpr char model[] = "model";
|
||||
constexpr char model_unit[] = "unit";
|
||||
constexpr char metadata[] = "metadata";
|
||||
constexpr char resources[] = "resources";
|
||||
constexpr char object[] = "object";
|
||||
constexpr char mesh[] = "mesh";
|
||||
constexpr char components[] = "components";
|
||||
constexpr char component[] = "component";
|
||||
constexpr char vertices[] = "vertices";
|
||||
constexpr char vertex[] = "vertex";
|
||||
constexpr char triangles[] = "triangles";
|
||||
constexpr char triangle[] = "triangle";
|
||||
constexpr char x[] = "x";
|
||||
constexpr char y[] = "y";
|
||||
constexpr char z[] = "z";
|
||||
constexpr char v1[] = "v1";
|
||||
constexpr char v2[] = "v2";
|
||||
constexpr char v3[] = "v3";
|
||||
constexpr char id[] = "id";
|
||||
constexpr char pid[] = "pid";
|
||||
constexpr char pindex[] = "pindex";
|
||||
constexpr char p1[] = "p1";
|
||||
constexpr char p2[] = "p2";
|
||||
constexpr char p3[] = "p3";
|
||||
constexpr char name[] = "name";
|
||||
constexpr char type[] = "type";
|
||||
constexpr char build[] = "build";
|
||||
constexpr char item[] = "item";
|
||||
constexpr char objectid[] = "objectid";
|
||||
constexpr char transform[] = "transform";
|
||||
constexpr char path[] = "path";
|
||||
|
||||
// Material definitions
|
||||
const char* const basematerials = "basematerials";
|
||||
const char* const basematerials_base = "base";
|
||||
const char* const basematerials_name = "name";
|
||||
const char* const basematerials_displaycolor = "displaycolor";
|
||||
const char* const texture_2d = "m:texture2d";
|
||||
const char *const texture_group = "m:texture2dgroup";
|
||||
const char *const texture_content_type = "contenttype";
|
||||
const char *const texture_tilestyleu = "tilestyleu";
|
||||
const char *const texture_tilestylev = "tilestylev";
|
||||
const char *const texture_2d_coord = "m:tex2coord";
|
||||
const char *const texture_cuurd_u = "u";
|
||||
const char *const texture_cuurd_v = "v";
|
||||
constexpr char basematerials[] = "basematerials";
|
||||
constexpr char basematerials_base[] = "base";
|
||||
constexpr char basematerials_name[] = "name";
|
||||
constexpr char basematerials_displaycolor[] = "displaycolor";
|
||||
constexpr char texture_2d[] = "m:texture2d";
|
||||
constexpr char texture_group[] = "m:texture2dgroup";
|
||||
constexpr char texture_content_type[] = "contenttype";
|
||||
constexpr char texture_tilestyleu[] = "tilestyleu";
|
||||
constexpr char texture_tilestylev[] = "tilestylev";
|
||||
constexpr char texture_2d_coord[] = "m:tex2coord";
|
||||
constexpr char texture_cuurd_u[] = "u";
|
||||
constexpr char texture_cuurd_v[] = "v";
|
||||
|
||||
// vertex color definitions
|
||||
const char *const colorgroup = "m:colorgroup";
|
||||
const char *const color_item = "m:color";
|
||||
const char *const color_vaule = "color";
|
||||
constexpr char colorgroup[] = "m:colorgroup";
|
||||
constexpr char color_item[] = "m:color";
|
||||
constexpr char color_value[] = "color";
|
||||
|
||||
// Meta info tags
|
||||
const char* const CONTENT_TYPES_ARCHIVE = "[Content_Types].xml";
|
||||
const char* const ROOT_RELATIONSHIPS_ARCHIVE = "_rels/.rels";
|
||||
const char* const SCHEMA_CONTENTTYPES = "http://schemas.openxmlformats.org/package/2006/content-types";
|
||||
const char* const SCHEMA_RELATIONSHIPS = "http://schemas.openxmlformats.org/package/2006/relationships";
|
||||
const char* const RELS_RELATIONSHIP_CONTAINER = "Relationships";
|
||||
const char* const RELS_RELATIONSHIP_NODE = "Relationship";
|
||||
const char* const RELS_ATTRIB_TARGET = "Target";
|
||||
const char* const RELS_ATTRIB_TYPE = "Type";
|
||||
const char* const RELS_ATTRIB_ID = "Id";
|
||||
const char* const PACKAGE_START_PART_RELATIONSHIP_TYPE = "http://schemas.microsoft.com/3dmanufacturing/2013/01/3dmodel";
|
||||
const char* const PACKAGE_PRINT_TICKET_RELATIONSHIP_TYPE = "http://schemas.microsoft.com/3dmanufacturing/2013/01/printticket";
|
||||
const char* const PACKAGE_TEXTURE_RELATIONSHIP_TYPE = "http://schemas.microsoft.com/3dmanufacturing/2013/01/3dtexture";
|
||||
const char* const PACKAGE_CORE_PROPERTIES_RELATIONSHIP_TYPE = "http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties";
|
||||
const char* const PACKAGE_THUMBNAIL_RELATIONSHIP_TYPE = "http://schemas.openxmlformats.org/package/2006/relationships/metadata/thumbnail";
|
||||
}
|
||||
constexpr char CONTENT_TYPES_ARCHIVE[] = "[Content_Types].xml";
|
||||
constexpr char ROOT_RELATIONSHIPS_ARCHIVE[] = "_rels/.rels";
|
||||
constexpr char SCHEMA_CONTENTTYPES[] = "http://schemas.openxmlformats.org/package/2006/content-types";
|
||||
constexpr char SCHEMA_RELATIONSHIPS[] = "http://schemas.openxmlformats.org/package/2006/relationships";
|
||||
constexpr char RELS_RELATIONSHIP_CONTAINER[] = "Relationships";
|
||||
constexpr char RELS_RELATIONSHIP_NODE[] = "Relationship";
|
||||
constexpr char RELS_ATTRIB_TARGET[] = "Target";
|
||||
constexpr char RELS_ATTRIB_TYPE[] = "Type";
|
||||
constexpr char RELS_ATTRIB_ID[] = "Id";
|
||||
constexpr char PACKAGE_START_PART_RELATIONSHIP_TYPE[] = "http://schemas.microsoft.com/3dmanufacturing/2013/01/3dmodel";
|
||||
constexpr char PACKAGE_PRINT_TICKET_RELATIONSHIP_TYPE[] = "http://schemas.microsoft.com/3dmanufacturing/2013/01/printticket";
|
||||
constexpr char PACKAGE_TEXTURE_RELATIONSHIP_TYPE[] = "http://schemas.microsoft.com/3dmanufacturing/2013/01/3dtexture";
|
||||
constexpr char PACKAGE_CORE_PROPERTIES_RELATIONSHIP_TYPE[] = "http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties";
|
||||
constexpr char PACKAGE_THUMBNAIL_RELATIONSHIP_TYPE[] = "http://schemas.openxmlformats.org/package/2006/relationships/metadata/thumbnail";
|
||||
|
||||
} // Namespace D3MF
|
||||
} // Namespace Assimp
|
||||
} // namespace Assimp::D3MF
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
Open Asset Import Library (assimp)
|
||||
----------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2024, assimp team
|
||||
Copyright (c) 2006-2026, assimp team
|
||||
|
||||
All rights reserved.
|
||||
|
||||
|
|
@ -48,7 +48,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
#include <assimp/scene.h>
|
||||
#include <assimp/DefaultLogger.hpp>
|
||||
#include <assimp/Exporter.hpp>
|
||||
#include <assimp/IOStream.hpp>
|
||||
#include <assimp/IOSystem.hpp>
|
||||
|
||||
#include "3MFXmlTags.h"
|
||||
|
|
@ -94,7 +93,7 @@ D3MFExporter::~D3MFExporter() {
|
|||
mRelations.clear();
|
||||
}
|
||||
|
||||
bool D3MFExporter::validate() {
|
||||
bool D3MFExporter::validate() const {
|
||||
if (mArchiveName.empty()) {
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
Open Asset Import Library (assimp)
|
||||
----------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2024, assimp team
|
||||
Copyright (c) 2006-2026, assimp team
|
||||
|
||||
All rights reserved.
|
||||
|
||||
|
|
@ -68,7 +68,7 @@ class D3MFExporter {
|
|||
public:
|
||||
D3MFExporter( const char* pFile, const aiScene* pScene );
|
||||
~D3MFExporter();
|
||||
bool validate();
|
||||
bool validate() const;
|
||||
bool exportArchive( const char *file );
|
||||
bool exportContentTypes();
|
||||
bool exportRelations();
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
Open Asset Import Library (assimp)
|
||||
----------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2024, assimp team
|
||||
Copyright (c) 2006-2026, assimp team
|
||||
|
||||
All rights reserved.
|
||||
|
||||
|
|
@ -85,7 +85,7 @@ bool D3MFImporter::CanRead(const std::string &filename, IOSystem *pIOHandler, bo
|
|||
if (!ZipArchiveIOSystem::isZipArchive(pIOHandler, filename)) {
|
||||
return false;
|
||||
}
|
||||
static const char *const ModelRef = "3D/3dmodel.model";
|
||||
static constexpr char ModelRef[] = "3D/3dmodel.model";
|
||||
ZipArchiveIOSystem archive(pIOHandler, filename);
|
||||
if (!archive.Exists(ModelRef)) {
|
||||
return false;
|
||||
|
|
@ -107,7 +107,7 @@ void D3MFImporter::InternReadFile(const std::string &filename, aiScene *pScene,
|
|||
|
||||
XmlParser xmlParser;
|
||||
if (xmlParser.parse(opcPackage.RootStream())) {
|
||||
XmlSerializer xmlSerializer(&xmlParser);
|
||||
XmlSerializer xmlSerializer(xmlParser);
|
||||
xmlSerializer.ImportXml(pScene);
|
||||
|
||||
const std::vector<aiTexture*> &tex = opcPackage.GetEmbeddedTextures();
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
Open Asset Import Library (assimp)
|
||||
----------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2024, assimp team
|
||||
Copyright (c) 2006-2026, assimp team
|
||||
|
||||
All rights reserved.
|
||||
|
||||
|
|
@ -53,7 +53,7 @@ namespace Assimp {
|
|||
///
|
||||
/// Implements the basic topology import and embedded textures.
|
||||
// ---------------------------------------------------------------------------
|
||||
class D3MFImporter : public BaseImporter {
|
||||
class D3MFImporter final : public BaseImporter {
|
||||
public:
|
||||
/// @brief The default class constructor.
|
||||
D3MFImporter() = default;
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
Open Asset Import Library (assimp)
|
||||
----------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2024, assimp team
|
||||
Copyright (c) 2006-2026, assimp team
|
||||
|
||||
All rights reserved.
|
||||
|
||||
|
|
@ -65,10 +65,9 @@ namespace D3MF {
|
|||
|
||||
using OpcPackageRelationshipPtr = std::shared_ptr<OpcPackageRelationship>;
|
||||
|
||||
class OpcPackageRelationshipReader {
|
||||
class OpcPackageRelationshipReader final {
|
||||
public:
|
||||
OpcPackageRelationshipReader(XmlParser &parser) :
|
||||
mRelations() {
|
||||
explicit OpcPackageRelationshipReader(XmlParser &parser) : mRelations() {
|
||||
XmlNode root = parser.getRootNode();
|
||||
ParseRootNode(root);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
Open Asset Import Library (assimp)
|
||||
----------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2024, assimp team
|
||||
Copyright (c) 2006-2026, assimp team
|
||||
|
||||
All rights reserved.
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
Open Asset Import Library (assimp)
|
||||
----------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2024, assimp team
|
||||
Copyright (c) 2006-2026, assimp team
|
||||
|
||||
All rights reserved.
|
||||
|
||||
|
|
@ -199,11 +199,11 @@ void assignDiffuseColor(XmlNode &node, aiMaterial *mat) {
|
|||
|
||||
} // namespace
|
||||
|
||||
XmlSerializer::XmlSerializer(XmlParser *xmlParser) :
|
||||
XmlSerializer::XmlSerializer(XmlParser &xmlParser) :
|
||||
mResourcesDictionnary(),
|
||||
mMeshCount(0),
|
||||
mXmlParser(xmlParser) {
|
||||
ai_assert(nullptr != xmlParser);
|
||||
// empty
|
||||
}
|
||||
|
||||
XmlSerializer::~XmlSerializer() {
|
||||
|
|
@ -218,7 +218,7 @@ void XmlSerializer::ImportXml(aiScene *scene) {
|
|||
}
|
||||
|
||||
scene->mRootNode = new aiNode(XmlTag::RootTag);
|
||||
XmlNode node = mXmlParser->getRootNode().child(XmlTag::model);
|
||||
XmlNode node = mXmlParser.getRootNode().child(XmlTag::model);
|
||||
if (node.empty()) {
|
||||
return;
|
||||
}
|
||||
|
|
@ -680,7 +680,7 @@ void XmlSerializer::ReadColor(XmlNode &node, ColorGroup *colorGroup) {
|
|||
for (XmlNode currentNode : node.children()) {
|
||||
const std::string currentName = currentNode.name();
|
||||
if (currentName == XmlTag::color_item) {
|
||||
const char *color = currentNode.attribute(XmlTag::color_vaule).as_string();
|
||||
const char *color = currentNode.attribute(XmlTag::color_value).as_string();
|
||||
aiColor4D color_value;
|
||||
if (parseColor(color, color_value)) {
|
||||
colorGroup->mColors.push_back(color_value);
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
Open Asset Import Library (assimp)
|
||||
----------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2024, assimp team
|
||||
Copyright (c) 2006-2026, assimp team
|
||||
|
||||
All rights reserved.
|
||||
|
||||
|
|
@ -59,9 +59,10 @@ class Texture2DGroup;
|
|||
class EmbeddedTexture;
|
||||
class ColorGroup;
|
||||
|
||||
class XmlSerializer {
|
||||
/// @brief his class implements ther 3mf serialization.
|
||||
class XmlSerializer final {
|
||||
public:
|
||||
XmlSerializer(XmlParser *xmlParser);
|
||||
explicit XmlSerializer(XmlParser &xmlParser);
|
||||
~XmlSerializer();
|
||||
void ImportXml(aiScene *scene);
|
||||
|
||||
|
|
@ -92,7 +93,7 @@ private:
|
|||
std::vector<aiMaterial *> mMaterials;
|
||||
std::map<unsigned int, Resource *> mResourcesDictionnary;
|
||||
unsigned int mMeshCount;
|
||||
XmlParser *mXmlParser;
|
||||
XmlParser &mXmlParser;
|
||||
};
|
||||
|
||||
} // namespace D3MF
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
Open Asset Import Library (assimp)
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2024, assimp team
|
||||
Copyright (c) 2006-2026, assimp team
|
||||
|
||||
All rights reserved.
|
||||
|
||||
|
|
@ -75,6 +75,8 @@ static constexpr aiImporterDesc desc = {
|
|||
"ac acc ac3d"
|
||||
};
|
||||
|
||||
static constexpr auto ACDoubleSidedFlag = 0x20;
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// skip to the next token
|
||||
inline const char *AcSkipToNextToken(const char *buffer, const char *end) {
|
||||
|
|
@ -123,12 +125,36 @@ inline const char *TAcCheckedLoadFloatArray(const char *buffer, const char *end,
|
|||
}
|
||||
for (unsigned int _i = 0; _i < num; ++_i) {
|
||||
buffer = AcSkipToNextToken(buffer, end);
|
||||
buffer = fast_atoreal_move<float>(buffer, ((float *)out)[_i]);
|
||||
buffer = fast_atoreal_move(buffer, ((float *)out)[_i]);
|
||||
}
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Reverses vertex indices in a face.
|
||||
static void flipWindingOrder(aiFace &f) {
|
||||
std::reverse(f.mIndices, f.mIndices + f.mNumIndices);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Duplicates a face and inverts it. Also duplicates all vertices (so the new face gets its own
|
||||
// set of normals and isn’t smoothed against the original).
|
||||
static void buildBacksideOfFace(const aiFace &origFace, aiFace *&outFaces, aiVector3D *&outVertices, const aiVector3D *allVertices,
|
||||
aiVector3D *&outUV, const aiVector3D *allUV, unsigned &curIdx) {
|
||||
auto &newFace = *outFaces++;
|
||||
newFace = origFace;
|
||||
flipWindingOrder(newFace);
|
||||
for (unsigned f = 0; f < newFace.mNumIndices; ++f) {
|
||||
*outVertices++ = allVertices[newFace.mIndices[f]];
|
||||
if (outUV) {
|
||||
*outUV = allUV[newFace.mIndices[f]];
|
||||
outUV++;
|
||||
}
|
||||
newFace.mIndices[f] = curIdx++;
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Constructor to be privately used by Importer
|
||||
AC3DImporter::AC3DImporter() :
|
||||
|
|
@ -144,14 +170,10 @@ AC3DImporter::AC3DImporter() :
|
|||
// nothing to be done here
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Destructor, private as well
|
||||
AC3DImporter::~AC3DImporter() = default;
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Returns whether the class can handle the format of the given file.
|
||||
bool AC3DImporter::CanRead(const std::string &pFile, IOSystem *pIOHandler, bool /*checkSig*/) const {
|
||||
static const uint32_t tokens[] = { AI_MAKE_MAGIC("AC3D") };
|
||||
static constexpr uint32_t tokens[] = { AI_MAKE_MAGIC("AC3D") };
|
||||
return CheckMagicToken(pIOHandler, pFile, tokens, AI_COUNT_OF(tokens));
|
||||
}
|
||||
|
||||
|
|
@ -171,8 +193,9 @@ bool AC3DImporter::GetNextLine() {
|
|||
// ------------------------------------------------------------------------------------------------
|
||||
// Parse an object section in an AC file
|
||||
bool AC3DImporter::LoadObjectSection(std::vector<Object> &objects) {
|
||||
if (!TokenMatch(mBuffer.data, "OBJECT", 6))
|
||||
if (!TokenMatch(mBuffer.data, "OBJECT", 6)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
SkipSpaces(&mBuffer.data, mBuffer.end);
|
||||
|
||||
|
|
@ -192,7 +215,6 @@ bool AC3DImporter::LoadObjectSection(std::vector<Object> &objects) {
|
|||
light->mAttenuationConstant = 1.f;
|
||||
|
||||
// Generate a default name for both the light source and the node
|
||||
// FIXME - what's the right way to print a size_t? Is 'zu' universally available? stick with the safe version.
|
||||
light->mName.length = ::ai_snprintf(light->mName.data, AI_MAXLEN, "ACLight_%i", static_cast<unsigned int>(mLights->size()) - 1);
|
||||
obj.name = std::string(light->mName.data);
|
||||
|
||||
|
|
@ -202,8 +224,10 @@ bool AC3DImporter::LoadObjectSection(std::vector<Object> &objects) {
|
|||
obj.type = Object::Group;
|
||||
} else if (!ASSIMP_strincmp(mBuffer.data, "world", 5)) {
|
||||
obj.type = Object::World;
|
||||
} else
|
||||
} else {
|
||||
obj.type = Object::Poly;
|
||||
}
|
||||
|
||||
while (GetNextLine()) {
|
||||
if (TokenMatch(mBuffer.data, "kids", 4)) {
|
||||
SkipSpaces(&mBuffer.data, mBuffer.end);
|
||||
|
|
@ -344,6 +368,7 @@ bool AC3DImporter::LoadObjectSection(std::vector<Object> &objects) {
|
|||
}
|
||||
}
|
||||
ASSIMP_LOG_ERROR("AC3D: Unexpected EOF: \'kids\' line was expected");
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -452,6 +477,8 @@ aiNode *AC3DImporter::ConvertObjectSection(Object &object,
|
|||
if ((*it).entries.empty()) {
|
||||
ASSIMP_LOG_WARN("AC3D: surface has zero vertex references");
|
||||
}
|
||||
const bool isDoubleSided = ACDoubleSidedFlag == (it->flags & ACDoubleSidedFlag);
|
||||
const int doubleSidedFactor = isDoubleSided ? 2 : 1;
|
||||
|
||||
// validate all vertex indices to make sure we won't crash here
|
||||
for (it2 = (*it).entries.begin(),
|
||||
|
|
@ -481,8 +508,8 @@ aiNode *AC3DImporter::ConvertObjectSection(Object &object,
|
|||
|
||||
// triangle strip
|
||||
case Surface::TriangleStrip:
|
||||
needMat[idx].first += (unsigned int)(*it).entries.size() - 2;
|
||||
needMat[idx].second += ((unsigned int)(*it).entries.size() - 2) * 3;
|
||||
needMat[idx].first += static_cast<unsigned int>(it->entries.size() - 2) * doubleSidedFactor;
|
||||
needMat[idx].second += static_cast<unsigned int>(it->entries.size() - 2) * 3 * doubleSidedFactor;
|
||||
break;
|
||||
|
||||
default:
|
||||
|
|
@ -495,8 +522,8 @@ aiNode *AC3DImporter::ConvertObjectSection(Object &object,
|
|||
case Surface::Polygon:
|
||||
// the number of faces increments by one, the number
|
||||
// of vertices by surface.numref.
|
||||
needMat[idx].first++;
|
||||
needMat[idx].second += (unsigned int)(*it).entries.size();
|
||||
needMat[idx].first += doubleSidedFactor;
|
||||
needMat[idx].second += static_cast<unsigned int>(it->entries.size()) * doubleSidedFactor;
|
||||
};
|
||||
}
|
||||
unsigned int *pip = node->mMeshes = new unsigned int[node->mNumMeshes];
|
||||
|
|
@ -546,6 +573,7 @@ aiNode *AC3DImporter::ConvertObjectSection(Object &object,
|
|||
for (it = object.surfaces.begin(); it != end; ++it) {
|
||||
if (mat == (*it).mat) {
|
||||
const Surface &src = *it;
|
||||
const bool isDoubleSided = ACDoubleSidedFlag == (src.flags & ACDoubleSidedFlag);
|
||||
|
||||
// closed polygon
|
||||
uint8_t type = (*it).GetType();
|
||||
|
|
@ -571,12 +599,18 @@ aiNode *AC3DImporter::ConvertObjectSection(Object &object,
|
|||
++uv;
|
||||
}
|
||||
}
|
||||
if(isDoubleSided) // Need a backface?
|
||||
buildBacksideOfFace(faces[-1], faces, vertices, mesh->mVertices, uv, mesh->mTextureCoords[0], cur);
|
||||
}
|
||||
} else if (type == Surface::TriangleStrip) {
|
||||
for (unsigned int i = 0; i < (unsigned int)src.entries.size() - 2; ++i) {
|
||||
const Surface::SurfaceEntry &entry1 = src.entries[i];
|
||||
const Surface::SurfaceEntry &entry2 = src.entries[i + 1];
|
||||
const Surface::SurfaceEntry &entry3 = src.entries[i + 2];
|
||||
const unsigned int verticesNeeded = isDoubleSided ? 6 : 3;
|
||||
if (static_cast<unsigned>(vertices - mesh->mVertices) + verticesNeeded > mesh->mNumVertices) {
|
||||
throw DeadlyImportError("AC3D: Invalid number of vertices");
|
||||
}
|
||||
|
||||
aiFace &face = *faces++;
|
||||
face.mNumIndices = 3;
|
||||
|
|
@ -620,6 +654,8 @@ aiNode *AC3DImporter::ConvertObjectSection(Object &object,
|
|||
uv->y = entry3.second.y;
|
||||
++uv;
|
||||
}
|
||||
if(isDoubleSided) // Need a backface?
|
||||
buildBacksideOfFace(faces[-1], faces, vertices, mesh->mVertices, uv, mesh->mTextureCoords[0], cur);
|
||||
}
|
||||
} else {
|
||||
|
||||
|
|
@ -629,6 +665,10 @@ aiNode *AC3DImporter::ConvertObjectSection(Object &object,
|
|||
unsigned int tmp = (unsigned int)(*it).entries.size();
|
||||
if (Surface::OpenLine == type) --tmp;
|
||||
for (unsigned int m = 0; m < tmp; ++m) {
|
||||
if (static_cast<unsigned>(vertices - mesh->mVertices) + 2 > mesh->mNumVertices) {
|
||||
throw DeadlyImportError("AC3D: Invalid number of vertices");
|
||||
}
|
||||
|
||||
aiFace &face = *faces++;
|
||||
|
||||
face.mNumIndices = 2;
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
Open Asset Import Library (assimp)
|
||||
----------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2024, assimp team
|
||||
Copyright (c) 2006-2026, assimp team
|
||||
|
||||
All rights reserved.
|
||||
|
||||
|
|
@ -60,10 +60,10 @@ namespace Assimp {
|
|||
// ---------------------------------------------------------------------------
|
||||
/** AC3D (*.ac) importer class
|
||||
*/
|
||||
class AC3DImporter : public BaseImporter {
|
||||
class AC3DImporter final : public BaseImporter {
|
||||
public:
|
||||
AC3DImporter();
|
||||
~AC3DImporter() override;
|
||||
~AC3DImporter() override = default;
|
||||
|
||||
// Represents an AC3D material
|
||||
struct Material {
|
||||
|
|
@ -103,7 +103,7 @@ public:
|
|||
|
||||
unsigned int mat, flags;
|
||||
|
||||
typedef std::pair<unsigned int, aiVector2D> SurfaceEntry;
|
||||
using SurfaceEntry = std::pair<unsigned int, aiVector2D>;
|
||||
std::vector<SurfaceEntry> entries;
|
||||
|
||||
// Type is low nibble of flags
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
Open Asset Import Library (assimp)
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2024, assimp team
|
||||
Copyright (c) 2006-2026, assimp team
|
||||
|
||||
All rights reserved.
|
||||
|
||||
|
|
@ -327,8 +327,7 @@ void AMFImporter::ParseNode_Root() {
|
|||
// Multi elements - Yes.
|
||||
// Parent element - <amf>.
|
||||
void AMFImporter::ParseNode_Constellation(XmlNode &node) {
|
||||
std::string id;
|
||||
id = node.attribute("id").as_string();
|
||||
std::string id = node.attribute("id").as_string();
|
||||
|
||||
// create and if needed - define new grouping object.
|
||||
AMFNodeElementBase *ne = new AMFConstellation(mNodeElement_Cur);
|
||||
|
|
@ -474,7 +473,7 @@ void AMFImporter::ParseNode_Metadata(XmlNode &node) {
|
|||
|
||||
// read attribute
|
||||
ne = new AMFMetadata(mNodeElement_Cur);
|
||||
((AMFMetadata *)ne)->Type = type;
|
||||
((AMFMetadata *)ne)->MetaType = type;
|
||||
((AMFMetadata *)ne)->Value = value;
|
||||
mNodeElement_Cur->Child.push_back(ne); // Add element to child list of current element
|
||||
mNodeElement_List.push_back(ne); // and to node element list because its a new object in graph.
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
Open Asset Import Library (assimp)
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2024, assimp team
|
||||
Copyright (c) 2006-2026, assimp team
|
||||
|
||||
All rights reserved.
|
||||
|
||||
|
|
@ -97,7 +97,7 @@ namespace Assimp {
|
|||
/// new - <texmap> and children <utex1>, <utex2>, <utex3>, <vtex1>, <vtex2>, <vtex3>
|
||||
/// old - <map> and children <u1>, <u2>, <u3>, <v1>, <v2>, <v3>
|
||||
///
|
||||
class AMFImporter : public BaseImporter {
|
||||
class AMFImporter final : public BaseImporter {
|
||||
using AMFMetaDataArray = std::vector<AMFMetadata *>;
|
||||
using MeshArray = std::vector<aiMesh *>;
|
||||
using NodeArray = std::vector<aiNode *>;
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
Open Asset Import Library (assimp)
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2024, assimp team
|
||||
Copyright (c) 2006-2026, assimp team
|
||||
|
||||
All rights reserved.
|
||||
|
||||
|
|
@ -202,7 +202,7 @@ void AMFImporter::ParseNode_Volume(XmlNode &node) {
|
|||
|
||||
((AMFVolume *)ne)->MaterialID = node.attribute("materialid").as_string();
|
||||
|
||||
((AMFVolume *)ne)->Type = type;
|
||||
((AMFVolume *)ne)->VolumeType = type;
|
||||
// Check for child nodes
|
||||
bool col_read = false;
|
||||
if (!node.empty()) {
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
Open Asset Import Library (assimp)
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2024, assimp team
|
||||
Copyright (c) 2006-2026, assimp team
|
||||
|
||||
All rights reserved.
|
||||
|
||||
|
|
@ -263,22 +263,22 @@ void AMFImporter::ParseNode_TexMap(XmlNode &node, const bool pUseOldName) {
|
|||
const std::string &name = currentNode.name();
|
||||
if (name == "utex1") {
|
||||
read_flag[0] = true;
|
||||
XmlParser::getValueAsReal(node, als.TextureCoordinate[0].x);
|
||||
XmlParser::getValueAsReal(currentNode, als.TextureCoordinate[0].x);
|
||||
} else if (name == "utex2") {
|
||||
read_flag[1] = true;
|
||||
XmlParser::getValueAsReal(node, als.TextureCoordinate[1].x);
|
||||
XmlParser::getValueAsReal(currentNode, als.TextureCoordinate[1].x);
|
||||
} else if (name == "utex3") {
|
||||
read_flag[2] = true;
|
||||
XmlParser::getValueAsReal(node, als.TextureCoordinate[2].x);
|
||||
XmlParser::getValueAsReal(currentNode, als.TextureCoordinate[2].x);
|
||||
} else if (name == "vtex1") {
|
||||
read_flag[3] = true;
|
||||
XmlParser::getValueAsReal(node, als.TextureCoordinate[0].y);
|
||||
XmlParser::getValueAsReal(currentNode, als.TextureCoordinate[0].y);
|
||||
} else if (name == "vtex2") {
|
||||
read_flag[4] = true;
|
||||
XmlParser::getValueAsReal(node, als.TextureCoordinate[1].y);
|
||||
XmlParser::getValueAsReal(currentNode, als.TextureCoordinate[1].y);
|
||||
} else if (name == "vtex3") {
|
||||
read_flag[5] = true;
|
||||
XmlParser::getValueAsReal(node, als.TextureCoordinate[2].y);
|
||||
XmlParser::getValueAsReal(currentNode, als.TextureCoordinate[2].y);
|
||||
}
|
||||
}
|
||||
ParseHelper_Node_Exit();
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
Open Asset Import Library (assimp)
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2024, assimp team
|
||||
Copyright (c) 2006-2026, assimp team
|
||||
|
||||
All rights reserved.
|
||||
|
||||
|
|
@ -86,7 +86,8 @@ public:
|
|||
AMFNodeElementBase *Parent; ///< Parent element. If nullptr then this node is root.
|
||||
std::list<AMFNodeElementBase *> Child; ///< Child elements.
|
||||
|
||||
public: /// Destructor, virtual..
|
||||
public:
|
||||
/// Destructor, virtual..
|
||||
virtual ~AMFNodeElementBase() = default;
|
||||
|
||||
/// Disabled copy constructor and co.
|
||||
|
|
@ -97,25 +98,25 @@ public: /// Destructor, virtual..
|
|||
|
||||
protected:
|
||||
/// In constructor inheritor must set element type.
|
||||
/// \param [in] pType - element type.
|
||||
/// \param [in] type - element type.
|
||||
/// \param [in] pParent - parent element.
|
||||
AMFNodeElementBase(const EType pType, AMFNodeElementBase *pParent) :
|
||||
Type(pType), Parent(pParent) {
|
||||
AMFNodeElementBase(EType type, AMFNodeElementBase *pParent) :
|
||||
Type(type), Parent(pParent) {
|
||||
// empty
|
||||
}
|
||||
}; // class IAMFImporter_NodeElement
|
||||
|
||||
/// A collection of objects or constellations with specific relative locations.
|
||||
struct AMFConstellation : public AMFNodeElementBase {
|
||||
struct AMFConstellation final : public AMFNodeElementBase {
|
||||
/// Constructor.
|
||||
/// \param [in] pParent - pointer to parent node.
|
||||
AMFConstellation(AMFNodeElementBase *pParent) :
|
||||
explicit AMFConstellation(AMFNodeElementBase *pParent) :
|
||||
AMFNodeElementBase(ENET_Constellation, pParent) {}
|
||||
|
||||
}; // struct CAMFImporter_NodeElement_Constellation
|
||||
|
||||
/// Part of constellation.
|
||||
struct AMFInstance : public AMFNodeElementBase {
|
||||
struct AMFInstance final : public AMFNodeElementBase {
|
||||
|
||||
std::string ObjectID; ///< ID of object for instantiation.
|
||||
/// \var Delta - The distance of translation in the x, y, or z direction, respectively, in the referenced object's coordinate system, to
|
||||
|
|
@ -128,20 +129,22 @@ struct AMFInstance : public AMFNodeElementBase {
|
|||
|
||||
/// Constructor.
|
||||
/// \param [in] pParent - pointer to parent node.
|
||||
AMFInstance(AMFNodeElementBase *pParent) :
|
||||
explicit AMFInstance(AMFNodeElementBase *pParent) :
|
||||
AMFNodeElementBase(ENET_Instance, pParent) {}
|
||||
};
|
||||
|
||||
/// Structure that define metadata node.
|
||||
struct AMFMetadata : public AMFNodeElementBase {
|
||||
|
||||
std::string Type; ///< Type of "Value".
|
||||
std::string Value; ///< Value.
|
||||
std::string MetaType; ///< Type of "Value".
|
||||
std::string Value; ///< Value.
|
||||
|
||||
/// Constructor.
|
||||
/// \param [in] pParent - pointer to parent node.
|
||||
AMFMetadata(AMFNodeElementBase *pParent) :
|
||||
AMFNodeElementBase(ENET_Metadata, pParent) {}
|
||||
explicit AMFMetadata(AMFNodeElementBase *pParent) :
|
||||
AMFNodeElementBase(ENET_Metadata, pParent) {
|
||||
// empty
|
||||
}
|
||||
};
|
||||
|
||||
/// Structure that define root node.
|
||||
|
|
@ -152,8 +155,10 @@ struct AMFRoot : public AMFNodeElementBase {
|
|||
|
||||
/// Constructor.
|
||||
/// \param [in] pParent - pointer to parent node.
|
||||
AMFRoot(AMFNodeElementBase *pParent) :
|
||||
AMFNodeElementBase(ENET_Root, pParent) {}
|
||||
explicit AMFRoot(AMFNodeElementBase *pParent) :
|
||||
AMFNodeElementBase(ENET_Root, pParent) {
|
||||
// empty
|
||||
}
|
||||
};
|
||||
|
||||
/// Structure that define object node.
|
||||
|
|
@ -165,7 +170,7 @@ struct AMFColor : public AMFNodeElementBase {
|
|||
|
||||
/// @brief Constructor.
|
||||
/// @param [in] pParent - pointer to parent node.
|
||||
AMFColor(AMFNodeElementBase *pParent) :
|
||||
explicit AMFColor(AMFNodeElementBase *pParent) :
|
||||
AMFNodeElementBase(ENET_Color, pParent), Composed(false), Color() {
|
||||
// empty
|
||||
}
|
||||
|
|
@ -173,64 +178,75 @@ struct AMFColor : public AMFNodeElementBase {
|
|||
|
||||
/// Structure that define material node.
|
||||
struct AMFMaterial : public AMFNodeElementBase {
|
||||
|
||||
/// Constructor.
|
||||
/// \param [in] pParent - pointer to parent node.
|
||||
AMFMaterial(AMFNodeElementBase *pParent) :
|
||||
AMFNodeElementBase(ENET_Material, pParent) {}
|
||||
explicit AMFMaterial(AMFNodeElementBase *pParent) :
|
||||
AMFNodeElementBase(ENET_Material, pParent) {
|
||||
// empty
|
||||
}
|
||||
};
|
||||
|
||||
/// Structure that define object node.
|
||||
struct AMFObject : public AMFNodeElementBase {
|
||||
|
||||
/// Constructor.
|
||||
/// \param [in] pParent - pointer to parent node.
|
||||
AMFObject(AMFNodeElementBase *pParent) :
|
||||
AMFNodeElementBase(ENET_Object, pParent) {}
|
||||
explicit AMFObject(AMFNodeElementBase *pParent) :
|
||||
AMFNodeElementBase(ENET_Object, pParent) {
|
||||
// empty
|
||||
}
|
||||
};
|
||||
|
||||
/// \struct CAMFImporter_NodeElement_Mesh
|
||||
/// Structure that define mesh node.
|
||||
struct AMFMesh : public AMFNodeElementBase {
|
||||
/// Constructor.
|
||||
/// \param [in] pParent - pointer to parent node.
|
||||
AMFMesh(AMFNodeElementBase *pParent) :
|
||||
AMFNodeElementBase(ENET_Mesh, pParent) {}
|
||||
explicit AMFMesh(AMFNodeElementBase *pParent) :
|
||||
AMFNodeElementBase(ENET_Mesh, pParent) {
|
||||
// empty
|
||||
}
|
||||
};
|
||||
|
||||
/// Structure that define vertex node.
|
||||
struct AMFVertex : public AMFNodeElementBase {
|
||||
/// Constructor.
|
||||
/// \param [in] pParent - pointer to parent node.
|
||||
AMFVertex(AMFNodeElementBase *pParent) :
|
||||
AMFNodeElementBase(ENET_Vertex, pParent) {}
|
||||
explicit AMFVertex(AMFNodeElementBase *pParent) :
|
||||
AMFNodeElementBase(ENET_Vertex, pParent) {
|
||||
// empty
|
||||
}
|
||||
};
|
||||
|
||||
/// Structure that define edge node.
|
||||
struct AMFEdge : public AMFNodeElementBase {
|
||||
/// Constructor.
|
||||
/// \param [in] pParent - pointer to parent node.
|
||||
AMFEdge(AMFNodeElementBase *pParent) :
|
||||
AMFNodeElementBase(ENET_Edge, pParent) {}
|
||||
explicit AMFEdge(AMFNodeElementBase *pParent) :
|
||||
AMFNodeElementBase(ENET_Edge, pParent) {
|
||||
// empty
|
||||
}
|
||||
};
|
||||
|
||||
/// Structure that define vertices node.
|
||||
struct AMFVertices : public AMFNodeElementBase {
|
||||
/// Constructor.
|
||||
/// \param [in] pParent - pointer to parent node.
|
||||
AMFVertices(AMFNodeElementBase *pParent) :
|
||||
AMFNodeElementBase(ENET_Vertices, pParent) {}
|
||||
explicit AMFVertices(AMFNodeElementBase *pParent) :
|
||||
AMFNodeElementBase(ENET_Vertices, pParent) {
|
||||
// empty
|
||||
}
|
||||
};
|
||||
|
||||
/// Structure that define volume node.
|
||||
struct AMFVolume : public AMFNodeElementBase {
|
||||
std::string MaterialID; ///< Which material to use.
|
||||
std::string Type; ///< What this volume describes can be "region" or "support". If none specified, "object" is assumed.
|
||||
std::string VolumeType; ///< What this volume describes can be "region" or "support". If none specified, "object" is assumed.
|
||||
|
||||
/// Constructor.
|
||||
/// \param [in] pParent - pointer to parent node.
|
||||
AMFVolume(AMFNodeElementBase *pParent) :
|
||||
AMFNodeElementBase(ENET_Volume, pParent) {}
|
||||
explicit AMFVolume(AMFNodeElementBase *pParent) :
|
||||
AMFNodeElementBase(ENET_Volume, pParent) {
|
||||
// empty
|
||||
}
|
||||
};
|
||||
|
||||
/// Structure that define coordinates node.
|
||||
|
|
@ -239,8 +255,10 @@ struct AMFCoordinates : public AMFNodeElementBase {
|
|||
|
||||
/// Constructor.
|
||||
/// \param [in] pParent - pointer to parent node.
|
||||
AMFCoordinates(AMFNodeElementBase *pParent) :
|
||||
AMFNodeElementBase(ENET_Coordinates, pParent) {}
|
||||
explicit AMFCoordinates(AMFNodeElementBase *pParent) :
|
||||
AMFNodeElementBase(ENET_Coordinates, pParent) {
|
||||
// empty
|
||||
}
|
||||
};
|
||||
|
||||
/// Structure that define texture coordinates node.
|
||||
|
|
@ -253,7 +271,7 @@ struct AMFTexMap : public AMFNodeElementBase {
|
|||
|
||||
/// Constructor.
|
||||
/// \param [in] pParent - pointer to parent node.
|
||||
AMFTexMap(AMFNodeElementBase *pParent) :
|
||||
explicit AMFTexMap(AMFNodeElementBase *pParent) :
|
||||
AMFNodeElementBase(ENET_TexMap, pParent), TextureCoordinate{} {
|
||||
// empty
|
||||
}
|
||||
|
|
@ -265,7 +283,7 @@ struct AMFTriangle : public AMFNodeElementBase {
|
|||
|
||||
/// Constructor.
|
||||
/// \param [in] pParent - pointer to parent node.
|
||||
AMFTriangle(AMFNodeElementBase *pParent) :
|
||||
explicit AMFTriangle(AMFNodeElementBase *pParent) :
|
||||
AMFNodeElementBase(ENET_Triangle, pParent) {
|
||||
// empty
|
||||
}
|
||||
|
|
@ -279,7 +297,7 @@ struct AMFTexture : public AMFNodeElementBase {
|
|||
|
||||
/// Constructor.
|
||||
/// \param [in] pParent - pointer to parent node.
|
||||
AMFTexture(AMFNodeElementBase *pParent) :
|
||||
explicit AMFTexture(AMFNodeElementBase *pParent) :
|
||||
AMFNodeElementBase(ENET_Texture, pParent), Width(0), Height(0), Depth(0), Data(), Tiled(false) {
|
||||
// empty
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
Open Asset Import Library (assimp)
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2024, assimp team
|
||||
Copyright (c) 2006-2026, assimp team
|
||||
|
||||
All rights reserved.
|
||||
|
||||
|
|
@ -57,8 +57,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
namespace Assimp {
|
||||
|
||||
aiColor4D AMFImporter::SPP_Material::GetColor(const float /*pX*/, const float /*pY*/, const float /*pZ*/) const {
|
||||
aiColor4D tcol;
|
||||
|
||||
// Check if stored data are supported.
|
||||
if (!Composition.empty()) {
|
||||
throw DeadlyImportError("IME. GetColor for composition");
|
||||
|
|
@ -68,7 +66,7 @@ aiColor4D AMFImporter::SPP_Material::GetColor(const float /*pX*/, const float /*
|
|||
throw DeadlyImportError("IME. GetColor, composed color");
|
||||
}
|
||||
|
||||
tcol = Color->Color;
|
||||
aiColor4D tcol = Color->Color;
|
||||
|
||||
// Check if default color must be used
|
||||
if ((tcol.r == 0) && (tcol.g == 0) && (tcol.b == 0) && (tcol.a == 0)) {
|
||||
|
|
@ -333,7 +331,7 @@ void AMFImporter::Postprocess_AddMetadata(const AMFMetaDataArray &metadataList,
|
|||
size_t meta_idx(0);
|
||||
|
||||
for (const AMFMetadata *metadata : metadataList) {
|
||||
sceneNode.mMetaData->Set(static_cast<unsigned int>(meta_idx++), metadata->Type, aiString(metadata->Value));
|
||||
sceneNode.mMetaData->Set(static_cast<unsigned int>(meta_idx++), metadata->MetaType, aiString(metadata->Value));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -532,11 +530,9 @@ void AMFImporter::Postprocess_BuildMeshSet(const AMFMesh &pNodeElement, const st
|
|||
col_arr.reserve(VertexCount_Max * 2);
|
||||
|
||||
{ // fill arrays
|
||||
size_t vert_idx_from, vert_idx_to;
|
||||
|
||||
// first iteration.
|
||||
vert_idx_to = 0;
|
||||
vert_idx_from = VertexIndex_GetMinimal(face_list_cur, nullptr);
|
||||
size_t vert_idx_to = 0;
|
||||
size_t vert_idx_from = VertexIndex_GetMinimal(face_list_cur, nullptr);
|
||||
vert_arr.push_back(pVertexCoordinateArray.at(vert_idx_from));
|
||||
col_arr.push_back(Vertex_CalculateColor(vert_idx_from));
|
||||
if (vert_idx_from != vert_idx_to) VertexIndex_Replace(face_list_cur, vert_idx_from, vert_idx_to);
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
Open Asset Import Library (assimp)
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2024, assimp team
|
||||
Copyright (c) 2006-2026, assimp team
|
||||
|
||||
All rights reserved.
|
||||
|
||||
|
|
@ -731,6 +731,10 @@ void ASEImporter::BuildUniqueRepresentation(ASE::Mesh &mesh) {
|
|||
unsigned int iCurrent = 0, fi = 0;
|
||||
for (std::vector<ASE::Face>::iterator i = mesh.mFaces.begin(); i != mesh.mFaces.end(); ++i, ++fi) {
|
||||
for (unsigned int n = 0; n < 3; ++n, ++iCurrent) {
|
||||
const uint32_t curIndex = (*i).mIndices[n];
|
||||
if (curIndex >= mesh.mPositions.size()) {
|
||||
throw DeadlyImportError("ASE: Invalid vertex index in face ", fi, ".");
|
||||
}
|
||||
mPositions[iCurrent] = mesh.mPositions[(*i).mIndices[n]];
|
||||
|
||||
// add texture coordinates
|
||||
|
|
@ -1266,5 +1270,4 @@ bool ASEImporter::GenerateNormals(ASE::Mesh &mesh) {
|
|||
}
|
||||
|
||||
#endif // ASSIMP_BUILD_NO_3DS_IMPORTER
|
||||
|
||||
#endif // !! ASSIMP_BUILD_NO_BASE_IMPORTER
|
||||
#endif // ASSIMP_BUILD_NO_ASE_IMPORTER
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
Open Asset Import Library (assimp)
|
||||
----------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2024, assimp team
|
||||
Copyright (c) 2006-2026, assimp team
|
||||
|
||||
All rights reserved.
|
||||
|
||||
|
|
@ -59,7 +59,7 @@ namespace Assimp {
|
|||
/** Importer class for the 3DS ASE ASCII format.
|
||||
*
|
||||
*/
|
||||
class ASEImporter : public BaseImporter {
|
||||
class ASEImporter final : public BaseImporter {
|
||||
public:
|
||||
ASEImporter();
|
||||
~ASEImporter() override = default;
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
Open Asset Import Library (assimp)
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2024, assimp team
|
||||
Copyright (c) 2006-2026, assimp team
|
||||
|
||||
All rights reserved.
|
||||
|
||||
|
|
@ -1406,10 +1406,13 @@ void Parser::ParseLV4MeshBonesVertices(unsigned int iNumVertices, ASE::Mesh &mes
|
|||
if (TokenMatch(mFilePtr, "MESH_BONE_VERTEX", 16)) {
|
||||
// read the vertex index
|
||||
unsigned int iIndex = strtoul10(mFilePtr, &mFilePtr);
|
||||
if (iIndex >= mesh.mPositions.size()) {
|
||||
iIndex = (unsigned int)mesh.mPositions.size() - 1;
|
||||
if (mesh.mBoneVertices.empty()) {
|
||||
SkipSection();
|
||||
}
|
||||
if (iIndex >= mesh.mBoneVertices.size() ) {
|
||||
LogWarning("Bone vertex index is out of bounds. Using the largest valid "
|
||||
"bone vertex index instead");
|
||||
iIndex = (unsigned int)mesh.mBoneVertices.size() - 1;
|
||||
}
|
||||
|
||||
// --- ignored
|
||||
|
|
@ -1424,7 +1427,7 @@ void Parser::ParseLV4MeshBonesVertices(unsigned int iNumVertices, ASE::Mesh &mes
|
|||
|
||||
// then parse the vertex weight
|
||||
if (!SkipSpaces(&mFilePtr, mEnd)) break;
|
||||
mFilePtr = fast_atoreal_move<float>(mFilePtr, pairOut.second);
|
||||
mFilePtr = fast_atoreal_move(mFilePtr, pairOut.second);
|
||||
|
||||
// -1 marks unused entries
|
||||
if (-1 != pairOut.first) {
|
||||
|
|
@ -1890,7 +1893,7 @@ void Parser::ParseLV4MeshReal(ai_real &fOut) {
|
|||
return;
|
||||
}
|
||||
// parse the first float
|
||||
mFilePtr = fast_atoreal_move<ai_real>(mFilePtr, fOut);
|
||||
mFilePtr = fast_atoreal_move(mFilePtr, fOut);
|
||||
}
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void Parser::ParseLV4MeshFloat(float &fOut) {
|
||||
|
|
@ -1903,7 +1906,7 @@ void Parser::ParseLV4MeshFloat(float &fOut) {
|
|||
return;
|
||||
}
|
||||
// parse the first float
|
||||
mFilePtr = fast_atoreal_move<float>(mFilePtr, fOut);
|
||||
mFilePtr = fast_atoreal_move(mFilePtr, fOut);
|
||||
}
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void Parser::ParseLV4MeshLong(unsigned int &iOut) {
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
Open Asset Import Library (assimp)
|
||||
----------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2024, assimp team
|
||||
Copyright (c) 2006-2026, assimp team
|
||||
|
||||
All rights reserved.
|
||||
|
||||
|
|
@ -57,14 +57,13 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
// ASE is quite similar to 3ds. We can reuse some structures
|
||||
#include "AssetLib/3DS/3DSLoader.h"
|
||||
|
||||
namespace Assimp {
|
||||
namespace ASE {
|
||||
namespace Assimp::ASE {
|
||||
|
||||
using namespace D3DS;
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
/** Helper structure representing an ASE material */
|
||||
struct Material : public D3DS::Material {
|
||||
struct Material final : D3DS::Material {
|
||||
//! Default constructor has been deleted
|
||||
Material() = delete;
|
||||
|
||||
|
|
@ -115,7 +114,7 @@ struct Material : public D3DS::Material {
|
|||
return *this;
|
||||
}
|
||||
|
||||
~Material() = default;
|
||||
~Material() override = default;
|
||||
|
||||
//! Contains all sub materials of this material
|
||||
std::vector<Material> avSubMaterials;
|
||||
|
|
@ -373,8 +372,8 @@ struct Dummy : public BaseNode {
|
|||
};
|
||||
|
||||
// Parameters to Parser::Parse()
|
||||
#define AI_ASE_NEW_FILE_FORMAT 200
|
||||
#define AI_ASE_OLD_FILE_FORMAT 110
|
||||
static constexpr unsigned int AI_ASE_NEW_FILE_FORMAT = 200;
|
||||
static constexpr unsigned int AI_ASE_OLD_FILE_FORMAT = 110;
|
||||
|
||||
// Internally we're a little bit more tolerant
|
||||
#define AI_ASE_IS_NEW_FILE_FORMAT() (iFileFormat >= 200)
|
||||
|
|
@ -668,8 +667,7 @@ public:
|
|||
unsigned int iFileFormat;
|
||||
};
|
||||
|
||||
} // Namespace ASE
|
||||
} // namespace Assimp
|
||||
} // Namespace Assimp::ASE
|
||||
|
||||
#endif // ASSIMP_BUILD_NO_3DS_IMPORTER
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
Open Asset Import Library (assimp)
|
||||
----------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2024, assimp team
|
||||
Copyright (c) 2006-2026, assimp team
|
||||
|
||||
All rights reserved.
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
Open Asset Import Library (assimp)
|
||||
----------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2024, assimp team
|
||||
Copyright (c) 2006-2026, assimp team
|
||||
|
||||
All rights reserved.
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
Open Asset Import Library (assimp)
|
||||
----------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2024, assimp team
|
||||
Copyright (c) 2006-2026, assimp team
|
||||
|
||||
All rights reserved.
|
||||
|
||||
|
|
@ -239,29 +239,7 @@ inline size_t WriteArray(IOStream *stream, const T *in, unsigned int size) {
|
|||
* and the chunk contents to the container stream. This allows relatively easy chunk
|
||||
* chunk construction, even recursively.
|
||||
*/
|
||||
class AssbinChunkWriter : public IOStream {
|
||||
private:
|
||||
uint8_t *buffer;
|
||||
uint32_t magic;
|
||||
IOStream *container;
|
||||
size_t cur_size, cursor, initial;
|
||||
|
||||
private:
|
||||
// -------------------------------------------------------------------
|
||||
void Grow(size_t need = 0) {
|
||||
size_t new_size = std::max(initial, std::max(need, cur_size + (cur_size >> 1)));
|
||||
|
||||
const uint8_t *const old = buffer;
|
||||
buffer = new uint8_t[new_size];
|
||||
|
||||
if (old) {
|
||||
memcpy(buffer, old, cur_size);
|
||||
delete[] old;
|
||||
}
|
||||
|
||||
cur_size = new_size;
|
||||
}
|
||||
|
||||
class AssbinChunkWriter final : public IOStream {
|
||||
public:
|
||||
AssbinChunkWriter(IOStream *container, uint32_t magic, size_t initial = 4096) :
|
||||
buffer(nullptr),
|
||||
|
|
@ -315,6 +293,28 @@ public:
|
|||
|
||||
return pCount;
|
||||
}
|
||||
|
||||
private:
|
||||
// -------------------------------------------------------------------
|
||||
void Grow(size_t need = 0) {
|
||||
size_t new_size = std::max(initial, std::max(need, cur_size + (cur_size >> 1)));
|
||||
|
||||
const uint8_t *const old = buffer;
|
||||
buffer = new uint8_t[new_size];
|
||||
|
||||
if (old) {
|
||||
memcpy(buffer, old, cur_size);
|
||||
delete[] old;
|
||||
}
|
||||
|
||||
cur_size = new_size;
|
||||
}
|
||||
|
||||
private:
|
||||
uint8_t *buffer;
|
||||
uint32_t magic;
|
||||
IOStream *container;
|
||||
size_t cur_size, cursor, initial;
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
Open Asset Import Library (assimp)
|
||||
----------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2024, assimp team
|
||||
Copyright (c) 2006-2026, assimp team
|
||||
|
||||
All rights reserved.
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
Open Asset Import Library (assimp)
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2024, assimp team
|
||||
Copyright (c) 2006-2026, assimp team
|
||||
|
||||
All rights reserved.
|
||||
|
||||
|
|
@ -48,7 +48,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
#ifndef ASSIMP_BUILD_NO_ASSBIN_IMPORTER
|
||||
|
||||
// internal headers
|
||||
#include "AssetLib/Assbin/AssbinLoader.h"
|
||||
#include "AssbinLoader.h"
|
||||
#include "Common/assbin_chunks.h"
|
||||
#include <assimp/MemoryIOWrapper.h>
|
||||
#include <assimp/anim.h>
|
||||
|
|
@ -94,7 +94,7 @@ bool AssbinImporter::CanRead(const std::string &pFile, IOSystem *pIOHandler, boo
|
|||
const size_t read = in->Read(s, sizeof(char), 32);
|
||||
|
||||
pIOHandler->Close(in);
|
||||
|
||||
|
||||
if (read < 19) {
|
||||
return false;
|
||||
}
|
||||
|
|
@ -149,11 +149,18 @@ aiQuaternion Read<aiQuaternion>(IOStream *stream) {
|
|||
template <>
|
||||
aiString Read<aiString>(IOStream *stream) {
|
||||
aiString s;
|
||||
stream->Read(&s.length, 4, 1);
|
||||
if (s.length) {
|
||||
stream->Read(s.data, s.length, 1);
|
||||
uint32_t len;
|
||||
if (stream->Read(&len, 4, 1) != 1) {
|
||||
throw DeadlyImportError("ASSBIN: Unexpected EOF reading string length");
|
||||
}
|
||||
s.data[s.length] = 0;
|
||||
if (len >= AI_MAXLEN) {
|
||||
throw DeadlyImportError("ASSBIN: String length too large, potential buffer overflow attempt");
|
||||
}
|
||||
s.length = len;
|
||||
if ((s.length > 0) && (stream->Read(s.data, s.length, 1) != 1)) {
|
||||
throw DeadlyImportError("ASSBIN: Unexpected EOF reading string data");
|
||||
}
|
||||
s.data[s.length] = '\0';
|
||||
|
||||
return s;
|
||||
}
|
||||
|
|
@ -688,6 +695,7 @@ void AssbinImporter::InternReadFile(const std::string &pFile, aiScene *pScene, I
|
|||
unsigned int versionMajor = Read<unsigned int>(stream);
|
||||
unsigned int versionMinor = Read<unsigned int>(stream);
|
||||
if (versionMinor != ASSBIN_VERSION_MINOR || versionMajor != ASSBIN_VERSION_MAJOR) {
|
||||
pIOHandler->Close(stream);
|
||||
throw DeadlyImportError("Invalid version, data format not compatible!");
|
||||
}
|
||||
|
||||
|
|
@ -697,8 +705,10 @@ void AssbinImporter::InternReadFile(const std::string &pFile, aiScene *pScene, I
|
|||
shortened = Read<uint16_t>(stream) > 0;
|
||||
compressed = Read<uint16_t>(stream) > 0;
|
||||
|
||||
if (shortened)
|
||||
if (shortened) {
|
||||
pIOHandler->Close(stream);
|
||||
throw DeadlyImportError("Shortened binaries are not supported!");
|
||||
}
|
||||
|
||||
stream->Seek(256, aiOrigin_CUR); // original filename
|
||||
stream->Seek(128, aiOrigin_CUR); // options
|
||||
|
|
|
|||
|
|
@ -1,9 +1,8 @@
|
|||
|
||||
/*
|
||||
Open Asset Import Library (assimp)
|
||||
----------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2024, assimp team
|
||||
Copyright (c) 2006-2026, assimp team
|
||||
|
||||
All rights reserved.
|
||||
|
||||
|
|
@ -61,7 +60,7 @@ struct aiCamera;
|
|||
|
||||
#ifndef ASSIMP_BUILD_NO_ASSBIN_IMPORTER
|
||||
|
||||
namespace Assimp {
|
||||
namespace Assimp {
|
||||
|
||||
// ---------------------------------------------------------------------------------
|
||||
/** Importer class for 3D Studio r3 and r4 3DS files
|
||||
|
|
|
|||
|
|
@ -2,8 +2,7 @@
|
|||
Open Asset Import Library (assimp)
|
||||
----------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2024, assimp team
|
||||
|
||||
Copyright (c) 2006-2026, assimp team
|
||||
|
||||
All rights reserved.
|
||||
|
||||
|
|
@ -50,7 +49,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
#include <assimp/IOSystem.hpp>
|
||||
#include <assimp/Exporter.hpp>
|
||||
|
||||
namespace Assimp {
|
||||
namespace Assimp {
|
||||
|
||||
void ExportSceneAssxml(const char* pFile, IOSystem* pIOSystem, const aiScene* pScene, const ExportProperties* /*pProperties*/)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -2,8 +2,7 @@
|
|||
Open Asset Import Library (assimp)
|
||||
----------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2024, assimp team
|
||||
|
||||
Copyright (c) 2006-2026, assimp team
|
||||
|
||||
All rights reserved.
|
||||
|
||||
|
|
|
|||
|
|
@ -2,8 +2,7 @@
|
|||
Open Asset Import Library (assimp)
|
||||
----------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2024, assimp team
|
||||
|
||||
Copyright (c) 2006-2026, assimp team
|
||||
|
||||
All rights reserved.
|
||||
|
||||
|
|
@ -36,7 +35,6 @@ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
----------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
|
|
@ -79,8 +77,7 @@ static int ioprintf(IOStream *io, const char *format, ...) {
|
|||
}
|
||||
|
||||
static const int Size = 4096;
|
||||
char sz[Size];
|
||||
::memset(sz, '\0', Size);
|
||||
char sz[Size] = {};
|
||||
va_list va;
|
||||
va_start(va, format);
|
||||
const unsigned int nSize = vsnprintf(sz, Size - 1, format, va);
|
||||
|
|
@ -223,7 +220,7 @@ static void WriteDump(const char *pFile, const char *cmd, const aiScene *scene,
|
|||
const unsigned int majorVersion(aiGetVersionMajor());
|
||||
const unsigned int minorVersion(aiGetVersionMinor());
|
||||
const unsigned int rev(aiGetVersionRevision());
|
||||
const char *curtime(asctime(p));
|
||||
const char *curtime = asctime(p);
|
||||
ioprintf(io, header.c_str(), majorVersion, minorVersion, rev, pFile, c.c_str(), curtime, scene->mFlags, 0u);
|
||||
|
||||
// write the node graph
|
||||
|
|
@ -304,7 +301,11 @@ static void WriteDump(const char *pFile, const char *cmd, const aiScene *scene,
|
|||
bool compressed = (tex->mHeight == 0);
|
||||
|
||||
// mesh header
|
||||
ioprintf(io, "\t<Texture width=\"%u\" height=\"%u\" compressed=\"%s\"> \n",
|
||||
std::string texName = "unknown";
|
||||
if (tex->mFilename.length != 0u) {
|
||||
texName = tex->mFilename.data;
|
||||
}
|
||||
ioprintf(io, "\t<Texture name=\"%s\" width=\"%u\" height=\"%u\" compressed=\"%s\"> \n", texName.c_str(),
|
||||
(compressed ? -1 : tex->mWidth), (compressed ? -1 : tex->mHeight),
|
||||
(compressed ? "true" : "false"));
|
||||
|
||||
|
|
@ -352,7 +353,7 @@ static void WriteDump(const char *pFile, const char *cmd, const aiScene *scene,
|
|||
for (unsigned int n = 0; n < mat->mNumProperties; ++n) {
|
||||
|
||||
const aiMaterialProperty *prop = mat->mProperties[n];
|
||||
const char *sz = "";
|
||||
auto sz = "";
|
||||
if (prop->mType == aiPTI_Float) {
|
||||
sz = "float";
|
||||
} else if (prop->mType == aiPTI_Integer) {
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
Open Asset Import Library (assimp)
|
||||
----------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2024, assimp team
|
||||
Copyright (c) 2006-2026, assimp team
|
||||
|
||||
All rights reserved.
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
Open Asset Import Library (assimp)
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2024, assimp team
|
||||
Copyright (c) 2006-2026, assimp team
|
||||
|
||||
All rights reserved.
|
||||
|
||||
|
|
@ -46,7 +46,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
#ifndef ASSIMP_BUILD_NO_B3D_IMPORTER
|
||||
|
||||
// internal headers
|
||||
#include "AssetLib/B3D/B3DImporter.h"
|
||||
#include "B3DImporter.h"
|
||||
#include "PostProcessing/ConvertToLHProcess.h"
|
||||
#include "PostProcessing/TextureTransform.h"
|
||||
|
||||
|
|
@ -469,9 +469,11 @@ void B3DImporter::ReadBONE(int id) {
|
|||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void B3DImporter::ReadKEYS(aiNodeAnim *nodeAnim) {
|
||||
vector<aiVectorKey> trans, scale;
|
||||
vector<aiQuatKey> rot;
|
||||
void B3DImporter::ReadKEYS(AnimKeys& keys) {
|
||||
vector<aiVectorKey>& trans = keys.positionKeys;
|
||||
vector<aiVectorKey>& scale = keys.scalingKeys;
|
||||
vector<aiQuatKey>& rot = keys.rotationKeys;
|
||||
|
||||
int flags = ReadInt();
|
||||
while (ChunkSize()) {
|
||||
int frame = ReadInt();
|
||||
|
|
@ -485,21 +487,6 @@ void B3DImporter::ReadKEYS(aiNodeAnim *nodeAnim) {
|
|||
rot.emplace_back(frame, ReadQuat());
|
||||
}
|
||||
}
|
||||
|
||||
if (flags & 1) {
|
||||
nodeAnim->mNumPositionKeys = static_cast<unsigned int>(trans.size());
|
||||
nodeAnim->mPositionKeys = to_array(trans);
|
||||
}
|
||||
|
||||
if (flags & 2) {
|
||||
nodeAnim->mNumScalingKeys = static_cast<unsigned int>(scale.size());
|
||||
nodeAnim->mScalingKeys = to_array(scale);
|
||||
}
|
||||
|
||||
if (flags & 4) {
|
||||
nodeAnim->mNumRotationKeys = static_cast<unsigned int>(rot.size());
|
||||
nodeAnim->mRotationKeys = to_array(rot);
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
|
@ -542,6 +529,7 @@ aiNode *B3DImporter::ReadNODE(aiNode *parent) {
|
|||
std::unique_ptr<aiNodeAnim> nodeAnim;
|
||||
vector<unsigned> meshes;
|
||||
vector<aiNode *> children;
|
||||
AnimKeys keys;
|
||||
|
||||
while (ChunkSize()) {
|
||||
const string chunk = ReadChunk();
|
||||
|
|
@ -560,7 +548,7 @@ aiNode *B3DImporter::ReadNODE(aiNode *parent) {
|
|||
nodeAnim.reset(new aiNodeAnim);
|
||||
nodeAnim->mNodeName = node->mName;
|
||||
}
|
||||
ReadKEYS(nodeAnim.get());
|
||||
ReadKEYS(keys);
|
||||
} else if (chunk == "NODE") {
|
||||
aiNode *child = ReadNODE(node);
|
||||
children.push_back(child);
|
||||
|
|
@ -569,6 +557,21 @@ aiNode *B3DImporter::ReadNODE(aiNode *parent) {
|
|||
}
|
||||
|
||||
if (nodeAnim) {
|
||||
if (!keys.positionKeys.empty()) {
|
||||
nodeAnim->mNumPositionKeys = static_cast<unsigned int>(keys.positionKeys.size());
|
||||
nodeAnim->mPositionKeys = to_array(keys.positionKeys);
|
||||
}
|
||||
|
||||
if (!keys.scalingKeys.empty()) {
|
||||
nodeAnim->mNumScalingKeys = static_cast<unsigned int>(keys.scalingKeys.size());
|
||||
nodeAnim->mScalingKeys = to_array(keys.scalingKeys);
|
||||
}
|
||||
|
||||
if (!keys.rotationKeys.empty()) {
|
||||
nodeAnim->mNumRotationKeys = static_cast<unsigned int>(keys.rotationKeys.size());
|
||||
nodeAnim->mRotationKeys = to_array(keys.rotationKeys);
|
||||
}
|
||||
|
||||
_nodeAnims.emplace_back(std::move(nodeAnim));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
Open Asset Import Library (assimp)
|
||||
----------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2024, assimp team
|
||||
Copyright (c) 2006-2026, assimp team
|
||||
|
||||
All rights reserved.
|
||||
|
||||
|
|
@ -49,6 +49,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
#include <assimp/types.h>
|
||||
#include <assimp/mesh.h>
|
||||
#include <assimp/material.h>
|
||||
#include <assimp/anim.h>
|
||||
#include <assimp/BaseImporter.h>
|
||||
|
||||
#include <memory>
|
||||
|
|
@ -60,7 +61,7 @@ struct aiAnimation;
|
|||
|
||||
namespace Assimp{
|
||||
|
||||
class B3DImporter : public BaseImporter{
|
||||
class B3DImporter final : public BaseImporter{
|
||||
public:
|
||||
B3DImporter() = default;
|
||||
~B3DImporter() override;
|
||||
|
|
@ -94,6 +95,12 @@ private:
|
|||
float weights[4];
|
||||
};
|
||||
|
||||
struct AnimKeys {
|
||||
std::vector<aiVectorKey> positionKeys;
|
||||
std::vector<aiVectorKey> scalingKeys;
|
||||
std::vector<aiQuatKey> rotationKeys;
|
||||
};
|
||||
|
||||
AI_WONT_RETURN void Oops() AI_WONT_RETURN_SUFFIX;
|
||||
AI_WONT_RETURN void Fail(const std::string &str) AI_WONT_RETURN_SUFFIX;
|
||||
|
||||
|
|
@ -104,7 +111,7 @@ private:
|
|||
void ReadTRIS( int v0 );
|
||||
void ReadMESH();
|
||||
void ReadBONE( int id );
|
||||
void ReadKEYS( aiNodeAnim *nodeAnim );
|
||||
void ReadKEYS( AnimKeys& keys );
|
||||
void ReadANIM();
|
||||
|
||||
aiNode *ReadNODE( aiNode *parent );
|
||||
|
|
|
|||
|
|
@ -4,9 +4,7 @@
|
|||
Open Asset Import Library (assimp)
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2024, assimp team
|
||||
|
||||
|
||||
Copyright (c) 2006-2026, assimp team
|
||||
|
||||
All rights reserved.
|
||||
|
||||
|
|
@ -85,11 +83,9 @@ BVHLoader::BVHLoader() :
|
|||
mLine(),
|
||||
mAnimTickDuration(),
|
||||
mAnimNumFrames(),
|
||||
noSkeletonMesh() {}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Destructor, private as well
|
||||
BVHLoader::~BVHLoader() = default;
|
||||
noSkeletonMesh() {
|
||||
// empty
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Returns whether the class can handle the format of the given file.
|
||||
|
|
@ -389,7 +385,7 @@ float BVHLoader::GetNextTokenAsFloat() {
|
|||
// check if the float is valid by testing if the atof() function consumed every char of the token
|
||||
const char *ctoken = token.c_str();
|
||||
float result = 0.0f;
|
||||
ctoken = fast_atoreal_move<float>(ctoken, result);
|
||||
ctoken = fast_atoreal_move(ctoken, result);
|
||||
|
||||
if (ctoken != token.c_str() + token.length())
|
||||
ThrowException("Expected a floating point number, but found \"", token, "\".");
|
||||
|
|
|
|||
|
|
@ -4,8 +4,7 @@
|
|||
Open Asset Import Library (assimp)
|
||||
----------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2024, assimp team
|
||||
|
||||
Copyright (c) 2006-2026, assimp team
|
||||
|
||||
All rights reserved.
|
||||
|
||||
|
|
@ -62,7 +61,7 @@ namespace Assimp {
|
|||
* the hierarchy. It contains no actual mesh data, but we generate a dummy mesh
|
||||
* inside the loader just to be able to see something.
|
||||
*/
|
||||
class BVHLoader : public BaseImporter {
|
||||
class BVHLoader final : public BaseImporter {
|
||||
|
||||
/** Possible animation channels for which the motion data holds the values */
|
||||
enum ChannelType {
|
||||
|
|
@ -80,32 +79,27 @@ class BVHLoader : public BaseImporter {
|
|||
std::vector<ChannelType> mChannels;
|
||||
std::vector<float> mChannelValues; // motion data values for that node. Of size NumChannels * NumFrames
|
||||
|
||||
Node() :
|
||||
mNode(nullptr) {}
|
||||
|
||||
explicit Node(const aiNode *pNode) :
|
||||
mNode(pNode) {}
|
||||
Node() : mNode(nullptr) {}
|
||||
explicit Node(const aiNode *pNode) :mNode(pNode) {}
|
||||
};
|
||||
|
||||
public:
|
||||
BVHLoader();
|
||||
~BVHLoader();
|
||||
~BVHLoader() override = default;
|
||||
|
||||
public:
|
||||
/** Returns whether the class can handle the format of the given file.
|
||||
* See BaseImporter::CanRead() for details. */
|
||||
bool CanRead(const std::string &pFile, IOSystem *pIOHandler, bool cs) const;
|
||||
bool CanRead(const std::string &pFile, IOSystem *pIOHandler, bool cs) const override;
|
||||
|
||||
void SetupProperties(const Importer *pImp);
|
||||
const aiImporterDesc *GetInfo() const;
|
||||
void SetupProperties(const Importer *pImp) override;
|
||||
const aiImporterDesc *GetInfo() const override;
|
||||
|
||||
protected:
|
||||
/** Imports the given file into the given scene structure.
|
||||
* See BaseImporter::InternReadFile() for details
|
||||
*/
|
||||
void InternReadFile(const std::string &pFile, aiScene *pScene, IOSystem *pIOHandler);
|
||||
void InternReadFile(const std::string &pFile, aiScene *pScene, IOSystem *pIOHandler) override;
|
||||
|
||||
protected:
|
||||
/** Reads the file */
|
||||
void ReadStructure(aiScene *pScene);
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
Open Asset Import Library (assimp)
|
||||
----------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2024, assimp team
|
||||
Copyright (c) 2006-2026, assimp team
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use of this software in source and binary forms,
|
||||
|
|
@ -74,7 +74,9 @@ BlenderBMeshConverter::~BlenderBMeshConverter() {
|
|||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
bool BlenderBMeshConverter::ContainsBMesh() const {
|
||||
// TODO - Should probably do some additional verification here
|
||||
if (BMesh == nullptr) {
|
||||
return false;
|
||||
}
|
||||
return BMesh->totpoly && BMesh->totloop && BMesh->totvert;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
Open Asset Import Library (assimp)
|
||||
----------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2024, assimp team
|
||||
Copyright (c) 2006-2026, assimp team
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use of this software in source and binary forms,
|
||||
|
|
@ -63,14 +63,12 @@ namespace Assimp
|
|||
struct MLoop;
|
||||
}
|
||||
|
||||
class BlenderBMeshConverter: public LogFunctions< BlenderBMeshConverter >
|
||||
class BlenderBMeshConverter final : public LogFunctions< BlenderBMeshConverter >
|
||||
{
|
||||
public:
|
||||
BlenderBMeshConverter( const Blender::Mesh* mesh );
|
||||
~BlenderBMeshConverter( );
|
||||
|
||||
bool ContainsBMesh( ) const;
|
||||
|
||||
explicit BlenderBMeshConverter( const Blender::Mesh* mesh );
|
||||
~BlenderBMeshConverter();
|
||||
bool ContainsBMesh() const;
|
||||
const Blender::Mesh* TriangulateBMesh( );
|
||||
|
||||
private:
|
||||
|
|
|
|||
|
|
@ -96,7 +96,7 @@ struct CustomDataTypeDescription {
|
|||
* other (like CD_ORCO, ...) uses arrays of rawtypes or even arrays of Structures
|
||||
* use a special readfunction for that cases
|
||||
*/
|
||||
static std::array<CustomDataTypeDescription, CD_NUMTYPES> customDataTypeDescriptions = { {
|
||||
static const std::array<CustomDataTypeDescription, CD_NUMTYPES> customDataTypeDescriptions = { {
|
||||
DECL_STRUCT_CUSTOMDATATYPEDESCRIPTION(MVert),
|
||||
DECL_UNSUPPORTED_CUSTOMDATATYPEDESCRIPTION,
|
||||
DECL_UNSUPPORTED_CUSTOMDATATYPEDESCRIPTION,
|
||||
|
|
@ -142,7 +142,8 @@ static std::array<CustomDataTypeDescription, CD_NUMTYPES> customDataTypeDescript
|
|||
DECL_UNSUPPORTED_CUSTOMDATATYPEDESCRIPTION,
|
||||
|
||||
DECL_UNSUPPORTED_CUSTOMDATATYPEDESCRIPTION,
|
||||
DECL_UNSUPPORTED_CUSTOMDATATYPEDESCRIPTION } };
|
||||
DECL_UNSUPPORTED_CUSTOMDATATYPEDESCRIPTION
|
||||
} };
|
||||
|
||||
bool isValidCustomDataType(const int cdtype) {
|
||||
return cdtype >= 0 && cdtype < CD_NUMTYPES;
|
||||
|
|
|
|||
|
|
@ -2,8 +2,7 @@
|
|||
Open Asset Import Library (assimp)
|
||||
----------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2024, assimp team
|
||||
|
||||
Copyright (c) 2006-2026, assimp team
|
||||
|
||||
All rights reserved.
|
||||
|
||||
|
|
|
|||
|
|
@ -2,8 +2,7 @@
|
|||
Open Asset Import Library (assimp)
|
||||
----------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2024, assimp team
|
||||
|
||||
Copyright (c) 2006-2026, assimp team
|
||||
|
||||
All rights reserved.
|
||||
|
||||
|
|
@ -56,14 +55,14 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
|
||||
// enable verbose log output. really verbose, so be careful.
|
||||
#ifdef ASSIMP_BUILD_DEBUG
|
||||
#define ASSIMP_BUILD_BLENDER_DEBUG
|
||||
# define ASSIMP_BUILD_BLENDER_DEBUG
|
||||
#endif
|
||||
|
||||
// set this to non-zero to dump BlenderDNA stuff to dna.txt.
|
||||
// you could set it on the assimp build command line too without touching it here.
|
||||
// !!! please make sure this is set to 0 in the repo !!!
|
||||
#ifndef ASSIMP_BUILD_BLENDER_DEBUG_DNA
|
||||
#define ASSIMP_BUILD_BLENDER_DEBUG_DNA 0
|
||||
# define ASSIMP_BUILD_BLENDER_DEBUG_DNA 0
|
||||
#endif
|
||||
|
||||
// #define ASSIMP_BUILD_BLENDER_NO_STATS
|
||||
|
|
@ -125,22 +124,14 @@ struct ElemBase {
|
|||
* they used to point to.*/
|
||||
// -------------------------------------------------------------------------------
|
||||
struct Pointer {
|
||||
Pointer() :
|
||||
val() {
|
||||
// empty
|
||||
}
|
||||
uint64_t val;
|
||||
uint64_t val{0};
|
||||
};
|
||||
|
||||
// -------------------------------------------------------------------------------
|
||||
/** Represents a generic offset within a BLEND file */
|
||||
// -------------------------------------------------------------------------------
|
||||
struct FileOffset {
|
||||
FileOffset() :
|
||||
val() {
|
||||
// empty
|
||||
}
|
||||
uint64_t val;
|
||||
uint64_t val{0};
|
||||
};
|
||||
|
||||
// -------------------------------------------------------------------------------
|
||||
|
|
@ -205,7 +196,7 @@ enum ErrorPolicy {
|
|||
};
|
||||
|
||||
#ifdef ASSIMP_BUILD_BLENDER_DEBUG
|
||||
#define ErrorPolicy_Igno ErrorPolicy_Warn
|
||||
# define ErrorPolicy_Igno ErrorPolicy_Warn
|
||||
#endif
|
||||
|
||||
// -------------------------------------------------------------------------------
|
||||
|
|
@ -397,10 +388,9 @@ private:
|
|||
mutable size_t cache_idx;
|
||||
};
|
||||
|
||||
// --------------------------------------------------------
|
||||
template <>
|
||||
// -------------------------------------------------------------------------------------------------------
|
||||
template<>
|
||||
struct Structure::_defaultInitializer<ErrorPolicy_Warn> {
|
||||
|
||||
template <typename T>
|
||||
void operator()(T &out, const char *reason = "<add reason>") {
|
||||
ASSIMP_LOG_WARN(reason);
|
||||
|
|
@ -410,9 +400,9 @@ struct Structure::_defaultInitializer<ErrorPolicy_Warn> {
|
|||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
// -------------------------------------------------------------------------------------------------------
|
||||
template<>
|
||||
struct Structure::_defaultInitializer<ErrorPolicy_Fail> {
|
||||
|
||||
template <typename T>
|
||||
void operator()(T & /*out*/, const char *message = "") {
|
||||
// obviously, it is crucial that _DefaultInitializer is used
|
||||
|
|
@ -620,31 +610,23 @@ public:
|
|||
/** Import statistics, i.e. number of file blocks read*/
|
||||
// -------------------------------------------------------------------------------
|
||||
class Statistics {
|
||||
|
||||
public:
|
||||
Statistics() :
|
||||
fields_read(), pointers_resolved(), cache_hits()
|
||||
// , blocks_read ()
|
||||
,
|
||||
cached_objects() {}
|
||||
Statistics() = default;
|
||||
~Statistics() = default;
|
||||
|
||||
public:
|
||||
/** total number of fields we read */
|
||||
/// total number of fields we read
|
||||
unsigned int fields_read;
|
||||
|
||||
/** total number of resolved pointers */
|
||||
/// total number of resolved pointers
|
||||
unsigned int pointers_resolved;
|
||||
|
||||
/** number of pointers resolved from the cache */
|
||||
/// number of pointers resolved from the cache
|
||||
unsigned int cache_hits;
|
||||
|
||||
/** number of blocks (from FileDatabase::entries)
|
||||
we did actually read from. */
|
||||
// unsigned int blocks_read;
|
||||
|
||||
/** objects in FileData::cache */
|
||||
/// objects in FileData::cache
|
||||
unsigned int cached_objects;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
// -------------------------------------------------------------------------------
|
||||
|
|
@ -657,15 +639,13 @@ public:
|
|||
typedef std::map<Pointer, TOUT<ElemBase>> StructureCache;
|
||||
|
||||
public:
|
||||
ObjectCache(const FileDatabase &db) :
|
||||
db(db) {
|
||||
explicit ObjectCache(const FileDatabase &db) : db(db) {
|
||||
// currently there are only ~400 structure records per blend file.
|
||||
// we read only a small part of them and don't cache objects
|
||||
// which we don't need, so this should suffice.
|
||||
caches.reserve(64);
|
||||
}
|
||||
|
||||
public:
|
||||
// --------------------------------------------------------
|
||||
/** Check whether a specific item is in the cache.
|
||||
* @param s Data type of the item
|
||||
|
|
@ -673,10 +653,7 @@ public:
|
|||
* cache doesn't know the item yet.
|
||||
* @param ptr Item address to look for. */
|
||||
template <typename T>
|
||||
void get(
|
||||
const Structure &s,
|
||||
TOUT<T> &out,
|
||||
const Pointer &ptr) const;
|
||||
void get( const Structure &s,TOUT<T> &out, const Pointer &ptr) const;
|
||||
|
||||
// --------------------------------------------------------
|
||||
/** Add an item to the cache after the item has
|
||||
|
|
@ -701,7 +678,7 @@ private:
|
|||
template <>
|
||||
class ObjectCache<Blender::vector> {
|
||||
public:
|
||||
ObjectCache(const FileDatabase &) {}
|
||||
explicit ObjectCache(const FileDatabase &) {}
|
||||
|
||||
template <typename T>
|
||||
void get(const Structure &, vector<T> &, const Pointer &) {}
|
||||
|
|
@ -710,7 +687,7 @@ public:
|
|||
};
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(disable : 4355)
|
||||
# pragma warning(disable : 4355)
|
||||
#endif
|
||||
|
||||
// -------------------------------------------------------------------------------
|
||||
|
|
@ -725,16 +702,6 @@ public:
|
|||
FileDatabase() :
|
||||
_cacheArrays(*this), _cache(*this), next_cache_idx() {}
|
||||
|
||||
public:
|
||||
// publicly accessible fields
|
||||
bool i64bit;
|
||||
bool little;
|
||||
|
||||
DNA dna;
|
||||
std::shared_ptr<StreamReaderAny> reader;
|
||||
vector<FileBlockHead> entries;
|
||||
|
||||
public:
|
||||
Statistics &stats() const {
|
||||
return _stats;
|
||||
}
|
||||
|
|
@ -753,6 +720,15 @@ public:
|
|||
return _cacheArrays;
|
||||
}
|
||||
|
||||
public:
|
||||
// publicly accessible fields
|
||||
bool i64bit;
|
||||
bool little;
|
||||
|
||||
DNA dna;
|
||||
std::shared_ptr<StreamReaderAny> reader;
|
||||
vector<FileBlockHead> entries;
|
||||
|
||||
private:
|
||||
#ifndef ASSIMP_BUILD_BLENDER_NO_STATS
|
||||
mutable Statistics _stats;
|
||||
|
|
@ -765,20 +741,19 @@ private:
|
|||
};
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(default : 4355)
|
||||
# pragma warning(default : 4355)
|
||||
#endif
|
||||
|
||||
// -------------------------------------------------------------------------------
|
||||
/** Factory to extract a #DNA from the DNA1 file block in a BLEND file. */
|
||||
// -------------------------------------------------------------------------------
|
||||
class DNAParser {
|
||||
|
||||
public:
|
||||
/** Bind the parser to a empty DNA and an input stream */
|
||||
DNAParser(FileDatabase &db) :
|
||||
db(db) {}
|
||||
explicit DNAParser(FileDatabase &db) : db(db) {
|
||||
// empty
|
||||
}
|
||||
|
||||
public:
|
||||
// --------------------------------------------------------
|
||||
/** Locate the DNA in the file and parse it. The input
|
||||
* stream is expected to point to the beginning of the DN1
|
||||
|
|
@ -789,7 +764,6 @@ public:
|
|||
* afterwards.*/
|
||||
void Parse();
|
||||
|
||||
public:
|
||||
/** Obtain a reference to the extracted DNA information */
|
||||
const Blender::DNA &GetDNA() const {
|
||||
return db.dna;
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
Open Asset Import Library (assimp)
|
||||
----------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2024, assimp team
|
||||
Copyright (c) 2006-2026, assimp team
|
||||
|
||||
All rights reserved.
|
||||
|
||||
|
|
@ -841,5 +841,7 @@ template <template <typename> class TOUT> template <typename T> void ObjectCache
|
|||
#endif
|
||||
}
|
||||
|
||||
}}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -2,8 +2,7 @@
|
|||
Open Asset Import Library (assimp)
|
||||
----------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2024, assimp team
|
||||
|
||||
Copyright (c) 2006-2026, assimp team
|
||||
|
||||
All rights reserved.
|
||||
|
||||
|
|
@ -117,7 +116,7 @@ namespace Blender {
|
|||
mywrap arr;
|
||||
};
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#if defined(_MSC_VER) && _MSC_VER < 1900
|
||||
# pragma warning(disable:4351)
|
||||
#endif
|
||||
|
||||
|
|
@ -172,7 +171,7 @@ namespace Blender {
|
|||
// original file data
|
||||
const FileDatabase& db;
|
||||
};
|
||||
#ifdef _MSC_VER
|
||||
#if defined(_MSC_VER) && _MSC_VER < 1900
|
||||
# pragma warning(default:4351)
|
||||
#endif
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
Open Asset Import Library (assimp)
|
||||
----------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2024, assimp team
|
||||
Copyright (c) 2006-2026, assimp team
|
||||
|
||||
All rights reserved.
|
||||
|
||||
|
|
@ -108,7 +108,7 @@ BlenderImporter::~BlenderImporter() {
|
|||
delete modifier_cache;
|
||||
}
|
||||
|
||||
static const char Token[] = "BLENDER";
|
||||
static constexpr char Token[] = "BLENDER";
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Returns whether the class can handle the format of the given file.
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
Open Asset Import Library (assimp)
|
||||
----------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2024, assimp team
|
||||
Copyright (c) 2006-2026, assimp team
|
||||
|
||||
All rights reserved.
|
||||
|
||||
|
|
@ -105,7 +105,7 @@ class BlenderModifier;
|
|||
* call it is outsourced to BlenderDNA.cpp/BlenderDNA.h. This class only performs the
|
||||
* conversion from intermediate format to aiScene. */
|
||||
// -------------------------------------------------------------------------------------------
|
||||
class BlenderImporter : public BaseImporter, public LogFunctions<BlenderImporter> {
|
||||
class BlenderImporter final : public BaseImporter, public LogFunctions<BlenderImporter> {
|
||||
public:
|
||||
BlenderImporter();
|
||||
~BlenderImporter() override;
|
||||
|
|
|
|||
|
|
@ -2,8 +2,7 @@
|
|||
Open Asset Import Library (assimp)
|
||||
----------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2024, assimp team
|
||||
|
||||
Copyright (c) 2006-2026, assimp team
|
||||
|
||||
All rights reserved.
|
||||
|
||||
|
|
|
|||
|
|
@ -2,8 +2,7 @@
|
|||
Open Asset Import Library (assimp)
|
||||
----------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2024, assimp team
|
||||
|
||||
Copyright (c) 2006-2026, assimp team
|
||||
|
||||
All rights reserved.
|
||||
|
||||
|
|
@ -115,7 +114,7 @@ private:
|
|||
* Mirror modifier. Status: implemented.
|
||||
*/
|
||||
// -------------------------------------------------------------------------------------------
|
||||
class BlenderModifier_Mirror : public BlenderModifier {
|
||||
class BlenderModifier_Mirror final : public BlenderModifier {
|
||||
public:
|
||||
// --------------------
|
||||
virtual bool IsActive( const ModifierData& modin);
|
||||
|
|
@ -132,7 +131,7 @@ public:
|
|||
// -------------------------------------------------------------------------------------------
|
||||
/** Subdivision modifier. Status: dummy. */
|
||||
// -------------------------------------------------------------------------------------------
|
||||
class BlenderModifier_Subdivision : public BlenderModifier {
|
||||
class BlenderModifier_Subdivision final : public BlenderModifier {
|
||||
public:
|
||||
|
||||
// --------------------
|
||||
|
|
|
|||
|
|
@ -2,8 +2,7 @@
|
|||
Open Asset Import Library (assimp)
|
||||
----------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2024, assimp team
|
||||
|
||||
Copyright (c) 2006-2026, assimp team
|
||||
|
||||
All rights reserved.
|
||||
|
||||
|
|
@ -48,8 +47,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
|
||||
#include "BlenderDNA.h"
|
||||
|
||||
namespace Assimp {
|
||||
namespace Blender {
|
||||
namespace Assimp::Blender {
|
||||
|
||||
// Minor parts of this file are extracts from blender data structures,
|
||||
// declared in the ./source/blender/makesdna directory.
|
||||
|
|
@ -116,32 +114,32 @@ struct Collection;
|
|||
static const size_t MaxNameLen = 1024;
|
||||
|
||||
// -------------------------------------------------------------------------------
|
||||
struct ID : ElemBase {
|
||||
struct ID final : ElemBase {
|
||||
char name[MaxNameLen] WARN;
|
||||
short flag;
|
||||
};
|
||||
|
||||
// -------------------------------------------------------------------------------
|
||||
struct ListBase : ElemBase {
|
||||
struct ListBase final : ElemBase {
|
||||
std::shared_ptr<ElemBase> first;
|
||||
std::weak_ptr<ElemBase> last;
|
||||
};
|
||||
|
||||
// -------------------------------------------------------------------------------
|
||||
struct PackedFile : ElemBase {
|
||||
struct PackedFile final : ElemBase {
|
||||
int size WARN;
|
||||
int seek WARN;
|
||||
std::shared_ptr<FileOffset> data WARN;
|
||||
};
|
||||
|
||||
// -------------------------------------------------------------------------------
|
||||
struct GroupObject : ElemBase {
|
||||
struct GroupObject final : ElemBase {
|
||||
std::shared_ptr<GroupObject> prev, next FAIL;
|
||||
std::shared_ptr<Object> ob;
|
||||
};
|
||||
|
||||
// -------------------------------------------------------------------------------
|
||||
struct Group : ElemBase {
|
||||
struct Group final : ElemBase {
|
||||
ID id FAIL;
|
||||
int layer;
|
||||
|
||||
|
|
@ -149,32 +147,32 @@ struct Group : ElemBase {
|
|||
};
|
||||
|
||||
// -------------------------------------------------------------------------------
|
||||
struct CollectionObject : ElemBase {
|
||||
struct CollectionObject final : ElemBase {
|
||||
//CollectionObject* prev;
|
||||
std::shared_ptr<CollectionObject> next;
|
||||
Object *ob;
|
||||
};
|
||||
|
||||
// -------------------------------------------------------------------------------
|
||||
struct CollectionChild : ElemBase {
|
||||
struct CollectionChild final : ElemBase {
|
||||
std::shared_ptr<CollectionChild> next, prev;
|
||||
std::shared_ptr<Collection> collection;
|
||||
};
|
||||
|
||||
// -------------------------------------------------------------------------------
|
||||
struct Collection : ElemBase {
|
||||
struct Collection final : ElemBase {
|
||||
ID id FAIL;
|
||||
ListBase gobject; // CollectionObject
|
||||
ListBase children; // CollectionChild
|
||||
};
|
||||
|
||||
// -------------------------------------------------------------------------------
|
||||
struct World : ElemBase {
|
||||
struct World final : ElemBase {
|
||||
ID id FAIL;
|
||||
};
|
||||
|
||||
// -------------------------------------------------------------------------------
|
||||
struct MVert : ElemBase {
|
||||
struct MVert final : ElemBase {
|
||||
float co[3] FAIL;
|
||||
float no[3] FAIL; // read as short and divided through / 32767.f
|
||||
char flag;
|
||||
|
|
@ -186,31 +184,31 @@ struct MVert : ElemBase {
|
|||
};
|
||||
|
||||
// -------------------------------------------------------------------------------
|
||||
struct MEdge : ElemBase {
|
||||
struct MEdge final : ElemBase {
|
||||
int v1, v2 FAIL;
|
||||
char crease, bweight;
|
||||
short flag;
|
||||
};
|
||||
|
||||
// -------------------------------------------------------------------------------
|
||||
struct MLoop : ElemBase {
|
||||
struct MLoop final : ElemBase {
|
||||
int v, e;
|
||||
};
|
||||
|
||||
// -------------------------------------------------------------------------------
|
||||
struct MLoopUV : ElemBase {
|
||||
struct MLoopUV final : ElemBase {
|
||||
float uv[2];
|
||||
int flag;
|
||||
};
|
||||
|
||||
// -------------------------------------------------------------------------------
|
||||
// Note that red and blue are not swapped, as with MCol
|
||||
struct MLoopCol : ElemBase {
|
||||
struct MLoopCol final : ElemBase {
|
||||
unsigned char r, g, b, a;
|
||||
};
|
||||
|
||||
// -------------------------------------------------------------------------------
|
||||
struct MPoly : ElemBase {
|
||||
struct MPoly final : ElemBase {
|
||||
int loopstart;
|
||||
int totloop;
|
||||
short mat_nr;
|
||||
|
|
@ -218,26 +216,26 @@ struct MPoly : ElemBase {
|
|||
};
|
||||
|
||||
// -------------------------------------------------------------------------------
|
||||
struct MTexPoly : ElemBase {
|
||||
struct MTexPoly final : ElemBase {
|
||||
Image *tpage;
|
||||
char flag, transp;
|
||||
short mode, tile, pad;
|
||||
};
|
||||
|
||||
// -------------------------------------------------------------------------------
|
||||
struct MCol : ElemBase {
|
||||
struct MCol final : ElemBase {
|
||||
char r, g, b, a FAIL;
|
||||
};
|
||||
|
||||
// -------------------------------------------------------------------------------
|
||||
struct MFace : ElemBase {
|
||||
struct MFace final : ElemBase {
|
||||
int v1, v2, v3, v4 FAIL;
|
||||
int mat_nr FAIL;
|
||||
char flag;
|
||||
};
|
||||
|
||||
// -------------------------------------------------------------------------------
|
||||
struct TFace : ElemBase {
|
||||
struct TFace final : ElemBase {
|
||||
float uv[4][2] FAIL;
|
||||
int col[4] FAIL;
|
||||
char flag;
|
||||
|
|
@ -247,7 +245,7 @@ struct TFace : ElemBase {
|
|||
};
|
||||
|
||||
// -------------------------------------------------------------------------------
|
||||
struct MTFace : ElemBase {
|
||||
struct MTFace final : ElemBase {
|
||||
MTFace() :
|
||||
flag(0),
|
||||
mode(0),
|
||||
|
|
@ -265,24 +263,24 @@ struct MTFace : ElemBase {
|
|||
};
|
||||
|
||||
// -------------------------------------------------------------------------------
|
||||
struct MDeformWeight : ElemBase {
|
||||
struct MDeformWeight final : ElemBase {
|
||||
int def_nr FAIL;
|
||||
float weight FAIL;
|
||||
};
|
||||
|
||||
// -------------------------------------------------------------------------------
|
||||
struct MDeformVert : ElemBase {
|
||||
struct MDeformVert final : ElemBase {
|
||||
vector<MDeformWeight> dw WARN;
|
||||
int totweight;
|
||||
};
|
||||
|
||||
// -------------------------------------------------------------------------------
|
||||
#define MA_RAYMIRROR 0x40000
|
||||
#define MA_TRANSPARENCY 0x10000
|
||||
#define MA_RAYTRANSP 0x20000
|
||||
#define MA_ZTRANSP 0x00040
|
||||
constexpr uint32_t MA_RAYMIRROR = 0x40000;
|
||||
constexpr uint32_t MA_TRANSPARENCY = 0x10000;
|
||||
constexpr uint32_t MA_RAYTRANSP = 0x20000;
|
||||
constexpr uint32_t MA_ZTRANSP = 0x00040;
|
||||
|
||||
struct Material : ElemBase {
|
||||
struct Material final : ElemBase {
|
||||
ID id FAIL;
|
||||
|
||||
float r, g, b WARN;
|
||||
|
|
@ -404,7 +402,7 @@ CustomDataLayer 104
|
|||
char name 32 64
|
||||
void *data 96 8
|
||||
*/
|
||||
struct CustomDataLayer : ElemBase {
|
||||
struct CustomDataLayer final : ElemBase {
|
||||
int type;
|
||||
int offset;
|
||||
int flag;
|
||||
|
|
@ -442,7 +440,7 @@ CustomData 208
|
|||
BLI_mempool *pool 192 8
|
||||
CustomDataExternal *external 200 8
|
||||
*/
|
||||
struct CustomData : ElemBase {
|
||||
struct CustomData final : ElemBase {
|
||||
vector<std::shared_ptr<struct CustomDataLayer>> layers;
|
||||
int typemap[42]; // CD_NUMTYPES
|
||||
int totlayer;
|
||||
|
|
@ -455,7 +453,7 @@ struct CustomData : ElemBase {
|
|||
};
|
||||
|
||||
// -------------------------------------------------------------------------------
|
||||
struct Mesh : ElemBase {
|
||||
struct Mesh final : ElemBase {
|
||||
ID id FAIL;
|
||||
|
||||
int totface FAIL;
|
||||
|
|
@ -492,7 +490,7 @@ struct Mesh : ElemBase {
|
|||
};
|
||||
|
||||
// -------------------------------------------------------------------------------
|
||||
struct Library : ElemBase {
|
||||
struct Library final : ElemBase {
|
||||
ID id FAIL;
|
||||
|
||||
char name[240] WARN;
|
||||
|
|
@ -516,7 +514,7 @@ struct Camera : ElemBase {
|
|||
};
|
||||
|
||||
// -------------------------------------------------------------------------------
|
||||
struct Lamp : ElemBase {
|
||||
struct Lamp final : ElemBase {
|
||||
|
||||
enum FalloffType {
|
||||
FalloffType_Constant = 0x0,
|
||||
|
|
@ -603,7 +601,7 @@ struct Lamp : ElemBase {
|
|||
};
|
||||
|
||||
// -------------------------------------------------------------------------------
|
||||
struct ModifierData : ElemBase {
|
||||
struct ModifierData final : ElemBase {
|
||||
enum ModifierType {
|
||||
eModifierType_None = 0,
|
||||
eModifierType_Subsurf,
|
||||
|
|
@ -653,9 +651,8 @@ struct SharedModifierData : ElemBase {
|
|||
ModifierData modifier;
|
||||
};
|
||||
|
||||
|
||||
// -------------------------------------------------------------------------------
|
||||
struct SubsurfModifierData : SharedModifierData {
|
||||
struct SubsurfModifierData final : SharedModifierData {
|
||||
|
||||
enum Type {
|
||||
|
||||
|
|
@ -675,7 +672,7 @@ struct SubsurfModifierData : SharedModifierData {
|
|||
};
|
||||
|
||||
// -------------------------------------------------------------------------------
|
||||
struct MirrorModifierData : SharedModifierData {
|
||||
struct MirrorModifierData final : SharedModifierData {
|
||||
|
||||
enum Flags {
|
||||
Flags_CLIPPING = 1 << 0,
|
||||
|
|
@ -693,7 +690,7 @@ struct MirrorModifierData : SharedModifierData {
|
|||
};
|
||||
|
||||
// -------------------------------------------------------------------------------
|
||||
struct Object : ElemBase {
|
||||
struct Object final : ElemBase {
|
||||
ID id FAIL;
|
||||
|
||||
enum Type {
|
||||
|
|
@ -734,7 +731,7 @@ struct Object : ElemBase {
|
|||
};
|
||||
|
||||
// -------------------------------------------------------------------------------
|
||||
struct Base : ElemBase {
|
||||
struct Base final : ElemBase {
|
||||
Base *prev WARN;
|
||||
std::shared_ptr<Base> next WARN;
|
||||
std::shared_ptr<Object> object WARN;
|
||||
|
|
@ -746,7 +743,7 @@ struct Base : ElemBase {
|
|||
};
|
||||
|
||||
// -------------------------------------------------------------------------------
|
||||
struct Scene : ElemBase {
|
||||
struct Scene final : ElemBase {
|
||||
ID id FAIL;
|
||||
|
||||
std::shared_ptr<Object> camera WARN;
|
||||
|
|
@ -760,7 +757,7 @@ struct Scene : ElemBase {
|
|||
};
|
||||
|
||||
// -------------------------------------------------------------------------------
|
||||
struct Image : ElemBase {
|
||||
struct Image final : ElemBase {
|
||||
ID id FAIL;
|
||||
|
||||
char name[240] WARN;
|
||||
|
|
@ -790,7 +787,7 @@ struct Image : ElemBase {
|
|||
};
|
||||
|
||||
// -------------------------------------------------------------------------------
|
||||
struct Tex : ElemBase {
|
||||
struct Tex final : ElemBase {
|
||||
|
||||
// actually, the only texture type we support is Type_IMAGE
|
||||
enum Type {
|
||||
|
|
@ -875,14 +872,13 @@ struct Tex : ElemBase {
|
|||
|
||||
//char use_nodes;
|
||||
|
||||
Tex() :
|
||||
imaflag(ImageFlags_INTERPOL), type(Type_CLOUDS) {
|
||||
Tex() : imaflag(ImageFlags_INTERPOL), type(Type_CLOUDS) {
|
||||
// empty
|
||||
}
|
||||
};
|
||||
|
||||
// -------------------------------------------------------------------------------
|
||||
struct MTex : ElemBase {
|
||||
struct MTex final : ElemBase {
|
||||
|
||||
enum Projection {
|
||||
Proj_N = 0,
|
||||
|
|
@ -971,6 +967,6 @@ struct MTex : ElemBase {
|
|||
MTex() = default;
|
||||
};
|
||||
|
||||
} // namespace Blender
|
||||
} // namespace Assimp
|
||||
} // namespace Assimp::Blender
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
#include "BlenderDNA.h"
|
||||
#include "BlenderScene.h"
|
||||
|
||||
namespace Assimp {
|
||||
namespace Assimp {
|
||||
namespace Blender {
|
||||
|
||||
template <> void Structure :: Convert<Object> (
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
Open Asset Import Library (assimp)
|
||||
----------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2024, assimp team
|
||||
Copyright (c) 2006-2026, assimp team
|
||||
|
||||
All rights reserved.
|
||||
|
||||
|
|
@ -381,7 +381,14 @@ inline PointP2T& BlenderTessellatorP2T::GetActualPointStructure( p2t::Point& poi
|
|||
# pragma clang diagnostic push
|
||||
# pragma clang diagnostic ignored "-Winvalid-offsetof"
|
||||
#endif // __clang__
|
||||
#if defined __GNUC__
|
||||
# pragma GCC diagnostic push
|
||||
# pragma GCC diagnostic ignored "-Winvalid-offsetof"
|
||||
#endif // __GNUC__
|
||||
unsigned int pointOffset = offsetof( PointP2T, point2D );
|
||||
#if defined __GNUC__
|
||||
# pragma GCC diagnostic pop
|
||||
#endif // __GNUC__
|
||||
#if defined __clang__
|
||||
# pragma clang diagnostic pop
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
Open Asset Import Library (assimp)
|
||||
----------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2024, assimp team
|
||||
Copyright (c) 2006-2026, assimp team
|
||||
|
||||
All rights reserved.
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
Open Asset Import Library (assimp)
|
||||
----------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2021, assimp team
|
||||
Copyright (c) 2006-2026, assimp team
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use of this software in source and binary forms,
|
||||
|
|
@ -64,7 +64,7 @@ namespace {
|
|||
|
||||
aiString aiStringFrom(cineware::String const & cinestring) {
|
||||
aiString result;
|
||||
cinestring.GetCString(result.data, MAXLEN-1);
|
||||
cinestring.GetCString(result.data, AI_MAXLEN - 1);
|
||||
result.length = static_cast<ai_uint32>(cinestring.GetLength());
|
||||
return result;
|
||||
}
|
||||
|
|
@ -86,7 +86,7 @@ namespace Assimp {
|
|||
}
|
||||
}
|
||||
|
||||
static const aiImporterDesc desc = {
|
||||
static constexpr aiImporterDesc desc = {
|
||||
"Cinema4D Importer",
|
||||
"",
|
||||
"",
|
||||
|
|
@ -99,13 +99,6 @@ static const aiImporterDesc desc = {
|
|||
"c4d"
|
||||
};
|
||||
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
C4DImporter::C4DImporter() = default;
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
C4DImporter::~C4DImporter() = default;
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
bool C4DImporter::CanRead( const std::string& pFile, IOSystem* pIOHandler, bool checkSig) const {
|
||||
const std::string& extension = GetExtension(pFile);
|
||||
|
|
@ -196,7 +189,6 @@ void C4DImporter::InternReadFile( const std::string& pFile, aiScene* pScene, IOS
|
|||
std::copy(materials.begin(), materials.end(), pScene->mMaterials);
|
||||
}
|
||||
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
bool C4DImporter::ReadShader(aiMaterial* out, BaseShader* shader) {
|
||||
// based on Cineware sample code (C4DImportExport.cpp)
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@ namespace cineware {
|
|||
class BaseShader;
|
||||
}
|
||||
|
||||
namespace Assimp {
|
||||
namespace Assimp {
|
||||
// TinyFormatter.h
|
||||
namespace Formatter {
|
||||
template <typename T,typename TR, typename A> class basic_formatter;
|
||||
|
|
@ -78,8 +78,8 @@ namespace Assimp {
|
|||
// -------------------------------------------------------------------------------------------
|
||||
class C4DImporter : public BaseImporter, public LogFunctions<C4DImporter> {
|
||||
public:
|
||||
C4DImporter();
|
||||
~C4DImporter() override;
|
||||
C4DImporter() = default;
|
||||
~C4DImporter() override = default;
|
||||
bool CanRead( const std::string& pFile, IOSystem*, bool checkSig) const override;
|
||||
|
||||
protected:
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
Open Asset Import Library (assimp)
|
||||
----------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2024, assimp team
|
||||
Copyright (c) 2006-2026, assimp team
|
||||
|
||||
All rights reserved.
|
||||
|
||||
|
|
@ -45,8 +45,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
|
||||
#ifndef ASSIMP_BUILD_NO_COB_IMPORTER
|
||||
|
||||
#include "AssetLib/COB/COBLoader.h"
|
||||
#include "AssetLib/COB/COBScene.h"
|
||||
#include "COBLoader.h"
|
||||
#include "COBScene.h"
|
||||
#include "PostProcessing/ConvertToLHProcess.h"
|
||||
|
||||
#include <assimp/LineSplitter.h>
|
||||
|
|
@ -62,6 +62,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
#include <memory>
|
||||
|
||||
namespace Assimp {
|
||||
|
||||
using namespace Assimp::COB;
|
||||
using namespace Assimp::Formatter;
|
||||
|
||||
|
|
@ -109,10 +110,29 @@ void COBImporter::SetupProperties(const Importer * /*pImp*/) {
|
|||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
/*static*/ AI_WONT_RETURN void COBImporter::ThrowException(const std::string &msg) {
|
||||
AI_WONT_RETURN void COBImporter::ThrowException(const std::string &msg) {
|
||||
throw DeadlyImportError("COB: ", msg);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
static bool isValidASCIIHeader(const char *head) {
|
||||
ai_assert(head != nullptr);
|
||||
|
||||
if (strncmp(head, "Caligari ", 9) != 0) {
|
||||
COBImporter::ThrowException("Could not found magic id: `Caligari`");
|
||||
}
|
||||
|
||||
if (strncmp(&head[9], "V00.", 4) != 0) {
|
||||
COBImporter::ThrowException("Could not found Version tag: `V00.`");
|
||||
}
|
||||
ASSIMP_LOG_INFO("File format tag: ", std::string(head + 9, 6));
|
||||
if (head[16] != 'L') {
|
||||
COBImporter::ThrowException("File is big-endian, which is not supported");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Imports the given file into the given scene structure.
|
||||
void COBImporter::InternReadFile(const std::string &pFile, aiScene *pScene, IOSystem *pIOHandler) {
|
||||
|
|
@ -126,19 +146,15 @@ void COBImporter::InternReadFile(const std::string &pFile, aiScene *pScene, IOSy
|
|||
std::unique_ptr<StreamReaderLE> stream(new StreamReaderLE(file));
|
||||
|
||||
// check header
|
||||
char head[32];
|
||||
stream->CopyAndAdvance(head, 32);
|
||||
if (strncmp(head, "Caligari ", 9) != 0) {
|
||||
ThrowException("Could not found magic id: `Caligari`");
|
||||
}
|
||||
|
||||
ASSIMP_LOG_INFO("File format tag: ", std::string(head + 9, 6));
|
||||
if (head[16] != 'L') {
|
||||
ThrowException("File is big-endian, which is not supported");
|
||||
}
|
||||
static constexpr size_t HeaderSize = 32u;
|
||||
char head[HeaderSize] = {};
|
||||
stream->CopyAndAdvance(head, HeaderSize);
|
||||
|
||||
// load data into intermediate structures
|
||||
if (head[15] == 'A') {
|
||||
if (!isValidASCIIHeader(head)) {
|
||||
ThrowException("Invalid ASCII file header");
|
||||
}
|
||||
ReadAsciiFile(scene, stream.get());
|
||||
} else {
|
||||
ReadBinaryFile(scene, stream.get());
|
||||
|
|
@ -228,7 +244,7 @@ aiNode *COBImporter::BuildNodes(const Node &root, const Scene &scin, aiScene *fi
|
|||
const Mesh &ndmesh = (const Mesh &)(root);
|
||||
if (ndmesh.vertex_positions.size() && ndmesh.texture_coords.size()) {
|
||||
|
||||
typedef std::pair<const unsigned int, Mesh::FaceRefList> Entry;
|
||||
using Entry = std::pair<const unsigned int, Mesh::FaceRefList>;
|
||||
for (const Entry &reflist : ndmesh.temp_map) {
|
||||
{ // create mesh
|
||||
size_t n = 0;
|
||||
|
|
@ -1170,6 +1186,6 @@ void COBImporter::ReadUnit_Binary(COB::Scene &out, StreamReaderLE &reader, const
|
|||
ASSIMP_LOG_WARN("`Unit` chunk ", nfo.id, " is a child of ", nfo.parent_id, " which does not exist");
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace Assimp
|
||||
|
||||
#endif // ASSIMP_BUILD_NO_COB_IMPORTER
|
||||
|
|
|
|||
|
|
@ -2,8 +2,7 @@
|
|||
Open Asset Import Library (assimp)
|
||||
----------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2024, assimp team
|
||||
|
||||
Copyright (c) 2006-2026, assimp team
|
||||
|
||||
All rights reserved.
|
||||
|
||||
|
|
@ -73,7 +72,7 @@ namespace COB {
|
|||
*
|
||||
* Currently relatively limited, loads only ASCII files and needs more test coverage. */
|
||||
// -------------------------------------------------------------------------------------------
|
||||
class COBImporter : public BaseImporter {
|
||||
class COBImporter final : public BaseImporter {
|
||||
public:
|
||||
COBImporter() = default;
|
||||
~COBImporter() override = default;
|
||||
|
|
@ -82,6 +81,10 @@ public:
|
|||
bool CanRead(const std::string &pFile, IOSystem *pIOHandler,
|
||||
bool checkSig) const override;
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
/** Prepend 'COB: ' and throw msg.*/
|
||||
AI_WONT_RETURN static void ThrowException(const std::string &msg) AI_WONT_RETURN_SUFFIX;
|
||||
|
||||
protected:
|
||||
// --------------------
|
||||
const aiImporterDesc *GetInfo() const override;
|
||||
|
|
@ -94,10 +97,6 @@ protected:
|
|||
IOSystem *pIOHandler) override;
|
||||
|
||||
private:
|
||||
// -------------------------------------------------------------------
|
||||
/** Prepend 'COB: ' and throw msg.*/
|
||||
AI_WONT_RETURN static void ThrowException(const std::string &msg) AI_WONT_RETURN_SUFFIX;
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
/** @brief Read from an ascii scene/object file
|
||||
* @param out Receives output data.
|
||||
|
|
@ -149,4 +148,5 @@ private:
|
|||
}; // !class COBImporter
|
||||
|
||||
} // end of namespace Assimp
|
||||
|
||||
#endif // AI_UNREALIMPORTER_H_INC
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
Open Asset Import Library (assimp)
|
||||
----------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2024, assimp team
|
||||
Copyright (c) 2006-2026, assimp team
|
||||
|
||||
All rights reserved.
|
||||
|
||||
|
|
@ -52,68 +52,66 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
#include <deque>
|
||||
#include <map>
|
||||
|
||||
namespace Assimp {
|
||||
namespace COB {
|
||||
namespace Assimp::COB {
|
||||
|
||||
// ------------------
|
||||
/** Represents a single vertex index in a face */
|
||||
struct VertexIndex
|
||||
{
|
||||
struct VertexIndex {
|
||||
// intentionally uninitialized
|
||||
unsigned int pos_idx,uv_idx;
|
||||
};
|
||||
|
||||
// ------------------
|
||||
/** COB Face data structure */
|
||||
struct Face
|
||||
{
|
||||
struct Face {
|
||||
// intentionally uninitialized
|
||||
unsigned int material, flags;
|
||||
unsigned int material;
|
||||
unsigned int flags;
|
||||
std::vector<VertexIndex> indices;
|
||||
};
|
||||
|
||||
// ------------------
|
||||
/** COB chunk header information */
|
||||
const unsigned int NO_SIZE = UINT_MAX;
|
||||
constexpr unsigned int NO_SIZE = UINT_MAX;
|
||||
|
||||
struct ChunkInfo
|
||||
{
|
||||
ChunkInfo ()
|
||||
: id (0)
|
||||
, parent_id (0)
|
||||
, version (0)
|
||||
, size (NO_SIZE)
|
||||
{}
|
||||
struct ChunkInfo {
|
||||
ChunkInfo() = default;
|
||||
virtual ~ChunkInfo() = default;
|
||||
|
||||
// Id of this chunk, unique within file
|
||||
unsigned int id;
|
||||
unsigned int id{ 0 };
|
||||
|
||||
// and the corresponding parent
|
||||
unsigned int parent_id;
|
||||
unsigned int parent_id{ 0 };
|
||||
|
||||
// version. v1.23 becomes 123
|
||||
unsigned int version;
|
||||
unsigned int version{ 0 };
|
||||
|
||||
// chunk size in bytes, only relevant for binary files
|
||||
// NO_SIZE is also valid.
|
||||
unsigned int size;
|
||||
unsigned int size{NO_SIZE};
|
||||
};
|
||||
|
||||
// ------------------
|
||||
/** A node in the scenegraph */
|
||||
struct Node : public ChunkInfo
|
||||
{
|
||||
struct Node : ChunkInfo {
|
||||
enum Type {
|
||||
TYPE_MESH,TYPE_GROUP,TYPE_LIGHT,TYPE_CAMERA,TYPE_BONE
|
||||
TYPE_INVALID = -1,
|
||||
TYPE_MESH = 0,
|
||||
TYPE_GROUP,
|
||||
TYPE_LIGHT,
|
||||
TYPE_CAMERA,
|
||||
TYPE_BONE,
|
||||
TYPE_COUNT
|
||||
};
|
||||
|
||||
virtual ~Node() = default;
|
||||
Node(Type type) : type(type), unit_scale(1.f){}
|
||||
~Node() override = default;
|
||||
explicit Node(Type type) : type(type), unit_scale(1.f){}
|
||||
|
||||
Type type;
|
||||
|
||||
// used during resolving
|
||||
typedef std::deque<const Node*> ChildList;
|
||||
using ChildList = std::deque<const Node*> ;
|
||||
mutable ChildList temp_children;
|
||||
|
||||
// unique name
|
||||
|
|
@ -128,8 +126,7 @@ struct Node : public ChunkInfo
|
|||
|
||||
// ------------------
|
||||
/** COB Mesh data structure */
|
||||
struct Mesh : public Node
|
||||
{
|
||||
struct Mesh final : Node {
|
||||
using ChunkInfo::operator=;
|
||||
enum DrawFlags {
|
||||
SOLID = 0x1,
|
||||
|
|
@ -162,107 +159,118 @@ struct Mesh : public Node
|
|||
|
||||
// ------------------
|
||||
/** COB Group data structure */
|
||||
struct Group : public Node
|
||||
{
|
||||
struct Group final : Node {
|
||||
using ChunkInfo::operator=;
|
||||
Group() : Node(TYPE_GROUP) {}
|
||||
|
||||
Group() : Node(TYPE_GROUP) {
|
||||
// empty
|
||||
}
|
||||
};
|
||||
|
||||
// ------------------
|
||||
/** COB Bone data structure */
|
||||
struct Bone : public Node
|
||||
{
|
||||
struct Bone final : Node {
|
||||
using ChunkInfo::operator=;
|
||||
Bone() : Node(TYPE_BONE) {}
|
||||
|
||||
Bone() : Node(TYPE_BONE) {
|
||||
// empty
|
||||
}
|
||||
};
|
||||
|
||||
// ------------------
|
||||
/** COB Light data structure */
|
||||
struct Light : public Node
|
||||
{
|
||||
struct Light final : Node {
|
||||
enum LightType {
|
||||
SPOT,LOCAL,INFINITE
|
||||
SPOT,
|
||||
LOCAL,
|
||||
INFINITE
|
||||
};
|
||||
|
||||
using ChunkInfo::operator=;
|
||||
Light() : Node(TYPE_LIGHT),angle(),inner_angle(),ltype(SPOT) {}
|
||||
|
||||
Light() : Node(TYPE_LIGHT), ltype() {
|
||||
// empty
|
||||
}
|
||||
|
||||
aiColor3D color;
|
||||
float angle,inner_angle;
|
||||
float angle{ 0.0f };
|
||||
float inner_angle{ 0.0f };
|
||||
|
||||
LightType ltype;
|
||||
LightType ltype{SPOT};
|
||||
};
|
||||
|
||||
// ------------------
|
||||
/** COB Camera data structure */
|
||||
struct Camera : public Node
|
||||
{
|
||||
struct Camera final : Node {
|
||||
using ChunkInfo::operator=;
|
||||
Camera() : Node(TYPE_CAMERA) {}
|
||||
|
||||
Camera() : Node(TYPE_CAMERA) {
|
||||
// empty
|
||||
}
|
||||
};
|
||||
|
||||
// ------------------
|
||||
/** COB Texture data structure */
|
||||
struct Texture
|
||||
{
|
||||
struct Texture {
|
||||
std::string path;
|
||||
aiUVTransform transform;
|
||||
};
|
||||
|
||||
// ------------------
|
||||
/** COB Material data structure */
|
||||
struct Material : ChunkInfo
|
||||
{
|
||||
struct Material : ChunkInfo {
|
||||
using ChunkInfo::operator=;
|
||||
|
||||
enum Shader {
|
||||
FLAT,PHONG,METAL
|
||||
FLAT,
|
||||
PHONG,
|
||||
METAL
|
||||
};
|
||||
|
||||
enum AutoFacet {
|
||||
FACETED,AUTOFACETED,SMOOTH
|
||||
FACETED,
|
||||
AUTOFACETED,
|
||||
SMOOTH
|
||||
};
|
||||
|
||||
Material() : alpha(),exp(),ior(),ka(),ks(1.f),
|
||||
matnum(UINT_MAX),
|
||||
shader(FLAT),autofacet(FACETED),
|
||||
autofacet_angle()
|
||||
{}
|
||||
Material() : shader(FLAT) {
|
||||
// empty
|
||||
}
|
||||
|
||||
std::string type;
|
||||
|
||||
aiColor3D rgb;
|
||||
float alpha, exp, ior,ka,ks;
|
||||
|
||||
unsigned int matnum;
|
||||
float alpha{ 0.0f };
|
||||
float exp{ 0.0f };
|
||||
float ior{ 0.0f };
|
||||
float ka{ 0.0f };
|
||||
float ks{ 1.0f };
|
||||
unsigned int matnum{ UINT_MAX };
|
||||
Shader shader;
|
||||
|
||||
AutoFacet autofacet;
|
||||
float autofacet_angle;
|
||||
|
||||
AutoFacet autofacet{FACETED};
|
||||
float autofacet_angle{ 0.0f };
|
||||
std::shared_ptr<Texture> tex_env,tex_bump,tex_color;
|
||||
};
|
||||
|
||||
// ------------------
|
||||
/** Embedded bitmap, for instance for the thumbnail image */
|
||||
struct Bitmap : ChunkInfo
|
||||
{
|
||||
Bitmap() : orig_size() {}
|
||||
struct BitmapHeader
|
||||
{
|
||||
struct Bitmap : ChunkInfo {
|
||||
Bitmap() = default;
|
||||
|
||||
struct BitmapHeader {
|
||||
// empty
|
||||
};
|
||||
|
||||
BitmapHeader head;
|
||||
size_t orig_size;
|
||||
size_t orig_size{ 0u };
|
||||
std::vector<char> buff_zipped;
|
||||
};
|
||||
|
||||
typedef std::deque< std::shared_ptr<Node> > NodeList;
|
||||
typedef std::vector< Material > MaterialList;
|
||||
using NodeList = std::deque< std::shared_ptr<Node>>;
|
||||
using MaterialList = std::vector< Material >;
|
||||
|
||||
// ------------------
|
||||
/** Represents a master COB scene, even if we loaded just a single COB file */
|
||||
struct Scene
|
||||
{
|
||||
struct Scene {
|
||||
NodeList nodes;
|
||||
MaterialList materials;
|
||||
|
||||
|
|
@ -270,7 +278,6 @@ struct Scene
|
|||
Bitmap thumbnail;
|
||||
};
|
||||
|
||||
} // end COB
|
||||
} // end Assimp
|
||||
} // end Assimp::COB
|
||||
|
||||
#endif
|
||||
#endif // INCLUDED_AI_COB_SCENE_H
|
||||
|
|
|
|||
|
|
@ -3,9 +3,7 @@
|
|||
Open Asset Import Library (assimp)
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2024, assimp team
|
||||
|
||||
|
||||
Copyright (c) 2006-2026, assimp team
|
||||
|
||||
All rights reserved.
|
||||
|
||||
|
|
@ -73,10 +71,9 @@ static constexpr aiImporterDesc desc = {
|
|||
"csm"
|
||||
};
|
||||
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Constructor to be privately used by Importer
|
||||
CSMImporter::CSMImporter() : noSkeletonMesh(){
|
||||
CSMImporter::CSMImporter() : noSkeletonMesh() {
|
||||
// empty
|
||||
}
|
||||
|
||||
|
|
@ -102,8 +99,7 @@ void CSMImporter::SetupProperties(const Importer* pImp) {
|
|||
// ------------------------------------------------------------------------------------------------
|
||||
// Imports the given file into the given scene structure.
|
||||
void CSMImporter::InternReadFile( const std::string& pFile,
|
||||
aiScene* pScene, IOSystem* pIOHandler)
|
||||
{
|
||||
aiScene* pScene, IOSystem* pIOHandler) {
|
||||
std::unique_ptr<IOStream> file( pIOHandler->Open( pFile, "rb"));
|
||||
|
||||
// Check whether we can read from the file
|
||||
|
|
@ -122,23 +118,24 @@ void CSMImporter::InternReadFile( const std::string& pFile,
|
|||
// now process the file and look out for '$' sections
|
||||
while (true) {
|
||||
SkipSpaces(&buffer, end);
|
||||
if ('\0' == *buffer)
|
||||
if ('\0' == *buffer) {
|
||||
break;
|
||||
}
|
||||
|
||||
if ('$' == *buffer) {
|
||||
if ('$' == *buffer) {
|
||||
++buffer;
|
||||
if (TokenMatchI(buffer,"firstframe",10)) {
|
||||
if (TokenMatchI(buffer,"firstframe",10)) {
|
||||
SkipSpaces(&buffer, end);
|
||||
first = strtol10(buffer,&buffer);
|
||||
}
|
||||
else if (TokenMatchI(buffer,"lastframe",9)) {
|
||||
else if (TokenMatchI(buffer,"lastframe",9)) {
|
||||
SkipSpaces(&buffer, end);
|
||||
last = strtol10(buffer,&buffer);
|
||||
}
|
||||
else if (TokenMatchI(buffer,"rate",4)) {
|
||||
SkipSpaces(&buffer, end);
|
||||
float d = { 0.0f };
|
||||
buffer = fast_atoreal_move<float>(buffer,d);
|
||||
buffer = fast_atoreal_move(buffer,d);
|
||||
anim->mTicksPerSecond = d;
|
||||
}
|
||||
else if (TokenMatchI(buffer,"order",5)) {
|
||||
|
|
@ -153,8 +150,9 @@ void CSMImporter::InternReadFile( const std::string& pFile,
|
|||
anims_temp.push_back(new aiNodeAnim());
|
||||
aiNodeAnim* nda = anims_temp.back();
|
||||
|
||||
char* ot = nda->mNodeName.data;
|
||||
while (!IsSpaceOrNewLine(*buffer)) {
|
||||
char *ot = nda->mNodeName.data;
|
||||
const char *ot_end = nda->mNodeName.data + AI_MAXLEN;
|
||||
while (!IsSpaceOrNewLine(*buffer) && buffer != end && ot != ot_end) {
|
||||
*ot++ = *buffer++;
|
||||
}
|
||||
|
||||
|
|
@ -178,9 +176,17 @@ void CSMImporter::InternReadFile( const std::string& pFile,
|
|||
// If we know how many frames we'll read, we can preallocate some storage
|
||||
unsigned int alloc = 100;
|
||||
if (last != 0x00ffffff) {
|
||||
// re-init if the file has last frame data
|
||||
alloc = last-first;
|
||||
alloc += alloc>>2u; // + 25%
|
||||
for (unsigned int i = 0; i < anim->mNumChannels; ++i) {
|
||||
if (anim->mChannels[i]->mPositionKeys != nullptr) delete[] anim->mChannels[i]->mPositionKeys;
|
||||
anim->mChannels[i]->mPositionKeys = new aiVectorKey[alloc];
|
||||
}
|
||||
} else {
|
||||
// default init
|
||||
for (unsigned int i = 0; i < anim->mNumChannels; ++i) {
|
||||
if (anim->mChannels[i]->mPositionKeys != nullptr) continue;
|
||||
anim->mChannels[i]->mPositionKeys = new aiVectorKey[alloc];
|
||||
}
|
||||
}
|
||||
|
|
@ -204,7 +210,7 @@ void CSMImporter::InternReadFile( const std::string& pFile,
|
|||
if (s->mNumPositionKeys == alloc) {
|
||||
// need to reallocate?
|
||||
aiVectorKey* old = s->mPositionKeys;
|
||||
s->mPositionKeys = new aiVectorKey[s->mNumPositionKeys = alloc*2];
|
||||
s->mPositionKeys = new aiVectorKey[alloc*2];
|
||||
::memcpy(s->mPositionKeys,old,sizeof(aiVectorKey)*alloc);
|
||||
delete[] old;
|
||||
}
|
||||
|
|
@ -220,17 +226,17 @@ void CSMImporter::InternReadFile( const std::string& pFile,
|
|||
} else {
|
||||
aiVectorKey* sub = s->mPositionKeys + s->mNumPositionKeys;
|
||||
sub->mTime = (double)frame;
|
||||
buffer = fast_atoreal_move<float>(buffer, (float&)sub->mValue.x);
|
||||
buffer = fast_atoreal_move(buffer, sub->mValue.x);
|
||||
|
||||
if (!SkipSpacesAndLineEnd(&buffer, end)) {
|
||||
throw DeadlyImportError("CSM: Unexpected EOF occurred reading sample y coord");
|
||||
}
|
||||
buffer = fast_atoreal_move<float>(buffer, (float&)sub->mValue.y);
|
||||
buffer = fast_atoreal_move(buffer, sub->mValue.y);
|
||||
|
||||
if (!SkipSpacesAndLineEnd(&buffer, end)) {
|
||||
throw DeadlyImportError("CSM: Unexpected EOF occurred reading sample z coord");
|
||||
}
|
||||
buffer = fast_atoreal_move<float>(buffer, (float&)sub->mValue.z);
|
||||
buffer = fast_atoreal_move(buffer, sub->mValue.z);
|
||||
|
||||
++s->mNumPositionKeys;
|
||||
}
|
||||
|
|
@ -273,7 +279,13 @@ void CSMImporter::InternReadFile( const std::string& pFile,
|
|||
nd->mName = anim->mChannels[i]->mNodeName;
|
||||
nd->mParent = pScene->mRootNode;
|
||||
|
||||
aiMatrix4x4::Translation(na->mPositionKeys[0].mValue, nd->mTransformation);
|
||||
if (na->mPositionKeys != nullptr && na->mNumPositionKeys > 0) {
|
||||
aiMatrix4x4::Translation(na->mPositionKeys[0].mValue, nd->mTransformation);
|
||||
} else {
|
||||
// Use identity matrix if no valid position data is available
|
||||
nd->mTransformation = aiMatrix4x4();
|
||||
DefaultLogger::get()->warn("CSM: No position keys available for node - using identity transformation");
|
||||
}
|
||||
}
|
||||
|
||||
// Store the one and only animation in the scene
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
Open Asset Import Library (assimp)
|
||||
----------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2024, assimp team
|
||||
Copyright (c) 2006-2026, assimp team
|
||||
|
||||
All rights reserved.
|
||||
|
||||
|
|
@ -58,7 +58,7 @@ namespace Assimp {
|
|||
* Link to file format specification:
|
||||
* <max_8_dvd>\samples\Motion\Docs\CSM.rtf
|
||||
*/
|
||||
class CSMImporter : public BaseImporter {
|
||||
class CSMImporter final : public BaseImporter {
|
||||
public:
|
||||
CSMImporter();
|
||||
~CSMImporter() override = default;
|
||||
|
|
|
|||
|
|
@ -2,8 +2,7 @@
|
|||
Open Asset Import Library (assimp)
|
||||
----------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2024, assimp team
|
||||
|
||||
Copyright (c) 2006-2026, assimp team
|
||||
|
||||
All rights reserved.
|
||||
|
||||
|
|
@ -36,7 +35,6 @@ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
----------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
|
|
@ -64,6 +62,37 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
|
||||
namespace Assimp {
|
||||
|
||||
static const aiNode *findSkeletonRootNode(const aiScene *scene, const aiMesh *mesh) {
|
||||
std::set<const aiNode *> topParentBoneNodes;
|
||||
if (mesh && mesh->mNumBones > 0) {
|
||||
for (unsigned int i = 0; i < mesh->mNumBones; ++i) {
|
||||
aiBone *bone = mesh->mBones[i];
|
||||
|
||||
const aiNode *node = scene->mRootNode->findBoneNode(bone);
|
||||
if (node) {
|
||||
while (node->mParent && scene->findBone(node->mParent->mName) != nullptr) {
|
||||
node = node->mParent;
|
||||
}
|
||||
topParentBoneNodes.insert(node);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!topParentBoneNodes.empty()) {
|
||||
const aiNode *parentBoneNode = *topParentBoneNodes.begin();
|
||||
if (topParentBoneNodes.size() == 1) {
|
||||
return parentBoneNode;
|
||||
} else {
|
||||
for (auto it : topParentBoneNodes) {
|
||||
if (it->mParent) return it->mParent;
|
||||
}
|
||||
return parentBoneNode;
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Worker function for exporting a scene to Collada. Prototyped and registered in Exporter.cpp
|
||||
void ExportSceneCollada(const char *pFile, IOSystem *pIOSystem, const aiScene *pScene, const ExportProperties * /*pProperties*/) {
|
||||
|
|
@ -152,10 +181,6 @@ ColladaExporter::ColladaExporter(const aiScene *pScene, IOSystem *pIOSystem, con
|
|||
WriteFile();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Destructor
|
||||
ColladaExporter::~ColladaExporter() = default;
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Starts writing the contents
|
||||
void ColladaExporter::WriteFile() {
|
||||
|
|
@ -331,60 +356,68 @@ void ColladaExporter::WriteHeader() {
|
|||
// ------------------------------------------------------------------------------------------------
|
||||
// Write the embedded textures
|
||||
void ColladaExporter::WriteTextures() {
|
||||
static const unsigned int buffer_size = 1024;
|
||||
char str[buffer_size];
|
||||
static constexpr unsigned int buffer_size = 1024;
|
||||
char str[buffer_size] = {'\0'};
|
||||
|
||||
if (mScene->HasTextures()) {
|
||||
for (unsigned int i = 0; i < mScene->mNumTextures; i++) {
|
||||
// It would be great to be able to create a directory in portable standard C++, but it's not the case,
|
||||
// so we just write the textures in the current directory.
|
||||
if (!mScene->HasTextures()) {
|
||||
return;
|
||||
}
|
||||
|
||||
aiTexture *texture = mScene->mTextures[i];
|
||||
if (nullptr == texture) {
|
||||
continue;
|
||||
}
|
||||
for (unsigned int i = 0; i < mScene->mNumTextures; i++) {
|
||||
// It would be great to be able to create a directory in portable standard C++, but it's not the case,
|
||||
// so we just write the textures in the current directory.
|
||||
|
||||
ASSIMP_itoa10(str, buffer_size, i + 1);
|
||||
|
||||
std::string name = mFile + "_texture_" + (i < 1000 ? "0" : "") + (i < 100 ? "0" : "") + (i < 10 ? "0" : "") + str + "." + ((const char *)texture->achFormatHint);
|
||||
|
||||
std::unique_ptr<IOStream> outfile(mIOSystem->Open(mPath + mIOSystem->getOsSeparator() + name, "wb"));
|
||||
if (outfile == nullptr) {
|
||||
throw DeadlyExportError("could not open output texture file: " + mPath + name);
|
||||
}
|
||||
|
||||
if (texture->mHeight == 0) {
|
||||
outfile->Write((void *)texture->pcData, texture->mWidth, 1);
|
||||
} else {
|
||||
Bitmap::Save(texture, outfile.get());
|
||||
}
|
||||
|
||||
outfile->Flush();
|
||||
|
||||
textures.insert(std::make_pair(i, name));
|
||||
aiTexture *texture = mScene->mTextures[i];
|
||||
if (nullptr == texture) {
|
||||
continue;
|
||||
}
|
||||
|
||||
ASSIMP_itoa10(str, buffer_size, i + 1);
|
||||
|
||||
std::string name = mFile + "_texture_" + (i < 1000 ? "0" : "") + (i < 100 ? "0" : "") + (i < 10 ? "0" : "") + str + "." + ((const char *)texture->achFormatHint);
|
||||
|
||||
std::unique_ptr<IOStream> outfile(mIOSystem->Open(mPath + mIOSystem->getOsSeparator() + name, "wb"));
|
||||
if (outfile == nullptr) {
|
||||
throw DeadlyExportError("could not open output texture file: " + mPath + name);
|
||||
}
|
||||
|
||||
if (texture->mHeight == 0) {
|
||||
outfile->Write((void *)texture->pcData, texture->mWidth, 1);
|
||||
} else {
|
||||
Bitmap::Save(texture, outfile.get());
|
||||
}
|
||||
|
||||
outfile->Flush();
|
||||
|
||||
textures.insert(std::make_pair(i, name));
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Write the embedded textures
|
||||
void ColladaExporter::WriteCamerasLibrary() {
|
||||
if (mScene->HasCameras()) {
|
||||
|
||||
mOutput << startstr << "<library_cameras>" << endstr;
|
||||
PushTag();
|
||||
|
||||
for (size_t a = 0; a < mScene->mNumCameras; ++a)
|
||||
WriteCamera(a);
|
||||
|
||||
PopTag();
|
||||
mOutput << startstr << "</library_cameras>" << endstr;
|
||||
if (!mScene->HasCameras()) {
|
||||
return;
|
||||
}
|
||||
|
||||
mOutput << startstr << "<library_cameras>" << endstr;
|
||||
PushTag();
|
||||
|
||||
for (size_t a = 0; a < mScene->mNumCameras; ++a) {
|
||||
WriteCamera(a);
|
||||
}
|
||||
|
||||
PopTag();
|
||||
mOutput << startstr << "</library_cameras>" << endstr;
|
||||
}
|
||||
|
||||
void ColladaExporter::WriteCamera(size_t pIndex) {
|
||||
|
||||
const aiCamera *cam = mScene->mCameras[pIndex];
|
||||
if (cam == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
const std::string cameraId = GetObjectUniqueId(AiObjectType::Camera, pIndex);
|
||||
const std::string cameraName = GetObjectName(AiObjectType::Camera, pIndex);
|
||||
|
||||
|
|
@ -422,22 +455,27 @@ void ColladaExporter::WriteCamera(size_t pIndex) {
|
|||
// ------------------------------------------------------------------------------------------------
|
||||
// Write the embedded textures
|
||||
void ColladaExporter::WriteLightsLibrary() {
|
||||
if (mScene->HasLights()) {
|
||||
|
||||
mOutput << startstr << "<library_lights>" << endstr;
|
||||
PushTag();
|
||||
|
||||
for (size_t a = 0; a < mScene->mNumLights; ++a)
|
||||
WriteLight(a);
|
||||
|
||||
PopTag();
|
||||
mOutput << startstr << "</library_lights>" << endstr;
|
||||
if (!mScene->HasLights()) {
|
||||
return;
|
||||
}
|
||||
|
||||
mOutput << startstr << "<library_lights>" << endstr;
|
||||
PushTag();
|
||||
|
||||
for (size_t a = 0; a < mScene->mNumLights; ++a) {
|
||||
WriteLight(a);
|
||||
}
|
||||
|
||||
PopTag();
|
||||
mOutput << startstr << "</library_lights>" << endstr;
|
||||
}
|
||||
|
||||
void ColladaExporter::WriteLight(size_t pIndex) {
|
||||
|
||||
const aiLight *light = mScene->mLights[pIndex];
|
||||
if (light == nullptr) {
|
||||
return;
|
||||
}
|
||||
const std::string lightId = GetObjectUniqueId(AiObjectType::Light, pIndex);
|
||||
const std::string lightName = GetObjectName(AiObjectType::Light, pIndex);
|
||||
|
||||
|
|
@ -462,6 +500,7 @@ void ColladaExporter::WriteLight(size_t pIndex) {
|
|||
case aiLightSource_AREA:
|
||||
case aiLightSource_UNDEFINED:
|
||||
case _aiLightSource_Force32Bit:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
PopTag();
|
||||
|
|
@ -521,10 +560,6 @@ void ColladaExporter::WriteSpotLight(const aiLight *const light) {
|
|||
mOutput << startstr << "<quadratic_attenuation>"
|
||||
<< light->mAttenuationQuadratic
|
||||
<< "</quadratic_attenuation>" << endstr;
|
||||
/*
|
||||
out->mAngleOuterCone = AI_DEG_TO_RAD (std::acos(std::pow(0.1f,1.f/srcLight->mFalloffExponent))+
|
||||
srcLight->mFalloffAngle);
|
||||
*/
|
||||
|
||||
const ai_real fallOffAngle = AI_RAD_TO_DEG(light->mAngleInnerCone);
|
||||
mOutput << startstr << "<falloff_angle sid=\"fall_off_angle\">"
|
||||
|
|
@ -559,41 +594,43 @@ void ColladaExporter::WriteAmbientLight(const aiLight *const light) {
|
|||
// ------------------------------------------------------------------------------------------------
|
||||
// Reads a single surface entry from the given material keys
|
||||
bool ColladaExporter::ReadMaterialSurface(Surface &poSurface, const aiMaterial &pSrcMat, aiTextureType pTexture, const char *pKey, size_t pType, size_t pIndex) {
|
||||
if (pSrcMat.GetTextureCount(pTexture) > 0) {
|
||||
aiString texfile;
|
||||
unsigned int uvChannel = 0;
|
||||
pSrcMat.GetTexture(pTexture, 0, &texfile, nullptr, &uvChannel);
|
||||
|
||||
std::string index_str(texfile.C_Str());
|
||||
|
||||
if (index_str.size() != 0 && index_str[0] == '*') {
|
||||
unsigned int index;
|
||||
|
||||
index_str = index_str.substr(1, std::string::npos);
|
||||
|
||||
try {
|
||||
index = (unsigned int)strtoul10_64<DeadlyExportError>(index_str.c_str());
|
||||
} catch (std::exception &error) {
|
||||
throw DeadlyExportError(error.what());
|
||||
}
|
||||
|
||||
std::map<unsigned int, std::string>::const_iterator name = textures.find(index);
|
||||
|
||||
if (name != textures.end()) {
|
||||
poSurface.texture = name->second;
|
||||
} else {
|
||||
throw DeadlyExportError("could not find embedded texture at index " + index_str);
|
||||
}
|
||||
} else {
|
||||
poSurface.texture = texfile.C_Str();
|
||||
}
|
||||
|
||||
poSurface.channel = uvChannel;
|
||||
poSurface.exist = true;
|
||||
} else {
|
||||
if (pSrcMat.GetTextureCount(pTexture) == 0) {
|
||||
if (pKey)
|
||||
poSurface.exist = pSrcMat.Get(pKey, static_cast<unsigned int>(pType), static_cast<unsigned int>(pIndex), poSurface.color) == aiReturn_SUCCESS;
|
||||
return poSurface.exist;
|
||||
}
|
||||
|
||||
aiString texfile;
|
||||
unsigned int uvChannel = 0;
|
||||
pSrcMat.GetTexture(pTexture, 0, &texfile, nullptr, &uvChannel);
|
||||
|
||||
std::string index_str(texfile.C_Str());
|
||||
|
||||
if (index_str.size() != 0 && index_str[0] == '*') {
|
||||
unsigned int index;
|
||||
|
||||
index_str = index_str.substr(1, std::string::npos);
|
||||
|
||||
try {
|
||||
index = (unsigned int)strtoul10_64<DeadlyExportError>(index_str.c_str());
|
||||
} catch (std::exception &error) {
|
||||
throw DeadlyExportError(error.what());
|
||||
}
|
||||
|
||||
std::map<unsigned int, std::string>::const_iterator name = textures.find(index);
|
||||
|
||||
if (name != textures.end()) {
|
||||
poSurface.texture = name->second;
|
||||
} else {
|
||||
throw DeadlyExportError("could not find embedded texture at index " + index_str);
|
||||
}
|
||||
} else {
|
||||
poSurface.texture = texfile.C_Str();
|
||||
}
|
||||
|
||||
poSurface.channel = uvChannel;
|
||||
poSurface.exist = true;
|
||||
|
||||
return poSurface.exist;
|
||||
}
|
||||
|
||||
|
|
@ -606,79 +643,87 @@ static bool isalnum_C(char c) {
|
|||
// ------------------------------------------------------------------------------------------------
|
||||
// Writes an image entry for the given surface
|
||||
void ColladaExporter::WriteImageEntry(const Surface &pSurface, const std::string &imageId) {
|
||||
if (!pSurface.texture.empty()) {
|
||||
mOutput << startstr << "<image id=\"" << imageId << "\">" << endstr;
|
||||
PushTag();
|
||||
mOutput << startstr << "<init_from>";
|
||||
|
||||
// URL encode image file name first, then XML encode on top
|
||||
std::stringstream imageUrlEncoded;
|
||||
for (std::string::const_iterator it = pSurface.texture.begin(); it != pSurface.texture.end(); ++it) {
|
||||
if (isalnum_C((unsigned char)*it) || *it == ':' || *it == '_' || *it == '-' || *it == '.' || *it == '/' || *it == '\\')
|
||||
imageUrlEncoded << *it;
|
||||
else
|
||||
imageUrlEncoded << '%' << std::hex << size_t((unsigned char)*it) << std::dec;
|
||||
}
|
||||
mOutput << XMLEscape(imageUrlEncoded.str());
|
||||
mOutput << "</init_from>" << endstr;
|
||||
PopTag();
|
||||
mOutput << startstr << "</image>" << endstr;
|
||||
if (pSurface.texture.empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
mOutput << startstr << "<image id=\"" << imageId << "\">" << endstr;
|
||||
PushTag();
|
||||
mOutput << startstr << "<init_from>";
|
||||
|
||||
// URL encode image file name first, then XML encode on top
|
||||
std::stringstream imageUrlEncoded;
|
||||
for (std::string::const_iterator it = pSurface.texture.begin(); it != pSurface.texture.end(); ++it) {
|
||||
if (isalnum_C((unsigned char)*it) || *it == ':' || *it == '_' || *it == '-' || *it == '.' || *it == '/' || *it == '\\')
|
||||
imageUrlEncoded << *it;
|
||||
else
|
||||
imageUrlEncoded << '%' << std::hex << size_t((unsigned char)*it) << std::dec;
|
||||
}
|
||||
mOutput << XMLEscape(imageUrlEncoded.str());
|
||||
mOutput << "</init_from>" << endstr;
|
||||
PopTag();
|
||||
mOutput << startstr << "</image>" << endstr;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Writes a color-or-texture entry into an effect definition
|
||||
void ColladaExporter::WriteTextureColorEntry(const Surface &pSurface, const std::string &pTypeName, const std::string &imageId) {
|
||||
if (pSurface.exist) {
|
||||
mOutput << startstr << "<" << pTypeName << ">" << endstr;
|
||||
PushTag();
|
||||
if (pSurface.texture.empty()) {
|
||||
mOutput << startstr << "<color sid=\"" << pTypeName << "\">" << pSurface.color.r << " " << pSurface.color.g << " " << pSurface.color.b << " " << pSurface.color.a << "</color>" << endstr;
|
||||
} else {
|
||||
mOutput << startstr << "<texture texture=\"" << imageId << "\" texcoord=\"CHANNEL" << pSurface.channel << "\" />" << endstr;
|
||||
}
|
||||
PopTag();
|
||||
mOutput << startstr << "</" << pTypeName << ">" << endstr;
|
||||
if (!pSurface.exist) {
|
||||
return;
|
||||
}
|
||||
|
||||
mOutput << startstr << "<" << pTypeName << ">" << endstr;
|
||||
PushTag();
|
||||
if (pSurface.texture.empty()) {
|
||||
mOutput << startstr << "<color sid=\"" << pTypeName << "\">" << pSurface.color.r << " " << pSurface.color.g << " " << pSurface.color.b << " " << pSurface.color.a << "</color>" << endstr;
|
||||
} else {
|
||||
mOutput << startstr << "<texture texture=\"" << imageId << "\" texcoord=\"CHANNEL" << pSurface.channel << "\" />" << endstr;
|
||||
}
|
||||
PopTag();
|
||||
mOutput << startstr << "</" << pTypeName << ">" << endstr;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Writes the two parameters necessary for referencing a texture in an effect entry
|
||||
void ColladaExporter::WriteTextureParamEntry(const Surface &pSurface, const std::string &pTypeName, const std::string &materialId) {
|
||||
// if surface is a texture, write out the sampler and the surface parameters necessary to reference the texture
|
||||
if (!pSurface.texture.empty()) {
|
||||
mOutput << startstr << "<newparam sid=\"" << materialId << "-" << pTypeName << "-surface\">" << endstr;
|
||||
PushTag();
|
||||
mOutput << startstr << "<surface type=\"2D\">" << endstr;
|
||||
PushTag();
|
||||
mOutput << startstr << "<init_from>" << materialId << "-" << pTypeName << "-image</init_from>" << endstr;
|
||||
PopTag();
|
||||
mOutput << startstr << "</surface>" << endstr;
|
||||
PopTag();
|
||||
mOutput << startstr << "</newparam>" << endstr;
|
||||
|
||||
mOutput << startstr << "<newparam sid=\"" << materialId << "-" << pTypeName << "-sampler\">" << endstr;
|
||||
PushTag();
|
||||
mOutput << startstr << "<sampler2D>" << endstr;
|
||||
PushTag();
|
||||
mOutput << startstr << "<source>" << materialId << "-" << pTypeName << "-surface</source>" << endstr;
|
||||
PopTag();
|
||||
mOutput << startstr << "</sampler2D>" << endstr;
|
||||
PopTag();
|
||||
mOutput << startstr << "</newparam>" << endstr;
|
||||
if (pSurface.texture.empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
mOutput << startstr << "<newparam sid=\"" << materialId << "-" << pTypeName << "-surface\">" << endstr;
|
||||
PushTag();
|
||||
mOutput << startstr << "<surface type=\"2D\">" << endstr;
|
||||
PushTag();
|
||||
mOutput << startstr << "<init_from>" << materialId << "-" << pTypeName << "-image</init_from>" << endstr;
|
||||
PopTag();
|
||||
mOutput << startstr << "</surface>" << endstr;
|
||||
PopTag();
|
||||
mOutput << startstr << "</newparam>" << endstr;
|
||||
|
||||
mOutput << startstr << "<newparam sid=\"" << materialId << "-" << pTypeName << "-sampler\">" << endstr;
|
||||
PushTag();
|
||||
mOutput << startstr << "<sampler2D>" << endstr;
|
||||
PushTag();
|
||||
mOutput << startstr << "<source>" << materialId << "-" << pTypeName << "-surface</source>" << endstr;
|
||||
PopTag();
|
||||
mOutput << startstr << "</sampler2D>" << endstr;
|
||||
PopTag();
|
||||
mOutput << startstr << "</newparam>" << endstr;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Writes a scalar property
|
||||
void ColladaExporter::WriteFloatEntry(const Property &pProperty, const std::string &pTypeName) {
|
||||
if (pProperty.exist) {
|
||||
mOutput << startstr << "<" << pTypeName << ">" << endstr;
|
||||
PushTag();
|
||||
mOutput << startstr << "<float sid=\"" << pTypeName << "\">" << pProperty.value << "</float>" << endstr;
|
||||
PopTag();
|
||||
mOutput << startstr << "</" << pTypeName << ">" << endstr;
|
||||
if (!pProperty.exist) {
|
||||
return;
|
||||
}
|
||||
|
||||
mOutput << startstr << "<" << pTypeName << ">" << endstr;
|
||||
PushTag();
|
||||
mOutput << startstr << "<float sid=\"" << pTypeName << "\">" << pProperty.value << "</float>" << endstr;
|
||||
PopTag();
|
||||
mOutput << startstr << "</" << pTypeName << ">" << endstr;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
|
@ -832,8 +877,9 @@ void ColladaExporter::WriteControllerLibrary() {
|
|||
void ColladaExporter::WriteController(size_t pIndex) {
|
||||
const aiMesh *mesh = mScene->mMeshes[pIndex];
|
||||
// Is there a skin controller?
|
||||
if (mesh->mNumBones == 0 || mesh->mNumFaces == 0 || mesh->mNumVertices == 0)
|
||||
if (mesh->mNumBones == 0 || mesh->mNumFaces == 0 || mesh->mNumVertices == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
const std::string idstr = GetObjectUniqueId(AiObjectType::Mesh, pIndex);
|
||||
const std::string namestr = GetObjectName(AiObjectType::Mesh, pIndex);
|
||||
|
|
@ -864,8 +910,9 @@ void ColladaExporter::WriteController(size_t pIndex) {
|
|||
|
||||
mOutput << startstr << "<Name_array id=\"" << idstr << "-skin-joints-array\" count=\"" << mesh->mNumBones << "\">";
|
||||
|
||||
for (size_t i = 0; i < mesh->mNumBones; ++i)
|
||||
for (size_t i = 0; i < mesh->mNumBones; ++i) {
|
||||
mOutput << GetBoneUniqueId(mesh->mBones[i]) << ' ';
|
||||
}
|
||||
|
||||
mOutput << "</Name_array>" << endstr;
|
||||
|
||||
|
|
@ -888,9 +935,11 @@ void ColladaExporter::WriteController(size_t pIndex) {
|
|||
|
||||
std::vector<ai_real> bind_poses;
|
||||
bind_poses.reserve(mesh->mNumBones * 16);
|
||||
for (unsigned int i = 0; i < mesh->mNumBones; ++i)
|
||||
for (unsigned int j = 0; j < 4; ++j)
|
||||
for (unsigned int i = 0; i < mesh->mNumBones; ++i) {
|
||||
for (unsigned int j = 0; j < 4; ++j) {
|
||||
bind_poses.insert(bind_poses.end(), mesh->mBones[i]->mOffsetMatrix[j], mesh->mBones[i]->mOffsetMatrix[j] + 4);
|
||||
}
|
||||
}
|
||||
|
||||
WriteFloatArray(idstr + "-skin-bind_poses", FloatType_Mat4x4, (const ai_real *)bind_poses.data(), bind_poses.size() / 16);
|
||||
|
||||
|
|
@ -898,9 +947,11 @@ void ColladaExporter::WriteController(size_t pIndex) {
|
|||
|
||||
std::vector<ai_real> skin_weights;
|
||||
skin_weights.reserve(mesh->mNumVertices * mesh->mNumBones);
|
||||
for (size_t i = 0; i < mesh->mNumBones; ++i)
|
||||
for (size_t j = 0; j < mesh->mBones[i]->mNumWeights; ++j)
|
||||
for (size_t i = 0; i < mesh->mNumBones; ++i) {
|
||||
for (size_t j = 0; j < mesh->mBones[i]->mNumWeights; ++j) {
|
||||
skin_weights.push_back(mesh->mBones[i]->mWeights[j].mWeight);
|
||||
}
|
||||
}
|
||||
|
||||
WriteFloatArray(idstr + "-skin-weights", FloatType_Weight, (const ai_real *)skin_weights.data(), skin_weights.size());
|
||||
|
||||
|
|
@ -924,12 +975,15 @@ void ColladaExporter::WriteController(size_t pIndex) {
|
|||
mOutput << startstr << "<vcount>";
|
||||
|
||||
std::vector<ai_uint> num_influences(mesh->mNumVertices, (ai_uint)0);
|
||||
for (size_t i = 0; i < mesh->mNumBones; ++i)
|
||||
for (size_t j = 0; j < mesh->mBones[i]->mNumWeights; ++j)
|
||||
for (size_t i = 0; i < mesh->mNumBones; ++i) {
|
||||
for (size_t j = 0; j < mesh->mBones[i]->mNumWeights; ++j) {
|
||||
++num_influences[mesh->mBones[i]->mWeights[j].mVertexId];
|
||||
}
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < mesh->mNumVertices; ++i)
|
||||
for (size_t i = 0; i < mesh->mNumVertices; ++i) {
|
||||
mOutput << num_influences[i] << " ";
|
||||
}
|
||||
|
||||
mOutput << "</vcount>" << endstr;
|
||||
|
||||
|
|
@ -945,7 +999,7 @@ void ColladaExporter::WriteController(size_t pIndex) {
|
|||
|
||||
ai_uint weight_index = 0;
|
||||
std::vector<ai_int> joint_weight_indices(2 * joint_weight_indices_length, (ai_int)-1);
|
||||
for (unsigned int i = 0; i < mesh->mNumBones; ++i)
|
||||
for (unsigned int i = 0; i < mesh->mNumBones; ++i) {
|
||||
for (unsigned j = 0; j < mesh->mBones[i]->mNumWeights; ++j) {
|
||||
unsigned int vId = mesh->mBones[i]->mWeights[j].mVertexId;
|
||||
for (ai_uint k = 0; k < num_influences[vId]; ++k) {
|
||||
|
|
@ -957,9 +1011,11 @@ void ColladaExporter::WriteController(size_t pIndex) {
|
|||
}
|
||||
++weight_index;
|
||||
}
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < joint_weight_indices.size(); ++i)
|
||||
for (size_t i = 0; i < joint_weight_indices.size(); ++i) {
|
||||
mOutput << joint_weight_indices[i] << " ";
|
||||
}
|
||||
|
||||
num_influences.clear();
|
||||
accum_influences.clear();
|
||||
|
|
@ -983,8 +1039,9 @@ void ColladaExporter::WriteGeometryLibrary() {
|
|||
mOutput << startstr << "<library_geometries>" << endstr;
|
||||
PushTag();
|
||||
|
||||
for (size_t a = 0; a < mScene->mNumMeshes; ++a)
|
||||
for (size_t a = 0; a < mScene->mNumMeshes; ++a) {
|
||||
WriteGeometry(a);
|
||||
}
|
||||
|
||||
PopTag();
|
||||
mOutput << startstr << "</library_geometries>" << endstr;
|
||||
|
|
@ -997,8 +1054,9 @@ void ColladaExporter::WriteGeometry(size_t pIndex) {
|
|||
const std::string geometryId = GetObjectUniqueId(AiObjectType::Mesh, pIndex);
|
||||
const std::string geometryName = GetObjectName(AiObjectType::Mesh, pIndex);
|
||||
|
||||
if (mesh->mNumFaces == 0 || mesh->mNumVertices == 0)
|
||||
if (mesh->mNumFaces == 0 || mesh->mNumVertices == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
// opening tag
|
||||
mOutput << startstr << "<geometry id=\"" << geometryId << "\" name=\"" << geometryName << "\" >" << endstr;
|
||||
|
|
@ -1010,8 +1068,9 @@ void ColladaExporter::WriteGeometry(size_t pIndex) {
|
|||
// Positions
|
||||
WriteFloatArray(geometryId + "-positions", FloatType_Vector, (ai_real *)mesh->mVertices, mesh->mNumVertices);
|
||||
// Normals, if any
|
||||
if (mesh->HasNormals())
|
||||
if (mesh->HasNormals()) {
|
||||
WriteFloatArray(geometryId + "-normals", FloatType_Vector, (ai_real *)mesh->mNormals, mesh->mNumVertices);
|
||||
}
|
||||
|
||||
// texture coords
|
||||
for (size_t a = 0; a < AI_MAX_NUMBER_OF_TEXTURECOORDS; ++a) {
|
||||
|
|
@ -1040,10 +1099,11 @@ void ColladaExporter::WriteGeometry(size_t pIndex) {
|
|||
int countLines = 0;
|
||||
int countPoly = 0;
|
||||
for (size_t a = 0; a < mesh->mNumFaces; ++a) {
|
||||
if (mesh->mFaces[a].mNumIndices == 2)
|
||||
if (mesh->mFaces[a].mNumIndices == 2) {
|
||||
countLines++;
|
||||
else if (mesh->mFaces[a].mNumIndices >= 3)
|
||||
} else if (mesh->mFaces[a].mNumIndices >= 3) {
|
||||
countPoly++;
|
||||
}
|
||||
}
|
||||
|
||||
// lines
|
||||
|
|
@ -1051,13 +1111,18 @@ void ColladaExporter::WriteGeometry(size_t pIndex) {
|
|||
mOutput << startstr << "<lines count=\"" << countLines << "\" material=\"defaultMaterial\">" << endstr;
|
||||
PushTag();
|
||||
mOutput << startstr << "<input offset=\"0\" semantic=\"VERTEX\" source=\"#" << geometryId << "-vertices\" />" << endstr;
|
||||
if (mesh->HasNormals())
|
||||
if (mesh->HasNormals()) {
|
||||
mOutput << startstr << "<input semantic=\"NORMAL\" source=\"#" << geometryId << "-normals\" />" << endstr;
|
||||
}
|
||||
for (size_t a = 0; a < AI_MAX_NUMBER_OF_TEXTURECOORDS; ++a) {
|
||||
if (mesh->HasTextureCoords(static_cast<unsigned int>(a)))
|
||||
mOutput << startstr << "<input semantic=\"TEXCOORD\" source=\"#" << geometryId << "-tex" << a << "\" "
|
||||
if (mesh->HasTextureCoords(static_cast<unsigned int>(a))) {
|
||||
mOutput << startstr
|
||||
<< "<input semantic=\"TEXCOORD\" source=\"#"
|
||||
<< geometryId
|
||||
<< "-tex" << a << "\" "
|
||||
<< "set=\"" << a << "\""
|
||||
<< " />" << endstr;
|
||||
}
|
||||
}
|
||||
for (size_t a = 0; a < AI_MAX_NUMBER_OF_COLOR_SETS; ++a) {
|
||||
if (mesh->HasVertexColors(static_cast<unsigned int>(a)))
|
||||
|
|
@ -1070,8 +1135,9 @@ void ColladaExporter::WriteGeometry(size_t pIndex) {
|
|||
for (size_t a = 0; a < mesh->mNumFaces; ++a) {
|
||||
const aiFace &face = mesh->mFaces[a];
|
||||
if (face.mNumIndices != 2) continue;
|
||||
for (size_t b = 0; b < face.mNumIndices; ++b)
|
||||
for (size_t b = 0; b < face.mNumIndices; ++b) {
|
||||
mOutput << face.mIndices[b] << " ";
|
||||
}
|
||||
}
|
||||
mOutput << "</p>" << endstr;
|
||||
PopTag();
|
||||
|
|
@ -1085,8 +1151,9 @@ void ColladaExporter::WriteGeometry(size_t pIndex) {
|
|||
mOutput << startstr << "<polylist count=\"" << countPoly << "\" material=\"defaultMaterial\">" << endstr;
|
||||
PushTag();
|
||||
mOutput << startstr << "<input offset=\"0\" semantic=\"VERTEX\" source=\"#" << geometryId << "-vertices\" />" << endstr;
|
||||
if (mesh->HasNormals())
|
||||
if (mesh->HasNormals()) {
|
||||
mOutput << startstr << "<input offset=\"0\" semantic=\"NORMAL\" source=\"#" << geometryId << "-normals\" />" << endstr;
|
||||
}
|
||||
for (size_t a = 0; a < AI_MAX_NUMBER_OF_TEXTURECOORDS; ++a) {
|
||||
if (mesh->HasTextureCoords(static_cast<unsigned int>(a)))
|
||||
mOutput << startstr << "<input offset=\"0\" semantic=\"TEXCOORD\" source=\"#" << geometryId << "-tex" << a << "\" "
|
||||
|
|
@ -1111,8 +1178,9 @@ void ColladaExporter::WriteGeometry(size_t pIndex) {
|
|||
for (size_t a = 0; a < mesh->mNumFaces; ++a) {
|
||||
const aiFace &face = mesh->mFaces[a];
|
||||
if (face.mNumIndices < 3) continue;
|
||||
for (size_t b = 0; b < face.mNumIndices; ++b)
|
||||
for (size_t b = 0; b < face.mNumIndices; ++b) {
|
||||
mOutput << face.mIndices[b] << " ";
|
||||
}
|
||||
}
|
||||
mOutput << "</p>" << endstr;
|
||||
PopTag();
|
||||
|
|
@ -1131,13 +1199,27 @@ void ColladaExporter::WriteGeometry(size_t pIndex) {
|
|||
void ColladaExporter::WriteFloatArray(const std::string &pIdString, FloatDataType pType, const ai_real *pData, size_t pElementCount) {
|
||||
size_t floatsPerElement = 0;
|
||||
switch (pType) {
|
||||
case FloatType_Vector: floatsPerElement = 3; break;
|
||||
case FloatType_TexCoord2: floatsPerElement = 2; break;
|
||||
case FloatType_TexCoord3: floatsPerElement = 3; break;
|
||||
case FloatType_Color: floatsPerElement = 3; break;
|
||||
case FloatType_Mat4x4: floatsPerElement = 16; break;
|
||||
case FloatType_Weight: floatsPerElement = 1; break;
|
||||
case FloatType_Time: floatsPerElement = 1; break;
|
||||
case FloatType_Vector:
|
||||
floatsPerElement = 3;
|
||||
break;
|
||||
case FloatType_TexCoord2:
|
||||
floatsPerElement = 2;
|
||||
break;
|
||||
case FloatType_TexCoord3:
|
||||
floatsPerElement = 3;
|
||||
break;
|
||||
case FloatType_Color:
|
||||
floatsPerElement = 3;
|
||||
break;
|
||||
case FloatType_Mat4x4:
|
||||
floatsPerElement = 16;
|
||||
break;
|
||||
case FloatType_Weight:
|
||||
floatsPerElement = 1;
|
||||
break;
|
||||
case FloatType_Time:
|
||||
floatsPerElement = 1;
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
|
@ -1163,8 +1245,9 @@ void ColladaExporter::WriteFloatArray(const std::string &pIdString, FloatDataTyp
|
|||
mOutput << pData[a * 4 + 2] << " ";
|
||||
}
|
||||
} else {
|
||||
for (size_t a = 0; a < pElementCount * floatsPerElement; ++a)
|
||||
for (size_t a = 0; a < pElementCount * floatsPerElement; ++a) {
|
||||
mOutput << pData[a] << " ";
|
||||
}
|
||||
}
|
||||
mOutput << "</float_array>" << endstr;
|
||||
PopTag();
|
||||
|
|
@ -1256,9 +1339,13 @@ void ColladaExporter::WriteSceneLibrary() {
|
|||
// ------------------------------------------------------------------------------------------------
|
||||
void ColladaExporter::WriteAnimationLibrary(size_t pIndex) {
|
||||
const aiAnimation *anim = mScene->mAnimations[pIndex];
|
||||
|
||||
if (anim->mNumChannels == 0 && anim->mNumMeshChannels == 0 && anim->mNumMorphMeshChannels == 0)
|
||||
if (anim == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (anim->mNumChannels == 0 && anim->mNumMeshChannels == 0 && anim->mNumMorphMeshChannels == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
const std::string animationNameEscaped = GetObjectName(AiObjectType::Animation, pIndex);
|
||||
const std::string idstrEscaped = GetObjectUniqueId(AiObjectType::Animation, pIndex);
|
||||
|
|
@ -1269,8 +1356,11 @@ void ColladaExporter::WriteAnimationLibrary(size_t pIndex) {
|
|||
std::string cur_node_idstr;
|
||||
for (size_t a = 0; a < anim->mNumChannels; ++a) {
|
||||
const aiNodeAnim *nodeAnim = anim->mChannels[a];
|
||||
if (nodeAnim == nullptr) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// sanity check
|
||||
// sanity checks
|
||||
if (nodeAnim->mNumPositionKeys != nodeAnim->mNumScalingKeys || nodeAnim->mNumPositionKeys != nodeAnim->mNumRotationKeys) {
|
||||
continue;
|
||||
}
|
||||
|
|
@ -1369,6 +1459,9 @@ void ColladaExporter::WriteAnimationLibrary(size_t pIndex) {
|
|||
|
||||
for (size_t a = 0; a < anim->mNumChannels; ++a) {
|
||||
const aiNodeAnim *nodeAnim = anim->mChannels[a];
|
||||
if (nodeAnim == nullptr) {
|
||||
continue;
|
||||
}
|
||||
|
||||
{
|
||||
// samplers
|
||||
|
|
@ -1387,97 +1480,42 @@ void ColladaExporter::WriteAnimationLibrary(size_t pIndex) {
|
|||
|
||||
for (size_t a = 0; a < anim->mNumChannels; ++a) {
|
||||
const aiNodeAnim *nodeAnim = anim->mChannels[a];
|
||||
if (nodeAnim == nullptr) {
|
||||
continue;
|
||||
}
|
||||
|
||||
{
|
||||
// channels
|
||||
mOutput << startstr << "<channel source=\"#" << XMLIDEncode(nodeAnim->mNodeName.data + std::string("_matrix-sampler")) << "\" target=\"" << XMLIDEncode(nodeAnim->mNodeName.data) << "/matrix\"/>" << endstr;
|
||||
mOutput << startstr
|
||||
<< "<channel source=\"#"
|
||||
<< XMLIDEncode(nodeAnim->mNodeName.data + std::string("_matrix-sampler"))
|
||||
<< "\" target=\""
|
||||
<< XMLIDEncode(nodeAnim->mNodeName.data)
|
||||
<< "/matrix\"/>"
|
||||
<< endstr;
|
||||
}
|
||||
}
|
||||
|
||||
PopTag();
|
||||
mOutput << startstr << "</animation>" << endstr;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void ColladaExporter::WriteAnimationsLibrary() {
|
||||
if (mScene->mNumAnimations > 0) {
|
||||
mOutput << startstr << "<library_animations>" << endstr;
|
||||
PushTag();
|
||||
|
||||
// start recursive write at the root node
|
||||
for (size_t a = 0; a < mScene->mNumAnimations; ++a)
|
||||
WriteAnimationLibrary(a);
|
||||
|
||||
PopTag();
|
||||
mOutput << startstr << "</library_animations>" << endstr;
|
||||
}
|
||||
}
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Helper to find a bone by name in the scene
|
||||
aiBone *findBone(const aiScene *scene, const aiString &name) {
|
||||
for (size_t m = 0; m < scene->mNumMeshes; m++) {
|
||||
aiMesh *mesh = scene->mMeshes[m];
|
||||
for (size_t b = 0; b < mesh->mNumBones; b++) {
|
||||
aiBone *bone = mesh->mBones[b];
|
||||
if (name == bone->mName) {
|
||||
return bone;
|
||||
}
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Helper to find the node associated with a bone in the scene
|
||||
const aiNode *findBoneNode(const aiNode *aNode, const aiBone *bone) {
|
||||
if (aNode && bone && aNode->mName == bone->mName) {
|
||||
return aNode;
|
||||
if (mScene->mNumAnimations == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (aNode && bone) {
|
||||
for (unsigned int i = 0; i < aNode->mNumChildren; ++i) {
|
||||
aiNode *aChild = aNode->mChildren[i];
|
||||
const aiNode *foundFromChild = nullptr;
|
||||
if (aChild) {
|
||||
foundFromChild = findBoneNode(aChild, bone);
|
||||
if (foundFromChild) {
|
||||
return foundFromChild;
|
||||
}
|
||||
}
|
||||
}
|
||||
mOutput << startstr << "<library_animations>" << endstr;
|
||||
PushTag();
|
||||
|
||||
// start recursive write at the root node
|
||||
for (size_t a = 0; a < mScene->mNumAnimations; ++a) {
|
||||
WriteAnimationLibrary(a);
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const aiNode *findSkeletonRootNode(const aiScene *scene, const aiMesh *mesh) {
|
||||
std::set<const aiNode *> topParentBoneNodes;
|
||||
if (mesh && mesh->mNumBones > 0) {
|
||||
for (unsigned int i = 0; i < mesh->mNumBones; ++i) {
|
||||
aiBone *bone = mesh->mBones[i];
|
||||
|
||||
const aiNode *node = findBoneNode(scene->mRootNode, bone);
|
||||
if (node) {
|
||||
while (node->mParent && findBone(scene, node->mParent->mName) != nullptr) {
|
||||
node = node->mParent;
|
||||
}
|
||||
topParentBoneNodes.insert(node);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!topParentBoneNodes.empty()) {
|
||||
const aiNode *parentBoneNode = *topParentBoneNodes.begin();
|
||||
if (topParentBoneNodes.size() == 1) {
|
||||
return parentBoneNode;
|
||||
} else {
|
||||
for (auto it : topParentBoneNodes) {
|
||||
if (it->mParent) return it->mParent;
|
||||
}
|
||||
return parentBoneNode;
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
PopTag();
|
||||
mOutput << startstr << "</library_animations>" << endstr;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
|
@ -1488,13 +1526,13 @@ void ColladaExporter::WriteNode(const aiNode *pNode) {
|
|||
// Assimp-specific: nodes with no name cannot be associated with bones
|
||||
const char *node_type;
|
||||
bool is_joint, is_skeleton_root = false;
|
||||
if (pNode->mName.length == 0 || nullptr == findBone(mScene, pNode->mName)) {
|
||||
if (pNode->mName.length == 0 || nullptr == mScene->findBone(pNode->mName)) {
|
||||
node_type = "NODE";
|
||||
is_joint = false;
|
||||
} else {
|
||||
node_type = "JOINT";
|
||||
is_joint = true;
|
||||
if (!pNode->mParent || nullptr == findBone(mScene, pNode->mParent->mName)) {
|
||||
if (!pNode->mParent || nullptr == mScene->findBone(pNode->mParent->mName)) {
|
||||
is_skeleton_root = true;
|
||||
}
|
||||
}
|
||||
|
|
@ -1532,7 +1570,6 @@ void ColladaExporter::WriteNode(const aiNode *pNode) {
|
|||
}
|
||||
|
||||
// customized, sid should be 'matrix' to match with loader code.
|
||||
//mOutput << startstr << "<matrix sid=\"transform\">";
|
||||
mOutput << startstr << "<matrix sid=\"matrix\">";
|
||||
|
||||
mOutput << mat.a1 << " " << mat.a2 << " " << mat.a3 << " " << mat.a4 << " ";
|
||||
|
|
@ -1556,7 +1593,6 @@ void ColladaExporter::WriteNode(const aiNode *pNode) {
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
} else
|
||||
// instance every geometry
|
||||
for (size_t a = 0; a < pNode->mNumMeshes; ++a) {
|
||||
|
|
@ -1612,8 +1648,9 @@ void ColladaExporter::WriteNode(const aiNode *pNode) {
|
|||
}
|
||||
|
||||
// recurse into subnodes
|
||||
for (size_t a = 0; a < pNode->mNumChildren; ++a)
|
||||
for (size_t a = 0; a < pNode->mNumChildren; ++a) {
|
||||
WriteNode(pNode->mChildren[a]);
|
||||
}
|
||||
|
||||
PopTag();
|
||||
mOutput << startstr << "</node>" << endstr;
|
||||
|
|
@ -1628,8 +1665,9 @@ void ColladaExporter::CreateNodeIds(const aiNode *node) {
|
|||
std::string ColladaExporter::GetNodeUniqueId(const aiNode *node) {
|
||||
// Use the pointer as the key. This is safe because the scene is immutable.
|
||||
auto idIt = mNodeIdMap.find(node);
|
||||
if (idIt != mNodeIdMap.cend())
|
||||
if (idIt != mNodeIdMap.cend()) {
|
||||
return idIt->second;
|
||||
}
|
||||
|
||||
// Prefer the requested Collada Id if extant
|
||||
std::string idStr;
|
||||
|
|
@ -1640,36 +1678,42 @@ std::string ColladaExporter::GetNodeUniqueId(const aiNode *node) {
|
|||
idStr = node->mName.C_Str();
|
||||
}
|
||||
// Make sure the requested id is valid
|
||||
if (idStr.empty())
|
||||
if (idStr.empty()) {
|
||||
idStr = "node";
|
||||
else
|
||||
} else {
|
||||
idStr = XMLIDEncode(idStr);
|
||||
}
|
||||
|
||||
// Ensure it's unique
|
||||
idStr = MakeUniqueId(mUniqueIds, idStr, std::string());
|
||||
mUniqueIds.insert(idStr);
|
||||
mNodeIdMap.insert(std::make_pair(node, idStr));
|
||||
|
||||
return idStr;
|
||||
}
|
||||
|
||||
std::string ColladaExporter::GetNodeName(const aiNode *node) {
|
||||
|
||||
if (node == nullptr) {
|
||||
return std::string();
|
||||
}
|
||||
return XMLEscape(node->mName.C_Str());
|
||||
}
|
||||
|
||||
std::string ColladaExporter::GetBoneUniqueId(const aiBone *bone) {
|
||||
// Find the Node that is this Bone
|
||||
const aiNode *boneNode = findBoneNode(mScene->mRootNode, bone);
|
||||
if (boneNode == nullptr)
|
||||
const aiNode *boneNode = mScene->mRootNode->findBoneNode(bone);
|
||||
if (boneNode == nullptr) {
|
||||
return std::string();
|
||||
}
|
||||
|
||||
return GetNodeUniqueId(boneNode);
|
||||
}
|
||||
|
||||
std::string ColladaExporter::GetObjectUniqueId(AiObjectType type, size_t pIndex) {
|
||||
auto idIt = GetObjectIdMap(type).find(pIndex);
|
||||
if (idIt != GetObjectIdMap(type).cend())
|
||||
if (idIt != GetObjectIdMap(type).cend()) {
|
||||
return idIt->second;
|
||||
}
|
||||
|
||||
// Not seen this object before, create and add
|
||||
NameIdPair result = AddObjectIndexToMaps(type, pIndex);
|
||||
|
|
@ -1678,8 +1722,9 @@ std::string ColladaExporter::GetObjectUniqueId(AiObjectType type, size_t pIndex)
|
|||
|
||||
std::string ColladaExporter::GetObjectName(AiObjectType type, size_t pIndex) {
|
||||
auto objectName = GetObjectNameMap(type).find(pIndex);
|
||||
if (objectName != GetObjectNameMap(type).cend())
|
||||
if (objectName != GetObjectNameMap(type).cend()) {
|
||||
return objectName->second;
|
||||
}
|
||||
|
||||
// Not seen this object before, create and add
|
||||
NameIdPair result = AddObjectIndexToMaps(type, pIndex);
|
||||
|
|
@ -1699,9 +1744,15 @@ ColladaExporter::NameIdPair ColladaExporter::AddObjectIndexToMaps(AiObjectType t
|
|||
|
||||
// Get the name and id postfix
|
||||
switch (type) {
|
||||
case AiObjectType::Mesh: name = mScene->mMeshes[index]->mName.C_Str(); break;
|
||||
case AiObjectType::Material: name = mScene->mMaterials[index]->GetName().C_Str(); break;
|
||||
case AiObjectType::Animation: name = mScene->mAnimations[index]->mName.C_Str(); break;
|
||||
case AiObjectType::Mesh:
|
||||
name = mScene->mMeshes[index]->mName.C_Str();
|
||||
break;
|
||||
case AiObjectType::Material:
|
||||
name = mScene->mMaterials[index]->GetName().C_Str();
|
||||
break;
|
||||
case AiObjectType::Animation:
|
||||
name = mScene->mAnimations[index]->mName.C_Str();
|
||||
break;
|
||||
case AiObjectType::Light:
|
||||
name = mScene->mLights[index]->mName.C_Str();
|
||||
idPostfix = "-light";
|
||||
|
|
@ -1710,7 +1761,8 @@ ColladaExporter::NameIdPair ColladaExporter::AddObjectIndexToMaps(AiObjectType t
|
|||
name = mScene->mCameras[index]->mName.C_Str();
|
||||
idPostfix = "-camera";
|
||||
break;
|
||||
case AiObjectType::Count: throw std::logic_error("ColladaExporter::AiObjectType::Count is not an object type");
|
||||
case AiObjectType::Count:
|
||||
throw std::logic_error("ColladaExporter::AiObjectType::Count is not an object type");
|
||||
}
|
||||
|
||||
if (name.empty()) {
|
||||
|
|
@ -1728,8 +1780,9 @@ ColladaExporter::NameIdPair ColladaExporter::AddObjectIndexToMaps(AiObjectType t
|
|||
idStr = XMLIDEncode(name);
|
||||
}
|
||||
|
||||
if (!name.empty())
|
||||
if (!name.empty()) {
|
||||
name = XMLEscape(name);
|
||||
}
|
||||
|
||||
idStr = MakeUniqueId(mUniqueIds, idStr, idPostfix);
|
||||
|
||||
|
|
@ -1743,5 +1796,5 @@ ColladaExporter::NameIdPair ColladaExporter::AddObjectIndexToMaps(AiObjectType t
|
|||
|
||||
} // end of namespace Assimp
|
||||
|
||||
#endif
|
||||
#endif
|
||||
#endif // ASSIMP_BUILD_NO_COLLADA_EXPORTER
|
||||
#endif // ASSIMP_BUILD_NO_EXPORT
|
||||
|
|
|
|||
|
|
@ -2,8 +2,7 @@
|
|||
Open Asset Import Library (assimp)
|
||||
----------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2024, assimp team
|
||||
|
||||
Copyright (c) 2006-2026, assimp team
|
||||
|
||||
All rights reserved.
|
||||
|
||||
|
|
@ -66,13 +65,13 @@ class IOSystem;
|
|||
|
||||
/// Helper class to export a given scene to a Collada file. Just for my personal
|
||||
/// comfort when implementing it.
|
||||
class ColladaExporter {
|
||||
class ColladaExporter final {
|
||||
public:
|
||||
/// Constructor for a specific scene to export
|
||||
ColladaExporter(const aiScene *pScene, IOSystem *pIOSystem, const std::string &path, const std::string &file);
|
||||
|
||||
/// Destructor
|
||||
virtual ~ColladaExporter();
|
||||
virtual ~ColladaExporter() = default;
|
||||
|
||||
protected:
|
||||
/// Starts writing the contents
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
Open Asset Import Library (assimp)
|
||||
----------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2024, assimp team
|
||||
Copyright (c) 2006-2026, assimp team
|
||||
|
||||
All rights reserved.
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
Open Asset Import Library (assimp)
|
||||
----------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2024, assimp team
|
||||
Copyright (c) 2006-2026, assimp team
|
||||
|
||||
All rights reserved.
|
||||
|
||||
|
|
@ -341,7 +341,7 @@ struct SubMesh {
|
|||
|
||||
/// Contains data for a single mesh
|
||||
struct Mesh {
|
||||
Mesh(const std::string &id) :
|
||||
explicit Mesh(const std::string &id) :
|
||||
mId(id) {
|
||||
for (unsigned int i = 0; i < AI_MAX_NUMBER_OF_TEXTURECOORDS; ++i) {
|
||||
mNumUVComponents[i] = 2;
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
Open Asset Import Library (assimp)
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2024, assimp team
|
||||
Copyright (c) 2006-2026, assimp team
|
||||
|
||||
All rights reserved.
|
||||
|
||||
|
|
@ -77,18 +77,26 @@ static constexpr aiImporterDesc desc = {
|
|||
"dae xml zae"
|
||||
};
|
||||
|
||||
static const float kMillisecondsFromSeconds = 1000.f;
|
||||
static constexpr float kMillisecondsFromSeconds = 1000.f;
|
||||
|
||||
// Add an item of metadata to a node
|
||||
// Assumes the key is not already in the list
|
||||
template <typename T>
|
||||
inline void AddNodeMetaData(aiNode *node, const std::string &key, const T &value) {
|
||||
void AddNodeMetaData(aiNode *node, const std::string &key, const T &value) {
|
||||
if (nullptr == node->mMetaData) {
|
||||
node->mMetaData = new aiMetadata();
|
||||
}
|
||||
node->mMetaData->Add(key, value);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Reads a float value from an accessor and its data array.
|
||||
static ai_real ReadFloat(const Accessor &pAccessor, const Data &pData, size_t pIndex, size_t pOffset) {
|
||||
const size_t pos = pAccessor.mStride * pIndex + pAccessor.mOffset + pOffset;
|
||||
ai_assert(pos < pData.mValues.size());
|
||||
return pData.mValues[pos];
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Constructor to be privately used by Importer
|
||||
ColladaLoader::ColladaLoader() :
|
||||
|
|
@ -152,7 +160,7 @@ void ColladaLoader::InternReadFile(const std::string &pFile, aiScene *pScene, IO
|
|||
throw DeadlyImportError("Collada: File came out empty. Something is wrong here.");
|
||||
}
|
||||
|
||||
// reserve some storage to avoid unnecessary reallocs
|
||||
// reserve some storage to avoid unnecessary reallocates
|
||||
newMats.reserve(parser.mMaterialLibrary.size() * 2u);
|
||||
mMeshes.reserve(parser.mMeshLibrary.size() * 2u);
|
||||
|
||||
|
|
@ -176,7 +184,7 @@ void ColladaLoader::InternReadFile(const std::string &pFile, aiScene *pScene, IO
|
|||
0, 0, parser.mUnitSize, 0,
|
||||
0, 0, 0, 1);
|
||||
}
|
||||
|
||||
|
||||
if (!ignoreUpDirection) {
|
||||
// Convert to Y_UP, if different orientation
|
||||
if (parser.mUpDirection == ColladaParser::UP_X) {
|
||||
|
|
@ -224,7 +232,7 @@ void ColladaLoader::InternReadFile(const std::string &pFile, aiScene *pScene, IO
|
|||
// Recursively constructs a scene node for the given parser node and returns it.
|
||||
aiNode *ColladaLoader::BuildHierarchy(const ColladaParser &pParser, const Collada::Node *pNode) {
|
||||
// create a node for it
|
||||
aiNode *node = new aiNode();
|
||||
auto *node = new aiNode();
|
||||
|
||||
// find a name for the new node. It's more complicated than you might think
|
||||
node->mName.Set(FindNameForNode(pNode));
|
||||
|
|
@ -272,24 +280,24 @@ aiNode *ColladaLoader::BuildHierarchy(const ColladaParser &pParser, const Collad
|
|||
// ------------------------------------------------------------------------------------------------
|
||||
// Resolve node instances
|
||||
void ColladaLoader::ResolveNodeInstances(const ColladaParser &pParser, const Node *pNode,
|
||||
std::vector<const Node*> &resolved) {
|
||||
std::vector<const Node*> &resolved) const {
|
||||
// reserve enough storage
|
||||
resolved.reserve(pNode->mNodeInstances.size());
|
||||
|
||||
// ... and iterate through all nodes to be instanced as children of pNode
|
||||
for (const auto &nodeInst : pNode->mNodeInstances) {
|
||||
for (const auto &[mNode] : pNode->mNodeInstances) {
|
||||
// find the corresponding node in the library
|
||||
const ColladaParser::NodeLibrary::const_iterator itt = pParser.mNodeLibrary.find(nodeInst.mNode);
|
||||
const auto itt = pParser.mNodeLibrary.find(mNode);
|
||||
const Node *nd = itt == pParser.mNodeLibrary.end() ? nullptr : (*itt).second;
|
||||
|
||||
// FIX for http://sourceforge.net/tracker/?func=detail&aid=3054873&group_id=226462&atid=1067632
|
||||
// need to check for both name and ID to catch all. To avoid breaking valid files,
|
||||
// the workaround is only enabled when the first attempt to resolve the node has failed.
|
||||
if (nullptr == nd) {
|
||||
nd = FindNode(pParser.mRootNode, nodeInst.mNode);
|
||||
nd = FindNode(pParser.mRootNode, mNode);
|
||||
}
|
||||
if (nullptr == nd) {
|
||||
ASSIMP_LOG_ERROR("Collada: Unable to resolve reference to instanced node ", nodeInst.mNode);
|
||||
ASSIMP_LOG_ERROR("Collada: Unable to resolve reference to instanced node ", mNode);
|
||||
} else {
|
||||
// attach this node to the list of children
|
||||
resolved.push_back(nd);
|
||||
|
|
@ -299,8 +307,8 @@ void ColladaLoader::ResolveNodeInstances(const ColladaParser &pParser, const Nod
|
|||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Resolve UV channels
|
||||
void ColladaLoader::ApplyVertexToEffectSemanticMapping(Sampler &sampler, const SemanticMappingTable &table) {
|
||||
SemanticMappingTable::InputSemanticMap::const_iterator it = table.mMap.find(sampler.mUVChannel);
|
||||
static void ApplyVertexToEffectSemanticMapping(Sampler &sampler, const SemanticMappingTable &table) {
|
||||
const auto it = table.mMap.find(sampler.mUVChannel);
|
||||
if (it == table.mMap.end()) {
|
||||
return;
|
||||
}
|
||||
|
|
@ -317,7 +325,7 @@ void ColladaLoader::ApplyVertexToEffectSemanticMapping(Sampler &sampler, const S
|
|||
void ColladaLoader::BuildLightsForNode(const ColladaParser &pParser, const Node *pNode, aiNode *pTarget) {
|
||||
for (const LightInstance &lid : pNode->mLights) {
|
||||
// find the referred light
|
||||
ColladaParser::LightLibrary::const_iterator srcLightIt = pParser.mLightLibrary.find(lid.mLight);
|
||||
auto srcLightIt = pParser.mLightLibrary.find(lid.mLight);
|
||||
if (srcLightIt == pParser.mLightLibrary.end()) {
|
||||
ASSIMP_LOG_WARN("Collada: Unable to find light for ID \"", lid.mLight, "\". Skipping.");
|
||||
continue;
|
||||
|
|
@ -325,7 +333,7 @@ void ColladaLoader::BuildLightsForNode(const ColladaParser &pParser, const Node
|
|||
const Collada::Light *srcLight = &srcLightIt->second;
|
||||
|
||||
// now fill our ai data structure
|
||||
aiLight *out = new aiLight();
|
||||
auto out = new aiLight();
|
||||
out->mName = pTarget->mName;
|
||||
out->mType = (aiLightSourceType)srcLight->mType;
|
||||
|
||||
|
|
@ -382,7 +390,7 @@ void ColladaLoader::BuildLightsForNode(const ColladaParser &pParser, const Node
|
|||
void ColladaLoader::BuildCamerasForNode(const ColladaParser &pParser, const Node *pNode, aiNode *pTarget) {
|
||||
for (const CameraInstance &cid : pNode->mCameras) {
|
||||
// find the referred light
|
||||
ColladaParser::CameraLibrary::const_iterator srcCameraIt = pParser.mCameraLibrary.find(cid.mCamera);
|
||||
auto srcCameraIt = pParser.mCameraLibrary.find(cid.mCamera);
|
||||
if (srcCameraIt == pParser.mCameraLibrary.end()) {
|
||||
ASSIMP_LOG_WARN("Collada: Unable to find camera for ID \"", cid.mCamera, "\". Skipping.");
|
||||
continue;
|
||||
|
|
@ -395,7 +403,7 @@ void ColladaLoader::BuildCamerasForNode(const ColladaParser &pParser, const Node
|
|||
}
|
||||
|
||||
// now fill our ai data structure
|
||||
aiCamera *out = new aiCamera();
|
||||
auto *out = new aiCamera();
|
||||
out->mName = pTarget->mName;
|
||||
|
||||
// collada cameras point in -Z by default, rest is specified in node transform
|
||||
|
|
@ -445,10 +453,10 @@ void ColladaLoader::BuildMeshesForNode(const ColladaParser &pParser, const Node
|
|||
const Controller *srcController = nullptr;
|
||||
|
||||
// find the referred mesh
|
||||
ColladaParser::MeshLibrary::const_iterator srcMeshIt = pParser.mMeshLibrary.find(mid.mMeshOrController);
|
||||
auto srcMeshIt = pParser.mMeshLibrary.find(mid.mMeshOrController);
|
||||
if (srcMeshIt == pParser.mMeshLibrary.end()) {
|
||||
// if not found in the mesh-library, it might also be a controller referring to a mesh
|
||||
ColladaParser::ControllerLibrary::const_iterator srcContrIt = pParser.mControllerLibrary.find(mid.mMeshOrController);
|
||||
auto srcContrIt = pParser.mControllerLibrary.find(mid.mMeshOrController);
|
||||
if (srcContrIt != pParser.mControllerLibrary.end()) {
|
||||
srcController = &srcContrIt->second;
|
||||
srcMeshIt = pParser.mMeshLibrary.find(srcController->mMeshId);
|
||||
|
|
@ -462,7 +470,7 @@ void ColladaLoader::BuildMeshesForNode(const ColladaParser &pParser, const Node
|
|||
continue;
|
||||
}
|
||||
} else {
|
||||
// ID found in the mesh library -> direct reference to an unskinned mesh
|
||||
// ID found in the mesh library -> direct reference to a not skinned mesh
|
||||
srcMesh = srcMeshIt->second;
|
||||
}
|
||||
|
||||
|
|
@ -476,7 +484,7 @@ void ColladaLoader::BuildMeshesForNode(const ColladaParser &pParser, const Node
|
|||
|
||||
// find material assigned to this submesh
|
||||
std::string meshMaterial;
|
||||
std::map<std::string, SemanticMappingTable>::const_iterator meshMatIt = mid.mMaterials.find(submesh.mMaterial);
|
||||
auto meshMatIt = mid.mMaterials.find(submesh.mMaterial);
|
||||
|
||||
const Collada::SemanticMappingTable *table = nullptr;
|
||||
if (meshMatIt != mid.mMaterials.end()) {
|
||||
|
|
@ -492,30 +500,34 @@ void ColladaLoader::BuildMeshesForNode(const ColladaParser &pParser, const Node
|
|||
|
||||
// OK ... here the *real* fun starts ... we have the vertex-input-to-effect-semantic-table
|
||||
// given. The only mapping stuff which we do actually support is the UV channel.
|
||||
std::map<std::string, size_t>::const_iterator matIt = mMaterialIndexByName.find(meshMaterial);
|
||||
auto matIt = mMaterialIndexByName.find(meshMaterial);
|
||||
unsigned int matIdx = 0;
|
||||
if (matIt != mMaterialIndexByName.end()) {
|
||||
matIdx = static_cast<unsigned int>(matIt->second);
|
||||
}
|
||||
|
||||
if (table && !table->mMap.empty()) {
|
||||
std::pair<Collada::Effect *, aiMaterial *> &mat = newMats[matIdx];
|
||||
if (matIdx < newMats.size()) {
|
||||
std::pair<Collada::Effect *, aiMaterial *> &mat = newMats[matIdx];
|
||||
|
||||
// Iterate through all texture channels assigned to the effect and
|
||||
// check whether we have mapping information for it.
|
||||
ApplyVertexToEffectSemanticMapping(mat.first->mTexDiffuse, *table);
|
||||
ApplyVertexToEffectSemanticMapping(mat.first->mTexAmbient, *table);
|
||||
ApplyVertexToEffectSemanticMapping(mat.first->mTexSpecular, *table);
|
||||
ApplyVertexToEffectSemanticMapping(mat.first->mTexEmissive, *table);
|
||||
ApplyVertexToEffectSemanticMapping(mat.first->mTexTransparent, *table);
|
||||
ApplyVertexToEffectSemanticMapping(mat.first->mTexBump, *table);
|
||||
// Iterate through all texture channels assigned to the effect and
|
||||
// check whether we have mapping information for it.
|
||||
ApplyVertexToEffectSemanticMapping(mat.first->mTexDiffuse, *table);
|
||||
ApplyVertexToEffectSemanticMapping(mat.first->mTexAmbient, *table);
|
||||
ApplyVertexToEffectSemanticMapping(mat.first->mTexSpecular, *table);
|
||||
ApplyVertexToEffectSemanticMapping(mat.first->mTexEmissive, *table);
|
||||
ApplyVertexToEffectSemanticMapping(mat.first->mTexTransparent, *table);
|
||||
ApplyVertexToEffectSemanticMapping(mat.first->mTexBump, *table);
|
||||
} else {
|
||||
ASSIMP_LOG_WARN("Collada: Ignoring material mapping for mesh \"", mid.mMeshOrController, "\". Material index ", matIdx, " is out of bounds (newMats.size()=", newMats.size(), ").");
|
||||
}
|
||||
}
|
||||
|
||||
// built lookup index of the Mesh-Submesh-Material combination
|
||||
ColladaMeshIndex index(mid.mMeshOrController, sm, meshMaterial);
|
||||
|
||||
// if we already have the mesh at the library, just add its index to the node's array
|
||||
std::map<ColladaMeshIndex, size_t>::const_iterator dstMeshIt = mMeshIndexByID.find(index);
|
||||
auto dstMeshIt = mMeshIndexByID.find(index);
|
||||
if (dstMeshIt != mMeshIndexByID.end()) {
|
||||
newMeshRefs.push_back(dstMeshIt->second);
|
||||
} else {
|
||||
|
|
@ -530,7 +542,7 @@ void ColladaLoader::BuildMeshesForNode(const ColladaParser &pParser, const Node
|
|||
faceStart += submesh.mNumFaces;
|
||||
|
||||
// assign the material index
|
||||
std::map<std::string, size_t>::const_iterator subMatIt = mMaterialIndexByName.find(submesh.mMaterial);
|
||||
auto subMatIt = mMaterialIndexByName.find(submesh.mMaterial);
|
||||
if (subMatIt != mMaterialIndexByName.end()) {
|
||||
dstMesh->mMaterialIndex = static_cast<unsigned int>(subMatIt->second);
|
||||
} else {
|
||||
|
|
@ -618,7 +630,7 @@ aiMesh *ColladaLoader::CreateMesh(const ColladaParser &pParser, const Mesh *pSrc
|
|||
std::copy(pSrcMesh->mTangents.begin() + pStartVertex, pSrcMesh->mTangents.begin() + pStartVertex + numVertices, dstMesh->mTangents);
|
||||
}
|
||||
|
||||
// bitangents, if given.
|
||||
// bi-tangents, if given.
|
||||
if (pSrcMesh->mBitangents.size() >= pStartVertex + numVertices) {
|
||||
dstMesh->mBitangents = new aiVector3D[numVertices];
|
||||
std::copy(pSrcMesh->mBitangents.begin() + pStartVertex, pSrcMesh->mBitangents.begin() + pStartVertex + numVertices, dstMesh->mBitangents);
|
||||
|
|
@ -664,7 +676,7 @@ aiMesh *ColladaLoader::CreateMesh(const ColladaParser &pParser, const Mesh *pSrc
|
|||
std::vector<float> targetWeights;
|
||||
Collada::MorphMethod method = Normalized;
|
||||
|
||||
for (std::map<std::string, Controller>::const_iterator it = pParser.mControllerLibrary.begin();
|
||||
for (auto it = pParser.mControllerLibrary.begin();
|
||||
it != pParser.mControllerLibrary.end(); ++it) {
|
||||
const Controller &c = it->second;
|
||||
const Collada::Mesh *baseMesh = pParser.ResolveLibraryReference(pParser.mMeshLibrary, c.mMeshId);
|
||||
|
|
@ -754,7 +766,7 @@ aiMesh *ColladaLoader::CreateMesh(const ColladaParser &pParser, const Mesh *pSrc
|
|||
std::vector<IndexPairVector::const_iterator> weightStartPerVertex;
|
||||
weightStartPerVertex.resize(pSrcController->mWeightCounts.size(), pSrcController->mWeights.end());
|
||||
|
||||
IndexPairVector::const_iterator pit = pSrcController->mWeights.begin();
|
||||
auto pit = pSrcController->mWeights.begin();
|
||||
for (size_t a = 0; a < pSrcController->mWeightCounts.size(); ++a) {
|
||||
weightStartPerVertex[a] = pit;
|
||||
pit += pSrcController->mWeightCounts[a];
|
||||
|
|
@ -766,7 +778,7 @@ aiMesh *ColladaLoader::CreateMesh(const ColladaParser &pParser, const Mesh *pSrc
|
|||
// the controller assigns the vertex weights
|
||||
size_t orgIndex = pSrcMesh->mFacePosIndices[a];
|
||||
// find the vertex weights for this vertex
|
||||
IndexPairVector::const_iterator iit = weightStartPerVertex[orgIndex];
|
||||
auto iit = weightStartPerVertex[orgIndex];
|
||||
size_t pairCount = pSrcController->mWeightCounts[orgIndex];
|
||||
|
||||
for (size_t b = 0; b < pairCount; ++b, ++iit) {
|
||||
|
|
@ -807,7 +819,7 @@ aiMesh *ColladaLoader::CreateMesh(const ColladaParser &pParser, const Mesh *pSrc
|
|||
}
|
||||
|
||||
// create bone with its weights
|
||||
aiBone *bone = new aiBone;
|
||||
auto bone = new aiBone;
|
||||
bone->mName = ReadString(jointNamesAcc, jointNames, a);
|
||||
bone->mOffsetMatrix.a1 = ReadFloat(jointMatrixAcc, jointMatrices, a, 0);
|
||||
bone->mOffsetMatrix.a2 = ReadFloat(jointMatrixAcc, jointMatrices, a, 1);
|
||||
|
|
@ -973,7 +985,7 @@ void ColladaLoader::StoreAnimations(aiScene *pScene, const ColladaParser &pParse
|
|||
|
||||
// if there are other animations which fit the template anim, combine all channels into a single anim
|
||||
if (!collectedAnimIndices.empty()) {
|
||||
aiAnimation *combinedAnim = new aiAnimation();
|
||||
auto *combinedAnim = new aiAnimation();
|
||||
combinedAnim->mName = aiString(std::string("combinedAnim_") + char('0' + a));
|
||||
combinedAnim->mDuration = templateAnim->mDuration;
|
||||
combinedAnim->mTicksPerSecond = templateAnim->mTicksPerSecond;
|
||||
|
|
@ -1040,7 +1052,7 @@ struct MorphTimeValues {
|
|||
};
|
||||
|
||||
void insertMorphTimeValue(std::vector<MorphTimeValues> &values, float time, float weight, unsigned int value) {
|
||||
MorphTimeValues::key k;
|
||||
MorphTimeValues::key k{};
|
||||
k.mValue = value;
|
||||
k.mWeight = weight;
|
||||
if (values.empty() || time < values[0].mTime) {
|
||||
|
|
@ -1077,6 +1089,7 @@ static float getWeightAtKey(const std::vector<MorphTimeValues> &values, int key,
|
|||
return mKey.mWeight;
|
||||
}
|
||||
}
|
||||
|
||||
// no value at key found, try to interpolate if present at other keys. if not, return zero
|
||||
// TODO: interpolation
|
||||
return 0.0f;
|
||||
|
|
@ -1105,7 +1118,7 @@ void ColladaLoader::CreateAnimation(aiScene *pScene, const ColladaParser &pParse
|
|||
|
||||
// now check all channels if they affect the current node
|
||||
std::string targetID, subElement;
|
||||
for (std::vector<AnimationChannel>::const_iterator cit = pSrcAnim->mChannels.begin();
|
||||
for (auto cit = pSrcAnim->mChannels.begin();
|
||||
cit != pSrcAnim->mChannels.end(); ++cit) {
|
||||
const AnimationChannel &srcChannel = *cit;
|
||||
ChannelEntry entry;
|
||||
|
|
@ -1348,7 +1361,7 @@ void ColladaLoader::CreateAnimation(aiScene *pScene, const ColladaParser &pParse
|
|||
|
||||
// build an animation channel for the given node out of these trafo keys
|
||||
if (!resultTrafos.empty()) {
|
||||
aiNodeAnim *dstAnim = new aiNodeAnim;
|
||||
auto *dstAnim = new aiNodeAnim;
|
||||
dstAnim->mNodeName = nodeName;
|
||||
dstAnim->mNumPositionKeys = static_cast<unsigned int>(resultTrafos.size());
|
||||
dstAnim->mNumRotationKeys = static_cast<unsigned int>(resultTrafos.size());
|
||||
|
|
@ -1390,7 +1403,7 @@ void ColladaLoader::CreateAnimation(aiScene *pScene, const ColladaParser &pParse
|
|||
// or 2) one channel with morph target count arrays
|
||||
// assume first
|
||||
|
||||
aiMeshMorphAnim *morphAnim = new aiMeshMorphAnim;
|
||||
auto *morphAnim = new aiMeshMorphAnim;
|
||||
morphAnim->mName.Set(nodeName);
|
||||
|
||||
std::vector<MorphTimeValues> morphTimeValues;
|
||||
|
|
@ -1433,7 +1446,7 @@ void ColladaLoader::CreateAnimation(aiScene *pScene, const ColladaParser &pParse
|
|||
}
|
||||
|
||||
if (!anims.empty() || !morphAnims.empty()) {
|
||||
aiAnimation *anim = new aiAnimation;
|
||||
auto anim = new aiAnimation;
|
||||
anim->mName.Set(pName);
|
||||
anim->mNumChannels = static_cast<unsigned int>(anims.size());
|
||||
if (anim->mNumChannels > 0) {
|
||||
|
|
@ -1513,7 +1526,7 @@ void ColladaLoader::AddTexture(aiMaterial &mat,
|
|||
map = sampler.mUVId;
|
||||
} else {
|
||||
map = -1;
|
||||
for (std::string::const_iterator it = sampler.mUVChannel.begin(); it != sampler.mUVChannel.end(); ++it) {
|
||||
for (auto it = sampler.mUVChannel.begin(); it != sampler.mUVChannel.end(); ++it) {
|
||||
if (IsNumeric(*it)) {
|
||||
map = strtoul10(&(*it));
|
||||
break;
|
||||
|
|
@ -1531,7 +1544,7 @@ void ColladaLoader::AddTexture(aiMaterial &mat,
|
|||
// Fills materials from the collada material definitions
|
||||
void ColladaLoader::FillMaterials(const ColladaParser &pParser, aiScene * /*pScene*/) {
|
||||
for (auto &elem : newMats) {
|
||||
aiMaterial &mat = (aiMaterial &)*elem.second;
|
||||
auto &mat = (aiMaterial &)*elem.second;
|
||||
Collada::Effect &effect = *elem.first;
|
||||
|
||||
// resolve shading mode
|
||||
|
|
@ -1641,17 +1654,17 @@ void ColladaLoader::FillMaterials(const ColladaParser &pParser, aiScene * /*pSce
|
|||
void ColladaLoader::BuildMaterials(ColladaParser &pParser, aiScene * /*pScene*/) {
|
||||
newMats.reserve(pParser.mMaterialLibrary.size());
|
||||
|
||||
for (ColladaParser::MaterialLibrary::const_iterator matIt = pParser.mMaterialLibrary.begin();
|
||||
for (auto matIt = pParser.mMaterialLibrary.begin();
|
||||
matIt != pParser.mMaterialLibrary.end(); ++matIt) {
|
||||
const Material &material = matIt->second;
|
||||
// a material is only a reference to an effect
|
||||
ColladaParser::EffectLibrary::iterator effIt = pParser.mEffectLibrary.find(material.mEffect);
|
||||
auto effIt = pParser.mEffectLibrary.find(material.mEffect);
|
||||
if (effIt == pParser.mEffectLibrary.end())
|
||||
continue;
|
||||
Effect &effect = effIt->second;
|
||||
|
||||
// create material
|
||||
aiMaterial *mat = new aiMaterial;
|
||||
auto *mat = new aiMaterial;
|
||||
aiString name(material.mName.empty() ? matIt->first : material.mName);
|
||||
mat->AddProperty(&name, AI_MATKEY_NAME);
|
||||
|
||||
|
|
@ -1674,7 +1687,7 @@ aiString ColladaLoader::FindFilenameForEffectTexture(const ColladaParser &pParse
|
|||
std::string name = pName;
|
||||
while (true) {
|
||||
// the given string is a param entry. Find it
|
||||
Effect::ParamLibrary::const_iterator it = pEffect.mParams.find(name);
|
||||
auto it = pEffect.mParams.find(name);
|
||||
// if not found, we're at the end of the recursion. The resulting string should be the image ID
|
||||
if (it == pEffect.mParams.end())
|
||||
break;
|
||||
|
|
@ -1684,7 +1697,7 @@ aiString ColladaLoader::FindFilenameForEffectTexture(const ColladaParser &pParse
|
|||
}
|
||||
|
||||
// find the image referred by this name in the image library of the scene
|
||||
ColladaParser::ImageLibrary::const_iterator imIt = pParser.mImageLibrary.find(name);
|
||||
auto imIt = pParser.mImageLibrary.find(name);
|
||||
if (imIt == pParser.mImageLibrary.end()) {
|
||||
ASSIMP_LOG_WARN("Collada: Unable to resolve effect texture entry \"", pName, "\", ended up at ID \"", name, "\".");
|
||||
|
||||
|
|
@ -1696,7 +1709,7 @@ aiString ColladaLoader::FindFilenameForEffectTexture(const ColladaParser &pParse
|
|||
|
||||
// if this is an embedded texture image setup an aiTexture for it
|
||||
if (!imIt->second.mImageData.empty()) {
|
||||
aiTexture *tex = new aiTexture();
|
||||
auto *tex = new aiTexture();
|
||||
|
||||
// Store embedded texture name reference
|
||||
tex->mFilename.Set(imIt->second.mFileName.c_str());
|
||||
|
|
@ -1728,14 +1741,6 @@ aiString ColladaLoader::FindFilenameForEffectTexture(const ColladaParser &pParse
|
|||
return result;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Reads a float value from an accessor and its data array.
|
||||
ai_real ColladaLoader::ReadFloat(const Accessor &pAccessor, const Data &pData, size_t pIndex, size_t pOffset) const {
|
||||
size_t pos = pAccessor.mStride * pIndex + pAccessor.mOffset + pOffset;
|
||||
ai_assert(pos < pData.mValues.size());
|
||||
return pData.mValues[pos];
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Reads a string value from an accessor and its data array.
|
||||
const std::string &ColladaLoader::ReadString(const Accessor &pAccessor, const Data &pData, size_t pIndex) const {
|
||||
|
|
@ -1818,4 +1823,4 @@ std::string ColladaLoader::FindNameForNode(const Node *pNode) {
|
|||
|
||||
} // Namespace Assimp
|
||||
|
||||
#endif // !! ASSIMP_BUILD_NO_DAE_IMPORTER
|
||||
#endif // !! ASSIMP_BUILD_NO_COLLADA_IMPORTER
|
||||
|
|
|
|||
|
|
@ -4,8 +4,7 @@
|
|||
Open Asset Import Library (assimp)
|
||||
----------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2024, assimp team
|
||||
|
||||
Copyright (c) 2006-2026, assimp team
|
||||
|
||||
All rights reserved.
|
||||
|
||||
|
|
@ -77,10 +76,13 @@ struct ColladaMeshIndex {
|
|||
}
|
||||
};
|
||||
|
||||
/** Loader class to read Collada scenes. Collada is over-engineered to death, with every new iteration bringing
|
||||
* more useless stuff, so I limited the data to what I think is useful for games.
|
||||
/**
|
||||
* @brief Loader class to read Collada scenes.
|
||||
*
|
||||
* Collada is over-engineered to death, with every new iteration bringing more useless stuff,
|
||||
* so I limited the data to what I think is useful for games.
|
||||
*/
|
||||
class ColladaLoader : public BaseImporter {
|
||||
class ColladaLoader final : public BaseImporter {
|
||||
public:
|
||||
/// The class constructor.
|
||||
ColladaLoader();
|
||||
|
|
@ -102,50 +104,51 @@ protected:
|
|||
/// See #BaseImporter::InternReadFile for the details
|
||||
void InternReadFile(const std::string &pFile, aiScene *pScene, IOSystem *pIOHandler) override;
|
||||
|
||||
/** Recursively constructs a scene node for the given parser node and returns it. */
|
||||
/// Recursively constructs a scene node for the given parser node and returns it.
|
||||
aiNode *BuildHierarchy(const ColladaParser &pParser, const Collada::Node *pNode);
|
||||
|
||||
/** Resolve node instances */
|
||||
/// Resolve node instances
|
||||
void ResolveNodeInstances(const ColladaParser &pParser, const Collada::Node *pNode,
|
||||
std::vector<const Collada::Node *> &resolved);
|
||||
std::vector<const Collada::Node *> &resolved) const;
|
||||
|
||||
/** Builds meshes for the given node and references them */
|
||||
/// Builds meshes for the given node and references them
|
||||
void BuildMeshesForNode(const ColladaParser &pParser, const Collada::Node *pNode,
|
||||
aiNode *pTarget);
|
||||
|
||||
/// Lookup for meshes by their name
|
||||
aiMesh *findMesh(const std::string &meshid);
|
||||
|
||||
/** Creates a mesh for the given ColladaMesh face subset and returns the newly created mesh */
|
||||
/// Creates a mesh for the given ColladaMesh face subset and returns the newly created mesh
|
||||
aiMesh *CreateMesh(const ColladaParser &pParser, const Collada::Mesh *pSrcMesh, const Collada::SubMesh &pSubMesh,
|
||||
const Collada::Controller *pSrcController, size_t pStartVertex, size_t pStartFace);
|
||||
|
||||
/** Builds cameras for the given node and references them */
|
||||
/// Builds cameras for the given node and references them
|
||||
void BuildCamerasForNode(const ColladaParser &pParser, const Collada::Node *pNode,
|
||||
aiNode *pTarget);
|
||||
|
||||
/** Builds lights for the given node and references them */
|
||||
/// Builds lights for the given node and references them
|
||||
void BuildLightsForNode(const ColladaParser &pParser, const Collada::Node *pNode,
|
||||
aiNode *pTarget);
|
||||
|
||||
/** Stores all meshes in the given scene */
|
||||
/// Stores all meshes in the given scene
|
||||
void StoreSceneMeshes(aiScene *pScene);
|
||||
|
||||
/** Stores all materials in the given scene */
|
||||
/// Stores all materials in the given scene
|
||||
void StoreSceneMaterials(aiScene *pScene);
|
||||
|
||||
/** Stores all lights in the given scene */
|
||||
/// Stores all lights in the given scene
|
||||
void StoreSceneLights(aiScene *pScene);
|
||||
|
||||
/** Stores all cameras in the given scene */
|
||||
/// Stores all cameras in the given scene
|
||||
void StoreSceneCameras(aiScene *pScene);
|
||||
|
||||
/** Stores all textures in the given scene */
|
||||
/// Stores all textures in the given scene
|
||||
void StoreSceneTextures(aiScene *pScene);
|
||||
|
||||
/** Stores all animations
|
||||
* @param pScene target scene to store the anims
|
||||
*/
|
||||
void StoreAnimations(aiScene *pScene, const ColladaParser &pParser);
|
||||
/// Stores all animations
|
||||
/// @param pScene Target scene to store the anims
|
||||
/// @param parser The collada parser
|
||||
void StoreAnimations(aiScene *pScene, const ColladaParser &parser);
|
||||
|
||||
/** Stores all animations for the given source anim and its nested child animations
|
||||
* @param pScene target scene to store the anims
|
||||
|
|
@ -163,10 +166,6 @@ protected:
|
|||
/** Fill materials from the collada material definitions */
|
||||
void FillMaterials(const ColladaParser &pParser, aiScene *pScene);
|
||||
|
||||
/** Resolve UV channel mappings*/
|
||||
void ApplyVertexToEffectSemanticMapping(Collada::Sampler &sampler,
|
||||
const Collada::SemanticMappingTable &table);
|
||||
|
||||
/** Add a texture and all of its sampling properties to a material*/
|
||||
void AddTexture(aiMaterial &mat, const ColladaParser &pParser,
|
||||
const Collada::Effect &effect,
|
||||
|
|
@ -177,22 +176,13 @@ protected:
|
|||
aiString FindFilenameForEffectTexture(const ColladaParser &pParser,
|
||||
const Collada::Effect &pEffect, const std::string &pName);
|
||||
|
||||
/** Reads a float value from an accessor and its data array.
|
||||
* @param pAccessor The accessor to use for reading
|
||||
* @param pData The data array to read from
|
||||
* @param pIndex The index of the element to retrieve
|
||||
* @param pOffset Offset into the element, for multipart elements such as vectors or matrices
|
||||
* @return the specified value
|
||||
*/
|
||||
ai_real ReadFloat(const Collada::Accessor &pAccessor, const Collada::Data &pData, size_t pIndex, size_t pOffset) const;
|
||||
|
||||
/** Reads a string value from an accessor and its data array.
|
||||
* @param pAccessor The accessor to use for reading
|
||||
* @param pData The data array to read from
|
||||
* @param pIndex The index of the element to retrieve
|
||||
* @return the specified value
|
||||
*/
|
||||
const std::string &ReadString(const Collada::Accessor &pAccessor, const Collada::Data &pData, size_t pIndex) const;
|
||||
[[nodiscard]] const std::string &ReadString(const Collada::Accessor &pAccessor, const Collada::Data &pData, size_t pIndex) const;
|
||||
|
||||
/** Recursively collects all nodes into the given array */
|
||||
void CollectNodes(const aiNode *pNode, std::vector<const aiNode *> &poNodes) const;
|
||||
|
|
@ -205,7 +195,7 @@ protected:
|
|||
/** Finds a proper name for a node derived from the collada-node's properties */
|
||||
std::string FindNameForNode(const Collada::Node *pNode);
|
||||
|
||||
protected:
|
||||
private:
|
||||
/** Filename, for a verbose error message */
|
||||
std::string mFileName;
|
||||
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -2,7 +2,7 @@
|
|||
Open Asset Import Library (assimp)
|
||||
----------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2024, assimp team
|
||||
Copyright (c) 2006-2026, assimp team
|
||||
|
||||
All rights reserved.
|
||||
|
||||
|
|
@ -48,7 +48,6 @@
|
|||
#define AI_COLLADAPARSER_H_INC
|
||||
|
||||
#include "ColladaHelper.h"
|
||||
#include <assimp/TinyFormatter.h>
|
||||
#include <assimp/ai_assert.h>
|
||||
#include <assimp/XmlParser.h>
|
||||
|
||||
|
|
@ -67,268 +66,240 @@ class ZipArchiveIOSystem;
|
|||
class ColladaParser {
|
||||
friend class ColladaLoader;
|
||||
|
||||
/** Converts a path read from a collada file to the usual representation */
|
||||
static void UriDecodePath(aiString &ss);
|
||||
public:
|
||||
/// Map for generic metadata as aiString.
|
||||
using StringMetaData = std::map<std::string, aiString>;
|
||||
|
||||
protected:
|
||||
/** Map for generic metadata as aiString */
|
||||
typedef std::map<std::string, aiString> StringMetaData;
|
||||
|
||||
/** Constructor from XML file */
|
||||
/// Constructor from XML file.
|
||||
ColladaParser(IOSystem *pIOHandler, const std::string &pFile);
|
||||
|
||||
/** Destructor */
|
||||
/// Destructor
|
||||
~ColladaParser();
|
||||
|
||||
/** Attempts to read the ZAE manifest and returns the DAE to open */
|
||||
/// Attempts to read the ZAE manifest and returns the DAE to open
|
||||
static std::string ReadZaeManifest(ZipArchiveIOSystem &zip_archive);
|
||||
|
||||
/** Reads the contents of the file */
|
||||
/// Reads the contents of the file
|
||||
void ReadContents(XmlNode &node);
|
||||
|
||||
/** Reads the structure of the file */
|
||||
/// Reads the structure of the file
|
||||
void ReadStructure(XmlNode &node);
|
||||
|
||||
/** Reads asset information such as coordinate system information and legal blah */
|
||||
/// Reads asset information such as coordinate system information and legal blah
|
||||
void ReadAssetInfo(XmlNode &node);
|
||||
|
||||
/** Reads contributor information such as author and legal blah */
|
||||
/// Reads contributor information such as author and legal blah
|
||||
void ReadContributorInfo(XmlNode &node);
|
||||
|
||||
/** Reads generic metadata into provided map and renames keys for Assimp */
|
||||
void ReadMetaDataItem(XmlNode &node, StringMetaData &metadata);
|
||||
|
||||
/** Reads the animation library */
|
||||
/// Reads the animation library
|
||||
void ReadAnimationLibrary(XmlNode &node);
|
||||
|
||||
/** Reads the animation clip library */
|
||||
/// Reads the animation clip library
|
||||
void ReadAnimationClipLibrary(XmlNode &node);
|
||||
|
||||
/** Unwrap controllers dependency hierarchy */
|
||||
/// Unwrap controllers dependency hierarchy
|
||||
void PostProcessControllers();
|
||||
|
||||
/** Re-build animations from animation clip library, if present, otherwise combine single-channel animations */
|
||||
/// Re-build animations from animation clip library, if present, otherwise combine single-channel animations
|
||||
void PostProcessRootAnimations();
|
||||
|
||||
/** Reads an animation into the given parent structure */
|
||||
/// Reads an animation into the given parent structure
|
||||
void ReadAnimation(XmlNode &node, Collada::Animation *pParent);
|
||||
|
||||
/** Reads an animation sampler into the given anim channel */
|
||||
void ReadAnimationSampler(XmlNode &node, Collada::AnimationChannel &pChannel);
|
||||
|
||||
/** Reads the skeleton controller library */
|
||||
/// Reads the skeleton controller library
|
||||
void ReadControllerLibrary(XmlNode &node);
|
||||
|
||||
/** Reads a controller into the given mesh structure */
|
||||
/// Reads a controller into the given mesh structure
|
||||
void ReadController(XmlNode &node, Collada::Controller &pController);
|
||||
|
||||
/** Reads the joint definitions for the given controller */
|
||||
void ReadControllerJoints(XmlNode &node, Collada::Controller &pController);
|
||||
/// Reads the image library contents
|
||||
void ReadImageLibrary(const XmlNode &node);
|
||||
|
||||
/** Reads the joint weights for the given controller */
|
||||
void ReadControllerWeights(XmlNode &node, Collada::Controller &pController);
|
||||
/// Reads an image entry into the given image
|
||||
void ReadImage(const XmlNode &node, Collada::Image &pImage) const;
|
||||
|
||||
/** Reads the image library contents */
|
||||
void ReadImageLibrary(XmlNode &node);
|
||||
|
||||
/** Reads an image entry into the given image */
|
||||
void ReadImage(XmlNode &node, Collada::Image &pImage);
|
||||
|
||||
/** Reads the material library */
|
||||
/// Reads the material library
|
||||
void ReadMaterialLibrary(XmlNode &node);
|
||||
|
||||
/** Reads a material entry into the given material */
|
||||
void ReadMaterial(XmlNode &node, Collada::Material &pMaterial);
|
||||
|
||||
/** Reads the camera library */
|
||||
/// Reads the camera library
|
||||
void ReadCameraLibrary(XmlNode &node);
|
||||
|
||||
/** Reads a camera entry into the given camera */
|
||||
void ReadCamera(XmlNode &node, Collada::Camera &pCamera);
|
||||
|
||||
/** Reads the light library */
|
||||
/// Reads the light library
|
||||
void ReadLightLibrary(XmlNode &node);
|
||||
|
||||
/** Reads a light entry into the given light */
|
||||
void ReadLight(XmlNode &node, Collada::Light &pLight);
|
||||
|
||||
/** Reads the effect library */
|
||||
/// Reads the effect library
|
||||
void ReadEffectLibrary(XmlNode &node);
|
||||
|
||||
/** Reads an effect entry into the given effect*/
|
||||
/// Reads an effect entry into the given effect
|
||||
void ReadEffect(XmlNode &node, Collada::Effect &pEffect);
|
||||
|
||||
/** Reads an COMMON effect profile */
|
||||
/// Reads an COMMON effect profile
|
||||
void ReadEffectProfileCommon(XmlNode &node, Collada::Effect &pEffect);
|
||||
|
||||
/** Read sampler properties */
|
||||
/// Read sampler properties
|
||||
void ReadSamplerProperties(XmlNode &node, Collada::Sampler &pSampler);
|
||||
|
||||
/** Reads an effect entry containing a color or a texture defining that color */
|
||||
/// Reads an effect entry containing a color or a texture defining that color
|
||||
void ReadEffectColor(XmlNode &node, aiColor4D &pColor, Collada::Sampler &pSampler);
|
||||
|
||||
/** Reads an effect entry containing a float */
|
||||
/// Reads an effect entry containing a float
|
||||
void ReadEffectFloat(XmlNode &node, ai_real &pFloat);
|
||||
|
||||
/** Reads an effect parameter specification of any kind */
|
||||
/// Reads an effect parameter specification of any kind
|
||||
void ReadEffectParam(XmlNode &node, Collada::EffectParam &pParam);
|
||||
|
||||
/** Reads the geometry library contents */
|
||||
/// Reads the geometry library contents
|
||||
void ReadGeometryLibrary(XmlNode &node);
|
||||
|
||||
/** Reads a geometry from the geometry library. */
|
||||
/// Reads a geometry from the geometry library.
|
||||
void ReadGeometry(XmlNode &node, Collada::Mesh &pMesh);
|
||||
|
||||
/** Reads a mesh from the geometry library */
|
||||
/// Reads a mesh from the geometry library
|
||||
void ReadMesh(XmlNode &node, Collada::Mesh &pMesh);
|
||||
|
||||
/** Reads a source element - a combination of raw data and an accessor defining
|
||||
* things that should not be redefinable. Yes, that's another rant.
|
||||
*/
|
||||
/// Reads a source element - a combination of raw data and an accessor defining
|
||||
///things that should not be definable. Yes, that's another rant.
|
||||
void ReadSource(XmlNode &node);
|
||||
|
||||
/** Reads a data array holding a number of elements, and stores it in the global library.
|
||||
* Currently supported are array of floats and arrays of strings.
|
||||
*/
|
||||
/// Reads a data array holding a number of elements, and stores it in the global library.
|
||||
/// Currently supported are array of floats and arrays of strings.
|
||||
void ReadDataArray(XmlNode &node);
|
||||
|
||||
/** Reads an accessor and stores it in the global library under the given ID -
|
||||
* accessors use the ID of the parent <source> element
|
||||
*/
|
||||
/// Reads an accessor and stores it in the global library under the given ID -
|
||||
/// accessors use the ID of the parent <source> element
|
||||
void ReadAccessor(XmlNode &node, const std::string &pID);
|
||||
|
||||
/** Reads input declarations of per-vertex mesh data into the given mesh */
|
||||
/// Reads input declarations of per-vertex mesh data into the given mesh
|
||||
void ReadVertexData(XmlNode &node, Collada::Mesh &pMesh);
|
||||
|
||||
/** Reads input declarations of per-index mesh data into the given mesh */
|
||||
/// Reads input declarations of per-index mesh data into the given mesh
|
||||
void ReadIndexData(XmlNode &node, Collada::Mesh &pMesh);
|
||||
|
||||
/** Reads a single input channel element and stores it in the given array, if valid */
|
||||
/// Reads a single input channel element and stores it in the given array, if valid
|
||||
void ReadInputChannel(XmlNode &node, std::vector<Collada::InputChannel> &poChannels);
|
||||
|
||||
/** Reads a <p> primitive index list and assembles the mesh data into the given mesh */
|
||||
/// Reads a <p> primitive index list and assembles the mesh data into the given mesh
|
||||
size_t ReadPrimitives(XmlNode &node, Collada::Mesh &pMesh, std::vector<Collada::InputChannel> &pPerIndexChannels,
|
||||
size_t pNumPrimitives, const std::vector<size_t> &pVCount, Collada::PrimitiveType pPrimType);
|
||||
|
||||
/** Copies the data for a single primitive into the mesh, based on the InputChannels */
|
||||
/// Copies the data for a single primitive into the mesh, based on the InputChannels
|
||||
void CopyVertex(size_t currentVertex, size_t numOffsets, size_t numPoints, size_t perVertexOffset,
|
||||
Collada::Mesh &pMesh, std::vector<Collada::InputChannel> &pPerIndexChannels,
|
||||
size_t currentPrimitive, const std::vector<size_t> &indices);
|
||||
|
||||
/** Reads one triangle of a tristrip into the mesh */
|
||||
/// Reads one triangle of a tristrip into the mesh
|
||||
void ReadPrimTriStrips(size_t numOffsets, size_t perVertexOffset, Collada::Mesh &pMesh,
|
||||
std::vector<Collada::InputChannel> &pPerIndexChannels, size_t currentPrimitive, const std::vector<size_t> &indices);
|
||||
|
||||
/** Extracts a single object from an input channel and stores it in the appropriate mesh data array */
|
||||
/// Extracts a single object from an input channel and stores it in the appropriate mesh data array
|
||||
void ExtractDataObjectFromChannel(const Collada::InputChannel &pInput, size_t pLocalIndex, Collada::Mesh &pMesh);
|
||||
|
||||
/** Reads the library of node hierarchies and scene parts */
|
||||
/// Reads the library of node hierarchies and scene parts
|
||||
void ReadSceneLibrary(XmlNode &node);
|
||||
|
||||
/** Reads a scene node's contents including children and stores it in the given node */
|
||||
/// Reads a scene node's contents including children and stores it in the given node
|
||||
void ReadSceneNode(XmlNode &node, Collada::Node *pNode);
|
||||
|
||||
/** Reads a node transformation entry of the given type and adds it to the given node's transformation list. */
|
||||
void ReadNodeTransformation(XmlNode &node, Collada::Node *pNode, Collada::TransformType pType);
|
||||
|
||||
/** Reads a mesh reference in a node and adds it to the node's mesh list */
|
||||
|
||||
/// Reads a mesh reference in a node and adds it to the node's mesh list
|
||||
void ReadNodeGeometry(XmlNode &node, Collada::Node *pNode);
|
||||
|
||||
/** Reads the collada scene */
|
||||
/// Reads the collada scene
|
||||
void ReadScene(XmlNode &node);
|
||||
|
||||
// Processes bind_vertex_input and bind elements
|
||||
/// Processes bind_vertex_input and bind elements
|
||||
void ReadMaterialVertexInputBinding(XmlNode &node, Collada::SemanticMappingTable &tbl);
|
||||
|
||||
/** Reads embedded textures from a ZAE archive*/
|
||||
/// Reads embedded textures from a ZAE archive
|
||||
void ReadEmbeddedTextures(ZipArchiveIOSystem &zip_archive);
|
||||
|
||||
protected:
|
||||
/** Calculates the resulting transformation from all the given transform steps */
|
||||
/// Converts a path read from a collada file to the usual representation
|
||||
static void UriDecodePath(aiString &ss);
|
||||
|
||||
/// Calculates the resulting transformation from all the given transform steps
|
||||
aiMatrix4x4 CalculateResultTransform(const std::vector<Collada::Transform> &pTransforms) const;
|
||||
|
||||
/** Determines the input data type for the given semantic string */
|
||||
/// Determines the input data type for the given semantic string
|
||||
Collada::InputType GetTypeForSemantic(const std::string &pSemantic);
|
||||
|
||||
/** Finds the item in the given library by its reference, throws if not found */
|
||||
/// Finds the item in the given library by its reference, throws if not found
|
||||
template <typename Type>
|
||||
const Type &ResolveLibraryReference(const std::map<std::string, Type> &pLibrary, const std::string &pURL) const;
|
||||
|
||||
protected:
|
||||
// Filename, for a verbose error message
|
||||
private:
|
||||
/// Filename, for a verbose error message
|
||||
std::string mFileName;
|
||||
|
||||
// XML reader, member for everyday use
|
||||
/// XML reader, member for everyday use
|
||||
XmlParser mXmlParser;
|
||||
|
||||
/** All data arrays found in the file by ID. Might be referred to by actually
|
||||
everyone. Collada, you are a steaming pile of indirection. */
|
||||
/// All data arrays found in the file by ID. Might be referred to by actually
|
||||
/// everyone. Collada, you are a steaming pile of indirection.
|
||||
using DataLibrary = std::map<std::string, Collada::Data> ;
|
||||
DataLibrary mDataLibrary;
|
||||
|
||||
/** Same for accessors which define how the data in a data array is accessed. */
|
||||
/// Same for accessors which define how the data in a data array is accessed.
|
||||
using AccessorLibrary = std::map<std::string, Collada::Accessor> ;
|
||||
AccessorLibrary mAccessorLibrary;
|
||||
|
||||
/** Mesh library: mesh by ID */
|
||||
/// Mesh library: mesh by ID
|
||||
using MeshLibrary = std::map<std::string, Collada::Mesh *>;
|
||||
MeshLibrary mMeshLibrary;
|
||||
|
||||
/** node library: root node of the hierarchy part by ID */
|
||||
/// node library: root node of the hierarchy part by ID
|
||||
using NodeLibrary = std::map<std::string, Collada::Node *>;
|
||||
NodeLibrary mNodeLibrary;
|
||||
|
||||
/** Image library: stores texture properties by ID */
|
||||
/// Image library: stores texture properties by ID
|
||||
using ImageLibrary = std::map<std::string, Collada::Image> ;
|
||||
ImageLibrary mImageLibrary;
|
||||
|
||||
/** Effect library: surface attributes by ID */
|
||||
/// Effect library: surface attributes by ID
|
||||
using EffectLibrary = std::map<std::string, Collada::Effect> ;
|
||||
EffectLibrary mEffectLibrary;
|
||||
|
||||
/** Material library: surface material by ID */
|
||||
/// Material library: surface material by ID
|
||||
using MaterialLibrary = std::map<std::string, Collada::Material> ;
|
||||
MaterialLibrary mMaterialLibrary;
|
||||
|
||||
/** Light library: surface light by ID */
|
||||
/// Light library: surface light by ID
|
||||
using LightLibrary = std::map<std::string, Collada::Light> ;
|
||||
LightLibrary mLightLibrary;
|
||||
|
||||
/** Camera library: surface material by ID */
|
||||
/// Camera library: surface material by ID
|
||||
using CameraLibrary = std::map<std::string, Collada::Camera> ;
|
||||
CameraLibrary mCameraLibrary;
|
||||
|
||||
/** Controller library: joint controllers by ID */
|
||||
/// Controller library: joint controllers by ID
|
||||
using ControllerLibrary = std::map<std::string, Collada::Controller> ;
|
||||
ControllerLibrary mControllerLibrary;
|
||||
|
||||
/** Animation library: animation references by ID */
|
||||
/// Animation library: animation references by ID
|
||||
using AnimationLibrary = std::map<std::string, Collada::Animation *> ;
|
||||
AnimationLibrary mAnimationLibrary;
|
||||
|
||||
/** Animation clip library: clip animation references by ID */
|
||||
/// Animation clip library: clip animation references by ID
|
||||
using AnimationClipLibrary = std::vector<std::pair<std::string, std::vector<std::string>>> ;
|
||||
AnimationClipLibrary mAnimationClipLibrary;
|
||||
|
||||
/** Pointer to the root node. Don't delete, it just points to one of
|
||||
the nodes in the node library. */
|
||||
/// Pointer to the root node. Don't delete, it just points to one of the nodes in the node library.
|
||||
Collada::Node *mRootNode;
|
||||
|
||||
/** Root animation container */
|
||||
/// Root animation container
|
||||
Collada::Animation mAnims;
|
||||
|
||||
/** Size unit: how large compared to a meter */
|
||||
/// Size unit: how large compared to a meter
|
||||
ai_real mUnitSize;
|
||||
|
||||
/** Which is the up vector */
|
||||
/// Which is the up vector
|
||||
enum { UP_X,
|
||||
UP_Y,
|
||||
UP_Z } mUpDirection;
|
||||
|
||||
/** Asset metadata (global for scene) */
|
||||
/// Asset metadata (global for scene)
|
||||
StringMetaData mAssetMetaData;
|
||||
|
||||
/** Collada file format version */
|
||||
/// Collada file format version
|
||||
Collada::FormatVersion mFormat;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -2,8 +2,7 @@
|
|||
Open Asset Import Library (assimp)
|
||||
----------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2024, assimp team
|
||||
|
||||
Copyright (c) 2006-2026, assimp team
|
||||
|
||||
All rights reserved.
|
||||
|
||||
|
|
@ -54,18 +53,14 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
#include <vector>
|
||||
#include <assimp/DefaultLogger.hpp>
|
||||
|
||||
namespace Assimp {
|
||||
namespace DXF {
|
||||
namespace Assimp::DXF {
|
||||
|
||||
// read pairs of lines, parse group code and value and provide utilities
|
||||
// to convert the data to the target data type.
|
||||
// do NOT skip empty lines. In DXF files, they count as valid data.
|
||||
class LineReader {
|
||||
public:
|
||||
LineReader(StreamReaderLE& reader)
|
||||
: splitter(reader,false,true)
|
||||
, groupcode( 0 )
|
||||
, end() {
|
||||
explicit LineReader(StreamReaderLE& reader) : splitter(reader,false,true), groupcode( 0 ), end() {
|
||||
// empty
|
||||
}
|
||||
|
||||
|
|
@ -105,7 +100,7 @@ public:
|
|||
}
|
||||
|
||||
// -----------------------------------------
|
||||
float ValueAsFloat() const {
|
||||
ai_real ValueAsFloat() const {
|
||||
return fast_atof(value.c_str());
|
||||
}
|
||||
|
||||
|
|
@ -165,8 +160,7 @@ private:
|
|||
|
||||
// represents a POLYLINE or a LWPOLYLINE. or even a 3DFACE The data is converted as needed.
|
||||
struct PolyLine {
|
||||
PolyLine()
|
||||
: flags() {
|
||||
PolyLine() : flags() {
|
||||
// empty
|
||||
}
|
||||
|
||||
|
|
@ -182,10 +176,7 @@ struct PolyLine {
|
|||
|
||||
// reference to a BLOCK. Specifies its own coordinate system.
|
||||
struct InsertBlock {
|
||||
InsertBlock()
|
||||
: pos()
|
||||
, scale(1.f,1.f,1.f)
|
||||
, angle() {
|
||||
InsertBlock() : pos(0.f, 0.f, 0.f), scale(1.f,1.f,1.f), angle(0.0f) {
|
||||
// empty
|
||||
}
|
||||
|
||||
|
|
@ -198,8 +189,7 @@ struct InsertBlock {
|
|||
|
||||
|
||||
// keeps track of all geometry in a single BLOCK.
|
||||
struct Block
|
||||
{
|
||||
struct Block {
|
||||
std::vector< std::shared_ptr<PolyLine> > lines;
|
||||
std::vector<InsertBlock> insertions;
|
||||
|
||||
|
|
@ -207,14 +197,11 @@ struct Block
|
|||
aiVector3D base;
|
||||
};
|
||||
|
||||
|
||||
struct FileData
|
||||
{
|
||||
struct FileData {
|
||||
// note: the LAST block always contains the stuff from ENTITIES.
|
||||
std::vector<Block> blocks;
|
||||
};
|
||||
|
||||
}
|
||||
} // Namespace Assimp
|
||||
} // namespace Assimp::DXF
|
||||
|
||||
#endif
|
||||
#endif // INCLUDED_DXFHELPER_H
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
Open Asset Import Library (assimp)
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2024, assimp team
|
||||
Copyright (c) 2006-2026, assimp team
|
||||
|
||||
All rights reserved.
|
||||
|
||||
|
|
@ -45,8 +45,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
|
||||
#ifndef ASSIMP_BUILD_NO_DXF_IMPORTER
|
||||
|
||||
#include "AssetLib/DXF/DXFLoader.h"
|
||||
#include "AssetLib/DXF/DXFHelper.h"
|
||||
#include "DXFLoader.h"
|
||||
#include "DXFHelper.h"
|
||||
#include "PostProcessing/ConvertToLHProcess.h"
|
||||
|
||||
#include <assimp/ParsingUtils.h>
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
Open Asset Import Library (assimp)
|
||||
----------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2024, assimp team
|
||||
Copyright (c) 2006-2026, assimp team
|
||||
|
||||
All rights reserved.
|
||||
|
||||
|
|
@ -49,7 +49,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
#include <assimp/BaseImporter.h>
|
||||
#include <map>
|
||||
|
||||
namespace Assimp {
|
||||
namespace Assimp {
|
||||
|
||||
// Forward declarations
|
||||
namespace DXF {
|
||||
|
|
@ -66,7 +66,7 @@ namespace DXF {
|
|||
/**
|
||||
* @brief DXF importer implementation.
|
||||
*/
|
||||
class DXFImporter : public BaseImporter {
|
||||
class DXFImporter final : public BaseImporter {
|
||||
public:
|
||||
DXFImporter() = default;
|
||||
~DXFImporter() override = default;
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
Open Asset Import Library (assimp)
|
||||
----------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2024, assimp team
|
||||
Copyright (c) 2006-2026, assimp team
|
||||
|
||||
All rights reserved.
|
||||
|
||||
|
|
@ -143,31 +143,33 @@ AnimationCurveNode::AnimationCurveNode(uint64_t id, const Element &element, cons
|
|||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
const AnimationCurveMap &AnimationCurveNode::Curves() const {
|
||||
if (curves.empty()) {
|
||||
// resolve attached animation curves
|
||||
const std::vector<const Connection *> &conns = doc.GetConnectionsByDestinationSequenced(ID(), "AnimationCurve");
|
||||
if (!curves.empty()) {
|
||||
return curves;
|
||||
}
|
||||
|
||||
for (const Connection *con : conns) {
|
||||
// resolve attached animation curves
|
||||
const std::vector<const Connection *> &conns = doc.GetConnectionsByDestinationSequenced(ID(), "AnimationCurve");
|
||||
|
||||
// link should go for a property
|
||||
if (!con->PropertyName().length()) {
|
||||
continue;
|
||||
}
|
||||
for (const Connection *con : conns) {
|
||||
|
||||
const Object *const ob = con->SourceObject();
|
||||
if (nullptr == ob) {
|
||||
DOMWarning("failed to read source object for AnimationCurve->AnimationCurveNode link, ignoring", &element);
|
||||
continue;
|
||||
}
|
||||
|
||||
const AnimationCurve *const anim = dynamic_cast<const AnimationCurve *>(ob);
|
||||
if (nullptr == anim) {
|
||||
DOMWarning("source object for ->AnimationCurveNode link is not an AnimationCurve", &element);
|
||||
continue;
|
||||
}
|
||||
|
||||
curves[con->PropertyName()] = anim;
|
||||
// link should go for a property
|
||||
if (!con->PropertyName().length()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const Object *const ob = con->SourceObject();
|
||||
if (nullptr == ob) {
|
||||
DOMWarning("failed to read source object for AnimationCurve->AnimationCurveNode link, ignoring", &element);
|
||||
continue;
|
||||
}
|
||||
|
||||
const AnimationCurve *const anim = dynamic_cast<const AnimationCurve *>(ob);
|
||||
if (nullptr == anim) {
|
||||
DOMWarning("source object for ->AnimationCurveNode link is not an AnimationCurve", &element);
|
||||
continue;
|
||||
}
|
||||
|
||||
curves[con->PropertyName()] = anim;
|
||||
}
|
||||
|
||||
return curves;
|
||||
|
|
|
|||
|
|
@ -2,8 +2,7 @@
|
|||
Open Asset Import Library (assimp)
|
||||
----------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2024, assimp team
|
||||
|
||||
Copyright (c) 2006-2026, assimp team
|
||||
|
||||
All rights reserved.
|
||||
|
||||
|
|
@ -60,58 +59,16 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
namespace Assimp {
|
||||
namespace FBX {
|
||||
|
||||
//enum Flag
|
||||
//{
|
||||
// e_unknown_0 = 1 << 0,
|
||||
// e_unknown_1 = 1 << 1,
|
||||
// e_unknown_2 = 1 << 2,
|
||||
// e_unknown_3 = 1 << 3,
|
||||
// e_unknown_4 = 1 << 4,
|
||||
// e_unknown_5 = 1 << 5,
|
||||
// e_unknown_6 = 1 << 6,
|
||||
// e_unknown_7 = 1 << 7,
|
||||
// e_unknown_8 = 1 << 8,
|
||||
// e_unknown_9 = 1 << 9,
|
||||
// e_unknown_10 = 1 << 10,
|
||||
// e_unknown_11 = 1 << 11,
|
||||
// e_unknown_12 = 1 << 12,
|
||||
// e_unknown_13 = 1 << 13,
|
||||
// e_unknown_14 = 1 << 14,
|
||||
// e_unknown_15 = 1 << 15,
|
||||
// e_unknown_16 = 1 << 16,
|
||||
// e_unknown_17 = 1 << 17,
|
||||
// e_unknown_18 = 1 << 18,
|
||||
// e_unknown_19 = 1 << 19,
|
||||
// e_unknown_20 = 1 << 20,
|
||||
// e_unknown_21 = 1 << 21,
|
||||
// e_unknown_22 = 1 << 22,
|
||||
// e_unknown_23 = 1 << 23,
|
||||
// e_flag_field_size_64_bit = 1 << 24, // Not sure what is
|
||||
// e_unknown_25 = 1 << 25,
|
||||
// e_unknown_26 = 1 << 26,
|
||||
// e_unknown_27 = 1 << 27,
|
||||
// e_unknown_28 = 1 << 28,
|
||||
// e_unknown_29 = 1 << 29,
|
||||
// e_unknown_30 = 1 << 30,
|
||||
// e_unknown_31 = 1 << 31
|
||||
//};
|
||||
//
|
||||
//bool check_flag(uint32_t flags, Flag to_check)
|
||||
//{
|
||||
// return (flags & to_check) != 0;
|
||||
//}
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Token::Token(const char* sbegin, const char* send, TokenType type, size_t offset)
|
||||
:
|
||||
#ifdef DEBUG
|
||||
contents(sbegin, static_cast<size_t>(send-sbegin)),
|
||||
#endif
|
||||
sbegin(sbegin)
|
||||
, send(send)
|
||||
, type(type)
|
||||
, line(offset)
|
||||
, column(BINARY_MARKER)
|
||||
{
|
||||
Token::Token(const char* sbegin, const char* send, TokenType type, size_t offset) :
|
||||
#ifdef DEBUG
|
||||
contents(sbegin, static_cast<size_t>(send-sbegin)),
|
||||
#endif
|
||||
sbegin(sbegin),
|
||||
send(send),
|
||||
type(type),
|
||||
line(offset),
|
||||
column(BINARY_MARKER) {
|
||||
ai_assert(sbegin);
|
||||
ai_assert(send);
|
||||
|
||||
|
|
@ -134,7 +91,9 @@ AI_WONT_RETURN void TokenizeError(const std::string& message, size_t offset)
|
|||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
size_t Offset(const char* begin, const char* cursor) {
|
||||
ai_assert(begin <= cursor);
|
||||
if (begin > cursor) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return cursor - begin;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
Open Asset Import Library (assimp)
|
||||
----------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2024, assimp team
|
||||
Copyright (c) 2006-2026, assimp team
|
||||
|
||||
All rights reserved.
|
||||
|
||||
|
|
@ -47,11 +47,11 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
|
||||
#ifndef ASSIMP_BUILD_NO_FBX_EXPORTER
|
||||
|
||||
namespace Assimp {
|
||||
namespace FBX {
|
||||
namespace Assimp::FBX {
|
||||
|
||||
static constexpr size_t NumNullRecords = 25;
|
||||
const char NULL_RECORD[NumNullRecords] = { // 25 null bytes in 64-bit and 13 null bytes in 32-bit
|
||||
|
||||
constexpr char NULL_RECORD[NumNullRecords] = { // 25 null bytes in 64-bit and 13 null bytes in 32-bit
|
||||
'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
|
||||
'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0'
|
||||
}; // who knows why, it looks like two integers 32/64 bit (compressed and uncompressed sizes?) + 1 byte (might be compression type?)
|
||||
|
|
@ -83,8 +83,7 @@ enum TransformInheritance {
|
|||
TransformInheritance_MAX // end-of-enum sentinel
|
||||
};
|
||||
|
||||
} // namespace FBX
|
||||
} // namespace Assimp
|
||||
} // namespace Assimp::FBX
|
||||
|
||||
#endif // ASSIMP_BUILD_NO_FBX_EXPORTER
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
Open Asset Import Library (assimp)
|
||||
----------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2024, assimp team
|
||||
Copyright (c) 2006-2026, assimp team
|
||||
|
||||
All rights reserved.
|
||||
|
||||
|
|
@ -49,7 +49,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
#include <set>
|
||||
|
||||
//
|
||||
#if _MSC_VER > 1500 || (defined __GNUC___)
|
||||
#if _MSC_VER > 1500 || (defined __GNUC__)
|
||||
# define ASSIMP_FBX_USE_UNORDERED_MULTIMAP
|
||||
# else
|
||||
# define fbx_unordered_map map
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
Open Asset Import Library (assimp)
|
||||
----------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2024, assimp team
|
||||
Copyright (c) 2006-2026, assimp team
|
||||
|
||||
All rights reserved.
|
||||
|
||||
|
|
@ -237,7 +237,7 @@ std::string FBXConverter::MakeUniqueNodeName(const Model *const model, const aiN
|
|||
/// When a node becomes a child of another node, that node becomes its owner and mOwnership should be released.
|
||||
struct FBXConverter::PotentialNode {
|
||||
PotentialNode() : mOwnership(new aiNode), mNode(mOwnership.get()) {}
|
||||
PotentialNode(const std::string& name) : mOwnership(new aiNode(name)), mNode(mOwnership.get()) {}
|
||||
explicit PotentialNode(const std::string& name) : mOwnership(new aiNode(name)), mNode(mOwnership.get()) {}
|
||||
aiNode* operator->() { return mNode; }
|
||||
std::unique_ptr<aiNode> mOwnership;
|
||||
aiNode* mNode;
|
||||
|
|
@ -438,7 +438,8 @@ void FBXConverter::ConvertLight(const Light &light, const std::string &orig_name
|
|||
out_light->mType = aiLightSource_UNDEFINED;
|
||||
break;
|
||||
default:
|
||||
ai_assert(false);
|
||||
FBXImporter::LogError("Not handled light type: ", light.LightType());
|
||||
break;
|
||||
}
|
||||
|
||||
float decay = light.DecayStart();
|
||||
|
|
@ -463,7 +464,7 @@ void FBXConverter::ConvertLight(const Light &light, const std::string &orig_name
|
|||
out_light->mAttenuationQuadratic = 1.0f;
|
||||
break;
|
||||
default:
|
||||
ai_assert(false);
|
||||
FBXImporter::LogError("Not handled light decay type: ", light.DecayType());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
@ -601,7 +602,7 @@ const char *FBXConverter::NameTransformationCompProperty(TransformationComp comp
|
|||
return "GeometricRotationInverse";
|
||||
case TransformationComp_GeometricTranslationInverse:
|
||||
return "GeometricTranslationInverse";
|
||||
case TransformationComp_MAXIMUM: // this is to silence compiler warnings
|
||||
case TransformationComp_MAXIMUM:
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
@ -2957,7 +2958,7 @@ void FBXConverter::GenerateNodeAnimations(std::vector<aiNodeAnim *> &node_anims,
|
|||
// be invoked _later_ (animations come first). If this node has only rotation,
|
||||
// scaling and translation _and_ there are no animated other components either,
|
||||
// we can use a single node and also a single node animation channel.
|
||||
if( !has_complex && !NeedsComplexTransformationChain(target)) {
|
||||
if (!doc.Settings().preservePivots || (!has_complex && !NeedsComplexTransformationChain(target))) {
|
||||
aiNodeAnim* const nd = GenerateSimpleNodeAnim(fixed_name, target, chain,
|
||||
node_property_map.end(),
|
||||
start, stop,
|
||||
|
|
@ -3415,7 +3416,7 @@ FBXConverter::KeyFrameListList FBXConverter::GetRotationKeyframeList(const std::
|
|||
KeyFrameListList inputs;
|
||||
inputs.reserve(nodes.size() * 3);
|
||||
|
||||
//give some breathing room for rounding errors
|
||||
// give some breathing room for rounding errors
|
||||
const int64_t adj_start = start - 10000;
|
||||
const int64_t adj_stop = stop + 10000;
|
||||
|
||||
|
|
@ -3441,7 +3442,7 @@ FBXConverter::KeyFrameListList FBXConverter::GetRotationKeyframeList(const std::
|
|||
ai_assert(curve->GetKeys().size() == curve->GetValues().size());
|
||||
ai_assert(curve->GetKeys().size());
|
||||
|
||||
//get values within the start/stop time window
|
||||
// get values within the start/stop time window
|
||||
std::shared_ptr<KeyTimeList> Keys(new KeyTimeList());
|
||||
std::shared_ptr<KeyValueList> Values(new KeyValueList());
|
||||
const size_t count = curve->GetKeys().size();
|
||||
|
|
@ -3461,8 +3462,7 @@ FBXConverter::KeyFrameListList FBXConverter::GetRotationKeyframeList(const std::
|
|||
if (tnew >= adj_start && tnew <= adj_stop) {
|
||||
Keys->push_back(tnew);
|
||||
Values->push_back(vnew);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
// Something broke
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,8 +2,7 @@
|
|||
Open Asset Import Library (assimp)
|
||||
----------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2024, assimp team
|
||||
|
||||
Copyright (c) 2006-2026, assimp team
|
||||
|
||||
All rights reserved.
|
||||
|
||||
|
|
@ -70,7 +69,7 @@ struct morphKeyData {
|
|||
std::vector<unsigned int> values;
|
||||
std::vector<float> weights;
|
||||
};
|
||||
typedef std::map<int64_t, morphKeyData*> morphAnimData;
|
||||
using morphAnimData = std::map<int64_t, morphKeyData*> ;
|
||||
|
||||
namespace Assimp {
|
||||
namespace FBX {
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
Open Asset Import Library (assimp)
|
||||
----------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2024, assimp team
|
||||
Copyright (c) 2006-2026, assimp team
|
||||
|
||||
All rights reserved.
|
||||
|
||||
|
|
@ -45,6 +45,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
|
||||
#ifndef ASSIMP_BUILD_NO_FBX_IMPORTER
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include "FBXParser.h"
|
||||
#include "FBXDocument.h"
|
||||
#include "FBXMeshGeometry.h"
|
||||
|
|
@ -65,9 +67,6 @@ Deformer::Deformer(uint64_t id, const Element& element, const Document& doc, con
|
|||
props = GetPropertyTable(doc,"Deformer.Fbx" + classname,element,sc,true);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Deformer::~Deformer() = default;
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Cluster::Cluster(uint64_t id, const Element& element, const Document& doc, const std::string& name)
|
||||
: Deformer(id,element,doc,name)
|
||||
|
|
@ -113,10 +112,6 @@ Cluster::Cluster(uint64_t id, const Element& element, const Document& doc, const
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Cluster::~Cluster() = default;
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Skin::Skin(uint64_t id, const Element& element, const Document& doc, const std::string& name)
|
||||
: Deformer(id,element,doc,name)
|
||||
|
|
@ -142,9 +137,6 @@ Skin::Skin(uint64_t id, const Element& element, const Document& doc, const std::
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Skin::~Skin() = default;
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
BlendShape::BlendShape(uint64_t id, const Element& element, const Document& doc, const std::string& name)
|
||||
: Deformer(id, element, doc, name)
|
||||
|
|
@ -154,15 +146,16 @@ BlendShape::BlendShape(uint64_t id, const Element& element, const Document& doc,
|
|||
for (const Connection* con : conns) {
|
||||
const BlendShapeChannel* const bspc = ProcessSimpleConnection<BlendShapeChannel>(*con, false, "BlendShapeChannel -> BlendShape", element);
|
||||
if (bspc) {
|
||||
auto pr = blendShapeChannels.insert(bspc);
|
||||
if (!pr.second) {
|
||||
// Only add a channel if it doesn't exist already
|
||||
if (std::find(blendShapeChannels.begin(), blendShapeChannels.end(), bspc) == blendShapeChannels.end()) {
|
||||
blendShapeChannels.push_back(bspc);
|
||||
} else {
|
||||
FBXImporter::LogWarn("there is the same blendShapeChannel id ", bspc->ID());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
BlendShape::~BlendShape() = default;
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
BlendShapeChannel::BlendShapeChannel(uint64_t id, const Element& element, const Document& doc, const std::string& name)
|
||||
: Deformer(id, element, doc, name)
|
||||
|
|
@ -181,17 +174,17 @@ BlendShapeChannel::BlendShapeChannel(uint64_t id, const Element& element, const
|
|||
for (const Connection* con : conns) {
|
||||
const ShapeGeometry* const sg = ProcessSimpleConnection<ShapeGeometry>(*con, false, "Shape -> BlendShapeChannel", element);
|
||||
if (sg) {
|
||||
auto pr = shapeGeometries.insert(sg);
|
||||
if (!pr.second) {
|
||||
// Only add a geometry if it doesn't exist already
|
||||
if (std::find(shapeGeometries.begin(), shapeGeometries.end(), sg) == shapeGeometries.end()) {
|
||||
shapeGeometries.push_back(sg);
|
||||
} else {
|
||||
FBXImporter::LogWarn("there is the same shapeGeometrie id ", sg->ID());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
BlendShapeChannel::~BlendShapeChannel() = default;
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
} // namespace FBX
|
||||
} // Namespace Assimp
|
||||
|
||||
#endif // ASSIMP_BUILD_NO_FBX_IMPORTER
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
Open Asset Import Library (assimp)
|
||||
----------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2024, assimp team
|
||||
Copyright (c) 2006-2026, assimp team
|
||||
|
||||
All rights reserved.
|
||||
|
||||
|
|
@ -269,7 +269,7 @@ Document::~Document()
|
|||
{
|
||||
// The document does not own the memory for the following objects, but we need to call their d'tor
|
||||
// so they can properly free memory like string members:
|
||||
|
||||
|
||||
for (ObjectMap::value_type &v : objects) {
|
||||
delete_LazyObject(v.second);
|
||||
}
|
||||
|
|
@ -663,6 +663,10 @@ LazyObject& Connection::LazyDestinationObject() const {
|
|||
const Object* Connection::SourceObject() const {
|
||||
LazyObject* const lazy = doc.GetObject(src);
|
||||
ai_assert(lazy);
|
||||
if (lazy == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return lazy->Get();
|
||||
}
|
||||
|
||||
|
|
@ -670,6 +674,10 @@ const Object* Connection::SourceObject() const {
|
|||
const Object* Connection::DestinationObject() const {
|
||||
LazyObject* const lazy = doc.GetObject(dest);
|
||||
ai_assert(lazy);
|
||||
if (lazy == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return lazy->Get();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
Open Asset Import Library (assimp)
|
||||
----------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2024, assimp team
|
||||
Copyright (c) 2006-2026, assimp team
|
||||
|
||||
All rights reserved.
|
||||
|
||||
|
|
@ -174,7 +174,7 @@ class NodeAttribute : public Object {
|
|||
public:
|
||||
NodeAttribute(uint64_t id, const Element& element, const Document& doc, const std::string& name);
|
||||
|
||||
virtual ~NodeAttribute() = default;
|
||||
~NodeAttribute() override = default;
|
||||
|
||||
const PropertyTable& Props() const {
|
||||
ai_assert(props.get());
|
||||
|
|
@ -186,11 +186,11 @@ private:
|
|||
};
|
||||
|
||||
/** DOM base class for FBX camera settings attached to a node */
|
||||
class CameraSwitcher : public NodeAttribute {
|
||||
class CameraSwitcher final : public NodeAttribute {
|
||||
public:
|
||||
CameraSwitcher(uint64_t id, const Element& element, const Document& doc, const std::string& name);
|
||||
|
||||
virtual ~CameraSwitcher() = default;
|
||||
~CameraSwitcher() override= default;
|
||||
|
||||
int CameraID() const {
|
||||
return cameraId;
|
||||
|
|
@ -231,11 +231,11 @@ private:
|
|||
|
||||
|
||||
/** DOM base class for FBX cameras attached to a node */
|
||||
class Camera : public NodeAttribute {
|
||||
class Camera final : public NodeAttribute {
|
||||
public:
|
||||
Camera(uint64_t id, const Element& element, const Document& doc, const std::string& name);
|
||||
|
||||
virtual ~Camera() = default;
|
||||
~Camera() override = default;
|
||||
|
||||
fbx_simple_property(Position, aiVector3D, aiVector3D(0,0,0))
|
||||
fbx_simple_property(UpVector, aiVector3D, aiVector3D(0,1,0))
|
||||
|
|
@ -257,24 +257,24 @@ public:
|
|||
};
|
||||
|
||||
/** DOM base class for FBX null markers attached to a node */
|
||||
class Null : public NodeAttribute {
|
||||
class Null final : public NodeAttribute {
|
||||
public:
|
||||
Null(uint64_t id, const Element& element, const Document& doc, const std::string& name);
|
||||
virtual ~Null() = default;
|
||||
~Null() override = default;
|
||||
};
|
||||
|
||||
/** DOM base class for FBX limb node markers attached to a node */
|
||||
class LimbNode : public NodeAttribute {
|
||||
class LimbNode final : public NodeAttribute {
|
||||
public:
|
||||
LimbNode(uint64_t id, const Element& element, const Document& doc, const std::string& name);
|
||||
virtual ~LimbNode() = default;
|
||||
~LimbNode() override = default;
|
||||
};
|
||||
|
||||
/** DOM base class for FBX lights attached to a node */
|
||||
class Light : public NodeAttribute {
|
||||
class Light final : public NodeAttribute {
|
||||
public:
|
||||
Light(uint64_t id, const Element& element, const Document& doc, const std::string& name);
|
||||
virtual ~Light() = default;
|
||||
~Light() override = default;
|
||||
|
||||
enum Type {
|
||||
Type_Point,
|
||||
|
|
@ -329,7 +329,7 @@ public:
|
|||
};
|
||||
|
||||
/** DOM base class for FBX models (even though its semantics are more "node" than "model" */
|
||||
class Model : public Object {
|
||||
class Model final : public Object {
|
||||
public:
|
||||
enum RotOrder {
|
||||
RotOrder_EulerXYZ = 0,
|
||||
|
|
@ -354,7 +354,7 @@ public:
|
|||
|
||||
Model(uint64_t id, const Element& element, const Document& doc, const std::string& name);
|
||||
|
||||
virtual ~Model() = default;
|
||||
~Model() override = default;
|
||||
|
||||
fbx_simple_property(QuaternionInterpolate, int, 0)
|
||||
|
||||
|
|
@ -477,11 +477,11 @@ private:
|
|||
};
|
||||
|
||||
/** DOM class for generic FBX textures */
|
||||
class Texture : public Object {
|
||||
class Texture final : public Object {
|
||||
public:
|
||||
Texture(uint64_t id, const Element& element, const Document& doc, const std::string& name);
|
||||
|
||||
virtual ~Texture();
|
||||
~Texture() override;
|
||||
|
||||
const std::string& Type() const {
|
||||
return type;
|
||||
|
|
@ -542,10 +542,10 @@ private:
|
|||
};
|
||||
|
||||
/** DOM class for layered FBX textures */
|
||||
class LayeredTexture : public Object {
|
||||
class LayeredTexture final : public Object {
|
||||
public:
|
||||
LayeredTexture(uint64_t id, const Element& element, const Document& doc, const std::string& name);
|
||||
virtual ~LayeredTexture();
|
||||
~LayeredTexture() override;
|
||||
|
||||
// Can only be called after construction of the layered texture object due to construction flag.
|
||||
void fillTexture(const Document& doc);
|
||||
|
|
@ -608,11 +608,11 @@ using TextureMap = std::fbx_unordered_map<std::string, const Texture*>;
|
|||
using LayeredTextureMap = std::fbx_unordered_map<std::string, const LayeredTexture*>;
|
||||
|
||||
/** DOM class for generic FBX videos */
|
||||
class Video : public Object {
|
||||
class Video final : public Object {
|
||||
public:
|
||||
Video(uint64_t id, const Element& element, const Document& doc, const std::string& name);
|
||||
|
||||
virtual ~Video();
|
||||
~Video() override;
|
||||
|
||||
const std::string& Type() const {
|
||||
return type;
|
||||
|
|
@ -657,11 +657,11 @@ private:
|
|||
};
|
||||
|
||||
/** DOM class for generic FBX materials */
|
||||
class Material : public Object {
|
||||
class Material final : public Object {
|
||||
public:
|
||||
Material(uint64_t id, const Element& element, const Document& doc, const std::string& name);
|
||||
|
||||
virtual ~Material();
|
||||
~Material() override = default;
|
||||
|
||||
const std::string& GetShadingModel() const {
|
||||
return shading;
|
||||
|
|
@ -697,10 +697,10 @@ using KeyTimeList = std::vector<int64_t>;
|
|||
using KeyValueList = std::vector<float>;
|
||||
|
||||
/** Represents a FBX animation curve (i.e. a 1-dimensional set of keyframes and values therefore) */
|
||||
class AnimationCurve : public Object {
|
||||
class AnimationCurve final : public Object {
|
||||
public:
|
||||
AnimationCurve(uint64_t id, const Element& element, const std::string& name, const Document& doc);
|
||||
virtual ~AnimationCurve() = default;
|
||||
~AnimationCurve() override = default;
|
||||
|
||||
/** get list of keyframe positions (time).
|
||||
* Invariant: |GetKeys()| > 0 */
|
||||
|
|
@ -733,7 +733,7 @@ private:
|
|||
using AnimationCurveMap = std::map<std::string, const AnimationCurve*>;
|
||||
|
||||
/** Represents a FBX animation curve (i.e. a mapping from single animation curves to nodes) */
|
||||
class AnimationCurveNode : public Object {
|
||||
class AnimationCurveNode final : public Object {
|
||||
public:
|
||||
/* the optional white list specifies a list of property names for which the caller
|
||||
wants animations for. If the curve node does not match one of these, std::range_error
|
||||
|
|
@ -741,7 +741,7 @@ public:
|
|||
AnimationCurveNode(uint64_t id, const Element& element, const std::string& name, const Document& doc,
|
||||
const char *const *target_prop_whitelist = nullptr, size_t whitelist_size = 0);
|
||||
|
||||
virtual ~AnimationCurveNode() = default;
|
||||
~AnimationCurveNode() override = default;
|
||||
|
||||
const PropertyTable& Props() const {
|
||||
ai_assert(props.get());
|
||||
|
|
@ -783,7 +783,7 @@ private:
|
|||
using AnimationCurveNodeList = std::vector<const AnimationCurveNode*>;
|
||||
|
||||
/** Represents a FBX animation layer (i.e. a list of node animations) */
|
||||
class AnimationLayer : public Object {
|
||||
class AnimationLayer final : public Object {
|
||||
public:
|
||||
AnimationLayer(uint64_t id, const Element& element, const std::string& name, const Document& doc);
|
||||
virtual ~AnimationLayer() = default;
|
||||
|
|
@ -806,7 +806,7 @@ private:
|
|||
using AnimationLayerList = std::vector<const AnimationLayer*>;
|
||||
|
||||
/** Represents a FBX animation stack (i.e. a list of animation layers) */
|
||||
class AnimationStack : public Object {
|
||||
class AnimationStack final : public Object {
|
||||
public:
|
||||
AnimationStack(uint64_t id, const Element& element, const std::string& name, const Document& doc);
|
||||
virtual ~AnimationStack() = default;
|
||||
|
|
@ -835,7 +835,7 @@ private:
|
|||
class Deformer : public Object {
|
||||
public:
|
||||
Deformer(uint64_t id, const Element& element, const Document& doc, const std::string& name);
|
||||
virtual ~Deformer();
|
||||
virtual ~Deformer() = default;
|
||||
|
||||
const PropertyTable& Props() const {
|
||||
ai_assert(props.get());
|
||||
|
|
@ -851,11 +851,11 @@ using WeightIndexArray = std::vector<unsigned int>;
|
|||
|
||||
|
||||
/** DOM class for BlendShapeChannel deformers */
|
||||
class BlendShapeChannel : public Deformer {
|
||||
class BlendShapeChannel final : public Deformer {
|
||||
public:
|
||||
BlendShapeChannel(uint64_t id, const Element& element, const Document& doc, const std::string& name);
|
||||
|
||||
virtual ~BlendShapeChannel();
|
||||
virtual ~BlendShapeChannel() = default;
|
||||
|
||||
float DeformPercent() const {
|
||||
return percent;
|
||||
|
|
@ -865,37 +865,37 @@ public:
|
|||
return fullWeights;
|
||||
}
|
||||
|
||||
const std::unordered_set<const ShapeGeometry*>& GetShapeGeometries() const {
|
||||
const std::vector<const ShapeGeometry*>& GetShapeGeometries() const {
|
||||
return shapeGeometries;
|
||||
}
|
||||
|
||||
private:
|
||||
float percent;
|
||||
WeightArray fullWeights;
|
||||
std::unordered_set<const ShapeGeometry*> shapeGeometries;
|
||||
std::vector<const ShapeGeometry*> shapeGeometries;
|
||||
};
|
||||
|
||||
/** DOM class for BlendShape deformers */
|
||||
class BlendShape : public Deformer {
|
||||
class BlendShape final : public Deformer {
|
||||
public:
|
||||
BlendShape(uint64_t id, const Element& element, const Document& doc, const std::string& name);
|
||||
|
||||
virtual ~BlendShape();
|
||||
virtual ~BlendShape() = default;
|
||||
|
||||
const std::unordered_set<const BlendShapeChannel*>& BlendShapeChannels() const {
|
||||
const std::vector<const BlendShapeChannel*>& BlendShapeChannels() const {
|
||||
return blendShapeChannels;
|
||||
}
|
||||
|
||||
private:
|
||||
std::unordered_set<const BlendShapeChannel*> blendShapeChannels;
|
||||
std::vector<const BlendShapeChannel*> blendShapeChannels;
|
||||
};
|
||||
|
||||
/** DOM class for skin deformer clusters (aka sub-deformers) */
|
||||
class Cluster : public Deformer {
|
||||
class Cluster final : public Deformer {
|
||||
public:
|
||||
Cluster(uint64_t id, const Element& element, const Document& doc, const std::string& name);
|
||||
|
||||
virtual ~Cluster();
|
||||
virtual ~Cluster() = default;
|
||||
|
||||
/** get the list of deformer weights associated with this cluster.
|
||||
* Use #GetIndices() to get the associated vertices. Both arrays
|
||||
|
|
@ -935,11 +935,11 @@ private:
|
|||
};
|
||||
|
||||
/** DOM class for skin deformers */
|
||||
class Skin : public Deformer {
|
||||
class Skin final : public Deformer {
|
||||
public:
|
||||
Skin(uint64_t id, const Element& element, const Document& doc, const std::string& name);
|
||||
|
||||
virtual ~Skin();
|
||||
virtual ~Skin() = default;
|
||||
|
||||
float DeformAccuracy() const {
|
||||
return accuracy;
|
||||
|
|
|
|||
|
|
@ -2,8 +2,7 @@
|
|||
Open Asset Import Library (assimp)
|
||||
----------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2024, assimp team
|
||||
|
||||
Copyright (c) 2006-2026, assimp team
|
||||
|
||||
All rights reserved.
|
||||
|
||||
|
|
@ -36,7 +35,6 @@ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
----------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
|
|
@ -81,8 +79,7 @@ void DOMWarning(const std::string& message, const Token& token) {
|
|||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void DOMWarning(const std::string& message, const Element* element /*= nullptr*/)
|
||||
{
|
||||
void DOMWarning(const std::string& message, const Element* element /*= nullptr*/) {
|
||||
if(element) {
|
||||
DOMWarning(message,element->KeyToken());
|
||||
return;
|
||||
|
|
@ -92,41 +89,39 @@ void DOMWarning(const std::string& message, const Element* element /*= nullptr*/
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// fetch a property table and the corresponding property template
|
||||
std::shared_ptr<const PropertyTable> GetPropertyTable(const Document& doc,
|
||||
const std::string& templateName,
|
||||
const Element &element,
|
||||
const Scope& sc,
|
||||
bool no_warn /*= false*/)
|
||||
{
|
||||
const std::string& templateName,
|
||||
const Element &element,
|
||||
const Scope& sc,
|
||||
bool no_warn /*= false*/) {
|
||||
const Element* const Properties70 = sc["Properties70"];
|
||||
std::shared_ptr<const PropertyTable> templateProps = std::shared_ptr<const PropertyTable>(
|
||||
static_cast<const PropertyTable *>(nullptr));
|
||||
|
||||
if(templateName.length()) {
|
||||
if (templateName.length()) {
|
||||
PropertyTemplateMap::const_iterator it = doc.Templates().find(templateName);
|
||||
if(it != doc.Templates().end()) {
|
||||
templateProps = (*it).second;
|
||||
}
|
||||
}
|
||||
|
||||
if(!Properties70 || !Properties70->Compound()) {
|
||||
if (!Properties70 || !Properties70->Compound()) {
|
||||
if(!no_warn) {
|
||||
DOMWarning("property table (Properties70) not found",&element);
|
||||
}
|
||||
if(templateProps) {
|
||||
return templateProps;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return std::make_shared<const PropertyTable>();
|
||||
}
|
||||
}
|
||||
return std::make_shared<const PropertyTable>(*Properties70,templateProps);
|
||||
}
|
||||
|
||||
} // !Util
|
||||
} // !FBX
|
||||
} // !Assimp
|
||||
|
||||
#endif
|
||||
#endif // ASSIMP_BUILD_NO_FBX_IMPORTER
|
||||
|
|
|
|||
|
|
@ -114,4 +114,4 @@ inline const T* ProcessSimpleConnection(const Connection& con,
|
|||
} //!FBX
|
||||
} //!Assimp
|
||||
|
||||
#endif
|
||||
#endif // ASSIMP_BUILD_NO_FBX_IMPORTER
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
Open Asset Import Library (assimp)
|
||||
----------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2024, assimp team
|
||||
Copyright (c) 2006-2026, assimp team
|
||||
|
||||
All rights reserved.
|
||||
|
||||
|
|
@ -35,7 +35,6 @@ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
----------------------------------------------------------------------
|
||||
*/
|
||||
#ifndef ASSIMP_BUILD_NO_EXPORT
|
||||
|
|
@ -55,37 +54,31 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
#include <memory> // shared_ptr
|
||||
|
||||
namespace Assimp {
|
||||
|
||||
// AddP70<type> helpers... there's no usable pattern here,
|
||||
// so all are defined as separate functions.
|
||||
// Even "animatable" properties are often completely different
|
||||
// from the standard (nonanimated) property definition,
|
||||
// so they are specified with an 'A' suffix.
|
||||
|
||||
void FBX::Node::AddP70int(
|
||||
const std::string& cur_name, int32_t value
|
||||
) {
|
||||
void FBX::Node::AddP70int(const std::string& cur_name, int32_t value) {
|
||||
FBX::Node n("P");
|
||||
n.AddProperties(cur_name, "int", "Integer", "", value);
|
||||
AddChild(n);
|
||||
}
|
||||
|
||||
void FBX::Node::AddP70bool(
|
||||
const std::string& cur_name, bool value
|
||||
) {
|
||||
void FBX::Node::AddP70bool(const std::string& cur_name, bool value) {
|
||||
FBX::Node n("P");
|
||||
n.AddProperties(cur_name, "bool", "", "", int32_t(value));
|
||||
AddChild(n);
|
||||
}
|
||||
|
||||
void FBX::Node::AddP70double(
|
||||
const std::string &cur_name, double value) {
|
||||
FBX::Node n("P");
|
||||
void FBX::Node::AddP70double(const std::string &cur_name, double value) { FBX::Node n("P");
|
||||
n.AddProperties(cur_name, "double", "Number", "", value);
|
||||
AddChild(n);
|
||||
}
|
||||
|
||||
void FBX::Node::AddP70numberA(
|
||||
const std::string &cur_name, double value) {
|
||||
void FBX::Node::AddP70numberA(const std::string &cur_name, double value) {
|
||||
FBX::Node n("P");
|
||||
n.AddProperties(cur_name, "Number", "", "A", value);
|
||||
AddChild(n);
|
||||
|
|
@ -405,8 +398,7 @@ void FBX::Node::DumpChildrenAscii(std::ostream& s, int indent)
|
|||
}
|
||||
}
|
||||
|
||||
void FBX::Node::EndAscii(std::ostream& s, int indent, bool has_children)
|
||||
{
|
||||
void FBX::Node::EndAscii(std::ostream& s, int indent, bool has_children) {
|
||||
if (!has_children) { return; } // nothing to do
|
||||
s << '\n';
|
||||
for (int i = 0; i < indent; ++i) { s << '\t'; }
|
||||
|
|
@ -417,11 +409,10 @@ void FBX::Node::EndAscii(std::ostream& s, int indent, bool has_children)
|
|||
|
||||
// ascii property node from vector of doubles
|
||||
void FBX::Node::WritePropertyNodeAscii(
|
||||
const std::string& name,
|
||||
const std::vector<double>& v,
|
||||
Assimp::StreamWriterLE& s,
|
||||
int indent
|
||||
){
|
||||
const std::string& name,
|
||||
const std::vector<double>& v,
|
||||
Assimp::StreamWriterLE& s,
|
||||
int indent){
|
||||
char buffer[32];
|
||||
FBX::Node node(name);
|
||||
node.Begin(s, false, indent);
|
||||
|
|
@ -556,6 +547,8 @@ void FBX::Node::WritePropertyNode(
|
|||
FBX::Node::WritePropertyNodeAscii(name, v, s, indent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Assimp
|
||||
|
||||
#endif // ASSIMP_BUILD_NO_FBX_EXPORTER
|
||||
#endif // ASSIMP_BUILD_NO_EXPORT
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
Open Asset Import Library (assimp)
|
||||
----------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2024, assimp team
|
||||
Copyright (c) 2006-2026, assimp team
|
||||
|
||||
All rights reserved.
|
||||
|
||||
|
|
@ -35,7 +35,6 @@ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
----------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
|
|
@ -70,7 +69,6 @@ public:
|
|||
// some nodes always pretend they have children...
|
||||
bool force_has_children = false;
|
||||
|
||||
public: // constructors
|
||||
/// The default class constructor.
|
||||
Node() = default;
|
||||
|
||||
|
|
@ -89,7 +87,6 @@ public: // constructors
|
|||
AddProperties(std::forward<More>(more)...);
|
||||
}
|
||||
|
||||
public: // functions to add properties or children
|
||||
// add a single property to the node
|
||||
template <typename T>
|
||||
void AddProperty(T&& value) {
|
||||
|
|
@ -118,8 +115,6 @@ public: // functions to add properties or children
|
|||
children.push_back(std::move(c));
|
||||
}
|
||||
|
||||
public: // support specifically for dealing with Properties70 nodes
|
||||
|
||||
// it really is simpler to make these all separate functions.
|
||||
// the versions with 'A' suffixes are for animatable properties.
|
||||
// those often follow a completely different format internally in FBX.
|
||||
|
|
@ -150,8 +145,6 @@ public: // support specifically for dealing with Properties70 nodes
|
|||
AddChild(n);
|
||||
}
|
||||
|
||||
public: // member functions for writing data to a file or stream
|
||||
|
||||
// write the full node to the given file or stream
|
||||
void Dump(
|
||||
const std::shared_ptr<Assimp::IOStream> &outfile,
|
||||
|
|
@ -175,31 +168,6 @@ public: // member functions for writing data to a file or stream
|
|||
bool has_children
|
||||
);
|
||||
|
||||
private: // internal functions used for writing
|
||||
|
||||
void DumpBinary(Assimp::StreamWriterLE &s);
|
||||
void DumpAscii(Assimp::StreamWriterLE &s, int indent);
|
||||
void DumpAscii(std::ostream &s, int indent);
|
||||
|
||||
void BeginBinary(Assimp::StreamWriterLE &s);
|
||||
void DumpPropertiesBinary(Assimp::StreamWriterLE& s);
|
||||
void EndPropertiesBinary(Assimp::StreamWriterLE &s);
|
||||
void EndPropertiesBinary(Assimp::StreamWriterLE &s, size_t num_properties);
|
||||
void DumpChildrenBinary(Assimp::StreamWriterLE& s);
|
||||
void EndBinary(Assimp::StreamWriterLE &s, bool has_children);
|
||||
|
||||
void BeginAscii(std::ostream &s, int indent);
|
||||
void DumpPropertiesAscii(std::ostream &s, int indent);
|
||||
void BeginChildrenAscii(std::ostream &s, int indent);
|
||||
void DumpChildrenAscii(std::ostream &s, int indent);
|
||||
void EndAscii(std::ostream &s, int indent, bool has_children);
|
||||
|
||||
private: // data used for binary dumps
|
||||
size_t start_pos; // starting position in stream
|
||||
size_t end_pos; // ending position in stream
|
||||
size_t property_start; // starting position of property section
|
||||
|
||||
public: // static member functions
|
||||
|
||||
// convenience function to create a node with a single property,
|
||||
// and write it to the stream.
|
||||
|
|
@ -235,7 +203,26 @@ public: // static member functions
|
|||
bool binary, int indent
|
||||
);
|
||||
|
||||
private: // static helper functions
|
||||
private: // internal functions used for writing
|
||||
|
||||
void DumpBinary(Assimp::StreamWriterLE &s);
|
||||
void DumpAscii(Assimp::StreamWriterLE &s, int indent);
|
||||
void DumpAscii(std::ostream &s, int indent);
|
||||
|
||||
void BeginBinary(Assimp::StreamWriterLE &s);
|
||||
void DumpPropertiesBinary(Assimp::StreamWriterLE& s);
|
||||
void EndPropertiesBinary(Assimp::StreamWriterLE &s);
|
||||
void EndPropertiesBinary(Assimp::StreamWriterLE &s, size_t num_properties);
|
||||
void DumpChildrenBinary(Assimp::StreamWriterLE& s);
|
||||
void EndBinary(Assimp::StreamWriterLE &s, bool has_children);
|
||||
|
||||
void BeginAscii(std::ostream &s, int indent);
|
||||
void DumpPropertiesAscii(std::ostream &s, int indent);
|
||||
void BeginChildrenAscii(std::ostream &s, int indent);
|
||||
void DumpChildrenAscii(std::ostream &s, int indent);
|
||||
void EndAscii(std::ostream &s, int indent, bool has_children);
|
||||
|
||||
// static helper functions
|
||||
static void WritePropertyNodeAscii(
|
||||
const std::string& name,
|
||||
const std::vector<double>& v,
|
||||
|
|
@ -259,9 +246,13 @@ private: // static helper functions
|
|||
Assimp::StreamWriterLE& s
|
||||
);
|
||||
|
||||
private: // data used for binary dumps
|
||||
size_t start_pos; // starting position in stream
|
||||
size_t end_pos; // ending position in stream
|
||||
size_t property_start; // starting position of property section
|
||||
};
|
||||
}
|
||||
|
||||
} // Namespace Assimp
|
||||
|
||||
#endif // ASSIMP_BUILD_NO_FBX_EXPORTER
|
||||
|
||||
#endif // AI_FBXEXPORTNODE_H_INC
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
Open Asset Import Library (assimp)
|
||||
----------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2024, assimp team
|
||||
Copyright (c) 2006-2026, assimp team
|
||||
|
||||
All rights reserved.
|
||||
|
||||
|
|
@ -286,6 +286,8 @@ void FBXExportProperty::DumpAscii(std::ostream& s, int indent) {
|
|||
break;
|
||||
}
|
||||
}
|
||||
// assimp issue #6112; fallthrough confirmed by @mesilliac
|
||||
[[fallthrough]];
|
||||
case 'R':
|
||||
s << '"';
|
||||
// we might as well check this now,
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
Open Asset Import Library (assimp)
|
||||
----------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2024, assimp team
|
||||
Copyright (c) 2006-2026, assimp team
|
||||
|
||||
All rights reserved.
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
Open Asset Import Library (assimp)
|
||||
----------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2024, assimp team
|
||||
Copyright (c) 2006-2026, assimp team
|
||||
|
||||
All rights reserved.
|
||||
|
||||
|
|
@ -51,6 +51,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
#include <assimp/IOSystem.hpp>
|
||||
#include <assimp/Exporter.hpp>
|
||||
#include <assimp/DefaultLogger.hpp>
|
||||
#include <assimp/Logger.hpp>
|
||||
#include <assimp/StreamWriter.h> // StreamWriterLE
|
||||
#include <assimp/Exceptional.h> // DeadlyExportError
|
||||
#include <assimp/material.h> // aiTextureType
|
||||
|
|
@ -370,12 +371,6 @@ void FBXExporter::WriteHeaderExtension ()
|
|||
"Creator", creator.str(), outstream, binary, indent
|
||||
);
|
||||
|
||||
//FBX::Node sceneinfo("SceneInfo");
|
||||
//sceneinfo.AddProperty("GlobalInfo" + FBX::SEPARATOR + "SceneInfo");
|
||||
// not sure if any of this is actually needed,
|
||||
// so just write an empty node for now.
|
||||
//sceneinfo.Dump(outstream, binary, indent);
|
||||
|
||||
indent = 0;
|
||||
|
||||
// finish node
|
||||
|
|
@ -459,11 +454,7 @@ void WritePropString(const aiScene* scene, FBX::Node& p, const std::string& key,
|
|||
}
|
||||
}
|
||||
|
||||
void FBXExporter::WriteGlobalSettings ()
|
||||
{
|
||||
if (!binary) {
|
||||
// no title, follows directly from the header extension
|
||||
}
|
||||
void FBXExporter::WriteGlobalSettings () {
|
||||
FBX::Node gs("GlobalSettings");
|
||||
gs.AddChild("Version", int32_t(1000));
|
||||
|
||||
|
|
@ -493,8 +484,7 @@ void FBXExporter::WriteGlobalSettings ()
|
|||
gs.Dump(outfile, binary, 0);
|
||||
}
|
||||
|
||||
void FBXExporter::WriteDocuments ()
|
||||
{
|
||||
void FBXExporter::WriteDocuments() {
|
||||
if (!binary) {
|
||||
WriteAsciiSectionHeader("Documents Description");
|
||||
}
|
||||
|
|
@ -523,8 +513,7 @@ void FBXExporter::WriteDocuments ()
|
|||
docs.Dump(outfile, binary, 0);
|
||||
}
|
||||
|
||||
void FBXExporter::WriteReferences ()
|
||||
{
|
||||
void FBXExporter::WriteReferences() {
|
||||
if (!binary) {
|
||||
WriteAsciiSectionHeader("Document References");
|
||||
}
|
||||
|
|
@ -540,7 +529,6 @@ void FBXExporter::WriteReferences ()
|
|||
// some internal helper functions used for writing the definitions
|
||||
// (before any actual data is written)
|
||||
// ---------------------------------------------------------------
|
||||
|
||||
size_t count_nodes(const aiNode* n, const aiNode* root) {
|
||||
size_t count;
|
||||
if (n == root) {
|
||||
|
|
@ -556,8 +544,7 @@ size_t count_nodes(const aiNode* n, const aiNode* root) {
|
|||
return count;
|
||||
}
|
||||
|
||||
bool has_phong_mat(const aiScene* scene)
|
||||
{
|
||||
static bool has_phong_mat(const aiScene* scene) {
|
||||
// just search for any material with a shininess exponent
|
||||
for (size_t i = 0; i < scene->mNumMaterials; ++i) {
|
||||
aiMaterial* mat = scene->mMaterials[i];
|
||||
|
|
@ -570,16 +557,12 @@ bool has_phong_mat(const aiScene* scene)
|
|||
return false;
|
||||
}
|
||||
|
||||
size_t count_images(const aiScene* scene) {
|
||||
static size_t count_images(const aiScene* scene) {
|
||||
std::unordered_set<std::string> images;
|
||||
aiString texpath;
|
||||
for (size_t i = 0; i < scene->mNumMaterials; ++i) {
|
||||
aiMaterial* mat = scene->mMaterials[i];
|
||||
for (
|
||||
size_t tt = aiTextureType_DIFFUSE;
|
||||
tt < aiTextureType_UNKNOWN;
|
||||
++tt
|
||||
){
|
||||
aiMaterial *mat = scene->mMaterials[i];
|
||||
for (size_t tt = aiTextureType_DIFFUSE; tt < aiTextureType_UNKNOWN; ++tt) {
|
||||
const aiTextureType textype = static_cast<aiTextureType>(tt);
|
||||
const size_t texcount = mat->GetTextureCount(textype);
|
||||
for (unsigned int j = 0; j < texcount; ++j) {
|
||||
|
|
@ -588,10 +571,11 @@ size_t count_images(const aiScene* scene) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
return images.size();
|
||||
}
|
||||
|
||||
size_t count_textures(const aiScene* scene) {
|
||||
static size_t count_textures(const aiScene* scene) {
|
||||
size_t count = 0;
|
||||
for (size_t i = 0; i < scene->mNumMaterials; ++i) {
|
||||
aiMaterial* mat = scene->mMaterials[i];
|
||||
|
|
@ -609,7 +593,7 @@ size_t count_textures(const aiScene* scene) {
|
|||
return count;
|
||||
}
|
||||
|
||||
size_t count_deformers(const aiScene* scene) {
|
||||
static size_t count_deformers(const aiScene* scene) {
|
||||
size_t count = 0;
|
||||
for (size_t i = 0; i < scene->mNumMeshes; ++i) {
|
||||
const size_t n = scene->mMeshes[i]->mNumBones;
|
||||
|
|
@ -621,8 +605,7 @@ size_t count_deformers(const aiScene* scene) {
|
|||
return count;
|
||||
}
|
||||
|
||||
void FBXExporter::WriteDefinitions ()
|
||||
{
|
||||
void FBXExporter::WriteDefinitions () {
|
||||
// basically this is just bookkeeping:
|
||||
// determining how many of each type of object there are
|
||||
// and specifying the base properties to use when otherwise unspecified.
|
||||
|
|
@ -1033,9 +1016,7 @@ void FBXExporter::WriteDefinitions ()
|
|||
// some internal helper functions used for writing the objects section
|
||||
// (which holds the actual data)
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
aiNode* get_node_for_mesh(unsigned int meshIndex, aiNode* node)
|
||||
{
|
||||
static aiNode* get_node_for_mesh(unsigned int meshIndex, aiNode* node) {
|
||||
for (size_t i = 0; i < node->mNumMeshes; ++i) {
|
||||
if (node->mMeshes[i] == meshIndex) {
|
||||
return node;
|
||||
|
|
@ -1048,8 +1029,7 @@ aiNode* get_node_for_mesh(unsigned int meshIndex, aiNode* node)
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
aiMatrix4x4 get_world_transform(const aiNode* node, const aiScene* scene)
|
||||
{
|
||||
aiMatrix4x4 get_world_transform(const aiNode* node, const aiScene* scene) {
|
||||
std::vector<const aiNode*> node_chain;
|
||||
while (node != scene->mRootNode && node != nullptr) {
|
||||
node_chain.push_back(node);
|
||||
|
|
@ -1063,18 +1043,47 @@ aiMatrix4x4 get_world_transform(const aiNode* node, const aiScene* scene)
|
|||
}
|
||||
|
||||
inline int64_t to_ktime(double ticks, const aiAnimation* anim) {
|
||||
if (FP_ZERO == std::fpclassify(anim->mTicksPerSecond)) {
|
||||
return static_cast<int64_t>(ticks) * FBX::SECOND;
|
||||
if (FP_ZERO == std::fpclassify(anim->mTicksPerSecond)) {
|
||||
return static_cast<int64_t>(ticks * FBX::SECOND);
|
||||
}
|
||||
return (static_cast<int64_t>(ticks / anim->mTicksPerSecond)) * FBX::SECOND;
|
||||
|
||||
// Defensive: handle zero or near-zero mTicksPerSecond
|
||||
double tps = anim->mTicksPerSecond;
|
||||
double timeVal;
|
||||
if (FP_ZERO == std::fpclassify(tps)) {
|
||||
timeVal = ticks;
|
||||
} else {
|
||||
timeVal = ticks / tps;
|
||||
}
|
||||
|
||||
// Clamp to prevent overflow
|
||||
const double kMax = static_cast<double>(INT64_MAX) / static_cast<double>(FBX::SECOND);
|
||||
const double kMin = static_cast<double>(INT64_MIN) / static_cast<double>(FBX::SECOND);
|
||||
|
||||
if (timeVal > kMax) {
|
||||
return INT64_MAX;
|
||||
}
|
||||
if (timeVal < kMin) {
|
||||
return INT64_MIN;
|
||||
}
|
||||
return static_cast<int64_t>((ticks / anim->mTicksPerSecond) * FBX::SECOND);
|
||||
}
|
||||
|
||||
inline int64_t to_ktime(double time) {
|
||||
return (static_cast<int64_t>(time * FBX::SECOND));
|
||||
// Clamp to prevent overflow
|
||||
const double kMax = static_cast<double>(INT64_MAX) / static_cast<double>(FBX::SECOND);
|
||||
const double kMin = static_cast<double>(INT64_MIN) / static_cast<double>(FBX::SECOND);
|
||||
|
||||
if (time > kMax) {
|
||||
return INT64_MAX;
|
||||
}
|
||||
if (time < kMin) {
|
||||
return INT64_MIN;
|
||||
}
|
||||
return static_cast<int64_t>(time * FBX::SECOND);
|
||||
}
|
||||
|
||||
void FBXExporter::WriteObjects ()
|
||||
{
|
||||
void FBXExporter::WriteObjects () {
|
||||
if (!binary) {
|
||||
WriteAsciiSectionHeader("Object properties");
|
||||
}
|
||||
|
|
@ -1087,21 +1096,27 @@ void FBXExporter::WriteObjects ()
|
|||
object_node.BeginChildren(outstream, binary, indent);
|
||||
|
||||
bool bJoinIdenticalVertices = mProperties->GetPropertyBool("bJoinIdenticalVertices", true);
|
||||
std::vector<std::vector<int32_t>> vVertexIndice;//save vertex_indices as it is needed later
|
||||
// save vertex_indices as it is needed later
|
||||
std::vector<std::vector<int32_t>> vVertexIndice(mScene->mNumMeshes);
|
||||
std::vector<uint32_t> uniq_v_before_mi;
|
||||
|
||||
const auto bTransparencyFactorReferencedToOpacity = mProperties->GetPropertyBool(AI_CONFIG_EXPORT_FBX_TRANSPARENCY_FACTOR_REFER_TO_OPACITY, false);
|
||||
|
||||
// geometry (aiMesh)
|
||||
mesh_uids.clear();
|
||||
indent = 1;
|
||||
for (size_t mi = 0; mi < mScene->mNumMeshes; ++mi) {
|
||||
// it's all about this mesh
|
||||
aiMesh* m = mScene->mMeshes[mi];
|
||||
std::function<void(const aiNode*)> visit_node_geo = [&](const aiNode *node) {
|
||||
if (node->mNumMeshes == 0) {
|
||||
for (uint32_t ni = 0; ni < node->mNumChildren; ni++) {
|
||||
visit_node_geo(node->mChildren[ni]);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// start the node record
|
||||
FBX::Node n("Geometry");
|
||||
int64_t uid = generate_uid();
|
||||
mesh_uids.push_back(uid);
|
||||
mesh_uids[node] = uid;
|
||||
n.AddProperty(uid);
|
||||
n.AddProperty(FBX::SEPARATOR + "Geometry");
|
||||
n.AddProperty("Mesh");
|
||||
|
|
@ -1109,159 +1124,113 @@ void FBXExporter::WriteObjects ()
|
|||
n.DumpProperties(outstream, binary, indent);
|
||||
n.EndProperties(outstream, binary, indent);
|
||||
n.BeginChildren(outstream, binary, indent);
|
||||
indent = 2;
|
||||
|
||||
// output vertex data - each vertex should be unique (probably)
|
||||
std::vector<double> flattened_vertices;
|
||||
// index of original vertex in vertex data vector
|
||||
std::vector<int32_t> vertex_indices;
|
||||
// map of vertex value to its index in the data vector
|
||||
std::map<aiVector3D,size_t> index_by_vertex_value;
|
||||
if(bJoinIdenticalVertices){
|
||||
int32_t index = 0;
|
||||
for (size_t vi = 0; vi < m->mNumVertices; ++vi) {
|
||||
aiVector3D vtx = m->mVertices[vi];
|
||||
auto elem = index_by_vertex_value.find(vtx);
|
||||
if (elem == index_by_vertex_value.end()) {
|
||||
vertex_indices.push_back(index);
|
||||
index_by_vertex_value[vtx] = index;
|
||||
flattened_vertices.push_back(vtx[0]);
|
||||
flattened_vertices.push_back(vtx[1]);
|
||||
flattened_vertices.push_back(vtx[2]);
|
||||
++index;
|
||||
} else {
|
||||
vertex_indices.push_back(int32_t(elem->second));
|
||||
}
|
||||
}
|
||||
}
|
||||
else { // do not join vertex, respect the export flag
|
||||
vertex_indices.resize(m->mNumVertices);
|
||||
std::iota(vertex_indices.begin(), vertex_indices.end(), 0);
|
||||
for(unsigned int v = 0; v < m->mNumVertices; ++ v) {
|
||||
aiVector3D vtx = m->mVertices[v];
|
||||
flattened_vertices.push_back(vtx.x);
|
||||
flattened_vertices.push_back(vtx.y);
|
||||
flattened_vertices.push_back(vtx.z);
|
||||
}
|
||||
}
|
||||
vVertexIndice.push_back(vertex_indices);
|
||||
|
||||
FBX::Node::WritePropertyNode(
|
||||
"Vertices", flattened_vertices, outstream, binary, indent
|
||||
);
|
||||
std::vector<double> normal_data;
|
||||
std::vector<double> color_data;
|
||||
|
||||
std::vector<int32_t> polygon_data;
|
||||
|
||||
std::vector<std::vector<double>> uv_data;
|
||||
std::vector<std::vector<int32_t>> uv_indices;
|
||||
|
||||
indent = 2;
|
||||
|
||||
for (uint32_t n_mi = 0; n_mi < node->mNumMeshes; n_mi++) {
|
||||
const auto mi = node->mMeshes[n_mi];
|
||||
const aiMesh *m = mScene->mMeshes[mi];
|
||||
|
||||
size_t v_offset = vertex_indices.size();
|
||||
size_t uniq_v_before = flattened_vertices.size() / 3;
|
||||
|
||||
// map of vertex value to its index in the data vector
|
||||
std::map<aiVector3D,size_t> index_by_vertex_value;
|
||||
if (bJoinIdenticalVertices) {
|
||||
int32_t index = 0;
|
||||
for (size_t vi = 0; vi < m->mNumVertices; ++vi) {
|
||||
aiVector3D vtx = m->mVertices[vi];
|
||||
auto elem = index_by_vertex_value.find(vtx);
|
||||
if (elem == index_by_vertex_value.end()) {
|
||||
vertex_indices.push_back(index);
|
||||
index_by_vertex_value[vtx] = index;
|
||||
flattened_vertices.insert(flattened_vertices.end(), { vtx.x, vtx.y, vtx.z });
|
||||
++index;
|
||||
} else {
|
||||
vertex_indices.push_back(int32_t(elem->second));
|
||||
}
|
||||
}
|
||||
} else { // do not join vertex, respect the export flag
|
||||
vertex_indices.resize(v_offset + m->mNumVertices);
|
||||
std::iota(vertex_indices.begin() + v_offset, vertex_indices.end(), 0);
|
||||
for(unsigned int v = 0; v < m->mNumVertices; ++ v) {
|
||||
aiVector3D vtx = m->mVertices[v];
|
||||
flattened_vertices.insert(flattened_vertices.end(), {vtx.x, vtx.y, vtx.z});
|
||||
}
|
||||
}
|
||||
vVertexIndice[mi].insert(
|
||||
// TODO test whether this can be end or not
|
||||
vVertexIndice[mi].end(),
|
||||
vertex_indices.begin() + v_offset,
|
||||
vertex_indices.end()
|
||||
);
|
||||
|
||||
// here could be edges but they're insane.
|
||||
// it's optional anyway, so let's ignore it.
|
||||
|
||||
// output polygon data as a flattened array of vertex indices.
|
||||
// the last vertex index of each polygon is negated and - 1
|
||||
std::vector<int32_t> polygon_data;
|
||||
for (size_t fi = 0; fi < m->mNumFaces; ++fi) {
|
||||
for (size_t fi = 0; fi < m->mNumFaces; fi++) {
|
||||
const aiFace &f = m->mFaces[fi];
|
||||
for (size_t pvi = 0; pvi < f.mNumIndices - 1; ++pvi) {
|
||||
polygon_data.push_back(vertex_indices[f.mIndices[pvi]]);
|
||||
if (f.mNumIndices == 0) continue;
|
||||
size_t pvi = 0;
|
||||
for (; pvi < f.mNumIndices - 1; pvi++) {
|
||||
polygon_data.push_back(
|
||||
static_cast<int32_t>(uniq_v_before + vertex_indices[v_offset + f.mIndices[pvi]])
|
||||
);
|
||||
}
|
||||
polygon_data.push_back(
|
||||
-1 - vertex_indices[f.mIndices[f.mNumIndices-1]]
|
||||
static_cast<int32_t>(-1 ^ (uniq_v_before + vertex_indices[v_offset+f.mIndices[pvi]]))
|
||||
);
|
||||
}
|
||||
FBX::Node::WritePropertyNode(
|
||||
"PolygonVertexIndex", polygon_data, outstream, binary, indent
|
||||
);
|
||||
}
|
||||
|
||||
// here could be edges but they're insane.
|
||||
// it's optional anyway, so let's ignore it.
|
||||
uniq_v_before_mi.push_back(static_cast<uint32_t>(uniq_v_before));
|
||||
|
||||
FBX::Node::WritePropertyNode(
|
||||
"GeometryVersion", int32_t(124), outstream, binary, indent
|
||||
);
|
||||
|
||||
// normals, if any
|
||||
if (m->HasNormals()) {
|
||||
FBX::Node normals("LayerElementNormal", int32_t(0));
|
||||
normals.Begin(outstream, binary, indent);
|
||||
normals.DumpProperties(outstream, binary, indent);
|
||||
normals.EndProperties(outstream, binary, indent);
|
||||
normals.BeginChildren(outstream, binary, indent);
|
||||
indent = 3;
|
||||
FBX::Node::WritePropertyNode(
|
||||
"Version", int32_t(101), outstream, binary, indent
|
||||
);
|
||||
FBX::Node::WritePropertyNode(
|
||||
"Name", "", outstream, binary, indent
|
||||
);
|
||||
FBX::Node::WritePropertyNode(
|
||||
"MappingInformationType", "ByPolygonVertex",
|
||||
outstream, binary, indent
|
||||
);
|
||||
// TODO: vertex-normals or indexed normals when appropriate
|
||||
FBX::Node::WritePropertyNode(
|
||||
"ReferenceInformationType", "Direct",
|
||||
outstream, binary, indent
|
||||
);
|
||||
std::vector<double> normal_data;
|
||||
if (m->HasNormals()) {
|
||||
normal_data.reserve(3 * polygon_data.size());
|
||||
for (size_t fi = 0; fi < m->mNumFaces; ++fi) {
|
||||
const aiFace &f = m->mFaces[fi];
|
||||
for (size_t pvi = 0; pvi < f.mNumIndices; ++pvi) {
|
||||
const aiVector3D &curN = m->mNormals[f.mIndices[pvi]];
|
||||
normal_data.push_back(curN.x);
|
||||
normal_data.push_back(curN.y);
|
||||
normal_data.push_back(curN.z);
|
||||
}
|
||||
for (size_t fi = 0; fi < m->mNumFaces; fi++) {
|
||||
const aiFace & f = m->mFaces[fi];
|
||||
for (size_t pvi = 0; pvi < f.mNumIndices; pvi++) {
|
||||
const aiVector3D &curN = m->mNormals[f.mIndices[pvi]];
|
||||
normal_data.insert(normal_data.end(), { curN.x, curN.y, curN.z });
|
||||
}
|
||||
}
|
||||
FBX::Node::WritePropertyNode(
|
||||
"Normals", normal_data, outstream, binary, indent
|
||||
);
|
||||
// note: version 102 has a NormalsW also... not sure what it is,
|
||||
// so we can stick with version 101 for now.
|
||||
indent = 2;
|
||||
normals.End(outstream, binary, indent, true);
|
||||
}
|
||||
}
|
||||
|
||||
// colors, if any
|
||||
for (size_t ci = 0; ci < m->GetNumColorChannels(); ++ci) {
|
||||
FBX::Node vertexcolors("LayerElementColor", int32_t(ci));
|
||||
vertexcolors.Begin(outstream, binary, indent);
|
||||
vertexcolors.DumpProperties(outstream, binary, indent);
|
||||
vertexcolors.EndProperties(outstream, binary, indent);
|
||||
vertexcolors.BeginChildren(outstream, binary, indent);
|
||||
indent = 3;
|
||||
FBX::Node::WritePropertyNode(
|
||||
"Version", int32_t(101), outstream, binary, indent
|
||||
);
|
||||
char layerName[8];
|
||||
snprintf(layerName, sizeof(layerName), "COLOR_%d", int32_t(ci));
|
||||
FBX::Node::WritePropertyNode(
|
||||
"Name", (const char*)layerName, outstream, binary, indent
|
||||
);
|
||||
FBX::Node::WritePropertyNode(
|
||||
"MappingInformationType", "ByPolygonVertex",
|
||||
outstream, binary, indent
|
||||
);
|
||||
FBX::Node::WritePropertyNode(
|
||||
"ReferenceInformationType", "Direct",
|
||||
outstream, binary, indent
|
||||
);
|
||||
std::vector<double> color_data;
|
||||
const int32_t colorChannelIndex = 0;
|
||||
if (m->HasVertexColors(colorChannelIndex)) {
|
||||
color_data.reserve(4 * polygon_data.size());
|
||||
for (size_t fi = 0; fi < m->mNumFaces; ++fi) {
|
||||
const aiFace &f = m->mFaces[fi];
|
||||
for (size_t pvi = 0; pvi < f.mNumIndices; ++pvi) {
|
||||
const aiColor4D &c = m->mColors[ci][f.mIndices[pvi]];
|
||||
color_data.push_back(c.r);
|
||||
color_data.push_back(c.g);
|
||||
color_data.push_back(c.b);
|
||||
color_data.push_back(c.a);
|
||||
}
|
||||
for (size_t fi = 0; fi < m->mNumFaces; fi++) {
|
||||
const aiFace &f = m->mFaces[fi];
|
||||
for (size_t pvi = 0; pvi < f.mNumIndices; pvi++) {
|
||||
const aiColor4D &c = m->mColors[colorChannelIndex][f.mIndices[pvi]];
|
||||
color_data.insert(color_data.end(), { c.r, c.g, c.b, c.a });
|
||||
}
|
||||
}
|
||||
FBX::Node::WritePropertyNode(
|
||||
"Colors", color_data, outstream, binary, indent
|
||||
);
|
||||
indent = 2;
|
||||
vertexcolors.End(outstream, binary, indent, true);
|
||||
}
|
||||
}
|
||||
|
||||
// uvs, if any
|
||||
for (size_t uvi = 0; uvi < m->GetNumUVChannels(); ++uvi) {
|
||||
if (m->mNumUVComponents[uvi] > 2) {
|
||||
const auto num_uv = static_cast<size_t>(m->GetNumUVChannels());
|
||||
uv_indices.resize(std::max(num_uv, uv_indices.size()));
|
||||
uv_data.resize(std::max(num_uv, uv_data.size()));
|
||||
std::map<aiVector3D, int32_t> index_by_uv;
|
||||
|
||||
// uvs, if any
|
||||
for (size_t uvi = 0; uvi < m->GetNumUVChannels(); uvi++) {
|
||||
const auto nc = m->mNumUVComponents[uvi];
|
||||
if (nc > 2) {
|
||||
// FBX only supports 2-channel UV maps...
|
||||
// or at least i'm not sure how to indicate a different number
|
||||
std::stringstream err;
|
||||
|
|
@ -1276,71 +1245,112 @@ void FBXExporter::WriteObjects ()
|
|||
err << " but may be incorrectly interpreted on load.";
|
||||
ASSIMP_LOG_WARN(err.str());
|
||||
}
|
||||
FBX::Node uv("LayerElementUV", int32_t(uvi));
|
||||
uv.Begin(outstream, binary, indent);
|
||||
uv.DumpProperties(outstream, binary, indent);
|
||||
uv.EndProperties(outstream, binary, indent);
|
||||
uv.BeginChildren(outstream, binary, indent);
|
||||
indent = 3;
|
||||
FBX::Node::WritePropertyNode(
|
||||
"Version", int32_t(101), outstream, binary, indent
|
||||
);
|
||||
// it doesn't seem like assimp keeps the uv map name,
|
||||
// so just leave it blank.
|
||||
FBX::Node::WritePropertyNode(
|
||||
"Name", "", outstream, binary, indent
|
||||
);
|
||||
FBX::Node::WritePropertyNode(
|
||||
"MappingInformationType", "ByPolygonVertex",
|
||||
outstream, binary, indent
|
||||
);
|
||||
FBX::Node::WritePropertyNode(
|
||||
"ReferenceInformationType", "IndexToDirect",
|
||||
outstream, binary, indent
|
||||
);
|
||||
|
||||
std::vector<double> uv_data;
|
||||
std::vector<int32_t> uv_indices;
|
||||
std::map<aiVector3D,int32_t> index_by_uv;
|
||||
int32_t index = 0;
|
||||
for (size_t fi = 0; fi < m->mNumFaces; ++fi) {
|
||||
const aiFace &f = m->mFaces[fi];
|
||||
for (size_t pvi = 0; pvi < f.mNumIndices; ++pvi) {
|
||||
const aiVector3D &curUv =
|
||||
m->mTextureCoords[uvi][f.mIndices[pvi]];
|
||||
auto elem = index_by_uv.find(curUv);
|
||||
if (elem == index_by_uv.end()) {
|
||||
index_by_uv[curUv] = index;
|
||||
uv_indices.push_back(index);
|
||||
for (unsigned int x = 0; x < m->mNumUVComponents[uvi]; ++x) {
|
||||
uv_data.push_back(curUv[x]);
|
||||
}
|
||||
++index;
|
||||
} else {
|
||||
uv_indices.push_back(elem->second);
|
||||
}
|
||||
int32_t index = static_cast<int32_t>(uv_data[uvi].size()) / nc;
|
||||
for (size_t fi = 0; fi < m->mNumFaces; fi++) {
|
||||
const aiFace &f = m->mFaces[fi];
|
||||
for (size_t pvi = 0; pvi < f.mNumIndices; pvi++) {
|
||||
const aiVector3D &curUv = m->mTextureCoords[uvi][f.mIndices[pvi]];
|
||||
auto elem = index_by_uv.find(curUv);
|
||||
if (elem == index_by_uv.end()) {
|
||||
index_by_uv[curUv] = index;
|
||||
uv_indices[uvi].push_back(index);
|
||||
for (uint32_t x = 0; x < nc; ++x) {
|
||||
uv_data[uvi].push_back(curUv[x]);
|
||||
}
|
||||
++index;
|
||||
} else {
|
||||
uv_indices[uvi].push_back(elem->second);
|
||||
}
|
||||
}
|
||||
}
|
||||
FBX::Node::WritePropertyNode(
|
||||
"UV", uv_data, outstream, binary, indent
|
||||
);
|
||||
FBX::Node::WritePropertyNode(
|
||||
"UVIndex", uv_indices, outstream, binary, indent
|
||||
);
|
||||
indent = 2;
|
||||
uv.End(outstream, binary, indent, true);
|
||||
}
|
||||
}
|
||||
|
||||
// i'm not really sure why this material section exists,
|
||||
// as the material is linked via "Connections".
|
||||
// it seems to always have the same "0" value.
|
||||
|
||||
FBX::Node::WritePropertyNode("Vertices", flattened_vertices, outstream, binary, indent);
|
||||
FBX::Node::WritePropertyNode("PolygonVertexIndex", polygon_data, outstream, binary, indent);
|
||||
FBX::Node::WritePropertyNode("GeometryVersion", int32_t(124), outstream, binary, indent);
|
||||
|
||||
if (!normal_data.empty()) {
|
||||
FBX::Node normals("LayerElementNormal", int32_t(0));
|
||||
normals.Begin(outstream, binary, indent);
|
||||
normals.DumpProperties(outstream, binary, indent);
|
||||
normals.EndProperties(outstream, binary, indent);
|
||||
normals.BeginChildren(outstream, binary, indent);
|
||||
indent = 3;
|
||||
FBX::Node::WritePropertyNode("Version", int32_t(101), outstream, binary, indent);
|
||||
FBX::Node::WritePropertyNode("Name", "", outstream, binary, indent);
|
||||
FBX::Node::WritePropertyNode("MappingInformationType", "ByPolygonVertex", outstream, binary, indent);
|
||||
FBX::Node::WritePropertyNode("ReferenceInformationType", "Direct", outstream, binary, indent);
|
||||
FBX::Node::WritePropertyNode("Normals", normal_data, outstream, binary, indent);
|
||||
// note: version 102 has a NormalsW also... not sure what it is,
|
||||
// so stick with version 101 for now.
|
||||
indent = 2;
|
||||
normals.End(outstream, binary, indent, true);
|
||||
}
|
||||
|
||||
if (!color_data.empty()) {
|
||||
const auto colorChannelIndex = 0;
|
||||
FBX::Node vertexcolors("LayerElementColor", int32_t(colorChannelIndex));
|
||||
vertexcolors.Begin(outstream, binary, indent);
|
||||
vertexcolors.DumpProperties(outstream, binary, indent);
|
||||
vertexcolors.EndProperties(outstream, binary, indent);
|
||||
vertexcolors.BeginChildren(outstream, binary, indent);
|
||||
indent = 3;
|
||||
FBX::Node::WritePropertyNode("Version", int32_t(101), outstream, binary, indent);
|
||||
char layerName[8];
|
||||
snprintf(layerName, sizeof(layerName), "COLOR_%d", colorChannelIndex);
|
||||
FBX::Node::WritePropertyNode("Name", (const char *)layerName, outstream, binary, indent);
|
||||
FBX::Node::WritePropertyNode("MappingInformationType", "ByPolygonVertex", outstream, binary, indent);
|
||||
FBX::Node::WritePropertyNode("ReferenceInformationType", "Direct", outstream, binary, indent);
|
||||
FBX::Node::WritePropertyNode("Colors", color_data, outstream, binary, indent);
|
||||
indent = 2;
|
||||
vertexcolors.End(outstream, binary, indent, true);
|
||||
}
|
||||
|
||||
for (uint32_t uvi = 0; uvi < uv_data.size(); uvi++) {
|
||||
FBX::Node uv("LayerElementUV", int32_t(uvi));
|
||||
uv.Begin(outstream, binary, indent);
|
||||
uv.DumpProperties(outstream, binary, indent);
|
||||
uv.EndProperties(outstream, binary, indent);
|
||||
uv.BeginChildren(outstream, binary, indent);
|
||||
indent = 3;
|
||||
FBX::Node::WritePropertyNode("Version", int32_t(101), outstream, binary, indent);
|
||||
FBX::Node::WritePropertyNode("Name", "", outstream, binary, indent);
|
||||
FBX::Node::WritePropertyNode("MappingInformationType", "ByPolygonVertex", outstream, binary, indent);
|
||||
FBX::Node::WritePropertyNode("ReferenceInformationType", "IndexToDirect", outstream, binary, indent);
|
||||
FBX::Node::WritePropertyNode("UV", uv_data[uvi], outstream, binary, indent);
|
||||
FBX::Node::WritePropertyNode("UVIndex", uv_indices[uvi], outstream, binary, indent);
|
||||
indent = 2;
|
||||
uv.End(outstream, binary, indent, true);
|
||||
}
|
||||
|
||||
|
||||
// When merging multiple meshes, we instead use by polygon so the correct material is
|
||||
// assigned to each face. Previously, this LayerElementMaterial always had 0 since it
|
||||
// assumed there was 1 material for each node for all meshes.
|
||||
FBX::Node mat("LayerElementMaterial", int32_t(0));
|
||||
mat.AddChild("Version", int32_t(101));
|
||||
mat.AddChild("Name", "");
|
||||
mat.AddChild("MappingInformationType", "AllSame");
|
||||
mat.AddChild("ReferenceInformationType", "IndexToDirect");
|
||||
std::vector<int32_t> mat_indices = {0};
|
||||
mat.AddChild("Materials", mat_indices);
|
||||
if (node->mNumMeshes == 1) {
|
||||
mat.AddChild("MappingInformationType", "AllSame");
|
||||
mat.AddChild("ReferenceInformationType", "IndexToDirect");
|
||||
std::vector<int32_t> mat_indices = {0};
|
||||
mat.AddChild("Materials", mat_indices);
|
||||
} else {
|
||||
mat.AddChild("MappingInformationType", "ByPolygon");
|
||||
mat.AddChild("ReferenceInformationType", "IndexToDirect");
|
||||
std::vector<int32_t> mat_indices;
|
||||
for (uint32_t n_mi = 0; n_mi < node->mNumMeshes; n_mi++) {
|
||||
const auto mi = node->mMeshes[n_mi];
|
||||
const auto *const m = mScene->mMeshes[mi];
|
||||
for (size_t fi = 0; fi < m->mNumFaces; fi++) {
|
||||
mat_indices.push_back(n_mi);
|
||||
}
|
||||
}
|
||||
mat.AddChild("Materials", mat_indices);
|
||||
}
|
||||
mat.Dump(outstream, binary, indent);
|
||||
|
||||
// finally we have the layer specifications,
|
||||
|
|
@ -1348,16 +1358,20 @@ void FBXExporter::WriteObjects ()
|
|||
// TODO: handle multiple uv sets correctly?
|
||||
FBX::Node layer("Layer", int32_t(0));
|
||||
layer.AddChild("Version", int32_t(100));
|
||||
FBX::Node le("LayerElement");
|
||||
le.AddChild("Type", "LayerElementNormal");
|
||||
le.AddChild("TypedIndex", int32_t(0));
|
||||
layer.AddChild(le);
|
||||
FBX::Node le;
|
||||
|
||||
for (size_t ci = 0; ci < m->GetNumColorChannels(); ++ci) {
|
||||
le = FBX::Node("LayerElement");
|
||||
le.AddChild("Type", "LayerElementColor");
|
||||
le.AddChild("TypedIndex", int32_t(ci));
|
||||
layer.AddChild(le);
|
||||
if (!normal_data.empty()) {
|
||||
le = FBX::Node("LayerElement");
|
||||
le.AddChild("Type", "LayerElementNormal");
|
||||
le.AddChild("TypedIndex", int32_t(0));
|
||||
layer.AddChild(le);
|
||||
}
|
||||
|
||||
if (!color_data.empty()) {
|
||||
le = FBX::Node("LayerElement");
|
||||
le.AddChild("Type", "LayerElementColor");
|
||||
le.AddChild("TypedIndex", int32_t(0));
|
||||
layer.AddChild(le);
|
||||
}
|
||||
|
||||
le = FBX::Node("LayerElement");
|
||||
|
|
@ -1370,8 +1384,7 @@ void FBXExporter::WriteObjects ()
|
|||
layer.AddChild(le);
|
||||
layer.Dump(outstream, binary, indent);
|
||||
|
||||
for(unsigned int lr = 1; lr < m->GetNumUVChannels(); ++ lr)
|
||||
{
|
||||
for(unsigned int lr = 1; lr < uv_data.size(); ++ lr) {
|
||||
FBX::Node layerExtra("Layer", int32_t(lr));
|
||||
layerExtra.AddChild("Version", int32_t(100));
|
||||
FBX::Node leExtra("LayerElement");
|
||||
|
|
@ -1383,7 +1396,14 @@ void FBXExporter::WriteObjects ()
|
|||
// finish the node record
|
||||
indent = 1;
|
||||
n.End(outstream, binary, indent, true);
|
||||
}
|
||||
|
||||
for (uint32_t ni = 0; ni < node->mNumChildren; ni++) {
|
||||
visit_node_geo(node->mChildren[ni]);
|
||||
}
|
||||
return;
|
||||
};
|
||||
|
||||
visit_node_geo(mScene->mRootNode);
|
||||
|
||||
|
||||
// aiMaterial
|
||||
|
|
@ -1562,6 +1582,7 @@ void FBXExporter::WriteObjects ()
|
|||
}
|
||||
}
|
||||
|
||||
std::map<std::string, std::string> tpath_by_image;
|
||||
// FbxVideo - stores images used by textures.
|
||||
for (const auto &it : uid_by_image) {
|
||||
FBX::Node n("Video");
|
||||
|
|
@ -1581,10 +1602,21 @@ void FBXExporter::WriteObjects ()
|
|||
std::stringstream newPath;
|
||||
if (embedded_texture->mFilename.length > 0) {
|
||||
newPath << embedded_texture->mFilename.C_Str();
|
||||
// If newPath doesn't end in an extension, add extension from embedded_texture->achFormatHint
|
||||
std::string np = newPath.str();
|
||||
size_t dot_pos = np.find_last_of('.');
|
||||
if (dot_pos == std::string::npos || dot_pos < np.find_last_of("/\\")) {
|
||||
// No extension found, add one
|
||||
newPath << "." << embedded_texture->achFormatHint;
|
||||
}
|
||||
} else if (embedded_texture->achFormatHint[0]) {
|
||||
int texture_index = std::stoi(path.substr(1, path.size() - 1));
|
||||
newPath << texture_index << "." << embedded_texture->achFormatHint;
|
||||
}
|
||||
auto elem = tpath_by_image.find(path);
|
||||
if (elem == tpath_by_image.end()) {
|
||||
tpath_by_image[path] = newPath.str();
|
||||
}
|
||||
path = newPath.str();
|
||||
// embed the texture
|
||||
size_t texture_size = static_cast<size_t>(embedded_texture->mWidth * std::max(embedded_texture->mHeight, 1u));
|
||||
|
|
@ -1703,6 +1735,17 @@ void FBXExporter::WriteObjects ()
|
|||
unsigned int max = sizeof(aiUVTransform);
|
||||
aiGetMaterialFloatArray(mat, AI_MATKEY_UVTRANSFORM(aiTextureType_DIFFUSE, 0), (ai_real *)&trafo, &max);
|
||||
|
||||
auto tp_elem = tpath_by_image.find(texture_path);
|
||||
std::string tfile_path = texture_path;
|
||||
if (tp_elem != tpath_by_image.end()) {
|
||||
tfile_path = tp_elem->second;
|
||||
} else {
|
||||
std::stringstream err;
|
||||
err << "Texture path not found for texure " << texture_path;
|
||||
err << " on material " << i;
|
||||
ASSIMP_LOG_WARN(err.str());
|
||||
}
|
||||
|
||||
// now write the actual texture node
|
||||
FBX::Node tnode("Texture");
|
||||
// TODO: some way to determine texture name?
|
||||
|
|
@ -1723,8 +1766,8 @@ void FBXExporter::WriteObjects ()
|
|||
// can't easily determine which texture path will be correct,
|
||||
// so just store what we have in every field.
|
||||
// these being incorrect is a common problem with FBX anyway.
|
||||
tnode.AddChild("FileName", texture_path);
|
||||
tnode.AddChild("RelativeFilename", texture_path);
|
||||
tnode.AddChild("FileName", tfile_path);
|
||||
tnode.AddChild("RelativeFilename", tfile_path);
|
||||
tnode.AddChild("ModelUVTranslation", double(0.0), double(0.0));
|
||||
tnode.AddChild("ModelUVScaling", double(1.0), double(1.0));
|
||||
tnode.AddChild("Texture_Alpha_Source", "None");
|
||||
|
|
@ -1748,7 +1791,8 @@ void FBXExporter::WriteObjects ()
|
|||
dnode.AddChild("Version", int32_t(101));
|
||||
dnode.Dump(outstream, binary, indent);
|
||||
// connect it
|
||||
connections.emplace_back("C", "OO", deformer_uid, mesh_uids[mi]);
|
||||
const auto node = get_node_for_mesh((unsigned int)mi, mScene->mRootNode);
|
||||
connections.emplace_back("C", "OO", deformer_uid, mesh_uids[node]);
|
||||
std::vector<int32_t> vertex_indices = vVertexIndice[mi];
|
||||
|
||||
for (unsigned int am = 0; am < m->mNumAnimMeshes; ++am) {
|
||||
|
|
@ -1758,7 +1802,7 @@ void FBXExporter::WriteObjects ()
|
|||
// start the node record
|
||||
FBX::Node bsnode("Geometry");
|
||||
int64_t blendshape_uid = generate_uid();
|
||||
mesh_uids.push_back(blendshape_uid);
|
||||
blendshape_uids.push_back(blendshape_uid);
|
||||
bsnode.AddProperty(blendshape_uid);
|
||||
bsnode.AddProperty(blendshape_name + FBX::SEPARATOR + "Geometry");
|
||||
bsnode.AddProperty("Shape");
|
||||
|
|
@ -1945,22 +1989,15 @@ void FBXExporter::WriteObjects ()
|
|||
// otherwise check if this is the root of the skeleton
|
||||
bool end = false;
|
||||
// is the mesh part of this node?
|
||||
for (size_t i = 0; i < parent->mNumMeshes; ++i) {
|
||||
if (parent->mMeshes[i] == mi) {
|
||||
end = true;
|
||||
break;
|
||||
}
|
||||
for (size_t i = 0; i < parent->mNumMeshes && !end; ++i) {
|
||||
end |= parent->mMeshes[i] == mi;
|
||||
}
|
||||
// is the mesh in one of the children of this node?
|
||||
for (size_t j = 0; j < parent->mNumChildren; ++j) {
|
||||
for (size_t j = 0; j < parent->mNumChildren && !end; ++j) {
|
||||
aiNode* child = parent->mChildren[j];
|
||||
for (size_t i = 0; i < child->mNumMeshes; ++i) {
|
||||
if (child->mMeshes[i] == mi) {
|
||||
end = true;
|
||||
break;
|
||||
}
|
||||
for (size_t i = 0; i < child->mNumMeshes && !end; ++i) {
|
||||
end |= child->mMeshes[i] == mi;
|
||||
}
|
||||
if (end) { break; }
|
||||
}
|
||||
|
||||
// if it was the skeleton root we can finish here
|
||||
|
|
@ -1974,8 +2011,7 @@ void FBXExporter::WriteObjects ()
|
|||
for (size_t i = 0; i < mScene->mNumMeshes; ++i) {
|
||||
auto &s = skeleton_by_mesh[i];
|
||||
for (const aiNode* n : s) {
|
||||
auto elem = node_uids.find(n);
|
||||
if (elem == node_uids.end()) {
|
||||
if (node_uids.find(n) == node_uids.end()) {
|
||||
node_uids[n] = generate_uid();
|
||||
}
|
||||
}
|
||||
|
|
@ -1991,6 +2027,8 @@ void FBXExporter::WriteObjects ()
|
|||
if (!m->HasBones()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const aiNode *mesh_node = get_node_for_mesh((uint32_t)mi, mScene->mRootNode);
|
||||
// make a deformer for this mesh
|
||||
int64_t deformer_uid = generate_uid();
|
||||
FBX::Node dnode("Deformer");
|
||||
|
|
@ -2002,10 +2040,7 @@ void FBXExporter::WriteObjects ()
|
|||
dnode.Dump(outstream, binary, indent);
|
||||
|
||||
// connect it
|
||||
connections.emplace_back("C", "OO", deformer_uid, mesh_uids[mi]);
|
||||
|
||||
//computed before
|
||||
std::vector<int32_t>& vertex_indices = vVertexIndice[mi];
|
||||
connections.emplace_back("C", "OO", deformer_uid, mesh_uids[mesh_node]);
|
||||
|
||||
// TODO, FIXME: this won't work if anything is not in the bind pose.
|
||||
// for now if such a situation is detected, we throw an exception.
|
||||
|
|
@ -2019,7 +2054,6 @@ void FBXExporter::WriteObjects ()
|
|||
// as it can be instanced to many nodes.
|
||||
// All we can do is assume no instancing,
|
||||
// and take the first node we find that contains the mesh.
|
||||
aiNode* mesh_node = get_node_for_mesh((unsigned int)mi, mScene->mRootNode);
|
||||
aiMatrix4x4 mesh_xform = get_world_transform(mesh_node, mScene);
|
||||
|
||||
// now make a subdeformer for each bone in the skeleton
|
||||
|
|
@ -2048,14 +2082,19 @@ void FBXExporter::WriteObjects ()
|
|||
sdnode.AddChild("Version", int32_t(100));
|
||||
sdnode.AddChild("UserData", "", "");
|
||||
|
||||
std::set<int32_t> setWeightedVertex;
|
||||
// add indices and weights, if any
|
||||
if (b) {
|
||||
std::set<int32_t> setWeightedVertex;
|
||||
std::vector<int32_t> subdef_indices;
|
||||
std::vector<double> subdef_weights;
|
||||
int32_t last_index = -1;
|
||||
for (size_t wi = 0; wi < b->mNumWeights; ++wi) {
|
||||
int32_t vi = vertex_indices[b->mWeights[wi].mVertexId];
|
||||
if (b->mWeights[wi].mVertexId >= vVertexIndice[mi].size()) {
|
||||
ASSIMP_LOG_ERROR("UNREAL: Skipping vertex index to prevent buffer overflow.");
|
||||
continue;
|
||||
}
|
||||
int32_t vi = vVertexIndice[mi][b->mWeights[wi].mVertexId]
|
||||
+ uniq_v_before_mi[mi];
|
||||
bool bIsWeightedAlready = (setWeightedVertex.find(vi) != setWeightedVertex.end());
|
||||
if (vi == last_index || bIsWeightedAlready) {
|
||||
// only for vertices we exported to fbx
|
||||
|
|
@ -2535,9 +2574,9 @@ void add_meta(FBX::Node& fbx_node, const aiNode* node){
|
|||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
// write a single model node to the stream
|
||||
|
|
@ -2702,9 +2741,8 @@ void FBXExporter::WriteModelNodes(
|
|||
// handled later
|
||||
} else if (node->mNumMeshes == 1) {
|
||||
// connect to child mesh, which should have been written previously
|
||||
connections.emplace_back(
|
||||
"C", "OO", mesh_uids[node->mMeshes[0]], node_uid
|
||||
);
|
||||
// TODO double check this line
|
||||
connections.emplace_back("C", "OO", mesh_uids[node], node_uid);
|
||||
// also connect to the material for the child mesh
|
||||
connections.emplace_back(
|
||||
"C", "OO",
|
||||
|
|
@ -2729,6 +2767,16 @@ void FBXExporter::WriteModelNodes(
|
|||
na.Dump(outstream, binary, 1);
|
||||
// and connect them
|
||||
connections.emplace_back("C", "OO", node_attribute_uid, node_uid);
|
||||
} else if (node->mNumMeshes >= 1) {
|
||||
connections.emplace_back("C", "OO", mesh_uids[node], node_uid);
|
||||
for (size_t i = 0; i < node->mNumMeshes; i++) {
|
||||
connections.emplace_back(
|
||||
"C", "OO",
|
||||
material_uids[mScene->mMeshes[node->mMeshes[i]]->mMaterialIndex],
|
||||
node_uid
|
||||
);
|
||||
}
|
||||
WriteModelNode(outstream, binary, node, node_uid, "Mesh", transform_chain);
|
||||
} else {
|
||||
const auto& lightIt = lights_uids.find(node->mName.C_Str());
|
||||
if(lightIt != lights_uids.end()) {
|
||||
|
|
@ -2745,34 +2793,20 @@ void FBXExporter::WriteModelNodes(
|
|||
}
|
||||
}
|
||||
|
||||
// if more than one child mesh, make nodes for each mesh
|
||||
if (node->mNumMeshes > 1 || node == mScene->mRootNode) {
|
||||
for (size_t i = 0; i < node->mNumMeshes; ++i) {
|
||||
// make a new model node
|
||||
int64_t new_node_uid = generate_uid();
|
||||
// connect to parent node
|
||||
connections.emplace_back("C", "OO", new_node_uid, node_uid);
|
||||
// connect to child mesh, which should have been written previously
|
||||
connections.emplace_back(
|
||||
"C", "OO", mesh_uids[node->mMeshes[i]], new_node_uid
|
||||
);
|
||||
// also connect to the material for the child mesh
|
||||
connections.emplace_back(
|
||||
"C", "OO",
|
||||
material_uids[
|
||||
mScene->mMeshes[node->mMeshes[i]]->mMaterialIndex
|
||||
],
|
||||
new_node_uid
|
||||
);
|
||||
|
||||
aiNode new_node;
|
||||
// take name from mesh name, if it exists
|
||||
new_node.mName = mScene->mMeshes[node->mMeshes[i]]->mName;
|
||||
// write model node
|
||||
WriteModelNode(
|
||||
outstream, binary, &new_node, new_node_uid, "Mesh", std::vector<std::pair<std::string,aiVector3D>>()
|
||||
);
|
||||
}
|
||||
if (node == mScene->mRootNode && node->mNumMeshes > 0) {
|
||||
int64_t new_node_uid = generate_uid();
|
||||
connections.emplace_back("C", "OO", new_node_uid, node_uid);
|
||||
connections.emplace_back("C", "OO", mesh_uids[node], new_node_uid);
|
||||
for (size_t i = 0; i < node->mNumMeshes; ++i) {
|
||||
connections.emplace_back(
|
||||
"C", "OO",
|
||||
material_uids[mScene->mMeshes[node->mMeshes[i]]->mMaterialIndex],
|
||||
new_node_uid
|
||||
);
|
||||
}
|
||||
aiNode new_node;
|
||||
new_node.mName = mScene->mMeshes[0]->mName;
|
||||
WriteModelNode(outstream, binary, &new_node, new_node_uid, "Mesh", {});
|
||||
}
|
||||
|
||||
// now recurse into children
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
Open Asset Import Library (assimp)
|
||||
----------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2024, assimp team
|
||||
Copyright (c) 2006-2026, assimp team
|
||||
|
||||
All rights reserved.
|
||||
|
||||
|
|
@ -51,7 +51,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
#include "FBXCommon.h" // FBX::TransformInheritance
|
||||
|
||||
#include <assimp/types.h>
|
||||
//#include <assimp/material.h>
|
||||
#include <assimp/StreamWriter.h> // StreamWriterLE
|
||||
#include <assimp/Exceptional.h> // DeadlyExportError
|
||||
|
||||
|
|
@ -91,7 +90,8 @@ namespace Assimp {
|
|||
|
||||
std::vector<FBX::Node> connections; // connection storage
|
||||
|
||||
std::vector<int64_t> mesh_uids;
|
||||
std::map<const aiNode*, int64_t> mesh_uids;
|
||||
std::vector<int64_t> blendshape_uids;
|
||||
std::vector<int64_t> material_uids;
|
||||
std::map<const aiNode*,int64_t> node_uids;
|
||||
std::map<std::string,int64_t> lights_uids;
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
Open Asset Import Library (assimp)
|
||||
----------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2024, assimp team
|
||||
Copyright (c) 2006-2026, assimp team
|
||||
|
||||
All rights reserved.
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
Open Asset Import Library (assimp)
|
||||
----------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2024, assimp team
|
||||
Copyright (c) 2006-2026, assimp team
|
||||
|
||||
All rights reserved.
|
||||
|
||||
|
|
@ -90,7 +90,7 @@ namespace {
|
|||
// Returns whether the class can handle the format of the given file.
|
||||
bool FBXImporter::CanRead(const std::string & pFile, IOSystem * pIOHandler, bool /*checkSig*/) const {
|
||||
// at least ASCII-FBX files usually have a 'FBX' somewhere in their head
|
||||
static const char *tokens[] = { " \n\r\n " };
|
||||
static const char *tokens[] = { " \n\r\n ", "fbx" };
|
||||
return SearchFileHeaderForToken(pIOHandler, pFile, tokens, AI_COUNT_OF(tokens));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
Open Asset Import Library (assimp)
|
||||
----------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2024, assimp team
|
||||
Copyright (c) 2006-2026, assimp team
|
||||
|
||||
All rights reserved.
|
||||
|
||||
|
|
@ -67,7 +67,7 @@ typedef class basic_formatter<char, std::char_traits<char>, std::allocator<char>
|
|||
///
|
||||
/// See http://en.wikipedia.org/wiki/FBX
|
||||
// -------------------------------------------------------------------------------------------
|
||||
class FBXImporter : public BaseImporter, public LogFunctions<FBXImporter> {
|
||||
class FBXImporter final : public BaseImporter, public LogFunctions<FBXImporter> {
|
||||
public:
|
||||
/// @brief The class constructor.
|
||||
FBXImporter() = default;
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
Open Asset Import Library (assimp)
|
||||
----------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2024, assimp team
|
||||
Copyright (c) 2006-2026, assimp team
|
||||
|
||||
All rights reserved.
|
||||
|
||||
|
|
@ -134,10 +134,6 @@ Material::Material(uint64_t id, const Element& element, const Document& doc, con
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Material::~Material() = default;
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Texture::Texture(uint64_t id, const Element& element, const Document& doc, const std::string& name) :
|
||||
Object(id,element,name),
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
Open Asset Import Library (assimp)
|
||||
----------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2024, assimp team
|
||||
Copyright (c) 2006-2026, assimp team
|
||||
|
||||
All rights reserved.
|
||||
|
||||
|
|
@ -45,6 +45,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
|
||||
#ifndef ASSIMP_BUILD_NO_FBX_IMPORTER
|
||||
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
|
||||
#include "FBXMeshGeometry.h"
|
||||
|
|
@ -69,8 +70,10 @@ Geometry::Geometry(uint64_t id, const Element& element, const std::string& name,
|
|||
}
|
||||
const BlendShape* const bsp = ProcessSimpleConnection<BlendShape>(*con, false, "BlendShape -> Geometry", element);
|
||||
if (bsp) {
|
||||
auto pr = blendShapes.insert(bsp);
|
||||
if (!pr.second) {
|
||||
// Only add a blendshape if it doesn't exist already
|
||||
if (std::find(blendShapes.begin(), blendShapes.end(), bsp) == blendShapes.end()) {
|
||||
blendShapes.push_back(bsp);
|
||||
} else {
|
||||
FBXImporter::LogWarn("there is the same blendShape id ", bsp->ID());
|
||||
}
|
||||
}
|
||||
|
|
@ -78,7 +81,7 @@ Geometry::Geometry(uint64_t id, const Element& element, const std::string& name,
|
|||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
const std::unordered_set<const BlendShape*>& Geometry::GetBlendShapes() const {
|
||||
const std::vector<const BlendShape*>& Geometry::GetBlendShapes() const {
|
||||
return blendShapes;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
Open Asset Import Library (assimp)
|
||||
----------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2024, assimp team
|
||||
Copyright (c) 2006-2026, assimp team
|
||||
|
||||
All rights reserved.
|
||||
|
||||
|
|
@ -72,11 +72,11 @@ public:
|
|||
|
||||
/// @brief Get the BlendShape attached to this geometry or nullptr
|
||||
/// @return The blendshape arrays.
|
||||
const std::unordered_set<const BlendShape*>& GetBlendShapes() const;
|
||||
const std::vector<const BlendShape*>& GetBlendShapes() const;
|
||||
|
||||
private:
|
||||
const Skin* skin;
|
||||
std::unordered_set<const BlendShape*> blendShapes;
|
||||
std::vector<const BlendShape*> blendShapes;
|
||||
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
Open Asset Import Library (assimp)
|
||||
----------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2024, assimp team
|
||||
Copyright (c) 2006-2026, assimp team
|
||||
|
||||
All rights reserved.
|
||||
|
||||
|
|
|
|||
|
|
@ -2,8 +2,7 @@
|
|||
Open Asset Import Library (assimp)
|
||||
----------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2024, assimp team
|
||||
|
||||
Copyright (c) 2006-2026, assimp team
|
||||
|
||||
All rights reserved.
|
||||
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue