Skip to content

Commit

Permalink
Book geometry
Browse files Browse the repository at this point in the history
Interior pages
  • Loading branch information
jasonsturges committed Nov 6, 2024
1 parent 2d2329d commit a37e4e4
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/geometry/books/BookGeometry.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import {BufferAttribute, BufferGeometry} from "three";
import { BoxGeometry, BufferAttribute, BufferGeometry } from "three";
import { mergeGeometries } from "three/addons/utils/BufferGeometryUtils.js";

export class BookGeometry extends BufferGeometry {
constructor(width = 1, height = 1.5, depth = 0.5, coverThickness = 0.05) {
constructor(width = 1, height = 1.5, depth = 0.5, coverThickness = 0.05, pageIndent = 0.05) {
super();

const w = width;
const h = height;
const d = depth;
const t = coverThickness;
const i = pageIndent;

const vertices = [
// Front cover
Expand Down Expand Up @@ -157,9 +158,14 @@ export class BookGeometry extends BufferGeometry {
const uvArray = new Float32Array(uvs);
const indexArray = new Uint16Array(indices);

this.setAttribute('position', new BufferAttribute(positions, 3));
this.setAttribute('normal', new BufferAttribute(normalArray, 3));
this.setAttribute('uv', new BufferAttribute(uvArray, 2));
this.setIndex(new BufferAttribute(indexArray, 1));
const coverGeometry = new BufferGeometry();
coverGeometry.setAttribute('position', new BufferAttribute(positions, 3));
coverGeometry.setAttribute('normal', new BufferAttribute(normalArray, 3));
coverGeometry.setAttribute('uv', new BufferAttribute(uvArray, 2));
coverGeometry.setIndex(new BufferAttribute(indexArray, 1));

const pagesGeometry = new BoxGeometry(width - t - i, h - i * 2, d - t * 2);
pagesGeometry.translate((width - t - i) / 2 + t, h / 2, -d / 2 );
this.copy(mergeGeometries([coverGeometry, pagesGeometry], true));
}
}

0 comments on commit a37e4e4

Please sign in to comment.