-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathBREP_Primitives.html
More file actions
100 lines (86 loc) · 3.43 KB
/
BREP_Primitives.html
File metadata and controls
100 lines (86 loc) · 3.43 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
<!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: Primitives</title>
<link rel="stylesheet" href="./example.css" />
</head>
<body>
<main>
<header class="example-header">
<div>
<h1>BREP Primitives</h1>
<p class="lead">Creates a set of primitive solids and reports volume, area, and triangle count.</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_Primitives.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 fmt = (num) => Number(num).toFixed(6);
const write = (...parts) => {
const line = parts.map((part) => (typeof part === 'string' ? part : JSON.stringify(part))).join(' ');
logEl.textContent += `${line}\n`;
console.log(...parts);
};
const summarize = (solid) => ({
volume: solid.volume(),
area: solid.surfaceArea(),
triangles: solid.getTriangleCount(),
});
const runExample = () => {
logEl.textContent = '';
setStatus('Running...', 'pending');
const primitives = [
['Cube', () => new BREP.Cube({ x: 2, y: 3, z: 4, name: 'Cube' })],
['Sphere', () => new BREP.Sphere({ r: 1.2, resolution: 32, name: 'Sphere' })],
['Cylinder', () => new BREP.Cylinder({ radius: 1, height: 2.4, resolution: 48, name: 'Cylinder' })],
['Cone', () => new BREP.Cone({ radius: 1.1, height: 2.1, resolution: 48, name: 'Cone' })],
['Torus', () => new BREP.Torus({ mR: 2, tR: 0.55, resolution: 64, name: 'Torus' })],
['Pyramid', () => new BREP.Pyramid({ bL: 2, s: 4, h: 2.7, name: 'Pyramid' })],
];
write('--- Primitive Summary ---');
for (const [name, createSolid] of primitives) {
const solid = createSolid();
const stats = summarize(solid);
write(`${name.padEnd(10)} volume=${fmt(stats.volume)} area=${fmt(stats.area)} triangles=${stats.triangles}`);
}
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>