@xeokit/xeokit-sdk 2.5.2-beta-10 → 2.5.2-beta-13

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 (462) hide show
  1. package/dist/xeokit-sdk.cjs.js +146 -132
  2. package/dist/xeokit-sdk.es.js +146 -132
  3. package/dist/xeokit-sdk.es5.js +84 -84
  4. package/dist/xeokit-sdk.min.cjs.js +1 -1
  5. package/dist/xeokit-sdk.min.es.js +1 -1
  6. package/dist/xeokit-sdk.min.es5.js +1 -1
  7. package/package.json +1 -1
  8. package/src/src/extras/ContextMenu/ContextMenu.js +907 -0
  9. package/src/src/extras/ContextMenu/index.js +1 -0
  10. package/src/src/extras/MarqueePicker/MarqueePicker.js +352 -0
  11. package/src/src/extras/MarqueePicker/MarqueePickerMouseControl.js +174 -0
  12. package/src/src/extras/MarqueePicker/index.js +2 -0
  13. package/src/src/extras/PointerLens/PointerLens.js +312 -0
  14. package/src/src/extras/PointerLens/index.js +1 -0
  15. package/src/src/extras/collision/ObjectsKdTree3.js +149 -0
  16. package/src/src/extras/collision/index.js +1 -0
  17. package/src/src/extras/index.js +4 -0
  18. package/src/src/index.js +3 -0
  19. package/src/src/plugins/AngleMeasurementsPlugin/AngleMeasurement.js +731 -0
  20. package/src/src/plugins/AngleMeasurementsPlugin/AngleMeasurementsControl.js +84 -0
  21. package/src/src/plugins/AngleMeasurementsPlugin/AngleMeasurementsMouseControl.js +435 -0
  22. package/src/src/plugins/AngleMeasurementsPlugin/AngleMeasurementsPlugin.js +406 -0
  23. package/src/src/plugins/AngleMeasurementsPlugin/index.js +3 -0
  24. package/src/src/plugins/AnnotationsPlugin/Annotation.js +368 -0
  25. package/src/src/plugins/AnnotationsPlugin/AnnotationsPlugin.js +583 -0
  26. package/src/src/plugins/AnnotationsPlugin/index.js +1 -0
  27. package/src/src/plugins/AxisGizmoPlugin/AxisGizmoPlugin.js +333 -0
  28. package/src/src/plugins/AxisGizmoPlugin/index.js +1 -0
  29. package/src/src/plugins/BCFViewpointsPlugin/BCFViewpointsPlugin.js +977 -0
  30. package/src/src/plugins/BCFViewpointsPlugin/index.js +1 -0
  31. package/src/src/plugins/CityJSONLoaderPlugin/CityJSONDefaultDataSource.js +29 -0
  32. package/src/src/plugins/CityJSONLoaderPlugin/CityJSONLoaderPlugin.js +751 -0
  33. package/src/src/plugins/CityJSONLoaderPlugin/index.js +1 -0
  34. package/src/src/plugins/DistanceMeasurementsPlugin/DistanceMeasurement.js +963 -0
  35. package/src/src/plugins/DistanceMeasurementsPlugin/DistanceMeasurementsControl.js +84 -0
  36. package/src/src/plugins/DistanceMeasurementsPlugin/DistanceMeasurementsMouseControl.js +399 -0
  37. package/src/src/plugins/DistanceMeasurementsPlugin/DistanceMeasurementsPlugin.js +505 -0
  38. package/src/src/plugins/DistanceMeasurementsPlugin/index.js +3 -0
  39. package/src/src/plugins/FaceAlignedSectionPlanesPlugin/FaceAlignedSectionPlanesControl.js +639 -0
  40. package/src/src/plugins/FaceAlignedSectionPlanesPlugin/FaceAlignedSectionPlanesPlugin.js +436 -0
  41. package/src/src/plugins/FaceAlignedSectionPlanesPlugin/Overview.js +247 -0
  42. package/src/src/plugins/FaceAlignedSectionPlanesPlugin/Plane.js +167 -0
  43. package/src/src/plugins/FaceAlignedSectionPlanesPlugin/index.js +1 -0
  44. package/src/src/plugins/FastNavPlugin/FastNavPlugin.js +429 -0
  45. package/src/src/plugins/FastNavPlugin/index.js +1 -0
  46. package/src/src/plugins/GLTFLoaderPlugin/GLTFDefaultDataSource.js +140 -0
  47. package/src/src/plugins/GLTFLoaderPlugin/GLTFLoaderPlugin.js +421 -0
  48. package/src/src/plugins/GLTFLoaderPlugin/GLTFSceneModelLoader.js +669 -0
  49. package/src/src/plugins/GLTFLoaderPlugin/index.js +2 -0
  50. package/src/src/plugins/LASLoaderPlugin/LASDefaultDataSource.js +58 -0
  51. package/src/src/plugins/LASLoaderPlugin/LASLoaderPlugin.js +563 -0
  52. package/src/src/plugins/LASLoaderPlugin/index.js +1 -0
  53. package/src/src/plugins/LASLoaderPlugin/loadLASHeader.js +183 -0
  54. package/src/src/plugins/NavCubePlugin/CubeTextureCanvas.js +290 -0
  55. package/src/src/plugins/NavCubePlugin/NavCubePlugin.js +753 -0
  56. package/src/src/plugins/NavCubePlugin/index.js +1 -0
  57. package/src/src/plugins/OBJLoaderPlugin/OBJLoaderPlugin.js +145 -0
  58. package/src/src/plugins/OBJLoaderPlugin/OBJSceneGraphLoader.js +777 -0
  59. package/src/src/plugins/OBJLoaderPlugin/index.js +1 -0
  60. package/src/src/plugins/STLLoaderPlugin/STLDefaultDataSource.js +33 -0
  61. package/src/src/plugins/STLLoaderPlugin/STLLoaderPlugin.js +274 -0
  62. package/src/src/plugins/STLLoaderPlugin/STLSceneGraphLoader.js +313 -0
  63. package/src/src/plugins/STLLoaderPlugin/index.js +2 -0
  64. package/src/src/plugins/SectionPlanesPlugin/Control.js +1328 -0
  65. package/src/src/plugins/SectionPlanesPlugin/Overview.js +249 -0
  66. package/src/src/plugins/SectionPlanesPlugin/Plane.js +169 -0
  67. package/src/src/plugins/SectionPlanesPlugin/SectionPlanesPlugin.js +404 -0
  68. package/src/src/plugins/SectionPlanesPlugin/index.js +1 -0
  69. package/src/src/plugins/SkyboxesPlugin/SkyboxesPlugin.js +134 -0
  70. package/src/src/plugins/SkyboxesPlugin/index.js +1 -0
  71. package/src/src/plugins/StoreyViewsPlugin/Storey.js +84 -0
  72. package/src/src/plugins/StoreyViewsPlugin/StoreyMap.js +57 -0
  73. package/src/src/plugins/StoreyViewsPlugin/StoreyViewsPlugin.js +773 -0
  74. package/src/src/plugins/StoreyViewsPlugin/index.js +1 -0
  75. package/src/src/plugins/TreeViewPlugin/RenderService.js +169 -0
  76. package/src/src/plugins/TreeViewPlugin/TreeViewNode.js +101 -0
  77. package/src/src/plugins/TreeViewPlugin/TreeViewPlugin.js +1370 -0
  78. package/src/src/plugins/TreeViewPlugin/index.js +1 -0
  79. package/src/src/plugins/ViewCullPlugin/ViewCullPlugin.js +295 -0
  80. package/src/src/plugins/ViewCullPlugin/index.js +1 -0
  81. package/src/src/plugins/WebIFCLoaderPlugin/WebIFCDefaultDataSource.js +58 -0
  82. package/src/src/plugins/WebIFCLoaderPlugin/WebIFCLoaderPlugin.js +942 -0
  83. package/src/src/plugins/WebIFCLoaderPlugin/index.js +1 -0
  84. package/src/src/plugins/XKTLoaderPlugin/XKTDefaultDataSource.js +95 -0
  85. package/src/src/plugins/XKTLoaderPlugin/XKTLoaderPlugin.js +1194 -0
  86. package/src/src/plugins/XKTLoaderPlugin/index.js +2 -0
  87. package/src/src/plugins/XKTLoaderPlugin/parsers/ParserV1.js +169 -0
  88. package/src/src/plugins/XKTLoaderPlugin/parsers/ParserV10.js +660 -0
  89. package/src/src/plugins/XKTLoaderPlugin/parsers/ParserV11.js +663 -0
  90. package/src/src/plugins/XKTLoaderPlugin/parsers/ParserV2.js +230 -0
  91. package/src/src/plugins/XKTLoaderPlugin/parsers/ParserV3.js +223 -0
  92. package/src/src/plugins/XKTLoaderPlugin/parsers/ParserV4.js +283 -0
  93. package/src/src/plugins/XKTLoaderPlugin/parsers/ParserV5.js +246 -0
  94. package/src/src/plugins/XKTLoaderPlugin/parsers/ParserV6.js +301 -0
  95. package/src/src/plugins/XKTLoaderPlugin/parsers/ParserV7.js +439 -0
  96. package/src/src/plugins/XKTLoaderPlugin/parsers/ParserV8.js +563 -0
  97. package/src/src/plugins/XKTLoaderPlugin/parsers/ParserV9.js +518 -0
  98. package/src/src/plugins/XKTLoaderPlugin/parsers/lib/pako.js +2 -0
  99. package/src/src/plugins/XML3DLoaderPlugin/XML3DLoaderPlugin.js +238 -0
  100. package/src/src/plugins/XML3DLoaderPlugin/XML3DSceneGraphLoader.js +1279 -0
  101. package/src/src/plugins/XML3DLoaderPlugin/index.js +1 -0
  102. package/src/src/plugins/XML3DLoaderPlugin/zipjs/.jshintrc +11 -0
  103. package/src/src/plugins/XML3DLoaderPlugin/zipjs/deflate.js +2060 -0
  104. package/src/src/plugins/XML3DLoaderPlugin/zipjs/inflate.js +2155 -0
  105. package/src/src/plugins/XML3DLoaderPlugin/zipjs/mime-types.js +1002 -0
  106. package/src/src/plugins/XML3DLoaderPlugin/zipjs/pako/codecs.js +64 -0
  107. package/src/src/plugins/XML3DLoaderPlugin/zipjs/z-worker.js +153 -0
  108. package/src/src/plugins/XML3DLoaderPlugin/zipjs/zip-ext.js +267 -0
  109. package/src/src/plugins/XML3DLoaderPlugin/zipjs/zip-fs.js +553 -0
  110. package/src/src/plugins/XML3DLoaderPlugin/zipjs/zip.js +991 -0
  111. package/src/src/plugins/XML3DLoaderPlugin/zipjs/zlib-asm/codecs.js +49 -0
  112. package/src/src/plugins/index.js +21 -0
  113. package/src/src/plugins/lib/culling/ObjectCullStates.js +208 -0
  114. package/src/src/plugins/lib/earcut.js +677 -0
  115. package/src/src/plugins/lib/html/Dot.js +179 -0
  116. package/src/src/plugins/lib/html/Label.js +174 -0
  117. package/src/src/plugins/lib/html/Wire.js +220 -0
  118. package/src/src/viewer/Configs.js +127 -0
  119. package/src/src/viewer/Plugin.js +233 -0
  120. package/src/src/viewer/Viewer.js +542 -0
  121. package/src/src/viewer/index.js +5 -0
  122. package/src/src/viewer/localization/LocaleService.js +475 -0
  123. package/src/src/viewer/metadata/IFCObjectDefaultColors.js +163 -0
  124. package/src/src/viewer/metadata/IFCObjectDefaults.js +17 -0
  125. package/src/src/viewer/metadata/MetaModel.js +414 -0
  126. package/src/src/viewer/metadata/MetaObject.js +223 -0
  127. package/src/src/viewer/metadata/MetaScene.js +336 -0
  128. package/src/src/viewer/metadata/Property.js +55 -0
  129. package/src/src/viewer/metadata/PropertySet.js +77 -0
  130. package/src/src/viewer/scene/Bitmap/Bitmap.js +473 -0
  131. package/src/src/viewer/scene/Bitmap/index.js +1 -0
  132. package/src/src/viewer/scene/CameraControl/CameraControl.js +1750 -0
  133. package/src/src/viewer/scene/CameraControl/lib/CameraUpdater.js +312 -0
  134. package/src/src/viewer/scene/CameraControl/lib/controllers/PanController.js +112 -0
  135. package/src/src/viewer/scene/CameraControl/lib/controllers/PickController.js +265 -0
  136. package/src/src/viewer/scene/CameraControl/lib/controllers/PivotController.js +384 -0
  137. package/src/src/viewer/scene/CameraControl/lib/handlers/KeyboardAxisViewHandler.js +122 -0
  138. package/src/src/viewer/scene/CameraControl/lib/handlers/KeyboardPanRotateDollyHandler.js +183 -0
  139. package/src/src/viewer/scene/CameraControl/lib/handlers/MouseMiscHandler.js +68 -0
  140. package/src/src/viewer/scene/CameraControl/lib/handlers/MousePanRotateDollyHandler.js +345 -0
  141. package/src/src/viewer/scene/CameraControl/lib/handlers/MousePickHandler.js +376 -0
  142. package/src/src/viewer/scene/CameraControl/lib/handlers/TouchPanRotateAndDollyHandler.js +288 -0
  143. package/src/src/viewer/scene/CameraControl/lib/handlers/TouchPickHandler.js +235 -0
  144. package/src/src/viewer/scene/Component.js +915 -0
  145. package/src/src/viewer/scene/Entity.js +502 -0
  146. package/src/src/viewer/scene/ImagePlane/ImagePlane.js +570 -0
  147. package/src/src/viewer/scene/ImagePlane/index.js +1 -0
  148. package/src/src/viewer/scene/LineSet/LineSet.js +163 -0
  149. package/src/src/viewer/scene/LineSet/index.js +1 -0
  150. package/src/src/viewer/scene/camera/Camera.js +912 -0
  151. package/src/src/viewer/scene/camera/CameraFlightAnimation.js +669 -0
  152. package/src/src/viewer/scene/camera/CameraPath.js +194 -0
  153. package/src/src/viewer/scene/camera/CameraPathAnimation.js +326 -0
  154. package/src/src/viewer/scene/camera/CustomProjection.js +149 -0
  155. package/src/src/viewer/scene/camera/Frustum.js +316 -0
  156. package/src/src/viewer/scene/camera/Ortho.js +286 -0
  157. package/src/src/viewer/scene/camera/Perspective.js +304 -0
  158. package/src/src/viewer/scene/camera/index.js +2 -0
  159. package/src/src/viewer/scene/canvas/Canvas.js +490 -0
  160. package/src/src/viewer/scene/canvas/Spinner.js +323 -0
  161. package/src/src/viewer/scene/constants/constants.js +371 -0
  162. package/src/src/viewer/scene/core.js +268 -0
  163. package/src/src/viewer/scene/geometry/Geometry.js +33 -0
  164. package/src/src/viewer/scene/geometry/ReadableGeometry.js +682 -0
  165. package/src/src/viewer/scene/geometry/VBOGeometry.js +319 -0
  166. package/src/src/viewer/scene/geometry/builders/buildBoxGeometry.js +238 -0
  167. package/src/src/viewer/scene/geometry/builders/buildBoxLinesGeometry.js +106 -0
  168. package/src/src/viewer/scene/geometry/builders/buildCylinderGeometry.js +271 -0
  169. package/src/src/viewer/scene/geometry/builders/buildGridGeometry.js +102 -0
  170. package/src/src/viewer/scene/geometry/builders/buildPlaneGeometry.js +168 -0
  171. package/src/src/viewer/scene/geometry/builders/buildSphereGeometry.js +161 -0
  172. package/src/src/viewer/scene/geometry/builders/buildTorusGeometry.js +172 -0
  173. package/src/src/viewer/scene/geometry/builders/buildVectorTextGeometry.js +1721 -0
  174. package/src/src/viewer/scene/geometry/builders/index.js +8 -0
  175. package/src/src/viewer/scene/geometry/index.js +4 -0
  176. package/src/src/viewer/scene/geometry/loaders/index.js +2 -0
  177. package/src/src/viewer/scene/geometry/loaders/load3DSGeometry.js +103 -0
  178. package/src/src/viewer/scene/geometry/loaders/loadOBJGeometry.js +130 -0
  179. package/src/src/viewer/scene/index.js +21 -0
  180. package/src/src/viewer/scene/input/Input.js +1333 -0
  181. package/src/src/viewer/scene/libs/k3d.js +1032 -0
  182. package/src/src/viewer/scene/lights/AmbientLight.js +175 -0
  183. package/src/src/viewer/scene/lights/CubeTexture.js +156 -0
  184. package/src/src/viewer/scene/lights/DirLight.js +314 -0
  185. package/src/src/viewer/scene/lights/Light.js +29 -0
  186. package/src/src/viewer/scene/lights/LightMap.js +77 -0
  187. package/src/src/viewer/scene/lights/PointLight.js +395 -0
  188. package/src/src/viewer/scene/lights/ReflectionMap.js +79 -0
  189. package/src/src/viewer/scene/lights/Shadow.js +138 -0
  190. package/src/src/viewer/scene/lights/index.js +5 -0
  191. package/src/src/viewer/scene/marker/Marker.js +383 -0
  192. package/src/src/viewer/scene/marker/SpriteMarker.js +356 -0
  193. package/src/src/viewer/scene/marker/index.js +2 -0
  194. package/src/src/viewer/scene/materials/EdgeMaterial.js +359 -0
  195. package/src/src/viewer/scene/materials/EmphasisMaterial.js +613 -0
  196. package/src/src/viewer/scene/materials/Fresnel.js +222 -0
  197. package/src/src/viewer/scene/materials/LambertMaterial.js +378 -0
  198. package/src/src/viewer/scene/materials/LinesMaterial.js +169 -0
  199. package/src/src/viewer/scene/materials/Material.js +39 -0
  200. package/src/src/viewer/scene/materials/MetallicMaterial.js +820 -0
  201. package/src/src/viewer/scene/materials/PhongMaterial.js +860 -0
  202. package/src/src/viewer/scene/materials/PointsMaterial.js +409 -0
  203. package/src/src/viewer/scene/materials/SpecularMaterial.js +807 -0
  204. package/src/src/viewer/scene/materials/Texture.js +513 -0
  205. package/src/src/viewer/scene/materials/index.js +8 -0
  206. package/src/src/viewer/scene/math/Frustum.js +118 -0
  207. package/src/src/viewer/scene/math/buildEdgeIndices.js +162 -0
  208. package/src/src/viewer/scene/math/geometryCompressionUtils.js +365 -0
  209. package/src/src/viewer/scene/math/index.js +3 -0
  210. package/src/src/viewer/scene/math/math.js +5386 -0
  211. package/src/src/viewer/scene/math/rtcCoords.js +139 -0
  212. package/src/src/viewer/scene/mementos/CameraMemento.js +200 -0
  213. package/src/src/viewer/scene/mementos/ModelMemento.js +263 -0
  214. package/src/src/viewer/scene/mementos/ObjectsMemento.js +259 -0
  215. package/src/src/viewer/scene/mementos/index.js +3 -0
  216. package/src/src/viewer/scene/mesh/Mesh.js +2202 -0
  217. package/src/src/viewer/scene/mesh/draw/DrawRenderer.js +996 -0
  218. package/src/src/viewer/scene/mesh/draw/DrawShaderSource.js +1570 -0
  219. package/src/src/viewer/scene/mesh/emphasis/EmphasisEdgesRenderer.js +259 -0
  220. package/src/src/viewer/scene/mesh/emphasis/EmphasisEdgesShaderSource.js +159 -0
  221. package/src/src/viewer/scene/mesh/emphasis/EmphasisFillRenderer.js +286 -0
  222. package/src/src/viewer/scene/mesh/emphasis/EmphasisFillShaderSource.js +262 -0
  223. package/src/src/viewer/scene/mesh/index.js +1 -0
  224. package/src/src/viewer/scene/mesh/occlusion/OcclusionRenderer.js +217 -0
  225. package/src/src/viewer/scene/mesh/occlusion/OcclusionShaderSource.js +157 -0
  226. package/src/src/viewer/scene/mesh/pick/PickMeshRenderer.js +223 -0
  227. package/src/src/viewer/scene/mesh/pick/PickMeshShaderSource.js +151 -0
  228. package/src/src/viewer/scene/mesh/pick/PickTriangleRenderer.js +200 -0
  229. package/src/src/viewer/scene/mesh/pick/PickTriangleShaderSource.js +124 -0
  230. package/src/src/viewer/scene/mesh/shadow/ShadowRenderer.js +214 -0
  231. package/src/src/viewer/scene/mesh/shadow/ShadowShaderSource.js +98 -0
  232. package/src/src/viewer/scene/metriqs/Metriqs.js +259 -0
  233. package/src/src/viewer/scene/model/ENTITY_FLAGS.js +21 -0
  234. package/src/src/viewer/scene/model/PerformanceModel.js +26 -0
  235. package/src/src/viewer/scene/model/RENDER_PASSES.js +34 -0
  236. package/src/src/viewer/scene/model/SceneModel.js +4018 -0
  237. package/src/src/viewer/scene/model/SceneModelEntity.js +715 -0
  238. package/src/src/viewer/scene/model/SceneModelMesh.js +341 -0
  239. package/src/src/viewer/scene/model/SceneModelTexture.js +38 -0
  240. package/src/src/viewer/scene/model/SceneModelTextureSet.js +59 -0
  241. package/src/src/viewer/scene/model/SceneModelTransform.js +404 -0
  242. package/src/src/viewer/scene/model/VBOSceneModel.js +26 -0
  243. package/src/src/viewer/scene/model/calculateUniquePositions.js +126 -0
  244. package/src/src/viewer/scene/model/compression.js +227 -0
  245. package/src/src/viewer/scene/model/dtx/BindableDataTexture.js +31 -0
  246. package/src/src/viewer/scene/model/dtx/lines/DTXLinesBuffer.js +27 -0
  247. package/src/src/viewer/scene/model/dtx/lines/DTXLinesLayer.js +891 -0
  248. package/src/src/viewer/scene/model/dtx/lines/DTXLinesState.js +46 -0
  249. package/src/src/viewer/scene/model/dtx/lines/DTXLinesTextureFactory.js +411 -0
  250. package/src/src/viewer/scene/model/dtx/lines/dataTextureRamStats.js +49 -0
  251. package/src/src/viewer/scene/model/dtx/lines/rebucketPositions.js +208 -0
  252. package/src/src/viewer/scene/model/dtx/lines/renderers/DTXLinesColorRenderer.js +389 -0
  253. package/src/src/viewer/scene/model/dtx/lines/renderers/DTXLinesRenderers.js +65 -0
  254. package/src/src/viewer/scene/model/dtx/triangles/DTXTrianglesLayer.js +1322 -0
  255. package/src/src/viewer/scene/model/dtx/triangles/lib/DTXTrianglesBuffer.js +46 -0
  256. package/src/src/viewer/scene/model/dtx/triangles/lib/DTXTrianglesState.js +250 -0
  257. package/src/src/viewer/scene/model/dtx/triangles/lib/DTXTrianglesTextureFactory.js +518 -0
  258. package/src/src/viewer/scene/model/dtx/triangles/lib/dataTextureRamStats.js +54 -0
  259. package/src/src/viewer/scene/model/dtx/triangles/renderers/DTXTrianglesColorRenderer.js +619 -0
  260. package/src/src/viewer/scene/model/dtx/triangles/renderers/DTXTrianglesDepthRenderer.js +464 -0
  261. package/src/src/viewer/scene/model/dtx/triangles/renderers/DTXTrianglesEdgesColorRenderer.js +414 -0
  262. package/src/src/viewer/scene/model/dtx/triangles/renderers/DTXTrianglesEdgesRenderer.js +422 -0
  263. package/src/src/viewer/scene/model/dtx/triangles/renderers/DTXTrianglesNormalsRenderer.js +345 -0
  264. package/src/src/viewer/scene/model/dtx/triangles/renderers/DTXTrianglesOcclusionRenderer.js +436 -0
  265. package/src/src/viewer/scene/model/dtx/triangles/renderers/DTXTrianglesPickDepthRenderer.js +462 -0
  266. package/src/src/viewer/scene/model/dtx/triangles/renderers/DTXTrianglesPickMeshRenderer.js +436 -0
  267. package/src/src/viewer/scene/model/dtx/triangles/renderers/DTXTrianglesPickNormalsFlatRenderer.js +455 -0
  268. package/src/src/viewer/scene/model/dtx/triangles/renderers/DTXTrianglesPickNormalsRenderer.js +440 -0
  269. package/src/src/viewer/scene/model/dtx/triangles/renderers/DTXTrianglesRenderers.js +307 -0
  270. package/src/src/viewer/scene/model/dtx/triangles/renderers/DTXTrianglesSilhouetteRenderer.js +465 -0
  271. package/src/src/viewer/scene/model/dtx/triangles/renderers/DTXTrianglesSnapInitRenderer.js +466 -0
  272. package/src/src/viewer/scene/model/dtx/triangles/renderers/DTXTrianglesSnapRenderer.js +427 -0
  273. package/src/src/viewer/scene/model/index.js +5 -0
  274. package/src/src/viewer/scene/model/rebucketPositions.js +354 -0
  275. package/src/src/viewer/scene/model/vbo/ScratchMemory.js +63 -0
  276. package/src/src/viewer/scene/model/vbo/VBORenderer.js +646 -0
  277. package/src/src/viewer/scene/model/vbo/batching/lines/VBOBatchingLinesLayer.js +699 -0
  278. package/src/src/viewer/scene/model/vbo/batching/lines/lib/VBOBatchingLinesBuffer.js +19 -0
  279. package/src/src/viewer/scene/model/vbo/batching/lines/renderers/VBOBatchingLineSnapInitRenderer.js +316 -0
  280. package/src/src/viewer/scene/model/vbo/batching/lines/renderers/VBOBatchingLinesColorRenderer.js +114 -0
  281. package/src/src/viewer/scene/model/vbo/batching/lines/renderers/VBOBatchingLinesRenderers.js +99 -0
  282. package/src/src/viewer/scene/model/vbo/batching/lines/renderers/VBOBatchingLinesSilhouetteRenderer.js +124 -0
  283. package/src/src/viewer/scene/model/vbo/batching/lines/renderers/VBOBatchingLinesSnapInitRenderer.js +311 -0
  284. package/src/src/viewer/scene/model/vbo/batching/lines/renderers/VBOBatchingLinesSnapRenderer.js +309 -0
  285. package/src/src/viewer/scene/model/vbo/batching/lines/renderers/VBOSceneModelLineBatchingRenderer.js +24 -0
  286. package/src/src/viewer/scene/model/vbo/batching/points/VBOBatchingPointsBuffer.js +20 -0
  287. package/src/src/viewer/scene/model/vbo/batching/points/VBOBatchingPointsLayer.js +718 -0
  288. package/src/src/viewer/scene/model/vbo/batching/points/VBOBatchingPointsRenderer.js +24 -0
  289. package/src/src/viewer/scene/model/vbo/batching/points/renderers/VBOBatchingPointsColorRenderer.js +168 -0
  290. package/src/src/viewer/scene/model/vbo/batching/points/renderers/VBOBatchingPointsOcclusionRenderer.js +136 -0
  291. package/src/src/viewer/scene/model/vbo/batching/points/renderers/VBOBatchingPointsPickDepthRenderer.js +156 -0
  292. package/src/src/viewer/scene/model/vbo/batching/points/renderers/VBOBatchingPointsPickMeshRenderer.js +148 -0
  293. package/src/src/viewer/scene/model/vbo/batching/points/renderers/VBOBatchingPointsRenderers.js +144 -0
  294. package/src/src/viewer/scene/model/vbo/batching/points/renderers/VBOBatchingPointsShadowRenderer.js +107 -0
  295. package/src/src/viewer/scene/model/vbo/batching/points/renderers/VBOBatchingPointsSilhouetteRenderer.js +146 -0
  296. package/src/src/viewer/scene/model/vbo/batching/points/renderers/VBOBatchingPointsSnapInitRenderer.js +309 -0
  297. package/src/src/viewer/scene/model/vbo/batching/points/renderers/VBOBatchingPointsSnapRenderer.js +303 -0
  298. package/src/src/viewer/scene/model/vbo/batching/triangles/VBOBatchingTrianglesBuffer.js +24 -0
  299. package/src/src/viewer/scene/model/vbo/batching/triangles/VBOBatchingTrianglesLayer.js +1257 -0
  300. package/src/{viewer/scene/model/vbo/batching/triangles/renderers/VBOBatchingTrianglesEdgesColorRenderer.js → src/viewer/scene/model/vbo/batching/triangles/renderers/EdgesColorRenderer.js} +6 -2
  301. package/src/{viewer/scene/model/vbo/batching/triangles/renderers/VBOBatchingTrianglesEdgesRenderer.js → src/viewer/scene/model/vbo/batching/triangles/renderers/EdgesEmphasisRenderer.js} +6 -4
  302. package/src/src/viewer/scene/model/vbo/batching/triangles/renderers/EdgesRenderer.js +12 -0
  303. package/src/{viewer/scene/model/vbo/batching/triangles/renderers/VBOBatchingTrianglesRenderers.js → src/viewer/scene/model/vbo/batching/triangles/renderers/Renderers.js} +45 -45
  304. package/src/{viewer/scene/model/vbo/batching/triangles/renderers/VBOBatchingTrianglesRenderer.js → src/viewer/scene/model/vbo/batching/triangles/renderers/TrianglesBatchingRenderer.js} +4 -3
  305. package/src/{viewer/scene/model/vbo/batching/triangles/renderers/VBOBatchingTrianglesColorRenderer.js → src/viewer/scene/model/vbo/batching/triangles/renderers/TrianglesColorRenderer.js} +2 -2
  306. package/src/{viewer/scene/model/vbo/batching/triangles/renderers/VBOBatchingTrianglesColorTextureRenderer.js → src/viewer/scene/model/vbo/batching/triangles/renderers/TrianglesColorTextureRenderer.js} +2 -2
  307. package/src/{viewer/scene/model/vbo/batching/triangles/renderers/VBOBatchingTrianglesDepthRenderer.js → src/viewer/scene/model/vbo/batching/triangles/renderers/TrianglesDepthRenderer.js} +2 -2
  308. package/src/{viewer/scene/model/vbo/batching/triangles/renderers/VBOBatchingTrianglesFlatColorRenderer.js → src/viewer/scene/model/vbo/batching/triangles/renderers/TrianglesFlatColorRenderer.js} +2 -2
  309. package/src/{viewer/scene/model/vbo/batching/triangles/renderers/VBOBatchingTrianglesNormalsRenderer.js → src/viewer/scene/model/vbo/batching/triangles/renderers/TrianglesNormalsRenderer.js} +2 -2
  310. package/src/{viewer/scene/model/vbo/batching/triangles/renderers/VBOBatchingTrianglesOcclusionRenderer.js → src/viewer/scene/model/vbo/batching/triangles/renderers/TrianglesOcclusionRenderer.js} +2 -2
  311. package/src/{viewer/scene/model/vbo/batching/triangles/renderers/VBOBatchingTrianglesPBRRenderer.js → src/viewer/scene/model/vbo/batching/triangles/renderers/TrianglesPBRRenderer.js} +2 -2
  312. package/src/{viewer/scene/model/vbo/batching/triangles/renderers/VBOBatchingTrianglesPickDepthRenderer.js → src/viewer/scene/model/vbo/batching/triangles/renderers/TrianglesPickDepthRenderer.js} +2 -2
  313. package/src/{viewer/scene/model/vbo/batching/triangles/renderers/VBOBatchingTrianglesPickMeshRenderer.js → src/viewer/scene/model/vbo/batching/triangles/renderers/TrianglesPickMeshRenderer.js} +2 -2
  314. package/src/{viewer/scene/model/vbo/batching/triangles/renderers/VBOBatchingTrianglesPickNormalsFlatRenderer.js → src/viewer/scene/model/vbo/batching/triangles/renderers/TrianglesPickNormalsFlatRenderer.js} +2 -2
  315. package/src/{viewer/scene/model/vbo/batching/triangles/renderers/VBOBatchingTrianglesPickNormalsRenderer.js → src/viewer/scene/model/vbo/batching/triangles/renderers/TrianglesPickNormalsRenderer.js} +2 -2
  316. package/src/{viewer/scene/model/vbo/batching/triangles/renderers/VBOBatchingTrianglesShadowRenderer.js → src/viewer/scene/model/vbo/batching/triangles/renderers/TrianglesShadowRenderer.js} +2 -2
  317. package/src/{viewer/scene/model/vbo/batching/triangles/renderers/VBOBatchingTrianglesSilhouetteRenderer.js → src/viewer/scene/model/vbo/batching/triangles/renderers/TrianglesSilhouetteRenderer.js} +3 -3
  318. package/src/{viewer/scene/model/vbo/batching/triangles/renderers/VBOBatchingTrianglesSnapInitRenderer.js → src/viewer/scene/model/vbo/batching/triangles/renderers/TrianglesSnapInitRenderer.js} +1 -1
  319. package/src/{viewer/scene/model/vbo/batching/triangles/renderers/VBOBatchingTrianglesSnapRenderer.js → src/viewer/scene/model/vbo/batching/triangles/renderers/TrianglesSnapRenderer.js} +1 -1
  320. package/src/src/viewer/scene/model/vbo/float16.js +760 -0
  321. package/src/src/viewer/scene/model/vbo/instancing/lines/VBOInstancingLinesLayer.js +704 -0
  322. package/src/src/viewer/scene/model/vbo/instancing/lines/renderers/VBOInstancingLinesColorRenderer.js +148 -0
  323. package/src/src/viewer/scene/model/vbo/instancing/lines/renderers/VBOInstancingLinesRenderer.js +26 -0
  324. package/src/src/viewer/scene/model/vbo/instancing/lines/renderers/VBOInstancingLinesRenderers.js +139 -0
  325. package/src/src/viewer/scene/model/vbo/instancing/lines/renderers/VBOInstancingLinesSilhouetteRenderer.js +127 -0
  326. package/src/src/viewer/scene/model/vbo/instancing/lines/renderers/VBOInstancingLinesSnapInitRenderer.js +331 -0
  327. package/src/src/viewer/scene/model/vbo/instancing/lines/renderers/VBOInstancingLinesSnapRenderer.js +316 -0
  328. package/src/src/viewer/scene/model/vbo/instancing/points/VBOInstancingPointsLayer.js +728 -0
  329. package/src/src/viewer/scene/model/vbo/instancing/points/renderers/VBOInstancingPointsColorRenderer.js +174 -0
  330. package/src/src/viewer/scene/model/vbo/instancing/points/renderers/VBOInstancingPointsDepthRenderer.js +156 -0
  331. package/src/src/viewer/scene/model/vbo/instancing/points/renderers/VBOInstancingPointsOcclusionRenderer.js +149 -0
  332. package/src/src/viewer/scene/model/vbo/instancing/points/renderers/VBOInstancingPointsPickDepthRenderer.js +170 -0
  333. package/src/src/viewer/scene/model/vbo/instancing/points/renderers/VBOInstancingPointsPickMeshRenderer.js +152 -0
  334. package/src/src/viewer/scene/model/vbo/instancing/points/renderers/VBOInstancingPointsRenderer.js +26 -0
  335. package/src/src/viewer/scene/model/vbo/instancing/points/renderers/VBOInstancingPointsRenderers.js +174 -0
  336. package/src/src/viewer/scene/model/vbo/instancing/points/renderers/VBOInstancingPointsShadowRenderer.js +119 -0
  337. package/src/src/viewer/scene/model/vbo/instancing/points/renderers/VBOInstancingPointsSilhouetteRenderer.js +154 -0
  338. package/src/src/viewer/scene/model/vbo/instancing/points/renderers/VBOInstancingPointsSnapInitRenderer.js +330 -0
  339. package/src/src/viewer/scene/model/vbo/instancing/points/renderers/VBOInstancingPointsSnapRenderer.js +311 -0
  340. package/src/src/viewer/scene/model/vbo/instancing/points/renderers/VBOInstancingTrianglesRenderer.js +150 -0
  341. package/src/src/viewer/scene/model/vbo/instancing/triangles/VBOInstancingTrianglesLayer.js +1190 -0
  342. package/src/{viewer/scene/model/vbo/instancing/triangles/renderers/VBOInstancingTrianglesEdgesColorRenderer.js → src/viewer/scene/model/vbo/instancing/triangles/renderers/EdgesColorRenderer.js} +8 -4
  343. package/src/{viewer/scene/model/vbo/instancing/triangles/renderers/VBOInstancingTrianglesEdgesRenderer.js → src/viewer/scene/model/vbo/instancing/triangles/renderers/EdgesEmphasisRenderer.js} +8 -5
  344. package/src/src/viewer/scene/model/vbo/instancing/triangles/renderers/EdgesRenderer.js +12 -0
  345. package/src/{viewer/scene/model/vbo/instancing/triangles/renderers/VBOInstancingTrianglesRenderers.js → src/viewer/scene/model/vbo/instancing/triangles/renderers/Renderers.js} +45 -45
  346. package/src/{viewer/scene/model/vbo/instancing/triangles/renderers/VBOInstancingTrianglesColorRenderer.js → src/viewer/scene/model/vbo/instancing/triangles/renderers/TrianglesColorRenderer.js} +3 -3
  347. package/src/{viewer/scene/model/vbo/instancing/triangles/renderers/VBOInstancingTrianglesColorTextureRenderer.js → src/viewer/scene/model/vbo/instancing/triangles/renderers/TrianglesColorTextureRenderer.js} +2 -2
  348. package/src/{viewer/scene/model/vbo/instancing/triangles/renderers/VBOInstancingTrianglesDepthRenderer.js → src/viewer/scene/model/vbo/instancing/triangles/renderers/TrianglesDepthRenderer.js} +2 -2
  349. package/src/{viewer/scene/model/vbo/instancing/triangles/renderers/VBOInstancingTrianglesFlatColorRenderer.js → src/viewer/scene/model/vbo/instancing/triangles/renderers/TrianglesFlatColorRenderer.js} +2 -2
  350. package/src/{viewer/scene/model/vbo/instancing/triangles/renderers/VBOInstancingTrianglesFlatNormalsRenderer.js → src/viewer/scene/model/vbo/instancing/triangles/renderers/TrianglesFlatNormalsRenderer.js} +2 -2
  351. package/src/{viewer/scene/model/vbo/instancing/triangles/renderers/VBOSceneModelTriangleInstancingRenderer.js → src/viewer/scene/model/vbo/instancing/triangles/renderers/TrianglesInstancingRenderer.js} +1 -1
  352. package/src/{viewer/scene/model/vbo/instancing/triangles/renderers/VBOInstancingTrianglesNormalsRenderer.js → src/viewer/scene/model/vbo/instancing/triangles/renderers/TrianglesNormalsRenderer.js} +2 -2
  353. package/src/{viewer/scene/model/vbo/instancing/triangles/renderers/VBOInstancingTrianglesOcclusionRenderer.js → src/viewer/scene/model/vbo/instancing/triangles/renderers/TrianglesOcclusionRenderer.js} +2 -2
  354. package/src/{viewer/scene/model/vbo/instancing/triangles/renderers/VBOInstancingTrianglesPBRRenderer.js → src/viewer/scene/model/vbo/instancing/triangles/renderers/TrianglesPBRRenderer.js} +2 -2
  355. package/src/{viewer/scene/model/vbo/instancing/triangles/renderers/VBOInstancingTrianglesPickDepthRenderer.js → src/viewer/scene/model/vbo/instancing/triangles/renderers/TrianglesPickDepthRenderer.js} +2 -2
  356. package/src/{viewer/scene/model/vbo/instancing/triangles/renderers/VBOInstancingTrianglesPickMeshRenderer.js → src/viewer/scene/model/vbo/instancing/triangles/renderers/TrianglesPickMeshRenderer.js} +2 -2
  357. package/src/{viewer/scene/model/vbo/instancing/triangles/renderers/VBOInstancingTrianglesPickNormalsFlatRenderer.js → src/viewer/scene/model/vbo/instancing/triangles/renderers/TrianglesPickNormalsFlatRenderer.js} +2 -2
  358. package/src/{viewer/scene/model/vbo/instancing/triangles/renderers/VBOInstancingTrianglesPickNormalsRenderer.js → src/viewer/scene/model/vbo/instancing/triangles/renderers/TrianglesPickNormalsRenderer.js} +2 -2
  359. package/src/{viewer/scene/model/vbo/instancing/triangles/renderers/VBOInstancingTrianglesShadowRenderer.js → src/viewer/scene/model/vbo/instancing/triangles/renderers/TrianglesShadowRenderer.js} +2 -2
  360. package/src/{viewer/scene/model/vbo/instancing/triangles/renderers/VBOInstancingTrianglesSilhouetteRenderer.js → src/viewer/scene/model/vbo/instancing/triangles/renderers/TrianglesSilhouetteRenderer.js} +2 -2
  361. package/src/{viewer/scene/model/vbo/instancing/triangles/renderers/VBOInstancingTrianglesSnapInitRenderer.js → src/viewer/scene/model/vbo/instancing/triangles/renderers/TrianglesSnapInitRenderer.js} +1 -1
  362. package/src/{viewer/scene/model/vbo/instancing/triangles/renderers/VBOInstancingTrianglesSnapRenderer.js → src/viewer/scene/model/vbo/instancing/triangles/renderers/TrianglesSnapRenderer.js} +1 -1
  363. package/src/src/viewer/scene/nodes/Node.js +1383 -0
  364. package/src/src/viewer/scene/nodes/index.js +1 -0
  365. package/src/src/viewer/scene/paths/CubicBezierCurve.js +194 -0
  366. package/src/src/viewer/scene/paths/Curve.js +183 -0
  367. package/src/src/viewer/scene/paths/Path.js +239 -0
  368. package/src/src/viewer/scene/paths/QuadraticBezierCurve.js +161 -0
  369. package/src/src/viewer/scene/paths/SplineCurve.js +133 -0
  370. package/src/src/viewer/scene/paths/index.js +5 -0
  371. package/src/src/viewer/scene/postfx/SAO.js +543 -0
  372. package/src/src/viewer/scene/scene/Scene.js +2802 -0
  373. package/src/src/viewer/scene/sectionPlane/SectionPlane.js +198 -0
  374. package/src/src/viewer/scene/sectionPlane/SectionPlaneCache.js +101 -0
  375. package/src/src/viewer/scene/sectionPlane/index.js +1 -0
  376. package/src/src/viewer/scene/skybox/Skybox.js +123 -0
  377. package/src/src/viewer/scene/skybox/index.js +1 -0
  378. package/src/src/viewer/scene/stats.js +44 -0
  379. package/src/src/viewer/scene/utils/Cache.js +29 -0
  380. package/src/src/viewer/scene/utils/FileLoader.js +161 -0
  381. package/src/src/viewer/scene/utils/Loader.js +55 -0
  382. package/src/src/viewer/scene/utils/LoadingManager.js +86 -0
  383. package/src/src/viewer/scene/utils/Map.js +45 -0
  384. package/src/src/viewer/scene/utils/Queue.js +56 -0
  385. package/src/src/viewer/scene/utils/WorkerPool.js +73 -0
  386. package/src/src/viewer/scene/utils/index.js +6 -0
  387. package/src/src/viewer/scene/utils/textureTranscoders/KTX2TextureTranscoder/KTX2TextureTranscoder.js +650 -0
  388. package/src/src/viewer/scene/utils/textureTranscoders/KTX2TextureTranscoder/index.js +1 -0
  389. package/src/src/viewer/scene/utils/textureTranscoders/TextureTranscoder.js +31 -0
  390. package/src/src/viewer/scene/utils/textureTranscoders/index.js +2 -0
  391. package/src/src/viewer/scene/utils.js +453 -0
  392. package/src/src/viewer/scene/viewport/Viewport.js +212 -0
  393. package/src/src/viewer/scene/webgl/ArrayBuf.js +121 -0
  394. package/src/src/viewer/scene/webgl/Attribute.js +23 -0
  395. package/src/src/viewer/scene/webgl/Drawable.js +270 -0
  396. package/src/src/viewer/scene/webgl/FrameContext.js +313 -0
  397. package/src/src/viewer/scene/webgl/PickResult.js +364 -0
  398. package/src/src/viewer/scene/webgl/Pickable.js +69 -0
  399. package/src/src/viewer/scene/webgl/Program.js +181 -0
  400. package/src/src/viewer/scene/webgl/RenderBuffer.js +378 -0
  401. package/src/src/viewer/scene/webgl/RenderBufferManager.js +34 -0
  402. package/src/src/viewer/scene/webgl/RenderFlags.js +203 -0
  403. package/src/src/viewer/scene/webgl/RenderState.js +40 -0
  404. package/src/src/viewer/scene/webgl/Renderer.js +1781 -0
  405. package/src/src/viewer/scene/webgl/Sampler.js +18 -0
  406. package/src/src/viewer/scene/webgl/Shader.js +49 -0
  407. package/src/src/viewer/scene/webgl/Texture2D.js +442 -0
  408. package/src/src/viewer/scene/webgl/convertConstant.js +244 -0
  409. package/src/src/viewer/scene/webgl/getExtension.js +32 -0
  410. package/src/src/viewer/scene/webgl/occlusion/OcclusionLayer.js +214 -0
  411. package/src/src/viewer/scene/webgl/occlusion/OcclusionTester.js +426 -0
  412. package/src/src/viewer/scene/webgl/sao/SAODepthLimitedBlurRenderer.js +324 -0
  413. package/src/src/viewer/scene/webgl/sao/SAOOcclusionRenderer.js +376 -0
  414. package/src/src/viewer/scene/webgl/webglEnums.js +61 -0
  415. package/src/src/viewer/scene/webglInfo.js +47 -0
  416. package/src/viewer/scene/model/SceneModel.js +1 -1
  417. package/src/viewer/scene/model/vbo/batching/triangles/VBOBatchingTrianglesLayer.js +1 -1
  418. package/src/viewer/scene/model/vbo/batching/triangles/renderers/EdgesColorRenderer.js +131 -0
  419. package/src/viewer/scene/model/vbo/batching/triangles/renderers/EdgesEmphasisRenderer.js +135 -0
  420. package/src/viewer/scene/model/vbo/batching/triangles/renderers/EdgesRenderer.js +12 -0
  421. package/src/viewer/scene/model/vbo/batching/triangles/renderers/Renderers.js +375 -0
  422. package/src/viewer/scene/model/vbo/batching/triangles/renderers/TrianglesBatchingRenderer.js +34 -0
  423. package/src/viewer/scene/model/vbo/batching/triangles/renderers/TrianglesColorRenderer.js +238 -0
  424. package/src/viewer/scene/model/vbo/batching/triangles/renderers/TrianglesColorTextureRenderer.js +270 -0
  425. package/src/viewer/scene/model/vbo/batching/triangles/renderers/TrianglesDepthRenderer.js +126 -0
  426. package/src/viewer/scene/model/vbo/batching/triangles/renderers/TrianglesFlatColorRenderer.js +235 -0
  427. package/src/viewer/scene/model/vbo/batching/triangles/renderers/TrianglesNormalsRenderer.js +139 -0
  428. package/src/viewer/scene/model/vbo/batching/triangles/renderers/TrianglesOcclusionRenderer.js +125 -0
  429. package/src/viewer/scene/model/vbo/batching/triangles/renderers/TrianglesPBRRenderer.js +561 -0
  430. package/src/viewer/scene/model/vbo/batching/triangles/renderers/TrianglesPickDepthRenderer.js +144 -0
  431. package/src/viewer/scene/model/vbo/batching/triangles/renderers/TrianglesPickMeshRenderer.js +130 -0
  432. package/src/viewer/scene/model/vbo/batching/triangles/renderers/TrianglesPickNormalsFlatRenderer.js +121 -0
  433. package/src/viewer/scene/model/vbo/batching/triangles/renderers/TrianglesPickNormalsRenderer.js +131 -0
  434. package/src/viewer/scene/model/vbo/batching/triangles/renderers/TrianglesShadowRenderer.js +107 -0
  435. package/src/viewer/scene/model/vbo/batching/triangles/renderers/TrianglesSilhouetteRenderer.js +136 -0
  436. package/src/viewer/scene/model/vbo/batching/triangles/renderers/TrianglesSnapInitRenderer.js +311 -0
  437. package/src/viewer/scene/model/vbo/batching/triangles/renderers/TrianglesSnapRenderer.js +308 -0
  438. package/src/viewer/scene/model/vbo/instancing/triangles/VBOInstancingTrianglesLayer.js +1 -1
  439. package/src/viewer/scene/model/vbo/instancing/triangles/renderers/EdgesColorRenderer.js +136 -0
  440. package/src/viewer/scene/model/vbo/instancing/triangles/renderers/EdgesEmphasisRenderer.js +137 -0
  441. package/src/viewer/scene/model/vbo/instancing/triangles/renderers/EdgesRenderer.js +12 -0
  442. package/src/viewer/scene/model/vbo/instancing/triangles/renderers/Renderers.js +376 -0
  443. package/src/viewer/scene/model/vbo/instancing/triangles/renderers/TrianglesColorRenderer.js +253 -0
  444. package/src/viewer/scene/model/vbo/instancing/triangles/renderers/TrianglesColorTextureRenderer.js +278 -0
  445. package/src/viewer/scene/model/vbo/instancing/triangles/renderers/TrianglesDepthRenderer.js +126 -0
  446. package/src/viewer/scene/model/vbo/instancing/triangles/renderers/TrianglesFlatColorRenderer.js +244 -0
  447. package/src/viewer/scene/model/vbo/instancing/triangles/renderers/TrianglesFlatNormalsRenderer.js +130 -0
  448. package/src/viewer/scene/model/vbo/instancing/triangles/renderers/TrianglesInstancingRenderer.js +29 -0
  449. package/src/viewer/scene/model/vbo/instancing/triangles/renderers/TrianglesNormalsRenderer.js +138 -0
  450. package/src/viewer/scene/model/vbo/instancing/triangles/renderers/TrianglesOcclusionRenderer.js +128 -0
  451. package/src/viewer/scene/model/vbo/instancing/triangles/renderers/TrianglesPBRRenderer.js +561 -0
  452. package/src/viewer/scene/model/vbo/instancing/triangles/renderers/TrianglesPickDepthRenderer.js +149 -0
  453. package/src/viewer/scene/model/vbo/instancing/triangles/renderers/TrianglesPickMeshRenderer.js +136 -0
  454. package/src/viewer/scene/model/vbo/instancing/triangles/renderers/TrianglesPickNormalsFlatRenderer.js +130 -0
  455. package/src/viewer/scene/model/vbo/instancing/triangles/renderers/TrianglesPickNormalsRenderer.js +145 -0
  456. package/src/viewer/scene/model/vbo/instancing/triangles/renderers/TrianglesShadowRenderer.js +113 -0
  457. package/src/viewer/scene/model/vbo/instancing/triangles/renderers/TrianglesSilhouetteRenderer.js +139 -0
  458. package/src/viewer/scene/model/vbo/instancing/triangles/renderers/TrianglesSnapInitRenderer.js +342 -0
  459. package/src/viewer/scene/model/vbo/instancing/triangles/renderers/TrianglesSnapRenderer.js +325 -0
  460. package/src/viewer/scene/webgl/Renderer.js +20 -19
  461. package/src/viewer/scene/model/vbo/batching/triangles/renderers/VBOSceneModelTriangleBatchingEdgesRenderer.js +0 -12
  462. package/src/viewer/scene/model/vbo/instancing/triangles/renderers/VBOSceneModelTriangleInstancingEdgesRenderer.js +0 -12
@@ -0,0 +1,2802 @@
1
+ import {core} from '../core.js';
2
+ import {utils} from '../utils.js';
3
+ import {math} from '../math/math.js';
4
+ import {Component} from '../Component.js';
5
+ import {Canvas} from '../canvas/Canvas.js';
6
+ import {Renderer} from '../webgl/Renderer.js';
7
+ import {Input} from '../input/Input.js';
8
+ import {Viewport} from '../viewport/Viewport.js';
9
+ import {Camera} from '../camera/Camera.js';
10
+ import {DirLight} from '../lights/DirLight.js';
11
+ import {AmbientLight} from '../lights/AmbientLight.js';
12
+ import {ReadableGeometry} from "../geometry/ReadableGeometry.js";
13
+ import {buildBoxGeometry} from '../geometry/builders/buildBoxGeometry.js';
14
+ import {PhongMaterial} from '../materials/PhongMaterial.js';
15
+ import {EmphasisMaterial} from '../materials/EmphasisMaterial.js';
16
+ import {EdgeMaterial} from '../materials/EdgeMaterial.js';
17
+ import {Metrics} from "../metriqs/Metriqs.js";
18
+ import {SAO} from "../postfx/SAO.js";
19
+ import {PointsMaterial} from "../materials/PointsMaterial.js";
20
+ import {LinesMaterial} from "../materials/LinesMaterial.js";
21
+
22
+ // Enables runtime check for redundant calls to object state update methods, eg. Scene#_objectVisibilityUpdated
23
+ const ASSERT_OBJECT_STATE_UPDATE = false;
24
+
25
+ // Cached vars to avoid garbage collection
26
+
27
+ function getEntityIDMap(scene, entityIds) {
28
+ const map = {};
29
+ let entityId;
30
+ let entity;
31
+ for (let i = 0, len = entityIds.length; i < len; i++) {
32
+ entityId = entityIds[i];
33
+ entity = scene.components[entityId];
34
+ if (!entity) {
35
+ scene.warn("pick(): Component not found: " + entityId);
36
+ continue;
37
+ }
38
+ if (!entity.isEntity) {
39
+ scene.warn("pick(): Component is not an Entity: " + entityId);
40
+ continue;
41
+ }
42
+ map[entityId] = true;
43
+ }
44
+ return map;
45
+ }
46
+
47
+ /**
48
+ * Fired whenever a debug message is logged on a component within this Scene.
49
+ * @event log
50
+ * @param {String} value The debug message
51
+ */
52
+
53
+ /**
54
+ * Fired whenever an error is logged on a component within this Scene.
55
+ * @event error
56
+ * @param {String} value The error message
57
+ */
58
+
59
+ /**
60
+ * Fired whenever a warning is logged on a component within this Scene.
61
+ * @event warn
62
+ * @param {String} value The warning message
63
+ */
64
+
65
+ /**
66
+ * @desc Contains the components that comprise a 3D scene.
67
+ *
68
+ * * A {@link Viewer} has a single Scene, which it provides in {@link Viewer#scene}.
69
+ * * Plugins like {@link AxisGizmoPlugin} also have their own private Scenes.
70
+ * * Each Scene has a corresponding {@link MetaScene}, which the Viewer provides in {@link Viewer#metaScene}.
71
+ *
72
+ * ## Getting a Viewer's Scene
73
+ *
74
+ * ````javascript
75
+ * var scene = viewer.scene;
76
+ * ````
77
+ *
78
+ * ## Creating and accessing Scene components
79
+ *
80
+ * As a brief introduction to creating Scene components, we'll create a {@link Mesh} that has a
81
+ * {@link buildTorusGeometry} and a {@link PhongMaterial}:
82
+ *
83
+ * ````javascript
84
+ * var teapotMesh = new Mesh(scene, {
85
+ * id: "myMesh", // <<---------- ID automatically generated if not provided
86
+ * geometry: new TorusGeometry(scene),
87
+ * material: new PhongMaterial(scene, {
88
+ * id: "myMaterial",
89
+ * diffuse: [0.2, 0.2, 1.0]
90
+ * })
91
+ * });
92
+ *
93
+ * teapotMesh.scene.camera.eye = [45, 45, 45];
94
+ * ````
95
+ *
96
+ * Find components by ID in their Scene's {@link Scene#components} map:
97
+ *
98
+ * ````javascript
99
+ * var teapotMesh = scene.components["myMesh"];
100
+ * teapotMesh.visible = false;
101
+ *
102
+ * var teapotMaterial = scene.components["myMaterial"];
103
+ * teapotMaterial.diffuse = [1,0,0]; // Change to red
104
+ * ````
105
+ *
106
+ * A Scene also has a map of component instances for each {@link Component} subtype:
107
+ *
108
+ * ````javascript
109
+ * var meshes = scene.types["Mesh"];
110
+ * var teapotMesh = meshes["myMesh"];
111
+ * teapotMesh.xrayed = true;
112
+ *
113
+ * var phongMaterials = scene.types["PhongMaterial"];
114
+ * var teapotMaterial = phongMaterials["myMaterial"];
115
+ * teapotMaterial.diffuse = [0,1,0]; // Change to green
116
+ * ````
117
+ *
118
+ * See {@link Node}, {@link Node} and {@link Model} for how to create and access more sophisticated content.
119
+ *
120
+ * ## Controlling the camera
121
+ *
122
+ * Use the Scene's {@link Camera} to control the current viewpoint and projection:
123
+ *
124
+ * ````javascript
125
+ * var camera = myScene.camera;
126
+ *
127
+ * camera.eye = [-10,0,0];
128
+ * camera.look = [-10,0,0];
129
+ * camera.up = [0,1,0];
130
+ *
131
+ * camera.projection = "perspective";
132
+ * camera.perspective.fov = 45;
133
+ * //...
134
+ * ````
135
+ *
136
+ * ## Managing the canvas
137
+ *
138
+ * The Scene's {@link Canvas} component provides various conveniences relevant to the WebGL canvas, such
139
+ * as firing resize events etc:
140
+ *
141
+ * ````javascript
142
+ * var canvas = scene.canvas;
143
+ *
144
+ * canvas.on("boundary", function(boundary) {
145
+ * //...
146
+ * });
147
+ * ````
148
+ *
149
+ * ## Picking
150
+ *
151
+ * Use {@link Scene#pick} to pick and raycast entites.
152
+ *
153
+ * For example, to pick a point on the surface of the closest entity at the given canvas coordinates:
154
+ *
155
+ * ````javascript
156
+ * var pickResult = scene.pick({
157
+ * pickSurface: true,
158
+ * canvasPos: [23, 131]
159
+ * });
160
+ *
161
+ * if (pickResult) { // Picked an entity
162
+ *
163
+ * var entity = pickResult.entity;
164
+ *
165
+ * var primitive = pickResult.primitive; // Type of primitive that was picked, usually "triangles"
166
+ * var primIndex = pickResult.primIndex; // Position of triangle's first index in the picked Mesh's Geometry's indices array
167
+ * var indices = pickResult.indices; // UInt32Array containing the triangle's vertex indices
168
+ * var localPos = pickResult.localPos; // Float64Array containing the picked Local-space position on the triangle
169
+ * var worldPos = pickResult.worldPos; // Float64Array containing the picked World-space position on the triangle
170
+ * var viewPos = pickResult.viewPos; // Float64Array containing the picked View-space position on the triangle
171
+ * var bary = pickResult.bary; // Float64Array containing the picked barycentric position within the triangle
172
+ * var normal = pickResult.normal; // Float64Array containing the interpolated normal vector at the picked position on the triangle
173
+ * var uv = pickResult.uv; // Float64Array containing the interpolated UV coordinates at the picked position on the triangle
174
+ * }
175
+ * ````
176
+ *
177
+ * ## Pick masking
178
+ *
179
+ * We can use {@link Scene#pick}'s ````includeEntities```` and ````excludeEntities```` options to mask which {@link Mesh}es we attempt to pick.
180
+ *
181
+ * This is useful for picking through things, to pick only the Entities of interest.
182
+ *
183
+ * To pick only Entities ````"gearbox#77.0"```` and ````"gearbox#79.0"````, picking through any other Entities that are
184
+ * in the way, as if they weren't there:
185
+ *
186
+ * ````javascript
187
+ * var pickResult = scene.pick({
188
+ * canvasPos: [23, 131],
189
+ * includeEntities: ["gearbox#77.0", "gearbox#79.0"]
190
+ * });
191
+ *
192
+ * if (pickResult) {
193
+ * // Entity will always be either "gearbox#77.0" or "gearbox#79.0"
194
+ * var entity = pickResult.entity;
195
+ * }
196
+ * ````
197
+ *
198
+ * To pick any pickable Entity, except for ````"gearbox#77.0"```` and ````"gearbox#79.0"````, picking through those
199
+ * Entities if they happen to be in the way:
200
+ *
201
+ * ````javascript
202
+ * var pickResult = scene.pick({
203
+ * canvasPos: [23, 131],
204
+ * excludeEntities: ["gearbox#77.0", "gearbox#79.0"]
205
+ * });
206
+ *
207
+ * if (pickResult) {
208
+ * // Entity will never be "gearbox#77.0" or "gearbox#79.0"
209
+ * var entity = pickResult.entity;
210
+ * }
211
+ * ````
212
+ *
213
+ * See {@link Scene#pick} for more info on picking.
214
+ *
215
+ * ## Querying and tracking boundaries
216
+ *
217
+ * Getting a Scene's World-space axis-aligned boundary (AABB):
218
+ *
219
+ * ````javascript
220
+ * var aabb = scene.aabb; // [xmin, ymin, zmin, xmax, ymax, zmax]
221
+ * ````
222
+ *
223
+ * Subscribing to updates to the AABB, which occur whenever {@link Entity}s are transformed, their
224
+ * {@link ReadableGeometry}s have been updated, or the {@link Camera} has moved:
225
+ *
226
+ * ````javascript
227
+ * scene.on("boundary", function() {
228
+ * var aabb = scene.aabb;
229
+ * });
230
+ * ````
231
+ *
232
+ * Getting the AABB of the {@link Entity}s with the given IDs:
233
+ *
234
+ * ````JavaScript
235
+ * scene.getAABB(); // Gets collective boundary of all Entities in the scene
236
+ * scene.getAABB("saw"); // Gets boundary of an Object
237
+ * scene.getAABB(["saw", "gearbox"]); // Gets collective boundary of two Objects
238
+ * ````
239
+ *
240
+ * See {@link Scene#getAABB} and {@link Entity} for more info on querying and tracking boundaries.
241
+ *
242
+ * ## Managing the viewport
243
+ *
244
+ * The Scene's {@link Viewport} component manages the WebGL viewport:
245
+ *
246
+ * ````javascript
247
+ * var viewport = scene.viewport
248
+ * viewport.boundary = [0, 0, 500, 400];;
249
+ * ````
250
+ *
251
+ * ## Controlling rendering
252
+ *
253
+ * You can configure a Scene to perform multiple "passes" (renders) per frame. This is useful when we want to render the
254
+ * scene to multiple viewports, such as for stereo effects.
255
+ *
256
+ * In the example, below, we'll configure the Scene to render twice on each frame, each time to different viewport. We'll do this
257
+ * with a callback that intercepts the Scene before each render and sets its {@link Viewport} to a
258
+ * different portion of the canvas. By default, the Scene will clear the canvas only before the first render, allowing the
259
+ * two views to be shown on the canvas at the same time.
260
+ *
261
+ * ````Javascript
262
+ * var viewport = scene.viewport;
263
+ *
264
+ * // Configure Scene to render twice for each frame
265
+ * scene.passes = 2; // Default is 1
266
+ * scene.clearEachPass = false; // Default is false
267
+ *
268
+ * // Render to a separate viewport on each render
269
+ *
270
+ * var viewport = scene.viewport;
271
+ * viewport.autoBoundary = false;
272
+ *
273
+ * scene.on("rendering", function (e) {
274
+ * switch (e.pass) {
275
+ * case 0:
276
+ * viewport.boundary = [0, 0, 200, 200]; // xmin, ymin, width, height
277
+ * break;
278
+ *
279
+ * case 1:
280
+ * viewport.boundary = [200, 0, 200, 200];
281
+ * break;
282
+ * }
283
+ * });
284
+ *
285
+ * // We can also intercept the Scene after each render,
286
+ * // (though we're not using this for anything here)
287
+ * scene.on("rendered", function (e) {
288
+ * switch (e.pass) {
289
+ * case 0:
290
+ * break;
291
+ *
292
+ * case 1:
293
+ * break;
294
+ * }
295
+ * });
296
+ * ````
297
+ *
298
+ * ## Gamma correction
299
+ *
300
+ * Within its shaders, xeokit performs shading calculations in linear space.
301
+ *
302
+ * By default, the Scene expects color textures (eg. {@link PhongMaterial#diffuseMap},
303
+ * {@link MetallicMaterial#baseColorMap} and {@link SpecularMaterial#diffuseMap}) to
304
+ * be in pre-multipled gamma space, so will convert those to linear space before they are used in shaders. Other textures are
305
+ * always expected to be in linear space.
306
+ *
307
+ * By default, the Scene will also gamma-correct its rendered output.
308
+ *
309
+ * You can configure the Scene to expect all those color textures to be linear space, so that it does not gamma-correct them:
310
+ *
311
+ * ````javascript
312
+ * scene.gammaInput = false;
313
+ * ````
314
+ *
315
+ * You would still need to gamma-correct the output, though, if it's going straight to the canvas, so normally we would
316
+ * leave that enabled:
317
+ *
318
+ * ````javascript
319
+ * scene.gammaOutput = true;
320
+ * ````
321
+ *
322
+ * See {@link Texture} for more information on texture encoding and gamma.
323
+ *
324
+ * @class Scene
325
+ */
326
+ class Scene extends Component {
327
+
328
+ /**
329
+ @private
330
+ */
331
+ get type() {
332
+ return "Scene";
333
+ }
334
+
335
+ /**
336
+ * @private
337
+ * @constructor
338
+ * @param {Viewer} viewer The Viewer this Scene belongs to.
339
+ * @param {Object} cfg Scene configuration.
340
+ * @param {String} [cfg.canvasId] ID of an existing HTML canvas for the {@link Scene#canvas} - either this or canvasElement is mandatory. When both values are given, the element reference is always preferred to the ID.
341
+ * @param {HTMLCanvasElement} [cfg.canvasElement] Reference of an existing HTML canvas for the {@link Scene#canvas} - either this or canvasId is mandatory. When both values are given, the element reference is always preferred to the ID.
342
+ * @param {HTMLElement} [cfg.keyboardEventsElement] Optional reference to HTML element on which key events should be handled. Defaults to the HTML Document.
343
+ * @param {number} [cfg.numCachedSectionPlanes=0] Enhances the efficiency of SectionPlane creation by proactively allocating Viewer resources for a specified quantity
344
+ * of SectionPlanes. Introducing this parameter streamlines the initial creation speed of SectionPlanes, particularly up to the designated quantity. This parameter internally
345
+ * configures renderer logic for the specified number of SectionPlanes, eliminating the need for setting up logic with each SectionPlane creation and thereby enhancing
346
+ * responsiveness. It is important to consider that each SectionPlane imposes rendering performance, so it is recommended to set this value to a quantity that aligns with
347
+ * your expected usage.
348
+ * @throws {String} Throws an exception when both canvasId or canvasElement are missing or they aren't pointing to a valid HTMLCanvasElement.
349
+ */
350
+ constructor(viewer, cfg = {}) {
351
+
352
+ super(null, cfg);
353
+
354
+ const canvas = cfg.canvasElement || document.getElementById(cfg.canvasId);
355
+
356
+ if (!(canvas instanceof HTMLCanvasElement)) {
357
+ throw "Mandatory config expected: valid canvasId or canvasElement";
358
+ }
359
+
360
+ /**
361
+ * @type {{[key: string]: {wrapperFunc: Function, tickSubId: string}}}
362
+ */
363
+ this._tickifiedFunctions = {};
364
+
365
+ const transparent = (!!cfg.transparent);
366
+ const alphaDepthMask = (!!cfg.alphaDepthMask);
367
+
368
+ this._aabbDirty = true;
369
+
370
+ /**
371
+ * The {@link Viewer} this Scene belongs to.
372
+ * @type {Viewer}
373
+ */
374
+ this.viewer = viewer;
375
+
376
+ /** Decremented each frame, triggers occlusion test for occludable {@link Marker}s when zero.
377
+ * @private
378
+ * @type {number}
379
+ */
380
+ this.occlusionTestCountdown = 0;
381
+
382
+ /**
383
+ The number of models currently loading.
384
+
385
+ @property loading
386
+ @final
387
+ @type {Number}
388
+ */
389
+ this.loading = 0;
390
+
391
+ /**
392
+ The epoch time (in milliseconds since 1970) when this Scene was instantiated.
393
+
394
+ @property timeCreated
395
+ @final
396
+ @type {Number}
397
+ */
398
+ this.startTime = (new Date()).getTime();
399
+
400
+ /**
401
+ * Map of {@link Entity}s that represent models.
402
+ *
403
+ * Each {@link Entity} is mapped here by {@link Entity#id} when {@link Entity#isModel} is ````true````.
404
+ *
405
+ * @property models
406
+ * @final
407
+ * @type {{String:Entity}}
408
+ */
409
+ this.models = {};
410
+
411
+ /**
412
+ * Map of {@link Entity}s that represents objects.
413
+ *
414
+ * Each {@link Entity} is mapped here by {@link Entity#id} when {@link Entity#isObject} is ````true````.
415
+ *
416
+ * @property objects
417
+ * @final
418
+ * @type {{String:Entity}}
419
+ */
420
+ this.objects = {};
421
+ this._numObjects = 0;
422
+
423
+ /**
424
+ * Map of currently visible {@link Entity}s that represent objects.
425
+ *
426
+ * An Entity represents an object if {@link Entity#isObject} is ````true````, and is visible when {@link Entity#visible} is true.
427
+ *
428
+ * @property visibleObjects
429
+ * @final
430
+ * @type {{String:Object}}
431
+ */
432
+ this.visibleObjects = {};
433
+ this._numVisibleObjects = 0;
434
+
435
+ /**
436
+ * Map of currently xrayed {@link Entity}s that represent objects.
437
+ *
438
+ * An Entity represents an object if {@link Entity#isObject} is ````true````, and is xrayed when {@link Entity#xrayed} is true.
439
+ *
440
+ * Each {@link Entity} is mapped here by {@link Entity#id}.
441
+ *
442
+ * @property xrayedObjects
443
+ * @final
444
+ * @type {{String:Object}}
445
+ */
446
+ this.xrayedObjects = {};
447
+ this._numXRayedObjects = 0;
448
+
449
+ /**
450
+ * Map of currently highlighted {@link Entity}s that represent objects.
451
+ *
452
+ * An Entity represents an object if {@link Entity#isObject} is ````true```` is true, and is highlighted when {@link Entity#highlighted} is true.
453
+ *
454
+ * Each {@link Entity} is mapped here by {@link Entity#id}.
455
+ *
456
+ * @property highlightedObjects
457
+ * @final
458
+ * @type {{String:Object}}
459
+ */
460
+ this.highlightedObjects = {};
461
+ this._numHighlightedObjects = 0;
462
+
463
+ /**
464
+ * Map of currently selected {@link Entity}s that represent objects.
465
+ *
466
+ * An Entity represents an object if {@link Entity#isObject} is true, and is selected while {@link Entity#selected} is true.
467
+ *
468
+ * Each {@link Entity} is mapped here by {@link Entity#id}.
469
+ *
470
+ * @property selectedObjects
471
+ * @final
472
+ * @type {{String:Object}}
473
+ */
474
+ this.selectedObjects = {};
475
+ this._numSelectedObjects = 0;
476
+
477
+ /**
478
+ * Map of currently colorized {@link Entity}s that represent objects.
479
+ *
480
+ * An Entity represents an object if {@link Entity#isObject} is ````true````.
481
+ *
482
+ * Each {@link Entity} is mapped here by {@link Entity#id}.
483
+ *
484
+ * @property colorizedObjects
485
+ * @final
486
+ * @type {{String:Object}}
487
+ */
488
+ this.colorizedObjects = {};
489
+ this._numColorizedObjects = 0;
490
+
491
+ /**
492
+ * Map of {@link Entity}s that represent objects whose opacity was updated.
493
+ *
494
+ * An Entity represents an object if {@link Entity#isObject} is ````true````.
495
+ *
496
+ * Each {@link Entity} is mapped here by {@link Entity#id}.
497
+ *
498
+ * @property opacityObjects
499
+ * @final
500
+ * @type {{String:Object}}
501
+ */
502
+ this.opacityObjects = {};
503
+ this._numOpacityObjects = 0;
504
+
505
+ /**
506
+ * Map of {@link Entity}s that represent objects whose {@link Entity#offset}s were updated.
507
+ *
508
+ * An Entity represents an object if {@link Entity#isObject} is ````true````.
509
+ *
510
+ * Each {@link Entity} is mapped here by {@link Entity#id}.
511
+ *
512
+ * @property offsetObjects
513
+ * @final
514
+ * @type {{String:Object}}
515
+ */
516
+ this.offsetObjects = {};
517
+ this._numOffsetObjects = 0;
518
+
519
+ // Cached ID arrays, lazy-rebuilt as needed when stale after map updates
520
+
521
+ /**
522
+ Lazy-regenerated ID lists.
523
+ */
524
+ this._modelIds = null;
525
+ this._objectIds = null;
526
+ this._visibleObjectIds = null;
527
+ this._xrayedObjectIds = null;
528
+ this._highlightedObjectIds = null;
529
+ this._selectedObjectIds = null;
530
+ this._colorizedObjectIds = null;
531
+ this._opacityObjectIds = null;
532
+ this._offsetObjectIds = null;
533
+
534
+ this._collidables = {}; // Components that contribute to the Scene AABB
535
+ this._compilables = {}; // Components that require shader compilation
536
+
537
+ this._needRecompile = false;
538
+
539
+ /**
540
+ * For each {@link Component} type, a map of IDs to {@link Component} instances of that type.
541
+ *
542
+ * @type {{String:{String:Component}}}
543
+ */
544
+ this.types = {};
545
+
546
+ /**
547
+ * The {@link Component}s within this Scene, each mapped to its {@link Component#id}.
548
+ *
549
+ * *@type {{String:Component}}
550
+ */
551
+ this.components = {};
552
+
553
+ /**
554
+ * The {@link SectionPlane}s in this Scene, each mapped to its {@link SectionPlane#id}.
555
+ *
556
+ * @type {{String:SectionPlane}}
557
+ */
558
+ this.sectionPlanes = {};
559
+
560
+ /**
561
+ * The {@link Light}s in this Scene, each mapped to its {@link Light#id}.
562
+ *
563
+ * @type {{String:Light}}
564
+ */
565
+ this.lights = {};
566
+
567
+ /**
568
+ * The {@link LightMap}s in this Scene, each mapped to its {@link LightMap#id}.
569
+ *
570
+ * @type {{String:LightMap}}
571
+ */
572
+ this.lightMaps = {};
573
+
574
+ /**
575
+ * The {@link ReflectionMap}s in this Scene, each mapped to its {@link ReflectionMap#id}.
576
+ *
577
+ * @type {{String:ReflectionMap}}
578
+ */
579
+ this.reflectionMaps = {};
580
+
581
+ /**
582
+ * The {@link Bitmap}s in this Scene, each mapped to its {@link Bitmap#id}.
583
+ *
584
+ * @type {{String:Bitmap}}
585
+ */
586
+ this.bitmaps = {};
587
+
588
+ /**
589
+ * The {@link LineSet}s in this Scene, each mapped to its {@link LineSet#id}.
590
+ *
591
+ * @type {{String:LineSet}}
592
+ */
593
+ this.lineSets = {};
594
+
595
+ /**
596
+ * The real world offset for this Scene
597
+ *
598
+ * @type {Number[]}
599
+ */
600
+ this.realWorldOffset = cfg.realWorldOffset || new Float64Array([0, 0, 0]);
601
+
602
+ /**
603
+ * Manages the HTML5 canvas for this Scene.
604
+ *
605
+ * @type {Canvas}
606
+ */
607
+ this.canvas = new Canvas(this, {
608
+ dontClear: true, // Never destroy this component with Scene#clear();
609
+ canvas: canvas,
610
+ spinnerElementId: cfg.spinnerElementId,
611
+ transparent: transparent,
612
+ webgl2: cfg.webgl2 !== false,
613
+ contextAttr: cfg.contextAttr || {},
614
+ backgroundColor: cfg.backgroundColor,
615
+ backgroundColorFromAmbientLight: cfg.backgroundColorFromAmbientLight,
616
+ premultipliedAlpha: cfg.premultipliedAlpha
617
+ });
618
+
619
+ this.canvas.on("boundary", () => {
620
+ this.glRedraw();
621
+ });
622
+
623
+ this.canvas.on("webglContextFailed", () => {
624
+ alert("xeokit failed to find WebGL!");
625
+ });
626
+
627
+ this._renderer = new Renderer(this, {
628
+ transparent: transparent,
629
+ alphaDepthMask: alphaDepthMask
630
+ });
631
+
632
+ this._sectionPlanesState = new (function () {
633
+
634
+ this.sectionPlanes = [];
635
+
636
+ this.clippingCaps = false;
637
+
638
+ this._numCachedSectionPlanes = 0;
639
+
640
+ let hash = null;
641
+
642
+ this.getHash = function () {
643
+ if (hash) {
644
+ return hash;
645
+ }
646
+ const numAllocatedSectionPlanes = this.getNumAllocatedSectionPlanes();
647
+ const sectionPlanes = this.sectionPlanes;
648
+ if (numAllocatedSectionPlanes === 0) {
649
+ return this.hash = ";";
650
+ }
651
+ let sectionPlane;
652
+
653
+ const hashParts = [];
654
+ for (let i = 0, len = numAllocatedSectionPlanes; i < len; i++) {
655
+ sectionPlane = sectionPlanes[i];
656
+ hashParts.push("cp");
657
+ }
658
+ hashParts.push(";");
659
+ hash = hashParts.join("");
660
+ return hash;
661
+ };
662
+
663
+ this.addSectionPlane = function (sectionPlane) {
664
+ this.sectionPlanes.push(sectionPlane);
665
+ hash = null;
666
+ };
667
+
668
+ this.removeSectionPlane = function (sectionPlane) {
669
+ for (let i = 0, len = this.sectionPlanes.length; i < len; i++) {
670
+ if (this.sectionPlanes[i].id === sectionPlane.id) {
671
+ this.sectionPlanes.splice(i, 1);
672
+ hash = null;
673
+ return;
674
+ }
675
+ }
676
+ };
677
+
678
+ this.setNumCachedSectionPlanes = function (numCachedSectionPlanes) {
679
+ this._numCachedSectionPlanes = numCachedSectionPlanes;
680
+ hash = null;
681
+ }
682
+
683
+ this.getNumCachedSectionPlanes = function () {
684
+ return this._numCachedSectionPlanes;
685
+ }
686
+
687
+ this.getNumAllocatedSectionPlanes = function () {
688
+ const num = this.sectionPlanes.length;
689
+ return (num > this._numCachedSectionPlanes) ? num : this._numCachedSectionPlanes;
690
+ };
691
+ })();
692
+
693
+ this._sectionPlanesState.setNumCachedSectionPlanes(cfg.numCachedSectionPlanes || 0);
694
+
695
+ this._lightsState = new (function () {
696
+
697
+ const DEFAULT_AMBIENT = math.vec4([0, 0, 0, 0]);
698
+ const ambientColorIntensity = math.vec4();
699
+
700
+ this.lights = [];
701
+ this.reflectionMaps = [];
702
+ this.lightMaps = [];
703
+
704
+ let hash = null;
705
+ let ambientLight = null;
706
+
707
+ this.getHash = function () {
708
+ if (hash) {
709
+ return hash;
710
+ }
711
+ const hashParts = [];
712
+ const lights = this.lights;
713
+ let light;
714
+ for (let i = 0, len = lights.length; i < len; i++) {
715
+ light = lights[i];
716
+ hashParts.push("/");
717
+ hashParts.push(light.type);
718
+ hashParts.push((light.space === "world") ? "w" : "v");
719
+ if (light.castsShadow) {
720
+ hashParts.push("sh");
721
+ }
722
+ }
723
+ if (this.lightMaps.length > 0) {
724
+ hashParts.push("/lm");
725
+ }
726
+ if (this.reflectionMaps.length > 0) {
727
+ hashParts.push("/rm");
728
+ }
729
+ hashParts.push(";");
730
+ hash = hashParts.join("");
731
+ return hash;
732
+ };
733
+
734
+ this.addLight = function (state) {
735
+ this.lights.push(state);
736
+ ambientLight = null;
737
+ hash = null;
738
+ };
739
+
740
+ this.removeLight = function (state) {
741
+ for (let i = 0, len = this.lights.length; i < len; i++) {
742
+ const light = this.lights[i];
743
+ if (light.id === state.id) {
744
+ this.lights.splice(i, 1);
745
+ if (ambientLight && ambientLight.id === state.id) {
746
+ ambientLight = null;
747
+ }
748
+ hash = null;
749
+ return;
750
+ }
751
+ }
752
+ };
753
+
754
+ this.addReflectionMap = function (state) {
755
+ this.reflectionMaps.push(state);
756
+ hash = null;
757
+ };
758
+
759
+ this.removeReflectionMap = function (state) {
760
+ for (let i = 0, len = this.reflectionMaps.length; i < len; i++) {
761
+ if (this.reflectionMaps[i].id === state.id) {
762
+ this.reflectionMaps.splice(i, 1);
763
+ hash = null;
764
+ return;
765
+ }
766
+ }
767
+ };
768
+
769
+ this.addLightMap = function (state) {
770
+ this.lightMaps.push(state);
771
+ hash = null;
772
+ };
773
+
774
+ this.removeLightMap = function (state) {
775
+ for (let i = 0, len = this.lightMaps.length; i < len; i++) {
776
+ if (this.lightMaps[i].id === state.id) {
777
+ this.lightMaps.splice(i, 1);
778
+ hash = null;
779
+ return;
780
+ }
781
+ }
782
+ };
783
+
784
+ this.getAmbientColorAndIntensity = function () {
785
+ if (!ambientLight) {
786
+ for (let i = 0, len = this.lights.length; i < len; i++) {
787
+ const light = this.lights[i];
788
+ if (light.type === "ambient") {
789
+ ambientLight = light;
790
+ break;
791
+ }
792
+ }
793
+ }
794
+ if (ambientLight) {
795
+ const color = ambientLight.color;
796
+ const intensity = ambientLight.intensity;
797
+ ambientColorIntensity[0] = color[0];
798
+ ambientColorIntensity[1] = color[1];
799
+ ambientColorIntensity[2] = color[2];
800
+ ambientColorIntensity[3] = intensity
801
+ return ambientColorIntensity;
802
+ } else {
803
+ return DEFAULT_AMBIENT;
804
+ }
805
+ };
806
+
807
+ })();
808
+
809
+ /**
810
+ * Publishes input events that occur on this Scene's canvas.
811
+ *
812
+ * @property input
813
+ * @type {Input}
814
+ * @final
815
+ */
816
+ this.input = new Input(this, {
817
+ dontClear: true, // Never destroy this component with Scene#clear();
818
+ element: this.canvas.canvas,
819
+ keyboardEventsElement: cfg.keyboardEventsElement
820
+ });
821
+
822
+ /**
823
+ * Configures this Scene's units of measurement and coordinate mapping between Real-space and World-space 3D coordinate systems.
824
+ *
825
+ * @property metrics
826
+ * @type {Metrics}
827
+ * @final
828
+ */
829
+ this.metrics = new Metrics(this, {
830
+ units: cfg.units,
831
+ scale: cfg.scale,
832
+ origin: cfg.origin
833
+ });
834
+
835
+ /** Configures Scalable Ambient Obscurance (SAO) for this Scene.
836
+ * @type {SAO}
837
+ * @final
838
+ */
839
+ this.sao = new SAO(this, {
840
+ enabled: cfg.saoEnabled
841
+ });
842
+
843
+ this.ticksPerRender = cfg.ticksPerRender;
844
+ this.ticksPerOcclusionTest = cfg.ticksPerOcclusionTest;
845
+ this.passes = cfg.passes;
846
+ this.clearEachPass = cfg.clearEachPass;
847
+ this.gammaInput = cfg.gammaInput;
848
+ this.gammaOutput = cfg.gammaOutput;
849
+ this.gammaFactor = cfg.gammaFactor;
850
+
851
+ this._entityOffsetsEnabled = !!cfg.entityOffsetsEnabled;
852
+ this._logarithmicDepthBufferEnabled = !!cfg.logarithmicDepthBufferEnabled;
853
+
854
+ this._dtxEnabled = (cfg.dtxEnabled !== false);
855
+ this._pbrEnabled = !!cfg.pbrEnabled;
856
+ this._colorTextureEnabled = (cfg.colorTextureEnabled !== false);
857
+ this._dtxEnabled = !!cfg.dtxEnabled;
858
+
859
+ // Register Scene on xeokit
860
+ // Do this BEFORE we add components below
861
+ core._addScene(this);
862
+
863
+ this._initDefaults();
864
+
865
+ // Global components
866
+
867
+ this._viewport = new Viewport(this, {
868
+ id: "default.viewport",
869
+ autoBoundary: true,
870
+ dontClear: true // Never destroy this component with Scene#clear();
871
+ });
872
+
873
+ this._camera = new Camera(this, {
874
+ id: "default.camera",
875
+ dontClear: true // Never destroy this component with Scene#clear();
876
+ });
877
+
878
+ // Default lights
879
+
880
+ new AmbientLight(this, {
881
+ color: [1.0, 1.0, 1.0],
882
+ intensity: 0.7
883
+ });
884
+
885
+ new DirLight(this, {
886
+ dir: [0.8, -.5, -0.5],
887
+ color: [0.67, 0.67, 1.0],
888
+ intensity: 0.7,
889
+ space: "world"
890
+ });
891
+
892
+ new DirLight(this, {
893
+ dir: [-0.8, -1.0, 0.5],
894
+ color: [1, 1, .9],
895
+ intensity: 0.9,
896
+ space: "world"
897
+ });
898
+
899
+ this._camera.on("dirty", () => {
900
+ this._renderer.imageDirty();
901
+ });
902
+ }
903
+
904
+ _initDefaults() {
905
+
906
+ // Call this Scene's property accessors to lazy-init their properties
907
+
908
+ let dummy; // Keeps Codacy happy
909
+
910
+ dummy = this.geometry;
911
+ dummy = this.material;
912
+ dummy = this.xrayMaterial;
913
+ dummy = this.edgeMaterial;
914
+ dummy = this.selectedMaterial;
915
+ dummy = this.highlightMaterial;
916
+ }
917
+
918
+ _addComponent(component) {
919
+ if (component.id) { // Manual ID
920
+ if (this.components[component.id]) {
921
+ this.error("Component " + utils.inQuotes(component.id) + " already exists in Scene - ignoring ID, will randomly-generate instead");
922
+ component.id = null;
923
+ }
924
+ }
925
+ if (!component.id) { // Auto ID
926
+ if (window.nextID === undefined) {
927
+ window.nextID = 0;
928
+ }
929
+ //component.id = math.createUUID();
930
+ component.id = "__" + window.nextID++;
931
+ while (this.components[component.id]) {
932
+ component.id = math.createUUID();
933
+ }
934
+ }
935
+ this.components[component.id] = component;
936
+
937
+ // Register for class type
938
+ const type = component.type;
939
+ let types = this.types[component.type];
940
+ if (!types) {
941
+ types = this.types[type] = {};
942
+ }
943
+ types[component.id] = component;
944
+
945
+ if (component.compile) {
946
+ this._compilables[component.id] = component;
947
+ }
948
+ if (component.isDrawable) {
949
+ this._renderer.addDrawable(component.id, component);
950
+ this._collidables[component.id] = component;
951
+ }
952
+ }
953
+
954
+ _removeComponent(component) {
955
+ var id = component.id;
956
+ var type = component.type;
957
+ delete this.components[id];
958
+ // Unregister for types
959
+ const types = this.types[type];
960
+ if (types) {
961
+ delete types[id];
962
+ if (utils.isEmptyObject(types)) {
963
+ delete this.types[type];
964
+ }
965
+ }
966
+ if (component.compile) {
967
+ delete this._compilables[component.id];
968
+ }
969
+ if (component.isDrawable) {
970
+ this._renderer.removeDrawable(component.id);
971
+ delete this._collidables[component.id];
972
+ }
973
+ }
974
+
975
+ // Methods below are called by various component types to register themselves on their
976
+ // Scene. Violates Hollywood Principle, where we could just filter on type in _addComponent,
977
+ // but this is faster than checking the type of each component in such a filter.
978
+
979
+ _sectionPlaneCreated(sectionPlane) {
980
+ this.sectionPlanes[sectionPlane.id] = sectionPlane;
981
+ this.scene._sectionPlanesState.addSectionPlane(sectionPlane._state);
982
+ this.scene.fire("sectionPlaneCreated", sectionPlane, true /* Don't retain event */);
983
+ this._needRecompile = true;
984
+ }
985
+
986
+ _bitmapCreated(bitmap) {
987
+ this.bitmaps[bitmap.id] = bitmap;
988
+ this.scene.fire("bitmapCreated", bitmap, true /* Don't retain event */);
989
+ }
990
+
991
+ _lineSetCreated(lineSet) {
992
+ this.lineSets[lineSet.id] = lineSet;
993
+ this.scene.fire("lineSetCreated", lineSet, true /* Don't retain event */);
994
+ }
995
+
996
+ _lightCreated(light) {
997
+ this.lights[light.id] = light;
998
+ this.scene._lightsState.addLight(light._state);
999
+ this._needRecompile = true;
1000
+ }
1001
+
1002
+ _lightMapCreated(lightMap) {
1003
+ this.lightMaps[lightMap.id] = lightMap;
1004
+ this.scene._lightsState.addLightMap(lightMap._state);
1005
+ this._needRecompile = true;
1006
+ }
1007
+
1008
+ _reflectionMapCreated(reflectionMap) {
1009
+ this.reflectionMaps[reflectionMap.id] = reflectionMap;
1010
+ this.scene._lightsState.addReflectionMap(reflectionMap._state);
1011
+ this._needRecompile = true;
1012
+ }
1013
+
1014
+ _sectionPlaneDestroyed(sectionPlane) {
1015
+ delete this.sectionPlanes[sectionPlane.id];
1016
+ this.scene._sectionPlanesState.removeSectionPlane(sectionPlane._state);
1017
+ this.scene.fire("sectionPlaneDestroyed", sectionPlane, true /* Don't retain event */);
1018
+ this._needRecompile = true;
1019
+ }
1020
+
1021
+ _bitmapDestroyed(bitmap) {
1022
+ delete this.bitmaps[bitmap.id];
1023
+ this.scene.fire("bitmapDestroyed", bitmap, true /* Don't retain event */);
1024
+ }
1025
+
1026
+ _lineSetDestroyed(lineSet) {
1027
+ delete this.lineSets[lineSet.id];
1028
+ this.scene.fire("lineSetDestroyed", lineSet, true /* Don't retain event */);
1029
+ }
1030
+
1031
+ _lightDestroyed(light) {
1032
+ delete this.lights[light.id];
1033
+ this.scene._lightsState.removeLight(light._state);
1034
+ this._needRecompile = true;
1035
+ }
1036
+
1037
+ _lightMapDestroyed(lightMap) {
1038
+ delete this.lightMaps[lightMap.id];
1039
+ this.scene._lightsState.removeLightMap(lightMap._state);
1040
+ this._needRecompile = true;
1041
+ }
1042
+
1043
+ _reflectionMapDestroyed(reflectionMap) {
1044
+ delete this.reflectionMaps[reflectionMap.id];
1045
+ this.scene._lightsState.removeReflectionMap(reflectionMap._state);
1046
+ this._needRecompile = true;
1047
+ }
1048
+
1049
+ _registerModel(entity) {
1050
+ this.models[entity.id] = entity;
1051
+ this._modelIds = null; // Lazy regenerate
1052
+ }
1053
+
1054
+ _deregisterModel(entity) {
1055
+ const modelId = entity.id;
1056
+ delete this.models[modelId];
1057
+ this._modelIds = null; // Lazy regenerate
1058
+ this.fire("modelUnloaded", modelId);
1059
+ }
1060
+
1061
+ _registerObject(entity) {
1062
+ this.objects[entity.id] = entity;
1063
+ this._numObjects++;
1064
+ this._objectIds = null; // Lazy regenerate
1065
+ }
1066
+
1067
+ _deregisterObject(entity) {
1068
+ delete this.objects[entity.id];
1069
+ this._numObjects--;
1070
+ this._objectIds = null; // Lazy regenerate
1071
+ }
1072
+
1073
+ _objectVisibilityUpdated(entity, notify = true) {
1074
+ if (entity.visible) {
1075
+ if (ASSERT_OBJECT_STATE_UPDATE && this.visibleObjects[entity.id]) {
1076
+ console.error("Redundant object visibility update (visible=true)");
1077
+ return;
1078
+ }
1079
+ this.visibleObjects[entity.id] = entity;
1080
+ this._numVisibleObjects++;
1081
+ } else {
1082
+ if (ASSERT_OBJECT_STATE_UPDATE && (!this.visibleObjects[entity.id])) {
1083
+ console.error("Redundant object visibility update (visible=false)");
1084
+ return;
1085
+ }
1086
+ delete this.visibleObjects[entity.id];
1087
+ this._numVisibleObjects--;
1088
+ }
1089
+ this._visibleObjectIds = null; // Lazy regenerate
1090
+ if (notify) {
1091
+ this.fire("objectVisibility", entity, true);
1092
+ }
1093
+ }
1094
+
1095
+ _deRegisterVisibleObject(entity) {
1096
+ delete this.visibleObjects[entity.id];
1097
+ this._numVisibleObjects--;
1098
+ this._visibleObjectIds = null; // Lazy regenerate
1099
+ }
1100
+
1101
+ _objectXRayedUpdated(entity, notify = true) {
1102
+ if (entity.xrayed) {
1103
+ if (ASSERT_OBJECT_STATE_UPDATE && this.xrayedObjects[entity.id]) {
1104
+ console.error("Redundant object xray update (xrayed=true)");
1105
+ return;
1106
+ }
1107
+ this.xrayedObjects[entity.id] = entity;
1108
+ this._numXRayedObjects++;
1109
+ } else {
1110
+ if (ASSERT_OBJECT_STATE_UPDATE && (!this.xrayedObjects[entity.id])) {
1111
+ console.error("Redundant object xray update (xrayed=false)");
1112
+ return;
1113
+ }
1114
+ delete this.xrayedObjects[entity.id];
1115
+ this._numXRayedObjects--;
1116
+ }
1117
+ this._xrayedObjectIds = null; // Lazy regenerate
1118
+ if (notify) {
1119
+ this.fire("objectXRayed", entity, true);
1120
+ }
1121
+ }
1122
+
1123
+ _deRegisterXRayedObject(entity) {
1124
+ delete this.xrayedObjects[entity.id];
1125
+ this._numXRayedObjects--;
1126
+ this._xrayedObjectIds = null; // Lazy regenerate
1127
+ }
1128
+
1129
+ _objectHighlightedUpdated(entity) {
1130
+ if (entity.highlighted) {
1131
+ if (ASSERT_OBJECT_STATE_UPDATE && this.highlightedObjects[entity.id]) {
1132
+ console.error("Redundant object highlight update (highlighted=true)");
1133
+ return;
1134
+ }
1135
+ this.highlightedObjects[entity.id] = entity;
1136
+ this._numHighlightedObjects++;
1137
+ } else {
1138
+ if (ASSERT_OBJECT_STATE_UPDATE && (!this.highlightedObjects[entity.id])) {
1139
+ console.error("Redundant object highlight update (highlighted=false)");
1140
+ return;
1141
+ }
1142
+ delete this.highlightedObjects[entity.id];
1143
+ this._numHighlightedObjects--;
1144
+ }
1145
+ this._highlightedObjectIds = null; // Lazy regenerate
1146
+ }
1147
+
1148
+ _deRegisterHighlightedObject(entity) {
1149
+ delete this.highlightedObjects[entity.id];
1150
+ this._numHighlightedObjects--;
1151
+ this._highlightedObjectIds = null; // Lazy regenerate
1152
+ }
1153
+
1154
+ _objectSelectedUpdated(entity, notify = true) {
1155
+ if (entity.selected) {
1156
+ if (ASSERT_OBJECT_STATE_UPDATE && this.selectedObjects[entity.id]) {
1157
+ console.error("Redundant object select update (selected=true)");
1158
+ return;
1159
+ }
1160
+ this.selectedObjects[entity.id] = entity;
1161
+ this._numSelectedObjects++;
1162
+ } else {
1163
+ if (ASSERT_OBJECT_STATE_UPDATE && (!this.selectedObjects[entity.id])) {
1164
+ console.error("Redundant object select update (selected=false)");
1165
+ return;
1166
+ }
1167
+ delete this.selectedObjects[entity.id];
1168
+ this._numSelectedObjects--;
1169
+ }
1170
+ this._selectedObjectIds = null; // Lazy regenerate
1171
+ if (notify) {
1172
+ this.fire("objectSelected", entity, true);
1173
+ }
1174
+ }
1175
+
1176
+ _deRegisterSelectedObject(entity) {
1177
+ delete this.selectedObjects[entity.id];
1178
+ this._numSelectedObjects--;
1179
+ this._selectedObjectIds = null; // Lazy regenerate
1180
+ }
1181
+
1182
+
1183
+ _objectColorizeUpdated(entity, colorized) {
1184
+ if (colorized) {
1185
+ this.colorizedObjects[entity.id] = entity;
1186
+ this._numColorizedObjects++;
1187
+ } else {
1188
+ delete this.colorizedObjects[entity.id];
1189
+ this._numColorizedObjects--;
1190
+ }
1191
+ this._colorizedObjectIds = null; // Lazy regenerate
1192
+ }
1193
+
1194
+ _deRegisterColorizedObject(entity) {
1195
+ delete this.colorizedObjects[entity.id];
1196
+ this._numColorizedObjects--;
1197
+ this._colorizedObjectIds = null; // Lazy regenerate
1198
+ }
1199
+
1200
+ _objectOpacityUpdated(entity, opacityUpdated) {
1201
+ if (opacityUpdated) {
1202
+ this.opacityObjects[entity.id] = entity;
1203
+ this._numOpacityObjects++;
1204
+ } else {
1205
+ delete this.opacityObjects[entity.id];
1206
+ this._numOpacityObjects--;
1207
+ }
1208
+ this._opacityObjectIds = null; // Lazy regenerate
1209
+ }
1210
+
1211
+ _deRegisterOpacityObject(entity) {
1212
+ delete this.opacityObjects[entity.id];
1213
+ this._numOpacityObjects--;
1214
+ this._opacityObjectIds = null; // Lazy regenerate
1215
+ }
1216
+
1217
+ _objectOffsetUpdated(entity, offset) {
1218
+ if (!offset || offset[0] === 0 && offset[1] === 0 && offset[2] === 0) {
1219
+ this.offsetObjects[entity.id] = entity;
1220
+ this._numOffsetObjects++;
1221
+ } else {
1222
+ delete this.offsetObjects[entity.id];
1223
+ this._numOffsetObjects--;
1224
+ }
1225
+ this._offsetObjectIds = null; // Lazy regenerate
1226
+ }
1227
+
1228
+ _deRegisterOffsetObject(entity) {
1229
+ delete this.offsetObjects[entity.id];
1230
+ this._numOffsetObjects--;
1231
+ this._offsetObjectIds = null; // Lazy regenerate
1232
+ }
1233
+
1234
+ _webglContextLost() {
1235
+ // this.loading++;
1236
+ this.canvas.spinner.processes++;
1237
+ for (const id in this.components) {
1238
+ if (this.components.hasOwnProperty(id)) {
1239
+ const component = this.components[id];
1240
+ if (component._webglContextLost) {
1241
+ component._webglContextLost();
1242
+ }
1243
+ }
1244
+ }
1245
+ this._renderer.webglContextLost();
1246
+ }
1247
+
1248
+ _webglContextRestored() {
1249
+ const gl = this.canvas.gl;
1250
+ for (const id in this.components) {
1251
+ if (this.components.hasOwnProperty(id)) {
1252
+ const component = this.components[id];
1253
+ if (component._webglContextRestored) {
1254
+ component._webglContextRestored(gl);
1255
+ }
1256
+ }
1257
+ }
1258
+ this._renderer.webglContextRestored(gl);
1259
+ //this.loading--;
1260
+ this.canvas.spinner.processes--;
1261
+ }
1262
+
1263
+ /**
1264
+ * Returns the capabilities of this Scene.
1265
+ *
1266
+ * @private
1267
+ * @returns {{astcSupported: boolean, etc1Supported: boolean, pvrtcSupported: boolean, etc2Supported: boolean, dxtSupported: boolean, bptcSupported: boolean}}
1268
+ */
1269
+ get capabilities() {
1270
+ return this._renderer.capabilities;
1271
+ }
1272
+
1273
+ /**
1274
+ * Whether {@link Entity#offset} is enabled.
1275
+ *
1276
+ * This is set via the {@link Viewer} constructor and is ````false```` by default.
1277
+ *
1278
+ * @returns {Boolean} True if {@link Entity#offset} is enabled.
1279
+ */
1280
+ get entityOffsetsEnabled() {
1281
+ return this._entityOffsetsEnabled;
1282
+ }
1283
+
1284
+ /**
1285
+ * Whether precision surface picking is enabled.
1286
+ *
1287
+ * This is set via the {@link Viewer} constructor and is ````false```` by default.
1288
+ *
1289
+ * The ````pickSurfacePrecision```` option for ````Scene#pick```` only works if this is set ````true````.
1290
+ *
1291
+ * Note that when ````true````, this configuration will increase the amount of browser memory used by the Viewer.
1292
+ *
1293
+ * @returns {Boolean} True if precision picking is enabled.
1294
+ */
1295
+ get pickSurfacePrecisionEnabled() {
1296
+ return false; // Removed
1297
+ }
1298
+
1299
+ /**
1300
+ * Whether logarithmic depth buffer is enabled.
1301
+ *
1302
+ * This is set via the {@link Viewer} constructor and is ````false```` by default.
1303
+ *
1304
+ * @returns {Boolean} True if logarithmic depth buffer is enabled.
1305
+ */
1306
+ get logarithmicDepthBufferEnabled() {
1307
+ return this._logarithmicDepthBufferEnabled;
1308
+ }
1309
+
1310
+ /**
1311
+ * Sets the number of {@link SectionPlane}s for which this Scene pre-caches resources.
1312
+ *
1313
+ * This property enhances the efficiency of SectionPlane creation by proactively allocating and caching Viewer resources for a specified quantity
1314
+ * of SectionPlanes. Introducing this parameter streamlines the initial creation speed of SectionPlanes, particularly up to the designated quantity. This parameter internally
1315
+ * configures renderer logic for the specified number of SectionPlanes, eliminating the need for setting up logic with each SectionPlane creation and thereby enhancing
1316
+ * responsiveness. It is important to consider that each SectionPlane impacts rendering performance, so it is recommended to set this value to a quantity that aligns with
1317
+ * your expected usage.
1318
+ *
1319
+ * Default is ````0````.
1320
+ */
1321
+ set numCachedSectionPlanes(numCachedSectionPlanes) {
1322
+ numCachedSectionPlanes = numCachedSectionPlanes || 0;
1323
+ if (this._sectionPlanesState.getNumCachedSectionPlanes() !== numCachedSectionPlanes) {
1324
+ this._sectionPlanesState.setNumCachedSectionPlanes(numCachedSectionPlanes);
1325
+ this._needRecompile = true;
1326
+ this.glRedraw();
1327
+ }
1328
+ }
1329
+
1330
+ /**
1331
+ * Gets the number of {@link SectionPlane}s for which this Scene pre-caches resources.
1332
+ *
1333
+ * This property enhances the efficiency of SectionPlane creation by proactively allocating and caching Viewer resources for a specified quantity
1334
+ * of SectionPlanes. Introducing this parameter streamlines the initial creation speed of SectionPlanes, particularly up to the designated quantity. This parameter internally
1335
+ * configures renderer logic for the specified number of SectionPlanes, eliminating the need for setting up logic with each SectionPlane creation and thereby enhancing
1336
+ * responsiveness. It is important to consider that each SectionPlane impacts rendering performance, so it is recommended to set this value to a quantity that aligns with
1337
+ * your expected usage.
1338
+ *
1339
+ * Default is ````0````.
1340
+ *
1341
+ * @returns {number} The number of {@link SectionPlane}s for which this Scene pre-caches resources.
1342
+ */
1343
+ get numCachedSectionPlanes() {
1344
+ return this._sectionPlanesState.getNumCachedSectionPlanes();
1345
+ }
1346
+
1347
+ /**
1348
+ * Sets whether physically-based rendering is enabled.
1349
+ *
1350
+ * Default is ````false````.
1351
+ */
1352
+ set pbrEnabled(pbrEnabled) {
1353
+ this._pbrEnabled = !!pbrEnabled;
1354
+ this.glRedraw();
1355
+ }
1356
+
1357
+ /**
1358
+ * Gets whether physically-based rendering is enabled.
1359
+ *
1360
+ * Default is ````false````.
1361
+ *
1362
+ * @returns {Boolean} True if quality rendering is enabled.
1363
+ */
1364
+ get pbrEnabled() {
1365
+ return this._pbrEnabled;
1366
+ }
1367
+
1368
+ /**
1369
+ * Sets whether data texture scene representation (DTX) is enabled for the {@link Scene}.
1370
+ *
1371
+ * Even when enabled, DTX will only work if supported.
1372
+ *
1373
+ * Default value is ````false````.
1374
+ *
1375
+ * @type {Boolean}
1376
+ */
1377
+ set dtxEnabled(value) {
1378
+ value = !!value;
1379
+ if (this._dtxEnabled === value) {
1380
+ return;
1381
+ }
1382
+ this._dtxEnabled = value;
1383
+ }
1384
+
1385
+ /**
1386
+ * Gets whether data texture-based scene representation (DTX) is enabled for the {@link Scene}.
1387
+ *
1388
+ * Even when enabled, DTX will only apply if supported.
1389
+ *
1390
+ * Default value is ````false````.
1391
+ *
1392
+ * @type {Boolean}
1393
+ */
1394
+ get dtxEnabled() {
1395
+ return this._dtxEnabled;
1396
+ }
1397
+
1398
+ /**
1399
+ * Sets whether basic color texture rendering is enabled.
1400
+ *
1401
+ * Default is ````true````.
1402
+ *
1403
+ * @returns {Boolean} True if basic color texture rendering is enabled.
1404
+ */
1405
+ set colorTextureEnabled(colorTextureEnabled) {
1406
+ this._colorTextureEnabled = !!colorTextureEnabled;
1407
+ this.glRedraw();
1408
+ }
1409
+
1410
+ /**
1411
+ * Gets whether basic color texture rendering is enabled.
1412
+ *
1413
+ * Default is ````true````.
1414
+ *
1415
+ * @returns {Boolean} True if basic color texture rendering is enabled.
1416
+ */
1417
+ get colorTextureEnabled() {
1418
+ return this._colorTextureEnabled;
1419
+ }
1420
+
1421
+ /**
1422
+ * Performs an occlusion test on all {@link Marker}s in this {@link Scene}.
1423
+ *
1424
+ * Sets each {@link Marker#visible} ````true```` if the Marker is currently not occluded by any opaque {@link Entity}s
1425
+ * in the Scene, or ````false```` if an Entity is occluding it.
1426
+ */
1427
+ doOcclusionTest() {
1428
+ if (this._needRecompile) {
1429
+ this._recompile();
1430
+ this._needRecompile = false;
1431
+ }
1432
+ this._renderer.doOcclusionTest();
1433
+ }
1434
+
1435
+ /**
1436
+ * Renders a single frame of this Scene.
1437
+ *
1438
+ * The Scene will periodically render itself after any updates, but you can call this method to force a render
1439
+ * if required.
1440
+ *
1441
+ * @param {Boolean} [forceRender=false] Forces a render when true, otherwise only renders if something has changed in this Scene
1442
+ * since the last render.
1443
+ */
1444
+ render(forceRender) {
1445
+
1446
+ if (forceRender) {
1447
+ core.runTasks();
1448
+ }
1449
+
1450
+ const renderEvent = {
1451
+ sceneId: null,
1452
+ pass: 0
1453
+ };
1454
+
1455
+ if (this._needRecompile) {
1456
+ this._recompile();
1457
+ this._renderer.imageDirty();
1458
+ this._needRecompile = false;
1459
+ }
1460
+
1461
+ if (!forceRender && !this._renderer.needsRender()) {
1462
+ return;
1463
+ }
1464
+
1465
+ renderEvent.sceneId = this.id;
1466
+
1467
+ const passes = this._passes;
1468
+ const clearEachPass = this._clearEachPass;
1469
+ let pass;
1470
+ let clear;
1471
+
1472
+ for (pass = 0; pass < passes; pass++) {
1473
+
1474
+ renderEvent.pass = pass;
1475
+
1476
+ /**
1477
+ * Fired when about to render a frame for a Scene.
1478
+ *
1479
+ * @event rendering
1480
+ * @param {String} sceneID The ID of this Scene.
1481
+ * @param {Number} pass Index of the pass we are about to render (see {@link Scene#passes}).
1482
+ */
1483
+ this.fire("rendering", renderEvent, true);
1484
+
1485
+ clear = clearEachPass || (pass === 0);
1486
+
1487
+ this._renderer.render({pass: pass, clear: clear, force: forceRender});
1488
+
1489
+ /**
1490
+ * Fired when we have just rendered a frame for a Scene.
1491
+ *
1492
+ * @event rendering
1493
+ * @param {String} sceneID The ID of this Scene.
1494
+ * @param {Number} pass Index of the pass we rendered (see {@link Scene#passes}).
1495
+ */
1496
+ this.fire("rendered", renderEvent, true);
1497
+ }
1498
+
1499
+ this._saveAmbientColor();
1500
+ }
1501
+
1502
+
1503
+ /**
1504
+ * @private
1505
+ */
1506
+ compile() {
1507
+ if (this._needRecompile) {
1508
+ this._recompile();
1509
+ this._renderer.imageDirty();
1510
+ this._needRecompile = false;
1511
+ }
1512
+ }
1513
+
1514
+ _recompile() {
1515
+ for (const id in this._compilables) {
1516
+ if (this._compilables.hasOwnProperty(id)) {
1517
+ this._compilables[id].compile();
1518
+ }
1519
+ }
1520
+ this._renderer.shadowsDirty();
1521
+ this.fire("compile", this, true);
1522
+ }
1523
+
1524
+ _saveAmbientColor() {
1525
+ const canvas = this.canvas;
1526
+ if (!canvas.transparent && !canvas.backgroundImage && !canvas.backgroundColor) {
1527
+ const ambientColorIntensity = this._lightsState.getAmbientColorAndIntensity();
1528
+ if (!this._lastAmbientColor ||
1529
+ this._lastAmbientColor[0] !== ambientColorIntensity[0] ||
1530
+ this._lastAmbientColor[1] !== ambientColorIntensity[1] ||
1531
+ this._lastAmbientColor[2] !== ambientColorIntensity[2] ||
1532
+ this._lastAmbientColor[3] !== ambientColorIntensity[3]) {
1533
+ canvas.backgroundColor = ambientColorIntensity;
1534
+ if (!this._lastAmbientColor) {
1535
+ this._lastAmbientColor = math.vec4([0, 0, 0, 1]);
1536
+ }
1537
+ this._lastAmbientColor.set(ambientColorIntensity);
1538
+ }
1539
+ } else {
1540
+ this._lastAmbientColor = null;
1541
+ }
1542
+ }
1543
+
1544
+ /**
1545
+ * Gets the IDs of the {@link Entity}s in {@link Scene#models}.
1546
+ *
1547
+ * @type {String[]}
1548
+ */
1549
+ get modelIds() {
1550
+ if (!this._modelIds) {
1551
+ this._modelIds = Object.keys(this.models);
1552
+ }
1553
+ return this._modelIds;
1554
+ }
1555
+
1556
+ /**
1557
+ * Gets the number of {@link Entity}s in {@link Scene#objects}.
1558
+ *
1559
+ * @type {Number}
1560
+ */
1561
+ get numObjects() {
1562
+ return this._numObjects;
1563
+ }
1564
+
1565
+ /**
1566
+ * Gets the IDs of the {@link Entity}s in {@link Scene#objects}.
1567
+ *
1568
+ * @type {String[]}
1569
+ */
1570
+ get objectIds() {
1571
+ if (!this._objectIds) {
1572
+ this._objectIds = Object.keys(this.objects);
1573
+ }
1574
+ return this._objectIds;
1575
+ }
1576
+
1577
+ /**
1578
+ * Gets the number of {@link Entity}s in {@link Scene#visibleObjects}.
1579
+ *
1580
+ * @type {Number}
1581
+ */
1582
+ get numVisibleObjects() {
1583
+ return this._numVisibleObjects;
1584
+ }
1585
+
1586
+ /**
1587
+ * Gets the IDs of the {@link Entity}s in {@link Scene#visibleObjects}.
1588
+ *
1589
+ * @type {String[]}
1590
+ */
1591
+ get visibleObjectIds() {
1592
+ if (!this._visibleObjectIds) {
1593
+ this._visibleObjectIds = Object.keys(this.visibleObjects);
1594
+ }
1595
+ return this._visibleObjectIds;
1596
+ }
1597
+
1598
+ /**
1599
+ * Gets the number of {@link Entity}s in {@link Scene#xrayedObjects}.
1600
+ *
1601
+ * @type {Number}
1602
+ */
1603
+ get numXRayedObjects() {
1604
+ return this._numXRayedObjects;
1605
+ }
1606
+
1607
+ /**
1608
+ * Gets the IDs of the {@link Entity}s in {@link Scene#xrayedObjects}.
1609
+ *
1610
+ * @type {String[]}
1611
+ */
1612
+ get xrayedObjectIds() {
1613
+ if (!this._xrayedObjectIds) {
1614
+ this._xrayedObjectIds = Object.keys(this.xrayedObjects);
1615
+ }
1616
+ return this._xrayedObjectIds;
1617
+ }
1618
+
1619
+ /**
1620
+ * Gets the number of {@link Entity}s in {@link Scene#highlightedObjects}.
1621
+ *
1622
+ * @type {Number}
1623
+ */
1624
+ get numHighlightedObjects() {
1625
+ return this._numHighlightedObjects;
1626
+ }
1627
+
1628
+ /**
1629
+ * Gets the IDs of the {@link Entity}s in {@link Scene#highlightedObjects}.
1630
+ *
1631
+ * @type {String[]}
1632
+ */
1633
+ get highlightedObjectIds() {
1634
+ if (!this._highlightedObjectIds) {
1635
+ this._highlightedObjectIds = Object.keys(this.highlightedObjects);
1636
+ }
1637
+ return this._highlightedObjectIds;
1638
+ }
1639
+
1640
+ /**
1641
+ * Gets the number of {@link Entity}s in {@link Scene#selectedObjects}.
1642
+ *
1643
+ * @type {Number}
1644
+ */
1645
+ get numSelectedObjects() {
1646
+ return this._numSelectedObjects;
1647
+ }
1648
+
1649
+ /**
1650
+ * Gets the IDs of the {@link Entity}s in {@link Scene#selectedObjects}.
1651
+ *
1652
+ * @type {String[]}
1653
+ */
1654
+ get selectedObjectIds() {
1655
+ if (!this._selectedObjectIds) {
1656
+ this._selectedObjectIds = Object.keys(this.selectedObjects);
1657
+ }
1658
+ return this._selectedObjectIds;
1659
+ }
1660
+
1661
+ /**
1662
+ * Gets the number of {@link Entity}s in {@link Scene#colorizedObjects}.
1663
+ *
1664
+ * @type {Number}
1665
+ */
1666
+ get numColorizedObjects() {
1667
+ return this._numColorizedObjects;
1668
+ }
1669
+
1670
+ /**
1671
+ * Gets the IDs of the {@link Entity}s in {@link Scene#colorizedObjects}.
1672
+ *
1673
+ * @type {String[]}
1674
+ */
1675
+ get colorizedObjectIds() {
1676
+ if (!this._colorizedObjectIds) {
1677
+ this._colorizedObjectIds = Object.keys(this.colorizedObjects);
1678
+ }
1679
+ return this._colorizedObjectIds;
1680
+ }
1681
+
1682
+ /**
1683
+ * Gets the IDs of the {@link Entity}s in {@link Scene#opacityObjects}.
1684
+ *
1685
+ * @type {String[]}
1686
+ */
1687
+ get opacityObjectIds() {
1688
+ if (!this._opacityObjectIds) {
1689
+ this._opacityObjectIds = Object.keys(this.opacityObjects);
1690
+ }
1691
+ return this._opacityObjectIds;
1692
+ }
1693
+
1694
+ /**
1695
+ * Gets the IDs of the {@link Entity}s in {@link Scene#offsetObjects}.
1696
+ *
1697
+ * @type {String[]}
1698
+ */
1699
+ get offsetObjectIds() {
1700
+ if (!this._offsetObjectIds) {
1701
+ this._offsetObjectIds = Object.keys(this.offsetObjects);
1702
+ }
1703
+ return this._offsetObjectIds;
1704
+ }
1705
+
1706
+ /**
1707
+ * Sets the number of "ticks" that happen between each render or this Scene.
1708
+ *
1709
+ * Default value is ````1````.
1710
+ *
1711
+ * @type {Number}
1712
+ */
1713
+ set ticksPerRender(value) {
1714
+ if (value === undefined || value === null) {
1715
+ value = 1;
1716
+ } else if (!utils.isNumeric(value) || value <= 0) {
1717
+ this.error("Unsupported value for 'ticksPerRender': '" + value +
1718
+ "' - should be an integer greater than zero.");
1719
+ value = 1;
1720
+ }
1721
+ if (value === this._ticksPerRender) {
1722
+ return;
1723
+ }
1724
+ this._ticksPerRender = value;
1725
+ }
1726
+
1727
+ /**
1728
+ * Gets the number of "ticks" that happen between each render or this Scene.
1729
+ *
1730
+ * Default value is ````1````.
1731
+ *
1732
+ * @type {Number}
1733
+ */
1734
+ get ticksPerRender() {
1735
+ return this._ticksPerRender;
1736
+ }
1737
+
1738
+ /**
1739
+ * Sets the number of "ticks" that happen between occlusion testing for {@link Marker}s.
1740
+ *
1741
+ * Default value is ````20````.
1742
+ *
1743
+ * @type {Number}
1744
+ */
1745
+ set ticksPerOcclusionTest(value) {
1746
+ if (value === undefined || value === null) {
1747
+ value = 20;
1748
+ } else if (!utils.isNumeric(value) || value <= 0) {
1749
+ this.error("Unsupported value for 'ticksPerOcclusionTest': '" + value +
1750
+ "' - should be an integer greater than zero.");
1751
+ value = 20;
1752
+ }
1753
+ if (value === this._ticksPerOcclusionTest) {
1754
+ return;
1755
+ }
1756
+ this._ticksPerOcclusionTest = value;
1757
+ }
1758
+
1759
+ /**
1760
+ * Gets the number of "ticks" that happen between each render of this Scene.
1761
+ *
1762
+ * Default value is ````1````.
1763
+ *
1764
+ * @type {Number}
1765
+ */
1766
+ get ticksPerOcclusionTest() {
1767
+ return this._ticksPerOcclusionTest;
1768
+ }
1769
+
1770
+ /**
1771
+ * Sets the number of times this Scene renders per frame.
1772
+ *
1773
+ * Default value is ````1````.
1774
+ *
1775
+ * @type {Number}
1776
+ */
1777
+ set passes(value) {
1778
+ if (value === undefined || value === null) {
1779
+ value = 1;
1780
+ } else if (!utils.isNumeric(value) || value <= 0) {
1781
+ this.error("Unsupported value for 'passes': '" + value +
1782
+ "' - should be an integer greater than zero.");
1783
+ value = 1;
1784
+ }
1785
+ if (value === this._passes) {
1786
+ return;
1787
+ }
1788
+ this._passes = value;
1789
+ this.glRedraw();
1790
+ }
1791
+
1792
+ /**
1793
+ * Gets the number of times this Scene renders per frame.
1794
+ *
1795
+ * Default value is ````1````.
1796
+ *
1797
+ * @type {Number}
1798
+ */
1799
+ get passes() {
1800
+ return this._passes;
1801
+ }
1802
+
1803
+ /**
1804
+ * When {@link Scene#passes} is greater than ````1````, indicates whether or not to clear the canvas before each pass (````true````) or just before the first pass (````false````).
1805
+ *
1806
+ * Default value is ````false````.
1807
+ *
1808
+ * @type {Boolean}
1809
+ */
1810
+ set clearEachPass(value) {
1811
+ value = !!value;
1812
+ if (value === this._clearEachPass) {
1813
+ return;
1814
+ }
1815
+ this._clearEachPass = value;
1816
+ this.glRedraw();
1817
+ }
1818
+
1819
+ /**
1820
+ * When {@link Scene#passes} is greater than ````1````, indicates whether or not to clear the canvas before each pass (````true````) or just before the first pass (````false````).
1821
+ *
1822
+ * Default value is ````false````.
1823
+ *
1824
+ * @type {Boolean}
1825
+ */
1826
+ get clearEachPass() {
1827
+ return this._clearEachPass;
1828
+ }
1829
+
1830
+ /**
1831
+ * Sets whether or not {@link Scene} should expect all {@link Texture}s and colors to have pre-multiplied gamma.
1832
+ *
1833
+ * Default value is ````false````.
1834
+ *
1835
+ * @type {Boolean}
1836
+ */
1837
+ set gammaInput(value) {
1838
+ value = value !== false;
1839
+ if (value === this._renderer.gammaInput) {
1840
+ return;
1841
+ }
1842
+ this._renderer.gammaInput = value;
1843
+ this._needRecompile = true;
1844
+ this.glRedraw();
1845
+ }
1846
+
1847
+ /**
1848
+ * Gets whether or not {@link Scene} should expect all {@link Texture}s and colors to have pre-multiplied gamma.
1849
+ *
1850
+ * Default value is ````false````.
1851
+ *
1852
+ * @type {Boolean}
1853
+ */
1854
+ get gammaInput() {
1855
+ return this._renderer.gammaInput;
1856
+ }
1857
+
1858
+ /**
1859
+ * Sets whether or not to render pixels with pre-multiplied gama.
1860
+ *
1861
+ * Default value is ````false````.
1862
+ *
1863
+ * @type {Boolean}
1864
+ */
1865
+ set gammaOutput(value) {
1866
+ value = !!value;
1867
+ if (value === this._renderer.gammaOutput) {
1868
+ return;
1869
+ }
1870
+ this._renderer.gammaOutput = value;
1871
+ this._needRecompile = true;
1872
+ this.glRedraw();
1873
+ }
1874
+
1875
+ /**
1876
+ * Gets whether or not to render pixels with pre-multiplied gama.
1877
+ *
1878
+ * Default value is ````true````.
1879
+ *
1880
+ * @type {Boolean}
1881
+ */
1882
+ get gammaOutput() {
1883
+ return this._renderer.gammaOutput;
1884
+ }
1885
+
1886
+ /**
1887
+ * Sets the gamma factor to use when {@link Scene#gammaOutput} is set true.
1888
+ *
1889
+ * Default value is ````2.2````.
1890
+ *
1891
+ * @type {Number}
1892
+ */
1893
+ set gammaFactor(value) {
1894
+ value = (value === undefined || value === null) ? 2.2 : value;
1895
+ if (value === this._renderer.gammaFactor) {
1896
+ return;
1897
+ }
1898
+ this._renderer.gammaFactor = value;
1899
+ this.glRedraw();
1900
+ }
1901
+
1902
+ /**
1903
+ * Gets the gamma factor to use when {@link Scene#gammaOutput} is set true.
1904
+ *
1905
+ * Default value is ````2.2````.
1906
+ *
1907
+ * @type {Number}
1908
+ */
1909
+ get gammaFactor() {
1910
+ return this._renderer.gammaFactor;
1911
+ }
1912
+
1913
+ /**
1914
+ * Gets the default {@link Geometry} for this Scene, which is a {@link ReadableGeometry} with a unit-sized box shape.
1915
+ *
1916
+ * Has {@link ReadableGeometry#id} set to "default.geometry".
1917
+ *
1918
+ * {@link Mesh}s in this Scene have {@link Mesh#geometry} set to this {@link ReadableGeometry} by default.
1919
+ *
1920
+ * @type {ReadableGeometry}
1921
+ */
1922
+ get geometry() {
1923
+ return this.components["default.geometry"] || buildBoxGeometry(ReadableGeometry, this, {
1924
+ id: "default.geometry",
1925
+ dontClear: true
1926
+ });
1927
+ }
1928
+
1929
+ /**
1930
+ * Gets the default {@link Material} for this Scene, which is a {@link PhongMaterial}.
1931
+ *
1932
+ * Has {@link PhongMaterial#id} set to "default.material".
1933
+ *
1934
+ * {@link Mesh}s in this Scene have {@link Mesh#material} set to this {@link PhongMaterial} by default.
1935
+ *
1936
+ * @type {PhongMaterial}
1937
+ */
1938
+ get material() {
1939
+ return this.components["default.material"] || new PhongMaterial(this, {
1940
+ id: "default.material",
1941
+ emissive: [0.4, 0.4, 0.4], // Visible by default on geometry without normals
1942
+ dontClear: true
1943
+ });
1944
+ }
1945
+
1946
+ /**
1947
+ * Gets the default xraying {@link EmphasisMaterial} for this Scene.
1948
+ *
1949
+ * Has {@link EmphasisMaterial#id} set to "default.xrayMaterial".
1950
+ *
1951
+ * {@link Mesh}s in this Scene have {@link Mesh#xrayMaterial} set to this {@link EmphasisMaterial} by default.
1952
+ *
1953
+ * {@link Mesh}s are xrayed while {@link Mesh#xrayed} is ````true````.
1954
+ *
1955
+ * @type {EmphasisMaterial}
1956
+ */
1957
+ get xrayMaterial() {
1958
+ return this.components["default.xrayMaterial"] || new EmphasisMaterial(this, {
1959
+ id: "default.xrayMaterial",
1960
+ preset: "sepia",
1961
+ dontClear: true
1962
+ });
1963
+ }
1964
+
1965
+ /**
1966
+ * Gets the default highlight {@link EmphasisMaterial} for this Scene.
1967
+ *
1968
+ * Has {@link EmphasisMaterial#id} set to "default.highlightMaterial".
1969
+ *
1970
+ * {@link Mesh}s in this Scene have {@link Mesh#highlightMaterial} set to this {@link EmphasisMaterial} by default.
1971
+ *
1972
+ * {@link Mesh}s are highlighted while {@link Mesh#highlighted} is ````true````.
1973
+ *
1974
+ * @type {EmphasisMaterial}
1975
+ */
1976
+ get highlightMaterial() {
1977
+ return this.components["default.highlightMaterial"] || new EmphasisMaterial(this, {
1978
+ id: "default.highlightMaterial",
1979
+ preset: "yellowHighlight",
1980
+ dontClear: true
1981
+ });
1982
+ }
1983
+
1984
+ /**
1985
+ * Gets the default selection {@link EmphasisMaterial} for this Scene.
1986
+ *
1987
+ * Has {@link EmphasisMaterial#id} set to "default.selectedMaterial".
1988
+ *
1989
+ * {@link Mesh}s in this Scene have {@link Mesh#highlightMaterial} set to this {@link EmphasisMaterial} by default.
1990
+ *
1991
+ * {@link Mesh}s are highlighted while {@link Mesh#highlighted} is ````true````.
1992
+ *
1993
+ * @type {EmphasisMaterial}
1994
+ */
1995
+ get selectedMaterial() {
1996
+ return this.components["default.selectedMaterial"] || new EmphasisMaterial(this, {
1997
+ id: "default.selectedMaterial",
1998
+ preset: "greenSelected",
1999
+ dontClear: true
2000
+ });
2001
+ }
2002
+
2003
+ /**
2004
+ * Gets the default {@link EdgeMaterial} for this Scene.
2005
+ *
2006
+ * Has {@link EdgeMaterial#id} set to "default.edgeMaterial".
2007
+ *
2008
+ * {@link Mesh}s in this Scene have {@link Mesh#edgeMaterial} set to this {@link EdgeMaterial} by default.
2009
+ *
2010
+ * {@link Mesh}s have their edges emphasized while {@link Mesh#edges} is ````true````.
2011
+ *
2012
+ * @type {EdgeMaterial}
2013
+ */
2014
+ get edgeMaterial() {
2015
+ return this.components["default.edgeMaterial"] || new EdgeMaterial(this, {
2016
+ id: "default.edgeMaterial",
2017
+ preset: "default",
2018
+ edgeColor: [0.0, 0.0, 0.0],
2019
+ edgeAlpha: 1.0,
2020
+ edgeWidth: 1,
2021
+ dontClear: true
2022
+ });
2023
+ }
2024
+
2025
+ /**
2026
+ * Gets the {@link PointsMaterial} for this Scene.
2027
+ *
2028
+ * @type {PointsMaterial}
2029
+ */
2030
+ get pointsMaterial() {
2031
+ return this.components["default.pointsMaterial"] || new PointsMaterial(this, {
2032
+ id: "default.pointsMaterial",
2033
+ preset: "default",
2034
+ dontClear: true
2035
+ });
2036
+ }
2037
+
2038
+ /**
2039
+ * Gets the {@link LinesMaterial} for this Scene.
2040
+ *
2041
+ * @type {LinesMaterial}
2042
+ */
2043
+ get linesMaterial() {
2044
+ return this.components["default.linesMaterial"] || new LinesMaterial(this, {
2045
+ id: "default.linesMaterial",
2046
+ preset: "default",
2047
+ dontClear: true
2048
+ });
2049
+ }
2050
+
2051
+ /**
2052
+ * Gets the {@link Viewport} for this Scene.
2053
+ *
2054
+ * @type Viewport
2055
+ */
2056
+ get viewport() {
2057
+ return this._viewport;
2058
+ }
2059
+
2060
+ /**
2061
+ * Gets the {@link Camera} for this Scene.
2062
+ *
2063
+ * @type {Camera}
2064
+ */
2065
+ get camera() {
2066
+ return this._camera;
2067
+ }
2068
+
2069
+ /**
2070
+ * Gets the World-space 3D center of this Scene.
2071
+ *
2072
+ *@type {Number[]}
2073
+ */
2074
+ get center() {
2075
+ if (this._aabbDirty || !this._center) {
2076
+ if (!this._center || !this._center) {
2077
+ this._center = math.vec3();
2078
+ }
2079
+ const aabb = this.aabb;
2080
+ this._center[0] = (aabb[0] + aabb[3]) / 2;
2081
+ this._center[1] = (aabb[1] + aabb[4]) / 2;
2082
+ this._center[2] = (aabb[2] + aabb[5]) / 2;
2083
+ }
2084
+ return this._center;
2085
+ }
2086
+
2087
+ /**
2088
+ * Gets the World-space axis-aligned 3D boundary (AABB) of this Scene.
2089
+ *
2090
+ * The AABB is represented by a six-element Float64Array containing the min/max extents of the axis-aligned volume, ie. ````[xmin, ymin,zmin,xmax,ymax, zmax]````.
2091
+ *
2092
+ * When the Scene has no content, will be ````[-100,-100,-100,100,100,100]````.
2093
+ *
2094
+ * @type {Number[]}
2095
+ */
2096
+ get aabb() {
2097
+ if (this._aabbDirty) {
2098
+ if (!this._aabb) {
2099
+ this._aabb = math.AABB3();
2100
+ }
2101
+ let xmin = math.MAX_DOUBLE;
2102
+ let ymin = math.MAX_DOUBLE;
2103
+ let zmin = math.MAX_DOUBLE;
2104
+ let xmax = math.MIN_DOUBLE;
2105
+ let ymax = math.MIN_DOUBLE;
2106
+ let zmax = math.MIN_DOUBLE;
2107
+ let aabb;
2108
+ const collidables = this._collidables;
2109
+ let collidable;
2110
+ let valid = false;
2111
+ for (const collidableId in collidables) {
2112
+ if (collidables.hasOwnProperty(collidableId)) {
2113
+ collidable = collidables[collidableId];
2114
+ if (collidable.collidable === false) {
2115
+ continue;
2116
+ }
2117
+ aabb = collidable.aabb;
2118
+ if (aabb[0] < xmin) {
2119
+ xmin = aabb[0];
2120
+ }
2121
+ if (aabb[1] < ymin) {
2122
+ ymin = aabb[1];
2123
+ }
2124
+ if (aabb[2] < zmin) {
2125
+ zmin = aabb[2];
2126
+ }
2127
+ if (aabb[3] > xmax) {
2128
+ xmax = aabb[3];
2129
+ }
2130
+ if (aabb[4] > ymax) {
2131
+ ymax = aabb[4];
2132
+ }
2133
+ if (aabb[5] > zmax) {
2134
+ zmax = aabb[5];
2135
+ }
2136
+ valid = true;
2137
+ }
2138
+ }
2139
+ if (!valid) {
2140
+ xmin = -100;
2141
+ ymin = -100;
2142
+ zmin = -100;
2143
+ xmax = 100;
2144
+ ymax = 100;
2145
+ zmax = 100;
2146
+ }
2147
+ this._aabb[0] = xmin;
2148
+ this._aabb[1] = ymin;
2149
+ this._aabb[2] = zmin;
2150
+ this._aabb[3] = xmax;
2151
+ this._aabb[4] = ymax;
2152
+ this._aabb[5] = zmax;
2153
+ this._aabbDirty = false;
2154
+ }
2155
+ return this._aabb;
2156
+ }
2157
+
2158
+ _setAABBDirty() {
2159
+ //if (!this._aabbDirty) {
2160
+ this._aabbDirty = true;
2161
+ this.fire("boundary");
2162
+ // }
2163
+ }
2164
+
2165
+ /**
2166
+ * Attempts to pick an {@link Entity} in this Scene.
2167
+ *
2168
+ * Ignores {@link Entity}s with {@link Entity#pickable} set ````false````.
2169
+ *
2170
+ * When an {@link Entity} is picked, fires a "pick" event on the {@link Entity} with the pick result as parameters.
2171
+ *
2172
+ * Picking the {@link Entity} at the given canvas coordinates:
2173
+
2174
+ * ````javascript
2175
+ * var pickResult = scene.pick({
2176
+ * canvasPos: [23, 131]
2177
+ * });
2178
+ *
2179
+ * if (pickResult) { // Picked an Entity
2180
+ * var entity = pickResult.entity;
2181
+ * }
2182
+ * ````
2183
+ *
2184
+ * Picking, with a ray cast through the canvas, hits an {@link Entity}:
2185
+ *
2186
+ * ````javascript
2187
+ * var pickResult = scene.pick({
2188
+ * pickSurface: true,
2189
+ * canvasPos: [23, 131]
2190
+ * });
2191
+ *
2192
+ * if (pickResult) { // Picked an Entity
2193
+ *
2194
+ * var entity = pickResult.entity;
2195
+ *
2196
+ * if (pickResult.primitive === "triangle") {
2197
+ *
2198
+ * // Picked a triangle on the entity surface
2199
+ *
2200
+ * var primIndex = pickResult.primIndex; // Position of triangle's first index in the picked Entity's Geometry's indices array
2201
+ * var indices = pickResult.indices; // UInt32Array containing the triangle's vertex indices
2202
+ * var localPos = pickResult.localPos; // Float64Array containing the picked Local-space position on the triangle
2203
+ * var worldPos = pickResult.worldPos; // Float64Array containing the picked World-space position on the triangle
2204
+ * var viewPos = pickResult.viewPos; // Float64Array containing the picked View-space position on the triangle
2205
+ * var bary = pickResult.bary; // Float64Array containing the picked barycentric position within the triangle
2206
+ * var worldNormal = pickResult.worldNormal; // Float64Array containing the interpolated World-space normal vector at the picked position on the triangle
2207
+ * var uv = pickResult.uv; // Float64Array containing the interpolated UV coordinates at the picked position on the triangle
2208
+ *
2209
+ * } else if (pickResult.worldPos && pickResult.worldNormal) {
2210
+ *
2211
+ * // Picked a point and normal on the entity surface
2212
+ *
2213
+ * var worldPos = pickResult.worldPos; // Float64Array containing the picked World-space position on the Entity surface
2214
+ * var worldNormal = pickResult.worldNormal; // Float64Array containing the picked World-space normal vector on the Entity Surface
2215
+ * }
2216
+ * }
2217
+ * ````
2218
+ *
2219
+ * Picking the {@link Entity} that intersects an arbitrarily-aligned World-space ray:
2220
+ *
2221
+ * ````javascript
2222
+ * var pickResult = scene.pick({
2223
+ * pickSurface: true, // Picking with arbitrarily-positioned ray
2224
+ * origin: [0,0,-5], // Ray origin
2225
+ * direction: [0,0,1] // Ray direction
2226
+ * });
2227
+ *
2228
+ * if (pickResult) { // Picked an Entity with the ray
2229
+ *
2230
+ * var entity = pickResult.entity;
2231
+ *
2232
+ * if (pickResult.primitive == "triangle") {
2233
+ *
2234
+ * // Picked a triangle on the entity surface
2235
+ *
2236
+ * var primitive = pickResult.primitive; // Type of primitive that was picked, usually "triangles"
2237
+ * var primIndex = pickResult.primIndex; // Position of triangle's first index in the picked Entity's Geometry's indices array
2238
+ * var indices = pickResult.indices; // UInt32Array containing the triangle's vertex indices
2239
+ * var localPos = pickResult.localPos; // Float64Array containing the picked Local-space position on the triangle
2240
+ * var worldPos = pickResult.worldPos; // Float64Array containing the picked World-space position on the triangle
2241
+ * var viewPos = pickResult.viewPos; // Float64Array containing the picked View-space position on the triangle
2242
+ * var bary = pickResult.bary; // Float64Array containing the picked barycentric position within the triangle
2243
+ * var worldNormal = pickResult.worldNormal; // Float64Array containing the interpolated World-space normal vector at the picked position on the triangle
2244
+ * var uv = pickResult.uv; // Float64Array containing the interpolated UV coordinates at the picked position on the triangle
2245
+ * var origin = pickResult.origin; // Float64Array containing the World-space ray origin
2246
+ * var direction = pickResult.direction; // Float64Array containing the World-space ray direction
2247
+ *
2248
+ * } else if (pickResult.worldPos && pickResult.worldNormal) {
2249
+ *
2250
+ * // Picked a point and normal on the entity surface
2251
+ *
2252
+ * var worldPos = pickResult.worldPos; // Float64Array containing the picked World-space position on the Entity surface
2253
+ * var worldNormal = pickResult.worldNormal; // Float64Array containing the picked World-space normal vector on the Entity Surface
2254
+ * }
2255
+ * }
2256
+ * ````
2257
+ *
2258
+ * @param {*} params Picking parameters.
2259
+ * @param {Boolean} [params.pickSurface=false] Whether to find the picked position on the surface of the Entity.
2260
+ * @param {Boolean} [params.pickSurfacePrecision=false] When picking an Entity surface position, indicates whether or not we want full-precision {@link PickResult#worldPos}. Only works when {@link Scene#pickSurfacePrecisionEnabled} is ````true````. If pick succeeds, the returned {@link PickResult} will have {@link PickResult#precision} set ````true````, to indicate that it contains full-precision surface pick results.
2261
+ * @param {Boolean} [params.pickSurfaceNormal=false] Whether to find the picked normal on the surface of the Entity. Only works if ````pickSurface```` is given.
2262
+ * @param {Number[]} [params.canvasPos] Canvas-space coordinates. When ray-picking, this will override the **origin** and ** direction** parameters and will cause the ray to be fired through the canvas at this position, directly along the negative View-space Z-axis.
2263
+ * @param {Number[]} [params.origin] World-space ray origin when ray-picking. Ignored when canvasPos given.
2264
+ * @param {Number[]} [params.direction] World-space ray direction when ray-picking. Also indicates the length of the ray. Ignored when canvasPos given.
2265
+ * @param {Number[]} [params.matrix] 4x4 transformation matrix to define the World-space ray origin and direction, as an alternative to ````origin```` and ````direction````.
2266
+ * @param {String[]} [params.includeEntities] IDs of {@link Entity}s to restrict picking to. When given, ignores {@link Entity}s whose IDs are not in this list.
2267
+ * @param {String[]} [params.excludeEntities] IDs of {@link Entity}s to ignore. When given, will pick *through* these {@link Entity}s, as if they were not there.
2268
+ * @param {Number} [params.snapRadius=30] The snap radius, in canvas pixels
2269
+ * @param {boolean} [params.snapToVertex=true] Whether to snap to vertex.
2270
+ * @param {boolean} [params.snapToEdge=true] Whether to snap to edge.
2271
+ * @param {PickResult} [pickResult] Holds the results of the pick attempt. Will use the Scene's singleton PickResult if you don't supply your own.
2272
+ * @returns {PickResult} Holds results of the pick attempt, returned when an {@link Entity} is picked, else null. See method comments for description.
2273
+ */
2274
+ pick(params, pickResult) {
2275
+
2276
+ if (this.canvas.boundary[2] === 0 || this.canvas.boundary[3] === 0) {
2277
+ this.error("Picking not allowed while canvas has zero width or height");
2278
+ return null;
2279
+ }
2280
+
2281
+ params = params || {};
2282
+
2283
+ params.pickSurface = params.pickSurface || params.rayPick; // Backwards compatibility
2284
+
2285
+ if (!params.canvasPos && !params.matrix && (!params.origin || !params.direction)) {
2286
+ this.warn("picking without canvasPos, matrix, or ray origin and direction");
2287
+ }
2288
+
2289
+ const includeEntities = params.includeEntities || params.include; // Backwards compat
2290
+ if (includeEntities) {
2291
+ params.includeEntityIds = getEntityIDMap(this, includeEntities);
2292
+ }
2293
+
2294
+ const excludeEntities = params.excludeEntities || params.exclude; // Backwards compat
2295
+ if (excludeEntities) {
2296
+ params.excludeEntityIds = getEntityIDMap(this, excludeEntities);
2297
+ }
2298
+
2299
+ if (this._needRecompile) {
2300
+ this._recompile();
2301
+ this._renderer.imageDirty();
2302
+ this._needRecompile = false;
2303
+ }
2304
+
2305
+ if (params.snapToEdge || params.snapToVertex) {
2306
+ pickResult = this._renderer.snapPick(
2307
+ params.canvasPos,
2308
+ params.snapRadius || 30,
2309
+ params.snapToVertex,
2310
+ params.snapToEdge,
2311
+ pickResult
2312
+ );
2313
+ } else {
2314
+ pickResult = this._renderer.pick(params, pickResult);
2315
+ }
2316
+
2317
+ if (pickResult) {
2318
+ if (pickResult.entity && pickResult.entity.fire) {
2319
+ pickResult.entity.fire("picked", pickResult); // TODO: SceneModelEntity doesn't fire events
2320
+ }
2321
+ }
2322
+
2323
+ return pickResult;
2324
+ }
2325
+
2326
+ /**
2327
+ * @param {Object} params Picking parameters.
2328
+ * @param {Number[]} [params.canvasPos] Canvas-space coordinates. When ray-picking, this will override the **origin** and ** direction** parameters and will cause the ray to be fired through the canvas at this position, directly along the negative View-space Z-axis.
2329
+ * @param {Number} [params.snapRadius=30] The snap radius, in canvas pixels
2330
+ * @param {boolean} [params.snapToVertex=true] Whether to snap to vertex.
2331
+ * @param {boolean} [params.snapToEdge=true] Whether to snap to edge.
2332
+ * @deprecated
2333
+ */
2334
+ snapPick(params) {
2335
+ if (undefined === this._warnSnapPickDeprecated) {
2336
+ this._warnSnapPickDeprecated = true;
2337
+ this.warn("Scene.snapPick() is deprecated since v2.4.2 - use Scene.pick() instead")
2338
+ }
2339
+ return this._renderer.snapPick(
2340
+ params.canvasPos,
2341
+ params.snapRadius || 30,
2342
+ params.snapToVertex,
2343
+ params.snapToEdge,
2344
+ );
2345
+ }
2346
+
2347
+ /**
2348
+ * Destroys all non-default {@link Component}s in this Scene.
2349
+ */
2350
+ clear() {
2351
+ var component;
2352
+ for (const id in this.components) {
2353
+ if (this.components.hasOwnProperty(id)) {
2354
+ component = this.components[id];
2355
+ if (!component._dontClear) { // Don't destroy components like Camera, Input, Viewport etc.
2356
+ component.destroy();
2357
+ }
2358
+ }
2359
+ }
2360
+ }
2361
+
2362
+ /**
2363
+ * Destroys all {@link Light}s in this Scene..
2364
+ */
2365
+ clearLights() {
2366
+ const ids = Object.keys(this.lights);
2367
+ for (let i = 0, len = ids.length; i < len; i++) {
2368
+ this.lights[ids[i]].destroy();
2369
+ }
2370
+ }
2371
+
2372
+ /**
2373
+ * Destroys all {@link SectionPlane}s in this Scene.
2374
+ */
2375
+ clearSectionPlanes() {
2376
+ const ids = Object.keys(this.sectionPlanes);
2377
+ for (let i = 0, len = ids.length; i < len; i++) {
2378
+ this.sectionPlanes[ids[i]].destroy();
2379
+ }
2380
+ }
2381
+
2382
+ /**
2383
+ * Destroys all {@link Line}s in this Scene.
2384
+ */
2385
+ clearBitmaps() {
2386
+ const ids = Object.keys(this.bitmaps);
2387
+ for (let i = 0, len = ids.length; i < len; i++) {
2388
+ this.bitmaps[ids[i]].destroy();
2389
+ }
2390
+ }
2391
+
2392
+
2393
+ /**
2394
+ * Destroys all {@link Line}s in this Scene.
2395
+ */
2396
+ clearLines() {
2397
+ const ids = Object.keys(this.lineSets);
2398
+ for (let i = 0, len = ids.length; i < len; i++) {
2399
+ this.lineSets[ids[i]].destroy();
2400
+ }
2401
+ }
2402
+
2403
+ /**
2404
+ * Gets the collective axis-aligned boundary (AABB) of a batch of {@link Entity}s that represent objects.
2405
+ *
2406
+ * An {@link Entity} represents an object when {@link Entity#isObject} is ````true````.
2407
+ *
2408
+ * Each {@link Entity} on which {@link Entity#isObject} is registered by {@link Entity#id} in {@link Scene#visibleObjects}.
2409
+ *
2410
+ * Each {@link Entity} is only included in the AABB when {@link Entity#collidable} is ````true````.
2411
+ *
2412
+ * @param {String[]} ids Array of {@link Entity#id} values.
2413
+ * @returns {[Number, Number, Number, Number, Number, Number]} An axis-aligned World-space bounding box, given as elements ````[xmin, ymin, zmin, xmax, ymax, zmax]````.
2414
+ */
2415
+ getAABB(ids) {
2416
+ if (ids === undefined) {
2417
+ return this.aabb;
2418
+ }
2419
+ if (utils.isString(ids)) {
2420
+ const entity = this.objects[ids];
2421
+ if (entity && entity.aabb) { // A Component subclass with an AABB
2422
+ return entity.aabb;
2423
+ }
2424
+ ids = [ids]; // Must be an entity type
2425
+ }
2426
+ if (ids.length === 0) {
2427
+ return this.aabb;
2428
+ }
2429
+ let xmin = math.MAX_DOUBLE;
2430
+ let ymin = math.MAX_DOUBLE;
2431
+ let zmin = math.MAX_DOUBLE;
2432
+ let xmax = math.MIN_DOUBLE;
2433
+ let ymax = math.MIN_DOUBLE;
2434
+ let zmax = math.MIN_DOUBLE;
2435
+ let valid;
2436
+ this.withObjects(ids, entity => {
2437
+ if (entity.collidable) {
2438
+ const aabb = entity.aabb;
2439
+ if (aabb[0] < xmin) {
2440
+ xmin = aabb[0];
2441
+ }
2442
+ if (aabb[1] < ymin) {
2443
+ ymin = aabb[1];
2444
+ }
2445
+ if (aabb[2] < zmin) {
2446
+ zmin = aabb[2];
2447
+ }
2448
+ if (aabb[3] > xmax) {
2449
+ xmax = aabb[3];
2450
+ }
2451
+ if (aabb[4] > ymax) {
2452
+ ymax = aabb[4];
2453
+ }
2454
+ if (aabb[5] > zmax) {
2455
+ zmax = aabb[5];
2456
+ }
2457
+ valid = true;
2458
+ }
2459
+ }
2460
+ );
2461
+ if (valid) {
2462
+ const aabb2 = math.AABB3();
2463
+ aabb2[0] = xmin;
2464
+ aabb2[1] = ymin;
2465
+ aabb2[2] = zmin;
2466
+ aabb2[3] = xmax;
2467
+ aabb2[4] = ymax;
2468
+ aabb2[5] = zmax;
2469
+ return aabb2;
2470
+ } else {
2471
+ return this.aabb; // Scene AABB
2472
+ }
2473
+ }
2474
+
2475
+ /**
2476
+ * Batch-updates {@link Entity#visible} on {@link Entity}s that represent objects.
2477
+ *
2478
+ * An {@link Entity} represents an object when {@link Entity#isObject} is ````true````.
2479
+ *
2480
+ * Each {@link Entity} on which both {@link Entity#isObject} and {@link Entity#visible} are ````true```` is
2481
+ * registered by {@link Entity#id} in {@link Scene#visibleObjects}.
2482
+ *
2483
+ * @param {String[]} ids Array of {@link Entity#id} values.
2484
+ * @param {Boolean} visible Whether or not to set visible.
2485
+ * @returns {Boolean} True if any {@link Entity}s were updated, else false if all updates were redundant and not applied.
2486
+ */
2487
+ setObjectsVisible(ids, visible) {
2488
+ return this.withObjects(ids, entity => {
2489
+ const changed = (entity.visible !== visible);
2490
+ entity.visible = visible;
2491
+ return changed;
2492
+ });
2493
+ }
2494
+
2495
+ /**
2496
+ * Batch-updates {@link Entity#collidable} on {@link Entity}s that represent objects.
2497
+ *
2498
+ * An {@link Entity} represents an object when {@link Entity#isObject} is ````true````.
2499
+ *
2500
+ * @param {String[]} ids Array of {@link Entity#id} values.
2501
+ * @param {Boolean} collidable Whether or not to set collidable.
2502
+ * @returns {Boolean} True if any {@link Entity}s were updated, else false if all updates were redundant and not applied.
2503
+ */
2504
+ setObjectsCollidable(ids, collidable) {
2505
+ return this.withObjects(ids, entity => {
2506
+ const changed = (entity.collidable !== collidable);
2507
+ entity.collidable = collidable;
2508
+ return changed;
2509
+ });
2510
+ }
2511
+
2512
+ /**
2513
+ * Batch-updates {@link Entity#culled} on {@link Entity}s that represent objects.
2514
+ *
2515
+ * An {@link Entity} represents an object when {@link Entity#isObject} is ````true````.
2516
+ *
2517
+ * @param {String[]} ids Array of {@link Entity#id} values.
2518
+ * @param {Boolean} culled Whether or not to cull.
2519
+ * @returns {Boolean} True if any {@link Entity}s were updated, else false if all updates were redundant and not applied.
2520
+ */
2521
+ setObjectsCulled(ids, culled) {
2522
+ return this.withObjects(ids, entity => {
2523
+ const changed = (entity.culled !== culled);
2524
+ entity.culled = culled;
2525
+ return changed;
2526
+ });
2527
+ }
2528
+
2529
+ /**
2530
+ * Batch-updates {@link Entity#selected} on {@link Entity}s that represent objects.
2531
+ *
2532
+ * An {@link Entity} represents an object when {@link Entity#isObject} is ````true````.
2533
+ *
2534
+ * Each {@link Entity} on which both {@link Entity#isObject} and {@link Entity#selected} are ````true```` is
2535
+ * registered by {@link Entity#id} in {@link Scene#selectedObjects}.
2536
+ *
2537
+ * @param {String[]} ids Array of {@link Entity#id} values.
2538
+ * @param {Boolean} selected Whether or not to select.
2539
+ * @returns {Boolean} True if any {@link Entity}s were updated, else false if all updates were redundant and not applied.
2540
+ */
2541
+ setObjectsSelected(ids, selected) {
2542
+ return this.withObjects(ids, entity => {
2543
+ const changed = (entity.selected !== selected);
2544
+ entity.selected = selected;
2545
+ return changed;
2546
+ });
2547
+ }
2548
+
2549
+ /**
2550
+ * Batch-updates {@link Entity#highlighted} on {@link Entity}s that represent objects.
2551
+ *
2552
+ * An {@link Entity} represents an object when {@link Entity#isObject} is ````true````.
2553
+ *
2554
+ * Each {@link Entity} on which both {@link Entity#isObject} and {@link Entity#highlighted} are ````true```` is
2555
+ * registered by {@link Entity#id} in {@link Scene#highlightedObjects}.
2556
+ *
2557
+ * @param {String[]} ids Array of {@link Entity#id} values.
2558
+ * @param {Boolean} highlighted Whether or not to highlight.
2559
+ * @returns {Boolean} True if any {@link Entity}s were updated, else false if all updates were redundant and not applied.
2560
+ */
2561
+ setObjectsHighlighted(ids, highlighted) {
2562
+ return this.withObjects(ids, entity => {
2563
+ const changed = (entity.highlighted !== highlighted);
2564
+ entity.highlighted = highlighted;
2565
+ return changed;
2566
+ });
2567
+ }
2568
+
2569
+ /**
2570
+ * Batch-updates {@link Entity#xrayed} on {@link Entity}s that represent objects.
2571
+ *
2572
+ * An {@link Entity} represents an object when {@link Entity#isObject} is ````true````.
2573
+ *
2574
+ * @param {String[]} ids Array of {@link Entity#id} values.
2575
+ * @param {Boolean} xrayed Whether or not to xray.
2576
+ * @returns {Boolean} True if any {@link Entity}s were updated, else false if all updates were redundant and not applied.
2577
+ */
2578
+ setObjectsXRayed(ids, xrayed) {
2579
+ return this.withObjects(ids, entity => {
2580
+ const changed = (entity.xrayed !== xrayed);
2581
+ entity.xrayed = xrayed;
2582
+ return changed;
2583
+ });
2584
+ }
2585
+
2586
+ /**
2587
+ * Batch-updates {@link Entity#edges} on {@link Entity}s that represent objects.
2588
+ *
2589
+ * An {@link Entity} represents an object when {@link Entity#isObject} is ````true````.
2590
+ *
2591
+ * @param {String[]} ids Array of {@link Entity#id} values.
2592
+ * @param {Boolean} edges Whether or not to show edges.
2593
+ * @returns {Boolean} True if any {@link Entity}s were updated, else false if all updates were redundant and not applied.
2594
+ */
2595
+ setObjectsEdges(ids, edges) {
2596
+ return this.withObjects(ids, entity => {
2597
+ const changed = (entity.edges !== edges);
2598
+ entity.edges = edges;
2599
+ return changed;
2600
+ });
2601
+ }
2602
+
2603
+ /**
2604
+ * Batch-updates {@link Entity#colorize} on {@link Entity}s that represent objects.
2605
+ *
2606
+ * An {@link Entity} represents an object when {@link Entity#isObject} is ````true````.
2607
+ *
2608
+ * @param {String[]} ids Array of {@link Entity#id} values.
2609
+ * @param {Number[]} [colorize=(1,1,1)] RGB colorize factors, multiplied by the rendered pixel colors.
2610
+ * @returns {Boolean} True if any {@link Entity}s changed opacity, else false if all updates were redundant and not applied.
2611
+ */
2612
+ setObjectsColorized(ids, colorize) {
2613
+ return this.withObjects(ids, entity => {
2614
+ entity.colorize = colorize;
2615
+ });
2616
+ }
2617
+
2618
+ /**
2619
+ * Batch-updates {@link Entity#opacity} on {@link Entity}s that represent objects.
2620
+ *
2621
+ * An {@link Entity} represents an object when {@link Entity#isObject} is ````true````.
2622
+ *
2623
+ * @param {String[]} ids Array of {@link Entity#id} values.
2624
+ * @param {Number} [opacity=1.0] Opacity factor, multiplied by the rendered pixel alphas.
2625
+ * @returns {Boolean} True if any {@link Entity}s changed opacity, else false if all updates were redundant and not applied.
2626
+ */
2627
+ setObjectsOpacity(ids, opacity) {
2628
+ return this.withObjects(ids, entity => {
2629
+ const changed = (entity.opacity !== opacity);
2630
+ entity.opacity = opacity;
2631
+ return changed;
2632
+ });
2633
+ }
2634
+
2635
+ /**
2636
+ * Batch-updates {@link Entity#pickable} on {@link Entity}s that represent objects.
2637
+ *
2638
+ * An {@link Entity} represents an object when {@link Entity#isObject} is ````true````.
2639
+ *
2640
+ * @param {String[]} ids Array of {@link Entity#id} values.
2641
+ * @param {Boolean} pickable Whether or not to set pickable.
2642
+ * @returns {Boolean} True if any {@link Entity}s were updated, else false if all updates were redundant and not applied.
2643
+ */
2644
+ setObjectsPickable(ids, pickable) {
2645
+ return this.withObjects(ids, entity => {
2646
+ const changed = (entity.pickable !== pickable);
2647
+ entity.pickable = pickable;
2648
+ return changed;
2649
+ });
2650
+ }
2651
+
2652
+ /**
2653
+ * Batch-updates {@link Entity#offset} on {@link Entity}s that represent objects.
2654
+ *
2655
+ * An {@link Entity} represents an object when {@link Entity#isObject} is ````true````.
2656
+ *
2657
+ * @param {String[]} ids Array of {@link Entity#id} values.
2658
+ * @param {Number[]} [offset] 3D offset vector.
2659
+ */
2660
+ setObjectsOffset(ids, offset) {
2661
+ this.withObjects(ids, entity => {
2662
+ entity.offset = offset;
2663
+ });
2664
+ }
2665
+
2666
+ /**
2667
+ * Iterates with a callback over {@link Entity}s that represent objects.
2668
+ *
2669
+ * An {@link Entity} represents an object when {@link Entity#isObject} is ````true````.
2670
+ *
2671
+ * @param {String[]} ids Array of {@link Entity#id} values.
2672
+ * @param {Function} callback Callback to execute on eacn {@link Entity}.
2673
+ * @returns {Boolean} True if any {@link Entity}s were updated, else false if all updates were redundant and not applied.
2674
+ */
2675
+ withObjects(ids, callback) {
2676
+ if (utils.isString(ids)) {
2677
+ ids = [ids];
2678
+ }
2679
+ let changed = false;
2680
+ for (let i = 0, len = ids.length; i < len; i++) {
2681
+ const id = ids[i];
2682
+ let entity = this.objects[id];
2683
+ if (entity) {
2684
+ changed = callback(entity) || changed;
2685
+ } else {
2686
+ const modelIds = this.modelIds;
2687
+ for (let i = 0, len = modelIds.length; i < len; i++) {
2688
+ const modelId = modelIds[i];
2689
+ const globalObjectId = math.globalizeObjectId(modelId, id);
2690
+ entity = this.objects[globalObjectId];
2691
+ if (entity) {
2692
+ changed = callback(entity) || changed;
2693
+ }
2694
+ }
2695
+ }
2696
+ }
2697
+ return changed;
2698
+ }
2699
+
2700
+ /**
2701
+ * This method will "tickify" the provided `cb` function.
2702
+ *
2703
+ * This means, the function will be wrapped so:
2704
+ *
2705
+ * - it runs time-aligned to scene ticks
2706
+ * - it runs maximum once per scene-tick
2707
+ *
2708
+ * @param {Function} cb The function to tickify
2709
+ * @returns {Function}
2710
+ */
2711
+ tickify(cb) {
2712
+ const cbString = cb.toString();
2713
+
2714
+ /**
2715
+ * Check if the function is already tickified, and if so return the cached one.
2716
+ */
2717
+ if (cbString in this._tickifiedFunctions) {
2718
+ return this._tickifiedFunctions[cbString].wrapperFunc;
2719
+ }
2720
+
2721
+ let alreadyRun = 0;
2722
+ let needToRun = 0;
2723
+
2724
+ let lastArgs;
2725
+
2726
+ /**
2727
+ * The provided `cb` function is replaced with a "set-dirty" function
2728
+ *
2729
+ * @type {Function}
2730
+ */
2731
+ const wrapperFunc = function (...args) {
2732
+ lastArgs = args;
2733
+ needToRun++;
2734
+ };
2735
+
2736
+ /**
2737
+ * An each scene tick, if the "dirty-flag" is set, run the `cb` function.
2738
+ *
2739
+ * This will make it run time-aligned to the scene tick.
2740
+ */
2741
+ const tickSubId = this.on("tick", () => {
2742
+ const tmp = needToRun;
2743
+ if (tmp > alreadyRun) {
2744
+ alreadyRun = tmp;
2745
+ cb(...lastArgs);
2746
+ }
2747
+ });
2748
+
2749
+ /**
2750
+ * And, store the list of subscribers.
2751
+ */
2752
+ this._tickifiedFunctions[cbString] = {tickSubId, wrapperFunc};
2753
+
2754
+ return wrapperFunc;
2755
+ }
2756
+
2757
+ /**
2758
+ * Destroys this Scene.
2759
+ */
2760
+ destroy() {
2761
+
2762
+ super.destroy();
2763
+
2764
+ for (const id in this.components) {
2765
+ if (this.components.hasOwnProperty(id)) {
2766
+ this.components[id].destroy();
2767
+ }
2768
+ }
2769
+
2770
+ this.canvas.gl = null;
2771
+
2772
+ // Memory leak prevention
2773
+ this.components = null;
2774
+ this.models = null;
2775
+ this.objects = null;
2776
+ this.visibleObjects = null;
2777
+ this.xrayedObjects = null;
2778
+ this.highlightedObjects = null;
2779
+ this.selectedObjects = null;
2780
+ this.colorizedObjects = null;
2781
+ this.opacityObjects = null;
2782
+ this.sectionPlanes = null;
2783
+ this.lights = null;
2784
+ this.lightMaps = null;
2785
+ this.reflectionMaps = null;
2786
+ this._objectIds = null;
2787
+ this._visibleObjectIds = null;
2788
+ this._xrayedObjectIds = null;
2789
+ this._highlightedObjectIds = null;
2790
+ this._selectedObjectIds = null;
2791
+ this._colorizedObjectIds = null;
2792
+ this.types = null;
2793
+ this.components = null;
2794
+ this.canvas = null;
2795
+ this._renderer = null;
2796
+ this.input = null;
2797
+ this._viewport = null;
2798
+ this._camera = null;
2799
+ }
2800
+ }
2801
+
2802
+ export {Scene};