@playdrop/playdrop-cli 0.7.15 → 0.7.17

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 (70) 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/types/dist/api.js +289 -203
  53. package/node_modules/@playdrop/types/dist/app-capability-filters.js +112 -62
  54. package/node_modules/@playdrop/types/dist/app.js +91 -45
  55. package/node_modules/@playdrop/types/dist/asset-pack.js +37 -5
  56. package/node_modules/@playdrop/types/dist/asset-spec.js +170 -90
  57. package/node_modules/@playdrop/types/dist/asset.js +186 -108
  58. package/node_modules/@playdrop/types/dist/content-license.js +49 -15
  59. package/node_modules/@playdrop/types/dist/creator-public-image.js +60 -32
  60. package/node_modules/@playdrop/types/dist/ecs.js +102 -82
  61. package/node_modules/@playdrop/types/dist/engine-builtins.js +603 -573
  62. package/node_modules/@playdrop/types/dist/entity.js +63 -53
  63. package/node_modules/@playdrop/types/dist/graph.js +116 -80
  64. package/node_modules/@playdrop/types/dist/index.js +47 -20
  65. package/node_modules/@playdrop/types/dist/owned-assets.js +55 -33
  66. package/node_modules/@playdrop/types/dist/player-meta.js +151 -100
  67. package/node_modules/@playdrop/types/dist/realtime.js +27 -7
  68. package/node_modules/@playdrop/types/dist/version.js +182 -124
  69. package/node_modules/@playdrop/types/package.json +1 -1
  70. package/package.json +1 -1
@@ -1,107 +1,133 @@
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 texture_atlas_exports = {};
19
+ __export(texture_atlas_exports, {
20
+ buildEmissiveAtlas: () => buildEmissiveAtlas,
21
+ buildTextureAtlas: () => buildTextureAtlas
22
+ });
23
+ module.exports = __toCommonJS(texture_atlas_exports);
1
24
  const toPowerOfTwo = (value) => {
2
- return 2 ** Math.ceil(Math.log2(Math.max(1, value)));
25
+ return 2 ** Math.ceil(Math.log2(Math.max(1, value)));
3
26
  };
4
- export function buildTextureAtlas(THREE, textures) {
5
- const uniqueTextures = Array.from(new Set(textures));
6
- if (uniqueTextures.length === 0) {
7
- return null;
27
+ function buildTextureAtlas(THREE, textures) {
28
+ const uniqueTextures = Array.from(new Set(textures));
29
+ if (uniqueTextures.length === 0) {
30
+ return null;
31
+ }
32
+ const maxWidth = uniqueTextures.reduce((acc, tex) => Math.max(acc, tex.image?.width ?? 0), 0);
33
+ const totalHeight = uniqueTextures.reduce((acc, tex) => acc + (tex.image?.height ?? 0), 0);
34
+ if (maxWidth === 0 || totalHeight === 0) {
35
+ return null;
36
+ }
37
+ const atlasWidth = toPowerOfTwo(maxWidth);
38
+ const atlasHeight = toPowerOfTwo(totalHeight);
39
+ const atlasData = new Uint8Array(atlasWidth * atlasHeight * 4);
40
+ const transforms = /* @__PURE__ */ new Map();
41
+ let offsetY = 0;
42
+ uniqueTextures.forEach((texture) => {
43
+ const image = texture.image;
44
+ if (!image) {
45
+ return;
8
46
  }
9
- const maxWidth = uniqueTextures.reduce((acc, tex) => Math.max(acc, tex.image?.width ?? 0), 0);
10
- const totalHeight = uniqueTextures.reduce((acc, tex) => acc + (tex.image?.height ?? 0), 0);
11
- if (maxWidth === 0 || totalHeight === 0) {
12
- return null;
47
+ const width = image.width;
48
+ const height = image.height;
49
+ const data = image.data;
50
+ const startY = offsetY;
51
+ for (let row = 0; row < height; row += 1) {
52
+ const srcStart = row * width * 4;
53
+ const dstStart = (startY + row) * atlasWidth * 4;
54
+ atlasData.set(data.subarray(srcStart, srcStart + width * 4), dstStart);
13
55
  }
14
- const atlasWidth = toPowerOfTwo(maxWidth);
15
- const atlasHeight = toPowerOfTwo(totalHeight);
16
- const atlasData = new Uint8Array(atlasWidth * atlasHeight * 4);
17
- const transforms = new Map();
18
- let offsetY = 0;
19
- uniqueTextures.forEach(texture => {
20
- const image = texture.image;
21
- if (!image) {
22
- return;
23
- }
24
- const width = image.width;
25
- const height = image.height;
26
- const data = image.data;
27
- const startY = offsetY;
28
- for (let row = 0; row < height; row += 1) {
29
- const srcStart = row * width * 4;
30
- const dstStart = ((startY + row) * atlasWidth) * 4;
31
- atlasData.set(data.subarray(srcStart, srcStart + width * 4), dstStart);
32
- }
33
- transforms.set(texture, {
34
- offset: [0, startY / atlasHeight],
35
- scale: [width / atlasWidth, height / atlasHeight],
36
- });
37
- offsetY += height;
56
+ transforms.set(texture, {
57
+ offset: [0, startY / atlasHeight],
58
+ scale: [width / atlasWidth, height / atlasHeight]
38
59
  });
39
- const template = uniqueTextures[0];
40
- const templateTexture = template;
41
- const atlasTexture = new THREE.DataTexture(atlasData, atlasWidth, atlasHeight);
42
- atlasTexture.needsUpdate = true;
43
- atlasTexture.magFilter = templateTexture.magFilter;
44
- atlasTexture.minFilter = templateTexture.minFilter;
45
- atlasTexture.wrapS = templateTexture.wrapS;
46
- atlasTexture.wrapT = templateTexture.wrapT;
47
- atlasTexture.flipY = false;
48
- if ('colorSpace' in atlasTexture && 'colorSpace' in templateTexture) {
49
- atlasTexture.colorSpace = templateTexture.colorSpace;
50
- }
51
- else if ('encoding' in atlasTexture && 'encoding' in templateTexture) {
52
- atlasTexture.encoding = templateTexture.encoding;
53
- }
54
- return {
55
- texture: atlasTexture,
56
- transforms,
57
- width: atlasWidth,
58
- height: atlasHeight,
59
- };
60
+ offsetY += height;
61
+ });
62
+ const template = uniqueTextures[0];
63
+ const templateTexture = template;
64
+ const atlasTexture = new THREE.DataTexture(atlasData, atlasWidth, atlasHeight);
65
+ atlasTexture.needsUpdate = true;
66
+ atlasTexture.magFilter = templateTexture.magFilter;
67
+ atlasTexture.minFilter = templateTexture.minFilter;
68
+ atlasTexture.wrapS = templateTexture.wrapS;
69
+ atlasTexture.wrapT = templateTexture.wrapT;
70
+ atlasTexture.flipY = false;
71
+ if ("colorSpace" in atlasTexture && "colorSpace" in templateTexture) {
72
+ atlasTexture.colorSpace = templateTexture.colorSpace;
73
+ } else if ("encoding" in atlasTexture && "encoding" in templateTexture) {
74
+ atlasTexture.encoding = templateTexture.encoding;
75
+ }
76
+ return {
77
+ texture: atlasTexture,
78
+ transforms,
79
+ width: atlasWidth,
80
+ height: atlasHeight
81
+ };
60
82
  }
61
- export function buildEmissiveAtlas(THREE, width, height, transforms, pairs) {
62
- if (pairs.size === 0) {
63
- return null;
64
- }
65
- const atlasData = new Uint8Array(width * height * 4);
66
- let template = null;
67
- pairs.forEach((emissive, reference) => {
68
- const transform = transforms.get(reference);
69
- if (!transform) {
70
- return;
71
- }
72
- const image = emissive.image;
73
- const refImage = reference.image;
74
- if (!image || !refImage) {
75
- return;
76
- }
77
- const texWidth = refImage.width;
78
- const texHeight = refImage.height;
79
- const data = image.data;
80
- const offsetX = Math.round(transform.offset[0] * width);
81
- const offsetY = Math.round(transform.offset[1] * height);
82
- for (let row = 0; row < texHeight; row += 1) {
83
- const srcStart = row * texWidth * 4;
84
- const dstStart = ((offsetY + row) * width + offsetX) * 4;
85
- atlasData.set(data.subarray(srcStart, srcStart + texWidth * 4), dstStart);
86
- }
87
- template = emissive;
88
- });
89
- if (!template) {
90
- return null;
83
+ function buildEmissiveAtlas(THREE, width, height, transforms, pairs) {
84
+ if (pairs.size === 0) {
85
+ return null;
86
+ }
87
+ const atlasData = new Uint8Array(width * height * 4);
88
+ let template = null;
89
+ pairs.forEach((emissive, reference) => {
90
+ const transform = transforms.get(reference);
91
+ if (!transform) {
92
+ return;
91
93
  }
92
- const templateTexture = template;
93
- const atlasTexture = new THREE.DataTexture(atlasData, width, height);
94
- atlasTexture.needsUpdate = true;
95
- atlasTexture.magFilter = templateTexture.magFilter;
96
- atlasTexture.minFilter = templateTexture.minFilter;
97
- atlasTexture.wrapS = templateTexture.wrapS;
98
- atlasTexture.wrapT = templateTexture.wrapT;
99
- atlasTexture.flipY = false;
100
- if ('colorSpace' in atlasTexture && 'colorSpace' in templateTexture) {
101
- atlasTexture.colorSpace = templateTexture.colorSpace;
94
+ const image = emissive.image;
95
+ const refImage = reference.image;
96
+ if (!image || !refImage) {
97
+ return;
102
98
  }
103
- else if ('encoding' in atlasTexture && 'encoding' in templateTexture) {
104
- atlasTexture.encoding = templateTexture.encoding;
99
+ const texWidth = refImage.width;
100
+ const texHeight = refImage.height;
101
+ const data = image.data;
102
+ const offsetX = Math.round(transform.offset[0] * width);
103
+ const offsetY = Math.round(transform.offset[1] * height);
104
+ for (let row = 0; row < texHeight; row += 1) {
105
+ const srcStart = row * texWidth * 4;
106
+ const dstStart = ((offsetY + row) * width + offsetX) * 4;
107
+ atlasData.set(data.subarray(srcStart, srcStart + texWidth * 4), dstStart);
105
108
  }
106
- return atlasTexture;
109
+ template = emissive;
110
+ });
111
+ if (!template) {
112
+ return null;
113
+ }
114
+ const templateTexture = template;
115
+ const atlasTexture = new THREE.DataTexture(atlasData, width, height);
116
+ atlasTexture.needsUpdate = true;
117
+ atlasTexture.magFilter = templateTexture.magFilter;
118
+ atlasTexture.minFilter = templateTexture.minFilter;
119
+ atlasTexture.wrapS = templateTexture.wrapS;
120
+ atlasTexture.wrapT = templateTexture.wrapT;
121
+ atlasTexture.flipY = false;
122
+ if ("colorSpace" in atlasTexture && "colorSpace" in templateTexture) {
123
+ atlasTexture.colorSpace = templateTexture.colorSpace;
124
+ } else if ("encoding" in atlasTexture && "encoding" in templateTexture) {
125
+ atlasTexture.encoding = templateTexture.encoding;
126
+ }
127
+ return atlasTexture;
107
128
  }
129
+ // Annotate the CommonJS export names for ESM import in node:
130
+ 0 && (module.exports = {
131
+ buildEmissiveAtlas,
132
+ buildTextureAtlas
133
+ });
@@ -1,191 +1,216 @@
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 textures_exports = {};
19
+ __export(textures_exports, {
20
+ buildTexturePixels: () => buildTexturePixels,
21
+ createPatternPlaceholderTexture: () => createPatternPlaceholderTexture,
22
+ createTextureMaterial: () => createTextureMaterial,
23
+ ensureTextureInstance: () => ensureTextureInstance,
24
+ toThreeColorRGB: () => toThreeColorRGB
25
+ });
26
+ module.exports = __toCommonJS(textures_exports);
1
27
  function toThreeColor(THREE, rgb) {
2
- const color = new THREE.Color(rgb[0] / 255, rgb[1] / 255, rgb[2] / 255);
3
- if (typeof color.convertSRGBToLinear === 'function') {
4
- color.convertSRGBToLinear();
5
- }
6
- else if (typeof color
7
- .convertGammaToLinear === 'function') {
8
- color.convertGammaToLinear(2.2);
9
- }
10
- return color;
28
+ const color = new THREE.Color(rgb[0] / 255, rgb[1] / 255, rgb[2] / 255);
29
+ if (typeof color.convertSRGBToLinear === "function") {
30
+ color.convertSRGBToLinear();
31
+ } else if (typeof color.convertGammaToLinear === "function") {
32
+ color.convertGammaToLinear(2.2);
33
+ }
34
+ return color;
11
35
  }
12
- export function buildTexturePixels(context, textureDef, pattern, materialsById) {
13
- const [width, height] = pattern.size;
14
- const colorBuffer = new Uint8Array(width * height * 4);
15
- const emissiveBuffer = new Uint8Array(width * height * 4);
16
- let hasEmissive = false;
17
- for (let y = 0; y < height; y += 1) {
18
- for (let x = 0; x < width; x += 1) {
19
- const sourceIndex = y * width + x;
20
- const paletteIndex = pattern.data[sourceIndex];
21
- const materialId = textureDef.materials[paletteIndex];
22
- const material = materialId ? materialsById.get(materialId) : undefined;
23
- const color = material?.baseColor ?? [59, 130, 246];
24
- const opacityValue = material?.opacity !== undefined ? Number(material.opacity) : 1;
25
- const clampedOpacity = Number.isFinite(opacityValue)
26
- ? Math.max(0, Math.min(1, opacityValue))
27
- : 1;
28
- const targetY = height - 1 - y;
29
- const targetIndex = (targetY * width + x) * 4;
30
- colorBuffer[targetIndex] = color[0];
31
- colorBuffer[targetIndex + 1] = color[1];
32
- colorBuffer[targetIndex + 2] = color[2];
33
- colorBuffer[targetIndex + 3] = Math.round(clampedOpacity * 255);
34
- const emissive = material?.emissiveColor ?? null;
35
- if (emissive) {
36
- emissiveBuffer[targetIndex] = emissive[0];
37
- emissiveBuffer[targetIndex + 1] = emissive[1];
38
- emissiveBuffer[targetIndex + 2] = emissive[2];
39
- emissiveBuffer[targetIndex + 3] = 255;
40
- if (!hasEmissive) {
41
- hasEmissive = emissive.some(component => component !== 0);
42
- }
43
- }
44
- else {
45
- emissiveBuffer[targetIndex] = 0;
46
- emissiveBuffer[targetIndex + 1] = 0;
47
- emissiveBuffer[targetIndex + 2] = 0;
48
- emissiveBuffer[targetIndex + 3] = 0;
49
- }
36
+ function buildTexturePixels(context, textureDef, pattern, materialsById) {
37
+ const [width, height] = pattern.size;
38
+ const colorBuffer = new Uint8Array(width * height * 4);
39
+ const emissiveBuffer = new Uint8Array(width * height * 4);
40
+ let hasEmissive = false;
41
+ for (let y = 0; y < height; y += 1) {
42
+ for (let x = 0; x < width; x += 1) {
43
+ const sourceIndex = y * width + x;
44
+ const paletteIndex = pattern.data[sourceIndex];
45
+ const materialId = textureDef.materials[paletteIndex];
46
+ const material = materialId ? materialsById.get(materialId) : void 0;
47
+ const color = material?.baseColor ?? [59, 130, 246];
48
+ const opacityValue = material?.opacity !== void 0 ? Number(material.opacity) : 1;
49
+ const clampedOpacity = Number.isFinite(opacityValue) ? Math.max(0, Math.min(1, opacityValue)) : 1;
50
+ const targetY = height - 1 - y;
51
+ const targetIndex = (targetY * width + x) * 4;
52
+ colorBuffer[targetIndex] = color[0];
53
+ colorBuffer[targetIndex + 1] = color[1];
54
+ colorBuffer[targetIndex + 2] = color[2];
55
+ colorBuffer[targetIndex + 3] = Math.round(clampedOpacity * 255);
56
+ const emissive = material?.emissiveColor ?? null;
57
+ if (emissive) {
58
+ emissiveBuffer[targetIndex] = emissive[0];
59
+ emissiveBuffer[targetIndex + 1] = emissive[1];
60
+ emissiveBuffer[targetIndex + 2] = emissive[2];
61
+ emissiveBuffer[targetIndex + 3] = 255;
62
+ if (!hasEmissive) {
63
+ hasEmissive = emissive.some((component) => component !== 0);
50
64
  }
51
- }
52
- return {
53
- color: colorBuffer,
54
- emissive: hasEmissive ? emissiveBuffer : null,
55
- };
65
+ } else {
66
+ emissiveBuffer[targetIndex] = 0;
67
+ emissiveBuffer[targetIndex + 1] = 0;
68
+ emissiveBuffer[targetIndex + 2] = 0;
69
+ emissiveBuffer[targetIndex + 3] = 0;
70
+ }
71
+ }
72
+ }
73
+ return {
74
+ color: colorBuffer,
75
+ emissive: hasEmissive ? emissiveBuffer : null
76
+ };
56
77
  }
57
- export function ensureTextureInstance(context, textureDef) {
58
- const cached = context.textureCache.get(textureDef.id);
59
- if (cached) {
60
- return cached;
61
- }
62
- if (!context.entity) {
63
- return null;
64
- }
65
- const pattern = context.entity.patterns.find(entry => entry.id === textureDef.pattern);
66
- if (!pattern) {
67
- console.warn('[boxel-three] pattern not found for texture', textureDef.id);
68
- return null;
69
- }
70
- const { color, emissive } = buildTexturePixels(context, textureDef, pattern, context.materialsById);
71
- const colorTexture = new context.THREE.DataTexture(color, pattern.size[0], pattern.size[1]);
72
- colorTexture.needsUpdate = true;
73
- colorTexture.magFilter = context.THREE.NearestFilter;
74
- colorTexture.minFilter = context.THREE.NearestFilter;
75
- colorTexture.wrapS = context.THREE.ClampToEdgeWrapping;
76
- colorTexture.wrapT = context.THREE.ClampToEdgeWrapping;
77
- colorTexture.flipY = false;
78
- if ('colorSpace' in colorTexture) {
79
- colorTexture.colorSpace = context.THREE.SRGBColorSpace ?? colorTexture.colorSpace;
80
- }
81
- else if ('encoding' in colorTexture) {
82
- colorTexture.encoding = context.THREE.sRGBEncoding ?? colorTexture.encoding;
83
- }
84
- let emissiveTexture;
85
- if (emissive) {
86
- emissiveTexture = new context.THREE.DataTexture(emissive, pattern.size[0], pattern.size[1]);
87
- emissiveTexture.needsUpdate = true;
88
- emissiveTexture.magFilter = context.THREE.NearestFilter;
89
- emissiveTexture.minFilter = context.THREE.NearestFilter;
90
- emissiveTexture.wrapS = context.THREE.ClampToEdgeWrapping;
91
- emissiveTexture.wrapT = context.THREE.ClampToEdgeWrapping;
92
- emissiveTexture.flipY = false;
93
- if ('colorSpace' in emissiveTexture) {
94
- emissiveTexture.colorSpace = context.THREE.SRGBColorSpace ?? emissiveTexture.colorSpace;
95
- }
96
- else if ('encoding' in emissiveTexture) {
97
- emissiveTexture.encoding = context.THREE.sRGBEncoding ?? emissiveTexture.encoding;
98
- }
99
- }
100
- const bundle = {
101
- color: colorTexture,
102
- emissive: emissiveTexture,
103
- };
104
- context.textureCache.set(textureDef.id, bundle);
105
- return bundle;
78
+ function ensureTextureInstance(context, textureDef) {
79
+ const cached = context.textureCache.get(textureDef.id);
80
+ if (cached) {
81
+ return cached;
82
+ }
83
+ if (!context.entity) {
84
+ return null;
85
+ }
86
+ const pattern = context.entity.patterns.find((entry) => entry.id === textureDef.pattern);
87
+ if (!pattern) {
88
+ console.warn("[boxel-three] pattern not found for texture", textureDef.id);
89
+ return null;
90
+ }
91
+ const { color, emissive } = buildTexturePixels(context, textureDef, pattern, context.materialsById);
92
+ const colorTexture = new context.THREE.DataTexture(color, pattern.size[0], pattern.size[1]);
93
+ colorTexture.needsUpdate = true;
94
+ colorTexture.magFilter = context.THREE.NearestFilter;
95
+ colorTexture.minFilter = context.THREE.NearestFilter;
96
+ colorTexture.wrapS = context.THREE.ClampToEdgeWrapping;
97
+ colorTexture.wrapT = context.THREE.ClampToEdgeWrapping;
98
+ colorTexture.flipY = false;
99
+ if ("colorSpace" in colorTexture) {
100
+ colorTexture.colorSpace = context.THREE.SRGBColorSpace ?? colorTexture.colorSpace;
101
+ } else if ("encoding" in colorTexture) {
102
+ colorTexture.encoding = context.THREE.sRGBEncoding ?? colorTexture.encoding;
103
+ }
104
+ let emissiveTexture;
105
+ if (emissive) {
106
+ emissiveTexture = new context.THREE.DataTexture(emissive, pattern.size[0], pattern.size[1]);
107
+ emissiveTexture.needsUpdate = true;
108
+ emissiveTexture.magFilter = context.THREE.NearestFilter;
109
+ emissiveTexture.minFilter = context.THREE.NearestFilter;
110
+ emissiveTexture.wrapS = context.THREE.ClampToEdgeWrapping;
111
+ emissiveTexture.wrapT = context.THREE.ClampToEdgeWrapping;
112
+ emissiveTexture.flipY = false;
113
+ if ("colorSpace" in emissiveTexture) {
114
+ emissiveTexture.colorSpace = context.THREE.SRGBColorSpace ?? emissiveTexture.colorSpace;
115
+ } else if ("encoding" in emissiveTexture) {
116
+ emissiveTexture.encoding = context.THREE.sRGBEncoding ?? emissiveTexture.encoding;
117
+ }
118
+ }
119
+ const bundle = {
120
+ color: colorTexture,
121
+ emissive: emissiveTexture
122
+ };
123
+ context.textureCache.set(textureDef.id, bundle);
124
+ return bundle;
106
125
  }
107
- export function createPatternPlaceholderTexture(context, pattern) {
108
- const [width, height] = pattern.size;
109
- const buffer = new Uint8Array(width * height * 4);
110
- const maxValue = pattern.data.reduce((acc, value) => Math.max(acc, value), 0);
111
- const normalizer = maxValue > 0 ? maxValue : 1;
112
- for (let y = 0; y < height; y += 1) {
113
- for (let x = 0; x < width; x += 1) {
114
- const sourceIndex = y * width + x;
115
- const value = pattern.data[sourceIndex];
116
- const shade = Math.round((value / normalizer) * 255);
117
- const targetY = height - 1 - y;
118
- const targetIndex = (targetY * width + x) * 4;
119
- buffer[targetIndex] = shade;
120
- buffer[targetIndex + 1] = shade;
121
- buffer[targetIndex + 2] = shade;
122
- buffer[targetIndex + 3] = 255;
123
- }
124
- }
125
- const texture = new context.THREE.DataTexture(buffer, width, height);
126
- texture.needsUpdate = true;
127
- texture.magFilter = context.THREE.NearestFilter;
128
- texture.minFilter = context.THREE.NearestFilter;
129
- texture.wrapS = context.THREE.ClampToEdgeWrapping;
130
- texture.wrapT = context.THREE.ClampToEdgeWrapping;
131
- texture.flipY = false;
132
- if ('colorSpace' in texture) {
133
- texture.colorSpace = context.THREE.SRGBColorSpace ?? texture.colorSpace;
134
- }
135
- else if ('encoding' in texture) {
136
- texture.encoding = context.THREE.sRGBEncoding ?? texture.encoding;
137
- }
138
- return texture;
126
+ function createPatternPlaceholderTexture(context, pattern) {
127
+ const [width, height] = pattern.size;
128
+ const buffer = new Uint8Array(width * height * 4);
129
+ const maxValue = pattern.data.reduce((acc, value) => Math.max(acc, value), 0);
130
+ const normalizer = maxValue > 0 ? maxValue : 1;
131
+ for (let y = 0; y < height; y += 1) {
132
+ for (let x = 0; x < width; x += 1) {
133
+ const sourceIndex = y * width + x;
134
+ const value = pattern.data[sourceIndex];
135
+ const shade = Math.round(value / normalizer * 255);
136
+ const targetY = height - 1 - y;
137
+ const targetIndex = (targetY * width + x) * 4;
138
+ buffer[targetIndex] = shade;
139
+ buffer[targetIndex + 1] = shade;
140
+ buffer[targetIndex + 2] = shade;
141
+ buffer[targetIndex + 3] = 255;
142
+ }
143
+ }
144
+ const texture = new context.THREE.DataTexture(buffer, width, height);
145
+ texture.needsUpdate = true;
146
+ texture.magFilter = context.THREE.NearestFilter;
147
+ texture.minFilter = context.THREE.NearestFilter;
148
+ texture.wrapS = context.THREE.ClampToEdgeWrapping;
149
+ texture.wrapT = context.THREE.ClampToEdgeWrapping;
150
+ texture.flipY = false;
151
+ if ("colorSpace" in texture) {
152
+ texture.colorSpace = context.THREE.SRGBColorSpace ?? texture.colorSpace;
153
+ } else if ("encoding" in texture) {
154
+ texture.encoding = context.THREE.sRGBEncoding ?? texture.encoding;
155
+ }
156
+ return texture;
139
157
  }
140
- export function createTextureMaterial(context, textureId) {
141
- if (!textureId || !context.entity) {
142
- return new context.THREE.MeshStandardMaterial({
143
- color: 0x3b82f6,
144
- opacity: 0.45,
145
- transparent: true,
146
- metalness: 0,
147
- roughness: 1,
148
- });
149
- }
150
- const textureDef = context.entity.textures.find(entry => entry.id === textureId);
151
- if (!textureDef) {
152
- console.warn('[boxel-three] texture not found', textureId);
153
- return new context.THREE.MeshStandardMaterial({
154
- color: 0x3b82f6,
155
- opacity: 0.45,
156
- transparent: true,
157
- metalness: 0,
158
- roughness: 1,
159
- });
160
- }
161
- const bundle = ensureTextureInstance(context, textureDef);
162
- if (!bundle) {
163
- return new context.THREE.MeshStandardMaterial({
164
- color: 0x3b82f6,
165
- opacity: 0.45,
166
- transparent: true,
167
- metalness: 0,
168
- roughness: 1,
169
- });
170
- }
171
- const material = new context.THREE.MeshStandardMaterial({
172
- map: bundle.color,
173
- transparent: true,
174
- metalness: 0,
175
- roughness: 1,
158
+ function createTextureMaterial(context, textureId) {
159
+ if (!textureId || !context.entity) {
160
+ return new context.THREE.MeshStandardMaterial({
161
+ color: 3900150,
162
+ opacity: 0.45,
163
+ transparent: true,
164
+ metalness: 0,
165
+ roughness: 1
176
166
  });
177
- if (bundle.emissive) {
178
- material.emissiveMap = bundle.emissive;
179
- material.emissive = new context.THREE.Color(1, 1, 1);
180
- material.emissiveIntensity = 1;
181
- }
182
- else {
183
- material.emissive.setRGB(0, 0, 0);
184
- material.emissiveIntensity = 1;
185
- }
186
- material.needsUpdate = true;
187
- return material;
167
+ }
168
+ const textureDef = context.entity.textures.find((entry) => entry.id === textureId);
169
+ if (!textureDef) {
170
+ console.warn("[boxel-three] texture not found", textureId);
171
+ return new context.THREE.MeshStandardMaterial({
172
+ color: 3900150,
173
+ opacity: 0.45,
174
+ transparent: true,
175
+ metalness: 0,
176
+ roughness: 1
177
+ });
178
+ }
179
+ const bundle = ensureTextureInstance(context, textureDef);
180
+ if (!bundle) {
181
+ return new context.THREE.MeshStandardMaterial({
182
+ color: 3900150,
183
+ opacity: 0.45,
184
+ transparent: true,
185
+ metalness: 0,
186
+ roughness: 1
187
+ });
188
+ }
189
+ const material = new context.THREE.MeshStandardMaterial({
190
+ map: bundle.color,
191
+ transparent: true,
192
+ metalness: 0,
193
+ roughness: 1
194
+ });
195
+ if (bundle.emissive) {
196
+ material.emissiveMap = bundle.emissive;
197
+ material.emissive = new context.THREE.Color(1, 1, 1);
198
+ material.emissiveIntensity = 1;
199
+ } else {
200
+ material.emissive.setRGB(0, 0, 0);
201
+ material.emissiveIntensity = 1;
202
+ }
203
+ material.needsUpdate = true;
204
+ return material;
188
205
  }
189
- export function toThreeColorRGB(context, rgb) {
190
- return toThreeColor(context.THREE, rgb);
206
+ function toThreeColorRGB(context, rgb) {
207
+ return toThreeColor(context.THREE, rgb);
191
208
  }
209
+ // Annotate the CommonJS export names for ESM import in node:
210
+ 0 && (module.exports = {
211
+ buildTexturePixels,
212
+ createPatternPlaceholderTexture,
213
+ createTextureMaterial,
214
+ ensureTextureInstance,
215
+ toThreeColorRGB
216
+ });
@@ -1 +1,15 @@
1
- export {};
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __copyProps = (to, from, except, desc) => {
6
+ if (from && typeof from === "object" || typeof from === "function") {
7
+ for (let key of __getOwnPropNames(from))
8
+ if (!__hasOwnProp.call(to, key) && key !== except)
9
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
10
+ }
11
+ return to;
12
+ };
13
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
14
+ var types_exports = {};
15
+ module.exports = __toCommonJS(types_exports);