-
Notifications
You must be signed in to change notification settings - Fork 0
/
clipping.html
56 lines (45 loc) · 1.73 KB
/
clipping.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Three.js Boolean Test</title>
<style>
body { margin: 0; }
canvas { display: block; }
</style>
</head>
<body>
<script src="https://threejs.org/build/three.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/examples/js/controls/OrbitControls.js"></script>
<script src="path_to_ThreeBSP_library.js"></script>
<script>
let scene = new THREE.Scene();
let camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
let renderer = new THREE.WebGLRenderer();
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
let controls = new THREE.OrbitControls(camera, renderer.domElement);
let ambientLight = new THREE.AmbientLight(0x404040, 2);
scene.add(ambientLight);
let directionalLight = new THREE.DirectionalLight(0xffffff, 0.5);
directionalLight.position.set(1, 1, 1).normalize();
scene.add(directionalLight);
let cubeGeometry = new THREE.BoxGeometry(1, 1, 1);
let sphereGeometry = new THREE.SphereGeometry(0.6, 32, 32);
let cubeBSP = new ThreeBSP(cubeGeometry);
let sphereBSP = new ThreeBSP(sphereGeometry);
let subtractedBSP = cubeBSP.subtract(sphereBSP);
let result = subtractedBSP.toMesh(new THREE.MeshLambertMaterial({ color: 0xff0000 }));
scene.add(result);
camera.position.set(2, 2, 3);
camera.lookAt(0, 0, 0);
function animate() {
requestAnimationFrame(animate);
controls.update();
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>