Three.js - Scale model with scale.set() or increase model size?

74,287

It is not a matter of best practice but rather of optimization. If your mesh will always be scaled, it is better if you do the scaling in your modeling software. That simple statement mesh.scale.set(2,2,2); is a matrix multiplication that needs to happen on each frame rendered. Now maybe your scene does not have much geometry in it in which case you don't care. But as I said it is a matter of optimization. What if your scene had 1000 such meshes or 1000000. That matrix multiplication would need to happen for each one of them. Optimize whenever you can.

Share:
74,287

Related videos on Youtube

jskidd3
Author by

jskidd3

Web developer from Southampton, United Kingdom.

Updated on July 15, 2020

Comments

  • jskidd3
    jskidd3 almost 4 years

    What is the best practise for scaling 3d models in Three.js (or other 3d renderers)?

    Here is an example I just faced:

    I load a model in and realise the size of the model is too small. I then scale the mesh using mesh.scale.set(2,2,2); and it is perfect size.

    What action should I take in this scenario, do I leave it scaled like that (programatically scaled) or do I go back to my 3d modelling software and double the size of the model?

    Thanks

  • WestLangley
    WestLangley almost 10 years
    gaitat - This is not correct. mesh.scale.set() is called once. By default, mesh.matrix is recomputed each frame anyway, regardless of the value of scale.
  • gaitat
    gaitat almost 10 years
    Yes but I assume that even in the interpreted javascript, multiplying by 1 is a no-op while multiplying by 2 is not.
  • Peter Ehrlich
    Peter Ehrlich over 9 years
    It would be interesting to see a proper performance test demonstrating this... any time I've tried similar things, there's been more randomness in the results than any discernible pattern. Not sure what the best way of running such a test is.
  • Agent Zebra
    Agent Zebra over 8 years
    @PeterEhrlich how would one set up such a performance test? o.O
  • Steven Lu
    Steven Lu over 8 years
    One thing that I might point out is you should be aware that mesh.scale.set(2,2,2) works while mesh.scale = new THREE.Vector3(2,2,2) does not. The reason is probably some internal caching being done in the mesh object.
  • Killroy
    Killroy almost 8 years
    You can "pre-scale" your geometry as well with mesh.geometry.scale(2, 2, 2). This happens only once and modifies the actual vertices in the geometry. Regarding above comment, mesh.scale.copy(new THREE.Vector3(2, 2, 2)) will work. Useful if you're re-using your scale vector.
  • 1owk3y
    1owk3y over 2 years
    Thanks @Killroy - I was using .geometry.scale.set()... didn't realise you could just .geometry.scale(). Wish your answer was more visible!