我正在做增強現實,需要將Object3D
添加到另一個對象進行渲染。threejs Colladaloader:如何將場景變成object3d
我使用ColladaLoader
導入對象;然而,返回類型是Scene
- 不是我所需要的。
如何將場景轉換爲Object3D
?
這裏是我當前的代碼:
var mouse;
var mouseObject;
var loader = new THREE.ColladaLoader();
// Need to convert the axes so that our model does not stand upside-down:
loader.options.convertUpAxis = true;
// Load the 3D collada file (robot01.dae in my example), and specify
// the callback function that is called once the model has loaded:
loader.load('assets/mouse_v1_model/meshes/mouse_v1_model_animated.dae', function (collada) {
// Grab the collada scene data:
mouse = collada.scene.children[0];
// No skin applied to my model so no need for the following:
// var skin = collada.skins[ 0 ];
mouseObject = new THREE.Object3D();
for (var j = 0; j < mouse.children.length; j++) {
mouseObject.add(new THREE.Mesh(mouse.children[j].geometry, mouse.children[j].material));
}
mouseObject.matrixAutoUpdate = false;
mouseObject.position.z = 100;
// Scale-up the model so that we can see it:
/* mouse.scale.x = mouse.scale.y = mouse.scale.z = 3.0;
mouse.rotation.z = 360;
mouse.rotation.x = 180;
mouse.rotation.y = 180;
mouse.position.x = 0;
mouse.position.y = -10;
mouse.position.z = 100;
mouse.updateMatrix();*/
//arScene.scene.add(mouseObject);
});
和
// Load the marker to use.
arController.loadMultiMarker('jsartoolkit5/examples/Data/multi/marker.dat', function(marker, markerNum) {
window.onclick = function() {
arScene.video.play();
};
// Create an object that tracks the marker transform.
var markerRoot = arController.createThreeMultiMarker(marker);
arScene.scene.add(markerRoot);
for (var i=0; i<markerNum; i++) {
markerRoot.markers[i] = mouseObject;
markerRoot.add(markerRoot.markers[i]);
}
// Call arScene.renderOn on each frame,
// it does marker detection, updates the Three.js scene and draws a new frame.
var tick = function() {
requestAnimationFrame(tick);
arScene.process();
arScene.renderOn(renderer);
};
tick();
});
您可以在現場得到你的對象加載器回調,如果你像這個'result.children'那樣訪問加載結果。 – Wilt
我就是這麼做的;看到我爲問題添加的代碼片段。 –
我用一個例子添加了一個答案... – Wilt