gulpfile.js 4.5 KB

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