@playdrop/playdrop-cli 0.7.13 → 0.7.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. package/config/client-meta.json +1 -1
  2. package/node_modules/@playdrop/ai-client/dist/index.js +461 -444
  3. package/node_modules/@playdrop/ai-client/package.json +1 -1
  4. package/node_modules/@playdrop/api-client/dist/client.js +903 -882
  5. package/node_modules/@playdrop/api-client/dist/core/errors.js +69 -45
  6. package/node_modules/@playdrop/api-client/dist/core/request.js +188 -159
  7. package/node_modules/@playdrop/api-client/dist/domains/admin.js +516 -491
  8. package/node_modules/@playdrop/api-client/dist/domains/ai.js +40 -14
  9. package/node_modules/@playdrop/api-client/dist/domains/apps.js +480 -462
  10. package/node_modules/@playdrop/api-client/dist/domains/asset-packs.js +439 -419
  11. package/node_modules/@playdrop/api-client/dist/domains/assets.js +696 -676
  12. package/node_modules/@playdrop/api-client/dist/domains/auth.js +346 -320
  13. package/node_modules/@playdrop/api-client/dist/domains/comments.js +124 -98
  14. package/node_modules/@playdrop/api-client/dist/domains/free-credits.js +91 -65
  15. package/node_modules/@playdrop/api-client/dist/domains/me.js +71 -45
  16. package/node_modules/@playdrop/api-client/dist/domains/payments.js +407 -386
  17. package/node_modules/@playdrop/api-client/dist/domains/player-meta.js +144 -118
  18. package/node_modules/@playdrop/api-client/dist/domains/search.js +117 -104
  19. package/node_modules/@playdrop/api-client/dist/domains/tags.js +188 -162
  20. package/node_modules/@playdrop/api-client/dist/index.js +993 -552
  21. package/node_modules/@playdrop/api-client/package.json +1 -1
  22. package/node_modules/@playdrop/boxel-three/dist/src/animations.js +84 -62
  23. package/node_modules/@playdrop/boxel-three/dist/src/builders.js +341 -308
  24. package/node_modules/@playdrop/boxel-three/dist/src/context.js +55 -29
  25. package/node_modules/@playdrop/boxel-three/dist/src/exporters/glb.js +856 -858
  26. package/node_modules/@playdrop/boxel-three/dist/src/exporters/image.js +267 -261
  27. package/node_modules/@playdrop/boxel-three/dist/src/index.js +64 -15
  28. package/node_modules/@playdrop/boxel-three/dist/src/instantiate.js +89 -63
  29. package/node_modules/@playdrop/boxel-three/dist/src/nodes.js +81 -56
  30. package/node_modules/@playdrop/boxel-three/dist/src/overlays.js +112 -86
  31. package/node_modules/@playdrop/boxel-three/dist/src/primitives.js +45 -17
  32. package/node_modules/@playdrop/boxel-three/dist/src/scene.js +160 -136
  33. package/node_modules/@playdrop/boxel-three/dist/src/skinned-mesh.js +582 -584
  34. package/node_modules/@playdrop/boxel-three/dist/src/texture-atlas.js +123 -97
  35. package/node_modules/@playdrop/boxel-three/dist/src/textures.js +207 -182
  36. package/node_modules/@playdrop/boxel-three/dist/src/types.js +15 -1
  37. package/node_modules/@playdrop/boxel-three/dist/src/voxels/faces.js +451 -425
  38. package/node_modules/@playdrop/boxel-three/dist/src/voxels/mesher.js +109 -84
  39. package/node_modules/@playdrop/boxel-three/dist/test/export-image.playwright.test.js +127 -106
  40. package/node_modules/@playdrop/boxel-three/dist/test/fixtures/render-worker.js +73 -51
  41. package/node_modules/@playdrop/boxel-three/dist/test/glb-skinned.test.js +97 -79
  42. package/node_modules/@playdrop/boxel-three/dist/test/index.test.js +29 -7
  43. package/node_modules/@playdrop/boxel-three/dist/test/instantiate.test.js +80 -60
  44. package/node_modules/@playdrop/boxel-three/dist/test/overlays.test.js +41 -19
  45. package/node_modules/@playdrop/boxel-three/dist/test/scene-filter.test.js +72 -50
  46. package/node_modules/@playdrop/boxel-three/dist/test/scene-smoke.test.js +84 -62
  47. package/node_modules/@playdrop/boxel-three/dist/test/skinned-mesh.test.js +69 -47
  48. package/node_modules/@playdrop/boxel-three/dist/test/textured-overlay.test.js +129 -109
  49. package/node_modules/@playdrop/boxel-three/dist/test/voxels.test.js +40 -18
  50. package/node_modules/@playdrop/boxel-three/package.json +1 -1
  51. package/node_modules/@playdrop/config/client-meta.json +1 -1
  52. package/node_modules/@playdrop/config/dist/tsconfig.tsbuildinfo +1 -1
  53. package/node_modules/@playdrop/types/dist/api.js +289 -203
  54. package/node_modules/@playdrop/types/dist/app-capability-filters.js +112 -62
  55. package/node_modules/@playdrop/types/dist/app.js +91 -45
  56. package/node_modules/@playdrop/types/dist/asset-pack.js +37 -5
  57. package/node_modules/@playdrop/types/dist/asset-spec.js +170 -90
  58. package/node_modules/@playdrop/types/dist/asset.js +186 -108
  59. package/node_modules/@playdrop/types/dist/content-license.js +49 -15
  60. package/node_modules/@playdrop/types/dist/creator-public-image.js +60 -32
  61. package/node_modules/@playdrop/types/dist/ecs.js +102 -82
  62. package/node_modules/@playdrop/types/dist/engine-builtins.js +603 -573
  63. package/node_modules/@playdrop/types/dist/entity.js +63 -53
  64. package/node_modules/@playdrop/types/dist/graph.js +116 -80
  65. package/node_modules/@playdrop/types/dist/index.js +47 -20
  66. package/node_modules/@playdrop/types/dist/owned-assets.js +55 -33
  67. package/node_modules/@playdrop/types/dist/player-meta.js +151 -100
  68. package/node_modules/@playdrop/types/dist/realtime.js +27 -7
  69. package/node_modules/@playdrop/types/dist/version.js +182 -124
  70. package/node_modules/@playdrop/types/package.json +1 -1
  71. package/package.json +1 -1
@@ -1,442 +1,468 @@
1
- export const FACE_ORDER = ['east', 'west', 'top', 'bottom', 'north', 'south'];
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var faces_exports = {};
19
+ __export(faces_exports, {
20
+ FACE_ORDER: () => FACE_ORDER,
21
+ generateVoxelFaceSurfaces: () => generateVoxelFaceSurfaces
22
+ });
23
+ module.exports = __toCommonJS(faces_exports);
24
+ const FACE_ORDER = ["east", "west", "top", "bottom", "north", "south"];
2
25
  const FACE_CONFIGS = {
3
- east: { axis: 0, direction: 1, uAxis: 2, vAxis: 1 },
4
- west: { axis: 0, direction: -1, uAxis: 2, vAxis: 1 },
5
- top: { axis: 1, direction: 1, uAxis: 0, vAxis: 2 },
6
- bottom: { axis: 1, direction: -1, uAxis: 0, vAxis: 2 },
7
- north: { axis: 2, direction: 1, uAxis: 0, vAxis: 1 },
8
- south: { axis: 2, direction: -1, uAxis: 0, vAxis: 1 },
26
+ east: { axis: 0, direction: 1, uAxis: 2, vAxis: 1 },
27
+ west: { axis: 0, direction: -1, uAxis: 2, vAxis: 1 },
28
+ top: { axis: 1, direction: 1, uAxis: 0, vAxis: 2 },
29
+ bottom: { axis: 1, direction: -1, uAxis: 0, vAxis: 2 },
30
+ north: { axis: 2, direction: 1, uAxis: 0, vAxis: 1 },
31
+ south: { axis: 2, direction: -1, uAxis: 0, vAxis: 1 }
9
32
  };
10
33
  function clamp(value, min, max) {
11
- return Math.min(max, Math.max(min, value));
34
+ return Math.min(max, Math.max(min, value));
12
35
  }
13
36
  function getVoxelAt(voxels, dims, x, y, z) {
14
- if (x < 0 || y < 0 || z < 0)
15
- return 0;
16
- if (x >= dims[0] || y >= dims[1] || z >= dims[2])
17
- return 0;
18
- const index = x + dims[0] * (y + dims[1] * z);
19
- return voxels[index] ?? 0;
37
+ if (x < 0 || y < 0 || z < 0)
38
+ return 0;
39
+ if (x >= dims[0] || y >= dims[1] || z >= dims[2])
40
+ return 0;
41
+ const index = x + dims[0] * (y + dims[1] * z);
42
+ return voxels[index] ?? 0;
20
43
  }
21
44
  function buildFaceGeometry(face, config, size) {
22
- const positions = new Float32Array(12);
23
- const normals = new Float32Array(12);
24
- const uvs = new Float32Array(8);
25
- // Establish canonical vertex order (counter-clockwise as seen from outside)
26
- const vertexOrder = (() => {
27
- switch (face) {
28
- case 'east':
29
- return [
30
- [-1, -1],
31
- [-1, 1],
32
- [1, 1],
33
- [1, -1],
34
- ];
35
- case 'west':
36
- return [
37
- [1, -1],
38
- [1, 1],
39
- [-1, 1],
40
- [-1, -1],
41
- ];
42
- case 'top':
43
- return [
44
- [-1, -1],
45
- [-1, 1],
46
- [1, 1],
47
- [1, -1],
48
- ];
49
- case 'bottom':
50
- return [
51
- [-1, -1],
52
- [1, -1],
53
- [1, 1],
54
- [-1, 1],
55
- ];
56
- case 'north':
57
- return [
58
- [-1, -1],
59
- [1, -1],
60
- [1, 1],
61
- [-1, 1],
62
- ];
63
- case 'south':
64
- default:
65
- return [
66
- [1, -1],
67
- [-1, -1],
68
- [-1, 1],
69
- [1, 1],
70
- ];
71
- }
72
- })();
73
- const indices = new Uint16Array([0, 1, 2, 0, 2, 3]);
74
- const halfSize = [size[0] / 2, size[1] / 2, size[2] / 2];
75
- const centerCoordinate = config.direction > 0 ? halfSize[config.axis] : -halfSize[config.axis];
76
- const uHalf = size[config.uAxis] / 2;
77
- const vHalf = size[config.vAxis] / 2;
78
- const normalVector = [0, 0, 0];
79
- normalVector[config.axis] = config.direction;
80
- vertexOrder.forEach(([uSign, vSign], index) => {
81
- const offset = index * 3;
82
- const position = [0, 0, 0];
83
- position[config.axis] = centerCoordinate;
84
- position[config.uAxis] = uSign * uHalf;
85
- position[config.vAxis] = vSign * vHalf;
86
- positions[offset] = position[0];
87
- positions[offset + 1] = position[1];
88
- positions[offset + 2] = position[2];
89
- normals[offset] = normalVector[0];
90
- normals[offset + 1] = normalVector[1];
91
- normals[offset + 2] = normalVector[2];
92
- });
93
- const baseUvs = (() => {
94
- switch (face) {
95
- case 'east':
96
- return [
97
- [0, 1],
98
- [0, 0],
99
- [1, 0],
100
- [1, 1],
101
- ];
102
- case 'west':
103
- return [
104
- [1, 1],
105
- [1, 0],
106
- [0, 0],
107
- [0, 1],
108
- ];
109
- case 'top':
110
- return [
111
- [0, 1],
112
- [0, 0],
113
- [1, 0],
114
- [1, 1],
115
- ];
116
- case 'bottom':
117
- return [
118
- [0, 0],
119
- [1, 0],
120
- [1, 1],
121
- [0, 1],
122
- ];
123
- case 'north':
124
- return [
125
- [0, 1],
126
- [1, 1],
127
- [1, 0],
128
- [0, 0],
129
- ];
130
- case 'south':
131
- default:
132
- return [
133
- [1, 1],
134
- [0, 1],
135
- [0, 0],
136
- [1, 0],
137
- ];
138
- }
139
- })();
140
- baseUvs.forEach(([u, v], index) => {
141
- uvs[index * 2] = u;
142
- uvs[index * 2 + 1] = v;
143
- });
144
- return { positions, normals, uvs, indices };
145
- }
146
- export function generateVoxelFaceSurfaces(options) {
147
- const { primitive, materialsById, defaultColor } = options;
148
- if (!Array.isArray(primitive.voxels) || primitive.voxels.length === 0) {
149
- return [];
45
+ const positions = new Float32Array(12);
46
+ const normals = new Float32Array(12);
47
+ const uvs = new Float32Array(8);
48
+ const vertexOrder = (() => {
49
+ switch (face) {
50
+ case "east":
51
+ return [
52
+ [-1, -1],
53
+ [-1, 1],
54
+ [1, 1],
55
+ [1, -1]
56
+ ];
57
+ case "west":
58
+ return [
59
+ [1, -1],
60
+ [1, 1],
61
+ [-1, 1],
62
+ [-1, -1]
63
+ ];
64
+ case "top":
65
+ return [
66
+ [-1, -1],
67
+ [-1, 1],
68
+ [1, 1],
69
+ [1, -1]
70
+ ];
71
+ case "bottom":
72
+ return [
73
+ [-1, -1],
74
+ [1, -1],
75
+ [1, 1],
76
+ [-1, 1]
77
+ ];
78
+ case "north":
79
+ return [
80
+ [-1, -1],
81
+ [1, -1],
82
+ [1, 1],
83
+ [-1, 1]
84
+ ];
85
+ case "south":
86
+ default:
87
+ return [
88
+ [1, -1],
89
+ [-1, -1],
90
+ [-1, 1],
91
+ [1, 1]
92
+ ];
150
93
  }
151
- const size = primitive.size ?? [1, 1, 1];
152
- const dims = [
153
- Math.max(1, Math.round(size[0])),
154
- Math.max(1, Math.round(size[1])),
155
- Math.max(1, Math.round(size[2])),
156
- ];
157
- if (primitive.voxels.length !== dims[0] * dims[1] * dims[2]) {
158
- return [];
94
+ })();
95
+ const indices = new Uint16Array([0, 1, 2, 0, 2, 3]);
96
+ const halfSize = [size[0] / 2, size[1] / 2, size[2] / 2];
97
+ const centerCoordinate = config.direction > 0 ? halfSize[config.axis] : -halfSize[config.axis];
98
+ const uHalf = size[config.uAxis] / 2;
99
+ const vHalf = size[config.vAxis] / 2;
100
+ const normalVector = [0, 0, 0];
101
+ normalVector[config.axis] = config.direction;
102
+ vertexOrder.forEach(([uSign, vSign], index) => {
103
+ const offset = index * 3;
104
+ const position = [0, 0, 0];
105
+ position[config.axis] = centerCoordinate;
106
+ position[config.uAxis] = uSign * uHalf;
107
+ position[config.vAxis] = vSign * vHalf;
108
+ positions[offset] = position[0];
109
+ positions[offset + 1] = position[1];
110
+ positions[offset + 2] = position[2];
111
+ normals[offset] = normalVector[0];
112
+ normals[offset + 1] = normalVector[1];
113
+ normals[offset + 2] = normalVector[2];
114
+ });
115
+ const baseUvs = (() => {
116
+ switch (face) {
117
+ case "east":
118
+ return [
119
+ [0, 1],
120
+ [0, 0],
121
+ [1, 0],
122
+ [1, 1]
123
+ ];
124
+ case "west":
125
+ return [
126
+ [1, 1],
127
+ [1, 0],
128
+ [0, 0],
129
+ [0, 1]
130
+ ];
131
+ case "top":
132
+ return [
133
+ [0, 1],
134
+ [0, 0],
135
+ [1, 0],
136
+ [1, 1]
137
+ ];
138
+ case "bottom":
139
+ return [
140
+ [0, 0],
141
+ [1, 0],
142
+ [1, 1],
143
+ [0, 1]
144
+ ];
145
+ case "north":
146
+ return [
147
+ [0, 1],
148
+ [1, 1],
149
+ [1, 0],
150
+ [0, 0]
151
+ ];
152
+ case "south":
153
+ default:
154
+ return [
155
+ [1, 1],
156
+ [0, 1],
157
+ [0, 0],
158
+ [1, 0]
159
+ ];
159
160
  }
160
- const voxelSize = [1, 1, 1];
161
- const primitiveSize = [
162
- dims[0] * voxelSize[0],
163
- dims[1] * voxelSize[1],
164
- dims[2] * voxelSize[2],
165
- ];
166
- const palette = primitive.palette ?? [];
167
- const patches = [];
168
- const createEmptyCell = () => ({
169
- color: [0, 0, 0, 0],
170
- emissive: [0, 0, 0, 0],
171
- occupied: false,
172
- });
173
- const ensurePlane = (planes, planeIndex, surfaceCoord, width, height) => {
174
- let plane = planes.get(planeIndex);
175
- if (!plane) {
176
- const cells = Array.from({ length: height }, () => Array.from({ length: width }, () => createEmptyCell()));
177
- plane = { surfaceCoord, cells };
178
- planes.set(planeIndex, plane);
161
+ })();
162
+ baseUvs.forEach(([u, v], index) => {
163
+ uvs[index * 2] = u;
164
+ uvs[index * 2 + 1] = v;
165
+ });
166
+ return { positions, normals, uvs, indices };
167
+ }
168
+ function generateVoxelFaceSurfaces(options) {
169
+ const { primitive, materialsById, defaultColor } = options;
170
+ if (!Array.isArray(primitive.voxels) || primitive.voxels.length === 0) {
171
+ return [];
172
+ }
173
+ const size = primitive.size ?? [1, 1, 1];
174
+ const dims = [
175
+ Math.max(1, Math.round(size[0])),
176
+ Math.max(1, Math.round(size[1])),
177
+ Math.max(1, Math.round(size[2]))
178
+ ];
179
+ if (primitive.voxels.length !== dims[0] * dims[1] * dims[2]) {
180
+ return [];
181
+ }
182
+ const voxelSize = [1, 1, 1];
183
+ const primitiveSize = [
184
+ dims[0] * voxelSize[0],
185
+ dims[1] * voxelSize[1],
186
+ dims[2] * voxelSize[2]
187
+ ];
188
+ const palette = primitive.palette ?? [];
189
+ const patches = [];
190
+ const createEmptyCell = () => ({
191
+ color: [0, 0, 0, 0],
192
+ emissive: [0, 0, 0, 0],
193
+ occupied: false
194
+ });
195
+ const ensurePlane = (planes, planeIndex, surfaceCoord, width, height) => {
196
+ let plane = planes.get(planeIndex);
197
+ if (!plane) {
198
+ const cells = Array.from({ length: height }, () => Array.from({ length: width }, () => createEmptyCell()));
199
+ plane = { surfaceCoord, cells };
200
+ planes.set(planeIndex, plane);
201
+ }
202
+ return plane;
203
+ };
204
+ const halfSize = [primitiveSize[0] / 2, primitiveSize[1] / 2, primitiveSize[2] / 2];
205
+ FACE_ORDER.forEach((face) => {
206
+ const config = FACE_CONFIGS[face];
207
+ const width = dims[config.uAxis];
208
+ const height = dims[config.vAxis];
209
+ const planes = /* @__PURE__ */ new Map();
210
+ for (let x = 0; x < dims[0]; x += 1) {
211
+ for (let y = 0; y < dims[1]; y += 1) {
212
+ for (let z = 0; z < dims[2]; z += 1) {
213
+ const paletteIndex = getVoxelAt(primitive.voxels, dims, x, y, z);
214
+ if (paletteIndex === 0) {
215
+ continue;
216
+ }
217
+ const neighborCoord = [x, y, z];
218
+ neighborCoord[config.axis] += config.direction;
219
+ const neighbor = getVoxelAt(primitive.voxels, dims, neighborCoord[0], neighborCoord[1], neighborCoord[2]);
220
+ if (neighbor !== 0) {
221
+ continue;
222
+ }
223
+ const uCoord = [x, y, z][config.uAxis];
224
+ const vCoord = [x, y, z][config.vAxis];
225
+ const voxelAxis = [x, y, z][config.axis];
226
+ const surfaceCoord = config.direction > 0 ? voxelAxis + 1 : voxelAxis;
227
+ const plane = ensurePlane(planes, surfaceCoord, surfaceCoord, width, height);
228
+ const cell = plane.cells[vCoord][uCoord];
229
+ const materialId = palette[paletteIndex - 1];
230
+ const material = materialId ? materialsById.get(materialId) : void 0;
231
+ const baseColor = material?.baseColor ?? defaultColor;
232
+ const opacity = material?.opacity !== void 0 ? clamp(material.opacity, 0, 1) : 1;
233
+ const alpha = Math.round(opacity * 255);
234
+ cell.color = [baseColor[0], baseColor[1], baseColor[2], alpha];
235
+ cell.occupied = alpha > 0;
236
+ if (material?.emissiveColor) {
237
+ cell.emissive = [material.emissiveColor[0], material.emissiveColor[1], material.emissiveColor[2], 255];
238
+ } else {
239
+ cell.emissive = [0, 0, 0, 0];
240
+ }
179
241
  }
180
- return plane;
181
- };
182
- const halfSize = [primitiveSize[0] / 2, primitiveSize[1] / 2, primitiveSize[2] / 2];
183
- FACE_ORDER.forEach(face => {
184
- const config = FACE_CONFIGS[face];
185
- const width = dims[config.uAxis];
186
- const height = dims[config.vAxis];
187
- const planes = new Map();
188
- for (let x = 0; x < dims[0]; x += 1) {
189
- for (let y = 0; y < dims[1]; y += 1) {
190
- for (let z = 0; z < dims[2]; z += 1) {
191
- const paletteIndex = getVoxelAt(primitive.voxels, dims, x, y, z);
192
- if (paletteIndex === 0) {
193
- continue;
194
- }
195
- const neighborCoord = [x, y, z];
196
- neighborCoord[config.axis] += config.direction;
197
- const neighbor = getVoxelAt(primitive.voxels, dims, neighborCoord[0], neighborCoord[1], neighborCoord[2]);
198
- if (neighbor !== 0) {
199
- continue;
200
- }
201
- const uCoord = [x, y, z][config.uAxis];
202
- const vCoord = [x, y, z][config.vAxis];
203
- const voxelAxis = [x, y, z][config.axis];
204
- const surfaceCoord = config.direction > 0 ? voxelAxis + 1 : voxelAxis;
205
- const plane = ensurePlane(planes, surfaceCoord, surfaceCoord, width, height);
206
- const cell = plane.cells[vCoord][uCoord];
207
- const materialId = palette[paletteIndex - 1];
208
- const material = materialId ? materialsById.get(materialId) : undefined;
209
- const baseColor = material?.baseColor ?? defaultColor;
210
- const opacity = material?.opacity !== undefined ? clamp(material.opacity, 0, 1) : 1;
211
- const alpha = Math.round(opacity * 255);
212
- cell.color = [baseColor[0], baseColor[1], baseColor[2], alpha];
213
- cell.occupied = alpha > 0;
214
- if (material?.emissiveColor) {
215
- cell.emissive = [material.emissiveColor[0], material.emissiveColor[1], material.emissiveColor[2], 255];
216
- }
217
- else {
218
- cell.emissive = [0, 0, 0, 0];
219
- }
220
- }
242
+ }
243
+ }
244
+ const cellSizeU = voxelSize[config.uAxis];
245
+ const cellSizeV = voxelSize[config.vAxis];
246
+ planes.forEach((plane) => {
247
+ const visited = Array.from({ length: height }, () => new Array(width).fill(false));
248
+ for (let v = 0; v < height; v += 1) {
249
+ for (let u = 0; u < width; u += 1) {
250
+ if (visited[v][u])
251
+ continue;
252
+ const cell = plane.cells[v][u];
253
+ if (!cell.occupied) {
254
+ visited[v][u] = true;
255
+ continue;
256
+ }
257
+ let patchWidth = 1;
258
+ while (u + patchWidth < width) {
259
+ const nextCell = plane.cells[v][u + patchWidth];
260
+ if (!nextCell.occupied || visited[v][u + patchWidth])
261
+ break;
262
+ patchWidth += 1;
263
+ }
264
+ let patchHeight = 1;
265
+ outer: while (v + patchHeight < height) {
266
+ for (let offset = 0; offset < patchWidth; offset += 1) {
267
+ const nextCell = plane.cells[v + patchHeight][u + offset];
268
+ if (!nextCell.occupied || visited[v + patchHeight][u + offset]) {
269
+ break outer;
270
+ }
221
271
  }
222
- }
223
- const cellSizeU = voxelSize[config.uAxis];
224
- const cellSizeV = voxelSize[config.vAxis];
225
- planes.forEach(plane => {
226
- const visited = Array.from({ length: height }, () => new Array(width).fill(false));
227
- for (let v = 0; v < height; v += 1) {
228
- for (let u = 0; u < width; u += 1) {
229
- if (visited[v][u])
230
- continue;
231
- const cell = plane.cells[v][u];
232
- if (!cell.occupied) {
233
- visited[v][u] = true;
234
- continue;
235
- }
236
- let patchWidth = 1;
237
- while (u + patchWidth < width) {
238
- const nextCell = plane.cells[v][u + patchWidth];
239
- if (!nextCell.occupied || visited[v][u + patchWidth])
240
- break;
241
- patchWidth += 1;
242
- }
243
- let patchHeight = 1;
244
- outer: while (v + patchHeight < height) {
245
- for (let offset = 0; offset < patchWidth; offset += 1) {
246
- const nextCell = plane.cells[v + patchHeight][u + offset];
247
- if (!nextCell.occupied || visited[v + patchHeight][u + offset]) {
248
- break outer;
249
- }
250
- }
251
- patchHeight += 1;
252
- }
253
- for (let dv = 0; dv < patchHeight; dv += 1) {
254
- for (let du = 0; du < patchWidth; du += 1) {
255
- visited[v + dv][u + du] = true;
256
- }
257
- }
258
- const textureWidth = patchWidth;
259
- const textureHeight = patchHeight;
260
- const colorBuffer = new Uint8Array(textureWidth * textureHeight * 4);
261
- const emissiveBuffer = new Uint8Array(textureWidth * textureHeight * 4);
262
- let patchHasEmissive = false;
263
- let patchHasTransparency = false;
264
- for (let pv = 0; pv < patchHeight; pv += 1) {
265
- for (let pu = 0; pu < patchWidth; pu += 1) {
266
- const sourceCell = plane.cells[v + pv][u + pu];
267
- const targetY = textureHeight - 1 - pv;
268
- const targetIndex = (targetY * textureWidth + pu) * 4;
269
- colorBuffer[targetIndex] = sourceCell.color[0];
270
- colorBuffer[targetIndex + 1] = sourceCell.color[1];
271
- colorBuffer[targetIndex + 2] = sourceCell.color[2];
272
- colorBuffer[targetIndex + 3] = sourceCell.color[3];
273
- if (sourceCell.color[3] < 255) {
274
- patchHasTransparency = true;
275
- }
276
- emissiveBuffer[targetIndex] = sourceCell.emissive[0];
277
- emissiveBuffer[targetIndex + 1] = sourceCell.emissive[1];
278
- emissiveBuffer[targetIndex + 2] = sourceCell.emissive[2];
279
- emissiveBuffer[targetIndex + 3] = sourceCell.emissive[3];
280
- if (sourceCell.emissive[3] > 0) {
281
- patchHasEmissive = true;
282
- }
283
- }
284
- }
285
- const geometry = buildPatchGeometry({
286
- face,
287
- config,
288
- primitiveSize,
289
- voxelSize,
290
- halfSize,
291
- uStart: u,
292
- vStart: v,
293
- patchWidth,
294
- patchHeight,
295
- surfaceCoord: plane.surfaceCoord,
296
- });
297
- patches.push({
298
- face,
299
- width: patchWidth * cellSizeU,
300
- height: patchHeight * cellSizeV,
301
- textureWidth,
302
- textureHeight,
303
- color: colorBuffer,
304
- emissive: patchHasEmissive ? emissiveBuffer : undefined,
305
- hasEmissive: patchHasEmissive,
306
- hasTransparency: patchHasTransparency,
307
- geometry,
308
- });
309
- }
272
+ patchHeight += 1;
273
+ }
274
+ for (let dv = 0; dv < patchHeight; dv += 1) {
275
+ for (let du = 0; du < patchWidth; du += 1) {
276
+ visited[v + dv][u + du] = true;
310
277
  }
311
- });
278
+ }
279
+ const textureWidth = patchWidth;
280
+ const textureHeight = patchHeight;
281
+ const colorBuffer = new Uint8Array(textureWidth * textureHeight * 4);
282
+ const emissiveBuffer = new Uint8Array(textureWidth * textureHeight * 4);
283
+ let patchHasEmissive = false;
284
+ let patchHasTransparency = false;
285
+ for (let pv = 0; pv < patchHeight; pv += 1) {
286
+ for (let pu = 0; pu < patchWidth; pu += 1) {
287
+ const sourceCell = plane.cells[v + pv][u + pu];
288
+ const targetY = textureHeight - 1 - pv;
289
+ const targetIndex = (targetY * textureWidth + pu) * 4;
290
+ colorBuffer[targetIndex] = sourceCell.color[0];
291
+ colorBuffer[targetIndex + 1] = sourceCell.color[1];
292
+ colorBuffer[targetIndex + 2] = sourceCell.color[2];
293
+ colorBuffer[targetIndex + 3] = sourceCell.color[3];
294
+ if (sourceCell.color[3] < 255) {
295
+ patchHasTransparency = true;
296
+ }
297
+ emissiveBuffer[targetIndex] = sourceCell.emissive[0];
298
+ emissiveBuffer[targetIndex + 1] = sourceCell.emissive[1];
299
+ emissiveBuffer[targetIndex + 2] = sourceCell.emissive[2];
300
+ emissiveBuffer[targetIndex + 3] = sourceCell.emissive[3];
301
+ if (sourceCell.emissive[3] > 0) {
302
+ patchHasEmissive = true;
303
+ }
304
+ }
305
+ }
306
+ const geometry = buildPatchGeometry({
307
+ face,
308
+ config,
309
+ primitiveSize,
310
+ voxelSize,
311
+ halfSize,
312
+ uStart: u,
313
+ vStart: v,
314
+ patchWidth,
315
+ patchHeight,
316
+ surfaceCoord: plane.surfaceCoord
317
+ });
318
+ patches.push({
319
+ face,
320
+ width: patchWidth * cellSizeU,
321
+ height: patchHeight * cellSizeV,
322
+ textureWidth,
323
+ textureHeight,
324
+ color: colorBuffer,
325
+ emissive: patchHasEmissive ? emissiveBuffer : void 0,
326
+ hasEmissive: patchHasEmissive,
327
+ hasTransparency: patchHasTransparency,
328
+ geometry
329
+ });
330
+ }
331
+ }
312
332
  });
313
- return patches;
333
+ });
334
+ return patches;
314
335
  }
315
336
  function buildPatchGeometry(options) {
316
- const { face, config, primitiveSize, voxelSize, halfSize, uStart, vStart, patchWidth, patchHeight, surfaceCoord } = options;
317
- const positions = new Float32Array(12);
318
- const normals = new Float32Array(12);
319
- const uvs = new Float32Array(8);
320
- const indices = new Uint16Array([0, 1, 2, 0, 2, 3]);
321
- const cellSizeAxis = voxelSize[config.axis];
322
- const axisCoord = -halfSize[config.axis] + surfaceCoord * cellSizeAxis;
323
- const cellSizeU = voxelSize[config.uAxis];
324
- const cellSizeV = voxelSize[config.vAxis];
325
- const uMin = -halfSize[config.uAxis] + uStart * cellSizeU;
326
- const uMax = uMin + patchWidth * cellSizeU;
327
- const vMin = -halfSize[config.vAxis] + vStart * cellSizeV;
328
- const vMax = vMin + patchHeight * cellSizeV;
329
- const pick = (sign, minValue, maxValue) => (sign < 0 ? minValue : maxValue);
330
- const vertexOrder = (() => {
331
- switch (face) {
332
- case 'east':
333
- return [
334
- [-1, -1],
335
- [-1, 1],
336
- [1, 1],
337
- [1, -1],
338
- ];
339
- case 'west':
340
- return [
341
- [1, -1],
342
- [1, 1],
343
- [-1, 1],
344
- [-1, -1],
345
- ];
346
- case 'top':
347
- return [
348
- [-1, -1],
349
- [-1, 1],
350
- [1, 1],
351
- [1, -1],
352
- ];
353
- case 'bottom':
354
- return [
355
- [-1, -1],
356
- [1, -1],
357
- [1, 1],
358
- [-1, 1],
359
- ];
360
- case 'north':
361
- return [
362
- [-1, -1],
363
- [1, -1],
364
- [1, 1],
365
- [-1, 1],
366
- ];
367
- case 'south':
368
- default:
369
- return [
370
- [1, -1],
371
- [-1, -1],
372
- [-1, 1],
373
- [1, 1],
374
- ];
375
- }
376
- })();
377
- const uvOrder = (() => {
378
- switch (face) {
379
- case 'east':
380
- return [
381
- [0, 1],
382
- [0, 0],
383
- [1, 0],
384
- [1, 1],
385
- ];
386
- case 'west':
387
- return [
388
- [1, 1],
389
- [1, 0],
390
- [0, 0],
391
- [0, 1],
392
- ];
393
- case 'top':
394
- return [
395
- [0, 1],
396
- [0, 0],
397
- [1, 0],
398
- [1, 1],
399
- ];
400
- case 'bottom':
401
- return [
402
- [0, 0],
403
- [1, 0],
404
- [1, 1],
405
- [0, 1],
406
- ];
407
- case 'north':
408
- return [
409
- [0, 1],
410
- [1, 1],
411
- [1, 0],
412
- [0, 0],
413
- ];
414
- case 'south':
415
- default:
416
- return [
417
- [1, 1],
418
- [0, 1],
419
- [0, 0],
420
- [1, 0],
421
- ];
422
- }
423
- })();
424
- for (let i = 0; i < vertexOrder.length; i += 1) {
425
- const [uSign, vSign] = vertexOrder[i];
426
- const pos = [0, 0, 0];
427
- pos[config.axis] = axisCoord;
428
- pos[config.uAxis] = pick(uSign, uMin, uMax);
429
- pos[config.vAxis] = pick(vSign, vMin, vMax);
430
- positions[i * 3] = pos[0];
431
- positions[i * 3 + 1] = pos[1];
432
- positions[i * 3 + 2] = pos[2];
433
- const normal = [0, 0, 0];
434
- normal[config.axis] = config.direction;
435
- normals[i * 3] = normal[0];
436
- normals[i * 3 + 1] = normal[1];
437
- normals[i * 3 + 2] = normal[2];
438
- uvs[i * 2] = uvOrder[i][0];
439
- uvs[i * 2 + 1] = uvOrder[i][1];
337
+ const { face, config, primitiveSize, voxelSize, halfSize, uStart, vStart, patchWidth, patchHeight, surfaceCoord } = options;
338
+ const positions = new Float32Array(12);
339
+ const normals = new Float32Array(12);
340
+ const uvs = new Float32Array(8);
341
+ const indices = new Uint16Array([0, 1, 2, 0, 2, 3]);
342
+ const cellSizeAxis = voxelSize[config.axis];
343
+ const axisCoord = -halfSize[config.axis] + surfaceCoord * cellSizeAxis;
344
+ const cellSizeU = voxelSize[config.uAxis];
345
+ const cellSizeV = voxelSize[config.vAxis];
346
+ const uMin = -halfSize[config.uAxis] + uStart * cellSizeU;
347
+ const uMax = uMin + patchWidth * cellSizeU;
348
+ const vMin = -halfSize[config.vAxis] + vStart * cellSizeV;
349
+ const vMax = vMin + patchHeight * cellSizeV;
350
+ const pick = (sign, minValue, maxValue) => sign < 0 ? minValue : maxValue;
351
+ const vertexOrder = (() => {
352
+ switch (face) {
353
+ case "east":
354
+ return [
355
+ [-1, -1],
356
+ [-1, 1],
357
+ [1, 1],
358
+ [1, -1]
359
+ ];
360
+ case "west":
361
+ return [
362
+ [1, -1],
363
+ [1, 1],
364
+ [-1, 1],
365
+ [-1, -1]
366
+ ];
367
+ case "top":
368
+ return [
369
+ [-1, -1],
370
+ [-1, 1],
371
+ [1, 1],
372
+ [1, -1]
373
+ ];
374
+ case "bottom":
375
+ return [
376
+ [-1, -1],
377
+ [1, -1],
378
+ [1, 1],
379
+ [-1, 1]
380
+ ];
381
+ case "north":
382
+ return [
383
+ [-1, -1],
384
+ [1, -1],
385
+ [1, 1],
386
+ [-1, 1]
387
+ ];
388
+ case "south":
389
+ default:
390
+ return [
391
+ [1, -1],
392
+ [-1, -1],
393
+ [-1, 1],
394
+ [1, 1]
395
+ ];
396
+ }
397
+ })();
398
+ const uvOrder = (() => {
399
+ switch (face) {
400
+ case "east":
401
+ return [
402
+ [0, 1],
403
+ [0, 0],
404
+ [1, 0],
405
+ [1, 1]
406
+ ];
407
+ case "west":
408
+ return [
409
+ [1, 1],
410
+ [1, 0],
411
+ [0, 0],
412
+ [0, 1]
413
+ ];
414
+ case "top":
415
+ return [
416
+ [0, 1],
417
+ [0, 0],
418
+ [1, 0],
419
+ [1, 1]
420
+ ];
421
+ case "bottom":
422
+ return [
423
+ [0, 0],
424
+ [1, 0],
425
+ [1, 1],
426
+ [0, 1]
427
+ ];
428
+ case "north":
429
+ return [
430
+ [0, 1],
431
+ [1, 1],
432
+ [1, 0],
433
+ [0, 0]
434
+ ];
435
+ case "south":
436
+ default:
437
+ return [
438
+ [1, 1],
439
+ [0, 1],
440
+ [0, 0],
441
+ [1, 0]
442
+ ];
440
443
  }
441
- return { positions, normals, uvs, indices };
444
+ })();
445
+ for (let i = 0; i < vertexOrder.length; i += 1) {
446
+ const [uSign, vSign] = vertexOrder[i];
447
+ const pos = [0, 0, 0];
448
+ pos[config.axis] = axisCoord;
449
+ pos[config.uAxis] = pick(uSign, uMin, uMax);
450
+ pos[config.vAxis] = pick(vSign, vMin, vMax);
451
+ positions[i * 3] = pos[0];
452
+ positions[i * 3 + 1] = pos[1];
453
+ positions[i * 3 + 2] = pos[2];
454
+ const normal = [0, 0, 0];
455
+ normal[config.axis] = config.direction;
456
+ normals[i * 3] = normal[0];
457
+ normals[i * 3 + 1] = normal[1];
458
+ normals[i * 3 + 2] = normal[2];
459
+ uvs[i * 2] = uvOrder[i][0];
460
+ uvs[i * 2 + 1] = uvOrder[i][1];
461
+ }
462
+ return { positions, normals, uvs, indices };
442
463
  }
464
+ // Annotate the CommonJS export names for ESM import in node:
465
+ 0 && (module.exports = {
466
+ FACE_ORDER,
467
+ generateVoxelFaceSurfaces
468
+ });