AIFanatic / earth-3d

Get 3D data from google earth.
MIT License
3 stars 5 forks source link

hi, great work, how can I download 3d model with textures #1

Closed jeannotes closed 2 years ago

jeannotes commented 2 years ago

hi, great work, how can I download 3d model with textures

AIFanatic commented 2 years ago

Hi, thanks. The project uses THREE.js you can use something like GLTFExporter to export the whole scene into a gltf file.

jeannotes commented 2 years ago

@AIFanatic hi, can you write more tutorials or some useful tools to download those 3d models with textures. thanks!

AIFanatic commented 2 years ago

Here is some code on how to download everything from the Advanced demo

After opening the link above paste this into the devtools console:

import('https://cdn.skypack.dev/three@0.130.0/examples/jsm/exporters/GLTFExporter.js').then(module => {
    const GLTFExporter = module.GLTFExporter;
    const scene = window.scene;
    const gltfExporter = new GLTFExporter();

    gltfExporter.parse(
        scene,
        function ( result ) {
            function save( blob, filename ) {
                const link = document.createElement( 'a' );
                link.style.display = 'none';
                document.body.appendChild( link ); // Firefox workaround, see #6594

                link.href = URL.createObjectURL( blob );
                link.download = filename;
                link.click();
            }

            function saveString( text, filename ) {
                save( new Blob( [ text ], { type: 'text/plain' } ), filename );
            }

            console.log(result)
            const output = JSON.stringify( result, null, 2 );
            console.log( output );
            saveString( output, 'scene.gltf' );
        },
        function ( error ) {
            console.log( 'An error happened during parsing', error );
        },
    );
})

You can then open the saved gltf in blender or threejs/editor. The code is adapted from threejs.org/docs/en/exporters/GLTFExporter and is pretty easy to understand. The caveats is that its downloading all the nodes (big nodes will occlude small nodes) and there seems to be no textures but that is relatively easy to solve. I'll keep it at this and leave the rest as an exercise to you :)