其他分享
首页 > 其他分享> > three.js学习笔记二:导入外部gltf模型

three.js学习笔记二:导入外部gltf模型

作者:互联网


<!DOCTYPE html>
<head>
  <meta charset="utf-8" />
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
  <meta name="renderer" content="webkit" />
  <meta
    name="viewport"
    content="width=device-width, minimum-scale=1.0, initial-scale=1, user-scalable=no"
  />
  <title>BimAngle.com - Trial version</title>
  <link
    rel="stylesheet"
    type="text/css"
    href="http://fs3.bimangle.net/js/three-gltf-viewer/gltf-viewer.css"
  />
</head>
<body>
  <main class="wrap">
    <div id="viewer-local" class="viewer"></div>
    <div class="spinner"></div>
  </main>
  <script src="http://fs3.bimangle.net/js/three-gltf-viewer/gltf-viewer.js"></script>
  <script>
    const hash = location.hash ? queryString.parse(location.hash) : {};
    console.log(hash, "===");
    let modelUrl = hash.model || "./test.gltf";

    let element = document.getElementById("viewer-local");
    let viewer = new Viewer(element, {});
    viewer.load(modelUrl).then(onSuccess).catch(onError);

    function onSuccess() {
      let spinnerEl = document.querySelector(".spinner");
      if (spinnerEl) spinnerEl.style.display = "none";
      console.log("Succeeded!");
    }

    function one rror(error) {
      let message = (error || {}).message || error.toString();
      if (message.match(/ProgressEvent/)) {
        message =
          "Unable to retrieve this file. Check JS console and browser network tab.";
      } else if (message.match(/Unexpected token/)) {
        message = `Unable to parse file content. Verify that this file is valid. Error: "${message}"`;
      } else if (error && error.target && error.target instanceof Image) {
        message = "Missing texture: " + error.target.src.split("/").pop();
      }
      window.alert(message);
      console.error(error);
    }
  </script>
</body>

标签:hash,spinnerEl,three,js,let,error,console,message,gltf
来源: https://blog.csdn.net/weixin_35958891/article/details/122013269