Skip to content

Commit b67bf42

Browse files
committed
Update model scaling logic to get largest dimension instead of just height for re-scaling
1 parent 4fe27d3 commit b67bf42

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/lib/processes/load-model/StepLoadModel.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -233,18 +233,23 @@ export class StepLoadModel extends EventTarget {
233233
let scale_factor: number = 1.0
234234

235235
// calculate all the meshes to find out the max height
236+
// some models are more wide like a bird, so don't just use height for this calculation
236237
const bounding_box = this.calculate_bounding_box(scene_object)
237238
const height = bounding_box.max.y - bounding_box.min.y
239+
const width = bounding_box.max.x - bounding_box.min.x
240+
const depth = bounding_box.max.z - bounding_box.min.z
238241

239-
// if model is very large, or very small, scale it to 1.0 to help with application
240-
if (height > 0.1 && height < 4) {
241-
console.log('Model a reasonable size, so no scaling applied: ', height, ' height')
242+
const largest_dimension = Math.max(height, width, depth)
243+
244+
// if model is very large, or very small, scale it to 1.5 to help with application
245+
if (largest_dimension > 0.5 && largest_dimension < 8) {
246+
console.log('Model a reasonable size, so no scaling applied: ', largest_dimension, ' units is largest dimension')
242247
return
243248
} else {
244-
console.log('Model is very large or small, so scaling applied: ', height, ' height')
249+
console.log('Model is very large or small, so scaling applied: ', largest_dimension, ' units is largest dimension')
245250
}
246251

247-
scale_factor = 1.0 / height // goal is to scale the model to 1.0 height
252+
scale_factor = 1.5 / height // goal is to scale the model to 1.5 units height (similar to skeleton proportions)
248253

249254
// scale all the meshes down by the calculated amount
250255
scene_object.traverse((child) => {

0 commit comments

Comments
 (0)