GLTF导出器([name])

一个用于 glTF 2.0 的导出器。

[link:https://www.khronos.org/gltf glTF] (GL Transmission Format) 是一个用于高效传输和加载3D内容的 [link:https://github.com/KhronosGroup/glTF/tree/master/specification/2.0 开放格式规范]。 资源可以以 JSON (.gltf) 或二进制 (.glb) 格式提供。外部文件存储纹理 (.jpg, .png) 和额外的二进制数据 (.bin)。一个 glTF 资产可以包含一个或多个场景,包括网格、材质、纹理、蒙皮、骨骼、变形目标、动画、灯光和/或相机。

导入

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

import { GLTFExporter } from 'three/addons/exporters/GLTFExporter.js';

扩展

[name] 支持以下 [link:https://github.com/KhronosGroup/glTF/tree/master/extensions/ glTF 2.0 扩展]:

以下 glTF 2.0 扩展由外部用户插件支持

代码示例

// Instantiate a exporter const exporter = new GLTFExporter(); // Parse the input and generate the glTF output exporter.parse( scene, // called when the gltf has been generated function ( gltf ) { console.log( gltf ); downloadJSON( gltf ); }, // called when there is an error in the generation function ( error ) { console.log( 'An error happened' ); }, options );

例子

[example:misc_exporter_gltf]

构造函数

[name]()

创建一个新的 [name] 实例。

方法

[method:undefined parse]( [param:Object3D input], [param:Function onCompleted], [param:Function onError], [param:Object options] )

[page:Object input] — 要导出的场景或对象。有效选项:

[page:Function onCompleted] — 导出完成时将被调用。参数将是生成的 glTF JSON 或二进制 ArrayBuffer。
[page:Function onError] — 如果在 gltf 生成过程中出现任何错误,将被调用。
[page:Options options] — 导出选项

从输入(场景或对象)生成一个 .gltf(JSON)或 .glb(二进制)输出。

源代码

[link:https://github.com/mrdoob/three.js/blob/master/examples/jsm/exporters/GLTFExporter.js examples/jsm/exporters/GLTFExporter.js]