@chanmeng666/archlang-3d 0.1.2 → 0.2.0
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/CHANGELOG.md +52 -0
- package/dist/browser.d.ts +2 -2
- package/dist/browser.js +93 -48
- package/dist/{chunk-54YVSAVZ.js → chunk-2ZINQMUB.js} +18 -6
- package/dist/{chunk-DLZMYNAR.js → chunk-4AF5Q7M3.js} +104 -267
- package/dist/{chunk-CTFMM64C.js → chunk-EYEEIS4R.js} +128 -1
- package/dist/{chunk-KIRWFAD6.js → chunk-KUK6ARJC.js} +52 -32
- package/dist/chunk-VUSBWX7N.js +4125 -0
- package/dist/cli.js +5 -5
- package/dist/{facts-fLIb8sZ2.d.ts → facts-DHuCDilh.d.ts} +1 -1
- package/dist/index.d.ts +166 -64
- package/dist/index.js +51 -11
- package/dist/node.d.ts +10 -4
- package/dist/node.js +6 -4
- package/dist/replay.d.ts +12 -1
- package/dist/scene3d.schema.json +4 -0
- package/dist/{strip-DElA8ZbJ.d.ts → strip-CdTeMoHA.d.ts} +102 -1
- package/dist/viewer.iife.js +175 -175
- package/package.json +1 -1
- package/dist/chunk-PJMKP2ML.js +0 -950
|
@@ -1,14 +1,20 @@
|
|
|
1
1
|
import {
|
|
2
2
|
ARCHLANG_3D_VERSION,
|
|
3
3
|
validateScene3D
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-VUSBWX7N.js";
|
|
5
5
|
import {
|
|
6
6
|
PREVIEW_LABEL,
|
|
7
7
|
replayPayload
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-2ZINQMUB.js";
|
|
9
9
|
import {
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
FINISH_PALETTE,
|
|
11
|
+
FLOOR_FINISHES,
|
|
12
|
+
KIND_PALETTE,
|
|
13
|
+
PALETTE,
|
|
14
|
+
keyFrames,
|
|
15
|
+
linearRgb,
|
|
16
|
+
slotGroups
|
|
17
|
+
} from "./chunk-EYEEIS4R.js";
|
|
12
18
|
|
|
13
19
|
// src/node.ts
|
|
14
20
|
import { readFileSync as readFileSync2 } from "node:fs";
|
|
@@ -239,18 +245,16 @@ async function renderReplay(o) {
|
|
|
239
245
|
// src/glb/write.ts
|
|
240
246
|
import { Document, Logger, WebIO } from "@gltf-transform/core";
|
|
241
247
|
var GLB_GENERATOR = `archlang-3d ${ARCHLANG_3D_VERSION}`;
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
};
|
|
253
|
-
var DEMOLISH_COLOUR = [0.78, 0.33, 0.24, 0.3];
|
|
248
|
+
function bodyMaterialName(n) {
|
|
249
|
+
if (n.kind === "floor") return `floor:${FLOOR_FINISHES.find((f) => f === n.extras.finish) ?? "neutral"}`;
|
|
250
|
+
if (n.kind === "wall" && n.part === "demolish") return "wall:demolish";
|
|
251
|
+
if (n.kind === "window" && (n.part === "glass" || n.part === "frame")) return `window:${n.part}`;
|
|
252
|
+
return n.kind;
|
|
253
|
+
}
|
|
254
|
+
function bodyMaterial(name) {
|
|
255
|
+
if (name.startsWith("floor:")) return FINISH_PALETTE[name.slice("floor:".length)];
|
|
256
|
+
return KIND_PALETTE[name] ?? KIND_PALETTE.furniture;
|
|
257
|
+
}
|
|
254
258
|
var glbNodeName = (n) => n.key.slice(n.key.indexOf("/") + 1);
|
|
255
259
|
var levelNodeName = (level) => `level:L${level}`;
|
|
256
260
|
function nodeExtras(n) {
|
|
@@ -276,12 +280,23 @@ async function writeGlb(mesh, opts = {}) {
|
|
|
276
280
|
doc.getRoot().setDefaultScene(scene);
|
|
277
281
|
const materials = /* @__PURE__ */ new Map();
|
|
278
282
|
const material = (n) => {
|
|
279
|
-
const
|
|
280
|
-
|
|
283
|
+
const key = bodyMaterialName(n);
|
|
284
|
+
let m = materials.get(key);
|
|
285
|
+
if (!m) {
|
|
286
|
+
const p = bodyMaterial(key);
|
|
287
|
+
m = doc.createMaterial(key).setBaseColorFactor([...linearRgb(p.srgb), p.alpha]).setMetallicFactor(p.metallic).setRoughnessFactor(p.roughness);
|
|
288
|
+
if (p.alpha < 1) m.setAlphaMode("BLEND");
|
|
289
|
+
materials.set(key, m);
|
|
290
|
+
}
|
|
291
|
+
return m;
|
|
292
|
+
};
|
|
293
|
+
const slotMaterial = (slot) => {
|
|
294
|
+
const key = `fixture:${slot}`;
|
|
281
295
|
let m = materials.get(key);
|
|
282
296
|
if (!m) {
|
|
283
|
-
|
|
284
|
-
|
|
297
|
+
const p = PALETTE[slot];
|
|
298
|
+
m = doc.createMaterial(key).setBaseColorFactor([...linearRgb(p.srgb), p.alpha]).setMetallicFactor(p.metallic).setRoughnessFactor(p.roughness);
|
|
299
|
+
if (p.alpha < 1) m.setAlphaMode("BLEND");
|
|
285
300
|
materials.set(key, m);
|
|
286
301
|
}
|
|
287
302
|
return m;
|
|
@@ -294,19 +309,23 @@ async function writeGlb(mesh, opts = {}) {
|
|
|
294
309
|
scene.addChild(group);
|
|
295
310
|
levels.set(n.level, group);
|
|
296
311
|
}
|
|
297
|
-
const positions = [];
|
|
298
|
-
const indices = [];
|
|
299
|
-
for (const s of n.shells) {
|
|
300
|
-
const base = positions.length / 3;
|
|
301
|
-
for (const v of s.positions) positions.push(v / 1e6);
|
|
302
|
-
for (const i of s.indices) indices.push(base + i);
|
|
303
|
-
}
|
|
304
|
-
const count = positions.length / 3;
|
|
305
|
-
const pos = doc.createAccessor().setType("VEC3").setArray(new Float32Array(positions)).setBuffer(buffer);
|
|
306
|
-
const idx = doc.createAccessor().setType("SCALAR").setArray(count > 65535 ? new Uint32Array(indices) : new Uint16Array(indices)).setBuffer(buffer);
|
|
307
|
-
const prim = doc.createPrimitive().setAttribute("POSITION", pos).setIndices(idx).setMaterial(material(n));
|
|
308
312
|
const name = glbNodeName(n);
|
|
309
|
-
const
|
|
313
|
+
const gmesh = doc.createMesh(name);
|
|
314
|
+
for (const g of slotGroups(n.shells)) {
|
|
315
|
+
const positions = [];
|
|
316
|
+
const indices = [];
|
|
317
|
+
for (const s of g.shells) {
|
|
318
|
+
const base = positions.length / 3;
|
|
319
|
+
for (const v of s.positions) positions.push(v / 1e6);
|
|
320
|
+
for (const i of s.indices) indices.push(base + i);
|
|
321
|
+
}
|
|
322
|
+
const count = positions.length / 3;
|
|
323
|
+
const pos = doc.createAccessor().setType("VEC3").setArray(new Float32Array(positions)).setBuffer(buffer);
|
|
324
|
+
const idx = doc.createAccessor().setType("SCALAR").setArray(count > 65535 ? new Uint32Array(indices) : new Uint16Array(indices)).setBuffer(buffer);
|
|
325
|
+
const mat = g.slot === "body" ? material(n) : slotMaterial(g.slot);
|
|
326
|
+
gmesh.addPrimitive(doc.createPrimitive().setAttribute("POSITION", pos).setIndices(idx).setMaterial(mat));
|
|
327
|
+
}
|
|
328
|
+
const node = doc.createNode(name).setMesh(gmesh).setExtras({ archlang: nodeExtras(n) });
|
|
310
329
|
group.addChild(node);
|
|
311
330
|
}
|
|
312
331
|
return new WebIO().writeBinary(doc);
|
|
@@ -477,6 +496,7 @@ export {
|
|
|
477
496
|
SWIFTSHADER_ARGS,
|
|
478
497
|
renderReplay,
|
|
479
498
|
GLB_GENERATOR,
|
|
499
|
+
bodyMaterialName,
|
|
480
500
|
glbNodeName,
|
|
481
501
|
levelNodeName,
|
|
482
502
|
nodeExtras,
|