Javascript:FBXLoader不显示任何东西

By simon at 2018-02-07 • 0人收藏 • 94人看过

我正在尝试使用FBXLoader来显示一个FBX二进制文件 API。当我检查控制台日志,它显示我吨下载100%,但是 没有出现。我已经尝试过,没有网格部分。唯一的 我能想到的事情是th在我打电话给API发送这个FBX文件 内容类型正在申请/下载。我不确定这是否重要 是因为我仍然收到FBX二进制文件,并可以查看整个文件,当我 在Chrome开发工具中查看响应。

        var camera = new THREE.PerspectiveCamera(45, 1, 1, 2000);
        // camera.position.set( 600, 1150, 5 );
        // camera.up.set( 0, 0, 1 );
        // camera.lookAt( new THREE.Vector3( -100, 0, 0 ) );

        var scene = new THREE.Scene();

        // model
        var manager = new THREE.LoadingManager();
        manager.onProgress = function(item, loaded, total) {
          console.log(item, loaded, total);
        };
        var onProgress = function(xhr) {
          if (xhr.lengthComputable) {
            var percentComplete = xhr.loaded / xhr.total * 100;
            console.log(Math.round(percentComplete, 2) + '% downloaded');
          }
        };
        var onError = function(xhr) {};
        var loader = new THREE.FBXLoader(manager);
        loader.load(xhr.responseURL, function(geometry) {
          mesh = new THREE.Mesh( geometry, new THREE.MeshNormalMaterial() );
          mesh.scale.set( 10, 10, 10 );
          mesh.position.y = 150;
          mesh.position.x = 0;
          scene.add(mesh);
          console.log(mesh);
        }, onProgress, onError);
        var renderer = new THREE.WebGLRenderer();
        renderer.setPixelRatio(window.devicePixelRatio);
        renderer.setSize(500, 500);
        renderer.render(scene, camera);
        var container = document.getElementById("ava");
        container.appendChild(renderer.domElement);
[SCReenshot的100%FBX下载](https://i.stack.imgur.com/zOaHN.png)

1 个回复 | 最后更新于 2018-02-07
2018-02-07   #1

通常你会有一个循环的renderer.render(scene, camera)调用,但不总是。 在你的情况下,你似乎没有一个渲染循环,所以你至少要去 需要在载入器中调用renderer.render(场景,相机) 回电话。

// set up your renderer first.
var renderer = new THREE.WebGLRenderer();
renderer.setPixelRatio(window.devicePixelRatio);
renderer.setSize(500, 500);
var container = document.getElementById("ava");
container.appendChild(renderer.domElement);
renderer.render(scene, camera);

var loader = new THREE.FBXLoader(manager);
loader.load(xhr.responseURL, function(geometry) {
  mesh = new THREE.Mesh( geometry, new THREE.MeshNormalMaterial() );
  mesh.scale.set( 10, 10, 10 );
  mesh.position.y = 150;
  mesh.position.x = 0;
  scene.add(mesh);
  console.log(mesh);
  // Call render here as a mesh has been added.
  renderer.render(scene, camera);
}, onProgress, onError);

登录后方可回帖

Loading...