Skip to content

Commit 7b20a6f

Browse files
nuxt example of a basic occt app without jscad for now
1 parent 834a013 commit 7b20a6f

File tree

13 files changed

+9759
-1
lines changed

13 files changed

+9759
-1
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
node_modules
22
.angular
33
.vscode
4-
dist
4+
dist
5+
nuxt/basic/pnpm-lock.yaml
6+
.nuxt
7+
.output

nuxt/basic/BitByBitComponent.vue

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
<script lang="ts" setup>
2+
import { ref } from 'vue'
3+
import { BitByBitBase } from '@bitbybit-dev/core';
4+
import { OccStateEnum } from '@bitbybit-dev/occt-worker';
5+
import { Scene, Engine, Color4, HemisphericLight, Vector3, ArcRotateCamera, Light } from '@babylonjs/core';
6+
7+
onMounted(async () => {
8+
const bitbybit = new BitByBitBase();
9+
const canvas = document.getElementById('renderCanvas') as HTMLCanvasElement;
10+
11+
const engine = new Engine(canvas);
12+
engine.setHardwareScalingLevel(0.5);
13+
const scene = new Scene(engine);
14+
scene.clearColor = new Color4(26 / 255, 28 / 255, 31 / 255, 1);
15+
const camera = new ArcRotateCamera('Camera', 1.3, 1.3, 20, new Vector3(0, 0, 0), scene);
16+
camera.attachControl(canvas, true);
17+
18+
const light = new HemisphericLight('HemiLight', new Vector3(0, 1, 0), scene);
19+
light.intensityMode = Light.INTENSITYMODE_ILLUMINANCE;
20+
light.intensity = 1;
21+
scene.metadata = { shadowGenerators: [] };
22+
23+
const occt = new Worker(new URL('./occ.worker', import.meta.url), { name: 'OCC', type: 'module' })
24+
25+
bitbybit.init(scene, occt);
26+
27+
engine.runRenderLoop(() => {
28+
scene.render();
29+
});
30+
31+
bitbybit.occtWorkerManager.occWorkerState$.subscribe(s => {
32+
33+
if (s.state === OccStateEnum.initialised) {
34+
engine.resize();
35+
36+
const start = async()=>{
37+
const sphere = await bitbybit.occt.shapes.solid.createSphere({
38+
radius: 5,
39+
center: [0,0,0]
40+
});
41+
42+
const circle = await bitbybit.occt.shapes.wire.createCircleWire({
43+
radius: 10,
44+
center: [0,0,0],
45+
direction: [0,1,0],
46+
});
47+
48+
const points = await bitbybit.occt.shapes.wire.pointsOnWireAtPatternOfLengths({
49+
shape: circle,
50+
lengths: [0.1,0.3,0.4],
51+
includeFirst: true,
52+
includeLast: false,
53+
tryNext: false
54+
})
55+
56+
bitbybit.draw.drawAnyAsync({
57+
entity: sphere
58+
});
59+
60+
bitbybit.draw.drawAnyAsync({
61+
entity: circle
62+
});
63+
64+
bitbybit.draw.drawAnyAsync({
65+
entity: points
66+
});
67+
}
68+
69+
start();
70+
engine.runRenderLoop(() => {
71+
scene.render();
72+
});
73+
} else if (s.state === OccStateEnum.computing) {
74+
// Show Spinner
75+
} else if (s.state === OccStateEnum.loaded) {
76+
// Show Spinner
77+
}
78+
});
79+
})
80+
81+
</script>
82+
83+
<template>
84+
<canvas id="renderCanvas"></canvas>
85+
</template>
86+
87+
<style>
88+
#renderCanvas {
89+
width: 100%;
90+
height: 100%;
91+
border: none;
92+
}
93+
</style>

nuxt/basic/README.md

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# Nuxt 3 Minimal Starter
2+
3+
Look at the [Nuxt 3 documentation](https://nuxt.com/docs/getting-started/introduction) to learn more.
4+
5+
## Setup
6+
7+
Make sure to install the dependencies:
8+
9+
```bash
10+
# npm
11+
npm install
12+
13+
# pnpm
14+
pnpm install
15+
16+
# yarn
17+
yarn install
18+
19+
# bun
20+
bun install
21+
```
22+
23+
## Development Server
24+
25+
Start the development server on `http://localhost:3000`:
26+
27+
```bash
28+
# npm
29+
npm run dev
30+
31+
# pnpm
32+
pnpm run dev
33+
34+
# yarn
35+
yarn dev
36+
37+
# bun
38+
bun run dev
39+
```
40+
41+
## Production
42+
43+
Build the application for production:
44+
45+
```bash
46+
# npm
47+
npm run build
48+
49+
# pnpm
50+
pnpm run build
51+
52+
# yarn
53+
yarn build
54+
55+
# bun
56+
bun run build
57+
```
58+
59+
Locally preview production build:
60+
61+
```bash
62+
# npm
63+
npm run preview
64+
65+
# pnpm
66+
pnpm run preview
67+
68+
# yarn
69+
yarn preview
70+
71+
# bun
72+
bun run preview
73+
```
74+
75+
Check out the [deployment documentation](https://nuxt.com/docs/getting-started/deployment) for more information.

nuxt/basic/app.vue

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<script setup>
2+
import BitByBitComponent from "./BitByBitComponent.vue"
3+
</script>
4+
<template>
5+
<div>
6+
<ClientOnly fallback-tag="span" fallback="Loading bitbybit...">
7+
<BitByBitComponent />
8+
</ClientOnly>
9+
</div>
10+
</template>
11+

nuxt/basic/bitbybit-nuxt.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import ocFullJS from "@bitbybit-dev/occt/bitbybit-dev-occt/bitbybit-dev-occt.js";
2+
import ocFullWasm from "@bitbybit-dev/occt/bitbybit-dev-occt/bitbybit-dev-occt.wasm?url";
3+
4+
const initOpenCascade = ({
5+
mainJS = ocFullJS,
6+
mainWasm = ocFullWasm,
7+
worker = undefined,
8+
libs = [],
9+
module = {},
10+
} = {}) => {
11+
return new Promise((resolve, reject) => {
12+
new mainJS({
13+
locateFile(path) {
14+
if (path.endsWith('.wasm')) {
15+
return mainWasm;
16+
}
17+
if (path.endsWith('.worker.js') && !!worker) {
18+
return worker;
19+
}
20+
return path;
21+
},
22+
...module
23+
}).then(async oc => {
24+
for (let lib of libs) {
25+
await oc.loadDynamicLibrary(lib, { loadAsync: true, global: true, nodelete: true, allowUndefined: false });
26+
}
27+
resolve(oc);
28+
});
29+
});
30+
};
31+
32+
export default initOpenCascade;

nuxt/basic/nuxt.config.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// https://nuxt.com/docs/api/configuration/nuxt-config
2+
export default defineNuxtConfig({
3+
compatibilityDate: '2024-04-03',
4+
devtools: { enabled: true },
5+
ssr: false,
6+
modules: ['@pinia/nuxt'],
7+
})

nuxt/basic/occ.worker.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/// <reference lib="webworker" />
2+
/*eslint no-restricted-globals: 0*/
3+
import initOpenCascade from './bitbybit-nuxt.js';
4+
import type { OpenCascadeInstance } from '@bitbybit-dev/occt/bitbybit-dev-occt/bitbybit-dev-occt.js';
5+
import { initializationComplete, onMessageInput } from '@bitbybit-dev/occt-worker';
6+
7+
initOpenCascade().then((occ: OpenCascadeInstance) => {
8+
initializationComplete(occ, undefined);
9+
});
10+
11+
addEventListener('message', ({ data }) => {
12+
console.log(data)
13+
onMessageInput(data, postMessage);
14+
});

0 commit comments

Comments
 (0)