三个JS FBX Loader:场景中不可见的模型控制台中没有错误

时间:2018-05-17 12:20:56

标签: javascript three.js fbx

我想使用THREEJS FBXLoader渲染.fbx格式的3D模型,但模型在场景中不可见,尽管它已被添加。变量名为' model'其中存储3D FBX模型的定义为I console.log。 控制台中没有错误。

对此有任何帮助将非常有帮助

Console Log Image 我在console.log中记录了从FBXLoader返回的3d模型对象,它是可见的

Scene Image 在场景中,地面网格和网格是可见的,但模型不可见

if ( ! Detector.webgl ) Detector.addGetWebGLMessage();

var container, controls;

container = document.getElementById('container');

var width = container.clientWidth;

var height = container.clientHeight;

var camera, scene, renderer, light;

var mixers = [];

init();
animate();

function init() {

 camera = new THREE.PerspectiveCamera( 45, width / height, 0.001, 100  000 
 );
 camera.position.set( 100, 100, 100 );
 camera.up.set(0,1,0);

 controls = new THREE.OrbitControls( camera );
 controls.target.set( 0, 100, 0 );
 controls.update();

 scene = new THREE.Scene();

 var ambient = new THREE.AmbientLight(0x404040); //0x101030
 scene.add(ambient);
 scene.background = new THREE.Color( 0x1c0c4e );

 var grid = new THREE.GridHelper( 2000, 20, 0x000000, 0x000000 );
 grid.material.opacity = 1;
 grid.material.transparent = true;
 scene.add( grid );

 var loader = new THREE.FBXLoader();
 console.log(loader);
 loader.load( 'uploaded/silly_dancing.fbx', function ( object ) {
  model = object;
  console.log(model);
  scene.add( model );
 });        


 renderer = new THREE.WebGLRenderer();
 renderer.setPixelRatio( window.devicePixelRatio );
 renderer.setSize( width, height);
 renderer.shadowMap.enabled = true;
 container.appendChild( renderer.domElement );

 window.addEventListener( 'resize', onWindowResize, false );

}

function onWindowResize() {

 var width = container.clientWidth;
 var height = container.clientHeight;
 camera.aspect = width / height;

 camera.updateProjectionMatrix();

 renderer.setSize( width, height );
}

function animate() {

 requestAnimationFrame( animate );
 render()
 controls.update();
}

function render() {

 renderer.render( scene, camera );           
}

0 个答案:

没有答案