2

我有一个article容器,里面有三个aside标签。第三个aside元素id='menuPuzzleType'包含一个Three.js脚本,该脚本制作两个立方体网格,并在 Canvas 渲染器中渲染它们。

<article id="popup">

    <aside id='close'><img src="img/close.png" onClick="aFunction()" /></aside>
    <aside id='msgPuzzleType'>Please choose the puzzle type you want to play</aside>
    <aside id='menuPuzzleType'>
        <script>
        function animate() {
            requestAnimationFrame( animate );
            render();
        }

        function render() {
            cube.rotation.y -= 0.03;
            cube2.rotation.y -=0.03;
            renderer2.render(scene2, camera2);
        }
        var container2 = document.getElementById('menuPuzzleType');

        //renderer
        var renderer2 = new THREE.CanvasRenderer();
        renderer2.setSize(400,400);//Was 100,100
        container2.appendChild(renderer2.domElement);

        //Scene
        var scene2 = new THREE.Scene();

        //Camera
        var camera2 = new THREE.PerspectiveCamera(50,50/50,1,1000);
        camera2.position.z = 240;//normal value is 100
        camera2.position.y=60;
        scene2.add(camera2);

        //Axes
        var axes2= new THREE.AxisHelper();

        //Add texture for the cube
        //Use image as texture
        var img2 = new THREE.MeshBasicMaterial({ //CHANGED to MeshBasicMaterial
            map:THREE.ImageUtils.loadTexture('img/2d.png') 
        });
        img2.map.needsUpdate = true; //ADDED

        //Add Cube
        var cube = new THREE.Mesh(new THREE.CubeGeometry(40,40,40),img2);
        cube.position.x =- 60;
        scene2.add(cube);

        var img3 = new THREE.MeshBasicMaterial({ //CHANGED to MeshBasicMaterial
            map:THREE.ImageUtils.loadTexture('img/3d.png') 
        });

        img3.map.needsUpdate = true; //ADDED

        var cube2 = new THREE.Mesh(new THREE.CubeGeometry(40,40,40),img3);
        cube2.position.x = 70; cube.position.y = 60; cube2.position.y=60;
        scene2.add(cube2);
        renderer2.render(scene2,camera2);

        animate();
        </script>
    </aside>
</article>

我需要将两个立方体放入article容器标签中。

这是我的CSS代码:

body{ overflow:hidden; }

article {
    border:solid 1px #00CC33;
    width:420px;
    height:200px;
    font-family: baskerville; 
    font-size: 16px; 
    margin-top: 50px;

    /*For IE9 compatibility*/
    behavior: url(border-radius.htc);
    border-radius: 8px;
    position:relative;
}

#popup {
    bottom:50%;
    position:relative;
    margin: 0px; 
    left:30%;
}

#msgPuzzleType{ margin-left:60px; }

img{
    behavior: url(border-radius.htc);
    border-radius: 8px;
    position:relative;
}

#menuPuzzleType{
    background-color:#999999;
    border:solid 1px #3300CC;
    height:200px;
}

如何将两个立方体移动到article容器标签中?

4

2 回答 2

2

您的问题的“Three.js”解决方案是这样做:

renderer2.setSize( 400, 150 );

您还硬连线了 的纵横比PerspectiveCamera,因此您需要使其与画布尺寸相匹配。

var camera2 = new THREE.PerspectiveCamera( 50, 400/150, 1, 1000 );

这将使画布更小,以便适合。然后,您可以将相机移近一些,以便您的对象具有您想要的大小。

于 2012-09-25T14:01:48.930 回答
1

使用您提供的链接,我更改了以下内容以将多维数据集放入文章中:

canvas {
    position: absolute;
    top: -80px;
}

在此处输入图像描述

于 2012-09-25T13:47:02.467 回答