TAGS :Viewed: 9 - Published at: a few seconds ago

[ How to set the scale value in pixel size? ]

How to set the object scale value(width and height) based on the pixel value using three.js


i need to set 0.05 value pixel size

Please help any one.

Answer 1

Rephrasing your question, please correct me if I got you wrong:

You want to use pixel values instead of the relative values to set the size of your object as it appears on screen.

Now, the problem here is, that three.js (or even webgl) don't really use a concept of pixels internally.

How large (in pixels) an object appears on the screen depends on a lot of factors:

  • the css-size of the canvas element and the devicePixelRatio
  • the width and height of the canvas element
  • obviously the size of the object
  • the camera-position and other properties (aspect-ratio, field-of-view, relative orientation and position to object)

So pixels will simply lose any meaning when it comes to 3D-graphics. There's nothing keeping you from using any unit you want for sizes and positions, but that doesn't make it have any relation to pixels on screen.

You will also want to check out this answer: THREE.JS: Get object size with respect to camera and object position on screen