Files
blockly3d/webclient/src/utils/graphics/voxelGroup.ts
T
2026-06-17 10:54:13 +03:00

21 lines
722 B
TypeScript

import type { ObjectType, VoxelGroup, VoxelType } from "../../types";
export function getObjectVoxelGroups(
object: ObjectType,
voxelTypes: Record<string, VoxelType>,
): VoxelGroup[] {
const map = new Map<string, VoxelGroup>();
for (const idx in object.voxels) {
const v = object.voxels[idx];
const vt = voxelTypes[v.typeId];
const color = (v.color ?? vt?.color) ?? 'white';
const opacity = (v.opacity ?? vt?.opacity) ?? 1;
const key = `${color}-${opacity}`;
if (!map.has(key))
map.set(key, { id: key, color, opacity, positions: [] });
const p = v.position;
map.get(key)!.positions.push(p);
}
return [...map.values()];
}