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 >
0 commit comments