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

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