refactor: move world concepts into engine
This commit is contained in:
parent
eeedcb8e48
commit
2d15c7ab8d
52 changed files with 3298 additions and 1558 deletions
|
|
@ -1,5 +1,7 @@
|
|||
import type { Vec3 } from "../../engine/math/Vec3"
|
||||
import { STRIDE, type Mesh } from "../../engine/scene/Mesh"
|
||||
import type { Material } from "../../engine/render/Material"
|
||||
import type { Prefab } from "../../engine/scene/Prefab"
|
||||
|
||||
const TAU = Math.PI * 2
|
||||
|
||||
|
|
@ -22,8 +24,35 @@ export type Boulder = {
|
|||
* field of boulders batches into a single draw call.
|
||||
*/
|
||||
export namespace Boulder {
|
||||
export function create(material: Material): Prefab<Boulder> {
|
||||
return {
|
||||
position: (boulder) => boulder.position,
|
||||
bakeNear: (boulder, batch) => build(boulder, batch.mesh(material)),
|
||||
bakeFar: (boulder, batch) =>
|
||||
build(boulder, batch.mesh(material), "impostor"),
|
||||
collider(boulder) {
|
||||
if (boulder.radius <= 0.7) {
|
||||
return null
|
||||
}
|
||||
return {
|
||||
shape: "box",
|
||||
minX: boulder.position.x - boulder.radius,
|
||||
maxX: boulder.position.x + boulder.radius,
|
||||
minZ: boulder.position.z - boulder.radius,
|
||||
maxZ: boulder.position.z + boulder.radius,
|
||||
top: boulder.position.y + boulder.radius * 0.7,
|
||||
standable: false,
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
/** `lod` "impostor" bakes a coarser rock (fewer facets) for far chunks. */
|
||||
export function build(boulder: Boulder, mesh: Mesh, lod: "full" | "impostor" = "full"): void {
|
||||
export function build(
|
||||
boulder: Boulder,
|
||||
mesh: Mesh,
|
||||
lod: "full" | "impostor" = "full",
|
||||
): void {
|
||||
const rand = rng(boulder.seed)
|
||||
const seg = lod === "impostor" ? 4 : 5
|
||||
const rings = lod === "impostor" ? 2 : 4
|
||||
|
|
@ -67,7 +96,11 @@ export namespace Boulder {
|
|||
/** Per-vertex radial scale in ~0.72..1.14 for a chunky, angular surface. The
|
||||
* longitude seam (last column == first) and each pole row (one shared value)
|
||||
* match so the mesh stays closed. */
|
||||
function jitterGrid(seg: number, rings: number, rand: () => number): number[][] {
|
||||
function jitterGrid(
|
||||
seg: number,
|
||||
rings: number,
|
||||
rand: () => number,
|
||||
): number[][] {
|
||||
const grid: number[][] = []
|
||||
for (let ir = 0; ir <= rings; ir++) {
|
||||
const pole = ir === 0 || ir === rings
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue