refactor: move world concepts into engine
This commit is contained in:
parent
eeedcb8e48
commit
2d15c7ab8d
52 changed files with 3298 additions and 1558 deletions
29
engine/render/Chunk.ts
Normal file
29
engine/render/Chunk.ts
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
import type { DrawGroup } from "./Material"
|
||||
import type { Vec3 } from "../math/Vec3"
|
||||
|
||||
export type Bounds3 = {
|
||||
minX: number
|
||||
minY: number
|
||||
minZ: number
|
||||
maxX: number
|
||||
maxY: number
|
||||
maxZ: number
|
||||
}
|
||||
|
||||
/** One cullable section of static world geometry with two engine-supported LODs. */
|
||||
export type Chunk = Bounds3 & {
|
||||
readonly near: readonly DrawGroup[]
|
||||
readonly far: readonly DrawGroup[]
|
||||
}
|
||||
|
||||
export namespace Chunk {
|
||||
export function isFar(chunk: Chunk, eye: Vec3, lodDistance: number): boolean {
|
||||
if (!(lodDistance < Infinity)) {
|
||||
return false
|
||||
}
|
||||
const dx = eye.x - Math.max(chunk.minX, Math.min(chunk.maxX, eye.x))
|
||||
const dy = eye.y - Math.max(chunk.minY, Math.min(chunk.maxY, eye.y))
|
||||
const dz = eye.z - Math.max(chunk.minZ, Math.min(chunk.maxZ, eye.z))
|
||||
return dx * dx + dy * dy + dz * dz > lodDistance * lodDistance
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue