Ver código fonte

Merge pull request #20349 from mcneel/wip/3DMLoader

3DMLoader: Update
Mr.doob 4 anos atrás
pai
commit
6bad3dd667

+ 21 - 4
docs/examples/en/loaders/3DMLoader.html

@@ -15,7 +15,7 @@
 			A loader for Rhinoceros 3d files and objects. <br /><br />
 			Rhinoceros is a 3D modeler used to create, edit, analyze, document, render, animate, and translate NURBS curves, surfaces, solids, point clouds, as well as polygon meshes and SubD objects.
 			[link:https://github.com/mcneel/rhino3dm rhino3dm.js] is compiled to WebAssembly from the open source geometry library [link:https://github.com/mcneel/opennurbs openNURBS].
-
+			Currently uses rhino3dm.js 0.13.0
 		</p>
 
 		<h2>Supported Conversions</h2>
@@ -43,7 +43,7 @@
 			</tr>
 			<tr>
 				<td>Curve</td>
-				<td>[page:Line Line]</td>
+				<td>[page:Line Line] <sup>1</sup></td>
 			</tr>
 			<tr>
 				<td>Mesh</td>
@@ -51,11 +51,15 @@
 			</tr>
 			<tr>
 				<td>Extrusion</td>
-				<td>[page:Mesh Mesh]</td>
+				<td>[page:Mesh Mesh] <sup> 2</sup></td>
 			</tr>
 			<tr>
 				<td>BREP</td>
-				<td>[page:Object3D Object3D]</td>
+				<td>[page:Object3D Object3D] <sup>2, 3</sup></td>
+			</tr>
+			<tr>
+				<td>SubD</td>
+				<td>[page:Mesh Mesh] <sup>4</sup></td>
 			</tr>
 			<tr>
 				<td>InstanceReferences</td>
@@ -79,6 +83,19 @@
 			</tr>
 		</table>
 
+		<p><i>
+			<sup>1</sup> NURBS curves are discretized to a hardcoded resolution.
+		</i></p>
+		<p><i>
+			<sup>2</sup> Types which are based on BREPs and NURBS surfaces are represented with their "Render Mesh".
+		</i></p>
+		<p><i>
+			<sup>3</sup> BREPS are converted to an Object3D with it's children array populated with BREP Faces
+		</i></p>
+		<p><i>
+			<sup>4</sup> SubD objects are represented by subdividing their control net.
+		</i></p>
+
 		<h2>Code Example</h2>
 
 		<code>

Diferenças do arquivo suprimidas por serem muito extensas
+ 0 - 0
examples/jsm/libs/rhino3dm/rhino3dm.js


BIN
examples/jsm/libs/rhino3dm/rhino3dm.wasm


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

@@ -446,6 +446,7 @@ Rhino3dmLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
 
 			case 'Mesh':
 			case 'Extrusion':
+			case 'SubD':
 
 				var geometry = loader.parse( obj.geometry );
 
@@ -455,6 +456,13 @@ Rhino3dmLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
 
 				}
 
+				if ( mat === null ) {
+
+					mat = this._createMaterial();
+					mat = this._compareMaterials( mat );
+
+				}
+
 				var mesh = new Mesh( geometry, mat );
 				mesh.castShadow = attributes.castsShadows;
 				mesh.receiveShadow = attributes.receivesShadows;
@@ -509,8 +517,13 @@ Rhino3dmLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
 				var width = ctx.measureText( geometry.text ).width + 10;
 				var height = geometry.fontHeight + 10;
 
-				ctx.canvas.width = width;
-				ctx.canvas.height = height;
+				var r = window.devicePixelRatio;
+
+				ctx.canvas.width = width * r;
+				ctx.canvas.height = height * r;
+				ctx.canvas.style.width = width + 'px';
+				ctx.canvas.style.height = height + 'px';
+				ctx.setTransform( r, 0, 0, r, 0, 0 );
 
 				ctx.font = font;
 				ctx.textBaseline = 'middle';
@@ -548,7 +561,6 @@ Rhino3dmLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
 					light.castShadow = attributes.castsShadows;
 					light.position.set( geometry.location[ 0 ], geometry.location[ 1 ], geometry.location[ 2 ] );
 					light.target.position.set( geometry.direction[ 0 ], geometry.direction[ 1 ], geometry.direction[ 2 ] );
-
 					light.shadow.normalBias = 0.1;
 
 				} else if ( geometry.isPointLight ) {
@@ -592,6 +604,9 @@ Rhino3dmLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
 				if ( light ) {
 
 					light.intensity = geometry.intensity;
+					var _color = geometry.diffuse;
+					var color = new Color( _color.r / 255.0, _color.g / 255.0, _color.b / 255.0 );
+					light.color = color;
 					light.userData[ 'attributes' ] = attributes;
 					light.userData[ 'objectType' ] = obj.objectType;
 
@@ -1166,10 +1181,23 @@ Rhino3dmLoader.Rhino3dmWorker = function () {
 
 				break;
 
+			case rhino.ObjectType.SubD:
+
+				// TODO: precalculate resulting vertices and faces and warn on excessive results
+				_geometry.subdivide( 3 );
+				var mesh = rhino.Mesh.createFromSubDControlNet( _geometry );
+				if ( mesh ) {
+
+					geometry = mesh.toThreejsJSON();
+					mesh.delete();
+
+				}
+
+				break;
+
 				/*
 				case rhino.ObjectType.Annotation:
 				case rhino.ObjectType.Hatch:
-				case rhino.ObjectType.SubD:
 				case rhino.ObjectType.ClipPlane:
 				*/
 

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


BIN
examples/screenshots/webgl_loader_3dm.jpg


Alguns arquivos não foram mostrados porque muitos arquivos mudaram nesse diff