@@ -8,14 +8,28 @@ import vtkFullScreenRenderWindow from '@kitware/vtk.js/Rendering/Misc/FullScreen
8
8
import vtkMapper from '@kitware/vtk.js/Rendering/Core/Mapper' ;
9
9
import vtkPLYReader from '@kitware/vtk.js/IO/Geometry/PLYReader' ;
10
10
import vtkTexture from '@kitware/vtk.js/Rendering/Core/Texture' ;
11
+ import vtkURLExtract from '@kitware/vtk.js/Common/Core/URLExtract' ;
12
+
13
+ import controlPanel from './controller.html' ;
11
14
12
15
// ----------------------------------------------------------------------------
13
- // Example code
16
+ // Standard rendering code setup
14
17
// ----------------------------------------------------------------------------
18
+ const userParams = vtkURLExtract . extractURLParameters ( ) ;
19
+ const url = userParams . fileURL ;
20
+ const duplicatePointsForFaceTexture =
21
+ userParams . duplicatePointsForFaceTexture || false ;
22
+
23
+ const fullScreenRenderer = vtkFullScreenRenderWindow . newInstance ( ) ;
24
+ const renderer = fullScreenRenderer . getRenderer ( ) ;
25
+ const renderWindow = fullScreenRenderer . getRenderWindow ( ) ;
15
26
16
- let renderer = null ;
17
- let renderWindow = null ;
18
- const reader = vtkPLYReader . newInstance ( ) ;
27
+ // ----------------------------------------------------------------------------
28
+ // Example code
29
+ // ----------------------------------------------------------------------------
30
+ const reader = vtkPLYReader . newInstance ( {
31
+ duplicatePointsForFaceTexture,
32
+ } ) ;
19
33
const mapper = vtkMapper . newInstance ( { scalarVisibility : false } ) ;
20
34
const actor = vtkActor . newInstance ( ) ;
21
35
@@ -25,19 +39,13 @@ mapper.setInputConnection(reader.getOutputPort());
25
39
// ----------------------------------------------------------------------------
26
40
27
41
function refresh ( ) {
28
- if ( renderer && renderWindow ) {
29
- const resetCamera = renderer . resetCamera ;
30
- const render = renderWindow . render ;
31
- resetCamera ( ) ;
32
- render ( ) ;
33
- }
42
+ const resetCamera = renderer . resetCamera ;
43
+ const render = renderWindow . render ;
44
+ resetCamera ( ) ;
45
+ render ( ) ;
34
46
}
35
47
36
48
function update ( ) {
37
- const fullScreenRenderer = vtkFullScreenRenderWindow . newInstance ( ) ;
38
- renderer = fullScreenRenderer . getRenderer ( ) ;
39
- renderWindow = fullScreenRenderer . getRenderWindow ( ) ;
40
-
41
49
renderer . addActor ( actor ) ;
42
50
43
51
actor . getMapper ( ) . setScalarVisibility ( true ) ;
@@ -51,13 +59,11 @@ function update() {
51
59
// Use a file reader to load a local file
52
60
// ----------------------------------------------------------------------------
53
61
54
- const myContainer = document . querySelector ( 'body' ) ;
55
- const fileContainer = document . createElement ( 'div' ) ;
56
- fileContainer . innerHTML =
57
- '<div>Select a ply file or a ply file with its texture file.<br/><input type="file" class="file" multiple/></div>' ;
58
- myContainer . appendChild ( fileContainer ) ;
62
+ fullScreenRenderer . addController ( controlPanel ) ;
59
63
60
- const fileInput = fileContainer . querySelector ( 'input' ) ;
64
+ const fileInput = document . querySelector ( 'input' ) ;
65
+ const checkbox = document . querySelector ( '#duplicate_points_for_face_texture' ) ;
66
+ checkbox . checked = duplicatePointsForFaceTexture ;
61
67
62
68
function handlePlyFile ( file ) {
63
69
const fileReader = new FileReader ( ) ;
@@ -88,10 +94,8 @@ function handleFile(event) {
88
94
const dataTransfer = event . dataTransfer ;
89
95
const files = event . target . files || dataTransfer . files ;
90
96
if ( files . length === 1 ) {
91
- myContainer . removeChild ( fileContainer ) ;
92
97
handlePlyFile ( files [ 0 ] ) ;
93
98
} else if ( files . length > 1 ) {
94
- myContainer . removeChild ( fileContainer ) ;
95
99
Array . from ( files ) . forEach ( ( file ) => {
96
100
const name = file . name . toLowerCase ( ) ;
97
101
if ( name . endsWith ( '.ply' ) ) {
@@ -110,8 +114,17 @@ function handleFile(event) {
110
114
111
115
fileInput . addEventListener ( 'change' , handleFile ) ;
112
116
117
+ checkbox . addEventListener ( 'change' , ( e ) => {
118
+ const value = e . target . checked ;
119
+ console . log ( 'duplicate points for face texture' , value ) ;
120
+ window . location = `?duplicatePointsForFaceTexture=${ value } ` ;
121
+ refresh ( ) ;
122
+ } ) ;
123
+
113
124
// ----------------------------------------------------------------------------
114
125
// Use the reader to download a file
115
126
// ----------------------------------------------------------------------------
116
127
117
- // reader.setUrl(`${__BASE_PATH__}/data/ply/mesh.ply`, { binary: true }).then(update);
128
+ if ( url ) {
129
+ reader . setUrl ( url ) . then ( update ) ;
130
+ }
0 commit comments