[page:Loader] →

3DM加载器([name])

用于加载 Rhinoceros 3d 模型文件。

Rhinoceros 是一个 3D 建模器,用于创建、编辑、分析、记录、渲染、动画和转换 NURBS 曲线、曲面、breps、挤压、点云以及多边形网格和 SubD 对象。 [link:https://github.com/mcneel/rhino3dm rhino3dm.js] 从开源几何库 [link:https://github.com/mcneel/opennurbs openNURBS] 编译为 WebAssembly 。加载器当前使用 [link:https://www.npmjs.com/package/rhino3dm/v/8.0.1 rhino3dm.js 8.0.1.]。

导入

[name] 是一个附加组件,必须显式导入。请参阅 [link:#manual/introduction/Installation Installation / Addons]。

import { Rhino3dmLoader } from 'three/addons/loaders/3DMLoader.js';

支持的转换

[name] 将 Rhino 对象转换为以下 three.js 类型:

3dm type three.js type
Point [page:Points Points]
PointSet / PointCloud [page:Points Points]
TextDot [page:Sprite Sprite]
Curve [page:Line Line] 1
Mesh [page:Mesh Mesh]
Extrusion [page:Mesh Mesh] 2
BREP [page:Mesh Mesh] 2
SubD [page:Mesh Mesh] 3
InstanceReferences [page:Object3D Object3D]
DirectionalLight [page:DirectionalLight DirectionalLight]
PointLight [page:PointLight PointLight]
RectangularLight [page:RectAreaLight RectAreaLight]
SpotLight [page:SpotLight SpotLight]
File3dm [page:Object3D Object3D] 4
Material / Physically Based Material [page:MeshPhysicalMaterial MeshPhysicalMaterial]

注意:

1 NURBS 曲线被离散化为硬编码分辨率。

2 基于 BREP 和 NURBS 曲面的类型用其“渲染网格”表示。如果渲染网格未在 Rhino 中以适当的显示模式显示(即“着色”、“渲染”等),或者以编程方式创建(例如通过 Grasshopper 或直接使用 rhino3dm),则渲染网格可能不会与这些对象关联图书馆。从 rhino3dm.js@8.0.0-beta2 开始,BrepFace 和 Extrusions 可以分配网格表示,但这些必须由用户生成。

3 SubD 对象通过细分其控制网来表示。

4 无论 Rhino 文件(File3dm)被加载还是解析,返回的对象都是一个 [page:Object3D Object3D] ,所有 Rhino 对象(File3dmObject)都是子对象。File3dm 图层和其他文件级属性将添加到生成对象的 userData 中。

5 所有生成的 Three.js 对象都具有来自填充在其 userData 对象中的 Rhino 对象的有用属性(即图层索引、名称等)。

6 Rhino 和 Three.js 有不同的坐标系。导入后,您应该将生成的 [page:Object3D Object3D] 在 x 方向上旋转 -90° 或在应用程序开始时设置 THREE.Object3D.DEFAULT_UP: THREE.Object3D.DEFAULT_UP.set( 0, 0, 1 ); 请记住,这将影响应用程序中所有 Object3D 的方向。

例子

[example:webgl_loader_3dm]

构造函数

Rhino3dmLoader( [param:LoadingManager manager] )

[page:LoadingManager manager] — 加载器使用的 [page:LoadingManager loadingManager]。默认值为 [page:LoadingManager THREE.DefaultLoadingManager]。

创建一个新的 Rhino3dmLoader。

属性

有关常用属性,请参阅 [page:Loader] 基类。

方法

有关常用方法,请参阅 [page:Loader] 基类。

[method:Object3D load]( [param:String url], [param:Function onLoad], [param:Function onProgress], [param:Function onError] )

[page:String url] — 包含 `.3dm` 文件路径/URL的字符串
[page:Function onLoad] — 加载成功完成后调用的函数
[page:Function onProgress] — (可选)加载过程中调用的函数。参数将是 XMLHttpRequest 实例,其中包含 .[page:Integer total] 和 .[page:Integer loaded] 字节。如果服务器没有设置 Content-Length,.[page:Integer total] 将为 0。
[page:Function onError] — (可选)加载期间发生错误时调用的函数。该函数接收错误作为参数。

开始从 url 加载并在解析得到 Object3d 后调用 `onLoad` 。

// Instantiate a loader const loader = new Rhino3dmLoader(); // Specify path to a folder containing WASM/JS libraries or a CDN. // For example, /jsm/libs/rhino3dm/ is the location of the library inside the three.js repository // loader.setLibraryPath( '/path_to_library/rhino3dm/' ); loader.setLibraryPath( 'https://cdn.jsdelivr.net/npm/rhino3dm@8.0.1/' ); // 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' ); } );

[method:Object3D parse]( [param:ArrayBuffer buffer], [param:Function onLoad], [param:Function onProgress], [param:Function onError] )

[page:ArrayBuffer buffer] — 代表 Rhino `File3dm` 文档的 ArrayBuffer
[page:Function onLoad] — 加载成功完成后调用的函数。
[page:Function onError] — (可选)加载期间发生错误时调用的函数。该函数接收错误作为参数。

解析 File3dm ArrayBuffer 并在得到 Object3d 后调用 `onLoad`。 请参阅 [link:https://github.com/mcneel/rhino-developer-samples/tree/7/rhino3dm/js/SampleParse3dmObjects this example] 以获取更多参考。

import rhino3dm from 'https://cdn.jsdelivr.net/npm/rhino3dm@8.0.1' // 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/rhino3dm@8.0.1' ); const rhino = await rhino3dm(); console.log('Loaded rhino3dm.'); // 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 ); } );

[method:this setLibraryPath]( [param:String value] )

[page:String value] — 包含 JS 和 WASM 库的文件夹的路径。

// 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/rhino3dm@8.0.1' );

[method:this setWorkerLimit]( [param:Number workerLimit] )

[page:Number workerLimit] - 要分配的最大 worker 数量。默认值为 4。

设置解码期间要使用的 [link:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Using_web_workers Web Workers] 的最大数量。如果 worker 还负责应用程序中的其他任务,则较低的限制可能更好。

[method:this dispose]()

处理加载程序资源并释放内存。

源代码

[link:https://github.com/mrdoob/three.js/blob/master/examples/jsm/loaders/3DMLoader.js examples/jsm/loaders/3DMLoader.js]