@@ -15,7 +15,7 @@ Component({
15
15
renderByXRFrame : false , // 是否使用 xr-frame渲染
16
16
renderByWebGL2 : true , // 是否使用WebGL2渲染
17
17
workerOn : true ,
18
- maxGaussians : 600000 ,
18
+ maxGaussians : 800000 ,
19
19
} ,
20
20
lifetimes : {
21
21
/**
@@ -83,7 +83,7 @@ Component({
83
83
console . log ( '== PLY Init start ==' )
84
84
85
85
const host = 'https://mmbizwxaminiprogram-1258344707.cos.ap-guangzhou.myqcloud.com/xr-frame/demo' ;
86
- // const host = 'http://10.9.169.120 :8030'
86
+ // const host = 'http://10.9.169.125 :8030'
87
87
88
88
let type ;
89
89
@@ -167,9 +167,9 @@ Component({
167
167
case 'sakura' :
168
168
this . camera . updateCameraInfo (
169
169
// target
170
- [ 1.6 , 0.5 , 1 ] ,
170
+ [ 1.6 , 0 , 1 ] ,
171
171
// theta
172
- Math . PI / 4 ,
172
+ Math . PI * 3 / 11 ,
173
173
// phi
174
174
Math . PI * 3 / 5 ,
175
175
// raidus
@@ -242,9 +242,25 @@ Component({
242
242
break ;
243
243
}
244
244
245
+ // 提供渲染的高斯球数
246
+ const renderCount = this . renderCount = info . count ;
247
+
248
+ // 全部用 f32 存储
249
+ this . sabPositions = wx . createSharedArrayBuffer ( renderCount * 4 * 3 )
250
+ this . sabOpacities = wx . createSharedArrayBuffer ( renderCount * 4 )
251
+ this . sabCov3Da = wx . createSharedArrayBuffer ( renderCount * 4 * 3 )
252
+ this . sabCov3Db = wx . createSharedArrayBuffer ( renderCount * 4 * 3 )
253
+ this . sabcolors = wx . createSharedArrayBuffer ( renderCount * 4 * 3 )
254
+
255
+ console . log ( '创建 worker 共享内存' , this . sabPositions , this . sabOpacities , this . sabCov3Da , this . sabCov3Db , this . sabcolors )
256
+
245
257
// 初始化 worker 相关
246
258
this . initWorker ( info , {
247
- maxGaussians
259
+ sabPositions : this . sabPositions ,
260
+ sabOpacities : this . sabOpacities ,
261
+ sabCov3Da : this . sabCov3Da ,
262
+ sabCov3Db : this . sabCov3Db ,
263
+ sabcolors : this . sabcolors ,
248
264
} ) ;
249
265
250
266
} else {
@@ -288,47 +304,55 @@ Component({
288
304
289
305
this . camera . isWorkerSorting = false ;
290
306
291
- const start = new Date ( ) . getTime ( )
292
-
293
307
const data = res . result . data
294
308
309
+ const start = new Date ( ) . getTime ( )
310
+
295
311
const gl = this . gl
296
312
297
313
const updateBuffer = ( buffer , data ) => {
298
314
gl . bindBuffer ( gl . ARRAY_BUFFER , buffer )
299
315
gl . bufferData ( gl . ARRAY_BUFFER , data , gl . DYNAMIC_DRAW )
300
316
}
317
+ // const colors = new Float32Array(data.colors);
318
+ // const positions = new Float32Array(data.positions);
319
+ // const opacities = new Float32Array(data.opacities);
320
+ // const cov3Da = new Float32Array(data.cov3Da);
321
+ // const cov3Db = new Float32Array(data.cov3Db);
301
322
302
- const colors = new Float32Array ( data . colors ) ;
303
- const positions = new Float32Array ( data . positions ) ;
304
- const opacities = new Float32Array ( data . opacities ) ;
305
- const cov3Da = new Float32Array ( data . cov3Da ) ;
306
- const cov3Db = new Float32Array ( data . cov3Db ) ;
323
+ const positions = new Float32Array ( this . sabPositions . buffer ) ;
324
+ const opacities = new Float32Array ( this . sabOpacities . buffer ) ;
325
+ const cov3Da = new Float32Array ( this . sabCov3Da . buffer ) ;
326
+ const cov3Db = new Float32Array ( this . sabCov3Db . buffer ) ;
327
+ const colors = new Float32Array ( this . sabcolors . buffer ) ;
328
+
329
+ // console.log('positions', positions);
330
+ // console.log('opacities', opacities);
331
+ // console.log('cov3Da', cov3Da);
332
+ // console.log('cov3Db', cov3Db);
333
+ // console.log('colors', colors);
307
334
308
335
309
- updateBuffer ( this . splat . buffers . color , colors )
310
336
updateBuffer ( this . splat . buffers . center , positions )
311
337
updateBuffer ( this . splat . buffers . opacity , opacities )
312
338
updateBuffer ( this . splat . buffers . covA , cov3Da )
313
339
updateBuffer ( this . splat . buffers . covB , cov3Db )
340
+ updateBuffer ( this . splat . buffers . color , colors )
314
341
315
- // console.log(this.splat.buffers.color, colors)
316
342
// console.log(this.splat.buffers.center, positions)
317
343
// console.log(this.splat.buffers.opacity, opacities)
318
344
// console.log(this.splat.buffers.covA, cov3Da)
319
345
// console.log(this.splat.buffers.covB, cov3Db)
346
+ // console.log(this.splat.buffers.color, colors)
320
347
348
+ // 设定绘制的高斯球数量
321
349
this . gaussiansCount = data . gaussiansCount ;
322
350
323
- console . log ( 'gaussiansCount' , this . gaussiansCount )
324
-
325
-
326
351
const end = new Date ( ) . getTime ( )
327
352
328
353
const sortTime = `${ ( ( end - start ) / 1000 ) . toFixed ( 3 ) } s`
329
354
console . log ( `updateBuffer ${ sortTime } ` )
330
355
331
- // this.requestRender();
332
356
this . canvas . requestAnimationFrame ( this . requestRender . bind ( this ) ) ;
333
357
334
358
// console.log('execFunc_sort end')
@@ -392,18 +416,15 @@ Component({
392
416
gl . enable ( gl . BLEND )
393
417
gl . blendFunc ( gl . ONE_MINUS_DST_ALPHA , gl . ONE )
394
418
// gl.blendFuncSeparate(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA)
395
-
396
419
397
420
// clear
398
421
gl . clear ( gl . COLOR_BUFFER_BIT ) ;
399
422
400
- // camera
423
+ // drawCubeMesh
401
424
// const projMatrix = this.camera.projMatrix;
402
425
// const viewMatrix = this.camera.viewMatrix;
403
-
404
426
// this.drawCubeMesh(gl, projMatrix, viewMatrix)
405
427
406
-
407
428
this . drawSplat ( gl ) ;
408
429
409
430
// const end = new Date().getTime()
@@ -495,24 +516,82 @@ Component({
495
516
// webGL触摸相关逻辑
496
517
onTouchStartWebGL ( e ) {
497
518
// console.log(e);
498
- this . camera . lastTouch . clientX = e . touches [ 0 ] . clientX
499
- this . camera . lastTouch . clientY = e . touches [ 0 ] . clientY
519
+
520
+ if ( e . touches . length === 1 ) {
521
+ this . camera . lastTouch . x1 = e . touches [ 0 ] . clientX
522
+ this . camera . lastTouch . y1 = e . touches [ 0 ] . clientY
523
+ this . camera . lastTouch . x2 = null ;
524
+ this . camera . lastTouch . y2 = null ;
525
+ this . camera . lastTouch . distance = 0 ;
526
+ } else if ( e . touches . length === 2 ) {
527
+ const touch1 = e . touches [ 0 ] ;
528
+ const touch2 = e . touches [ 1 ] ;
529
+
530
+ this . camera . lastTouch . x1 = touch1 . clientX
531
+ this . camera . lastTouch . y1 = touch1 . clientY
532
+ this . camera . lastTouch . x2 = touch2 . clientX
533
+ this . camera . lastTouch . y2 = touch2 . clientY
534
+
535
+ const distanceX = touch1 . clientX - touch2 . clientX ;
536
+ const distanceY = touch1 . clientY - touch2 . clientY ;
537
+ this . camera . lastTouch . distance = Math . sqrt ( distanceX * distanceX + distanceY * distanceY ) ;
538
+ }
539
+
500
540
} ,
501
541
onTouchMoveWebGL ( e ) {
502
542
// console.log(e);
503
543
504
- const touch = e . touches [ 0 ]
505
- const movementX = touch . clientX - this . camera . lastTouch . clientX
506
- const movementY = touch . clientY - this . camera . lastTouch . clientY
507
- this . camera . lastTouch . clientX = touch . clientX
508
- this . camera . lastTouch . clientY = touch . clientY
544
+ const moveScale = 1 ;
545
+
546
+ if ( e . touches . length === 1 ) {
547
+ const touch = e . touches [ 0 ] ;
548
+ // 单指移动镜头
549
+ const movementX = touch . clientX - this . camera . lastTouch . x1
550
+ const movementY = touch . clientY - this . camera . lastTouch . y1
551
+ this . camera . lastTouch . x1 = touch . clientX
552
+ this . camera . lastTouch . y1 = touch . clientY
509
553
510
- this . camera . theta -= movementX * 0.01 * .5 * .3
511
- this . camera . phi = Math . max ( 1e-6 , Math . min ( Math . PI - 1e-6 , this . camera . phi + movementY * 0.01 * .5 ) )
554
+ if ( Math . abs ( movementX ) < 100 && Math . abs ( movementY ) < 100 ) {
555
+ // 只处理小移动
556
+ this . camera . theta -= movementX * 0.01 * .3 * moveScale
557
+ this . camera . phi = Math . max ( 1e-6 , Math . min ( Math . PI - 1e-6 , this . camera . phi + movementY * 0.01 * moveScale ) )
558
+ }
559
+
560
+ } else if ( e . touches . length === 2 ) {
561
+ // 支持单指变双指,兼容双指操作但是两根手指触屏时间不一致的情况
562
+ const touch1 = e . touches [ 0 ] ;
563
+ const touch2 = e . touches [ 1 ] ;
564
+
565
+ const distanceX = touch1 . clientX - touch2 . clientX ;
566
+ const distanceY = touch1 . clientY - touch2 . clientY ;
567
+ const distance = Math . sqrt ( distanceX * distanceX + distanceY * distanceY ) ;
568
+
569
+ if ( this . camera . lastTouch . x2 === null && this . camera . lastTouch . y2 === null ) {
570
+ this . camera . lastTouch . x1 = touch1 . clientX
571
+ this . camera . lastTouch . y1 = touch1 . clientY
572
+ this . camera . lastTouch . x2 = touch2 . clientX
573
+ this . camera . lastTouch . y2 = touch2 . clientY
574
+
575
+ this . camera . lastTouch . distance = distance ;
576
+ } else {
577
+ // 双指开始滑动
578
+ let deltaScale = distance - this . camera . lastTouch . distance ;
579
+ this . camera . lastTouch . distance = distance ;
580
+
581
+ if ( deltaScale < - 2 ) {
582
+ deltaScale = - 2 ;
583
+ } else if ( deltaScale > 2 ) {
584
+ deltaScale = 2 ;
585
+ }
586
+
587
+ const newRaidus = this . camera . radius - deltaScale * 0.2 ;
588
+ this . camera . radius = newRaidus > 0 ? newRaidus : this . camera . radius ;
589
+ }
590
+
591
+ }
512
592
513
593
this . camera . update ( ) ;
514
594
515
- // this.requestRender();
516
595
this . canvas . requestAnimationFrame ( this . requestRender . bind ( this ) ) ;
517
596
} ,
518
597
onTapControl ( e ) {
0 commit comments