Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(CSS3DRenderer): modify perspective transform to avoid browser issues #308

Merged
merged 1 commit into from
Nov 3, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading