Skip to content

Commit

Permalink
Parallelogram box example
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonsturges committed Nov 24, 2024
1 parent 6e129aa commit 5860f99
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 0 deletions.
7 changes: 7 additions & 0 deletions examples/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,13 @@ <h2>Models</h2>
</ul>
</div>

<div>
<header>Primitives</header>
<ul>
<li><a href="/three-low-poly/models/primitives/parallelogram-box">Parallelogram Box</a></li>
</ul>
</div>

<div>
<header>Rocks</header>
<ul>
Expand Down
68 changes: 68 additions & 0 deletions examples/models/primitives/parallelogram-box.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Three Low Poly</title>
<style>
body {
margin: 0;
}
canvas {
display: block;
}
</style>
</head>
<body>
<script type="module">
import * as THREE from "three";
import GUI from "lil-gui";
import { ParallelogramBoxGeometry } from "../../../src/index.js";
import { VertexNormalsHelper } from "three-stdlib";
import { createOrbitScene } from "../../utils/orbitScene.js";

const { scene, camera, controls } = createOrbitScene();

// Material
const textureLoader = new THREE.TextureLoader();
const texture = textureLoader.load("https://threejs.org/examples/textures/uv_grid_opengl.jpg");
const material = new THREE.MeshStandardMaterial({
map: texture,
side: THREE.FrontSide,
});

// Mesh
const board = new ParallelogramBoxGeometry(5, 2, 0.5, Math.PI / 4); // Customize width, length, and angle
const mesh = new THREE.Mesh(board, material);
scene.add(mesh);

// Helpers
const normalsHelper = new VertexNormalsHelper(mesh, 1, 0xff0000);
scene.add(normalsHelper);

const axesHelper = new THREE.AxesHelper(5); // 5 is the length of the axes lines
scene.add(axesHelper);

// GUI
const params = {
width: 1,
height: 2,
depth: 0.5,
skew: Math.PI / 4,
};

const gui = new GUI();
gui.title("Parallelogram Box");
gui.add(params, "width", 0, 5, 0.01).name("Width").onChange(update);
gui.add(params, "height", 0, 5, 0.01).name("Height").onChange(update);
gui.add(params, "depth", 0, 5, 0.01).name("Depth").onChange(update);
gui.add(params, "skew", -Math.PI / 2, Math.PI / 2, 0.01).name("Skew").onChange(update);

function update() {
mesh.geometry.dispose();
mesh.geometry = new ParallelogramBoxGeometry(params.width, params.height, params.depth, params.skew);
normalsHelper.update();
}
</script>
</body>
</html>

0 comments on commit 5860f99

Please sign in to comment.