@@ -9,6 +9,28 @@ import { GUI } from 'lil-gui';
9
9
10
10
function component ( ) {
11
11
12
+ const showSpinner = ( ) => {
13
+ const element = document . createElement ( 'div' ) ;
14
+ element . id = "spinner" ;
15
+ element . className = "lds-ellipsis" ;
16
+ element . innerHTML = `
17
+ <div></div>
18
+ <div></div>
19
+ <div></div>
20
+ ` ;
21
+
22
+ document . body . appendChild (
23
+ element
24
+ ) ;
25
+ }
26
+
27
+ const hideSpinner = ( ) => {
28
+ const el = document . getElementById ( 'spinner' ) ;
29
+ if ( el ) {
30
+ el . remove ( ) ;
31
+ }
32
+ }
33
+
12
34
let current : { group : Group | undefined , ground : Mesh | undefined , gui : GUI | undefined } = {
13
35
group : undefined ,
14
36
ground : undefined ,
@@ -24,8 +46,6 @@ function component() {
24
46
color : string ,
25
47
downloadSTL ?: ( ) => void ,
26
48
downloadStep ?: ( ) => void
27
- goHome ?: ( ) => void
28
- goBitbybit ?: ( ) => void
29
49
}
30
50
31
51
const model = {
@@ -75,13 +95,12 @@ function component() {
75
95
subdivideOptions . offsetFromBorderV = 0.01 ;
76
96
77
97
const withHoles = await bitbybit . occt . shapes . face . subdivideToRectangleHoles ( subdivideOptions ) ;
78
- const finalShape = await bitbybit . occt . operations . makeThickSolidSimple ( { shape : withHoles [ 0 ] , offset : 0.5 } ) ;
79
- // const box = await bitbybit.occt.shapes.solid.createBox({ width: 1, height: 10, length: 1, center: [0, 0, 0] });
98
+ finalShape = await bitbybit . occt . operations . makeThickSolidSimple ( { shape : withHoles [ 0 ] , offset : 0.5 } ) ;
80
99
81
100
shapesToClean = [ ...wires , loft , translated , ...faces , ...withHoles , finalShape ] ;
82
101
83
102
const options = new Inputs . Draw . DrawOcctShapeOptions ( ) ;
84
- options . precision = 0.05 ;
103
+ options . precision = 0.02 ;
85
104
options . drawEdges = model . drawEdges ;
86
105
options . drawFaces = model . drawFaces ;
87
106
options . drawVertices = false ;
@@ -101,15 +120,14 @@ function component() {
101
120
102
121
current . group = group ;
103
122
104
- finalShape ;
105
123
}
106
124
}
107
125
108
126
const downloadStep = async ( ) => {
109
127
if ( bitbybit && finalShape ) {
110
128
await bitbybit . occt . io . saveShapeSTEP ( {
111
129
shape : finalShape ,
112
- fileName : 'vase .stp' ,
130
+ fileName : 'shape .stp' ,
113
131
adjustYtoZ : true ,
114
132
tryDownload : true
115
133
} ) ;
@@ -134,23 +152,26 @@ function component() {
134
152
model . downloadStep = downloadStep ;
135
153
136
154
const updateShape = async ( ) => {
137
- toggleInputs ( ) ;
155
+ showSpinner ( ) ;
156
+ disableGUI ( ) ;
138
157
current . group ?. traverse ( ( obj ) => {
139
158
scene ?. remove ( obj ) ;
140
159
} ) ;
141
160
await createShape ( bitbybit , scene ) ;
142
- toggleInputs ( ) ;
161
+ enableGUI ( ) ;
162
+ hideSpinner ( ) ;
143
163
}
144
164
145
165
const init = async ( ) => {
166
+ showSpinner ( ) ;
146
167
bitbybit = new BitByBitBase ( ) ;
147
168
148
169
const domNode = document . getElementById ( 'three-canvas' ) as HTMLCanvasElement ;
149
170
const occt = new Worker ( new URL ( '../occ.worker' , import . meta. url ) , { name : 'OCC' , type : 'module' } ) ;
150
171
151
172
const camera = new PerspectiveCamera ( 70 , window . innerWidth / window . innerHeight , 0.01 , 1000 ) ;
152
173
scene = new Scene ( ) ;
153
- scene . fog = new Fog ( 0xffffff , 15 , 60 ) ;
174
+ scene . fog = new Fog ( 0x1a1c1f , 15 , 60 ) ;
154
175
const light = new HemisphereLight ( 0xffffff , 0x000000 , 10 ) ;
155
176
scene . add ( light ) ;
156
177
await bitbybit . init ( scene , occt , undefined ) ;
@@ -159,16 +180,15 @@ function component() {
159
180
camera . aspect = window . innerWidth / window . innerHeight ;
160
181
camera . updateProjectionMatrix ( ) ;
161
182
renderer . setSize ( window . innerWidth , window . innerHeight ) ;
162
- // renderer.setSize(domNode.clientWidth, domNode.clientHeight);
163
-
183
+ renderer . setPixelRatio ( window . devicePixelRatio / 1.5 )
164
184
const animation = ( time : number ) => {
165
185
renderer . render ( scene , camera ) ;
166
186
rotateGroup ( ) ;
167
187
controls . update ( ) ;
168
188
}
169
189
170
190
const controls = new OrbitControls ( camera , renderer . domElement ) ;
171
- camera . position . set ( 10 , 10 , 30 ) ;
191
+ camera . position . set ( 10 , 10 , 20 ) ;
172
192
173
193
controls . update ( ) ;
174
194
controls . target = new Vector3 ( 0 , 5 , 0 ) ;
@@ -186,7 +206,7 @@ function component() {
186
206
}
187
207
window . addEventListener ( "resize" , onWindowResize , false ) ;
188
208
189
- renderer . setClearColor ( new Color ( 0xffffff ) , 1 ) ;
209
+ renderer . setClearColor ( new Color ( 0x1a1c1f ) , 1 ) ;
190
210
191
211
bitbybit . occtWorkerManager . occWorkerState$ . subscribe ( async s => {
192
212
if ( s . state === OccStateEnum . initialised ) {
@@ -222,30 +242,28 @@ function component() {
222
242
scene . add ( ground ) ;
223
243
224
244
createGui ( ) ;
245
+ hideSpinner ( ) ;
225
246
}
226
247
} ) ;
227
248
}
228
249
229
- const toggleInputs = ( ) => {
230
- const allInputs = document . getElementsByTagName ( 'input' ) ;
231
- for ( let i = 0 ; i < allInputs . length ; i ++ ) {
232
- allInputs [ i ] . disabled = ! allInputs [ i ] . disabled ;
233
- }
250
+ const disableGUI = ( ) => {
251
+ const lilGui = document . getElementsByClassName ( 'lil-gui' ) [ 0 ] as HTMLElement ;
252
+ lilGui . style . pointerEvents = "none" ;
253
+ lilGui . style . opacity = "0.5" ;
254
+ }
255
+
256
+ const enableGUI = ( ) => {
257
+ const lilGui = document . getElementsByClassName ( 'lil-gui' ) [ 0 ] as HTMLElement ;
258
+ lilGui . style . pointerEvents = "all" ;
259
+ lilGui . style . opacity = "1" ;
234
260
}
235
261
236
262
const createGui = ( ) => {
237
263
238
264
const gui = new GUI ( ) ;
239
265
current . gui = gui ;
240
266
gui . $title . innerHTML = "Pattern" ;
241
- model . goHome = ( ) => {
242
- window . location . href = "/" ;
243
- gui . destroy ( ) ;
244
- } ;
245
- model . goBitbybit = ( ) => {
246
- window . location . href = "https://bitbybit.dev" ;
247
- gui . destroy ( ) ;
248
- } ;
249
267
250
268
gui
251
269
. add ( model , "uRec" , 4 , 32 , 4 )
@@ -301,12 +319,10 @@ function component() {
301
319
302
320
gui . add ( model , "downloadSTL" ) . name ( "Download STL" ) ;
303
321
gui . add ( model , "downloadStep" ) . name ( "Download STEP" ) ;
304
- gui . add ( model , "goHome" ) . name ( "Examples" ) ;
305
- gui . add ( model , "goBitbybit" ) . name ( "Bitbybit.dev" ) ;
306
322
}
307
323
308
324
init ( ) ;
309
-
325
+
310
326
}
311
327
312
328
component ( ) ;
0 commit comments