Apply Assimp clangformat to touched Collada files
parent
a52b66f10d
commit
2c6ac23a4e
|
@ -45,24 +45,24 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
#include "ColladaExporter.h"
|
#include "ColladaExporter.h"
|
||||||
#include <assimp/Bitmap.h>
|
#include <assimp/Bitmap.h>
|
||||||
#include <assimp/commonMetaData.h>
|
#include <assimp/DefaultIOSystem.h>
|
||||||
#include <assimp/MathFunctions.h>
|
#include <assimp/MathFunctions.h>
|
||||||
#include <assimp/fast_atof.h>
|
|
||||||
#include <assimp/SceneCombiner.h>
|
#include <assimp/SceneCombiner.h>
|
||||||
#include <assimp/StringUtils.h>
|
#include <assimp/StringUtils.h>
|
||||||
#include <assimp/XMLTools.h>
|
#include <assimp/XMLTools.h>
|
||||||
#include <assimp/DefaultIOSystem.h>
|
#include <assimp/commonMetaData.h>
|
||||||
#include <assimp/IOSystem.hpp>
|
#include <assimp/fast_atof.h>
|
||||||
#include <assimp/Exporter.hpp>
|
|
||||||
#include <assimp/scene.h>
|
#include <assimp/scene.h>
|
||||||
|
#include <assimp/Exporter.hpp>
|
||||||
|
#include <assimp/IOSystem.hpp>
|
||||||
|
|
||||||
#include <assimp/Exceptional.h>
|
#include <assimp/Exceptional.h>
|
||||||
|
|
||||||
#include <memory>
|
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
|
#include <iostream>
|
||||||
|
#include <memory>
|
||||||
#include <set>
|
#include <set>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
using namespace Assimp;
|
using namespace Assimp;
|
||||||
|
|
||||||
|
@ -125,10 +125,10 @@ static const std::string XMLIDEncode(const std::string& name) {
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
// Constructor for a specific scene to export
|
// Constructor for a specific scene to export
|
||||||
ColladaExporter::ColladaExporter( const aiScene* pScene, IOSystem* pIOSystem, const std::string& path, const std::string& file)
|
ColladaExporter::ColladaExporter(const aiScene *pScene, IOSystem *pIOSystem, const std::string &path, const std::string &file) :
|
||||||
: mIOSystem(pIOSystem)
|
mIOSystem(pIOSystem),
|
||||||
, mPath(path)
|
mPath(path),
|
||||||
, mFile(file) {
|
mFile(file) {
|
||||||
// make sure that all formatting happens using the standard, C locale and not the user's current locale
|
// make sure that all formatting happens using the standard, C locale and not the user's current locale
|
||||||
mOutput.imbue(std::locale("C"));
|
mOutput.imbue(std::locale("C"));
|
||||||
mOutput.precision(ASSIMP_AI_REAL_TEXT_PRECISION);
|
mOutput.precision(ASSIMP_AI_REAL_TEXT_PRECISION);
|
||||||
|
@ -273,13 +273,17 @@ void ColladaExporter::WriteHeader() {
|
||||||
|
|
||||||
aiString value;
|
aiString value;
|
||||||
if (!meta || !meta->Get("Author", value)) {
|
if (!meta || !meta->Get("Author", value)) {
|
||||||
mOutput << startstr << "<author>" << "Assimp" << "</author>" << endstr;
|
mOutput << startstr << "<author>"
|
||||||
|
<< "Assimp"
|
||||||
|
<< "</author>" << endstr;
|
||||||
} else {
|
} else {
|
||||||
mOutput << startstr << "<author>" << XMLEscape(value.C_Str()) << "</author>" << endstr;
|
mOutput << startstr << "<author>" << XMLEscape(value.C_Str()) << "</author>" << endstr;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nullptr == meta || !meta->Get(AI_METADATA_SOURCE_GENERATOR, value)) {
|
if (nullptr == meta || !meta->Get(AI_METADATA_SOURCE_GENERATOR, value)) {
|
||||||
mOutput << startstr << "<authoring_tool>" << "Assimp Exporter" << "</authoring_tool>" << endstr;
|
mOutput << startstr << "<authoring_tool>"
|
||||||
|
<< "Assimp Exporter"
|
||||||
|
<< "</authoring_tool>" << endstr;
|
||||||
} else {
|
} else {
|
||||||
mOutput << startstr << "<authoring_tool>" << XMLEscape(value.C_Str()) << "</authoring_tool>" << endstr;
|
mOutput << startstr << "<authoring_tool>" << XMLEscape(value.C_Str()) << "</authoring_tool>" << endstr;
|
||||||
}
|
}
|
||||||
|
@ -380,7 +384,6 @@ void ColladaExporter::WriteCamerasLibrary() {
|
||||||
|
|
||||||
PopTag();
|
PopTag();
|
||||||
mOutput << startstr << "</library_cameras>" << endstr;
|
mOutput << startstr << "</library_cameras>" << endstr;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -400,8 +403,7 @@ void ColladaExporter::WriteCamera(size_t pIndex){
|
||||||
//always perspective
|
//always perspective
|
||||||
mOutput << startstr << "<perspective>" << endstr;
|
mOutput << startstr << "<perspective>" << endstr;
|
||||||
PushTag();
|
PushTag();
|
||||||
mOutput << startstr << "<xfov sid=\"xfov\">"<<
|
mOutput << startstr << "<xfov sid=\"xfov\">" << AI_RAD_TO_DEG(cam->mHorizontalFOV)
|
||||||
AI_RAD_TO_DEG(cam->mHorizontalFOV)
|
|
||||||
<< "</xfov>" << endstr;
|
<< "</xfov>" << endstr;
|
||||||
mOutput << startstr << "<aspect_ratio>"
|
mOutput << startstr << "<aspect_ratio>"
|
||||||
<< cam->mAspect
|
<< cam->mAspect
|
||||||
|
@ -420,10 +422,8 @@ void ColladaExporter::WriteCamera(size_t pIndex){
|
||||||
mOutput << startstr << "</optics>" << endstr;
|
mOutput << startstr << "</optics>" << endstr;
|
||||||
PopTag();
|
PopTag();
|
||||||
mOutput << startstr << "</camera>" << endstr;
|
mOutput << startstr << "</camera>" << endstr;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
// Write the embedded textures
|
// Write the embedded textures
|
||||||
void ColladaExporter::WriteLightsLibrary() {
|
void ColladaExporter::WriteLightsLibrary() {
|
||||||
|
@ -437,7 +437,6 @@ void ColladaExporter::WriteLightsLibrary() {
|
||||||
|
|
||||||
PopTag();
|
PopTag();
|
||||||
mOutput << startstr << "</library_lights>" << endstr;
|
mOutput << startstr << "</library_lights>" << endstr;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -475,7 +474,6 @@ void ColladaExporter::WriteLight(size_t pIndex){
|
||||||
|
|
||||||
PopTag();
|
PopTag();
|
||||||
mOutput << startstr << "</light>" << endstr;
|
mOutput << startstr << "</light>" << endstr;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ColladaExporter::WritePointLight(const aiLight *const light) {
|
void ColladaExporter::WritePointLight(const aiLight *const light) {
|
||||||
|
@ -497,7 +495,6 @@ void ColladaExporter::WritePointLight(const aiLight *const light){
|
||||||
|
|
||||||
PopTag();
|
PopTag();
|
||||||
mOutput << startstr << "</point>" << endstr;
|
mOutput << startstr << "</point>" << endstr;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ColladaExporter::WriteDirectionalLight(const aiLight *const light) {
|
void ColladaExporter::WriteDirectionalLight(const aiLight *const light) {
|
||||||
|
@ -510,7 +507,6 @@ void ColladaExporter::WriteDirectionalLight(const aiLight *const light){
|
||||||
|
|
||||||
PopTag();
|
PopTag();
|
||||||
mOutput << startstr << "</directional>" << endstr;
|
mOutput << startstr << "</directional>" << endstr;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ColladaExporter::WriteSpotLight(const aiLight *const light) {
|
void ColladaExporter::WriteSpotLight(const aiLight *const light) {
|
||||||
|
@ -548,10 +544,8 @@ void ColladaExporter::WriteSpotLight(const aiLight *const light){
|
||||||
<< temp
|
<< temp
|
||||||
<< "</falloff_exponent>" << endstr;
|
<< "</falloff_exponent>" << endstr;
|
||||||
|
|
||||||
|
|
||||||
PopTag();
|
PopTag();
|
||||||
mOutput << startstr << "</spot>" << endstr;
|
mOutput << startstr << "</spot>" << endstr;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ColladaExporter::WriteAmbienttLight(const aiLight *const light) {
|
void ColladaExporter::WriteAmbienttLight(const aiLight *const light) {
|
||||||
|
@ -617,16 +611,14 @@ static bool isalnum_C(char c) {
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
// Writes an image entry for the given surface
|
// Writes an image entry for the given surface
|
||||||
void ColladaExporter::WriteImageEntry(const Surface &pSurface, const std::string &pNameAdd) {
|
void ColladaExporter::WriteImageEntry(const Surface &pSurface, const std::string &pNameAdd) {
|
||||||
if( !pSurface.texture.empty() )
|
if (!pSurface.texture.empty()) {
|
||||||
{
|
|
||||||
mOutput << startstr << "<image id=\"" << XMLIDEncode(pNameAdd) << "\">" << endstr;
|
mOutput << startstr << "<image id=\"" << XMLIDEncode(pNameAdd) << "\">" << endstr;
|
||||||
PushTag();
|
PushTag();
|
||||||
mOutput << startstr << "<init_from>";
|
mOutput << startstr << "<init_from>";
|
||||||
|
|
||||||
// URL encode image file name first, then XML encode on top
|
// URL encode image file name first, then XML encode on top
|
||||||
std::stringstream imageUrlEncoded;
|
std::stringstream imageUrlEncoded;
|
||||||
for( std::string::const_iterator it = pSurface.texture.begin(); it != pSurface.texture.end(); ++it )
|
for (std::string::const_iterator it = pSurface.texture.begin(); it != pSurface.texture.end(); ++it) {
|
||||||
{
|
|
||||||
if (isalnum_C((unsigned char)*it) || *it == ':' || *it == '_' || *it == '-' || *it == '.' || *it == '/' || *it == '\\')
|
if (isalnum_C((unsigned char)*it) || *it == ':' || *it == '_' || *it == '-' || *it == '.' || *it == '/' || *it == '\\')
|
||||||
imageUrlEncoded << *it;
|
imageUrlEncoded << *it;
|
||||||
else
|
else
|
||||||
|
@ -641,17 +633,13 @@ void ColladaExporter::WriteImageEntry( const Surface& pSurface, const std::strin
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
// Writes a color-or-texture entry into an effect definition
|
// Writes a color-or-texture entry into an effect definition
|
||||||
void ColladaExporter::WriteTextureColorEntry( const Surface& pSurface, const std::string& pTypeName, const std::string& pImageName)
|
void ColladaExporter::WriteTextureColorEntry(const Surface &pSurface, const std::string &pTypeName, const std::string &pImageName) {
|
||||||
{
|
|
||||||
if (pSurface.exist) {
|
if (pSurface.exist) {
|
||||||
mOutput << startstr << "<" << pTypeName << ">" << endstr;
|
mOutput << startstr << "<" << pTypeName << ">" << endstr;
|
||||||
PushTag();
|
PushTag();
|
||||||
if( pSurface.texture.empty() )
|
if (pSurface.texture.empty()) {
|
||||||
{
|
|
||||||
mOutput << startstr << "<color sid=\"" << pTypeName << "\">" << pSurface.color.r << " " << pSurface.color.g << " " << pSurface.color.b << " " << pSurface.color.a << "</color>" << endstr;
|
mOutput << startstr << "<color sid=\"" << pTypeName << "\">" << pSurface.color.r << " " << pSurface.color.g << " " << pSurface.color.b << " " << pSurface.color.a << "</color>" << endstr;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
mOutput << startstr << "<texture texture=\"" << XMLIDEncode(pImageName) << "\" texcoord=\"CHANNEL" << pSurface.channel << "\" />" << endstr;
|
mOutput << startstr << "<texture texture=\"" << XMLIDEncode(pImageName) << "\" texcoord=\"CHANNEL" << pSurface.channel << "\" />" << endstr;
|
||||||
}
|
}
|
||||||
PopTag();
|
PopTag();
|
||||||
|
@ -661,11 +649,9 @@ void ColladaExporter::WriteTextureColorEntry( const Surface& pSurface, const std
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
// Writes the two parameters necessary for referencing a texture in an effect entry
|
// Writes the two parameters necessary for referencing a texture in an effect entry
|
||||||
void ColladaExporter::WriteTextureParamEntry( const Surface& pSurface, const std::string& pTypeName, const std::string& pMatName)
|
void ColladaExporter::WriteTextureParamEntry(const Surface &pSurface, const std::string &pTypeName, const std::string &pMatName) {
|
||||||
{
|
|
||||||
// if surface is a texture, write out the sampler and the surface parameters necessary to reference the texture
|
// if surface is a texture, write out the sampler and the surface parameters necessary to reference the texture
|
||||||
if( !pSurface.texture.empty() )
|
if (!pSurface.texture.empty()) {
|
||||||
{
|
|
||||||
mOutput << startstr << "<newparam sid=\"" << XMLIDEncode(pMatName) << "-" << pTypeName << "-surface\">" << endstr;
|
mOutput << startstr << "<newparam sid=\"" << XMLIDEncode(pMatName) << "-" << pTypeName << "-surface\">" << endstr;
|
||||||
PushTag();
|
PushTag();
|
||||||
mOutput << startstr << "<surface type=\"2D\">" << endstr;
|
mOutput << startstr << "<surface type=\"2D\">" << endstr;
|
||||||
|
@ -690,8 +676,7 @@ void ColladaExporter::WriteTextureParamEntry( const Surface& pSurface, const std
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
// Writes a scalar property
|
// Writes a scalar property
|
||||||
void ColladaExporter::WriteFloatEntry( const Property& pProperty, const std::string& pTypeName)
|
void ColladaExporter::WriteFloatEntry(const Property &pProperty, const std::string &pTypeName) {
|
||||||
{
|
|
||||||
if (pProperty.exist) {
|
if (pProperty.exist) {
|
||||||
mOutput << startstr << "<" << pTypeName << ">" << endstr;
|
mOutput << startstr << "<" << pTypeName << ">" << endstr;
|
||||||
PushTag();
|
PushTag();
|
||||||
|
@ -703,14 +688,12 @@ void ColladaExporter::WriteFloatEntry( const Property& pProperty, const std::str
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
// Writes the material setup
|
// Writes the material setup
|
||||||
void ColladaExporter::WriteMaterials()
|
void ColladaExporter::WriteMaterials() {
|
||||||
{
|
|
||||||
materials.resize(mScene->mNumMaterials);
|
materials.resize(mScene->mNumMaterials);
|
||||||
|
|
||||||
/// collect all materials from the scene
|
/// collect all materials from the scene
|
||||||
size_t numTextures = 0;
|
size_t numTextures = 0;
|
||||||
for( size_t a = 0; a < mScene->mNumMaterials; ++a )
|
for (size_t a = 0; a < mScene->mNumMaterials; ++a) {
|
||||||
{
|
|
||||||
const aiMaterial *mat = mScene->mMaterials[a];
|
const aiMaterial *mat = mScene->mMaterials[a];
|
||||||
|
|
||||||
aiString name;
|
aiString name;
|
||||||
|
@ -768,12 +751,10 @@ void ColladaExporter::WriteMaterials()
|
||||||
}
|
}
|
||||||
|
|
||||||
// output textures if present
|
// output textures if present
|
||||||
if( numTextures > 0 )
|
if (numTextures > 0) {
|
||||||
{
|
|
||||||
mOutput << startstr << "<library_images>" << endstr;
|
mOutput << startstr << "<library_images>" << endstr;
|
||||||
PushTag();
|
PushTag();
|
||||||
for( std::vector<Material>::const_iterator it = materials.begin(); it != materials.end(); ++it )
|
for (std::vector<Material>::const_iterator it = materials.begin(); it != materials.end(); ++it) {
|
||||||
{
|
|
||||||
const Material &mat = *it;
|
const Material &mat = *it;
|
||||||
WriteImageEntry(mat.ambient, mat.name + "-ambient-image");
|
WriteImageEntry(mat.ambient, mat.name + "-ambient-image");
|
||||||
WriteImageEntry(mat.diffuse, mat.name + "-diffuse-image");
|
WriteImageEntry(mat.diffuse, mat.name + "-diffuse-image");
|
||||||
|
@ -788,12 +769,10 @@ void ColladaExporter::WriteMaterials()
|
||||||
}
|
}
|
||||||
|
|
||||||
// output effects - those are the actual carriers of information
|
// output effects - those are the actual carriers of information
|
||||||
if( !materials.empty() )
|
if (!materials.empty()) {
|
||||||
{
|
|
||||||
mOutput << startstr << "<library_effects>" << endstr;
|
mOutput << startstr << "<library_effects>" << endstr;
|
||||||
PushTag();
|
PushTag();
|
||||||
for( std::vector<Material>::const_iterator it = materials.begin(); it != materials.end(); ++it )
|
for (std::vector<Material>::const_iterator it = materials.begin(); it != materials.end(); ++it) {
|
||||||
{
|
|
||||||
const Material &mat = *it;
|
const Material &mat = *it;
|
||||||
// this is so ridiculous it must be right
|
// 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=\"" << XMLIDEncode(mat.name) << "-fx\" name=\"" << XMLEscape(mat.name) << "\">" << endstr;
|
||||||
|
@ -844,8 +823,7 @@ void ColladaExporter::WriteMaterials()
|
||||||
// write materials - they're just effect references
|
// write materials - they're just effect references
|
||||||
mOutput << startstr << "<library_materials>" << endstr;
|
mOutput << startstr << "<library_materials>" << endstr;
|
||||||
PushTag();
|
PushTag();
|
||||||
for( std::vector<Material>::const_iterator it = materials.begin(); it != materials.end(); ++it )
|
for (std::vector<Material>::const_iterator it = materials.begin(); it != materials.end(); ++it) {
|
||||||
{
|
|
||||||
const Material &mat = *it;
|
const Material &mat = *it;
|
||||||
mOutput << startstr << "<material id=\"" << XMLIDEncode(mat.name) << "\" name=\"" << XMLEscape(mat.name) << "\">" << endstr;
|
mOutput << startstr << "<material id=\"" << XMLIDEncode(mat.name) << "\" name=\"" << XMLEscape(mat.name) << "\">" << endstr;
|
||||||
PushTag();
|
PushTag();
|
||||||
|
@ -860,8 +838,7 @@ void ColladaExporter::WriteMaterials()
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
// Writes the controller library
|
// Writes the controller library
|
||||||
void ColladaExporter::WriteControllerLibrary()
|
void ColladaExporter::WriteControllerLibrary() {
|
||||||
{
|
|
||||||
mOutput << startstr << "<library_controllers>" << endstr;
|
mOutput << startstr << "<library_controllers>" << endstr;
|
||||||
PushTag();
|
PushTag();
|
||||||
|
|
||||||
|
@ -875,8 +852,7 @@ void ColladaExporter::WriteControllerLibrary()
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
// Writes a skin controller of the given mesh
|
// Writes a skin controller of the given mesh
|
||||||
void ColladaExporter::WriteController( size_t pIndex)
|
void ColladaExporter::WriteController(size_t pIndex) {
|
||||||
{
|
|
||||||
const aiMesh *mesh = mScene->mMeshes[pIndex];
|
const aiMesh *mesh = mScene->mMeshes[pIndex];
|
||||||
const std::string idstr = mesh->mName.length == 0 ? GetMeshId(pIndex) : mesh->mName.C_Str();
|
const std::string idstr = mesh->mName.length == 0 ? GetMeshId(pIndex) : mesh->mName.C_Str();
|
||||||
const std::string idstrEscaped = XMLIDEncode(idstr);
|
const std::string idstrEscaped = XMLIDEncode(idstr);
|
||||||
|
@ -987,8 +963,7 @@ void ColladaExporter::WriteController( size_t pIndex)
|
||||||
ai_uint joint_weight_indices_length = 0;
|
ai_uint joint_weight_indices_length = 0;
|
||||||
std::vector<ai_uint> accum_influences;
|
std::vector<ai_uint> accum_influences;
|
||||||
accum_influences.reserve(num_influences.size());
|
accum_influences.reserve(num_influences.size());
|
||||||
for( size_t i = 0; i < num_influences.size(); ++i)
|
for (size_t i = 0; i < num_influences.size(); ++i) {
|
||||||
{
|
|
||||||
accum_influences.push_back(joint_weight_indices_length);
|
accum_influences.push_back(joint_weight_indices_length);
|
||||||
joint_weight_indices_length += num_influences[i];
|
joint_weight_indices_length += num_influences[i];
|
||||||
}
|
}
|
||||||
|
@ -996,13 +971,10 @@ void ColladaExporter::WriteController( size_t pIndex)
|
||||||
ai_uint weight_index = 0;
|
ai_uint weight_index = 0;
|
||||||
std::vector<ai_int> joint_weight_indices(2 * joint_weight_indices_length, (ai_int)-1);
|
std::vector<ai_int> joint_weight_indices(2 * joint_weight_indices_length, (ai_int)-1);
|
||||||
for (unsigned int i = 0; i < mesh->mNumBones; ++i)
|
for (unsigned int i = 0; i < mesh->mNumBones; ++i)
|
||||||
for( unsigned j = 0; j < mesh->mBones[i]->mNumWeights; ++j)
|
for (unsigned j = 0; j < mesh->mBones[i]->mNumWeights; ++j) {
|
||||||
{
|
|
||||||
unsigned int vId = mesh->mBones[i]->mWeights[j].mVertexId;
|
unsigned int vId = mesh->mBones[i]->mWeights[j].mVertexId;
|
||||||
for( ai_uint k = 0; k < num_influences[vId]; ++k)
|
for (ai_uint k = 0; k < num_influences[vId]; ++k) {
|
||||||
{
|
if (joint_weight_indices[2 * (accum_influences[vId] + k)] == -1) {
|
||||||
if (joint_weight_indices[2 * (accum_influences[vId] + k)] == -1)
|
|
||||||
{
|
|
||||||
joint_weight_indices[2 * (accum_influences[vId] + k)] = i;
|
joint_weight_indices[2 * (accum_influences[vId] + k)] = i;
|
||||||
joint_weight_indices[2 * (accum_influences[vId] + k) + 1] = weight_index;
|
joint_weight_indices[2 * (accum_influences[vId] + k) + 1] = weight_index;
|
||||||
break;
|
break;
|
||||||
|
@ -1032,8 +1004,7 @@ void ColladaExporter::WriteController( size_t pIndex)
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
// Writes the geometry library
|
// Writes the geometry library
|
||||||
void ColladaExporter::WriteGeometryLibrary()
|
void ColladaExporter::WriteGeometryLibrary() {
|
||||||
{
|
|
||||||
mOutput << startstr << "<library_geometries>" << endstr;
|
mOutput << startstr << "<library_geometries>" << endstr;
|
||||||
PushTag();
|
PushTag();
|
||||||
|
|
||||||
|
@ -1046,8 +1017,7 @@ void ColladaExporter::WriteGeometryLibrary()
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
// Writes the given mesh
|
// Writes the given mesh
|
||||||
void ColladaExporter::WriteGeometry( size_t pIndex)
|
void ColladaExporter::WriteGeometry(size_t pIndex) {
|
||||||
{
|
|
||||||
const aiMesh *mesh = mScene->mMeshes[pIndex];
|
const aiMesh *mesh = mScene->mMeshes[pIndex];
|
||||||
const std::string idstr = mesh->mName.length == 0 ? GetMeshId(pIndex) : mesh->mName.C_Str();
|
const std::string idstr = mesh->mName.length == 0 ? GetMeshId(pIndex) : mesh->mName.C_Str();
|
||||||
const std::string geometryName = XMLEscape(idstr);
|
const std::string geometryName = XMLEscape(idstr);
|
||||||
|
@ -1070,25 +1040,23 @@ void ColladaExporter::WriteGeometry( size_t pIndex)
|
||||||
WriteFloatArray(idstr + "-normals", FloatType_Vector, (ai_real *)mesh->mNormals, mesh->mNumVertices);
|
WriteFloatArray(idstr + "-normals", FloatType_Vector, (ai_real *)mesh->mNormals, mesh->mNumVertices);
|
||||||
|
|
||||||
// texture coords
|
// texture coords
|
||||||
for( size_t a = 0; a < AI_MAX_NUMBER_OF_TEXTURECOORDS; ++a)
|
for (size_t a = 0; a < AI_MAX_NUMBER_OF_TEXTURECOORDS; ++a) {
|
||||||
{
|
if (mesh->HasTextureCoords(static_cast<unsigned int>(a))) {
|
||||||
if( mesh->HasTextureCoords(static_cast<unsigned int>(a)) )
|
|
||||||
{
|
|
||||||
WriteFloatArray(idstr + "-tex" + to_string(a), mesh->mNumUVComponents[a] == 3 ? FloatType_TexCoord3 : FloatType_TexCoord2,
|
WriteFloatArray(idstr + "-tex" + to_string(a), mesh->mNumUVComponents[a] == 3 ? FloatType_TexCoord3 : FloatType_TexCoord2,
|
||||||
(ai_real *)mesh->mTextureCoords[a], mesh->mNumVertices);
|
(ai_real *)mesh->mTextureCoords[a], mesh->mNumVertices);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// vertex colors
|
// vertex colors
|
||||||
for( size_t a = 0; a < AI_MAX_NUMBER_OF_TEXTURECOORDS; ++a)
|
for (size_t a = 0; a < AI_MAX_NUMBER_OF_TEXTURECOORDS; ++a) {
|
||||||
{
|
|
||||||
if (mesh->HasVertexColors(static_cast<unsigned int>(a)))
|
if (mesh->HasVertexColors(static_cast<unsigned int>(a)))
|
||||||
WriteFloatArray(idstr + "-color" + to_string(a), FloatType_Color, (ai_real *)mesh->mColors[a], mesh->mNumVertices);
|
WriteFloatArray(idstr + "-color" + to_string(a), FloatType_Color, (ai_real *)mesh->mColors[a], mesh->mNumVertices);
|
||||||
}
|
}
|
||||||
|
|
||||||
// assemble vertex structure
|
// assemble vertex structure
|
||||||
// Only write input for POSITION since we will write other as shared inputs in polygon definition
|
// 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=\"" << geometryId << "-vertices"
|
||||||
|
<< "\">" << endstr;
|
||||||
PushTag();
|
PushTag();
|
||||||
mOutput << startstr << "<input semantic=\"POSITION\" source=\"#" << geometryId << "-positions\" />" << endstr;
|
mOutput << startstr << "<input semantic=\"POSITION\" source=\"#" << geometryId << "-positions\" />" << endstr;
|
||||||
PopTag();
|
PopTag();
|
||||||
|
@ -1097,34 +1065,35 @@ void ColladaExporter::WriteGeometry( size_t pIndex)
|
||||||
// count the number of lines, triangles and polygon meshes
|
// count the number of lines, triangles and polygon meshes
|
||||||
int countLines = 0;
|
int countLines = 0;
|
||||||
int countPoly = 0;
|
int countPoly = 0;
|
||||||
for( size_t a = 0; a < mesh->mNumFaces; ++a )
|
for (size_t a = 0; a < mesh->mNumFaces; ++a) {
|
||||||
{
|
if (mesh->mFaces[a].mNumIndices == 2)
|
||||||
if (mesh->mFaces[a].mNumIndices == 2) countLines++;
|
countLines++;
|
||||||
else if (mesh->mFaces[a].mNumIndices >= 3) countPoly++;
|
else if (mesh->mFaces[a].mNumIndices >= 3)
|
||||||
|
countPoly++;
|
||||||
}
|
}
|
||||||
|
|
||||||
// lines
|
// lines
|
||||||
if (countLines)
|
if (countLines) {
|
||||||
{
|
|
||||||
mOutput << startstr << "<lines count=\"" << countLines << "\" material=\"defaultMaterial\">" << endstr;
|
mOutput << startstr << "<lines count=\"" << countLines << "\" material=\"defaultMaterial\">" << endstr;
|
||||||
PushTag();
|
PushTag();
|
||||||
mOutput << startstr << "<input offset=\"0\" semantic=\"VERTEX\" source=\"#" << geometryId << "-vertices\" />" << endstr;
|
mOutput << startstr << "<input offset=\"0\" semantic=\"VERTEX\" source=\"#" << geometryId << "-vertices\" />" << endstr;
|
||||||
if (mesh->HasNormals())
|
if (mesh->HasNormals())
|
||||||
mOutput << startstr << "<input semantic=\"NORMAL\" source=\"#" << geometryId << "-normals\" />" << endstr;
|
mOutput << startstr << "<input semantic=\"NORMAL\" source=\"#" << geometryId << "-normals\" />" << endstr;
|
||||||
for( size_t a = 0; a < AI_MAX_NUMBER_OF_TEXTURECOORDS; ++a )
|
for (size_t a = 0; a < AI_MAX_NUMBER_OF_TEXTURECOORDS; ++a) {
|
||||||
{
|
|
||||||
if (mesh->HasTextureCoords(static_cast<unsigned int>(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=\"#" << geometryId << "-tex" << a << "\" "
|
||||||
|
<< "set=\"" << a << "\""
|
||||||
|
<< " />" << endstr;
|
||||||
}
|
}
|
||||||
for( size_t a = 0; a < AI_MAX_NUMBER_OF_COLOR_SETS; ++a )
|
for (size_t a = 0; a < AI_MAX_NUMBER_OF_COLOR_SETS; ++a) {
|
||||||
{
|
|
||||||
if (mesh->HasVertexColors(static_cast<unsigned int>(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=\"#" << geometryId << "-color" << a << "\" "
|
||||||
|
<< "set=\"" << a << "\""
|
||||||
|
<< " />" << endstr;
|
||||||
}
|
}
|
||||||
|
|
||||||
mOutput << startstr << "<p>";
|
mOutput << startstr << "<p>";
|
||||||
for( size_t a = 0; a < mesh->mNumFaces; ++a )
|
for (size_t a = 0; a < mesh->mNumFaces; ++a) {
|
||||||
{
|
|
||||||
const aiFace &face = mesh->mFaces[a];
|
const aiFace &face = mesh->mFaces[a];
|
||||||
if (face.mNumIndices != 2) continue;
|
if (face.mNumIndices != 2) continue;
|
||||||
for (size_t b = 0; b < face.mNumIndices; ++b)
|
for (size_t b = 0; b < face.mNumIndices; ++b)
|
||||||
|
@ -1138,35 +1107,34 @@ void ColladaExporter::WriteGeometry( size_t pIndex)
|
||||||
// triangle - don't use it, because compatibility problems
|
// triangle - don't use it, because compatibility problems
|
||||||
|
|
||||||
// polygons
|
// polygons
|
||||||
if (countPoly)
|
if (countPoly) {
|
||||||
{
|
|
||||||
mOutput << startstr << "<polylist count=\"" << countPoly << "\" material=\"defaultMaterial\">" << endstr;
|
mOutput << startstr << "<polylist count=\"" << countPoly << "\" material=\"defaultMaterial\">" << endstr;
|
||||||
PushTag();
|
PushTag();
|
||||||
mOutput << startstr << "<input offset=\"0\" semantic=\"VERTEX\" source=\"#" << geometryId << "-vertices\" />" << endstr;
|
mOutput << startstr << "<input offset=\"0\" semantic=\"VERTEX\" source=\"#" << geometryId << "-vertices\" />" << endstr;
|
||||||
if (mesh->HasNormals())
|
if (mesh->HasNormals())
|
||||||
mOutput << startstr << "<input offset=\"0\" semantic=\"NORMAL\" source=\"#" << geometryId << "-normals\" />" << endstr;
|
mOutput << startstr << "<input offset=\"0\" semantic=\"NORMAL\" source=\"#" << geometryId << "-normals\" />" << endstr;
|
||||||
for( size_t a = 0; a < AI_MAX_NUMBER_OF_TEXTURECOORDS; ++a )
|
for (size_t a = 0; a < AI_MAX_NUMBER_OF_TEXTURECOORDS; ++a) {
|
||||||
{
|
|
||||||
if (mesh->HasTextureCoords(static_cast<unsigned int>(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=\"#" << geometryId << "-tex" << a << "\" "
|
||||||
|
<< "set=\"" << a << "\""
|
||||||
|
<< " />" << endstr;
|
||||||
}
|
}
|
||||||
for( size_t a = 0; a < AI_MAX_NUMBER_OF_COLOR_SETS; ++a )
|
for (size_t a = 0; a < AI_MAX_NUMBER_OF_COLOR_SETS; ++a) {
|
||||||
{
|
|
||||||
if (mesh->HasVertexColors(static_cast<unsigned int>(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=\"#" << geometryId << "-color" << a << "\" "
|
||||||
|
<< "set=\"" << a << "\""
|
||||||
|
<< " />" << endstr;
|
||||||
}
|
}
|
||||||
|
|
||||||
mOutput << startstr << "<vcount>";
|
mOutput << startstr << "<vcount>";
|
||||||
for( size_t a = 0; a < mesh->mNumFaces; ++a )
|
for (size_t a = 0; a < mesh->mNumFaces; ++a) {
|
||||||
{
|
|
||||||
if (mesh->mFaces[a].mNumIndices < 3) continue;
|
if (mesh->mFaces[a].mNumIndices < 3) continue;
|
||||||
mOutput << mesh->mFaces[a].mNumIndices << " ";
|
mOutput << mesh->mFaces[a].mNumIndices << " ";
|
||||||
}
|
}
|
||||||
mOutput << "</vcount>" << endstr;
|
mOutput << "</vcount>" << endstr;
|
||||||
|
|
||||||
mOutput << startstr << "<p>";
|
mOutput << startstr << "<p>";
|
||||||
for( size_t a = 0; a < mesh->mNumFaces; ++a )
|
for (size_t a = 0; a < mesh->mNumFaces; ++a) {
|
||||||
{
|
|
||||||
const aiFace &face = mesh->mFaces[a];
|
const aiFace &face = mesh->mFaces[a];
|
||||||
if (face.mNumIndices < 3) continue;
|
if (face.mNumIndices < 3) continue;
|
||||||
for (size_t b = 0; b < face.mNumIndices; ++b)
|
for (size_t b = 0; b < face.mNumIndices; ++b)
|
||||||
|
@ -1186,11 +1154,9 @@ void ColladaExporter::WriteGeometry( size_t pIndex)
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
// Writes a float array of the given type
|
// Writes a float array of the given type
|
||||||
void ColladaExporter::WriteFloatArray( const std::string& pIdString, FloatDataType pType, const ai_real* pData, size_t pElementCount)
|
void ColladaExporter::WriteFloatArray(const std::string &pIdString, FloatDataType pType, const ai_real *pData, size_t pElementCount) {
|
||||||
{
|
|
||||||
size_t floatsPerElement = 0;
|
size_t floatsPerElement = 0;
|
||||||
switch( pType )
|
switch (pType) {
|
||||||
{
|
|
||||||
case FloatType_Vector: floatsPerElement = 3; break;
|
case FloatType_Vector: floatsPerElement = 3; break;
|
||||||
case FloatType_TexCoord2: floatsPerElement = 2; break;
|
case FloatType_TexCoord2: floatsPerElement = 2; break;
|
||||||
case FloatType_TexCoord3: floatsPerElement = 3; break;
|
case FloatType_TexCoord3: floatsPerElement = 3; break;
|
||||||
|
@ -1211,25 +1177,18 @@ void ColladaExporter::WriteFloatArray( const std::string& pIdString, FloatDataTy
|
||||||
mOutput << startstr << "<float_array id=\"" << arrayId << "\" count=\"" << pElementCount * floatsPerElement << "\"> ";
|
mOutput << startstr << "<float_array id=\"" << arrayId << "\" count=\"" << pElementCount * floatsPerElement << "\"> ";
|
||||||
PushTag();
|
PushTag();
|
||||||
|
|
||||||
if( pType == FloatType_TexCoord2 )
|
if (pType == FloatType_TexCoord2) {
|
||||||
{
|
for (size_t a = 0; a < pElementCount; ++a) {
|
||||||
for( size_t a = 0; a < pElementCount; ++a )
|
|
||||||
{
|
|
||||||
mOutput << pData[a * 3 + 0] << " ";
|
mOutput << pData[a * 3 + 0] << " ";
|
||||||
mOutput << pData[a * 3 + 1] << " ";
|
mOutput << pData[a * 3 + 1] << " ";
|
||||||
}
|
}
|
||||||
}
|
} else if (pType == FloatType_Color) {
|
||||||
else if( pType == FloatType_Color )
|
for (size_t a = 0; a < pElementCount; ++a) {
|
||||||
{
|
|
||||||
for( size_t a = 0; a < pElementCount; ++a )
|
|
||||||
{
|
|
||||||
mOutput << pData[a * 4 + 0] << " ";
|
mOutput << pData[a * 4 + 0] << " ";
|
||||||
mOutput << pData[a * 4 + 1] << " ";
|
mOutput << pData[a * 4 + 1] << " ";
|
||||||
mOutput << pData[a * 4 + 2] << " ";
|
mOutput << pData[a * 4 + 2] << " ";
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
for (size_t a = 0; a < pElementCount * floatsPerElement; ++a)
|
for (size_t a = 0; a < pElementCount * floatsPerElement; ++a)
|
||||||
mOutput << pData[a] << " ";
|
mOutput << pData[a] << " ";
|
||||||
}
|
}
|
||||||
|
@ -1242,8 +1201,7 @@ void ColladaExporter::WriteFloatArray( const std::string& pIdString, FloatDataTy
|
||||||
mOutput << startstr << "<accessor count=\"" << pElementCount << "\" offset=\"0\" source=\"#" << arrayId << "\" stride=\"" << floatsPerElement << "\">" << endstr;
|
mOutput << startstr << "<accessor count=\"" << pElementCount << "\" offset=\"0\" source=\"#" << arrayId << "\" stride=\"" << floatsPerElement << "\">" << endstr;
|
||||||
PushTag();
|
PushTag();
|
||||||
|
|
||||||
switch( pType )
|
switch (pType) {
|
||||||
{
|
|
||||||
case FloatType_Vector:
|
case FloatType_Vector:
|
||||||
mOutput << startstr << "<param name=\"X\" type=\"float\" />" << endstr;
|
mOutput << startstr << "<param name=\"X\" type=\"float\" />" << endstr;
|
||||||
mOutput << startstr << "<param name=\"Y\" type=\"float\" />" << endstr;
|
mOutput << startstr << "<param name=\"Y\" type=\"float\" />" << endstr;
|
||||||
|
@ -1279,7 +1237,6 @@ void ColladaExporter::WriteFloatArray( const std::string& pIdString, FloatDataTy
|
||||||
case FloatType_Time:
|
case FloatType_Time:
|
||||||
mOutput << startstr << "<param name=\"TIME\" type=\"float\" />" << endstr;
|
mOutput << startstr << "<param name=\"TIME\" type=\"float\" />" << endstr;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PopTag();
|
PopTag();
|
||||||
|
@ -1292,8 +1249,7 @@ void ColladaExporter::WriteFloatArray( const std::string& pIdString, FloatDataTy
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
// Writes the scene library
|
// Writes the scene library
|
||||||
void ColladaExporter::WriteSceneLibrary()
|
void ColladaExporter::WriteSceneLibrary() {
|
||||||
{
|
|
||||||
const std::string sceneName = 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());
|
const std::string sceneId = XMLIDEncode(mScene->mRootNode->mName.C_Str());
|
||||||
|
|
||||||
|
@ -1312,8 +1268,7 @@ void ColladaExporter::WriteSceneLibrary()
|
||||||
mOutput << startstr << "</library_visual_scenes>" << endstr;
|
mOutput << startstr << "</library_visual_scenes>" << endstr;
|
||||||
}
|
}
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
void ColladaExporter::WriteAnimationLibrary(size_t pIndex)
|
void ColladaExporter::WriteAnimationLibrary(size_t pIndex) {
|
||||||
{
|
|
||||||
const aiAnimation *anim = mScene->mAnimations[pIndex];
|
const aiAnimation *anim = mScene->mAnimations[pIndex];
|
||||||
|
|
||||||
if (anim->mNumChannels == 0 && anim->mNumMeshChannels == 0 && anim->mNumMorphMeshChannels == 0)
|
if (anim->mNumChannels == 0 && anim->mNumMeshChannels == 0 && anim->mNumMorphMeshChannels == 0)
|
||||||
|
@ -1369,7 +1324,9 @@ void ColladaExporter::WriteAnimationLibrary(size_t pIndex)
|
||||||
for (size_t i = 0; i < nodeAnim->mNumPositionKeys; ++i) {
|
for (size_t i = 0; i < nodeAnim->mNumPositionKeys; ++i) {
|
||||||
aiVector3D Scaling = nodeAnim->mScalingKeys[i].mValue;
|
aiVector3D Scaling = nodeAnim->mScalingKeys[i].mValue;
|
||||||
aiMatrix4x4 ScalingM; // identity
|
aiMatrix4x4 ScalingM; // identity
|
||||||
ScalingM[0][0] = Scaling.x; ScalingM[1][1] = Scaling.y; ScalingM[2][2] = Scaling.z;
|
ScalingM[0][0] = Scaling.x;
|
||||||
|
ScalingM[1][1] = Scaling.y;
|
||||||
|
ScalingM[2][2] = Scaling.z;
|
||||||
|
|
||||||
aiQuaternion RotationQ = nodeAnim->mRotationKeys[i].mValue;
|
aiQuaternion RotationQ = nodeAnim->mRotationKeys[i].mValue;
|
||||||
aiMatrix4x4 s = aiMatrix4x4(RotationQ.GetMatrix());
|
aiMatrix4x4 s = aiMatrix4x4(RotationQ.GetMatrix());
|
||||||
|
@ -1377,7 +1334,9 @@ void ColladaExporter::WriteAnimationLibrary(size_t pIndex)
|
||||||
|
|
||||||
aiVector3D Translation = nodeAnim->mPositionKeys[i].mValue;
|
aiVector3D Translation = nodeAnim->mPositionKeys[i].mValue;
|
||||||
aiMatrix4x4 TranslationM; // identity
|
aiMatrix4x4 TranslationM; // identity
|
||||||
TranslationM[0][3] = Translation.x; TranslationM[1][3] = Translation.y; TranslationM[2][3] = Translation.z;
|
TranslationM[0][3] = Translation.x;
|
||||||
|
TranslationM[1][3] = Translation.y;
|
||||||
|
TranslationM[2][3] = Translation.z;
|
||||||
|
|
||||||
// Combine the above transformations
|
// Combine the above transformations
|
||||||
aiMatrix4x4 mat = TranslationM * RotationM * ScalingM;
|
aiMatrix4x4 mat = TranslationM * RotationM * ScalingM;
|
||||||
|
@ -1393,10 +1352,7 @@ void ColladaExporter::WriteAnimationLibrary(size_t pIndex)
|
||||||
{
|
{
|
||||||
std::vector<std::string> names;
|
std::vector<std::string> names;
|
||||||
for (size_t i = 0; i < nodeAnim->mNumPositionKeys; ++i) {
|
for (size_t i = 0; i < nodeAnim->mNumPositionKeys; ++i) {
|
||||||
if ( nodeAnim->mPreState == aiAnimBehaviour_DEFAULT
|
if (nodeAnim->mPreState == aiAnimBehaviour_DEFAULT || nodeAnim->mPreState == aiAnimBehaviour_LINEAR || nodeAnim->mPreState == aiAnimBehaviour_REPEAT) {
|
||||||
|| nodeAnim->mPreState == aiAnimBehaviour_LINEAR
|
|
||||||
|| nodeAnim->mPreState == aiAnimBehaviour_REPEAT
|
|
||||||
) {
|
|
||||||
names.push_back("LINEAR");
|
names.push_back("LINEAR");
|
||||||
} else if (nodeAnim->mPostState == aiAnimBehaviour_CONSTANT) {
|
} else if (nodeAnim->mPostState == aiAnimBehaviour_CONSTANT) {
|
||||||
names.push_back("STEP");
|
names.push_back("STEP");
|
||||||
|
@ -1464,11 +1420,9 @@ void ColladaExporter::WriteAnimationLibrary(size_t pIndex)
|
||||||
|
|
||||||
PopTag();
|
PopTag();
|
||||||
mOutput << startstr << "</animation>" << endstr;
|
mOutput << startstr << "</animation>" << endstr;
|
||||||
|
|
||||||
}
|
}
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
void ColladaExporter::WriteAnimationsLibrary()
|
void ColladaExporter::WriteAnimationsLibrary() {
|
||||||
{
|
|
||||||
if (mScene->mNumAnimations > 0) {
|
if (mScene->mNumAnimations > 0) {
|
||||||
mOutput << startstr << "<library_animations>" << endstr;
|
mOutput << startstr << "<library_animations>" << endstr;
|
||||||
PushTag();
|
PushTag();
|
||||||
|
@ -1497,8 +1451,7 @@ aiBone* findBone( const aiScene* scene, const char * name) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
const aiNode * findBoneNode( const aiNode* aNode, const aiBone* bone)
|
const aiNode *findBoneNode(const aiNode *aNode, const aiBone *bone) {
|
||||||
{
|
|
||||||
if (aNode && bone && aNode->mName == bone->mName) {
|
if (aNode && bone && aNode->mName == bone->mName) {
|
||||||
return aNode;
|
return aNode;
|
||||||
}
|
}
|
||||||
|
@ -1517,8 +1470,7 @@ const aiNode * findBoneNode( const aiNode* aNode, const aiBone* bone)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
const aiNode * findSkeletonRootNode( const aiScene* scene, const aiMesh * mesh)
|
const aiNode *findSkeletonRootNode(const aiScene *scene, const aiMesh *mesh) {
|
||||||
{
|
|
||||||
std::set<const aiNode *> topParentBoneNodes;
|
std::set<const aiNode *> topParentBoneNodes;
|
||||||
if (mesh && mesh->mNumBones > 0) {
|
if (mesh && mesh->mNumBones > 0) {
|
||||||
for (unsigned int i = 0; i < mesh->mNumBones; ++i) {
|
for (unsigned int i = 0; i < mesh->mNumBones; ++i) {
|
||||||
|
@ -1551,11 +1503,9 @@ const aiNode * findSkeletonRootNode( const aiScene* scene, const aiMesh * mesh)
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
// Recursively writes the given node
|
// Recursively writes the given node
|
||||||
void ColladaExporter::WriteNode( const aiScene* pScene, aiNode* pNode)
|
void ColladaExporter::WriteNode(const aiScene *pScene, aiNode *pNode) {
|
||||||
{
|
|
||||||
// the node must have a name
|
// the node must have a name
|
||||||
if (pNode->mName.length == 0)
|
if (pNode->mName.length == 0) {
|
||||||
{
|
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
ss << "Node_" << pNode;
|
ss << "Node_" << pNode;
|
||||||
pNode->mName.Set(ss.str());
|
pNode->mName.Set(ss.str());
|
||||||
|
@ -1639,8 +1589,7 @@ void ColladaExporter::WriteNode( const aiScene* pScene, aiNode* pNode)
|
||||||
|
|
||||||
} else
|
} else
|
||||||
// instance every geometry
|
// instance every geometry
|
||||||
for( size_t a = 0; a < pNode->mNumMeshes; ++a )
|
for (size_t a = 0; a < pNode->mNumMeshes; ++a) {
|
||||||
{
|
|
||||||
const aiMesh *mesh = mScene->mMeshes[pNode->mMeshes[a]];
|
const aiMesh *mesh = mScene->mMeshes[pNode->mMeshes[a]];
|
||||||
// do not instantiate mesh if empty. I wonder how this could happen
|
// do not instantiate mesh if empty. I wonder how this could happen
|
||||||
if (mesh->mNumFaces == 0 || mesh->mNumVertices == 0)
|
if (mesh->mNumFaces == 0 || mesh->mNumVertices == 0)
|
||||||
|
@ -1648,13 +1597,10 @@ void ColladaExporter::WriteNode( const aiScene* pScene, aiNode* pNode)
|
||||||
|
|
||||||
const std::string meshName = mesh->mName.length == 0 ? GetMeshId(pNode->mMeshes[a]) : mesh->mName.C_Str();
|
const std::string meshName = mesh->mName.length == 0 ? GetMeshId(pNode->mMeshes[a]) : mesh->mName.C_Str();
|
||||||
|
|
||||||
if( mesh->mNumBones == 0 )
|
if (mesh->mNumBones == 0) {
|
||||||
{
|
|
||||||
mOutput << startstr << "<instance_geometry url=\"#" << XMLIDEncode(meshName) << "\">" << endstr;
|
mOutput << startstr << "<instance_geometry url=\"#" << XMLIDEncode(meshName) << "\">" << endstr;
|
||||||
PushTag();
|
PushTag();
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
mOutput << startstr
|
mOutput << startstr
|
||||||
<< "<instance_controller url=\"#" << XMLIDEncode(meshName) << "-skin\">"
|
<< "<instance_controller url=\"#" << XMLIDEncode(meshName) << "-skin\">"
|
||||||
<< endstr;
|
<< endstr;
|
||||||
|
@ -1674,8 +1620,7 @@ void ColladaExporter::WriteNode( const aiScene* pScene, aiNode* pNode)
|
||||||
PushTag();
|
PushTag();
|
||||||
mOutput << startstr << "<instance_material symbol=\"defaultMaterial\" target=\"#" << XMLIDEncode(materials[mesh->mMaterialIndex].name) << "\">" << endstr;
|
mOutput << startstr << "<instance_material symbol=\"defaultMaterial\" target=\"#" << XMLIDEncode(materials[mesh->mMaterialIndex].name) << "\">" << endstr;
|
||||||
PushTag();
|
PushTag();
|
||||||
for( size_t aa = 0; aa < AI_MAX_NUMBER_OF_TEXTURECOORDS; ++aa )
|
for (size_t aa = 0; aa < AI_MAX_NUMBER_OF_TEXTURECOORDS; ++aa) {
|
||||||
{
|
|
||||||
if (mesh->HasTextureCoords(static_cast<unsigned int>(aa)))
|
if (mesh->HasTextureCoords(static_cast<unsigned int>(aa)))
|
||||||
// semantic as in <texture texcoord=...>
|
// semantic as in <texture texcoord=...>
|
||||||
// input_semantic as in <input semantic=...>
|
// input_semantic as in <input semantic=...>
|
||||||
|
|
|
@ -47,26 +47,24 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
#define AI_COLLADAEXPORTER_H_INC
|
#define AI_COLLADAEXPORTER_H_INC
|
||||||
|
|
||||||
#include <assimp/ai_assert.h>
|
#include <assimp/ai_assert.h>
|
||||||
|
#include <assimp/light.h>
|
||||||
#include <assimp/material.h>
|
#include <assimp/material.h>
|
||||||
#include <assimp/mesh.h>
|
#include <assimp/mesh.h>
|
||||||
#include <assimp/light.h>
|
|
||||||
#include <assimp/Exporter.hpp>
|
#include <assimp/Exporter.hpp>
|
||||||
|
#include <map>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <map>
|
|
||||||
|
|
||||||
#include <assimp/StringUtils.h>
|
#include <assimp/StringUtils.h>
|
||||||
|
|
||||||
struct aiScene;
|
struct aiScene;
|
||||||
struct aiNode;
|
struct aiNode;
|
||||||
|
|
||||||
namespace Assimp
|
namespace Assimp {
|
||||||
{
|
|
||||||
|
|
||||||
/// Helper class to export a given scene to a Collada file. Just for my personal
|
/// Helper class to export a given scene to a Collada file. Just for my personal
|
||||||
/// comfort when implementing it.
|
/// comfort when implementing it.
|
||||||
class ColladaExporter
|
class ColladaExporter {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
/// Constructor for a specific scene to export
|
/// Constructor for a specific scene to export
|
||||||
ColladaExporter(const aiScene *pScene, IOSystem *pIOSystem, const std::string &path, const std::string &file);
|
ColladaExporter(const aiScene *pScene, IOSystem *pIOSystem, const std::string &path, const std::string &file);
|
||||||
|
@ -117,7 +115,13 @@ protected:
|
||||||
|
|
||||||
//enum FloatDataType { FloatType_Vector, FloatType_TexCoord2, FloatType_TexCoord3, FloatType_Color, FloatType_Mat4x4, FloatType_Weight };
|
//enum FloatDataType { FloatType_Vector, FloatType_TexCoord2, FloatType_TexCoord3, FloatType_Color, FloatType_Mat4x4, FloatType_Weight };
|
||||||
// customized to add animation related type
|
// customized to add animation related type
|
||||||
enum FloatDataType { FloatType_Vector, FloatType_TexCoord2, FloatType_TexCoord3, FloatType_Color, FloatType_Mat4x4, FloatType_Weight, FloatType_Time };
|
enum FloatDataType { FloatType_Vector,
|
||||||
|
FloatType_TexCoord2,
|
||||||
|
FloatType_TexCoord3,
|
||||||
|
FloatType_Color,
|
||||||
|
FloatType_Mat4x4,
|
||||||
|
FloatType_Weight,
|
||||||
|
FloatType_Time };
|
||||||
|
|
||||||
/// Writes a float array of the given type
|
/// Writes a float array of the given type
|
||||||
void WriteFloatArray(const std::string &pIdString, FloatDataType pType, const ai_real *pData, size_t pElementCount);
|
void WriteFloatArray(const std::string &pIdString, FloatDataType pType, const ai_real *pData, size_t pElementCount);
|
||||||
|
@ -169,28 +173,27 @@ public:
|
||||||
std::string endstr;
|
std::string endstr;
|
||||||
|
|
||||||
// pair of color and texture - texture precedences color
|
// pair of color and texture - texture precedences color
|
||||||
struct Surface
|
struct Surface {
|
||||||
{
|
|
||||||
bool exist;
|
bool exist;
|
||||||
aiColor4D color;
|
aiColor4D color;
|
||||||
std::string texture;
|
std::string texture;
|
||||||
size_t channel;
|
size_t channel;
|
||||||
Surface() { exist = false; channel = 0; }
|
Surface() {
|
||||||
|
exist = false;
|
||||||
|
channel = 0;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Property
|
struct Property {
|
||||||
{
|
|
||||||
bool exist;
|
bool exist;
|
||||||
ai_real value;
|
ai_real value;
|
||||||
Property()
|
Property() :
|
||||||
: exist(false)
|
exist(false),
|
||||||
, value(0.0)
|
value(0.0) {}
|
||||||
{}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// summarize a material in an convenient way.
|
// summarize a material in an convenient way.
|
||||||
struct Material
|
struct Material {
|
||||||
{
|
|
||||||
std::string name;
|
std::string name;
|
||||||
std::string shading_model;
|
std::string shading_model;
|
||||||
Surface ambient, diffuse, specular, emissive, reflective, transparent, normal;
|
Surface ambient, diffuse, specular, emissive, reflective, transparent, normal;
|
||||||
|
@ -217,6 +220,6 @@ public:
|
||||||
void WriteFloatEntry(const Property &pProperty, const std::string &pTypeName);
|
void WriteFloatEntry(const Property &pProperty, const std::string &pTypeName);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
} // namespace Assimp
|
||||||
|
|
||||||
#endif // !! AI_COLLADAEXPORTER_H_INC
|
#endif // !! AI_COLLADAEXPORTER_H_INC
|
||||||
|
|
|
@ -43,8 +43,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
#include "ColladaHelper.h"
|
#include "ColladaHelper.h"
|
||||||
|
|
||||||
#include <assimp/commonMetaData.h>
|
|
||||||
#include <assimp/ParsingUtils.h>
|
#include <assimp/ParsingUtils.h>
|
||||||
|
#include <assimp/commonMetaData.h>
|
||||||
|
|
||||||
namespace Assimp {
|
namespace Assimp {
|
||||||
namespace Collada {
|
namespace Collada {
|
||||||
|
@ -63,39 +63,32 @@ const MetaKeyPairVector &GetColladaAssimpMetaKeys() {
|
||||||
|
|
||||||
const MetaKeyPairVector MakeColladaAssimpMetaKeysCamelCase() {
|
const MetaKeyPairVector MakeColladaAssimpMetaKeysCamelCase() {
|
||||||
MetaKeyPairVector result = MakeColladaAssimpMetaKeys();
|
MetaKeyPairVector result = MakeColladaAssimpMetaKeys();
|
||||||
for (auto &val : result)
|
for (auto &val : result) {
|
||||||
{
|
|
||||||
ToCamelCase(val.first);
|
ToCamelCase(val.first);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
const MetaKeyPairVector &GetColladaAssimpMetaKeysCamelCase()
|
const MetaKeyPairVector &GetColladaAssimpMetaKeysCamelCase() {
|
||||||
{
|
|
||||||
static const MetaKeyPairVector result = MakeColladaAssimpMetaKeysCamelCase();
|
static const MetaKeyPairVector result = MakeColladaAssimpMetaKeysCamelCase();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
// Convert underscore_separated to CamelCase: "authoring_tool" becomes "AuthoringTool"
|
// Convert underscore_separated to CamelCase: "authoring_tool" becomes "AuthoringTool"
|
||||||
void ToCamelCase(std::string &text)
|
void ToCamelCase(std::string &text) {
|
||||||
{
|
|
||||||
if (text.empty())
|
if (text.empty())
|
||||||
return;
|
return;
|
||||||
// Capitalise first character
|
// Capitalise first character
|
||||||
auto it = text.begin();
|
auto it = text.begin();
|
||||||
(*it) = ToUpper(*it);
|
(*it) = ToUpper(*it);
|
||||||
++it;
|
++it;
|
||||||
for (/*started above*/ ; it != text.end(); /*iterated below*/)
|
for (/*started above*/; it != text.end(); /*iterated below*/) {
|
||||||
{
|
if ((*it) == '_') {
|
||||||
if ((*it) == '_')
|
|
||||||
{
|
|
||||||
it = text.erase(it);
|
it = text.erase(it);
|
||||||
if (it != text.end())
|
if (it != text.end())
|
||||||
(*it) = ToUpper(*it);
|
(*it) = ToUpper(*it);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
// Make lower case
|
// Make lower case
|
||||||
(*it) = ToLower(*it);
|
(*it) = ToLower(*it);
|
||||||
++it;
|
++it;
|
||||||
|
|
|
@ -45,13 +45,13 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
#ifndef AI_COLLADAHELPER_H_INC
|
#ifndef AI_COLLADAHELPER_H_INC
|
||||||
#define AI_COLLADAHELPER_H_INC
|
#define AI_COLLADAHELPER_H_INC
|
||||||
|
|
||||||
#include <map>
|
|
||||||
#include <vector>
|
|
||||||
#include <set>
|
|
||||||
#include <stdint.h>
|
|
||||||
#include <assimp/light.h>
|
#include <assimp/light.h>
|
||||||
#include <assimp/mesh.h>
|
|
||||||
#include <assimp/material.h>
|
#include <assimp/material.h>
|
||||||
|
#include <assimp/mesh.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <map>
|
||||||
|
#include <set>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
struct aiMaterial;
|
struct aiMaterial;
|
||||||
|
|
||||||
|
@ -59,17 +59,14 @@ namespace Assimp {
|
||||||
namespace Collada {
|
namespace Collada {
|
||||||
|
|
||||||
/** Collada file versions which evolved during the years ... */
|
/** Collada file versions which evolved during the years ... */
|
||||||
enum FormatVersion
|
enum FormatVersion {
|
||||||
{
|
|
||||||
FV_1_5_n,
|
FV_1_5_n,
|
||||||
FV_1_4_n,
|
FV_1_4_n,
|
||||||
FV_1_3_n
|
FV_1_3_n
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/** Transformation types that can be applied to a node */
|
/** Transformation types that can be applied to a node */
|
||||||
enum TransformType
|
enum TransformType {
|
||||||
{
|
|
||||||
TF_LOOKAT,
|
TF_LOOKAT,
|
||||||
TF_ROTATE,
|
TF_ROTATE,
|
||||||
TF_TRANSLATE,
|
TF_TRANSLATE,
|
||||||
|
@ -79,8 +76,7 @@ enum TransformType
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Different types of input data to a vertex or face */
|
/** Different types of input data to a vertex or face */
|
||||||
enum InputType
|
enum InputType {
|
||||||
{
|
|
||||||
IT_Invalid,
|
IT_Invalid,
|
||||||
IT_Vertex, // special type for per-index data referring to the <vertices> element carrying the per-vertex data.
|
IT_Vertex, // special type for per-index data referring to the <vertices> element carrying the per-vertex data.
|
||||||
IT_Position,
|
IT_Position,
|
||||||
|
@ -92,15 +88,13 @@ enum InputType
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Supported controller types */
|
/** Supported controller types */
|
||||||
enum ControllerType
|
enum ControllerType {
|
||||||
{
|
|
||||||
Skin,
|
Skin,
|
||||||
Morph
|
Morph
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Supported morph methods */
|
/** Supported morph methods */
|
||||||
enum MorphMethod
|
enum MorphMethod {
|
||||||
{
|
|
||||||
Normalized,
|
Normalized,
|
||||||
Relative
|
Relative
|
||||||
};
|
};
|
||||||
|
@ -118,24 +112,21 @@ const MetaKeyPairVector &GetColladaAssimpMetaKeysCamelCase();
|
||||||
void ToCamelCase(std::string &text);
|
void ToCamelCase(std::string &text);
|
||||||
|
|
||||||
/** Contains all data for one of the different transformation types */
|
/** Contains all data for one of the different transformation types */
|
||||||
struct Transform
|
struct Transform {
|
||||||
{
|
|
||||||
std::string mID; ///< SID of the transform step, by which anim channels address their target node
|
std::string mID; ///< SID of the transform step, by which anim channels address their target node
|
||||||
TransformType mType;
|
TransformType mType;
|
||||||
ai_real f[16]; ///< Interpretation of data depends on the type of the transformation
|
ai_real f[16]; ///< Interpretation of data depends on the type of the transformation
|
||||||
};
|
};
|
||||||
|
|
||||||
/** A collada camera. */
|
/** A collada camera. */
|
||||||
struct Camera
|
struct Camera {
|
||||||
{
|
Camera() :
|
||||||
Camera()
|
mOrtho(false),
|
||||||
: mOrtho (false)
|
mHorFov(10e10f),
|
||||||
, mHorFov (10e10f)
|
mVerFov(10e10f),
|
||||||
, mVerFov (10e10f)
|
mAspect(10e10f),
|
||||||
, mAspect (10e10f)
|
mZNear(0.1f),
|
||||||
, mZNear (0.1f)
|
mZFar(1000.f) {}
|
||||||
, mZFar (1000.f)
|
|
||||||
{}
|
|
||||||
|
|
||||||
// Name of camera
|
// Name of camera
|
||||||
std::string mName;
|
std::string mName;
|
||||||
|
@ -159,19 +150,17 @@ struct Camera
|
||||||
#define ASSIMP_COLLADA_LIGHT_ANGLE_NOT_SET 1e9f
|
#define ASSIMP_COLLADA_LIGHT_ANGLE_NOT_SET 1e9f
|
||||||
|
|
||||||
/** A collada light source. */
|
/** A collada light source. */
|
||||||
struct Light
|
struct Light {
|
||||||
{
|
Light() :
|
||||||
Light()
|
mType(aiLightSource_UNDEFINED),
|
||||||
: mType (aiLightSource_UNDEFINED)
|
mAttConstant(1.f),
|
||||||
, mAttConstant (1.f)
|
mAttLinear(0.f),
|
||||||
, mAttLinear (0.f)
|
mAttQuadratic(0.f),
|
||||||
, mAttQuadratic (0.f)
|
mFalloffAngle(180.f),
|
||||||
, mFalloffAngle (180.f)
|
mFalloffExponent(0.f),
|
||||||
, mFalloffExponent (0.f)
|
mPenumbraAngle(ASSIMP_COLLADA_LIGHT_ANGLE_NOT_SET),
|
||||||
, mPenumbraAngle (ASSIMP_COLLADA_LIGHT_ANGLE_NOT_SET)
|
mOuterAngle(ASSIMP_COLLADA_LIGHT_ANGLE_NOT_SET),
|
||||||
, mOuterAngle (ASSIMP_COLLADA_LIGHT_ANGLE_NOT_SET)
|
mIntensity(1.f) {}
|
||||||
, mIntensity (1.f)
|
|
||||||
{}
|
|
||||||
|
|
||||||
//! Type of the light source aiLightSourceType + ambient
|
//! Type of the light source aiLightSourceType + ambient
|
||||||
unsigned int mType;
|
unsigned int mType;
|
||||||
|
@ -198,12 +187,10 @@ struct Light
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Short vertex index description */
|
/** Short vertex index description */
|
||||||
struct InputSemanticMapEntry
|
struct InputSemanticMapEntry {
|
||||||
{
|
InputSemanticMapEntry() :
|
||||||
InputSemanticMapEntry()
|
mSet(0),
|
||||||
: mSet(0)
|
mType(IT_Invalid) {}
|
||||||
, mType(IT_Invalid)
|
|
||||||
{}
|
|
||||||
|
|
||||||
//! Index of set, optional
|
//! Index of set, optional
|
||||||
unsigned int mSet;
|
unsigned int mSet;
|
||||||
|
@ -213,8 +200,7 @@ struct InputSemanticMapEntry
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Table to map from effect to vertex input semantics */
|
/** Table to map from effect to vertex input semantics */
|
||||||
struct SemanticMappingTable
|
struct SemanticMappingTable {
|
||||||
{
|
|
||||||
//! Name of material
|
//! Name of material
|
||||||
std::string mMatName;
|
std::string mMatName;
|
||||||
|
|
||||||
|
@ -230,8 +216,7 @@ struct SemanticMappingTable
|
||||||
/** A reference to a mesh inside a node, including materials assigned to the various subgroups.
|
/** A reference to a mesh inside a node, including materials assigned to the various subgroups.
|
||||||
* The ID refers to either a mesh or a controller which specifies the mesh
|
* The ID refers to either a mesh or a controller which specifies the mesh
|
||||||
*/
|
*/
|
||||||
struct MeshInstance
|
struct MeshInstance {
|
||||||
{
|
|
||||||
///< ID of the mesh or controller to be instanced
|
///< ID of the mesh or controller to be instanced
|
||||||
std::string mMeshOrController;
|
std::string mMeshOrController;
|
||||||
|
|
||||||
|
@ -240,29 +225,25 @@ struct MeshInstance
|
||||||
};
|
};
|
||||||
|
|
||||||
/** A reference to a camera inside a node*/
|
/** A reference to a camera inside a node*/
|
||||||
struct CameraInstance
|
struct CameraInstance {
|
||||||
{
|
|
||||||
///< ID of the camera
|
///< ID of the camera
|
||||||
std::string mCamera;
|
std::string mCamera;
|
||||||
};
|
};
|
||||||
|
|
||||||
/** A reference to a light inside a node*/
|
/** A reference to a light inside a node*/
|
||||||
struct LightInstance
|
struct LightInstance {
|
||||||
{
|
|
||||||
///< ID of the camera
|
///< ID of the camera
|
||||||
std::string mLight;
|
std::string mLight;
|
||||||
};
|
};
|
||||||
|
|
||||||
/** A reference to a node inside a node*/
|
/** A reference to a node inside a node*/
|
||||||
struct NodeInstance
|
struct NodeInstance {
|
||||||
{
|
|
||||||
///< ID of the node
|
///< ID of the node
|
||||||
std::string mNode;
|
std::string mNode;
|
||||||
};
|
};
|
||||||
|
|
||||||
/** A node in a scene hierarchy */
|
/** A node in a scene hierarchy */
|
||||||
struct Node
|
struct Node {
|
||||||
{
|
|
||||||
std::string mName;
|
std::string mName;
|
||||||
std::string mID;
|
std::string mID;
|
||||||
std::string mSID;
|
std::string mSID;
|
||||||
|
@ -288,8 +269,8 @@ struct Node
|
||||||
std::string mPrimaryCamera;
|
std::string mPrimaryCamera;
|
||||||
|
|
||||||
//! Constructor. Begin with a zero parent
|
//! Constructor. Begin with a zero parent
|
||||||
Node()
|
Node() :
|
||||||
: mParent( nullptr ){
|
mParent(nullptr) {
|
||||||
// empty
|
// empty
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -301,16 +282,14 @@ struct Node
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Data source array: either floats or strings */
|
/** Data source array: either floats or strings */
|
||||||
struct Data
|
struct Data {
|
||||||
{
|
|
||||||
bool mIsStringArray;
|
bool mIsStringArray;
|
||||||
std::vector<ai_real> mValues;
|
std::vector<ai_real> mValues;
|
||||||
std::vector<std::string> mStrings;
|
std::vector<std::string> mStrings;
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Accessor to a data array */
|
/** Accessor to a data array */
|
||||||
struct Accessor
|
struct Accessor {
|
||||||
{
|
|
||||||
size_t mCount; // in number of objects
|
size_t mCount; // in number of objects
|
||||||
size_t mSize; // size of an object, in elements (floats or strings, mostly 1)
|
size_t mSize; // size of an object, in elements (floats or strings, mostly 1)
|
||||||
size_t mOffset; // in number of values
|
size_t mOffset; // in number of values
|
||||||
|
@ -321,43 +300,46 @@ struct Accessor
|
||||||
std::string mSource; // URL of the source array
|
std::string mSource; // URL of the source array
|
||||||
mutable const Data *mData; // Pointer to the source array, if resolved. NULL else
|
mutable const Data *mData; // Pointer to the source array, if resolved. NULL else
|
||||||
|
|
||||||
Accessor()
|
Accessor() {
|
||||||
{
|
mCount = 0;
|
||||||
mCount = 0; mSize = 0; mOffset = 0; mStride = 0; mData = NULL;
|
mSize = 0;
|
||||||
|
mOffset = 0;
|
||||||
|
mStride = 0;
|
||||||
|
mData = NULL;
|
||||||
mSubOffset[0] = mSubOffset[1] = mSubOffset[2] = mSubOffset[3] = 0;
|
mSubOffset[0] = mSubOffset[1] = mSubOffset[2] = mSubOffset[3] = 0;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/** A single face in a mesh */
|
/** A single face in a mesh */
|
||||||
struct Face
|
struct Face {
|
||||||
{
|
|
||||||
std::vector<size_t> mIndices;
|
std::vector<size_t> mIndices;
|
||||||
};
|
};
|
||||||
|
|
||||||
/** An input channel for mesh data, referring to a single accessor */
|
/** An input channel for mesh data, referring to a single accessor */
|
||||||
struct InputChannel
|
struct InputChannel {
|
||||||
{
|
|
||||||
InputType mType; // Type of the data
|
InputType mType; // Type of the data
|
||||||
size_t mIndex; // Optional index, if multiple sets of the same data type are given
|
size_t mIndex; // Optional index, if multiple sets of the same data type are given
|
||||||
size_t mOffset; // Index offset in the indices array of per-face indices. Don't ask, can't explain that any better.
|
size_t mOffset; // Index offset in the indices array of per-face indices. Don't ask, can't explain that any better.
|
||||||
std::string mAccessor; // ID of the accessor where to read the actual values from.
|
std::string mAccessor; // ID of the accessor where to read the actual values from.
|
||||||
mutable const Accessor *mResolved; // Pointer to the accessor, if resolved. NULL else
|
mutable const Accessor *mResolved; // Pointer to the accessor, if resolved. NULL else
|
||||||
|
|
||||||
InputChannel() { mType = IT_Invalid; mIndex = 0; mOffset = 0; mResolved = NULL; }
|
InputChannel() {
|
||||||
|
mType = IT_Invalid;
|
||||||
|
mIndex = 0;
|
||||||
|
mOffset = 0;
|
||||||
|
mResolved = NULL;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Subset of a mesh with a certain material */
|
/** Subset of a mesh with a certain material */
|
||||||
struct SubMesh
|
struct SubMesh {
|
||||||
{
|
|
||||||
std::string mMaterial; ///< subgroup identifier
|
std::string mMaterial; ///< subgroup identifier
|
||||||
size_t mNumFaces; ///< number of faces in this submesh
|
size_t mNumFaces; ///< number of faces in this submesh
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Contains data for a single mesh */
|
/** Contains data for a single mesh */
|
||||||
struct Mesh
|
struct Mesh {
|
||||||
{
|
Mesh() {
|
||||||
Mesh()
|
|
||||||
{
|
|
||||||
for (unsigned int i = 0; i < AI_MAX_NUMBER_OF_TEXTURECOORDS; ++i)
|
for (unsigned int i = 0; i < AI_MAX_NUMBER_OF_TEXTURECOORDS; ++i)
|
||||||
mNumUVComponents[i] = 2;
|
mNumUVComponents[i] = 2;
|
||||||
}
|
}
|
||||||
|
@ -394,8 +376,7 @@ struct Mesh
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Which type of primitives the ReadPrimitives() function is going to read */
|
/** Which type of primitives the ReadPrimitives() function is going to read */
|
||||||
enum PrimitiveType
|
enum PrimitiveType {
|
||||||
{
|
|
||||||
Prim_Invalid,
|
Prim_Invalid,
|
||||||
Prim_Lines,
|
Prim_Lines,
|
||||||
Prim_LineStrip,
|
Prim_LineStrip,
|
||||||
|
@ -407,8 +388,7 @@ enum PrimitiveType
|
||||||
};
|
};
|
||||||
|
|
||||||
/** A skeleton controller to deform a mesh with the use of joints */
|
/** A skeleton controller to deform a mesh with the use of joints */
|
||||||
struct Controller
|
struct Controller {
|
||||||
{
|
|
||||||
// controller type
|
// controller type
|
||||||
ControllerType mType;
|
ControllerType mType;
|
||||||
|
|
||||||
|
@ -443,29 +423,25 @@ struct Controller
|
||||||
};
|
};
|
||||||
|
|
||||||
/** A collada material. Pretty much the only member is a reference to an effect. */
|
/** A collada material. Pretty much the only member is a reference to an effect. */
|
||||||
struct Material
|
struct Material {
|
||||||
{
|
|
||||||
std::string mName;
|
std::string mName;
|
||||||
std::string mEffect;
|
std::string mEffect;
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Type of the effect param */
|
/** Type of the effect param */
|
||||||
enum ParamType
|
enum ParamType {
|
||||||
{
|
|
||||||
Param_Sampler,
|
Param_Sampler,
|
||||||
Param_Surface
|
Param_Surface
|
||||||
};
|
};
|
||||||
|
|
||||||
/** A param for an effect. Might be of several types, but they all just refer to each other, so I summarize them */
|
/** A param for an effect. Might be of several types, but they all just refer to each other, so I summarize them */
|
||||||
struct EffectParam
|
struct EffectParam {
|
||||||
{
|
|
||||||
ParamType mType;
|
ParamType mType;
|
||||||
std::string mReference; // to which other thing the param is referring to.
|
std::string mReference; // to which other thing the param is referring to.
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Shading type supported by the standard effect spec of Collada */
|
/** Shading type supported by the standard effect spec of Collada */
|
||||||
enum ShadeType
|
enum ShadeType {
|
||||||
{
|
|
||||||
Shade_Invalid,
|
Shade_Invalid,
|
||||||
Shade_Constant,
|
Shade_Constant,
|
||||||
Shade_Lambert,
|
Shade_Lambert,
|
||||||
|
@ -474,18 +450,16 @@ enum ShadeType
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Represents a texture sampler in collada */
|
/** Represents a texture sampler in collada */
|
||||||
struct Sampler
|
struct Sampler {
|
||||||
{
|
Sampler() :
|
||||||
Sampler()
|
mWrapU(true),
|
||||||
: mWrapU (true)
|
mWrapV(true),
|
||||||
, mWrapV (true)
|
mMirrorU(),
|
||||||
, mMirrorU ()
|
mMirrorV(),
|
||||||
, mMirrorV ()
|
mOp(aiTextureOp_Multiply),
|
||||||
, mOp (aiTextureOp_Multiply)
|
mUVId(UINT_MAX),
|
||||||
, mUVId (UINT_MAX)
|
mWeighting(1.f),
|
||||||
, mWeighting (1.f)
|
mMixWithPrevious(1.f) {}
|
||||||
, mMixWithPrevious (1.f)
|
|
||||||
{}
|
|
||||||
|
|
||||||
/** Name of image reference
|
/** Name of image reference
|
||||||
*/
|
*/
|
||||||
|
@ -537,8 +511,7 @@ struct Sampler
|
||||||
|
|
||||||
/** A collada effect. Can contain about anything according to the Collada spec,
|
/** A collada effect. Can contain about anything according to the Collada spec,
|
||||||
but we limit our version to a reasonable subset. */
|
but we limit our version to a reasonable subset. */
|
||||||
struct Effect
|
struct Effect {
|
||||||
{
|
|
||||||
// Shading mode
|
// Shading mode
|
||||||
ShadeType mShadeType;
|
ShadeType mShadeType;
|
||||||
|
|
||||||
|
@ -566,30 +539,28 @@ struct Effect
|
||||||
// Double-sided?
|
// Double-sided?
|
||||||
bool mDoubleSided, mWireframe, mFaceted;
|
bool mDoubleSided, mWireframe, mFaceted;
|
||||||
|
|
||||||
Effect()
|
Effect() :
|
||||||
: mShadeType (Shade_Phong)
|
mShadeType(Shade_Phong),
|
||||||
, mEmissive ( 0, 0, 0, 1)
|
mEmissive(0, 0, 0, 1),
|
||||||
, mAmbient ( 0.1f, 0.1f, 0.1f, 1)
|
mAmbient(0.1f, 0.1f, 0.1f, 1),
|
||||||
, mDiffuse ( 0.6f, 0.6f, 0.6f, 1)
|
mDiffuse(0.6f, 0.6f, 0.6f, 1),
|
||||||
, mSpecular ( 0.4f, 0.4f, 0.4f, 1)
|
mSpecular(0.4f, 0.4f, 0.4f, 1),
|
||||||
, mTransparent ( 0, 0, 0, 1)
|
mTransparent(0, 0, 0, 1),
|
||||||
, mShininess (10.0f)
|
mShininess(10.0f),
|
||||||
, mRefractIndex (1.f)
|
mRefractIndex(1.f),
|
||||||
, mReflectivity (0.f)
|
mReflectivity(0.f),
|
||||||
, mTransparency (1.f)
|
mTransparency(1.f),
|
||||||
, mHasTransparency (false)
|
mHasTransparency(false),
|
||||||
, mRGBTransparency(false)
|
mRGBTransparency(false),
|
||||||
, mInvertTransparency(false)
|
mInvertTransparency(false),
|
||||||
, mDoubleSided (false)
|
mDoubleSided(false),
|
||||||
, mWireframe (false)
|
mWireframe(false),
|
||||||
, mFaceted (false)
|
mFaceted(false) {
|
||||||
{
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/** An image, meaning texture */
|
/** An image, meaning texture */
|
||||||
struct Image
|
struct Image {
|
||||||
{
|
|
||||||
std::string mFileName;
|
std::string mFileName;
|
||||||
|
|
||||||
/** Embedded image data */
|
/** Embedded image data */
|
||||||
|
@ -600,8 +571,7 @@ struct Image
|
||||||
};
|
};
|
||||||
|
|
||||||
/** An animation channel. */
|
/** An animation channel. */
|
||||||
struct AnimationChannel
|
struct AnimationChannel {
|
||||||
{
|
|
||||||
/** URL of the data to animate. Could be about anything, but we support only the
|
/** URL of the data to animate. Could be about anything, but we support only the
|
||||||
* "NodeID/TransformID.SubElement" notation
|
* "NodeID/TransformID.SubElement" notation
|
||||||
*/
|
*/
|
||||||
|
@ -620,8 +590,7 @@ struct AnimationChannel
|
||||||
};
|
};
|
||||||
|
|
||||||
/** An animation. Container for 0-x animation channels or 0-x animations */
|
/** An animation. Container for 0-x animation channels or 0-x animations */
|
||||||
struct Animation
|
struct Animation {
|
||||||
{
|
|
||||||
/** Anim name */
|
/** Anim name */
|
||||||
std::string mName;
|
std::string mName;
|
||||||
|
|
||||||
|
@ -632,19 +601,16 @@ struct Animation
|
||||||
std::vector<Animation *> mSubAnims;
|
std::vector<Animation *> mSubAnims;
|
||||||
|
|
||||||
/** Destructor */
|
/** Destructor */
|
||||||
~Animation()
|
~Animation() {
|
||||||
{
|
|
||||||
for (std::vector<Animation *>::iterator it = mSubAnims.begin(); it != mSubAnims.end(); ++it)
|
for (std::vector<Animation *>::iterator it = mSubAnims.begin(); it != mSubAnims.end(); ++it)
|
||||||
delete *it;
|
delete *it;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Collect all channels in the animation hierarchy into a single channel list. */
|
/** Collect all channels in the animation hierarchy into a single channel list. */
|
||||||
void CollectChannelsRecursively(std::vector<AnimationChannel> &channels)
|
void CollectChannelsRecursively(std::vector<AnimationChannel> &channels) {
|
||||||
{
|
|
||||||
channels.insert(channels.end(), mChannels.begin(), mChannels.end());
|
channels.insert(channels.end(), mChannels.begin(), mChannels.end());
|
||||||
|
|
||||||
for (std::vector<Animation*>::iterator it = mSubAnims.begin(); it != mSubAnims.end(); ++it)
|
for (std::vector<Animation *>::iterator it = mSubAnims.begin(); it != mSubAnims.end(); ++it) {
|
||||||
{
|
|
||||||
Animation *pAnim = (*it);
|
Animation *pAnim = (*it);
|
||||||
|
|
||||||
pAnim->CollectChannelsRecursively(channels);
|
pAnim->CollectChannelsRecursively(channels);
|
||||||
|
@ -652,18 +618,15 @@ struct Animation
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Combine all single-channel animations' channel into the same (parent) animation channel list. */
|
/** Combine all single-channel animations' channel into the same (parent) animation channel list. */
|
||||||
void CombineSingleChannelAnimations()
|
void CombineSingleChannelAnimations() {
|
||||||
{
|
|
||||||
CombineSingleChannelAnimationsRecursively(this);
|
CombineSingleChannelAnimationsRecursively(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CombineSingleChannelAnimationsRecursively(Animation *pParent)
|
void CombineSingleChannelAnimationsRecursively(Animation *pParent) {
|
||||||
{
|
|
||||||
std::set<std::string> childrenTargets;
|
std::set<std::string> childrenTargets;
|
||||||
bool childrenAnimationsHaveDifferentChannels = true;
|
bool childrenAnimationsHaveDifferentChannels = true;
|
||||||
|
|
||||||
for (std::vector<Animation*>::iterator it = pParent->mSubAnims.begin(); it != pParent->mSubAnims.end();)
|
for (std::vector<Animation *>::iterator it = pParent->mSubAnims.begin(); it != pParent->mSubAnims.end();) {
|
||||||
{
|
|
||||||
Animation *anim = *it;
|
Animation *anim = *it;
|
||||||
CombineSingleChannelAnimationsRecursively(anim);
|
CombineSingleChannelAnimationsRecursively(anim);
|
||||||
|
|
||||||
|
@ -678,10 +641,8 @@ struct Animation
|
||||||
}
|
}
|
||||||
|
|
||||||
// We only want to combine animations if they have different channels
|
// We only want to combine animations if they have different channels
|
||||||
if (childrenAnimationsHaveDifferentChannels)
|
if (childrenAnimationsHaveDifferentChannels) {
|
||||||
{
|
for (std::vector<Animation *>::iterator it = pParent->mSubAnims.begin(); it != pParent->mSubAnims.end();) {
|
||||||
for (std::vector<Animation*>::iterator it = pParent->mSubAnims.begin(); it != pParent->mSubAnims.end();)
|
|
||||||
{
|
|
||||||
Animation *anim = *it;
|
Animation *anim = *it;
|
||||||
|
|
||||||
pParent->mChannels.push_back(anim->mChannels[0]);
|
pParent->mChannels.push_back(anim->mChannels[0]);
|
||||||
|
@ -696,8 +657,7 @@ struct Animation
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Description of a collada animation channel which has been determined to affect the current node */
|
/** Description of a collada animation channel which has been determined to affect the current node */
|
||||||
struct ChannelEntry
|
struct ChannelEntry {
|
||||||
{
|
|
||||||
const Collada::AnimationChannel *mChannel; ///> the source channel
|
const Collada::AnimationChannel *mChannel; ///> the source channel
|
||||||
std::string mTargetId;
|
std::string mTargetId;
|
||||||
std::string mTransformId; // the ID of the transformation step of the node which is influenced
|
std::string mTransformId; // the ID of the transformation step of the node which is influenced
|
||||||
|
@ -710,15 +670,14 @@ struct ChannelEntry
|
||||||
const Collada::Accessor *mValueAccessor; ///> Collada accessor to the key value values
|
const Collada::Accessor *mValueAccessor; ///> Collada accessor to the key value values
|
||||||
const Collada::Data *mValueData; ///> Source datat array for the key value values
|
const Collada::Data *mValueData; ///> Source datat array for the key value values
|
||||||
|
|
||||||
ChannelEntry()
|
ChannelEntry() :
|
||||||
: mChannel()
|
mChannel(),
|
||||||
, mTransformIndex()
|
mTransformIndex(),
|
||||||
, mSubElement()
|
mSubElement(),
|
||||||
, mTimeAccessor()
|
mTimeAccessor(),
|
||||||
, mTimeData()
|
mTimeData(),
|
||||||
, mValueAccessor()
|
mValueAccessor(),
|
||||||
, mValueData()
|
mValueData() {}
|
||||||
{}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // end of namespace Collada
|
} // end of namespace Collada
|
||||||
|
|
|
@ -46,24 +46,24 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
#include "ColladaLoader.h"
|
#include "ColladaLoader.h"
|
||||||
#include "ColladaParser.h"
|
#include "ColladaParser.h"
|
||||||
|
|
||||||
|
#include <assimp/Defines.h>
|
||||||
#include <assimp/anim.h>
|
#include <assimp/anim.h>
|
||||||
|
#include <assimp/importerdesc.h>
|
||||||
#include <assimp/scene.h>
|
#include <assimp/scene.h>
|
||||||
#include <assimp/DefaultLogger.hpp>
|
#include <assimp/DefaultLogger.hpp>
|
||||||
#include <assimp/Importer.hpp>
|
#include <assimp/Importer.hpp>
|
||||||
#include <assimp/importerdesc.h>
|
|
||||||
#include <assimp/Defines.h>
|
|
||||||
|
|
||||||
#include <assimp/fast_atof.h>
|
#include <assimp/CreateAnimMesh.h>
|
||||||
#include <assimp/ParsingUtils.h>
|
#include <assimp/ParsingUtils.h>
|
||||||
#include <assimp/SkeletonMeshBuilder.h>
|
#include <assimp/SkeletonMeshBuilder.h>
|
||||||
#include <assimp/CreateAnimMesh.h>
|
|
||||||
#include <assimp/ZipArchiveIOSystem.h>
|
#include <assimp/ZipArchiveIOSystem.h>
|
||||||
|
#include <assimp/fast_atof.h>
|
||||||
|
|
||||||
#include "time.h"
|
|
||||||
#include "math.h"
|
#include "math.h"
|
||||||
|
#include "time.h"
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <numeric>
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <numeric>
|
||||||
|
|
||||||
namespace Assimp {
|
namespace Assimp {
|
||||||
|
|
||||||
|
@ -84,20 +84,20 @@ static const aiImporterDesc desc = {
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
// Constructor to be privately used by Importer
|
// Constructor to be privately used by Importer
|
||||||
ColladaLoader::ColladaLoader()
|
ColladaLoader::ColladaLoader() :
|
||||||
: mFileName()
|
mFileName(),
|
||||||
, mMeshIndexByID()
|
mMeshIndexByID(),
|
||||||
, mMaterialIndexByName()
|
mMaterialIndexByName(),
|
||||||
, mMeshes()
|
mMeshes(),
|
||||||
, newMats()
|
newMats(),
|
||||||
, mCameras()
|
mCameras(),
|
||||||
, mLights()
|
mLights(),
|
||||||
, mTextures()
|
mTextures(),
|
||||||
, mAnims()
|
mAnims(),
|
||||||
, noSkeletonMesh(false)
|
noSkeletonMesh(false),
|
||||||
, ignoreUpDirection(false)
|
ignoreUpDirection(false),
|
||||||
, useColladaName(false)
|
useColladaName(false),
|
||||||
, mNodeNameCounter(0) {
|
mNodeNameCounter(0) {
|
||||||
// empty
|
// empty
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -176,7 +176,6 @@ void ColladaLoader::InternReadFile(const std::string& pFile, aiScene* pScene, IO
|
||||||
// parse the input file
|
// parse the input file
|
||||||
ColladaParser parser(pIOHandler, pFile);
|
ColladaParser parser(pIOHandler, pFile);
|
||||||
|
|
||||||
|
|
||||||
if (!parser.mRootNode) {
|
if (!parser.mRootNode) {
|
||||||
throw DeadlyImportError("Collada: File came out empty. Something is wrong here.");
|
throw DeadlyImportError("Collada: File came out empty. Something is wrong here.");
|
||||||
}
|
}
|
||||||
|
@ -372,8 +371,7 @@ void ColladaLoader::BuildLightsForNode(const ColladaParser& pParser, const Colla
|
||||||
if (out->mType == aiLightSource_AMBIENT) {
|
if (out->mType == aiLightSource_AMBIENT) {
|
||||||
out->mColorDiffuse = out->mColorSpecular = aiColor3D(0, 0, 0);
|
out->mColorDiffuse = out->mColorSpecular = aiColor3D(0, 0, 0);
|
||||||
out->mColorAmbient = srcLight->mColor * srcLight->mIntensity;
|
out->mColorAmbient = srcLight->mColor * srcLight->mIntensity;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
// collada doesn't differentiate between these color types
|
// collada doesn't differentiate between these color types
|
||||||
out->mColorDiffuse = out->mColorSpecular = srcLight->mColor * srcLight->mIntensity;
|
out->mColorDiffuse = out->mColorSpecular = srcLight->mColor * srcLight->mIntensity;
|
||||||
out->mColorAmbient = aiColor3D(0, 0, 0);
|
out->mColorAmbient = aiColor3D(0, 0, 0);
|
||||||
|
@ -391,14 +389,12 @@ void ColladaLoader::BuildLightsForNode(const ColladaParser& pParser, const Colla
|
||||||
// epsilon chosen to be 0.1
|
// epsilon chosen to be 0.1
|
||||||
out->mAngleOuterCone = std::acos(std::pow(0.1f, 1.f / srcLight->mFalloffExponent)) +
|
out->mAngleOuterCone = std::acos(std::pow(0.1f, 1.f / srcLight->mFalloffExponent)) +
|
||||||
out->mAngleInnerCone;
|
out->mAngleInnerCone;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
out->mAngleOuterCone = out->mAngleInnerCone + AI_DEG_TO_RAD(srcLight->mPenumbraAngle);
|
out->mAngleOuterCone = out->mAngleInnerCone + AI_DEG_TO_RAD(srcLight->mPenumbraAngle);
|
||||||
if (out->mAngleOuterCone < out->mAngleInnerCone)
|
if (out->mAngleOuterCone < out->mAngleInnerCone)
|
||||||
std::swap(out->mAngleInnerCone, out->mAngleOuterCone);
|
std::swap(out->mAngleInnerCone, out->mAngleOuterCone);
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
out->mAngleOuterCone = AI_DEG_TO_RAD(srcLight->mOuterAngle);
|
out->mAngleOuterCone = AI_DEG_TO_RAD(srcLight->mOuterAngle);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -488,13 +484,11 @@ void ColladaLoader::BuildMeshesForNode(const ColladaParser& pParser, const Colla
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (nullptr == srcMesh) {
|
if (nullptr == srcMesh) {
|
||||||
ASSIMP_LOG_WARN_F("Collada: Unable to find geometry for ID \"", mid.mMeshOrController, "\". Skipping.");
|
ASSIMP_LOG_WARN_F("Collada: Unable to find geometry for ID \"", mid.mMeshOrController, "\". Skipping.");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
// ID found in the mesh library -> direct reference to an unskinned mesh
|
// ID found in the mesh library -> direct reference to an unskinned mesh
|
||||||
srcMesh = srcMeshIt->second;
|
srcMesh = srcMeshIt->second;
|
||||||
}
|
}
|
||||||
|
@ -515,8 +509,7 @@ void ColladaLoader::BuildMeshesForNode(const ColladaParser& pParser, const Colla
|
||||||
if (meshMatIt != mid.mMaterials.end()) {
|
if (meshMatIt != mid.mMaterials.end()) {
|
||||||
table = &meshMatIt->second;
|
table = &meshMatIt->second;
|
||||||
meshMaterial = table->mMatName;
|
meshMaterial = table->mMatName;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
ASSIMP_LOG_WARN_F("Collada: No material specified for subgroup <", submesh.mMaterial, "> in geometry <",
|
ASSIMP_LOG_WARN_F("Collada: No material specified for subgroup <", submesh.mMaterial, "> in geometry <",
|
||||||
mid.mMeshOrController, ">.");
|
mid.mMeshOrController, ">.");
|
||||||
if (!mid.mMaterials.empty()) {
|
if (!mid.mMaterials.empty()) {
|
||||||
|
@ -552,8 +545,7 @@ void ColladaLoader::BuildMeshesForNode(const ColladaParser& pParser, const Colla
|
||||||
std::map<ColladaMeshIndex, size_t>::const_iterator dstMeshIt = mMeshIndexByID.find(index);
|
std::map<ColladaMeshIndex, size_t>::const_iterator dstMeshIt = mMeshIndexByID.find(index);
|
||||||
if (dstMeshIt != mMeshIndexByID.end()) {
|
if (dstMeshIt != mMeshIndexByID.end()) {
|
||||||
newMeshRefs.push_back(dstMeshIt->second);
|
newMeshRefs.push_back(dstMeshIt->second);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
// else we have to add the mesh to the collection and store its newly assigned index at the node
|
// else we have to add the mesh to the collection and store its newly assigned index at the node
|
||||||
aiMesh *dstMesh = CreateMesh(pParser, srcMesh, submesh, srcController, vertexStart, faceStart);
|
aiMesh *dstMesh = CreateMesh(pParser, srcMesh, submesh, srcController, vertexStart, faceStart);
|
||||||
|
|
||||||
|
@ -561,7 +553,8 @@ void ColladaLoader::BuildMeshesForNode(const ColladaParser& pParser, const Colla
|
||||||
newMeshRefs.push_back(mMeshes.size());
|
newMeshRefs.push_back(mMeshes.size());
|
||||||
mMeshIndexByID[index] = mMeshes.size();
|
mMeshIndexByID[index] = mMeshes.size();
|
||||||
mMeshes.push_back(dstMesh);
|
mMeshes.push_back(dstMesh);
|
||||||
vertexStart += dstMesh->mNumVertices; faceStart += submesh.mNumFaces;
|
vertexStart += dstMesh->mNumVertices;
|
||||||
|
faceStart += submesh.mNumFaces;
|
||||||
|
|
||||||
// assign the material index
|
// assign the material index
|
||||||
dstMesh->mMaterialIndex = matIdx;
|
dstMesh->mMaterialIndex = matIdx;
|
||||||
|
@ -619,30 +612,26 @@ aiMesh* ColladaLoader::CreateMesh(const ColladaParser& pParser, const Collada::M
|
||||||
// copy positions
|
// copy positions
|
||||||
dstMesh->mNumVertices = static_cast<unsigned int>(numVertices);
|
dstMesh->mNumVertices = static_cast<unsigned int>(numVertices);
|
||||||
dstMesh->mVertices = new aiVector3D[numVertices];
|
dstMesh->mVertices = new aiVector3D[numVertices];
|
||||||
std::copy(pSrcMesh->mPositions.begin() + pStartVertex, pSrcMesh->mPositions.begin() +
|
std::copy(pSrcMesh->mPositions.begin() + pStartVertex, pSrcMesh->mPositions.begin() + pStartVertex + numVertices, dstMesh->mVertices);
|
||||||
pStartVertex + numVertices, dstMesh->mVertices);
|
|
||||||
|
|
||||||
// normals, if given. HACK: (thom) Due to the glorious Collada spec we never
|
// normals, if given. HACK: (thom) Due to the glorious Collada spec we never
|
||||||
// know if we have the same number of normals as there are positions. So we
|
// know if we have the same number of normals as there are positions. So we
|
||||||
// also ignore any vertex attribute if it has a different count
|
// also ignore any vertex attribute if it has a different count
|
||||||
if (pSrcMesh->mNormals.size() >= pStartVertex + numVertices) {
|
if (pSrcMesh->mNormals.size() >= pStartVertex + numVertices) {
|
||||||
dstMesh->mNormals = new aiVector3D[numVertices];
|
dstMesh->mNormals = new aiVector3D[numVertices];
|
||||||
std::copy(pSrcMesh->mNormals.begin() + pStartVertex, pSrcMesh->mNormals.begin() +
|
std::copy(pSrcMesh->mNormals.begin() + pStartVertex, pSrcMesh->mNormals.begin() + pStartVertex + numVertices, dstMesh->mNormals);
|
||||||
pStartVertex + numVertices, dstMesh->mNormals);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// tangents, if given.
|
// tangents, if given.
|
||||||
if (pSrcMesh->mTangents.size() >= pStartVertex + numVertices) {
|
if (pSrcMesh->mTangents.size() >= pStartVertex + numVertices) {
|
||||||
dstMesh->mTangents = new aiVector3D[numVertices];
|
dstMesh->mTangents = new aiVector3D[numVertices];
|
||||||
std::copy(pSrcMesh->mTangents.begin() + pStartVertex, pSrcMesh->mTangents.begin() +
|
std::copy(pSrcMesh->mTangents.begin() + pStartVertex, pSrcMesh->mTangents.begin() + pStartVertex + numVertices, dstMesh->mTangents);
|
||||||
pStartVertex + numVertices, dstMesh->mTangents);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// bitangents, if given.
|
// bitangents, if given.
|
||||||
if (pSrcMesh->mBitangents.size() >= pStartVertex + numVertices) {
|
if (pSrcMesh->mBitangents.size() >= pStartVertex + numVertices) {
|
||||||
dstMesh->mBitangents = new aiVector3D[numVertices];
|
dstMesh->mBitangents = new aiVector3D[numVertices];
|
||||||
std::copy(pSrcMesh->mBitangents.begin() + pStartVertex, pSrcMesh->mBitangents.begin() +
|
std::copy(pSrcMesh->mBitangents.begin() + pStartVertex, pSrcMesh->mBitangents.begin() + pStartVertex + numVertices, dstMesh->mBitangents);
|
||||||
pStartVertex + numVertices, dstMesh->mBitangents);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// same for texturecoords, as many as we have
|
// same for texturecoords, as many as we have
|
||||||
|
@ -736,9 +725,7 @@ aiMesh* ColladaLoader::CreateMesh(const ColladaParser& pParser, const Collada::M
|
||||||
animMesh->mName = targetMesh->mName;
|
animMesh->mName = targetMesh->mName;
|
||||||
animMeshes.push_back(animMesh);
|
animMeshes.push_back(animMesh);
|
||||||
}
|
}
|
||||||
dstMesh->mMethod = (method == Collada::Relative)
|
dstMesh->mMethod = (method == Collada::Relative) ? aiMorphingMethod_MORPH_RELATIVE : aiMorphingMethod_MORPH_NORMALIZED;
|
||||||
? aiMorphingMethod_MORPH_RELATIVE
|
|
||||||
: aiMorphingMethod_MORPH_NORMALIZED;
|
|
||||||
dstMesh->mAnimMeshes = new aiAnimMesh *[animMeshes.size()];
|
dstMesh->mAnimMeshes = new aiAnimMesh *[animMeshes.size()];
|
||||||
dstMesh->mNumAnimMeshes = static_cast<unsigned int>(animMeshes.size());
|
dstMesh->mNumAnimMeshes = static_cast<unsigned int>(animMeshes.size());
|
||||||
for (unsigned int i = 0; i < animMeshes.size(); ++i) {
|
for (unsigned int i = 0; i < animMeshes.size(); ++i) {
|
||||||
|
@ -792,7 +779,6 @@ aiMesh* ColladaLoader::CreateMesh(const ColladaParser& pParser, const Collada::M
|
||||||
IndexPairVector::const_iterator iit = weightStartPerVertex[orgIndex];
|
IndexPairVector::const_iterator iit = weightStartPerVertex[orgIndex];
|
||||||
size_t pairCount = pSrcController->mWeightCounts[orgIndex];
|
size_t pairCount = pSrcController->mWeightCounts[orgIndex];
|
||||||
|
|
||||||
|
|
||||||
for (size_t b = 0; b < pairCount; ++b, ++iit) {
|
for (size_t b = 0; b < pairCount; ++b, ++iit) {
|
||||||
const size_t jointIndex = iit->first;
|
const size_t jointIndex = iit->first;
|
||||||
const size_t vertexIndex = iit->second;
|
const size_t vertexIndex = iit->second;
|
||||||
|
@ -802,8 +788,7 @@ aiMesh* ColladaLoader::CreateMesh(const ColladaParser& pParser, const Collada::M
|
||||||
}
|
}
|
||||||
|
|
||||||
// one day I gonna kill that XSI Collada exporter
|
// one day I gonna kill that XSI Collada exporter
|
||||||
if (weight > 0.0f)
|
if (weight > 0.0f) {
|
||||||
{
|
|
||||||
aiVertexWeight w;
|
aiVertexWeight w;
|
||||||
w.mVertexId = static_cast<unsigned int>(a - pStartVertex);
|
w.mVertexId = static_cast<unsigned int>(a - pStartVertex);
|
||||||
w.mWeight = weight;
|
w.mWeight = weight;
|
||||||
|
@ -980,8 +965,7 @@ void ColladaLoader::StoreAnimations( aiScene* pScene, const ColladaParser& pPars
|
||||||
std::set<std::string> animTargets;
|
std::set<std::string> animTargets;
|
||||||
animTargets.insert(templateAnim->mChannels[0]->mNodeName.C_Str());
|
animTargets.insert(templateAnim->mChannels[0]->mNodeName.C_Str());
|
||||||
bool collectedAnimationsHaveDifferentChannels = true;
|
bool collectedAnimationsHaveDifferentChannels = true;
|
||||||
for (size_t b = 0; b < collectedAnimIndices.size(); ++b)
|
for (size_t b = 0; b < collectedAnimIndices.size(); ++b) {
|
||||||
{
|
|
||||||
aiAnimation *srcAnimation = mAnims[collectedAnimIndices[b]];
|
aiAnimation *srcAnimation = mAnims[collectedAnimIndices[b]];
|
||||||
std::string channelName = std::string(srcAnimation->mChannels[0]->mNodeName.C_Str());
|
std::string channelName = std::string(srcAnimation->mChannels[0]->mNodeName.C_Str());
|
||||||
if (animTargets.find(channelName) == animTargets.end()) {
|
if (animTargets.find(channelName) == animTargets.end()) {
|
||||||
|
@ -996,8 +980,7 @@ void ColladaLoader::StoreAnimations( aiScene* pScene, const ColladaParser& pPars
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// if there are other animations which fit the template anim, combine all channels into a single anim
|
// if there are other animations which fit the template anim, combine all channels into a single anim
|
||||||
if (!collectedAnimIndices.empty())
|
if (!collectedAnimIndices.empty()) {
|
||||||
{
|
|
||||||
aiAnimation *combinedAnim = new aiAnimation();
|
aiAnimation *combinedAnim = new aiAnimation();
|
||||||
combinedAnim->mName = aiString(std::string("combinedAnim_") + char('0' + a));
|
combinedAnim->mName = aiString(std::string("combinedAnim_") + char('0' + a));
|
||||||
combinedAnim->mDuration = templateAnim->mDuration;
|
combinedAnim->mDuration = templateAnim->mDuration;
|
||||||
|
@ -1012,8 +995,7 @@ void ColladaLoader::StoreAnimations( aiScene* pScene, const ColladaParser& pPars
|
||||||
mAnims[a] = combinedAnim;
|
mAnims[a] = combinedAnim;
|
||||||
|
|
||||||
// move the memory of all other anims to the combined anim and erase them from the source anims
|
// move the memory of all other anims to the combined anim and erase them from the source anims
|
||||||
for (size_t b = 0; b < collectedAnimIndices.size(); ++b)
|
for (size_t b = 0; b < collectedAnimIndices.size(); ++b) {
|
||||||
{
|
|
||||||
aiAnimation *srcAnimation = mAnims[collectedAnimIndices[b]];
|
aiAnimation *srcAnimation = mAnims[collectedAnimIndices[b]];
|
||||||
combinedAnim->mChannels[1 + b] = srcAnimation->mChannels[0];
|
combinedAnim->mChannels[1 + b] = srcAnimation->mChannels[0];
|
||||||
srcAnimation->mChannels[0] = NULL;
|
srcAnimation->mChannels[0] = NULL;
|
||||||
|
@ -1022,8 +1004,7 @@ void ColladaLoader::StoreAnimations( aiScene* pScene, const ColladaParser& pPars
|
||||||
|
|
||||||
// in a second go, delete all the single-channel-anims that we've stripped from their channels
|
// in a second go, delete all the single-channel-anims that we've stripped from their channels
|
||||||
// back to front to preserve indices - you know, removing an element from a vector moves all elements behind the removed one
|
// back to front to preserve indices - you know, removing an element from a vector moves all elements behind the removed one
|
||||||
while (!collectedAnimIndices.empty())
|
while (!collectedAnimIndices.empty()) {
|
||||||
{
|
|
||||||
mAnims.erase(mAnims.begin() + collectedAnimIndices.back());
|
mAnims.erase(mAnims.begin() + collectedAnimIndices.back());
|
||||||
collectedAnimIndices.pop_back();
|
collectedAnimIndices.pop_back();
|
||||||
}
|
}
|
||||||
|
@ -1032,8 +1013,7 @@ void ColladaLoader::StoreAnimations( aiScene* pScene, const ColladaParser& pPars
|
||||||
}
|
}
|
||||||
|
|
||||||
// now store all anims in the scene
|
// now store all anims in the scene
|
||||||
if (!mAnims.empty())
|
if (!mAnims.empty()) {
|
||||||
{
|
|
||||||
pScene->mNumAnimations = static_cast<unsigned int>(mAnims.size());
|
pScene->mNumAnimations = static_cast<unsigned int>(mAnims.size());
|
||||||
pScene->mAnimations = new aiAnimation *[mAnims.size()];
|
pScene->mAnimations = new aiAnimation *[mAnims.size()];
|
||||||
std::copy(mAnims.begin(), mAnims.end(), pScene->mAnimations);
|
std::copy(mAnims.begin(), mAnims.end(), pScene->mAnimations);
|
||||||
|
@ -1044,8 +1024,7 @@ void ColladaLoader::StoreAnimations( aiScene* pScene, const ColladaParser& pPars
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
// Constructs the animations for the given source anim
|
// Constructs the animations for the given source anim
|
||||||
void ColladaLoader::StoreAnimations(aiScene* pScene, const ColladaParser& pParser, const Collada::Animation* pSrcAnim, const std::string &pPrefix)
|
void ColladaLoader::StoreAnimations(aiScene *pScene, const ColladaParser &pParser, const Collada::Animation *pSrcAnim, const std::string &pPrefix) {
|
||||||
{
|
|
||||||
std::string animName = pPrefix.empty() ? pSrcAnim->mName : pPrefix + "_" + pSrcAnim->mName;
|
std::string animName = pPrefix.empty() ? pSrcAnim->mName : pPrefix + "_" + pSrcAnim->mName;
|
||||||
|
|
||||||
// create nested animations, if given
|
// create nested animations, if given
|
||||||
|
@ -1057,47 +1036,38 @@ void ColladaLoader::StoreAnimations(aiScene* pScene, const ColladaParser& pParse
|
||||||
CreateAnimation(pScene, pParser, pSrcAnim, animName);
|
CreateAnimation(pScene, pParser, pSrcAnim, animName);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct MorphTimeValues
|
struct MorphTimeValues {
|
||||||
{
|
|
||||||
float mTime;
|
float mTime;
|
||||||
struct key
|
struct key {
|
||||||
{
|
|
||||||
float mWeight;
|
float mWeight;
|
||||||
unsigned int mValue;
|
unsigned int mValue;
|
||||||
};
|
};
|
||||||
std::vector<key> mKeys;
|
std::vector<key> mKeys;
|
||||||
};
|
};
|
||||||
|
|
||||||
void insertMorphTimeValue(std::vector<MorphTimeValues> &values, float time, float weight, unsigned int value)
|
void insertMorphTimeValue(std::vector<MorphTimeValues> &values, float time, float weight, unsigned int value) {
|
||||||
{
|
|
||||||
MorphTimeValues::key k;
|
MorphTimeValues::key k;
|
||||||
k.mValue = value;
|
k.mValue = value;
|
||||||
k.mWeight = weight;
|
k.mWeight = weight;
|
||||||
if (values.size() == 0 || time < values[0].mTime)
|
if (values.size() == 0 || time < values[0].mTime) {
|
||||||
{
|
|
||||||
MorphTimeValues val;
|
MorphTimeValues val;
|
||||||
val.mTime = time;
|
val.mTime = time;
|
||||||
val.mKeys.push_back(k);
|
val.mKeys.push_back(k);
|
||||||
values.insert(values.begin(), val);
|
values.insert(values.begin(), val);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (time > values.back().mTime)
|
if (time > values.back().mTime) {
|
||||||
{
|
|
||||||
MorphTimeValues val;
|
MorphTimeValues val;
|
||||||
val.mTime = time;
|
val.mTime = time;
|
||||||
val.mKeys.push_back(k);
|
val.mKeys.push_back(k);
|
||||||
values.insert(values.end(), val);
|
values.insert(values.end(), val);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for (unsigned int i = 0; i < values.size(); i++)
|
for (unsigned int i = 0; i < values.size(); i++) {
|
||||||
{
|
if (std::abs(time - values[i].mTime) < 1e-6f) {
|
||||||
if (std::abs(time - values[i].mTime) < 1e-6f)
|
|
||||||
{
|
|
||||||
values[i].mKeys.push_back(k);
|
values[i].mKeys.push_back(k);
|
||||||
return;
|
return;
|
||||||
}
|
} else if (time > values[i].mTime && time < values[i + 1].mTime) {
|
||||||
else if (time > values[i].mTime && time < values[i + 1].mTime)
|
|
||||||
{
|
|
||||||
MorphTimeValues val;
|
MorphTimeValues val;
|
||||||
val.mTime = time;
|
val.mTime = time;
|
||||||
val.mKeys.push_back(k);
|
val.mKeys.push_back(k);
|
||||||
|
@ -1108,10 +1078,8 @@ void insertMorphTimeValue(std::vector<MorphTimeValues> &values, float time, floa
|
||||||
// should not get here
|
// should not get here
|
||||||
}
|
}
|
||||||
|
|
||||||
float getWeightAtKey(const std::vector<MorphTimeValues> &values, int key, unsigned int value)
|
float getWeightAtKey(const std::vector<MorphTimeValues> &values, int key, unsigned int value) {
|
||||||
{
|
for (unsigned int i = 0; i < values[key].mKeys.size(); i++) {
|
||||||
for (unsigned int i = 0; i < values[key].mKeys.size(); i++)
|
|
||||||
{
|
|
||||||
if (values[key].mKeys[i].mValue == value)
|
if (values[key].mKeys[i].mValue == value)
|
||||||
return values[key].mKeys[i].mWeight;
|
return values[key].mKeys[i].mWeight;
|
||||||
}
|
}
|
||||||
|
@ -1122,8 +1090,7 @@ float getWeightAtKey(const std::vector<MorphTimeValues> &values, int key, unsign
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
// Constructs the animation for the given source anim
|
// Constructs the animation for the given source anim
|
||||||
void ColladaLoader::CreateAnimation(aiScene* pScene, const ColladaParser& pParser, const Collada::Animation* pSrcAnim, const std::string& pName)
|
void ColladaLoader::CreateAnimation(aiScene *pScene, const ColladaParser &pParser, const Collada::Animation *pSrcAnim, const std::string &pName) {
|
||||||
{
|
|
||||||
// collect a list of animatable nodes
|
// collect a list of animatable nodes
|
||||||
std::vector<const aiNode *> nodes;
|
std::vector<const aiNode *> nodes;
|
||||||
CollectNodes(pScene->mRootNode, nodes);
|
CollectNodes(pScene->mRootNode, nodes);
|
||||||
|
@ -1131,8 +1098,7 @@ void ColladaLoader::CreateAnimation(aiScene* pScene, const ColladaParser& pParse
|
||||||
std::vector<aiNodeAnim *> anims;
|
std::vector<aiNodeAnim *> anims;
|
||||||
std::vector<aiMeshMorphAnim *> morphAnims;
|
std::vector<aiMeshMorphAnim *> morphAnims;
|
||||||
|
|
||||||
for (std::vector<const aiNode*>::const_iterator nit = nodes.begin(); nit != nodes.end(); ++nit)
|
for (std::vector<const aiNode *>::const_iterator nit = nodes.begin(); nit != nodes.end(); ++nit) {
|
||||||
{
|
|
||||||
// find all the collada anim channels which refer to the current node
|
// find all the collada anim channels which refer to the current node
|
||||||
std::vector<Collada::ChannelEntry> entries;
|
std::vector<Collada::ChannelEntry> entries;
|
||||||
std::string nodeName = (*nit)->mName.data;
|
std::string nodeName = (*nit)->mName.data;
|
||||||
|
@ -1146,16 +1112,14 @@ void ColladaLoader::CreateAnimation(aiScene* pScene, const ColladaParser& pParse
|
||||||
// now check all channels if they affect the current node
|
// now check all channels if they affect the current node
|
||||||
std::string targetID, subElement;
|
std::string targetID, subElement;
|
||||||
for (std::vector<Collada::AnimationChannel>::const_iterator cit = pSrcAnim->mChannels.begin();
|
for (std::vector<Collada::AnimationChannel>::const_iterator cit = pSrcAnim->mChannels.begin();
|
||||||
cit != pSrcAnim->mChannels.end(); ++cit)
|
cit != pSrcAnim->mChannels.end(); ++cit) {
|
||||||
{
|
|
||||||
const Collada::AnimationChannel &srcChannel = *cit;
|
const Collada::AnimationChannel &srcChannel = *cit;
|
||||||
Collada::ChannelEntry entry;
|
Collada::ChannelEntry entry;
|
||||||
|
|
||||||
// we expect the animation target to be of type "nodeName/transformID.subElement". Ignore all others
|
// we expect the animation target to be of type "nodeName/transformID.subElement". Ignore all others
|
||||||
// find the slash that separates the node name - there should be only one
|
// find the slash that separates the node name - there should be only one
|
||||||
std::string::size_type slashPos = srcChannel.mTarget.find('/');
|
std::string::size_type slashPos = srcChannel.mTarget.find('/');
|
||||||
if (slashPos == std::string::npos)
|
if (slashPos == std::string::npos) {
|
||||||
{
|
|
||||||
std::string::size_type targetPos = srcChannel.mTarget.find(srcNode->mID);
|
std::string::size_type targetPos = srcChannel.mTarget.find(srcNode->mID);
|
||||||
if (targetPos == std::string::npos)
|
if (targetPos == std::string::npos)
|
||||||
continue;
|
continue;
|
||||||
|
@ -1179,8 +1143,7 @@ void ColladaLoader::CreateAnimation(aiScene* pScene, const ColladaParser& pParse
|
||||||
|
|
||||||
// find the dot that separates the transformID - there should be only one or zero
|
// find the dot that separates the transformID - there should be only one or zero
|
||||||
std::string::size_type dotPos = srcChannel.mTarget.find('.');
|
std::string::size_type dotPos = srcChannel.mTarget.find('.');
|
||||||
if (dotPos != std::string::npos)
|
if (dotPos != std::string::npos) {
|
||||||
{
|
|
||||||
if (srcChannel.mTarget.find('.', dotPos + 1) != std::string::npos)
|
if (srcChannel.mTarget.find('.', dotPos + 1) != std::string::npos)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
@ -1198,15 +1161,13 @@ void ColladaLoader::CreateAnimation(aiScene* pScene, const ColladaParser& pParse
|
||||||
entry.mSubElement = 2;
|
entry.mSubElement = 2;
|
||||||
else
|
else
|
||||||
ASSIMP_LOG_WARN_F("Unknown anim subelement <", subElement, ">. Ignoring");
|
ASSIMP_LOG_WARN_F("Unknown anim subelement <", subElement, ">. Ignoring");
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
// no subelement following, transformId is remaining string
|
// no subelement following, transformId is remaining string
|
||||||
entry.mTransformId = srcChannel.mTarget.substr(slashPos + 1);
|
entry.mTransformId = srcChannel.mTarget.substr(slashPos + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string::size_type bracketPos = srcChannel.mTarget.find('(');
|
std::string::size_type bracketPos = srcChannel.mTarget.find('(');
|
||||||
if (bracketPos != std::string::npos)
|
if (bracketPos != std::string::npos) {
|
||||||
{
|
|
||||||
entry.mTransformId = srcChannel.mTarget.substr(slashPos + 1, bracketPos - slashPos - 1);
|
entry.mTransformId = srcChannel.mTarget.substr(slashPos + 1, bracketPos - slashPos - 1);
|
||||||
subElement.clear();
|
subElement.clear();
|
||||||
subElement = srcChannel.mTarget.substr(bracketPos);
|
subElement = srcChannel.mTarget.substr(bracketPos);
|
||||||
|
@ -1251,14 +1212,11 @@ void ColladaLoader::CreateAnimation(aiScene* pScene, const ColladaParser& pParse
|
||||||
if (srcNode->mTransforms[a].mID == entry.mTransformId)
|
if (srcNode->mTransforms[a].mID == entry.mTransformId)
|
||||||
entry.mTransformIndex = a;
|
entry.mTransformIndex = a;
|
||||||
|
|
||||||
if (entry.mTransformIndex == SIZE_MAX)
|
if (entry.mTransformIndex == SIZE_MAX) {
|
||||||
{
|
if (entry.mTransformId.find("morph-weights") != std::string::npos) {
|
||||||
if (entry.mTransformId.find("morph-weights") != std::string::npos)
|
|
||||||
{
|
|
||||||
entry.mTargetId = entry.mTransformId;
|
entry.mTargetId = entry.mTransformId;
|
||||||
entry.mTransformId = "";
|
entry.mTransformId = "";
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1272,8 +1230,7 @@ void ColladaLoader::CreateAnimation(aiScene* pScene, const ColladaParser& pParse
|
||||||
|
|
||||||
// resolve the data pointers for all anim channels. Find the minimum time while we're at it
|
// resolve the data pointers for all anim channels. Find the minimum time while we're at it
|
||||||
ai_real startTime = ai_real(1e20), endTime = ai_real(-1e20);
|
ai_real startTime = ai_real(1e20), endTime = ai_real(-1e20);
|
||||||
for (std::vector<Collada::ChannelEntry>::iterator it = entries.begin(); it != entries.end(); ++it)
|
for (std::vector<Collada::ChannelEntry>::iterator it = entries.begin(); it != entries.end(); ++it) {
|
||||||
{
|
|
||||||
Collada::ChannelEntry &e = *it;
|
Collada::ChannelEntry &e = *it;
|
||||||
e.mTimeAccessor = &pParser.ResolveLibraryReference(pParser.mAccessorLibrary, e.mChannel->mSourceTimes);
|
e.mTimeAccessor = &pParser.ResolveLibraryReference(pParser.mAccessorLibrary, e.mChannel->mSourceTimes);
|
||||||
e.mTimeData = &pParser.ResolveLibraryReference(pParser.mDataLibrary, e.mTimeAccessor->mSource);
|
e.mTimeData = &pParser.ResolveLibraryReference(pParser.mDataLibrary, e.mTimeAccessor->mSource);
|
||||||
|
@ -1284,8 +1241,7 @@ void ColladaLoader::CreateAnimation(aiScene* pScene, const ColladaParser& pParse
|
||||||
if (e.mTimeAccessor->mCount != e.mValueAccessor->mCount)
|
if (e.mTimeAccessor->mCount != e.mValueAccessor->mCount)
|
||||||
throw DeadlyImportError(format() << "Time count / value count mismatch in animation channel \"" << e.mChannel->mTarget << "\".");
|
throw DeadlyImportError(format() << "Time count / value count mismatch in animation channel \"" << e.mChannel->mTarget << "\".");
|
||||||
|
|
||||||
if (e.mTimeAccessor->mCount > 0)
|
if (e.mTimeAccessor->mCount > 0) {
|
||||||
{
|
|
||||||
// find bounding times
|
// find bounding times
|
||||||
startTime = std::min(startTime, ReadFloat(*e.mTimeAccessor, *e.mTimeData, 0, 0));
|
startTime = std::min(startTime, ReadFloat(*e.mTimeAccessor, *e.mTimeData, 0, 0));
|
||||||
endTime = std::max(endTime, ReadFloat(*e.mTimeAccessor, *e.mTimeData, e.mTimeAccessor->mCount - 1, 0));
|
endTime = std::max(endTime, ReadFloat(*e.mTimeAccessor, *e.mTimeData, e.mTimeAccessor->mCount - 1, 0));
|
||||||
|
@ -1293,25 +1249,21 @@ void ColladaLoader::CreateAnimation(aiScene* pScene, const ColladaParser& pParse
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<aiMatrix4x4> resultTrafos;
|
std::vector<aiMatrix4x4> resultTrafos;
|
||||||
if (!entries.empty() && entries.front().mTimeAccessor->mCount > 0)
|
if (!entries.empty() && entries.front().mTimeAccessor->mCount > 0) {
|
||||||
{
|
|
||||||
// create a local transformation chain of the node's transforms
|
// create a local transformation chain of the node's transforms
|
||||||
std::vector<Collada::Transform> transforms = srcNode->mTransforms;
|
std::vector<Collada::Transform> transforms = srcNode->mTransforms;
|
||||||
|
|
||||||
// now for every unique point in time, find or interpolate the key values for that time
|
// now for every unique point in time, find or interpolate the key values for that time
|
||||||
// and apply them to the transform chain. Then the node's present transformation can be calculated.
|
// and apply them to the transform chain. Then the node's present transformation can be calculated.
|
||||||
ai_real time = startTime;
|
ai_real time = startTime;
|
||||||
while (1)
|
while (1) {
|
||||||
{
|
for (std::vector<Collada::ChannelEntry>::iterator it = entries.begin(); it != entries.end(); ++it) {
|
||||||
for (std::vector<Collada::ChannelEntry>::iterator it = entries.begin(); it != entries.end(); ++it)
|
|
||||||
{
|
|
||||||
Collada::ChannelEntry &e = *it;
|
Collada::ChannelEntry &e = *it;
|
||||||
|
|
||||||
// find the keyframe behind the current point in time
|
// find the keyframe behind the current point in time
|
||||||
size_t pos = 0;
|
size_t pos = 0;
|
||||||
ai_real postTime = 0.0;
|
ai_real postTime = 0.0;
|
||||||
while (1)
|
while (1) {
|
||||||
{
|
|
||||||
if (pos >= e.mTimeAccessor->mCount)
|
if (pos >= e.mTimeAccessor->mCount)
|
||||||
break;
|
break;
|
||||||
postTime = ReadFloat(*e.mTimeAccessor, *e.mTimeData, pos, 0);
|
postTime = ReadFloat(*e.mTimeAccessor, *e.mTimeData, pos, 0);
|
||||||
|
@ -1328,13 +1280,11 @@ void ColladaLoader::CreateAnimation(aiScene* pScene, const ColladaParser& pParse
|
||||||
temp[c] = ReadFloat(*e.mValueAccessor, *e.mValueData, pos, c);
|
temp[c] = ReadFloat(*e.mValueAccessor, *e.mValueData, pos, c);
|
||||||
|
|
||||||
// if not exactly at the key time, interpolate with previous value set
|
// if not exactly at the key time, interpolate with previous value set
|
||||||
if (postTime > time && pos > 0)
|
if (postTime > time && pos > 0) {
|
||||||
{
|
|
||||||
ai_real preTime = ReadFloat(*e.mTimeAccessor, *e.mTimeData, pos - 1, 0);
|
ai_real preTime = ReadFloat(*e.mTimeAccessor, *e.mTimeData, pos - 1, 0);
|
||||||
ai_real factor = (time - postTime) / (preTime - postTime);
|
ai_real factor = (time - postTime) / (preTime - postTime);
|
||||||
|
|
||||||
for (size_t c = 0; c < e.mValueAccessor->mSize; ++c)
|
for (size_t c = 0; c < e.mValueAccessor->mSize; ++c) {
|
||||||
{
|
|
||||||
ai_real v = ReadFloat(*e.mValueAccessor, *e.mValueData, pos - 1, c);
|
ai_real v = ReadFloat(*e.mValueAccessor, *e.mValueData, pos - 1, c);
|
||||||
temp[c] += (v - temp[c]) * factor;
|
temp[c] += (v - temp[c]) * factor;
|
||||||
}
|
}
|
||||||
|
@ -1353,17 +1303,14 @@ void ColladaLoader::CreateAnimation(aiScene* pScene, const ColladaParser& pParse
|
||||||
|
|
||||||
// find next point in time to evaluate. That's the closest frame larger than the current in any channel
|
// find next point in time to evaluate. That's the closest frame larger than the current in any channel
|
||||||
ai_real nextTime = ai_real(1e20);
|
ai_real nextTime = ai_real(1e20);
|
||||||
for (std::vector<Collada::ChannelEntry>::iterator it = entries.begin(); it != entries.end(); ++it)
|
for (std::vector<Collada::ChannelEntry>::iterator it = entries.begin(); it != entries.end(); ++it) {
|
||||||
{
|
|
||||||
Collada::ChannelEntry &channelElement = *it;
|
Collada::ChannelEntry &channelElement = *it;
|
||||||
|
|
||||||
// find the next time value larger than the current
|
// find the next time value larger than the current
|
||||||
size_t pos = 0;
|
size_t pos = 0;
|
||||||
while (pos < channelElement.mTimeAccessor->mCount)
|
while (pos < channelElement.mTimeAccessor->mCount) {
|
||||||
{
|
|
||||||
const ai_real t = ReadFloat(*channelElement.mTimeAccessor, *channelElement.mTimeData, pos, 0);
|
const ai_real t = ReadFloat(*channelElement.mTimeAccessor, *channelElement.mTimeData, pos, 0);
|
||||||
if (t > time)
|
if (t > time) {
|
||||||
{
|
|
||||||
nextTime = std::min(nextTime, t);
|
nextTime = std::min(nextTime, t);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -1403,8 +1350,7 @@ void ColladaLoader::CreateAnimation(aiScene* pScene, const ColladaParser& pParse
|
||||||
// ai_assert( resultTrafos.size() > 0);
|
// ai_assert( resultTrafos.size() > 0);
|
||||||
|
|
||||||
// build an animation channel for the given node out of these trafo keys
|
// build an animation channel for the given node out of these trafo keys
|
||||||
if (!resultTrafos.empty())
|
if (!resultTrafos.empty()) {
|
||||||
{
|
|
||||||
aiNodeAnim *dstAnim = new aiNodeAnim;
|
aiNodeAnim *dstAnim = new aiNodeAnim;
|
||||||
dstAnim->mNodeName = nodeName;
|
dstAnim->mNodeName = nodeName;
|
||||||
dstAnim->mNumPositionKeys = static_cast<unsigned int>(resultTrafos.size());
|
dstAnim->mNumPositionKeys = static_cast<unsigned int>(resultTrafos.size());
|
||||||
|
@ -1414,8 +1360,7 @@ void ColladaLoader::CreateAnimation(aiScene* pScene, const ColladaParser& pParse
|
||||||
dstAnim->mRotationKeys = new aiQuatKey[resultTrafos.size()];
|
dstAnim->mRotationKeys = new aiQuatKey[resultTrafos.size()];
|
||||||
dstAnim->mScalingKeys = new aiVectorKey[resultTrafos.size()];
|
dstAnim->mScalingKeys = new aiVectorKey[resultTrafos.size()];
|
||||||
|
|
||||||
for (size_t a = 0; a < resultTrafos.size(); ++a)
|
for (size_t a = 0; a < resultTrafos.size(); ++a) {
|
||||||
{
|
|
||||||
aiMatrix4x4 mat = resultTrafos[a];
|
aiMatrix4x4 mat = resultTrafos[a];
|
||||||
double time = double(mat.d4); // remember? time is stored in mat.d4
|
double time = double(mat.d4); // remember? time is stored in mat.d4
|
||||||
mat.d4 = 1.0f;
|
mat.d4 = 1.0f;
|
||||||
|
@ -1427,17 +1372,13 @@ void ColladaLoader::CreateAnimation(aiScene* pScene, const ColladaParser& pParse
|
||||||
}
|
}
|
||||||
|
|
||||||
anims.push_back(dstAnim);
|
anims.push_back(dstAnim);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
ASSIMP_LOG_WARN("Collada loader: found empty animation channel, ignored. Please check your exporter.");
|
ASSIMP_LOG_WARN("Collada loader: found empty animation channel, ignored. Please check your exporter.");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!entries.empty() && entries.front().mTimeAccessor->mCount > 0)
|
if (!entries.empty() && entries.front().mTimeAccessor->mCount > 0) {
|
||||||
{
|
|
||||||
std::vector<Collada::ChannelEntry> morphChannels;
|
std::vector<Collada::ChannelEntry> morphChannels;
|
||||||
for (std::vector<Collada::ChannelEntry>::iterator it = entries.begin(); it != entries.end(); ++it)
|
for (std::vector<Collada::ChannelEntry>::iterator it = entries.begin(); it != entries.end(); ++it) {
|
||||||
{
|
|
||||||
Collada::ChannelEntry &e = *it;
|
Collada::ChannelEntry &e = *it;
|
||||||
|
|
||||||
// skip non-transform types
|
// skip non-transform types
|
||||||
|
@ -1447,8 +1388,7 @@ void ColladaLoader::CreateAnimation(aiScene* pScene, const ColladaParser& pParse
|
||||||
if (e.mTargetId.find("morph-weights") != std::string::npos)
|
if (e.mTargetId.find("morph-weights") != std::string::npos)
|
||||||
morphChannels.push_back(e);
|
morphChannels.push_back(e);
|
||||||
}
|
}
|
||||||
if (morphChannels.size() > 0)
|
if (morphChannels.size() > 0) {
|
||||||
{
|
|
||||||
// either 1) morph weight animation count should contain morph target count channels
|
// either 1) morph weight animation count should contain morph target count channels
|
||||||
// or 2) one channel with morph target count arrays
|
// or 2) one channel with morph target count arrays
|
||||||
// assume first
|
// assume first
|
||||||
|
@ -1459,8 +1399,7 @@ void ColladaLoader::CreateAnimation(aiScene* pScene, const ColladaParser& pParse
|
||||||
std::vector<MorphTimeValues> morphTimeValues;
|
std::vector<MorphTimeValues> morphTimeValues;
|
||||||
|
|
||||||
int morphAnimChannelIndex = 0;
|
int morphAnimChannelIndex = 0;
|
||||||
for (std::vector<Collada::ChannelEntry>::iterator it = morphChannels.begin(); it != morphChannels.end(); ++it)
|
for (std::vector<Collada::ChannelEntry>::iterator it = morphChannels.begin(); it != morphChannels.end(); ++it) {
|
||||||
{
|
|
||||||
Collada::ChannelEntry &e = *it;
|
Collada::ChannelEntry &e = *it;
|
||||||
std::string::size_type apos = e.mTargetId.find('(');
|
std::string::size_type apos = e.mTargetId.find('(');
|
||||||
std::string::size_type bpos = e.mTargetId.find(')');
|
std::string::size_type bpos = e.mTargetId.find(')');
|
||||||
|
@ -1478,15 +1417,13 @@ void ColladaLoader::CreateAnimation(aiScene* pScene, const ColladaParser& pParse
|
||||||
|
|
||||||
morphAnim->mNumKeys = static_cast<unsigned int>(morphTimeValues.size());
|
morphAnim->mNumKeys = static_cast<unsigned int>(morphTimeValues.size());
|
||||||
morphAnim->mKeys = new aiMeshMorphKey[morphAnim->mNumKeys];
|
morphAnim->mKeys = new aiMeshMorphKey[morphAnim->mNumKeys];
|
||||||
for (unsigned int key = 0; key < morphAnim->mNumKeys; key++)
|
for (unsigned int key = 0; key < morphAnim->mNumKeys; key++) {
|
||||||
{
|
|
||||||
morphAnim->mKeys[key].mNumValuesAndWeights = static_cast<unsigned int>(morphChannels.size());
|
morphAnim->mKeys[key].mNumValuesAndWeights = static_cast<unsigned int>(morphChannels.size());
|
||||||
morphAnim->mKeys[key].mValues = new unsigned int[morphChannels.size()];
|
morphAnim->mKeys[key].mValues = new unsigned int[morphChannels.size()];
|
||||||
morphAnim->mKeys[key].mWeights = new double[morphChannels.size()];
|
morphAnim->mKeys[key].mWeights = new double[morphChannels.size()];
|
||||||
|
|
||||||
morphAnim->mKeys[key].mTime = morphTimeValues[key].mTime;
|
morphAnim->mKeys[key].mTime = morphTimeValues[key].mTime;
|
||||||
for (unsigned int valueIndex = 0; valueIndex < morphChannels.size(); valueIndex++)
|
for (unsigned int valueIndex = 0; valueIndex < morphChannels.size(); valueIndex++) {
|
||||||
{
|
|
||||||
morphAnim->mKeys[key].mValues[valueIndex] = valueIndex;
|
morphAnim->mKeys[key].mValues[valueIndex] = valueIndex;
|
||||||
morphAnim->mKeys[key].mWeights[valueIndex] = getWeightAtKey(morphTimeValues, key, valueIndex);
|
morphAnim->mKeys[key].mWeights[valueIndex] = getWeightAtKey(morphTimeValues, key, valueIndex);
|
||||||
}
|
}
|
||||||
|
@ -1497,31 +1434,26 @@ void ColladaLoader::CreateAnimation(aiScene* pScene, const ColladaParser& pParse
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!anims.empty() || !morphAnims.empty())
|
if (!anims.empty() || !morphAnims.empty()) {
|
||||||
{
|
|
||||||
aiAnimation *anim = new aiAnimation;
|
aiAnimation *anim = new aiAnimation;
|
||||||
anim->mName.Set(pName);
|
anim->mName.Set(pName);
|
||||||
anim->mNumChannels = static_cast<unsigned int>(anims.size());
|
anim->mNumChannels = static_cast<unsigned int>(anims.size());
|
||||||
if (anim->mNumChannels > 0)
|
if (anim->mNumChannels > 0) {
|
||||||
{
|
|
||||||
anim->mChannels = new aiNodeAnim *[anims.size()];
|
anim->mChannels = new aiNodeAnim *[anims.size()];
|
||||||
std::copy(anims.begin(), anims.end(), anim->mChannels);
|
std::copy(anims.begin(), anims.end(), anim->mChannels);
|
||||||
}
|
}
|
||||||
anim->mNumMorphMeshChannels = static_cast<unsigned int>(morphAnims.size());
|
anim->mNumMorphMeshChannels = static_cast<unsigned int>(morphAnims.size());
|
||||||
if (anim->mNumMorphMeshChannels > 0)
|
if (anim->mNumMorphMeshChannels > 0) {
|
||||||
{
|
|
||||||
anim->mMorphMeshChannels = new aiMeshMorphAnim *[anim->mNumMorphMeshChannels];
|
anim->mMorphMeshChannels = new aiMeshMorphAnim *[anim->mNumMorphMeshChannels];
|
||||||
std::copy(morphAnims.begin(), morphAnims.end(), anim->mMorphMeshChannels);
|
std::copy(morphAnims.begin(), morphAnims.end(), anim->mMorphMeshChannels);
|
||||||
}
|
}
|
||||||
anim->mDuration = 0.0f;
|
anim->mDuration = 0.0f;
|
||||||
for (size_t a = 0; a < anims.size(); ++a)
|
for (size_t a = 0; a < anims.size(); ++a) {
|
||||||
{
|
|
||||||
anim->mDuration = std::max(anim->mDuration, anims[a]->mPositionKeys[anims[a]->mNumPositionKeys - 1].mTime);
|
anim->mDuration = std::max(anim->mDuration, anims[a]->mPositionKeys[anims[a]->mNumPositionKeys - 1].mTime);
|
||||||
anim->mDuration = std::max(anim->mDuration, anims[a]->mRotationKeys[anims[a]->mNumRotationKeys - 1].mTime);
|
anim->mDuration = std::max(anim->mDuration, anims[a]->mRotationKeys[anims[a]->mNumRotationKeys - 1].mTime);
|
||||||
anim->mDuration = std::max(anim->mDuration, anims[a]->mScalingKeys[anims[a]->mNumScalingKeys - 1].mTime);
|
anim->mDuration = std::max(anim->mDuration, anims[a]->mScalingKeys[anims[a]->mNumScalingKeys - 1].mTime);
|
||||||
}
|
}
|
||||||
for (size_t a = 0; a < morphAnims.size(); ++a)
|
for (size_t a = 0; a < morphAnims.size(); ++a) {
|
||||||
{
|
|
||||||
anim->mDuration = std::max(anim->mDuration, morphAnims[a]->mKeys[morphAnims[a]->mNumKeys - 1].mTime);
|
anim->mDuration = std::max(anim->mDuration, morphAnims[a]->mKeys[morphAnims[a]->mNumKeys - 1].mTime);
|
||||||
}
|
}
|
||||||
anim->mTicksPerSecond = 1;
|
anim->mTicksPerSecond = 1;
|
||||||
|
@ -1534,8 +1466,7 @@ void ColladaLoader::CreateAnimation(aiScene* pScene, const ColladaParser& pParse
|
||||||
void ColladaLoader::AddTexture(aiMaterial &mat, const ColladaParser &pParser,
|
void ColladaLoader::AddTexture(aiMaterial &mat, const ColladaParser &pParser,
|
||||||
const Collada::Effect &effect,
|
const Collada::Effect &effect,
|
||||||
const Collada::Sampler &sampler,
|
const Collada::Sampler &sampler,
|
||||||
aiTextureType type, unsigned int idx)
|
aiTextureType type, unsigned int idx) {
|
||||||
{
|
|
||||||
// first of all, basic file name
|
// first of all, basic file name
|
||||||
const aiString name = FindFilenameForEffectTexture(pParser, effect, sampler.mName);
|
const aiString name = FindFilenameForEffectTexture(pParser, effect, sampler.mName);
|
||||||
mat.AddProperty(&name, _AI_MATKEY_TEXTURE_BASE, type, idx);
|
mat.AddProperty(&name, _AI_MATKEY_TEXTURE_BASE, type, idx);
|
||||||
|
@ -1594,10 +1525,8 @@ void ColladaLoader::AddTexture(aiMaterial& mat, const ColladaParser& pParser,
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
// Fills materials from the collada material definitions
|
// Fills materials from the collada material definitions
|
||||||
void ColladaLoader::FillMaterials(const ColladaParser& pParser, aiScene* /*pScene*/)
|
void ColladaLoader::FillMaterials(const ColladaParser &pParser, aiScene * /*pScene*/) {
|
||||||
{
|
for (auto &elem : newMats) {
|
||||||
for (auto &elem : newMats)
|
|
||||||
{
|
|
||||||
aiMaterial &mat = (aiMaterial &)*elem.second;
|
aiMaterial &mat = (aiMaterial &)*elem.second;
|
||||||
Collada::Effect &effect = *elem.first;
|
Collada::Effect &effect = *elem.first;
|
||||||
|
|
||||||
|
@ -1606,8 +1535,7 @@ void ColladaLoader::FillMaterials(const ColladaParser& pParser, aiScene* /*pScen
|
||||||
if (effect.mFaceted) /* fixme */
|
if (effect.mFaceted) /* fixme */
|
||||||
shadeMode = aiShadingMode_Flat;
|
shadeMode = aiShadingMode_Flat;
|
||||||
else {
|
else {
|
||||||
switch (effect.mShadeType)
|
switch (effect.mShadeType) {
|
||||||
{
|
|
||||||
case Collada::Shade_Constant:
|
case Collada::Shade_Constant:
|
||||||
shadeMode = aiShadingMode_NoShading;
|
shadeMode = aiShadingMode_NoShading;
|
||||||
break;
|
break;
|
||||||
|
@ -1657,17 +1585,14 @@ void ColladaLoader::FillMaterials(const ColladaParser& pParser, aiScene* /*pScen
|
||||||
// handle RGB transparency completely, cf Collada specs 1.5.0 pages 249 and 304
|
// handle RGB transparency completely, cf Collada specs 1.5.0 pages 249 and 304
|
||||||
if (effect.mRGBTransparency) {
|
if (effect.mRGBTransparency) {
|
||||||
// use luminance as defined by ISO/CIE color standards (see ITU-R Recommendation BT.709-4)
|
// use luminance as defined by ISO/CIE color standards (see ITU-R Recommendation BT.709-4)
|
||||||
effect.mTransparency *= (
|
effect.mTransparency *= (0.212671f * effect.mTransparent.r +
|
||||||
0.212671f * effect.mTransparent.r +
|
|
||||||
0.715160f * effect.mTransparent.g +
|
0.715160f * effect.mTransparent.g +
|
||||||
0.072169f * effect.mTransparent.b
|
0.072169f * effect.mTransparent.b);
|
||||||
);
|
|
||||||
|
|
||||||
effect.mTransparent.a = 1.f;
|
effect.mTransparent.a = 1.f;
|
||||||
|
|
||||||
mat.AddProperty(&effect.mTransparent, 1, AI_MATKEY_COLOR_TRANSPARENT);
|
mat.AddProperty(&effect.mTransparent, 1, AI_MATKEY_COLOR_TRANSPARENT);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
effect.mTransparency *= effect.mTransparent.a;
|
effect.mTransparency *= effect.mTransparent.a;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1709,8 +1634,7 @@ void ColladaLoader::FillMaterials(const ColladaParser& pParser, aiScene* /*pScen
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
// Constructs materials from the collada material definitions
|
// Constructs materials from the collada material definitions
|
||||||
void ColladaLoader::BuildMaterials(ColladaParser& pParser, aiScene* /*pScene*/)
|
void ColladaLoader::BuildMaterials(ColladaParser &pParser, aiScene * /*pScene*/) {
|
||||||
{
|
|
||||||
newMats.reserve(pParser.mMaterialLibrary.size());
|
newMats.reserve(pParser.mMaterialLibrary.size());
|
||||||
|
|
||||||
for (ColladaParser::MaterialLibrary::const_iterator matIt = pParser.mMaterialLibrary.begin();
|
for (ColladaParser::MaterialLibrary::const_iterator matIt = pParser.mMaterialLibrary.begin();
|
||||||
|
@ -1757,14 +1681,12 @@ void ColladaLoader::BuildMaterials(ColladaParser& pParser, aiScene* /*pScene*/)
|
||||||
// Resolves the texture name for the given effect texture entry
|
// Resolves the texture name for the given effect texture entry
|
||||||
// and loads the texture data
|
// and loads the texture data
|
||||||
aiString ColladaLoader::FindFilenameForEffectTexture(const ColladaParser &pParser,
|
aiString ColladaLoader::FindFilenameForEffectTexture(const ColladaParser &pParser,
|
||||||
const Collada::Effect& pEffect, const std::string& pName)
|
const Collada::Effect &pEffect, const std::string &pName) {
|
||||||
{
|
|
||||||
aiString result;
|
aiString result;
|
||||||
|
|
||||||
// recurse through the param references until we end up at an image
|
// recurse through the param references until we end up at an image
|
||||||
std::string name = pName;
|
std::string name = pName;
|
||||||
while (1)
|
while (1) {
|
||||||
{
|
|
||||||
// the given string is a param entry. Find it
|
// the given string is a param entry. Find it
|
||||||
Collada::Effect::ParamLibrary::const_iterator it = pEffect.mParams.find(name);
|
Collada::Effect::ParamLibrary::const_iterator it = pEffect.mParams.find(name);
|
||||||
// if not found, we're at the end of the recursion. The resulting string should be the image ID
|
// if not found, we're at the end of the recursion. The resulting string should be the image ID
|
||||||
|
@ -1777,8 +1699,7 @@ aiString ColladaLoader::FindFilenameForEffectTexture(const ColladaParser& pParse
|
||||||
|
|
||||||
// find the image referred by this name in the image library of the scene
|
// find the image referred by this name in the image library of the scene
|
||||||
ColladaParser::ImageLibrary::const_iterator imIt = pParser.mImageLibrary.find(name);
|
ColladaParser::ImageLibrary::const_iterator imIt = pParser.mImageLibrary.find(name);
|
||||||
if (imIt == pParser.mImageLibrary.end())
|
if (imIt == pParser.mImageLibrary.end()) {
|
||||||
{
|
|
||||||
ASSIMP_LOG_WARN_F("Collada: Unable to resolve effect texture entry \"", pName, "\", ended up at ID \"", name, "\".");
|
ASSIMP_LOG_WARN_F("Collada: Unable to resolve effect texture entry \"", pName, "\", ended up at ID \"", name, "\".");
|
||||||
|
|
||||||
//set default texture file name
|
//set default texture file name
|
||||||
|
@ -1788,8 +1709,7 @@ aiString ColladaLoader::FindFilenameForEffectTexture(const ColladaParser& pParse
|
||||||
}
|
}
|
||||||
|
|
||||||
// if this is an embedded texture image setup an aiTexture for it
|
// if this is an embedded texture image setup an aiTexture for it
|
||||||
if (!imIt->second.mImageData.empty())
|
if (!imIt->second.mImageData.empty()) {
|
||||||
{
|
|
||||||
aiTexture *tex = new aiTexture();
|
aiTexture *tex = new aiTexture();
|
||||||
|
|
||||||
// Store embedded texture name reference
|
// Store embedded texture name reference
|
||||||
|
@ -1800,7 +1720,6 @@ aiString ColladaLoader::FindFilenameForEffectTexture(const ColladaParser& pParse
|
||||||
// result.data[0] = '*';
|
// result.data[0] = '*';
|
||||||
// result.length = 1 + ASSIMP_itoa10(result.data + 1, static_cast<unsigned int>(MAXLEN - 1), static_cast<int32_t>(mTextures.size()));
|
// result.length = 1 + ASSIMP_itoa10(result.data + 1, static_cast<unsigned int>(MAXLEN - 1), static_cast<int32_t>(mTextures.size()));
|
||||||
|
|
||||||
|
|
||||||
// setup format hint
|
// setup format hint
|
||||||
if (imIt->second.mEmbeddedFormat.length() >= HINTMAXTEXTURELEN) {
|
if (imIt->second.mEmbeddedFormat.length() >= HINTMAXTEXTURELEN) {
|
||||||
ASSIMP_LOG_WARN("Collada: texture format hint is too long, truncating to 3 characters");
|
ASSIMP_LOG_WARN("Collada: texture format hint is too long, truncating to 3 characters");
|
||||||
|
@ -1815,9 +1734,7 @@ aiString ColladaLoader::FindFilenameForEffectTexture(const ColladaParser& pParse
|
||||||
|
|
||||||
// and add this texture to the list
|
// and add this texture to the list
|
||||||
mTextures.push_back(tex);
|
mTextures.push_back(tex);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
if (imIt->second.mFileName.empty()) {
|
if (imIt->second.mFileName.empty()) {
|
||||||
throw DeadlyImportError("Collada: Invalid texture, no data or file reference given");
|
throw DeadlyImportError("Collada: Invalid texture, no data or file reference given");
|
||||||
}
|
}
|
||||||
|
@ -1829,8 +1746,7 @@ aiString ColladaLoader::FindFilenameForEffectTexture(const ColladaParser& pParse
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
// Reads a float value from an accessor and its data array.
|
// 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
|
ai_real ColladaLoader::ReadFloat(const Collada::Accessor &pAccessor, const Collada::Data &pData, size_t pIndex, size_t pOffset) const {
|
||||||
{
|
|
||||||
// FIXME: (thom) Test for data type here in every access? For the moment, I leave this to the caller
|
// FIXME: (thom) Test for data type here in every access? For the moment, I leave this to the caller
|
||||||
size_t pos = pAccessor.mStride * pIndex + pAccessor.mOffset + pOffset;
|
size_t pos = pAccessor.mStride * pIndex + pAccessor.mOffset + pOffset;
|
||||||
ai_assert(pos < pData.mValues.size());
|
ai_assert(pos < pData.mValues.size());
|
||||||
|
@ -1839,8 +1755,7 @@ ai_real ColladaLoader::ReadFloat(const Collada::Accessor& pAccessor, const Colla
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
// Reads a string value from an accessor and its data array.
|
// Reads a string value from an accessor and its data array.
|
||||||
const std::string& ColladaLoader::ReadString(const Collada::Accessor& pAccessor, const Collada::Data& pData, size_t pIndex) const
|
const std::string &ColladaLoader::ReadString(const Collada::Accessor &pAccessor, const Collada::Data &pData, size_t pIndex) const {
|
||||||
{
|
|
||||||
size_t pos = pAccessor.mStride * pIndex + pAccessor.mOffset;
|
size_t pos = pAccessor.mStride * pIndex + pAccessor.mOffset;
|
||||||
ai_assert(pos < pData.mStrings.size());
|
ai_assert(pos < pData.mStrings.size());
|
||||||
return pData.mStrings[pos];
|
return pData.mStrings[pos];
|
||||||
|
@ -1848,8 +1763,7 @@ const std::string& ColladaLoader::ReadString(const Collada::Accessor& pAccessor,
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
// Collects all nodes into the given array
|
// Collects all nodes into the given array
|
||||||
void ColladaLoader::CollectNodes(const aiNode* pNode, std::vector<const aiNode*>& poNodes) const
|
void ColladaLoader::CollectNodes(const aiNode *pNode, std::vector<const aiNode *> &poNodes) const {
|
||||||
{
|
|
||||||
poNodes.push_back(pNode);
|
poNodes.push_back(pNode);
|
||||||
for (size_t a = 0; a < pNode->mNumChildren; ++a) {
|
for (size_t a = 0; a < pNode->mNumChildren; ++a) {
|
||||||
CollectNodes(pNode->mChildren[a], poNodes);
|
CollectNodes(pNode->mChildren[a], poNodes);
|
||||||
|
@ -1858,13 +1772,11 @@ void ColladaLoader::CollectNodes(const aiNode* pNode, std::vector<const aiNode*>
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
// Finds a node in the collada scene by the given name
|
// Finds a node in the collada scene by the given name
|
||||||
const Collada::Node* ColladaLoader::FindNode(const Collada::Node* pNode, const std::string& pName) const
|
const Collada::Node *ColladaLoader::FindNode(const Collada::Node *pNode, const std::string &pName) const {
|
||||||
{
|
|
||||||
if (pNode->mName == pName || pNode->mID == pName)
|
if (pNode->mName == pName || pNode->mID == pName)
|
||||||
return pNode;
|
return pNode;
|
||||||
|
|
||||||
for (size_t a = 0; a < pNode->mChildren.size(); ++a)
|
for (size_t a = 0; a < pNode->mChildren.size(); ++a) {
|
||||||
{
|
|
||||||
const Collada::Node *node = FindNode(pNode->mChildren[a], pName);
|
const Collada::Node *node = FindNode(pNode->mChildren[a], pName);
|
||||||
if (node)
|
if (node)
|
||||||
return node;
|
return node;
|
||||||
|
@ -1897,28 +1809,22 @@ const Collada::Node* ColladaLoader::FindNodeBySID( const Collada::Node* pNode, c
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
// Finds a proper unique name for a node derived from the collada-node's properties.
|
// Finds a proper unique name for a node derived from the collada-node's properties.
|
||||||
// The name must be unique for proper node-bone association.
|
// The name must be unique for proper node-bone association.
|
||||||
std::string ColladaLoader::FindNameForNode(const Collada::Node* pNode)
|
std::string ColladaLoader::FindNameForNode(const Collada::Node *pNode) {
|
||||||
{
|
|
||||||
// If explicitly requested, just use the collada name.
|
// If explicitly requested, just use the collada name.
|
||||||
if (useColladaName)
|
if (useColladaName) {
|
||||||
{
|
|
||||||
if (!pNode->mName.empty()) {
|
if (!pNode->mName.empty()) {
|
||||||
return pNode->mName;
|
return pNode->mName;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
return format() << "$ColladaAutoName$_" << mNodeNameCounter++;
|
return format() << "$ColladaAutoName$_" << mNodeNameCounter++;
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
// Now setup the name of the assimp node. The collada name might not be
|
// Now setup the name of the assimp node. The collada name might not be
|
||||||
// unique, so we use the collada ID.
|
// unique, so we use the collada ID.
|
||||||
if (!pNode->mID.empty())
|
if (!pNode->mID.empty())
|
||||||
return pNode->mID;
|
return pNode->mID;
|
||||||
else if (!pNode->mSID.empty())
|
else if (!pNode->mSID.empty())
|
||||||
return pNode->mSID;
|
return pNode->mSID;
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
// No need to worry. Unnamed nodes are no problem at all, except
|
// No need to worry. Unnamed nodes are no problem at all, except
|
||||||
// if cameras or lights need to be assigned to them.
|
// if cameras or lights need to be assigned to them.
|
||||||
return format() << "$ColladaAutoName$_" << mNodeNameCounter++;
|
return format() << "$ColladaAutoName$_" << mNodeNameCounter++;
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -47,13 +47,12 @@
|
||||||
#ifndef AI_COLLADAPARSER_H_INC
|
#ifndef AI_COLLADAPARSER_H_INC
|
||||||
#define AI_COLLADAPARSER_H_INC
|
#define AI_COLLADAPARSER_H_INC
|
||||||
|
|
||||||
#include <assimp/irrXMLWrapper.h>
|
|
||||||
#include "ColladaHelper.h"
|
#include "ColladaHelper.h"
|
||||||
#include <assimp/ai_assert.h>
|
|
||||||
#include <assimp/TinyFormatter.h>
|
#include <assimp/TinyFormatter.h>
|
||||||
|
#include <assimp/ai_assert.h>
|
||||||
|
#include <assimp/irrXMLWrapper.h>
|
||||||
|
|
||||||
namespace Assimp
|
namespace Assimp {
|
||||||
{
|
|
||||||
class ZipArchiveIOSystem;
|
class ZipArchiveIOSystem;
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------
|
||||||
|
@ -62,8 +61,7 @@ namespace Assimp
|
||||||
* Does all the XML reading and builds internal data structures from it,
|
* Does all the XML reading and builds internal data structures from it,
|
||||||
* but leaves the resolving of all the references to the loader.
|
* but leaves the resolving of all the references to the loader.
|
||||||
*/
|
*/
|
||||||
class ColladaParser
|
class ColladaParser {
|
||||||
{
|
|
||||||
friend class ColladaLoader;
|
friend class ColladaLoader;
|
||||||
|
|
||||||
/** Converts a path read from a collada file to the usual representation */
|
/** Converts a path read from a collada file to the usual representation */
|
||||||
|
@ -291,7 +289,8 @@ namespace Assimp
|
||||||
Collada::InputType GetTypeForSemantic(const std::string &pSemantic);
|
Collada::InputType GetTypeForSemantic(const std::string &pSemantic);
|
||||||
|
|
||||||
/** Finds the item in the given library by its reference, throws if not found */
|
/** Finds the item in the given library by its reference, throws if not found */
|
||||||
template <typename Type> const Type& ResolveLibraryReference( const std::map<std::string, Type>& pLibrary, const std::string& pURL) const;
|
template <typename Type>
|
||||||
|
const Type &ResolveLibraryReference(const std::map<std::string, Type> &pLibrary, const std::string &pURL) const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/** Filename, for a verbose error message */
|
/** Filename, for a verbose error message */
|
||||||
|
@ -360,7 +359,9 @@ namespace Assimp
|
||||||
ai_real mUnitSize;
|
ai_real mUnitSize;
|
||||||
|
|
||||||
/** Which is the up vector */
|
/** Which is the up vector */
|
||||||
enum { UP_X, UP_Y, UP_Z } mUpDirection;
|
enum { UP_X,
|
||||||
|
UP_Y,
|
||||||
|
UP_Z } mUpDirection;
|
||||||
|
|
||||||
/** Asset metadata (global for scene) */
|
/** Asset metadata (global for scene) */
|
||||||
StringMetaData mAssetMetaData;
|
StringMetaData mAssetMetaData;
|
||||||
|
@ -371,8 +372,7 @@ namespace Assimp
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
// Check for element match
|
// Check for element match
|
||||||
inline bool ColladaParser::IsElement( const char* pName) const
|
inline bool ColladaParser::IsElement(const char *pName) const {
|
||||||
{
|
|
||||||
ai_assert(mReader->getNodeType() == irr::io::EXN_ELEMENT);
|
ai_assert(mReader->getNodeType() == irr::io::EXN_ELEMENT);
|
||||||
return ::strcmp(mReader->getNodeName(), pName) == 0;
|
return ::strcmp(mReader->getNodeName(), pName) == 0;
|
||||||
}
|
}
|
||||||
|
@ -380,8 +380,7 @@ namespace Assimp
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
// Finds the item in the given library by its reference, throws if not found
|
// Finds the item in the given library by its reference, throws if not found
|
||||||
template <typename Type>
|
template <typename Type>
|
||||||
const Type& ColladaParser::ResolveLibraryReference( const std::map<std::string, Type>& pLibrary, const std::string& pURL) const
|
const Type &ColladaParser::ResolveLibraryReference(const std::map<std::string, Type> &pLibrary, const std::string &pURL) const {
|
||||||
{
|
|
||||||
typename std::map<std::string, Type>::const_iterator it = pLibrary.find(pURL);
|
typename std::map<std::string, Type>::const_iterator it = pLibrary.find(pURL);
|
||||||
if (it == pLibrary.end())
|
if (it == pLibrary.end())
|
||||||
ThrowException(Formatter::format() << "Unable to resolve library reference \"" << pURL << "\".");
|
ThrowException(Formatter::format() << "Unable to resolve library reference \"" << pURL << "\".");
|
||||||
|
|
Loading…
Reference in New Issue