浏览代码

3DMLoader: Material Madnes

Adding MaterialUUID to the objects (attributes) that have a Rhino Material
Luis Fraguada 4 年之前
父节点
当前提交
466c007d85
共有 3 个文件被更改,包括 18 次插入6 次删除
  1. 18 4
      examples/jsm/loaders/3DMLoader.js
  2. 二进制
      examples/models/3dm/Rhino_Logo.3dm
  3. 0 2
      examples/webgl_loader_3dm.html

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

@@ -222,7 +222,7 @@ Rhino3dmLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
 
 
 		}
 		}
 
 
-		console.log( material );
+		// console.log( material );
 
 
 		var mat = new MeshStandardMaterial( {
 		var mat = new MeshStandardMaterial( {
 			color: diffusecolor,
 			color: diffusecolor,
@@ -315,11 +315,18 @@ Rhino3dmLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
 
 
 				default:
 				default:
 
 
-					var material = this._createMaterial( materials[ attributes.materialIndex ] );
+					if ( attributes.hasOwnProperty( 'materialUUID' ) ) {
 
 
-					material = this._compareMaterials( material );
+						var rMaterial = materials.find( m => m.id === attributes.materialUUID );
+						var material = this._createMaterial( rMaterial );
+						material = this._compareMaterials( material );
+						var _object = this._createObject( obj, material );
 
 
-					var _object = this._createObject( obj, material );
+					} else {
+
+						var _object = this._createObject( obj, null );
+
+					}
 
 
 					if ( _object === undefined ) {
 					if ( _object === undefined ) {
 
 
@@ -790,6 +797,13 @@ Rhino3dmLoader.Rhino3dmWorker = function () {
 
 
 			if ( object !== undefined ) {
 			if ( object !== undefined ) {
 
 
+				if ( object.attributes.materialIndex >= 0 ) {
+
+					var mId = doc.materials().findIndex( object.attributes.materialIndex ).id;
+					object.attributes.materialUUID = mId;
+
+				}
+
 				objects.push( object );
 				objects.push( object );
 
 
 			}
 			}

二进制
examples/models/3dm/Rhino_Logo.3dm


+ 0 - 2
examples/webgl_loader_3dm.html

@@ -39,8 +39,6 @@
 
 
 				scene = new THREE.Scene();
 				scene = new THREE.Scene();
 
 
-				scene.add( new THREE.AmbientLight( { intensity: 0.0001 } ) );
-
 				var directionalLight = new THREE.DirectionalLight( 0xffffff );
 				var directionalLight = new THREE.DirectionalLight( 0xffffff );
 				directionalLight.position.set( 0, 0, 2 );
 				directionalLight.position.set( 0, 0, 2 );
 				directionalLight.castShadow = true;
 				directionalLight.castShadow = true;