[英]Three.js and colladaloader
I am new to Three.JS and am trying to load a load a very simple (single cube) Sketchup model into Three.JS via the ColladaLoader, I get no errors but nothing is displayed: 我是Three.JS的新手,我试图通过ColladaLoader将一个非常简单的(单一立方体)Sketchup模型加载到Three.JS中,我没有得到任何错误,但没有显示任何内容:
var renderer = new THREE.WebGLRenderer();
var loader = new THREE.ColladaLoader();
var scene = new THREE.Scene();
var camera = new THREE.Camera();
loader.load('Test.dae', function (result) {
scene.add(result.scene);
});
camera = new THREE.PerspectiveCamera(35, window.innerWidth / window.innerHeight, 1, 10000 );
camera.position.set(0, 0, 5);
scene.add(camera);
renderer.render(scene,camera);
Can anyone spot any immediate errors? 有人能发现任何即时错误吗? Thanks
谢谢
Fixed. 固定。 Whilst I had declared the renderer, I hadn't attached it to the document.
虽然我已经宣布了渲染器,但我没有将它附加到文档中。 The following code works:
以下代码有效:
var scene = new THREE.Scene();
var camera = new THREE.PerspectiveCamera(100, window.innerWidth / window.innerHeight, 0.1, 1000);
var renderer = new THREE.WebGLRenderer();
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
camera.position.set(0, 0, 4);
var loader = new THREE.ColladaLoader();
loader.load("test.dae", function (result) {
scene.add(result.scene);
});
function render() {
requestAnimationFrame(render);
renderer.render(scene, camera);
}
render();
You need to rerender the scene after the collada is loaded. 加载collada后需要重新渲染场景。 Something like
就像是
loader.load('Test.dae', function (result) {
scene.add(result.scene);
renderer.render(scene,camera);
});
Additionally: 另外:
loader.load('test.dae', function colladaReady(collada) {
localObject = collada.scene;
localObject.scale.x = localObject.scale.y = localObject.scale.z = 2;
localObject.updateMatrix();
scene.add(localObject);
I think you need to add the object in the collada scene, or there might be problem with the scaling of the object that you are adding, scale it and than update the matrix of the object. 我认为您需要在collada场景中添加对象,或者您正在添加的对象的缩放可能存在问题,缩放它并更新对象的矩阵。
如果您仍然遇到问题,可能是某些版本的IE停止下载本地文件(您的Test.dae),因此可能值得使用firefox或将您的代码放在服务器上进行尝试。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.