首页 > 解决方案 > 是否可以以 GLTF 格式从场景中导出动画和变形?

问题描述

我想导出场景中包含所有动画、纹理和变形的模型。

    const mixers = [];
    const loader = new GLTFLoader();
    const clock = new THREE.Clock();
    let exsp_obj    
    loader.load( 'models/gltf/Flamingo.glb', function ( gltf ) {
        const mesh = gltf.scene.children[ 0 ];
        exsp_obj = mesh;
        mesh.castShadow = true;
        mesh.receiveShadow = true;
        scene.add( mesh );
        const mixer = new THREE.AnimationMixer( mesh );
        mixer.clipAction( gltf.animations[ 0 ] ).setDuration( 1 ).play();
        mixers.push( mixer );
    } );
    function gltf_animated() {
        const delta = clock.getDelta();
        for ( let i = 0; i < mixers.length; i ++ ) {
            mixers[ i ].update( delta );
        }
    }
    // Run animate
    const animate = function () {
        requestAnimationFrame( animate );
        renderer.render( scene, camera );
        gltf_animated()
    };
    animate();  
    // EXPORT MODEL
    function exportGLTF( input ) {
        const gltfExporter = new GLTFExporter();
        const options = {
            trs: false,
            onlyVisible: true,
            truncateDrawRange: true,
            binary: false,
            maxTextureSize: 4096 || Infinity // To prevent NaN value
        };
        gltfExporter.parse( input, function ( result ) {
            if ( result instanceof ArrayBuffer ) {
                // send result code
                console.log(result)
            } else {
                const output = JSON.stringify( result, null, 2 );
                // send result code
                console.log(output)
            }
        }, options );
    }
    exportGLTF( exsp_obj );

但我不太明白如何将场景变成 GLTF 模型。
我再说一遍,我想从 GLTF 的场景中导出所有可能的内容

标签: javascriptthree.js

解决方案


推荐阅读