Skip to content
Merged
Show file tree
Hide file tree
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
33 changes: 29 additions & 4 deletions src/math/Matrix4.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down Expand Up @@ -274,6 +284,12 @@ class Matrix4 {
*/
extractRotation( m ) {

if ( m.determinant() === 0 ) {

return this.identity();

}

const te = this.elements;
const me = m.elements;

Expand Down Expand Up @@ -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();
Expand All @@ -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 );

Expand Down
6 changes: 3 additions & 3 deletions src/renderers/webgl-fallback/WebGLBackend.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

}
Expand Down Expand Up @@ -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 ) );

Expand Down
4 changes: 2 additions & 2 deletions src/renderers/webgl-fallback/utils/WebGLState.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 );

}

Expand Down
8 changes: 5 additions & 3 deletions src/renderers/webgl-fallback/utils/WebGLTextureUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand All @@ -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 );

}
Expand Down Expand Up @@ -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;

Expand All @@ -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;
Expand Down