@@ -15,6 +15,7 @@ const container = document.getElementById( 'container' );
15
15
const progressDialog = document . getElementById ( "progress-dialog" ) ;
16
16
const progressIndicator = document . getElementById ( "progress-indicator" ) ;
17
17
const colorPicker = document . getElementById ( "color-picker" ) ;
18
+ const downloadButton = document . getElementById ( "download-button" ) ;
18
19
19
20
const renderer = new THREE . WebGLRenderer ( { antialias : true } ) ;
20
21
renderer . setPixelRatio ( window . devicePixelRatio ) ;
@@ -56,9 +57,14 @@ const clock = new THREE.Clock();
56
57
var lastTimestamp = "" ;
57
58
var needUpdate = false ;
58
59
let mixer ;
60
+ let currentURL ;
61
+
62
+ downloadButton . addEventListener ( 'click' , e => {
63
+ window . open ( currentURL , '_blank' ) ;
64
+ } ) ;
59
65
60
66
function frameUpdate ( ) {
61
-
67
+
62
68
var filepath = visualizer . getAttribute ( "filepath" ) ;
63
69
var timestamp = visualizer . getAttribute ( "timestamp" ) ;
64
70
if ( timestamp == lastTimestamp ) {
@@ -100,12 +106,12 @@ async function main(filepath="") {
100
106
if ( / ^ .+ \. [ a - z A - Z ] + $ / . test ( filepath ) ) {
101
107
102
108
let params = { "filepath" : filepath } ;
103
- const url = api . apiURL ( '/viewfile?' + new URLSearchParams ( params ) ) ;
109
+ currentURL = api . apiURL ( '/viewfile?' + new URLSearchParams ( params ) ) ;
104
110
105
111
var filepathSplit = filepath . split ( '.' ) ;
106
112
var fileExt = filepathSplit . pop ( ) . toLowerCase ( ) ;
107
- var filepathNoExt = filepathSplit . join ( "." ) ;
108
-
113
+ var filepathNoExt = filepathSplit . join ( "." ) ;
114
+
109
115
if ( fileExt == "obj" ) {
110
116
const loader = new OBJLoader ( ) ;
111
117
@@ -118,16 +124,16 @@ async function main(filepath="") {
118
124
mtl . preload ( ) ;
119
125
loader . setMaterials ( mtl ) ;
120
126
} , onProgress , onError ) ;
121
-
122
- loader . load ( url , function ( obj ) {
127
+
128
+ loader . load ( currentURL , function ( obj ) {
123
129
obj . scale . setScalar ( 5 ) ;
124
130
scene . add ( obj ) ;
125
131
obj . traverse ( node => {
126
132
if ( node . material && node . material . map == null ) {
127
133
node . material . vertexColors = true ;
128
134
}
129
135
} ) ;
130
-
136
+
131
137
} , onProgress , onError ) ;
132
138
133
139
} else if ( fileExt == "glb" ) {
@@ -136,7 +142,7 @@ async function main(filepath="") {
136
142
const loader = new GLTFLoader ( ) ;
137
143
loader . setDRACOLoader ( dracoLoader ) ;
138
144
139
- loader . load ( url , function ( gltf ) {
145
+ loader . load ( currentURL , function ( gltf ) {
140
146
const model = gltf . scene ;
141
147
//model.position.set( 1, 1, 0 );
142
148
model . scale . set ( 3 , 3 , 3 ) ;
@@ -146,7 +152,7 @@ async function main(filepath="") {
146
152
gltf . animations . forEach ( ( clip ) => {
147
153
mixer . clipAction ( clip ) . play ( ) ;
148
154
} ) ;
149
-
155
+
150
156
} , onProgress , onError ) ;
151
157
152
158
} else if ( fileExt == "ply" ) {
0 commit comments