diff --git a/src/math/Matrix4.js b/src/math/Matrix4.js index d0ad3d41c49830..471f9295278253 100644 --- a/src/math/Matrix4.js +++ b/src/math/Matrix4.js @@ -234,6 +234,16 @@ class Matrix4 { */ extractBasis( xAxis, yAxis, zAxis ) { + if ( this.determinant() === 0 ) { + + xAxis.set( 1, 0, 0 ); + yAxis.set( 0, 1, 0 ); + zAxis.set( 0, 0, 1 ); + + return this; + + } + xAxis.setFromMatrixColumn( this, 0 ); yAxis.setFromMatrixColumn( this, 1 ); zAxis.setFromMatrixColumn( this, 2 ); @@ -274,6 +284,12 @@ class Matrix4 { */ extractRotation( m ) { + if ( m.determinant() === 0 ) { + + return this.identity(); + + } + const te = this.elements; const me = m.elements; @@ -1026,6 +1042,19 @@ class Matrix4 { const te = this.elements; + position.x = te[ 12 ]; + position.y = te[ 13 ]; + position.z = te[ 14 ]; + + if ( this.determinant() === 0 ) { + + scale.set( 1, 1, 1 ); + quaternion.identity(); + + return this; + + } + let sx = _v1.set( te[ 0 ], te[ 1 ], te[ 2 ] ).length(); const sy = _v1.set( te[ 4 ], te[ 5 ], te[ 6 ] ).length(); const sz = _v1.set( te[ 8 ], te[ 9 ], te[ 10 ] ).length(); @@ -1034,10 +1063,6 @@ class Matrix4 { const det = this.determinant(); if ( det < 0 ) sx = - sx; - position.x = te[ 12 ]; - position.y = te[ 13 ]; - position.z = te[ 14 ]; - // scale the rotation part _m1.copy( this ); diff --git a/src/renderers/webgl-fallback/WebGLBackend.js b/src/renderers/webgl-fallback/WebGLBackend.js index 167ef97af0cb0f..7b420c1eda1b80 100644 --- a/src/renderers/webgl-fallback/WebGLBackend.js +++ b/src/renderers/webgl-fallback/WebGLBackend.js @@ -815,7 +815,7 @@ class WebGLBackend extends Backend { if ( this.discard === false ) { // required here to handle async behaviour of render.compute() - gl.enable( gl.RASTERIZER_DISCARD ); + state.enable( gl.RASTERIZER_DISCARD ); this.discard = true; } @@ -901,11 +901,11 @@ class WebGLBackend extends Backend { */ finishCompute( computeGroup ) { - const gl = this.gl; + const { state, gl } = this; this.discard = false; - gl.disable( gl.RASTERIZER_DISCARD ); + state.disable( gl.RASTERIZER_DISCARD ); this.prepareTimestampBuffer( TimestampQuery.COMPUTE, this.getTimestampUID( computeGroup ) ); diff --git a/src/renderers/webgl-fallback/utils/WebGLState.js b/src/renderers/webgl-fallback/utils/WebGLState.js index 556a6ef763c00d..d9e5d5bf820c8c 100644 --- a/src/renderers/webgl-fallback/utils/WebGLState.js +++ b/src/renderers/webgl-fallback/utils/WebGLState.js @@ -625,11 +625,11 @@ class WebGLState { if ( boolean ) { - gl.enable( gl.SCISSOR_TEST ); + this.enable( gl.SCISSOR_TEST ); } else { - gl.disable( gl.SCISSOR_TEST ); + this.disable( gl.SCISSOR_TEST ); } diff --git a/src/renderers/webgl-fallback/utils/WebGLTextureUtils.js b/src/renderers/webgl-fallback/utils/WebGLTextureUtils.js index f6da1850f5ea10..41846e7ec63005 100644 --- a/src/renderers/webgl-fallback/utils/WebGLTextureUtils.js +++ b/src/renderers/webgl-fallback/utils/WebGLTextureUtils.js @@ -488,7 +488,7 @@ class WebGLTextureUtils { backend.state.unbindTexture(); // debug // const framebuffer = gl.createFramebuffer(); - // gl.bindFramebuffer( gl.FRAMEBUFFER, framebuffer ); + // backend.state.bindFramebuffer( gl.FRAMEBUFFER, framebuffer ); // gl.framebufferTexture2D( gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, glTextureType, textureGPU, 0 ); // const readout = new Float32Array( width * height * 4 ); @@ -497,7 +497,7 @@ class WebGLTextureUtils { // const altType = gl.getParameter( gl.IMPLEMENTATION_COLOR_READ_TYPE ); // gl.readPixels( 0, 0, width, height, altFormat, altType, readout ); - // gl.bindFramebuffer( gl.FRAMEBUFFER, null ); + // backend.state.bindFramebuffer( gl.FRAMEBUFFER, null ); // log( readout ); } @@ -1183,7 +1183,7 @@ class WebGLTextureUtils { const fb = gl.createFramebuffer(); - gl.bindFramebuffer( gl.READ_FRAMEBUFFER, fb ); + backend.state.bindFramebuffer( gl.READ_FRAMEBUFFER, fb ); const target = texture.isCubeTexture ? gl.TEXTURE_CUBE_MAP_POSITIVE_X + faceIndex : gl.TEXTURE_2D; @@ -1210,6 +1210,8 @@ class WebGLTextureUtils { gl.getBufferSubData( gl.PIXEL_PACK_BUFFER, 0, dstBuffer ); gl.bindBuffer( gl.PIXEL_PACK_BUFFER, null ); + backend.state.bindFramebuffer( gl.READ_FRAMEBUFFER, null ); + gl.deleteFramebuffer( fb ); return dstBuffer;