MCPcopy Create free account
hub / github.com/assimp/assimp / Execute

Method Execute

code/PostProcessing/ScaleProcess.cpp:83–161  ·  view source on GitHub ↗

------------------------------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

81
82// ------------------------------------------------------------------------------------------------
83void ScaleProcess::Execute( aiScene* pScene ) {
84 if(mScale == 1.0f) {
85 return; // nothing to scale
86 }
87
88 ai_assert(mScale != 0 );
89 ai_assert(nullptr != pScene );
90 ai_assert(nullptr != pScene->mRootNode );
91
92 if ( nullptr == pScene ) {
93 return;
94 }
95
96 if ( nullptr == pScene->mRootNode ) {
97 return;
98 }
99
100 // Process animations and update position transform to new unit system
101 for( unsigned int animationID = 0; animationID < pScene->mNumAnimations; animationID++ ) {
102 aiAnimation* animation = pScene->mAnimations[animationID];
103
104 for( unsigned int animationChannel = 0; animationChannel < animation->mNumChannels; animationChannel++) {
105 aiNodeAnim* anim = animation->mChannels[animationChannel];
106
107 for( unsigned int posKey = 0; posKey < anim->mNumPositionKeys; posKey++) {
108 aiVectorKey& vectorKey = anim->mPositionKeys[posKey];
109 vectorKey.mValue *= mScale;
110 }
111 }
112 }
113
114 for( unsigned int meshID = 0; meshID < pScene->mNumMeshes; meshID++) {
115 aiMesh *mesh = pScene->mMeshes[meshID];
116
117 // Reconstruct mesh vertices to the new unit system
118 for( unsigned int vertexID = 0; vertexID < mesh->mNumVertices; vertexID++) {
119 aiVector3D& vertex = mesh->mVertices[vertexID];
120 vertex *= mScale;
121 }
122
123 // bone placement / scaling
124 for( unsigned int boneID = 0; boneID < mesh->mNumBones; boneID++) {
125 // Reconstruct matrix by transform rather than by scale
126 // This prevent scale values being changed which can
127 // be meaningful in some cases
128 // like when you want the modeller to see 1:1 compatibility.
129 aiBone* bone = mesh->mBones[boneID];
130
131 aiVector3D pos, scale;
132 aiQuaternion rotation;
133
134 bone->mOffsetMatrix.Decompose( scale, rotation, pos);
135
136 aiMatrix4x4 translation;
137 aiMatrix4x4::Translation( pos * mScale, translation );
138
139 aiMatrix4x4 scaling;
140 aiMatrix4x4::Scaling( aiVector3D(scale), scaling );

Callers 1

ExportMethod · 0.45

Calls 4

TranslationClass · 0.85
aiVector3DClass · 0.85
aiMatrix4x4Class · 0.85
GetMatrixMethod · 0.80

Tested by

no test coverage detected