从json模型THREE.JS加载纹理

时间:2016-09-28 12:13:25

标签: javascript json three.js

我在台球桌上制作了一个模型,我在maya编辑器中添加了纹理,但是当我将它加载到javascript文件中时,它不会显示纹理。

如何让纹理工作

var scene, camera, renderer;
var controls, mesh;
init();
animate();

function init() {
scene = new THREE.Scene();
var directionalLight = new THREE.DirectionalLight( 0xffffff, 0.8 );
directionalLight.position.set( 0, 10, 0 );
scene.add( directionalLight );
var loader = new THREE.JSONLoader();
loader.load( "js/biljart.json", function ( geometry) {
    mesh = new THREE.Mesh( geometry, new THREE.MeshPhongMaterial() );
    mesh.position.x =0;
    mesh.position.y =-1;
    mesh.position.z =0;
    scene.add(mesh);
});

camera = new THREE.PerspectiveCamera(65, window.innerWidth / window.innerHeight, 1, 10000);
camera.position.z = 10;
renderer = new THREE.WebGLRenderer();
renderer.setSize(window.innerWidth - 20, window.innerHeight - 20);
document.body.appendChild(renderer.domElement);
controls = new THREE.OrbitControls( camera );
controls.addEventListener( 'change', animate );
}

function animate() {
renderer.render(scene, camera);
}

这是js文件

0 个答案:

没有答案