forked from serjIII/threejsSDK
-
Notifications
You must be signed in to change notification settings - Fork 0
/
3DMLoader.html
265 lines (220 loc) · 8.13 KB
/
3DMLoader.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<base href="../../../" />
<script src="page.js"></script>
<link type="text/css" rel="stylesheet" href="page.css" />
</head>
<body>
[page:Loader] →
<h1>[name]</h1>
<p class="desc">
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, breps, extrusions, 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].
The loader currently uses [link:https://www.npmjs.com/package/rhino3dm/v/0.15.0-beta rhino3dm.js 0.15.0-beta.]
</p>
<h2>Import</h2>
<p>
[name] is an add-on, and must be imported explicitly.
See [link:#manual/introduction/Installation Installation / Addons].
</p>
<code>
import { Rhino3dmLoader } from 'three/addons/loaders/3DMLoader.js';
</code>
<h2>Supported Conversions</h2>
<p>
The [name] converts Rhino objects to the following three.js types:
</p>
<table>
<tr>
<th>3dm type</th>
<th>three.js type</th>
</tr>
<tr>
<td>Point</td>
<td>[page:Points Points]</td>
</tr>
<tr>
<td>PointSet</td>
<td>[page:Points Points]</td>
</tr>
<tr>
<td>TextDot</td>
<td>[page:Sprite Sprite]</td>
</tr>
<tr>
<td>Curve</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]<sup> 2</sup></td>
</tr>
<tr>
<td>BREP</td>
<td>[page:Mesh Mesh]<sup> 2</sup></td>
</tr>
<tr>
<td>SubD</td>
<td>[page:Mesh Mesh]<sup> 3</sup></td>
</tr>
<tr>
<td>InstanceReferences</td>
<td>[page:Object3D Object3D]</td>
</tr>
<tr>
<td>DirectionalLight</td>
<td>[page:DirectionalLight DirectionalLight]</td>
</tr>
<tr>
<td>PointLight</td>
<td>[page:PointLight PointLight]</td>
</tr>
<tr>
<td>RectangularLight</td>
<td>[page:RectAreaLight RectAreaLight]</td>
</tr>
<tr>
<td>SpotLight</td>
<td>[page:SpotLight SpotLight]</td>
</tr>
<tr>
<td>File3dm</td>
<td>[page:Object3D Object3D]<sup> 4</sup></td>
</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". Render meshes might not be associated with these objects if they have not been displayed in an appropriate display mode in Rhino (i.e. "Shaded", "Rendered", etc), or are created programmatically, for example, via Grasshopper or directly with the rhino3dm library.
</i></p>
<p><i>
<sup>3</sup> SubD objects are represented by subdividing their control net.
</i></p>
<p><i>
<sup>4</sup> Whether a Rhino Document (File3dm) is loaded or parsed, the returned object is an [page:Object3D Object3D] with all Rhino objects (File3dmObject) as children.
</i></p>
<p><i>
<sup>5</sup> All resulting three.js objects have useful properties from the Rhino object (i.e. layer index, name, etc.) populated in their userData object.
</i></p>
<h2>Code Example</h2>
<code>
// Instantiate a loader
const loader = new Rhino3dmLoader();
// Specify path to a folder containing WASM/JS libraries or a CDN.
//loader.setLibraryPath( '/path_to_library/rhino3dm/' );
loader.setLibraryPath( 'https://cdn.jsdelivr.net/npm/[email protected]/' );
// Load a 3DM file
loader.load(
// resource URL
'model.3dm',
// called when the resource is loaded
function ( object ) {
scene.add( object );
},
// called as loading progresses
function ( xhr ) {
console.log( ( xhr.loaded / xhr.total * 100 ) + '% loaded' );
},
// called when loading has errors
function ( error ) {
console.log( 'An error happened' );
}
);
</code>
<h2>Examples</h2>
<p>
[example:webgl_loader_3dm]
</p>
<hr>
<h2>Constructor</h2>
<h3>Rhino3dmLoader( [param:LoadingManager manager] )</h3>
<p>
[page:LoadingManager manager] — The [page:LoadingManager loadingManager] for the loader to use. Default is [page:LoadingManager THREE.DefaultLoadingManager].
</p>
<p>
Creates a new Rhino3dmLoader.
</p>
<h2>Properties</h2>
<p>See the base [page:Loader] class for common properties.</p>
<h2>Methods</h2>
<p>See the base [page:Loader] class for common methods.</p>
<h3>[method:undefined load]( [param:String url], [param:Function onLoad], [param:Function onProgress], [param:Function onError] )</h3>
<p>
[page:String url] — A string containing the path/URL of the `.3dm` file.<br />
[page:Function onLoad] — A function to be called after the loading is successfully completed.<br />
[page:Function onProgress] — (optional) A function to be called while the loading is in progress. The argument will be the XMLHttpRequest instance, that contains .[page:Integer total] and .[page:Integer loaded] bytes. If the server does not set the Content-Length header; .[page:Integer total] will be 0.<br />
[page:Function onError] — (optional) A function to be called if an error occurs during loading. The function receives error as an argument.<br />
</p>
<p>
Begin loading from url and call the `onLoad` function with the resulting Object3d.
</p>
<h3>[method:undefined parse]( [param:ArrayBuffer buffer], [param:Function onLoad], [param:Function onProgress], [param:Function onError] )</h3>
<p>
[page:ArrayBuffer buffer] — An ArrayBuffer representing the Rhino `File3dm` document.<br />
[page:Function onLoad] — A function to be called after the loading is successfully completed.<br />
[page:Function onError] — (optional) A function to be called if an error occurs during loading. The function receives error as an argument.<br />
</p>
<p>
Parse a File3dm ArrayBuffer and call the `onLoad` function with the resulting Object3d.
See [link:https://github.com/mcneel/rhino-developer-samples/tree/7/rhino3dm/js/SampleParse3dmObjects this example] for further reference.
</p>
<code>
import rhino3dm from 'https://cdn.jsdelivr.net/npm/[email protected]/rhino3dm.module.js'
// Instantiate a loader
const loader = new Rhino3dmLoader();
// Specify path to a folder containing WASM/JS libraries or a CDN.
loader.setLibraryPath( 'https://cdn.jsdelivr.net/npm/[email protected]/' );
rhino3dm().then(async m => {
console.log('Loaded rhino3dm.');
const rhino = m; // global
// create Rhino Document and add a point to it
const doc = new rhino.File3dm();
const ptA = [0, 0, 0];
const point = new rhino.Point( ptA );
doc.objects().add( point, null );
// create a copy of the doc.toByteArray data to get an ArrayBuffer
const buffer = new Uint8Array( doc.toByteArray() ).buffer;
loader.parse( buffer, function ( object ) {
scene.add( object );
} );
})
</code>
<h3>[method:this setLibraryPath]( [param:String value] )</h3>
<p>
[page:String value] — Path to folder containing the JS and WASM libraries.
</p>
<code>
// Instantiate a loader
const loader = new Rhino3dmLoader();
// Specify path to a folder containing the WASM/JS library:
loader.setLibraryPath( '/path_to_library/rhino3dm/' );
// or from a CDN:
loader.setLibraryPath( 'https://cdn.jsdelivr.net/npm/[email protected]/' );
</code>
<h3>[method:this setWorkerLimit]( [param:Number workerLimit] )</h3>
<p>
[page:Number workerLimit] - Maximum number of workers to be allocated. Default is 4.<br />
</p>
<p>
Sets the maximum number of [link:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Using_web_workers Web Workers]
to be used during decoding. A lower limit may be preferable if workers are also for other tasks
in the application.
</p>
<h3>[method:this dispose]()</h3>
<p>
Disposes of the loader resources and deallocates memory.
</p>
<h2>Source</h2>
<p>
[link:https://github.com/mrdoob/three.js/blob/master/examples/jsm/loaders/3DMLoader.js examples/jsm/loaders/3DMLoader.js]
</p>
</body>
</html>