小程序
小游戏
企业微信
微信支付
扫描小程序码分享
提示我没有加载DRACOLoader,请问threejs-miniprogram要如何加载DRACOLoader?
1 个回答
加粗
标红
插入代码
插入链接
插入图片
上传视频
class GLTFDracoMeshCompressionExtension {
constructor( json, dracoLoader ) {
if ( ! dracoLoader ) {
throw new Error( 'THREE.GLTFLoader: No DRACOLoader instance provided.' );
}
this.name = EXTENSIONS.KHR_DRACO_MESH_COMPRESSION;
this.json = json;
this.dracoLoader = dracoLoader;
this.dracoLoader.preload();
decodePrimitive( primitive, parser ) {
const json = this.json;
const dracoLoader = this.dracoLoader;
const bufferViewIndex = primitive.extensions[ this.name ].bufferView;
const gltfAttributeMap = primitive.extensions[ this.name ].attributes;
const threeAttributeMap = {};
const attributeNormalizedMap = {};
const attributeTypeMap = {};
for ( const attributeName in gltfAttributeMap ) {
const threeAttributeName = ATTRIBUTES[ attributeName ] || attributeName.toLowerCase();
threeAttributeMap[ threeAttributeName ] = gltfAttributeMap[ attributeName ];
for ( const attributeName in primitive.attributes ) {
if ( gltfAttributeMap[ attributeName ] !== undefined ) {
const accessorDef = json.accessors[ primitive.attributes[ attributeName ] ];
const componentType = WEBGL_COMPONENT_TYPES[ accessorDef.componentType ];
attributeTypeMap[ threeAttributeName ] = componentType;
attributeNormalizedMap[ threeAttributeName ] = accessorDef.normalized === true;
return parser.getDependency( 'bufferView', bufferViewIndex ).then( function ( bufferView ) {
return new Promise( function ( resolve ) {
dracoLoader.decodeDracoFile( bufferView, function ( geometry ) {
for ( const attributeName in geometry.attributes ) {
const attribute = geometry.attributes[ attributeName ];
const normalized = attributeNormalizedMap[ attributeName ];
if ( normalized !== undefined ) attribute.normalized = normalized;
resolve( geometry );
}, threeAttributeMap, attributeTypeMap );
} );
你好,麻烦通过点击下方“反馈信息”按钮,提供出现问题的。
关注后,可在微信内接收相应的重要提醒。
请使用微信扫描二维码关注 “微信开放社区” 公众号
class GLTFDracoMeshCompressionExtension {
constructor( json, dracoLoader ) {
if ( ! dracoLoader ) {
throw new Error( 'THREE.GLTFLoader: No DRACOLoader instance provided.' );
}
this.name = EXTENSIONS.KHR_DRACO_MESH_COMPRESSION;
this.json = json;
this.dracoLoader = dracoLoader;
this.dracoLoader.preload();
}
decodePrimitive( primitive, parser ) {
const json = this.json;
const dracoLoader = this.dracoLoader;
const bufferViewIndex = primitive.extensions[ this.name ].bufferView;
const gltfAttributeMap = primitive.extensions[ this.name ].attributes;
const threeAttributeMap = {};
const attributeNormalizedMap = {};
const attributeTypeMap = {};
for ( const attributeName in gltfAttributeMap ) {
const threeAttributeName = ATTRIBUTES[ attributeName ] || attributeName.toLowerCase();
threeAttributeMap[ threeAttributeName ] = gltfAttributeMap[ attributeName ];
}
for ( const attributeName in primitive.attributes ) {
const threeAttributeName = ATTRIBUTES[ attributeName ] || attributeName.toLowerCase();
if ( gltfAttributeMap[ attributeName ] !== undefined ) {
const accessorDef = json.accessors[ primitive.attributes[ attributeName ] ];
const componentType = WEBGL_COMPONENT_TYPES[ accessorDef.componentType ];
attributeTypeMap[ threeAttributeName ] = componentType;
attributeNormalizedMap[ threeAttributeName ] = accessorDef.normalized === true;
}
}
return parser.getDependency( 'bufferView', bufferViewIndex ).then( function ( bufferView ) {
return new Promise( function ( resolve ) {
dracoLoader.decodeDracoFile( bufferView, function ( geometry ) {
for ( const attributeName in geometry.attributes ) {
const attribute = geometry.attributes[ attributeName ];
const normalized = attributeNormalizedMap[ attributeName ];
if ( normalized !== undefined ) attribute.normalized = normalized;
}
resolve( geometry );
}, threeAttributeMap, attributeTypeMap );
} );
} );
}
}