我正在尝试使用ObjectLoader()函数将blender场景导入到three.js。我想让它尽可能简单,没有动画只是在正确的位置具有正确的纹理和颜色的对象。不幸的是,three.js文档对于新手来说不是一个友好的地方。到目前为止,我设法从场景中绘制每个对象,但每个对象都是不同的颜色,平面缺乏纹理,它们都在错误的位置。我究竟做错了什么?这是我的.js代码:
var scene, camera, renderer;
var WIDTH = window.innerWidth;
var HEIGHT = window.innerHeight;
function init() {
scene = new THREE.Scene();
initCamera();
initLights();
initRenderer();
document.body.appendChild(renderer.domElement);
}
function initCamera() {
camera = new THREE.PerspectiveCamera(70, WIDTH / HEIGHT, 1, 10);
camera.position.set(0, 3.5, 5);
camera.lookAt(scene.position);
}
function initRenderer() {
renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setSize(WIDTH, HEIGHT);
}
function initLights() {
var light = new THREE.AmbientLight(0xffffff);
scene.add(light);
}
var loader = new THREE.ObjectLoader();
loader.load('./city.json', function(loadedObj) {
mesh = new THREE.Mesh(loadedObj);
var plane = loadedObj.getObjectByName("plane");
var building1 = loadedObj.getObjectByName("building1");
var building2 = loadedObj.getObjectByName("building2");
var building3 = loadedObj.getObjectByName("building3");
var building4 = loadedObj.getObjectByName("building4");
var building5 = loadedObj.getObjectByName("building5");
var building6 = loadedObj.getObjectByName("building6");
var building7 = loadedObj.getObjectByName("building7");
var building8 = loadedObj.getObjectByName("building8");
scene.add(loadedObj);
console.log(building1);
console.log(building2);
console.log(building3);
console.log(building4);
console.log(building5);
console.log(building6);
console.log(building7);
console.log(building8);
});
function render() {
requestAnimationFrame(render);
renderer.render(scene, camera);
}
init();
render();
是否有可能从混合器导出的方式有问题而不是代码?
编辑:对不起,这是我的city.json文件 city.json