({
box,
cells,
dotScale,
color,
opacity,
}: {
box: THREE.Box3;
cells: THREE.Vector3;
dotScale: number;
color?: THREE.Color;
opacity?: number;
})
| 22 | } from "../dyno"; |
| 23 | |
| 24 | export function staticBox({ |
| 25 | box, |
| 26 | cells, |
| 27 | dotScale, |
| 28 | color, |
| 29 | opacity, |
| 30 | }: { |
| 31 | box: THREE.Box3; |
| 32 | cells: THREE.Vector3; |
| 33 | dotScale: number; |
| 34 | color?: THREE.Color; |
| 35 | opacity?: number; |
| 36 | }) { |
| 37 | cells.x = Math.max(1, Math.round(cells.x)); |
| 38 | cells.y = Math.max(1, Math.round(cells.y)); |
| 39 | cells.z = Math.max(1, Math.round(cells.z)); |
| 40 | opacity = opacity ?? 1; |
| 41 | const numSplats = cells.x * cells.y * cells.z; |
| 42 | const dynoX = dynoConst("int", cells.x); |
| 43 | const dynoY = dynoConst("int", cells.y); |
| 44 | const dynoZ = dynoConst("int", cells.z); |
| 45 | |
| 46 | const dynoTime = dynoFloat(0); |
| 47 | const generator = new SplatGenerator({ |
| 48 | numSplats, |
| 49 | generator: dynoBlock( |
| 50 | { index: "int" }, |
| 51 | { gsplat: Gsplat }, |
| 52 | ({ index }) => { |
| 53 | if (!index) { |
| 54 | throw new Error("index is undefined"); |
| 55 | } |
| 56 | const cellX = imod(index, dynoX); |
| 57 | const index2 = div(index, dynoX); |
| 58 | const cellY = imod(index2, dynoY); |
| 59 | const cellZ = div(index2, dynoY); |
| 60 | const cell = combine({ |
| 61 | vectorType: "ivec3", |
| 62 | x: cellX, |
| 63 | y: cellY, |
| 64 | z: cellZ, |
| 65 | }); |
| 66 | |
| 67 | const intTime = floatBitsToInt(dynoTime); |
| 68 | const inputs = combine({ vectorType: "ivec2", x: index, y: intTime }); |
| 69 | const random = hashVec3(inputs); |
| 70 | const min = dynoConst("vec3", box.min); |
| 71 | const max = dynoConst("vec3", box.max); |
| 72 | const size = sub(max, min); |
| 73 | const coord = div(add(vec3(cell), random), dynoConst("vec3", cells)); |
| 74 | let r: DynoVal<"float">; |
| 75 | let g: DynoVal<"float">; |
| 76 | let b: DynoVal<"float">; |
| 77 | if (color) { |
| 78 | r = dynoConst("float", color.r); |
| 79 | g = dynoConst("float", color.g); |
| 80 | b = dynoConst("float", color.b); |
| 81 | } else { |
nothing calls this directly
no test coverage detected