使用three.js JSONLoader [英] using three.js JSONLoader

查看:3299
本文介绍了使用three.js JSONLoader的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

只是看不到模型导入到three.js场景中。
几何看起来很好,但无论我申请什么材料,模型都不会显示。

Just can't see models imported into three.js scene. The geometry looks fine but the model isn't displaying no matter what material I apply to it.

我是WebGL的新手,所以对我来说很难诊断,但我的猜测是在JSONLoader回调期间出现问题。

I'm new to WebGL so it's hard for me to diagnose, but my guess is that something is going wrong during the JSONLoader callback.

感谢您的帮助。

var camera, scene, renderer, mesh, loader;

init();
animate();

function init() {

    camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 1, 10000 );
    camera.position.z = 1000;

    scene = new THREE.Scene();

    loader = new THREE.JSONLoader();

    loader.load( "scripts/model.js", 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 );

    var ambientLight = new THREE.AmbientLight(0x555555);
    scene.add(ambientLight);

    var directionalLight = new THREE.DirectionalLight(0xffffff);
    directionalLight.position.set(1, 1, 1).normalize();
    scene.add(directionalLight);

    renderer = new THREE.WebGLRenderer();
    renderer.setSize( window.innerWidth, window.innerHeight );

    document.body.appendChild( renderer.domElement );

}

function animate() {

    requestAnimationFrame( animate );

    mesh.rotation.x += 0.05;

    renderer.render( scene, camera );
}


推荐答案

您正在添加网格模型完成加载前的场景。

You are adding the mesh to the scene before the model finishes loading.

移动线

scene.add( mesh );

进入加载程序回调函数。

into the loader callback function.

这篇关于使用three.js JSONLoader的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆