Does Three have any kind of independent unit? I understand that a unit in Three is abstract, but scale.set seems to be relative to the models imported size

So basically, if I had two chairs created in Blender, which has real-world scales set.

Here’s an example

“Small Chair” is 1.5 metres tall.
“Big Chair” is 25 metres tall.

Three will see "Small Chair"s scale as 1. Three will also see "Big Chair"s scale as 1. Is there a unit that see’s the difference (world scale?)

Here’s what I’m trying to achieve. Say I have a cube in my initial scene. This cube is in theory 1 metre tall and its scale is 1,1,1.

If I import either of my chairs, what property am I looking to alter to make both my chairs be the same height as the cube, as each other, and its height equal to the independent unit ‘1’.

Hi!
Take a look at this post and whole topic: Why does scale and setting geometry looks different?

If your chair is 25 units tall and you want it to be fitted in 1 unit, then scaling is: model.scale.setScalar(1/25);

Thanks, but what if I don’t know what Big Chairs scale is? What if the model is supplied by a download on some CAD website, and I don’t know the scale (or better yet, the end user of the tool I’m creating) doesn’t know the scale of that object before loading it?

One idea I had was to have an invisible imposter box in the scene that I copy the scale from, but I don’t know if that’s a thing or if it’d even work.

Use var box = new THREE.Box3().setFromObject( model );
then something like this from scratch:

var size = new THREE.Vector3();
box.getSize( size );
var scaleVec = new THREE.Vector3().divide( size );
var scale = Math.min( scaleVec.x, Math.min( saleVec.y, scaleVec.z );
model.scale.setScalar( scale );
2 Likes

Legend, thanks mate

You’re welcome. :beers:
Hope it helps :slight_smile:

1 Like

Hey mate, it seems to set the scale to 0

Here’s the walkthrough

  const box = new Box3().setFromObject(model);
  /** 
  * box Box3 {min: Vector3, max: Vector3}
   max: Vector3 {x: 0.4365261477323296, y: 1.2794534378966684, z: 0.5277511065088767}
   min: Vector3 {x: -0.43155783968249595, y: 0.0004506949421276829, z: -0.5522331090289871}
  *
  */

  const size = new Vector3();
  /** 
  * size Vector3 {x: 0, y: 0, z: 0}
     x: 0.8680839874148256
     y: 1.2790027429545408
     z: 1.0799842155378638
  *
  */

  box.getSize(size);
  /** NOTE THAT BOX HASN'T CHANGED
  * box Box3 {min: Vector3, max: Vector3}
   max: Vector3 {x: 0.4365261477323296, y: 1.2794534378966684, z: 0.5277511065088767}
   min: Vector3 {x: -0.43155783968249595, y: 0.0004506949421276829, z: -0.5522331090289871}
  *
  */
  const scaleVec = new Vector3().divide(size);
  /** 
  * scaleVec Vector3 {x: 0, y: 0, z: 0}
    x: 0
    y: 0
    z: 0
  *
  */
  const scale = Math.min(scaleVec.x, Math.min(scaleVec.y, scaleVec.z));
  // scale 0

  model.scale.setScalar(scale);

Perhaps I’ve done something wrong?

No :slight_smile:
I’ve done something wrong.
This line
var scaleVec = new THREE.Vector3().divide( size );
must be like this:
var scaleVec = new THREE.Vector3( 1, 1, 1 ).divide( size );

2 Likes

HAH! It worked, what a legend maneuver

2 Likes

I have to zoom in 100 times to see the model, and the model is a little bit small.
Did I do something wrong .

@seanin Any chance to provide an editable working live code example, that demonstrates the issue?

demo:https://pgn1y.csb.app/
code: confident-dew-pgn1y - CodeSandbox

I don’t know why model doesn’t show up in the demo.
But the scale data in the developer tools is the same.

1 Like