1
- import { Vector3 } from 'three' ;
2
1
import { ClipMode , PointCloudOctree } from '../src' ;
3
2
import { Viewer } from './viewer' ;
4
3
@@ -14,18 +13,19 @@ viewer.initialize(targetEl);
14
13
interface PointCloudsConfig {
15
14
file : string ;
16
15
url : string ;
17
- version : 'v1' | 'v2' ;
16
+ version : 'v1' | 'v2' | 'splats' ;
18
17
}
19
18
20
19
const examplePointClouds : PointCloudsConfig [ ] = [
21
20
{
22
21
file : 'cloud.js' ,
23
22
url : 'https://raw.githubusercontent.com/potree/potree/develop/pointclouds/lion_takanawa/' ,
24
- version : 'v1'
25
- } , {
23
+ version : 'v1' ,
24
+ } ,
25
+ {
26
26
file : 'metadata.json' ,
27
27
url : 'https://test-pix4d-cloud-eu-central-1.s3.eu-central-1.amazonaws.com/lion_takanawa_converted/' ,
28
- version : 'v2'
28
+ version : 'v2' ,
29
29
}
30
30
] ;
31
31
@@ -39,15 +39,17 @@ interface LoadedState {
39
39
40
40
const pointClouds : PointClouds = {
41
41
v1 : undefined ,
42
- v2 : undefined
42
+ v2 : undefined ,
43
+ splats : undefined
43
44
} ;
44
45
45
46
const loaded : LoadedState = {
46
47
v1 : false ,
47
- v2 : false
48
+ v2 : false ,
49
+ splats : false
48
50
} ;
49
51
50
- function createButton ( text : string , onClick : ( ) => void ) : HTMLButtonElement {
52
+ function createButton ( text : string , onClick : ( e : MouseEvent ) => void ) : HTMLButtonElement {
51
53
const button : HTMLButtonElement = document . createElement ( 'button' ) ;
52
54
button . textContent = text ;
53
55
button . addEventListener ( 'click' , onClick ) ;
@@ -58,45 +60,67 @@ function createSlider(version: string): HTMLInputElement {
58
60
const slider : HTMLInputElement = document . createElement ( 'input' ) ;
59
61
slider . type = 'range' ;
60
62
slider . min = '10000' ;
61
- slider . max = '500000' ;
63
+ slider . max = '1000000' ;
64
+ slider . value = '1000000' ;
62
65
slider . className = 'budget-slider' ;
63
66
slider . addEventListener ( 'change' , ( ) => {
64
67
const cloud = pointClouds [ version ] ;
65
68
if ( ! cloud ) {
66
69
return ;
67
70
}
68
71
cloud . potree . pointBudget = parseInt ( slider . value , 10 ) ;
72
+ viewer . update ( 0 ) ;
69
73
console . log ( cloud . potree . pointBudget ) ;
70
74
} ) ;
71
75
return slider ;
72
76
}
73
77
74
- function setupPointCloud ( version : 'v1' | 'v2' , file : string , url : string ) : void {
78
+ function setupPointCloud ( version : 'v1' | 'v2' | 'splats' , file : string , url : string ) : void {
75
79
if ( loaded [ version ] ) {
76
80
return ;
77
81
}
78
82
loaded [ version ] = true ;
79
83
80
- viewer . load ( file , url , version )
84
+ //TODO: check for mobile, not noly IOS
85
+ function isIOS ( ) {
86
+ const ua = navigator . userAgent ;
87
+ return ua . indexOf ( 'iPhone' ) > 0 || ua . indexOf ( 'iPad' ) > 0 ;
88
+ }
89
+
90
+ viewer . load ( file , url , version == 'splats' ? 'v2' : version , ! isIOS ( ) )
81
91
. then ( pco => {
82
92
pointClouds [ version ] = pco ;
83
- pco . rotateX ( - Math . PI / 2 ) ;
84
93
pco . material . size = 1.0 ;
94
+
95
+ pco . material . pointColorType = 0 ;
96
+
85
97
pco . material . clipMode = ClipMode . CLIP_HORIZONTALLY ;
86
98
pco . material . clipExtent = [ 0.0 , 0.0 , 1.0 , 1.0 ] ;
99
+ pco . position . set ( 0 , 0 , 0 ) ;
87
100
88
101
const camera = viewer . camera ;
102
+ camera . up . set ( 0 , 0 , 1 ) ;
89
103
camera . far = 1000 ;
90
104
camera . updateProjectionMatrix ( ) ;
91
- camera . position . set ( 0 , 0 , 10 ) ;
92
- camera . lookAt ( new Vector3 ( ) ) ;
105
+ camera . position . set ( - 4 , 4 , 16 ) ;
93
106
94
107
viewer . add ( pco ) ;
95
108
} )
96
109
. catch ( err => console . error ( err ) ) ;
97
110
}
98
111
99
112
function setupUI ( cfg : PointCloudsConfig ) : void {
113
+
114
+ const updateBtn = createButton ( "Update" , ( e : MouseEvent ) => {
115
+ e . stopPropagation ( ) ;
116
+ viewer . enableUpdate = ! viewer . enableUpdate ;
117
+ updateBtn . style . backgroundColor = viewer . enableUpdate ? "#00ff00" : "#ff0000" ;
118
+ } )
119
+
120
+ updateBtn . style . backgroundColor = "#00ff00" ;
121
+
122
+ const slider = createSlider ( cfg . version ) ;
123
+
100
124
const unloadBtn = createButton ( 'Unload' , ( ) => {
101
125
if ( ! loaded [ cfg . version ] ) {
102
126
return ;
@@ -109,18 +133,25 @@ function setupUI(cfg: PointCloudsConfig): void {
109
133
viewer . disposePointCloud ( pointCloud ) ;
110
134
loaded [ cfg . version ] = false ;
111
135
pointClouds [ cfg . version ] = undefined ;
112
- } ) ;
113
136
114
- const loadBtn = createButton ( 'Load' , ( ) => setupPointCloud ( cfg . version , cfg . file , cfg . url ) ) ;
137
+ viewer . enableUpdate = true ;
138
+ updateBtn . style . backgroundColor = "#00ff00" ;
139
+ } ) ;
115
140
116
- const slider = createSlider ( cfg . version ) ;
141
+ const loadBtn = createButton ( 'Load' , ( e : MouseEvent ) => {
142
+ e . stopPropagation ( ) ;
143
+ setupPointCloud ( cfg . version , cfg . file , cfg . url )
144
+ }
145
+ ) ;
117
146
118
147
const btnContainer : HTMLDivElement = document . createElement ( 'div' ) ;
119
148
btnContainer . className = 'btn-container-' + cfg . version ;
120
149
document . body . appendChild ( btnContainer ) ;
121
150
btnContainer . appendChild ( unloadBtn ) ;
122
151
btnContainer . appendChild ( loadBtn ) ;
152
+ btnContainer . append ( updateBtn ) ;
123
153
btnContainer . appendChild ( slider ) ;
154
+
124
155
}
125
156
126
157
examplePointClouds . forEach ( setupUI ) ;
0 commit comments