I want to export a model that is in the scene with all animations, textures and morphs.
all code
import * as THREE from './three/build/three.module.js';
import { OrbitControls } from './three/examples/jsm/controls/OrbitControls.js';
// Create 3d scene
// Create Scene Camera Renderer
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 0.1, 1000 );
camera.position.z = 5;
const renderer = new THREE.WebGLRenderer();
// set size for render
renderer.setSize( window.innerWidth, window.innerHeight );
document.body.appendChild( renderer.domElement );
// Light
var DiLight = new THREE.DirectionalLight(0xFDFCEB, 0.5)
scene.add(DiLight);
const hemiLight = new THREE.HemisphereLight( 0xffffff, 0x444444 );
hemiLight.position.set( 0, 100, 0 );
scene.add( hemiLight );
const dirLight = new THREE.DirectionalLight( 0xffffff );
dirLight.position.set( - 0, 40, 50 );
dirLight.castShadow = true;
dirLight.shadow.camera.top = 50;
dirLight.shadow.camera.bottom = - 25;
dirLight.shadow.camera.left = - 25;
dirLight.shadow.camera.right = 25;
dirLight.shadow.camera.near = 0.1;
dirLight.shadow.camera.far = 200;
dirLight.shadow.mapSize.set( 1024, 1024 );
scene.add( dirLight );
// CONTROLS
const controls = new OrbitControls( camera, renderer.domElement );
// GLTFLoader
import { GLTFLoader } from './three/examples/jsm/loaders/GLTFLoader.js';
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 animated() {
const delta = clock.getDelta();
for ( let i = 0; i < mixers.length; i ++ ) {
mixers[ i ].update( delta );
}
}
// Run animate
const animate = function () {
controls.update();
requestAnimationFrame( animate );
renderer.render( scene, camera );
animated()
};
animate();
// EXSPORT
import { GLTFExporter } from './three/examples/jsm/exporters/GLTFExporter.js';
function exportGLTF( input ) {
const gltfExporter = new GLTFExporter();
const options = {
trs: document.getElementById( 'option_trs' ).checked,
onlyVisible: document.getElementById( 'option_visible' ).checked,
truncateDrawRange: document.getElementById( 'option_drawrange' ).checked,
binary: document.getElementById( 'option_binary' ).checked,
maxTextureSize: Number( document.getElementById( 'option_maxsize' ).value ) || Infinity // To prevent NaN value
};
gltfExporter.parse( input, function ( result ) {
if ( result instanceof ArrayBuffer ) {
console.log(result)
} else {
const output = JSON.stringify( result, null, 2 );
// generate object output
console.log(output)
//saveString( output, 'scene.gltf' );
}
}, options );
}
exportGLTF( exsp_obj );
But I do not quite understand how to turn the scene into the GLTF model.
I repeat I want to export all that is possible from the scene in GLTF