itowns 2.45.1-next.0 → 2.45.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (185) hide show
  1. package/dist/455.js +2 -0
  2. package/dist/455.js.map +1 -0
  3. package/dist/debug.js +3 -0
  4. package/dist/debug.js.LICENSE.txt +13 -0
  5. package/dist/debug.js.map +1 -0
  6. package/dist/itowns.js +3 -0
  7. package/dist/itowns.js.LICENSE.txt +5 -0
  8. package/dist/itowns.js.map +1 -0
  9. package/dist/itowns_lasparser.js +2 -0
  10. package/dist/itowns_lasparser.js.map +1 -0
  11. package/dist/itowns_lasworker.js +2 -0
  12. package/dist/itowns_lasworker.js.map +1 -0
  13. package/dist/itowns_potree2worker.js +2 -0
  14. package/dist/itowns_potree2worker.js.map +1 -0
  15. package/dist/itowns_widgets.js +2 -0
  16. package/dist/itowns_widgets.js.map +1 -0
  17. package/lib/Controls/FirstPersonControls.js +308 -0
  18. package/lib/Controls/FlyControls.js +175 -0
  19. package/lib/Controls/GlobeControls.js +1178 -0
  20. package/lib/Controls/PlanarControls.js +1025 -0
  21. package/lib/Controls/StateControl.js +432 -0
  22. package/lib/Controls/StreetControls.js +392 -0
  23. package/lib/Converter/Feature2Mesh.js +612 -0
  24. package/lib/Converter/Feature2Texture.js +174 -0
  25. package/lib/Converter/convertToTile.js +70 -0
  26. package/lib/Converter/textureConverter.js +43 -0
  27. package/lib/Core/3DTiles/C3DTBatchTable.js +131 -0
  28. package/lib/Core/3DTiles/C3DTBatchTableHierarchyExtension.js +96 -0
  29. package/lib/Core/3DTiles/C3DTBoundingVolume.js +156 -0
  30. package/lib/Core/3DTiles/C3DTExtensions.js +97 -0
  31. package/lib/Core/3DTiles/C3DTFeature.js +110 -0
  32. package/lib/Core/3DTiles/C3DTilesEnums.js +20 -0
  33. package/lib/Core/3DTiles/C3DTileset.js +99 -0
  34. package/lib/Core/3DTiles/utils/BinaryPropertyAccessor.js +100 -0
  35. package/lib/Core/AnimationPlayer.js +142 -0
  36. package/lib/Core/CopcNode.js +174 -0
  37. package/lib/Core/Deprecated/Undeprecator.js +74 -0
  38. package/lib/Core/EntwinePointTileNode.js +126 -0
  39. package/lib/Core/Feature.js +488 -0
  40. package/lib/Core/Geographic/GeoidGrid.js +108 -0
  41. package/lib/Core/Label.js +222 -0
  42. package/lib/Core/MainLoop.js +209 -0
  43. package/lib/Core/Picking.js +255 -0
  44. package/lib/Core/PointCloudNode.js +42 -0
  45. package/lib/Core/Potree2Node.js +206 -0
  46. package/lib/Core/Potree2PointAttributes.js +139 -0
  47. package/lib/Core/PotreeNode.js +101 -0
  48. package/lib/Core/Prefab/Globe/Atmosphere.js +293 -0
  49. package/lib/Core/Prefab/Globe/GlobeLayer.js +152 -0
  50. package/lib/Core/Prefab/Globe/GlobeTileBuilder.js +110 -0
  51. package/lib/Core/Prefab/Globe/SkyShader.js +78 -0
  52. package/lib/Core/Prefab/GlobeView.js +155 -0
  53. package/lib/Core/Prefab/Planar/PlanarLayer.js +59 -0
  54. package/lib/Core/Prefab/Planar/PlanarTileBuilder.js +71 -0
  55. package/lib/Core/Prefab/PlanarView.js +62 -0
  56. package/lib/Core/Prefab/TileBuilder.js +82 -0
  57. package/lib/Core/Prefab/computeBufferTileGeometry.js +248 -0
  58. package/lib/Core/Scheduler/Cache.js +17 -0
  59. package/lib/Core/Scheduler/CancelledCommandException.js +15 -0
  60. package/lib/Core/Scheduler/Scheduler.js +294 -0
  61. package/lib/Core/Style.js +660 -0
  62. package/lib/Core/StyleOptions.js +486 -0
  63. package/lib/Core/System/Capabilities.js +63 -0
  64. package/lib/Core/Tile/Tile.js +205 -0
  65. package/lib/Core/Tile/TileGrid.js +49 -0
  66. package/lib/Core/TileGeometry.js +124 -0
  67. package/lib/Core/TileMesh.js +108 -0
  68. package/lib/Core/View.js +1115 -0
  69. package/lib/Layer/C3DTilesLayer.js +459 -0
  70. package/lib/Layer/ColorLayer.js +154 -0
  71. package/lib/Layer/CopcLayer.js +63 -0
  72. package/lib/Layer/ElevationLayer.js +139 -0
  73. package/lib/Layer/EntwinePointTileLayer.js +71 -0
  74. package/lib/Layer/FeatureGeometryLayer.js +77 -0
  75. package/lib/Layer/GeoidLayer.js +80 -0
  76. package/lib/Layer/GeometryLayer.js +233 -0
  77. package/lib/Layer/InfoLayer.js +64 -0
  78. package/lib/Layer/LabelLayer.js +469 -0
  79. package/lib/Layer/Layer.js +335 -0
  80. package/lib/Layer/LayerUpdateState.js +89 -0
  81. package/lib/Layer/LayerUpdateStrategy.js +80 -0
  82. package/lib/Layer/OGC3DTilesLayer.js +543 -0
  83. package/lib/Layer/OrientedImageLayer.js +227 -0
  84. package/lib/Layer/PointCloudLayer.js +405 -0
  85. package/lib/Layer/Potree2Layer.js +171 -0
  86. package/lib/Layer/PotreeLayer.js +72 -0
  87. package/lib/Layer/RasterLayer.js +37 -0
  88. package/lib/Layer/ReferencingLayerProperties.js +62 -0
  89. package/lib/Layer/TiledGeometryLayer.js +459 -0
  90. package/lib/Loader/LASLoader.js +193 -0
  91. package/lib/Loader/Potree2BrotliLoader.js +261 -0
  92. package/lib/Loader/Potree2Loader.js +207 -0
  93. package/lib/Main.js +113 -0
  94. package/lib/MainBundle.js +4 -0
  95. package/lib/Parser/B3dmParser.js +174 -0
  96. package/lib/Parser/CameraCalibrationParser.js +94 -0
  97. package/lib/Parser/GDFParser.js +72 -0
  98. package/lib/Parser/GTXParser.js +75 -0
  99. package/lib/Parser/GeoJsonParser.js +212 -0
  100. package/lib/Parser/GpxParser.js +25 -0
  101. package/lib/Parser/ISGParser.js +71 -0
  102. package/lib/Parser/KMLParser.js +25 -0
  103. package/lib/Parser/LASParser.js +137 -0
  104. package/lib/Parser/MapBoxUrlParser.js +83 -0
  105. package/lib/Parser/PntsParser.js +131 -0
  106. package/lib/Parser/Potree2BinParser.js +92 -0
  107. package/lib/Parser/PotreeBinParser.js +106 -0
  108. package/lib/Parser/PotreeCinParser.js +29 -0
  109. package/lib/Parser/ShapefileParser.js +78 -0
  110. package/lib/Parser/VectorTileParser.js +215 -0
  111. package/lib/Parser/XbilParser.js +120 -0
  112. package/lib/Parser/deprecated/LegacyGLTFLoader.js +1386 -0
  113. package/lib/Parser/iGLTFLoader.js +168 -0
  114. package/lib/Process/3dTilesProcessing.js +304 -0
  115. package/lib/Process/FeatureProcessing.js +76 -0
  116. package/lib/Process/LayeredMaterialNodeProcessing.js +229 -0
  117. package/lib/Process/ObjectRemovalHelper.js +97 -0
  118. package/lib/Process/handlerNodeError.js +23 -0
  119. package/lib/Provider/3dTilesProvider.js +149 -0
  120. package/lib/Provider/DataSourceProvider.js +24 -0
  121. package/lib/Provider/Fetcher.js +233 -0
  122. package/lib/Provider/PointCloudProvider.js +45 -0
  123. package/lib/Provider/TileProvider.js +16 -0
  124. package/lib/Provider/URLBuilder.js +116 -0
  125. package/lib/Renderer/Camera.js +281 -0
  126. package/lib/Renderer/Color.js +56 -0
  127. package/lib/Renderer/ColorLayersOrdering.js +115 -0
  128. package/lib/Renderer/CommonMaterial.js +31 -0
  129. package/lib/Renderer/Label2DRenderer.js +192 -0
  130. package/lib/Renderer/LayeredMaterial.js +243 -0
  131. package/lib/Renderer/OBB.js +150 -0
  132. package/lib/Renderer/OrientedImageCamera.js +118 -0
  133. package/lib/Renderer/OrientedImageMaterial.js +167 -0
  134. package/lib/Renderer/PointsMaterial.js +485 -0
  135. package/lib/Renderer/RasterTile.js +243 -0
  136. package/lib/Renderer/RenderMode.js +31 -0
  137. package/lib/Renderer/Shader/ShaderChunk.js +160 -0
  138. package/lib/Renderer/Shader/ShaderUtils.js +47 -0
  139. package/lib/Renderer/SphereHelper.js +17 -0
  140. package/lib/Renderer/WebXR.js +51 -0
  141. package/lib/Renderer/c3DEngine.js +214 -0
  142. package/lib/Source/C3DTilesGoogleSource.js +74 -0
  143. package/lib/Source/C3DTilesIonSource.js +54 -0
  144. package/lib/Source/C3DTilesSource.js +30 -0
  145. package/lib/Source/CopcSource.js +126 -0
  146. package/lib/Source/EntwinePointTileSource.js +72 -0
  147. package/lib/Source/FileSource.js +188 -0
  148. package/lib/Source/OGC3DTilesGoogleSource.js +29 -0
  149. package/lib/Source/OGC3DTilesIonSource.js +34 -0
  150. package/lib/Source/OGC3DTilesSource.js +21 -0
  151. package/lib/Source/OrientedImageSource.js +59 -0
  152. package/lib/Source/Potree2Source.js +167 -0
  153. package/lib/Source/PotreeSource.js +82 -0
  154. package/lib/Source/Source.js +202 -0
  155. package/lib/Source/TMSSource.js +144 -0
  156. package/lib/Source/VectorTilesSource.js +182 -0
  157. package/lib/Source/WFSSource.js +170 -0
  158. package/lib/Source/WMSSource.js +167 -0
  159. package/lib/Source/WMTSSource.js +92 -0
  160. package/lib/ThreeExtended/capabilities/WebGL.js +69 -0
  161. package/lib/ThreeExtended/libs/ktx-parse.module.js +506 -0
  162. package/lib/ThreeExtended/libs/zstddec.module.js +29 -0
  163. package/lib/ThreeExtended/loaders/DDSLoader.js +200 -0
  164. package/lib/ThreeExtended/loaders/DRACOLoader.js +400 -0
  165. package/lib/ThreeExtended/loaders/GLTFLoader.js +2879 -0
  166. package/lib/ThreeExtended/loaders/KTX2Loader.js +709 -0
  167. package/lib/ThreeExtended/math/ColorSpaces.js +59 -0
  168. package/lib/ThreeExtended/utils/BufferGeometryUtils.js +846 -0
  169. package/lib/ThreeExtended/utils/WorkerPool.js +70 -0
  170. package/lib/Utils/CameraUtils.js +554 -0
  171. package/lib/Utils/DEMUtils.js +350 -0
  172. package/lib/Utils/FeaturesUtils.js +156 -0
  173. package/lib/Utils/Gradients.js +16 -0
  174. package/lib/Utils/ThreeUtils.js +115 -0
  175. package/lib/Utils/gui/C3DTilesStyle.js +218 -0
  176. package/lib/Utils/gui/Main.js +7 -0
  177. package/lib/Utils/gui/Minimap.js +152 -0
  178. package/lib/Utils/gui/Navigation.js +245 -0
  179. package/lib/Utils/gui/Scale.js +104 -0
  180. package/lib/Utils/gui/Searchbar.js +234 -0
  181. package/lib/Utils/gui/Widget.js +80 -0
  182. package/lib/Utils/placeObjectOnGround.js +136 -0
  183. package/lib/Worker/LASLoaderWorker.js +19 -0
  184. package/lib/Worker/Potree2Worker.js +21 -0
  185. package/package.json +2 -2
@@ -0,0 +1,485 @@
1
+ import * as THREE from 'three';
2
+ /* babel-plugin-inline-import './Shader/PointsVS.glsl' */
3
+ const PointsVS = "#include <common>\n#include <fog_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvarying vec4 vColor; // color_pars_vertex\n\n#ifdef USE_POINTS_UV\n varying vec2 vUv;\n uniform mat3 uvTransform;\n#endif\n\n#define NB_CLASS 8.\n\nuniform float size;\nuniform float scale;\n\nuniform bool picking;\nuniform int mode;\n\nuniform vec2 elevationRange;\nuniform vec2 intensityRange;\nuniform vec2 angleRange;\n\nuniform sampler2D classificationTexture;\nuniform sampler2D discreteTexture;\nuniform sampler2D gradientTexture;\nuniform int sizeMode;\nuniform float minAttenuatedSize;\nuniform float maxAttenuatedSize;\n\nattribute vec4 unique_id;\nattribute float intensity;\nattribute float classification;\nattribute float pointSourceID;\n\nattribute float returnNumber;\nattribute float numberOfReturns;\nattribute float scanAngle;\n\nvoid main() {\n vColor = vec4(1.0);\n if (picking) {\n vColor = unique_id;\n } else {\n if (mode == PNTS_MODE_CLASSIFICATION) {\n vec2 uv = vec2(classification/255., 0.5);\n vColor = texture2D(classificationTexture, uv);\n } else if (mode == PNTS_MODE_NORMAL) {\n vColor.rgb = abs(normal);\n } else if (mode == PNTS_MODE_COLOR) {\n#if defined(USE_COLOR)\n vColor.rgb = color.rgb;\n#elif defined(USE_COLOR_ALPHA)\n vColor = color;\n#endif\n } else if (mode == PNTS_MODE_RETURN_NUMBER) {\n vec2 uv = vec2(returnNumber/255., 0.5);\n vColor = texture2D(discreteTexture, uv);\n } else if (mode == PNTS_MODE_RETURN_TYPE) {\n float returnType;\n if (returnNumber > numberOfReturns) {\n returnType = 4.;\n } else if (returnNumber == 1.) {\n if (numberOfReturns == 1.) {\n // single\n returnType = 0.;\n } else {\n // first\n returnType = 1.;\n }\n } else {\n if (returnNumber == numberOfReturns) {\n // last\n returnType = 3.;\n } else {\n // intermediate\n returnType = 2.;\n }\n }\n vec2 uv = vec2(returnType/255., 0.5);\n vColor = texture2D(discreteTexture, uv);\n } else if (mode == PNTS_MODE_RETURN_COUNT) {\n vec2 uv = vec2(numberOfReturns/255., 0.5);\n vColor = texture2D(discreteTexture, uv);\n } else if (mode == PNTS_MODE_POINT_SOURCE_ID) {\n vec2 uv = vec2(mod(pointSourceID, NB_CLASS)/255., 0.5);\n vColor = texture2D(discreteTexture, uv);\n } else if (mode == PNTS_MODE_SCAN_ANGLE) {\n float i = (scanAngle - angleRange.x) / (angleRange.y - angleRange.x);\n vec2 uv = vec2(i, (1. - i));\n vColor = texture2D(gradientTexture, uv);\n } else if (mode == PNTS_MODE_INTENSITY) {\n float i = (intensity - intensityRange.x) / (intensityRange.y - intensityRange.x);\n vec2 uv = vec2(i, (1. - i));\n vColor = texture2D(gradientTexture, uv);\n } else if (mode == PNTS_MODE_ELEVATION) {\n float z = (modelMatrix * vec4(position, 1.0)).z;\n float i = (z - elevationRange.x) / (elevationRange.y - elevationRange.x);\n vec2 uv = vec2(i, (1. - i));\n vColor = texture2D(gradientTexture, uv);\n }\n }\n\n#define USE_COLOR_ALPHA\n#include <morphcolor_vertex>\n#include <begin_vertex>\n#include <morphtarget_vertex>\n#include <project_vertex>\n\n gl_PointSize = size;\n\n if (sizeMode == PNTS_SIZE_MODE_ATTENUATED) {\n bool isPerspective = isPerspectiveMatrix(projectionMatrix);\n\n if (isPerspective) {\n gl_PointSize *= scale / -mvPosition.z;\n gl_PointSize = clamp(gl_PointSize, minAttenuatedSize, maxAttenuatedSize);\n }\n }\n\n#include <logdepthbuf_vertex>\n#include <clipping_planes_vertex>\n#include <worldpos_vertex>\n#include <fog_vertex>\n}\n";
4
+ /* babel-plugin-inline-import './Shader/PointsFS.glsl' */
5
+ const PointsFS = "#define USE_COLOR_ALPHA\n\n#include <color_pars_fragment>\n#include <map_particle_pars_fragment>\n#include <alphatest_pars_fragment>\n#include <alphahash_pars_fragment>\n#include <fog_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\n\nuniform vec3 diffuse;\nuniform float opacity;\n\nuniform bool picking;\nuniform int shape;\n\nvoid main() {\n\n// Early discard (clipping planes and shape)\n#include <clipping_planes_fragment>\n if (shape == PNTS_SHAPE_CIRCLE) {\n //circular rendering in glsl\n if ((length(gl_PointCoord - 0.5) > 0.5)) {\n discard;\n }\n }\n\n#include <logdepthbuf_fragment>\n\n vec4 diffuseColor = vec4(diffuse, opacity);\n#include <map_particle_fragment>\n#include <color_fragment>\n\n#include <alphatest_fragment>\n#include <alphahash_fragment>\n\n vec3 outgoingLight = diffuseColor.rgb;\n#include <opaque_fragment> // gl_FragColor\n#include <tonemapping_fragment>\n#include <fog_fragment>\n#include <premultiplied_alpha_fragment>\n\n}\n";
6
+ import CommonMaterial from "./CommonMaterial.js";
7
+ import Gradients from "../Utils/Gradients.js";
8
+ export const PNTS_MODE = {
9
+ COLOR: 0,
10
+ INTENSITY: 1,
11
+ CLASSIFICATION: 2,
12
+ ELEVATION: 3,
13
+ RETURN_NUMBER: 4,
14
+ RETURN_TYPE: 5,
15
+ RETURN_COUNT: 6,
16
+ POINT_SOURCE_ID: 7,
17
+ SCAN_ANGLE: 8,
18
+ NORMAL: 9
19
+ };
20
+ export const PNTS_SHAPE = {
21
+ CIRCLE: 0,
22
+ SQUARE: 1
23
+ };
24
+ export const PNTS_SIZE_MODE = {
25
+ VALUE: 0,
26
+ ATTENUATED: 1
27
+ };
28
+ const white = new THREE.Color(1.0, 1.0, 1.0);
29
+
30
+ /**
31
+ * Every lidar point can have a classification assigned to it that defines
32
+ * the type of object that has reflected the laser pulse. Lidar points can be
33
+ * classified into a number of categories including bare earth or ground,
34
+ * top of canopy, and water. The different classes are defined using numeric
35
+ * integer codes in the files.
36
+ *
37
+ * @typedef {Object} Classification
38
+ * @property {boolean} visible - category visibility,
39
+ * @property {string} name - category name,
40
+ * @property {THREE.Color} color - category color,
41
+ * @property {number} opacity - category opacity,
42
+ */
43
+
44
+ export const ClassificationScheme = {
45
+ DEFAULT: {
46
+ 0: {
47
+ visible: true,
48
+ name: 'never classified',
49
+ color: new THREE.Color(0.5, 0.5, 0.5),
50
+ opacity: 1.0
51
+ },
52
+ 1: {
53
+ visible: true,
54
+ name: 'unclassified',
55
+ color: new THREE.Color(0.5, 0.5, 0.5),
56
+ opacity: 1.0
57
+ },
58
+ 2: {
59
+ visible: true,
60
+ name: 'ground',
61
+ color: new THREE.Color(0.63, 0.32, 0.18),
62
+ opacity: 1.0
63
+ },
64
+ 3: {
65
+ visible: true,
66
+ name: 'low vegetation',
67
+ color: new THREE.Color(0.0, 1.0, 0.0),
68
+ opacity: 1.0
69
+ },
70
+ 4: {
71
+ visible: true,
72
+ name: 'medium vegetation',
73
+ color: new THREE.Color(0.0, 0.8, 0.0),
74
+ opacity: 1.0
75
+ },
76
+ 5: {
77
+ visible: true,
78
+ name: 'high vegetation',
79
+ color: new THREE.Color(0.0, 0.6, 0.0),
80
+ opacity: 1.0
81
+ },
82
+ 6: {
83
+ visible: true,
84
+ name: 'building',
85
+ color: new THREE.Color(1.0, 0.66, 0.0),
86
+ opacity: 1.0
87
+ },
88
+ 7: {
89
+ visible: true,
90
+ name: 'low point(noise)',
91
+ color: new THREE.Color(1.0, 0.0, 1.0),
92
+ opacity: 1.0
93
+ },
94
+ 8: {
95
+ visible: true,
96
+ name: 'key-point',
97
+ color: new THREE.Color(1.0, 0.0, 0.0),
98
+ opacity: 1.0
99
+ },
100
+ 9: {
101
+ visible: true,
102
+ name: 'water',
103
+ color: new THREE.Color(0.0, 0.0, 1.0),
104
+ opacity: 1.0
105
+ },
106
+ 10: {
107
+ visible: true,
108
+ name: 'rail',
109
+ color: new THREE.Color(0.8, 0.8, 1.0),
110
+ opacity: 1.0
111
+ },
112
+ 11: {
113
+ visible: true,
114
+ name: 'road Surface',
115
+ color: new THREE.Color(0.4, 0.4, 0.7),
116
+ opacity: 1.0
117
+ },
118
+ 12: {
119
+ visible: true,
120
+ name: 'overlap',
121
+ color: new THREE.Color(1.0, 1.0, 0.0),
122
+ opacity: 1.0
123
+ },
124
+ DEFAULT: {
125
+ visible: true,
126
+ name: 'default',
127
+ color: new THREE.Color(0.3, 0.6, 0.6),
128
+ opacity: 1.0
129
+ }
130
+ }
131
+ };
132
+ const DiscreteScheme = {
133
+ DEFAULT: {
134
+ 0: {
135
+ visible: true,
136
+ name: '0',
137
+ color: new THREE.Color('rgb(67, 99, 216)'),
138
+ opacity: 1.0
139
+ },
140
+ 1: {
141
+ visible: true,
142
+ name: '1',
143
+ color: new THREE.Color('rgb(60, 180, 75);'),
144
+ opacity: 1.0
145
+ },
146
+ 2: {
147
+ visible: true,
148
+ name: '2',
149
+ color: new THREE.Color('rgb(255, 255, 25)'),
150
+ opacity: 1.0
151
+ },
152
+ 3: {
153
+ visible: true,
154
+ name: '3',
155
+ color: new THREE.Color('rgb(145, 30, 180)'),
156
+ opacity: 1.0
157
+ },
158
+ 4: {
159
+ visible: true,
160
+ name: '4',
161
+ color: new THREE.Color('rgb(245, 130, 49)'),
162
+ opacity: 1.0
163
+ },
164
+ 5: {
165
+ visible: true,
166
+ name: '5',
167
+ color: new THREE.Color('rgb(230, 25, 75)'),
168
+ opacity: 1.0
169
+ },
170
+ 6: {
171
+ visible: true,
172
+ name: '6',
173
+ color: new THREE.Color('rgb(66, 212, 244)'),
174
+ opacity: 1.0
175
+ },
176
+ 7: {
177
+ visible: true,
178
+ name: '7',
179
+ color: new THREE.Color('rgb(240, 50, 230)'),
180
+ opacity: 1.0
181
+ },
182
+ DEFAULT: {
183
+ visible: true,
184
+ name: 'default',
185
+ color: white,
186
+ opacity: 1.0
187
+ }
188
+ }
189
+ };
190
+
191
+ // Taken from Potree. Copyright (c) 2011-2020, Markus Schütz All rights reserved.
192
+ // https://github.com/potree/potree/blob/develop/src/materials/PointCloudMaterial.js
193
+ function generateGradientTexture(gradient) {
194
+ const size = 64;
195
+
196
+ // create canvas
197
+ const canvas = document.createElement('canvas');
198
+ canvas.width = size;
199
+ canvas.height = size;
200
+
201
+ // get context
202
+ const context = canvas.getContext('2d');
203
+
204
+ // draw gradient
205
+ context.rect(0, 0, size, size);
206
+ const ctxGradient = context.createLinearGradient(0, 0, size, size);
207
+ for (let i = 0; i < gradient.length; i++) {
208
+ const step = gradient[i];
209
+ ctxGradient.addColorStop(step[0], `#${step[1].getHexString()}`);
210
+ }
211
+ context.fillStyle = ctxGradient;
212
+ context.fill();
213
+ const texture = new THREE.CanvasTexture(canvas);
214
+ texture.needsUpdate = true;
215
+ texture.minFilter = THREE.LinearFilter;
216
+ texture.wrap = THREE.RepeatWrapping;
217
+ texture.repeat = 2;
218
+ return texture;
219
+ }
220
+ function recomputeTexture(scheme, texture, nbClass) {
221
+ let needTransparency;
222
+ const data = texture.image.data;
223
+ const width = texture.image.width;
224
+ if (!nbClass) {
225
+ nbClass = Object.keys(scheme).length;
226
+ }
227
+ for (let i = 0; i < width; i++) {
228
+ let color;
229
+ let opacity;
230
+ let visible = true;
231
+ if (scheme[i]) {
232
+ color = scheme[i].color;
233
+ visible = scheme[i].visible;
234
+ opacity = scheme[i].opacity;
235
+ } else if (scheme[i % nbClass]) {
236
+ color = scheme[i % nbClass].color;
237
+ visible = scheme[i % nbClass].visible;
238
+ opacity = scheme[i % nbClass].opacity;
239
+ } else if (scheme.DEFAULT) {
240
+ color = scheme.DEFAULT.color;
241
+ visible = scheme.DEFAULT.visible;
242
+ opacity = scheme.DEFAULT.opacity;
243
+ } else {
244
+ color = white;
245
+ opacity = 1.0;
246
+ }
247
+ const j = 4 * i;
248
+ data[j + 0] = parseInt(255 * color.r, 10);
249
+ data[j + 1] = parseInt(255 * color.g, 10);
250
+ data[j + 2] = parseInt(255 * color.b, 10);
251
+ data[j + 3] = visible ? parseInt(255 * opacity, 10) : 0;
252
+ needTransparency = needTransparency || opacity < 1 || !visible;
253
+ }
254
+ texture.needsUpdate = true;
255
+ return needTransparency;
256
+ }
257
+ class PointsMaterial extends THREE.ShaderMaterial {
258
+ /**
259
+ * @class PointsMaterial
260
+ * @param {object} [options={}] The options
261
+ * @param {number} [options.size=1] point size
262
+ * @param {number} [options.mode=PNTS_MODE.COLOR] display mode.
263
+ * @param {number} [options.shape=PNTS_SHAPE.CIRCLE] rendered points shape.
264
+ * @param {THREE.Vector4} [options.overlayColor=new THREE.Vector4(0, 0, 0, 0)] overlay color.
265
+ * @param {Scheme} [options.classificationScheme] LUT for point classification colorization.
266
+ * @param {Scheme} [options.discreteScheme] LUT for other discret point values colorization.
267
+ * @param {string} [options.gradient] Descrition of the gradient to use for continuous point values.
268
+ * (Default value will be the 'SPECTRAL' gradient from Utils/Gradients)
269
+ * @param {number} [options.sizeMode=PNTS_SIZE_MODE.VALUE] point cloud size mode. Only 'VALUE' or 'ATTENUATED' are possible. VALUE use constant size, ATTENUATED compute size depending on distance from point to camera.
270
+ * @param {number} [options.minAttenuatedSize=3] minimum scale used by 'ATTENUATED' size mode
271
+ * @param {number} [options.maxAttenuatedSize=10] maximum scale used by 'ATTENUATED' size mode
272
+ *
273
+ * @property {THREE.Vector2} [options.intensityRange=new THREE.Vector2(1, 65536)] intensity range (default value will be [1, 65536] if not defined at Layer level).
274
+ * @property {THREE.Vector2} [options.elevationRange=new THREE.Vector2(0, 1000)] elevation range (default value will be [0, 1000] if not defined at Layer level).
275
+ * @property {THREE.Vector2} [options.angleRange=new THREE.Vector2(-90, 90)] scan angle range (default value will be [-90, 90] if not defined at Layer level).
276
+ * @property {Scheme} classificationScheme - Color scheme for point classification values.
277
+ * @property {Scheme} discreteScheme - Color scheme for all other discrete values.
278
+ * @property {object} gradients - Descriptions of all available gradients.
279
+ * @property {object} gradient - Description of the gradient to use for display.
280
+ * @property {THREE.CanvasTexture} gradientTexture - The texture generate from the choosen gradient.
281
+ *
282
+ * @example
283
+ * // change color category classification
284
+ * const pointMaterial = new PointsMaterial();
285
+ * pointMaterial.classification[3].color.setStyle('red');
286
+ * pointMaterial.recomputeClassification();
287
+ */
288
+ constructor() {
289
+ let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
290
+ const gradients = {
291
+ ...options.gradient,
292
+ ...Gradients
293
+ };
294
+ options.gradient = Object.values(gradients)[0];
295
+ const {
296
+ intensityRange = new THREE.Vector2(1, 65536),
297
+ elevationRange = new THREE.Vector2(0, 1000),
298
+ angleRange = new THREE.Vector2(-90, 90),
299
+ classificationScheme = ClassificationScheme.DEFAULT,
300
+ discreteScheme = DiscreteScheme.DEFAULT,
301
+ size = 1,
302
+ mode = PNTS_MODE.COLOR,
303
+ shape = PNTS_SHAPE.CIRCLE,
304
+ sizeMode = PNTS_SIZE_MODE.ATTENUATED,
305
+ minAttenuatedSize = 3,
306
+ maxAttenuatedSize = 10,
307
+ gradient,
308
+ scale = 0.05 * 0.5 / Math.tan(1.0 / 2.0),
309
+ ...materialOptions
310
+ } = options;
311
+ super({
312
+ ...materialOptions,
313
+ fog: true,
314
+ precision: 'highp',
315
+ vertexColors: true
316
+ });
317
+ this.uniforms = THREE.UniformsUtils.merge([
318
+ // THREE.PointsMaterial uniforms
319
+ THREE.UniformsLib.points, THREE.UniformsLib.fog]);
320
+ this.vertexShader = PointsVS;
321
+ this.fragmentShader = PointsFS;
322
+ this.userData.needTransparency = {};
323
+ this.gradients = gradients;
324
+ this.gradientTexture = new THREE.CanvasTexture();
325
+ CommonMaterial.setDefineMapping(this, 'PNTS_MODE', PNTS_MODE);
326
+ CommonMaterial.setDefineMapping(this, 'PNTS_SHAPE', PNTS_SHAPE);
327
+ CommonMaterial.setDefineMapping(this, 'PNTS_SIZE_MODE', PNTS_SIZE_MODE);
328
+ this.size = size;
329
+ CommonMaterial.setUniformProperty(this, 'mode', mode);
330
+ CommonMaterial.setUniformProperty(this, 'shape', shape);
331
+ CommonMaterial.setUniformProperty(this, 'picking', false);
332
+ CommonMaterial.setUniformProperty(this, 'opacity', this.opacity);
333
+ CommonMaterial.setUniformProperty(this, 'intensityRange', intensityRange);
334
+ CommonMaterial.setUniformProperty(this, 'elevationRange', elevationRange);
335
+ CommonMaterial.setUniformProperty(this, 'angleRange', angleRange);
336
+ CommonMaterial.setUniformProperty(this, 'sizeMode', sizeMode);
337
+ CommonMaterial.setUniformProperty(this, 'scale', scale);
338
+ CommonMaterial.setUniformProperty(this, 'minAttenuatedSize', minAttenuatedSize);
339
+ CommonMaterial.setUniformProperty(this, 'maxAttenuatedSize', maxAttenuatedSize);
340
+
341
+ // add classification texture to apply classification lut.
342
+ const data = new Uint8Array(256 * 4);
343
+ const texture = new THREE.DataTexture(data, 256, 1, THREE.RGBAFormat);
344
+ texture.needsUpdate = true;
345
+ texture.magFilter = THREE.NearestFilter;
346
+ CommonMaterial.setUniformProperty(this, 'classificationTexture', texture);
347
+
348
+ // add texture to applying the discrete lut.
349
+ const dataLUT = new Uint8Array(256 * 4);
350
+ const textureLUT = new THREE.DataTexture(dataLUT, 256, 1, THREE.RGBAFormat);
351
+ textureLUT.needsUpdate = true;
352
+ textureLUT.magFilter = THREE.NearestFilter;
353
+ CommonMaterial.setUniformProperty(this, 'discreteTexture', textureLUT);
354
+
355
+ // Classification and other discrete values scheme
356
+ this.classificationScheme = classificationScheme;
357
+ this.discreteScheme = discreteScheme;
358
+
359
+ // Update classification and discrete Texture
360
+ this.recomputeClassification();
361
+ this.recomputeDiscreteTexture();
362
+
363
+ // Gradient texture for continuous values
364
+ this.gradient = gradient;
365
+ CommonMaterial.setUniformProperty(this, 'gradientTexture', this.gradientTexture);
366
+ }
367
+
368
+ /**
369
+ * Copy the parameters from the passed material into this material.
370
+ * @override
371
+ * @param {THREE.PointsMaterial} source
372
+ * @returns {this}
373
+ */
374
+ copy(source) {
375
+ // Manually copy this needTransparency if source doesn't have one. Prevents losing it when copying a three
376
+ // PointsMaterial into this PointsMaterial
377
+ const needTransparency = source.userData.needTransparency !== undefined ? source.userData.needTransparency : this.userData.needTransparency;
378
+ if (source.isShaderMaterial) {
379
+ super.copy(source);
380
+ } else {
381
+ THREE.Material.prototype.copy.call(this, source);
382
+ }
383
+
384
+ // Parameters of THREE.PointsMaterial
385
+ this.color.copy(source.color);
386
+ this.map = source.map;
387
+ this.alphaMap = source.alphaMap;
388
+ this.size = source.size;
389
+ this.sizeAttenuation = source.sizeAttenuation;
390
+ this.fog = source.fog;
391
+ this.userData.needTransparency = needTransparency;
392
+ return this;
393
+ }
394
+
395
+ /** @returns {THREE.Color} */
396
+ get color() {
397
+ return this.uniforms.diffuse.value;
398
+ }
399
+
400
+ /** @param {THREE.Color} color */
401
+ set color(color) {
402
+ this.uniforms.diffuse.value.copy(color);
403
+ }
404
+
405
+ /** @returns {THREE.Texture | null} */
406
+ get map() {
407
+ return this.uniforms.map.value;
408
+ }
409
+
410
+ /** @param {THREE.Texture | null} map */
411
+ set map(map) {
412
+ this.uniforms.map.value = map;
413
+ if (!map) {
414
+ return;
415
+ }
416
+ if (map.matrixAutoUpdate) {
417
+ map.updateMatrix();
418
+ }
419
+ this.uniforms.uvTransform.value.copy(map.matrix);
420
+ }
421
+
422
+ /** @returns {THREE.Texture | null} */
423
+ get alphaMap() {
424
+ return this.uniforms.alphaMap.value;
425
+ }
426
+
427
+ /** @param {THREE.Texture | null} map */
428
+ set alphaMap(map) {
429
+ this.uniforms.alphaMap.value = map;
430
+ if (!map) {
431
+ return;
432
+ }
433
+ if (map.matrixAutoUpdate) {
434
+ map.updateMatrix();
435
+ }
436
+ this.uniforms.alphaMapTransform.value.copy(map.matrix);
437
+ }
438
+
439
+ /** @returns {number} */
440
+ get size() {
441
+ return this.uniforms.size.value;
442
+ }
443
+
444
+ /** @param {number} size */
445
+ set size(size) {
446
+ this.uniforms.size.value = size;
447
+ }
448
+
449
+ /** @returns {boolean} */
450
+ get sizeAttenuation() {
451
+ return this.sizeMode !== PNTS_SIZE_MODE.VALUE;
452
+ }
453
+
454
+ /** @param {boolean} value */
455
+ set sizeAttenuation(value) {
456
+ this.sizeMode = value ? PNTS_SIZE_MODE.ATTENUATED : PNTS_SIZE_MODE.VALUE;
457
+ }
458
+ recomputeClassification() {
459
+ const needTransparency = recomputeTexture(this.classificationScheme, this.classificationTexture, 256);
460
+ this.userData.needTransparency[PNTS_MODE.CLASSIFICATION] = needTransparency;
461
+ this.dispatchEvent({
462
+ type: 'material_property_changed',
463
+ target: this.uniforms
464
+ });
465
+ }
466
+ recomputeDiscreteTexture() {
467
+ const needTransparency = recomputeTexture(this.discreteScheme, this.discreteTexture);
468
+ this.userData.needTransparency[PNTS_MODE.RETURN_NUMBER] = needTransparency;
469
+ this.userData.needTransparency[PNTS_MODE.RETURN_TYPE] = needTransparency;
470
+ this.userData.needTransparency[PNTS_MODE.RETURN_COUNT] = needTransparency;
471
+ this.userData.needTransparency[PNTS_MODE.POINT_SOURCE_ID] = needTransparency;
472
+ this.dispatchEvent({
473
+ type: 'material_property_changed',
474
+ target: this.uniforms
475
+ });
476
+ }
477
+ enablePicking(picking) {
478
+ this.picking = picking;
479
+ this.blending = picking ? THREE.NoBlending : THREE.NormalBlending;
480
+ }
481
+ set gradient(value) {
482
+ this.gradientTexture = generateGradientTexture(value);
483
+ }
484
+ }
485
+ export default PointsMaterial;