Merge branch 'master' into fix_gltf_accessor_overflow
This commit is contained in:
@@ -72,7 +72,7 @@ void Discreet3DSImporter::ReplaceDefaultMaterial()
|
||||
unsigned int idx( NotSet );
|
||||
for (unsigned int i = 0; i < mScene->mMaterials.size();++i)
|
||||
{
|
||||
std::string &s = mScene->mMaterials[i].mName;
|
||||
std::string s = mScene->mMaterials[i].mName;
|
||||
for ( std::string::iterator it = s.begin(); it != s.end(); ++it ) {
|
||||
*it = static_cast< char >( ::tolower( *it ) );
|
||||
}
|
||||
|
||||
@@ -50,9 +50,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#ifndef ASSIMP_BUILD_NO_3DS_IMPORTER
|
||||
|
||||
// internal headers
|
||||
#include "3DSLoader.h"
|
||||
#include <assimp/Macros.h>
|
||||
#include <assimp/IOSystem.hpp>
|
||||
#include <assimp/scene.h>
|
||||
#include <assimp/DefaultLogger.hpp>
|
||||
|
||||
+16
-1
@@ -137,7 +137,6 @@ SET( PUBLIC_HEADERS
|
||||
${HEADER_PATH}/irrXMLWrapper.h
|
||||
${HEADER_PATH}/BlobIOSystem.h
|
||||
${HEADER_PATH}/MathFunctions.h
|
||||
${HEADER_PATH}/Macros.h
|
||||
${HEADER_PATH}/Exceptional.h
|
||||
${HEADER_PATH}/ByteSwapper.h
|
||||
)
|
||||
@@ -408,6 +407,18 @@ ADD_ASSIMP_IMPORTER( LWS
|
||||
LWS/LWSLoader.h
|
||||
)
|
||||
|
||||
ADD_ASSIMP_IMPORTER( M3D
|
||||
M3D/M3DMaterials.h
|
||||
M3D/M3DImporter.h
|
||||
M3D/M3DImporter.cpp
|
||||
M3D/m3d.h
|
||||
)
|
||||
|
||||
ADD_ASSIMP_EXPORTER( M3D
|
||||
M3D/M3DExporter.h
|
||||
M3D/M3DExporter.cpp
|
||||
)
|
||||
|
||||
ADD_ASSIMP_IMPORTER( MD2
|
||||
MD2/MD2FileData.h
|
||||
MD2/MD2Loader.cpp
|
||||
@@ -671,6 +682,8 @@ SET( PostProcessing_SRCS
|
||||
PostProcessing/MakeVerboseFormat.h
|
||||
PostProcessing/ScaleProcess.cpp
|
||||
PostProcessing/ScaleProcess.h
|
||||
PostProcessing/ArmaturePopulate.cpp
|
||||
PostProcessing/ArmaturePopulate.h
|
||||
PostProcessing/GenBoundingBoxesProcess.cpp
|
||||
PostProcessing/GenBoundingBoxesProcess.h
|
||||
)
|
||||
@@ -1059,6 +1072,8 @@ MESSAGE(STATUS "Disabled importer formats:${ASSIMP_IMPORTERS_DISABLED}")
|
||||
MESSAGE(STATUS "Enabled exporter formats:${ASSIMP_EXPORTERS_ENABLED}")
|
||||
MESSAGE(STATUS "Disabled exporter formats:${ASSIMP_EXPORTERS_DISABLED}")
|
||||
|
||||
SOURCE_GROUP( include\\assimp FILES ${PUBLIC_HEADERS} )
|
||||
|
||||
SET( assimp_src
|
||||
# Assimp Files
|
||||
${Core_SRCS}
|
||||
|
||||
@@ -92,6 +92,36 @@ void ExportSceneCollada(const char* pFile, IOSystem* pIOSystem, const aiScene* p
|
||||
|
||||
} // end of namespace Assimp
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Encodes a string into a valid XML ID using the xsd:ID schema qualifications.
|
||||
static const std::string XMLIDEncode(const std::string& name) {
|
||||
const char XML_ID_CHARS[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_-.";
|
||||
const unsigned int XML_ID_CHARS_COUNT = sizeof(XML_ID_CHARS) / sizeof(char);
|
||||
|
||||
if (name.length() == 0) {
|
||||
return name;
|
||||
}
|
||||
|
||||
std::stringstream idEncoded;
|
||||
|
||||
// xsd:ID must start with letter or underscore
|
||||
if (!((name[0] >= 'A' && name[0] <= 'z') || name[0] == '_')) {
|
||||
idEncoded << '_';
|
||||
}
|
||||
|
||||
for (std::string::const_iterator it = name.begin(); it != name.end(); ++it) {
|
||||
// xsd:ID can only contain letters, digits, underscores, hyphens and periods
|
||||
if (strchr(XML_ID_CHARS, *it) != nullptr) {
|
||||
idEncoded << *it;
|
||||
} else {
|
||||
// Select placeholder character based on invalid character to prevent name collisions
|
||||
idEncoded << XML_ID_CHARS[(*it) % XML_ID_CHARS_COUNT];
|
||||
}
|
||||
}
|
||||
|
||||
return idEncoded.str();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Constructor for a specific scene to export
|
||||
ColladaExporter::ColladaExporter( const aiScene* pScene, IOSystem* pIOSystem, const std::string& path, const std::string& file)
|
||||
@@ -146,7 +176,7 @@ void ColladaExporter::WriteFile() {
|
||||
// useless Collada fu at the end, just in case we haven't had enough indirections, yet.
|
||||
mOutput << startstr << "<scene>" << endstr;
|
||||
PushTag();
|
||||
mOutput << startstr << "<instance_visual_scene url=\"#" + XMLEscape(mScene->mRootNode->mName.C_Str()) + "\" />" << endstr;
|
||||
mOutput << startstr << "<instance_visual_scene url=\"#" + XMLIDEncode(mScene->mRootNode->mName.C_Str()) + "\" />" << endstr;
|
||||
PopTag();
|
||||
mOutput << startstr << "</scene>" << endstr;
|
||||
PopTag();
|
||||
@@ -356,9 +386,10 @@ void ColladaExporter::WriteCamerasLibrary() {
|
||||
void ColladaExporter::WriteCamera(size_t pIndex){
|
||||
|
||||
const aiCamera *cam = mScene->mCameras[pIndex];
|
||||
const std::string idstrEscaped = XMLEscape(cam->mName.C_Str());
|
||||
const std::string cameraName = XMLEscape(cam->mName.C_Str());
|
||||
const std::string cameraId = XMLIDEncode(cam->mName.C_Str());
|
||||
|
||||
mOutput << startstr << "<camera id=\"" << idstrEscaped << "-camera\" name=\"" << idstrEscaped << "_name\" >" << endstr;
|
||||
mOutput << startstr << "<camera id=\"" << cameraId << "-camera\" name=\"" << cameraName << "\" >" << endstr;
|
||||
PushTag();
|
||||
mOutput << startstr << "<optics>" << endstr;
|
||||
PushTag();
|
||||
@@ -412,10 +443,11 @@ void ColladaExporter::WriteLightsLibrary() {
|
||||
void ColladaExporter::WriteLight(size_t pIndex){
|
||||
|
||||
const aiLight *light = mScene->mLights[pIndex];
|
||||
const std::string idstrEscaped = XMLEscape(light->mName.C_Str());
|
||||
const std::string lightName = XMLEscape(light->mName.C_Str());
|
||||
const std::string lightId = XMLIDEncode(light->mName.C_Str());
|
||||
|
||||
mOutput << startstr << "<light id=\"" << idstrEscaped << "-light\" name=\""
|
||||
<< idstrEscaped << "_name\" >" << endstr;
|
||||
mOutput << startstr << "<light id=\"" << lightId << "-light\" name=\""
|
||||
<< lightName << "\" >" << endstr;
|
||||
PushTag();
|
||||
mOutput << startstr << "<technique_common>" << endstr;
|
||||
PushTag();
|
||||
@@ -586,7 +618,7 @@ static bool isalnum_C(char c) {
|
||||
void ColladaExporter::WriteImageEntry( const Surface& pSurface, const std::string& pNameAdd) {
|
||||
if( !pSurface.texture.empty() )
|
||||
{
|
||||
mOutput << startstr << "<image id=\"" << XMLEscape(pNameAdd) << "\">" << endstr;
|
||||
mOutput << startstr << "<image id=\"" << XMLIDEncode(pNameAdd) << "\">" << endstr;
|
||||
PushTag();
|
||||
mOutput << startstr << "<init_from>";
|
||||
|
||||
@@ -619,7 +651,7 @@ void ColladaExporter::WriteTextureColorEntry( const Surface& pSurface, const std
|
||||
}
|
||||
else
|
||||
{
|
||||
mOutput << startstr << "<texture texture=\"" << XMLEscape(pImageName) << "\" texcoord=\"CHANNEL" << pSurface.channel << "\" />" << endstr;
|
||||
mOutput << startstr << "<texture texture=\"" << XMLIDEncode(pImageName) << "\" texcoord=\"CHANNEL" << pSurface.channel << "\" />" << endstr;
|
||||
}
|
||||
PopTag();
|
||||
mOutput << startstr << "</" << pTypeName << ">" << endstr;
|
||||
@@ -633,21 +665,21 @@ void ColladaExporter::WriteTextureParamEntry( const Surface& pSurface, const std
|
||||
// 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=\"" << XMLEscape(pMatName) << "-" << pTypeName << "-surface\">" << endstr;
|
||||
mOutput << startstr << "<newparam sid=\"" << XMLIDEncode(pMatName) << "-" << pTypeName << "-surface\">" << endstr;
|
||||
PushTag();
|
||||
mOutput << startstr << "<surface type=\"2D\">" << endstr;
|
||||
PushTag();
|
||||
mOutput << startstr << "<init_from>" << XMLEscape(pMatName) << "-" << pTypeName << "-image</init_from>" << endstr;
|
||||
mOutput << startstr << "<init_from>" << XMLIDEncode(pMatName) << "-" << pTypeName << "-image</init_from>" << endstr;
|
||||
PopTag();
|
||||
mOutput << startstr << "</surface>" << endstr;
|
||||
PopTag();
|
||||
mOutput << startstr << "</newparam>" << endstr;
|
||||
|
||||
mOutput << startstr << "<newparam sid=\"" << XMLEscape(pMatName) << "-" << pTypeName << "-sampler\">" << endstr;
|
||||
mOutput << startstr << "<newparam sid=\"" << XMLIDEncode(pMatName) << "-" << pTypeName << "-sampler\">" << endstr;
|
||||
PushTag();
|
||||
mOutput << startstr << "<sampler2D>" << endstr;
|
||||
PushTag();
|
||||
mOutput << startstr << "<source>" << XMLEscape(pMatName) << "-" << pTypeName << "-surface</source>" << endstr;
|
||||
mOutput << startstr << "<source>" << XMLIDEncode(pMatName) << "-" << pTypeName << "-surface</source>" << endstr;
|
||||
PopTag();
|
||||
mOutput << startstr << "</sampler2D>" << endstr;
|
||||
PopTag();
|
||||
@@ -699,11 +731,6 @@ void ColladaExporter::WriteMaterials()
|
||||
materials[a].name = std::string(name.C_Str()) + to_string(materialCountWithThisName);
|
||||
}
|
||||
}
|
||||
for( std::string::iterator it = materials[a].name.begin(); it != materials[a].name.end(); ++it ) {
|
||||
if( !isalnum_C( *it ) ) {
|
||||
*it = '_';
|
||||
}
|
||||
}
|
||||
|
||||
aiShadingMode shading = aiShadingMode_Flat;
|
||||
materials[a].shading_model = "phong";
|
||||
@@ -768,7 +795,7 @@ void ColladaExporter::WriteMaterials()
|
||||
{
|
||||
const Material& mat = *it;
|
||||
// this is so ridiculous it must be right
|
||||
mOutput << startstr << "<effect id=\"" << XMLEscape(mat.name) << "-fx\" name=\"" << XMLEscape(mat.name) << "\">" << endstr;
|
||||
mOutput << startstr << "<effect id=\"" << XMLIDEncode(mat.name) << "-fx\" name=\"" << XMLEscape(mat.name) << "\">" << endstr;
|
||||
PushTag();
|
||||
mOutput << startstr << "<profile_COMMON>" << endstr;
|
||||
PushTag();
|
||||
@@ -819,9 +846,9 @@ void ColladaExporter::WriteMaterials()
|
||||
for( std::vector<Material>::const_iterator it = materials.begin(); it != materials.end(); ++it )
|
||||
{
|
||||
const Material& mat = *it;
|
||||
mOutput << startstr << "<material id=\"" << XMLEscape(mat.name) << "\" name=\"" << mat.name << "\">" << endstr;
|
||||
mOutput << startstr << "<material id=\"" << XMLIDEncode(mat.name) << "\" name=\"" << XMLEscape(mat.name) << "\">" << endstr;
|
||||
PushTag();
|
||||
mOutput << startstr << "<instance_effect url=\"#" << XMLEscape(mat.name) << "-fx\"/>" << endstr;
|
||||
mOutput << startstr << "<instance_effect url=\"#" << XMLIDEncode(mat.name) << "-fx\"/>" << endstr;
|
||||
PopTag();
|
||||
mOutput << startstr << "</material>" << endstr;
|
||||
}
|
||||
@@ -850,8 +877,8 @@ void ColladaExporter::WriteControllerLibrary()
|
||||
void ColladaExporter::WriteController( size_t pIndex)
|
||||
{
|
||||
const aiMesh* mesh = mScene->mMeshes[pIndex];
|
||||
const std::string idstr = GetMeshId( pIndex);
|
||||
const std::string idstrEscaped = XMLEscape(idstr);
|
||||
const std::string idstr = mesh->mName.length == 0 ? GetMeshId(pIndex) : mesh->mName.C_Str();
|
||||
const std::string idstrEscaped = XMLIDEncode(idstr);
|
||||
|
||||
if ( mesh->mNumFaces == 0 || mesh->mNumVertices == 0 )
|
||||
return;
|
||||
@@ -886,7 +913,7 @@ void ColladaExporter::WriteController( size_t pIndex)
|
||||
mOutput << startstr << "<Name_array id=\"" << idstrEscaped << "-skin-joints-array\" count=\"" << mesh->mNumBones << "\">";
|
||||
|
||||
for( size_t i = 0; i < mesh->mNumBones; ++i )
|
||||
mOutput << XMLEscape(mesh->mBones[i]->mName.C_Str()) << " ";
|
||||
mOutput << XMLIDEncode(mesh->mBones[i]->mName.C_Str()) << " ";
|
||||
|
||||
mOutput << "</Name_array>" << endstr;
|
||||
|
||||
@@ -1021,14 +1048,15 @@ void ColladaExporter::WriteGeometryLibrary()
|
||||
void ColladaExporter::WriteGeometry( size_t pIndex)
|
||||
{
|
||||
const aiMesh* mesh = mScene->mMeshes[pIndex];
|
||||
const std::string idstr = GetMeshId( pIndex);
|
||||
const std::string idstrEscaped = XMLEscape(idstr);
|
||||
const std::string idstr = mesh->mName.length == 0 ? GetMeshId(pIndex) : mesh->mName.C_Str();
|
||||
const std::string geometryName = XMLEscape(idstr);
|
||||
const std::string geometryId = XMLIDEncode(idstr);
|
||||
|
||||
if ( mesh->mNumFaces == 0 || mesh->mNumVertices == 0 )
|
||||
return;
|
||||
|
||||
// opening tag
|
||||
mOutput << startstr << "<geometry id=\"" << idstrEscaped << "\" name=\"" << idstrEscaped << "_name\" >" << endstr;
|
||||
mOutput << startstr << "<geometry id=\"" << geometryId << "\" name=\"" << geometryName << "\" >" << endstr;
|
||||
PushTag();
|
||||
|
||||
mOutput << startstr << "<mesh>" << endstr;
|
||||
@@ -1059,9 +1087,9 @@ void ColladaExporter::WriteGeometry( size_t pIndex)
|
||||
|
||||
// assemble vertex structure
|
||||
// Only write input for POSITION since we will write other as shared inputs in polygon definition
|
||||
mOutput << startstr << "<vertices id=\"" << idstrEscaped << "-vertices" << "\">" << endstr;
|
||||
mOutput << startstr << "<vertices id=\"" << geometryId << "-vertices" << "\">" << endstr;
|
||||
PushTag();
|
||||
mOutput << startstr << "<input semantic=\"POSITION\" source=\"#" << idstrEscaped << "-positions\" />" << endstr;
|
||||
mOutput << startstr << "<input semantic=\"POSITION\" source=\"#" << geometryId << "-positions\" />" << endstr;
|
||||
PopTag();
|
||||
mOutput << startstr << "</vertices>" << endstr;
|
||||
|
||||
@@ -1079,18 +1107,18 @@ void ColladaExporter::WriteGeometry( size_t pIndex)
|
||||
{
|
||||
mOutput << startstr << "<lines count=\"" << countLines << "\" material=\"defaultMaterial\">" << endstr;
|
||||
PushTag();
|
||||
mOutput << startstr << "<input offset=\"0\" semantic=\"VERTEX\" source=\"#" << idstrEscaped << "-vertices\" />" << endstr;
|
||||
mOutput << startstr << "<input offset=\"0\" semantic=\"VERTEX\" source=\"#" << geometryId << "-vertices\" />" << endstr;
|
||||
if( mesh->HasNormals() )
|
||||
mOutput << startstr << "<input semantic=\"NORMAL\" source=\"#" << idstrEscaped << "-normals\" />" << endstr;
|
||||
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=\"#" << idstrEscaped << "-tex" << a << "\" " << "set=\"" << a << "\"" << " />" << endstr;
|
||||
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) ) )
|
||||
mOutput << startstr << "<input semantic=\"COLOR\" source=\"#" << idstrEscaped << "-color" << a << "\" " << "set=\"" << a << "\"" << " />" << endstr;
|
||||
mOutput << startstr << "<input semantic=\"COLOR\" source=\"#" << geometryId << "-color" << a << "\" " << "set=\"" << a << "\"" << " />" << endstr;
|
||||
}
|
||||
|
||||
mOutput << startstr << "<p>";
|
||||
@@ -1113,18 +1141,18 @@ void ColladaExporter::WriteGeometry( size_t pIndex)
|
||||
{
|
||||
mOutput << startstr << "<polylist count=\"" << countPoly << "\" material=\"defaultMaterial\">" << endstr;
|
||||
PushTag();
|
||||
mOutput << startstr << "<input offset=\"0\" semantic=\"VERTEX\" source=\"#" << idstrEscaped << "-vertices\" />" << endstr;
|
||||
mOutput << startstr << "<input offset=\"0\" semantic=\"VERTEX\" source=\"#" << geometryId << "-vertices\" />" << endstr;
|
||||
if( mesh->HasNormals() )
|
||||
mOutput << startstr << "<input offset=\"0\" semantic=\"NORMAL\" source=\"#" << idstrEscaped << "-normals\" />" << endstr;
|
||||
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=\"#" << idstrEscaped << "-tex" << a << "\" " << "set=\"" << a << "\"" << " />" << endstr;
|
||||
mOutput << startstr << "<input offset=\"0\" 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) ) )
|
||||
mOutput << startstr << "<input offset=\"0\" semantic=\"COLOR\" source=\"#" << idstrEscaped << "-color" << a << "\" " << "set=\"" << a << "\"" << " />" << endstr;
|
||||
mOutput << startstr << "<input offset=\"0\" semantic=\"COLOR\" source=\"#" << geometryId << "-color" << a << "\" " << "set=\"" << a << "\"" << " />" << endstr;
|
||||
}
|
||||
|
||||
mOutput << startstr << "<vcount>";
|
||||
@@ -1173,13 +1201,13 @@ void ColladaExporter::WriteFloatArray( const std::string& pIdString, FloatDataTy
|
||||
return;
|
||||
}
|
||||
|
||||
std::string arrayId = pIdString + "-array";
|
||||
std::string arrayId = XMLIDEncode(pIdString) + "-array";
|
||||
|
||||
mOutput << startstr << "<source id=\"" << XMLEscape(pIdString) << "\" name=\"" << XMLEscape(pIdString) << "\">" << endstr;
|
||||
mOutput << startstr << "<source id=\"" << XMLIDEncode(pIdString) << "\" name=\"" << XMLEscape(pIdString) << "\">" << endstr;
|
||||
PushTag();
|
||||
|
||||
// source array
|
||||
mOutput << startstr << "<float_array id=\"" << XMLEscape(arrayId) << "\" count=\"" << pElementCount * floatsPerElement << "\"> ";
|
||||
mOutput << startstr << "<float_array id=\"" << arrayId << "\" count=\"" << pElementCount * floatsPerElement << "\"> ";
|
||||
PushTag();
|
||||
|
||||
if( pType == FloatType_TexCoord2 )
|
||||
@@ -1265,11 +1293,12 @@ void ColladaExporter::WriteFloatArray( const std::string& pIdString, FloatDataTy
|
||||
// Writes the scene library
|
||||
void ColladaExporter::WriteSceneLibrary()
|
||||
{
|
||||
const std::string scene_name_escaped = XMLEscape(mScene->mRootNode->mName.C_Str());
|
||||
const std::string sceneName = XMLEscape(mScene->mRootNode->mName.C_Str());
|
||||
const std::string sceneId = XMLIDEncode(mScene->mRootNode->mName.C_Str());
|
||||
|
||||
mOutput << startstr << "<library_visual_scenes>" << endstr;
|
||||
PushTag();
|
||||
mOutput << startstr << "<visual_scene id=\"" + scene_name_escaped + "\" name=\"" + scene_name_escaped + "\">" << endstr;
|
||||
mOutput << startstr << "<visual_scene id=\"" + sceneId + "\" name=\"" + sceneName + "\">" << endstr;
|
||||
PushTag();
|
||||
|
||||
// start recursive write at the root node
|
||||
@@ -1300,7 +1329,7 @@ void ColladaExporter::WriteAnimationLibrary(size_t pIndex)
|
||||
idstr = idstr + ending;
|
||||
}
|
||||
|
||||
const std::string idstrEscaped = XMLEscape(idstr);
|
||||
const std::string idstrEscaped = XMLIDEncode(idstr);
|
||||
|
||||
mOutput << startstr << "<animation id=\"" + idstrEscaped + "\" name=\"" + animation_name_escaped + "\">" << endstr;
|
||||
PushTag();
|
||||
@@ -1372,13 +1401,13 @@ void ColladaExporter::WriteAnimationLibrary(size_t pIndex)
|
||||
}
|
||||
|
||||
const std::string node_idstr = nodeAnim->mNodeName.data + std::string("_matrix-interpolation");
|
||||
std::string arrayId = node_idstr + "-array";
|
||||
std::string arrayId = XMLIDEncode(node_idstr) + "-array";
|
||||
|
||||
mOutput << startstr << "<source id=\"" << XMLEscape(node_idstr) << "\">" << endstr;
|
||||
mOutput << startstr << "<source id=\"" << XMLIDEncode(node_idstr) << "\">" << endstr;
|
||||
PushTag();
|
||||
|
||||
// source array
|
||||
mOutput << startstr << "<Name_array id=\"" << XMLEscape(arrayId) << "\" count=\"" << names.size() << "\"> ";
|
||||
mOutput << startstr << "<Name_array id=\"" << arrayId << "\" count=\"" << names.size() << "\"> ";
|
||||
for( size_t a = 0; a < names.size(); ++a ) {
|
||||
mOutput << names[a] << " ";
|
||||
}
|
||||
@@ -1387,7 +1416,7 @@ void ColladaExporter::WriteAnimationLibrary(size_t pIndex)
|
||||
mOutput << startstr << "<technique_common>" << endstr;
|
||||
PushTag();
|
||||
|
||||
mOutput << startstr << "<accessor source=\"#" << XMLEscape(arrayId) << "\" count=\"" << names.size() << "\" stride=\"" << 1 << "\">" << endstr;
|
||||
mOutput << startstr << "<accessor source=\"#" << arrayId << "\" count=\"" << names.size() << "\" stride=\"" << 1 << "\">" << endstr;
|
||||
PushTag();
|
||||
|
||||
mOutput << startstr << "<param name=\"INTERPOLATION\" type=\"name\"></param>" << endstr;
|
||||
@@ -1409,12 +1438,12 @@ void ColladaExporter::WriteAnimationLibrary(size_t pIndex)
|
||||
{
|
||||
// samplers
|
||||
const std::string node_idstr = nodeAnim->mNodeName.data + std::string("_matrix-sampler");
|
||||
mOutput << startstr << "<sampler id=\"" << XMLEscape(node_idstr) << "\">" << endstr;
|
||||
mOutput << startstr << "<sampler id=\"" << XMLIDEncode(node_idstr) << "\">" << endstr;
|
||||
PushTag();
|
||||
|
||||
mOutput << startstr << "<input semantic=\"INPUT\" source=\"#" << XMLEscape( nodeAnim->mNodeName.data + std::string("_matrix-input") ) << "\"/>" << endstr;
|
||||
mOutput << startstr << "<input semantic=\"OUTPUT\" source=\"#" << XMLEscape( nodeAnim->mNodeName.data + std::string("_matrix-output") ) << "\"/>" << endstr;
|
||||
mOutput << startstr << "<input semantic=\"INTERPOLATION\" source=\"#" << XMLEscape( nodeAnim->mNodeName.data + std::string("_matrix-interpolation") ) << "\"/>" << endstr;
|
||||
mOutput << startstr << "<input semantic=\"INPUT\" source=\"#" << XMLIDEncode( nodeAnim->mNodeName.data + std::string("_matrix-input") ) << "\"/>" << endstr;
|
||||
mOutput << startstr << "<input semantic=\"OUTPUT\" source=\"#" << XMLIDEncode( nodeAnim->mNodeName.data + std::string("_matrix-output") ) << "\"/>" << endstr;
|
||||
mOutput << startstr << "<input semantic=\"INTERPOLATION\" source=\"#" << XMLIDEncode( nodeAnim->mNodeName.data + std::string("_matrix-interpolation") ) << "\"/>" << endstr;
|
||||
|
||||
PopTag();
|
||||
mOutput << startstr << "</sampler>" << endstr;
|
||||
@@ -1426,7 +1455,7 @@ void ColladaExporter::WriteAnimationLibrary(size_t pIndex)
|
||||
|
||||
{
|
||||
// channels
|
||||
mOutput << startstr << "<channel source=\"#" << XMLEscape( nodeAnim->mNodeName.data + std::string("_matrix-sampler") ) << "\" target=\"" << XMLEscape(nodeAnim->mNodeName.data) << "/matrix\"/>" << endstr;
|
||||
mOutput << startstr << "<channel source=\"#" << XMLIDEncode( nodeAnim->mNodeName.data + std::string("_matrix-sampler") ) << "\" target=\"" << XMLIDEncode(nodeAnim->mNodeName.data) << "/matrix\"/>" << endstr;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1437,8 +1466,6 @@ void ColladaExporter::WriteAnimationLibrary(size_t pIndex)
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void ColladaExporter::WriteAnimationsLibrary()
|
||||
{
|
||||
const std::string scene_name_escaped = XMLEscape(mScene->mRootNode->mName.C_Str());
|
||||
|
||||
if ( mScene->mNumAnimations > 0 ) {
|
||||
mOutput << startstr << "<library_animations>" << endstr;
|
||||
PushTag();
|
||||
@@ -1546,16 +1573,17 @@ void ColladaExporter::WriteNode( const aiScene* pScene, aiNode* pNode)
|
||||
}
|
||||
}
|
||||
|
||||
const std::string node_name_escaped = XMLEscape(pNode->mName.data);
|
||||
const std::string node_id = XMLIDEncode(pNode->mName.data);
|
||||
const std::string node_name = XMLEscape(pNode->mName.data);
|
||||
mOutput << startstr << "<node ";
|
||||
if(is_skeleton_root) {
|
||||
mOutput << "id=\"" << node_name_escaped << "\" " << (is_joint ? "sid=\"" + node_name_escaped +"\"" : "") ; // For now, only support one skeleton in a scene.
|
||||
mFoundSkeletonRootNodeID = node_name_escaped;
|
||||
mOutput << "id=\"" << node_id << "\" " << (is_joint ? "sid=\"" + node_id +"\"" : "") ; // For now, only support one skeleton in a scene.
|
||||
mFoundSkeletonRootNodeID = node_id;
|
||||
} else {
|
||||
mOutput << "id=\"" << node_name_escaped << "\" " << (is_joint ? "sid=\"" + node_name_escaped +"\"": "") ;
|
||||
mOutput << "id=\"" << node_id << "\" " << (is_joint ? "sid=\"" + node_id +"\"": "") ;
|
||||
}
|
||||
|
||||
mOutput << " name=\"" << node_name_escaped
|
||||
mOutput << " name=\"" << node_name
|
||||
<< "\" type=\"" << node_type
|
||||
<< "\">" << endstr;
|
||||
PushTag();
|
||||
@@ -1594,14 +1622,14 @@ void ColladaExporter::WriteNode( const aiScene* pScene, aiNode* pNode)
|
||||
//check if it is a camera node
|
||||
for(size_t i=0; i<mScene->mNumCameras; i++){
|
||||
if(mScene->mCameras[i]->mName == pNode->mName){
|
||||
mOutput << startstr <<"<instance_camera url=\"#" << node_name_escaped << "-camera\"/>" << endstr;
|
||||
mOutput << startstr <<"<instance_camera url=\"#" << node_id << "-camera\"/>" << endstr;
|
||||
break;
|
||||
}
|
||||
}
|
||||
//check if it is a light node
|
||||
for(size_t i=0; i<mScene->mNumLights; i++){
|
||||
if(mScene->mLights[i]->mName == pNode->mName){
|
||||
mOutput << startstr <<"<instance_light url=\"#" << node_name_escaped << "-light\"/>" << endstr;
|
||||
mOutput << startstr <<"<instance_light url=\"#" << node_id << "-light\"/>" << endstr;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -1615,15 +1643,17 @@ void ColladaExporter::WriteNode( const aiScene* pScene, aiNode* pNode)
|
||||
if( mesh->mNumFaces == 0 || mesh->mNumVertices == 0 )
|
||||
continue;
|
||||
|
||||
const std::string meshName = mesh->mName.length == 0 ? GetMeshId(pNode->mMeshes[a]) : mesh->mName.C_Str();
|
||||
|
||||
if( mesh->mNumBones == 0 )
|
||||
{
|
||||
mOutput << startstr << "<instance_geometry url=\"#" << XMLEscape(GetMeshId( pNode->mMeshes[a])) << "\">" << endstr;
|
||||
mOutput << startstr << "<instance_geometry url=\"#" << XMLIDEncode(meshName) << "\">" << endstr;
|
||||
PushTag();
|
||||
}
|
||||
else
|
||||
{
|
||||
mOutput << startstr
|
||||
<< "<instance_controller url=\"#" << XMLEscape(GetMeshId( pNode->mMeshes[a])) << "-skin\">"
|
||||
<< "<instance_controller url=\"#" << XMLIDEncode(meshName) << "-skin\">"
|
||||
<< endstr;
|
||||
PushTag();
|
||||
|
||||
@@ -1631,7 +1661,7 @@ void ColladaExporter::WriteNode( const aiScene* pScene, aiNode* pNode)
|
||||
// use the first bone to find skeleton root
|
||||
const aiNode * skeletonRootBoneNode = findSkeletonRootNode( pScene, mesh );
|
||||
if ( skeletonRootBoneNode ) {
|
||||
mFoundSkeletonRootNodeID = XMLEscape( skeletonRootBoneNode->mName.C_Str() );
|
||||
mFoundSkeletonRootNodeID = XMLIDEncode( skeletonRootBoneNode->mName.C_Str() );
|
||||
}
|
||||
mOutput << startstr << "<skeleton>#" << mFoundSkeletonRootNodeID << "</skeleton>" << endstr;
|
||||
}
|
||||
@@ -1639,7 +1669,7 @@ void ColladaExporter::WriteNode( const aiScene* pScene, aiNode* pNode)
|
||||
PushTag();
|
||||
mOutput << startstr << "<technique_common>" << endstr;
|
||||
PushTag();
|
||||
mOutput << startstr << "<instance_material symbol=\"defaultMaterial\" target=\"#" << XMLEscape(materials[mesh->mMaterialIndex].name) << "\">" << endstr;
|
||||
mOutput << startstr << "<instance_material symbol=\"defaultMaterial\" target=\"#" << XMLIDEncode(materials[mesh->mMaterialIndex].name) << "\">" << endstr;
|
||||
PushTag();
|
||||
for( size_t a = 0; a < AI_MAX_NUMBER_OF_TEXTURECOORDS; ++a )
|
||||
{
|
||||
|
||||
@@ -583,7 +583,7 @@ struct Image
|
||||
/** Embedded image data */
|
||||
std::vector<uint8_t> mImageData;
|
||||
|
||||
/** File format hint ofembedded image data */
|
||||
/** File format hint of embedded image data */
|
||||
std::string mEmbeddedFormat;
|
||||
};
|
||||
|
||||
|
||||
@@ -1735,6 +1735,7 @@ void ColladaLoader::BuildMaterials(ColladaParser& pParser, aiScene* /*pScene*/)
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Resolves the texture name for the given effect texture entry
|
||||
// and loads the texture data
|
||||
aiString ColladaLoader::FindFilenameForEffectTexture(const ColladaParser& pParser,
|
||||
const Collada::Effect& pEffect, const std::string& pName)
|
||||
{
|
||||
@@ -1762,7 +1763,7 @@ aiString ColladaLoader::FindFilenameForEffectTexture(const ColladaParser& pParse
|
||||
|
||||
//set default texture file name
|
||||
result.Set(name + ".jpg");
|
||||
ConvertPath(result);
|
||||
ColladaParser::UriDecodePath(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -1781,7 +1782,7 @@ aiString ColladaLoader::FindFilenameForEffectTexture(const ColladaParser& pParse
|
||||
|
||||
|
||||
// setup format hint
|
||||
if (imIt->second.mEmbeddedFormat.length() > 3) {
|
||||
if (imIt->second.mEmbeddedFormat.length() >= HINTMAXTEXTURELEN) {
|
||||
ASSIMP_LOG_WARN("Collada: texture format hint is too long, truncating to 3 characters");
|
||||
}
|
||||
strncpy(tex->achFormatHint, imIt->second.mEmbeddedFormat.c_str(), 3);
|
||||
@@ -1802,61 +1803,10 @@ aiString ColladaLoader::FindFilenameForEffectTexture(const ColladaParser& pParse
|
||||
}
|
||||
|
||||
result.Set(imIt->second.mFileName);
|
||||
ConvertPath(result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Convert a path read from a collada file to the usual representation
|
||||
void ColladaLoader::ConvertPath(aiString& ss)
|
||||
{
|
||||
// TODO: collada spec, p 22. Handle URI correctly.
|
||||
// For the moment we're just stripping the file:// away to make it work.
|
||||
// Windows doesn't seem to be able to find stuff like
|
||||
// 'file://..\LWO\LWO2\MappingModes\earthSpherical.jpg'
|
||||
if (0 == strncmp(ss.data, "file://", 7))
|
||||
{
|
||||
ss.length -= 7;
|
||||
memmove(ss.data, ss.data + 7, ss.length);
|
||||
ss.data[ss.length] = '\0';
|
||||
}
|
||||
|
||||
// Maxon Cinema Collada Export writes "file:///C:\andsoon" with three slashes...
|
||||
// I need to filter it without destroying linux paths starting with "/somewhere"
|
||||
#if defined( _MSC_VER )
|
||||
if (ss.data[0] == '/' && isalpha((unsigned char)ss.data[1]) && ss.data[2] == ':') {
|
||||
#else
|
||||
if (ss.data[0] == '/' && isalpha(ss.data[1]) && ss.data[2] == ':') {
|
||||
#endif
|
||||
--ss.length;
|
||||
::memmove(ss.data, ss.data + 1, ss.length);
|
||||
ss.data[ss.length] = 0;
|
||||
}
|
||||
|
||||
// find and convert all %xy special chars
|
||||
char* out = ss.data;
|
||||
for (const char* it = ss.data; it != ss.data + ss.length; /**/)
|
||||
{
|
||||
if (*it == '%' && (it + 3) < ss.data + ss.length)
|
||||
{
|
||||
// separate the number to avoid dragging in chars from behind into the parsing
|
||||
char mychar[3] = { it[1], it[2], 0 };
|
||||
size_t nbr = strtoul16(mychar);
|
||||
it += 3;
|
||||
*out++ = (char)(nbr & 0xFF);
|
||||
}
|
||||
else
|
||||
{
|
||||
*out++ = *it++;
|
||||
}
|
||||
}
|
||||
|
||||
// adjust length and terminator of the shortened string
|
||||
*out = 0;
|
||||
ss.length = (ptrdiff_t)(out - ss.data);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Reads a float value from an accessor and its data array.
|
||||
ai_real ColladaLoader::ReadFloat(const Collada::Accessor& pAccessor, const Collada::Data& pData, size_t pIndex, size_t pOffset) const
|
||||
|
||||
@@ -94,7 +94,7 @@ public:
|
||||
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 checkSig) const override;
|
||||
bool CanRead(const std::string& pFile, IOSystem* pIOHandler, bool checkSig) const override;
|
||||
|
||||
protected:
|
||||
/** Return importer meta information.
|
||||
@@ -184,9 +184,6 @@ protected:
|
||||
aiString FindFilenameForEffectTexture( const ColladaParser& pParser,
|
||||
const Collada::Effect& pEffect, const std::string& pName);
|
||||
|
||||
/** Converts a path read from a collada file to the usual representation */
|
||||
void ConvertPath( aiString& ss);
|
||||
|
||||
/** 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
|
||||
|
||||
@@ -183,13 +183,67 @@ std::string ColladaParser::ReadZaeManifest(ZipArchiveIOSystem &zip_archive) {
|
||||
if (filepath == nullptr)
|
||||
return std::string();
|
||||
|
||||
return std::string(filepath);
|
||||
aiString ai_str(filepath);
|
||||
UriDecodePath(ai_str);
|
||||
|
||||
return std::string(ai_str.C_Str());
|
||||
}
|
||||
}
|
||||
}
|
||||
return std::string();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Convert a path read from a collada file to the usual representation
|
||||
void ColladaParser::UriDecodePath(aiString& ss)
|
||||
{
|
||||
// TODO: collada spec, p 22. Handle URI correctly.
|
||||
// For the moment we're just stripping the file:// away to make it work.
|
||||
// Windows doesn't seem to be able to find stuff like
|
||||
// 'file://..\LWO\LWO2\MappingModes\earthSpherical.jpg'
|
||||
if (0 == strncmp(ss.data, "file://", 7))
|
||||
{
|
||||
ss.length -= 7;
|
||||
memmove(ss.data, ss.data + 7, ss.length);
|
||||
ss.data[ss.length] = '\0';
|
||||
}
|
||||
|
||||
// Maxon Cinema Collada Export writes "file:///C:\andsoon" with three slashes...
|
||||
// I need to filter it without destroying linux paths starting with "/somewhere"
|
||||
#if defined( _MSC_VER )
|
||||
if (ss.data[0] == '/' && isalpha((unsigned char)ss.data[1]) && ss.data[2] == ':') {
|
||||
#else
|
||||
if (ss.data[0] == '/' && isalpha(ss.data[1]) && ss.data[2] == ':') {
|
||||
#endif
|
||||
--ss.length;
|
||||
::memmove(ss.data, ss.data + 1, ss.length);
|
||||
ss.data[ss.length] = 0;
|
||||
}
|
||||
|
||||
// find and convert all %xy special chars
|
||||
char* out = ss.data;
|
||||
for (const char* it = ss.data; it != ss.data + ss.length; /**/)
|
||||
{
|
||||
if (*it == '%' && (it + 3) < ss.data + ss.length)
|
||||
{
|
||||
// separate the number to avoid dragging in chars from behind into the parsing
|
||||
char mychar[3] = { it[1], it[2], 0 };
|
||||
size_t nbr = strtoul16(mychar);
|
||||
it += 3;
|
||||
*out++ = (char)(nbr & 0xFF);
|
||||
}
|
||||
else
|
||||
{
|
||||
*out++ = *it++;
|
||||
}
|
||||
}
|
||||
|
||||
// adjust length and terminator of the shortened string
|
||||
*out = 0;
|
||||
ai_assert(out > ss.data);
|
||||
ss.length = static_cast<ai_uint32>(out - ss.data);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Read bool from text contents of current element
|
||||
bool ColladaParser::ReadBoolFromTextContent()
|
||||
@@ -1120,7 +1174,12 @@ void ColladaParser::ReadImage(Collada::Image& pImage)
|
||||
if (!mReader->isEmptyElement()) {
|
||||
// element content is filename - hopefully
|
||||
const char* sz = TestTextContent();
|
||||
if (sz)pImage.mFileName = sz;
|
||||
if (sz)
|
||||
{
|
||||
aiString filepath(sz);
|
||||
UriDecodePath(filepath);
|
||||
pImage.mFileName = filepath.C_Str();
|
||||
}
|
||||
TestClosing("init_from");
|
||||
}
|
||||
if (!pImage.mFileName.length()) {
|
||||
@@ -1153,7 +1212,12 @@ void ColladaParser::ReadImage(Collada::Image& pImage)
|
||||
{
|
||||
// element content is filename - hopefully
|
||||
const char* sz = TestTextContent();
|
||||
if (sz)pImage.mFileName = sz;
|
||||
if (sz)
|
||||
{
|
||||
aiString filepath(sz);
|
||||
UriDecodePath(filepath);
|
||||
pImage.mFileName = filepath.C_Str();
|
||||
}
|
||||
TestClosing("ref");
|
||||
}
|
||||
else if (IsElement("hex") && !pImage.mFileName.length())
|
||||
@@ -3056,7 +3120,7 @@ void ColladaParser::ReadMaterialVertexInputBinding(Collada::SemanticMappingTable
|
||||
}
|
||||
}
|
||||
|
||||
void Assimp::ColladaParser::ReadEmbeddedTextures(ZipArchiveIOSystem& zip_archive)
|
||||
void ColladaParser::ReadEmbeddedTextures(ZipArchiveIOSystem& zip_archive)
|
||||
{
|
||||
// Attempt to load any undefined Collada::Image in ImageLibrary
|
||||
for (ImageLibrary::iterator it = mImageLibrary.begin(); it != mImageLibrary.end(); ++it) {
|
||||
|
||||
@@ -66,12 +66,15 @@ namespace Assimp
|
||||
{
|
||||
friend class ColladaLoader;
|
||||
|
||||
/** Converts a path read from a collada file to the usual representation */
|
||||
static void UriDecodePath(aiString& ss);
|
||||
|
||||
protected:
|
||||
/** Map for generic metadata as aiString */
|
||||
typedef std::map<std::string, aiString> StringMetaData;
|
||||
|
||||
/** Constructor from XML file */
|
||||
ColladaParser( IOSystem* pIOHandler, const std::string& pFile);
|
||||
ColladaParser(IOSystem* pIOHandler, const std::string& pFile);
|
||||
|
||||
/** Destructor */
|
||||
~ColladaParser();
|
||||
|
||||
@@ -67,7 +67,20 @@ using namespace Assimp;
|
||||
// Constructor to be privately used by Importer
|
||||
BaseImporter::BaseImporter() AI_NO_EXCEPT
|
||||
: m_progress() {
|
||||
// nothing to do here
|
||||
/**
|
||||
* Assimp Importer
|
||||
* unit conversions available
|
||||
* if you need another measurment unit add it below.
|
||||
* it's currently defined in assimp that we prefer meters.
|
||||
*
|
||||
* NOTE: Initialised here rather than in the header file
|
||||
* to workaround a VS2013 bug with brace initialisers
|
||||
* */
|
||||
importerUnits[ImporterUnits::M] = 1.0;
|
||||
importerUnits[ImporterUnits::CM] = 0.01;
|
||||
importerUnits[ImporterUnits::MM] = 0.001;
|
||||
importerUnits[ImporterUnits::INCHES] = 0.0254;
|
||||
importerUnits[ImporterUnits::FEET] = 0.3048;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -52,6 +52,35 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
using namespace Assimp;
|
||||
|
||||
namespace
|
||||
{
|
||||
template<size_t sizeOfPointer>
|
||||
size_t select_ftell(FILE* file)
|
||||
{
|
||||
return ::ftell(file);
|
||||
}
|
||||
|
||||
template<size_t sizeOfPointer>
|
||||
int select_fseek(FILE* file, int64_t offset, int origin)
|
||||
{
|
||||
return ::fseek(file, static_cast<long>(offset), origin);
|
||||
}
|
||||
|
||||
#if defined _WIN32 && (!defined __GNUC__ || __MSVCRT_VERSION__ >= 0x0601)
|
||||
template<>
|
||||
size_t select_ftell<8>(FILE* file)
|
||||
{
|
||||
return ::_ftelli64(file);
|
||||
}
|
||||
|
||||
template<>
|
||||
int select_fseek<8>(FILE* file, int64_t offset, int origin)
|
||||
{
|
||||
return ::_fseeki64(file, offset, origin);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------------
|
||||
DefaultIOStream::~DefaultIOStream()
|
||||
{
|
||||
@@ -93,7 +122,7 @@ aiReturn DefaultIOStream::Seek(size_t pOffset,
|
||||
aiOrigin_END == SEEK_END && aiOrigin_SET == SEEK_SET");
|
||||
|
||||
// do the seek
|
||||
return (0 == ::fseek(mFile, (long)pOffset,(int)pOrigin) ? AI_SUCCESS : AI_FAILURE);
|
||||
return (0 == select_fseek<sizeof(void*)>(mFile, (int64_t)pOffset,(int)pOrigin) ? AI_SUCCESS : AI_FAILURE);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------------
|
||||
@@ -102,7 +131,7 @@ size_t DefaultIOStream::Tell() const
|
||||
if (!mFile) {
|
||||
return 0;
|
||||
}
|
||||
return ::ftell(mFile);
|
||||
return select_ftell<sizeof(void*)>(mFile);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------------
|
||||
|
||||
@@ -107,7 +107,7 @@ LogStream* LogStream::createDefaultStream(aiDefaultLogStream streams,
|
||||
return nullptr;
|
||||
#endif
|
||||
|
||||
// Platform-independent default streams
|
||||
// Platform-independent default streams
|
||||
case aiDefaultLogStream_STDERR:
|
||||
return new StdOStreamLogStream(std::cerr);
|
||||
case aiDefaultLogStream_STDOUT:
|
||||
@@ -121,7 +121,7 @@ LogStream* LogStream::createDefaultStream(aiDefaultLogStream streams,
|
||||
};
|
||||
|
||||
// For compilers without dead code path detection
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------------
|
||||
|
||||
+69
-61
@@ -102,94 +102,92 @@ void ExportSceneX3D(const char*, IOSystem*, const aiScene*, const ExportProperti
|
||||
void ExportSceneFBX(const char*, IOSystem*, const aiScene*, const ExportProperties*);
|
||||
void ExportSceneFBXA(const char*, IOSystem*, const aiScene*, const ExportProperties*);
|
||||
void ExportScene3MF( const char*, IOSystem*, const aiScene*, const ExportProperties* );
|
||||
void ExportSceneM3D(const char*, IOSystem*, const aiScene*, const ExportProperties*);
|
||||
void ExportSceneA3D(const char*, IOSystem*, const aiScene*, const ExportProperties*);
|
||||
void ExportAssimp2Json(const char* , IOSystem*, const aiScene* , const Assimp::ExportProperties*);
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// global array of all export formats which Assimp supports in its current build
|
||||
Exporter::ExportFormatEntry gExporters[] =
|
||||
{
|
||||
|
||||
static void setupExporterArray(std::vector<Exporter::ExportFormatEntry> &exporters) {
|
||||
#ifndef ASSIMP_BUILD_NO_COLLADA_EXPORTER
|
||||
Exporter::ExportFormatEntry( "collada", "COLLADA - Digital Asset Exchange Schema", "dae", &ExportSceneCollada ),
|
||||
exporters.push_back(Exporter::ExportFormatEntry("collada", "COLLADA - Digital Asset Exchange Schema", "dae", &ExportSceneCollada));
|
||||
#endif
|
||||
|
||||
#ifndef ASSIMP_BUILD_NO_X_EXPORTER
|
||||
Exporter::ExportFormatEntry( "x", "X Files", "x", &ExportSceneXFile,
|
||||
aiProcess_MakeLeftHanded | aiProcess_FlipWindingOrder | aiProcess_FlipUVs ),
|
||||
exporters.push_back(Exporter::ExportFormatEntry("x", "X Files", "x", &ExportSceneXFile,
|
||||
aiProcess_MakeLeftHanded | aiProcess_FlipWindingOrder | aiProcess_FlipUVs));
|
||||
#endif
|
||||
|
||||
#ifndef ASSIMP_BUILD_NO_STEP_EXPORTER
|
||||
Exporter::ExportFormatEntry( "stp", "Step Files", "stp", &ExportSceneStep, 0 ),
|
||||
exporters.push_back(Exporter::ExportFormatEntry("stp", "Step Files", "stp", &ExportSceneStep, 0));
|
||||
#endif
|
||||
|
||||
#ifndef ASSIMP_BUILD_NO_OBJ_EXPORTER
|
||||
Exporter::ExportFormatEntry( "obj", "Wavefront OBJ format", "obj", &ExportSceneObj,
|
||||
aiProcess_GenSmoothNormals /*| aiProcess_PreTransformVertices */ ),
|
||||
Exporter::ExportFormatEntry( "objnomtl", "Wavefront OBJ format without material file", "obj", &ExportSceneObjNoMtl,
|
||||
aiProcess_GenSmoothNormals /*| aiProcess_PreTransformVertices */ ),
|
||||
exporters.push_back(Exporter::ExportFormatEntry("obj", "Wavefront OBJ format", "obj", &ExportSceneObj,
|
||||
aiProcess_GenSmoothNormals /*| aiProcess_PreTransformVertices */));
|
||||
exporters.push_back(Exporter::ExportFormatEntry("objnomtl", "Wavefront OBJ format without material file", "obj", &ExportSceneObjNoMtl,
|
||||
aiProcess_GenSmoothNormals /*| aiProcess_PreTransformVertices */));
|
||||
#endif
|
||||
|
||||
#ifndef ASSIMP_BUILD_NO_STL_EXPORTER
|
||||
Exporter::ExportFormatEntry( "stl", "Stereolithography", "stl" , &ExportSceneSTL,
|
||||
aiProcess_Triangulate | aiProcess_GenNormals | aiProcess_PreTransformVertices
|
||||
),
|
||||
Exporter::ExportFormatEntry( "stlb", "Stereolithography (binary)", "stl" , &ExportSceneSTLBinary,
|
||||
aiProcess_Triangulate | aiProcess_GenNormals | aiProcess_PreTransformVertices
|
||||
),
|
||||
exporters.push_back(Exporter::ExportFormatEntry("stl", "Stereolithography", "stl", &ExportSceneSTL,
|
||||
aiProcess_Triangulate | aiProcess_GenNormals | aiProcess_PreTransformVertices));
|
||||
exporters.push_back(Exporter::ExportFormatEntry("stlb", "Stereolithography (binary)", "stl", &ExportSceneSTLBinary,
|
||||
aiProcess_Triangulate | aiProcess_GenNormals | aiProcess_PreTransformVertices));
|
||||
#endif
|
||||
|
||||
#ifndef ASSIMP_BUILD_NO_PLY_EXPORTER
|
||||
Exporter::ExportFormatEntry( "ply", "Stanford Polygon Library", "ply" , &ExportScenePly,
|
||||
aiProcess_PreTransformVertices
|
||||
),
|
||||
Exporter::ExportFormatEntry( "plyb", "Stanford Polygon Library (binary)", "ply", &ExportScenePlyBinary,
|
||||
aiProcess_PreTransformVertices
|
||||
),
|
||||
exporters.push_back(Exporter::ExportFormatEntry("ply", "Stanford Polygon Library", "ply", &ExportScenePly,
|
||||
aiProcess_PreTransformVertices));
|
||||
exporters.push_back(Exporter::ExportFormatEntry("plyb", "Stanford Polygon Library (binary)", "ply", &ExportScenePlyBinary,
|
||||
aiProcess_PreTransformVertices));
|
||||
#endif
|
||||
|
||||
#ifndef ASSIMP_BUILD_NO_3DS_EXPORTER
|
||||
Exporter::ExportFormatEntry( "3ds", "Autodesk 3DS (legacy)", "3ds" , &ExportScene3DS,
|
||||
aiProcess_Triangulate | aiProcess_SortByPType | aiProcess_JoinIdenticalVertices ),
|
||||
exporters.push_back(Exporter::ExportFormatEntry("3ds", "Autodesk 3DS (legacy)", "3ds", &ExportScene3DS,
|
||||
aiProcess_Triangulate | aiProcess_SortByPType | aiProcess_JoinIdenticalVertices));
|
||||
#endif
|
||||
|
||||
#ifndef ASSIMP_BUILD_NO_GLTF_EXPORTER
|
||||
Exporter::ExportFormatEntry( "gltf2", "GL Transmission Format v. 2", "gltf", &ExportSceneGLTF2,
|
||||
aiProcess_JoinIdenticalVertices | aiProcess_Triangulate | aiProcess_SortByPType ),
|
||||
Exporter::ExportFormatEntry( "glb2", "GL Transmission Format v. 2 (binary)", "glb", &ExportSceneGLB2,
|
||||
aiProcess_JoinIdenticalVertices | aiProcess_Triangulate | aiProcess_SortByPType ),
|
||||
Exporter::ExportFormatEntry( "gltf", "GL Transmission Format", "gltf", &ExportSceneGLTF,
|
||||
aiProcess_JoinIdenticalVertices | aiProcess_Triangulate | aiProcess_SortByPType ),
|
||||
Exporter::ExportFormatEntry( "glb", "GL Transmission Format (binary)", "glb", &ExportSceneGLB,
|
||||
aiProcess_JoinIdenticalVertices | aiProcess_Triangulate | aiProcess_SortByPType ),
|
||||
exporters.push_back(Exporter::ExportFormatEntry("gltf2", "GL Transmission Format v. 2", "gltf", &ExportSceneGLTF2,
|
||||
aiProcess_JoinIdenticalVertices | aiProcess_Triangulate | aiProcess_SortByPType));
|
||||
exporters.push_back(Exporter::ExportFormatEntry("glb2", "GL Transmission Format v. 2 (binary)", "glb", &ExportSceneGLB2,
|
||||
aiProcess_JoinIdenticalVertices | aiProcess_Triangulate | aiProcess_SortByPType));
|
||||
exporters.push_back(Exporter::ExportFormatEntry("gltf", "GL Transmission Format", "gltf", &ExportSceneGLTF,
|
||||
aiProcess_JoinIdenticalVertices | aiProcess_Triangulate | aiProcess_SortByPType));
|
||||
exporters.push_back(Exporter::ExportFormatEntry("glb", "GL Transmission Format (binary)", "glb", &ExportSceneGLB,
|
||||
aiProcess_JoinIdenticalVertices | aiProcess_Triangulate | aiProcess_SortByPType));
|
||||
#endif
|
||||
|
||||
#ifndef ASSIMP_BUILD_NO_ASSBIN_EXPORTER
|
||||
Exporter::ExportFormatEntry( "assbin", "Assimp Binary File", "assbin" , &ExportSceneAssbin, 0 ),
|
||||
exporters.push_back(Exporter::ExportFormatEntry("assbin", "Assimp Binary File", "assbin", &ExportSceneAssbin, 0));
|
||||
#endif
|
||||
|
||||
#ifndef ASSIMP_BUILD_NO_ASSXML_EXPORTER
|
||||
Exporter::ExportFormatEntry( "assxml", "Assimp XML Document", "assxml" , &ExportSceneAssxml, 0 ),
|
||||
exporters.push_back(Exporter::ExportFormatEntry("assxml", "Assimp XML Document", "assxml", &ExportSceneAssxml, 0));
|
||||
#endif
|
||||
|
||||
#ifndef ASSIMP_BUILD_NO_X3D_EXPORTER
|
||||
Exporter::ExportFormatEntry( "x3d", "Extensible 3D", "x3d" , &ExportSceneX3D, 0 ),
|
||||
exporters.push_back(Exporter::ExportFormatEntry("x3d", "Extensible 3D", "x3d", &ExportSceneX3D, 0));
|
||||
#endif
|
||||
|
||||
#ifndef ASSIMP_BUILD_NO_FBX_EXPORTER
|
||||
Exporter::ExportFormatEntry( "fbx", "Autodesk FBX (binary)", "fbx", &ExportSceneFBX, 0 ),
|
||||
Exporter::ExportFormatEntry( "fbxa", "Autodesk FBX (ascii)", "fbx", &ExportSceneFBXA, 0 ),
|
||||
exporters.push_back(Exporter::ExportFormatEntry("fbx", "Autodesk FBX (binary)", "fbx", &ExportSceneFBX, 0));
|
||||
exporters.push_back(Exporter::ExportFormatEntry("fbxa", "Autodesk FBX (ascii)", "fbx", &ExportSceneFBXA, 0));
|
||||
#endif
|
||||
|
||||
#ifndef ASSIMP_BUILD_NO_M3D_EXPORTER
|
||||
exporters.push_back(Exporter::ExportFormatEntry("m3d", "Model 3D (binary)", "m3d", &ExportSceneM3D, 0));
|
||||
exporters.push_back(Exporter::ExportFormatEntry("a3d", "Model 3D (ascii)", "m3d", &ExportSceneA3D, 0));
|
||||
#endif
|
||||
|
||||
#ifndef ASSIMP_BUILD_NO_3MF_EXPORTER
|
||||
Exporter::ExportFormatEntry( "3mf", "The 3MF-File-Format", "3mf", &ExportScene3MF, 0 ),
|
||||
exporters.push_back(Exporter::ExportFormatEntry("3mf", "The 3MF-File-Format", "3mf", &ExportScene3MF, 0));
|
||||
#endif
|
||||
|
||||
#ifndef ASSIMP_BUILD_NO_ASSJSON_EXPORTER
|
||||
Exporter::ExportFormatEntry( "assjson", "Assimp JSON Document", "json", &ExportAssimp2Json, 0)
|
||||
exporters.push_back(Exporter::ExportFormatEntry("assjson", "Assimp JSON Document", "json", &ExportAssimp2Json, 0));
|
||||
#endif
|
||||
};
|
||||
|
||||
#define ASSIMP_NUM_EXPORTERS (sizeof(gExporters)/sizeof(gExporters[0]))
|
||||
|
||||
}
|
||||
|
||||
class ExporterPimpl {
|
||||
public:
|
||||
@@ -205,10 +203,7 @@ public:
|
||||
GetPostProcessingStepInstanceList(mPostProcessingSteps);
|
||||
|
||||
// grab all built-in exporters
|
||||
if ( 0 != ( ASSIMP_NUM_EXPORTERS ) ) {
|
||||
mExporters.resize( ASSIMP_NUM_EXPORTERS );
|
||||
std::copy( gExporters, gExporters + ASSIMP_NUM_EXPORTERS, mExporters.begin() );
|
||||
}
|
||||
setupExporterArray(mExporters);
|
||||
}
|
||||
|
||||
~ExporterPimpl() {
|
||||
@@ -252,24 +247,28 @@ Exporter :: Exporter()
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Exporter::~Exporter() {
|
||||
FreeBlob();
|
||||
ai_assert(nullptr != pimpl);
|
||||
FreeBlob();
|
||||
delete pimpl;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void Exporter::SetIOHandler( IOSystem* pIOHandler) {
|
||||
pimpl->mIsDefaultIOHandler = !pIOHandler;
|
||||
ai_assert(nullptr != pimpl);
|
||||
pimpl->mIsDefaultIOHandler = !pIOHandler;
|
||||
pimpl->mIOSystem.reset(pIOHandler);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
IOSystem* Exporter::GetIOHandler() const {
|
||||
return pimpl->mIOSystem.get();
|
||||
ai_assert(nullptr != pimpl);
|
||||
return pimpl->mIOSystem.get();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
bool Exporter::IsDefaultIOHandler() const {
|
||||
return pimpl->mIsDefaultIOHandler;
|
||||
ai_assert(nullptr != pimpl);
|
||||
return pimpl->mIsDefaultIOHandler;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@@ -295,6 +294,7 @@ void Exporter::SetProgressHandler(ProgressHandler* pHandler) {
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
const aiExportDataBlob* Exporter::ExportToBlob( const aiScene* pScene, const char* pFormatId,
|
||||
unsigned int pPreprocessing, const ExportProperties* pProperties) {
|
||||
ai_assert(nullptr != pimpl);
|
||||
if (pimpl->blob) {
|
||||
delete pimpl->blob;
|
||||
pimpl->blob = nullptr;
|
||||
@@ -319,7 +319,7 @@ const aiExportDataBlob* Exporter::ExportToBlob( const aiScene* pScene, const cha
|
||||
aiReturn Exporter::Export( const aiScene* pScene, const char* pFormatId, const char* pPath,
|
||||
unsigned int pPreprocessing, const ExportProperties* pProperties) {
|
||||
ASSIMP_BEGIN_EXCEPTION_REGION();
|
||||
|
||||
ai_assert(nullptr != pimpl);
|
||||
// when they create scenes from scratch, users will likely create them not in verbose
|
||||
// format. They will likely not be aware that there is a flag in the scene to indicate
|
||||
// this, however. To avoid surprises and bug reports, we check for duplicates in
|
||||
@@ -466,11 +466,13 @@ aiReturn Exporter::Export( const aiScene* pScene, const char* pFormatId, const c
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
const char* Exporter::GetErrorString() const {
|
||||
ai_assert(nullptr != pimpl);
|
||||
return pimpl->mError.c_str();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void Exporter::FreeBlob() {
|
||||
ai_assert(nullptr != pimpl);
|
||||
delete pimpl->blob;
|
||||
pimpl->blob = nullptr;
|
||||
|
||||
@@ -479,30 +481,34 @@ void Exporter::FreeBlob() {
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
const aiExportDataBlob* Exporter::GetBlob() const {
|
||||
return pimpl->blob;
|
||||
ai_assert(nullptr != pimpl);
|
||||
return pimpl->blob;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
const aiExportDataBlob* Exporter::GetOrphanedBlob() const {
|
||||
const aiExportDataBlob* tmp = pimpl->blob;
|
||||
ai_assert(nullptr != pimpl);
|
||||
const aiExportDataBlob *tmp = pimpl->blob;
|
||||
pimpl->blob = nullptr;
|
||||
return tmp;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
size_t Exporter::GetExportFormatCount() const {
|
||||
ai_assert(nullptr != pimpl);
|
||||
return pimpl->mExporters.size();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
const aiExportFormatDesc* Exporter::GetExportFormatDescription( size_t index ) const {
|
||||
if (index >= GetExportFormatCount()) {
|
||||
ai_assert(nullptr != pimpl);
|
||||
if (index >= GetExportFormatCount()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// Return from static storage if the requested index is built-in.
|
||||
if (index < sizeof(gExporters) / sizeof(gExporters[0])) {
|
||||
return &gExporters[index].mDescription;
|
||||
if (index < pimpl->mExporters.size()) {
|
||||
return &pimpl->mExporters[index].mDescription;
|
||||
}
|
||||
|
||||
return &pimpl->mExporters[index].mDescription;
|
||||
@@ -510,7 +516,8 @@ const aiExportFormatDesc* Exporter::GetExportFormatDescription( size_t index ) c
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
aiReturn Exporter::RegisterExporter(const ExportFormatEntry& desc) {
|
||||
for(const ExportFormatEntry& e : pimpl->mExporters) {
|
||||
ai_assert(nullptr != pimpl);
|
||||
for (const ExportFormatEntry &e : pimpl->mExporters) {
|
||||
if (!strcmp(e.mDescription.id,desc.mDescription.id)) {
|
||||
return aiReturn_FAILURE;
|
||||
}
|
||||
@@ -522,7 +529,8 @@ aiReturn Exporter::RegisterExporter(const ExportFormatEntry& desc) {
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void Exporter::UnregisterExporter(const char* id) {
|
||||
for(std::vector<ExportFormatEntry>::iterator it = pimpl->mExporters.begin();
|
||||
ai_assert(nullptr != pimpl);
|
||||
for (std::vector<ExportFormatEntry>::iterator it = pimpl->mExporters.begin();
|
||||
it != pimpl->mExporters.end(); ++it) {
|
||||
if (!strcmp((*it).mDescription.id,id)) {
|
||||
pimpl->mExporters.erase(it);
|
||||
|
||||
@@ -197,6 +197,9 @@ corresponding preprocessor flag to selectively disable formats.
|
||||
#ifndef ASSIMP_BUILD_NO_MMD_IMPORTER
|
||||
# include "MMD/MMDImporter.h"
|
||||
#endif
|
||||
#ifndef ASSIMP_BUILD_NO_M3D_IMPORTER
|
||||
# include "M3D/M3DImporter.h"
|
||||
#endif
|
||||
#ifndef ASSIMP_BUILD_NO_STEP_IMPORTER
|
||||
# include "Importer/StepFile/StepFileImporter.h"
|
||||
#endif
|
||||
@@ -223,6 +226,9 @@ void GetImporterInstanceList(std::vector< BaseImporter* >& out)
|
||||
#if (!defined ASSIMP_BUILD_NO_3DS_IMPORTER)
|
||||
out.push_back( new Discreet3DSImporter());
|
||||
#endif
|
||||
#if (!defined ASSIMP_BUILD_NO_M3D_IMPORTER)
|
||||
out.push_back( new M3DImporter());
|
||||
#endif
|
||||
#if (!defined ASSIMP_BUILD_NO_MD3_IMPORTER)
|
||||
out.push_back( new MD3Importer());
|
||||
#endif
|
||||
|
||||
@@ -131,11 +131,15 @@ corresponding preprocessor flag to selectively disable steps.
|
||||
#if (!defined ASSIMP_BUILD_NO_GLOBALSCALE_PROCESS)
|
||||
# include "PostProcessing/ScaleProcess.h"
|
||||
#endif
|
||||
#if (!defined ASSIMP_BUILD_NO_ARMATUREPOPULATE_PROCESS)
|
||||
# include "PostProcessing/ArmaturePopulate.h"
|
||||
#endif
|
||||
#if (!defined ASSIMP_BUILD_NO_GENBOUNDINGBOXES_PROCESS)
|
||||
# include "PostProcessing/GenBoundingBoxesProcess.h"
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
namespace Assimp {
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@@ -180,6 +184,9 @@ void GetPostProcessingStepInstanceList(std::vector< BaseProcess* >& out)
|
||||
#if (!defined ASSIMP_BUILD_NO_GLOBALSCALE_PROCESS)
|
||||
out.push_back( new ScaleProcess());
|
||||
#endif
|
||||
#if (!defined ASSIMP_BUILD_NO_ARMATUREPOPULATE_PROCESS)
|
||||
out.push_back( new ArmaturePopulate());
|
||||
#endif
|
||||
#if (!defined ASSIMP_BUILD_NO_PRETRANSFORMVERTICES_PROCESS)
|
||||
out.push_back( new PretransformVertices());
|
||||
#endif
|
||||
|
||||
@@ -1196,6 +1196,7 @@ void SceneCombiner::Copy( aiAnimation** _dest, const aiAnimation* src ) {
|
||||
|
||||
// and reallocate all arrays
|
||||
CopyPtrArray( dest->mChannels, src->mChannels, dest->mNumChannels );
|
||||
CopyPtrArray( dest->mMorphMeshChannels, src->mMorphMeshChannels, dest->mNumMorphMeshChannels );
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@@ -1215,6 +1216,26 @@ void SceneCombiner::Copy(aiNodeAnim** _dest, const aiNodeAnim* src) {
|
||||
GetArrayCopy( dest->mRotationKeys, dest->mNumRotationKeys );
|
||||
}
|
||||
|
||||
void SceneCombiner::Copy(aiMeshMorphAnim** _dest, const aiMeshMorphAnim* src) {
|
||||
if ( nullptr == _dest || nullptr == src ) {
|
||||
return;
|
||||
}
|
||||
|
||||
aiMeshMorphAnim* dest = *_dest = new aiMeshMorphAnim();
|
||||
|
||||
// get a flat copy
|
||||
::memcpy(dest,src,sizeof(aiMeshMorphAnim));
|
||||
|
||||
// and reallocate all arrays
|
||||
GetArrayCopy( dest->mKeys, dest->mNumKeys );
|
||||
for (ai_uint i = 0; i < dest->mNumKeys;++i) {
|
||||
dest->mKeys[i].mValues = new unsigned int[dest->mKeys[i].mNumValuesAndWeights];
|
||||
dest->mKeys[i].mWeights = new double[dest->mKeys[i].mNumValuesAndWeights];
|
||||
::memcpy(dest->mKeys[i].mValues, src->mKeys[i].mValues, dest->mKeys[i].mNumValuesAndWeights * sizeof(unsigned int));
|
||||
::memcpy(dest->mKeys[i].mWeights, src->mKeys[i].mWeights, dest->mKeys[i].mNumValuesAndWeights * sizeof(double));
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void SceneCombiner::Copy( aiCamera** _dest,const aiCamera* src) {
|
||||
if ( nullptr == _dest || nullptr == src ) {
|
||||
|
||||
@@ -46,8 +46,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#include <assimp/scene.h>
|
||||
#include "ScenePrivate.h"
|
||||
|
||||
static const unsigned int MajorVersion = 4;
|
||||
static const unsigned int MinorVersion = 1;
|
||||
#include "revision.h"
|
||||
|
||||
// --------------------------------------------------------------------------------
|
||||
// Legal information string - don't remove this.
|
||||
@@ -56,9 +55,9 @@ static const char* LEGAL_INFORMATION =
|
||||
"Open Asset Import Library (Assimp).\n"
|
||||
"A free C/C++ library to import various 3D file formats into applications\n\n"
|
||||
|
||||
"(c) 2008-2017, assimp team\n"
|
||||
"(c) 2006-2019, assimp team\n"
|
||||
"License under the terms and conditions of the 3-clause BSD license\n"
|
||||
"http://assimp.sourceforge.net\n"
|
||||
"http://assimp.org\n"
|
||||
;
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@@ -70,13 +69,13 @@ ASSIMP_API const char* aiGetLegalString () {
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Get Assimp minor version
|
||||
ASSIMP_API unsigned int aiGetVersionMinor () {
|
||||
return MinorVersion;
|
||||
return VER_MINOR;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Get Assimp major version
|
||||
ASSIMP_API unsigned int aiGetVersionMajor () {
|
||||
return MajorVersion;
|
||||
return VER_MAJOR;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@@ -104,9 +103,6 @@ ASSIMP_API unsigned int aiGetCompileFlags () {
|
||||
return flags;
|
||||
}
|
||||
|
||||
// include current build revision, which is even updated from time to time -- :-)
|
||||
#include "revision.h"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
ASSIMP_API unsigned int aiGetVersionRevision() {
|
||||
return GitVersion;
|
||||
|
||||
@@ -44,23 +44,23 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
aiNode::aiNode()
|
||||
: mName("")
|
||||
, mParent(NULL)
|
||||
, mParent(nullptr)
|
||||
, mNumChildren(0)
|
||||
, mChildren(NULL)
|
||||
, mChildren(nullptr)
|
||||
, mNumMeshes(0)
|
||||
, mMeshes(NULL)
|
||||
, mMetaData(NULL) {
|
||||
, mMeshes(nullptr)
|
||||
, mMetaData(nullptr) {
|
||||
// empty
|
||||
}
|
||||
|
||||
aiNode::aiNode(const std::string& name)
|
||||
: mName(name)
|
||||
, mParent(NULL)
|
||||
, mParent(nullptr)
|
||||
, mNumChildren(0)
|
||||
, mChildren(NULL)
|
||||
, mChildren(nullptr)
|
||||
, mNumMeshes(0)
|
||||
, mMeshes(NULL)
|
||||
, mMetaData(NULL) {
|
||||
, mMeshes(nullptr)
|
||||
, mMetaData(nullptr) {
|
||||
// empty
|
||||
}
|
||||
|
||||
@@ -68,7 +68,7 @@ aiNode::aiNode(const std::string& name)
|
||||
aiNode::~aiNode() {
|
||||
// delete all children recursively
|
||||
// to make sure we won't crash if the data is invalid ...
|
||||
if (mChildren && mNumChildren)
|
||||
if (mNumChildren && mChildren)
|
||||
{
|
||||
for (unsigned int a = 0; a < mNumChildren; a++)
|
||||
delete mChildren[a];
|
||||
|
||||
@@ -50,9 +50,10 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
namespace Assimp {
|
||||
namespace FBX
|
||||
{
|
||||
const std::string NULL_RECORD = { // 13 null bytes
|
||||
'\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0'
|
||||
}; // who knows why
|
||||
const std::string NULL_RECORD = { // 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?)
|
||||
const std::string SEPARATOR = {'\x00', '\x01'}; // for use inside strings
|
||||
const std::string MAGIC_NODE_TAG = "_$AssimpFbx$"; // from import
|
||||
const int64_t SECOND = 46186158000; // FBX's kTime unit
|
||||
|
||||
@@ -47,6 +47,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#define INCLUDED_AI_FBX_COMPILECONFIG_H
|
||||
|
||||
#include <map>
|
||||
#include <set>
|
||||
|
||||
//
|
||||
#if _MSC_VER > 1500 || (defined __GNUC___)
|
||||
@@ -54,16 +55,23 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
# else
|
||||
# define fbx_unordered_map map
|
||||
# define fbx_unordered_multimap multimap
|
||||
# define fbx_unordered_set set
|
||||
# define fbx_unordered_multiset multiset
|
||||
#endif
|
||||
|
||||
#ifdef ASSIMP_FBX_USE_UNORDERED_MULTIMAP
|
||||
# include <unordered_map>
|
||||
# include <unordered_set>
|
||||
# if _MSC_VER > 1600
|
||||
# define fbx_unordered_map unordered_map
|
||||
# define fbx_unordered_multimap unordered_multimap
|
||||
# define fbx_unordered_set unordered_set
|
||||
# define fbx_unordered_multiset unordered_multiset
|
||||
# else
|
||||
# define fbx_unordered_map tr1::unordered_map
|
||||
# define fbx_unordered_multimap tr1::unordered_multimap
|
||||
# define fbx_unordered_set tr1::unordered_set
|
||||
# define fbx_unordered_multiset tr1::unordered_multiset
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
+226
-114
@@ -68,7 +68,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
#include <cstdint>
|
||||
|
||||
#include <iostream>
|
||||
#include <stdlib.h>
|
||||
|
||||
namespace Assimp {
|
||||
namespace FBX {
|
||||
@@ -77,7 +78,7 @@ namespace Assimp {
|
||||
|
||||
#define MAGIC_NODE_TAG "_$AssimpFbx$"
|
||||
|
||||
#define CONVERT_FBX_TIME(time) static_cast<double>(time) / 46186158000L
|
||||
#define CONVERT_FBX_TIME(time) static_cast<double>(time) / 46186158000LL
|
||||
|
||||
FBXConverter::FBXConverter(aiScene* out, const Document& doc, bool removeEmptyBones )
|
||||
: defaultMaterialIndex()
|
||||
@@ -96,6 +97,14 @@ namespace Assimp {
|
||||
// populate the node_anim_chain_bits map, which is needed
|
||||
// to determine which nodes need to be generated.
|
||||
ConvertAnimations();
|
||||
// Embedded textures in FBX could be connected to nothing but to itself,
|
||||
// for instance Texture -> Video connection only but not to the main graph,
|
||||
// The idea here is to traverse all objects to find these Textures and convert them,
|
||||
// so later during material conversion it will find converted texture in the textures_converted array.
|
||||
if (doc.Settings().readTextures)
|
||||
{
|
||||
ConvertOrphantEmbeddedTextures();
|
||||
}
|
||||
ConvertRootNode();
|
||||
|
||||
if (doc.Settings().readAllMaterials) {
|
||||
@@ -145,7 +154,7 @@ namespace Assimp {
|
||||
out->mRootNode->mName.Set(unique_name);
|
||||
|
||||
// root has ID 0
|
||||
ConvertNodes(0L, *out->mRootNode);
|
||||
ConvertNodes(0L, out->mRootNode, out->mRootNode);
|
||||
}
|
||||
|
||||
static std::string getAncestorBaseName(const aiNode* node)
|
||||
@@ -179,8 +188,11 @@ namespace Assimp {
|
||||
GetUniqueName(original_name, unique_name);
|
||||
return unique_name;
|
||||
}
|
||||
|
||||
void FBXConverter::ConvertNodes(uint64_t id, aiNode& parent, const aiMatrix4x4& parent_transform) {
|
||||
/// todo: pre-build node hierarchy
|
||||
/// todo: get bone from stack
|
||||
/// todo: make map of aiBone* to aiNode*
|
||||
/// then update convert clusters to the new format
|
||||
void FBXConverter::ConvertNodes(uint64_t id, aiNode *parent, aiNode *root_node) {
|
||||
const std::vector<const Connection*>& conns = doc.GetConnectionsByDestinationSequenced(id, "Model");
|
||||
|
||||
std::vector<aiNode*> nodes;
|
||||
@@ -191,62 +203,69 @@ namespace Assimp {
|
||||
|
||||
try {
|
||||
for (const Connection* con : conns) {
|
||||
|
||||
// ignore object-property links
|
||||
if (con->PropertyName().length()) {
|
||||
continue;
|
||||
// really important we document why this is ignored.
|
||||
FBXImporter::LogInfo("ignoring property link - no docs on why this is ignored");
|
||||
continue; //?
|
||||
}
|
||||
|
||||
// convert connection source object into Object base class
|
||||
const Object* const object = con->SourceObject();
|
||||
if (nullptr == object) {
|
||||
FBXImporter::LogWarn("failed to convert source object for Model link");
|
||||
FBXImporter::LogError("failed to convert source object for Model link");
|
||||
continue;
|
||||
}
|
||||
|
||||
// FBX Model::Cube, Model::Bone001, etc elements
|
||||
// This detects if we can cast the object into this model structure.
|
||||
const Model* const model = dynamic_cast<const Model*>(object);
|
||||
|
||||
if (nullptr != model) {
|
||||
nodes_chain.clear();
|
||||
post_nodes_chain.clear();
|
||||
|
||||
aiMatrix4x4 new_abs_transform = parent_transform;
|
||||
|
||||
std::string unique_name = MakeUniqueNodeName(model, parent);
|
||||
|
||||
aiMatrix4x4 new_abs_transform = parent->mTransformation;
|
||||
std::string node_name = FixNodeName(model->Name());
|
||||
// even though there is only a single input node, the design of
|
||||
// assimp (or rather: the complicated transformation chain that
|
||||
// is employed by fbx) means that we may need multiple aiNode's
|
||||
// to represent a fbx node's transformation.
|
||||
const bool need_additional_node = GenerateTransformationNodeChain(*model, unique_name, nodes_chain, post_nodes_chain);
|
||||
|
||||
|
||||
// generate node transforms - this includes pivot data
|
||||
// if need_additional_node is true then you t
|
||||
const bool need_additional_node = GenerateTransformationNodeChain(*model, node_name, nodes_chain, post_nodes_chain);
|
||||
|
||||
// assert that for the current node we must have at least a single transform
|
||||
ai_assert(nodes_chain.size());
|
||||
|
||||
if (need_additional_node) {
|
||||
nodes_chain.push_back(new aiNode(unique_name));
|
||||
nodes_chain.push_back(new aiNode(node_name));
|
||||
}
|
||||
|
||||
//setup metadata on newest node
|
||||
SetupNodeMetadata(*model, *nodes_chain.back());
|
||||
|
||||
// link all nodes in a row
|
||||
aiNode* last_parent = &parent;
|
||||
for (aiNode* prenode : nodes_chain) {
|
||||
ai_assert(prenode);
|
||||
aiNode* last_parent = parent;
|
||||
for (aiNode* child : nodes_chain) {
|
||||
ai_assert(child);
|
||||
|
||||
if (last_parent != &parent) {
|
||||
if (last_parent != parent) {
|
||||
last_parent->mNumChildren = 1;
|
||||
last_parent->mChildren = new aiNode*[1];
|
||||
last_parent->mChildren[0] = prenode;
|
||||
last_parent->mChildren[0] = child;
|
||||
}
|
||||
|
||||
prenode->mParent = last_parent;
|
||||
last_parent = prenode;
|
||||
child->mParent = last_parent;
|
||||
last_parent = child;
|
||||
|
||||
new_abs_transform *= prenode->mTransformation;
|
||||
new_abs_transform *= child->mTransformation;
|
||||
}
|
||||
|
||||
// attach geometry
|
||||
ConvertModel(*model, *nodes_chain.back(), new_abs_transform);
|
||||
ConvertModel(*model, nodes_chain.back(), root_node, new_abs_transform);
|
||||
|
||||
// check if there will be any child nodes
|
||||
const std::vector<const Connection*>& child_conns
|
||||
@@ -258,7 +277,7 @@ namespace Assimp {
|
||||
for (aiNode* postnode : post_nodes_chain) {
|
||||
ai_assert(postnode);
|
||||
|
||||
if (last_parent != &parent) {
|
||||
if (last_parent != parent) {
|
||||
last_parent->mNumChildren = 1;
|
||||
last_parent->mChildren = new aiNode*[1];
|
||||
last_parent->mChildren[0] = postnode;
|
||||
@@ -280,15 +299,15 @@ namespace Assimp {
|
||||
);
|
||||
}
|
||||
|
||||
// attach sub-nodes (if any)
|
||||
ConvertNodes(model->ID(), *last_parent, new_abs_transform);
|
||||
// recursion call - child nodes
|
||||
ConvertNodes(model->ID(), last_parent, root_node);
|
||||
|
||||
if (doc.Settings().readLights) {
|
||||
ConvertLights(*model, unique_name);
|
||||
ConvertLights(*model, node_name);
|
||||
}
|
||||
|
||||
if (doc.Settings().readCameras) {
|
||||
ConvertCameras(*model, unique_name);
|
||||
ConvertCameras(*model, node_name);
|
||||
}
|
||||
|
||||
nodes.push_back(nodes_chain.front());
|
||||
@@ -297,11 +316,17 @@ namespace Assimp {
|
||||
}
|
||||
|
||||
if (nodes.size()) {
|
||||
parent.mChildren = new aiNode*[nodes.size()]();
|
||||
parent.mNumChildren = static_cast<unsigned int>(nodes.size());
|
||||
parent->mChildren = new aiNode*[nodes.size()]();
|
||||
parent->mNumChildren = static_cast<unsigned int>(nodes.size());
|
||||
|
||||
std::swap_ranges(nodes.begin(), nodes.end(), parent.mChildren);
|
||||
std::swap_ranges(nodes.begin(), nodes.end(), parent->mChildren);
|
||||
}
|
||||
else
|
||||
{
|
||||
parent->mNumChildren = 0;
|
||||
parent->mChildren = nullptr;
|
||||
}
|
||||
|
||||
}
|
||||
catch (std::exception&) {
|
||||
Util::delete_fun<aiNode> deleter;
|
||||
@@ -803,7 +828,7 @@ namespace Assimp {
|
||||
// is_complex needs to be consistent with NeedsComplexTransformationChain()
|
||||
// or the interplay between this code and the animation converter would
|
||||
// not be guaranteed.
|
||||
ai_assert(NeedsComplexTransformationChain(model) == ((chainBits & chainMaskComplex) != 0));
|
||||
//ai_assert(NeedsComplexTransformationChain(model) == ((chainBits & chainMaskComplex) != 0));
|
||||
|
||||
// now, if we have more than just Translation, Scaling and Rotation,
|
||||
// we need to generate a full node chain to accommodate for assimp's
|
||||
@@ -905,7 +930,8 @@ namespace Assimp {
|
||||
}
|
||||
}
|
||||
|
||||
void FBXConverter::ConvertModel(const Model& model, aiNode& nd, const aiMatrix4x4& node_global_transform)
|
||||
void FBXConverter::ConvertModel(const Model &model, aiNode *parent, aiNode *root_node,
|
||||
const aiMatrix4x4 &absolute_transform)
|
||||
{
|
||||
const std::vector<const Geometry*>& geos = model.GetGeometry();
|
||||
|
||||
@@ -917,11 +943,12 @@ namespace Assimp {
|
||||
const MeshGeometry* const mesh = dynamic_cast<const MeshGeometry*>(geo);
|
||||
const LineGeometry* const line = dynamic_cast<const LineGeometry*>(geo);
|
||||
if (mesh) {
|
||||
const std::vector<unsigned int>& indices = ConvertMesh(*mesh, model, node_global_transform, nd);
|
||||
const std::vector<unsigned int>& indices = ConvertMesh(*mesh, model, parent, root_node,
|
||||
absolute_transform);
|
||||
std::copy(indices.begin(), indices.end(), std::back_inserter(meshes));
|
||||
}
|
||||
else if (line) {
|
||||
const std::vector<unsigned int>& indices = ConvertLine(*line, model, node_global_transform, nd);
|
||||
const std::vector<unsigned int>& indices = ConvertLine(*line, model, parent, root_node);
|
||||
std::copy(indices.begin(), indices.end(), std::back_inserter(meshes));
|
||||
}
|
||||
else {
|
||||
@@ -930,15 +957,16 @@ namespace Assimp {
|
||||
}
|
||||
|
||||
if (meshes.size()) {
|
||||
nd.mMeshes = new unsigned int[meshes.size()]();
|
||||
nd.mNumMeshes = static_cast<unsigned int>(meshes.size());
|
||||
parent->mMeshes = new unsigned int[meshes.size()]();
|
||||
parent->mNumMeshes = static_cast<unsigned int>(meshes.size());
|
||||
|
||||
std::swap_ranges(meshes.begin(), meshes.end(), nd.mMeshes);
|
||||
std::swap_ranges(meshes.begin(), meshes.end(), parent->mMeshes);
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<unsigned int> FBXConverter::ConvertMesh(const MeshGeometry& mesh, const Model& model,
|
||||
const aiMatrix4x4& node_global_transform, aiNode& nd)
|
||||
std::vector<unsigned int>
|
||||
FBXConverter::ConvertMesh(const MeshGeometry &mesh, const Model &model, aiNode *parent, aiNode *root_node,
|
||||
const aiMatrix4x4 &absolute_transform)
|
||||
{
|
||||
std::vector<unsigned int> temp;
|
||||
|
||||
@@ -962,18 +990,18 @@ namespace Assimp {
|
||||
const MatIndexArray::value_type base = mindices[0];
|
||||
for (MatIndexArray::value_type index : mindices) {
|
||||
if (index != base) {
|
||||
return ConvertMeshMultiMaterial(mesh, model, node_global_transform, nd);
|
||||
return ConvertMeshMultiMaterial(mesh, model, parent, root_node, absolute_transform);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// faster code-path, just copy the data
|
||||
temp.push_back(ConvertMeshSingleMaterial(mesh, model, node_global_transform, nd));
|
||||
temp.push_back(ConvertMeshSingleMaterial(mesh, model, absolute_transform, parent, root_node));
|
||||
return temp;
|
||||
}
|
||||
|
||||
std::vector<unsigned int> FBXConverter::ConvertLine(const LineGeometry& line, const Model& model,
|
||||
const aiMatrix4x4& node_global_transform, aiNode& nd)
|
||||
aiNode *parent, aiNode *root_node)
|
||||
{
|
||||
std::vector<unsigned int> temp;
|
||||
|
||||
@@ -984,7 +1012,7 @@ namespace Assimp {
|
||||
return temp;
|
||||
}
|
||||
|
||||
aiMesh* const out_mesh = SetupEmptyMesh(line, nd);
|
||||
aiMesh* const out_mesh = SetupEmptyMesh(line, root_node);
|
||||
out_mesh->mPrimitiveTypes |= aiPrimitiveType_LINE;
|
||||
|
||||
// copy vertices
|
||||
@@ -1019,7 +1047,7 @@ namespace Assimp {
|
||||
return temp;
|
||||
}
|
||||
|
||||
aiMesh* FBXConverter::SetupEmptyMesh(const Geometry& mesh, aiNode& nd)
|
||||
aiMesh* FBXConverter::SetupEmptyMesh(const Geometry& mesh, aiNode *parent)
|
||||
{
|
||||
aiMesh* const out_mesh = new aiMesh();
|
||||
meshes.push_back(out_mesh);
|
||||
@@ -1036,17 +1064,18 @@ namespace Assimp {
|
||||
}
|
||||
else
|
||||
{
|
||||
out_mesh->mName = nd.mName;
|
||||
out_mesh->mName = parent->mName;
|
||||
}
|
||||
|
||||
return out_mesh;
|
||||
}
|
||||
|
||||
unsigned int FBXConverter::ConvertMeshSingleMaterial(const MeshGeometry& mesh, const Model& model,
|
||||
const aiMatrix4x4& node_global_transform, aiNode& nd)
|
||||
unsigned int FBXConverter::ConvertMeshSingleMaterial(const MeshGeometry &mesh, const Model &model,
|
||||
const aiMatrix4x4 &absolute_transform, aiNode *parent,
|
||||
aiNode *root_node)
|
||||
{
|
||||
const MatIndexArray& mindices = mesh.GetMaterialIndices();
|
||||
aiMesh* const out_mesh = SetupEmptyMesh(mesh, nd);
|
||||
aiMesh* const out_mesh = SetupEmptyMesh(mesh, parent);
|
||||
|
||||
const std::vector<aiVector3D>& vertices = mesh.GetVertices();
|
||||
const std::vector<unsigned int>& faces = mesh.GetFaceIndexCounts();
|
||||
@@ -1113,7 +1142,7 @@ namespace Assimp {
|
||||
binormals = &tempBinormals;
|
||||
}
|
||||
else {
|
||||
binormals = NULL;
|
||||
binormals = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1163,8 +1192,9 @@ namespace Assimp {
|
||||
ConvertMaterialForMesh(out_mesh, model, mesh, mindices[0]);
|
||||
}
|
||||
|
||||
if (doc.Settings().readWeights && mesh.DeformerSkin() != NULL) {
|
||||
ConvertWeights(out_mesh, model, mesh, node_global_transform, NO_MATERIAL_SEPARATION);
|
||||
if (doc.Settings().readWeights && mesh.DeformerSkin() != nullptr) {
|
||||
ConvertWeights(out_mesh, model, mesh, absolute_transform, parent, root_node, NO_MATERIAL_SEPARATION,
|
||||
nullptr);
|
||||
}
|
||||
|
||||
std::vector<aiAnimMesh*> animMeshes;
|
||||
@@ -1209,8 +1239,10 @@ namespace Assimp {
|
||||
return static_cast<unsigned int>(meshes.size() - 1);
|
||||
}
|
||||
|
||||
std::vector<unsigned int> FBXConverter::ConvertMeshMultiMaterial(const MeshGeometry& mesh, const Model& model,
|
||||
const aiMatrix4x4& node_global_transform, aiNode& nd)
|
||||
std::vector<unsigned int>
|
||||
FBXConverter::ConvertMeshMultiMaterial(const MeshGeometry &mesh, const Model &model, aiNode *parent,
|
||||
aiNode *root_node,
|
||||
const aiMatrix4x4 &absolute_transform)
|
||||
{
|
||||
const MatIndexArray& mindices = mesh.GetMaterialIndices();
|
||||
ai_assert(mindices.size());
|
||||
@@ -1221,7 +1253,7 @@ namespace Assimp {
|
||||
for (MatIndexArray::value_type index : mindices) {
|
||||
if (had.find(index) == had.end()) {
|
||||
|
||||
indices.push_back(ConvertMeshMultiMaterial(mesh, model, index, node_global_transform, nd));
|
||||
indices.push_back(ConvertMeshMultiMaterial(mesh, model, index, parent, root_node, absolute_transform));
|
||||
had.insert(index);
|
||||
}
|
||||
}
|
||||
@@ -1229,18 +1261,18 @@ namespace Assimp {
|
||||
return indices;
|
||||
}
|
||||
|
||||
unsigned int FBXConverter::ConvertMeshMultiMaterial(const MeshGeometry& mesh, const Model& model,
|
||||
MatIndexArray::value_type index,
|
||||
const aiMatrix4x4& node_global_transform,
|
||||
aiNode& nd)
|
||||
unsigned int FBXConverter::ConvertMeshMultiMaterial(const MeshGeometry &mesh, const Model &model,
|
||||
MatIndexArray::value_type index,
|
||||
aiNode *parent, aiNode *root_node,
|
||||
const aiMatrix4x4 &absolute_transform)
|
||||
{
|
||||
aiMesh* const out_mesh = SetupEmptyMesh(mesh, nd);
|
||||
aiMesh* const out_mesh = SetupEmptyMesh(mesh, parent);
|
||||
|
||||
const MatIndexArray& mindices = mesh.GetMaterialIndices();
|
||||
const std::vector<aiVector3D>& vertices = mesh.GetVertices();
|
||||
const std::vector<unsigned int>& faces = mesh.GetFaceIndexCounts();
|
||||
|
||||
const bool process_weights = doc.Settings().readWeights && mesh.DeformerSkin() != NULL;
|
||||
const bool process_weights = doc.Settings().readWeights && mesh.DeformerSkin() != nullptr;
|
||||
|
||||
unsigned int count_faces = 0;
|
||||
unsigned int count_vertices = 0;
|
||||
@@ -1300,7 +1332,7 @@ namespace Assimp {
|
||||
binormals = &tempBinormals;
|
||||
}
|
||||
else {
|
||||
binormals = NULL;
|
||||
binormals = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1399,7 +1431,7 @@ namespace Assimp {
|
||||
ConvertMaterialForMesh(out_mesh, model, mesh, index);
|
||||
|
||||
if (process_weights) {
|
||||
ConvertWeights(out_mesh, model, mesh, node_global_transform, index, &reverseMapping);
|
||||
ConvertWeights(out_mesh, model, mesh, absolute_transform, parent, root_node, index, &reverseMapping);
|
||||
}
|
||||
|
||||
std::vector<aiAnimMesh*> animMeshes;
|
||||
@@ -1449,10 +1481,10 @@ namespace Assimp {
|
||||
return static_cast<unsigned int>(meshes.size() - 1);
|
||||
}
|
||||
|
||||
void FBXConverter::ConvertWeights(aiMesh* out, const Model& model, const MeshGeometry& geo,
|
||||
const aiMatrix4x4& node_global_transform,
|
||||
unsigned int materialIndex,
|
||||
std::vector<unsigned int>* outputVertStartIndices)
|
||||
void FBXConverter::ConvertWeights(aiMesh *out, const Model &model, const MeshGeometry &geo,
|
||||
const aiMatrix4x4 &absolute_transform,
|
||||
aiNode *parent, aiNode *root_node, unsigned int materialIndex,
|
||||
std::vector<unsigned int> *outputVertStartIndices)
|
||||
{
|
||||
ai_assert(geo.DeformerSkin());
|
||||
|
||||
@@ -1463,13 +1495,12 @@ namespace Assimp {
|
||||
const Skin& sk = *geo.DeformerSkin();
|
||||
|
||||
std::vector<aiBone*> bones;
|
||||
bones.reserve(sk.Clusters().size());
|
||||
|
||||
const bool no_mat_check = materialIndex == NO_MATERIAL_SEPARATION;
|
||||
ai_assert(no_mat_check || outputVertStartIndices);
|
||||
|
||||
try {
|
||||
|
||||
// iterate over the sub deformers
|
||||
for (const Cluster* cluster : sk.Clusters()) {
|
||||
ai_assert(cluster);
|
||||
|
||||
@@ -1483,15 +1514,16 @@ namespace Assimp {
|
||||
index_out_indices.clear();
|
||||
out_indices.clear();
|
||||
|
||||
|
||||
// now check if *any* of these weights is contained in the output mesh,
|
||||
// taking notes so we don't need to do it twice.
|
||||
for (WeightIndexArray::value_type index : indices) {
|
||||
|
||||
unsigned int count = 0;
|
||||
const unsigned int* const out_idx = geo.ToOutputVertexIndex(index, count);
|
||||
// ToOutputVertexIndex only returns NULL if index is out of bounds
|
||||
// ToOutputVertexIndex only returns nullptr if index is out of bounds
|
||||
// which should never happen
|
||||
ai_assert(out_idx != NULL);
|
||||
ai_assert(out_idx != nullptr);
|
||||
|
||||
index_out_indices.push_back(no_index_sentinel);
|
||||
count_out_indices.push_back(0);
|
||||
@@ -1520,68 +1552,107 @@ namespace Assimp {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// if we found at least one, generate the output bones
|
||||
// XXX this could be heavily simplified by collecting the bone
|
||||
// data in a single step.
|
||||
ConvertCluster(bones, model, *cluster, out_indices, index_out_indices,
|
||||
count_out_indices, node_global_transform);
|
||||
ConvertCluster(bones, cluster, out_indices, index_out_indices,
|
||||
count_out_indices, absolute_transform, parent, root_node);
|
||||
}
|
||||
|
||||
bone_map.clear();
|
||||
}
|
||||
catch (std::exception&) {
|
||||
catch (std::exception&e) {
|
||||
std::for_each(bones.begin(), bones.end(), Util::delete_fun<aiBone>());
|
||||
throw;
|
||||
}
|
||||
|
||||
if (bones.empty()) {
|
||||
out->mBones = nullptr;
|
||||
out->mNumBones = 0;
|
||||
return;
|
||||
} else {
|
||||
out->mBones = new aiBone *[bones.size()]();
|
||||
out->mNumBones = static_cast<unsigned int>(bones.size());
|
||||
|
||||
std::swap_ranges(bones.begin(), bones.end(), out->mBones);
|
||||
}
|
||||
|
||||
out->mBones = new aiBone*[bones.size()]();
|
||||
out->mNumBones = static_cast<unsigned int>(bones.size());
|
||||
|
||||
std::swap_ranges(bones.begin(), bones.end(), out->mBones);
|
||||
}
|
||||
|
||||
void FBXConverter::ConvertCluster(std::vector<aiBone*>& bones, const Model& /*model*/, const Cluster& cl,
|
||||
std::vector<size_t>& out_indices,
|
||||
std::vector<size_t>& index_out_indices,
|
||||
std::vector<size_t>& count_out_indices,
|
||||
const aiMatrix4x4& node_global_transform)
|
||||
const aiNode* FBXConverter::GetNodeByName( const aiString& name, aiNode *current_node )
|
||||
{
|
||||
aiNode * iter = current_node;
|
||||
//printf("Child count: %d", iter->mNumChildren);
|
||||
return iter;
|
||||
}
|
||||
|
||||
aiBone* const bone = new aiBone();
|
||||
bones.push_back(bone);
|
||||
void FBXConverter::ConvertCluster(std::vector<aiBone *> &local_mesh_bones, const Cluster *cl,
|
||||
std::vector<size_t> &out_indices, std::vector<size_t> &index_out_indices,
|
||||
std::vector<size_t> &count_out_indices, const aiMatrix4x4 &absolute_transform,
|
||||
aiNode *parent, aiNode *root_node) {
|
||||
ai_assert(cl); // make sure cluster valid
|
||||
std::string deformer_name = cl->TargetNode()->Name();
|
||||
aiString bone_name = aiString(FixNodeName(deformer_name));
|
||||
|
||||
bone->mName = FixNodeName(cl.TargetNode()->Name());
|
||||
aiBone *bone = nullptr;
|
||||
|
||||
bone->mOffsetMatrix = cl.TransformLink();
|
||||
bone->mOffsetMatrix.Inverse();
|
||||
if (bone_map.count(deformer_name)) {
|
||||
std::cout << "retrieved bone from lookup " << bone_name.C_Str() << ". Deformer: " << deformer_name
|
||||
<< std::endl;
|
||||
bone = bone_map[deformer_name];
|
||||
} else {
|
||||
std::cout << "created new bone " << bone_name.C_Str() << ". Deformer: " << deformer_name << std::endl;
|
||||
bone = new aiBone();
|
||||
bone->mName = bone_name;
|
||||
|
||||
bone->mOffsetMatrix = bone->mOffsetMatrix * node_global_transform;
|
||||
// store local transform link for post processing
|
||||
bone->mOffsetMatrix = cl->TransformLink();
|
||||
bone->mOffsetMatrix.Inverse();
|
||||
|
||||
bone->mNumWeights = static_cast<unsigned int>(out_indices.size());
|
||||
aiVertexWeight* cursor = bone->mWeights = new aiVertexWeight[out_indices.size()];
|
||||
aiMatrix4x4 matrix = (aiMatrix4x4)absolute_transform;
|
||||
|
||||
const size_t no_index_sentinel = std::numeric_limits<size_t>::max();
|
||||
const WeightArray& weights = cl.GetWeights();
|
||||
bone->mOffsetMatrix = bone->mOffsetMatrix * matrix; // * mesh_offset
|
||||
|
||||
const size_t c = index_out_indices.size();
|
||||
for (size_t i = 0; i < c; ++i) {
|
||||
const size_t index_index = index_out_indices[i];
|
||||
|
||||
if (index_index == no_index_sentinel) {
|
||||
continue;
|
||||
//
|
||||
// Now calculate the aiVertexWeights
|
||||
//
|
||||
|
||||
aiVertexWeight *cursor = nullptr;
|
||||
|
||||
bone->mNumWeights = static_cast<unsigned int>(out_indices.size());
|
||||
cursor = bone->mWeights = new aiVertexWeight[out_indices.size()];
|
||||
|
||||
const size_t no_index_sentinel = std::numeric_limits<size_t>::max();
|
||||
const WeightArray& weights = cl->GetWeights();
|
||||
|
||||
const size_t c = index_out_indices.size();
|
||||
for (size_t i = 0; i < c; ++i) {
|
||||
const size_t index_index = index_out_indices[i];
|
||||
|
||||
if (index_index == no_index_sentinel) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const size_t cc = count_out_indices[i];
|
||||
for (size_t j = 0; j < cc; ++j) {
|
||||
// cursor runs from first element relative to the start
|
||||
// or relative to the start of the next indexes.
|
||||
aiVertexWeight& out_weight = *cursor++;
|
||||
|
||||
out_weight.mVertexId = static_cast<unsigned int>(out_indices[index_index + j]);
|
||||
out_weight.mWeight = weights[i];
|
||||
}
|
||||
}
|
||||
|
||||
const size_t cc = count_out_indices[i];
|
||||
for (size_t j = 0; j < cc; ++j) {
|
||||
aiVertexWeight& out_weight = *cursor++;
|
||||
|
||||
out_weight.mVertexId = static_cast<unsigned int>(out_indices[index_index + j]);
|
||||
out_weight.mWeight = weights[i];
|
||||
}
|
||||
bone_map.insert(std::pair<const std::string, aiBone *>(deformer_name, bone));
|
||||
}
|
||||
|
||||
std::cout << "bone research: Indicies size: " << out_indices.size() << std::endl;
|
||||
|
||||
// lookup must be populated in case something goes wrong
|
||||
// this also allocates bones to mesh instance outside
|
||||
local_mesh_bones.push_back(bone);
|
||||
}
|
||||
|
||||
void FBXConverter::ConvertMaterialForMesh(aiMesh* out, const Model& model, const MeshGeometry& geo,
|
||||
@@ -1711,7 +1782,7 @@ namespace Assimp {
|
||||
bool textureReady = false; //tells if our texture is ready (if it was loaded or if it was found)
|
||||
unsigned int index;
|
||||
|
||||
VideoMap::const_iterator it = textures_converted.find(media);
|
||||
VideoMap::const_iterator it = textures_converted.find(*media);
|
||||
if (it != textures_converted.end()) {
|
||||
index = (*it).second;
|
||||
textureReady = true;
|
||||
@@ -1719,7 +1790,7 @@ namespace Assimp {
|
||||
else {
|
||||
if (media->ContentLength() > 0) {
|
||||
index = ConvertVideo(*media);
|
||||
textures_converted[media] = index;
|
||||
textures_converted[*media] = index;
|
||||
textureReady = true;
|
||||
}
|
||||
}
|
||||
@@ -2243,13 +2314,13 @@ void FBXConverter::SetShadingPropertiesRaw(aiMaterial* out_mat, const PropertyTa
|
||||
if (media != nullptr && media->ContentLength() > 0) {
|
||||
unsigned int index;
|
||||
|
||||
VideoMap::const_iterator it = textures_converted.find(media);
|
||||
VideoMap::const_iterator it = textures_converted.find(*media);
|
||||
if (it != textures_converted.end()) {
|
||||
index = (*it).second;
|
||||
}
|
||||
else {
|
||||
index = ConvertVideo(*media);
|
||||
textures_converted[media] = index;
|
||||
textures_converted[*media] = index;
|
||||
}
|
||||
|
||||
// setup texture reference string (copied from ColladaLoader::FindFilenameForEffectTexture)
|
||||
@@ -2677,7 +2748,7 @@ void FBXConverter::SetShadingPropertiesRaw(aiMaterial* out_mat, const PropertyTa
|
||||
// sanity check whether the input is ok
|
||||
static void validateAnimCurveNodes(const std::vector<const AnimationCurveNode*>& curves,
|
||||
bool strictMode) {
|
||||
const Object* target(NULL);
|
||||
const Object* target(nullptr);
|
||||
for (const AnimationCurveNode* node : curves) {
|
||||
if (!target) {
|
||||
target = node->Target();
|
||||
@@ -2708,7 +2779,7 @@ void FBXConverter::SetShadingPropertiesRaw(aiMaterial* out_mat, const PropertyTa
|
||||
#ifdef ASSIMP_BUILD_DEBUG
|
||||
validateAnimCurveNodes(curves, doc.Settings().strictMode);
|
||||
#endif
|
||||
const AnimationCurveNode* curve_node = NULL;
|
||||
const AnimationCurveNode* curve_node = nullptr;
|
||||
for (const AnimationCurveNode* node : curves) {
|
||||
ai_assert(node);
|
||||
|
||||
@@ -3556,7 +3627,7 @@ void FBXConverter::SetShadingPropertiesRaw(aiMaterial* out_mat, const PropertyTa
|
||||
ai_assert(!out->mMeshes);
|
||||
ai_assert(!out->mNumMeshes);
|
||||
|
||||
// note: the trailing () ensures initialization with NULL - not
|
||||
// note: the trailing () ensures initialization with nullptr - not
|
||||
// many C++ users seem to know this, so pointing it out to avoid
|
||||
// confusion why this code works.
|
||||
|
||||
@@ -3603,6 +3674,47 @@ void FBXConverter::SetShadingPropertiesRaw(aiMaterial* out_mat, const PropertyTa
|
||||
}
|
||||
}
|
||||
|
||||
void FBXConverter::ConvertOrphantEmbeddedTextures()
|
||||
{
|
||||
// in C++14 it could be:
|
||||
// for (auto&& [id, object] : objects)
|
||||
for (auto&& id_and_object : doc.Objects())
|
||||
{
|
||||
auto&& id = std::get<0>(id_and_object);
|
||||
auto&& object = std::get<1>(id_and_object);
|
||||
// If an object doesn't have parent
|
||||
if (doc.ConnectionsBySource().count(id) == 0)
|
||||
{
|
||||
const Texture* realTexture = nullptr;
|
||||
try
|
||||
{
|
||||
const auto& element = object->GetElement();
|
||||
const Token& key = element.KeyToken();
|
||||
const char* obtype = key.begin();
|
||||
const size_t length = static_cast<size_t>(key.end() - key.begin());
|
||||
if (strncmp(obtype, "Texture", length) == 0)
|
||||
{
|
||||
const Texture* texture = static_cast<const Texture*>(object->Get());
|
||||
if (texture->Media() && texture->Media()->ContentLength() > 0)
|
||||
{
|
||||
realTexture = texture;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
if (realTexture)
|
||||
{
|
||||
const Video* media = realTexture->Media();
|
||||
unsigned int index = ConvertVideo(*media);
|
||||
textures_converted[*media] = index;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void ConvertToAssimpScene(aiScene* out, const Document& doc, bool removeEmptyBones)
|
||||
{
|
||||
|
||||
+55
-28
@@ -123,7 +123,7 @@ private:
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// collect and assign child nodes
|
||||
void ConvertNodes(uint64_t id, aiNode& parent, const aiMatrix4x4& parent_transform = aiMatrix4x4());
|
||||
void ConvertNodes(uint64_t id, aiNode *parent, aiNode *root_node);
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void ConvertLights(const Model& model, const std::string &orig_name );
|
||||
@@ -179,32 +179,35 @@ private:
|
||||
void SetupNodeMetadata(const Model& model, aiNode& nd);
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void ConvertModel(const Model& model, aiNode& nd, const aiMatrix4x4& node_global_transform);
|
||||
void ConvertModel(const Model &model, aiNode *parent, aiNode *root_node,
|
||||
const aiMatrix4x4 &absolute_transform);
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// MeshGeometry -> aiMesh, return mesh index + 1 or 0 if the conversion failed
|
||||
std::vector<unsigned int> ConvertMesh(const MeshGeometry& mesh, const Model& model,
|
||||
const aiMatrix4x4& node_global_transform, aiNode& nd);
|
||||
std::vector<unsigned int>
|
||||
ConvertMesh(const MeshGeometry &mesh, const Model &model, aiNode *parent, aiNode *root_node,
|
||||
const aiMatrix4x4 &absolute_transform);
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
std::vector<unsigned int> ConvertLine(const LineGeometry& line, const Model& model,
|
||||
const aiMatrix4x4& node_global_transform, aiNode& nd);
|
||||
aiNode *parent, aiNode *root_node);
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
aiMesh* SetupEmptyMesh(const Geometry& mesh, aiNode& nd);
|
||||
aiMesh* SetupEmptyMesh(const Geometry& mesh, aiNode *parent);
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
unsigned int ConvertMeshSingleMaterial(const MeshGeometry& mesh, const Model& model,
|
||||
const aiMatrix4x4& node_global_transform, aiNode& nd);
|
||||
unsigned int ConvertMeshSingleMaterial(const MeshGeometry &mesh, const Model &model,
|
||||
const aiMatrix4x4 &absolute_transform, aiNode *parent,
|
||||
aiNode *root_node);
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
std::vector<unsigned int> ConvertMeshMultiMaterial(const MeshGeometry& mesh, const Model& model,
|
||||
const aiMatrix4x4& node_global_transform, aiNode& nd);
|
||||
std::vector<unsigned int>
|
||||
ConvertMeshMultiMaterial(const MeshGeometry &mesh, const Model &model, aiNode *parent, aiNode *root_node,
|
||||
const aiMatrix4x4 &absolute_transform);
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
unsigned int ConvertMeshMultiMaterial(const MeshGeometry& mesh, const Model& model,
|
||||
MatIndexArray::value_type index,
|
||||
const aiMatrix4x4& node_global_transform, aiNode& nd);
|
||||
unsigned int ConvertMeshMultiMaterial(const MeshGeometry &mesh, const Model &model, MatIndexArray::value_type index,
|
||||
aiNode *parent, aiNode *root_node, const aiMatrix4x4 &absolute_transform);
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
static const unsigned int NO_MATERIAL_SEPARATION = /* std::numeric_limits<unsigned int>::max() */
|
||||
@@ -217,17 +220,17 @@ private:
|
||||
* - outputVertStartIndices is only used when a material index is specified, it gives for
|
||||
* each output vertex the DOM index it maps to.
|
||||
*/
|
||||
void ConvertWeights(aiMesh* out, const Model& model, const MeshGeometry& geo,
|
||||
const aiMatrix4x4& node_global_transform = aiMatrix4x4(),
|
||||
unsigned int materialIndex = NO_MATERIAL_SEPARATION,
|
||||
std::vector<unsigned int>* outputVertStartIndices = NULL);
|
||||
|
||||
void ConvertWeights(aiMesh *out, const Model &model, const MeshGeometry &geo, const aiMatrix4x4 &absolute_transform,
|
||||
aiNode *parent = NULL, aiNode *root_node = NULL,
|
||||
unsigned int materialIndex = NO_MATERIAL_SEPARATION,
|
||||
std::vector<unsigned int> *outputVertStartIndices = NULL);
|
||||
// lookup
|
||||
static const aiNode* GetNodeByName( const aiString& name, aiNode *current_node );
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void ConvertCluster(std::vector<aiBone*>& bones, const Model& /*model*/, const Cluster& cl,
|
||||
std::vector<size_t>& out_indices,
|
||||
std::vector<size_t>& index_out_indices,
|
||||
std::vector<size_t>& count_out_indices,
|
||||
const aiMatrix4x4& node_global_transform);
|
||||
void ConvertCluster(std::vector<aiBone *> &local_mesh_bones, const Cluster *cl,
|
||||
std::vector<size_t> &out_indices, std::vector<size_t> &index_out_indices,
|
||||
std::vector<size_t> &count_out_indices, const aiMatrix4x4 &absolute_transform,
|
||||
aiNode *parent, aiNode *root_node);
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void ConvertMaterialForMesh(aiMesh* out, const Model& model, const MeshGeometry& geo,
|
||||
@@ -424,6 +427,10 @@ private:
|
||||
// copy generated meshes, animations, lights, cameras and textures to the output scene
|
||||
void TransferDataToScene();
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// FBX file could have embedded textures not connected to anything
|
||||
void ConvertOrphantEmbeddedTextures();
|
||||
|
||||
private:
|
||||
// 0: not assigned yet, others: index is value - 1
|
||||
unsigned int defaultMaterialIndex;
|
||||
@@ -435,27 +442,47 @@ private:
|
||||
std::vector<aiCamera*> cameras;
|
||||
std::vector<aiTexture*> textures;
|
||||
|
||||
using MaterialMap = std::map<const Material*, unsigned int>;
|
||||
using MaterialMap = std::fbx_unordered_map<const Material*, unsigned int>;
|
||||
MaterialMap materials_converted;
|
||||
|
||||
using VideoMap = std::map<const Video*, unsigned int>;
|
||||
using VideoMap = std::fbx_unordered_map<const Video, unsigned int>;
|
||||
VideoMap textures_converted;
|
||||
|
||||
using MeshMap = std::map<const Geometry*, std::vector<unsigned int> >;
|
||||
using MeshMap = std::fbx_unordered_map<const Geometry*, std::vector<unsigned int> >;
|
||||
MeshMap meshes_converted;
|
||||
|
||||
// fixed node name -> which trafo chain components have animations?
|
||||
using NodeAnimBitMap = std::map<std::string, unsigned int> ;
|
||||
using NodeAnimBitMap = std::fbx_unordered_map<std::string, unsigned int> ;
|
||||
NodeAnimBitMap node_anim_chain_bits;
|
||||
|
||||
// number of nodes with the same name
|
||||
using NodeNameCache = std::unordered_map<std::string, unsigned int>;
|
||||
using NodeNameCache = std::fbx_unordered_map<std::string, unsigned int>;
|
||||
NodeNameCache mNodeNames;
|
||||
|
||||
// Deformer name is not the same as a bone name - it does contain the bone name though :)
|
||||
// Deformer names in FBX are always unique in an FBX file.
|
||||
std::map<const std::string, aiBone *> bone_map;
|
||||
|
||||
double anim_fps;
|
||||
|
||||
aiScene* const out;
|
||||
const FBX::Document& doc;
|
||||
|
||||
static void BuildBoneList(aiNode *current_node, const aiNode *root_node, const aiScene *scene,
|
||||
std::vector<aiBone*>& bones);
|
||||
|
||||
void BuildBoneStack(aiNode *current_node, const aiNode *root_node, const aiScene *scene,
|
||||
const std::vector<aiBone *> &bones,
|
||||
std::map<aiBone *, aiNode *> &bone_stack,
|
||||
std::vector<aiNode*> &node_stack );
|
||||
|
||||
static void BuildNodeList(aiNode *current_node, std::vector<aiNode *> &nodes);
|
||||
|
||||
static aiNode *GetNodeFromStack(const aiString &node_name, std::vector<aiNode *> &nodes);
|
||||
|
||||
static aiNode *GetArmatureRoot(aiNode *bone_node, std::vector<aiBone*> &bone_list);
|
||||
|
||||
static bool IsBoneNode(const aiString &bone_name, std::vector<aiBone *> &bones);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
+37
-2
@@ -637,6 +637,20 @@ public:
|
||||
return ptr;
|
||||
}
|
||||
|
||||
bool operator==(const Video& other) const
|
||||
{
|
||||
return (
|
||||
type == other.type
|
||||
&& relativeFileName == other.relativeFileName
|
||||
&& fileName == other.fileName
|
||||
);
|
||||
}
|
||||
|
||||
bool operator<(const Video& other) const
|
||||
{
|
||||
return std::tie(type, relativeFileName, fileName) < std::tie(other.type, other.relativeFileName, other.fileName);
|
||||
}
|
||||
|
||||
private:
|
||||
std::string type;
|
||||
std::string relativeFileName;
|
||||
@@ -1005,10 +1019,10 @@ public:
|
||||
// during their entire lifetime (Document). FBX files have
|
||||
// up to many thousands of objects (most of which we never use),
|
||||
// so the memory overhead for them should be kept at a minimum.
|
||||
typedef std::map<uint64_t, LazyObject*> ObjectMap;
|
||||
typedef std::fbx_unordered_map<uint64_t, LazyObject*> ObjectMap;
|
||||
typedef std::fbx_unordered_map<std::string, std::shared_ptr<const PropertyTable> > PropertyTemplateMap;
|
||||
|
||||
typedef std::multimap<uint64_t, const Connection*> ConnectionMap;
|
||||
typedef std::fbx_unordered_multimap<uint64_t, const Connection*> ConnectionMap;
|
||||
|
||||
/** DOM class for global document settings, a single instance per document can
|
||||
* be accessed via Document.Globals(). */
|
||||
@@ -1177,4 +1191,25 @@ private:
|
||||
} // Namespace FBX
|
||||
} // Namespace Assimp
|
||||
|
||||
namespace std
|
||||
{
|
||||
template <>
|
||||
struct hash<const Assimp::FBX::Video>
|
||||
{
|
||||
std::size_t operator()(const Assimp::FBX::Video& video) const
|
||||
{
|
||||
using std::size_t;
|
||||
using std::hash;
|
||||
using std::string;
|
||||
|
||||
size_t res = 17;
|
||||
res = res * 31 + hash<string>()(video.Name());
|
||||
res = res * 31 + hash<string>()(video.RelativeFilename());
|
||||
res = res * 31 + hash<string>()(video.Type());
|
||||
|
||||
return res;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#endif // INCLUDED_AI_FBX_DOCUMENT_H
|
||||
|
||||
@@ -325,9 +325,9 @@ void FBX::Node::BeginBinary(Assimp::StreamWriterLE &s)
|
||||
this->start_pos = s.Tell();
|
||||
|
||||
// placeholders for end pos and property section info
|
||||
s.PutU4(0); // end pos
|
||||
s.PutU4(0); // number of properties
|
||||
s.PutU4(0); // total property section length
|
||||
s.PutU8(0); // end pos
|
||||
s.PutU8(0); // number of properties
|
||||
s.PutU8(0); // total property section length
|
||||
|
||||
// node name
|
||||
s.PutU1(uint8_t(name.size())); // length of node name
|
||||
@@ -352,9 +352,9 @@ void FBX::Node::EndPropertiesBinary(
|
||||
size_t pos = s.Tell();
|
||||
ai_assert(pos > property_start);
|
||||
size_t property_section_size = pos - property_start;
|
||||
s.Seek(start_pos + 4);
|
||||
s.PutU4(uint32_t(num_properties));
|
||||
s.PutU4(uint32_t(property_section_size));
|
||||
s.Seek(start_pos + 8); // 8 bytes of uint64_t of end_pos
|
||||
s.PutU8(num_properties);
|
||||
s.PutU8(property_section_size);
|
||||
s.Seek(pos);
|
||||
}
|
||||
|
||||
@@ -375,7 +375,7 @@ void FBX::Node::EndBinary(
|
||||
// now go back and write initial pos
|
||||
this->end_pos = s.Tell();
|
||||
s.Seek(start_pos);
|
||||
s.PutU4(uint32_t(end_pos));
|
||||
s.PutU8(end_pos);
|
||||
s.Seek(end_pos);
|
||||
}
|
||||
|
||||
|
||||
@@ -81,8 +81,8 @@ using namespace Assimp::FBX;
|
||||
// some constants that we'll use for writing metadata
|
||||
namespace Assimp {
|
||||
namespace FBX {
|
||||
const std::string EXPORT_VERSION_STR = "7.4.0";
|
||||
const uint32_t EXPORT_VERSION_INT = 7400; // 7.4 == 2014/2015
|
||||
const std::string EXPORT_VERSION_STR = "7.5.0";
|
||||
const uint32_t EXPORT_VERSION_INT = 7500; // 7.5 == 2016+
|
||||
// FBX files have some hashed values that depend on the creation time field,
|
||||
// but for now we don't actually know how to generate these.
|
||||
// what we can do is set them to a known-working version.
|
||||
@@ -1289,7 +1289,7 @@ void FBXExporter::WriteObjects ()
|
||||
|
||||
for(unsigned int lr = 1; lr < m->GetNumUVChannels(); ++ lr)
|
||||
{
|
||||
FBX::Node layerExtra("Layer", int32_t(1));
|
||||
FBX::Node layerExtra("Layer", int32_t(lr));
|
||||
layerExtra.AddChild("Version", int32_t(100));
|
||||
FBX::Node leExtra("LayerElement");
|
||||
leExtra.AddChild("Type", "LayerElementUV");
|
||||
|
||||
+93
-101
@@ -48,26 +48,26 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#include "FBXImporter.h"
|
||||
|
||||
#include "FBXTokenizer.h"
|
||||
#include "FBXParser.h"
|
||||
#include "FBXUtil.h"
|
||||
#include "FBXDocument.h"
|
||||
#include "FBXConverter.h"
|
||||
#include "FBXDocument.h"
|
||||
#include "FBXParser.h"
|
||||
#include "FBXTokenizer.h"
|
||||
#include "FBXUtil.h"
|
||||
|
||||
#include <assimp/StreamReader.h>
|
||||
#include <assimp/MemoryIOWrapper.h>
|
||||
#include <assimp/Importer.hpp>
|
||||
#include <assimp/StreamReader.h>
|
||||
#include <assimp/importerdesc.h>
|
||||
#include <assimp/Importer.hpp>
|
||||
|
||||
namespace Assimp {
|
||||
|
||||
template<>
|
||||
const char* LogFunctions<FBXImporter>::Prefix() {
|
||||
static auto prefix = "FBX: ";
|
||||
return prefix;
|
||||
template <>
|
||||
const char *LogFunctions<FBXImporter>::Prefix() {
|
||||
static auto prefix = "FBX: ";
|
||||
return prefix;
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace Assimp
|
||||
|
||||
using namespace Assimp;
|
||||
using namespace Assimp::Formatter;
|
||||
@@ -76,131 +76,123 @@ using namespace Assimp::FBX;
|
||||
namespace {
|
||||
|
||||
static const aiImporterDesc desc = {
|
||||
"Autodesk FBX Importer",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
aiImporterFlags_SupportTextFlavour,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
"fbx"
|
||||
"Autodesk FBX Importer",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
aiImporterFlags_SupportTextFlavour,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
"fbx"
|
||||
};
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Constructor to be privately used by #Importer
|
||||
FBXImporter::FBXImporter()
|
||||
{
|
||||
FBXImporter::FBXImporter() {
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Destructor, private as well
|
||||
FBXImporter::~FBXImporter()
|
||||
{
|
||||
FBXImporter::~FBXImporter() {
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Returns whether the class can handle the format of the given file.
|
||||
bool FBXImporter::CanRead( const std::string& pFile, IOSystem* pIOHandler, bool checkSig) const
|
||||
{
|
||||
const std::string& extension = GetExtension(pFile);
|
||||
if (extension == std::string( desc.mFileExtensions ) ) {
|
||||
return true;
|
||||
}
|
||||
bool FBXImporter::CanRead(const std::string &pFile, IOSystem *pIOHandler, bool checkSig) const {
|
||||
const std::string &extension = GetExtension(pFile);
|
||||
if (extension == std::string(desc.mFileExtensions)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
else if ((!extension.length() || checkSig) && pIOHandler) {
|
||||
// at least ASCII-FBX files usually have a 'FBX' somewhere in their head
|
||||
const char* tokens[] = {"fbx"};
|
||||
return SearchFileHeaderForToken(pIOHandler,pFile,tokens,1);
|
||||
}
|
||||
return false;
|
||||
else if ((!extension.length() || checkSig) && pIOHandler) {
|
||||
// at least ASCII-FBX files usually have a 'FBX' somewhere in their head
|
||||
const char *tokens[] = { "fbx" };
|
||||
return SearchFileHeaderForToken(pIOHandler, pFile, tokens, 1);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// List all extensions handled by this loader
|
||||
const aiImporterDesc* FBXImporter::GetInfo () const
|
||||
{
|
||||
return &desc;
|
||||
const aiImporterDesc *FBXImporter::GetInfo() const {
|
||||
return &desc;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Setup configuration properties for the loader
|
||||
void FBXImporter::SetupProperties(const Importer* pImp)
|
||||
{
|
||||
settings.readAllLayers = pImp->GetPropertyBool(AI_CONFIG_IMPORT_FBX_READ_ALL_GEOMETRY_LAYERS, true);
|
||||
settings.readAllMaterials = pImp->GetPropertyBool(AI_CONFIG_IMPORT_FBX_READ_ALL_MATERIALS, false);
|
||||
settings.readMaterials = pImp->GetPropertyBool(AI_CONFIG_IMPORT_FBX_READ_MATERIALS, true);
|
||||
settings.readTextures = pImp->GetPropertyBool(AI_CONFIG_IMPORT_FBX_READ_TEXTURES, true);
|
||||
settings.readCameras = pImp->GetPropertyBool(AI_CONFIG_IMPORT_FBX_READ_CAMERAS, true);
|
||||
settings.readLights = pImp->GetPropertyBool(AI_CONFIG_IMPORT_FBX_READ_LIGHTS, true);
|
||||
settings.readAnimations = pImp->GetPropertyBool(AI_CONFIG_IMPORT_FBX_READ_ANIMATIONS, true);
|
||||
settings.strictMode = pImp->GetPropertyBool(AI_CONFIG_IMPORT_FBX_STRICT_MODE, false);
|
||||
settings.preservePivots = pImp->GetPropertyBool(AI_CONFIG_IMPORT_FBX_PRESERVE_PIVOTS, true);
|
||||
settings.optimizeEmptyAnimationCurves = pImp->GetPropertyBool(AI_CONFIG_IMPORT_FBX_OPTIMIZE_EMPTY_ANIMATION_CURVES, true);
|
||||
settings.useLegacyEmbeddedTextureNaming = pImp->GetPropertyBool(AI_CONFIG_IMPORT_FBX_EMBEDDED_TEXTURES_LEGACY_NAMING, false);
|
||||
settings.removeEmptyBones = pImp->GetPropertyBool(AI_CONFIG_IMPORT_REMOVE_EMPTY_BONES, true);
|
||||
settings.convertToMeters = pImp->GetPropertyBool(AI_CONFIG_FBX_CONVERT_TO_M, false);
|
||||
void FBXImporter::SetupProperties(const Importer *pImp) {
|
||||
settings.readAllLayers = pImp->GetPropertyBool(AI_CONFIG_IMPORT_FBX_READ_ALL_GEOMETRY_LAYERS, true);
|
||||
settings.readAllMaterials = pImp->GetPropertyBool(AI_CONFIG_IMPORT_FBX_READ_ALL_MATERIALS, false);
|
||||
settings.readMaterials = pImp->GetPropertyBool(AI_CONFIG_IMPORT_FBX_READ_MATERIALS, true);
|
||||
settings.readTextures = pImp->GetPropertyBool(AI_CONFIG_IMPORT_FBX_READ_TEXTURES, true);
|
||||
settings.readCameras = pImp->GetPropertyBool(AI_CONFIG_IMPORT_FBX_READ_CAMERAS, true);
|
||||
settings.readLights = pImp->GetPropertyBool(AI_CONFIG_IMPORT_FBX_READ_LIGHTS, true);
|
||||
settings.readAnimations = pImp->GetPropertyBool(AI_CONFIG_IMPORT_FBX_READ_ANIMATIONS, true);
|
||||
settings.strictMode = pImp->GetPropertyBool(AI_CONFIG_IMPORT_FBX_STRICT_MODE, false);
|
||||
settings.preservePivots = pImp->GetPropertyBool(AI_CONFIG_IMPORT_FBX_PRESERVE_PIVOTS, true);
|
||||
settings.optimizeEmptyAnimationCurves = pImp->GetPropertyBool(AI_CONFIG_IMPORT_FBX_OPTIMIZE_EMPTY_ANIMATION_CURVES, true);
|
||||
settings.useLegacyEmbeddedTextureNaming = pImp->GetPropertyBool(AI_CONFIG_IMPORT_FBX_EMBEDDED_TEXTURES_LEGACY_NAMING, false);
|
||||
settings.removeEmptyBones = pImp->GetPropertyBool(AI_CONFIG_IMPORT_REMOVE_EMPTY_BONES, true);
|
||||
settings.convertToMeters = pImp->GetPropertyBool(AI_CONFIG_FBX_CONVERT_TO_M, false);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Imports the given file into the given scene structure.
|
||||
void FBXImporter::InternReadFile( const std::string& pFile, aiScene* pScene, IOSystem* pIOHandler)
|
||||
{
|
||||
std::unique_ptr<IOStream> stream(pIOHandler->Open(pFile,"rb"));
|
||||
if (!stream) {
|
||||
ThrowException("Could not open file for reading");
|
||||
}
|
||||
void FBXImporter::InternReadFile(const std::string &pFile, aiScene *pScene, IOSystem *pIOHandler) {
|
||||
std::unique_ptr<IOStream> stream(pIOHandler->Open(pFile, "rb"));
|
||||
if (!stream) {
|
||||
ThrowException("Could not open file for reading");
|
||||
}
|
||||
|
||||
// read entire file into memory - no streaming for this, fbx
|
||||
// files can grow large, but the assimp output data structure
|
||||
// then becomes very large, too. Assimp doesn't support
|
||||
// streaming for its output data structures so the net win with
|
||||
// streaming input data would be very low.
|
||||
std::vector<char> contents;
|
||||
contents.resize(stream->FileSize()+1);
|
||||
stream->Read( &*contents.begin(), 1, contents.size()-1 );
|
||||
contents[ contents.size() - 1 ] = 0;
|
||||
const char* const begin = &*contents.begin();
|
||||
// read entire file into memory - no streaming for this, fbx
|
||||
// files can grow large, but the assimp output data structure
|
||||
// then becomes very large, too. Assimp doesn't support
|
||||
// streaming for its output data structures so the net win with
|
||||
// streaming input data would be very low.
|
||||
std::vector<char> contents;
|
||||
contents.resize(stream->FileSize() + 1);
|
||||
stream->Read(&*contents.begin(), 1, contents.size() - 1);
|
||||
contents[contents.size() - 1] = 0;
|
||||
const char *const begin = &*contents.begin();
|
||||
|
||||
// broadphase tokenizing pass in which we identify the core
|
||||
// syntax elements of FBX (brackets, commas, key:value mappings)
|
||||
TokenList tokens;
|
||||
try {
|
||||
// broadphase tokenizing pass in which we identify the core
|
||||
// syntax elements of FBX (brackets, commas, key:value mappings)
|
||||
TokenList tokens;
|
||||
try {
|
||||
|
||||
bool is_binary = false;
|
||||
if (!strncmp(begin,"Kaydara FBX Binary",18)) {
|
||||
is_binary = true;
|
||||
TokenizeBinary(tokens,begin,contents.size());
|
||||
}
|
||||
else {
|
||||
Tokenize(tokens,begin);
|
||||
}
|
||||
bool is_binary = false;
|
||||
if (!strncmp(begin, "Kaydara FBX Binary", 18)) {
|
||||
is_binary = true;
|
||||
TokenizeBinary(tokens, begin, contents.size());
|
||||
} else {
|
||||
Tokenize(tokens, begin);
|
||||
}
|
||||
|
||||
// use this information to construct a very rudimentary
|
||||
// parse-tree representing the FBX scope structure
|
||||
Parser parser(tokens, is_binary);
|
||||
// use this information to construct a very rudimentary
|
||||
// parse-tree representing the FBX scope structure
|
||||
Parser parser(tokens, is_binary);
|
||||
|
||||
// take the raw parse-tree and convert it to a FBX DOM
|
||||
Document doc(parser,settings);
|
||||
// take the raw parse-tree and convert it to a FBX DOM
|
||||
Document doc(parser, settings);
|
||||
|
||||
// convert the FBX DOM to aiScene
|
||||
ConvertToAssimpScene(pScene, doc, settings.removeEmptyBones);
|
||||
// convert the FBX DOM to aiScene
|
||||
ConvertToAssimpScene(pScene, doc, settings.removeEmptyBones);
|
||||
|
||||
// size relative to cm
|
||||
float size_relative_to_cm = doc.GlobalSettings().UnitScaleFactor();
|
||||
// size relative to cm
|
||||
float size_relative_to_cm = doc.GlobalSettings().UnitScaleFactor();
|
||||
|
||||
// Set FBX file scale is relative to CM must be converted to M for
|
||||
// assimp universal format (M)
|
||||
SetFileScale( size_relative_to_cm * 0.01f);
|
||||
// Set FBX file scale is relative to CM must be converted to M for
|
||||
// assimp universal format (M)
|
||||
SetFileScale(size_relative_to_cm * 0.01f);
|
||||
|
||||
std::for_each(tokens.begin(),tokens.end(),Util::delete_fun<Token>());
|
||||
}
|
||||
catch(std::exception&) {
|
||||
std::for_each(tokens.begin(),tokens.end(),Util::delete_fun<Token>());
|
||||
throw;
|
||||
}
|
||||
std::for_each(tokens.begin(), tokens.end(), Util::delete_fun<Token>());
|
||||
} catch (std::exception &) {
|
||||
std::for_each(tokens.begin(), tokens.end(), Util::delete_fun<Token>());
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
#endif // !ASSIMP_BUILD_NO_FBX_IMPORTER
|
||||
|
||||
@@ -57,7 +57,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#include <assimp/material.h>
|
||||
#include <assimp/scene.h>
|
||||
#include <assimp/importerdesc.h>
|
||||
#include <assimp/Macros.h>
|
||||
|
||||
using namespace Assimp;
|
||||
using namespace irr;
|
||||
|
||||
@@ -0,0 +1,420 @@
|
||||
/*
|
||||
Open Asset Import Library (assimp)
|
||||
----------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2019, assimp team
|
||||
Copyright (c) 2019 bzt
|
||||
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use of this software in source and binary forms,
|
||||
with or without modification, are permitted provided that the
|
||||
following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above
|
||||
copyright notice, this list of conditions and the
|
||||
following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above
|
||||
copyright notice, this list of conditions and the
|
||||
following disclaimer in the documentation and/or other
|
||||
materials provided with the distribution.
|
||||
|
||||
* Neither the name of the assimp team, nor the names of its
|
||||
contributors may be used to endorse or promote products
|
||||
derived from this software without specific prior
|
||||
written permission of the assimp team.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
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
|
||||
#ifndef ASSIMP_BUILD_NO_M3D_EXPORTER
|
||||
|
||||
#define M3D_IMPLEMENTATION
|
||||
#define M3D_NOIMPORTER
|
||||
#define M3D_EXPORTER
|
||||
#define M3D_ASCII
|
||||
#ifndef ASSIMP_BUILD_NO_M3D_IMPORTER
|
||||
#define M3D_NODUP
|
||||
#endif
|
||||
|
||||
// Header files, standard library.
|
||||
#include <memory> // shared_ptr
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <assimp/version.h> // aiGetVersion
|
||||
#include <assimp/IOSystem.hpp>
|
||||
#include <assimp/Exporter.hpp>
|
||||
#include <assimp/DefaultLogger.hpp>
|
||||
#include <assimp/StreamWriter.h> // StreamWriterLE
|
||||
#include <assimp/Exceptional.h> // DeadlyExportError
|
||||
#include <assimp/material.h> // aiTextureType
|
||||
#include <assimp/scene.h>
|
||||
#include <assimp/mesh.h>
|
||||
#include "M3DExporter.h"
|
||||
#include "M3DMaterials.h"
|
||||
|
||||
// RESOURCES:
|
||||
// https://gitlab.com/bztsrc/model3d/blob/master/docs/m3d_format.md
|
||||
// https://gitlab.com/bztsrc/model3d/blob/master/docs/a3d_format.md
|
||||
|
||||
/*
|
||||
* Currently supports static meshes, vertex colors, materials, textures
|
||||
*
|
||||
* For animation, it would require the following conversions:
|
||||
* - aiNode (bones) -> m3d_t.bone (with parent id, position vector and oriantation quaternion)
|
||||
* - aiMesh.aiBone -> m3d_t.skin (per vertex, with bone id, weight pairs)
|
||||
* - aiAnimation -> m3d_action (frame with timestamp and list of bone id, position, orientation
|
||||
* triplets, instead of per bone timestamp + lists)
|
||||
*/
|
||||
using namespace Assimp;
|
||||
|
||||
namespace Assimp {
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
// Worker function for exporting a scene to binary M3D.
|
||||
// Prototyped and registered in Exporter.cpp
|
||||
void ExportSceneM3D (
|
||||
const char* pFile,
|
||||
IOSystem* pIOSystem,
|
||||
const aiScene* pScene,
|
||||
const ExportProperties* pProperties
|
||||
){
|
||||
// initialize the exporter
|
||||
M3DExporter exporter(pScene, pProperties);
|
||||
|
||||
// perform binary export
|
||||
exporter.doExport(pFile, pIOSystem, false);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
// Worker function for exporting a scene to ASCII A3D.
|
||||
// Prototyped and registered in Exporter.cpp
|
||||
void ExportSceneA3D (
|
||||
const char* pFile,
|
||||
IOSystem* pIOSystem,
|
||||
const aiScene* pScene,
|
||||
const ExportProperties* pProperties
|
||||
|
||||
){
|
||||
// initialize the exporter
|
||||
M3DExporter exporter(pScene, pProperties);
|
||||
|
||||
// perform ascii export
|
||||
exporter.doExport(pFile, pIOSystem, true);
|
||||
}
|
||||
|
||||
} // end of namespace Assimp
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
M3DExporter::M3DExporter ( const aiScene* pScene, const ExportProperties* pProperties )
|
||||
: mScene(pScene)
|
||||
, mProperties(pProperties)
|
||||
, outfile()
|
||||
, m3d(nullptr) { }
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void M3DExporter::doExport (
|
||||
const char* pFile,
|
||||
IOSystem* pIOSystem,
|
||||
bool toAscii
|
||||
){
|
||||
// TODO: convert mProperties into M3D_EXP_* flags
|
||||
(void)mProperties;
|
||||
|
||||
// open the indicated file for writing (in binary / ASCII mode)
|
||||
outfile.reset(pIOSystem->Open(pFile, toAscii ? "wt" : "wb"));
|
||||
if (!outfile) {
|
||||
throw DeadlyExportError( "could not open output .m3d file: " + std::string(pFile) );
|
||||
}
|
||||
|
||||
// use malloc() here because m3d_free() will call free()
|
||||
m3d = (m3d_t*)calloc(1, sizeof(m3d_t));
|
||||
if(!m3d) {
|
||||
throw DeadlyExportError( "memory allocation error" );
|
||||
}
|
||||
m3d->name = _m3d_safestr((char*)&mScene->mRootNode->mName.data, 2);
|
||||
|
||||
// Create a model from assimp structures
|
||||
aiMatrix4x4 m;
|
||||
NodeWalk(mScene->mRootNode, m);
|
||||
|
||||
// serialize the structures
|
||||
unsigned int size;
|
||||
unsigned char *output = m3d_save(m3d, M3D_EXP_FLOAT,
|
||||
M3D_EXP_EXTRA | (toAscii ? M3D_EXP_ASCII : 0), &size);
|
||||
m3d_free(m3d);
|
||||
if(!output || size < 8) {
|
||||
throw DeadlyExportError( "unable to serialize into Model 3D" );
|
||||
}
|
||||
|
||||
// Write out serialized model
|
||||
outfile->Write(output, size, 1);
|
||||
|
||||
// explicitly release file pointer,
|
||||
// so we don't have to rely on class destruction.
|
||||
outfile.reset();
|
||||
}
|
||||
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// helper to add a vertex (private to NodeWalk)
|
||||
m3dv_t *M3DExporter::AddVrtx(m3dv_t *vrtx, uint32_t *numvrtx, m3dv_t *v, uint32_t *idx)
|
||||
{
|
||||
if(v->x == (M3D_FLOAT)-0.0) v->x = (M3D_FLOAT)0.0;
|
||||
if(v->y == (M3D_FLOAT)-0.0) v->y = (M3D_FLOAT)0.0;
|
||||
if(v->z == (M3D_FLOAT)-0.0) v->z = (M3D_FLOAT)0.0;
|
||||
if(v->w == (M3D_FLOAT)-0.0) v->w = (M3D_FLOAT)0.0;
|
||||
vrtx = (m3dv_t*)M3D_REALLOC(vrtx, ((*numvrtx) + 1) * sizeof(m3dv_t));
|
||||
memcpy(&vrtx[*numvrtx], v, sizeof(m3dv_t));
|
||||
*idx = *numvrtx;
|
||||
(*numvrtx)++;
|
||||
return vrtx;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// helper to add a tmap (private to NodeWalk)
|
||||
m3dti_t *M3DExporter::AddTmap(m3dti_t *tmap, uint32_t *numtmap, m3dti_t *ti, uint32_t *idx)
|
||||
{
|
||||
tmap = (m3dti_t*)M3D_REALLOC(tmap, ((*numtmap) + 1) * sizeof(m3dti_t));
|
||||
memcpy(&tmap[*numtmap], ti, sizeof(m3dti_t));
|
||||
*idx = *numtmap;
|
||||
(*numtmap)++;
|
||||
return tmap;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// recursive node walker
|
||||
void M3DExporter::NodeWalk(const aiNode* pNode, aiMatrix4x4 m)
|
||||
{
|
||||
aiMatrix4x4 nm = m * pNode->mTransformation;
|
||||
|
||||
for(unsigned int i = 0; i < pNode->mNumMeshes; i++) {
|
||||
const aiMesh *mesh = mScene->mMeshes[pNode->mMeshes[i]];
|
||||
unsigned int mi = (M3D_INDEX)-1U;
|
||||
if(mScene->mMaterials) {
|
||||
// get the material for this mesh
|
||||
mi = addMaterial(mScene->mMaterials[mesh->mMaterialIndex]);
|
||||
}
|
||||
// iterate through the mesh faces
|
||||
for(unsigned int j = 0; j < mesh->mNumFaces; j++) {
|
||||
unsigned int n;
|
||||
const aiFace* face = &(mesh->mFaces[j]);
|
||||
// only triangle meshes supported for now
|
||||
if(face->mNumIndices != 3) {
|
||||
throw DeadlyExportError( "use aiProcess_Triangulate before export" );
|
||||
}
|
||||
// add triangle to the output
|
||||
n = m3d->numface++;
|
||||
m3d->face = (m3df_t*)M3D_REALLOC(m3d->face,
|
||||
m3d->numface * sizeof(m3df_t));
|
||||
if(!m3d->face) {
|
||||
throw DeadlyExportError( "memory allocation error" );
|
||||
}
|
||||
/* set all index to -1 by default */
|
||||
m3d->face[n].vertex[0] = m3d->face[n].vertex[1] = m3d->face[n].vertex[2] =
|
||||
m3d->face[n].normal[0] = m3d->face[n].normal[1] = m3d->face[n].normal[2] =
|
||||
m3d->face[n].texcoord[0] = m3d->face[n].texcoord[1] = m3d->face[n].texcoord[2] = -1U;
|
||||
m3d->face[n].materialid = mi;
|
||||
for(unsigned int k = 0; k < face->mNumIndices; k++) {
|
||||
// get the vertex's index
|
||||
unsigned int l = face->mIndices[k];
|
||||
unsigned int idx;
|
||||
m3dv_t vertex;
|
||||
m3dti_t ti;
|
||||
// multiply the position vector by the transformation matrix
|
||||
aiVector3D v = mesh->mVertices[l];
|
||||
v *= nm;
|
||||
vertex.x = v.x;
|
||||
vertex.y = v.y;
|
||||
vertex.z = v.z;
|
||||
vertex.w = 1.0;
|
||||
vertex.color = 0;
|
||||
vertex.skinid = -1U;
|
||||
// add color if defined
|
||||
if(mesh->HasVertexColors(0))
|
||||
vertex.color = mkColor(&mesh->mColors[0][l]);
|
||||
// save the vertex to the output
|
||||
m3d->vertex = AddVrtx(m3d->vertex, &m3d->numvertex,
|
||||
&vertex, &idx);
|
||||
m3d->face[n].vertex[k] = (M3D_INDEX)idx;
|
||||
// do we have texture coordinates?
|
||||
if(mesh->HasTextureCoords(0)) {
|
||||
ti.u = mesh->mTextureCoords[0][l].x;
|
||||
ti.v = mesh->mTextureCoords[0][l].y;
|
||||
m3d->tmap = AddTmap(m3d->tmap, &m3d->numtmap, &ti, &idx);
|
||||
m3d->face[n].texcoord[k] = (M3D_INDEX)idx;
|
||||
}
|
||||
// do we have normal vectors?
|
||||
if(mesh->HasNormals()) {
|
||||
vertex.x = mesh->mNormals[l].x;
|
||||
vertex.y = mesh->mNormals[l].y;
|
||||
vertex.z = mesh->mNormals[l].z;
|
||||
vertex.color = 0;
|
||||
m3d->vertex = AddVrtx(m3d->vertex, &m3d->numvertex, &vertex, &idx);
|
||||
m3d->face[n].normal[k] = (M3D_INDEX)idx;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// repeat for the children nodes
|
||||
for (unsigned int i = 0; i < pNode->mNumChildren; i++) {
|
||||
NodeWalk(pNode->mChildren[i], nm);
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// convert aiColor4D into uint32_t
|
||||
uint32_t M3DExporter::mkColor(aiColor4D* c)
|
||||
{
|
||||
return ((uint8_t)(c->a*255) << 24L) |
|
||||
((uint8_t)(c->b*255) << 16L) |
|
||||
((uint8_t)(c->g*255) << 8L) |
|
||||
((uint8_t)(c->r*255) << 0L);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// add a material to the output
|
||||
M3D_INDEX M3DExporter::addMaterial(const aiMaterial *mat)
|
||||
{
|
||||
unsigned int mi = -1U;
|
||||
aiColor4D c;
|
||||
aiString name;
|
||||
ai_real f;
|
||||
char *fn;
|
||||
|
||||
if(mat && mat->Get(AI_MATKEY_NAME, name) == AI_SUCCESS && name.length &&
|
||||
strcmp((char*)&name.data, AI_DEFAULT_MATERIAL_NAME)) {
|
||||
// check if we have saved a material by this name. This has to be done
|
||||
// because only the referenced materials should be added to the output
|
||||
for(unsigned int i = 0; i < m3d->nummaterial; i++)
|
||||
if(!strcmp((char*)&name.data, m3d->material[i].name)) {
|
||||
mi = i;
|
||||
break;
|
||||
}
|
||||
// if not found, add the material to the output
|
||||
if(mi == -1U) {
|
||||
unsigned int k;
|
||||
mi = m3d->nummaterial++;
|
||||
m3d->material = (m3dm_t*)M3D_REALLOC(m3d->material, m3d->nummaterial
|
||||
* sizeof(m3dm_t));
|
||||
if(!m3d->material) {
|
||||
throw DeadlyExportError( "memory allocation error" );
|
||||
}
|
||||
m3d->material[mi].name = _m3d_safestr((char*)&name.data, 0);
|
||||
m3d->material[mi].numprop = 0;
|
||||
m3d->material[mi].prop = NULL;
|
||||
// iterate through the material property table and see what we got
|
||||
for(k = 0; k < 15; k++) {
|
||||
unsigned int j;
|
||||
if(m3d_propertytypes[k].format == m3dpf_map)
|
||||
continue;
|
||||
if(aiProps[k].pKey) {
|
||||
switch(m3d_propertytypes[k].format) {
|
||||
case m3dpf_color:
|
||||
if(mat->Get(aiProps[k].pKey, aiProps[k].type,
|
||||
aiProps[k].index, c) == AI_SUCCESS)
|
||||
addProp(&m3d->material[mi],
|
||||
m3d_propertytypes[k].id, mkColor(&c));
|
||||
break;
|
||||
case m3dpf_float:
|
||||
if(mat->Get(aiProps[k].pKey, aiProps[k].type,
|
||||
aiProps[k].index, f) == AI_SUCCESS)
|
||||
addProp(&m3d->material[mi],
|
||||
m3d_propertytypes[k].id,
|
||||
/* not (uint32_t)f, because we don't want to convert
|
||||
* it, we want to see it as 32 bits of memory */
|
||||
*((uint32_t*)&f));
|
||||
break;
|
||||
case m3dpf_uint8:
|
||||
if(mat->Get(aiProps[k].pKey, aiProps[k].type,
|
||||
aiProps[k].index, j) == AI_SUCCESS) {
|
||||
// special conversion for illumination model property
|
||||
if(m3d_propertytypes[k].id == m3dp_il) {
|
||||
switch(j) {
|
||||
case aiShadingMode_NoShading: j = 0; break;
|
||||
case aiShadingMode_Phong: j = 2; break;
|
||||
default: j = 1; break;
|
||||
}
|
||||
}
|
||||
addProp(&m3d->material[mi],
|
||||
m3d_propertytypes[k].id, j);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if(mat->Get(aiProps[k].pKey, aiProps[k].type,
|
||||
aiProps[k].index, j) == AI_SUCCESS)
|
||||
addProp(&m3d->material[mi],
|
||||
m3d_propertytypes[k].id, j);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(aiTxProps[k].pKey &&
|
||||
mat->GetTexture((aiTextureType)aiTxProps[k].type,
|
||||
aiTxProps[k].index, &name, NULL, NULL, NULL,
|
||||
NULL, NULL) == AI_SUCCESS) {
|
||||
unsigned int i;
|
||||
for(j = name.length-1; j > 0 && name.data[j]!='.'; j++);
|
||||
if(j && name.data[j]=='.' &&
|
||||
(name.data[j+1]=='p' || name.data[j+1]=='P') &&
|
||||
(name.data[j+1]=='n' || name.data[j+1]=='N') &&
|
||||
(name.data[j+1]=='g' || name.data[j+1]=='G'))
|
||||
name.data[j]=0;
|
||||
// do we have this texture saved already?
|
||||
fn = _m3d_safestr((char*)&name.data, 0);
|
||||
for(j = 0, i = -1U; j < m3d->numtexture; j++)
|
||||
if(!strcmp(fn, m3d->texture[j].name)) {
|
||||
i = j;
|
||||
free(fn);
|
||||
break;
|
||||
}
|
||||
if(i == -1U) {
|
||||
i = m3d->numtexture++;
|
||||
m3d->texture = (m3dtx_t*)M3D_REALLOC(
|
||||
m3d->texture,
|
||||
m3d->numtexture * sizeof(m3dtx_t));
|
||||
if(!m3d->texture) {
|
||||
throw DeadlyExportError( "memory allocation error" );
|
||||
}
|
||||
// we don't need the texture itself, only its name
|
||||
m3d->texture[i].name = fn;
|
||||
m3d->texture[i].w = 0;
|
||||
m3d->texture[i].h = 0;
|
||||
m3d->texture[i].d = NULL;
|
||||
}
|
||||
addProp(&m3d->material[mi],
|
||||
m3d_propertytypes[k].id + 128, i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return mi;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// add a material property to the output
|
||||
void M3DExporter::addProp(m3dm_t *m, uint8_t type, uint32_t value)
|
||||
{
|
||||
unsigned int i;
|
||||
i = m->numprop++;
|
||||
m->prop = (m3dp_t*)M3D_REALLOC(m->prop, m->numprop * sizeof(m3dp_t));
|
||||
if(!m->prop) { throw DeadlyExportError( "memory allocation error" ); }
|
||||
m->prop[i].type = type;
|
||||
m->prop[i].value.num = value;
|
||||
}
|
||||
|
||||
#endif // ASSIMP_BUILD_NO_M3D_EXPORTER
|
||||
#endif // ASSIMP_BUILD_NO_EXPORT
|
||||
@@ -0,0 +1,100 @@
|
||||
/*
|
||||
Open Asset Import Library (assimp)
|
||||
----------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2019, assimp team
|
||||
Copyright (c) 2019 bzt
|
||||
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use of this software in source and binary forms,
|
||||
with or without modification, are permitted provided that the
|
||||
following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above
|
||||
copyright notice, this list of conditions and the
|
||||
following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above
|
||||
copyright notice, this list of conditions and the
|
||||
following disclaimer in the documentation and/or other
|
||||
materials provided with the distribution.
|
||||
|
||||
* Neither the name of the assimp team, nor the names of its
|
||||
contributors may be used to endorse or promote products
|
||||
derived from this software without specific prior
|
||||
written permission of the assimp team.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
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.
|
||||
|
||||
----------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/** @file M3DExporter.h
|
||||
* @brief Declares the exporter class to write a scene to a Model 3D file
|
||||
*/
|
||||
#ifndef AI_M3DEXPORTER_H_INC
|
||||
#define AI_M3DEXPORTER_H_INC
|
||||
|
||||
#ifndef ASSIMP_BUILD_NO_M3D_EXPORTER
|
||||
|
||||
#include "m3d.h"
|
||||
|
||||
#include <assimp/types.h>
|
||||
//#include <assimp/material.h>
|
||||
#include <assimp/StreamWriter.h> // StreamWriterLE
|
||||
#include <assimp/Exceptional.h> // DeadlyExportError
|
||||
|
||||
#include <memory> // shared_ptr
|
||||
|
||||
struct aiScene;
|
||||
struct aiNode;
|
||||
struct aiMaterial;
|
||||
struct aiFace;
|
||||
|
||||
namespace Assimp
|
||||
{
|
||||
class IOSystem;
|
||||
class IOStream;
|
||||
class ExportProperties;
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
/** Helper class to export a given scene to an M3D file. */
|
||||
// ---------------------------------------------------------------------
|
||||
class M3DExporter
|
||||
{
|
||||
public:
|
||||
/// Constructor for a specific scene to export
|
||||
M3DExporter(const aiScene* pScene, const ExportProperties* pProperties);
|
||||
// call this to do the actual export
|
||||
void doExport(const char* pFile, IOSystem* pIOSystem, bool toAscii);
|
||||
|
||||
private:
|
||||
const aiScene* mScene; // the scene to export
|
||||
const ExportProperties* mProperties; // currently unused
|
||||
std::shared_ptr<IOStream> outfile; // file to write to
|
||||
m3d_t *m3d; // model for the C library to convert to
|
||||
|
||||
// helper to do the recursive walking
|
||||
void NodeWalk(const aiNode* pNode, aiMatrix4x4 m);
|
||||
m3dv_t *AddVrtx(m3dv_t *vrtx, uint32_t *numvrtx, m3dv_t *v, uint32_t *idx);
|
||||
m3dti_t *AddTmap(m3dti_t *tmap, uint32_t *numtmap, m3dti_t *ti, uint32_t *idx);
|
||||
uint32_t mkColor(aiColor4D* c);
|
||||
M3D_INDEX addMaterial(const aiMaterial *mat);
|
||||
void addProp(m3dm_t *m, uint8_t type, uint32_t value);
|
||||
};
|
||||
}
|
||||
|
||||
#endif // ASSIMP_BUILD_NO_M3D_EXPORTER
|
||||
|
||||
#endif // AI_M3DEXPORTER_H_INC
|
||||
@@ -0,0 +1,766 @@
|
||||
/*
|
||||
Open Asset Import Library (assimp)
|
||||
----------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2019, assimp team
|
||||
Copyright (c) 2019 bzt
|
||||
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use of this software in source and binary forms,
|
||||
with or without modification, are permitted provided that the
|
||||
following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above
|
||||
copyright notice, this list of conditions and the
|
||||
following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above
|
||||
copyright notice, this list of conditions and the
|
||||
following disclaimer in the documentation and/or other
|
||||
materials provided with the distribution.
|
||||
|
||||
* Neither the name of the assimp team, nor the names of its
|
||||
contributors may be used to endorse or promote products
|
||||
derived from this software without specific prior
|
||||
written permission of the assimp team.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
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_M3D_IMPORTER
|
||||
|
||||
#define M3D_IMPLEMENTATION
|
||||
#define M3D_ASCII
|
||||
#define M3D_NONORMALS /* leave the post-processing to Assimp */
|
||||
#define M3D_NOWEIGHTS
|
||||
#define M3D_NOANIMATION
|
||||
|
||||
#include <assimp/IOStreamBuffer.h>
|
||||
#include <memory>
|
||||
#include <assimp/DefaultIOSystem.h>
|
||||
#include <assimp/Importer.hpp>
|
||||
#include <assimp/scene.h>
|
||||
#include <assimp/ai_assert.h>
|
||||
#include <assimp/DefaultLogger.hpp>
|
||||
#include <assimp/importerdesc.h>
|
||||
#include "M3DImporter.h"
|
||||
#include "M3DMaterials.h"
|
||||
|
||||
// RESOURCES:
|
||||
// https://gitlab.com/bztsrc/model3d/blob/master/docs/m3d_format.md
|
||||
// https://gitlab.com/bztsrc/model3d/blob/master/docs/a3d_format.md
|
||||
|
||||
/*
|
||||
Unfortunately aiNode has bone structures and meshes too, yet we can't assign
|
||||
the mesh to a bone aiNode as a skin may refer to several aiNodes. Therefore
|
||||
I've decided to import into this structure:
|
||||
|
||||
aiScene->mRootNode
|
||||
| |->mMeshes (all the meshes)
|
||||
| \->children (empty if there's no skeleton imported, no meshes)
|
||||
| \->skeleton root aiNode*
|
||||
| |->bone aiNode
|
||||
| | \->subbone aiNode
|
||||
| |->bone aiNode
|
||||
| | ...
|
||||
| \->bone aiNode
|
||||
\->mMeshes[]
|
||||
\->aiBone, referencing mesh-less aiNodes from above
|
||||
|
||||
* - normally one, but if a model has several skeleton roots, then all of them
|
||||
are listed in aiScene->mRootNode->children, but all without meshes
|
||||
*/
|
||||
|
||||
static const aiImporterDesc desc = {
|
||||
"Model 3D Importer",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
aiImporterFlags_SupportBinaryFlavour,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
"m3d a3d"
|
||||
};
|
||||
|
||||
// workaround: the SDK expects a C callback, but we want to use Assimp::IOSystem to implement that
|
||||
extern "C" {
|
||||
void* m3dimporter_pIOHandler;
|
||||
|
||||
unsigned char *m3dimporter_readfile(char *fn, unsigned int *size) {
|
||||
ai_assert( nullptr != fn );
|
||||
ai_assert( nullptr != size );
|
||||
std::string file(fn);
|
||||
std::unique_ptr<Assimp::IOStream> pStream(
|
||||
(reinterpret_cast<Assimp::IOSystem*>(m3dimporter_pIOHandler))->Open( file, "rb"));
|
||||
size_t fileSize = 0;
|
||||
unsigned char *data = NULL;
|
||||
// sometimes pStream is nullptr for some reason (should be an empty object returning nothing I guess)
|
||||
if(pStream) {
|
||||
fileSize = pStream->FileSize();
|
||||
// should be allocated with malloc(), because the library will call free() to deallocate
|
||||
data = (unsigned char*)malloc(fileSize);
|
||||
if( !data || !pStream.get() || !fileSize || fileSize != pStream->Read(data,1,fileSize)) {
|
||||
pStream.reset();
|
||||
*size = 0;
|
||||
// don't throw a deadly exception, it's not fatal if we can't read an external asset
|
||||
return nullptr;
|
||||
}
|
||||
pStream.reset();
|
||||
}
|
||||
*size = (int)fileSize;
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
namespace Assimp {
|
||||
|
||||
using namespace std;
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Default constructor
|
||||
M3DImporter::M3DImporter()
|
||||
: mScene(nullptr)
|
||||
, m3d(nullptr) { }
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Destructor.
|
||||
M3DImporter::~M3DImporter() {}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Returns true, if file is a binary or ASCII Model 3D file.
|
||||
bool M3DImporter::CanRead(const std::string& pFile, IOSystem* pIOHandler , bool checkSig) const {
|
||||
const std::string extension = GetExtension(pFile);
|
||||
|
||||
if (extension == "m3d" || extension == "a3d")
|
||||
return true;
|
||||
else if (!extension.length() || checkSig) {
|
||||
if (!pIOHandler) {
|
||||
return true;
|
||||
}
|
||||
/*
|
||||
* don't use CheckMagicToken because that checks with swapped bytes too, leading to false
|
||||
* positives. This magic is not uint32_t, but char[4], so memcmp is the best way
|
||||
|
||||
const char* tokens[] = {"3DMO", "3dmo"};
|
||||
return CheckMagicToken(pIOHandler,pFile,tokens,2,0,4);
|
||||
*/
|
||||
std::unique_ptr<IOStream> pStream (pIOHandler->Open(pFile, "rb"));
|
||||
unsigned char data[4];
|
||||
if(4 != pStream->Read(data,1,4)) {
|
||||
return false;
|
||||
}
|
||||
return !memcmp(data, "3DMO", 4) /* bin */ || !memcmp(data, "3dmo", 4) /* ASCII */;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
const aiImporterDesc* M3DImporter::GetInfo() const {
|
||||
return &desc;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Model 3D import implementation
|
||||
void M3DImporter::InternReadFile( const std::string &file, aiScene* pScene, IOSystem* pIOHandler) {
|
||||
// Read file into memory
|
||||
std::unique_ptr<IOStream> pStream( pIOHandler->Open( file, "rb"));
|
||||
if( !pStream.get() ) {
|
||||
throw DeadlyImportError( "Failed to open file " + file + "." );
|
||||
}
|
||||
|
||||
// Get the file-size and validate it, throwing an exception when fails
|
||||
size_t fileSize = pStream->FileSize();
|
||||
if( fileSize < 8 ) {
|
||||
throw DeadlyImportError( "M3D-file " + file + " is too small." );
|
||||
}
|
||||
std::unique_ptr<unsigned char[]> _buffer (new unsigned char[fileSize]);
|
||||
unsigned char *data( _buffer.get() );
|
||||
if(fileSize != pStream->Read(data,1,fileSize)) {
|
||||
throw DeadlyImportError( "Failed to read the file " + file + "." );
|
||||
}
|
||||
|
||||
// Get the path for external assets
|
||||
std::string folderName( "./" );
|
||||
std::string::size_type pos = file.find_last_of( "\\/" );
|
||||
if ( pos != std::string::npos ) {
|
||||
folderName = file.substr( 0, pos );
|
||||
if ( !folderName.empty() ) {
|
||||
pIOHandler->PushDirectory( folderName );
|
||||
}
|
||||
}
|
||||
// pass this IOHandler to the C callback
|
||||
m3dimporter_pIOHandler = pIOHandler;
|
||||
|
||||
//DefaultLogger::create("/dev/stderr", Logger::VERBOSE);
|
||||
ASSIMP_LOG_DEBUG_F("M3D: loading ", file);
|
||||
|
||||
// let the C SDK do the hard work for us
|
||||
m3d = m3d_load(&data[0], m3dimporter_readfile, free, nullptr);
|
||||
m3dimporter_pIOHandler = nullptr;
|
||||
if( !m3d ) {
|
||||
throw DeadlyImportError( "Unable to parse " + file + " as M3D." );
|
||||
}
|
||||
|
||||
// create the root node
|
||||
pScene->mRootNode = new aiNode;
|
||||
pScene->mRootNode->mName = aiString(std::string(std::string(m3d->name)));
|
||||
pScene->mRootNode->mTransformation = aiMatrix4x4();
|
||||
pScene->mRootNode->mNumChildren = 0;
|
||||
mScene = pScene;
|
||||
|
||||
ASSIMP_LOG_DEBUG("M3D: root node " + std::string(m3d->name));
|
||||
|
||||
// now we just have to fill up the Assimp structures in pScene
|
||||
importMaterials();
|
||||
importTextures();
|
||||
importBones(-1U, pScene->mRootNode);
|
||||
importMeshes();
|
||||
importAnimations();
|
||||
|
||||
// we don't need the SDK's version any more
|
||||
m3d_free(m3d);
|
||||
|
||||
// Pop directory stack
|
||||
if ( pIOHandler->StackSize() > 0 ) {
|
||||
pIOHandler->PopDirectory();
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// convert materials. properties are converted using a static table in M3DMaterials.h
|
||||
void M3DImporter::importMaterials()
|
||||
{
|
||||
unsigned int i, j, k, l, n;
|
||||
m3dm_t *m;
|
||||
aiString name = aiString(AI_DEFAULT_MATERIAL_NAME);
|
||||
aiColor4D c;
|
||||
ai_real f;
|
||||
|
||||
ai_assert(mScene != nullptr);
|
||||
ai_assert(m3d != nullptr);
|
||||
|
||||
mScene->mNumMaterials = m3d->nummaterial + 1;
|
||||
mScene->mMaterials = new aiMaterial*[ m3d->nummaterial + 1 ];
|
||||
|
||||
ASSIMP_LOG_DEBUG_F("M3D: importMaterials ", mScene->mNumMaterials);
|
||||
|
||||
// add a default material as first
|
||||
aiMaterial* mat = new aiMaterial;
|
||||
mat->AddProperty( &name, AI_MATKEY_NAME );
|
||||
c.a = 1.0; c.b = c.g = c.r = 0.6;
|
||||
mat->AddProperty( &c, 1, AI_MATKEY_COLOR_DIFFUSE);
|
||||
mScene->mMaterials[0] = mat;
|
||||
|
||||
for(i = 0; i < m3d->nummaterial; i++) {
|
||||
m = &m3d->material[i];
|
||||
aiMaterial* mat = new aiMaterial;
|
||||
name.Set(std::string(m->name));
|
||||
mat->AddProperty( &name, AI_MATKEY_NAME );
|
||||
for(j = 0; j < m->numprop; j++) {
|
||||
// look up property type
|
||||
// 0 - 127 scalar values,
|
||||
// 128 - 255 the same properties but for texture maps
|
||||
k = 256;
|
||||
for(l = 0; l < sizeof(m3d_propertytypes)/sizeof(m3d_propertytypes[0]); l++)
|
||||
if(m->prop[j].type == m3d_propertytypes[l].id ||
|
||||
m->prop[j].type == m3d_propertytypes[l].id + 128) {
|
||||
k = l;
|
||||
break;
|
||||
}
|
||||
// should never happen, but be safe than sorry
|
||||
if(k == 256) continue;
|
||||
|
||||
// scalar properties
|
||||
if(m->prop[j].type < 128 && aiProps[k].pKey) {
|
||||
switch(m3d_propertytypes[k].format) {
|
||||
case m3dpf_color:
|
||||
c = mkColor(m->prop[j].value.color);
|
||||
mat->AddProperty(&c, 1, aiProps[k].pKey, aiProps[k].type, aiProps[k].index);
|
||||
break;
|
||||
case m3dpf_float:
|
||||
f = m->prop[j].value.fnum;
|
||||
mat->AddProperty(&f, 1, aiProps[k].pKey, aiProps[k].type, aiProps[k].index);
|
||||
break;
|
||||
default:
|
||||
n = m->prop[j].value.num;
|
||||
if(m->prop[j].type == m3dp_il) {
|
||||
switch(n) {
|
||||
case 0: n = aiShadingMode_NoShading; break;
|
||||
case 2: n = aiShadingMode_Phong; break;
|
||||
default: n = aiShadingMode_Gouraud; break;
|
||||
}
|
||||
}
|
||||
mat->AddProperty(&n, 1, aiProps[k].pKey, aiProps[k].type, aiProps[k].index);
|
||||
break;
|
||||
}
|
||||
}
|
||||
// texture map properties
|
||||
if(m->prop[j].type >= 128 && aiTxProps[k].pKey &&
|
||||
// extra check, should never happen, do we have the refered texture?
|
||||
m->prop[j].value.textureid < m3d->numtexture &&
|
||||
m3d->texture[m->prop[j].value.textureid].name) {
|
||||
name.Set(std::string(std::string(m3d->texture[m->prop[j].value.textureid].name) + ".png"));
|
||||
mat->AddProperty(&name, aiTxProps[k].pKey, aiTxProps[k].type, aiTxProps[k].index);
|
||||
n = 0;
|
||||
mat->AddProperty(&n, 1, _AI_MATKEY_UVWSRC_BASE, aiProps[k].type, aiProps[k].index);
|
||||
}
|
||||
}
|
||||
mScene->mMaterials[i + 1] = mat;
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// import textures, this is the simplest of all
|
||||
void M3DImporter::importTextures()
|
||||
{
|
||||
unsigned int i;
|
||||
const char *formatHint[] = { "rgba0800", "rgba0808", "rgba8880", "rgba8888" };
|
||||
m3dtx_t *t;
|
||||
|
||||
ai_assert(mScene != nullptr);
|
||||
ai_assert(m3d != nullptr);
|
||||
|
||||
mScene->mNumTextures = m3d->numtexture;
|
||||
ASSIMP_LOG_DEBUG_F("M3D: importTextures ", mScene->mNumTextures);
|
||||
|
||||
if(!m3d->numtexture)
|
||||
return;
|
||||
|
||||
mScene->mTextures = new aiTexture*[m3d->numtexture];
|
||||
for(i = 0; i < m3d->numtexture; i++) {
|
||||
unsigned int j, k;
|
||||
t = &m3d->texture[i];
|
||||
if(!t->w || !t->h || !t->f || !t->d) continue;
|
||||
aiTexture *tx = new aiTexture;
|
||||
strcpy(tx->achFormatHint, formatHint[t->f - 1]);
|
||||
tx->mFilename = aiString(std::string(t->name) + ".png");
|
||||
tx->mWidth = t->w;
|
||||
tx->mHeight = t->h;
|
||||
tx->pcData = new aiTexel[ tx->mWidth*tx->mHeight ];
|
||||
for(j = k = 0; j < tx->mWidth*tx->mHeight; j++) {
|
||||
switch(t->f) {
|
||||
case 1: tx->pcData[j].g = t->d[k++]; break;
|
||||
case 2: tx->pcData[j].g = t->d[k++]; tx->pcData[j].a = t->d[k++]; break;
|
||||
case 3:
|
||||
tx->pcData[j].r = t->d[k++]; tx->pcData[j].g = t->d[k++];
|
||||
tx->pcData[j].b = t->d[k++]; tx->pcData[j].a = 255;
|
||||
break;
|
||||
case 4:
|
||||
tx->pcData[j].r = t->d[k++]; tx->pcData[j].g = t->d[k++];
|
||||
tx->pcData[j].b = t->d[k++]; tx->pcData[j].a = t->d[k++];
|
||||
break;
|
||||
}
|
||||
}
|
||||
mScene->mTextures[i] = tx;
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// this is tricky. M3D has a global vertex and UV list, and faces are indexing them
|
||||
// individually. In assimp there're per mesh vertex and UV lists, and they must be
|
||||
// indexed simultaneously.
|
||||
void M3DImporter::importMeshes()
|
||||
{
|
||||
unsigned int i, j, k, l, numpoly = 3, lastMat = -2U;
|
||||
std::vector<aiMesh*> *meshes = new std::vector<aiMesh*>();
|
||||
std::vector<aiFace> *faces = nullptr;
|
||||
std::vector<aiVector3D> *vertices = nullptr;
|
||||
std::vector<aiVector3D> *normals = nullptr;
|
||||
std::vector<aiVector3D> *texcoords = nullptr;
|
||||
std::vector<aiColor4D> *colors = nullptr;
|
||||
std::vector<unsigned int> *vertexids = nullptr;
|
||||
aiMesh *pMesh = nullptr;
|
||||
|
||||
ai_assert(mScene != nullptr);
|
||||
ai_assert(m3d != nullptr);
|
||||
ai_assert(mScene->mRootNode != nullptr);
|
||||
|
||||
ASSIMP_LOG_DEBUG_F("M3D: importMeshes ", m3d->numface);
|
||||
|
||||
for(i = 0; i < m3d->numface; i++) {
|
||||
// we must switch mesh if material changes
|
||||
if(lastMat != m3d->face[i].materialid) {
|
||||
lastMat = m3d->face[i].materialid;
|
||||
if(pMesh && vertices && vertices->size() && faces && faces->size()) {
|
||||
populateMesh(pMesh, faces, vertices, normals, texcoords, colors, vertexids);
|
||||
meshes->push_back(pMesh);
|
||||
delete faces;
|
||||
delete vertices;
|
||||
delete normals;
|
||||
delete texcoords;
|
||||
delete colors;
|
||||
delete vertexids; // this is not stored in pMesh, just to collect bone vertices
|
||||
}
|
||||
pMesh = new aiMesh;
|
||||
pMesh->mPrimitiveTypes = aiPrimitiveType_TRIANGLE;
|
||||
pMesh->mMaterialIndex = lastMat + 1;
|
||||
faces = new std::vector<aiFace>();
|
||||
vertices = new std::vector<aiVector3D>();
|
||||
normals = new std::vector<aiVector3D>();
|
||||
texcoords = new std::vector<aiVector3D>();
|
||||
colors = new std::vector<aiColor4D>();
|
||||
vertexids = new std::vector<unsigned int>();
|
||||
}
|
||||
// add a face to temporary vector
|
||||
aiFace *pFace = new aiFace;
|
||||
pFace->mNumIndices = numpoly;
|
||||
pFace->mIndices = new unsigned int[numpoly];
|
||||
for(j = 0; j < numpoly; j++) {
|
||||
aiVector3D pos, uv, norm;
|
||||
k = vertices->size();
|
||||
pFace->mIndices[j] = k;
|
||||
l = m3d->face[i].vertex[j];
|
||||
pos.x = m3d->vertex[l].x;
|
||||
pos.y = m3d->vertex[l].y;
|
||||
pos.z = m3d->vertex[l].z;
|
||||
vertices->push_back(pos);
|
||||
colors->push_back(mkColor(m3d->vertex[l].color));
|
||||
// add a bone to temporary vector
|
||||
if(m3d->vertex[l].skinid != -1U &&m3d->vertex[l].skinid != -2U && m3d->skin && m3d->bone) {
|
||||
// this is complicated, because M3D stores a list of bone id / weight pairs per
|
||||
// vertex but assimp uses lists of local vertex id/weight pairs per local bone list
|
||||
vertexids->push_back(l);
|
||||
}
|
||||
l = m3d->face[i].texcoord[j];
|
||||
if(l != -1U) {
|
||||
uv.x = m3d->tmap[l].u;
|
||||
uv.y = m3d->tmap[l].v;
|
||||
uv.z = 0.0;
|
||||
texcoords->push_back(uv);
|
||||
}
|
||||
l = m3d->face[i].normal[j];
|
||||
if(l != -1U) {
|
||||
norm.x = m3d->vertex[l].x;
|
||||
norm.y = m3d->vertex[l].y;
|
||||
norm.z = m3d->vertex[l].z;
|
||||
normals->push_back(norm);
|
||||
}
|
||||
}
|
||||
faces->push_back(*pFace);
|
||||
delete pFace;
|
||||
}
|
||||
// if there's data left in the temporary vectors, flush them
|
||||
if(pMesh && vertices->size() && faces->size()) {
|
||||
populateMesh(pMesh, faces, vertices, normals, texcoords, colors, vertexids);
|
||||
meshes->push_back(pMesh);
|
||||
}
|
||||
|
||||
// create global mesh list in scene
|
||||
mScene->mNumMeshes = meshes->size();
|
||||
mScene->mMeshes = new aiMesh*[mScene->mNumMeshes];
|
||||
std::copy(meshes->begin(), meshes->end(), mScene->mMeshes);
|
||||
|
||||
// create mesh indeces in root node
|
||||
mScene->mRootNode->mNumMeshes = meshes->size();
|
||||
mScene->mRootNode->mMeshes = new unsigned int[meshes->size()];
|
||||
for(i = 0; i < meshes->size(); i++) {
|
||||
mScene->mRootNode->mMeshes[i] = i;
|
||||
}
|
||||
|
||||
delete meshes;
|
||||
if(faces) delete faces;
|
||||
if(vertices) delete vertices;
|
||||
if(normals) delete normals;
|
||||
if(texcoords) delete texcoords;
|
||||
if(colors) delete colors;
|
||||
if(vertexids) delete vertexids;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// a reentrant node parser. Otherwise this is simple
|
||||
void M3DImporter::importBones(unsigned int parentid, aiNode *pParent)
|
||||
{
|
||||
unsigned int i, n;
|
||||
|
||||
ai_assert(pParent != nullptr);
|
||||
ai_assert(mScene != nullptr);
|
||||
ai_assert(m3d != nullptr);
|
||||
|
||||
ASSIMP_LOG_DEBUG_F("M3D: importBones ", m3d->numbone, " parentid ", (int)parentid);
|
||||
|
||||
for(n = 0, i = parentid + 1; i < m3d->numbone; i++)
|
||||
if(m3d->bone[i].parent == parentid) n++;
|
||||
pParent->mChildren = new aiNode*[n];
|
||||
|
||||
for(i = parentid + 1; i < m3d->numbone; i++) {
|
||||
if(m3d->bone[i].parent == parentid) {
|
||||
aiNode *pChild = new aiNode;
|
||||
pChild->mParent = pParent;
|
||||
pChild->mName = aiString(std::string(m3d->bone[i].name));
|
||||
convertPose(&pChild->mTransformation, m3d->bone[i].pos, m3d->bone[i].ori);
|
||||
pChild->mNumChildren = 0;
|
||||
pParent->mChildren[pParent->mNumChildren] = pChild;
|
||||
pParent->mNumChildren++;
|
||||
importBones(i, pChild);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// this is another headache. M3D stores list of changed bone id/position/orientation triplets and
|
||||
// a timestamp per frame, but assimp needs timestamp and lists of position, orientation lists per
|
||||
// bone, so we have to convert between the two conceptually different representation forms
|
||||
void M3DImporter::importAnimations()
|
||||
{
|
||||
unsigned int i, j, k, l, pos, ori;
|
||||
double t;
|
||||
m3da_t *a;
|
||||
|
||||
ai_assert(mScene != nullptr);
|
||||
ai_assert(m3d != nullptr);
|
||||
|
||||
mScene->mNumAnimations = m3d->numaction;
|
||||
|
||||
ASSIMP_LOG_DEBUG_F("M3D: importAnimations ", mScene->mNumAnimations);
|
||||
|
||||
if(!m3d->numaction || !m3d->numbone)
|
||||
return;
|
||||
|
||||
mScene->mAnimations = new aiAnimation*[m3d->numaction];
|
||||
for(i = 0; i < m3d->numaction; i++) {
|
||||
a = &m3d->action[i];
|
||||
aiAnimation *pAnim = new aiAnimation;
|
||||
pAnim->mName = aiString(std::string(a->name));
|
||||
pAnim->mDuration = ((double)a->durationmsec) / 10;
|
||||
pAnim->mTicksPerSecond = 100;
|
||||
// now we know how many bones are referenced in this animation
|
||||
pAnim->mNumChannels = m3d->numbone;
|
||||
pAnim->mChannels = new aiNodeAnim*[pAnim->mNumChannels];
|
||||
for(l = 0; l < m3d->numbone; l++) {
|
||||
unsigned int n;
|
||||
pAnim->mChannels[l] = new aiNodeAnim;
|
||||
pAnim->mChannels[l]->mNodeName = aiString(std::string(m3d->bone[l].name));
|
||||
// now n is the size of positions / orientations arrays
|
||||
pAnim->mChannels[l]->mNumPositionKeys = pAnim->mChannels[l]->mNumRotationKeys = a->numframe;
|
||||
pAnim->mChannels[l]->mPositionKeys = new aiVectorKey[a->numframe];
|
||||
pAnim->mChannels[l]->mRotationKeys = new aiQuatKey[a->numframe];
|
||||
pos = m3d->bone[l].pos;
|
||||
ori = m3d->bone[l].ori;
|
||||
for(j = n = 0; j < a->numframe; j++) {
|
||||
t = ((double)a->frame[j].msec) / 10;
|
||||
for(k = 0; k < a->frame[j].numtransform; k++) {
|
||||
if(a->frame[j].transform[k].boneid == l) {
|
||||
pos = a->frame[j].transform[k].pos;
|
||||
ori = a->frame[j].transform[k].ori;
|
||||
}
|
||||
}
|
||||
m3dv_t *v = &m3d->vertex[pos];
|
||||
m3dv_t *q = &m3d->vertex[ori];
|
||||
pAnim->mChannels[l]->mPositionKeys[j].mTime = t;
|
||||
pAnim->mChannels[l]->mPositionKeys[j].mValue.x = v->x;
|
||||
pAnim->mChannels[l]->mPositionKeys[j].mValue.y = v->y;
|
||||
pAnim->mChannels[l]->mPositionKeys[j].mValue.z = v->z;
|
||||
pAnim->mChannels[l]->mRotationKeys[j].mTime = t;
|
||||
pAnim->mChannels[l]->mRotationKeys[j].mValue.w = q->w;
|
||||
pAnim->mChannels[l]->mRotationKeys[j].mValue.x = q->x;
|
||||
pAnim->mChannels[l]->mRotationKeys[j].mValue.y = q->y;
|
||||
pAnim->mChannels[l]->mRotationKeys[j].mValue.z = q->z;
|
||||
}// foreach frame
|
||||
}// foreach bones
|
||||
mScene->mAnimations[i] = pAnim;
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// convert uint32_t into aiColor4D
|
||||
aiColor4D M3DImporter::mkColor(uint32_t c) {
|
||||
aiColor4D color;
|
||||
color.a = ((float)((c >> 24)&0xff)) / 255;
|
||||
color.b = ((float)((c >> 16)&0xff)) / 255;
|
||||
color.g = ((float)((c >> 8)&0xff)) / 255;
|
||||
color.r = ((float)((c >> 0)&0xff)) / 255;
|
||||
return color;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// convert a position id and orientation id into a 4 x 4 transformation matrix
|
||||
void M3DImporter::convertPose(aiMatrix4x4 *m, unsigned int posid, unsigned int orientid)
|
||||
{
|
||||
ai_assert(m != nullptr);
|
||||
ai_assert(m3d != nullptr);
|
||||
ai_assert(posid != -1U && posid < m3d->numvertex);
|
||||
ai_assert(orientid != -1U && orientid < m3d->numvertex);
|
||||
m3dv_t *p = &m3d->vertex[posid];
|
||||
m3dv_t *q = &m3d->vertex[orientid];
|
||||
|
||||
/* quaternion to matrix. Do NOT use aiQuaternion to aiMatrix3x3, gives bad results */
|
||||
if(q->x == 0.0 && q->y == 0.0 && q->z >= 0.7071065 && q->z <= 0.7071075 && q->w == 0.0) {
|
||||
m->a2 = m->a3 = m->b1 = m->b3 = m->c1 = m->c2 = 0.0;
|
||||
m->a1 = m->b2 = m->c3 = -1.0;
|
||||
} else {
|
||||
m->a1 = 1 - 2 * (q->y * q->y + q->z * q->z); if(m->a1 > -M3D_EPSILON && m->a1 < M3D_EPSILON) m->a1 = 0.0;
|
||||
m->a2 = 2 * (q->x * q->y - q->z * q->w); if(m->a2 > -M3D_EPSILON && m->a2 < M3D_EPSILON) m->a2 = 0.0;
|
||||
m->a3 = 2 * (q->x * q->z + q->y * q->w); if(m->a3 > -M3D_EPSILON && m->a3 < M3D_EPSILON) m->a3 = 0.0;
|
||||
m->b1 = 2 * (q->x * q->y + q->z * q->w); if(m->b1 > -M3D_EPSILON && m->b1 < M3D_EPSILON) m->b1 = 0.0;
|
||||
m->b2 = 1 - 2 * (q->x * q->x + q->z * q->z); if(m->b2 > -M3D_EPSILON && m->b2 < M3D_EPSILON) m->b2 = 0.0;
|
||||
m->b3 = 2 * (q->y * q->z - q->x * q->w); if(m->b3 > -M3D_EPSILON && m->b3 < M3D_EPSILON) m->b3 = 0.0;
|
||||
m->c1 = 2 * (q->x * q->z - q->y * q->w); if(m->c1 > -M3D_EPSILON && m->c1 < M3D_EPSILON) m->c1 = 0.0;
|
||||
m->c2 = 2 * (q->y * q->z + q->x * q->w); if(m->c2 > -M3D_EPSILON && m->c2 < M3D_EPSILON) m->c2 = 0.0;
|
||||
m->c3 = 1 - 2 * (q->x * q->x + q->y * q->y); if(m->c3 > -M3D_EPSILON && m->c3 < M3D_EPSILON) m->c3 = 0.0;
|
||||
}
|
||||
|
||||
/* set translation */
|
||||
m->a4 = p->x; m->b4 = p->y; m->c4 = p->z;
|
||||
|
||||
m->d1 = 0; m->d2 = 0; m->d3 = 0; m->d4 = 1;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// find a node by name
|
||||
aiNode *M3DImporter::findNode(aiNode *pNode, aiString name)
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
ai_assert(pNode != nullptr);
|
||||
ai_assert(mScene != nullptr);
|
||||
|
||||
if(pNode->mName == name)
|
||||
return pNode;
|
||||
for(i = 0; i < pNode->mNumChildren; i++) {
|
||||
aiNode *pChild = findNode(pNode->mChildren[i], name);
|
||||
if(pChild) return pChild;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// fills up offsetmatrix in mBones
|
||||
void M3DImporter::calculateOffsetMatrix(aiNode *pNode, aiMatrix4x4 *m)
|
||||
{
|
||||
ai_assert(pNode != nullptr);
|
||||
ai_assert(mScene != nullptr);
|
||||
|
||||
if(pNode->mParent) {
|
||||
calculateOffsetMatrix(pNode->mParent, m);
|
||||
*m *= pNode->mTransformation;
|
||||
} else {
|
||||
*m = pNode->mTransformation;
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// because M3D has a global mesh, global vertex ids and stores materialid on the face, we need
|
||||
// temporary lists to collect data for an aiMesh, which requires local arrays and local indeces
|
||||
// this function fills up an aiMesh with those temporary lists
|
||||
void M3DImporter::populateMesh(aiMesh *pMesh, std::vector<aiFace> *faces, std::vector<aiVector3D> *vertices,
|
||||
std::vector<aiVector3D> *normals, std::vector<aiVector3D> *texcoords, std::vector<aiColor4D> *colors,
|
||||
std::vector<unsigned int> *vertexids) {
|
||||
|
||||
ai_assert(pMesh != nullptr);
|
||||
ai_assert(faces != nullptr);
|
||||
ai_assert(vertices != nullptr);
|
||||
ai_assert(normals != nullptr);
|
||||
ai_assert(texcoords != nullptr);
|
||||
ai_assert(colors != nullptr);
|
||||
ai_assert(vertexids != nullptr);
|
||||
ai_assert(m3d != nullptr);
|
||||
|
||||
ASSIMP_LOG_DEBUG_F("M3D: populateMesh numvertices ", vertices->size(), " numfaces ", faces->size(),
|
||||
" numnormals ", normals->size(), " numtexcoord ", texcoords->size(), " numbones ", m3d->numbone);
|
||||
|
||||
if(vertices->size() && faces->size()) {
|
||||
pMesh->mNumFaces = faces->size();
|
||||
pMesh->mFaces = new aiFace[pMesh->mNumFaces];
|
||||
std::copy(faces->begin(), faces->end(), pMesh->mFaces);
|
||||
pMesh->mNumVertices = vertices->size();
|
||||
pMesh->mVertices = new aiVector3D[pMesh->mNumVertices];
|
||||
std::copy(vertices->begin(), vertices->end(), pMesh->mVertices);
|
||||
if(normals->size() == vertices->size()) {
|
||||
pMesh->mNormals = new aiVector3D[pMesh->mNumVertices];
|
||||
std::copy(normals->begin(), normals->end(), pMesh->mNormals);
|
||||
}
|
||||
if(texcoords->size() == vertices->size()) {
|
||||
pMesh->mTextureCoords[0] = new aiVector3D[pMesh->mNumVertices];
|
||||
std::copy(texcoords->begin(), texcoords->end(), pMesh->mTextureCoords[0]);
|
||||
pMesh->mNumUVComponents[0] = 2;
|
||||
}
|
||||
if(colors->size() == vertices->size()) {
|
||||
pMesh->mColors[0] = new aiColor4D[pMesh->mNumVertices];
|
||||
std::copy(colors->begin(), colors->end(), pMesh->mColors[0]);
|
||||
}
|
||||
// this is complicated, because M3D stores a list of bone id / weight pairs per
|
||||
// vertex but assimp uses lists of local vertex id/weight pairs per local bone list
|
||||
pMesh->mNumBones = m3d->numbone;
|
||||
/* we need aiBone with mOffsetMatrix for bones without weights as well */
|
||||
if(pMesh->mNumBones) {
|
||||
pMesh->mBones = new aiBone*[pMesh->mNumBones];
|
||||
for(unsigned int i = 0; i < m3d->numbone; i++) {
|
||||
aiNode *pNode;
|
||||
pMesh->mBones[i] = new aiBone;
|
||||
pMesh->mBones[i]->mName = aiString(std::string(m3d->bone[i].name));
|
||||
pMesh->mBones[i]->mNumWeights = 0;
|
||||
pNode = findNode(mScene->mRootNode, pMesh->mBones[i]->mName);
|
||||
if(pNode) {
|
||||
calculateOffsetMatrix(pNode, &pMesh->mBones[i]->mOffsetMatrix);
|
||||
pMesh->mBones[i]->mOffsetMatrix.Inverse();
|
||||
} else
|
||||
pMesh->mBones[i]->mOffsetMatrix = aiMatrix4x4();
|
||||
}
|
||||
if(vertexids->size()) {
|
||||
unsigned int i, j;
|
||||
// first count how many vertices we have per bone
|
||||
for(i = 0; i < vertexids->size(); i++) {
|
||||
unsigned int s = m3d->vertex[vertexids->at(i)].skinid;
|
||||
if(s != -1U && s!= -2U) {
|
||||
for(unsigned int k = 0; k < M3D_NUMBONE && m3d->skin[s].weight[k] > 0.0; k++) {
|
||||
aiString name = aiString(std::string(m3d->bone[m3d->skin[s].boneid[k]].name));
|
||||
for(j = 0; j < pMesh->mNumBones; j++) {
|
||||
if(pMesh->mBones[j]->mName == name) {
|
||||
pMesh->mBones[j]->mNumWeights++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// allocate mWeights
|
||||
for(j = 0; j < pMesh->mNumBones; j++) {
|
||||
aiBone *pBone = pMesh->mBones[j];
|
||||
if(pBone->mNumWeights) {
|
||||
pBone->mWeights = new aiVertexWeight[pBone->mNumWeights];
|
||||
pBone->mNumWeights = 0;
|
||||
}
|
||||
}
|
||||
// fill up with data
|
||||
for(i = 0; i < vertexids->size(); i++) {
|
||||
unsigned int s = m3d->vertex[vertexids->at(i)].skinid;
|
||||
if(s != -1U && s!= -2U) {
|
||||
for(unsigned int k = 0; k < M3D_NUMBONE && m3d->skin[s].weight[k] > 0.0; k++) {
|
||||
aiString name = aiString(std::string(m3d->bone[m3d->skin[s].boneid[k]].name));
|
||||
for(j = 0; j < pMesh->mNumBones; j++) {
|
||||
if(pMesh->mBones[j]->mName == name) {
|
||||
aiBone *pBone = pMesh->mBones[j];
|
||||
pBone->mWeights[pBone->mNumWeights].mVertexId = i;
|
||||
pBone->mWeights[pBone->mNumWeights].mWeight = m3d->skin[s].weight[k];
|
||||
pBone->mNumWeights++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} // foreach skin
|
||||
}
|
||||
} // foreach vertexids
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
||||
} // Namespace Assimp
|
||||
|
||||
#endif // !! ASSIMP_BUILD_NO_M3D_IMPORTER
|
||||
@@ -0,0 +1,106 @@
|
||||
/*
|
||||
Open Asset Import Library (assimp)
|
||||
----------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2019, assimp team
|
||||
Copyright (c) 2019 bzt
|
||||
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use of this software in source and binary forms,
|
||||
with or without modification, are permitted provided that the
|
||||
following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above
|
||||
copyright notice, this list of conditions and the
|
||||
following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above
|
||||
copyright notice, this list of conditions and the
|
||||
following disclaimer in the documentation and/or other
|
||||
materials provided with the distribution.
|
||||
|
||||
* Neither the name of the assimp team, nor the names of its
|
||||
contributors may be used to endorse or promote products
|
||||
derived from this software without specific prior
|
||||
written permission of the assimp team.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
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.
|
||||
|
||||
----------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/** @file M3DImporter.h
|
||||
* @brief Declares the importer class to read a scene from a Model 3D file
|
||||
*/
|
||||
#ifndef AI_M3DIMPORTER_H_INC
|
||||
#define AI_M3DIMPORTER_H_INC
|
||||
|
||||
#ifndef ASSIMP_BUILD_NO_M3D_IMPORTER
|
||||
|
||||
#include "m3d.h"
|
||||
#include <assimp/BaseImporter.h>
|
||||
#include <assimp/material.h>
|
||||
#include <vector>
|
||||
|
||||
struct aiMesh;
|
||||
struct aiNode;
|
||||
struct aiMaterial;
|
||||
struct aiFace;
|
||||
|
||||
namespace Assimp {
|
||||
|
||||
class M3DImporter : public BaseImporter {
|
||||
public:
|
||||
/// \brief Default constructor
|
||||
M3DImporter();
|
||||
|
||||
/// \brief Destructor
|
||||
~M3DImporter();
|
||||
|
||||
public:
|
||||
/// \brief Returns whether the class can handle the format of the given file.
|
||||
/// \remark See BaseImporter::CanRead() for details.
|
||||
bool CanRead( const std::string& pFile, IOSystem* pIOHandler, bool checkSig) const;
|
||||
|
||||
private:
|
||||
aiScene* mScene; // the scene to import to
|
||||
m3d_t *m3d; // model for the C library to convert from
|
||||
|
||||
//! \brief Appends the supported extension.
|
||||
const aiImporterDesc* GetInfo () const;
|
||||
|
||||
//! \brief File import implementation.
|
||||
void InternReadFile(const std::string& pFile, aiScene* pScene, IOSystem* pIOHandler);
|
||||
|
||||
void importMaterials();
|
||||
void importTextures();
|
||||
void importMeshes();
|
||||
void importBones(unsigned int parentid, aiNode *pParent);
|
||||
void importAnimations();
|
||||
|
||||
// helper functions
|
||||
aiColor4D mkColor(uint32_t c);
|
||||
void convertPose(aiMatrix4x4 *m, unsigned int posid, unsigned int orientid);
|
||||
aiNode *findNode(aiNode *pNode, aiString name);
|
||||
void calculateOffsetMatrix(aiNode *pNode, aiMatrix4x4 *m);
|
||||
void populateMesh(aiMesh *pMesh, std::vector<aiFace> *faces, std::vector<aiVector3D> *verteces,
|
||||
std::vector<aiVector3D> *normals, std::vector<aiVector3D> *texcoords, std::vector<aiColor4D> *colors,
|
||||
std::vector<unsigned int> *vertexids);
|
||||
};
|
||||
|
||||
} // Namespace Assimp
|
||||
|
||||
#endif // ASSIMP_BUILD_NO_M3D_IMPORTER
|
||||
|
||||
#endif // AI_M3DIMPORTER_H_INC
|
||||
@@ -0,0 +1,106 @@
|
||||
/*
|
||||
Open Asset Import Library (assimp)
|
||||
----------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2019, assimp team
|
||||
Copyright (c) 2019 bzt
|
||||
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use of this software in source and binary forms,
|
||||
with or without modification, are permitted provided that the
|
||||
following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above
|
||||
copyright notice, this list of conditions and the
|
||||
following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above
|
||||
copyright notice, this list of conditions and the
|
||||
following disclaimer in the documentation and/or other
|
||||
materials provided with the distribution.
|
||||
|
||||
* Neither the name of the assimp team, nor the names of its
|
||||
contributors may be used to endorse or promote products
|
||||
derived from this software without specific prior
|
||||
written permission of the assimp team.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
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.
|
||||
|
||||
----------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/** @file M3DMaterials.h
|
||||
* @brief Declares the Assimp and Model 3D file material type relations
|
||||
*/
|
||||
#ifndef AI_M3DMATERIALS_H_INC
|
||||
#define AI_M3DMATERIALS_H_INC
|
||||
|
||||
/*
|
||||
* In the m3d.h header, there's a static array which defines the material
|
||||
* properties, called m3d_propertytypes. These must have the same size, and
|
||||
* list the matching Assimp materials for those properties. Used by both the
|
||||
* M3DImporter and the M3DExporter, so you have to define these relations
|
||||
* only once. D.R.Y. and K.I.S.S.
|
||||
*/
|
||||
typedef struct {
|
||||
const char *pKey;
|
||||
unsigned int type;
|
||||
unsigned int index;
|
||||
} aiMatProp;
|
||||
|
||||
/* --- Scalar Properties --- !!!!! must match m3d_propertytypes !!!!! */
|
||||
static const aiMatProp aiProps[] = {
|
||||
{ AI_MATKEY_COLOR_DIFFUSE }, /* m3dp_Kd */
|
||||
{ AI_MATKEY_COLOR_AMBIENT }, /* m3dp_Ka */
|
||||
{ AI_MATKEY_COLOR_SPECULAR }, /* m3dp_Ks */
|
||||
{ AI_MATKEY_SHININESS }, /* m3dp_Ns */
|
||||
{ AI_MATKEY_COLOR_EMISSIVE }, /* m3dp_Ke */
|
||||
{ AI_MATKEY_COLOR_REFLECTIVE }, /* m3dp_Tf */
|
||||
{ AI_MATKEY_BUMPSCALING }, /* m3dp_Km */
|
||||
{ AI_MATKEY_OPACITY }, /* m3dp_d */
|
||||
{ AI_MATKEY_SHADING_MODEL }, /* m3dp_il */
|
||||
|
||||
{ NULL, 0, 0 }, /* m3dp_Pr */
|
||||
{ AI_MATKEY_REFLECTIVITY }, /* m3dp_Pm */
|
||||
{ NULL, 0, 0 }, /* m3dp_Ps */
|
||||
{ AI_MATKEY_REFRACTI }, /* m3dp_Ni */
|
||||
{ NULL, 0, 0 }, /* m3dp_Nt */
|
||||
{ NULL, 0, 0 },
|
||||
{ NULL, 0, 0 },
|
||||
{ NULL, 0, 0 }
|
||||
};
|
||||
|
||||
/* --- Texture Map Properties --- !!!!! must match m3d_propertytypes !!!!! */
|
||||
static const aiMatProp aiTxProps[] = {
|
||||
{ AI_MATKEY_TEXTURE_DIFFUSE(0) }, /* m3dp_map_Kd */
|
||||
{ AI_MATKEY_TEXTURE_AMBIENT(0) }, /* m3dp_map_Ka */
|
||||
{ AI_MATKEY_TEXTURE_SPECULAR(0) }, /* m3dp_map_Ks */
|
||||
{ AI_MATKEY_TEXTURE_SHININESS(0) }, /* m3dp_map_Ns */
|
||||
{ AI_MATKEY_TEXTURE_EMISSIVE(0) }, /* m3dp_map_Ke */
|
||||
{ NULL, 0, 0 }, /* m3dp_map_Tf */
|
||||
{ AI_MATKEY_TEXTURE_HEIGHT(0) }, /* m3dp_bump */
|
||||
{ AI_MATKEY_TEXTURE_OPACITY(0) }, /* m3dp_map_d */
|
||||
{ AI_MATKEY_TEXTURE_REFLECTION(0) }, /* m3dp_refl */
|
||||
|
||||
{ AI_MATKEY_TEXTURE(aiTextureType_DIFFUSE_ROUGHNESS,0) },/* m3dp_map_Pr */
|
||||
{ AI_MATKEY_TEXTURE(aiTextureType_METALNESS,0) }, /* m3dp_map_Pm */
|
||||
{ NULL, 0, 0 }, /* m3dp_map_Ps */
|
||||
{ AI_MATKEY_TEXTURE(aiTextureType_AMBIENT_OCCLUSION,0) },/* m3dp_map_Ni */
|
||||
{ NULL, 0, 0 }, /* m3dp_map_Nt */
|
||||
{ NULL, 0, 0 },
|
||||
{ NULL, 0, 0 },
|
||||
{ NULL, 0, 0 }
|
||||
};
|
||||
|
||||
#endif // AI_M3DMATERIALS_H_INC
|
||||
+5568
File diff suppressed because it is too large
Load Diff
@@ -52,7 +52,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#include "MDL/MDLDefaultColorMap.h"
|
||||
#include "MD2/MD2FileData.h"
|
||||
|
||||
#include <assimp/Macros.h>
|
||||
#include <assimp/qnan.h>
|
||||
#include <assimp/StringUtils.h>
|
||||
#include <assimp/Importer.hpp>
|
||||
|
||||
@@ -51,7 +51,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#include <assimp/types.h>
|
||||
#include <assimp/material.h>
|
||||
#include <assimp/DefaultLogger.hpp>
|
||||
#include <assimp/Macros.h>
|
||||
|
||||
using namespace Assimp;
|
||||
|
||||
@@ -472,12 +471,12 @@ aiReturn aiMaterial::AddBinaryProperty (const void* pInput,
|
||||
aiPropertyTypeInfo pType
|
||||
)
|
||||
{
|
||||
ai_assert( pInput != NULL );
|
||||
ai_assert( pKey != NULL );
|
||||
ai_assert( pInput != nullptr );
|
||||
ai_assert(pKey != nullptr );
|
||||
ai_assert( 0 != pSizeInBytes );
|
||||
|
||||
if ( 0 == pSizeInBytes ) {
|
||||
|
||||
return AI_FAILURE;
|
||||
}
|
||||
|
||||
// first search the list whether there is already an entry with this key
|
||||
|
||||
@@ -49,7 +49,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
// internal headers
|
||||
#include "PlyLoader.h"
|
||||
#include <assimp/IOStreamBuffer.h>
|
||||
#include <assimp/Macros.h>
|
||||
#include <memory>
|
||||
#include <assimp/IOSystem.hpp>
|
||||
#include <assimp/scene.h>
|
||||
|
||||
@@ -0,0 +1,268 @@
|
||||
/*
|
||||
Open Asset Import Library (assimp)
|
||||
----------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2019, assimp team
|
||||
|
||||
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use of this software in source and binary forms,
|
||||
with or without modification, are permitted provided that the
|
||||
following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above
|
||||
copyright notice, this list of conditions and the
|
||||
following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above
|
||||
copyright notice, this list of conditions and the
|
||||
following disclaimer in the documentation and/or other
|
||||
materials provided with the distribution.
|
||||
|
||||
* Neither the name of the assimp team, nor the names of its
|
||||
contributors may be used to endorse or promote products
|
||||
derived from this software without specific prior
|
||||
written permission of the assimp team.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
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.
|
||||
|
||||
----------------------------------------------------------------------
|
||||
*/
|
||||
#include "ArmaturePopulate.h"
|
||||
|
||||
#include <assimp/BaseImporter.h>
|
||||
#include <assimp/DefaultLogger.hpp>
|
||||
#include <assimp/postprocess.h>
|
||||
#include <assimp/scene.h>
|
||||
#include <iostream>
|
||||
|
||||
namespace Assimp {
|
||||
|
||||
/// The default class constructor.
|
||||
ArmaturePopulate::ArmaturePopulate() : BaseProcess()
|
||||
{}
|
||||
|
||||
/// The class destructor.
|
||||
ArmaturePopulate::~ArmaturePopulate()
|
||||
{}
|
||||
|
||||
bool ArmaturePopulate::IsActive(unsigned int pFlags) const {
|
||||
return (pFlags & aiProcess_PopulateArmatureData) != 0;
|
||||
}
|
||||
|
||||
void ArmaturePopulate::SetupProperties(const Importer *pImp) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
void ArmaturePopulate::Execute(aiScene *out) {
|
||||
|
||||
// Now convert all bone positions to the correct mOffsetMatrix
|
||||
std::vector<aiBone *> bones;
|
||||
std::vector<aiNode *> nodes;
|
||||
std::map<aiBone *, aiNode *> bone_stack;
|
||||
BuildBoneList(out->mRootNode, out->mRootNode, out, bones);
|
||||
BuildNodeList(out->mRootNode, nodes);
|
||||
|
||||
BuildBoneStack(out->mRootNode, out->mRootNode, out, bones, bone_stack, nodes);
|
||||
|
||||
ASSIMP_LOG_DEBUG_F("Bone stack size: ", bone_stack.size());
|
||||
|
||||
for (std::pair<aiBone *, aiNode *> kvp : bone_stack) {
|
||||
aiBone *bone = kvp.first;
|
||||
aiNode *bone_node = kvp.second;
|
||||
ASSIMP_LOG_DEBUG_F("active node lookup: ", bone->mName.C_Str());
|
||||
// lcl transform grab - done in generate_nodes :)
|
||||
|
||||
// bone->mOffsetMatrix = bone_node->mTransformation;
|
||||
aiNode *armature = GetArmatureRoot(bone_node, bones);
|
||||
|
||||
ai_assert(armature);
|
||||
|
||||
// set up bone armature id
|
||||
bone->mArmature = armature;
|
||||
|
||||
// set this bone node to be referenced properly
|
||||
ai_assert(bone_node);
|
||||
bone->mNode = bone_node;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Reprocess all nodes to calculate bone transforms properly based on the REAL
|
||||
* mOffsetMatrix not the local. */
|
||||
/* Before this would use mesh transforms which is wrong for bone transforms */
|
||||
/* Before this would work for simple character skeletons but not complex meshes
|
||||
* with multiple origins */
|
||||
/* Source: sketch fab log cutter fbx */
|
||||
void ArmaturePopulate::BuildBoneList(aiNode *current_node,
|
||||
const aiNode *root_node,
|
||||
const aiScene *scene,
|
||||
std::vector<aiBone *> &bones) {
|
||||
ai_assert(scene);
|
||||
for (unsigned int nodeId = 0; nodeId < current_node->mNumChildren; ++nodeId) {
|
||||
aiNode *child = current_node->mChildren[nodeId];
|
||||
ai_assert(child);
|
||||
|
||||
// check for bones
|
||||
for (unsigned int meshId = 0; meshId < child->mNumMeshes; ++meshId) {
|
||||
ai_assert(child->mMeshes);
|
||||
unsigned int mesh_index = child->mMeshes[meshId];
|
||||
aiMesh *mesh = scene->mMeshes[mesh_index];
|
||||
ai_assert(mesh);
|
||||
|
||||
for (unsigned int boneId = 0; boneId < mesh->mNumBones; ++boneId) {
|
||||
aiBone *bone = mesh->mBones[boneId];
|
||||
ai_assert(bone);
|
||||
|
||||
// duplicate meshes exist with the same bones sometimes :)
|
||||
// so this must be detected
|
||||
if (std::find(bones.begin(), bones.end(), bone) == bones.end()) {
|
||||
// add the element once
|
||||
bones.push_back(bone);
|
||||
}
|
||||
}
|
||||
|
||||
// find mesh and get bones
|
||||
// then do recursive lookup for bones in root node hierarchy
|
||||
}
|
||||
|
||||
BuildBoneList(child, root_node, scene, bones);
|
||||
}
|
||||
}
|
||||
|
||||
/* Prepare flat node list which can be used for non recursive lookups later */
|
||||
void ArmaturePopulate::BuildNodeList(const aiNode *current_node,
|
||||
std::vector<aiNode *> &nodes) {
|
||||
ai_assert(current_node);
|
||||
|
||||
for (unsigned int nodeId = 0; nodeId < current_node->mNumChildren; ++nodeId) {
|
||||
aiNode *child = current_node->mChildren[nodeId];
|
||||
ai_assert(child);
|
||||
|
||||
nodes.push_back(child);
|
||||
|
||||
BuildNodeList(child, nodes);
|
||||
}
|
||||
}
|
||||
|
||||
/* A bone stack allows us to have multiple armatures, with the same bone names
|
||||
* A bone stack allows us also to retrieve bones true transform even with
|
||||
* duplicate names :)
|
||||
*/
|
||||
void ArmaturePopulate::BuildBoneStack(aiNode *current_node,
|
||||
const aiNode *root_node,
|
||||
const aiScene *scene,
|
||||
const std::vector<aiBone *> &bones,
|
||||
std::map<aiBone *, aiNode *> &bone_stack,
|
||||
std::vector<aiNode *> &node_stack) {
|
||||
ai_assert(scene);
|
||||
ai_assert(root_node);
|
||||
ai_assert(!node_stack.empty());
|
||||
|
||||
for (aiBone *bone : bones) {
|
||||
ai_assert(bone);
|
||||
aiNode *node = GetNodeFromStack(bone->mName, node_stack);
|
||||
if (node == nullptr) {
|
||||
node_stack.clear();
|
||||
BuildNodeList(root_node, node_stack);
|
||||
ASSIMP_LOG_DEBUG_F("Resetting bone stack: nullptr element ", bone->mName.C_Str());
|
||||
|
||||
node = GetNodeFromStack(bone->mName, node_stack);
|
||||
|
||||
if (!node) {
|
||||
ASSIMP_LOG_ERROR("serious import issue node for bone was not detected");
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
ASSIMP_LOG_DEBUG_F("Successfully added bone[", bone->mName.C_Str(), "] to stack and bone node is: ", node->mName.C_Str());
|
||||
|
||||
bone_stack.insert(std::pair<aiBone *, aiNode *>(bone, node));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Returns the armature root node */
|
||||
/* This is required to be detected for a bone initially, it will recurse up
|
||||
* until it cannot find another bone and return the node No known failure
|
||||
* points. (yet)
|
||||
*/
|
||||
aiNode *ArmaturePopulate::GetArmatureRoot(aiNode *bone_node,
|
||||
std::vector<aiBone *> &bone_list) {
|
||||
while (bone_node) {
|
||||
if (!IsBoneNode(bone_node->mName, bone_list)) {
|
||||
ASSIMP_LOG_DEBUG_F("GetArmatureRoot() Found valid armature: ", bone_node->mName.C_Str());
|
||||
return bone_node;
|
||||
}
|
||||
|
||||
bone_node = bone_node->mParent;
|
||||
}
|
||||
|
||||
ASSIMP_LOG_ERROR("GetArmatureRoot() can't find armature!");
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* Simple IsBoneNode check if this could be a bone */
|
||||
bool ArmaturePopulate::IsBoneNode(const aiString &bone_name,
|
||||
std::vector<aiBone *> &bones) {
|
||||
for (aiBone *bone : bones) {
|
||||
if (bone->mName == bone_name) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Pop this node by name from the stack if found */
|
||||
/* Used in multiple armature situations with duplicate node / bone names */
|
||||
/* Known flaw: cannot have nodes with bone names, will be fixed in later release
|
||||
*/
|
||||
/* (serious to be fixed) Known flaw: nodes which have more than one bone could
|
||||
* be prematurely dropped from stack */
|
||||
aiNode *ArmaturePopulate::GetNodeFromStack(const aiString &node_name,
|
||||
std::vector<aiNode *> &nodes) {
|
||||
std::vector<aiNode *>::iterator iter;
|
||||
aiNode *found = nullptr;
|
||||
for (iter = nodes.begin(); iter < nodes.end(); ++iter) {
|
||||
aiNode *element = *iter;
|
||||
ai_assert(element);
|
||||
// node valid and node name matches
|
||||
if (element->mName == node_name) {
|
||||
found = element;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (found != nullptr) {
|
||||
ASSIMP_LOG_INFO_F("Removed node from stack: ", found->mName.C_Str());
|
||||
// now pop the element from the node list
|
||||
nodes.erase(iter);
|
||||
|
||||
return found;
|
||||
}
|
||||
|
||||
// unique names can cause this problem
|
||||
ASSIMP_LOG_ERROR("[Serious] GetNodeFromStack() can't find node from stack!");
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
} // Namespace Assimp
|
||||
@@ -0,0 +1,112 @@
|
||||
/*
|
||||
Open Asset Import Library (assimp)
|
||||
----------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2019, assimp team
|
||||
|
||||
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use of this software in source and binary forms,
|
||||
with or without modification, are permitted provided that the
|
||||
following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above
|
||||
copyright notice, this list of conditions and the
|
||||
following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above
|
||||
copyright notice, this list of conditions and the
|
||||
following disclaimer in the documentation and/or other
|
||||
materials provided with the distribution.
|
||||
|
||||
* Neither the name of the assimp team, nor the names of its
|
||||
contributors may be used to endorse or promote products
|
||||
derived from this software without specific prior
|
||||
written permission of the assimp team.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
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 ARMATURE_POPULATE_H_
|
||||
#define ARMATURE_POPULATE_H_
|
||||
|
||||
#include "Common/BaseProcess.h"
|
||||
#include <assimp/BaseImporter.h>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
|
||||
|
||||
struct aiNode;
|
||||
struct aiBone;
|
||||
|
||||
namespace Assimp {
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
/** Armature Populate: This is a post process designed
|
||||
* To save you time when importing models into your game engines
|
||||
* This was originally designed only for fbx but will work with other formats
|
||||
* it is intended to auto populate aiBone data with armature and the aiNode
|
||||
* This is very useful when dealing with skinned meshes
|
||||
* or when dealing with many different skeletons
|
||||
* It's off by default but recommend that you try it and use it
|
||||
* It should reduce down any glue code you have in your
|
||||
* importers
|
||||
* You can contact RevoluPowered <gordon@gordonite.tech>
|
||||
* For more info about this
|
||||
*/
|
||||
class ASSIMP_API ArmaturePopulate : public BaseProcess {
|
||||
public:
|
||||
/// The default class constructor.
|
||||
ArmaturePopulate();
|
||||
|
||||
/// The class destructor.
|
||||
virtual ~ArmaturePopulate();
|
||||
|
||||
/// Overwritten, @see BaseProcess
|
||||
virtual bool IsActive( unsigned int pFlags ) const;
|
||||
|
||||
/// Overwritten, @see BaseProcess
|
||||
virtual void SetupProperties( const Importer* pImp );
|
||||
|
||||
/// Overwritten, @see BaseProcess
|
||||
virtual void Execute( aiScene* pScene );
|
||||
|
||||
static aiNode *GetArmatureRoot(aiNode *bone_node,
|
||||
std::vector<aiBone *> &bone_list);
|
||||
|
||||
static bool IsBoneNode(const aiString &bone_name,
|
||||
std::vector<aiBone *> &bones);
|
||||
|
||||
static aiNode *GetNodeFromStack(const aiString &node_name,
|
||||
std::vector<aiNode *> &nodes);
|
||||
|
||||
static void BuildNodeList(const aiNode *current_node,
|
||||
std::vector<aiNode *> &nodes);
|
||||
|
||||
static void BuildBoneList(aiNode *current_node, const aiNode *root_node,
|
||||
const aiScene *scene,
|
||||
std::vector<aiBone *> &bones);
|
||||
|
||||
static void BuildBoneStack(aiNode *current_node, const aiNode *root_node,
|
||||
const aiScene *scene,
|
||||
const std::vector<aiBone *> &bones,
|
||||
std::map<aiBone *, aiNode *> &bone_stack,
|
||||
std::vector<aiNode *> &node_stack);
|
||||
};
|
||||
|
||||
} // Namespace Assimp
|
||||
|
||||
|
||||
#endif // SCALE_PROCESS_H_
|
||||
@@ -52,7 +52,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#include "FindInvalidDataProcess.h"
|
||||
#include "ProcessHelper.h"
|
||||
|
||||
#include <assimp/Macros.h>
|
||||
#include <assimp/Exceptional.h>
|
||||
#include <assimp/qnan.h>
|
||||
|
||||
|
||||
@@ -538,13 +538,17 @@ void ValidateDSProcess::Validate( const aiAnimation* pAnimation)
|
||||
{
|
||||
Validate(&pAnimation->mName);
|
||||
|
||||
// validate all materials
|
||||
if (pAnimation->mNumChannels)
|
||||
// validate all animations
|
||||
if (pAnimation->mNumChannels || pAnimation->mNumMorphMeshChannels)
|
||||
{
|
||||
if (!pAnimation->mChannels) {
|
||||
if (!pAnimation->mChannels && pAnimation->mNumChannels) {
|
||||
ReportError("aiAnimation::mChannels is NULL (aiAnimation::mNumChannels is %i)",
|
||||
pAnimation->mNumChannels);
|
||||
}
|
||||
if (!pAnimation->mMorphMeshChannels && pAnimation->mNumMorphMeshChannels) {
|
||||
ReportError("aiAnimation::mMorphMeshChannels is NULL (aiAnimation::mNumMorphMeshChannels is %i)",
|
||||
pAnimation->mNumMorphMeshChannels);
|
||||
}
|
||||
for (unsigned int i = 0; i < pAnimation->mNumChannels;++i)
|
||||
{
|
||||
if (!pAnimation->mChannels[i])
|
||||
@@ -554,6 +558,15 @@ void ValidateDSProcess::Validate( const aiAnimation* pAnimation)
|
||||
}
|
||||
Validate(pAnimation, pAnimation->mChannels[i]);
|
||||
}
|
||||
for (unsigned int i = 0; i < pAnimation->mNumMorphMeshChannels;++i)
|
||||
{
|
||||
if (!pAnimation->mMorphMeshChannels[i])
|
||||
{
|
||||
ReportError("aiAnimation::mMorphMeshChannels[%i] is NULL (aiAnimation::mNumMorphMeshChannels is %i)",
|
||||
i, pAnimation->mNumMorphMeshChannels);
|
||||
}
|
||||
Validate(pAnimation, pAnimation->mMorphMeshChannels[i]);
|
||||
}
|
||||
}
|
||||
else {
|
||||
ReportError("aiAnimation::mNumChannels is 0. At least one node animation channel must be there.");
|
||||
@@ -590,15 +603,18 @@ void ValidateDSProcess::SearchForInvalidTextures(const aiMaterial* pMaterial,
|
||||
ReportError("%s #%i is set, but there are only %i %s textures",
|
||||
szType,iIndex,iNumIndices,szType);
|
||||
}
|
||||
if (!iNumIndices)return;
|
||||
if (!iNumIndices) {
|
||||
return;
|
||||
}
|
||||
std::vector<aiTextureMapping> mappings(iNumIndices);
|
||||
|
||||
// Now check whether all UV indices are valid ...
|
||||
bool bNoSpecified = true;
|
||||
for (unsigned int i = 0; i < pMaterial->mNumProperties;++i)
|
||||
{
|
||||
for (unsigned int i = 0; i < pMaterial->mNumProperties;++i) {
|
||||
aiMaterialProperty* prop = pMaterial->mProperties[i];
|
||||
if (prop->mSemantic != type)continue;
|
||||
if (prop->mSemantic != type) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ((int)prop->mIndex >= iNumIndices)
|
||||
{
|
||||
@@ -621,7 +637,7 @@ void ValidateDSProcess::SearchForInvalidTextures(const aiMaterial* pMaterial,
|
||||
ReportError("Material property %s%i is expected to be 5 floats large (size is %i)",
|
||||
prop->mKey.data,prop->mIndex, prop->mDataLength);
|
||||
}
|
||||
mappings[prop->mIndex] = *((aiTextureMapping*)prop->mData);
|
||||
//mappings[prop->mIndex] = ((aiUVTransform*)prop->mData);
|
||||
}
|
||||
else if (!::strcmp(prop->mKey.data,"$tex.uvwsrc")) {
|
||||
if (aiPTI_Integer != prop->mType || sizeof(int) > prop->mDataLength)
|
||||
@@ -903,6 +919,48 @@ void ValidateDSProcess::Validate( const aiAnimation* pAnimation,
|
||||
}
|
||||
}
|
||||
|
||||
void ValidateDSProcess::Validate( const aiAnimation* pAnimation,
|
||||
const aiMeshMorphAnim* pMeshMorphAnim)
|
||||
{
|
||||
Validate(&pMeshMorphAnim->mName);
|
||||
|
||||
if (!pMeshMorphAnim->mNumKeys) {
|
||||
ReportError("Empty mesh morph animation channel");
|
||||
}
|
||||
|
||||
// otherwise check whether one of the keys exceeds the total duration of the animation
|
||||
if (pMeshMorphAnim->mNumKeys)
|
||||
{
|
||||
if (!pMeshMorphAnim->mKeys)
|
||||
{
|
||||
ReportError("aiMeshMorphAnim::mKeys is NULL (aiMeshMorphAnim::mNumKeys is %i)",
|
||||
pMeshMorphAnim->mNumKeys);
|
||||
}
|
||||
double dLast = -10e10;
|
||||
for (unsigned int i = 0; i < pMeshMorphAnim->mNumKeys;++i)
|
||||
{
|
||||
// ScenePreprocessor will compute the duration if still the default value
|
||||
// (Aramis) Add small epsilon, comparison tended to fail if max_time == duration,
|
||||
// seems to be due the compilers register usage/width.
|
||||
if (pAnimation->mDuration > 0. && pMeshMorphAnim->mKeys[i].mTime > pAnimation->mDuration+0.001)
|
||||
{
|
||||
ReportError("aiMeshMorphAnim::mKeys[%i].mTime (%.5f) is larger "
|
||||
"than aiAnimation::mDuration (which is %.5f)",i,
|
||||
(float)pMeshMorphAnim->mKeys[i].mTime,
|
||||
(float)pAnimation->mDuration);
|
||||
}
|
||||
if (i && pMeshMorphAnim->mKeys[i].mTime <= dLast)
|
||||
{
|
||||
ReportWarning("aiMeshMorphAnim::mKeys[%i].mTime (%.5f) is smaller "
|
||||
"than aiMeshMorphAnim::mKeys[%i] (which is %.5f)",i,
|
||||
(float)pMeshMorphAnim->mKeys[i].mTime,
|
||||
i-1, (float)dLast);
|
||||
}
|
||||
dLast = pMeshMorphAnim->mKeys[i].mTime;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void ValidateDSProcess::Validate( const aiNode* pNode)
|
||||
{
|
||||
|
||||
@@ -55,6 +55,7 @@ struct aiBone;
|
||||
struct aiMesh;
|
||||
struct aiAnimation;
|
||||
struct aiNodeAnim;
|
||||
struct aiMeshMorphAnim;
|
||||
struct aiTexture;
|
||||
struct aiMaterial;
|
||||
struct aiNode;
|
||||
@@ -150,6 +151,13 @@ protected:
|
||||
void Validate( const aiAnimation* pAnimation,
|
||||
const aiNodeAnim* pBoneAnim);
|
||||
|
||||
/** Validates a mesh morph animation channel.
|
||||
* @param pAnimation Input animation.
|
||||
* @param pMeshMorphAnim Mesh morph animation channel.
|
||||
* */
|
||||
void Validate( const aiAnimation* pAnimation,
|
||||
const aiMeshMorphAnim* pMeshMorphAnim);
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
/** Validates a node and all of its subnodes
|
||||
* @param Node Input node*/
|
||||
|
||||
@@ -1427,9 +1427,6 @@ inline void Asset::ReadExtensionsUsed(Document& doc)
|
||||
}
|
||||
}
|
||||
|
||||
#define CHECK_EXT(EXT) \
|
||||
if (exts.find(#EXT) != exts.end()) extensionsUsed.EXT = true;
|
||||
|
||||
CHECK_EXT(KHR_binary_glTF);
|
||||
CHECK_EXT(KHR_materials_common);
|
||||
|
||||
|
||||
+7
-10
@@ -188,7 +188,7 @@ namespace glTFCommon {
|
||||
size_t DecodeBase64(const char* in, size_t inLength, uint8_t*& out);
|
||||
|
||||
inline
|
||||
size_t DecodeBase64(const char* in, uint8_t*& out) {
|
||||
size_t DecodeBase64(const char* in, uint8_t*& out) {
|
||||
return DecodeBase64(in, strlen(in), out);
|
||||
}
|
||||
|
||||
@@ -221,25 +221,22 @@ namespace glTFCommon {
|
||||
};
|
||||
|
||||
inline
|
||||
char EncodeCharBase64(uint8_t b) {
|
||||
char EncodeCharBase64(uint8_t b) {
|
||||
return "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="[size_t(b)];
|
||||
}
|
||||
|
||||
inline
|
||||
uint8_t DecodeCharBase64(char c) {
|
||||
uint8_t DecodeCharBase64(char c) {
|
||||
return DATA<true>::tableDecodeBase64[size_t(c)]; // TODO faster with lookup table or ifs?
|
||||
/*if (c >= 'A' && c <= 'Z') return c - 'A';
|
||||
if (c >= 'a' && c <= 'z') return c - 'a' + 26;
|
||||
if (c >= '0' && c <= '9') return c - '0' + 52;
|
||||
if (c == '+') return 62;
|
||||
if (c == '/') return 63;
|
||||
return 64; // '-' */
|
||||
}
|
||||
|
||||
size_t DecodeBase64(const char* in, size_t inLength, uint8_t*& out);
|
||||
|
||||
void EncodeBase64(const uint8_t* in, size_t inLength, std::string& out);
|
||||
}
|
||||
} // namespace Util
|
||||
|
||||
#define CHECK_EXT(EXT) \
|
||||
if (exts.find(#EXT) != exts.end()) extensionsUsed.EXT = true;
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -170,6 +170,8 @@ void glTFImporter::ImportMaterials(glTF::Asset& r) {
|
||||
|
||||
if (mScene->mNumMaterials == 0) {
|
||||
mScene->mNumMaterials = 1;
|
||||
// Delete the array of length zero created above.
|
||||
delete[] mScene->mMaterials;
|
||||
mScene->mMaterials = new aiMaterial*[1];
|
||||
mScene->mMaterials[0] = new aiMaterial();
|
||||
}
|
||||
@@ -330,6 +332,10 @@ void glTFImporter::ImportMeshes(glTF::Asset& r)
|
||||
|
||||
case PrimitiveMode_LINES: {
|
||||
nFaces = count / 2;
|
||||
if (nFaces * 2 != count) {
|
||||
ASSIMP_LOG_WARN("The number of vertices was not compatible with the LINES mode. Some vertices were dropped.");
|
||||
count = nFaces * 2;
|
||||
}
|
||||
faces = new aiFace[nFaces];
|
||||
for (unsigned int i = 0; i < count; i += 2) {
|
||||
SetFace(faces[i / 2], data.GetUInt(i), data.GetUInt(i + 1));
|
||||
@@ -353,6 +359,10 @@ void glTFImporter::ImportMeshes(glTF::Asset& r)
|
||||
|
||||
case PrimitiveMode_TRIANGLES: {
|
||||
nFaces = count / 3;
|
||||
if (nFaces * 3 != count) {
|
||||
ASSIMP_LOG_WARN("The number of vertices was not compatible with the TRIANGLES mode. Some vertices were dropped.");
|
||||
count = nFaces * 3;
|
||||
}
|
||||
faces = new aiFace[nFaces];
|
||||
for (unsigned int i = 0; i < count; i += 3) {
|
||||
SetFace(faces[i / 3], data.GetUInt(i), data.GetUInt(i + 1), data.GetUInt(i + 2));
|
||||
@@ -395,6 +405,10 @@ void glTFImporter::ImportMeshes(glTF::Asset& r)
|
||||
|
||||
case PrimitiveMode_LINES: {
|
||||
nFaces = count / 2;
|
||||
if (nFaces * 2 != count) {
|
||||
ASSIMP_LOG_WARN("The number of vertices was not compatible with the LINES mode. Some vertices were dropped.");
|
||||
count = nFaces * 2;
|
||||
}
|
||||
faces = new aiFace[nFaces];
|
||||
for (unsigned int i = 0; i < count; i += 2) {
|
||||
SetFace(faces[i / 2], i, i + 1);
|
||||
@@ -418,6 +432,10 @@ void glTFImporter::ImportMeshes(glTF::Asset& r)
|
||||
|
||||
case PrimitiveMode_TRIANGLES: {
|
||||
nFaces = count / 3;
|
||||
if (nFaces * 3 != count) {
|
||||
ASSIMP_LOG_WARN("The number of vertices was not compatible with the TRIANGLES mode. Some vertices were dropped.");
|
||||
count = nFaces * 3;
|
||||
}
|
||||
faces = new aiFace[nFaces];
|
||||
for (unsigned int i = 0; i < count; i += 3) {
|
||||
SetFace(faces[i / 3], i, i + 1, i + 2);
|
||||
|
||||
@@ -685,6 +685,13 @@ namespace glTF2
|
||||
Ref<Texture> texture;
|
||||
unsigned int index;
|
||||
unsigned int texCoord = 0;
|
||||
|
||||
bool textureTransformSupported = false;
|
||||
struct TextureTransformExt {
|
||||
float offset[2];
|
||||
float rotation;
|
||||
float scale[2];
|
||||
} TextureTransformExt_t;
|
||||
};
|
||||
|
||||
struct NormalTextureInfo : TextureInfo
|
||||
@@ -1024,7 +1031,7 @@ namespace glTF2
|
||||
bool KHR_materials_pbrSpecularGlossiness;
|
||||
bool KHR_materials_unlit;
|
||||
bool KHR_lights_punctual;
|
||||
|
||||
bool KHR_texture_transform;
|
||||
} extensionsUsed;
|
||||
|
||||
AssetMetadata asset;
|
||||
|
||||
@@ -800,8 +800,34 @@ inline void Texture::Read(Value& obj, Asset& r)
|
||||
}
|
||||
|
||||
namespace {
|
||||
inline void SetTextureProperties(Asset& r, Value* prop, TextureInfo& out)
|
||||
{
|
||||
inline void SetTextureProperties(Asset& r, Value* prop, TextureInfo& out) {
|
||||
if (r.extensionsUsed.KHR_texture_transform) {
|
||||
if (Value *extensions = FindObject(*prop, "extensions")) {
|
||||
out.textureTransformSupported = true;
|
||||
if (Value *pKHR_texture_transform = FindObject(*extensions, "KHR_texture_transform")) {
|
||||
if (Value *array = FindArray(*pKHR_texture_transform, "offset")) {
|
||||
out.TextureTransformExt_t.offset[0] = (*array)[0].GetFloat();
|
||||
out.TextureTransformExt_t.offset[1] = (*array)[1].GetFloat();
|
||||
} else {
|
||||
out.TextureTransformExt_t.offset[0] = 0;
|
||||
out.TextureTransformExt_t.offset[1] = 0;
|
||||
}
|
||||
|
||||
if (!ReadMember(*pKHR_texture_transform, "rotation", out.TextureTransformExt_t.rotation)) {
|
||||
out.TextureTransformExt_t.rotation = 0;
|
||||
}
|
||||
|
||||
if (Value *array = FindArray(*pKHR_texture_transform, "scale")) {
|
||||
out.TextureTransformExt_t.scale[0] = (*array)[0].GetFloat();
|
||||
out.TextureTransformExt_t.scale[1] = (*array)[1].GetFloat();
|
||||
} else {
|
||||
out.TextureTransformExt_t.scale[0] = 1;
|
||||
out.TextureTransformExt_t.scale[1] = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (Value* index = FindUInt(*prop, "index")) {
|
||||
out.texture = r.textures.Retrieve(index->GetUint());
|
||||
}
|
||||
@@ -877,6 +903,9 @@ inline void Material::Read(Value& material, Asset& r)
|
||||
}
|
||||
}
|
||||
|
||||
if (r.extensionsUsed.KHR_texture_transform) {
|
||||
}
|
||||
|
||||
unlit = nullptr != FindObject(*extensions, "KHR_materials_unlit");
|
||||
}
|
||||
}
|
||||
@@ -1463,12 +1492,10 @@ inline void Asset::ReadExtensionsUsed(Document& doc)
|
||||
}
|
||||
}
|
||||
|
||||
#define CHECK_EXT(EXT) \
|
||||
if (exts.find(#EXT) != exts.end()) extensionsUsed.EXT = true;
|
||||
|
||||
CHECK_EXT(KHR_materials_pbrSpecularGlossiness);
|
||||
CHECK_EXT(KHR_materials_unlit);
|
||||
CHECK_EXT(KHR_lights_punctual);
|
||||
CHECK_EXT(KHR_texture_transform);
|
||||
|
||||
#undef CHECK_EXT
|
||||
}
|
||||
|
||||
@@ -375,7 +375,7 @@ namespace glTF2 {
|
||||
WriteVec(pbrSpecularGlossiness, pbrSG.specularFactor, "specularFactor", defaultSpecularFactor, w.mAl);
|
||||
|
||||
if (pbrSG.glossinessFactor != 1) {
|
||||
WriteFloat(obj, pbrSG.glossinessFactor, "glossinessFactor", w.mAl);
|
||||
WriteFloat(pbrSpecularGlossiness, pbrSG.glossinessFactor, "glossinessFactor", w.mAl);
|
||||
}
|
||||
|
||||
WriteTex(pbrSpecularGlossiness, pbrSG.diffuseTexture, "diffuseTexture", w.mAl);
|
||||
|
||||
@@ -350,7 +350,9 @@ void glTF2Exporter::GetMatTex(const aiMaterial* mat, Ref<Texture>& texture, aiTe
|
||||
if (path[0] == '*') { // embedded
|
||||
aiTexture* tex = mScene->mTextures[atoi(&path[1])];
|
||||
|
||||
uint8_t* data = reinterpret_cast<uint8_t*>(tex->pcData);
|
||||
// copy data since lifetime control is handed over to the asset
|
||||
uint8_t* data = new uint8_t[tex->mWidth];
|
||||
memcpy(data, tex->pcData, tex->mWidth);
|
||||
texture->source->SetData(data, tex->mWidth, *mAsset);
|
||||
|
||||
if (tex->achFormatHint[0]) {
|
||||
|
||||
@@ -74,6 +74,7 @@ namespace glTF2
|
||||
struct Texture;
|
||||
|
||||
// Vec/matrix types, as raw float arrays
|
||||
typedef float (vec2)[2];
|
||||
typedef float (vec3)[3];
|
||||
typedef float (vec4)[4];
|
||||
}
|
||||
|
||||
+1000
-939
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user