-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathBREP_Transforms.html
More file actions
103 lines (88 loc) · 3.3 KB
/
BREP_Transforms.html
File metadata and controls
103 lines (88 loc) · 3.3 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
<!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: Transforms</title>
<link rel="stylesheet" href="./example.css" />
</head>
<body>
<main>
<header class="example-header">
<div>
<h1>BREP Transforms</h1>
<p class="lead">Clones a solid, bakes TRS transforms, mirrors across a plane, then unions the result.</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_Transforms.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 describe = (label, solid) => {
write(
`${label.padEnd(16)} volume=${fmt(solid.volume())} area=${fmt(solid.surfaceArea())} triangles=${solid.getTriangleCount()}`,
);
};
const runExample = () => {
logEl.textContent = '';
setStatus('Running...', 'pending');
const base = new BREP.Cube({ x: 2.2, y: 1.4, z: 1.0, name: 'BaseCube' });
const moved = base.clone().bakeTRS({
position: [2.0, 0.4, 0.3],
rotationEuler: [0, 35, 20],
scale: [1.1, 0.85, 1.25],
});
const mirrored = moved.mirrorAcrossPlane([0, 0, 0], [1, 0, 0]);
const combined = moved.union(mirrored);
write('--- Transform Summary ---');
describe('base', base);
describe('moved', moved);
describe('mirrored', mirrored);
describe('combined', combined);
if (combined.volume() <= moved.volume()) {
throw new Error('Combined solid volume should be greater than a single moved solid.');
}
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>