@react-arch/exporters 0.1.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/LICENSE +21 -0
- package/dist/index.d.ts +32 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +156 -0
- package/dist/index.js.map +1 -0
- package/package.json +51 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 React Arch
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { BuildingDocument } from "@react-arch/core";
|
|
2
|
+
import * as THREE from "three";
|
|
3
|
+
|
|
4
|
+
//#region src/json.d.ts
|
|
5
|
+
/** Canonical lossless JSON export. */
|
|
6
|
+
declare function exportJSON(doc: BuildingDocument): string;
|
|
7
|
+
//#endregion
|
|
8
|
+
//#region src/svg.d.ts
|
|
9
|
+
interface SvgExportOptions {
|
|
10
|
+
floorIds?: string[] | "all";
|
|
11
|
+
showLabels?: boolean;
|
|
12
|
+
showDimensions?: boolean;
|
|
13
|
+
padding?: number;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Export a scale-preserving SVG floor plan. Coordinates are in metres; the
|
|
17
|
+
* viewBox maps 1 unit = 1 metre so the drawing is to scale.
|
|
18
|
+
*/
|
|
19
|
+
declare function exportSVG(doc: BuildingDocument, options?: SvgExportOptions): string;
|
|
20
|
+
//#endregion
|
|
21
|
+
//#region src/gltf.d.ts
|
|
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). */
|
|
29
|
+
declare function exportGLTF(doc: BuildingDocument, options?: GltfExportOptions): Promise<ArrayBuffer | object>;
|
|
30
|
+
//#endregion
|
|
31
|
+
export { type GltfExportOptions, type SvgExportOptions, buildExportScene, exportGLTF, exportJSON, exportSVG };
|
|
32
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/json.ts","../src/svg.ts","../src/gltf.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;;;UChB9D,iBAAA;EACf,QAAA;EACA,MAAM;AAAA;;iBAIQ,gBAAA,CACd,GAAA,EAAK,gBAAA,EACL,QAAA,sBACC,KAAA,CAAM,KAAK;AFXkC;AAAA,iBEqFhC,UAAA,CACd,GAAA,EAAK,gBAAA,EACL,OAAA,GAAS,iBAAA,GACR,OAAA,CAAQ,WAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { allFloors, serialize } from "@react-arch/core";
|
|
2
|
+
import { bounds, openingSpan, polygonArea, polygonCentroid, wallBoxes, wallDirection, wallPolygon } from "@react-arch/geometry";
|
|
3
|
+
import * as THREE from "three";
|
|
4
|
+
import { GLTFExporter } from "three/examples/jsm/exporters/GLTFExporter.js";
|
|
5
|
+
//#region src/json.ts
|
|
6
|
+
/** Canonical lossless JSON export. */
|
|
7
|
+
function exportJSON(doc) {
|
|
8
|
+
return serialize(doc);
|
|
9
|
+
}
|
|
10
|
+
//#endregion
|
|
11
|
+
//#region src/svg.ts
|
|
12
|
+
/**
|
|
13
|
+
* Export a scale-preserving SVG floor plan. Coordinates are in metres; the
|
|
14
|
+
* viewBox maps 1 unit = 1 metre so the drawing is to scale.
|
|
15
|
+
*/
|
|
16
|
+
function exportSVG(doc, options = {}) {
|
|
17
|
+
const floorIds = options.floorIds ?? "all";
|
|
18
|
+
const showLabels = options.showLabels ?? true;
|
|
19
|
+
const showDimensions = options.showDimensions ?? true;
|
|
20
|
+
const pad = options.padding ?? 1;
|
|
21
|
+
const floors = allFloors(doc).filter((f) => floorIds === "all" ? f.visible : floorIds.includes(f.id));
|
|
22
|
+
const pts = [];
|
|
23
|
+
for (const f of floors) for (const w of f.walls) pts.push(...wallPolygon(w));
|
|
24
|
+
const b = bounds(pts.length ? pts : [[0, 0], [1, 1]]);
|
|
25
|
+
const vx = b.min[0] - pad;
|
|
26
|
+
const vy = b.min[1] - pad;
|
|
27
|
+
const vw = b.width + pad * 2;
|
|
28
|
+
const vh = b.height + pad * 2;
|
|
29
|
+
const parts = [];
|
|
30
|
+
parts.push(`<svg xmlns="http://www.w3.org/2000/svg" viewBox="${vx} ${vy} ${vw} ${vh}" width="${vw * 100}" height="${vh * 100}">`);
|
|
31
|
+
parts.push(`<rect x="${vx}" y="${vy}" width="${vw}" height="${vh}" fill="#ffffff"/>`);
|
|
32
|
+
parts.push(`<g stroke-linejoin="round">`);
|
|
33
|
+
for (const f of floors) {
|
|
34
|
+
for (const r of f.rooms) {
|
|
35
|
+
const d = r.polygon.map((p, i) => `${i === 0 ? "M" : "L"}${p[0]} ${p[1]}`).join(" ") + " Z";
|
|
36
|
+
parts.push(`<path d="${d}" fill="#eef2f7" stroke="none"/>`);
|
|
37
|
+
if (showLabels) {
|
|
38
|
+
const c = polygonCentroid(r.polygon);
|
|
39
|
+
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>`);
|
|
40
|
+
if (showDimensions) parts.push(`<text x="${c[0]}" y="${c[1] + .4}" font-size="0.24" text-anchor="middle" fill="#5a6573" font-family="monospace">${polygonArea(r.polygon).toFixed(1)} m²</text>`);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
for (const w of f.walls) {
|
|
44
|
+
const d = wallPolygon(w).map((p, i) => `${i === 0 ? "M" : "L"}${p[0]} ${p[1]}`).join(" ") + " Z";
|
|
45
|
+
parts.push(`<path d="${d}" fill="#2b2f36" stroke="#000" stroke-width="0.01"/>`);
|
|
46
|
+
}
|
|
47
|
+
const wallById = new Map(f.walls.map((w) => [w.id, w]));
|
|
48
|
+
for (const o of f.openings) {
|
|
49
|
+
const wall = wallById.get(o.wallId);
|
|
50
|
+
if (!wall) continue;
|
|
51
|
+
const span = openingSpan(wall, o);
|
|
52
|
+
const color = o.type === "door" ? "#c2451f" : "#2f6df6";
|
|
53
|
+
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"/>`);
|
|
54
|
+
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"/>`);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
parts.push(`</g></svg>`);
|
|
58
|
+
return parts.join("\n");
|
|
59
|
+
}
|
|
60
|
+
function escapeXml(s) {
|
|
61
|
+
return s.replace(/[<>&'"]/g, (c) => ({
|
|
62
|
+
"<": "<",
|
|
63
|
+
">": ">",
|
|
64
|
+
"&": "&",
|
|
65
|
+
"'": "'",
|
|
66
|
+
"\"": """
|
|
67
|
+
})[c]);
|
|
68
|
+
}
|
|
69
|
+
//#endregion
|
|
70
|
+
//#region src/gltf.ts
|
|
71
|
+
/** Build a Three.js scene mirroring the 3D renderer's geometry. */
|
|
72
|
+
function buildExportScene(doc, floorIds = "all") {
|
|
73
|
+
const root = new THREE.Group();
|
|
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
|
+
});
|
|
152
|
+
}
|
|
153
|
+
//#endregion
|
|
154
|
+
export { buildExportScene, exportGLTF, exportJSON, exportSVG };
|
|
155
|
+
|
|
156
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +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,MAAM,IAAI,OAAO,IAAI,SAAS,MAAM,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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/package.json
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@react-arch/exporters",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"module": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"default": "./dist/index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"dependencies": {
|
|
15
|
+
"@react-arch/core": "0.1.0",
|
|
16
|
+
"@react-arch/shared": "0.1.0",
|
|
17
|
+
"@react-arch/geometry": "0.1.0"
|
|
18
|
+
},
|
|
19
|
+
"peerDependencies": {
|
|
20
|
+
"three": ">=0.160"
|
|
21
|
+
},
|
|
22
|
+
"peerDependenciesMeta": {
|
|
23
|
+
"three": {
|
|
24
|
+
"optional": true
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"@types/three": "^0.169.0",
|
|
29
|
+
"three": "^0.169.0",
|
|
30
|
+
"typescript": "^5.7.2",
|
|
31
|
+
"vitest": "^2.1.8"
|
|
32
|
+
},
|
|
33
|
+
"files": [
|
|
34
|
+
"dist"
|
|
35
|
+
],
|
|
36
|
+
"publishConfig": {
|
|
37
|
+
"access": "public"
|
|
38
|
+
},
|
|
39
|
+
"repository": {
|
|
40
|
+
"type": "git",
|
|
41
|
+
"url": "https://github.com/react-arch/react-arch.git",
|
|
42
|
+
"directory": "packages/exporters"
|
|
43
|
+
},
|
|
44
|
+
"license": "MIT",
|
|
45
|
+
"scripts": {
|
|
46
|
+
"typecheck": "tsc --noEmit",
|
|
47
|
+
"test": "vitest run --passWithNoTests",
|
|
48
|
+
"lint": "oxlint src",
|
|
49
|
+
"build": "tsdown"
|
|
50
|
+
}
|
|
51
|
+
}
|