Getting real screen width in div / image pixels using Three.js and CSS3DRenderer

Really struggled with this. I have a program that uses the CSS3D Renderer of Three.js and I am trying to get the projected "real" screen width in pixels of a div (which contains one image).

I tried using getBoundingClientRect () on the image, but the width and height values ​​returned from this function are not correct. I guess it has to do with perspective.

I also tried this method, which gives me the exact coordinates of the center and is included in the message mrdoob: qaru.site/questions/200533 / ...

var width = window.innerWidth, height = window.innerHeight;
var widthHalf = width / 2, heightHalf = height / 2;

var projector = new THREE.Projector();
var vector = projector.projectVector( object.matrixWorld.getPosition().clone(), this.camera );

vector.x = ( vector.x * widthHalf ) + widthHalf;
vector.y = -( vector.y * heightHalf ) + heightHalf;

      

Unfortunately, all the methods I find for getting the top, left, or any corner of an object use geometry objects that CSS3DObject does not use (i.e. getting a vector of corner vertices and projecting those ref vectors: stack overflow / ... ).

Does anyone know how to do this? To be brief, I would just like to get the actual screen size of a div (which fits snugly against its img) in a Three.js CSS3D scene. In the end, I would like to determine if the camera image has changed more than its original pixel size.

Thank!

+1
javascript css3 3d three.js


source to share


No one has answered this question yet

See similar questions:

3
How to calculate the z-distance of a camera to view an image at 100% of its original scale in 3D space

or similar:

1904
Get the size of the screen, current web page and browser window
737
Using jQuery to center a DIV on the screen
499
Expand the div to fill the remaining width
sixteen
Three.js full screen problem
8
Javascript gets 100vh in pixels
1
How to position the camera so that the object always has the same pixel width and height on the screen?
0
Resize multiple PlaneBufferGeometries to fit images with Three.js
0
AFrame / Three.js - is there a way to get the dimensions in pixels of a 3D object to calculate the number of pixels per meter?
0
Get the real width and height of an image
0
Three.js - Create a CSS3D DIV demo in full screen mode



All Articles
Loading...
X
Show
Funny
Dev
Pics