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

Update 3MFLoader.js to use JSZip 3 (via jszip-sync) #17864

Closed
wants to merge 1 commit into from
Closed
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
36 changes: 23 additions & 13 deletions examples/js/loaders/3MFLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,17 @@ THREE.ThreeMFLoader.prototype = Object.assign( Object.create( THREE.Loader.proto

parse: function ( data ) {

function getZippedFileContentSync(zip, fileName, dataType) {
return zip.sync(() => {
let data;
zip
.file(fileName)
.async(dataType)
.then(_data => (data = _data));
return data;
});
}

var scope = this;
var textureLoader = new THREE.TextureLoader( this.manager );

Expand All @@ -69,18 +80,17 @@ THREE.ThreeMFLoader.prototype = Object.assign( Object.create( THREE.Loader.proto
var otherParts = {};

try {

zip = new JSZip( data ); // eslint-disable-line no-undef

} catch ( e ) {

if ( e instanceof ReferenceError ) {

console.error( 'THREE.3MFLoader: jszip missing and file is compressed.' );
zip = new JSZip(); // eslint-disable-line no-undef
zip.sync(() => {
JSZip.loadAsync(data).then(_zip => (zip = _zip));
});
} catch (e) {
if (e instanceof ReferenceError) {
console.error(
"THREE.3MFLoader: JSZip (sync) is missing and file is compressed. See https://www.npmjs.com/package/jszip-sync."
);
return null;

}

}

for ( file in zip.files ) {
Expand Down Expand Up @@ -115,15 +125,15 @@ THREE.ThreeMFLoader.prototype = Object.assign( Object.create( THREE.Loader.proto

//

var relsView = new Uint8Array( zip.file( relsName ).asArrayBuffer() );
var relsView = new Uint8Array( getZippedFileContentSync(zip, relsName, "arraybuffer") );
var relsFileText = THREE.LoaderUtils.decodeText( relsView );
rels = parseRelsXml( relsFileText );

//

if ( modelRelsName ) {

var relsView = new Uint8Array( zip.file( modelRelsName ).asArrayBuffer() );
var relsView = new Uint8Array( getZippedFileContentSync(zip, modelRelsName, "arraybuffer") );
var relsFileText = THREE.LoaderUtils.decodeText( relsView );
modelRels = parseRelsXml( relsFileText );

Expand All @@ -134,7 +144,7 @@ THREE.ThreeMFLoader.prototype = Object.assign( Object.create( THREE.Loader.proto
for ( var i = 0; i < modelPartNames.length; i ++ ) {

var modelPart = modelPartNames[ i ];
var view = new Uint8Array( zip.file( modelPart ).asArrayBuffer() );
var view = new Uint8Array( getZippedFileContentSync(zip, modelPart, "arraybuffer") );

var fileText = THREE.LoaderUtils.decodeText( view );
var xmlData = new DOMParser().parseFromString( fileText, 'application/xml' );
Expand Down