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
8 changes: 4 additions & 4 deletions examples/jsm/exporters/GLTFExporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -1852,12 +1852,12 @@ class GLTFWriter {
! ( array instanceof Uint8Array ) ) {

console.warn( 'GLTFExporter: Attribute "skinIndex" converted to type UNSIGNED_SHORT.' );
modifiedAttribute = new BufferAttribute( new Uint16Array( array ), attribute.itemSize, attribute.normalized );
modifiedAttribute = GLTFExporter.Utils.toTypedBufferAttribute( attribute, Uint16Array );

} else if ( ( array instanceof Uint32Array || array instanceof Int32Array ) && ! attributeName.startsWith( '_' ) ) {

console.warn( `GLTFExporter: Attribute "${ attributeName }" converted to type FLOAT.` );
modifiedAttribute = GLTFExporter.Utils.toFloat32BufferAttribute( attribute );
modifiedAttribute = GLTFExporter.Utils.toTypedBufferAttribute( attribute, Float32Array );

}

Expand Down Expand Up @@ -3538,9 +3538,9 @@ GLTFExporter.Utils = {

},

toFloat32BufferAttribute: function ( srcAttribute ) {
toTypedBufferAttribute: function ( srcAttribute, TypedArray ) {

const dstAttribute = new BufferAttribute( new Float32Array( srcAttribute.count * srcAttribute.itemSize ), srcAttribute.itemSize, false );
const dstAttribute = new BufferAttribute( new TypedArray( srcAttribute.count * srcAttribute.itemSize ), srcAttribute.itemSize, false );

if ( ! srcAttribute.normalized && ! srcAttribute.isInterleavedBufferAttribute ) {

Expand Down
57 changes: 35 additions & 22 deletions examples/jsm/loaders/VTKLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,20 @@ class VTKLoader extends Loader {
// pattern for detecting the end of a number sequence
const patWord = /^[^\d.\s-]+/;

// pattern for reading vertices, 3 floats or integers
const pat3Floats = /(\-?\d+\.?[\d\-\+e]*)\s+(\-?\d+\.?[\d\-\+e]*)\s+(\-?\d+\.?[\d\-\+e]*)/g;
function parseFloats( line ) {

const result = [];
const parts = line.split( /\s+/ );

for ( let i = 0; i < parts.length; i ++ ) {

if ( parts[ i ] !== '' ) result.push( parseFloat( parts[ i ] ) );

}

return result;

}

// pattern for connectivity, an integer followed by any number of ints
// the first integer is the number of polygon nodes
Expand Down Expand Up @@ -165,14 +177,15 @@ class VTKLoader extends Loader {
} else if ( inPointsSection ) {

// get the vertices
while ( ( result = pat3Floats.exec( line ) ) !== null ) {
if ( patWord.exec( line ) === null ) {

if ( patWord.exec( line ) !== null ) break;
const values = parseFloats( line );

const x = parseFloat( result[ 1 ] );
const y = parseFloat( result[ 2 ] );
const z = parseFloat( result[ 3 ] );
positions.push( x, y, z );
for ( let k = 0; k + 2 < values.length; k += 3 ) {

positions.push( values[ k ], values[ k + 1 ], values[ k + 2 ] );

}

}

Expand Down Expand Up @@ -243,32 +256,32 @@ class VTKLoader extends Loader {

// Get the colors

while ( ( result = pat3Floats.exec( line ) ) !== null ) {
if ( patWord.exec( line ) === null ) {

if ( patWord.exec( line ) !== null ) break;
const values = parseFloats( line );

const r = parseFloat( result[ 1 ] );
const g = parseFloat( result[ 2 ] );
const b = parseFloat( result[ 3 ] );
for ( let k = 0; k + 2 < values.length; k += 3 ) {

color.setRGB( r, g, b, SRGBColorSpace );
color.setRGB( values[ k ], values[ k + 1 ], values[ k + 2 ], SRGBColorSpace );
colors.push( color.r, color.g, color.b );

colors.push( color.r, color.g, color.b );
}

}

} else if ( inNormalsSection ) {

// Get the normal vectors

while ( ( result = pat3Floats.exec( line ) ) !== null ) {
if ( patWord.exec( line ) === null ) {

if ( patWord.exec( line ) !== null ) break;
const values = parseFloats( line );

const nx = parseFloat( result[ 1 ] );
const ny = parseFloat( result[ 2 ] );
const nz = parseFloat( result[ 3 ] );
normals.push( nx, ny, nz );
for ( let k = 0; k + 2 < values.length; k += 3 ) {

normals.push( values[ k ], values[ k + 1 ], values[ k + 2 ] );

}

}

Expand Down Expand Up @@ -400,7 +413,7 @@ class VTKLoader extends Loader {
let index = start;
let c = buffer[ index ];
const s = [];
while ( c !== 10 ) {
while ( c !== 10 && index < buffer.length ) {

s.push( String.fromCharCode( c ) );
index ++;
Expand Down
17 changes: 9 additions & 8 deletions src/renderers/WebGLRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2988,6 +2988,10 @@ class WebGLRenderer {
const textureFormat = texture.format;
const textureType = texture.type;

// when using MRT, select the correct color buffer for the subsequent read command

if ( renderTarget.textures.length > 1 ) _gl.readBuffer( _gl.COLOR_ATTACHMENT0 + textureIndex );

if ( ! capabilities.textureFormatReadable( textureFormat ) ) {

error( 'WebGLRenderer.readRenderTargetPixels: renderTarget is not in RGBA or implementation defined format.' );
Expand All @@ -3006,10 +3010,6 @@ class WebGLRenderer {

if ( ( x >= 0 && x <= ( renderTarget.width - width ) ) && ( y >= 0 && y <= ( renderTarget.height - height ) ) ) {

// when using MRT, select the correct color buffer for the subsequent read command

if ( renderTarget.textures.length > 1 ) _gl.readBuffer( _gl.COLOR_ATTACHMENT0 + textureIndex );

_gl.readPixels( x, y, width, height, utils.convert( textureFormat ), utils.convert( textureType ), buffer );

}
Expand Down Expand Up @@ -3070,6 +3070,11 @@ class WebGLRenderer {
const textureFormat = texture.format;
const textureType = texture.type;

// when using MRT, select the correct color buffer for the subsequent read command

if ( renderTarget.textures.length > 1 ) _gl.readBuffer( _gl.COLOR_ATTACHMENT0 + textureIndex );


if ( ! capabilities.textureFormatReadable( textureFormat ) ) {

throw new Error( 'THREE.WebGLRenderer.readRenderTargetPixelsAsync: renderTarget is not in RGBA or implementation defined format.' );
Expand All @@ -3086,10 +3091,6 @@ class WebGLRenderer {
_gl.bindBuffer( _gl.PIXEL_PACK_BUFFER, glBuffer );
_gl.bufferData( _gl.PIXEL_PACK_BUFFER, buffer.byteLength, _gl.STREAM_READ );

// when using MRT, select the correct color buffer for the subsequent read command

if ( renderTarget.textures.length > 1 ) _gl.readBuffer( _gl.COLOR_ATTACHMENT0 + textureIndex );

_gl.readPixels( x, y, width, height, utils.convert( textureFormat ), utils.convert( textureType ), 0 );

// reset the frame buffer to the currently set buffer before waiting
Expand Down