@playdrop/playdrop-cli 0.7.15 → 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.
- package/config/client-meta.json +1 -1
- package/node_modules/@playdrop/ai-client/dist/index.js +461 -444
- package/node_modules/@playdrop/ai-client/package.json +1 -1
- package/node_modules/@playdrop/api-client/dist/client.js +903 -882
- package/node_modules/@playdrop/api-client/dist/core/errors.js +69 -45
- package/node_modules/@playdrop/api-client/dist/core/request.js +188 -159
- package/node_modules/@playdrop/api-client/dist/domains/admin.js +516 -491
- package/node_modules/@playdrop/api-client/dist/domains/ai.js +40 -14
- package/node_modules/@playdrop/api-client/dist/domains/apps.js +480 -462
- package/node_modules/@playdrop/api-client/dist/domains/asset-packs.js +439 -419
- package/node_modules/@playdrop/api-client/dist/domains/assets.js +696 -676
- package/node_modules/@playdrop/api-client/dist/domains/auth.js +346 -320
- package/node_modules/@playdrop/api-client/dist/domains/comments.js +124 -98
- package/node_modules/@playdrop/api-client/dist/domains/free-credits.js +91 -65
- package/node_modules/@playdrop/api-client/dist/domains/me.js +71 -45
- package/node_modules/@playdrop/api-client/dist/domains/payments.js +407 -386
- package/node_modules/@playdrop/api-client/dist/domains/player-meta.js +144 -118
- package/node_modules/@playdrop/api-client/dist/domains/search.js +117 -104
- package/node_modules/@playdrop/api-client/dist/domains/tags.js +188 -162
- package/node_modules/@playdrop/api-client/dist/index.js +993 -552
- package/node_modules/@playdrop/api-client/package.json +1 -1
- package/node_modules/@playdrop/boxel-three/dist/src/animations.js +84 -62
- package/node_modules/@playdrop/boxel-three/dist/src/builders.js +341 -308
- package/node_modules/@playdrop/boxel-three/dist/src/context.js +55 -29
- package/node_modules/@playdrop/boxel-three/dist/src/exporters/glb.js +856 -858
- package/node_modules/@playdrop/boxel-three/dist/src/exporters/image.js +267 -261
- package/node_modules/@playdrop/boxel-three/dist/src/index.js +64 -15
- package/node_modules/@playdrop/boxel-three/dist/src/instantiate.js +89 -63
- package/node_modules/@playdrop/boxel-three/dist/src/nodes.js +81 -56
- package/node_modules/@playdrop/boxel-three/dist/src/overlays.js +112 -86
- package/node_modules/@playdrop/boxel-three/dist/src/primitives.js +45 -17
- package/node_modules/@playdrop/boxel-three/dist/src/scene.js +160 -136
- package/node_modules/@playdrop/boxel-three/dist/src/skinned-mesh.js +582 -584
- package/node_modules/@playdrop/boxel-three/dist/src/texture-atlas.js +123 -97
- package/node_modules/@playdrop/boxel-three/dist/src/textures.js +207 -182
- package/node_modules/@playdrop/boxel-three/dist/src/types.js +15 -1
- package/node_modules/@playdrop/boxel-three/dist/src/voxels/faces.js +451 -425
- package/node_modules/@playdrop/boxel-three/dist/src/voxels/mesher.js +109 -84
- package/node_modules/@playdrop/boxel-three/dist/test/export-image.playwright.test.js +127 -106
- package/node_modules/@playdrop/boxel-three/dist/test/fixtures/render-worker.js +73 -51
- package/node_modules/@playdrop/boxel-three/dist/test/glb-skinned.test.js +97 -79
- package/node_modules/@playdrop/boxel-three/dist/test/index.test.js +29 -7
- package/node_modules/@playdrop/boxel-three/dist/test/instantiate.test.js +80 -60
- package/node_modules/@playdrop/boxel-three/dist/test/overlays.test.js +41 -19
- package/node_modules/@playdrop/boxel-three/dist/test/scene-filter.test.js +72 -50
- package/node_modules/@playdrop/boxel-three/dist/test/scene-smoke.test.js +84 -62
- package/node_modules/@playdrop/boxel-three/dist/test/skinned-mesh.test.js +69 -47
- package/node_modules/@playdrop/boxel-three/dist/test/textured-overlay.test.js +129 -109
- package/node_modules/@playdrop/boxel-three/dist/test/voxels.test.js +40 -18
- package/node_modules/@playdrop/boxel-three/package.json +1 -1
- package/node_modules/@playdrop/config/client-meta.json +1 -1
- package/node_modules/@playdrop/types/dist/api.js +289 -203
- package/node_modules/@playdrop/types/dist/app-capability-filters.js +112 -62
- package/node_modules/@playdrop/types/dist/app.js +91 -45
- package/node_modules/@playdrop/types/dist/asset-pack.js +37 -5
- package/node_modules/@playdrop/types/dist/asset-spec.js +170 -90
- package/node_modules/@playdrop/types/dist/asset.js +186 -108
- package/node_modules/@playdrop/types/dist/content-license.js +49 -15
- package/node_modules/@playdrop/types/dist/creator-public-image.js +60 -32
- package/node_modules/@playdrop/types/dist/ecs.js +102 -82
- package/node_modules/@playdrop/types/dist/engine-builtins.js +603 -573
- package/node_modules/@playdrop/types/dist/entity.js +63 -53
- package/node_modules/@playdrop/types/dist/graph.js +116 -80
- package/node_modules/@playdrop/types/dist/index.js +47 -20
- package/node_modules/@playdrop/types/dist/owned-assets.js +55 -33
- package/node_modules/@playdrop/types/dist/player-meta.js +151 -100
- package/node_modules/@playdrop/types/dist/realtime.js +27 -7
- package/node_modules/@playdrop/types/dist/version.js +182 -124
- package/node_modules/@playdrop/types/package.json +1 -1
- package/package.json +1 -1
|
@@ -1,330 +1,363 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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 builders_exports = {};
|
|
19
|
+
__export(builders_exports, {
|
|
20
|
+
DEFAULT_COLOR: () => DEFAULT_COLOR,
|
|
21
|
+
DEFAULT_OPACITY: () => DEFAULT_OPACITY,
|
|
22
|
+
DEFAULT_WIREFRAME_COLOR: () => DEFAULT_WIREFRAME_COLOR,
|
|
23
|
+
createBoundingBoxMesh: () => createBoundingBoxMesh,
|
|
24
|
+
createPrimitiveObject: () => createPrimitiveObject
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(builders_exports);
|
|
27
|
+
var import_boxel_core = require("@playdrop/boxel-core");
|
|
28
|
+
var import_primitives = require("./primitives.js");
|
|
29
|
+
var import_textures = require("./textures.js");
|
|
30
|
+
var import_mesher = require("./voxels/mesher.js");
|
|
31
|
+
const DEFAULT_COLOR = 3900150;
|
|
32
|
+
const DEFAULT_OPACITY = 0.45;
|
|
33
|
+
const DEFAULT_WIREFRAME_COLOR = 6333946;
|
|
34
|
+
const BOX_FACES = ["east", "west", "top", "bottom", "north", "south"];
|
|
9
35
|
const OVERLAY_THICKNESS = 0.25;
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
36
|
+
function createBoundingBoxMesh(context, size) {
|
|
37
|
+
const geometry = (0, import_primitives.createBoxGeometry)(context.THREE, size);
|
|
38
|
+
const material = new context.THREE.MeshStandardMaterial({
|
|
39
|
+
color: DEFAULT_COLOR,
|
|
40
|
+
transparent: true,
|
|
41
|
+
opacity: DEFAULT_OPACITY,
|
|
42
|
+
metalness: 0,
|
|
43
|
+
roughness: 0.75
|
|
44
|
+
});
|
|
45
|
+
const mesh = new context.THREE.Mesh(geometry, material);
|
|
46
|
+
const edges = new context.THREE.EdgesGeometry(geometry);
|
|
47
|
+
const lineMaterial = new context.THREE.LineBasicMaterial({ color: DEFAULT_WIREFRAME_COLOR });
|
|
48
|
+
const wireframe = new context.THREE.LineSegments(edges, lineMaterial);
|
|
49
|
+
mesh.add(wireframe);
|
|
50
|
+
mesh.userData = {
|
|
51
|
+
...mesh.userData ?? {},
|
|
52
|
+
size: [...size],
|
|
53
|
+
placeholder: true
|
|
54
|
+
};
|
|
55
|
+
return mesh;
|
|
30
56
|
}
|
|
31
57
|
function createPlainBoxObject(context, primitive, alignment) {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
+
const materialDef = context.materialsById.get(primitive.material);
|
|
59
|
+
const color = materialDef?.baseColor ?? [59, 130, 246];
|
|
60
|
+
const geometry = (0, import_primitives.createBoxGeometry)(context.THREE, primitive.size);
|
|
61
|
+
const meshMaterial = new context.THREE.MeshStandardMaterial({
|
|
62
|
+
color: (0, import_textures.toThreeColorRGB)(context, color),
|
|
63
|
+
metalness: 0,
|
|
64
|
+
roughness: 1,
|
|
65
|
+
transparent: materialDef?.opacity !== void 0 && materialDef.opacity < 1,
|
|
66
|
+
opacity: materialDef?.opacity !== void 0 ? materialDef.opacity : 1
|
|
67
|
+
});
|
|
68
|
+
if (materialDef?.emissiveColor) {
|
|
69
|
+
meshMaterial.emissive.copy((0, import_textures.toThreeColorRGB)(context, materialDef.emissiveColor));
|
|
70
|
+
meshMaterial.emissiveIntensity = 1;
|
|
71
|
+
}
|
|
72
|
+
meshMaterial.needsUpdate = true;
|
|
73
|
+
const mesh = new context.THREE.Mesh(geometry, meshMaterial);
|
|
74
|
+
mesh.name = primitive.id;
|
|
75
|
+
mesh.userData = {
|
|
76
|
+
...mesh.userData ?? {},
|
|
77
|
+
primitiveId: primitive.id,
|
|
78
|
+
size: [...primitive.size]
|
|
79
|
+
};
|
|
80
|
+
if (alignment === "grounded") {
|
|
81
|
+
mesh.position.y = primitive.size[1] / 2;
|
|
82
|
+
}
|
|
83
|
+
return mesh;
|
|
58
84
|
}
|
|
59
85
|
function createTexturedBoxObject(context, primitive, alignment) {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
material.side = context.THREE.FrontSide;
|
|
73
|
-
}
|
|
74
|
-
material.depthWrite = true;
|
|
75
|
-
material.needsUpdate = true;
|
|
76
|
-
});
|
|
77
|
-
const mesh = new context.THREE.Mesh(geometry, materials);
|
|
78
|
-
mesh.name = primitive.id;
|
|
79
|
-
mesh.userData = {
|
|
80
|
-
...(mesh.userData ?? {}),
|
|
81
|
-
primitiveId: primitive.id,
|
|
82
|
-
size: [...primitive.size],
|
|
83
|
-
};
|
|
84
|
-
if (alignment === 'grounded') {
|
|
85
|
-
mesh.position.y = primitive.size[1] / 2;
|
|
86
|
+
const geometry = (0, import_primitives.createBoxGeometry)(context.THREE, primitive.size);
|
|
87
|
+
const materials = BOX_FACES.map((face) => (0, import_textures.createTextureMaterial)(context, (0, import_boxel_core.resolveFaceTextureId)(primitive, face)));
|
|
88
|
+
const renderMode = primitive.renderMode === "cutout" ? "cutout" : "plain";
|
|
89
|
+
materials.forEach((material) => {
|
|
90
|
+
if (renderMode === "cutout") {
|
|
91
|
+
material.transparent = false;
|
|
92
|
+
material.alphaTest = 0.5;
|
|
93
|
+
material.side = context.THREE.DoubleSide;
|
|
94
|
+
} else {
|
|
95
|
+
material.transparent = true;
|
|
96
|
+
material.alphaTest = 0;
|
|
97
|
+
material.side = context.THREE.FrontSide;
|
|
86
98
|
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
99
|
+
material.depthWrite = true;
|
|
100
|
+
material.needsUpdate = true;
|
|
101
|
+
});
|
|
102
|
+
const mesh = new context.THREE.Mesh(geometry, materials);
|
|
103
|
+
mesh.name = primitive.id;
|
|
104
|
+
mesh.userData = {
|
|
105
|
+
...mesh.userData ?? {},
|
|
106
|
+
primitiveId: primitive.id,
|
|
107
|
+
size: [...primitive.size]
|
|
108
|
+
};
|
|
109
|
+
if (alignment === "grounded") {
|
|
110
|
+
mesh.position.y = primitive.size[1] / 2;
|
|
111
|
+
}
|
|
112
|
+
const overlayTextureIds = BOX_FACES.map((face) => (0, import_boxel_core.resolveOverlayFaceTextureId)(primitive, face));
|
|
113
|
+
const hasOverlay = overlayTextureIds.some((id) => typeof id === "string" && id.trim().length > 0);
|
|
114
|
+
if (hasOverlay) {
|
|
115
|
+
const overlaySize = [
|
|
116
|
+
primitive.size[0] + OVERLAY_THICKNESS * 2,
|
|
117
|
+
primitive.size[1] + OVERLAY_THICKNESS * 2,
|
|
118
|
+
primitive.size[2] + OVERLAY_THICKNESS * 2
|
|
119
|
+
];
|
|
120
|
+
const overlayGeometry = (0, import_primitives.createBoxGeometry)(context.THREE, overlaySize);
|
|
121
|
+
const overlayMaterials = overlayTextureIds.map((textureId) => {
|
|
122
|
+
if (!textureId) {
|
|
123
|
+
const emptyMaterial = new context.THREE.MeshStandardMaterial({
|
|
124
|
+
transparent: true,
|
|
125
|
+
opacity: 0,
|
|
126
|
+
depthWrite: false,
|
|
127
|
+
metalness: 0,
|
|
128
|
+
roughness: 1
|
|
116
129
|
});
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
130
|
+
emptyMaterial.visible = false;
|
|
131
|
+
emptyMaterial.needsUpdate = true;
|
|
132
|
+
return emptyMaterial;
|
|
133
|
+
}
|
|
134
|
+
const material = (0, import_textures.createTextureMaterial)(context, textureId);
|
|
135
|
+
material.transparent = true;
|
|
136
|
+
material.alphaTest = 0.5;
|
|
137
|
+
material.side = context.THREE.DoubleSide;
|
|
138
|
+
material.depthWrite = false;
|
|
139
|
+
material.needsUpdate = true;
|
|
140
|
+
return material;
|
|
141
|
+
});
|
|
142
|
+
const overlayMesh = new context.THREE.Mesh(overlayGeometry, overlayMaterials);
|
|
143
|
+
overlayMesh.name = `${primitive.id}_overlay`;
|
|
144
|
+
overlayMesh.renderOrder = mesh.renderOrder + 1;
|
|
145
|
+
overlayMesh.userData = {
|
|
146
|
+
...mesh.userData ?? {},
|
|
147
|
+
primitiveId: primitive.id,
|
|
148
|
+
overlay: true,
|
|
149
|
+
size: [...overlaySize]
|
|
150
|
+
};
|
|
151
|
+
mesh.add(overlayMesh);
|
|
152
|
+
}
|
|
153
|
+
return mesh;
|
|
129
154
|
}
|
|
130
155
|
function createVoxelObject(context, primitive, alignment) {
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
}
|
|
149
|
-
return mesh;
|
|
156
|
+
const hasData = Array.isArray(primitive.voxels) && primitive.voxels.length > 0;
|
|
157
|
+
const size = primitive.size ?? [1, 1, 1];
|
|
158
|
+
const dims = [
|
|
159
|
+
Math.max(1, Math.round(size[0])),
|
|
160
|
+
Math.max(1, Math.round(size[1])),
|
|
161
|
+
Math.max(1, Math.round(size[2]))
|
|
162
|
+
];
|
|
163
|
+
const worldSize = [dims[0], dims[1], dims[2]];
|
|
164
|
+
if (!hasData) {
|
|
165
|
+
const mesh2 = createBoundingBoxMesh(context, worldSize);
|
|
166
|
+
mesh2.userData = {
|
|
167
|
+
...mesh2.userData ?? {},
|
|
168
|
+
primitiveId: primitive.id,
|
|
169
|
+
size: [...worldSize]
|
|
170
|
+
};
|
|
171
|
+
if (alignment === "grounded") {
|
|
172
|
+
mesh2.position.y = worldSize[1] / 2;
|
|
150
173
|
}
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
174
|
+
return mesh2;
|
|
175
|
+
}
|
|
176
|
+
const meshResult = (0, import_mesher.buildVoxelMesh)({
|
|
177
|
+
voxels: primitive.voxels,
|
|
178
|
+
dimensions: dims,
|
|
179
|
+
size: worldSize
|
|
180
|
+
});
|
|
181
|
+
if (meshResult.indices.length === 0 || meshResult.positions.length === 0) {
|
|
182
|
+
const mesh2 = createBoundingBoxMesh(context, worldSize);
|
|
183
|
+
mesh2.userData = {
|
|
184
|
+
...mesh2.userData ?? {},
|
|
185
|
+
primitiveId: primitive.id,
|
|
186
|
+
size: [...worldSize]
|
|
187
|
+
};
|
|
188
|
+
if (alignment === "grounded") {
|
|
189
|
+
mesh2.position.y = worldSize[1] / 2;
|
|
167
190
|
}
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
191
|
+
return mesh2;
|
|
192
|
+
}
|
|
193
|
+
const paletteIds = primitive.palette ?? [];
|
|
194
|
+
const materialCache = /* @__PURE__ */ new Map();
|
|
195
|
+
const materialIndexMap = /* @__PURE__ */ new Map();
|
|
196
|
+
const materials = [];
|
|
197
|
+
const geometry = new context.THREE.BufferGeometry();
|
|
198
|
+
geometry.setAttribute("position", new context.THREE.Float32BufferAttribute(meshResult.positions, 3));
|
|
199
|
+
geometry.setAttribute("normal", new context.THREE.Float32BufferAttribute(meshResult.normals, 3));
|
|
200
|
+
geometry.setAttribute("uv", new context.THREE.Float32BufferAttribute(meshResult.uvs, 2));
|
|
201
|
+
if (meshResult.indices.length > 0) {
|
|
202
|
+
const vertexCount = meshResult.positions.length / 3;
|
|
203
|
+
const useUint32 = vertexCount > 65535;
|
|
204
|
+
const indexArray = useUint32 ? meshResult.indices : new Uint16Array(meshResult.indices);
|
|
205
|
+
geometry.setIndex(new context.THREE.BufferAttribute(indexArray, 1));
|
|
206
|
+
}
|
|
207
|
+
geometry.computeBoundingBox();
|
|
208
|
+
geometry.computeBoundingSphere();
|
|
209
|
+
meshResult.groups.forEach((groupData) => {
|
|
210
|
+
const paletteIndex = groupData.material;
|
|
211
|
+
let material = materialCache.get(paletteIndex);
|
|
212
|
+
if (!material) {
|
|
213
|
+
const materialId = paletteIds[paletteIndex - 1];
|
|
214
|
+
const materialDef = materialId ? context.materialsById.get(materialId) : void 0;
|
|
215
|
+
const baseColor = materialDef?.baseColor ?? [59, 130, 246];
|
|
216
|
+
const emissive = materialDef?.emissiveColor;
|
|
217
|
+
const opacity = materialDef?.opacity ?? 1;
|
|
218
|
+
material = new context.THREE.MeshStandardMaterial({
|
|
219
|
+
color: (0, import_textures.toThreeColorRGB)(context, baseColor),
|
|
220
|
+
metalness: 0,
|
|
221
|
+
roughness: 1,
|
|
222
|
+
transparent: opacity < 1,
|
|
223
|
+
opacity
|
|
224
|
+
});
|
|
225
|
+
if (emissive) {
|
|
226
|
+
material.emissive.copy((0, import_textures.toThreeColorRGB)(context, emissive));
|
|
227
|
+
material.emissiveIntensity = 1;
|
|
228
|
+
}
|
|
229
|
+
material.needsUpdate = true;
|
|
230
|
+
materialCache.set(paletteIndex, material);
|
|
181
231
|
}
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
if (!material) {
|
|
188
|
-
const materialId = paletteIds[paletteIndex - 1];
|
|
189
|
-
const materialDef = materialId ? context.materialsById.get(materialId) : undefined;
|
|
190
|
-
const baseColor = materialDef?.baseColor ?? [59, 130, 246];
|
|
191
|
-
const emissive = materialDef?.emissiveColor;
|
|
192
|
-
const opacity = materialDef?.opacity ?? 1;
|
|
193
|
-
material = new context.THREE.MeshStandardMaterial({
|
|
194
|
-
color: toThreeColorRGB(context, baseColor),
|
|
195
|
-
metalness: 0,
|
|
196
|
-
roughness: 1,
|
|
197
|
-
transparent: opacity < 1,
|
|
198
|
-
opacity,
|
|
199
|
-
});
|
|
200
|
-
if (emissive) {
|
|
201
|
-
material.emissive.copy(toThreeColorRGB(context, emissive));
|
|
202
|
-
material.emissiveIntensity = 1;
|
|
203
|
-
}
|
|
204
|
-
material.needsUpdate = true;
|
|
205
|
-
materialCache.set(paletteIndex, material);
|
|
206
|
-
}
|
|
207
|
-
let materialIndex = materialIndexMap.get(paletteIndex);
|
|
208
|
-
if (materialIndex === undefined) {
|
|
209
|
-
materialIndex = materials.length;
|
|
210
|
-
materials.push(material);
|
|
211
|
-
materialIndexMap.set(paletteIndex, materialIndex);
|
|
212
|
-
}
|
|
213
|
-
geometry.addGroup(groupData.start, groupData.count, materialIndex);
|
|
214
|
-
});
|
|
215
|
-
const meshMaterial = materials.length === 1 ? materials[0] : materials;
|
|
216
|
-
const mesh = new context.THREE.Mesh(geometry, meshMaterial);
|
|
217
|
-
mesh.name = primitive.id;
|
|
218
|
-
mesh.userData = {
|
|
219
|
-
...(mesh.userData ?? {}),
|
|
220
|
-
primitiveId: primitive.id,
|
|
221
|
-
size: [...worldSize],
|
|
222
|
-
};
|
|
223
|
-
if (alignment === 'grounded') {
|
|
224
|
-
mesh.position.y = size[1] / 2;
|
|
232
|
+
let materialIndex = materialIndexMap.get(paletteIndex);
|
|
233
|
+
if (materialIndex === void 0) {
|
|
234
|
+
materialIndex = materials.length;
|
|
235
|
+
materials.push(material);
|
|
236
|
+
materialIndexMap.set(paletteIndex, materialIndex);
|
|
225
237
|
}
|
|
226
|
-
|
|
238
|
+
geometry.addGroup(groupData.start, groupData.count, materialIndex);
|
|
239
|
+
});
|
|
240
|
+
const meshMaterial = materials.length === 1 ? materials[0] : materials;
|
|
241
|
+
const mesh = new context.THREE.Mesh(geometry, meshMaterial);
|
|
242
|
+
mesh.name = primitive.id;
|
|
243
|
+
mesh.userData = {
|
|
244
|
+
...mesh.userData ?? {},
|
|
245
|
+
primitiveId: primitive.id,
|
|
246
|
+
size: [...worldSize]
|
|
247
|
+
};
|
|
248
|
+
if (alignment === "grounded") {
|
|
249
|
+
mesh.position.y = size[1] / 2;
|
|
250
|
+
}
|
|
251
|
+
return mesh;
|
|
227
252
|
}
|
|
228
253
|
function createComboObject(context, primitive, alignment, visited) {
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
}
|
|
239
|
-
const object = createPrimitiveObject(context, childPrimitive, alignment, new Set(visited));
|
|
240
|
-
if (!object)
|
|
241
|
-
return;
|
|
242
|
-
const childSize = [
|
|
243
|
-
childPrimitive.size?.[0] ?? 0,
|
|
244
|
-
childPrimitive.size?.[1] ?? 0,
|
|
245
|
-
childPrimitive.size?.[2] ?? 0,
|
|
246
|
-
];
|
|
247
|
-
slotEntries.push({ slot, object, size: childSize });
|
|
248
|
-
});
|
|
249
|
-
if (slotEntries.length === 0) {
|
|
250
|
-
const fallbackSize = [
|
|
251
|
-
primitive.size?.[0] ?? 1,
|
|
252
|
-
primitive.size?.[1] ?? 1,
|
|
253
|
-
primitive.size?.[2] ?? 1,
|
|
254
|
-
];
|
|
255
|
-
const bounding = createBoundingBoxMesh(context, fallbackSize);
|
|
256
|
-
bounding.userData = {
|
|
257
|
-
...(bounding.userData ?? {}),
|
|
258
|
-
primitiveId: primitive.id,
|
|
259
|
-
size: [...fallbackSize],
|
|
260
|
-
};
|
|
261
|
-
if (alignment === 'grounded') {
|
|
262
|
-
bounding.position.y = fallbackSize[1] / 2;
|
|
263
|
-
}
|
|
264
|
-
return bounding;
|
|
254
|
+
const group = new context.THREE.Group();
|
|
255
|
+
group.name = primitive.id;
|
|
256
|
+
const sockets = [];
|
|
257
|
+
const slotEntries = [];
|
|
258
|
+
primitive.slots.forEach((slot) => {
|
|
259
|
+
const childPrimitive = context.primitivesById.get(slot.primitive);
|
|
260
|
+
if (!childPrimitive) {
|
|
261
|
+
console.warn("[boxel-three] combo slot references missing primitive", slot.primitive);
|
|
262
|
+
return;
|
|
265
263
|
}
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
const halfSize = [size[0] / 2, size[1] / 2, size[2] / 2];
|
|
274
|
-
minX = Math.min(minX, slot.offset[0] - halfSize[0]);
|
|
275
|
-
minY = Math.min(minY, slot.offset[1] - halfSize[1]);
|
|
276
|
-
minZ = Math.min(minZ, slot.offset[2] - halfSize[2]);
|
|
277
|
-
maxX = Math.max(maxX, slot.offset[0] + halfSize[0]);
|
|
278
|
-
maxY = Math.max(maxY, slot.offset[1] + halfSize[1]);
|
|
279
|
-
maxZ = Math.max(maxZ, slot.offset[2] + halfSize[2]);
|
|
280
|
-
});
|
|
281
|
-
const derivedSize = [
|
|
282
|
-
Math.max(0, maxX - minX),
|
|
283
|
-
Math.max(0, maxY - minY),
|
|
284
|
-
Math.max(0, maxZ - minZ),
|
|
264
|
+
const object = createPrimitiveObject(context, childPrimitive, alignment, new Set(visited));
|
|
265
|
+
if (!object)
|
|
266
|
+
return;
|
|
267
|
+
const childSize = [
|
|
268
|
+
childPrimitive.size?.[0] ?? 0,
|
|
269
|
+
childPrimitive.size?.[1] ?? 0,
|
|
270
|
+
childPrimitive.size?.[2] ?? 0
|
|
285
271
|
];
|
|
286
|
-
slotEntries.
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
group.add(object);
|
|
294
|
-
sockets.push([slot.offset[0], slot.offset[1], slot.offset[2]]);
|
|
295
|
-
});
|
|
296
|
-
const comboSize = [
|
|
297
|
-
primitive.size?.[0] ?? derivedSize[0],
|
|
298
|
-
primitive.size?.[1] ?? derivedSize[1],
|
|
299
|
-
primitive.size?.[2] ?? derivedSize[2],
|
|
272
|
+
slotEntries.push({ slot, object, size: childSize });
|
|
273
|
+
});
|
|
274
|
+
if (slotEntries.length === 0) {
|
|
275
|
+
const fallbackSize = [
|
|
276
|
+
primitive.size?.[0] ?? 1,
|
|
277
|
+
primitive.size?.[1] ?? 1,
|
|
278
|
+
primitive.size?.[2] ?? 1
|
|
300
279
|
];
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
280
|
+
const bounding = createBoundingBoxMesh(context, fallbackSize);
|
|
281
|
+
bounding.userData = {
|
|
282
|
+
...bounding.userData ?? {},
|
|
283
|
+
primitiveId: primitive.id,
|
|
284
|
+
size: [...fallbackSize]
|
|
306
285
|
};
|
|
307
|
-
if (alignment ===
|
|
308
|
-
|
|
286
|
+
if (alignment === "grounded") {
|
|
287
|
+
bounding.position.y = fallbackSize[1] / 2;
|
|
309
288
|
}
|
|
310
|
-
return
|
|
289
|
+
return bounding;
|
|
290
|
+
}
|
|
291
|
+
let minX = Infinity;
|
|
292
|
+
let minY = Infinity;
|
|
293
|
+
let minZ = Infinity;
|
|
294
|
+
let maxX = -Infinity;
|
|
295
|
+
let maxY = -Infinity;
|
|
296
|
+
let maxZ = -Infinity;
|
|
297
|
+
slotEntries.forEach(({ slot, size }) => {
|
|
298
|
+
const halfSize = [size[0] / 2, size[1] / 2, size[2] / 2];
|
|
299
|
+
minX = Math.min(minX, slot.offset[0] - halfSize[0]);
|
|
300
|
+
minY = Math.min(minY, slot.offset[1] - halfSize[1]);
|
|
301
|
+
minZ = Math.min(minZ, slot.offset[2] - halfSize[2]);
|
|
302
|
+
maxX = Math.max(maxX, slot.offset[0] + halfSize[0]);
|
|
303
|
+
maxY = Math.max(maxY, slot.offset[1] + halfSize[1]);
|
|
304
|
+
maxZ = Math.max(maxZ, slot.offset[2] + halfSize[2]);
|
|
305
|
+
});
|
|
306
|
+
const derivedSize = [
|
|
307
|
+
Math.max(0, maxX - minX),
|
|
308
|
+
Math.max(0, maxY - minY),
|
|
309
|
+
Math.max(0, maxZ - minZ)
|
|
310
|
+
];
|
|
311
|
+
slotEntries.forEach(({ slot, object }) => {
|
|
312
|
+
object.position.set(slot.offset[0], slot.offset[1], slot.offset[2]);
|
|
313
|
+
object.userData = {
|
|
314
|
+
...object.userData ?? {},
|
|
315
|
+
comboSlotId: slot.id,
|
|
316
|
+
comboParentId: primitive.id
|
|
317
|
+
};
|
|
318
|
+
group.add(object);
|
|
319
|
+
sockets.push([slot.offset[0], slot.offset[1], slot.offset[2]]);
|
|
320
|
+
});
|
|
321
|
+
const comboSize = [
|
|
322
|
+
primitive.size?.[0] ?? derivedSize[0],
|
|
323
|
+
primitive.size?.[1] ?? derivedSize[1],
|
|
324
|
+
primitive.size?.[2] ?? derivedSize[2]
|
|
325
|
+
];
|
|
326
|
+
group.userData = {
|
|
327
|
+
...group.userData ?? {},
|
|
328
|
+
primitiveId: primitive.id,
|
|
329
|
+
size: [...comboSize],
|
|
330
|
+
sockets
|
|
331
|
+
};
|
|
332
|
+
if (alignment === "grounded") {
|
|
333
|
+
group.position.y = comboSize[1] / 2;
|
|
334
|
+
}
|
|
335
|
+
return group;
|
|
311
336
|
}
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
337
|
+
function createPrimitiveObject(context, primitive, alignment, visited = /* @__PURE__ */ new Set()) {
|
|
338
|
+
if (visited.has(primitive.id)) {
|
|
339
|
+
console.warn("[boxel-three] detected recursive primitive reference", primitive.id);
|
|
340
|
+
return null;
|
|
341
|
+
}
|
|
342
|
+
visited.add(primitive.id);
|
|
343
|
+
switch (primitive.kind) {
|
|
344
|
+
case "plain_box":
|
|
345
|
+
return createPlainBoxObject(context, primitive, alignment);
|
|
346
|
+
case "textured_box":
|
|
347
|
+
return createTexturedBoxObject(context, primitive, alignment);
|
|
348
|
+
case "voxel_box":
|
|
349
|
+
return createVoxelObject(context, primitive, alignment);
|
|
350
|
+
case "combo_box":
|
|
351
|
+
return createComboObject(context, primitive, alignment, visited);
|
|
352
|
+
default:
|
|
353
|
+
return null;
|
|
354
|
+
}
|
|
330
355
|
}
|
|
356
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
357
|
+
0 && (module.exports = {
|
|
358
|
+
DEFAULT_COLOR,
|
|
359
|
+
DEFAULT_OPACITY,
|
|
360
|
+
DEFAULT_WIREFRAME_COLOR,
|
|
361
|
+
createBoundingBoxMesh,
|
|
362
|
+
createPrimitiveObject
|
|
363
|
+
});
|