hello,
I need to export my scene to a glb file as I can use it for AR.
I tried GLTFExporter but I can’t export loaded mesh from Blender with GLTFLoader.
the exported scene contains only the camera, the scene and the primitive assets, it does not export the meshes with their materials.
I tried exactly the code in the documentation of threejs
If you drag and drop your glb file here, does it show up correctly? https://gltf.report/
If not, make sure when you’re exporting from Blender that these checkboxes are NOT checked, so that it exports everything in the scene:
Thank you for your reply @Omar_Shehata ,
what I want is not to export from Blender to ThreeJs
but export scene from threeJs to glb file
if i have only primitive asset on my scene like sphere or box the GLTFexporter work but when i have a loaded mesh ( a chair for example) it not export
Can you share the code you’re using, perhaps a CodePen that reproduces the issue?
import * as THREE from './THREE/three.module.js';
import {GLTFExporter} from './THREE/GLTFExporter.js'
import { watchviewer,LoadTextures} from './watch.js';
function _(elm){return document.getElementById(elm)}
Viewer = new watchviewer(_("container"))
Viewer.initScene()
Viewer.animate()
const geometry = new THREE.BoxGeometry(0.3, 0.3, 0.3);
const material = new THREE.MeshBasicMaterial({
color: 0x00ff00
});
const cube = new THREE.Mesh(geometry, material);
Viewer.scene.add(cube);
const gltfExporter = new GLTFExporter();
_("export").addEventListener('click',exportGLTF( Viewer.scene ))
function exportGLTF( input ) {
gltfExporter.parse(
input,
function ( result ) {
saveArrayBuffer( result, 'scene.glb' );
},
{
binary:true
},
function ( error ) { console.log( 'An error happened during parsing', error );}
);
}
const link = document.createElement( 'a' );
link.style.display = 'none';
document.body.appendChild( link ); // Firefox workaround, see #6594
function save( blob, filename )
{
link.href = URL.createObjectURL( blob );
link.download = filename;
link.click();
// URL.revokeObjectURL( url ); breaks Firefox...
}
function saveString( text, filename )
{
save( new Blob( [ text ], { type: 'text/plain' } ), filename );
}
function saveArrayBuffer( buffer, filename )
{
save( new Blob( [ buffer ], { type: 'application/octet-stream' } ), filename );
}
i use this method to export threejs scene.
when i open it with gltf.report i can see only the box
maybe it’s because the glb loaded before into the scene is with draco compression!!!
another problem that I don’t understand is that the download windows start automatically when the page is loaded repeatedly
Thanks for your help
thank you bro
i figure out my mistake and i can export my model now
it was something simple maybe that because i’m not sleeping enough this days
thank you again and viva egypt