From 8fba4ce7cf316fc85dcfbea0ad4f53c070e97295 Mon Sep 17 00:00:00 2001 From: Gareth Morgan Date: Wed, 8 Aug 2018 15:22:10 -0700 Subject: [PATCH 1/9] Support out of order channels --- code/BVHLoader.cpp | 70 ++++++++++++++++++++++++++++------------------ 1 file changed, 43 insertions(+), 27 deletions(-) diff --git a/code/BVHLoader.cpp b/code/BVHLoader.cpp index 0b2a818ae..8fa2a6f7f 100644 --- a/code/BVHLoader.cpp +++ b/code/BVHLoader.cpp @@ -54,6 +54,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include #include +#include using namespace Assimp; using namespace Assimp::Formatter; @@ -461,6 +462,13 @@ void BVHLoader::CreateAnimation( aiScene* pScene) aiNodeAnim* nodeAnim = new aiNodeAnim; anim->mChannels[a] = nodeAnim; nodeAnim->mNodeName.Set( nodeName); + std::map channelMap; + + //Build map of channels + for (unsigned int channel = 0; channel < node.mChannels.size(); ++channel) + { + channelMap[node.mChannels[channel]] = channel; + } // translational part, if given if( node.mChannels.size() == 6) @@ -472,16 +480,24 @@ void BVHLoader::CreateAnimation( aiScene* pScene) { poskey->mTime = double( fr); - // Now compute all translations in the right order - for( unsigned int channel = 0; channel < 3; ++channel) + // Now compute all translations + for(BVHLoader::ChannelType channel = Channel_PositionX; channel <= Channel_PositionZ; channel = (BVHLoader::ChannelType)(channel +1)) { - switch( node.mChannels[channel]) - { - case Channel_PositionX: poskey->mValue.x = node.mChannelValues[fr * node.mChannels.size() + channel]; break; - case Channel_PositionY: poskey->mValue.y = node.mChannelValues[fr * node.mChannels.size() + channel]; break; - case Channel_PositionZ: poskey->mValue.z = node.mChannelValues[fr * node.mChannels.size() + channel]; break; - default: throw DeadlyImportError( "Unexpected animation channel setup at node " + nodeName ); - } + //Find channel in node + std::map::iterator mapIter = channelMap.find(channel); + + if (mapIter == channelMap.end()) + throw DeadlyImportError("Missing position channel in node " + nodeName); + else { + int channelIdx = mapIter->second; + switch (channel) + { + case Channel_PositionX: poskey->mValue.x = node.mChannelValues[fr * node.mChannels.size() + channelIdx]; break; + case Channel_PositionY: poskey->mValue.y = node.mChannelValues[fr * node.mChannels.size() + channelIdx]; break; + case Channel_PositionZ: poskey->mValue.z = node.mChannelValues[fr * node.mChannels.size() + channelIdx]; break; + } + + } } ++poskey; } @@ -497,12 +513,6 @@ void BVHLoader::CreateAnimation( aiScene* pScene) // rotation part. Always present. First find value offsets { - unsigned int rotOffset = 0; - if( node.mChannels.size() == 6) - { - // Offset all further calculations - rotOffset = 3; - } // Then create the number of rotation keys nodeAnim->mNumRotationKeys = mAnimNumFrames; @@ -512,20 +522,26 @@ void BVHLoader::CreateAnimation( aiScene* pScene) { aiMatrix4x4 temp; aiMatrix3x3 rotMatrix; + for (BVHLoader::ChannelType channel = Channel_RotationX; channel <= Channel_RotationZ; channel = (BVHLoader::ChannelType)(channel + 1)) + { + //Find channel in node + std::map::iterator mapIter = channelMap.find(channel); - for( unsigned int channel = 0; channel < 3; ++channel) - { - // translate ZXY euler angels into a quaternion - const float angle = node.mChannelValues[fr * node.mChannels.size() + rotOffset + channel] * float( AI_MATH_PI) / 180.0f; + if (mapIter == channelMap.end()) + throw DeadlyImportError("Missing rotation channel in node " + nodeName); + else { + int channelIdx = mapIter->second; + // translate ZXY euler angels into a quaternion + const float angle = node.mChannelValues[fr * node.mChannels.size() + channelIdx] * float(AI_MATH_PI) / 180.0f; - // Compute rotation transformations in the right order - switch (node.mChannels[rotOffset+channel]) - { - case Channel_RotationX: aiMatrix4x4::RotationX( angle, temp); rotMatrix *= aiMatrix3x3( temp); break; - case Channel_RotationY: aiMatrix4x4::RotationY( angle, temp); rotMatrix *= aiMatrix3x3( temp); break; - case Channel_RotationZ: aiMatrix4x4::RotationZ( angle, temp); rotMatrix *= aiMatrix3x3( temp); break; - default: throw DeadlyImportError( "Unexpected animation channel setup at node " + nodeName ); - } + // Compute rotation transformations in the right order + switch (channel) + { + case Channel_RotationX: aiMatrix4x4::RotationX(angle, temp); rotMatrix *= aiMatrix3x3(temp); break; + case Channel_RotationY: aiMatrix4x4::RotationY(angle, temp); rotMatrix *= aiMatrix3x3(temp); break; + case Channel_RotationZ: aiMatrix4x4::RotationZ(angle, temp); rotMatrix *= aiMatrix3x3(temp); break; + } + } } rotkey->mTime = double( fr); From 43be7abb70bef4e4e5cf09a5b397f21fca6d1c56 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Thu, 9 Aug 2018 20:48:25 +0200 Subject: [PATCH 2/9] closes https://github.com/assimp/assimp/issues/2088: fix possible out-of-bound access in fbx-lerp operaation. --- code/FBXConverter.cpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/code/FBXConverter.cpp b/code/FBXConverter.cpp index c4b6c815f..701bd0562 100644 --- a/code/FBXConverter.cpp +++ b/code/FBXConverter.cpp @@ -2806,16 +2806,14 @@ KeyTimeList Converter::GetKeyTimeList( const KeyFrameListList& inputs ) } void Converter::InterpolateKeys( aiVectorKey* valOut, const KeyTimeList& keys, const KeyFrameListList& inputs, - const aiVector3D& def_value, - double& max_time, - double& min_time ) - -{ - ai_assert( keys.size() ); - ai_assert( valOut ); + const aiVector3D& def_value, + double& max_time, + double& min_time ) { + ai_assert( !keys.empty() ); + ai_assert( nullptr != valOut ); std::vector next_pos; - const size_t count = inputs.size(); + const size_t count( inputs.size() ); next_pos.resize( inputs.size(), 0 ); @@ -2826,6 +2824,9 @@ void Converter::InterpolateKeys( aiVectorKey* valOut, const KeyTimeList& keys, c const KeyFrameList& kfl = inputs[ i ]; const size_t ksize = std::get<0>(kfl)->size(); + if (ksize == 0) { + continue; + } if ( ksize > next_pos[ i ] && std::get<0>(kfl)->at( next_pos[ i ] ) == time ) { ++next_pos[ i ]; } From c3d043e7613215014479331651b8c854d57ca89c Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Thu, 9 Aug 2018 21:51:53 +0200 Subject: [PATCH 3/9] FBX: some refactorings. --- code/FBXConverter.cpp | 124 +++++++++++++++++++++--------------------- code/FBXConverter.h | 6 +- include/assimp/anim.h | 41 +++++++------- 3 files changed, 86 insertions(+), 85 deletions(-) diff --git a/code/FBXConverter.cpp b/code/FBXConverter.cpp index 701bd0562..45ef37ba0 100644 --- a/code/FBXConverter.cpp +++ b/code/FBXConverter.cpp @@ -73,7 +73,7 @@ using namespace Util; #define CONVERT_FBX_TIME(time) static_cast(time) / 46186158000L -Converter::Converter( aiScene* out, const Document& doc ) +FBXConverter::FBXConverter( aiScene* out, const Document& doc ) : defaultMaterialIndex() , out( out ) , doc( doc ) { @@ -114,7 +114,7 @@ Converter::Converter( aiScene* out, const Document& doc ) } -Converter::~Converter() { +FBXConverter::~FBXConverter() { std::for_each( meshes.begin(), meshes.end(), Util::delete_fun() ); std::for_each( materials.begin(), materials.end(), Util::delete_fun() ); std::for_each( animations.begin(), animations.end(), Util::delete_fun() ); @@ -123,7 +123,7 @@ Converter::~Converter() { std::for_each( textures.begin(), textures.end(), Util::delete_fun() ); } -void Converter::ConvertRootNode() { +void FBXConverter::ConvertRootNode() { out->mRootNode = new aiNode(); out->mRootNode->mName.Set( "RootNode" ); @@ -131,7 +131,7 @@ void Converter::ConvertRootNode() { ConvertNodes( 0L, *out->mRootNode ); } -void Converter::ConvertNodes( uint64_t id, aiNode& parent, const aiMatrix4x4& parent_transform ) { +void FBXConverter::ConvertNodes( uint64_t id, aiNode& parent, const aiMatrix4x4& parent_transform ) { const std::vector& conns = doc.GetConnectionsByDestinationSequenced( id, "Model" ); std::vector nodes; @@ -282,7 +282,7 @@ void Converter::ConvertNodes( uint64_t id, aiNode& parent, const aiMatrix4x4& pa } -void Converter::ConvertLights( const Model& model, const std::string &orig_name ) { +void FBXConverter::ConvertLights( const Model& model, const std::string &orig_name ) { const std::vector& node_attrs = model.GetAttributes(); for( const NodeAttribute* attr : node_attrs ) { const Light* const light = dynamic_cast( attr ); @@ -292,7 +292,7 @@ void Converter::ConvertLights( const Model& model, const std::string &orig_name } } -void Converter::ConvertCameras( const Model& model, const std::string &orig_name ) { +void FBXConverter::ConvertCameras( const Model& model, const std::string &orig_name ) { const std::vector& node_attrs = model.GetAttributes(); for( const NodeAttribute* attr : node_attrs ) { const Camera* const cam = dynamic_cast( attr ); @@ -302,7 +302,7 @@ void Converter::ConvertCameras( const Model& model, const std::string &orig_name } } -void Converter::ConvertLight( const Light& light, const std::string &orig_name ) { +void FBXConverter::ConvertLight( const Light& light, const std::string &orig_name ) { lights.push_back( new aiLight() ); aiLight* const out_light = lights.back(); @@ -379,7 +379,7 @@ void Converter::ConvertLight( const Light& light, const std::string &orig_name ) } } -void Converter::ConvertCamera( const Camera& cam, const std::string &orig_name ) +void FBXConverter::ConvertCamera( const Camera& cam, const std::string &orig_name ) { cameras.push_back( new aiCamera() ); aiCamera* const out_camera = cameras.back(); @@ -398,7 +398,7 @@ void Converter::ConvertCamera( const Camera& cam, const std::string &orig_name ) out_camera->mClipPlaneFar = cam.FarPlane(); } -void Converter::GetUniqueName( const std::string &name, std::string &uniqueName ) +void FBXConverter::GetUniqueName( const std::string &name, std::string &uniqueName ) { int i = 0; uniqueName = name; @@ -413,7 +413,7 @@ void Converter::GetUniqueName( const std::string &name, std::string &uniqueName } -const char* Converter::NameTransformationComp( TransformationComp comp ) +const char* FBXConverter::NameTransformationComp( TransformationComp comp ) { switch ( comp ) { @@ -460,7 +460,7 @@ const char* Converter::NameTransformationComp( TransformationComp comp ) return NULL; } -const char* Converter::NameTransformationCompProperty( TransformationComp comp ) +const char* FBXConverter::NameTransformationCompProperty( TransformationComp comp ) { switch ( comp ) { @@ -506,14 +506,14 @@ const char* Converter::NameTransformationCompProperty( TransformationComp comp ) return NULL; } -aiVector3D Converter::TransformationCompDefaultValue( TransformationComp comp ) +aiVector3D FBXConverter::TransformationCompDefaultValue( TransformationComp comp ) { // XXX a neat way to solve the never-ending special cases for scaling // would be to do everything in log space! return comp == TransformationComp_Scaling ? aiVector3D( 1.f, 1.f, 1.f ) : aiVector3D(); } -void Converter::GetRotationMatrix( Model::RotOrder mode, const aiVector3D& rotation, aiMatrix4x4& out ) +void FBXConverter::GetRotationMatrix( Model::RotOrder mode, const aiVector3D& rotation, aiMatrix4x4& out ) { if ( mode == Model::RotOrder_SphericXYZ ) { FBXImporter::LogError( "Unsupported RotationMode: SphericXYZ" ); @@ -603,7 +603,7 @@ void Converter::GetRotationMatrix( Model::RotOrder mode, const aiVector3D& rotat } } -bool Converter::NeedsComplexTransformationChain( const Model& model ) +bool FBXConverter::NeedsComplexTransformationChain( const Model& model ) { const PropertyTable& props = model.Props(); bool ok; @@ -634,12 +634,12 @@ bool Converter::NeedsComplexTransformationChain( const Model& model ) return false; } -std::string Converter::NameTransformationChainNode( const std::string& name, TransformationComp comp ) +std::string FBXConverter::NameTransformationChainNode( const std::string& name, TransformationComp comp ) { return name + std::string( MAGIC_NODE_TAG ) + "_" + NameTransformationComp( comp ); } -void Converter::GenerateTransformationNodeChain( const Model& model, std::vector& output_nodes, std::vector& post_output_nodes ) +void FBXConverter::GenerateTransformationNodeChain( const Model& model, std::vector& output_nodes, std::vector& post_output_nodes ) { const PropertyTable& props = model.Props(); const Model::RotOrder rot = model.RotationOrder(); @@ -811,7 +811,7 @@ void Converter::GenerateTransformationNodeChain( const Model& model, std::vector } } -void Converter::SetupNodeMetadata( const Model& model, aiNode& nd ) +void FBXConverter::SetupNodeMetadata( const Model& model, aiNode& nd ) { const PropertyTable& props = model.Props(); DirectPropertyMap unparsedProperties = props.GetUnparsedProperties(); @@ -848,7 +848,7 @@ void Converter::SetupNodeMetadata( const Model& model, aiNode& nd ) } } -void Converter::ConvertModel( const Model& model, aiNode& nd, const aiMatrix4x4& node_global_transform ) +void FBXConverter::ConvertModel( const Model& model, aiNode& nd, const aiMatrix4x4& node_global_transform ) { const std::vector& geos = model.GetGeometry(); @@ -875,7 +875,7 @@ void Converter::ConvertModel( const Model& model, aiNode& nd, const aiMatrix4x4& } } -std::vector Converter::ConvertMesh( const MeshGeometry& mesh, const Model& model, +std::vector FBXConverter::ConvertMesh( const MeshGeometry& mesh, const Model& model, const aiMatrix4x4& node_global_transform, aiNode& nd) { std::vector temp; @@ -910,7 +910,7 @@ std::vector Converter::ConvertMesh( const MeshGeometry& mesh, cons return temp; } -aiMesh* Converter::SetupEmptyMesh( const MeshGeometry& mesh, aiNode& nd) +aiMesh* FBXConverter::SetupEmptyMesh( const MeshGeometry& mesh, aiNode& nd) { aiMesh* const out_mesh = new aiMesh(); meshes.push_back( out_mesh ); @@ -933,7 +933,7 @@ aiMesh* Converter::SetupEmptyMesh( const MeshGeometry& mesh, aiNode& nd) return out_mesh; } -unsigned int Converter::ConvertMeshSingleMaterial( const MeshGeometry& mesh, const Model& model, +unsigned int FBXConverter::ConvertMeshSingleMaterial( const MeshGeometry& mesh, const Model& model, const aiMatrix4x4& node_global_transform, aiNode& nd) { const MatIndexArray& mindices = mesh.GetMaterialIndices(); @@ -1060,7 +1060,7 @@ unsigned int Converter::ConvertMeshSingleMaterial( const MeshGeometry& mesh, con return static_cast( meshes.size() - 1 ); } -std::vector Converter::ConvertMeshMultiMaterial( const MeshGeometry& mesh, const Model& model, +std::vector FBXConverter::ConvertMeshMultiMaterial( const MeshGeometry& mesh, const Model& model, const aiMatrix4x4& node_global_transform, aiNode& nd) { const MatIndexArray& mindices = mesh.GetMaterialIndices(); @@ -1080,7 +1080,7 @@ std::vector Converter::ConvertMeshMultiMaterial( const MeshGeometr return indices; } -unsigned int Converter::ConvertMeshMultiMaterial( const MeshGeometry& mesh, const Model& model, +unsigned int FBXConverter::ConvertMeshMultiMaterial( const MeshGeometry& mesh, const Model& model, MatIndexArray::value_type index, const aiMatrix4x4& node_global_transform, aiNode& nd) @@ -1256,7 +1256,7 @@ unsigned int Converter::ConvertMeshMultiMaterial( const MeshGeometry& mesh, cons return static_cast( meshes.size() - 1 ); } -void Converter::ConvertWeights( aiMesh* out, const Model& model, const MeshGeometry& geo, +void FBXConverter::ConvertWeights( aiMesh* out, const Model& model, const MeshGeometry& geo, const aiMatrix4x4& node_global_transform , unsigned int materialIndex, std::vector* outputVertStartIndices ) @@ -1361,7 +1361,7 @@ void Converter::ConvertWeights( aiMesh* out, const Model& model, const MeshGeome std::swap_ranges( bones.begin(), bones.end(), out->mBones ); } -void Converter::ConvertCluster( std::vector& bones, const Model& /*model*/, const Cluster& cl, +void FBXConverter::ConvertCluster( std::vector& bones, const Model& /*model*/, const Cluster& cl, std::vector& out_indices, std::vector& index_out_indices, std::vector& count_out_indices, @@ -1402,7 +1402,7 @@ void Converter::ConvertCluster( std::vector& bones, const Model& /*mode } } -void Converter::ConvertMaterialForMesh( aiMesh* out, const Model& model, const MeshGeometry& geo, +void FBXConverter::ConvertMaterialForMesh( aiMesh* out, const Model& model, const MeshGeometry& geo, MatIndexArray::value_type materialIndex ) { // locate source materials for this mesh @@ -1424,7 +1424,7 @@ void Converter::ConvertMaterialForMesh( aiMesh* out, const Model& model, const M materials_converted[ mat ] = out->mMaterialIndex; } -unsigned int Converter::GetDefaultMaterial() +unsigned int FBXConverter::GetDefaultMaterial() { if ( defaultMaterialIndex ) { return defaultMaterialIndex - 1; @@ -1446,7 +1446,7 @@ unsigned int Converter::GetDefaultMaterial() } -unsigned int Converter::ConvertMaterial( const Material& material, const MeshGeometry* const mesh ) +unsigned int FBXConverter::ConvertMaterial( const Material& material, const MeshGeometry* const mesh ) { const PropertyTable& props = material.Props(); @@ -1481,7 +1481,7 @@ unsigned int Converter::ConvertMaterial( const Material& material, const MeshGeo return static_cast( materials.size() - 1 ); } -unsigned int Converter::ConvertVideo( const Video& video ) +unsigned int FBXConverter::ConvertVideo( const Video& video ) { // generate empty output texture aiTexture* out_tex = new aiTexture(); @@ -1511,7 +1511,7 @@ unsigned int Converter::ConvertVideo( const Video& video ) return static_cast( textures.size() - 1 ); } -aiString Converter::GetTexturePath(const Texture* tex) +aiString FBXConverter::GetTexturePath(const Texture* tex) { aiString path; path.Set(tex->RelativeFilename()); @@ -1551,7 +1551,7 @@ aiString Converter::GetTexturePath(const Texture* tex) return path; } -void Converter::TrySetTextureProperties( aiMaterial* out_mat, const TextureMap& textures, +void FBXConverter::TrySetTextureProperties( aiMaterial* out_mat, const TextureMap& textures, const std::string& propName, aiTextureType target, const MeshGeometry* const mesh ) { @@ -1669,7 +1669,7 @@ void Converter::TrySetTextureProperties( aiMaterial* out_mat, const TextureMap& } } -void Converter::TrySetTextureProperties( aiMaterial* out_mat, const LayeredTextureMap& layeredTextures, +void FBXConverter::TrySetTextureProperties( aiMaterial* out_mat, const LayeredTextureMap& layeredTextures, const std::string& propName, aiTextureType target, const MeshGeometry* const mesh ) { LayeredTextureMap::const_iterator it = layeredTextures.find( propName ); @@ -1792,7 +1792,7 @@ void Converter::TrySetTextureProperties( aiMaterial* out_mat, const LayeredTextu } } -void Converter::SetTextureProperties( aiMaterial* out_mat, const TextureMap& textures, const MeshGeometry* const mesh ) +void FBXConverter::SetTextureProperties( aiMaterial* out_mat, const TextureMap& textures, const MeshGeometry* const mesh ) { TrySetTextureProperties( out_mat, textures, "DiffuseColor", aiTextureType_DIFFUSE, mesh ); TrySetTextureProperties( out_mat, textures, "AmbientColor", aiTextureType_AMBIENT, mesh ); @@ -1807,7 +1807,7 @@ void Converter::SetTextureProperties( aiMaterial* out_mat, const TextureMap& tex TrySetTextureProperties( out_mat, textures, "ShininessExponent", aiTextureType_SHININESS, mesh ); } -void Converter::SetTextureProperties( aiMaterial* out_mat, const LayeredTextureMap& layeredTextures, const MeshGeometry* const mesh ) +void FBXConverter::SetTextureProperties( aiMaterial* out_mat, const LayeredTextureMap& layeredTextures, const MeshGeometry* const mesh ) { TrySetTextureProperties( out_mat, layeredTextures, "DiffuseColor", aiTextureType_DIFFUSE, mesh ); TrySetTextureProperties( out_mat, layeredTextures, "AmbientColor", aiTextureType_AMBIENT, mesh ); @@ -1822,7 +1822,7 @@ void Converter::SetTextureProperties( aiMaterial* out_mat, const LayeredTextureM TrySetTextureProperties( out_mat, layeredTextures, "ShininessExponent", aiTextureType_SHININESS, mesh ); } -aiColor3D Converter::GetColorPropertyFactored( const PropertyTable& props, const std::string& colorName, +aiColor3D FBXConverter::GetColorPropertyFactored( const PropertyTable& props, const std::string& colorName, const std::string& factorName, bool& result, bool useTemplate ) { result = true; @@ -1847,13 +1847,13 @@ aiColor3D Converter::GetColorPropertyFactored( const PropertyTable& props, const return aiColor3D( BaseColor.x, BaseColor.y, BaseColor.z ); } -aiColor3D Converter::GetColorPropertyFromMaterial( const PropertyTable& props, const std::string& baseName, +aiColor3D FBXConverter::GetColorPropertyFromMaterial( const PropertyTable& props, const std::string& baseName, bool& result ) { return GetColorPropertyFactored( props, baseName + "Color", baseName + "Factor", result, true ); } -aiColor3D Converter::GetColorProperty( const PropertyTable& props, const std::string& colorName, +aiColor3D FBXConverter::GetColorProperty( const PropertyTable& props, const std::string& colorName, bool& result, bool useTemplate ) { result = true; @@ -1866,7 +1866,7 @@ aiColor3D Converter::GetColorProperty( const PropertyTable& props, const std::st return aiColor3D( ColorVec.x, ColorVec.y, ColorVec.z ); } -void Converter::SetShadingPropertiesCommon( aiMaterial* out_mat, const PropertyTable& props ) +void FBXConverter::SetShadingPropertiesCommon( aiMaterial* out_mat, const PropertyTable& props ) { // Set shading properties. // Modern FBX Files have two separate systems for defining these, @@ -1965,7 +1965,7 @@ void Converter::SetShadingPropertiesCommon( aiMaterial* out_mat, const PropertyT } -double Converter::FrameRateToDouble( FileGlobalSettings::FrameRate fp, double customFPSVal ) +double FBXConverter::FrameRateToDouble( FileGlobalSettings::FrameRate fp, double customFPSVal ) { switch ( fp ) { case FileGlobalSettings::FrameRate_DEFAULT: @@ -2018,7 +2018,7 @@ double Converter::FrameRateToDouble( FileGlobalSettings::FrameRate fp, double cu } -void Converter::ConvertAnimations() +void FBXConverter::ConvertAnimations() { // first of all determine framerate const FileGlobalSettings::FrameRate fps = doc.GlobalSettings().TimeMode(); @@ -2031,7 +2031,7 @@ void Converter::ConvertAnimations() } } -std::string Converter::FixNodeName( const std::string& name ) { +std::string FBXConverter::FixNodeName( const std::string& name ) { // strip Model:: prefix, avoiding ambiguities (i.e. don't strip if // this causes ambiguities, well possible between empty identifiers, // such as "Model::" and ""). Make sure the behaviour is consistent @@ -2044,7 +2044,7 @@ std::string Converter::FixNodeName( const std::string& name ) { return name; } -void Converter::ConvertAnimationStack( const AnimationStack& st ) +void FBXConverter::ConvertAnimationStack( const AnimationStack& st ) { const AnimationLayerList& layers = st.Layers(); if ( layers.empty() ) { @@ -2186,7 +2186,7 @@ static void validateAnimCurveNodes( const std::vector #endif // ASSIMP_BUILD_DEBUG // ------------------------------------------------------------------------------------------------ -void Converter::GenerateNodeAnimations( std::vector& node_anims, +void FBXConverter::GenerateNodeAnimations( std::vector& node_anims, const std::string& fixed_name, const std::vector& curves, const LayerMap& layer_map, @@ -2420,7 +2420,7 @@ void Converter::GenerateNodeAnimations( std::vector& node_anims, node_anim_chain_bits[ fixed_name ] = flags; } -bool Converter::IsRedundantAnimationData( const Model& target, +bool FBXConverter::IsRedundantAnimationData( const Model& target, TransformationComp comp, const std::vector& curves ) { @@ -2466,7 +2466,7 @@ bool Converter::IsRedundantAnimationData( const Model& target, } -aiNodeAnim* Converter::GenerateRotationNodeAnim( const std::string& name, +aiNodeAnim* FBXConverter::GenerateRotationNodeAnim( const std::string& name, const Model& target, const std::vector& curves, const LayerMap& layer_map, @@ -2496,7 +2496,7 @@ aiNodeAnim* Converter::GenerateRotationNodeAnim( const std::string& name, return na.release(); } -aiNodeAnim* Converter::GenerateScalingNodeAnim( const std::string& name, +aiNodeAnim* FBXConverter::GenerateScalingNodeAnim( const std::string& name, const Model& /*target*/, const std::vector& curves, const LayerMap& layer_map, @@ -2527,7 +2527,7 @@ aiNodeAnim* Converter::GenerateScalingNodeAnim( const std::string& name, } -aiNodeAnim* Converter::GenerateTranslationNodeAnim( const std::string& name, +aiNodeAnim* FBXConverter::GenerateTranslationNodeAnim( const std::string& name, const Model& /*target*/, const std::vector& curves, const LayerMap& layer_map, @@ -2564,7 +2564,7 @@ aiNodeAnim* Converter::GenerateTranslationNodeAnim( const std::string& name, return na.release(); } -aiNodeAnim* Converter::GenerateSimpleNodeAnim( const std::string& name, +aiNodeAnim* FBXConverter::GenerateSimpleNodeAnim( const std::string& name, const Model& target, NodeMap::const_iterator chain[ TransformationComp_MAXIMUM ], NodeMap::const_iterator iter_end, @@ -2700,7 +2700,7 @@ aiNodeAnim* Converter::GenerateSimpleNodeAnim( const std::string& name, return na.release(); } -Converter::KeyFrameListList Converter::GetKeyframeList( const std::vector& nodes, int64_t start, int64_t stop ) +FBXConverter::KeyFrameListList FBXConverter::GetKeyframeList( const std::vector& nodes, int64_t start, int64_t stop ) { KeyFrameListList inputs; inputs.reserve( nodes.size() * 3 ); @@ -2756,7 +2756,7 @@ Converter::KeyFrameListList Converter::GetKeyframeList( const std::vector temp( new aiVectorKey[ keys.size() ] ); InterpolateKeys( temp.get(), keys, inputs, def_value, maxTime, minTime ); @@ -2899,7 +2899,7 @@ void Converter::InterpolateKeys( aiQuatKey* valOut, const KeyTimeList& keys, con } } -void Converter::ConvertTransformOrder_TRStoSRT( aiQuatKey* out_quat, aiVectorKey* out_scale, +void FBXConverter::ConvertTransformOrder_TRStoSRT( aiQuatKey* out_quat, aiVectorKey* out_scale, aiVectorKey* out_translation, const KeyFrameListList& scaling, const KeyFrameListList& translation, @@ -2957,7 +2957,7 @@ void Converter::ConvertTransformOrder_TRStoSRT( aiQuatKey* out_quat, aiVectorKey } } -aiQuaternion Converter::EulerToQuaternion( const aiVector3D& rot, Model::RotOrder order ) +aiQuaternion FBXConverter::EulerToQuaternion( const aiVector3D& rot, Model::RotOrder order ) { aiMatrix4x4 m; GetRotationMatrix( order, rot, m ); @@ -2965,7 +2965,7 @@ aiQuaternion Converter::EulerToQuaternion( const aiVector3D& rot, Model::RotOrde return aiQuaternion( aiMatrix3x3( m ) ); } -void Converter::ConvertScaleKeys( aiNodeAnim* na, const std::vector& nodes, const LayerMap& /*layers*/, +void FBXConverter::ConvertScaleKeys( aiNodeAnim* na, const std::vector& nodes, const LayerMap& /*layers*/, int64_t start, int64_t stop, double& maxTime, double& minTime ) @@ -2985,7 +2985,7 @@ void Converter::ConvertScaleKeys( aiNodeAnim* na, const std::vectormScalingKeys, keys, inputs, aiVector3D( 1.0f, 1.0f, 1.0f ), maxTime, minTime ); } -void Converter::ConvertTranslationKeys( aiNodeAnim* na, const std::vector& nodes, +void FBXConverter::ConvertTranslationKeys( aiNodeAnim* na, const std::vector& nodes, const LayerMap& /*layers*/, int64_t start, int64_t stop, double& maxTime, @@ -3003,7 +3003,7 @@ void Converter::ConvertTranslationKeys( aiNodeAnim* na, const std::vectormPositionKeys, keys, inputs, aiVector3D( 0.0f, 0.0f, 0.0f ), maxTime, minTime ); } -void Converter::ConvertRotationKeys( aiNodeAnim* na, const std::vector& nodes, +void FBXConverter::ConvertRotationKeys( aiNodeAnim* na, const std::vector& nodes, const LayerMap& /*layers*/, int64_t start, int64_t stop, double& maxTime, @@ -3023,7 +3023,7 @@ void Converter::ConvertRotationKeys( aiNodeAnim* na, const std::vectormMetaData->Set(index, "UnitScaleFactor", unitScalFactor); } -void Converter::TransferDataToScene() +void FBXConverter::TransferDataToScene() { ai_assert( !out->mMeshes ); ai_assert( !out->mNumMeshes ); @@ -3089,7 +3089,7 @@ void Converter::TransferDataToScene() // ------------------------------------------------------------------------------------------------ void ConvertToAssimpScene(aiScene* out, const Document& doc) { - Converter converter(out,doc); + FBXConverter converter(out,doc); } } // !FBX diff --git a/code/FBXConverter.h b/code/FBXConverter.h index b6654e378..ca8dcba2e 100644 --- a/code/FBXConverter.h +++ b/code/FBXConverter.h @@ -78,7 +78,7 @@ using NodeNameCache = std::set; void ConvertToAssimpScene(aiScene* out, const Document& doc); /** Dummy class to encapsulate the conversion process */ -class Converter { +class FBXConverter { public: /** * The different parts that make up the final local transformation of a fbx-node @@ -106,8 +106,8 @@ public: }; public: - Converter(aiScene* out, const Document& doc); - ~Converter(); + FBXConverter(aiScene* out, const Document& doc); + ~FBXConverter(); private: // ------------------------------------------------------------------------------------------------ diff --git a/include/assimp/anim.h b/include/assimp/anim.h index 1a2c11044..5ed51af0c 100644 --- a/include/assimp/anim.h +++ b/include/assimp/anim.h @@ -79,26 +79,27 @@ struct aiVectorKey /// @brief Construction from a given time and key value. aiVectorKey(double time, const aiVector3D& value) - : mTime (time) - , mValue (value) - {} + : mTime( time ) + , mValue( value ) { + // empty + } typedef aiVector3D elem_type; // Comparison operators. For use with std::find(); - bool operator == (const aiVectorKey& o) const { - return o.mValue == this->mValue; + bool operator == (const aiVectorKey& rhs) const { + return rhs.mValue == this->mValue; } - bool operator != (const aiVectorKey& o) const { - return o.mValue != this->mValue; + bool operator != (const aiVectorKey& rhs ) const { + return rhs.mValue != this->mValue; } // Relational operators. For use with std::sort(); - bool operator < (const aiVectorKey& o) const { - return mTime < o.mTime; + bool operator < (const aiVectorKey& rhs ) const { + return mTime < rhs.mTime; } - bool operator > (const aiVectorKey& o) const { - return mTime > o.mTime; + bool operator > (const aiVectorKey& rhs ) const { + return mTime > rhs.mTime; } #endif // __cplusplus }; @@ -130,25 +131,25 @@ struct aiQuatKey typedef aiQuaternion elem_type; // Comparison operators. For use with std::find(); - bool operator == (const aiQuatKey& o) const { - return o.mValue == this->mValue; + bool operator == (const aiQuatKey& rhs ) const { + return rhs.mValue == this->mValue; } - bool operator != (const aiQuatKey& o) const { - return o.mValue != this->mValue; + bool operator != (const aiQuatKey& rhs ) const { + return rhs.mValue != this->mValue; } // Relational operators. For use with std::sort(); - bool operator < (const aiQuatKey& o) const { - return mTime < o.mTime; + bool operator < (const aiQuatKey& rhs ) const { + return mTime < rhs.mTime; } - bool operator > (const aiQuatKey& o) const { - return mTime > o.mTime; + bool operator > (const aiQuatKey& rhs ) const { + return mTime > rhs.mTime; } #endif }; // --------------------------------------------------------------------------- -/** Binds a anim mesh to a specific point in time. */ +/** Binds a anim-mesh to a specific point in time. */ struct aiMeshKey { /** The time of this key */ From 442b2583605f650302970ca8c2bd0e2bb5c62b50 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Thu, 9 Aug 2018 22:27:21 +0200 Subject: [PATCH 4/9] update gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index b3b4dc91d..d383f3ec8 100644 --- a/.gitignore +++ b/.gitignore @@ -21,6 +21,7 @@ revision.h contrib/zlib/zconf.h contrib/zlib/zlib.pc include/assimp/config.h +unit.vcxproj.user # CMake CMakeCache.txt From b3132bd8c22b5b846459a01d775e326a70be8fbc Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Fri, 10 Aug 2018 01:57:11 +0200 Subject: [PATCH 5/9] FBX: some refactorings. --- code/FBXConverter.cpp | 272 +++++++++++++++++++++--------------------- 1 file changed, 135 insertions(+), 137 deletions(-) diff --git a/code/FBXConverter.cpp b/code/FBXConverter.cpp index 45ef37ba0..b088b22e0 100644 --- a/code/FBXConverter.cpp +++ b/code/FBXConverter.cpp @@ -413,97 +413,95 @@ void FBXConverter::GetUniqueName( const std::string &name, std::string &uniqueNa } -const char* FBXConverter::NameTransformationComp( TransformationComp comp ) -{ - switch ( comp ) - { - case TransformationComp_Translation: - return "Translation"; - case TransformationComp_RotationOffset: - return "RotationOffset"; - case TransformationComp_RotationPivot: - return "RotationPivot"; - case TransformationComp_PreRotation: - return "PreRotation"; - case TransformationComp_Rotation: - return "Rotation"; - case TransformationComp_PostRotation: - return "PostRotation"; - case TransformationComp_RotationPivotInverse: - return "RotationPivotInverse"; - case TransformationComp_ScalingOffset: - return "ScalingOffset"; - case TransformationComp_ScalingPivot: - return "ScalingPivot"; - case TransformationComp_Scaling: - return "Scaling"; - case TransformationComp_ScalingPivotInverse: - return "ScalingPivotInverse"; - case TransformationComp_GeometricScaling: - return "GeometricScaling"; - case TransformationComp_GeometricRotation: - return "GeometricRotation"; - case TransformationComp_GeometricTranslation: - return "GeometricTranslation"; - case TransformationComp_GeometricScalingInverse: - return "GeometricScalingInverse"; - case TransformationComp_GeometricRotationInverse: - return "GeometricRotationInverse"; - case TransformationComp_GeometricTranslationInverse: - return "GeometricTranslationInverse"; - case TransformationComp_MAXIMUM: // this is to silence compiler warnings - default: - break; +const char* FBXConverter::NameTransformationComp( TransformationComp comp ) { + switch ( comp ) { + case TransformationComp_Translation: + return "Translation"; + case TransformationComp_RotationOffset: + return "RotationOffset"; + case TransformationComp_RotationPivot: + return "RotationPivot"; + case TransformationComp_PreRotation: + return "PreRotation"; + case TransformationComp_Rotation: + return "Rotation"; + case TransformationComp_PostRotation: + return "PostRotation"; + case TransformationComp_RotationPivotInverse: + return "RotationPivotInverse"; + case TransformationComp_ScalingOffset: + return "ScalingOffset"; + case TransformationComp_ScalingPivot: + return "ScalingPivot"; + case TransformationComp_Scaling: + return "Scaling"; + case TransformationComp_ScalingPivotInverse: + return "ScalingPivotInverse"; + case TransformationComp_GeometricScaling: + return "GeometricScaling"; + case TransformationComp_GeometricRotation: + return "GeometricRotation"; + case TransformationComp_GeometricTranslation: + return "GeometricTranslation"; + case TransformationComp_GeometricScalingInverse: + return "GeometricScalingInverse"; + case TransformationComp_GeometricRotationInverse: + return "GeometricRotationInverse"; + case TransformationComp_GeometricTranslationInverse: + return "GeometricTranslationInverse"; + case TransformationComp_MAXIMUM: // this is to silence compiler warnings + default: + break; } ai_assert( false ); - return NULL; + + return nullptr; } -const char* FBXConverter::NameTransformationCompProperty( TransformationComp comp ) -{ - switch ( comp ) - { - case TransformationComp_Translation: - return "Lcl Translation"; - case TransformationComp_RotationOffset: - return "RotationOffset"; - case TransformationComp_RotationPivot: - return "RotationPivot"; - case TransformationComp_PreRotation: - return "PreRotation"; - case TransformationComp_Rotation: - return "Lcl Rotation"; - case TransformationComp_PostRotation: - return "PostRotation"; - case TransformationComp_RotationPivotInverse: - return "RotationPivotInverse"; - case TransformationComp_ScalingOffset: - return "ScalingOffset"; - case TransformationComp_ScalingPivot: - return "ScalingPivot"; - case TransformationComp_Scaling: - return "Lcl Scaling"; - case TransformationComp_ScalingPivotInverse: - return "ScalingPivotInverse"; - case TransformationComp_GeometricScaling: - return "GeometricScaling"; - case TransformationComp_GeometricRotation: - return "GeometricRotation"; - case TransformationComp_GeometricTranslation: - return "GeometricTranslation"; - case TransformationComp_GeometricScalingInverse: - return "GeometricScalingInverse"; - case TransformationComp_GeometricRotationInverse: - return "GeometricRotationInverse"; - case TransformationComp_GeometricTranslationInverse: - return "GeometricTranslationInverse"; - case TransformationComp_MAXIMUM: // this is to silence compiler warnings - break; +const char* FBXConverter::NameTransformationCompProperty( TransformationComp comp ) { + switch ( comp ) { + case TransformationComp_Translation: + return "Lcl Translation"; + case TransformationComp_RotationOffset: + return "RotationOffset"; + case TransformationComp_RotationPivot: + return "RotationPivot"; + case TransformationComp_PreRotation: + return "PreRotation"; + case TransformationComp_Rotation: + return "Lcl Rotation"; + case TransformationComp_PostRotation: + return "PostRotation"; + case TransformationComp_RotationPivotInverse: + return "RotationPivotInverse"; + case TransformationComp_ScalingOffset: + return "ScalingOffset"; + case TransformationComp_ScalingPivot: + return "ScalingPivot"; + case TransformationComp_Scaling: + return "Lcl Scaling"; + case TransformationComp_ScalingPivotInverse: + return "ScalingPivotInverse"; + case TransformationComp_GeometricScaling: + return "GeometricScaling"; + case TransformationComp_GeometricRotation: + return "GeometricRotation"; + case TransformationComp_GeometricTranslation: + return "GeometricTranslation"; + case TransformationComp_GeometricScalingInverse: + return "GeometricScalingInverse"; + case TransformationComp_GeometricRotationInverse: + return "GeometricRotationInverse"; + case TransformationComp_GeometricTranslationInverse: + return "GeometricTranslationInverse"; + case TransformationComp_MAXIMUM: // this is to silence compiler warnings + break; } ai_assert( false ); - return NULL; + + return nullptr; } aiVector3D FBXConverter::TransformationCompDefaultValue( TransformationComp comp ) @@ -584,11 +582,15 @@ void FBXConverter::GetRotationMatrix( Model::RotOrder mode, const aiVector3D& ro default: ai_assert( false ); + break; } - ai_assert( ( order[ 0 ] >= 0 ) && ( order[ 0 ] <= 2 ) ); - ai_assert( ( order[ 1 ] >= 0 ) && ( order[ 1 ] <= 2 ) ); - ai_assert( ( order[ 2 ] >= 0 ) && ( order[ 2 ] <= 2 ) ); + ai_assert( order[ 0 ] >= 0 ); + ai_assert( order[ 0 ] <= 2 ); + ai_assert( order[ 1 ] >= 0 ); + ai_assert( order[ 1 ] <= 2 ); + ai_assert( order[ 2 ] >= 0 ); + ai_assert( order[ 2 ] <= 2 ); if ( !is_id[ order[ 0 ] ] ) { out = temp[ order[ 0 ] ]; @@ -639,8 +641,8 @@ std::string FBXConverter::NameTransformationChainNode( const std::string& name, return name + std::string( MAGIC_NODE_TAG ) + "_" + NameTransformationComp( comp ); } -void FBXConverter::GenerateTransformationNodeChain( const Model& model, std::vector& output_nodes, std::vector& post_output_nodes ) -{ +void FBXConverter::GenerateTransformationNodeChain( const Model& model, std::vector& output_nodes, + std::vector& post_output_nodes ) { const PropertyTable& props = model.Props(); const Model::RotOrder rot = model.RotationOrder(); @@ -1965,55 +1967,55 @@ void FBXConverter::SetShadingPropertiesCommon( aiMaterial* out_mat, const Proper } -double FBXConverter::FrameRateToDouble( FileGlobalSettings::FrameRate fp, double customFPSVal ) -{ +double FBXConverter::FrameRateToDouble( FileGlobalSettings::FrameRate fp, double customFPSVal ) { switch ( fp ) { - case FileGlobalSettings::FrameRate_DEFAULT: - return 1.0; + case FileGlobalSettings::FrameRate_DEFAULT: + return 1.0; - case FileGlobalSettings::FrameRate_120: - return 120.0; + case FileGlobalSettings::FrameRate_120: + return 120.0; - case FileGlobalSettings::FrameRate_100: - return 100.0; + case FileGlobalSettings::FrameRate_100: + return 100.0; - case FileGlobalSettings::FrameRate_60: - return 60.0; + case FileGlobalSettings::FrameRate_60: + return 60.0; - case FileGlobalSettings::FrameRate_50: - return 50.0; + case FileGlobalSettings::FrameRate_50: + return 50.0; - case FileGlobalSettings::FrameRate_48: - return 48.0; + case FileGlobalSettings::FrameRate_48: + return 48.0; - case FileGlobalSettings::FrameRate_30: - case FileGlobalSettings::FrameRate_30_DROP: - return 30.0; + case FileGlobalSettings::FrameRate_30: + case FileGlobalSettings::FrameRate_30_DROP: + return 30.0; - case FileGlobalSettings::FrameRate_NTSC_DROP_FRAME: - case FileGlobalSettings::FrameRate_NTSC_FULL_FRAME: - return 29.9700262; + case FileGlobalSettings::FrameRate_NTSC_DROP_FRAME: + case FileGlobalSettings::FrameRate_NTSC_FULL_FRAME: + return 29.9700262; - case FileGlobalSettings::FrameRate_PAL: - return 25.0; + case FileGlobalSettings::FrameRate_PAL: + return 25.0; - case FileGlobalSettings::FrameRate_CINEMA: - return 24.0; + case FileGlobalSettings::FrameRate_CINEMA: + return 24.0; - case FileGlobalSettings::FrameRate_1000: - return 1000.0; + case FileGlobalSettings::FrameRate_1000: + return 1000.0; - case FileGlobalSettings::FrameRate_CINEMA_ND: - return 23.976; + case FileGlobalSettings::FrameRate_CINEMA_ND: + return 23.976; - case FileGlobalSettings::FrameRate_CUSTOM: - return customFPSVal; + case FileGlobalSettings::FrameRate_CUSTOM: + return customFPSVal; - case FileGlobalSettings::FrameRate_MAX: // this is to silence compiler warnings - break; + case FileGlobalSettings::FrameRate_MAX: // this is to silence compiler warnings + break; } ai_assert( false ); + return -1.0f; } @@ -2421,9 +2423,8 @@ void FBXConverter::GenerateNodeAnimations( std::vector& node_anims, } bool FBXConverter::IsRedundantAnimationData( const Model& target, - TransformationComp comp, - const std::vector& curves ) -{ + TransformationComp comp, + const std::vector& curves ) { ai_assert( curves.size() ); // look for animation nodes with @@ -2526,16 +2527,14 @@ aiNodeAnim* FBXConverter::GenerateScalingNodeAnim( const std::string& name, return na.release(); } - aiNodeAnim* FBXConverter::GenerateTranslationNodeAnim( const std::string& name, - const Model& /*target*/, - const std::vector& curves, - const LayerMap& layer_map, - int64_t start, int64_t stop, - double& max_time, - double& min_time, - bool inverse ) -{ + const Model& /*target*/, + const std::vector& curves, + const LayerMap& layer_map, + int64_t start, int64_t stop, + double& max_time, + double& min_time, + bool inverse ) { std::unique_ptr na( new aiNodeAnim() ); na->mNodeName.Set( name ); @@ -2756,12 +2755,11 @@ FBXConverter::KeyFrameListList FBXConverter::GetKeyframeList( const std::vector< } -KeyTimeList FBXConverter::GetKeyTimeList( const KeyFrameListList& inputs ) -{ - ai_assert( inputs.size() ); +KeyTimeList FBXConverter::GetKeyTimeList( const KeyFrameListList& inputs ) { + ai_assert( !inputs.empty() ); - // reserve some space upfront - it is likely that the keyframe lists - // have matching time values, so max(of all keyframe lists) should + // reserve some space upfront - it is likely that the key-frame lists + // have matching time values, so max(of all key-frame lists) should // be a good estimate. KeyTimeList keys; From dd8cf73415576eb6939bbfa0686c1fadc40f3dff Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Sat, 11 Aug 2018 00:15:22 +0200 Subject: [PATCH 6/9] Update BVHLoader.cpp Fix compiler warning: not handled enum in switch. --- code/BVHLoader.cpp | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/code/BVHLoader.cpp b/code/BVHLoader.cpp index 8fa2a6f7f..cba58d056 100644 --- a/code/BVHLoader.cpp +++ b/code/BVHLoader.cpp @@ -490,11 +490,19 @@ void BVHLoader::CreateAnimation( aiScene* pScene) throw DeadlyImportError("Missing position channel in node " + nodeName); else { int channelIdx = mapIter->second; - switch (channel) - { - case Channel_PositionX: poskey->mValue.x = node.mChannelValues[fr * node.mChannels.size() + channelIdx]; break; - case Channel_PositionY: poskey->mValue.y = node.mChannelValues[fr * node.mChannels.size() + channelIdx]; break; - case Channel_PositionZ: poskey->mValue.z = node.mChannelValues[fr * node.mChannels.size() + channelIdx]; break; + switch (channel) { + case Channel_PositionX: + poskey->mValue.x = node.mChannelValues[fr * node.mChannels.size() + channelIdx]; + break; + case Channel_PositionY: + poskey->mValue.y = node.mChannelValues[fr * node.mChannels.size() + channelIdx]; + break; + case Channel_PositionZ: + poskey->mValue.z = node.mChannelValues[fr * node.mChannels.size() + channelIdx]; + break; + + default: + break; } } @@ -537,9 +545,16 @@ void BVHLoader::CreateAnimation( aiScene* pScene) // Compute rotation transformations in the right order switch (channel) { - case Channel_RotationX: aiMatrix4x4::RotationX(angle, temp); rotMatrix *= aiMatrix3x3(temp); break; - case Channel_RotationY: aiMatrix4x4::RotationY(angle, temp); rotMatrix *= aiMatrix3x3(temp); break; - case Channel_RotationZ: aiMatrix4x4::RotationZ(angle, temp); rotMatrix *= aiMatrix3x3(temp); break; + case Channel_RotationX: + aiMatrix4x4::RotationX(angle, temp); rotMatrix *= aiMatrix3x3(temp); + break; + case Channel_RotationY: + aiMatrix4x4::RotationY(angle, temp); rotMatrix *= aiMatrix3x3(temp); + break; + case Channel_RotationZ: aiMatrix4x4::RotationZ(angle, temp); rotMatrix *= aiMatrix3x3(temp); + break; + default: + break; } } } From d25083dba93726319fe889e766f761b7d1798c73 Mon Sep 17 00:00:00 2001 From: Jeka Vlasov Date: Mon, 13 Aug 2018 00:18:12 +0300 Subject: [PATCH 7/9] Add point cloud support for OBJ importer --- code/ObjFileImporter.cpp | 68 +++++++++++++++++++++++++++++++--------- 1 file changed, 53 insertions(+), 15 deletions(-) diff --git a/code/ObjFileImporter.cpp b/code/ObjFileImporter.cpp index 64eac6790..4fc042966 100644 --- a/code/ObjFileImporter.cpp +++ b/code/ObjFileImporter.cpp @@ -210,22 +210,60 @@ void ObjFileImporter::CreateDataFromImport(const ObjFile::Model* pModel, aiScene ai_assert(false); } - // Create nodes for the whole scene - std::vector MeshArray; - for (size_t index = 0; index < pModel->m_Objects.size(); ++index ) { - createNodes(pModel, pModel->m_Objects[ index ], pScene->mRootNode, pScene, MeshArray); - } - - // Create mesh pointer buffer for this scene - if (pScene->mNumMeshes > 0) { - pScene->mMeshes = new aiMesh*[ MeshArray.size() ]; - for (size_t index =0; index < MeshArray.size(); ++index ) { - pScene->mMeshes[ index ] = MeshArray[ index ]; + if (pModel->m_Objects.size() > 0) { + // Create nodes for the whole scene + std::vector MeshArray; + for (size_t index = 0; index < pModel->m_Objects.size(); ++index) { + createNodes(pModel, pModel->m_Objects[index], pScene->mRootNode, pScene, MeshArray); } - } - // Create all materials - createMaterials( pModel, pScene ); + // Create mesh pointer buffer for this scene + if (pScene->mNumMeshes > 0) { + pScene->mMeshes = new aiMesh*[MeshArray.size()]; + for (size_t index = 0; index < MeshArray.size(); ++index) { + pScene->mMeshes[index] = MeshArray[index]; + } + } + + // Create all materials + createMaterials(pModel, pScene); + }else { + if (pModel->m_Vertices.empty()) + return; + + aiMesh* mesh = new aiMesh(); + mesh->mPrimitiveTypes = aiPrimitiveType_POINT; + pScene->mRootNode->mNumMeshes = 1; + pScene->mRootNode->mMeshes = new unsigned int[1]; + pScene->mRootNode->mMeshes[0] = 0; + pScene->mMeshes = new aiMesh*[1]; + pScene->mNumMeshes = 1; + pScene->mMeshes[0] = mesh; + + unsigned int n = pModel->m_Vertices.size(); + mesh->mNumVertices = n; + + mesh->mVertices = new aiVector3D[n]; + memcpy_s(mesh->mVertices, n*sizeof(aiVector3D), pModel->m_Vertices.data(), pModel->m_Vertices.size()*sizeof(aiVector3D) ); + + // Allocate memory for attributes + if ( !pModel->m_Normals.empty() ) { + mesh->mNormals = new aiVector3D[n]; + memcpy_s(mesh->mNormals, n*sizeof(aiVector3D), pModel->m_Normals.data(), pModel->m_Normals.size()*sizeof(aiVector3D)); + } + + if ( !pModel->m_VertexColors.empty() ){ + mesh->mColors[0] = new aiColor4D[mesh->mNumVertices]; + for (unsigned int i = 0; i < n; ++i) { + if (i < pModel->m_VertexColors.size() ) { + const aiVector3D& color = pModel->m_VertexColors[i]; + mesh->mColors[0][i] = aiColor4D(color.x, color.y, color.z, 1.0); + }else { + mesh->mColors[0][i] = aiColor4D( 1.0, 1.0, 1.0, 1.0 ); // Any other ideas what to use as default color? + } + } + } + } } // ------------------------------------------------------------------------------------------------ @@ -452,7 +490,7 @@ void ObjFileImporter::createVertexArray(const ObjFile::Model* pModel, // Copy all vertex colors if ( !pModel->m_VertexColors.empty()) { - const aiVector3D color = pModel->m_VertexColors[ vertex ]; + const aiVector3D& color = pModel->m_VertexColors[ vertex ]; pMesh->mColors[0][ newIndex ] = aiColor4D(color.x, color.y, color.z, 1.0); } From 2b15586e6b9d729810340dcf3d87a09f4d4a6c2e Mon Sep 17 00:00:00 2001 From: Jeka Vlasov Date: Wed, 15 Aug 2018 01:22:28 +0300 Subject: [PATCH 8/9] Replace memcpy_s with memcpy to fix build with gcc 4.8 --- code/ObjFileImporter.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/code/ObjFileImporter.cpp b/code/ObjFileImporter.cpp index 4fc042966..c64518efe 100644 --- a/code/ObjFileImporter.cpp +++ b/code/ObjFileImporter.cpp @@ -244,12 +244,14 @@ void ObjFileImporter::CreateDataFromImport(const ObjFile::Model* pModel, aiScene mesh->mNumVertices = n; mesh->mVertices = new aiVector3D[n]; - memcpy_s(mesh->mVertices, n*sizeof(aiVector3D), pModel->m_Vertices.data(), pModel->m_Vertices.size()*sizeof(aiVector3D) ); + memcpy(mesh->mVertices, pModel->m_Vertices.data(), n*sizeof(aiVector3D) ); - // Allocate memory for attributes if ( !pModel->m_Normals.empty() ) { mesh->mNormals = new aiVector3D[n]; - memcpy_s(mesh->mNormals, n*sizeof(aiVector3D), pModel->m_Normals.data(), pModel->m_Normals.size()*sizeof(aiVector3D)); + if (pModel->m_Normals.size() < n) { + throw DeadlyImportError("OBJ: vertex normal index out of range"); + } + memcpy(mesh->mNormals, pModel->m_Normals.data(), n*sizeof(aiVector3D)); } if ( !pModel->m_VertexColors.empty() ){ @@ -259,7 +261,7 @@ void ObjFileImporter::CreateDataFromImport(const ObjFile::Model* pModel, aiScene const aiVector3D& color = pModel->m_VertexColors[i]; mesh->mColors[0][i] = aiColor4D(color.x, color.y, color.z, 1.0); }else { - mesh->mColors[0][i] = aiColor4D( 1.0, 1.0, 1.0, 1.0 ); // Any other ideas what to use as default color? + throw DeadlyImportError("OBJ: vertex color index out of range"); } } } From 102486005ddb9665458dd4d63adf73e35fe95552 Mon Sep 17 00:00:00 2001 From: Jeka Vlasov Date: Wed, 15 Aug 2018 02:27:56 +0300 Subject: [PATCH 9/9] Fix memory leak on throw --- code/ObjFileImporter.cpp | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/code/ObjFileImporter.cpp b/code/ObjFileImporter.cpp index c64518efe..2b6730e4e 100644 --- a/code/ObjFileImporter.cpp +++ b/code/ObjFileImporter.cpp @@ -228,18 +228,12 @@ void ObjFileImporter::CreateDataFromImport(const ObjFile::Model* pModel, aiScene // Create all materials createMaterials(pModel, pScene); }else { - if (pModel->m_Vertices.empty()) - return; + if (pModel->m_Vertices.empty()){ + return; + } - aiMesh* mesh = new aiMesh(); + std::unique_ptr mesh( new aiMesh ); mesh->mPrimitiveTypes = aiPrimitiveType_POINT; - pScene->mRootNode->mNumMeshes = 1; - pScene->mRootNode->mMeshes = new unsigned int[1]; - pScene->mRootNode->mMeshes[0] = 0; - pScene->mMeshes = new aiMesh*[1]; - pScene->mNumMeshes = 1; - pScene->mMeshes[0] = mesh; - unsigned int n = pModel->m_Vertices.size(); mesh->mNumVertices = n; @@ -264,7 +258,14 @@ void ObjFileImporter::CreateDataFromImport(const ObjFile::Model* pModel, aiScene throw DeadlyImportError("OBJ: vertex color index out of range"); } } - } + } + + pScene->mRootNode->mNumMeshes = 1; + pScene->mRootNode->mMeshes = new unsigned int[1]; + pScene->mRootNode->mMeshes[0] = 0; + pScene->mMeshes = new aiMesh*[1]; + pScene->mNumMeshes = 1; + pScene->mMeshes[0] = mesh.release(); } }