workspaces folders
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
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[0] + 0.5, p[1] + 0.5, p[2] + 0.5]);
|
||||
}
|
||||
return [...map.values()];
|
||||
}
|
||||
Reference in New Issue
Block a user