gpt4 book ai didi

javascript - 使用 Three.js 和 CSG 设置位置

转载 作者:行者123 更新时间:2023-11-28 09:46:07 31 4
gpt4 key购买 nike

当我使用它作为立方体和球体的代码时,它会切掉该立方体的某些部分:

    <!DOCTYPE html>

<html>

<head>

<script type="text/javascript" src="csg.js"></script>
<script type="text/javascript" src="http://chandler.prallfamily.com/threebuilds/builds/r46/ThreeMin.js"></script>
<script type="text/javascript" src="ThreeCSG.js"></script>

<script type="text/javascript">

window.onload = function() {

var projector = new THREE.Projector( );
var renderer = new THREE.WebGLRenderer({antialias: false});
renderer.setSize(800, 640);

document.getElementById('viewport').appendChild(renderer.domElement);

var scene = new THREE.Scene();

var camera = new THREE.PerspectiveCamera(
35,
800 / 640,
1,
10000
);
camera.position.set(5, 1.8, 5);
camera.lookAt(scene.position);

var cube = THREE.CSG.toCSG(
new THREE.CubeGeometry( 2, 2, 2 ),
new THREE.Vector3(-1, 0, 0)
);
var sphere = THREE.CSG.toCSG(new THREE.SphereGeometry(1.4, 16, 16));
var geometry = cube.subtract(sphere);
var mesh = new THREE.Mesh(
THREE.CSG.fromCSG( geometry ),
new THREE.MeshNormalMaterial()
);
scene.add( mesh );

renderer.render(scene, camera);

}

</script>

</head>

<body>

<div id="viewport"></div>

</body>

</html>

我现在如何设置立方体的位置?我是否需要诸如cube.CSG.position.set之类的东西,或者CSG库是否有特殊的方法可供使用?

谢谢!

最佳答案

设置渲染器后需要调用一个函数,例如:

animate();

定义如下:

function animate()
{
requestAnimationFrame(animate);
cube.position.x = your_value;
}

关于javascript - 使用 Three.js 和 CSG 设置位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11784967/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com