收藏
回答

threejs-miniprogram加载glb文件是出现问题,如何解决?

提示我没有加载DRACOLoader,请问threejs-miniprogram要如何加载DRACOLoader?

回答关注问题邀请回答
收藏

1 个回答

  • 马新杰
    马新杰
    2023-02-22

    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 );


    } );


    } );


    }


    }

    2023-02-22
    有用
    回复
登录 后发表内容