gulpfile.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. const path = require('path');
  2. const gulp = require('gulp');
  3. const exec = require('child_process').exec;
  4. const fs = require("fs");
  5. const fsp = fs.promises;
  6. const concat = require('gulp-concat');
  7. const connect = require('gulp-connect');
  8. const {watch} = gulp;
  9. const {createExamplesPage} = require("./src/tools/create_potree_page");
  10. const {createGithubPage} = require("./src/tools/create_github_page");
  11. const {createIconsPage} = require("./src/tools/create_icons_page");
  12. let paths = {
  13. laslaz: [
  14. "build/workers/laslaz-worker.js",
  15. "build/workers/lasdecoder-worker.js",
  16. ],
  17. html: [
  18. "src/viewer/potree.css",
  19. "src/viewer/sidebar.html",
  20. "src/viewer/sidebar2.html",
  21. "src/viewer/profile.html"
  22. ],
  23. resources: [
  24. "resources/**/*"
  25. ]
  26. };
  27. let workers = {
  28. "LASLAZWorker": [
  29. "libs/plasio/workers/laz-perf.js",
  30. "libs/plasio/workers/laz-loader-worker.js"
  31. ],
  32. "LASDecoderWorker": [
  33. "src/workers/LASDecoderWorker.js"
  34. ],
  35. "EptLaszipDecoderWorker": [
  36. "src/workers/EptLaszipDecoderWorker.js"
  37. ],
  38. "EptBinaryDecoderWorker": [
  39. "libs/ept/ParseBuffer.js",
  40. "src/workers/EptBinaryDecoderWorker.js"
  41. ],
  42. "EptZstandardDecoderWorker": [
  43. "src/workers/EptZstandardDecoder_preamble.js",
  44. 'libs/zstd-codec/bundle.js',
  45. "libs/ept/ParseBuffer.js",
  46. "src/workers/EptZstandardDecoderWorker.js"
  47. ]
  48. };
  49. // these libs are lazily loaded
  50. // in order for the lazy loader to find them, independent of the path of the html file,
  51. // we package them together with potree
  52. let lazyLibs = {
  53. "geopackage": "libs/geopackage",
  54. "sql.js": "libs/sql.js"
  55. };
  56. let shaders = [
  57. "src/materials/shaders/pointcloud.vs",
  58. "src/materials/shaders/pointcloud.fs",
  59. "src/materials/shaders/pointcloud_sm.vs",
  60. "src/materials/shaders/pointcloud_sm.fs",
  61. "src/materials/shaders/normalize.vs",
  62. "src/materials/shaders/normalize.fs",
  63. "src/materials/shaders/normalize_and_edl.fs",
  64. "src/materials/shaders/edl.vs",
  65. "src/materials/shaders/edl.fs",
  66. "src/materials/shaders/blur.vs",
  67. "src/materials/shaders/blur.fs",
  68. //add:
  69. "src/materials/shaders/depthBasic.vs",
  70. "src/materials/shaders/depthBasic.fs",
  71. "src/materials/shaders/copyCubeMap.vs",
  72. "src/materials/shaders/copyCubeMap.fs",
  73. "src/materials/shaders/basicTextured.vs",
  74. "src/materials/shaders/basicTextured.fs",
  75. ];
  76. 'src/**/*.js',
  77. // For development, it is now possible to use 'gulp webserver'
  78. // from the command line to start the server (default port is 8080)
  79. gulp.task('webserver', gulp.series(async function() {
  80. server = connect.server({
  81. port: 1234,
  82. host:'192.168.0.113',
  83. https: true,
  84. });
  85. }));
  86. gulp.task('examples_page', async function(done) {
  87. await Promise.all([
  88. createExamplesPage(),
  89. createGithubPage(),
  90. ]);
  91. done();
  92. });
  93. gulp.task('icons_viewer', async function(done) {
  94. await createIconsPage();
  95. done();
  96. });
  97. gulp.task('test', async function() {
  98. console.log("asdfiae8ofh");
  99. });
  100. gulp.task("workers", async function(done){
  101. for(let workerName of Object.keys(workers)){
  102. gulp.src(workers[workerName])
  103. .pipe(concat(`${workerName}.js`))
  104. .pipe(gulp.dest('build/potree/workers'));
  105. }
  106. done();
  107. });
  108. gulp.task("lazylibs", async function(done){
  109. for(let libname of Object.keys(lazyLibs)){
  110. const libpath = lazyLibs[libname];
  111. gulp.src([`${libpath}/**/*`])
  112. .pipe(gulp.dest(`build/potree/lazylibs/${libname}`));
  113. }
  114. done();
  115. });
  116. gulp.task("shaders", async function(){
  117. const components = [
  118. "let Shaders = {};"
  119. ];
  120. for(let file of shaders){
  121. const filename = path.basename(file);
  122. const content = await fsp.readFile(file);
  123. const prep = `Shaders["${filename}"] = \`${content}\``;
  124. components.push(prep);
  125. }
  126. components.push("export {Shaders};");
  127. const content = components.join("\n\n");
  128. const targetPath = `./build/shaders/shaders.js`;
  129. if(!fs.existsSync("build/shaders")){
  130. fs.mkdirSync("build/shaders");
  131. }
  132. fs.writeFileSync(targetPath, content, {flag: "w"});
  133. });
  134. gulp.task('build',
  135. gulp.series(
  136. gulp.parallel("workers", "lazylibs", "shaders", "icons_viewer", "examples_page"),
  137. async function(done){
  138. gulp.src(paths.html).pipe(gulp.dest('build/potree'));
  139. gulp.src(paths.resources).pipe(gulp.dest('build/potree/resources'));
  140. gulp.src(["LICENSE"]).pipe(gulp.dest('build/potree'));
  141. done();
  142. }
  143. )
  144. );
  145. gulp.task("pack", async function(){
  146. exec('rollup -c', function (err, stdout, stderr) {
  147. console.log(stdout);
  148. console.log(stderr);
  149. });
  150. });
  151. gulp.task('watch', gulp.parallel("build", "pack", "webserver", async function() {
  152. let watchlist = [
  153. 'src/**/*.js',
  154. 'src/**/**/*.js',
  155. 'src/**/*.css',
  156. 'src/**/*.html',
  157. 'src/**/*.vs',
  158. 'src/**/*.fs',
  159. 'resources/**/*',
  160. 'examples//**/*.json',
  161. '!resources/icons/index.html',
  162. ];
  163. watch(watchlist, gulp.series("build", "pack"));
  164. }));