Skip to content

Commit

Permalink
fix(CSS3DRenderer): modify perspective transform to avoid browser iss…
Browse files Browse the repository at this point in the history
…ues (#308)
  • Loading branch information
CodyJasonBennett authored Nov 3, 2023
1 parent 6441de6 commit 4f06413
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions src/renderers/CSS3DRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class CSS3DRenderer {
let _widthHalf, _heightHalf

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

Expand Down Expand Up @@ -101,11 +101,6 @@ class CSS3DRenderer {
this.render = function (scene, camera) {
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
viewElement.style.transform = `translate( ${-camera.view.offsetX * (_width / camera.view.width)}px, ${
Expand Down Expand Up @@ -143,8 +138,9 @@ class CSS3DRenderer {
'px)' +
getCameraCSSMatrix(camera.matrixWorldInverse)
: `scale( ${scaleByViewOffset} )` + 'translateZ(' + fov + 'px)' + getCameraCSSMatrix(camera.matrixWorldInverse)
const perspective = camera.isPerspectiveCamera ? 'perspective(' + fov + 'px) ' : ''

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

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

0 comments on commit 4f06413

Please sign in to comment.