@@ -147,100 +147,14 @@ bool LLGLTFLoader::parseMeshes()
147147 populateJointFromSkin (skin);
148148 }
149149
150- /* Two-pass mesh processing approach:
151- * 1. First pass: Calculate global bounds across all meshes to determine proper scaling
152- * and centering for the entire model. This ensures consistent normalization.
153- * 2. Second pass: Process each mesh node with the calculated global scale factor and
154- * center offset, ensuring the entire model is properly proportioned and centered.
155- */
156-
157- // First pass: Calculate global bounds across all meshes in the model
158- LLVector3 global_min_bounds (FLT_MAX, FLT_MAX, FLT_MAX);
159- LLVector3 global_max_bounds (-FLT_MAX, -FLT_MAX, -FLT_MAX);
160- bool has_geometry = false ;
161-
162- // Create coordinate system rotation matrix - GLTF is Y-up, SL is Z-up
163- LLMatrix4 coord_system_rotation;
164- coord_system_rotation.initRotation (90 .0f * DEG_TO_RAD, 0 .0f , 0 .0f );
165-
166- // Gather bounds from all meshes
167- for (auto &node : mGLTFAsset .mNodes )
168- {
169- auto meshidx = node.mMesh ;
170- if (meshidx >= 0 && meshidx < mGLTFAsset .mMeshes .size ())
171- {
172- auto mesh = mGLTFAsset .mMeshes [meshidx];
173-
174- // Make node matrix valid for correct transformation
175- node.makeMatrixValid ();
176-
177- LLMatrix4 node_matrix (glm::value_ptr (node.mMatrix ));
178- LLMatrix4 node_transform;
179- node_transform *= coord_system_rotation; // Apply coordinate rotation first
180- node_transform *= node_matrix;
181-
182- // Examine all primitives in this mesh
183- for (auto prim : mesh.mPrimitives )
184- {
185- if (prim.getVertexCount () >= USHRT_MAX)
186- continue ;
187-
188- for (U32 i = 0 ; i < prim.getVertexCount (); i++)
189- {
190- // Transform vertex position by node transform
191- LLVector4 pos (prim.mPositions [i][0 ], prim.mPositions [i][1 ], prim.mPositions [i][2 ], 1 .0f );
192- LLVector4 transformed_pos = pos * node_transform;
193-
194- global_min_bounds.mV [VX] = llmin (global_min_bounds.mV [VX], transformed_pos.mV [VX]);
195- global_min_bounds.mV [VY] = llmin (global_min_bounds.mV [VY], transformed_pos.mV [VY]);
196- global_min_bounds.mV [VZ] = llmin (global_min_bounds.mV [VZ], transformed_pos.mV [VZ]);
197-
198- global_max_bounds.mV [VX] = llmax (global_max_bounds.mV [VX], transformed_pos.mV [VX]);
199- global_max_bounds.mV [VY] = llmax (global_max_bounds.mV [VY], transformed_pos.mV [VY]);
200- global_max_bounds.mV [VZ] = llmax (global_max_bounds.mV [VZ], transformed_pos.mV [VZ]);
201-
202- has_geometry = true ;
203- }
204- }
205- }
206- }
207-
208- // Calculate model dimensions and center point for the entire model
209- F32 global_scale_factor = 1 .0f ;
210- LLVector3 global_center_offset (0 .0f , 0 .0f , 0 .0f );
211-
212- if (has_geometry
213- && mJointList .empty ()) // temporary disable offset and scaling for rigged meshes
150+ for (auto & node : mGLTFAsset .mNodes )
214151 {
215- // Calculate bounding box center - this will be our new origin
216- LLVector3 center = (global_min_bounds + global_max_bounds) * 0 .5f ;
217- global_center_offset = -center; // Offset to move center to origin
218-
219- // Calculate dimensions of the bounding box
220- LLVector3 dimensions = global_max_bounds - global_min_bounds;
221-
222- // Find the maximum dimension rather than the diagonal
223- F32 max_dimension = llmax (dimensions.mV [VX], llmax (dimensions.mV [VY], dimensions.mV [VZ]));
224-
225- // Always scale to the target size to ensure consistent bounding box
226- const F32 TARGET_SIZE = 1 .0f ; // Target size for maximum dimension in meters
227-
228- if (max_dimension > 0 .0f )
229- {
230- // Calculate scale factor to normalize model's maximum dimension to TARGET_SIZE
231- global_scale_factor = TARGET_SIZE / max_dimension;
232-
233- LL_INFOS (" GLTF_IMPORT" ) << " Model dimensions: " << dimensions.mV [VX] << " x"
234- << dimensions.mV [VY] << " x" << dimensions.mV [VZ]
235- << " , max dimension: " << max_dimension
236- << " , applying global scale factor: " << global_scale_factor
237- << " , global centering offset: (" << global_center_offset.mV [VX] << " , "
238- << global_center_offset.mV [VY] << " , " << global_center_offset.mV [VZ] << " )" << LL_ENDL;
239- }
152+ // Make node matrix valid for correct transformation
153+ node.makeMatrixValid ();
240154 }
241155
242- // Second pass: Process each node with the global scale and offset
243- for (auto & node : mGLTFAsset .mNodes )
156+ // Process each node
157+ for (auto & node : mGLTFAsset .mNodes )
244158 {
245159 LLMatrix4 transformation;
246160 material_map mats;
@@ -252,7 +166,7 @@ bool LLGLTFLoader::parseMeshes()
252166 {
253167 LLModel* pModel = new LLModel (volume_params, 0 .f );
254168 auto mesh = mGLTFAsset .mMeshes [meshidx];
255- if (populateModelFromMesh (pModel, mesh, node, mats, global_scale_factor, global_center_offset ) &&
169+ if (populateModelFromMesh (pModel, mesh, node, mats) &&
256170 (LLModel::NO_ERRORS == pModel->getStatus ()) &&
257171 validate_model (pModel))
258172 {
@@ -292,7 +206,7 @@ bool LLGLTFLoader::parseMeshes()
292206 else
293207 {
294208 setLoadState (ERROR_MODEL + pModel->getStatus ());
295- delete ( pModel) ;
209+ delete pModel;
296210 return false ;
297211 }
298212 }
@@ -330,8 +244,7 @@ void LLGLTFLoader::computeCombinedNodeTransform(const LL::GLTF::Asset& asset, S3
330244 combined_transform = node_transform;
331245}
332246
333- bool LLGLTFLoader::populateModelFromMesh (LLModel* pModel, const LL::GLTF::Mesh& mesh, const LL::GLTF::Node& nodeno, material_map& mats,
334- const F32 scale_factor, const LLVector3& center_offset)
247+ bool LLGLTFLoader::populateModelFromMesh (LLModel* pModel, const LL::GLTF::Mesh& mesh, const LL::GLTF::Node& nodeno, material_map& mats)
335248{
336249 pModel->mLabel = mesh.mName ;
337250 pModel->ClearFacesAndMaterials ();
@@ -481,11 +394,7 @@ bool LLGLTFLoader::populateModelFromMesh(LLModel* pModel, const LL::GLTF::Mesh&
481394
482395 // Apply scaling and centering after hierarchy transform
483396 GLTFVertex vert;
484- vert.position = glm::vec3 (
485- (transformed_pos.x + center_offset.mV [VX]) * scale_factor,
486- (transformed_pos.y + center_offset.mV [VY]) * scale_factor,
487- (transformed_pos.z + center_offset.mV [VZ]) * scale_factor
488- );
397+ vert.position = glm::vec3 (transformed_pos.x , transformed_pos.y , transformed_pos.z );
489398
490399 // Also rotate the normal vector
491400 glm::vec4 normal_vec (prim.mNormals [i][0 ], prim.mNormals [i][1 ], prim.mNormals [i][2 ], 0 .0f );
0 commit comments