Skip to content

Commit

Permalink
CSS3DRenderer: Fix positioning bugs in Chrome and Firefox
Browse files Browse the repository at this point in the history
  • Loading branch information
donmccurdy committed Oct 20, 2023
1 parent 7f351a0 commit 4b97cdc
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions examples/jsm/renderers/CSS3DRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class CSS3DRenderer {
let _widthHalf, _heightHalf;

const cache = {
camera: { fov: 0, style: '' },
camera: { style: '' },
objects: new WeakMap()
};

Expand Down Expand Up @@ -129,13 +129,6 @@ class CSS3DRenderer {

const fov = camera.projectionMatrix.elements[ 5 ] * _heightHalf;

if ( cache.camera.fov !== fov ) {

viewElement.style.perspective = camera.isPerspectiveCamera ? fov + 'px' : '';
cache.camera.fov = fov;

}

if ( camera.view && camera.view.enabled ) {

// view offset
Expand Down Expand Up @@ -166,8 +159,9 @@ class CSS3DRenderer {
const cameraCSSMatrix = camera.isOrthographicCamera ?
`scale( ${ scaleByViewOffset } )` + 'scale(' + fov + ')' + 'translate(' + epsilon( tx ) + 'px,' + epsilon( ty ) + 'px)' + getCameraCSSMatrix( camera.matrixWorldInverse ) :
`scale( ${ scaleByViewOffset } )` + 'translateZ(' + fov + 'px)' + getCameraCSSMatrix( camera.matrixWorldInverse );
const perspective = camera.isPerspectiveCamera ? 'perspective(' + fov + 'px) ' : '';

const style = cameraCSSMatrix +
const style = perspective + cameraCSSMatrix +
'translate(' + _widthHalf + 'px,' + _heightHalf + 'px)';

if ( cache.camera.style !== style ) {
Expand Down

0 comments on commit 4b97cdc

Please sign in to comment.