简体   繁体   English

无法在threejs中显示3D模型

[英]Cannot display 3D model in threejs

I am trying to display a model which is gltf but it doesn't come up.我正在尝试显示一个 gltf 模型,但它没有出现。 I'm running of a http server as without so it is causing more errors now this "Error: Could not establish connection. Receiving end does not exist."我正在运行一个 http 服务器,所以它现在导致更多错误,这个“错误:无法建立连接。接收端不存在。” comes up过来

    <html><head>
<title>My first three.js app</title>
<style>
  body {
    margin: 0;
  }
  canvas {
    display: block;
  }
</style></head>[enter image description here][1]<body>
<script src="js/three.js"></script>
<script src="js/GLTFLoader.js"></script>
<script> var scene = new THREE.Scene();
  var camera = new THREE.PerspectiveCamera(
    75,
    window.innerWidth / window.innerHeight,
    0.1,
    1000
  );var renderer = new THREE.WebGLRenderer();
  renderer.setSize(window.innerWidth, window.innerHeight);
  document.body.appendChild(renderer.domElement);

  var loader = new THREE.GLTFLoader();
  loader.load("LegoEv3.glb", handle_load);
  var mesh;

  function handle_load(gltf) {
    mesh = gltf.scene.children[0];
    scene.add(mesh);
    mesh.position, (z = -1000);
  }

  renderer.render(scene, camera);
</script>

you render only once before the model is loaded.在加载模型之前只渲染一次。
Try rendering again after the model is loaded and added to the scene在模型加载并添加到场景后再次尝试渲染

function handle_load(gltf) {
    mesh = gltf.scene.children[0];
    scene.add(mesh);
    mesh.position, (z = -1000);
    renderer.render(scene, camera); // You need to render after model is added
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM