@@ -22,8 +22,10 @@ Component({
22
22
heightScale : 1 , // canvas高度缩放值
23
23
renderByXRFrame : false , // 是否使用 xr-frame渲染
24
24
renderByWebGL2 : true , // 是否使用WebGL2渲染
25
- workerOn : true ,
26
- maxGaussians : 50000 ,
25
+ workerOn : false ,
26
+ wasmOn : true ,
27
+ splatInited : false ,
28
+ maxGaussians : 200000 ,
27
29
} ,
28
30
lifetimes : {
29
31
/**
@@ -242,13 +244,19 @@ Component({
242
244
// console.log('创建 worker 共享内存', this.sabPositions, this.sabOpacities, this.sabCov3Da, this.sabCov3Db, this.sabcolors)
243
245
244
246
// 初始化 worker 相关
245
- this . initWorker ( info , {
246
- // sabPositions: this.sabPositions,
247
- // sabOpacities: this.sabOpacities,
248
- // sabCov3Da: this.sabCov3Da,
249
- // sabCov3Db: this.sabCov3Db,
250
- // sabcolors: this.sabcolors,
251
- } ) ;
247
+ if ( this . data . workerOn ) {
248
+ this . initWorker ( info , {
249
+ // sabPositions: this.sabPositions,
250
+ // sabOpacities: this.sabOpacities,
251
+ // sabCov3Da: this.sabCov3Da,
252
+ // sabCov3Db: this.sabCov3Db,
253
+ // sabcolors: this.sabcolors,
254
+ } ) ;
255
+ }
256
+
257
+ if ( this . data . wasmOn ) {
258
+ this . initWASM ( info ) ;
259
+ }
252
260
253
261
} else {
254
262
wx . hideLoading ( ) ;
@@ -280,19 +288,18 @@ Component({
280
288
// worker 初始化 回调
281
289
console . log ( '[Worker callback] gaussianSplatting init callBack' , res )
282
290
283
- this . camera . isWorkerInit = true ;
284
- this . camera . updateByVK ( ) ;
291
+ this . camera . worker = this . worker ;
285
292
293
+ this . camera . updateByVK ( ) ;
286
294
287
295
} else if ( res . type === 'execFunc_sort' ) {
288
296
// worker 排序 回调
289
297
// console.log(res)
290
298
291
- this . camera . isWorkerSorting = false ;
299
+ this . camera . isSorting = false ;
292
300
293
301
const data = res . result . data
294
302
295
- const start = new Date ( ) . getTime ( )
296
303
297
304
const gl = this . gl
298
305
@@ -313,7 +320,6 @@ Component({
313
320
const cov3Db = new Float32Array ( data . cov3Db ) ;
314
321
const colors = new Float32Array ( data . colors ) ;
315
322
316
-
317
323
updateBuffer ( this . splat . buffers . center , positions )
318
324
updateBuffer ( this . splat . buffers . opacity , opacities )
319
325
updateBuffer ( this . splat . buffers . covA , cov3Da )
@@ -323,10 +329,6 @@ Component({
323
329
// 设定绘制的高斯球数量
324
330
this . gaussiansCount = data . gaussiansCount ;
325
331
326
- const end = new Date ( ) . getTime ( )
327
- // const sortTime = `${((end - start)/1000).toFixed(3)}s`
328
- // console.log(`updateBuffer ${sortTime}`)
329
-
330
332
// this.canvas.requestAnimationFrame(this.requestRender.bind(this));
331
333
332
334
// console.log('execFunc_sort end')
@@ -339,6 +341,69 @@ Component({
339
341
params : [ plyInfo , config ]
340
342
} )
341
343
} ,
344
+ async initWASM ( plyInfo ) {
345
+ // 初始化 WASM
346
+ this . wasm = await init ( "packageAPI/pages/ar/gaussian-splatting/wasm/out/gs_sort_bg.wasm" ) ;
347
+ // 共享内存
348
+ const memory = this . wasm . memory ;
349
+
350
+ console . log ( 'wasm' , this . wasm )
351
+
352
+ const gaussianCount = plyInfo . count
353
+
354
+ console . log ( 'gaussianCount' , gaussianCount )
355
+
356
+ const position_src = plyInfo . positions
357
+ const color_src = plyInfo . colors
358
+ const opacity_src = plyInfo . opacities
359
+ const cov_src = plyInfo . cov3Ds
360
+
361
+ const gaussian = Gaussian . new ( gaussianCount , position_src , color_src , opacity_src , cov_src )
362
+ this . gaussianWASM = gaussian ;
363
+
364
+ console . log ( 'gaussian' , gaussian )
365
+
366
+ this . vpmWASM = new Float32Array ( memory . buffer , gaussian . vpm_ptr , 16 )
367
+ this . positionWASM = new Float32Array ( memory . buffer , gaussian . positions_ptr , gaussianCount * 3 )
368
+ this . colorWASM = new Float32Array ( memory . buffer , gaussian . colors_ptr , gaussianCount * 3 )
369
+ this . opacitiesWASM = new Float32Array ( memory . buffer , gaussian . opacities_ptr , gaussianCount )
370
+ this . cov3DaWASM = new Float32Array ( memory . buffer , gaussian . cov_a_ptr , gaussianCount * 3 )
371
+ this . cov3DbWASM = new Float32Array ( memory . buffer , gaussian . cov_b_ptr , gaussianCount * 3 )
372
+
373
+ this . camera . wasm = this . wasm
374
+ this . camera . gaussian = this . gaussianWASM
375
+ this . camera . vpmWASM = this . vpmWASM
376
+
377
+ // 绑定更新回调
378
+ this . camera . wasmUpdateCallback = ( ) => {
379
+
380
+ // console.log('wasm vpm', this.vpmWASM);
381
+ // console.log('wasm positionF32', this.positionWASM )
382
+ // console.log('wasm opacitiesF32', this.opacitiesWASM )
383
+ // console.log('wasm colorF32', this.colorWASM )
384
+ // console.log('wasm cov3DaF32', this.cov3DaWASM )
385
+ // console.log('wasm cov3DbF32', this.cov3DbWASM )
386
+
387
+ const gl = this . gl
388
+
389
+ const updateBuffer = ( buffer , data ) => {
390
+ gl . bindBuffer ( gl . ARRAY_BUFFER , buffer )
391
+ gl . bufferData ( gl . ARRAY_BUFFER , data , gl . DYNAMIC_DRAW )
392
+ }
393
+
394
+ updateBuffer ( this . splat . buffers . center , this . positionWASM )
395
+ updateBuffer ( this . splat . buffers . color , this . colorWASM )
396
+ updateBuffer ( this . splat . buffers . opacity , this . opacitiesWASM )
397
+ updateBuffer ( this . splat . buffers . covA , this . cov3DaWASM )
398
+ updateBuffer ( this . splat . buffers . covB , this . cov3DbWASM )
399
+
400
+ this . gaussiansCount = this . renderCount ;
401
+
402
+ }
403
+
404
+ this . camera . updateByVK ( ) ;
405
+
406
+ } ,
342
407
// 后续为 webGL2 相关,为了方便开发,先放在一起
343
408
initWebGL2 ( ) {
344
409
console . log ( '== InitWebGL2 start ==' )
@@ -350,9 +415,10 @@ Component({
350
415
up : [ 0 , 1.0 , 0.0 ] ,
351
416
target : [ 0 , 0 , 0 ] ,
352
417
camera : [ Math . PI / 2 , Math . PI / 2 , 10 ] , // theta phi radius
418
+ workerOn : this . data . workerOn ,
419
+ wasmOn : this . data . wasmOn ,
353
420
}
354
- this . camera = new CameraWebGL ( gl , this . worker , cameraParameters )
355
-
421
+ this . camera = new CameraWebGL ( gl , cameraParameters )
356
422
// Setup Instance Mesh
357
423
this . cubeInstance = new CubeInstanceWebGL ( gl )
358
424
@@ -730,6 +796,10 @@ Component({
730
796
731
797
// 开始处理 ply 资源
732
798
this . initPLY ( id ) ;
799
+
800
+ this . setData ( {
801
+ splatInited : true
802
+ } )
733
803
}
734
804
} ,
735
805
changeMaxGaussianCount ( e ) {
@@ -741,10 +811,12 @@ Component({
741
811
} ,
742
812
switchWorker ( e ) {
743
813
this . setData ( {
744
- workerOn : e . detail . value
814
+ workerOn : e . detail . value ,
815
+ wasmOn : ! e . detail . value
745
816
} )
746
817
747
818
this . camera . setWorkerOn ( this . data . workerOn ) ;
819
+ this . camera . setWasmOn ( this . data . wasmOn )
748
820
749
821
console . log ( 'switch WorkerOn:' , this . data . workerOn ) ;
750
822
}
0 commit comments