@xeokit/xeokit-sdk 2.4.0-alpha-81 → 2.4.0-alpha-82

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 (384) hide show
  1. package/package.json +2 -1
  2. package/src/extras/ContextMenu/ContextMenu.js +907 -0
  3. package/src/extras/ContextMenu/index.js +1 -0
  4. package/src/extras/index.js +1 -0
  5. package/src/index.js +3 -0
  6. package/src/plugins/AngleMeasurementsPlugin/AngleMeasurement.js +658 -0
  7. package/src/plugins/AngleMeasurementsPlugin/AngleMeasurementsControl.js +418 -0
  8. package/src/plugins/AngleMeasurementsPlugin/AngleMeasurementsPlugin.js +400 -0
  9. package/src/plugins/AngleMeasurementsPlugin/index.js +1 -0
  10. package/src/plugins/AnnotationsPlugin/Annotation.js +368 -0
  11. package/src/plugins/AnnotationsPlugin/AnnotationsPlugin.js +583 -0
  12. package/src/plugins/AnnotationsPlugin/index.js +1 -0
  13. package/src/plugins/AxisGizmoPlugin/AxisGizmoPlugin.js +333 -0
  14. package/src/plugins/AxisGizmoPlugin/index.js +1 -0
  15. package/src/plugins/BCFViewpointsPlugin/BCFViewpointsPlugin.js +955 -0
  16. package/src/plugins/BCFViewpointsPlugin/index.js +1 -0
  17. package/src/plugins/CityJSONLoaderPlugin/CityJSONDefaultDataSource.js +29 -0
  18. package/src/plugins/CityJSONLoaderPlugin/CityJSONLoaderPlugin.js +751 -0
  19. package/src/plugins/CityJSONLoaderPlugin/index.js +1 -0
  20. package/src/plugins/DistanceMeasurementsPlugin/DistanceMeasurement.js +870 -0
  21. package/src/plugins/DistanceMeasurementsPlugin/DistanceMeasurementsControl.js +376 -0
  22. package/src/plugins/DistanceMeasurementsPlugin/DistanceMeasurementsPlugin.js +454 -0
  23. package/src/plugins/DistanceMeasurementsPlugin/index.js +1 -0
  24. package/src/plugins/FaceAlignedSectionPlanesPlugin/FaceAlignedSectionPlanesControl.js +639 -0
  25. package/src/plugins/FaceAlignedSectionPlanesPlugin/FaceAlignedSectionPlanesPlugin.js +436 -0
  26. package/src/plugins/FaceAlignedSectionPlanesPlugin/Overview.js +247 -0
  27. package/src/plugins/FaceAlignedSectionPlanesPlugin/Plane.js +167 -0
  28. package/src/plugins/FaceAlignedSectionPlanesPlugin/index.js +1 -0
  29. package/src/plugins/FastNavPlugin/FastNavPlugin.js +429 -0
  30. package/src/plugins/FastNavPlugin/index.js +1 -0
  31. package/src/plugins/GLTFLoaderPlugin/GLTFDefaultDataSource.js +139 -0
  32. package/src/plugins/GLTFLoaderPlugin/GLTFLoaderPlugin.js +421 -0
  33. package/src/plugins/GLTFLoaderPlugin/GLTFSceneModelLoader.js +669 -0
  34. package/src/plugins/GLTFLoaderPlugin/index.js +2 -0
  35. package/src/plugins/LASLoaderPlugin/LASDefaultDataSource.js +58 -0
  36. package/src/plugins/LASLoaderPlugin/LASLoaderPlugin.js +518 -0
  37. package/src/plugins/LASLoaderPlugin/index.js +1 -0
  38. package/src/plugins/LASLoaderPlugin/loadLASHeader.js +183 -0
  39. package/src/plugins/NavCubePlugin/CubeTextureCanvas.js +289 -0
  40. package/src/plugins/NavCubePlugin/NavCubePlugin.js +752 -0
  41. package/src/plugins/NavCubePlugin/index.js +1 -0
  42. package/src/plugins/OBJLoaderPlugin/OBJLoaderPlugin.js +145 -0
  43. package/src/plugins/OBJLoaderPlugin/OBJSceneGraphLoader.js +777 -0
  44. package/src/plugins/OBJLoaderPlugin/index.js +1 -0
  45. package/src/plugins/STLLoaderPlugin/STLDefaultDataSource.js +33 -0
  46. package/src/plugins/STLLoaderPlugin/STLLoaderPlugin.js +274 -0
  47. package/src/plugins/STLLoaderPlugin/STLSceneGraphLoader.js +313 -0
  48. package/src/plugins/STLLoaderPlugin/index.js +2 -0
  49. package/src/plugins/SectionPlanesPlugin/Control.js +1328 -0
  50. package/src/plugins/SectionPlanesPlugin/Overview.js +249 -0
  51. package/src/plugins/SectionPlanesPlugin/Plane.js +169 -0
  52. package/src/plugins/SectionPlanesPlugin/SectionPlanesPlugin.js +404 -0
  53. package/src/plugins/SectionPlanesPlugin/index.js +1 -0
  54. package/src/plugins/SkyboxesPlugin/SkyboxesPlugin.js +134 -0
  55. package/src/plugins/SkyboxesPlugin/index.js +1 -0
  56. package/src/plugins/StoreyViewsPlugin/IFCStoreyPlanObjectStates.js +77 -0
  57. package/src/plugins/StoreyViewsPlugin/Storey.js +61 -0
  58. package/src/plugins/StoreyViewsPlugin/StoreyMap.js +57 -0
  59. package/src/plugins/StoreyViewsPlugin/StoreyViewsPlugin.js +825 -0
  60. package/src/plugins/StoreyViewsPlugin/index.js +1 -0
  61. package/src/plugins/TreeViewPlugin/TreeViewNode.js +97 -0
  62. package/src/plugins/TreeViewPlugin/TreeViewPlugin.js +1424 -0
  63. package/src/plugins/TreeViewPlugin/index.js +1 -0
  64. package/src/plugins/ViewCullPlugin/ViewCullPlugin.js +295 -0
  65. package/src/plugins/ViewCullPlugin/index.js +1 -0
  66. package/src/plugins/WebIFCLoaderPlugin/WebIFCDefaultDataSource.js +58 -0
  67. package/src/plugins/WebIFCLoaderPlugin/WebIFCLoaderPlugin.js +942 -0
  68. package/src/plugins/WebIFCLoaderPlugin/index.js +1 -0
  69. package/src/plugins/XKTLoaderPlugin/XKTDefaultDataSource.js +95 -0
  70. package/src/plugins/XKTLoaderPlugin/XKTLoaderPlugin.js +1107 -0
  71. package/src/plugins/XKTLoaderPlugin/index.js +2 -0
  72. package/src/plugins/XKTLoaderPlugin/parsers/ParserV1.js +169 -0
  73. package/src/plugins/XKTLoaderPlugin/parsers/ParserV10.js +656 -0
  74. package/src/plugins/XKTLoaderPlugin/parsers/ParserV2.js +230 -0
  75. package/src/plugins/XKTLoaderPlugin/parsers/ParserV3.js +223 -0
  76. package/src/plugins/XKTLoaderPlugin/parsers/ParserV4.js +283 -0
  77. package/src/plugins/XKTLoaderPlugin/parsers/ParserV5.js +246 -0
  78. package/src/plugins/XKTLoaderPlugin/parsers/ParserV6.js +301 -0
  79. package/src/plugins/XKTLoaderPlugin/parsers/ParserV7.js +439 -0
  80. package/src/plugins/XKTLoaderPlugin/parsers/ParserV8.js +563 -0
  81. package/src/plugins/XKTLoaderPlugin/parsers/ParserV9.js +514 -0
  82. package/src/plugins/XKTLoaderPlugin/parsers/lib/pako.js +2 -0
  83. package/src/plugins/XML3DLoaderPlugin/XML3DLoaderPlugin.js +238 -0
  84. package/src/plugins/XML3DLoaderPlugin/XML3DSceneGraphLoader.js +1279 -0
  85. package/src/plugins/XML3DLoaderPlugin/index.js +1 -0
  86. package/src/plugins/XML3DLoaderPlugin/zipjs/.jshintrc +11 -0
  87. package/src/plugins/XML3DLoaderPlugin/zipjs/deflate.js +2060 -0
  88. package/src/plugins/XML3DLoaderPlugin/zipjs/inflate.js +2155 -0
  89. package/src/plugins/XML3DLoaderPlugin/zipjs/mime-types.js +1002 -0
  90. package/src/plugins/XML3DLoaderPlugin/zipjs/pako/codecs.js +64 -0
  91. package/src/plugins/XML3DLoaderPlugin/zipjs/z-worker.js +153 -0
  92. package/src/plugins/XML3DLoaderPlugin/zipjs/zip-ext.js +267 -0
  93. package/src/plugins/XML3DLoaderPlugin/zipjs/zip-fs.js +553 -0
  94. package/src/plugins/XML3DLoaderPlugin/zipjs/zip.js +991 -0
  95. package/src/plugins/XML3DLoaderPlugin/zipjs/zlib-asm/codecs.js +49 -0
  96. package/src/plugins/index.js +21 -0
  97. package/src/plugins/lib/culling/ObjectCullStates.js +208 -0
  98. package/src/plugins/lib/earcut.js +677 -0
  99. package/src/plugins/lib/html/Dot.js +145 -0
  100. package/src/plugins/lib/html/Label.js +156 -0
  101. package/src/plugins/lib/html/Wire.js +191 -0
  102. package/src/viewer/Configs.js +79 -0
  103. package/src/viewer/Plugin.js +224 -0
  104. package/src/viewer/Viewer.js +535 -0
  105. package/src/viewer/index.js +5 -0
  106. package/src/viewer/localization/LocaleService.js +475 -0
  107. package/src/viewer/metadata/IFCObjectDefaultColors.js +162 -0
  108. package/src/viewer/metadata/IFCObjectDefaults.js +17 -0
  109. package/src/viewer/metadata/MetaModel.js +389 -0
  110. package/src/viewer/metadata/MetaObject.js +218 -0
  111. package/src/viewer/metadata/MetaScene.js +336 -0
  112. package/src/viewer/metadata/Property.js +55 -0
  113. package/src/viewer/metadata/PropertySet.js +77 -0
  114. package/src/viewer/scene/Bitmap/Bitmap.js +470 -0
  115. package/src/viewer/scene/Bitmap/index.js +1 -0
  116. package/src/viewer/scene/CameraControl/CameraControl.js +1737 -0
  117. package/src/viewer/scene/CameraControl/lib/CameraUpdater.js +312 -0
  118. package/src/viewer/scene/CameraControl/lib/controllers/PanController.js +112 -0
  119. package/src/viewer/scene/CameraControl/lib/controllers/PickController.js +264 -0
  120. package/src/viewer/scene/CameraControl/lib/controllers/PivotController.js +384 -0
  121. package/src/viewer/scene/CameraControl/lib/handlers/KeyboardAxisViewHandler.js +122 -0
  122. package/src/viewer/scene/CameraControl/lib/handlers/KeyboardPanRotateDollyHandler.js +183 -0
  123. package/src/viewer/scene/CameraControl/lib/handlers/MouseMiscHandler.js +68 -0
  124. package/src/viewer/scene/CameraControl/lib/handlers/MousePanRotateDollyHandler.js +345 -0
  125. package/src/viewer/scene/CameraControl/lib/handlers/MousePickHandler.js +372 -0
  126. package/src/viewer/scene/CameraControl/lib/handlers/TouchPanRotateAndDollyHandler.js +269 -0
  127. package/src/viewer/scene/CameraControl/lib/handlers/TouchPickHandler.js +235 -0
  128. package/src/viewer/scene/Component.js +907 -0
  129. package/src/viewer/scene/Entity.js +502 -0
  130. package/src/viewer/scene/ImagePlane/ImagePlane.js +570 -0
  131. package/src/viewer/scene/ImagePlane/index.js +1 -0
  132. package/src/viewer/scene/LineSet/LineSet.js +164 -0
  133. package/src/viewer/scene/LineSet/index.js +1 -0
  134. package/src/viewer/scene/camera/Camera.js +912 -0
  135. package/src/viewer/scene/camera/CameraFlightAnimation.js +669 -0
  136. package/src/viewer/scene/camera/CameraPath.js +194 -0
  137. package/src/viewer/scene/camera/CameraPathAnimation.js +326 -0
  138. package/src/viewer/scene/camera/CustomProjection.js +149 -0
  139. package/src/viewer/scene/camera/Frustum.js +316 -0
  140. package/src/viewer/scene/camera/Ortho.js +286 -0
  141. package/src/viewer/scene/camera/Perspective.js +304 -0
  142. package/src/viewer/scene/camera/index.js +2 -0
  143. package/src/viewer/scene/canvas/Canvas.js +492 -0
  144. package/src/viewer/scene/canvas/Spinner.js +323 -0
  145. package/src/viewer/scene/constants/constants.js +371 -0
  146. package/src/viewer/scene/core.js +233 -0
  147. package/src/viewer/scene/geometry/Geometry.js +33 -0
  148. package/src/viewer/scene/geometry/ReadableGeometry.js +682 -0
  149. package/src/viewer/scene/geometry/VBOGeometry.js +319 -0
  150. package/src/viewer/scene/geometry/builders/buildBoxGeometry.js +238 -0
  151. package/src/viewer/scene/geometry/builders/buildBoxLinesGeometry.js +106 -0
  152. package/src/viewer/scene/geometry/builders/buildCylinderGeometry.js +271 -0
  153. package/src/viewer/scene/geometry/builders/buildGridGeometry.js +102 -0
  154. package/src/viewer/scene/geometry/builders/buildPlaneGeometry.js +168 -0
  155. package/src/viewer/scene/geometry/builders/buildSphereGeometry.js +161 -0
  156. package/src/viewer/scene/geometry/builders/buildTorusGeometry.js +172 -0
  157. package/src/viewer/scene/geometry/builders/buildVectorTextGeometry.js +1721 -0
  158. package/src/viewer/scene/geometry/builders/index.js +8 -0
  159. package/src/viewer/scene/geometry/index.js +4 -0
  160. package/src/viewer/scene/geometry/loaders/index.js +2 -0
  161. package/src/viewer/scene/geometry/loaders/load3DSGeometry.js +103 -0
  162. package/src/viewer/scene/geometry/loaders/loadOBJGeometry.js +130 -0
  163. package/src/viewer/scene/index.js +23 -0
  164. package/src/viewer/scene/input/Input.js +1325 -0
  165. package/src/viewer/scene/libs/k3d.js +1032 -0
  166. package/src/viewer/scene/lights/AmbientLight.js +175 -0
  167. package/src/viewer/scene/lights/CubeTexture.js +156 -0
  168. package/src/viewer/scene/lights/DirLight.js +314 -0
  169. package/src/viewer/scene/lights/Light.js +29 -0
  170. package/src/viewer/scene/lights/LightMap.js +77 -0
  171. package/src/viewer/scene/lights/PointLight.js +395 -0
  172. package/src/viewer/scene/lights/ReflectionMap.js +79 -0
  173. package/src/viewer/scene/lights/Shadow.js +138 -0
  174. package/src/viewer/scene/lights/index.js +5 -0
  175. package/src/viewer/scene/lod/LOD.js +162 -0
  176. package/src/viewer/scene/lod/LODCullingManager.js +83 -0
  177. package/src/viewer/scene/lod/LODState.js +125 -0
  178. package/src/viewer/scene/lod/index.js +1 -0
  179. package/src/viewer/scene/marker/Marker.js +383 -0
  180. package/src/viewer/scene/marker/SpriteMarker.js +356 -0
  181. package/src/viewer/scene/marker/index.js +2 -0
  182. package/src/viewer/scene/materials/EdgeMaterial.js +359 -0
  183. package/src/viewer/scene/materials/EmphasisMaterial.js +613 -0
  184. package/src/viewer/scene/materials/Fresnel.js +222 -0
  185. package/src/viewer/scene/materials/LambertMaterial.js +378 -0
  186. package/src/viewer/scene/materials/LinesMaterial.js +169 -0
  187. package/src/viewer/scene/materials/Material.js +39 -0
  188. package/src/viewer/scene/materials/MetallicMaterial.js +820 -0
  189. package/src/viewer/scene/materials/PhongMaterial.js +860 -0
  190. package/src/viewer/scene/materials/PointsMaterial.js +409 -0
  191. package/src/viewer/scene/materials/SpecularMaterial.js +807 -0
  192. package/src/viewer/scene/materials/Texture.js +513 -0
  193. package/src/viewer/scene/materials/index.js +8 -0
  194. package/src/viewer/scene/math/Frustum.js +118 -0
  195. package/src/viewer/scene/math/buildEdgeIndices.js +162 -0
  196. package/src/viewer/scene/math/geometryCompressionUtils.js +365 -0
  197. package/src/viewer/scene/math/index.js +3 -0
  198. package/src/viewer/scene/math/math.js +5363 -0
  199. package/src/viewer/scene/math/rtcCoords.js +139 -0
  200. package/src/viewer/scene/mementos/CameraMemento.js +200 -0
  201. package/src/viewer/scene/mementos/ModelMemento.js +263 -0
  202. package/src/viewer/scene/mementos/ObjectsMemento.js +259 -0
  203. package/src/viewer/scene/mementos/index.js +3 -0
  204. package/src/viewer/scene/mesh/Mesh.js +2202 -0
  205. package/src/viewer/scene/mesh/draw/DrawRenderer.js +986 -0
  206. package/src/viewer/scene/mesh/draw/DrawShaderSource.js +1570 -0
  207. package/src/viewer/scene/mesh/emphasis/EmphasisEdgesRenderer.js +249 -0
  208. package/src/viewer/scene/mesh/emphasis/EmphasisEdgesShaderSource.js +158 -0
  209. package/src/viewer/scene/mesh/emphasis/EmphasisFillRenderer.js +276 -0
  210. package/src/viewer/scene/mesh/emphasis/EmphasisFillShaderSource.js +261 -0
  211. package/src/viewer/scene/mesh/index.js +1 -0
  212. package/src/viewer/scene/mesh/occlusion/OcclusionRenderer.js +207 -0
  213. package/src/viewer/scene/mesh/occlusion/OcclusionShaderSource.js +156 -0
  214. package/src/viewer/scene/mesh/pick/PickMeshRenderer.js +210 -0
  215. package/src/viewer/scene/mesh/pick/PickMeshShaderSource.js +142 -0
  216. package/src/viewer/scene/mesh/pick/PickTriangleRenderer.js +186 -0
  217. package/src/viewer/scene/mesh/pick/PickTriangleShaderSource.js +116 -0
  218. package/src/viewer/scene/mesh/shadow/ShadowRenderer.js +214 -0
  219. package/src/viewer/scene/mesh/shadow/ShadowShaderSource.js +98 -0
  220. package/src/viewer/scene/metriqs/Metriqs.js +259 -0
  221. package/src/viewer/scene/model/ENTITY_FLAGS.js +21 -0
  222. package/src/viewer/scene/model/PerformanceModel.js +26 -0
  223. package/src/viewer/scene/model/RENDER_PASSES.js +34 -0
  224. package/src/viewer/scene/model/SceneModel.js +3817 -0
  225. package/src/viewer/scene/model/SceneModelEntity.js +478 -0
  226. package/src/viewer/scene/model/SceneModelMesh.js +160 -0
  227. package/src/viewer/scene/model/SceneModelTexture.js +17 -0
  228. package/src/viewer/scene/model/SceneModelTextureSet.js +17 -0
  229. package/src/viewer/scene/model/VBOSceneModel.js +26 -0
  230. package/src/viewer/scene/model/compression.js +227 -0
  231. package/src/viewer/scene/model/dtx/triangles/BindableDataTexture.js +31 -0
  232. package/src/viewer/scene/model/dtx/triangles/DataTextureGenerator.js +631 -0
  233. package/src/viewer/scene/model/dtx/triangles/DataTextureState.js +288 -0
  234. package/src/viewer/scene/model/dtx/triangles/TrianglesDataTextureBuffer.js +31 -0
  235. package/src/viewer/scene/model/dtx/triangles/TrianglesDataTextureLayer.js +1329 -0
  236. package/src/viewer/scene/model/dtx/triangles/TrianglesDataTextureRenderers.js +278 -0
  237. package/src/viewer/scene/model/dtx/triangles/calculateUniquePositions.js +126 -0
  238. package/src/viewer/scene/model/dtx/triangles/dataTextureRamStats.js +54 -0
  239. package/src/viewer/scene/model/dtx/triangles/rebucketPositions.js +347 -0
  240. package/src/viewer/scene/model/dtx/triangles/renderers/TrianglesDataTextureColorRenderer.js +633 -0
  241. package/src/viewer/scene/model/dtx/triangles/renderers/TrianglesDataTextureDepthRenderer.js +475 -0
  242. package/src/viewer/scene/model/dtx/triangles/renderers/TrianglesDataTextureEdgesColorRenderer.js +426 -0
  243. package/src/viewer/scene/model/dtx/triangles/renderers/TrianglesDataTextureEdgesRenderer.js +430 -0
  244. package/src/viewer/scene/model/dtx/triangles/renderers/TrianglesDataTextureNormalsRenderer.js +341 -0
  245. package/src/viewer/scene/model/dtx/triangles/renderers/TrianglesDataTextureOcclusionRenderer.js +442 -0
  246. package/src/viewer/scene/model/dtx/triangles/renderers/TrianglesDataTexturePickDepthRenderer.js +451 -0
  247. package/src/viewer/scene/model/dtx/triangles/renderers/TrianglesDataTexturePickMeshRenderer.js +436 -0
  248. package/src/viewer/scene/model/dtx/triangles/renderers/TrianglesDataTexturePickNormalsFlatRenderer.js +502 -0
  249. package/src/viewer/scene/model/dtx/triangles/renderers/TrianglesDataTexturePickNormalsRenderer.js +430 -0
  250. package/src/viewer/scene/model/dtx/triangles/renderers/TrianglesDataTextureSilhouetteRenderer.js +469 -0
  251. package/src/viewer/scene/model/dtx/triangles/renderers/TrianglesDataTextureSnapDepthBufInitRenderer.js +451 -0
  252. package/src/viewer/scene/model/dtx/triangles/renderers/TrianglesDataTextureSnapDepthRenderer.js +424 -0
  253. package/src/viewer/scene/model/index.js +3 -0
  254. package/src/viewer/scene/model/vbo/ScratchMemory.js +63 -0
  255. package/src/viewer/scene/model/vbo/VBOSceneModelRenderers.js +805 -0
  256. package/src/viewer/scene/model/vbo/float16.js +760 -0
  257. package/src/viewer/scene/model/vbo/linesBatching/LinesBatchingBuffer.js +21 -0
  258. package/src/viewer/scene/model/vbo/linesBatching/LinesBatchingLayer.js +744 -0
  259. package/src/viewer/scene/model/vbo/linesBatching/LinesBatchingRenderers.js +71 -0
  260. package/src/viewer/scene/model/vbo/linesBatching/renderers/LinesBatchingColorRenderer.js +116 -0
  261. package/src/viewer/scene/model/vbo/linesBatching/renderers/LinesBatchingSilhouetteRenderer.js +126 -0
  262. package/src/viewer/scene/model/vbo/linesInstancing/LinesInstancingLayer.js +653 -0
  263. package/src/viewer/scene/model/vbo/linesInstancing/LinesInstancingRenderers.js +71 -0
  264. package/src/viewer/scene/model/vbo/linesInstancing/renderers/LinesInstancingColorRenderer.js +150 -0
  265. package/src/viewer/scene/model/vbo/linesInstancing/renderers/LinesInstancingSilhouetteRenderer.js +128 -0
  266. package/src/viewer/scene/model/vbo/pointsBatching/PointsBatchingBuffer.js +22 -0
  267. package/src/viewer/scene/model/vbo/pointsBatching/PointsBatchingLayer.js +753 -0
  268. package/src/viewer/scene/model/vbo/pointsBatching/PointsBatchingRenderers.js +116 -0
  269. package/src/viewer/scene/model/vbo/pointsBatching/renderers/PointsBatchingColorRenderer.js +167 -0
  270. package/src/viewer/scene/model/vbo/pointsBatching/renderers/PointsBatchingOcclusionRenderer.js +135 -0
  271. package/src/viewer/scene/model/vbo/pointsBatching/renderers/PointsBatchingPickDepthRenderer.js +154 -0
  272. package/src/viewer/scene/model/vbo/pointsBatching/renderers/PointsBatchingPickMeshRenderer.js +146 -0
  273. package/src/viewer/scene/model/vbo/pointsBatching/renderers/PointsBatchingShadowRenderer.js +108 -0
  274. package/src/viewer/scene/model/vbo/pointsBatching/renderers/PointsBatchingSilhouetteRenderer.js +147 -0
  275. package/src/viewer/scene/model/vbo/pointsInstancing/PointsInstancingLayer.js +684 -0
  276. package/src/viewer/scene/model/vbo/pointsInstancing/PointsInstancingRenderers.js +146 -0
  277. package/src/viewer/scene/model/vbo/pointsInstancing/renderers/PointsInstancingColorRenderer.js +174 -0
  278. package/src/viewer/scene/model/vbo/pointsInstancing/renderers/PointsInstancingDepthRenderer.js +156 -0
  279. package/src/viewer/scene/model/vbo/pointsInstancing/renderers/PointsInstancingOcclusionRenderer.js +151 -0
  280. package/src/viewer/scene/model/vbo/pointsInstancing/renderers/PointsInstancingPickDepthRenderer.js +167 -0
  281. package/src/viewer/scene/model/vbo/pointsInstancing/renderers/PointsInstancingPickMeshRenderer.js +151 -0
  282. package/src/viewer/scene/model/vbo/pointsInstancing/renderers/PointsInstancingShadowRenderer.js +121 -0
  283. package/src/viewer/scene/model/vbo/pointsInstancing/renderers/PointsInstancingSilhouetteRenderer.js +156 -0
  284. package/src/viewer/scene/model/vbo/snapBatching/SnapBatchingDepthBufInitRenderer.js +351 -0
  285. package/src/viewer/scene/model/vbo/snapBatching/SnapBatchingDepthRenderer.js +365 -0
  286. package/src/viewer/scene/model/vbo/snapBatching/SnapBatchingRenderers.js +71 -0
  287. package/src/viewer/scene/model/vbo/snapInstancing/SnapInstancingDepthBufInitRenderer.js +381 -0
  288. package/src/viewer/scene/model/vbo/snapInstancing/SnapInstancingDepthRenderer.js +374 -0
  289. package/src/viewer/scene/model/vbo/snapInstancing/SnapInstancingRenderers.js +71 -0
  290. package/src/viewer/scene/model/vbo/trianglesBatching/TrianglesBatchingBuffer.js +26 -0
  291. package/src/viewer/scene/model/vbo/trianglesBatching/TrianglesBatchingLayer.js +1322 -0
  292. package/src/viewer/scene/model/vbo/trianglesBatching/TrianglesBatchingRenderers.js +322 -0
  293. package/src/viewer/scene/model/vbo/trianglesBatching/renderers/TrianglesBatchingColorRenderer.js +240 -0
  294. package/src/viewer/scene/model/vbo/trianglesBatching/renderers/TrianglesBatchingColorTextureRenderer.js +271 -0
  295. package/src/viewer/scene/model/vbo/trianglesBatching/renderers/TrianglesBatchingDepthRenderer.js +127 -0
  296. package/src/viewer/scene/model/vbo/trianglesBatching/renderers/TrianglesBatchingEdgesColorRenderer.js +129 -0
  297. package/src/viewer/scene/model/vbo/trianglesBatching/renderers/TrianglesBatchingEdgesRenderer.js +134 -0
  298. package/src/viewer/scene/model/vbo/trianglesBatching/renderers/TrianglesBatchingFlatColorRenderer.js +237 -0
  299. package/src/viewer/scene/model/vbo/trianglesBatching/renderers/TrianglesBatchingNormalsRenderer.js +139 -0
  300. package/src/viewer/scene/model/vbo/trianglesBatching/renderers/TrianglesBatchingOcclusionRenderer.js +127 -0
  301. package/src/viewer/scene/model/vbo/trianglesBatching/renderers/TrianglesBatchingPBRRenderer.js +563 -0
  302. package/src/viewer/scene/model/vbo/trianglesBatching/renderers/TrianglesBatchingPickDepthRenderer.js +143 -0
  303. package/src/viewer/scene/model/vbo/trianglesBatching/renderers/TrianglesBatchingPickMeshRenderer.js +130 -0
  304. package/src/viewer/scene/model/vbo/trianglesBatching/renderers/TrianglesBatchingPickNormalsFlatRenderer.js +119 -0
  305. package/src/viewer/scene/model/vbo/trianglesBatching/renderers/TrianglesBatchingPickNormalsRenderer.js +129 -0
  306. package/src/viewer/scene/model/vbo/trianglesBatching/renderers/TrianglesBatchingShadowRenderer.js +108 -0
  307. package/src/viewer/scene/model/vbo/trianglesBatching/renderers/TrianglesBatchingSilhouetteRenderer.js +137 -0
  308. package/src/viewer/scene/model/vbo/trianglesInstancing/TrianglesInstancingLayer.js +1167 -0
  309. package/src/viewer/scene/model/vbo/trianglesInstancing/TrianglesInstancingRenderers.js +322 -0
  310. package/src/viewer/scene/model/vbo/trianglesInstancing/renderers/TrianglesInstancingColorRenderer.js +253 -0
  311. package/src/viewer/scene/model/vbo/trianglesInstancing/renderers/TrianglesInstancingColorTextureRenderer.js +278 -0
  312. package/src/viewer/scene/model/vbo/trianglesInstancing/renderers/TrianglesInstancingDepthRenderer.js +125 -0
  313. package/src/viewer/scene/model/vbo/trianglesInstancing/renderers/TrianglesInstancingEdgesColorRenderer.js +131 -0
  314. package/src/viewer/scene/model/vbo/trianglesInstancing/renderers/TrianglesInstancingEdgesRenderer.js +134 -0
  315. package/src/viewer/scene/model/vbo/trianglesInstancing/renderers/TrianglesInstancingFlatColorRenderer.js +244 -0
  316. package/src/viewer/scene/model/vbo/trianglesInstancing/renderers/TrianglesInstancingFlatNormalsRenderer.js +130 -0
  317. package/src/viewer/scene/model/vbo/trianglesInstancing/renderers/TrianglesInstancingNormalsRenderer.js +140 -0
  318. package/src/viewer/scene/model/vbo/trianglesInstancing/renderers/TrianglesInstancingOcclusionRenderer.js +130 -0
  319. package/src/viewer/scene/model/vbo/trianglesInstancing/renderers/TrianglesInstancingPBRRenderer.js +563 -0
  320. package/src/viewer/scene/model/vbo/trianglesInstancing/renderers/TrianglesInstancingPickDepthRenderer.js +148 -0
  321. package/src/viewer/scene/model/vbo/trianglesInstancing/renderers/TrianglesInstancingPickMeshRenderer.js +135 -0
  322. package/src/viewer/scene/model/vbo/trianglesInstancing/renderers/TrianglesInstancingPickNormalsFlatRenderer.js +130 -0
  323. package/src/viewer/scene/model/vbo/trianglesInstancing/renderers/TrianglesInstancingPickNormalsRenderer.js +144 -0
  324. package/src/viewer/scene/model/vbo/trianglesInstancing/renderers/TrianglesInstancingShadowRenderer.js +113 -0
  325. package/src/viewer/scene/model/vbo/trianglesInstancing/renderers/TrianglesInstancingSilhouetteRenderer.js +141 -0
  326. package/src/viewer/scene/nodes/Node.js +1383 -0
  327. package/src/viewer/scene/nodes/index.js +1 -0
  328. package/src/viewer/scene/paths/CubicBezierCurve.js +194 -0
  329. package/src/viewer/scene/paths/Curve.js +183 -0
  330. package/src/viewer/scene/paths/Path.js +239 -0
  331. package/src/viewer/scene/paths/QuadraticBezierCurve.js +161 -0
  332. package/src/viewer/scene/paths/SplineCurve.js +133 -0
  333. package/src/viewer/scene/paths/index.js +5 -0
  334. package/src/viewer/scene/postfx/SAO.js +543 -0
  335. package/src/viewer/scene/scene/Scene.js +2627 -0
  336. package/src/viewer/scene/sectionPlane/SectionPlane.js +194 -0
  337. package/src/viewer/scene/sectionPlane/index.js +1 -0
  338. package/src/viewer/scene/skybox/Skybox.js +123 -0
  339. package/src/viewer/scene/skybox/index.js +1 -0
  340. package/src/viewer/scene/stats.js +44 -0
  341. package/src/viewer/scene/utils/Cache.js +29 -0
  342. package/src/viewer/scene/utils/FileLoader.js +160 -0
  343. package/src/viewer/scene/utils/Loader.js +55 -0
  344. package/src/viewer/scene/utils/LoadingManager.js +86 -0
  345. package/src/viewer/scene/utils/Map.js +45 -0
  346. package/src/viewer/scene/utils/Queue.js +56 -0
  347. package/src/viewer/scene/utils/WorkerPool.js +73 -0
  348. package/src/viewer/scene/utils/index.js +6 -0
  349. package/src/viewer/scene/utils/textureTranscoders/KTX2TextureTranscoder/KTX2TextureTranscoder.js +650 -0
  350. package/src/viewer/scene/utils/textureTranscoders/KTX2TextureTranscoder/index.js +1 -0
  351. package/src/viewer/scene/utils/textureTranscoders/TextureTranscoder.js +31 -0
  352. package/src/viewer/scene/utils/textureTranscoders/index.js +2 -0
  353. package/src/viewer/scene/utils.js +452 -0
  354. package/src/viewer/scene/vfc/VFC.js +82 -0
  355. package/src/viewer/scene/vfc/VFCManager.js +54 -0
  356. package/src/viewer/scene/vfc/VFCState.js +391 -0
  357. package/src/viewer/scene/vfc/cluster-helper.js +134 -0
  358. package/src/viewer/scene/vfc/index.js +1 -0
  359. package/src/viewer/scene/vfc/rbush3d.js +848 -0
  360. package/src/viewer/scene/vfc/xeokit-cluster.js +418 -0
  361. package/src/viewer/scene/viewport/Viewport.js +212 -0
  362. package/src/viewer/scene/webgl/ArrayBuf.js +121 -0
  363. package/src/viewer/scene/webgl/Attribute.js +23 -0
  364. package/src/viewer/scene/webgl/Drawable.js +270 -0
  365. package/src/viewer/scene/webgl/FrameContext.js +313 -0
  366. package/src/viewer/scene/webgl/PickResult.js +339 -0
  367. package/src/viewer/scene/webgl/Pickable.js +69 -0
  368. package/src/viewer/scene/webgl/Program.js +181 -0
  369. package/src/viewer/scene/webgl/RenderBuffer.js +350 -0
  370. package/src/viewer/scene/webgl/RenderBufferManager.js +34 -0
  371. package/src/viewer/scene/webgl/RenderFlags.js +203 -0
  372. package/src/viewer/scene/webgl/RenderState.js +40 -0
  373. package/src/viewer/scene/webgl/Renderer.js +1654 -0
  374. package/src/viewer/scene/webgl/Sampler.js +18 -0
  375. package/src/viewer/scene/webgl/Shader.js +49 -0
  376. package/src/viewer/scene/webgl/Texture2D.js +442 -0
  377. package/src/viewer/scene/webgl/convertConstant.js +244 -0
  378. package/src/viewer/scene/webgl/getExtension.js +32 -0
  379. package/src/viewer/scene/webgl/occlusion/OcclusionLayer.js +214 -0
  380. package/src/viewer/scene/webgl/occlusion/OcclusionTester.js +426 -0
  381. package/src/viewer/scene/webgl/sao/SAODepthLimitedBlurRenderer.js +324 -0
  382. package/src/viewer/scene/webgl/sao/SAOOcclusionRenderer.js +376 -0
  383. package/src/viewer/scene/webgl/webglEnums.js +61 -0
  384. package/src/viewer/scene/webglInfo.js +47 -0
@@ -0,0 +1,1167 @@
1
+ import {ENTITY_FLAGS} from '../../ENTITY_FLAGS.js';
2
+ import {RENDER_PASSES} from '../../RENDER_PASSES.js';
3
+
4
+ import {math} from "../../../math/math.js";
5
+ import {RenderState} from "../../../webgl/RenderState.js";
6
+ import {ArrayBuf} from "../../../webgl/ArrayBuf.js";
7
+ import {getInstancingRenderers} from "./TrianglesInstancingRenderers.js";
8
+ import {getSnapInstancingRenderers} from "../snapInstancing/SnapInstancingRenderers";
9
+
10
+ const tempUint8Vec4 = new Uint8Array(4);
11
+ const tempFloat32 = new Float32Array(1);
12
+ const tempVec4a = math.vec4([0, 0, 0, 1]);
13
+ const tempVec4b = math.vec4([0, 0, 0, 1]);
14
+ const tempVec4c = math.vec4([0, 0, 0, 1]);
15
+ const tempVec3fa = new Float32Array(3);
16
+
17
+ const tempVec3a = math.vec3();
18
+ const tempVec3b = math.vec3();
19
+ const tempVec3c = math.vec3();
20
+ const tempVec3d = math.vec3();
21
+ const tempVec3e = math.vec3();
22
+ const tempVec3f = math.vec3();
23
+ const tempVec3g = math.vec3();
24
+
25
+ /**
26
+ * @private
27
+ */
28
+ class TrianglesInstancingLayer {
29
+
30
+ /**
31
+ * @param cfg
32
+ * @param cfg.layerIndex
33
+ * @param cfg.model
34
+ * @param cfg.geometry
35
+ * @param cfg.textureSet
36
+ * @param cfg.origin
37
+ */
38
+ constructor(cfg) {
39
+
40
+ console.log("Creating TrianglesInstancingLayer");
41
+
42
+ /**
43
+ * Owner model
44
+ * @type {VBOSceneModel}
45
+ */
46
+ this.model = cfg.model;
47
+
48
+ /**
49
+ * State sorting key.
50
+ * @type {string}
51
+ */
52
+ this.sortId = "TrianglesInstancingLayer" + (cfg.solid ? "-solid" : "-surface") + (cfg.normals ? "-normals" : "-autoNormals");
53
+
54
+ /**
55
+ * Index of this InstancingLayer in VBOSceneModel#_layerList
56
+ * @type {Number}
57
+ */
58
+ this.layerIndex = cfg.layerIndex;
59
+
60
+ this._instancingRenderers = getInstancingRenderers(cfg.model.scene);
61
+ this._snapInstancingRenderers = getSnapInstancingRenderers(cfg.model.scene);
62
+
63
+ this._aabb = math.collapseAABB3();
64
+
65
+ this._state = new RenderState({
66
+ numInstances: 0,
67
+ obb: math.OBB3(),
68
+ origin: math.vec3(),
69
+ geometry: cfg.geometry,
70
+ textureSet: cfg.textureSet,
71
+ pbrSupported: false, // Set in #finalize if we have enough to support quality rendering
72
+ positionsDecodeMatrix: cfg.geometry.positionsDecodeMatrix, // So we can null the geometry for GC
73
+ colorsBuf: null,
74
+ metallicRoughnessBuf: null,
75
+ flagsBuf: null,
76
+ offsetsBuf: null,
77
+ modelMatrixCol0Buf: null,
78
+ modelMatrixCol1Buf: null,
79
+ modelMatrixCol2Buf: null,
80
+ modelNormalMatrixCol0Buf: null,
81
+ modelNormalMatrixCol1Buf: null,
82
+ modelNormalMatrixCol2Buf: null,
83
+ pickColorsBuf: null
84
+ });
85
+
86
+ // These counts are used to avoid unnecessary render passes
87
+ this._numPortions = 0;
88
+ this._numVisibleLayerPortions = 0;
89
+ this._numTransparentLayerPortions = 0;
90
+ this._numXRayedLayerPortions = 0;
91
+ this._numHighlightedLayerPortions = 0;
92
+ this._numSelectedLayerPortions = 0;
93
+ this._numClippableLayerPortions = 0;
94
+ this._numEdgesLayerPortions = 0;
95
+ this._numPickableLayerPortions = 0;
96
+ this._numCulledLayerPortions = 0;
97
+
98
+ /** @private */
99
+ this.numIndices = cfg.geometry.numIndices;
100
+
101
+ // Vertex arrays
102
+ this._colors = [];
103
+ this._metallicRoughness = [];
104
+ this._pickColors = [];
105
+ this._offsets = [];
106
+
107
+ // Modeling matrix per instance, array for each column
108
+ this._modelMatrixCol0 = [];
109
+ this._modelMatrixCol1 = [];
110
+ this._modelMatrixCol2 = [];
111
+
112
+ // Modeling normal matrix per instance, array for each column
113
+ this._modelNormalMatrixCol0 = [];
114
+ this._modelNormalMatrixCol1 = [];
115
+ this._modelNormalMatrixCol2 = [];
116
+
117
+ this._portions = [];
118
+
119
+ if (cfg.origin) {
120
+ this._state.origin.set(cfg.origin);
121
+ }
122
+
123
+ this._finalized = false;
124
+
125
+ /**
126
+ * The axis-aligned World-space boundary of this InstancingLayer's positions.
127
+ * @type {*|Float64Array}
128
+ */
129
+ this.aabb = math.collapseAABB3();
130
+
131
+ /**
132
+ * When true, this layer contains solid triangle meshes, otherwise this layer contains surface triangle meshes
133
+ * @type {boolean}
134
+ */
135
+ this.solid = !!cfg.solid;
136
+
137
+ /**
138
+ * The number of indices in this layer.
139
+ * @type {number|*}
140
+ */
141
+ this.numIndices = cfg.geometry.numIndices;
142
+ }
143
+
144
+ /**
145
+ * Creates a new portion within this InstancingLayer, returns the new portion ID.
146
+ *
147
+ * The portion will instance this InstancingLayer's geometry.
148
+ *
149
+ * Gives the portion the specified color and matrix.
150
+ *
151
+ * @param cfg Portion params
152
+ * @param cfg.color Color [0..255,0..255,0..255]
153
+ * @param cfg.metallic Metalness factor [0..255]
154
+ * @param cfg.roughness Roughness factor [0..255]
155
+ * @param cfg.opacity Opacity [0..255].
156
+ * @param cfg.meshMatrix Flat float 4x4 matrix.
157
+ * @param [cfg.worldMatrix] Flat float 4x4 matrix.
158
+ * @param cfg.worldAABB Flat float AABB.
159
+ * @param cfg.pickColor Quantized pick color
160
+ * @returns {number} Portion ID.
161
+ */
162
+ createPortion(cfg) {
163
+
164
+ const color = cfg.color;
165
+ const metallic = cfg.metallic;
166
+ const roughness = cfg.roughness;
167
+ const opacity = cfg.opacity !== null && cfg.opacity !== undefined ? cfg.opacity : 255;
168
+ const meshMatrix = cfg.meshMatrix;
169
+ const worldAABB = cfg.aabb;
170
+ const pickColor = cfg.pickColor;
171
+
172
+ if (this._finalized) {
173
+ throw "Already finalized";
174
+ }
175
+
176
+ // TODO: find AABB for portion by transforming the geometry local AABB by the given meshMatrix?
177
+
178
+ const r = color[0]; // Color is pre-quantized by SceneModel
179
+ const g = color[1];
180
+ const b = color[2];
181
+
182
+ this._colors.push(r);
183
+ this._colors.push(g);
184
+ this._colors.push(b);
185
+ this._colors.push(opacity);
186
+
187
+ this._metallicRoughness.push((metallic !== null && metallic !== undefined) ? metallic : 0);
188
+ this._metallicRoughness.push((roughness !== null && roughness !== undefined) ? roughness : 255);
189
+
190
+ if (this.model.scene.entityOffsetsEnabled) {
191
+ this._offsets.push(0);
192
+ this._offsets.push(0);
193
+ this._offsets.push(0);
194
+ }
195
+
196
+ this._modelMatrixCol0.push(meshMatrix[0]);
197
+ this._modelMatrixCol0.push(meshMatrix[4]);
198
+ this._modelMatrixCol0.push(meshMatrix[8]);
199
+ this._modelMatrixCol0.push(meshMatrix[12]);
200
+
201
+ this._modelMatrixCol1.push(meshMatrix[1]);
202
+ this._modelMatrixCol1.push(meshMatrix[5]);
203
+ this._modelMatrixCol1.push(meshMatrix[9]);
204
+ this._modelMatrixCol1.push(meshMatrix[13]);
205
+
206
+ this._modelMatrixCol2.push(meshMatrix[2]);
207
+ this._modelMatrixCol2.push(meshMatrix[6]);
208
+ this._modelMatrixCol2.push(meshMatrix[10]);
209
+ this._modelMatrixCol2.push(meshMatrix[14]);
210
+
211
+ if (this._state.geometry.normals) {
212
+
213
+ // Note: order of inverse and transpose doesn't matter
214
+
215
+ let transposedMat = math.transposeMat4(meshMatrix, math.mat4()); // TODO: Use cached matrix
216
+ let normalMatrix = math.inverseMat4(transposedMat);
217
+
218
+ this._modelNormalMatrixCol0.push(normalMatrix[0]);
219
+ this._modelNormalMatrixCol0.push(normalMatrix[4]);
220
+ this._modelNormalMatrixCol0.push(normalMatrix[8]);
221
+ this._modelNormalMatrixCol0.push(normalMatrix[12]);
222
+
223
+ this._modelNormalMatrixCol1.push(normalMatrix[1]);
224
+ this._modelNormalMatrixCol1.push(normalMatrix[5]);
225
+ this._modelNormalMatrixCol1.push(normalMatrix[9]);
226
+ this._modelNormalMatrixCol1.push(normalMatrix[13]);
227
+
228
+ this._modelNormalMatrixCol2.push(normalMatrix[2]);
229
+ this._modelNormalMatrixCol2.push(normalMatrix[6]);
230
+ this._modelNormalMatrixCol2.push(normalMatrix[10]);
231
+ this._modelNormalMatrixCol2.push(normalMatrix[14]);
232
+ }
233
+
234
+ // Per-vertex pick colors
235
+
236
+ this._pickColors.push(pickColor[0]);
237
+ this._pickColors.push(pickColor[1]);
238
+ this._pickColors.push(pickColor[2]);
239
+ this._pickColors.push(pickColor[3]);
240
+
241
+ // Expand AABB
242
+
243
+ const lenPositions = this._state.geometry.positionsCompressed.length;
244
+ const positions = this._state.geometry.positionsCompressed;
245
+ const positionsDecodeMatrix = this._state.geometry.positionsDecodeMatrix;
246
+ for (let i = 0; i < lenPositions; i += 3) {
247
+ tempVec4a[0] = positions[i + 0];
248
+ tempVec4a[1] = positions[i + 1];
249
+ tempVec4a[2] = positions[i + 2];
250
+ math.transformPoint4(positionsDecodeMatrix, tempVec4a, tempVec4b);
251
+ math.transformPoint4(meshMatrix, tempVec4b, tempVec4a);
252
+ math.expandAABB3Point3(worldAABB, tempVec4a);
253
+ }
254
+
255
+ if (this._state.origin) {
256
+ const origin = this._state.origin;
257
+ worldAABB[0] += origin[0];
258
+ worldAABB[1] += origin[1];
259
+ worldAABB[2] += origin[2];
260
+ worldAABB[3] += origin[0];
261
+ worldAABB[4] += origin[1];
262
+ worldAABB[5] += origin[2];
263
+ }
264
+
265
+ math.expandAABB3(this.aabb, worldAABB);
266
+
267
+ this._state.numInstances++;
268
+
269
+ const portionId = this._portions.length;
270
+
271
+ const portion = {};
272
+
273
+ if (this.model.scene.pickSurfacePrecisionEnabled) {
274
+ portion.matrix = meshMatrix.slice();
275
+ portion.inverseMatrix = null; // Lazy-computed in precisionRayPickSurface
276
+ portion.normalMatrix = null; // Lazy-computed in precisionRayPickSurface
277
+ }
278
+
279
+ this._portions.push(portion);
280
+
281
+ this._numPortions++;
282
+ this.model.numPortions++;
283
+
284
+ return portionId;
285
+ }
286
+
287
+ finalize() {
288
+
289
+ if (this._finalized) {
290
+ return;
291
+ }
292
+
293
+ const state = this._state;
294
+ const geometry = state.geometry;
295
+ const textureSet = state.textureSet;
296
+ const gl = this.model.scene.canvas.gl;
297
+ const colorsLength = this._colors.length;
298
+ const flagsLength = colorsLength / 4;
299
+
300
+ if (colorsLength > 0) {
301
+ let notNormalized = false;
302
+ state.colorsBuf = new ArrayBuf(gl, gl.ARRAY_BUFFER, new Uint8Array(this._colors), this._colors.length, 4, gl.DYNAMIC_DRAW, notNormalized);
303
+ this._colors = []; // Release memory
304
+ }
305
+
306
+ if (this._metallicRoughness.length > 0) {
307
+ const metallicRoughness = new Uint8Array(this._metallicRoughness);
308
+ let normalized = false;
309
+ state.metallicRoughnessBuf = new ArrayBuf(gl, gl.ARRAY_BUFFER, metallicRoughness, this._metallicRoughness.length, 2, gl.STATIC_DRAW, normalized);
310
+ }
311
+
312
+ if (flagsLength > 0) {
313
+ // Because we only build flags arrays here,
314
+ // get their length from the colors array
315
+ let notNormalized = false;
316
+ state.flagsBuf = new ArrayBuf(gl, gl.ARRAY_BUFFER, new Float32Array(flagsLength), flagsLength, 1, gl.DYNAMIC_DRAW, notNormalized);
317
+ }
318
+
319
+ if (this.model.scene.entityOffsetsEnabled) {
320
+ if (this._offsets.length > 0) {
321
+ const notNormalized = false;
322
+ state.offsetsBuf = new ArrayBuf(gl, gl.ARRAY_BUFFER, new Float32Array(this._offsets), this._offsets.length, 3, gl.DYNAMIC_DRAW, notNormalized);
323
+ this._offsets = []; // Release memory
324
+ }
325
+ }
326
+
327
+ if (geometry.positionsCompressed && geometry.positionsCompressed.length > 0) {
328
+ const normalized = false;
329
+ state.positionsBuf = new ArrayBuf(gl, gl.ARRAY_BUFFER, geometry.positionsCompressed, geometry.positionsCompressed.length, 3, gl.STATIC_DRAW, normalized);
330
+ state.positionsDecodeMatrix = math.mat4(geometry.positionsDecodeMatrix);
331
+ }
332
+ // if (geometry.normalsCompressed && geometry.normalsCompressed.length > 0) {
333
+ // const normalized = true; // For oct-encoded UInt8
334
+ // state.normalsBuf = new ArrayBuf(gl, gl.ARRAY_BUFFER, geometry.normalsCompressed, geometry.normalsCompressed.length, 3, gl.STATIC_DRAW, normalized);
335
+ // }
336
+ if (geometry.colorsCompressed && geometry.colorsCompressed.length > 0) {
337
+ const colorsCompressed = new Uint8Array(geometry.colorsCompressed);
338
+ const notNormalized = false;
339
+ state.colorsBuf = new ArrayBuf(gl, gl.ARRAY_BUFFER, colorsCompressed, colorsCompressed.length, 4, gl.STATIC_DRAW, notNormalized);
340
+ }
341
+ if (geometry.uvCompressed && geometry.uvCompressed.length > 0) {
342
+ const uvCompressed = geometry.uvCompressed;
343
+ state.uvDecodeMatrix = geometry.uvDecodeMatrix;
344
+ state.uvBuf = new ArrayBuf(gl, gl.ARRAY_BUFFER, uvCompressed, uvCompressed.length, 2, gl.STATIC_DRAW, false);
345
+ }
346
+ if (geometry.indices && geometry.indices.length > 0) {
347
+ state.indicesBuf = new ArrayBuf(gl, gl.ELEMENT_ARRAY_BUFFER, new Uint32Array(geometry.indices), geometry.indices.length, 1, gl.STATIC_DRAW);
348
+ state.numIndices = geometry.indices.length;
349
+ }
350
+ if (geometry.primitive === "triangles" || geometry.primitive === "solid" || geometry.primitive === "surface") {
351
+ state.edgeIndicesBuf = new ArrayBuf(gl, gl.ELEMENT_ARRAY_BUFFER, new Uint32Array(geometry.edgeIndices), geometry.edgeIndices.length, 1, gl.STATIC_DRAW);
352
+ }
353
+
354
+ if (this._modelMatrixCol0.length > 0) {
355
+
356
+ const normalized = false;
357
+
358
+ state.modelMatrixCol0Buf = new ArrayBuf(gl, gl.ARRAY_BUFFER, new Float32Array(this._modelMatrixCol0), this._modelMatrixCol0.length, 4, gl.STATIC_DRAW, normalized);
359
+ state.modelMatrixCol1Buf = new ArrayBuf(gl, gl.ARRAY_BUFFER, new Float32Array(this._modelMatrixCol1), this._modelMatrixCol1.length, 4, gl.STATIC_DRAW, normalized);
360
+ state.modelMatrixCol2Buf = new ArrayBuf(gl, gl.ARRAY_BUFFER, new Float32Array(this._modelMatrixCol2), this._modelMatrixCol2.length, 4, gl.STATIC_DRAW, normalized);
361
+ this._modelMatrixCol0 = [];
362
+ this._modelMatrixCol1 = [];
363
+ this._modelMatrixCol2 = [];
364
+
365
+ if (state.normalsBuf) {
366
+ state.modelNormalMatrixCol0Buf = new ArrayBuf(gl, gl.ARRAY_BUFFER, new Float32Array(this._modelNormalMatrixCol0), this._modelNormalMatrixCol0.length, 4, gl.STATIC_DRAW, normalized);
367
+ state.modelNormalMatrixCol1Buf = new ArrayBuf(gl, gl.ARRAY_BUFFER, new Float32Array(this._modelNormalMatrixCol1), this._modelNormalMatrixCol1.length, 4, gl.STATIC_DRAW, normalized);
368
+ state.modelNormalMatrixCol2Buf = new ArrayBuf(gl, gl.ARRAY_BUFFER, new Float32Array(this._modelNormalMatrixCol2), this._modelNormalMatrixCol2.length, 4, gl.STATIC_DRAW, normalized);
369
+ this._modelNormalMatrixCol0 = [];
370
+ this._modelNormalMatrixCol1 = [];
371
+ this._modelNormalMatrixCol2 = [];
372
+ }
373
+ }
374
+
375
+ if (this._pickColors.length > 0) {
376
+ const normalized = false;
377
+ state.pickColorsBuf = new ArrayBuf(gl, gl.ARRAY_BUFFER, new Uint8Array(this._pickColors), this._pickColors.length, 4, gl.STATIC_DRAW, normalized);
378
+ this._pickColors = []; // Release memory
379
+ }
380
+
381
+ state.pbrSupported
382
+ = !!state.metallicRoughnessBuf
383
+ && !!state.uvBuf
384
+ && !!state.normalsBuf
385
+ && !!textureSet
386
+ && !!textureSet.colorTexture
387
+ && !!textureSet.metallicRoughnessTexture;
388
+
389
+ state.colorTextureSupported
390
+ = !!state.uvBuf
391
+ && !!textureSet
392
+ && !!textureSet.colorTexture;
393
+
394
+ this._state.geometry = null;
395
+
396
+ this._finalized = true;
397
+ }
398
+
399
+ // The following setters are called by VBOSceneModelMesh, in turn called by VBOSceneModelNode, only after the layer is finalized.
400
+ // It's important that these are called after finalize() in order to maintain integrity of counts like _numVisibleLayerPortions etc.
401
+
402
+ initFlags(portionId, flags, meshTransparent) {
403
+ if (flags & ENTITY_FLAGS.VISIBLE) {
404
+ this._numVisibleLayerPortions++;
405
+ this.model.numVisibleLayerPortions++;
406
+ }
407
+ if (flags & ENTITY_FLAGS.HIGHLIGHTED) {
408
+ this._numHighlightedLayerPortions++;
409
+ this.model.numHighlightedLayerPortions++;
410
+ }
411
+ if (flags & ENTITY_FLAGS.XRAYED) {
412
+ this._numXRayedLayerPortions++;
413
+ this.model.numXRayedLayerPortions++;
414
+ }
415
+ if (flags & ENTITY_FLAGS.SELECTED) {
416
+ this._numSelectedLayerPortions++;
417
+ this.model.numSelectedLayerPortions++;
418
+ }
419
+ if (flags & ENTITY_FLAGS.CLIPPABLE) {
420
+ this._numClippableLayerPortions++;
421
+ this.model.numClippableLayerPortions++;
422
+ }
423
+ if (flags & ENTITY_FLAGS.EDGES) {
424
+ this._numEdgesLayerPortions++;
425
+ this.model.numEdgesLayerPortions++;
426
+ }
427
+ if (flags & ENTITY_FLAGS.PICKABLE) {
428
+ this._numPickableLayerPortions++;
429
+ this.model.numPickableLayerPortions++;
430
+ }
431
+ if (flags & ENTITY_FLAGS.CULLED) {
432
+ this._numCulledLayerPortions++;
433
+ this.model.numCulledLayerPortions++;
434
+ }
435
+ if (meshTransparent) {
436
+ this._numTransparentLayerPortions++;
437
+ this.model.numTransparentLayerPortions++;
438
+ }
439
+ this._setFlags(portionId, flags, meshTransparent);
440
+ }
441
+
442
+ setVisible(portionId, flags, meshTransparent) {
443
+ if (!this._finalized) {
444
+ throw "Not finalized";
445
+ }
446
+ if (flags & ENTITY_FLAGS.VISIBLE) {
447
+ this._numVisibleLayerPortions++;
448
+ this.model.numVisibleLayerPortions++;
449
+ } else {
450
+ this._numVisibleLayerPortions--;
451
+ this.model.numVisibleLayerPortions--;
452
+ }
453
+ this._setFlags(portionId, flags, meshTransparent);
454
+ }
455
+
456
+ setHighlighted(portionId, flags, meshTransparent) {
457
+ if (!this._finalized) {
458
+ throw "Not finalized";
459
+ }
460
+ if (flags & ENTITY_FLAGS.HIGHLIGHTED) {
461
+ this._numHighlightedLayerPortions++;
462
+ this.model.numHighlightedLayerPortions++;
463
+ } else {
464
+ this._numHighlightedLayerPortions--;
465
+ this.model.numHighlightedLayerPortions--;
466
+ }
467
+ this._setFlags(portionId, flags, meshTransparent);
468
+ }
469
+
470
+ setXRayed(portionId, flags, meshTransparent) {
471
+ if (!this._finalized) {
472
+ throw "Not finalized";
473
+ }
474
+ if (flags & ENTITY_FLAGS.XRAYED) {
475
+ this._numXRayedLayerPortions++;
476
+ this.model.numXRayedLayerPortions++;
477
+ } else {
478
+ this._numXRayedLayerPortions--;
479
+ this.model.numXRayedLayerPortions--;
480
+ }
481
+ this._setFlags(portionId, flags, meshTransparent);
482
+ }
483
+
484
+ setSelected(portionId, flags, meshTransparent) {
485
+ if (!this._finalized) {
486
+ throw "Not finalized";
487
+ }
488
+ if (flags & ENTITY_FLAGS.SELECTED) {
489
+ this._numSelectedLayerPortions++;
490
+ this.model.numSelectedLayerPortions++;
491
+ } else {
492
+ this._numSelectedLayerPortions--;
493
+ this.model.numSelectedLayerPortions--;
494
+ }
495
+ this._setFlags(portionId, flags, meshTransparent);
496
+ }
497
+
498
+ setEdges(portionId, flags, meshTransparent) {
499
+ if (!this._finalized) {
500
+ throw "Not finalized";
501
+ }
502
+ if (flags & ENTITY_FLAGS.EDGES) {
503
+ this._numEdgesLayerPortions++;
504
+ this.model.numEdgesLayerPortions++;
505
+ } else {
506
+ this._numEdgesLayerPortions--;
507
+ this.model.numEdgesLayerPortions--;
508
+ }
509
+ this._setFlags(portionId, flags, meshTransparent);
510
+ }
511
+
512
+ setClippable(portionId, flags) {
513
+ if (!this._finalized) {
514
+ throw "Not finalized";
515
+ }
516
+ if (flags & ENTITY_FLAGS.CLIPPABLE) {
517
+ this._numClippableLayerPortions++;
518
+ this.model.numClippableLayerPortions++;
519
+ } else {
520
+ this._numClippableLayerPortions--;
521
+ this.model.numClippableLayerPortions--;
522
+ }
523
+ this._setFlags(portionId, flags);
524
+ }
525
+
526
+ setCollidable(portionId, flags) {
527
+ if (!this._finalized) {
528
+ throw "Not finalized";
529
+ }
530
+ }
531
+
532
+ setPickable(portionId, flags, meshTransparent) {
533
+ if (!this._finalized) {
534
+ throw "Not finalized";
535
+ }
536
+ if (flags & ENTITY_FLAGS.PICKABLE) {
537
+ this._numPickableLayerPortions++;
538
+ this.model.numPickableLayerPortions++;
539
+ } else {
540
+ this._numPickableLayerPortions--;
541
+ this.model.numPickableLayerPortions--;
542
+ }
543
+ this._setFlags(portionId, flags, meshTransparent);
544
+ }
545
+
546
+ setCulled(portionId, flags, meshTransparent) {
547
+ if (!this._finalized) {
548
+ throw "Not finalized";
549
+ }
550
+ if (flags & ENTITY_FLAGS.CULLED) {
551
+ this._numCulledLayerPortions++;
552
+ this.model.numCulledLayerPortions++;
553
+ } else {
554
+ this._numCulledLayerPortions--;
555
+ this.model.numCulledLayerPortions--;
556
+ }
557
+ this._setFlags(portionId, flags, meshTransparent);
558
+ }
559
+
560
+ setColor(portionId, color) { // RGBA color is normalized as ints
561
+ if (!this._finalized) {
562
+ throw "Not finalized";
563
+ }
564
+ tempUint8Vec4[0] = color[0];
565
+ tempUint8Vec4[1] = color[1];
566
+ tempUint8Vec4[2] = color[2];
567
+ tempUint8Vec4[3] = color[3];
568
+ if (this._state.colorsBuf) {
569
+ this._state.colorsBuf.setData(tempUint8Vec4, portionId * 4);
570
+ }
571
+ }
572
+
573
+ setTransparent(portionId, flags, transparent) {
574
+ if (transparent) {
575
+ this._numTransparentLayerPortions++;
576
+ this.model.numTransparentLayerPortions++;
577
+ } else {
578
+ this._numTransparentLayerPortions--;
579
+ this.model.numTransparentLayerPortions--;
580
+ }
581
+ this._setFlags(portionId, flags, transparent);
582
+ }
583
+
584
+ // setMatrix(portionId, matrix) {
585
+ //
586
+ // if (!this._finalized) {
587
+ // throw "Not finalized";
588
+ // }
589
+ //
590
+ // var offset = portionId * 4;
591
+ //
592
+ // tempFloat32Vec4[0] = matrix[0];
593
+ // tempFloat32Vec4[1] = matrix[4];
594
+ // tempFloat32Vec4[2] = matrix[8];
595
+ // tempFloat32Vec4[3] = matrix[12];
596
+ //
597
+ // this._state.modelMatrixCol0Buf.setData(tempFloat32Vec4, offset);
598
+ //
599
+ // tempFloat32Vec4[0] = matrix[1];
600
+ // tempFloat32Vec4[1] = matrix[5];
601
+ // tempFloat32Vec4[2] = matrix[9];
602
+ // tempFloat32Vec4[3] = matrix[13];
603
+ //
604
+ // this._state.modelMatrixCol1Buf.setData(tempFloat32Vec4, offset);
605
+ //
606
+ // tempFloat32Vec4[0] = matrix[2];
607
+ // tempFloat32Vec4[1] = matrix[6];
608
+ // tempFloat32Vec4[2] = matrix[10];
609
+ // tempFloat32Vec4[3] = matrix[14];
610
+ //
611
+ // this._state.modelMatrixCol2Buf.setData(tempFloat32Vec4, offset);
612
+ // }
613
+
614
+ /**
615
+ * flags are 4bits values encoded on a 32bit base. color flag on the first 4 bits, silhouette flag on the next 4 bits and so on for edge, pick and clippable.
616
+ */
617
+ _setFlags(portionId, flags, meshTransparent) {
618
+
619
+ if (!this._finalized) {
620
+ throw "Not finalized";
621
+ }
622
+
623
+ const visible = !!(flags & ENTITY_FLAGS.VISIBLE);
624
+ const xrayed = !!(flags & ENTITY_FLAGS.XRAYED);
625
+ const highlighted = !!(flags & ENTITY_FLAGS.HIGHLIGHTED);
626
+ const selected = !!(flags & ENTITY_FLAGS.SELECTED);
627
+ const edges = !!(flags & ENTITY_FLAGS.EDGES);
628
+ const pickable = !!(flags & ENTITY_FLAGS.PICKABLE);
629
+ const culled = !!(flags & ENTITY_FLAGS.CULLED);
630
+
631
+ let colorFlag;
632
+ if (!visible || culled || xrayed
633
+ || (highlighted && !this.model.scene.highlightMaterial.glowThrough)
634
+ || (selected && !this.model.scene.selectedMaterial.glowThrough)) {
635
+ colorFlag = RENDER_PASSES.NOT_RENDERED;
636
+ } else {
637
+ if (meshTransparent) {
638
+ colorFlag = RENDER_PASSES.COLOR_TRANSPARENT;
639
+ } else {
640
+ colorFlag = RENDER_PASSES.COLOR_OPAQUE;
641
+ }
642
+ }
643
+
644
+ let silhouetteFlag;
645
+ if (!visible || culled) {
646
+ silhouetteFlag = RENDER_PASSES.NOT_RENDERED;
647
+ } else if (selected) {
648
+ silhouetteFlag = RENDER_PASSES.SILHOUETTE_SELECTED;
649
+ } else if (highlighted) {
650
+ silhouetteFlag = RENDER_PASSES.SILHOUETTE_HIGHLIGHTED;
651
+ } else if (xrayed) {
652
+ silhouetteFlag = RENDER_PASSES.SILHOUETTE_XRAYED;
653
+ } else {
654
+ silhouetteFlag = RENDER_PASSES.NOT_RENDERED;
655
+ }
656
+
657
+ let edgeFlag = 0;
658
+ if (!visible || culled) {
659
+ edgeFlag = RENDER_PASSES.NOT_RENDERED;
660
+ } else if (selected) {
661
+ edgeFlag = RENDER_PASSES.EDGES_SELECTED;
662
+ } else if (highlighted) {
663
+ edgeFlag = RENDER_PASSES.EDGES_HIGHLIGHTED;
664
+ } else if (xrayed) {
665
+ edgeFlag = RENDER_PASSES.EDGES_XRAYED;
666
+ } else if (edges) {
667
+ if (meshTransparent) {
668
+ edgeFlag = RENDER_PASSES.EDGES_COLOR_TRANSPARENT;
669
+ } else {
670
+ edgeFlag = RENDER_PASSES.EDGES_COLOR_OPAQUE;
671
+ }
672
+ } else {
673
+ edgeFlag = RENDER_PASSES.NOT_RENDERED;
674
+ }
675
+
676
+ const pickFlag = (visible && !culled && pickable) ? RENDER_PASSES.PICK : RENDER_PASSES.NOT_RENDERED;
677
+
678
+ const clippableFlag = !!(flags & ENTITY_FLAGS.CLIPPABLE) ? 1 : 0;
679
+
680
+ let vertFlag = 0;
681
+ vertFlag |= colorFlag;
682
+ vertFlag |= silhouetteFlag << 4;
683
+ vertFlag |= edgeFlag << 8;
684
+ vertFlag |= pickFlag << 12;
685
+ vertFlag |= clippableFlag << 16;
686
+
687
+ tempFloat32[0] = vertFlag;
688
+
689
+ if (this._state.flagsBuf) {
690
+ this._state.flagsBuf.setData(tempFloat32, portionId);
691
+ }
692
+ }
693
+
694
+ setOffset(portionId, offset) {
695
+ if (!this._finalized) {
696
+ throw "Not finalized";
697
+ }
698
+ if (!this.model.scene.entityOffsetsEnabled) {
699
+ this.model.error("Entity#offset not enabled for this Viewer"); // See Viewer entityOffsetsEnabled
700
+ return;
701
+ }
702
+ tempVec3fa[0] = offset[0];
703
+ tempVec3fa[1] = offset[1];
704
+ tempVec3fa[2] = offset[2];
705
+ if (this._state.offsetsBuf) {
706
+ this._state.offsetsBuf.setData(tempVec3fa, portionId * 3);
707
+ }
708
+ }
709
+
710
+ getEachVertex(portionId, callback) {
711
+ if (!this.model.scene.pickSurfacePrecisionEnabled) {
712
+ return false;
713
+ }
714
+ const state = this._state;
715
+ const geometry = state.geometry;
716
+ const portion = this._portions[portionId];
717
+ if (!portion) {
718
+ this.model.error("portion not found: " + portionId);
719
+ return;
720
+ }
721
+ const positions = geometry.quantizedPositions;
722
+ const origin = state.origin;
723
+ const offset = portion.offset;
724
+ const offsetX = origin[0] + offset[0];
725
+ const offsetY = origin[1] + offset[1];
726
+ const offsetZ = origin[2] + offset[2];
727
+ const worldPos = tempVec4a;
728
+ const portionMatrix = portion.matrix;
729
+ const sceneModelPatrix = this.model.sceneModelMatrix;
730
+ const positionsDecodeMatrix = state.positionsDecodeMatrix;
731
+ for (let i = 0, len = positions.length; i < len; i += 3) {
732
+ worldPos[0] = positions[i];
733
+ worldPos[1] = positions[i + 1];
734
+ worldPos[2] = positions[i + 2];
735
+ math.decompressPosition(worldPos, positionsDecodeMatrix);
736
+ math.transformPoint3(portionMatrix, worldPos);
737
+ math.transformPoint3(sceneModelPatrix, worldPos);
738
+ worldPos[0] += offsetX;
739
+ worldPos[1] += offsetY;
740
+ worldPos[2] += offsetZ;
741
+ callback(worldPos);
742
+ }
743
+ }
744
+
745
+ // ---------------------- COLOR RENDERING -----------------------------------
746
+
747
+ drawColorOpaque(renderFlags, frameCtx) {
748
+ if (this._numCulledLayerPortions === this._numPortions || this._numVisibleLayerPortions === 0 || this._numTransparentLayerPortions === this._numPortions || this._numXRayedLayerPortions === this._numPortions) {
749
+ return;
750
+ }
751
+ this._updateBackfaceCull(renderFlags, frameCtx);
752
+ if (frameCtx.withSAO && this.model.saoEnabled) {
753
+ if (frameCtx.pbrEnabled && this.model.pbrEnabled && this._state.pbrSupported) {
754
+ if (this._instancingRenderers.pbrRendererWithSAO) {
755
+ this._instancingRenderers.pbrRendererWithSAO.drawLayer(frameCtx, this, RENDER_PASSES.COLOR_OPAQUE);
756
+ }
757
+ } else if (frameCtx.colorTextureEnabled && this.model.colorTextureEnabled && this._state.colorTextureSupported) {
758
+ if (this._instancingRenderers.colorTextureRendererWithSAO) {
759
+ this._instancingRenderers.colorTextureRendererWithSAO.drawLayer(frameCtx, this, RENDER_PASSES.COLOR_OPAQUE);
760
+ }
761
+ } else if (this._state.normalsBuf) {
762
+ if (this._instancingRenderers.colorRendererWithSAO) {
763
+ this._instancingRenderers.colorRendererWithSAO.drawLayer(frameCtx, this, RENDER_PASSES.COLOR_OPAQUE);
764
+ }
765
+ } else {
766
+ if (this._instancingRenderers.flatColorRendererWithSAO) {
767
+ this._instancingRenderers.flatColorRendererWithSAO.drawLayer(frameCtx, this, RENDER_PASSES.COLOR_OPAQUE);
768
+ }
769
+ }
770
+ } else if (frameCtx.pbrEnabled && this.model.pbrEnabled && this._state.pbrSupported) {
771
+ if (this._instancingRenderers.pbrRenderer) {
772
+ this._instancingRenderers.pbrRenderer.drawLayer(frameCtx, this, RENDER_PASSES.COLOR_OPAQUE);
773
+ }
774
+ } else if (frameCtx.colorTextureEnabled && this.model.colorTextureEnabled && this._state.colorTextureSupported) {
775
+ if (this._instancingRenderers.colorTextureRenderer) {
776
+ this._instancingRenderers.colorTextureRenderer.drawLayer(frameCtx, this, RENDER_PASSES.COLOR_OPAQUE);
777
+ }
778
+ } else if (this._state.normalsBuf) {
779
+ if (this._instancingRenderers.colorRenderer) {
780
+ this._instancingRenderers.colorRenderer.drawLayer(frameCtx, this, RENDER_PASSES.COLOR_OPAQUE);
781
+ }
782
+ } else {
783
+ if (this._instancingRenderers.flatColorRenderer) {
784
+ this._instancingRenderers.flatColorRenderer.drawLayer(frameCtx, this, RENDER_PASSES.COLOR_OPAQUE);
785
+ }
786
+ }
787
+ }
788
+
789
+ _updateBackfaceCull(renderFlags, frameCtx) {
790
+ const backfaces = this.model.backfaces || (!this.solid) || renderFlags.sectioned;
791
+ if (frameCtx.backfaces !== backfaces) {
792
+ const gl = frameCtx.gl;
793
+ if (backfaces) {
794
+ gl.disable(gl.CULL_FACE);
795
+ } else {
796
+ gl.enable(gl.CULL_FACE);
797
+ }
798
+ frameCtx.backfaces = backfaces;
799
+ }
800
+ }
801
+
802
+ drawColorTransparent(renderFlags, frameCtx) {
803
+ if (this._numCulledLayerPortions === this._numPortions || this._numVisibleLayerPortions === 0 || this._numTransparentLayerPortions === 0 || this._numXRayedLayerPortions === this._numPortions) {
804
+ return;
805
+ }
806
+ this._updateBackfaceCull(renderFlags, frameCtx);
807
+ if (frameCtx.pbrEnabled && this.model.pbrEnabled && this._state.pbrSupported) {
808
+ if (this._instancingRenderers.pbrRenderer) {
809
+ this._instancingRenderers.pbrRenderer.drawLayer(frameCtx, this, RENDER_PASSES.COLOR_TRANSPARENT);
810
+ }
811
+ } else if (frameCtx.colorTextureEnabled && this.model.colorTextureEnabled && this._state.colorTextureSupported) {
812
+ if (this._instancingRenderers.colorTextureRenderer) {
813
+ this._instancingRenderers.colorTextureRenderer.drawLayer(frameCtx, this, RENDER_PASSES.COLOR_TRANSPARENT);
814
+ }
815
+ } else if (this._state.normalsBuf) {
816
+ if (this._instancingRenderers.colorRenderer) {
817
+ this._instancingRenderers.colorRenderer.drawLayer(frameCtx, this, RENDER_PASSES.COLOR_TRANSPARENT);
818
+ }
819
+ } else {
820
+ if (this._instancingRenderers.flatColorRenderer) {
821
+ this._instancingRenderers.flatColorRenderer.drawLayer(frameCtx, this, RENDER_PASSES.COLOR_TRANSPARENT);
822
+ }
823
+ }
824
+ }
825
+
826
+ // ---------------------- RENDERING SAO POST EFFECT TARGETS --------------
827
+
828
+ drawDepth(renderFlags, frameCtx) {
829
+ if (this._numCulledLayerPortions === this._numPortions || this._numVisibleLayerPortions === 0 || this._numTransparentLayerPortions === this._numPortions || this._numXRayedLayerPortions === this._numPortions) {
830
+ return;
831
+ }
832
+ this._updateBackfaceCull(renderFlags, frameCtx);
833
+ if (this._instancingRenderers.depthRenderer) {
834
+ this._instancingRenderers.depthRenderer.drawLayer(frameCtx, this, RENDER_PASSES.COLOR_OPAQUE); // Assume whatever post-effect uses depth (eg SAO) does not apply to transparent objects
835
+ }
836
+ }
837
+
838
+ drawNormals(renderFlags, frameCtx) {
839
+ if (this._numCulledLayerPortions === this._numPortions || this._numVisibleLayerPortions === 0 || this._numTransparentLayerPortions === this._numPortions || this._numXRayedLayerPortions === this._numPortions) {
840
+ return;
841
+ }
842
+ this._updateBackfaceCull(renderFlags, frameCtx);
843
+ if (this._instancingRenderers.normalsRenderer) {
844
+ this._instancingRenderers.normalsRenderer.drawLayer(frameCtx, this, RENDER_PASSES.COLOR_OPAQUE); // Assume whatever post-effect uses normals (eg SAO) does not apply to transparent objects
845
+ }
846
+ }
847
+
848
+ // ---------------------- SILHOUETTE RENDERING -----------------------------------
849
+
850
+ drawSilhouetteXRayed(renderFlags, frameCtx) {
851
+ if (this._numCulledLayerPortions === this._numPortions || this._numVisibleLayerPortions === 0 || this._numXRayedLayerPortions === 0) {
852
+ return;
853
+ }
854
+ this._updateBackfaceCull(renderFlags, frameCtx);
855
+ if (this._instancingRenderers.silhouetteRenderer) {
856
+ this._instancingRenderers.silhouetteRenderer.drawLayer(frameCtx, this, RENDER_PASSES.SILHOUETTE_XRAYED);
857
+ }
858
+ }
859
+
860
+ drawSilhouetteHighlighted(renderFlags, frameCtx) {
861
+ if (this._numCulledLayerPortions === this._numPortions || this._numVisibleLayerPortions === 0 || this._numHighlightedLayerPortions === 0) {
862
+ return;
863
+ }
864
+ this._updateBackfaceCull(renderFlags, frameCtx);
865
+ if (this._instancingRenderers.silhouetteRenderer) {
866
+ this._instancingRenderers.silhouetteRenderer.drawLayer(frameCtx, this, RENDER_PASSES.SILHOUETTE_HIGHLIGHTED);
867
+ }
868
+ }
869
+
870
+ drawSilhouetteSelected(renderFlags, frameCtx) {
871
+ if (this._numCulledLayerPortions === this._numPortions || this._numVisibleLayerPortions === 0 || this._numSelectedLayerPortions === 0) {
872
+ return;
873
+ }
874
+ this._updateBackfaceCull(renderFlags, frameCtx);
875
+ if (this._instancingRenderers.silhouetteRenderer) {
876
+ this._instancingRenderers.silhouetteRenderer.drawLayer(frameCtx, this, RENDER_PASSES.SILHOUETTE_SELECTED);
877
+ }
878
+ }
879
+
880
+ // ---------------------- EDGES RENDERING -----------------------------------
881
+
882
+ drawEdgesColorOpaque(renderFlags, frameCtx) {
883
+ if (this._numCulledLayerPortions === this._numPortions || this._numVisibleLayerPortions === 0 || this._numEdgesLayerPortions === 0) {
884
+ return;
885
+ }
886
+ if (this._instancingRenderers.edgesColorRenderer) {
887
+ this._instancingRenderers.edgesColorRenderer.drawLayer(frameCtx, this, RENDER_PASSES.EDGES_COLOR_OPAQUE);
888
+ }
889
+ }
890
+
891
+ drawEdgesColorTransparent(renderFlags, frameCtx) {
892
+ if (this._numCulledLayerPortions === this._numPortions || this._numVisibleLayerPortions === 0 || this._numEdgesLayerPortions === 0) {
893
+ return;
894
+ }
895
+ if (this._instancingRenderers.edgesColorRenderer) {
896
+ this._instancingRenderers.edgesColorRenderer.drawLayer(frameCtx, this, RENDER_PASSES.EDGES_COLOR_TRANSPARENT);
897
+ }
898
+ }
899
+
900
+ drawEdgesXRayed(renderFlags, frameCtx) {
901
+ if (this._numCulledLayerPortions === this._numPortions || this._numVisibleLayerPortions === 0 || this._numXRayedLayerPortions === 0) {
902
+ return;
903
+ }
904
+ if (this._instancingRenderers.edgesRenderer) {
905
+ this._instancingRenderers.edgesRenderer.drawLayer(frameCtx, this, RENDER_PASSES.EDGES_XRAYED);
906
+ }
907
+ }
908
+
909
+ drawEdgesHighlighted(renderFlags, frameCtx) {
910
+ if (this._numCulledLayerPortions === this._numPortions || this._numVisibleLayerPortions === 0 || this._numHighlightedLayerPortions === 0) {
911
+ return;
912
+ }
913
+ if (this._instancingRenderers.edgesRenderer) {
914
+ this._instancingRenderers.edgesRenderer.drawLayer(frameCtx, this, RENDER_PASSES.EDGES_HIGHLIGHTED);
915
+ }
916
+ }
917
+
918
+ drawEdgesSelected(renderFlags, frameCtx) {
919
+ if (this._numCulledLayerPortions === this._numPortions || this._numVisibleLayerPortions === 0 || this._numSelectedLayerPortions === 0) {
920
+ return;
921
+ }
922
+ if (this._instancingRenderers.edgesRenderer) {
923
+ this._instancingRenderers.edgesRenderer.drawLayer(frameCtx, this, RENDER_PASSES.EDGES_SELECTED);
924
+ }
925
+ }
926
+
927
+ // ---------------------- OCCLUSION CULL RENDERING -----------------------------------
928
+
929
+ drawOcclusion(renderFlags, frameCtx) {
930
+ if (this._numCulledLayerPortions === this._numPortions || this._numVisibleLayerPortions === 0) {
931
+ return;
932
+ }
933
+ this._updateBackfaceCull(renderFlags, frameCtx);
934
+ if (this._instancingRenderers.occlusionRenderer) {
935
+ // Only opaque, filled objects can be occluders
936
+ this._instancingRenderers.occlusionRenderer.drawLayer(frameCtx, this, RENDER_PASSES.COLOR_OPAQUE);
937
+ }
938
+ }
939
+
940
+ // ---------------------- SHADOW BUFFER RENDERING -----------------------------------
941
+
942
+ drawShadow(renderFlags, frameCtx) {
943
+ if (this._numCulledLayerPortions === this._numPortions || this._numVisibleLayerPortions === 0) {
944
+ return;
945
+ }
946
+ this._updateBackfaceCull(renderFlags, frameCtx);
947
+ if (this._instancingRenderers.shadowRenderer) {
948
+ this._instancingRenderers.shadowRenderer.drawLayer(frameCtx, this, RENDER_PASSES.COLOR_OPAQUE);
949
+ }
950
+ }
951
+
952
+ //---- PICKING ----------------------------------------------------------------------------------------------------
953
+
954
+ drawPickMesh(renderFlags, frameCtx) {
955
+ if (this._numCulledLayerPortions === this._numPortions || this._numVisibleLayerPortions === 0) {
956
+ return;
957
+ }
958
+ this._updateBackfaceCull(renderFlags, frameCtx);
959
+ if (this._instancingRenderers.pickMeshRenderer) {
960
+ this._instancingRenderers.pickMeshRenderer.drawLayer(frameCtx, this, RENDER_PASSES.PICK);
961
+ }
962
+ }
963
+
964
+ drawPickDepths(renderFlags, frameCtx) {
965
+ if (this._numCulledLayerPortions === this._numPortions || this._numVisibleLayerPortions === 0) {
966
+ return;
967
+ }
968
+ this._updateBackfaceCull(renderFlags, frameCtx);
969
+ if (this._instancingRenderers.pickDepthRenderer) {
970
+ this._instancingRenderers.pickDepthRenderer.drawLayer(frameCtx, this, RENDER_PASSES.PICK);
971
+ }
972
+ }
973
+
974
+ drawPickNormals(renderFlags, frameCtx) {
975
+ if (this._numCulledLayerPortions === this._numPortions || this._numVisibleLayerPortions === 0) {
976
+ return;
977
+ }
978
+ this._updateBackfaceCull(renderFlags, frameCtx);
979
+ if (this._instancingRenderers.pickNormalsRenderer) {
980
+ this._instancingRenderers.pickNormalsRenderer.drawLayer(frameCtx, this, RENDER_PASSES.PICK);
981
+ }
982
+ }
983
+
984
+ drawSnapInitDepthBuf(renderFlags, frameCtx) {
985
+ if (this._numCulledLayerPortions === this._numPortions || this._numVisibleLayerPortions === 0) {
986
+ return;
987
+ }
988
+ this._updateBackfaceCull(renderFlags, frameCtx);
989
+ if (this._snapInstancingRenderers.snapDepthBufInitRenderer) {
990
+ this._snapInstancingRenderers.snapDepthBufInitRenderer.drawLayer(frameCtx, this, RENDER_PASSES.PICK);
991
+ }
992
+ }
993
+
994
+ drawSnapDepths(renderFlags, frameCtx) {
995
+ if (this._numCulledLayerPortions === this._numPortions || this._numVisibleLayerPortions === 0) {
996
+ return;
997
+ }
998
+ this._updateBackfaceCull(renderFlags, frameCtx);
999
+ if (this._snapInstancingRenderers.snapDepthRenderer) {
1000
+ this._snapInstancingRenderers.snapDepthRenderer.drawLayer(frameCtx, this, RENDER_PASSES.PICK);
1001
+ }
1002
+ }
1003
+
1004
+ //-----------------------------------------------------------------------------------------
1005
+
1006
+ precisionRayPickSurface(portionId, worldRayOrigin, worldRayDir, worldSurfacePos, worldNormal) {
1007
+
1008
+ if (!this.model.scene.pickSurfacePrecisionEnabled) {
1009
+ return false;
1010
+ }
1011
+
1012
+ const geometry = this._state.geometry;
1013
+ const state = this._state;
1014
+ const portion = this._portions[portionId];
1015
+
1016
+ if (!portion) {
1017
+ this.model.error("portion not found: " + portionId);
1018
+ return false;
1019
+ }
1020
+
1021
+ if (!portion.inverseMatrix) {
1022
+ portion.inverseMatrix = math.inverseMat4(portion.matrix, math.mat4());
1023
+ }
1024
+
1025
+ if (worldNormal && !portion.normalMatrix) {
1026
+ portion.normalMatrix = math.transposeMat4(portion.inverseMatrix, math.mat4());
1027
+ }
1028
+
1029
+ const quantizedPositions = geometry.quantizedPositions;
1030
+ const indices = geometry.indices;
1031
+ const origin = state.origin;
1032
+ const offset = portion.offset;
1033
+
1034
+ const rtcRayOrigin = tempVec3a;
1035
+ const rtcRayDir = tempVec3b;
1036
+
1037
+ rtcRayOrigin.set(origin ? math.subVec3(worldRayOrigin, origin, tempVec3c) : worldRayOrigin); // World -> RTC
1038
+ rtcRayDir.set(worldRayDir);
1039
+
1040
+ if (offset) {
1041
+ math.subVec3(rtcRayOrigin, offset);
1042
+ }
1043
+
1044
+ math.transformRay(this.model.worldNormalMatrix, rtcRayOrigin, rtcRayDir, rtcRayOrigin, rtcRayDir);
1045
+
1046
+ math.transformRay(portion.inverseMatrix, rtcRayOrigin, rtcRayDir, rtcRayOrigin, rtcRayDir);
1047
+
1048
+ const a = tempVec3d;
1049
+ const b = tempVec3e;
1050
+ const c = tempVec3f;
1051
+
1052
+ let gotIntersect = false;
1053
+ let closestDist = 0;
1054
+ const closestIntersectPos = tempVec3g;
1055
+
1056
+ for (let i = 0, len = indices.length; i < len; i += 3) {
1057
+
1058
+ const ia = indices[i + 0] * 3;
1059
+ const ib = indices[i + 1] * 3;
1060
+ const ic = indices[i + 2] * 3;
1061
+
1062
+ a[0] = quantizedPositions[ia];
1063
+ a[1] = quantizedPositions[ia + 1];
1064
+ a[2] = quantizedPositions[ia + 2];
1065
+
1066
+ b[0] = quantizedPositions[ib];
1067
+ b[1] = quantizedPositions[ib + 1];
1068
+ b[2] = quantizedPositions[ib + 2];
1069
+
1070
+ c[0] = quantizedPositions[ic];
1071
+ c[1] = quantizedPositions[ic + 1];
1072
+ c[2] = quantizedPositions[ic + 2];
1073
+
1074
+ const {positionsDecodeMatrix} = state.geometry;
1075
+
1076
+ math.decompressPosition(a, positionsDecodeMatrix);
1077
+ math.decompressPosition(b, positionsDecodeMatrix);
1078
+ math.decompressPosition(c, positionsDecodeMatrix);
1079
+
1080
+ if (math.rayTriangleIntersect(rtcRayOrigin, rtcRayDir, a, b, c, closestIntersectPos)) {
1081
+
1082
+ math.transformPoint3(portion.matrix, closestIntersectPos, closestIntersectPos);
1083
+
1084
+ math.transformPoint3(this.model.worldMatrix, closestIntersectPos, closestIntersectPos);
1085
+
1086
+ if (offset) {
1087
+ math.addVec3(closestIntersectPos, offset);
1088
+ }
1089
+
1090
+ if (origin) {
1091
+ math.addVec3(closestIntersectPos, origin);
1092
+ }
1093
+
1094
+ const dist = Math.abs(math.lenVec3(math.subVec3(closestIntersectPos, worldRayOrigin, [])));
1095
+
1096
+ if (!gotIntersect || dist > closestDist) {
1097
+ closestDist = dist;
1098
+ worldSurfacePos.set(closestIntersectPos);
1099
+ if (worldNormal) { // Not that wasteful to eagerly compute - unlikely to hit >2 surfaces on most geometry
1100
+ math.triangleNormal(a, b, c, worldNormal);
1101
+ }
1102
+ gotIntersect = true;
1103
+ }
1104
+ }
1105
+ }
1106
+
1107
+ if (gotIntersect && worldNormal) {
1108
+ math.transformVec3(portion.normalMatrix, worldNormal, worldNormal);
1109
+ math.transformVec3(this.model.worldNormalMatrix, worldNormal, worldNormal);
1110
+ math.normalizeVec3(worldNormal);
1111
+ }
1112
+
1113
+ return gotIntersect;
1114
+ }
1115
+
1116
+ destroy() {
1117
+ const state = this._state;
1118
+ if (state.colorsBuf) {
1119
+ state.colorsBuf.destroy();
1120
+ state.colorsBuf = null;
1121
+ }
1122
+ if (state.metallicRoughnessBuf) {
1123
+ state.metallicRoughnessBuf.destroy();
1124
+ state.metallicRoughnessBuf = null;
1125
+ }
1126
+ if (state.flagsBuf) {
1127
+ state.flagsBuf.destroy();
1128
+ state.flagsBuf = null;
1129
+ }
1130
+ if (state.offsetsBuf) {
1131
+ state.offsetsBuf.destroy();
1132
+ state.offsetsBuf = null;
1133
+ }
1134
+ if (state.modelMatrixCol0Buf) {
1135
+ state.modelMatrixCol0Buf.destroy();
1136
+ state.modelMatrixCol0Buf = null;
1137
+ }
1138
+ if (state.modelMatrixCol1Buf) {
1139
+ state.modelMatrixCol1Buf.destroy();
1140
+ state.modelMatrixCol1Buf = null;
1141
+ }
1142
+ if (state.modelMatrixCol2Buf) {
1143
+ state.modelMatrixCol2Buf.destroy();
1144
+ state.modelMatrixCol2Buf = null;
1145
+ }
1146
+ if (state.modelNormalMatrixCol0Buf) {
1147
+ state.modelNormalMatrixCol0Buf.destroy();
1148
+ state.modelNormalMatrixCol0Buf = null;
1149
+ }
1150
+ if (state.modelNormalMatrixCol1Buf) {
1151
+ state.modelNormalMatrixCol1Buf.destroy();
1152
+ state.modelNormalMatrixCol1Buf = null;
1153
+ }
1154
+ if (state.modelNormalMatrixCol2Buf) {
1155
+ state.modelNormalMatrixCol2Buf.destroy();
1156
+ state.modelNormalMatrixCol2Buf = null;
1157
+ }
1158
+ if (state.pickColorsBuf) {
1159
+ state.pickColorsBuf.destroy();
1160
+ state.pickColorsBuf = null;
1161
+ }
1162
+ state.destroy();
1163
+ this._state = null;
1164
+ }
1165
+ }
1166
+
1167
+ export {TrianglesInstancingLayer};