mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-07-13 23:54:35 +00:00
* Adjustment: Update Assimp version to 5.0.1.
This commit is contained in:
parent
14ebeaf3eb
commit
4758f7bdaf
679 changed files with 50502 additions and 19698 deletions
|
|
@ -2,7 +2,7 @@
|
|||
Open Asset Import Library (assimp)
|
||||
----------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2020, assimp team
|
||||
Copyright (c) 2006-2019, assimp team
|
||||
|
||||
|
||||
All rights reserved.
|
||||
|
|
@ -45,7 +45,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
|
||||
#include "ColladaExporter.h"
|
||||
#include <assimp/Bitmap.h>
|
||||
#include <assimp/commonMetaData.h>
|
||||
#include <assimp/MathFunctions.h>
|
||||
#include <assimp/fast_atof.h>
|
||||
#include <assimp/SceneCombiner.h>
|
||||
|
|
@ -93,36 +92,6 @@ 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)
|
||||
|
|
@ -177,7 +146,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=\"#" + XMLIDEncode(mScene->mRootNode->mName.C_Str()) + "\" />" << endstr;
|
||||
mOutput << startstr << "<instance_visual_scene url=\"#" + XMLEscape(mScene->mRootNode->mName.C_Str()) + "\" />" << endstr;
|
||||
PopTag();
|
||||
mOutput << startstr << "</scene>" << endstr;
|
||||
PopTag();
|
||||
|
|
@ -278,7 +247,7 @@ void ColladaExporter::WriteHeader() {
|
|||
mOutput << startstr << "<author>" << XMLEscape(value.C_Str()) << "</author>" << endstr;
|
||||
}
|
||||
|
||||
if (nullptr == meta || !meta->Get(AI_METADATA_SOURCE_GENERATOR, value)) {
|
||||
if (nullptr == meta || !meta->Get("AuthoringTool", value)) {
|
||||
mOutput << startstr << "<authoring_tool>" << "Assimp Exporter" << "</authoring_tool>" << endstr;
|
||||
} else {
|
||||
mOutput << startstr << "<authoring_tool>" << XMLEscape(value.C_Str()) << "</authoring_tool>" << endstr;
|
||||
|
|
@ -288,7 +257,7 @@ void ColladaExporter::WriteHeader() {
|
|||
if (meta->Get("Comments", value)) {
|
||||
mOutput << startstr << "<comments>" << XMLEscape(value.C_Str()) << "</comments>" << endstr;
|
||||
}
|
||||
if (meta->Get(AI_METADATA_SOURCE_COPYRIGHT, value)) {
|
||||
if (meta->Get("Copyright", value)) {
|
||||
mOutput << startstr << "<copyright>" << XMLEscape(value.C_Str()) << "</copyright>" << endstr;
|
||||
}
|
||||
if (meta->Get("SourceData", value)) {
|
||||
|
|
@ -387,10 +356,9 @@ void ColladaExporter::WriteCamerasLibrary() {
|
|||
void ColladaExporter::WriteCamera(size_t pIndex){
|
||||
|
||||
const aiCamera *cam = mScene->mCameras[pIndex];
|
||||
const std::string cameraName = XMLEscape(cam->mName.C_Str());
|
||||
const std::string cameraId = XMLIDEncode(cam->mName.C_Str());
|
||||
const std::string idstrEscaped = XMLEscape(cam->mName.C_Str());
|
||||
|
||||
mOutput << startstr << "<camera id=\"" << cameraId << "-camera\" name=\"" << cameraName << "\" >" << endstr;
|
||||
mOutput << startstr << "<camera id=\"" << idstrEscaped << "-camera\" name=\"" << idstrEscaped << "_name\" >" << endstr;
|
||||
PushTag();
|
||||
mOutput << startstr << "<optics>" << endstr;
|
||||
PushTag();
|
||||
|
|
@ -444,11 +412,10 @@ void ColladaExporter::WriteLightsLibrary() {
|
|||
void ColladaExporter::WriteLight(size_t pIndex){
|
||||
|
||||
const aiLight *light = mScene->mLights[pIndex];
|
||||
const std::string lightName = XMLEscape(light->mName.C_Str());
|
||||
const std::string lightId = XMLIDEncode(light->mName.C_Str());
|
||||
const std::string idstrEscaped = XMLEscape(light->mName.C_Str());
|
||||
|
||||
mOutput << startstr << "<light id=\"" << lightId << "-light\" name=\""
|
||||
<< lightName << "\" >" << endstr;
|
||||
mOutput << startstr << "<light id=\"" << idstrEscaped << "-light\" name=\""
|
||||
<< idstrEscaped << "_name\" >" << endstr;
|
||||
PushTag();
|
||||
mOutput << startstr << "<technique_common>" << endstr;
|
||||
PushTag();
|
||||
|
|
@ -619,7 +586,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=\"" << XMLIDEncode(pNameAdd) << "\">" << endstr;
|
||||
mOutput << startstr << "<image id=\"" << XMLEscape(pNameAdd) << "\">" << endstr;
|
||||
PushTag();
|
||||
mOutput << startstr << "<init_from>";
|
||||
|
||||
|
|
@ -652,7 +619,7 @@ void ColladaExporter::WriteTextureColorEntry( const Surface& pSurface, const std
|
|||
}
|
||||
else
|
||||
{
|
||||
mOutput << startstr << "<texture texture=\"" << XMLIDEncode(pImageName) << "\" texcoord=\"CHANNEL" << pSurface.channel << "\" />" << endstr;
|
||||
mOutput << startstr << "<texture texture=\"" << XMLEscape(pImageName) << "\" texcoord=\"CHANNEL" << pSurface.channel << "\" />" << endstr;
|
||||
}
|
||||
PopTag();
|
||||
mOutput << startstr << "</" << pTypeName << ">" << endstr;
|
||||
|
|
@ -666,21 +633,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=\"" << XMLIDEncode(pMatName) << "-" << pTypeName << "-surface\">" << endstr;
|
||||
mOutput << startstr << "<newparam sid=\"" << XMLEscape(pMatName) << "-" << pTypeName << "-surface\">" << endstr;
|
||||
PushTag();
|
||||
mOutput << startstr << "<surface type=\"2D\">" << endstr;
|
||||
PushTag();
|
||||
mOutput << startstr << "<init_from>" << XMLIDEncode(pMatName) << "-" << pTypeName << "-image</init_from>" << endstr;
|
||||
mOutput << startstr << "<init_from>" << XMLEscape(pMatName) << "-" << pTypeName << "-image</init_from>" << endstr;
|
||||
PopTag();
|
||||
mOutput << startstr << "</surface>" << endstr;
|
||||
PopTag();
|
||||
mOutput << startstr << "</newparam>" << endstr;
|
||||
|
||||
mOutput << startstr << "<newparam sid=\"" << XMLIDEncode(pMatName) << "-" << pTypeName << "-sampler\">" << endstr;
|
||||
mOutput << startstr << "<newparam sid=\"" << XMLEscape(pMatName) << "-" << pTypeName << "-sampler\">" << endstr;
|
||||
PushTag();
|
||||
mOutput << startstr << "<sampler2D>" << endstr;
|
||||
PushTag();
|
||||
mOutput << startstr << "<source>" << XMLIDEncode(pMatName) << "-" << pTypeName << "-surface</source>" << endstr;
|
||||
mOutput << startstr << "<source>" << XMLEscape(pMatName) << "-" << pTypeName << "-surface</source>" << endstr;
|
||||
PopTag();
|
||||
mOutput << startstr << "</sampler2D>" << endstr;
|
||||
PopTag();
|
||||
|
|
@ -732,6 +699,11 @@ 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";
|
||||
|
|
@ -796,7 +768,7 @@ void ColladaExporter::WriteMaterials()
|
|||
{
|
||||
const Material& mat = *it;
|
||||
// this is so ridiculous it must be right
|
||||
mOutput << startstr << "<effect id=\"" << XMLIDEncode(mat.name) << "-fx\" name=\"" << XMLEscape(mat.name) << "\">" << endstr;
|
||||
mOutput << startstr << "<effect id=\"" << XMLEscape(mat.name) << "-fx\" name=\"" << XMLEscape(mat.name) << "\">" << endstr;
|
||||
PushTag();
|
||||
mOutput << startstr << "<profile_COMMON>" << endstr;
|
||||
PushTag();
|
||||
|
|
@ -847,9 +819,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=\"" << XMLIDEncode(mat.name) << "\" name=\"" << XMLEscape(mat.name) << "\">" << endstr;
|
||||
mOutput << startstr << "<material id=\"" << XMLEscape(mat.name) << "\" name=\"" << mat.name << "\">" << endstr;
|
||||
PushTag();
|
||||
mOutput << startstr << "<instance_effect url=\"#" << XMLIDEncode(mat.name) << "-fx\"/>" << endstr;
|
||||
mOutput << startstr << "<instance_effect url=\"#" << XMLEscape(mat.name) << "-fx\"/>" << endstr;
|
||||
PopTag();
|
||||
mOutput << startstr << "</material>" << endstr;
|
||||
}
|
||||
|
|
@ -878,8 +850,8 @@ void ColladaExporter::WriteControllerLibrary()
|
|||
void ColladaExporter::WriteController( size_t pIndex)
|
||||
{
|
||||
const aiMesh* mesh = mScene->mMeshes[pIndex];
|
||||
const std::string idstr = mesh->mName.length == 0 ? GetMeshId(pIndex) : mesh->mName.C_Str();
|
||||
const std::string idstrEscaped = XMLIDEncode(idstr);
|
||||
const std::string idstr = GetMeshId( pIndex);
|
||||
const std::string idstrEscaped = XMLEscape(idstr);
|
||||
|
||||
if ( mesh->mNumFaces == 0 || mesh->mNumVertices == 0 )
|
||||
return;
|
||||
|
|
@ -914,7 +886,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 << XMLIDEncode(mesh->mBones[i]->mName.C_Str()) << " ";
|
||||
mOutput << XMLEscape(mesh->mBones[i]->mName.C_Str()) << " ";
|
||||
|
||||
mOutput << "</Name_array>" << endstr;
|
||||
|
||||
|
|
@ -1049,15 +1021,14 @@ void ColladaExporter::WriteGeometryLibrary()
|
|||
void ColladaExporter::WriteGeometry( size_t pIndex)
|
||||
{
|
||||
const aiMesh* mesh = mScene->mMeshes[pIndex];
|
||||
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);
|
||||
const std::string idstr = GetMeshId( pIndex);
|
||||
const std::string idstrEscaped = XMLEscape(idstr);
|
||||
|
||||
if ( mesh->mNumFaces == 0 || mesh->mNumVertices == 0 )
|
||||
return;
|
||||
|
||||
// opening tag
|
||||
mOutput << startstr << "<geometry id=\"" << geometryId << "\" name=\"" << geometryName << "\" >" << endstr;
|
||||
mOutput << startstr << "<geometry id=\"" << idstrEscaped << "\" name=\"" << idstrEscaped << "_name\" >" << endstr;
|
||||
PushTag();
|
||||
|
||||
mOutput << startstr << "<mesh>" << endstr;
|
||||
|
|
@ -1088,9 +1059,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=\"" << geometryId << "-vertices" << "\">" << endstr;
|
||||
mOutput << startstr << "<vertices id=\"" << idstrEscaped << "-vertices" << "\">" << endstr;
|
||||
PushTag();
|
||||
mOutput << startstr << "<input semantic=\"POSITION\" source=\"#" << geometryId << "-positions\" />" << endstr;
|
||||
mOutput << startstr << "<input semantic=\"POSITION\" source=\"#" << idstrEscaped << "-positions\" />" << endstr;
|
||||
PopTag();
|
||||
mOutput << startstr << "</vertices>" << endstr;
|
||||
|
||||
|
|
@ -1108,18 +1079,18 @@ void ColladaExporter::WriteGeometry( size_t pIndex)
|
|||
{
|
||||
mOutput << startstr << "<lines count=\"" << countLines << "\" material=\"defaultMaterial\">" << endstr;
|
||||
PushTag();
|
||||
mOutput << startstr << "<input offset=\"0\" semantic=\"VERTEX\" source=\"#" << geometryId << "-vertices\" />" << endstr;
|
||||
mOutput << startstr << "<input offset=\"0\" semantic=\"VERTEX\" source=\"#" << idstrEscaped << "-vertices\" />" << endstr;
|
||||
if( mesh->HasNormals() )
|
||||
mOutput << startstr << "<input semantic=\"NORMAL\" source=\"#" << geometryId << "-normals\" />" << endstr;
|
||||
mOutput << startstr << "<input semantic=\"NORMAL\" source=\"#" << idstrEscaped << "-normals\" />" << endstr;
|
||||
for( size_t a = 0; a < AI_MAX_NUMBER_OF_TEXTURECOORDS; ++a )
|
||||
{
|
||||
if( mesh->HasTextureCoords(static_cast<unsigned int>(a)) )
|
||||
mOutput << startstr << "<input semantic=\"TEXCOORD\" source=\"#" << geometryId << "-tex" << a << "\" " << "set=\"" << a << "\"" << " />" << endstr;
|
||||
mOutput << startstr << "<input semantic=\"TEXCOORD\" source=\"#" << idstrEscaped << "-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=\"#" << geometryId << "-color" << a << "\" " << "set=\"" << a << "\"" << " />" << endstr;
|
||||
mOutput << startstr << "<input semantic=\"COLOR\" source=\"#" << idstrEscaped << "-color" << a << "\" " << "set=\"" << a << "\"" << " />" << endstr;
|
||||
}
|
||||
|
||||
mOutput << startstr << "<p>";
|
||||
|
|
@ -1142,18 +1113,18 @@ void ColladaExporter::WriteGeometry( size_t pIndex)
|
|||
{
|
||||
mOutput << startstr << "<polylist count=\"" << countPoly << "\" material=\"defaultMaterial\">" << endstr;
|
||||
PushTag();
|
||||
mOutput << startstr << "<input offset=\"0\" semantic=\"VERTEX\" source=\"#" << geometryId << "-vertices\" />" << endstr;
|
||||
mOutput << startstr << "<input offset=\"0\" semantic=\"VERTEX\" source=\"#" << idstrEscaped << "-vertices\" />" << endstr;
|
||||
if( mesh->HasNormals() )
|
||||
mOutput << startstr << "<input offset=\"0\" semantic=\"NORMAL\" source=\"#" << geometryId << "-normals\" />" << endstr;
|
||||
mOutput << startstr << "<input offset=\"0\" semantic=\"NORMAL\" source=\"#" << idstrEscaped << "-normals\" />" << endstr;
|
||||
for( size_t a = 0; a < AI_MAX_NUMBER_OF_TEXTURECOORDS; ++a )
|
||||
{
|
||||
if( mesh->HasTextureCoords(static_cast<unsigned int>(a)) )
|
||||
mOutput << startstr << "<input offset=\"0\" semantic=\"TEXCOORD\" source=\"#" << geometryId << "-tex" << a << "\" " << "set=\"" << a << "\"" << " />" << endstr;
|
||||
mOutput << startstr << "<input offset=\"0\" semantic=\"TEXCOORD\" source=\"#" << idstrEscaped << "-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=\"#" << geometryId << "-color" << a << "\" " << "set=\"" << a << "\"" << " />" << endstr;
|
||||
mOutput << startstr << "<input offset=\"0\" semantic=\"COLOR\" source=\"#" << idstrEscaped << "-color" << a << "\" " << "set=\"" << a << "\"" << " />" << endstr;
|
||||
}
|
||||
|
||||
mOutput << startstr << "<vcount>";
|
||||
|
|
@ -1202,13 +1173,13 @@ void ColladaExporter::WriteFloatArray( const std::string& pIdString, FloatDataTy
|
|||
return;
|
||||
}
|
||||
|
||||
std::string arrayId = XMLIDEncode(pIdString) + "-array";
|
||||
std::string arrayId = pIdString + "-array";
|
||||
|
||||
mOutput << startstr << "<source id=\"" << XMLIDEncode(pIdString) << "\" name=\"" << XMLEscape(pIdString) << "\">" << endstr;
|
||||
mOutput << startstr << "<source id=\"" << XMLEscape(pIdString) << "\" name=\"" << XMLEscape(pIdString) << "\">" << endstr;
|
||||
PushTag();
|
||||
|
||||
// source array
|
||||
mOutput << startstr << "<float_array id=\"" << arrayId << "\" count=\"" << pElementCount * floatsPerElement << "\"> ";
|
||||
mOutput << startstr << "<float_array id=\"" << XMLEscape(arrayId) << "\" count=\"" << pElementCount * floatsPerElement << "\"> ";
|
||||
PushTag();
|
||||
|
||||
if( pType == FloatType_TexCoord2 )
|
||||
|
|
@ -1294,12 +1265,11 @@ void ColladaExporter::WriteFloatArray( const std::string& pIdString, FloatDataTy
|
|||
// Writes the scene library
|
||||
void ColladaExporter::WriteSceneLibrary()
|
||||
{
|
||||
const std::string sceneName = XMLEscape(mScene->mRootNode->mName.C_Str());
|
||||
const std::string sceneId = XMLIDEncode(mScene->mRootNode->mName.C_Str());
|
||||
const std::string scene_name_escaped = XMLEscape(mScene->mRootNode->mName.C_Str());
|
||||
|
||||
mOutput << startstr << "<library_visual_scenes>" << endstr;
|
||||
PushTag();
|
||||
mOutput << startstr << "<visual_scene id=\"" + sceneId + "\" name=\"" + sceneName + "\">" << endstr;
|
||||
mOutput << startstr << "<visual_scene id=\"" + scene_name_escaped + "\" name=\"" + scene_name_escaped + "\">" << endstr;
|
||||
PushTag();
|
||||
|
||||
// start recursive write at the root node
|
||||
|
|
@ -1330,7 +1300,7 @@ void ColladaExporter::WriteAnimationLibrary(size_t pIndex)
|
|||
idstr = idstr + ending;
|
||||
}
|
||||
|
||||
const std::string idstrEscaped = XMLIDEncode(idstr);
|
||||
const std::string idstrEscaped = XMLEscape(idstr);
|
||||
|
||||
mOutput << startstr << "<animation id=\"" + idstrEscaped + "\" name=\"" + animation_name_escaped + "\">" << endstr;
|
||||
PushTag();
|
||||
|
|
@ -1402,13 +1372,13 @@ void ColladaExporter::WriteAnimationLibrary(size_t pIndex)
|
|||
}
|
||||
|
||||
const std::string node_idstr = nodeAnim->mNodeName.data + std::string("_matrix-interpolation");
|
||||
std::string arrayId = XMLIDEncode(node_idstr) + "-array";
|
||||
std::string arrayId = node_idstr + "-array";
|
||||
|
||||
mOutput << startstr << "<source id=\"" << XMLIDEncode(node_idstr) << "\">" << endstr;
|
||||
mOutput << startstr << "<source id=\"" << XMLEscape(node_idstr) << "\">" << endstr;
|
||||
PushTag();
|
||||
|
||||
// source array
|
||||
mOutput << startstr << "<Name_array id=\"" << arrayId << "\" count=\"" << names.size() << "\"> ";
|
||||
mOutput << startstr << "<Name_array id=\"" << XMLEscape(arrayId) << "\" count=\"" << names.size() << "\"> ";
|
||||
for( size_t a = 0; a < names.size(); ++a ) {
|
||||
mOutput << names[a] << " ";
|
||||
}
|
||||
|
|
@ -1417,7 +1387,7 @@ void ColladaExporter::WriteAnimationLibrary(size_t pIndex)
|
|||
mOutput << startstr << "<technique_common>" << endstr;
|
||||
PushTag();
|
||||
|
||||
mOutput << startstr << "<accessor source=\"#" << arrayId << "\" count=\"" << names.size() << "\" stride=\"" << 1 << "\">" << endstr;
|
||||
mOutput << startstr << "<accessor source=\"#" << XMLEscape(arrayId) << "\" count=\"" << names.size() << "\" stride=\"" << 1 << "\">" << endstr;
|
||||
PushTag();
|
||||
|
||||
mOutput << startstr << "<param name=\"INTERPOLATION\" type=\"name\"></param>" << endstr;
|
||||
|
|
@ -1439,12 +1409,12 @@ void ColladaExporter::WriteAnimationLibrary(size_t pIndex)
|
|||
{
|
||||
// samplers
|
||||
const std::string node_idstr = nodeAnim->mNodeName.data + std::string("_matrix-sampler");
|
||||
mOutput << startstr << "<sampler id=\"" << XMLIDEncode(node_idstr) << "\">" << endstr;
|
||||
mOutput << startstr << "<sampler id=\"" << XMLEscape(node_idstr) << "\">" << endstr;
|
||||
PushTag();
|
||||
|
||||
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;
|
||||
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;
|
||||
|
||||
PopTag();
|
||||
mOutput << startstr << "</sampler>" << endstr;
|
||||
|
|
@ -1456,7 +1426,7 @@ void ColladaExporter::WriteAnimationLibrary(size_t pIndex)
|
|||
|
||||
{
|
||||
// channels
|
||||
mOutput << startstr << "<channel source=\"#" << XMLIDEncode( nodeAnim->mNodeName.data + std::string("_matrix-sampler") ) << "\" target=\"" << XMLIDEncode(nodeAnim->mNodeName.data) << "/matrix\"/>" << endstr;
|
||||
mOutput << startstr << "<channel source=\"#" << XMLEscape( nodeAnim->mNodeName.data + std::string("_matrix-sampler") ) << "\" target=\"" << XMLEscape(nodeAnim->mNodeName.data) << "/matrix\"/>" << endstr;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1467,6 +1437,8 @@ 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();
|
||||
|
|
@ -1574,17 +1546,16 @@ void ColladaExporter::WriteNode( const aiScene* pScene, aiNode* pNode)
|
|||
}
|
||||
}
|
||||
|
||||
const std::string node_id = XMLIDEncode(pNode->mName.data);
|
||||
const std::string node_name = XMLEscape(pNode->mName.data);
|
||||
const std::string node_name_escaped = XMLEscape(pNode->mName.data);
|
||||
mOutput << startstr << "<node ";
|
||||
if(is_skeleton_root) {
|
||||
mOutput << "id=\"" << node_id << "\" " << (is_joint ? "sid=\"" + node_id +"\"" : "") ; // For now, only support one skeleton in a scene.
|
||||
mFoundSkeletonRootNodeID = node_id;
|
||||
mOutput << "id=\"" << node_name_escaped << "\" " << (is_joint ? "sid=\"" + node_name_escaped +"\"" : "") ; // For now, only support one skeleton in a scene.
|
||||
mFoundSkeletonRootNodeID = node_name_escaped;
|
||||
} else {
|
||||
mOutput << "id=\"" << node_id << "\" " << (is_joint ? "sid=\"" + node_id +"\"": "") ;
|
||||
mOutput << "id=\"" << node_name_escaped << "\" " << (is_joint ? "sid=\"" + node_name_escaped +"\"": "") ;
|
||||
}
|
||||
|
||||
mOutput << " name=\"" << node_name
|
||||
mOutput << " name=\"" << node_name_escaped
|
||||
<< "\" type=\"" << node_type
|
||||
<< "\">" << endstr;
|
||||
PushTag();
|
||||
|
|
@ -1623,14 +1594,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_id << "-camera\"/>" << endstr;
|
||||
mOutput << startstr <<"<instance_camera url=\"#" << node_name_escaped << "-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_id << "-light\"/>" << endstr;
|
||||
mOutput << startstr <<"<instance_light url=\"#" << node_name_escaped << "-light\"/>" << endstr;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
@ -1644,17 +1615,15 @@ 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=\"#" << XMLIDEncode(meshName) << "\">" << endstr;
|
||||
mOutput << startstr << "<instance_geometry url=\"#" << XMLEscape(GetMeshId( pNode->mMeshes[a])) << "\">" << endstr;
|
||||
PushTag();
|
||||
}
|
||||
else
|
||||
{
|
||||
mOutput << startstr
|
||||
<< "<instance_controller url=\"#" << XMLIDEncode(meshName) << "-skin\">"
|
||||
<< "<instance_controller url=\"#" << XMLEscape(GetMeshId( pNode->mMeshes[a])) << "-skin\">"
|
||||
<< endstr;
|
||||
PushTag();
|
||||
|
||||
|
|
@ -1662,7 +1631,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 = XMLIDEncode( skeletonRootBoneNode->mName.C_Str() );
|
||||
mFoundSkeletonRootNodeID = XMLEscape( skeletonRootBoneNode->mName.C_Str() );
|
||||
}
|
||||
mOutput << startstr << "<skeleton>#" << mFoundSkeletonRootNodeID << "</skeleton>" << endstr;
|
||||
}
|
||||
|
|
@ -1670,7 +1639,7 @@ void ColladaExporter::WriteNode( const aiScene* pScene, aiNode* pNode)
|
|||
PushTag();
|
||||
mOutput << startstr << "<technique_common>" << endstr;
|
||||
PushTag();
|
||||
mOutput << startstr << "<instance_material symbol=\"defaultMaterial\" target=\"#" << XMLIDEncode(materials[mesh->mMaterialIndex].name) << "\">" << endstr;
|
||||
mOutput << startstr << "<instance_material symbol=\"defaultMaterial\" target=\"#" << XMLEscape(materials[mesh->mMaterialIndex].name) << "\">" << endstr;
|
||||
PushTag();
|
||||
for( size_t a = 0; a < AI_MAX_NUMBER_OF_TEXTURECOORDS; ++a )
|
||||
{
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
Open Asset Import Library (assimp)
|
||||
----------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2020, assimp team
|
||||
Copyright (c) 2006-2019, assimp team
|
||||
|
||||
|
||||
All rights reserved.
|
||||
|
|
|
|||
|
|
@ -1,107 +0,0 @@
|
|||
/** Helper structures for the Collada loader */
|
||||
|
||||
/*
|
||||
Open Asset Import Library (assimp)
|
||||
----------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2020, 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 "ColladaHelper.h"
|
||||
|
||||
#include <assimp/commonMetaData.h>
|
||||
#include <assimp/ParsingUtils.h>
|
||||
|
||||
namespace Assimp {
|
||||
namespace Collada {
|
||||
|
||||
const MetaKeyPairVector MakeColladaAssimpMetaKeys() {
|
||||
MetaKeyPairVector result;
|
||||
result.emplace_back("authoring_tool", AI_METADATA_SOURCE_GENERATOR);
|
||||
result.emplace_back("copyright", AI_METADATA_SOURCE_COPYRIGHT);
|
||||
return result;
|
||||
};
|
||||
|
||||
const MetaKeyPairVector &GetColladaAssimpMetaKeys() {
|
||||
static const MetaKeyPairVector result = MakeColladaAssimpMetaKeys();
|
||||
return result;
|
||||
}
|
||||
|
||||
const MetaKeyPairVector MakeColladaAssimpMetaKeysCamelCase() {
|
||||
MetaKeyPairVector result = MakeColladaAssimpMetaKeys();
|
||||
for (auto &val : result)
|
||||
{
|
||||
ToCamelCase(val.first);
|
||||
}
|
||||
return result;
|
||||
};
|
||||
|
||||
const MetaKeyPairVector &GetColladaAssimpMetaKeysCamelCase()
|
||||
{
|
||||
static const MetaKeyPairVector result = MakeColladaAssimpMetaKeysCamelCase();
|
||||
return result;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Convert underscore_separated to CamelCase: "authoring_tool" becomes "AuthoringTool"
|
||||
void ToCamelCase(std::string &text)
|
||||
{
|
||||
if (text.empty())
|
||||
return;
|
||||
// Capitalise first character
|
||||
auto it = text.begin();
|
||||
(*it) = ToUpper(*it);
|
||||
++it;
|
||||
for (/*started above*/ ; it != text.end(); /*iterated below*/)
|
||||
{
|
||||
if ((*it) == '_')
|
||||
{
|
||||
it = text.erase(it);
|
||||
if (it != text.end())
|
||||
(*it) = ToUpper(*it);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Make lower case
|
||||
(*it) = ToLower(*it);
|
||||
++it;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Collada
|
||||
} // namespace Assimp
|
||||
|
|
@ -4,7 +4,7 @@
|
|||
Open Asset Import Library (assimp)
|
||||
----------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2020, assimp team
|
||||
Copyright (c) 2006-2019, assimp team
|
||||
|
||||
|
||||
All rights reserved.
|
||||
|
|
@ -47,7 +47,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include <set>
|
||||
#include <stdint.h>
|
||||
#include <assimp/light.h>
|
||||
#include <assimp/mesh.h>
|
||||
|
|
@ -105,17 +104,6 @@ enum MorphMethod
|
|||
Relative
|
||||
};
|
||||
|
||||
/** Common metadata keys as <Collada, Assimp> */
|
||||
typedef std::pair<std::string, std::string> MetaKeyPair;
|
||||
typedef std::vector<MetaKeyPair> MetaKeyPairVector;
|
||||
|
||||
// Collada as lower_case (native)
|
||||
const MetaKeyPairVector &GetColladaAssimpMetaKeys();
|
||||
// Collada as CamelCase (used by Assimp for consistency)
|
||||
const MetaKeyPairVector &GetColladaAssimpMetaKeysCamelCase();
|
||||
|
||||
/** Convert underscore_separated to CamelCase "authoring_tool" becomes "AuthoringTool" */
|
||||
void ToCamelCase(std::string &text);
|
||||
|
||||
/** Contains all data for one of the different transformation types */
|
||||
struct Transform
|
||||
|
|
@ -595,7 +583,7 @@ struct Image
|
|||
/** Embedded image data */
|
||||
std::vector<uint8_t> mImageData;
|
||||
|
||||
/** File format hint of embedded image data */
|
||||
/** File format hint ofembedded image data */
|
||||
std::string mEmbeddedFormat;
|
||||
};
|
||||
|
||||
|
|
@ -659,37 +647,23 @@ struct Animation
|
|||
|
||||
void CombineSingleChannelAnimationsRecursively(Animation *pParent)
|
||||
{
|
||||
std::set<std::string> childrenTargets;
|
||||
bool childrenAnimationsHaveDifferentChannels = true;
|
||||
|
||||
for (std::vector<Animation*>::iterator it = pParent->mSubAnims.begin(); it != pParent->mSubAnims.end();)
|
||||
{
|
||||
Animation *anim = *it;
|
||||
|
||||
CombineSingleChannelAnimationsRecursively(anim);
|
||||
|
||||
if (childrenAnimationsHaveDifferentChannels && anim->mChannels.size() == 1 &&
|
||||
childrenTargets.find(anim->mChannels[0].mTarget) == childrenTargets.end()) {
|
||||
childrenTargets.insert(anim->mChannels[0].mTarget);
|
||||
} else {
|
||||
childrenAnimationsHaveDifferentChannels = false;
|
||||
}
|
||||
|
||||
++it;
|
||||
}
|
||||
|
||||
// We only want to combine animations if they have different channels
|
||||
if (childrenAnimationsHaveDifferentChannels)
|
||||
{
|
||||
for (std::vector<Animation*>::iterator it = pParent->mSubAnims.begin(); it != pParent->mSubAnims.end();)
|
||||
if (anim->mChannels.size() == 1)
|
||||
{
|
||||
Animation *anim = *it;
|
||||
|
||||
pParent->mChannels.push_back(anim->mChannels[0]);
|
||||
|
||||
it = pParent->mSubAnims.erase(it);
|
||||
|
||||
delete anim;
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
++it;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
Open Asset Import Library (assimp)
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2020, assimp team
|
||||
Copyright (c) 2006-2019, assimp team
|
||||
|
||||
All rights reserved.
|
||||
|
||||
|
|
@ -963,38 +963,18 @@ void ColladaLoader::StoreAnimations( aiScene* pScene, const ColladaParser& pPars
|
|||
|
||||
// catch special case: many animations with the same length, each affecting only a single node.
|
||||
// we need to unite all those single-node-anims to a proper combined animation
|
||||
for(size_t a = 0; a < mAnims.size(); ++a) {
|
||||
for( size_t a = 0; a < mAnims.size(); ++a) {
|
||||
aiAnimation* templateAnim = mAnims[a];
|
||||
|
||||
if (templateAnim->mNumChannels == 1) {
|
||||
if( templateAnim->mNumChannels == 1) {
|
||||
// search for other single-channel-anims with the same duration
|
||||
std::vector<size_t> collectedAnimIndices;
|
||||
for( size_t b = a+1; b < mAnims.size(); ++b) {
|
||||
aiAnimation* other = mAnims[b];
|
||||
if (other->mNumChannels == 1 && other->mDuration == templateAnim->mDuration &&
|
||||
other->mTicksPerSecond == templateAnim->mTicksPerSecond)
|
||||
collectedAnimIndices.push_back(b);
|
||||
collectedAnimIndices.push_back(b);
|
||||
}
|
||||
|
||||
// We only want to combine the animations if they have different channels
|
||||
std::set<std::string> animTargets;
|
||||
animTargets.insert(templateAnim->mChannels[0]->mNodeName.C_Str());
|
||||
bool collectedAnimationsHaveDifferentChannels = true;
|
||||
for (size_t b = 0; b < collectedAnimIndices.size(); ++b)
|
||||
{
|
||||
aiAnimation* srcAnimation = mAnims[collectedAnimIndices[b]];
|
||||
std::string channelName = std::string(srcAnimation->mChannels[0]->mNodeName.C_Str());
|
||||
if (animTargets.find(channelName) == animTargets.end()) {
|
||||
animTargets.insert(channelName);
|
||||
} else {
|
||||
collectedAnimationsHaveDifferentChannels = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!collectedAnimationsHaveDifferentChannels)
|
||||
continue;
|
||||
|
||||
// if there are other animations which fit the template anim, combine all channels into a single anim
|
||||
if (!collectedAnimIndices.empty())
|
||||
{
|
||||
|
|
@ -1755,7 +1735,6 @@ 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)
|
||||
{
|
||||
|
|
@ -1783,7 +1762,7 @@ aiString ColladaLoader::FindFilenameForEffectTexture(const ColladaParser& pParse
|
|||
|
||||
//set default texture file name
|
||||
result.Set(name + ".jpg");
|
||||
ColladaParser::UriDecodePath(result);
|
||||
ConvertPath(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
@ -1802,7 +1781,7 @@ aiString ColladaLoader::FindFilenameForEffectTexture(const ColladaParser& pParse
|
|||
|
||||
|
||||
// setup format hint
|
||||
if (imIt->second.mEmbeddedFormat.length() >= HINTMAXTEXTURELEN) {
|
||||
if (imIt->second.mEmbeddedFormat.length() > 3) {
|
||||
ASSIMP_LOG_WARN("Collada: texture format hint is too long, truncating to 3 characters");
|
||||
}
|
||||
strncpy(tex->achFormatHint, imIt->second.mEmbeddedFormat.c_str(), 3);
|
||||
|
|
@ -1823,10 +1802,61 @@ 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
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
Open Asset Import Library (assimp)
|
||||
----------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2020, assimp team
|
||||
Copyright (c) 2006-2019, assimp team
|
||||
|
||||
|
||||
All rights reserved.
|
||||
|
|
@ -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,6 +184,9 @@ 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
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
Open Asset Import Library (assimp)
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2020, assimp team
|
||||
Copyright (c) 2006-2019, assimp team
|
||||
|
||||
|
||||
|
||||
|
|
@ -50,7 +50,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
#include <sstream>
|
||||
#include <stdarg.h>
|
||||
#include "ColladaParser.h"
|
||||
#include <assimp/commonMetaData.h>
|
||||
#include <assimp/fast_atof.h>
|
||||
#include <assimp/ParsingUtils.h>
|
||||
#include <assimp/StringUtils.h>
|
||||
|
|
@ -184,75 +183,18 @@ std::string ColladaParser::ReadZaeManifest(ZipArchiveIOSystem &zip_archive) {
|
|||
if (filepath == nullptr)
|
||||
return std::string();
|
||||
|
||||
aiString ai_str(filepath);
|
||||
UriDecodePath(ai_str);
|
||||
|
||||
return std::string(ai_str.C_Str());
|
||||
return std::string(filepath);
|
||||
}
|
||||
}
|
||||
}
|
||||
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()
|
||||
{
|
||||
const char* cur = GetTextContent();
|
||||
if ( nullptr == cur) {
|
||||
return false;
|
||||
}
|
||||
return (!ASSIMP_strincmp(cur, "true", 4) || '0' != *cur);
|
||||
}
|
||||
|
||||
|
|
@ -261,9 +203,6 @@ bool ColladaParser::ReadBoolFromTextContent()
|
|||
ai_real ColladaParser::ReadFloatFromTextContent()
|
||||
{
|
||||
const char* cur = GetTextContent();
|
||||
if ( nullptr == cur ) {
|
||||
return 0.0;
|
||||
}
|
||||
return fast_atof(cur);
|
||||
}
|
||||
|
||||
|
|
@ -283,11 +222,6 @@ void ColladaParser::ReadContents()
|
|||
if (attrib != -1) {
|
||||
const char* version = mReader->getAttributeValue(attrib);
|
||||
|
||||
// Store declared format version string
|
||||
aiString v;
|
||||
v.Set(version);
|
||||
mAssetMetaData.emplace(AI_METADATA_SOURCE_FORMAT_VERSION, v );
|
||||
|
||||
if (!::strncmp(version, "1.5", 3)) {
|
||||
mFormat = FV_1_5_n;
|
||||
ASSIMP_LOG_DEBUG("Collada schema version is 1.5.n");
|
||||
|
|
@ -446,39 +380,23 @@ void ColladaParser::ReadContributorInfo()
|
|||
}
|
||||
}
|
||||
|
||||
static bool FindCommonKey(const std::string &collada_key, const MetaKeyPairVector &key_renaming, size_t &found_index) {
|
||||
for (size_t i = 0; i < key_renaming.size(); ++i) {
|
||||
if (key_renaming[i].first == collada_key) {
|
||||
found_index = i;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
found_index = std::numeric_limits<size_t>::max();
|
||||
return false;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Reads a single string metadata item
|
||||
void ColladaParser::ReadMetaDataItem(StringMetaData &metadata) {
|
||||
const Collada::MetaKeyPairVector &key_renaming = GetColladaAssimpMetaKeysCamelCase();
|
||||
// Metadata such as created, keywords, subject etc
|
||||
const char *key_char = mReader->getNodeName();
|
||||
if (key_char != nullptr) {
|
||||
void ColladaParser::ReadMetaDataItem(StringMetaData &metadata)
|
||||
{
|
||||
// Metadata such as created, keywords, subject etc
|
||||
const char* key_char = mReader->getNodeName();
|
||||
if (key_char != nullptr)
|
||||
{
|
||||
const std::string key_str(key_char);
|
||||
const char *value_char = TestTextContent();
|
||||
if (value_char != nullptr) {
|
||||
const char* value_char = TestTextContent();
|
||||
if (value_char != nullptr)
|
||||
{
|
||||
std::string camel_key_str = key_str;
|
||||
ToCamelCase(camel_key_str);
|
||||
aiString aistr;
|
||||
aistr.Set(value_char);
|
||||
|
||||
std::string camel_key_str(key_str);
|
||||
ToCamelCase(camel_key_str);
|
||||
|
||||
size_t found_index;
|
||||
if (FindCommonKey(camel_key_str, key_renaming, found_index)) {
|
||||
metadata.emplace(key_renaming[found_index].second, aistr);
|
||||
} else {
|
||||
metadata.emplace(camel_key_str, aistr);
|
||||
}
|
||||
aistr.Set(value_char);
|
||||
metadata.emplace(camel_key_str, aistr);
|
||||
}
|
||||
TestClosing(key_str.c_str());
|
||||
}
|
||||
|
|
@ -486,6 +404,27 @@ void ColladaParser::ReadMetaDataItem(StringMetaData &metadata) {
|
|||
SkipElement();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Convert underscore_seperated to CamelCase: "authoring_tool" becomes "AuthoringTool"
|
||||
void ColladaParser::ToCamelCase(std::string &text)
|
||||
{
|
||||
if (text.empty())
|
||||
return;
|
||||
// Capitalise first character
|
||||
text[0] = ToUpper(text[0]);
|
||||
for (auto it = text.begin(); it != text.end(); /*iterated below*/)
|
||||
{
|
||||
if ((*it) == '_')
|
||||
{
|
||||
it = text.erase(it);
|
||||
if (it != text.end())
|
||||
(*it) = ToUpper(*it);
|
||||
}
|
||||
else
|
||||
++it;
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Reads the animation clips
|
||||
void ColladaParser::ReadAnimationClipLibrary()
|
||||
|
|
@ -1181,12 +1120,7 @@ void ColladaParser::ReadImage(Collada::Image& pImage)
|
|||
if (!mReader->isEmptyElement()) {
|
||||
// element content is filename - hopefully
|
||||
const char* sz = TestTextContent();
|
||||
if (sz)
|
||||
{
|
||||
aiString filepath(sz);
|
||||
UriDecodePath(filepath);
|
||||
pImage.mFileName = filepath.C_Str();
|
||||
}
|
||||
if (sz)pImage.mFileName = sz;
|
||||
TestClosing("init_from");
|
||||
}
|
||||
if (!pImage.mFileName.length()) {
|
||||
|
|
@ -1219,12 +1153,7 @@ void ColladaParser::ReadImage(Collada::Image& pImage)
|
|||
{
|
||||
// element content is filename - hopefully
|
||||
const char* sz = TestTextContent();
|
||||
if (sz)
|
||||
{
|
||||
aiString filepath(sz);
|
||||
UriDecodePath(filepath);
|
||||
pImage.mFileName = filepath.C_Str();
|
||||
}
|
||||
if (sz)pImage.mFileName = sz;
|
||||
TestClosing("ref");
|
||||
}
|
||||
else if (IsElement("hex") && !pImage.mFileName.length())
|
||||
|
|
@ -3127,7 +3056,7 @@ void ColladaParser::ReadMaterialVertexInputBinding(Collada::SemanticMappingTable
|
|||
}
|
||||
}
|
||||
|
||||
void ColladaParser::ReadEmbeddedTextures(ZipArchiveIOSystem& zip_archive)
|
||||
void Assimp::ColladaParser::ReadEmbeddedTextures(ZipArchiveIOSystem& zip_archive)
|
||||
{
|
||||
// Attempt to load any undefined Collada::Image in ImageLibrary
|
||||
for (ImageLibrary::iterator it = mImageLibrary.begin(); it != mImageLibrary.end(); ++it) {
|
||||
|
|
@ -3241,12 +3170,13 @@ void ColladaParser::ReadScene()
|
|||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Aborts the file reading with an exception
|
||||
AI_WONT_RETURN void ColladaParser::ThrowException(const std::string& pError) const {
|
||||
AI_WONT_RETURN void ColladaParser::ThrowException(const std::string& pError) const
|
||||
{
|
||||
throw DeadlyImportError(format() << "Collada: " << mFileName << " - " << pError);
|
||||
}
|
||||
|
||||
void ColladaParser::ReportWarning(const char* msg, ...) {
|
||||
ai_assert(nullptr != msg);
|
||||
void ColladaParser::ReportWarning(const char* msg, ...)
|
||||
{
|
||||
ai_assert(NULL != msg);
|
||||
|
||||
va_list args;
|
||||
va_start(args, msg);
|
||||
|
|
@ -3261,11 +3191,11 @@ void ColladaParser::ReportWarning(const char* msg, ...) {
|
|||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Skips all data until the end node of the current element
|
||||
void ColladaParser::SkipElement() {
|
||||
void ColladaParser::SkipElement()
|
||||
{
|
||||
// nothing to skip if it's an <element />
|
||||
if (mReader->isEmptyElement()) {
|
||||
if (mReader->isEmptyElement())
|
||||
return;
|
||||
}
|
||||
|
||||
// reroute
|
||||
SkipElement(mReader->getNodeName());
|
||||
|
|
@ -3273,75 +3203,63 @@ void ColladaParser::SkipElement() {
|
|||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Skips all data until the end node of the given element
|
||||
void ColladaParser::SkipElement(const char* pElement) {
|
||||
void ColladaParser::SkipElement(const char* pElement)
|
||||
{
|
||||
// copy the current node's name because it'a pointer to the reader's internal buffer,
|
||||
// which is going to change with the upcoming parsing
|
||||
std::string element = pElement;
|
||||
while (mReader->read()) {
|
||||
if (mReader->getNodeType() == irr::io::EXN_ELEMENT_END) {
|
||||
if (mReader->getNodeName() == element) {
|
||||
while (mReader->read())
|
||||
{
|
||||
if (mReader->getNodeType() == irr::io::EXN_ELEMENT_END)
|
||||
if (mReader->getNodeName() == element)
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Tests for an opening element of the given name, throws an exception if not found
|
||||
void ColladaParser::TestOpening(const char* pName) {
|
||||
void ColladaParser::TestOpening(const char* pName)
|
||||
{
|
||||
// read element start
|
||||
if (!mReader->read()) {
|
||||
if (!mReader->read())
|
||||
ThrowException(format() << "Unexpected end of file while beginning of <" << pName << "> element.");
|
||||
}
|
||||
// whitespace in front is ok, just read again if found
|
||||
if (mReader->getNodeType() == irr::io::EXN_TEXT) {
|
||||
if (!mReader->read()) {
|
||||
if (mReader->getNodeType() == irr::io::EXN_TEXT)
|
||||
if (!mReader->read())
|
||||
ThrowException(format() << "Unexpected end of file while reading beginning of <" << pName << "> element.");
|
||||
}
|
||||
}
|
||||
|
||||
if (mReader->getNodeType() != irr::io::EXN_ELEMENT || strcmp(mReader->getNodeName(), pName) != 0) {
|
||||
if (mReader->getNodeType() != irr::io::EXN_ELEMENT || strcmp(mReader->getNodeName(), pName) != 0)
|
||||
ThrowException(format() << "Expected start of <" << pName << "> element.");
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Tests for the closing tag of the given element, throws an exception if not found
|
||||
void ColladaParser::TestClosing(const char* pName) {
|
||||
// check if we have an empty (self-closing) element
|
||||
if (mReader->isEmptyElement()) {
|
||||
return;
|
||||
}
|
||||
|
||||
void ColladaParser::TestClosing(const char* pName)
|
||||
{
|
||||
// check if we're already on the closing tag and return right away
|
||||
if (mReader->getNodeType() == irr::io::EXN_ELEMENT_END && strcmp(mReader->getNodeName(), pName) == 0) {
|
||||
if (mReader->getNodeType() == irr::io::EXN_ELEMENT_END && strcmp(mReader->getNodeName(), pName) == 0)
|
||||
return;
|
||||
}
|
||||
|
||||
// if not, read some more
|
||||
if (!mReader->read()) {
|
||||
if (!mReader->read())
|
||||
ThrowException(format() << "Unexpected end of file while reading end of <" << pName << "> element.");
|
||||
}
|
||||
// whitespace in front is ok, just read again if found
|
||||
if (mReader->getNodeType() == irr::io::EXN_TEXT) {
|
||||
if (!mReader->read()) {
|
||||
if (mReader->getNodeType() == irr::io::EXN_TEXT)
|
||||
if (!mReader->read())
|
||||
ThrowException(format() << "Unexpected end of file while reading end of <" << pName << "> element.");
|
||||
}
|
||||
}
|
||||
|
||||
// but this has the be the closing tag, or we're lost
|
||||
if (mReader->getNodeType() != irr::io::EXN_ELEMENT_END || strcmp(mReader->getNodeName(), pName) != 0) {
|
||||
if (mReader->getNodeType() != irr::io::EXN_ELEMENT_END || strcmp(mReader->getNodeName(), pName) != 0)
|
||||
ThrowException(format() << "Expected end of <" << pName << "> element.");
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Returns the index of the named attribute or -1 if not found. Does not throw, therefore useful for optional attributes
|
||||
int ColladaParser::GetAttribute(const char* pAttr) const {
|
||||
int ColladaParser::GetAttribute(const char* pAttr) const
|
||||
{
|
||||
int index = TestAttribute(pAttr);
|
||||
if (index != -1) {
|
||||
if (index != -1)
|
||||
return index;
|
||||
}
|
||||
|
||||
// attribute not found -> throw an exception
|
||||
ThrowException(format() << "Expected attribute \"" << pAttr << "\" for element <" << mReader->getNodeName() << ">.");
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
Open Asset Import Library (assimp)
|
||||
----------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2020, assimp team
|
||||
Copyright (c) 2006-2019, assimp team
|
||||
|
||||
|
||||
All rights reserved.
|
||||
|
|
@ -66,15 +66,12 @@ 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();
|
||||
|
|
@ -94,9 +91,12 @@ namespace Assimp
|
|||
/** Reads contributor information such as author and legal blah */
|
||||
void ReadContributorInfo();
|
||||
|
||||
/** Reads generic metadata into provided map and renames keys for Assimp */
|
||||
/** Reads generic metadata into provided map */
|
||||
void ReadMetaDataItem(StringMetaData &metadata);
|
||||
|
||||
/** Convert underscore_seperated to CamelCase "authoring_tool" becomes "AuthoringTool" */
|
||||
static void ToCamelCase(std::string &text);
|
||||
|
||||
/** Reads the animation library */
|
||||
void ReadAnimationLibrary();
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue