123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175 |
- /**
- * @author Luis Fraguada / https://github.com/fraguada
- */
- import {
- BufferAttribute,
- BufferGeometry,
- FileLoader,
- Loader
- } from "../../../build/three.module.js";
- var Rhino3dmLoader = function ( manager ) {
- Loader.call( this, manager );
- this.libraryPath = '';
- this.libraryPending = null;
- this.libraryBinary = null;
- };
- Rhino3dmLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
- constructor: Rhino3dmLoader,
- setLibraryPath: function ( path ) {
- this.libraryPath = path;
- return this;
- },
- load: function ( url, onLoad, onProgress, onError ) {
- var scope = this;
- var path = ( this.path !== undefined ) ? this.path : LoaderUtils.extractUrlBase( url );
- var loader = new FileLoader( scope.manager );
- loader.load( url, function ( text ) {
- try {
- scope.parse( text, path, onLoad, onError );
- } catch ( e ) {
- if ( onError !== undefined ) {
- onError( e );
- } else {
- throw e;
- }
- }
- }, onProgress, onError );
- },
- parse: function ( ) {
- // parsing logic goes here
- console.log('3dm parsing');
- },
- _initLibrary: function () {
- if ( ! this.libraryPending ) {
- // Load transcoder wrapper.
- var jsLoader = new FileLoader( this.manager );
- jsLoader.setPath( this.libraryPath );
- var jsContent = new Promise( ( resolve, reject ) => {
- jsLoader.load( 'rhino3dm.js', resolve, undefined, reject );
- } );
- // Load transcoder WASM binary.
- var binaryLoader = new FileLoader( this.manager );
- binaryLoader.setPath( this.libraryPath );
- binaryLoader.setResponseType( 'arraybuffer' );
- var binaryContent = new Promise( ( resolve, reject ) => {
- binaryLoader.load( 'rhino3dm.wasm', resolve, undefined, reject );
- } );
- this.libraryPending = Promise.all( [ jsContent, binaryContent ] )
- .then( ( [ jsContent, binaryContent ] ) => {
- var fn = Rhino3dmLoader.Rhino3dmWorker.toString();
- var body = [
- '/* rhino3dm.js */',
- jsContent,
- '/* worker */',
- fn.substring( fn.indexOf( '{' ) + 1, fn.lastIndexOf( '}' ) )
- ].join( '\n' );
- this.workerSourceURL = URL.createObjectURL( new Blob( [ body ] ) );
- this.libraryBinary = binaryContent;
- } );
- }
- return this.libraryPending;
- }
- } );
- /* WEB WORKER */
- Rhino3dmLoader.Rhino3dmWorker = function () {
- var libraryConfig;
- var libraryPending;
- var _RhinoFile;
- onmessage = function ( e ) {
- var message = e.data;
- switch ( message.type ) {
- case 'init':
- libraryPending = new Promise( function ( resolve/*, reject*/ ) {
- libraryPending.onModuleLoaded = function ( draco ) {
- // Module is Promise-like. Wrap before resolving to avoid loop.
- resolve( { rhino3dm: rhino3dm } );
- };
- //DracoDecoderModule( decoderConfig );
- } );
- break;
- case 'decode':
- break;
- }
- }
- function init( wasmBinary ) {
- var rhino3dmModule;
- libraryPending = new Promise( ( resolve ) => {
- rhino3dmModule = { wasmBinary, onRuntimeInitialized: resolve };
- //BASIS( rhino3dmModule );
- } ).then( () => {
- var { BasisFile, initializeBasis } = rhino3dmModule;
- _RhinoFile = BasisFile;
- //initializeBasis();
- } );
- }
- };
- export { Rhino3dmLoader };
|