1

我正在使用 Meteor 构建一个 Web 应用程序,将场景以GLTF格式导出到服务器,这可能吗?

4

3 回答 3

0

我想你正在寻找的是这个例子

对于服务器端部分,只要您不使用需要浏览器的元素(例如THREE.WebGLRenderer()),您应该能够THREE在服务器上运行。这是使用 Node 服务器的一个很酷的例子

于 2018-08-10T00:38:46.880 回答
0

可能,是的。是否有人编写了 JavaScript 代码,使得从使用 Three.js 创建的 Web 应用程序中导出 glTF 变得容易?我不确定。

生成 glTF 的 Web 应用程序通常使用作为服务器端进程运行的本机组件,例如COLLADA2GLTFFBX-glTF ,如下例所示: https ://cesiumjs.org/convertmodel.html

于 2016-07-05T01:24:34.067 回答
0

我更喜欢使用 GLB 而不是 GLTF,因为 GLTF 文件包含对外部文件的引用,例如纹理(.png 文件)和动画(.bin 文件),而在 GLB 的情况下,所有这些文件都合并到一个文件中。这意味着 .glb 文件包含纹理和动画。

如果您想深入了解有关 gltf 与 glb 的整个讨论,此链接可能很有用 - https://github.com/KhronosGroup/glTF/issues/1117

您可以使用以下代码将 THREE.js 场景导出为 GLB 格式

const btn = document.getElementById('download-glb')
btn.addEventListener('click',download)

function download(){
    const exporter = new GLTFExporter();
    exporter.parse(
        scene,
        function (result) {
            saveArrayBuffer(result, 'ThreejsScene.glb'); 
        },
        { 
            binary: true
        }
    );
}

function saveArrayBuffer(buffer, filename) {
    save(new Blob([buffer], { type: 'application/octet-stream' }), filename);
}
   
function save(blob, filename) {
    link.href = URL.createObjectURL(blob);    
    link.download = filename;
    link.click(); // This step makes sure your glb file gets downloaded
    sendFileToBackend(blob, filename)
}

function sendFileToBackend(blob, filename){
    const endpoint = "YOUR_BACKEND_URL_HERE";
    const formData = new FormData();

    let sceneFile= new File([blob], "ThreejsScene.glb");
    console.log(sceneFile)
    formData.append("file", sceneFile);

    const options = {
        method:'POST',
        mode: 'no-cors',
        body: formData,
    }

    fetch(endpoint,options)
        .then(response => console.log(JSON.stringify(response)))
        .catch(error => console.error('Error:', error))

}
于 2021-05-30T02:36:56.127 回答