gulpfile.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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/sidebar1.html","src/viewer/sidebar2.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_new.vs",
  57. "src/materials/shaders/pointcloud_new.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_new.vs",
  64. "src/materials/shaders/edl_new.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. "src/materials/shaders/skybox.vs",
  75. "src/materials/shaders/skybox.fs",
  76. ];
  77. 'src/**/*.js',
  78. // For development, it is now possible to use 'gulp webserver'
  79. // from the command line to start the server (default port is 8080)
  80. gulp.task('webserver', gulp.series(async function() {
  81. server = connect.server({
  82. port: 1234,
  83. host:'192.168.0.113',
  84. https: false,
  85. });
  86. }));
  87. gulp.task('examples_page', async function(done) {
  88. await Promise.all([
  89. createExamplesPage(),
  90. createGithubPage(),
  91. ]);
  92. done();
  93. });
  94. gulp.task('icons_viewer', async function(done) {
  95. await createIconsPage();
  96. done();
  97. });
  98. gulp.task('test', async function() {
  99. console.log("asdfiae8ofh");
  100. });
  101. gulp.task("workers", async function(done){
  102. for(let workerName of Object.keys(workers)){
  103. gulp.src(workers[workerName])
  104. .pipe(concat(`${workerName}.js`))
  105. .pipe(gulp.dest('build/potree/workers'));
  106. }
  107. done();
  108. });
  109. gulp.task("lazylibs", async function(done){
  110. for(let libname of Object.keys(lazyLibs)){
  111. const libpath = lazyLibs[libname];
  112. gulp.src([`${libpath}/**/*`])
  113. .pipe(gulp.dest(`build/potree/lazylibs/${libname}`));
  114. }
  115. done();
  116. });
  117. gulp.task("shaders", async function(){
  118. const components = [
  119. "let Shaders = {};"
  120. ];
  121. for(let file of shaders){
  122. const filename = path.basename(file);
  123. const content = await fsp.readFile(file);
  124. const prep = `Shaders["${filename}"] = \`${content}\``;
  125. components.push(prep);
  126. }
  127. components.push("export {Shaders};");
  128. const content = components.join("\n\n");
  129. const targetPath = `./build/shaders/shaders.js`;
  130. if(!fs.existsSync("build/shaders")){
  131. fs.mkdirSync("build/shaders");
  132. }
  133. fs.writeFileSync(targetPath, content, {flag: "w"});
  134. });
  135. gulp.task('build',
  136. gulp.series(
  137. gulp.parallel("workers", "lazylibs", "shaders", "icons_viewer", "examples_page"),
  138. async function(done){
  139. gulp.src(paths.html).pipe(gulp.dest('build/potree'));
  140. gulp.src(paths.resources).pipe(gulp.dest('build/potree/resources'));
  141. gulp.src(["LICENSE"]).pipe(gulp.dest('build/potree'));
  142. done();
  143. }
  144. )
  145. );
  146. gulp.task("pack", async function(){
  147. exec('rollup -c', function (err, stdout, stderr) {
  148. console.log(stdout);
  149. console.log(stderr);
  150. });
  151. });
  152. gulp.task('watch', gulp.parallel("build", "pack", "webserver", async function() {
  153. let watchlist = [
  154. 'src/**/*.js',
  155. 'src/**/**/*.js',
  156. 'src/**/*.css',
  157. 'src/**/*.html',
  158. 'src/**/*.vs',
  159. 'src/**/*.fs',
  160. 'resources/**/*',
  161. 'examples//**/*.json',
  162. '!resources/icons/index.html',
  163. ];
  164. watch(watchlist, gulp.series("build", "pack"));
  165. }));