@@ -71,6 +71,53 @@ T3DM::T3DMData T3DM::parseGLTF(const char *gltfPath)
7171 continue ;
7272 }
7373
74+ constexpr auto EPSILON = 0.0001 ;
75+ bool ancestorHasTransforms = false ;
76+ cgltf_node* p = bone->parent ;
77+ while (p != nullptr ) {
78+ if (p->has_translation || p->has_rotation || p->has_scale || p->has_matrix ) {
79+ if (config.verbose ) printf (" Ancestor '%s' of skin armature/root bone '%s' has transforms: t:%d r:%d s:%d m:%d\n " , p->name , bone->name , p->has_translation , p->has_rotation , p->has_scale , p->has_matrix );
80+ if (p->has_translation ) {
81+ if (fabs (p->translation [0 ]) > EPSILON || fabs (p->translation [1 ]) > EPSILON || fabs (p->translation [2 ]) > EPSILON) {
82+ ancestorHasTransforms = true ;
83+ }
84+ if (config.verbose ) printf (" t: %f %f %f\n " , p->translation [0 ], p->translation [1 ], p->translation [2 ]);
85+ }
86+ if (p->has_rotation ) {
87+ if (fabs (p->rotation [0 ]) > EPSILON || fabs (p->rotation [1 ]) > EPSILON || fabs (p->rotation [2 ]) > EPSILON || fabs (p->rotation [3 ] - 1 ) > EPSILON) {
88+ ancestorHasTransforms = true ;
89+ }
90+ if (config.verbose ) printf (" r: %f %f %f %f\n " , p->rotation [0 ], p->rotation [1 ], p->rotation [2 ], p->rotation [3 ]);
91+ }
92+ if (p->has_scale ) {
93+ if (fabs (p->scale [0 ] - 1 ) > EPSILON || fabs (p->scale [1 ] - 1 ) > EPSILON || fabs (p->scale [2 ] - 1 ) > EPSILON) {
94+ ancestorHasTransforms = true ;
95+ }
96+ if (config.verbose ) printf (" s: %f %f %f\n " , p->scale [0 ], p->scale [1 ], p->scale [2 ]);
97+ }
98+ if (p->has_matrix ) {
99+ for (int y=0 ; y<4 ; y++) {
100+ for (int x=0 ; x<4 ; x++) {
101+ float reference = x==y ? 1 : 0 ;
102+ if (fabs (p->matrix [y+x*4 ] - reference) > EPSILON) {
103+ ancestorHasTransforms = true ;
104+ }
105+ }
106+ }
107+ if (config.verbose ) printf (" m: %f %f %f %f\n %f %f %f %f\n %f %f %f %f\n %f %f %f %f\n " ,
108+ p->matrix [0 ], p->matrix [4 ], p->matrix [8 ], p->matrix [12 ],
109+ p->matrix [1 ], p->matrix [5 ], p->matrix [9 ], p->matrix [13 ],
110+ p->matrix [2 ], p->matrix [6 ], p->matrix [10 ], p->matrix [14 ],
111+ p->matrix [3 ], p->matrix [7 ], p->matrix [11 ], p->matrix [15 ]
112+ );
113+ }
114+ }
115+ p = p->parent ;
116+ }
117+ if (ancestorHasTransforms) {
118+ throw std::runtime_error (" At least one ancestor of armature/skin root bone has significant transforms! (in file: " + std::string (gltfPath) + " )" );
119+ }
120+
74121 Bone armature = parseBoneTree (bone, nullptr , boneCount);
75122
76123 // printBoneTree(armature, 0);
0 commit comments