Skip to content

Commit

Permalink
Tree
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonsturges committed Nov 21, 2024
1 parent 6e0b0fb commit 72c9b5c
Showing 1 changed file with 34 additions and 32 deletions.
66 changes: 34 additions & 32 deletions src/models/trees/Tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@ import { Mesh, MeshStandardMaterial } from "three";
import { TreeGeometry } from "../../geometry/trees/TreeGeometry";

/**
* @example
* Material indices:
* 0. Trunk
* 1. leafSize
*
* Example usage:
* ```
* const tree = new Tree({
* trunkRadiusTop: 0.25,
* trunkRadiusBottom: 0.4,
Expand All @@ -15,8 +20,9 @@ import { TreeGeometry } from "../../geometry/trees/TreeGeometry";
* leafSpreadRadius: 1.5,
* leafColor: 0x228b22,
* });
* ```
*/
class Tree extends Mesh {
export class Tree extends Mesh<TreeGeometry, MeshStandardMaterial[]> {
constructor({
trunkRadiusTop = 0.25,
trunkRadiusBottom = 0.4,
Expand All @@ -29,36 +35,32 @@ class Tree extends Mesh {
leafSpreadRadius = 1.5,
leafColor = 0x228b22,
} = {}) {
super();
super(
new TreeGeometry({
trunkRadiusTop: trunkRadiusTop,
trunkRadiusBottom: trunkRadiusBottom,
trunkHeight: trunkHeight,
trunkSegments: trunkSegments,
leafSize: leafSize,
leafCount: leafCount,
leafDetail: leafDetail,
leafSpreadRadius: leafSpreadRadius,
}),
[
new MeshStandardMaterial({
color: trunkColor,
roughness: 0.9,
metalness: 0,
flatShading: true,
}),

const treeGeometry = new TreeGeometry({
trunkRadiusTop: trunkRadiusTop,
trunkRadiusBottom: trunkRadiusBottom,
trunkHeight: trunkHeight,
trunkSegments: trunkSegments,
leafSize: leafSize,
leafCount: leafCount,
leafDetail: leafDetail,
leafSpreadRadius: leafSpreadRadius,
});

const trunkMaterial = new MeshStandardMaterial({
color: trunkColor,
roughness: 0.9,
metalness: 0,
flatShading: true,
});

const leafMaterial = new MeshStandardMaterial({
color: leafColor,
roughness: 0.8,
metalness: 0,
flatShading: true,
});

this.geometry = treeGeometry;
this.material = [trunkMaterial, leafMaterial];
new MeshStandardMaterial({
color: leafColor,
roughness: 0.8,
metalness: 0,
flatShading: true,
}),
],
);
}
}

export { Tree };

0 comments on commit 72c9b5c

Please sign in to comment.