Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

3DMLoader: Update #20349

Merged
merged 7 commits into from
Sep 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 21 additions & 4 deletions docs/examples/en/loaders/3DMLoader.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ <h1>[name]</h1>
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>
Expand Down Expand Up @@ -43,19 +43,23 @@ <h2>Supported Conversions</h2>
</tr>
<tr>
<td>Curve</td>
<td>[page:Line Line]</td>
<td>[page:Line Line] <sup>1</sup></td>
</tr>
<tr>
<td>Mesh</td>
<td>[page:Mesh Mesh]</td>
</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>
Expand All @@ -79,6 +83,19 @@ <h2>Supported Conversions</h2>
</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>
Expand Down
4 changes: 2 additions & 2 deletions examples/jsm/libs/rhino3dm/rhino3dm.js

Large diffs are not rendered by default.

Binary file modified examples/jsm/libs/rhino3dm/rhino3dm.wasm
Binary file not shown.
36 changes: 32 additions & 4 deletions examples/jsm/loaders/3DMLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,7 @@ Rhino3dmLoader.prototype = Object.assign( Object.create( Loader.prototype ), {

case 'Mesh':
case 'Extrusion':
case 'SubD':

var geometry = loader.parse( obj.geometry );

Expand All @@ -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;
Expand Down Expand Up @@ -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';
Expand Down Expand Up @@ -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 ) {
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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:
*/

Expand Down
Binary file modified examples/models/3dm/Rhino_Logo.3dm
Binary file not shown.
Binary file modified examples/screenshots/webgl_loader_3dm.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.