forked from potree/potree
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
282 lines (234 loc) · 7.29 KB
/
gulpfile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
var path = require('path');
var gulp = require('gulp');
var concat = require('gulp-concat');
var size = require('gulp-size');
var rename = require('gulp-rename');
var uglify = require('gulp-uglify');
var gutil = require('gulp-util');
var through = require('through');
var os = require('os');
var File = gutil.File;
//We need this one for the in-built webserver
var connect = require('gulp-connect');
var paths = {
potree : [
"src/Potree.js",
"src/PointCloudTree.js",
"src/WorkerPool.js",
"build/shaders/shaders.js",
"src/extensions/EventDispatcher.js",
"src/extensions/PerspectiveCamera.js",
"src/extensions/Ray.js",
"src/loader/POCLoader.js",
"src/loader/PointAttributes.js",
"src/loader/BinaryLoader.js",
"src/loader/GreyhoundBinaryLoader.js",
"src/loader/GreyhoundLoader.js",
"src/loader/LasLazLoader.js",
"src/materials/PointCloudMaterial.js",
"src/materials/EyeDomeLightingMaterial.js",
"src/materials/BlurMaterial.js",
"src/navigation/InputHandler.js",
"src/navigation/FirstPersonControls.js",
"src/navigation/GeoControls.js",
"src/navigation/OrbitControls.js",
"src/navigation/EarthControls.js",
"src/LRU.js",
"src/Annotation.js",
"src/ProfileRequest.js",
"src/PointCloudOctree.js",
"src/PointCloudOctreeGeometry.js",
"src/PointCloudGreyhoundGeometry.js",
"src/PointCloudGreyhoundGeometryNode.js",
"src/utils.js",
"src/Features.js",
"src/TextSprite.js",
"src/AnimationPath.js",
"src/Version.js",
"src/utils/Measure.js",
"src/utils/MeasuringTool.js",
"src/utils/Profile.js",
"src/utils/ProfileTool.js",
"src/utils/TransformationTool.js",
"src/utils/Volume.js",
"src/utils/VolumeTool.js",
"src/exporter/GeoJSONExporter.js",
"src/exporter/DXFExporter.js",
"src/arena4d/PointCloudArena4D.js",
"src/arena4d/PointCloudArena4DGeometry.js",
"src/viewer/ProgressBar.js",
"src/viewer/viewer.js",
"src/viewer/profile.js",
"src/viewer/map.js",
"src/viewer/sidebar.js",
"src/stuff/HoverMenu.js"
],
laslaz: [
"build/workers/laslaz-worker.js",
"build/workers/lasdecoder-worker.js",
],
html: [
"src/viewer/potree.css",
"src/viewer/sidebar.html",
"src/viewer/profile.html"
],
resources: [
"resources/**/*"
]
};
var workers = {
"laslaz": [
"libs/plasio/workers/laz-perf.js",
"libs/plasio/workers/laz-loader-worker.js"
],
"LASDecoder": [
"src/workers/LASDecoderWorker.js"
],
"BinaryDecoder": [
"src/workers/BinaryDecoderWorker.js",
"src/Version.js",
"src/loader/PointAttributes.js"
],
"GreyhoundBinaryDecoder": [
"libs/plasio/workers/laz-perf.js",
"src/workers/GreyhoundBinaryDecoderWorker.js",
"src/Version.js",
"src/loader/PointAttributes.js"
]
};
var shaders = [
"src/materials/shaders/pointcloud.vs",
"src/materials/shaders/pointcloud.fs",
"src/materials/shaders/normalize.vs",
"src/materials/shaders/normalize.fs",
"src/materials/shaders/edl.vs",
"src/materials/shaders/edl.fs",
"src/materials/shaders/blur.vs",
"src/materials/shaders/blur.fs"
];
gulp.task("workers", function(){
gulp.src(workers.laslaz)
.pipe(encodeWorker('laslaz-worker.js', "Potree.workers.laslaz"))
.pipe(size({showFiles: true}))
.pipe(gulp.dest('build/potree/workers'));
gulp.src(workers.LASDecoder)
.pipe(encodeWorker('lasdecoder-worker.js', "Potree.workers.lasdecoder"))
.pipe(size({showFiles: true}))
.pipe(gulp.dest('build/potree/workers'));
gulp.src(workers.BinaryDecoder)
.pipe(encodeWorker('BinaryDecoderWorker.js', "Potree.workers.binaryDecoder"))
.pipe(size({showFiles: true}))
.pipe(gulp.dest('build/potree/workers'));
gulp.src(workers.GreyhoundBinaryDecoder)
.pipe(encodeWorker('GreyhoundBinaryDecoderWorker.js', "Potree.workers.greyhoundBinaryDecoder"))
.pipe(size({showFiles: true}))
.pipe(gulp.dest('build/potree/workers'));
});
gulp.task("shaders", function(){
return gulp.src(shaders)
.pipe(encodeShader('shaders.js', "Potree.Shader"))
.pipe(size({showFiles: true}))
.pipe(gulp.dest('build/shaders'));
});
gulp.task("scripts", ['workers','shaders'], function(){
gulp.src(paths.potree)
.pipe(concat('potree.js'))
.pipe(size({showFiles: true}))
.pipe(gulp.dest('build/potree'));
gulp.src(paths.laslaz)
.pipe(concat('laslaz.js'))
.pipe(size({showFiles: true}))
.pipe(gulp.dest('build/potree'));
gulp.src(paths.html)
.pipe(gulp.dest('build/potree'));
gulp.src(paths.resources)
.pipe(gulp.dest('build/potree/resources'));
gulp.src(["LICENSE"])
.pipe(gulp.dest('build/potree'));
return;
});
gulp.task('build', ['scripts']);
gulp.task('watch', function() {
gulp.watch('src/**/*.js', ['scripts']);
})
// For development, it is now possible to use 'gulp webserver'
// from the command line to start the server (default port is 8080)
gulp.task('webserver', function() {
connect.server();
});
var encodeWorker = function(fileName, varname, opt){
if (!fileName) throw new PluginError('gulp-concat', 'Missing fileName option for gulp-concat');
if (!opt) opt = {};
if (!opt.newLine) opt.newLine = gutil.linefeed;
var buffer = [];
var firstFile = null;
function bufferContents(file){
if (file.isNull()) return; // ignore
if (file.isStream()) return this.emit('error', new PluginError('gulp-concat', 'Streaming not supported'));
if (!firstFile) firstFile = file;
var string = file.contents.toString('utf8');
buffer.push(string);
}
function endStream(){
if (buffer.length === 0) return this.emit('end');
var joinedContents = buffer.join("");
//var content = varname + " = new Potree.WorkerManager(atob(\"" + new Buffer(joinedContents).toString('base64') + "\"));";
let content = joinedContents;
var joinedPath = path.join(firstFile.base, fileName);
var joinedFile = new File({
cwd: firstFile.cwd,
base: firstFile.base,
path: joinedPath,
contents: new Buffer(content)
});
this.emit('data', joinedFile);
this.emit('end');
}
return through(bufferContents, endStream);
};
var encodeShader = function(fileName, varname, opt){
if (!fileName) throw new PluginError('gulp-concat', 'Missing fileName option for gulp-concat');
if (!opt) opt = {};
if (!opt.newLine) opt.newLine = gutil.linefeed;
var buffer = [];
var files = [];
var firstFile = null;
function bufferContents(file){
if (file.isNull()) return; // ignore
if (file.isStream()) return this.emit('error', new PluginError('gulp-concat', 'Streaming not supported'));
if (!firstFile) firstFile = file;
var string = file.contents.toString('utf8');
buffer.push(string);
files.push(file);
}
function endStream(){
if (buffer.length === 0) return this.emit('end');
var joinedContent = "";
for(var i = 0; i < buffer.length; i++){
var b = buffer[i];
var file = files[i];
var fname = file.path.replace(file.base, "");
console.log(fname);
var content = new Buffer(b).toString();
var prep = "Potree.Shaders[\"" + fname + "\"] = [\n";
var lines = content.split("\n");
for(var j = 0; j < lines.length; j++){
var line = lines[j];
line = line.replace(/(\r\n|\n|\r)/gm,"");
prep += " \"" + line + "\",\n";
}
prep += "].join(\"\\n\");\n\n";
joinedContent += prep;
}
var joinedPath = path.join(firstFile.base, fileName);
var joinedFile = new File({
cwd: firstFile.cwd,
base: firstFile.base,
path: joinedPath,
contents: new Buffer(joinedContent)
});
this.emit('data', joinedFile);
this.emit('end');
}
return through(bufferContents, endStream);
};