Skip to content
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
79 changes: 76 additions & 3 deletions examples/jsm/loaders/VTKLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,6 @@ class VTKLoader extends Loader {

} else {


indices[ indicesIndex ++ ] = strip[ j ];
indices[ indicesIndex ++ ] = strip[ j + 1 ];
indices[ indicesIndex ++ ] = strip[ j + 2 ];
Expand Down Expand Up @@ -620,7 +619,17 @@ class VTKLoader extends Loader {

const tmp = xmlToJson( item );

if ( tmp !== '' ) obj[ nodeName ] = tmp;
if ( tmp !== '' ) {

if ( Array.isArray( tmp[ '#text' ] ) ) {

tmp[ '#text' ] = tmp[ '#text' ][ 0 ];

}

obj[ nodeName ] = tmp;

}

} else {

Expand All @@ -633,7 +642,17 @@ class VTKLoader extends Loader {

const tmp = xmlToJson( item );

if ( tmp !== '' ) obj[ nodeName ].push( tmp );
if ( tmp !== '' ) {

if ( Array.isArray( tmp[ '#text' ] ) ) {

tmp[ '#text' ] = tmp[ '#text' ][ 0 ];

}

obj[ nodeName ].push( tmp );

}

}

Expand Down Expand Up @@ -894,6 +913,60 @@ class VTKLoader extends Loader {
let normals = [];
let indices = [];

if ( json.AppendedData ) {

const appendedData = json.AppendedData[ '#text' ].slice( 1 );
const piece = json.PolyData.Piece;

const sections = [ 'PointData', 'CellData', 'Points', 'Verts', 'Lines', 'Strips', 'Polys' ];
let sectionIndex = 0;

const offsets = sections.map( s => {

const sect = piece[ s ];

if ( sect && sect.DataArray ) {

const arr = Array.isArray( sect.DataArray ) ? sect.DataArray : [ sect.DataArray ];

return arr.map( a => a.attributes.offset );

}

return [];

} ).flat();

for ( const sect of sections ) {

const section = piece[ sect ];

if ( section && section.DataArray ) {

if ( Array.isArray( section.DataArray ) ) {

for ( const sectionEle of section.DataArray ) {

sectionEle[ '#text' ] = appendedData.slice( offsets[ sectionIndex ], offsets[ sectionIndex + 1 ] );
sectionEle.attributes.format = 'binary';
sectionIndex ++;

}

} else {

section.DataArray[ '#text' ] = appendedData.slice( offsets[ sectionIndex ], offsets[ sectionIndex + 1 ] );
section.DataArray.attributes.format = 'binary';
sectionIndex ++;

}

}

}

}

if ( json.PolyData ) {

const piece = json.PolyData.Piece;
Expand Down