소스 검색

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. BIN
      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( {
 			color: diffusecolor,
@@ -315,11 +315,18 @@ Rhino3dmLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
 
 				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 ) {
 
@@ -790,6 +797,13 @@ Rhino3dmLoader.Rhino3dmWorker = function () {
 
 			if ( object !== undefined ) {
 
+				if ( object.attributes.materialIndex >= 0 ) {
+
+					var mId = doc.materials().findIndex( object.attributes.materialIndex ).id;
+					object.attributes.materialUUID = mId;
+
+				}
+
 				objects.push( object );
 
 			}

BIN
examples/models/3dm/Rhino_Logo.3dm


+ 0 - 2
examples/webgl_loader_3dm.html

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