1. 程式人生 > >threejs GLTFExporter 匯出檔案 GLTFLoader載入檔案

threejs GLTFExporter 匯出檔案 GLTFLoader載入檔案

        let gltfExporter = new GLTFExporter();
        // 單個模型資料 obj
        gltfExporter.parse(obj, function (result) {
          console.log(result);
          let link = document.createElement('a');
          link.style.display = 'none';
          document.body.appendChild(link);
          link.href = URL.createObjectURL(new Blob([JSON.stringify(result)], { type: 'text/plain' }));
          link.download = unescape(_this.ChildrenData[i].modelType) + '.gltf';
          link.click();
          document.body.removeChild(link);
        });
const loader = new GLTFLoader();
loader.load(‘檔案路徑’ (res) => {
 this.scene.add(res.scene.children[0]);
 }, function (xhr) {
 if ((xhr.loaded / xhr.total * 100) === 100) {
  console.log((xhr.loaded / xhr.total * 100) + '% loaded');
 }
  }, function (error) {
   console.log('load error!'+ error.getWebGLErrorMessage());
});