@react-arch/exporters 0.1.2 → 0.1.3
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/dist/gltf.d.ts +15 -0
- package/dist/gltf.d.ts.map +1 -0
- package/dist/gltf.js +99 -0
- package/dist/gltf.js.map +1 -0
- package/dist/index.d.ts +3 -10
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +23 -88
- package/dist/index.js.map +1 -1
- package/package.json +8 -4
package/dist/gltf.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { BuildingDocument } from "@react-arch/core";
|
|
2
|
+
import * as THREE from "three";
|
|
3
|
+
|
|
4
|
+
//#region src/gltf.d.ts
|
|
5
|
+
interface GltfExportOptions {
|
|
6
|
+
floorIds?: string[] | "all";
|
|
7
|
+
binary?: boolean;
|
|
8
|
+
}
|
|
9
|
+
/** Build a Three.js scene mirroring the 3D renderer's geometry. */
|
|
10
|
+
declare function buildExportScene(doc: BuildingDocument, floorIds?: string[] | "all"): THREE.Group;
|
|
11
|
+
/** Export the building as GLTF (JSON) or GLB (binary ArrayBuffer). */
|
|
12
|
+
declare function exportGLTF(doc: BuildingDocument, options?: GltfExportOptions): Promise<ArrayBuffer | object>;
|
|
13
|
+
//#endregion
|
|
14
|
+
export { GltfExportOptions, buildExportScene, exportGLTF };
|
|
15
|
+
//# sourceMappingURL=gltf.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gltf.d.ts","names":[],"sources":["../src/gltf.ts"],"mappings":";;;;UAKiB,iBAAA;EACf,QAAA;EACA,MAAM;AAAA;;iBAIQ,gBAAA,CACd,GAAA,EAAK,gBAAA,EACL,QAAA,sBACC,KAAA,CAAM,KAAK;AAPN;AAAA,iBAgGQ,UAAA,CACd,GAAA,EAAK,gBAAA,EACL,OAAA,GAAS,iBAAA,GACR,OAAA,CAAQ,WAAA"}
|
package/dist/gltf.js
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { allFloors, furnitureColor, furnitureDims } from "@react-arch/core";
|
|
2
|
+
import { bounds, wallBoxes, wallDirection } from "@react-arch/geometry";
|
|
3
|
+
import * as THREE from "three";
|
|
4
|
+
import { GLTFExporter } from "three/examples/jsm/exporters/GLTFExporter.js";
|
|
5
|
+
//#region src/gltf.ts
|
|
6
|
+
/** Build a Three.js scene mirroring the 3D renderer's geometry. */
|
|
7
|
+
function buildExportScene(doc, floorIds = "all") {
|
|
8
|
+
const root = new THREE.Group();
|
|
9
|
+
root.name = doc.name;
|
|
10
|
+
const matFor = (color, opts = {}) => new THREE.MeshStandardMaterial({
|
|
11
|
+
color: new THREE.Color(color),
|
|
12
|
+
roughness: .9,
|
|
13
|
+
...opts
|
|
14
|
+
});
|
|
15
|
+
const colorFor = (materialId, fallback) => materialId ? doc.materials.find((m) => m.id === materialId)?.baseColor ?? fallback : fallback;
|
|
16
|
+
const slabMat = matFor("#9b9b97");
|
|
17
|
+
for (const floor of allFloors(doc)) {
|
|
18
|
+
if (!(floorIds === "all" ? floor.visible : floorIds.includes(floor.id))) continue;
|
|
19
|
+
const floorGroup = new THREE.Group();
|
|
20
|
+
floorGroup.name = floor.name;
|
|
21
|
+
const el = floor.elevation;
|
|
22
|
+
const openingsByWall = /* @__PURE__ */ new Map();
|
|
23
|
+
for (const o of floor.openings) {
|
|
24
|
+
const arr = openingsByWall.get(o.wallId) ?? [];
|
|
25
|
+
arr.push(o);
|
|
26
|
+
openingsByWall.set(o.wallId, arr);
|
|
27
|
+
}
|
|
28
|
+
for (const wall of floor.walls) {
|
|
29
|
+
const dir = wallDirection(wall);
|
|
30
|
+
const theta = Math.atan2(dir[1], dir[0]);
|
|
31
|
+
const opens = (openingsByWall.get(wall.id) ?? []).map((o) => ({
|
|
32
|
+
offset: o.offset,
|
|
33
|
+
width: o.width,
|
|
34
|
+
height: o.height,
|
|
35
|
+
sillHeight: o.sillHeight
|
|
36
|
+
}));
|
|
37
|
+
for (const s of wallBoxes(wall, opens, wall.height, wall.thickness / 2)) {
|
|
38
|
+
const along = (s.along0 + s.along1) / 2;
|
|
39
|
+
const px = wall.start[0] + dir[0] * along;
|
|
40
|
+
const py = wall.start[1] + dir[1] * along;
|
|
41
|
+
const geo = new THREE.BoxGeometry(Math.max(s.along1 - s.along0, .001), Math.max(s.z1 - s.z0, .001), wall.thickness);
|
|
42
|
+
const mesh = new THREE.Mesh(geo, matFor(colorFor(wall.materialId, "#e8e6e1")));
|
|
43
|
+
mesh.position.set(px, el + (s.z0 + s.z1) / 2, py);
|
|
44
|
+
mesh.rotation.y = -theta;
|
|
45
|
+
floorGroup.add(mesh);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
const wallById = new Map(floor.walls.map((w) => [w.id, w]));
|
|
49
|
+
for (const o of floor.openings) {
|
|
50
|
+
if (o.type === "opening") continue;
|
|
51
|
+
const wall = wallById.get(o.wallId);
|
|
52
|
+
if (!wall) continue;
|
|
53
|
+
const dir = wallDirection(wall);
|
|
54
|
+
const theta = Math.atan2(dir[1], dir[0]);
|
|
55
|
+
const px = wall.start[0] + dir[0] * o.offset;
|
|
56
|
+
const py = wall.start[1] + dir[1] * o.offset;
|
|
57
|
+
const depth = o.type === "window" ? .05 : wall.thickness * .6;
|
|
58
|
+
const geo = new THREE.BoxGeometry(Math.max(o.width - .04, .05), Math.max(o.height - .04, .05), depth);
|
|
59
|
+
const mesh = new THREE.Mesh(geo, o.type === "window" ? matFor(colorFor(o.materialId, "#bcd6e6"), {
|
|
60
|
+
transparent: true,
|
|
61
|
+
opacity: .4,
|
|
62
|
+
roughness: .05
|
|
63
|
+
}) : matFor(colorFor(o.materialId, "#6b4b2f"), { roughness: .6 }));
|
|
64
|
+
mesh.position.set(px, el + o.sillHeight + o.height / 2, py);
|
|
65
|
+
mesh.rotation.y = -theta;
|
|
66
|
+
floorGroup.add(mesh);
|
|
67
|
+
}
|
|
68
|
+
for (const ob of floor.objects) {
|
|
69
|
+
const d = furnitureDims(ob.type, ob.scale);
|
|
70
|
+
const geo = new THREE.BoxGeometry(d.width, d.height, d.depth);
|
|
71
|
+
const mesh = new THREE.Mesh(geo, matFor(furnitureColor(ob.type), { roughness: .7 }));
|
|
72
|
+
mesh.name = ob.id;
|
|
73
|
+
mesh.position.set(ob.position[0], el + ob.position[2] + d.height / 2, ob.position[1]);
|
|
74
|
+
mesh.rotation.y = -ob.rotation[2];
|
|
75
|
+
floorGroup.add(mesh);
|
|
76
|
+
}
|
|
77
|
+
if (floor.walls.length > 0) {
|
|
78
|
+
const b = bounds(floor.walls.flatMap((w) => [w.start, w.end]));
|
|
79
|
+
const geo = new THREE.BoxGeometry(b.width + .4, .14, b.height + .4);
|
|
80
|
+
const slab = new THREE.Mesh(geo, slabMat);
|
|
81
|
+
slab.position.set((b.min[0] + b.max[0]) / 2, el - .07, (b.min[1] + b.max[1]) / 2);
|
|
82
|
+
floorGroup.add(slab);
|
|
83
|
+
}
|
|
84
|
+
root.add(floorGroup);
|
|
85
|
+
}
|
|
86
|
+
return root;
|
|
87
|
+
}
|
|
88
|
+
/** Export the building as GLTF (JSON) or GLB (binary ArrayBuffer). */
|
|
89
|
+
function exportGLTF(doc, options = {}) {
|
|
90
|
+
const scene = buildExportScene(doc, options.floorIds ?? "all");
|
|
91
|
+
const exporter = new GLTFExporter();
|
|
92
|
+
return new Promise((resolve, reject) => {
|
|
93
|
+
exporter.parse(scene, (result) => resolve(result), (err) => reject(err), { binary: options.binary ?? true });
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
//#endregion
|
|
97
|
+
export { buildExportScene, exportGLTF };
|
|
98
|
+
|
|
99
|
+
//# sourceMappingURL=gltf.js.map
|
package/dist/gltf.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gltf.js","names":[],"sources":["../src/gltf.ts"],"sourcesContent":["import * as THREE from \"three\";\nimport { GLTFExporter } from \"three/examples/jsm/exporters/GLTFExporter.js\";\nimport { allFloors, furnitureColor, furnitureDims, type BuildingDocument } from \"@react-arch/core\";\nimport { bounds, wallBoxes, wallDirection } from \"@react-arch/geometry\";\n\nexport interface GltfExportOptions {\n floorIds?: string[] | \"all\";\n binary?: boolean;\n}\n\n/** Build a Three.js scene mirroring the 3D renderer's geometry. */\nexport function buildExportScene(\n doc: BuildingDocument,\n floorIds: string[] | \"all\" = \"all\",\n): THREE.Group {\n const root = new THREE.Group();\n root.name = doc.name;\n\n const matFor = (color: string, opts: Partial<THREE.MeshStandardMaterialParameters> = {}) =>\n new THREE.MeshStandardMaterial({ color: new THREE.Color(color), roughness: 0.9, ...opts });\n const colorFor = (materialId: string | undefined, fallback: string) =>\n materialId ? doc.materials.find((m) => m.id === materialId)?.baseColor ?? fallback : fallback;\n\n const slabMat = matFor(\"#9b9b97\");\n\n for (const floor of allFloors(doc)) {\n const visible = floorIds === \"all\" ? floor.visible : floorIds.includes(floor.id);\n if (!visible) continue;\n const floorGroup = new THREE.Group();\n floorGroup.name = floor.name;\n const el = floor.elevation;\n\n const openingsByWall = new Map<string, typeof floor.openings>();\n for (const o of floor.openings) {\n const arr = openingsByWall.get(o.wallId) ?? [];\n arr.push(o);\n openingsByWall.set(o.wallId, arr);\n }\n\n for (const wall of floor.walls) {\n const dir = wallDirection(wall);\n const theta = Math.atan2(dir[1], dir[0]);\n const opens = (openingsByWall.get(wall.id) ?? []).map((o) => ({\n offset: o.offset, width: o.width, height: o.height, sillHeight: o.sillHeight,\n }));\n for (const s of wallBoxes(wall, opens, wall.height, wall.thickness / 2)) {\n const along = (s.along0 + s.along1) / 2;\n const px = wall.start[0] + dir[0] * along;\n const py = wall.start[1] + dir[1] * along;\n const geo = new THREE.BoxGeometry(Math.max(s.along1 - s.along0, 0.001), Math.max(s.z1 - s.z0, 0.001), wall.thickness);\n const mesh = new THREE.Mesh(geo, matFor(colorFor(wall.materialId, \"#e8e6e1\")));\n mesh.position.set(px, el + (s.z0 + s.z1) / 2, py);\n mesh.rotation.y = -theta;\n floorGroup.add(mesh);\n }\n }\n\n const wallById = new Map(floor.walls.map((w) => [w.id, w]));\n for (const o of floor.openings) {\n if (o.type === \"opening\") continue;\n const wall = wallById.get(o.wallId);\n if (!wall) continue;\n const dir = wallDirection(wall);\n const theta = Math.atan2(dir[1], dir[0]);\n const px = wall.start[0] + dir[0] * o.offset;\n const py = wall.start[1] + dir[1] * o.offset;\n const depth = o.type === \"window\" ? 0.05 : wall.thickness * 0.6;\n const geo = new THREE.BoxGeometry(Math.max(o.width - 0.04, 0.05), Math.max(o.height - 0.04, 0.05), depth);\n const mesh = new THREE.Mesh(\n geo,\n o.type === \"window\"\n ? matFor(colorFor(o.materialId, \"#bcd6e6\"), { transparent: true, opacity: 0.4, roughness: 0.05 })\n : matFor(colorFor(o.materialId, \"#6b4b2f\"), { roughness: 0.6 }),\n );\n mesh.position.set(px, el + o.sillHeight + o.height / 2, py);\n mesh.rotation.y = -theta;\n floorGroup.add(mesh);\n }\n\n for (const ob of floor.objects) {\n const d = furnitureDims(ob.type, ob.scale);\n const geo = new THREE.BoxGeometry(d.width, d.height, d.depth);\n const mesh = new THREE.Mesh(geo, matFor(furnitureColor(ob.type), { roughness: 0.7 }));\n mesh.name = ob.id;\n mesh.position.set(ob.position[0], el + ob.position[2] + d.height / 2, ob.position[1]);\n mesh.rotation.y = -ob.rotation[2];\n floorGroup.add(mesh);\n }\n\n if (floor.walls.length > 0) {\n const b = bounds(floor.walls.flatMap((w) => [w.start, w.end]));\n const geo = new THREE.BoxGeometry(b.width + 0.4, 0.14, b.height + 0.4);\n const slab = new THREE.Mesh(geo, slabMat);\n slab.position.set((b.min[0] + b.max[0]) / 2, el - 0.07, (b.min[1] + b.max[1]) / 2);\n floorGroup.add(slab);\n }\n\n root.add(floorGroup);\n }\n return root;\n}\n\n/** Export the building as GLTF (JSON) or GLB (binary ArrayBuffer). */\nexport function exportGLTF(\n doc: BuildingDocument,\n options: GltfExportOptions = {},\n): Promise<ArrayBuffer | object> {\n const scene = buildExportScene(doc, options.floorIds ?? \"all\");\n const exporter = new GLTFExporter();\n return new Promise((resolve, reject) => {\n exporter.parse(\n scene,\n (result) => resolve(result as ArrayBuffer | object),\n (err) => reject(err),\n { binary: options.binary ?? true },\n );\n });\n}\n"],"mappings":";;;;;;AAWA,SAAgB,iBACd,KACA,WAA6B,OAChB;CACb,MAAM,OAAO,IAAI,MAAM,MAAM;CAC7B,KAAK,OAAO,IAAI;CAEhB,MAAM,UAAU,OAAe,OAAsD,CAAC,MACpF,IAAI,MAAM,qBAAqB;EAAE,OAAO,IAAI,MAAM,MAAM,KAAK;EAAG,WAAW;EAAK,GAAG;CAAK,CAAC;CAC3F,MAAM,YAAY,YAAgC,aAChD,aAAa,IAAI,UAAU,MAAM,MAAM,EAAE,OAAO,UAAU,CAAC,EAAE,aAAa,WAAW;CAEvF,MAAM,UAAU,OAAO,SAAS;CAEhC,KAAK,MAAM,SAAS,UAAU,GAAG,GAAG;EAElC,IAAI,EADY,aAAa,QAAQ,MAAM,UAAU,SAAS,SAAS,MAAM,EAAE,IACjE;EACd,MAAM,aAAa,IAAI,MAAM,MAAM;EACnC,WAAW,OAAO,MAAM;EACxB,MAAM,KAAK,MAAM;EAEjB,MAAM,iCAAiB,IAAI,IAAmC;EAC9D,KAAK,MAAM,KAAK,MAAM,UAAU;GAC9B,MAAM,MAAM,eAAe,IAAI,EAAE,MAAM,KAAK,CAAC;GAC7C,IAAI,KAAK,CAAC;GACV,eAAe,IAAI,EAAE,QAAQ,GAAG;EAClC;EAEA,KAAK,MAAM,QAAQ,MAAM,OAAO;GAC9B,MAAM,MAAM,cAAc,IAAI;GAC9B,MAAM,QAAQ,KAAK,MAAM,IAAI,IAAI,IAAI,EAAE;GACvC,MAAM,SAAS,eAAe,IAAI,KAAK,EAAE,KAAK,CAAC,EAAA,CAAG,KAAK,OAAO;IAC5D,QAAQ,EAAE;IAAQ,OAAO,EAAE;IAAO,QAAQ,EAAE;IAAQ,YAAY,EAAE;GACpE,EAAE;GACF,KAAK,MA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6B,CAAC,GACC;CAC/B,MAAM,QAAQ,iBAAiB,KAAK,QAAQ,YAAY,KAAK;CAC7D,MAAM,WAAW,IAAI,aAAa;CAClC,OAAO,IAAI,SAAS,SAAS,WAAW;EACtC,SAAS,MACP,QACC,WAAW,QAAQ,MAA8B,IACjD,QAAQ,OAAO,GAAG,GACnB,EAAE,QAAQ,QAAQ,UAAU,KAAK,CACnC;CACF,CAAC;AACH"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { GltfExportOptions } from "./gltf.js";
|
|
1
2
|
import { BuildingDocument } from "@react-arch/core";
|
|
2
|
-
import * as THREE from "three";
|
|
3
3
|
|
|
4
4
|
//#region src/json.d.ts
|
|
5
5
|
/** Canonical lossless JSON export. */
|
|
@@ -18,15 +18,8 @@ interface SvgExportOptions {
|
|
|
18
18
|
*/
|
|
19
19
|
declare function exportSVG(doc: BuildingDocument, options?: SvgExportOptions): string;
|
|
20
20
|
//#endregion
|
|
21
|
-
//#region src/
|
|
22
|
-
interface GltfExportOptions {
|
|
23
|
-
floorIds?: string[] | "all";
|
|
24
|
-
binary?: boolean;
|
|
25
|
-
}
|
|
26
|
-
/** Build a Three.js scene mirroring the 3D renderer's geometry. */
|
|
27
|
-
declare function buildExportScene(doc: BuildingDocument, floorIds?: string[] | "all"): THREE.Group;
|
|
28
|
-
/** Export the building as GLTF (JSON) or GLB (binary ArrayBuffer). */
|
|
21
|
+
//#region src/index.d.ts
|
|
29
22
|
declare function exportGLTF(doc: BuildingDocument, options?: GltfExportOptions): Promise<ArrayBuffer | object>;
|
|
30
23
|
//#endregion
|
|
31
|
-
export { type GltfExportOptions, type SvgExportOptions,
|
|
24
|
+
export { type GltfExportOptions, type SvgExportOptions, exportGLTF, exportJSON, exportSVG };
|
|
32
25
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/json.ts","../src/svg.ts","../src/
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/json.ts","../src/svg.ts","../src/index.ts"],"mappings":";;;;;iBAGgB,UAAA,CAAW,GAAqB,EAAhB,gBAAgB;;;UCO/B,gBAAA;EACf,QAAA;EACA,UAAA;EACA,cAAA;EACA,OAAA;AAAA;;ADX8C;;;iBCkBhC,SAAA,CAAU,GAAA,EAAK,gBAAA,EAAkB,OAAA,GAAS,gBAAqB;;;iBCTzD,UAAA,CACpB,GAAA,EAAK,gBAAA,EACL,OAAA,GADqB,iBAAA,GAEpB,OAAA,CAAQ,WAAA"}
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import { allFloors, serialize } from "@react-arch/core";
|
|
2
|
-
import { bounds, openingSpan, polygonArea, polygonCentroid,
|
|
3
|
-
import * as THREE from "three";
|
|
4
|
-
import { GLTFExporter } from "three/examples/jsm/exporters/GLTFExporter.js";
|
|
1
|
+
import { allFloors, furnitureDims, serialize } from "@react-arch/core";
|
|
2
|
+
import { bounds, openingSpan, polygonArea, polygonCentroid, wallPolygon } from "@react-arch/geometry";
|
|
5
3
|
//#region src/json.ts
|
|
6
4
|
/** Canonical lossless JSON export. */
|
|
7
5
|
function exportJSON(doc) {
|
|
@@ -20,7 +18,22 @@ function exportSVG(doc, options = {}) {
|
|
|
20
18
|
const pad = options.padding ?? 1;
|
|
21
19
|
const floors = allFloors(doc).filter((f) => floorIds === "all" ? f.visible : floorIds.includes(f.id));
|
|
22
20
|
const pts = [];
|
|
23
|
-
for (const f of floors)
|
|
21
|
+
for (const f of floors) {
|
|
22
|
+
const wallById = new Map(f.walls.map((w) => [w.id, w]));
|
|
23
|
+
for (const w of f.walls) pts.push(...wallPolygon(w));
|
|
24
|
+
for (const r of f.rooms) pts.push(...r.polygon);
|
|
25
|
+
for (const o of f.openings) {
|
|
26
|
+
const wall = wallById.get(o.wallId);
|
|
27
|
+
if (wall) {
|
|
28
|
+
const span = openingSpan(wall, o);
|
|
29
|
+
pts.push(span.start, span.end);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
for (const ob of f.objects) {
|
|
33
|
+
const d = furnitureDims(ob.type, ob.scale);
|
|
34
|
+
pts.push([ob.position[0] - d.width / 2, ob.position[1] - d.depth / 2], [ob.position[0] + d.width / 2, ob.position[1] + d.depth / 2]);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
24
37
|
const b = bounds(pts.length ? pts : [[0, 0], [1, 1]]);
|
|
25
38
|
const vx = b.min[0] - pad;
|
|
26
39
|
const vy = b.min[1] - pad;
|
|
@@ -67,90 +80,12 @@ function escapeXml(s) {
|
|
|
67
80
|
})[c]);
|
|
68
81
|
}
|
|
69
82
|
//#endregion
|
|
70
|
-
//#region src/
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
root.name = doc.name;
|
|
75
|
-
const matFor = (color, opts = {}) => new THREE.MeshStandardMaterial({
|
|
76
|
-
color: new THREE.Color(color),
|
|
77
|
-
roughness: .9,
|
|
78
|
-
...opts
|
|
79
|
-
});
|
|
80
|
-
const wallMat = matFor("#e8e6e1");
|
|
81
|
-
const slabMat = matFor("#9b9b97");
|
|
82
|
-
const doorMat = matFor("#6b4b2f", { roughness: .6 });
|
|
83
|
-
const glassMat = matFor("#bcd6e6", {
|
|
84
|
-
transparent: true,
|
|
85
|
-
opacity: .4,
|
|
86
|
-
roughness: .05
|
|
87
|
-
});
|
|
88
|
-
for (const floor of allFloors(doc)) {
|
|
89
|
-
if (!(floorIds === "all" ? floor.visible : floorIds.includes(floor.id))) continue;
|
|
90
|
-
const floorGroup = new THREE.Group();
|
|
91
|
-
floorGroup.name = floor.name;
|
|
92
|
-
const el = floor.elevation;
|
|
93
|
-
const openingsByWall = /* @__PURE__ */ new Map();
|
|
94
|
-
for (const o of floor.openings) {
|
|
95
|
-
const arr = openingsByWall.get(o.wallId) ?? [];
|
|
96
|
-
arr.push(o);
|
|
97
|
-
openingsByWall.set(o.wallId, arr);
|
|
98
|
-
}
|
|
99
|
-
for (const wall of floor.walls) {
|
|
100
|
-
const dir = wallDirection(wall);
|
|
101
|
-
const theta = Math.atan2(dir[1], dir[0]);
|
|
102
|
-
const opens = (openingsByWall.get(wall.id) ?? []).map((o) => ({
|
|
103
|
-
offset: o.offset,
|
|
104
|
-
width: o.width,
|
|
105
|
-
height: o.height,
|
|
106
|
-
sillHeight: o.sillHeight
|
|
107
|
-
}));
|
|
108
|
-
for (const s of wallBoxes(wall, opens, wall.height, wall.thickness / 2)) {
|
|
109
|
-
const along = (s.along0 + s.along1) / 2;
|
|
110
|
-
const px = wall.start[0] + dir[0] * along;
|
|
111
|
-
const py = wall.start[1] + dir[1] * along;
|
|
112
|
-
const geo = new THREE.BoxGeometry(Math.max(s.along1 - s.along0, .001), Math.max(s.z1 - s.z0, .001), wall.thickness);
|
|
113
|
-
const mesh = new THREE.Mesh(geo, wallMat);
|
|
114
|
-
mesh.position.set(px, el + (s.z0 + s.z1) / 2, py);
|
|
115
|
-
mesh.rotation.y = -theta;
|
|
116
|
-
floorGroup.add(mesh);
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
const wallById = new Map(floor.walls.map((w) => [w.id, w]));
|
|
120
|
-
for (const o of floor.openings) {
|
|
121
|
-
const wall = wallById.get(o.wallId);
|
|
122
|
-
if (!wall) continue;
|
|
123
|
-
const dir = wallDirection(wall);
|
|
124
|
-
const theta = Math.atan2(dir[1], dir[0]);
|
|
125
|
-
const px = wall.start[0] + dir[0] * o.offset;
|
|
126
|
-
const py = wall.start[1] + dir[1] * o.offset;
|
|
127
|
-
const depth = o.type === "window" ? .05 : wall.thickness * .6;
|
|
128
|
-
const geo = new THREE.BoxGeometry(Math.max(o.width - .04, .05), Math.max(o.height - .04, .05), depth);
|
|
129
|
-
const mesh = new THREE.Mesh(geo, o.type === "window" ? glassMat : doorMat);
|
|
130
|
-
mesh.position.set(px, el + o.sillHeight + o.height / 2, py);
|
|
131
|
-
mesh.rotation.y = -theta;
|
|
132
|
-
floorGroup.add(mesh);
|
|
133
|
-
}
|
|
134
|
-
if (floor.walls.length > 0) {
|
|
135
|
-
const b = bounds(floor.walls.flatMap((w) => [w.start, w.end]));
|
|
136
|
-
const geo = new THREE.BoxGeometry(b.width + .4, .14, b.height + .4);
|
|
137
|
-
const slab = new THREE.Mesh(geo, slabMat);
|
|
138
|
-
slab.position.set((b.min[0] + b.max[0]) / 2, el - .07, (b.min[1] + b.max[1]) / 2);
|
|
139
|
-
floorGroup.add(slab);
|
|
140
|
-
}
|
|
141
|
-
root.add(floorGroup);
|
|
142
|
-
}
|
|
143
|
-
return root;
|
|
144
|
-
}
|
|
145
|
-
/** Export the building as GLTF (JSON) or GLB (binary ArrayBuffer). */
|
|
146
|
-
function exportGLTF(doc, options = {}) {
|
|
147
|
-
const scene = buildExportScene(doc, options.floorIds ?? "all");
|
|
148
|
-
const exporter = new GLTFExporter();
|
|
149
|
-
return new Promise((resolve, reject) => {
|
|
150
|
-
exporter.parse(scene, (result) => resolve(result), (err) => reject(err), { binary: options.binary ?? true });
|
|
151
|
-
});
|
|
83
|
+
//#region src/index.ts
|
|
84
|
+
async function exportGLTF(doc, options = {}) {
|
|
85
|
+
const { exportGLTF: exportWithThree } = await import("./gltf.js");
|
|
86
|
+
return exportWithThree(doc, options);
|
|
152
87
|
}
|
|
153
88
|
//#endregion
|
|
154
|
-
export {
|
|
89
|
+
export { exportGLTF, exportJSON, exportSVG };
|
|
155
90
|
|
|
156
91
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../src/json.ts","../src/svg.ts","../src/gltf.ts"],"sourcesContent":["import { serialize, type BuildingDocument } from \"@react-arch/core\";\n\n/** Canonical lossless JSON export. */\nexport function exportJSON(doc: BuildingDocument): string {\n return serialize(doc);\n}\n","import { allFloors, type BuildingDocument } from \"@react-arch/core\";\nimport {\n bounds,\n openingSpan,\n polygonArea,\n polygonCentroid,\n wallPolygon,\n type Vec2,\n} from \"@react-arch/geometry\";\n\nexport interface SvgExportOptions {\n floorIds?: string[] | \"all\";\n showLabels?: boolean;\n showDimensions?: boolean;\n padding?: number;\n}\n\n/**\n * Export a scale-preserving SVG floor plan. Coordinates are in metres; the\n * viewBox maps 1 unit = 1 metre so the drawing is to scale.\n */\nexport function exportSVG(doc: BuildingDocument, options: SvgExportOptions = {}): string {\n const floorIds = options.floorIds ?? \"all\";\n const showLabels = options.showLabels ?? true;\n const showDimensions = options.showDimensions ?? true;\n const pad = options.padding ?? 1;\n\n const floors = allFloors(doc).filter((f) =>\n floorIds === \"all\" ? f.visible : floorIds.includes(f.id),\n );\n\n const pts: Vec2[] = [];\n for (const f of floors) for (const w of f.walls) pts.push(...wallPolygon(w));\n const b = bounds(pts.length ? pts : [[0, 0], [1, 1]]);\n const vx = b.min[0] - pad;\n const vy = b.min[1] - pad;\n const vw = b.width + pad * 2;\n const vh = b.height + pad * 2;\n\n const parts: string[] = [];\n parts.push(\n `<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"${vx} ${vy} ${vw} ${vh}\" width=\"${vw * 100}\" height=\"${vh * 100}\">`,\n );\n parts.push(`<rect x=\"${vx}\" y=\"${vy}\" width=\"${vw}\" height=\"${vh}\" fill=\"#ffffff\"/>`);\n parts.push(`<g stroke-linejoin=\"round\">`);\n\n for (const f of floors) {\n // Room fills + labels.\n for (const r of f.rooms) {\n const d = r.polygon.map((p, i) => `${i === 0 ? \"M\" : \"L\"}${p[0]} ${p[1]}`).join(\" \") + \" Z\";\n parts.push(`<path d=\"${d}\" fill=\"#eef2f7\" stroke=\"none\"/>`);\n if (showLabels) {\n const c = polygonCentroid(r.polygon);\n parts.push(`<text x=\"${c[0]}\" y=\"${c[1]}\" font-size=\"0.32\" text-anchor=\"middle\" fill=\"#1c2430\" font-family=\"sans-serif\" font-weight=\"600\">${escapeXml(r.name)}</text>`);\n if (showDimensions) {\n parts.push(`<text x=\"${c[0]}\" y=\"${c[1] + 0.4}\" font-size=\"0.24\" text-anchor=\"middle\" fill=\"#5a6573\" font-family=\"monospace\">${polygonArea(r.polygon).toFixed(1)} m²</text>`);\n }\n }\n }\n // Walls.\n for (const w of f.walls) {\n const d = wallPolygon(w).map((p, i) => `${i === 0 ? \"M\" : \"L\"}${p[0]} ${p[1]}`).join(\" \") + \" Z\";\n parts.push(`<path d=\"${d}\" fill=\"#2b2f36\" stroke=\"#000\" stroke-width=\"0.01\"/>`);\n }\n // Openings.\n const wallById = new Map(f.walls.map((w) => [w.id, w]));\n for (const o of f.openings) {\n const wall = wallById.get(o.wallId);\n if (!wall) continue;\n const span = openingSpan(wall, o);\n const color = o.type === \"door\" ? \"#c2451f\" : \"#2f6df6\";\n parts.push(`<line x1=\"${span.start[0]}\" y1=\"${span.start[1]}\" x2=\"${span.end[0]}\" y2=\"${span.end[1]}\" stroke=\"#ffffff\" stroke-width=\"0.16\"/>`);\n parts.push(`<line x1=\"${span.start[0]}\" y1=\"${span.start[1]}\" x2=\"${span.end[0]}\" y2=\"${span.end[1]}\" stroke=\"${color}\" stroke-width=\"0.04\"/>`);\n }\n }\n\n parts.push(`</g></svg>`);\n return parts.join(\"\\n\");\n}\n\nfunction escapeXml(s: string): string {\n return s.replace(/[<>&'\"]/g, (c) => ({ \"<\": \"<\", \">\": \">\", \"&\": \"&\", \"'\": \"'\", '\"': \""\" })[c]!);\n}\n","import * as THREE from \"three\";\nimport { GLTFExporter } from \"three/examples/jsm/exporters/GLTFExporter.js\";\nimport { allFloors, type BuildingDocument } from \"@react-arch/core\";\nimport { bounds, wallBoxes, wallDirection } from \"@react-arch/geometry\";\n\nexport interface GltfExportOptions {\n floorIds?: string[] | \"all\";\n binary?: boolean;\n}\n\n/** Build a Three.js scene mirroring the 3D renderer's geometry. */\nexport function buildExportScene(\n doc: BuildingDocument,\n floorIds: string[] | \"all\" = \"all\",\n): THREE.Group {\n const root = new THREE.Group();\n root.name = doc.name;\n\n const matFor = (color: string, opts: Partial<THREE.MeshStandardMaterialParameters> = {}) =>\n new THREE.MeshStandardMaterial({ color: new THREE.Color(color), roughness: 0.9, ...opts });\n\n const wallMat = matFor(\"#e8e6e1\");\n const slabMat = matFor(\"#9b9b97\");\n const doorMat = matFor(\"#6b4b2f\", { roughness: 0.6 });\n const glassMat = matFor(\"#bcd6e6\", { transparent: true, opacity: 0.4, roughness: 0.05 });\n\n for (const floor of allFloors(doc)) {\n const visible = floorIds === \"all\" ? floor.visible : floorIds.includes(floor.id);\n if (!visible) continue;\n const floorGroup = new THREE.Group();\n floorGroup.name = floor.name;\n const el = floor.elevation;\n\n const openingsByWall = new Map<string, typeof floor.openings>();\n for (const o of floor.openings) {\n const arr = openingsByWall.get(o.wallId) ?? [];\n arr.push(o);\n openingsByWall.set(o.wallId, arr);\n }\n\n for (const wall of floor.walls) {\n const dir = wallDirection(wall);\n const theta = Math.atan2(dir[1], dir[0]);\n const opens = (openingsByWall.get(wall.id) ?? []).map((o) => ({\n offset: o.offset, width: o.width, height: o.height, sillHeight: o.sillHeight,\n }));\n for (const s of wallBoxes(wall, opens, wall.height, wall.thickness / 2)) {\n const along = (s.along0 + s.along1) / 2;\n const px = wall.start[0] + dir[0] * along;\n const py = wall.start[1] + dir[1] * along;\n const geo = new THREE.BoxGeometry(Math.max(s.along1 - s.along0, 0.001), Math.max(s.z1 - s.z0, 0.001), wall.thickness);\n const mesh = new THREE.Mesh(geo, wallMat);\n mesh.position.set(px, el + (s.z0 + s.z1) / 2, py);\n mesh.rotation.y = -theta;\n floorGroup.add(mesh);\n }\n }\n\n const wallById = new Map(floor.walls.map((w) => [w.id, w]));\n for (const o of floor.openings) {\n const wall = wallById.get(o.wallId);\n if (!wall) continue;\n const dir = wallDirection(wall);\n const theta = Math.atan2(dir[1], dir[0]);\n const px = wall.start[0] + dir[0] * o.offset;\n const py = wall.start[1] + dir[1] * o.offset;\n const depth = o.type === \"window\" ? 0.05 : wall.thickness * 0.6;\n const geo = new THREE.BoxGeometry(Math.max(o.width - 0.04, 0.05), Math.max(o.height - 0.04, 0.05), depth);\n const mesh = new THREE.Mesh(geo, o.type === \"window\" ? glassMat : doorMat);\n mesh.position.set(px, el + o.sillHeight + o.height / 2, py);\n mesh.rotation.y = -theta;\n floorGroup.add(mesh);\n }\n\n if (floor.walls.length > 0) {\n const b = bounds(floor.walls.flatMap((w) => [w.start, w.end]));\n const geo = new THREE.BoxGeometry(b.width + 0.4, 0.14, b.height + 0.4);\n const slab = new THREE.Mesh(geo, slabMat);\n slab.position.set((b.min[0] + b.max[0]) / 2, el - 0.07, (b.min[1] + b.max[1]) / 2);\n floorGroup.add(slab);\n }\n\n root.add(floorGroup);\n }\n return root;\n}\n\n/** Export the building as GLTF (JSON) or GLB (binary ArrayBuffer). */\nexport function exportGLTF(\n doc: BuildingDocument,\n options: GltfExportOptions = {},\n): Promise<ArrayBuffer | object> {\n const scene = buildExportScene(doc, options.floorIds ?? \"all\");\n const exporter = new GLTFExporter();\n return new Promise((resolve, reject) => {\n exporter.parse(\n scene,\n (result) => resolve(result as ArrayBuffer | object),\n (err) => reject(err),\n { binary: options.binary ?? true },\n );\n });\n}\n"],"mappings":";;;;;;AAGA,SAAgB,WAAW,KAA+B;CACxD,OAAO,UAAU,GAAG;AACtB;;;;;;;ACgBA,SAAgB,UAAU,KAAuB,UAA4B,CAAC,GAAW;CACvF,MAAM,WAAW,QAAQ,YAAY;CACrC,MAAM,aAAa,QAAQ,cAAc;CACzC,MAAM,iBAAiB,QAAQ,kBAAkB;CACjD,MAAM,MAAM,QAAQ,WAAW;CAE/B,MAAM,SAAS,UAAU,GAAG,CAAC,CAAC,QAAQ,MACpC,aAAa,QAAQ,EAAE,UAAU,SAAS,SAAS,EAAE,EAAE,CACzD;CAEA,MAAM,MAAc,CAAC;CACrB,KAAK,MAAM,KAAK,QAAQ,KAAK,MAAM,KAAK,EAAE,OAAO,IAAI,KAAK,GAAG,YAAY,CAAC,CAAC;CAC3E,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,SAAgB,WACd,KACA,UAA6B,CAAC,GACC;CAC/B,MAAM,QAAQ,iBAAiB,KAAK,QAAQ,YAAY,KAAK;CAC7D,MAAM,WAAW,IAAI,aAAa;CAClC,OAAO,IAAI,SAAS,SAAS,WAAW;EACtC,SAAS,MACP,QACC,WAAW,QAAQ,MAA8B,IACjD,QAAQ,OAAO,GAAG,GACnB,EAAE,QAAQ,QAAQ,UAAU,KAAK,CACnC;CACF,CAAC;AACH"}
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/json.ts","../src/svg.ts","../src/index.ts"],"sourcesContent":["import { serialize, type BuildingDocument } from \"@react-arch/core\";\n\n/** Canonical lossless JSON export. */\nexport function exportJSON(doc: BuildingDocument): string {\n return serialize(doc);\n}\n","import { allFloors, furnitureDims, type BuildingDocument } from \"@react-arch/core\";\nimport {\n bounds,\n openingSpan,\n polygonArea,\n polygonCentroid,\n wallPolygon,\n type Vec2,\n} from \"@react-arch/geometry\";\n\nexport interface SvgExportOptions {\n floorIds?: string[] | \"all\";\n showLabels?: boolean;\n showDimensions?: boolean;\n padding?: number;\n}\n\n/**\n * Export a scale-preserving SVG floor plan. Coordinates are in metres; the\n * viewBox maps 1 unit = 1 metre so the drawing is to scale.\n */\nexport function exportSVG(doc: BuildingDocument, options: SvgExportOptions = {}): string {\n const floorIds = options.floorIds ?? \"all\";\n const showLabels = options.showLabels ?? true;\n const showDimensions = options.showDimensions ?? true;\n const pad = options.padding ?? 1;\n\n const floors = allFloors(doc).filter((f) =>\n floorIds === \"all\" ? f.visible : floorIds.includes(f.id),\n );\n\n const pts: Vec2[] = [];\n for (const f of floors) {\n const wallById = new Map(f.walls.map((w) => [w.id, w]));\n for (const w of f.walls) pts.push(...wallPolygon(w));\n for (const r of f.rooms) pts.push(...r.polygon);\n for (const o of f.openings) {\n const wall = wallById.get(o.wallId);\n if (wall) {\n const span = openingSpan(wall, o);\n pts.push(span.start, span.end);\n }\n }\n for (const ob of f.objects) {\n const d = furnitureDims(ob.type, ob.scale);\n pts.push(\n [ob.position[0] - d.width / 2, ob.position[1] - d.depth / 2],\n [ob.position[0] + d.width / 2, ob.position[1] + d.depth / 2],\n );\n }\n }\n const b = bounds(pts.length ? pts : [[0, 0], [1, 1]]);\n const vx = b.min[0] - pad;\n const vy = b.min[1] - pad;\n const vw = b.width + pad * 2;\n const vh = b.height + pad * 2;\n\n const parts: string[] = [];\n parts.push(\n `<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"${vx} ${vy} ${vw} ${vh}\" width=\"${vw * 100}\" height=\"${vh * 100}\">`,\n );\n parts.push(`<rect x=\"${vx}\" y=\"${vy}\" width=\"${vw}\" height=\"${vh}\" fill=\"#ffffff\"/>`);\n parts.push(`<g stroke-linejoin=\"round\">`);\n\n for (const f of floors) {\n // Room fills + labels.\n for (const r of f.rooms) {\n const d = r.polygon.map((p, i) => `${i === 0 ? \"M\" : \"L\"}${p[0]} ${p[1]}`).join(\" \") + \" Z\";\n parts.push(`<path d=\"${d}\" fill=\"#eef2f7\" stroke=\"none\"/>`);\n if (showLabels) {\n const c = polygonCentroid(r.polygon);\n parts.push(`<text x=\"${c[0]}\" y=\"${c[1]}\" font-size=\"0.32\" text-anchor=\"middle\" fill=\"#1c2430\" font-family=\"sans-serif\" font-weight=\"600\">${escapeXml(r.name)}</text>`);\n if (showDimensions) {\n parts.push(`<text x=\"${c[0]}\" y=\"${c[1] + 0.4}\" font-size=\"0.24\" text-anchor=\"middle\" fill=\"#5a6573\" font-family=\"monospace\">${polygonArea(r.polygon).toFixed(1)} m²</text>`);\n }\n }\n }\n // Walls.\n for (const w of f.walls) {\n const d = wallPolygon(w).map((p, i) => `${i === 0 ? \"M\" : \"L\"}${p[0]} ${p[1]}`).join(\" \") + \" Z\";\n parts.push(`<path d=\"${d}\" fill=\"#2b2f36\" stroke=\"#000\" stroke-width=\"0.01\"/>`);\n }\n // Openings.\n const wallById = new Map(f.walls.map((w) => [w.id, w]));\n for (const o of f.openings) {\n const wall = wallById.get(o.wallId);\n if (!wall) continue;\n const span = openingSpan(wall, o);\n const color = o.type === \"door\" ? \"#c2451f\" : \"#2f6df6\";\n parts.push(`<line x1=\"${span.start[0]}\" y1=\"${span.start[1]}\" x2=\"${span.end[0]}\" y2=\"${span.end[1]}\" stroke=\"#ffffff\" stroke-width=\"0.16\"/>`);\n parts.push(`<line x1=\"${span.start[0]}\" y1=\"${span.start[1]}\" x2=\"${span.end[0]}\" y2=\"${span.end[1]}\" stroke=\"${color}\" stroke-width=\"0.04\"/>`);\n }\n }\n\n parts.push(`</g></svg>`);\n return parts.join(\"\\n\");\n}\n\nfunction escapeXml(s: string): string {\n return s.replace(/[<>&'\"]/g, (c) => ({ \"<\": \"<\", \">\": \">\", \"&\": \"&\", \"'\": \"'\", '\"': \""\" })[c]!);\n}\n","/**\n * @react-arch/exporters\n *\n * Export the canonical model to other formats. JSON is the lossless canonical\n * format; SVG preserves the scaled 2D plan; GLTF/GLB carries the 3D geometry.\n */\nimport type { BuildingDocument } from \"@react-arch/core\";\n\nexport { exportJSON } from \"./json.js\";\nexport { exportSVG, type SvgExportOptions } from \"./svg.js\";\nexport type { GltfExportOptions } from \"./gltf.js\";\n\nexport async function exportGLTF(\n doc: BuildingDocument,\n options: import(\"./gltf.js\").GltfExportOptions = {},\n): Promise<ArrayBuffer | object> {\n const { exportGLTF: exportWithThree } = await import(\"./gltf.js\");\n return exportWithThree(doc, options);\n}\n"],"mappings":";;;;AAGA,SAAgB,WAAW,KAA+B;CACxD,OAAO,UAAU,GAAG;AACtB;;;;;;;ACgBA,SAAgB,UAAU,KAAuB,UAA4B,CAAC,GAAW;CACvF,MAAM,WAAW,QAAQ,YAAY;CACrC,MAAM,aAAa,QAAQ,cAAc;CACzC,MAAM,iBAAiB,QAAQ,kBAAkB;CACjD,MAAM,MAAM,QAAQ,WAAW;CAE/B,MAAM,SAAS,UAAU,GAAG,CAAC,CAAC,QAAQ,MACpC,aAAa,QAAQ,EAAE,UAAU,SAAS,SAAS,EAA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,MAAM,GAAG,QAAQ,KAAK,MAAM,GAAG,QAAQ,KAAK,IAAI,GAAG,QAAQ,KAAK,IAAI,GAAG,YAAY,MAAM,wBAAwB;EAChJ;CACF;CAEA,MAAM,KAAK,YAAY;CACvB,OAAO,MAAM,KAAK,IAAI;AACxB;AAEA,SAAS,UAAU,GAAmB;CACpC,OAAO,EAAE,QAAQ,aAAa,OAAO;EAAE,KAAK;EAAQ,KAAK;EAAQ,KAAK;EAAS,KAAK;EAAU,MAAK;CAAS,EAAA,CAAG,EAAG;AACpH;;;ACxFA,eAAsB,WACpB,KACA,UAAiD,CAAC,GACnB;CAC/B,MAAM,EAAE,YAAY,oBAAoB,MAAM,OAAO;CACrD,OAAO,gBAAgB,KAAK,OAAO;AACrC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-arch/exporters",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -9,12 +9,16 @@
|
|
|
9
9
|
".": {
|
|
10
10
|
"types": "./dist/index.d.ts",
|
|
11
11
|
"default": "./dist/index.js"
|
|
12
|
+
},
|
|
13
|
+
"./gltf": {
|
|
14
|
+
"types": "./dist/gltf.d.ts",
|
|
15
|
+
"default": "./dist/gltf.js"
|
|
12
16
|
}
|
|
13
17
|
},
|
|
14
18
|
"dependencies": {
|
|
15
|
-
"@react-arch/core": "0.1.
|
|
16
|
-
"@react-arch/
|
|
17
|
-
"@react-arch/
|
|
19
|
+
"@react-arch/core": "0.1.3",
|
|
20
|
+
"@react-arch/geometry": "0.1.3",
|
|
21
|
+
"@react-arch/shared": "0.1.3"
|
|
18
22
|
},
|
|
19
23
|
"peerDependencies": {
|
|
20
24
|
"three": ">=0.160"
|