我创建了一些场景,添加到group_lev2;
group_lev2已添加到另一个组。像这样:
var group_top = new THREE.Object3D();
var group_lev2 = new THREE.Object3D();
var scene1,scene2,scene3 ...
group_lev2.add(SCENE1);
group_lev2.add(SCENE2);
group_lev2.add(scene3);
group_top.add(group_lev2);
我在firefox中运行它,
但是我的页面中没有看到任何内容
我将这些场景放入根组,显示;
但是我想要很多组合,使用不同的动画。
谢谢!
答案 0 :(得分:0)
我建议将scene1,scene2 ...作为子项添加到group_lev2
group_lev2.children(X) = sceneX;
答案 1 :(得分:0)
我认为你可以做你想做的事,但你需要新的THREE.Scene()而不是新的THREE.Object3D(),对吧?
<!DOCTYPE html><html><head>
<meta charset="UTF-8">
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r76/three.js"></script>
<script>
"use strict"
var scenetop, scenelev2, scene1, scene2, scene3;
var camera, light, mesh, geometry, material, renderer;
window.onload = function() {
renderer = new THREE.WebGLRenderer();
renderer.setSize(750, 750);
renderer.setClearColor(0xcccccc, 1);
document.body.appendChild(renderer.domElement);
camera = new THREE.PerspectiveCamera(30, 750/750);
camera.position.set(0, 0, 8);
camera.lookAt(new THREE.Vector3(0, 0, 0));
light = new THREE.DirectionalLight(0xffffff);
light.position.set(10, 10, 10);
// scenetop
scenetop = new THREE.Scene();
scenetop.add(light);
// scenelev2
scenelev2 = new THREE.Scene();
scenetop.add(scenelev2);
// scene1
scene1 = new THREE.Scene();
addsphere(.5, -1, -1, 0xffcccc, scene1);
scenelev2.add(scene1);
// scene2
scene2 = new THREE.Scene();
addsphere(.5, -1, +1, 0xccffcc, scene2);
scenelev2.add(scene2);
// scene3
scene3 = new THREE.Scene();
addsphere(.5, +1, -1, 0xccccff, scene3);
scenelev2.add(scene3);
renderer.render(scenetop, camera);
}
function addsphere (pr, px, py, pcolor, pscene) {
geometry = new THREE.SphereGeometry(pr);
material = new THREE.MeshPhongMaterial( { color:pcolor } );
mesh = new THREE.Mesh(geometry, material);
mesh.translateX(px);
mesh.translateY(py);
pscene.add(mesh);
}
</script></head><body></body></html>