|
1 | | -import { type BufferGeometry, ConeGeometry, DoubleSide, Group, Mesh } from 'three' |
| 1 | +import { BufferGeometry, DoubleSide, Float32BufferAttribute, Group, Mesh } from 'three' |
2 | 2 | import { mergeGeometries } from 'three/examples/jsm/utils/BufferGeometryUtils.js' |
3 | 3 | import { GRASS_PRESETS } from './grass-presets' |
4 | 4 | import type { GrassNode, GrassPreset } from './grass-schema' |
@@ -40,9 +40,35 @@ function buildGrass(preset: GrassPreset, seed: number, bladeColor: string): Grou |
40 | 40 | const blades: BufferGeometry[] = [] |
41 | 41 | for (let i = 0; i < spec.blades; i++) { |
42 | 42 | const bh = h * (0.6 + rng() * 0.6) |
43 | | - const blade = new ConeGeometry(0.02, bh, 3) |
44 | | - blade.scale(1, 1, 0.3) // flatten the cone into a blade |
45 | | - blade.translate(0, bh / 2, 0) |
| 43 | + const halfBaseWidth = 0.006 |
| 44 | + const halfTipWidth = 0.0006 |
| 45 | + const blade = new BufferGeometry() |
| 46 | + blade.setAttribute( |
| 47 | + 'position', |
| 48 | + new Float32BufferAttribute( |
| 49 | + [ |
| 50 | + -halfBaseWidth, |
| 51 | + 0, |
| 52 | + 0, |
| 53 | + halfBaseWidth, |
| 54 | + 0, |
| 55 | + 0, |
| 56 | + halfTipWidth, |
| 57 | + bh, |
| 58 | + 0, |
| 59 | + -halfTipWidth, |
| 60 | + bh, |
| 61 | + 0, |
| 62 | + ], |
| 63 | + 3, |
| 64 | + ), |
| 65 | + ) |
| 66 | + blade.setAttribute( |
| 67 | + 'uv', |
| 68 | + new Float32BufferAttribute([0, 0, 1, 0, 0.55, 1, 0.45, 1], 2), |
| 69 | + ) |
| 70 | + blade.setIndex([0, 1, 2, 0, 2, 3]) |
| 71 | + blade.computeVertexNormals() |
46 | 72 | blade.rotateZ((rng() - 0.5) * 0.7) // lean |
47 | 73 | const angle = rng() * Math.PI * 2 |
48 | 74 | blade.rotateY(angle) |
|
0 commit comments