|
@@ -156,9 +156,12 @@ Rhino3dmLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
|
|
|
|
|
|
parse: function ( data, onLoad, onError ) {
|
|
|
|
|
|
- if ( ! ( data instanceof ArrayBuffer ) ) {
|
|
|
+ // issue: https://github.com/mcneel/rhino3dm/issues/338
|
|
|
+ // issue: https://github.com/emscripten-core/emscripten/issues/13065
|
|
|
|
|
|
- data = this._objToUint( data ).buffer;
|
|
|
+ if ( data instanceof Uint8Array ) {
|
|
|
+
|
|
|
+ data = new Uint8Array( data ).buffer;
|
|
|
|
|
|
}
|
|
|
|
|
@@ -168,23 +171,6 @@ Rhino3dmLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
|
|
|
|
|
|
},
|
|
|
|
|
|
- // from https://stackoverflow.com/questions/35971566/store-a-json-object-in-arraybuffer/35971686#35971686
|
|
|
- _objToUint: function ( obj ) {
|
|
|
-
|
|
|
- var string = btoa( unescape( JSON.stringify( obj ) ) ),
|
|
|
- charList = string.split( '' ),
|
|
|
- uintArray = [];
|
|
|
-
|
|
|
- for ( var i = 0; i < charList.length; i ++ ) {
|
|
|
-
|
|
|
- uintArray.push( charList[ i ].charCodeAt( 0 ) );
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- return new Uint8Array( uintArray );
|
|
|
-
|
|
|
- },
|
|
|
-
|
|
|
_compareMaterials: function ( material ) {
|
|
|
|
|
|
var mat = {};
|
|
@@ -856,16 +842,6 @@ Rhino3dmLoader.Rhino3dmWorker = function () {
|
|
|
|
|
|
};
|
|
|
|
|
|
- // from https://stackoverflow.com/questions/35971566/store-a-json-object-in-arraybuffer/35971686#35971686
|
|
|
- function uintToObj( uintArray ) {
|
|
|
-
|
|
|
- var encodedString = String.fromCharCode.apply( null, uintArray ),
|
|
|
- decodedString = decodeURIComponent( escape( atob( encodedString ) ) );
|
|
|
-
|
|
|
- return JSON.parse( decodedString );
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
function decodeObjects( rhino, buffer ) {
|
|
|
|
|
|
var arr = new Uint8Array( buffer );
|
|
@@ -880,15 +856,6 @@ Rhino3dmLoader.Rhino3dmWorker = function () {
|
|
|
|
|
|
//Handle objects
|
|
|
|
|
|
- if ( doc === null ) {
|
|
|
-
|
|
|
- doc = new rhino.File3dm();
|
|
|
- var obj = uintToObj( arr );
|
|
|
- var rObj = rhino.CommonObject.decode( obj );
|
|
|
- doc.objects().add( rObj, null );
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
var objs = doc.objects();
|
|
|
var cnt = objs.count;
|
|
|
|