Przeglądaj źródła

Merge pull request #20148 from mcneel/wip/3dmLoader

Editor: Add 3dm import
Mr.doob 5 lat temu
rodzic
commit
39551eede7
3 zmienionych plików z 28 dodań i 7 usunięć
  1. 20 0
      editor/js/Loader.js
  2. 4 0
      editor/sw.js
  3. 4 7
      examples/jsm/loaders/3DMLoader.js

+ 20 - 0
editor/js/Loader.js

@@ -16,6 +16,7 @@ import { SVGLoader } from '../../examples/jsm/loaders/SVGLoader.js';
 import { TDSLoader } from '../../examples/jsm/loaders/TDSLoader.js';
 import { VTKLoader } from '../../examples/jsm/loaders/VTKLoader.js';
 import { VRMLLoader } from '../../examples/jsm/loaders/VRMLLoader.js';
+import { Rhino3dmLoader } from '../../examples/jsm/loaders/3DMLoader.js';
 
 import { TGALoader } from '../../examples/jsm/loaders/TGALoader.js';
 
@@ -94,6 +95,25 @@ function Loader( editor ) {
 
 		switch ( extension ) {
 
+			case '3dm':
+
+				reader.addEventListener( 'load', function ( event ) {
+
+					var contents = event.target.result;
+
+					var loader = new Rhino3dmLoader();
+					loader.setLibraryPath( '../examples/jsm/libs/rhino3dm/' );
+					loader.parse( contents, function ( object ) {
+
+						editor.execute( new AddObjectCommand( editor, object ) );
+
+					} );
+
+				}, false );
+				reader.readAsArrayBuffer( file );
+
+				break;
+
 			case '3ds':
 
 				reader.addEventListener( 'load', function ( event ) {

+ 4 - 0
editor/sw.js

@@ -25,6 +25,10 @@ const assets = [
 	'../examples/js/libs/draco/gltf/draco_decoder.wasm',
 	'../examples/js/libs/draco/gltf/draco_wasm_wrapper.js',
 
+	'../examples/jsm/libs/rhino3dm/rhino3dm.wasm',
+	'../examples/jsm/libs/rhino3dm/rhino3dm.js',
+
+	'../examples/jsm/loaders/3DMLoader.js',
 	'../examples/jsm/loaders/3MFLoader.js',
 	'../examples/jsm/loaders/AMFLoader.js',
 	'../examples/jsm/loaders/ColladaLoader.js',

+ 4 - 7
examples/jsm/loaders/3DMLoader.js

@@ -1,7 +1,3 @@
-/**
- * @author Luis Fraguada / https://github.com/fraguada
- */
-
 import {
 	BufferGeometryLoader,
 	FileLoader,
@@ -146,10 +142,11 @@ Rhino3dmLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
 
 	},
 
-	parse: function () {
+	parse: function ( data, onLoad, onError ) {
 
-		// parsing logic goes here
-		console.warn( 'THREE.3DMLoader: TODO: Implement parse function' );
+		this.decodeObjects( data, '' )
+			.then( onLoad )
+			.catch( onError );
 
 	},