glTF资源
大约 1 分钟基础知识文档资源glTF
glTF资源(GLTFResource)通过“引用计数”方式管理 glTF 数据,从而实现 glTF 数据的共享使用和正确释放。
glTF资源属性
const { nodes } = resource;
for ( const key in nodes ) {
const node = nodes[ key ];
if ( node.name === 'Object_13' ) {
// TODO:
}
}
- materials - 获取 glTF 的所有材质对象,只读属性。
const { materials } = resource;
for ( const key in materials ) {
const material = materials[ key ];
if ( material.name === 'default' ) {
// TODO:
}
}
- bounds - 获取 glTF 的本地外包范围,只读属性。
glTF资源方法
- reference - 引用 glTF 资源。
提示
调用 reference 会增加 glTF 资源的引用计数。通常先引用资源,再获取数据,如下所示:
// 引用资源
resource.reference();
// 获取 glTF 数据
const { glTF } = resource;
- dispose - 释放 glTF 资源。
提示
调用 dispose 会递减 glTF 资源的引用计数,当且仅当资源的引用计数等于0或设置强制释放时才会释放 glTF 内存数据。