-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathBREP_Export.html
More file actions
108 lines (92 loc) · 3.63 KB
/
BREP_Export.html
File metadata and controls
108 lines (92 loc) · 3.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
<title>BREP API Example: Export</title>
<link rel="stylesheet" href="./example.css" />
</head>
<body>
<main>
<header class="example-header">
<div>
<h1>BREP Export</h1>
<p class="lead">Builds a composed solid and exports ASCII STL + STEP strings.</p>
</div>
<nav class="example-nav">
<a href="./index.html">All Examples</a>
<a href="../index.html">BREP CAD App</a>
<a href="https://github.com/mmiscool/BREP/blob/master/apiExamples/BREP_Export.html" target="_blank" rel="noopener noreferrer">Source on GitHub</a>
</nav>
</header>
<div class="row">
<button id="btn-run">Run Example</button>
<span id="status" class="status pending">Ready</span>
</div>
<pre id="log">(Click "Run Example")</pre>
</main>
<script type="module">
import { BREP } from '../dist-kernel/brep-kernel.js';
const statusEl = document.getElementById('status');
const logEl = document.getElementById('log');
const btnRun = document.getElementById('btn-run');
const setStatus = (text, cls) => {
statusEl.textContent = text;
statusEl.className = `status ${cls}`;
};
const write = (...parts) => {
const line = parts.map((part) => (typeof part === 'string' ? part : JSON.stringify(part))).join(' ');
logEl.textContent += `${line}\n`;
console.log(...parts);
};
const firstLines = (text, count = 8) => text.split('\n').slice(0, count).join('\n');
const runExample = () => {
logEl.textContent = '';
setStatus('Running...', 'pending');
const shaft = new BREP.Cylinder({ radius: 1, height: 3, resolution: 48, name: 'Shaft' })
.bakeTRS({ position: [0, 0, 0.6], rotationEuler: [90, 0, 0], scale: [1, 1, 1] });
const head = new BREP.Cone({ radius: 1.55, height: 1.6, resolution: 48, name: 'Head' })
.bakeTRS({ position: [0, 1.65, 0.6], rotationEuler: [-90, 0, 0], scale: [1, 1, 1] });
const body = shaft.union(head);
const stl = body.toSTL('api_example_part', 4);
const step = body.toSTEP('api_example_part', { precision: 4 });
write('--- Export Summary ---');
write('Volume:', body.volume());
write('Surface area:', body.surfaceArea());
write('Triangles:', body.getTriangleCount());
write('STL characters:', stl.length);
write('STEP characters:', step.length);
write('');
write('--- STL Preview ---');
write(firstLines(stl));
write('');
write('--- STEP Preview ---');
write(firstLines(step));
if (!stl.startsWith('solid')) {
throw new Error('STL output did not start with "solid".');
}
if (!step.includes('ISO-10303-21')) {
throw new Error('STEP output did not contain expected ISO header.');
}
setStatus('Completed', 'ok');
};
btnRun.addEventListener('click', () => {
try {
runExample();
} catch (error) {
console.error(error);
write('ERROR:', error?.stack || error?.message || String(error));
setStatus('Failed', 'err');
}
});
try {
runExample();
} catch (error) {
console.error(error);
write('ERROR:', error?.stack || error?.message || String(error));
setStatus('Failed', 'err');
}
</script>
</body>
</html>