csyjk 1.1.1 → 1.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (323) hide show
  1. package/.babelrc +7 -0
  2. package/.idea/modules.xml +8 -0
  3. package/.idea/xx.iml +12 -0
  4. package/dist/app.js +43 -0
  5. package/{index.html → dist/index.html} +0 -0
  6. package/{style.css → dist/style.css} +1 -1
  7. package/package.json +40 -5
  8. package/public/gltf.js +2241 -0
  9. package/public/index.html +10 -0
  10. package/src/index.js +3 -0
  11. package/src/lib/gltf/assets/check.jpg +0 -0
  12. package/src/lib/gltf/assets/iconfont/iconfont.css +358 -0
  13. package/src/lib/gltf/assets/iconfont/iconfont.eot +0 -0
  14. package/src/lib/gltf/assets/iconfont/iconfont.js +1 -0
  15. package/src/lib/gltf/assets/iconfont/iconfont.json +604 -0
  16. package/src/lib/gltf/assets/iconfont/iconfont.svg +189 -0
  17. package/src/lib/gltf/assets/iconfont/iconfont.ttf +0 -0
  18. package/src/lib/gltf/assets/iconfont/iconfont.woff +0 -0
  19. package/src/lib/gltf/assets/iconfont/iconfont.woff2 +0 -0
  20. package/src/lib/gltf/assets/yjkkit-sdk/index.js +0 -0
  21. package/src/lib/gltf/assets/yjkkit-sdk/package.json +15 -0
  22. package/src/lib/gltf/assets/yjkkit-sdk/src/extras/ContextMenu/ContextMenu.js +863 -0
  23. package/src/lib/gltf/assets/yjkkit-sdk/src/extras/ContextMenu/index.js +1 -0
  24. package/src/lib/gltf/assets/yjkkit-sdk/src/extras/index.js +1 -0
  25. package/src/lib/gltf/assets/yjkkit-sdk/src/index.js +3 -0
  26. package/src/lib/gltf/assets/yjkkit-sdk/src/plugins/AngleMeasurementsPlugin/AngleMeasurement.js +462 -0
  27. package/src/lib/gltf/assets/yjkkit-sdk/src/plugins/AngleMeasurementsPlugin/AngleMeasurementsControl.js +279 -0
  28. package/src/lib/gltf/assets/yjkkit-sdk/src/plugins/AngleMeasurementsPlugin/AngleMeasurementsPlugin.js +262 -0
  29. package/src/lib/gltf/assets/yjkkit-sdk/src/plugins/AngleMeasurementsPlugin/index.js +1 -0
  30. package/src/lib/gltf/assets/yjkkit-sdk/src/plugins/AnnotationsPlugin/Annotation.js +362 -0
  31. package/src/lib/gltf/assets/yjkkit-sdk/src/plugins/AnnotationsPlugin/AnnotationsPlugin.js +575 -0
  32. package/src/lib/gltf/assets/yjkkit-sdk/src/plugins/AnnotationsPlugin/index.js +1 -0
  33. package/src/lib/gltf/assets/yjkkit-sdk/src/plugins/AxisGizmoPlugin/AxisGizmoPlugin.js +333 -0
  34. package/src/lib/gltf/assets/yjkkit-sdk/src/plugins/AxisGizmoPlugin/index.js +1 -0
  35. package/src/lib/gltf/assets/yjkkit-sdk/src/plugins/BCFViewpointsPlugin/BCFViewpointsPlugin.js +777 -0
  36. package/src/lib/gltf/assets/yjkkit-sdk/src/plugins/BCFViewpointsPlugin/index.js +1 -0
  37. package/src/lib/gltf/assets/yjkkit-sdk/src/plugins/DistanceMeasurementsPlugin/DistanceMeasurement.js +525 -0
  38. package/src/lib/gltf/assets/yjkkit-sdk/src/plugins/DistanceMeasurementsPlugin/DistanceMeasurementsControl.js +242 -0
  39. package/src/lib/gltf/assets/yjkkit-sdk/src/plugins/DistanceMeasurementsPlugin/DistanceMeasurementsPlugin.js +297 -0
  40. package/src/lib/gltf/assets/yjkkit-sdk/src/plugins/DistanceMeasurementsPlugin/index.js +1 -0
  41. package/src/lib/gltf/assets/yjkkit-sdk/src/plugins/FastNavPlugin/FastNavPlugin.js +345 -0
  42. package/src/lib/gltf/assets/yjkkit-sdk/src/plugins/FastNavPlugin/index.js +1 -0
  43. package/src/lib/gltf/assets/yjkkit-sdk/src/plugins/GLTFLoaderPlugin/GLTFDefaultDataSource.js +122 -0
  44. package/src/lib/gltf/assets/yjkkit-sdk/src/plugins/GLTFLoaderPlugin/GLTFLoaderPlugin.js +462 -0
  45. package/src/lib/gltf/assets/yjkkit-sdk/src/plugins/GLTFLoaderPlugin/GLTFPerformanceModelLoader.js +508 -0
  46. package/src/lib/gltf/assets/yjkkit-sdk/src/plugins/GLTFLoaderPlugin/GLTFSceneGraphLoader.js +922 -0
  47. package/src/lib/gltf/assets/yjkkit-sdk/src/plugins/GLTFLoaderPlugin/index.js +2 -0
  48. package/src/lib/gltf/assets/yjkkit-sdk/src/plugins/NavCubePlugin/CubeTextureCanvas.js +273 -0
  49. package/src/lib/gltf/assets/yjkkit-sdk/src/plugins/NavCubePlugin/NavCubePlugin.js +687 -0
  50. package/src/lib/gltf/assets/yjkkit-sdk/src/plugins/NavCubePlugin/index.js +1 -0
  51. package/src/lib/gltf/assets/yjkkit-sdk/src/plugins/OBJLoaderPlugin/OBJLoaderPlugin.js +145 -0
  52. package/src/lib/gltf/assets/yjkkit-sdk/src/plugins/OBJLoaderPlugin/OBJSceneGraphLoader.js +777 -0
  53. package/src/lib/gltf/assets/yjkkit-sdk/src/plugins/OBJLoaderPlugin/index.js +1 -0
  54. package/src/lib/gltf/assets/yjkkit-sdk/src/plugins/STLLoaderPlugin/STLDefaultDataSource.js +33 -0
  55. package/src/lib/gltf/assets/yjkkit-sdk/src/plugins/STLLoaderPlugin/STLLoaderPlugin.js +273 -0
  56. package/src/lib/gltf/assets/yjkkit-sdk/src/plugins/STLLoaderPlugin/STLSceneGraphLoader.js +313 -0
  57. package/src/lib/gltf/assets/yjkkit-sdk/src/plugins/STLLoaderPlugin/index.js +2 -0
  58. package/src/lib/gltf/assets/yjkkit-sdk/src/plugins/SectionPlanesPlugin/Control.js +1328 -0
  59. package/src/lib/gltf/assets/yjkkit-sdk/src/plugins/SectionPlanesPlugin/Overview.js +249 -0
  60. package/src/lib/gltf/assets/yjkkit-sdk/src/plugins/SectionPlanesPlugin/Plane.js +169 -0
  61. package/src/lib/gltf/assets/yjkkit-sdk/src/plugins/SectionPlanesPlugin/SectionPlanesPlugin.js +403 -0
  62. package/src/lib/gltf/assets/yjkkit-sdk/src/plugins/SectionPlanesPlugin/index.js +1 -0
  63. package/src/lib/gltf/assets/yjkkit-sdk/src/plugins/SkyboxesPlugin/SkyboxesPlugin.js +134 -0
  64. package/src/lib/gltf/assets/yjkkit-sdk/src/plugins/SkyboxesPlugin/index.js +1 -0
  65. package/src/lib/gltf/assets/yjkkit-sdk/src/plugins/StoreyViewsPlugin/IFCStoreyPlanObjectStates.js +77 -0
  66. package/src/lib/gltf/assets/yjkkit-sdk/src/plugins/StoreyViewsPlugin/Storey.js +61 -0
  67. package/src/lib/gltf/assets/yjkkit-sdk/src/plugins/StoreyViewsPlugin/StoreyMap.js +57 -0
  68. package/src/lib/gltf/assets/yjkkit-sdk/src/plugins/StoreyViewsPlugin/StoreyViewsPlugin.js +822 -0
  69. package/src/lib/gltf/assets/yjkkit-sdk/src/plugins/StoreyViewsPlugin/index.js +1 -0
  70. package/src/lib/gltf/assets/yjkkit-sdk/src/plugins/TreeViewPlugin/ModelTreeView.js +888 -0
  71. package/src/lib/gltf/assets/yjkkit-sdk/src/plugins/TreeViewPlugin/TreeViewNode.js +88 -0
  72. package/src/lib/gltf/assets/yjkkit-sdk/src/plugins/TreeViewPlugin/TreeViewPlugin.js +624 -0
  73. package/src/lib/gltf/assets/yjkkit-sdk/src/plugins/TreeViewPlugin/index.js +1 -0
  74. package/src/lib/gltf/assets/yjkkit-sdk/src/plugins/TreeViewPlugin/modelValidation.js +87 -0
  75. package/src/lib/gltf/assets/yjkkit-sdk/src/plugins/ViewCullPlugin/ViewCullPlugin.js +295 -0
  76. package/src/lib/gltf/assets/yjkkit-sdk/src/plugins/ViewCullPlugin/index.js +1 -0
  77. package/src/lib/gltf/assets/yjkkit-sdk/src/plugins/XKTLoaderPlugin/XKTDefaultDataSource.js +78 -0
  78. package/src/lib/gltf/assets/yjkkit-sdk/src/plugins/XKTLoaderPlugin/XKTLoaderPlugin.js +847 -0
  79. package/src/lib/gltf/assets/yjkkit-sdk/src/plugins/XKTLoaderPlugin/index.js +2 -0
  80. package/src/lib/gltf/assets/yjkkit-sdk/src/plugins/XKTLoaderPlugin/parsers/ParserV1.js +167 -0
  81. package/src/lib/gltf/assets/yjkkit-sdk/src/plugins/XKTLoaderPlugin/parsers/ParserV2.js +228 -0
  82. package/src/lib/gltf/assets/yjkkit-sdk/src/plugins/XKTLoaderPlugin/parsers/ParserV3.js +220 -0
  83. package/src/lib/gltf/assets/yjkkit-sdk/src/plugins/XKTLoaderPlugin/parsers/ParserV4.js +279 -0
  84. package/src/lib/gltf/assets/yjkkit-sdk/src/plugins/XKTLoaderPlugin/parsers/ParserV5.js +244 -0
  85. package/src/lib/gltf/assets/yjkkit-sdk/src/plugins/XKTLoaderPlugin/parsers/ParserV6.js +301 -0
  86. package/src/lib/gltf/assets/yjkkit-sdk/src/plugins/XKTLoaderPlugin/parsers/ParserV7.js +426 -0
  87. package/src/lib/gltf/assets/yjkkit-sdk/src/plugins/XKTLoaderPlugin/parsers/ParserV8.js +479 -0
  88. package/src/lib/gltf/assets/yjkkit-sdk/src/plugins/XKTLoaderPlugin/parsers/lib/pako.js +6818 -0
  89. package/src/lib/gltf/assets/yjkkit-sdk/src/plugins/XML3DLoaderPlugin/XML3DLoaderPlugin.js +238 -0
  90. package/src/lib/gltf/assets/yjkkit-sdk/src/plugins/XML3DLoaderPlugin/XML3DSceneGraphLoader.js +1279 -0
  91. package/src/lib/gltf/assets/yjkkit-sdk/src/plugins/XML3DLoaderPlugin/index.js +1 -0
  92. package/src/lib/gltf/assets/yjkkit-sdk/src/plugins/XML3DLoaderPlugin/zipjs/.jshintrc +11 -0
  93. package/src/lib/gltf/assets/yjkkit-sdk/src/plugins/XML3DLoaderPlugin/zipjs/deflate.js +2060 -0
  94. package/src/lib/gltf/assets/yjkkit-sdk/src/plugins/XML3DLoaderPlugin/zipjs/inflate.js +2155 -0
  95. package/src/lib/gltf/assets/yjkkit-sdk/src/plugins/XML3DLoaderPlugin/zipjs/mime-types.js +1002 -0
  96. package/src/lib/gltf/assets/yjkkit-sdk/src/plugins/XML3DLoaderPlugin/zipjs/pako/codecs.js +64 -0
  97. package/src/lib/gltf/assets/yjkkit-sdk/src/plugins/XML3DLoaderPlugin/zipjs/z-worker.js +153 -0
  98. package/src/lib/gltf/assets/yjkkit-sdk/src/plugins/XML3DLoaderPlugin/zipjs/zip-ext.js +267 -0
  99. package/src/lib/gltf/assets/yjkkit-sdk/src/plugins/XML3DLoaderPlugin/zipjs/zip-fs.js +553 -0
  100. package/src/lib/gltf/assets/yjkkit-sdk/src/plugins/XML3DLoaderPlugin/zipjs/zip.js +991 -0
  101. package/src/lib/gltf/assets/yjkkit-sdk/src/plugins/XML3DLoaderPlugin/zipjs/zlib-asm/codecs.js +49 -0
  102. package/src/lib/gltf/assets/yjkkit-sdk/src/plugins/index.js +17 -0
  103. package/src/lib/gltf/assets/yjkkit-sdk/src/plugins/lib/culling/ObjectCullStates.js +205 -0
  104. package/src/lib/gltf/assets/yjkkit-sdk/src/plugins/lib/html/Dot.js +78 -0
  105. package/src/lib/gltf/assets/yjkkit-sdk/src/plugins/lib/html/Label.js +97 -0
  106. package/src/lib/gltf/assets/yjkkit-sdk/src/plugins/lib/html/Wire.js +95 -0
  107. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/Plugin.js +112 -0
  108. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/Viewer.js +372 -0
  109. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/index.js +3 -0
  110. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/metadata/IFCObjectDefaultColors.js +162 -0
  111. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/metadata/IFCObjectDefaults.js +39 -0
  112. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/metadata/MetaModel.js +145 -0
  113. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/metadata/MetaObject.js +215 -0
  114. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/metadata/MetaScene.js +311 -0
  115. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/CameraControl/CameraControl.js +1669 -0
  116. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/CameraControl/cc.js +0 -0
  117. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/CameraControl/lib/CameraUpdater.js +312 -0
  118. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/CameraControl/lib/controllers/PanController.js +112 -0
  119. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/CameraControl/lib/controllers/PickController.js +193 -0
  120. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/CameraControl/lib/controllers/PivotController.js +289 -0
  121. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/CameraControl/lib/cu.js +0 -0
  122. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/CameraControl/lib/handlers/KeyboardAxisViewHandler.js +122 -0
  123. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/CameraControl/lib/handlers/KeyboardPanRotateDollyHandler.js +186 -0
  124. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/CameraControl/lib/handlers/MouseMiscHandler.js +68 -0
  125. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/CameraControl/lib/handlers/MousePanRotateDollyHandler.js +439 -0
  126. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/CameraControl/lib/handlers/MousePickHandler.js +361 -0
  127. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/CameraControl/lib/handlers/TouchPanRotateAndDollyHandler.js +258 -0
  128. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/CameraControl/lib/handlers/TouchPickHandler.js +197 -0
  129. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/CameraControl/lib/handlers/mouspan.js +498 -0
  130. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/Component.js +908 -0
  131. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/Entity.js +475 -0
  132. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/ImagePlane/ImagePlane.js +570 -0
  133. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/ImagePlane/index.js +1 -0
  134. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/PerformanceModel/PerformanceModel.js +2623 -0
  135. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/PerformanceModel/index.js +1 -0
  136. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/PerformanceModel/lib/ENTITY_FLAGS.js +21 -0
  137. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/PerformanceModel/lib/PerformanceMesh.js +262 -0
  138. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/PerformanceModel/lib/PerformanceNode.js +697 -0
  139. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/PerformanceModel/lib/RENDER_PASSES.js +34 -0
  140. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/PerformanceModel/lib/ScratchMemory.js +63 -0
  141. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/PerformanceModel/lib/compression.js +183 -0
  142. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/PerformanceModel/lib/layers/linesBatching/LinesBatchingBuffer.js +33 -0
  143. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/PerformanceModel/lib/layers/linesBatching/LinesBatchingLayer.js +736 -0
  144. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/PerformanceModel/lib/layers/linesBatching/LinesBatchingRenderers.js +68 -0
  145. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/PerformanceModel/lib/layers/linesBatching/renderers/LinesBatchingColorRenderer.js +295 -0
  146. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/PerformanceModel/lib/layers/linesBatching/renderers/LinesBatchingSilhouetteRenderer.js +327 -0
  147. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/PerformanceModel/lib/layers/linesInstancing/LinesInstancingLayer.js +698 -0
  148. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/PerformanceModel/lib/layers/linesInstancing/LinesInstancingRenderers.js +68 -0
  149. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/PerformanceModel/lib/layers/linesInstancing/renderers/LinesInstancingColorRenderer.js +364 -0
  150. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/PerformanceModel/lib/layers/linesInstancing/renderers/LinesInstancingSilhouetteRenderer.js +356 -0
  151. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/PerformanceModel/lib/layers/pointsBatching/PointsBatchingBuffer.js +33 -0
  152. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/PerformanceModel/lib/layers/pointsBatching/PointsBatchingLayer.js +776 -0
  153. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/PerformanceModel/lib/layers/pointsBatching/PointsBatchingRenderers.js +113 -0
  154. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/PerformanceModel/lib/layers/pointsBatching/renderers/PointsBatchingColorRenderer.js +340 -0
  155. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/PerformanceModel/lib/layers/pointsBatching/renderers/PointsBatchingOcclusionRenderer.js +312 -0
  156. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/PerformanceModel/lib/layers/pointsBatching/renderers/PointsBatchingPickDepthRenderer.js +343 -0
  157. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/PerformanceModel/lib/layers/pointsBatching/renderers/PointsBatchingPickMeshRenderer.js +331 -0
  158. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/PerformanceModel/lib/layers/pointsBatching/renderers/PointsBatchingShadowRenderer.js +242 -0
  159. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/PerformanceModel/lib/layers/pointsBatching/renderers/PointsBatchingSilhouetteRenderer.js +348 -0
  160. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/PerformanceModel/lib/layers/pointsInstancing/PointsInstancingLayer.js +737 -0
  161. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/PerformanceModel/lib/layers/pointsInstancing/PointsInstancingRenderers.js +143 -0
  162. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/PerformanceModel/lib/layers/pointsInstancing/renderers/PointsInstancingColorRenderer.js +373 -0
  163. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/PerformanceModel/lib/layers/pointsInstancing/renderers/PointsInstancingDepthRenderer.js +366 -0
  164. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/PerformanceModel/lib/layers/pointsInstancing/renderers/PointsInstancingOcclusionRenderer.js +370 -0
  165. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/PerformanceModel/lib/layers/pointsInstancing/renderers/PointsInstancingPickDepthRenderer.js +386 -0
  166. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/PerformanceModel/lib/layers/pointsInstancing/renderers/PointsInstancingPickMeshRenderer.js +376 -0
  167. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/PerformanceModel/lib/layers/pointsInstancing/renderers/PointsInstancingShadowRenderer.js +293 -0
  168. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/PerformanceModel/lib/layers/pointsInstancing/renderers/PointsInstancingSilhouetteRenderer.js +382 -0
  169. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/PerformanceModel/lib/layers/trianglesBatching/TrianglesBatchingBuffer.js +37 -0
  170. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/PerformanceModel/lib/layers/trianglesBatching/TrianglesBatchingLayer.js +1017 -0
  171. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/PerformanceModel/lib/layers/trianglesBatching/TrianglesBatchingRenderers.js +246 -0
  172. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/PerformanceModel/lib/layers/trianglesBatching/renderers/TrianglesBatchingColorQualityRenderer.js +809 -0
  173. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/PerformanceModel/lib/layers/trianglesBatching/renderers/TrianglesBatchingColorRenderer.js +504 -0
  174. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/PerformanceModel/lib/layers/trianglesBatching/renderers/TrianglesBatchingDepthRenderer.js +297 -0
  175. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/PerformanceModel/lib/layers/trianglesBatching/renderers/TrianglesBatchingEdgesColorRenderer.js +300 -0
  176. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/PerformanceModel/lib/layers/trianglesBatching/renderers/TrianglesBatchingEdgesRenderer.js +322 -0
  177. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/PerformanceModel/lib/layers/trianglesBatching/renderers/TrianglesBatchingNormalsRenderer.js +311 -0
  178. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/PerformanceModel/lib/layers/trianglesBatching/renderers/TrianglesBatchingOcclusionRenderer.js +291 -0
  179. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/PerformanceModel/lib/layers/trianglesBatching/renderers/TrianglesBatchingPickDepthRenderer.js +319 -0
  180. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/PerformanceModel/lib/layers/trianglesBatching/renderers/TrianglesBatchingPickMeshRenderer.js +305 -0
  181. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/PerformanceModel/lib/layers/trianglesBatching/renderers/TrianglesBatchingPickNormalsRenderer.js +300 -0
  182. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/PerformanceModel/lib/layers/trianglesBatching/renderers/TrianglesBatchingShadowRenderer.js +242 -0
  183. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/PerformanceModel/lib/layers/trianglesBatching/renderers/TrianglesBatchingSilhouetteRenderer.js +323 -0
  184. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/PerformanceModel/lib/layers/trianglesInstancing/TrianglesInstancingLayer.js +969 -0
  185. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/PerformanceModel/lib/layers/trianglesInstancing/TrianglesInstancingRenderers.js +246 -0
  186. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/PerformanceModel/lib/layers/trianglesInstancing/renderers/TrianglesInstancingColorQualityRenderer.js +859 -0
  187. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/PerformanceModel/lib/layers/trianglesInstancing/renderers/TrianglesInstancingColorRenderer.js +557 -0
  188. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/PerformanceModel/lib/layers/trianglesInstancing/renderers/TrianglesInstancingDepthRenderer.js +341 -0
  189. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/PerformanceModel/lib/layers/trianglesInstancing/renderers/TrianglesInstancingEdgesColorRenderer.js +338 -0
  190. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/PerformanceModel/lib/layers/trianglesInstancing/renderers/TrianglesInstancingEdgesRenderer.js +356 -0
  191. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/PerformanceModel/lib/layers/trianglesInstancing/renderers/TrianglesInstancingNormalsRenderer.js +354 -0
  192. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/PerformanceModel/lib/layers/trianglesInstancing/renderers/TrianglesInstancingOcclusionRenderer.js +329 -0
  193. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/PerformanceModel/lib/layers/trianglesInstancing/renderers/TrianglesInstancingPickDepthRenderer.js +358 -0
  194. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/PerformanceModel/lib/layers/trianglesInstancing/renderers/TrianglesInstancingPickMeshRenderer.js +349 -0
  195. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/PerformanceModel/lib/layers/trianglesInstancing/renderers/TrianglesInstancingPickNormalsRenderer.js +363 -0
  196. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/PerformanceModel/lib/layers/trianglesInstancing/renderers/TrianglesInstancingShadowRenderer.js +284 -0
  197. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/PerformanceModel/lib/layers/trianglesInstancing/renderers/TrianglesInstancingSilhouetteRenderer.js +354 -0
  198. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/camera/Camera.js +880 -0
  199. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/camera/CameraFlightAnimation.js +669 -0
  200. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/camera/CameraPath.js +194 -0
  201. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/camera/CameraPathAnimation.js +326 -0
  202. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/camera/CustomProjection.js +149 -0
  203. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/camera/Frustum.js +316 -0
  204. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/camera/Ortho.js +286 -0
  205. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/camera/Perspective.js +302 -0
  206. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/camera/index.js +2 -0
  207. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/canvas/Canvas.js +464 -0
  208. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/canvas/Spinner.js +323 -0
  209. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/core.js +234 -0
  210. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/geometry/Geometry.js +33 -0
  211. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/geometry/ReadableGeometry.js +689 -0
  212. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/geometry/VBOGeometry.js +327 -0
  213. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/geometry/builders/buildBoxGeometry.js +238 -0
  214. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/geometry/builders/buildBoxLinesGeometry.js +106 -0
  215. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/geometry/builders/buildCylinderGeometry.js +271 -0
  216. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/geometry/builders/buildGridGeometry.js +102 -0
  217. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/geometry/builders/buildPlaneGeometry.js +168 -0
  218. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/geometry/builders/buildSphereGeometry.js +161 -0
  219. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/geometry/builders/buildTorusGeometry.js +172 -0
  220. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/geometry/builders/buildVectorTextGeometry.js +1721 -0
  221. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/geometry/builders/index.js +8 -0
  222. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/geometry/index.js +4 -0
  223. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/geometry/loaders/index.js +2 -0
  224. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/geometry/loaders/load3DSGeometry.js +103 -0
  225. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/geometry/loaders/loadOBJGeometry.js +130 -0
  226. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/index.js +18 -0
  227. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/input/Input.js +1475 -0
  228. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/libs/canvas2image.js +218 -0
  229. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/libs/k3d.js +1032 -0
  230. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/lights/AmbientLight.js +175 -0
  231. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/lights/CubeTexture.js +156 -0
  232. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/lights/DirLight.js +314 -0
  233. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/lights/Light.js +29 -0
  234. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/lights/LightMap.js +77 -0
  235. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/lights/PointLight.js +395 -0
  236. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/lights/ReflectionMap.js +79 -0
  237. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/lights/Shadow.js +138 -0
  238. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/lights/index.js +5 -0
  239. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/marker/Marker.js +382 -0
  240. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/marker/index.js +1 -0
  241. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/materials/EdgeMaterial.js +359 -0
  242. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/materials/EmphasisMaterial.js +577 -0
  243. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/materials/Fresnel.js +222 -0
  244. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/materials/LambertMaterial.js +378 -0
  245. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/materials/LinesMaterial.js +169 -0
  246. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/materials/Material.js +39 -0
  247. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/materials/MetallicMaterial.js +820 -0
  248. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/materials/PhongMaterial.js +860 -0
  249. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/materials/PointsMaterial.js +320 -0
  250. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/materials/SpecularMaterial.js +807 -0
  251. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/materials/Texture.js +522 -0
  252. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/materials/index.js +8 -0
  253. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/math/Frustum.js +118 -0
  254. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/math/buildEdgeIndices.js +162 -0
  255. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/math/geometryCompressionUtils.js +353 -0
  256. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/math/index.js +1 -0
  257. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/math/math.js +5302 -0
  258. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/math/rtcCoords.js +132 -0
  259. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/mementos/CameraMemento.js +200 -0
  260. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/mementos/ModelMemento.js +272 -0
  261. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/mementos/ObjectsMemento.js +259 -0
  262. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/mementos/index.js +3 -0
  263. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/mesh/Mesh.js +2165 -0
  264. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/mesh/draw/DrawRenderer.js +978 -0
  265. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/mesh/draw/DrawShaderSource.js +1566 -0
  266. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/mesh/emphasis/EmphasisEdgesRenderer.js +249 -0
  267. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/mesh/emphasis/EmphasisEdgesShaderSource.js +163 -0
  268. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/mesh/emphasis/EmphasisFillRenderer.js +276 -0
  269. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/mesh/emphasis/EmphasisFillShaderSource.js +269 -0
  270. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/mesh/index.js +1 -0
  271. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/mesh/occlusion/OcclusionRenderer.js +207 -0
  272. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/mesh/occlusion/OcclusionShaderSource.js +156 -0
  273. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/mesh/pick/PickMeshRenderer.js +210 -0
  274. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/mesh/pick/PickMeshShaderSource.js +146 -0
  275. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/mesh/pick/PickTriangleRenderer.js +186 -0
  276. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/mesh/pick/PickTriangleShaderSource.js +120 -0
  277. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/mesh/shadow/ShadowRenderer.js +214 -0
  278. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/mesh/shadow/ShadowShaderSource.js +96 -0
  279. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/metriqs/Metriqs.js +259 -0
  280. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/nodes/Node.js +1356 -0
  281. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/nodes/index.js +1 -0
  282. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/paths/CubicBezierCurve.js +194 -0
  283. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/paths/Curve.js +183 -0
  284. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/paths/Path.js +239 -0
  285. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/paths/QuadraticBezierCurve.js +161 -0
  286. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/paths/SplineCurve.js +133 -0
  287. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/paths/index.js +5 -0
  288. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/postfx/SAO.js +547 -0
  289. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/scene/Scene.js +2481 -0
  290. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/sectionPlane/SectionPlane.js +194 -0
  291. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/sectionPlane/index.js +1 -0
  292. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/skybox/Skybox.js +119 -0
  293. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/skybox/index.js +1 -0
  294. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/stats.js +45 -0
  295. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/utils/Map.js +45 -0
  296. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/utils/Queue.js +56 -0
  297. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/utils/index.js +2 -0
  298. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/utils.js +452 -0
  299. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/viewport/Viewport.js +212 -0
  300. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/webgl/ArrayBuf.js +121 -0
  301. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/webgl/Attribute.js +23 -0
  302. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/webgl/Drawable.js +270 -0
  303. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/webgl/FrameContext.js +259 -0
  304. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/webgl/PickResult.js +317 -0
  305. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/webgl/Pickable.js +69 -0
  306. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/webgl/Program.js +179 -0
  307. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/webgl/RenderBuffer.js +315 -0
  308. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/webgl/RenderFlags.js +203 -0
  309. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/webgl/RenderState.js +40 -0
  310. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/webgl/Renderer.js +1300 -0
  311. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/webgl/Sampler.js +18 -0
  312. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/webgl/Shader.js +49 -0
  313. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/webgl/Texture2D.js +217 -0
  314. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/webgl/occlusion/OcclusionLayer.js +214 -0
  315. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/webgl/occlusion/OcclusionTester.js +432 -0
  316. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/webgl/sao/SAODepthLimitedBlurRenderer.js +326 -0
  317. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/webgl/sao/SAOOcclusionRenderer.js +375 -0
  318. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/webgl/webglEnums.js +61 -0
  319. package/src/lib/gltf/assets/yjkkit-sdk/src/viewer/scene/webglInfo.js +48 -0
  320. package/src/lib/gltf/gltf.css +392 -0
  321. package/src/lib/gltf/gltf.js +2241 -0
  322. package/webpack.config.js +70 -0
  323. package/app.js +0 -43
@@ -0,0 +1,2623 @@
1
+ import { Component } from "../Component.js";
2
+ import { math } from "../math/math.js";
3
+ import { buildEdgeIndices } from '../math/buildEdgeIndices.js';
4
+ import { WEBGL_INFO } from '../webglInfo.js';
5
+ import { PerformanceMesh } from './lib/PerformanceMesh.js';
6
+ import { PerformanceNode } from './lib/PerformanceNode.js';
7
+ import { getScratchMemory, putScratchMemory } from "./lib/ScratchMemory.js";
8
+ import { TrianglesBatchingLayer } from './lib/layers/trianglesBatching/TrianglesBatchingLayer.js';
9
+ import { TrianglesInstancingLayer } from './lib/layers/trianglesInstancing/TrianglesInstancingLayer.js';
10
+ import { LinesBatchingLayer } from './lib/layers/linesBatching/LinesBatchingLayer.js';
11
+ import { LinesInstancingLayer } from './lib/layers/linesInstancing/LinesInstancingLayer.js';
12
+
13
+ import { PointsBatchingLayer } from './lib/layers/pointsBatching/PointsBatchingLayer.js';
14
+ import { PointsInstancingLayer } from './lib/layers/pointsInstancing/PointsInstancingLayer.js';
15
+
16
+
17
+ import { ENTITY_FLAGS } from './lib/ENTITY_FLAGS.js';
18
+ import { utils } from "../utils.js";
19
+ import { RenderFlags } from "../webgl/RenderFlags.js";
20
+
21
+ const instancedArraysSupported = WEBGL_INFO.SUPPORTED_EXTENSIONS["ANGLE_instanced_arrays"];
22
+
23
+ const tempMat4 = math.mat4();
24
+
25
+ const defaultScale = math.vec3([1, 1, 1]);
26
+ const defaultPosition = math.vec3([0, 0, 0]);
27
+ const defaultRotation = math.vec3([0, 0, 0]);
28
+ const defaultQuaternion = math.identityQuaternion();
29
+
30
+ /**
31
+ * @desc A high-performance model representation for efficient rendering and low memory usage.
32
+ *
33
+ * # Examples
34
+ *
35
+ * * [PerformanceModel using geometry batching](http://yjkkit.github.io/yjkkit-sdk/examples/#sceneRepresentation_PerformanceModel_batching)
36
+ * * [PerformanceModel using geometry batching and RTC coordinates](http://yjkkit.github.io/yjkkit-sdk/examples/#sceneRepresentation_PerformanceModel_batching_rtcCenter)
37
+ * * [PerformanceModel using geometry instancing](http://yjkkit.github.io/yjkkit-sdk/examples/#sceneRepresentation_PerformanceModel_instancing)
38
+ * * [PerformanceModel using geometry instancing and RTC coordinates](http://yjkkit.github.io/yjkkit-sdk/examples/#sceneRepresentation_PerformanceModel_instancing_rtcCenter)
39
+ *
40
+ * # Overview
41
+ *
42
+ * While yjkkit's standard [scene graph](https://github.com/yjkkit/yjkkit-sdk/wiki/Scene-Graphs) is great for gizmos and medium-sized models, it doesn't scale up to millions of objects in terms of memory and rendering efficiency.
43
+ *
44
+ * For huge models, we have the ````PerformanceModel```` representation, which is optimized to pack large amounts of geometry into memory and render it efficiently using WebGL.
45
+ *
46
+ * ````PerformanceModel```` is the default model representation loaded by {@link GLTFLoaderPlugin}, {@link XKTLoaderPlugin} and {@link BIMServerLoaderPlugin}.
47
+ *
48
+ * In this tutorial you'll learn how to use ````PerformanceModel```` to create high-detail content programmatically. Ordinarily you'd be learning about ````PerformanceModel```` if you were writing your own model loader plugins.
49
+ *
50
+ * # Contents
51
+ *
52
+ * - [PerformanceModel](#performancemodel)
53
+ * - [GPU-Resident Geometry](#gpu-resident-geometry)
54
+ * - [Picking](#picking)
55
+ * - [Example 1: Geometry Instancing](#example-1--geometry-instancing)
56
+ * - [Finalizing a PerformanceModel](#finalizing-a-performancemodel)
57
+ * - [Finding Entities](#finding-entities)
58
+ * - [Example 2: Geometry Batching](#example-2--geometry-batching)
59
+ * - [Classifying with Metadata](#classifying-with-metadata)
60
+ * - [Querying Metadata](#querying-metadata)
61
+ * - [Metadata Structure](#metadata-structure)
62
+ * - [RTC Coordinates](#rtc-coordinates)
63
+ * - [Example 3: RTC Coordinates with Geometry Instancing](#example-2--rtc-coordinates-with-geometry-instancing)
64
+ * - [Example 4: RTC Coordinates with Geometry Batching](#example-2--rtc-coordinates-with-geometry-batching)
65
+ *
66
+ * ## PerformanceModel
67
+ *
68
+ * ````PerformanceModel```` uses two rendering techniques internally:
69
+ *
70
+ * 1. ***Geometry batching*** for unique geometries, combining those into a single WebGL geometry buffer, to render in one draw call, and
71
+ * 2. ***geometry instancing*** for geometries that are shared by multiple meshes, rendering all instances of each shared geometry in one draw call.
72
+ *
73
+ * <br>
74
+ * These techniques come with certain limitations:
75
+ *
76
+ * * Non-realistic rendering - while scene graphs can use yjkkit's full set of material workflows, ````PerformanceModel```` uses simple Lambertian shading without textures.
77
+ * * Static transforms - transforms within a ````PerformanceModel```` are static and cannot be dynamically translated, rotated and scaled the way {@link Node}s and {@link Mesh}es in scene graphs can.
78
+ * * Immutable model representation - while scene graph {@link Node}s and
79
+ * {@link Mesh}es can be dynamically plugged together, ````PerformanceModel```` is immutable,
80
+ * since it packs its geometries into buffers and instanced arrays.
81
+ *
82
+ * ````PerformanceModel````'s API allows us to exploit batching and instancing, while exposing its elements as
83
+ * abstract {@link Entity} types.
84
+ *
85
+ * {@link Entity} is the abstract base class for
86
+ * the various yjkkit components that represent models, objects, or anonymous visible elements. An Entity has a unique ID and can be
87
+ * individually shown, hidden, selected, highlighted, ghosted, culled, picked and clipped, and has its own World-space boundary.
88
+ *
89
+ * * A ````PerformanceModel```` is an {@link Entity} that represents a model.
90
+ * * A ````PerformanceModel```` represents each of its objects with an {@link Entity}.
91
+ * * Each {@link Entity} has one or more meshes that define its shape.
92
+ * * Each mesh has either its own unique geometry, or shares a geometry with other meshes.
93
+ *
94
+ * ## GPU-Resident Geometry
95
+ *
96
+ * For a low memory footprint, ````PerformanceModel```` stores its geometries in GPU memory only, compressed (quantized) as integers. Unfortunately, GPU-resident geometry is
97
+ * not readable by JavaScript.
98
+ *
99
+ *
100
+ * ## Example 1: Geometry Instancing
101
+ *
102
+ * In the example below, we'll use a ````PerformanceModel````
103
+ * to build a simple table model using geometry instancing.
104
+ *
105
+ * We'll start by adding a reusable box-shaped geometry to our ````PerformanceModel````.
106
+ *
107
+ * Then, for each object in our model we'll add an {@link Entity}
108
+ * that has a mesh that instances our box geometry, transforming and coloring the instance.
109
+ *
110
+ * [![](http://yjkkit.io/img/docs/sceneGraph.png)](https://yjkkit.github.io/yjkkit-sdk/examples/#sceneRepresentation_PerformanceModel_instancing)
111
+ *
112
+ * [[Run this example](https://yjkkit.github.io/yjkkit-sdk/examples/#sceneRepresentation_PerformanceModel_instancing)]
113
+ *
114
+ * ````javascript
115
+ * import {Viewer, PerformanceModel} from "yjkkit-sdk.es.js";
116
+ *
117
+ * const viewer = new Viewer({
118
+ * canvasId: "myCanvas",
119
+ * transparent: true
120
+ * });
121
+ *
122
+ * viewer.scene.camera.eye = [-21.80, 4.01, 6.56];
123
+ * viewer.scene.camera.look = [0, -5.75, 0];
124
+ * viewer.scene.camera.up = [0.37, 0.91, -0.11];
125
+ *
126
+ * // Build a PerformanceModel representing a table
127
+ * // with four legs, using geometry instancing
128
+ *
129
+ * const performanceModel = new PerformanceModel(viewer.scene, {
130
+ * id: "table",
131
+ * isModel: true, // <--- Registers PerformanceModel in viewer.scene.models
132
+ * position: [0, 0, 0],
133
+ * scale: [1, 1, 1],
134
+ * rotation: [0, 0, 0]
135
+ * });
136
+ *
137
+ * // Create a reusable geometry within the PerformanceModel
138
+ * // We'll instance this geometry by five meshes
139
+ *
140
+ * performanceModel.createGeometry({
141
+ *
142
+ * id: "myBoxGeometry",
143
+ *
144
+ * // The primitive type - allowed values are "points", "lines" and "triangles".
145
+ * // See the OpenGL/WebGL specification docs
146
+ * // for how the coordinate arrays are supposed to be laid out.
147
+ * primitive: "triangles",
148
+ *
149
+ * // The vertices - eight for our cube, each
150
+ * // one spanning three array elements for X,Y and Z
151
+ * positions: [
152
+ * 1, 1, 1, -1, 1, 1, -1, -1, 1, 1, -1, 1, // v0-v1-v2-v3 front
153
+ * 1, 1, 1, 1, -1, 1, 1, -1, -1, 1, 1, -1, // v0-v3-v4-v1 right
154
+ * 1, 1, 1, 1, 1, -1, -1, 1, -1, -1, 1, 1, // v0-v1-v6-v1 top
155
+ * -1, 1, 1, -1, 1, -1, -1, -1, -1, -1, -1, 1, // v1-v6-v7-v2 left
156
+ * -1, -1, -1, 1, -1, -1, 1, -1, 1, -1, -1, 1, // v7-v4-v3-v2 bottom
157
+ * 1, -1, -1, -1, -1, -1, -1, 1, -1, 1, 1, -1 // v4-v7-v6-v1 back
158
+ * ],
159
+ *
160
+ * // Normal vectors, one for each vertex
161
+ * normals: [
162
+ * 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, // v0-v1-v2-v3 front
163
+ * 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, // v0-v3-v4-v5 right
164
+ * 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, // v0-v5-v6-v1 top
165
+ * -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, // v1-v6-v7-v2 left
166
+ * 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, // v7-v4-v3-v2 bottom
167
+ * 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1 // v4-v7-v6-v5 back
168
+ * ],
169
+ *
170
+ * // Indices - these organise the positions and and normals
171
+ * // into geometric primitives in accordance with the "primitive" parameter,
172
+ * // in this case a set of three indices for each triangle.
173
+ * //
174
+ * // Note that each triangle is specified in counter-clockwise winding order.
175
+ * //
176
+ * indices: [
177
+ * 0, 1, 2, 0, 2, 3, // front
178
+ * 4, 5, 6, 4, 6, 7, // right
179
+ * 8, 9, 10, 8, 10, 11, // top
180
+ * 12, 13, 14, 12, 14, 15, // left
181
+ * 16, 17, 18, 16, 18, 19, // bottom
182
+ * 20, 21, 22, 20, 22, 23
183
+ * ]
184
+ * });
185
+ *
186
+ * // Red table leg
187
+ *
188
+ * performanceModel.createMesh({
189
+ * id: "redLegMesh",
190
+ * geometryId: "myBoxGeometry",
191
+ * position: [-4, -6, -4],
192
+ * scale: [1, 3, 1],
193
+ * rotation: [0, 0, 0],
194
+ * color: [1, 0.3, 0.3]
195
+ * });
196
+ *
197
+ * performanceModel.createEntity({
198
+ * id: "redLeg",
199
+ * meshIds: ["redLegMesh"],
200
+ * isObject: true // <---- Registers Entity by ID on viewer.scene.objects
201
+ * });
202
+ *
203
+ * // Green table leg
204
+ *
205
+ * performanceModel.createMesh({
206
+ * id: "greenLegMesh",
207
+ * geometryId: "myBoxGeometry",
208
+ * position: [4, -6, -4],
209
+ * scale: [1, 3, 1],
210
+ * rotation: [0, 0, 0],
211
+ * color: [0.3, 1.0, 0.3]
212
+ * });
213
+ *
214
+ * performanceModel.createEntity({
215
+ * id: "greenLeg",
216
+ * meshIds: ["greenLegMesh"],
217
+ * isObject: true // <---- Registers Entity by ID on viewer.scene.objects
218
+ * });
219
+ *
220
+ * // Blue table leg
221
+ *
222
+ * performanceModel.createMesh({
223
+ * id: "blueLegMesh",
224
+ * geometryId: "myBoxGeometry",
225
+ * position: [4, -6, 4],
226
+ * scale: [1, 3, 1],
227
+ * rotation: [0, 0, 0],
228
+ * color: [0.3, 0.3, 1.0]
229
+ * });
230
+ *
231
+ * performanceModel.createEntity({
232
+ * id: "blueLeg",
233
+ * meshIds: ["blueLegMesh"],
234
+ * isObject: true // <---- Registers Entity by ID on viewer.scene.objects
235
+ * });
236
+ *
237
+ * // Yellow table leg
238
+ *
239
+ * performanceModel.createMesh({
240
+ * id: "yellowLegMesh",
241
+ * geometryId: "myBoxGeometry",
242
+ * position: [-4, -6, 4],
243
+ * scale: [1, 3, 1],
244
+ * rotation: [0, 0, 0],
245
+ * color: [1.0, 1.0, 0.0]
246
+ * });
247
+ *
248
+ * performanceModel.createEntity({
249
+ * id: "yellowLeg",
250
+ * meshIds: ["yellowLegMesh"],
251
+ * isObject: true // <---- Registers Entity by ID on viewer.scene.objects
252
+ * });
253
+ *
254
+ * // Purple table top
255
+ *
256
+ * performanceModel.createMesh({
257
+ * id: "purpleTableTopMesh",
258
+ * geometryId: "myBoxGeometry",
259
+ * position: [0, -3, 0],
260
+ * scale: [6, 0.5, 6],
261
+ * rotation: [0, 0, 0],
262
+ * color: [1.0, 0.3, 1.0]
263
+ * });
264
+ *
265
+ * performanceModel.createEntity({
266
+ * id: "purpleTableTop",
267
+ * meshIds: ["purpleTableTopMesh"],
268
+ * isObject: true // <---- Registers Entity by ID on viewer.scene.objects
269
+ * });
270
+ * ````
271
+ *
272
+ * ## Finalizing a PerformanceModel
273
+ *
274
+ * Before we can view and interact with our ````PerformanceModel````, we need to **finalize** it. Internally, this causes the ````PerformanceModel```` to build the
275
+ * vertex buffer objects (VBOs) that support our geometry instances. When using geometry batching (see next example),
276
+ * this causes ````PerformanceModel```` to build the VBOs that combine the batched geometries. Note that you can do both instancing and
277
+ * batching within the same ````PerformanceModel````.
278
+ *
279
+ * Once finalized, we can't add anything more to our ````PerformanceModel````.
280
+ *
281
+ * ```` javascript
282
+ * performanceModel.finalize();
283
+ * ````
284
+ *
285
+ * ## Finding Entities
286
+ *
287
+ * As mentioned earlier, {@link Entity} is
288
+ * the abstract base class for components that represent models, objects, or just
289
+ * anonymous visible elements.
290
+ *
291
+ * Since we created configured our ````PerformanceModel```` with ````isModel: true````,
292
+ * we're able to find it as an Entity by ID in ````viewer.scene.models````. Likewise, since
293
+ * we configured each of its Entities with ````isObject: true````, we're able to
294
+ * find them in ````viewer.scene.objects````.
295
+ *
296
+ *
297
+ * ````javascript
298
+ * // Get the whole table model Entity
299
+ * const table = viewer.scene.models["table"];
300
+ *
301
+ * // Get some leg object Entities
302
+ * const redLeg = viewer.scene.objects["redLeg"];
303
+ * const greenLeg = viewer.scene.objects["greenLeg"];
304
+ * const blueLeg = viewer.scene.objects["blueLeg"];
305
+ * ````
306
+ *
307
+ * ## Example 2: Geometry Batching
308
+ *
309
+ * Let's once more use a ````PerformanceModel````
310
+ * to build the simple table model, this time exploiting geometry batching.
311
+ *
312
+ * [![](http://yjkkit.io/img/docs/sceneGraph.png)](https://yjkkit.github.io/yjkkit-sdk/examples/#sceneRepresentation_PerformanceModel_batching)
313
+ *
314
+ * * [[Run this example](https://yjkkit.github.io/yjkkit-sdk/examples/#sceneRepresentation_PerformanceModel_batching)]
315
+ *
316
+ * ````javascript
317
+ * import {Viewer, PerformanceModel} from "yjkkit-sdk.es.js";
318
+ *
319
+ * const viewer = new Viewer({
320
+ * canvasId: "myCanvas",
321
+ * transparent: true
322
+ * });
323
+ *
324
+ * viewer.scene.camera.eye = [-21.80, 4.01, 6.56];
325
+ * viewer.scene.camera.look = [0, -5.75, 0];
326
+ * viewer.scene.camera.up = [0.37, 0.91, -0.11];
327
+ *
328
+ * // Create a PerformanceModel representing a table with four legs, using geometry batching
329
+ * const performanceModel = new PerformanceModel(viewer.scene, {
330
+ * id: "table",
331
+ * isModel: true, // <--- Registers PerformanceModel in viewer.scene.models
332
+ * position: [0, 0, 0],
333
+ * scale: [1, 1, 1],
334
+ * rotation: [0, 0, 0]
335
+ * });
336
+ *
337
+ * // Red table leg
338
+ *
339
+ * performanceModel.createMesh({
340
+ * id: "redLegMesh",
341
+ *
342
+ * // Geometry arrays are same as for the earlier batching example
343
+ * primitive: "triangles",
344
+ * positions: [ 1, 1, 1, -1, 1, 1, -1, -1, 1, 1, -1, 1 ... ],
345
+ * normals: [ 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, ... ],
346
+ * indices: [ 0, 1, 2, 0, 2, 3, 4, 5, 6, 4, 6, 7, ... ],
347
+ * position: [-4, -6, -4],
348
+ * scale: [1, 3, 1],
349
+ * rotation: [0, 0, 0],
350
+ * color: [1, 0.3, 0.3]
351
+ * });
352
+ *
353
+ * performanceModel.createEntity({
354
+ * id: "redLeg",
355
+ * meshIds: ["redLegMesh"],
356
+ * isObject: true // <---- Registers Entity by ID on viewer.scene.objects
357
+ * });
358
+ *
359
+ * // Green table leg
360
+ *
361
+ * performanceModel.createMesh({
362
+ * id: "greenLegMesh",
363
+ * primitive: "triangles",
364
+ * primitive: "triangles",
365
+ * positions: [ 1, 1, 1, -1, 1, 1, -1, -1, 1, 1, -1, 1 ... ],
366
+ * normals: [ 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, ... ],
367
+ * indices: [ 0, 1, 2, 0, 2, 3, 4, 5, 6, 4, 6, 7, ... ],
368
+ * position: [4, -6, -4],
369
+ * scale: [1, 3, 1],
370
+ * rotation: [0, 0, 0],
371
+ * color: [0.3, 1.0, 0.3]
372
+ * });
373
+ *
374
+ * performanceModel.createEntity({
375
+ * id: "greenLeg",
376
+ * meshIds: ["greenLegMesh"],
377
+ * isObject: true // <---- Registers Entity by ID on viewer.scene.objects
378
+ * });
379
+ *
380
+ * // Blue table leg
381
+ *
382
+ * performanceModel.createMesh({
383
+ * id: "blueLegMesh",
384
+ * primitive: "triangles",
385
+ * positions: [ 1, 1, 1, -1, 1, 1, -1, -1, 1, 1, -1, 1 ... ],
386
+ * normals: [ 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, ... ],
387
+ * indices: [ 0, 1, 2, 0, 2, 3, 4, 5, 6, 4, 6, 7, ... ],
388
+ * position: [4, -6, 4],
389
+ * scale: [1, 3, 1],
390
+ * rotation: [0, 0, 0],
391
+ * color: [0.3, 0.3, 1.0]
392
+ * });
393
+ *
394
+ * performanceModel.createEntity({
395
+ * id: "blueLeg",
396
+ * meshIds: ["blueLegMesh"],
397
+ * isObject: true // <---- Registers Entity by ID on viewer.scene.objects
398
+ * });
399
+ *
400
+ * // Yellow table leg object
401
+ *
402
+ * performanceModel.createMesh({
403
+ * id: "yellowLegMesh",
404
+ * positions: [ 1, 1, 1, -1, 1, 1, -1, -1, 1, 1, -1, 1 ... ],
405
+ * normals: [ 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, ... ],
406
+ * indices: [ 0, 1, 2, 0, 2, 3, 4, 5, 6, 4, 6, 7, ... ],
407
+ * position: [-4, -6, 4],
408
+ * scale: [1, 3, 1],
409
+ * rotation: [0, 0, 0],
410
+ * color: [1.0, 1.0, 0.0]
411
+ * });
412
+ *
413
+ * performanceModel.createEntity({
414
+ * id: "yellowLeg",
415
+ * meshIds: ["yellowLegMesh"],
416
+ * isObject: true // <---- Registers Entity by ID on viewer.scene.objects
417
+ * });
418
+ *
419
+ * // Purple table top
420
+ *
421
+ * performanceModel.createMesh({
422
+ * id: "purpleTableTopMesh",
423
+ * positions: [ 1, 1, 1, -1, 1, 1, -1, -1, 1, 1, -1, 1 ... ],
424
+ * normals: [ 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, ... ],
425
+ * indices: [ 0, 1, 2, 0, 2, 3, 4, 5, 6, 4, 6, 7, ... ],
426
+ * position: [0, -3, 0],
427
+ * scale: [6, 0.5, 6],
428
+ * rotation: [0, 0, 0],
429
+ * color: [1.0, 0.3, 1.0]
430
+ * });
431
+ *
432
+ * performanceModel.createEntity({
433
+ * id: "purpleTableTop",
434
+ * meshIds: ["purpleTableTopMesh"],
435
+ * isObject: true // <---- Registers Entity by ID on viewer.scene.objects
436
+ * });
437
+ *
438
+ * // Finalize the PerformanceModel.
439
+ *
440
+ * performanceModel.finalize();
441
+ *
442
+ * // Find BigModelNodes by their model and object IDs
443
+ *
444
+ * // Get the whole table model
445
+ * const table = viewer.scene.models["table"];
446
+ *
447
+ * // Get some leg objects
448
+ * const redLeg = viewer.scene.objects["redLeg"];
449
+ * const greenLeg = viewer.scene.objects["greenLeg"];
450
+ * const blueLeg = viewer.scene.objects["blueLeg"];
451
+ * ````
452
+ *
453
+ * ## Classifying with Metadata
454
+ *
455
+ * In the previous examples, we used ````PerformanceModel```` to build
456
+ * two versions of the same table model, to demonstrate geometry batching and geometry instancing.
457
+ *
458
+ * We'll now classify our {@link Entity}s with metadata. This metadata
459
+ * will work the same for both our examples, since they create the exact same structure of {@link Entity}s
460
+ * to represent their models and objects. The abstract Entity type is, after all, intended to provide an abstract interface through which differently-implemented scene content can be accessed uniformly.
461
+ *
462
+ * To create the metadata, we'll create a {@link MetaModel} for our model,
463
+ * with a {@link MetaObject} for each of it's objects. The MetaModel and MetaObjects
464
+ * get the same IDs as the {@link Entity}s that represent their model and objects within our scene.
465
+ *
466
+ * ```` javascript
467
+ * const furnitureMetaModel = viewer.metaScene.createMetaModel("furniture", { // Creates a MetaModel in the MetaScene
468
+ *
469
+ * "projectId": "myTableProject",
470
+ * "revisionId": "V1.0",
471
+ *
472
+ * "metaObjects": [
473
+ * { // Creates a MetaObject in the MetaModel
474
+ * "id": "table",
475
+ * "name": "Table", // Same ID as an object Entity
476
+ * "type": "furniture", // Arbitrary type, could be IFC type
477
+ * "properties": { // Arbitrary properties, could be IfcPropertySet
478
+ * "cost": "200"
479
+ * }
480
+ * },
481
+ * {
482
+ * "id": "redLeg",
483
+ * "name": "Red table Leg",
484
+ * "type": "leg",
485
+ * "parent": "table", // References first MetaObject as parent
486
+ * "properties": {
487
+ * "material": "wood"
488
+ * }
489
+ * },
490
+ * {
491
+ * "id": "greenLeg", // Node with corresponding id does not need to exist
492
+ * "name": "Green table leg", // and MetaObject does not need to exist for Node with an id
493
+ * "type": "leg",
494
+ * "parent": "table",
495
+ * "properties": {
496
+ * "material": "wood"
497
+ * }
498
+ * },
499
+ * {
500
+ * "id": "blueLeg",
501
+ * "name": "Blue table leg",
502
+ * "type": "leg",
503
+ * "parent": "table",
504
+ * "properties": {
505
+ * "material": "wood"
506
+ * }
507
+ * },
508
+ * {
509
+ * "id": "yellowLeg",
510
+ * "name": "Yellow table leg",
511
+ * "type": "leg",
512
+ * "parent": "table",
513
+ * "properties": {
514
+ * "material": "wood"
515
+ * }
516
+ * },
517
+ * {
518
+ * "id": "tableTop",
519
+ * "name": "Purple table top",
520
+ * "type": "surface",
521
+ * "parent": "table",
522
+ * "properties": {
523
+ * "material": "formica",
524
+ * "width": "60",
525
+ * "depth": "60",
526
+ * "thickness": "5"
527
+ * }
528
+ * }
529
+ * ]
530
+ * });
531
+ * ````
532
+ *
533
+ * ## Querying Metadata
534
+ *
535
+ * Having created and classified our model (either the instancing or batching example), we can now find the {@link MetaModel}
536
+ * and {@link MetaObject}s using the IDs of their
537
+ * corresponding {@link Entity}s.
538
+ *
539
+ * ````JavaScript
540
+ * const furnitureMetaModel = scene.metaScene.metaModels["furniture"];
541
+ *
542
+ * const redLegMetaObject = scene.metaScene.metaObjects["redLeg"];
543
+ * ````
544
+ *
545
+ * In the snippet below, we'll log metadata on each {@link Entity} we click on:
546
+ *
547
+ * ````JavaScript
548
+ * viewer.scene.input.on("mouseclicked", function (coords) {
549
+ *
550
+ * const hit = viewer.scene.pick({
551
+ * canvasPos: coords
552
+ * });
553
+ *
554
+ * if (hit) {
555
+ * const entity = hit.entity;
556
+ * const metaObject = viewer.metaScene.metaObjects[entity.id];
557
+ * if (metaObject) {
558
+ * console.log(JSON.stringify(metaObject.getJSON(), null, "\t"));
559
+ * }
560
+ * }
561
+ * });
562
+ * ````
563
+ *
564
+ * ## Metadata Structure
565
+ *
566
+ * The {@link MetaModel}
567
+ * organizes its {@link MetaObject}s in
568
+ * a tree that describes their structural composition:
569
+ *
570
+ * ````JavaScript
571
+ * // Get metadata on the root object
572
+ * const tableMetaObject = furnitureMetaModel.rootMetaObject;
573
+ *
574
+ * // Get metadata on the leg objects
575
+ * const redLegMetaObject = tableMetaObject.children[0];
576
+ * const greenLegMetaObject = tableMetaObject.children[1];
577
+ * const blueLegMetaObject = tableMetaObject.children[2];
578
+ * const yellowLegMetaObject = tableMetaObject.children[3];
579
+ * ````
580
+ *
581
+ * Given an {@link Entity}, we can find the object or model of which it is a part, or the objects that comprise it. We can also generate UI
582
+ * components from the metadata, such as the tree view demonstrated in [this demo](https://yjkkit.github.io/yjkkit-sdk/examples/#BIMOffline_glTF_OTCConferenceCenter).
583
+ *
584
+ * This hierarchy allows us to express the hierarchical structure of a model while representing it in
585
+ * various ways in the 3D scene (such as with ````PerformanceModel````, which
586
+ * has a non-hierarchical scene representation).
587
+ *
588
+ * Note also that a {@link MetaObject} does not need to have a corresponding
589
+ * {@link Entity} and vice-versa.
590
+ *
591
+ * # RTC Coordinates for 64-Bit Precision
592
+ *
593
+ * ````PerformanceModel```` can emulate 64-bit precision on GPUs using relative-to-center (RTC) coordinates.
594
+ *
595
+ * Consider a model that contains many small objects, but with such large spatial extents that 32 bits of GPU precision (accurate to ~7 digits) will not be sufficient to render all of the the objects without jittering.
596
+ *
597
+ * To prevent jittering, we could spatially subdivide the objects into "tiles". Each tile would have a center position, and the positions of the objects within the tile would be relative to that center ("RTC coordinates").
598
+ *
599
+ * While the center positions of the tiles would be 64-bit values, the object positions only need to be 32-bit.
600
+ *
601
+ * Internally, when rendering an object with RTC coordinates, yjkkit first temporarily translates the camera viewing matrix by the object's tile's RTC center, on the CPU, using 64-bit math.
602
+ *
603
+ * Then yjkkit loads the viewing matrix into its WebGL shaders, where math happens at 32-bit precision. Within the shaders, the matrix is effectively down-cast to 32-bit precision, and the object's 32-bit vertex positions are transformed by the matrix.
604
+ *
605
+ * We see no jittering, because with RTC a detectable loss of GPU accuracy only starts happening to objects as they become very distant from the camera viewpoint, at which point they are too small to be discernible anyway.
606
+ *
607
+ * ## RTC Coordinates with Geometry Instancing
608
+ *
609
+ * To use RTC with ````PerformanceModel```` geometry instancing, we specify an RTC center for the geometry. Then ````PerformanceModel```` assumes that all meshes that instance that geometry are within the same RTC coordinate system, ie. the meshes ````position```` and ````rotation```` properties are assumed to be relative to the geometry's ````rtcCenter````.
610
+ *
611
+ * For simplicity, our example's meshes all instance the same geometry. Therefore, our example model has only one RTC center.
612
+ *
613
+ * Note that the axis-aligned World-space boundary (AABB) of our model is ````[ -6, -9, -6, 1000000006, -2.5, 1000000006]````.
614
+ *
615
+ * [![](http://yjkkit.io/img/docs/sceneGraph.png)](https://yjkkit.github.io/yjkkit-sdk/examples/#sceneRepresentation_PerformanceModel_batching)
616
+ *
617
+ * * [[Run this example](https://yjkkit.github.io/yjkkit-sdk/examples/#sceneRepresentation_PerformanceModel_instancing_rtcCenter)]
618
+ *
619
+ * ````javascript
620
+ * const rtcCenter = [100000000, 0, 100000000];
621
+ *
622
+ * performanceModel.createGeometry({
623
+ * id: "box",
624
+ * rtcCenter: rtcCenter, // This geometry's positions, and the transforms of all meshes that instance the geometry, are relative to the RTC center
625
+ * primitive: "triangles",
626
+ * positions: [ 1, 1, 1, -1, 1, 1, -1, -1, 1, 1, -1, 1 ... ],
627
+ * normals: [ 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, ... ],
628
+ * indices: [ 0, 1, 2, 0, 2, 3, 4, 5, 6, 4, 6, 7, ... ],
629
+ * });
630
+ *
631
+ * performanceModel.createMesh({
632
+ * id: "leg1",
633
+ * geometryId: "box",
634
+ * position: [-4, -6, -4],
635
+ * scale: [1, 3, 1],
636
+ * rotation: [0, 0, 0],
637
+ * color: [1, 0.3, 0.3]
638
+ * });
639
+ *
640
+ * performanceModel.createEntity({
641
+ * meshIds: ["leg1"],
642
+ * isObject: true
643
+ * });
644
+ *
645
+ * performanceModel.createMesh({
646
+ * id: "leg2",
647
+ * geometryId: "box",
648
+ * position: [4, -6, -4],
649
+ * scale: [1, 3, 1],
650
+ * rotation: [0, 0, 0],
651
+ * color: [0.3, 1.0, 0.3]
652
+ * });
653
+ *
654
+ * performanceModel.createEntity({
655
+ * meshIds: ["leg2"],
656
+ * isObject: true
657
+ * });
658
+ *
659
+ * performanceModel.createMesh({
660
+ * id: "leg3",
661
+ * geometryId: "box",
662
+ * position: [4, -6, 4],
663
+ * scale: [1, 3, 1],
664
+ * rotation: [0, 0, 0],
665
+ * color: [0.3, 0.3, 1.0]
666
+ * });
667
+ *
668
+ * performanceModel.createEntity({
669
+ * meshIds: ["leg3"],
670
+ * isObject: true
671
+ * });
672
+ *
673
+ * performanceModel.createMesh({
674
+ * id: "leg4",
675
+ * geometryId: "box",
676
+ * position: [-4, -6, 4],
677
+ * scale: [1, 3, 1],
678
+ * rotation: [0, 0, 0],
679
+ * color: [1.0, 1.0, 0.0]
680
+ * });
681
+ *
682
+ * performanceModel.createEntity({
683
+ * meshIds: ["leg4"],
684
+ * isObject: true
685
+ * });
686
+ *
687
+ * performanceModel.createMesh({
688
+ * id: "top",
689
+ * geometryId: "box",
690
+ * position: [0, -3, 0],
691
+ * scale: [6, 0.5, 6],
692
+ * rotation: [0, 0, 0],
693
+ * color: [1.0, 0.3, 1.0]
694
+ * });
695
+ *
696
+ * performanceModel.createEntity({
697
+ * meshIds: ["top"],
698
+ * isObject: true
699
+ * });
700
+ * ````
701
+ *
702
+ * ## RTC Coordinates with Geometry Batching
703
+ *
704
+ * To use RTC with ````PerformanceModel```` geometry batching, we specify an RTC center (````rtcCenter````) for each mesh. For performance, we try to have as many meshes share the same value for ````rtcCenter```` as possible. Each mesh's ````positions````, ````position```` and ````rotation```` properties are assumed to be relative to ````rtcCenter````.
705
+ *
706
+ * For simplicity, the meshes in our example all share the same RTC center.
707
+ *
708
+ * The axis-aligned World-space boundary (AABB) of our model is ````[ -6, -9, -6, 1000000006, -2.5, 1000000006]````.
709
+ *
710
+ * [![](http://yjkkit.io/img/docs/sceneGraph.png)](https://yjkkit.github.io/yjkkit-sdk/examples/#sceneRepresentation_PerformanceModel_batching)
711
+ *
712
+ * * [[Run this example](https://yjkkit.github.io/yjkkit-sdk/examples/#sceneRepresentation_PerformanceModel_batching_rtcCenter)]
713
+ *
714
+ * ````javascript
715
+ * const rtcCenter = [100000000, 0, 100000000];
716
+ *
717
+ * performanceModel.createMesh({
718
+ * id: "leg1",
719
+ * rtcCenter: rtcCenter, // This mesh's positions and transforms are relative to the RTC center
720
+ * primitive: "triangles",
721
+ * positions: [ 1, 1, 1, -1, 1, 1, -1, -1, 1, 1, -1, 1 ... ],
722
+ * normals: [ 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, ... ],
723
+ * indices: [ 0, 1, 2, 0, 2, 3, 4, 5, 6, 4, 6, 7, ... ],
724
+ * position: [-4, -6, -4],
725
+ * scale: [1, 3, 1],
726
+ * rotation: [0, 0, 0],
727
+ * color: [1, 0.3, 0.3]
728
+ * });
729
+ *
730
+ * performanceModel.createEntity({
731
+ * meshIds: ["leg1"],
732
+ * isObject: true
733
+ * });
734
+ *
735
+ * performanceModel.createMesh({
736
+ * id: "leg2",
737
+ * rtcCenter: rtcCenter, // This mesh's positions and transforms are relative to the RTC center
738
+ * primitive: "triangles",
739
+ * positions: [ 1, 1, 1, -1, 1, 1, -1, -1, 1, 1, -1, 1 ... ],
740
+ * normals: [ 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, ... ],
741
+ * indices: [ 0, 1, 2, 0, 2, 3, 4, 5, 6, 4, 6, 7, ... ],
742
+ * position: [4, -6, -4],
743
+ * scale: [1, 3, 1],
744
+ * rotation: [0, 0, 0],
745
+ * color: [0.3, 1.0, 0.3]
746
+ * });
747
+ *
748
+ * performanceModel.createEntity({
749
+ * meshIds: ["leg2"],
750
+ * isObject: true
751
+ * });
752
+ *
753
+ * performanceModel.createMesh({
754
+ * id: "leg3",
755
+ * rtcCenter: rtcCenter, // This mesh's positions and transforms are relative to the RTC center
756
+ * primitive: "triangles",
757
+ * positions: [ 1, 1, 1, -1, 1, 1, -1, -1, 1, 1, -1, 1 ... ],
758
+ * normals: [ 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, ... ],
759
+ * indices: [ 0, 1, 2, 0, 2, 3, 4, 5, 6, 4, 6, 7, ... ],
760
+ * position: [4, -6, 4],
761
+ * scale: [1, 3, 1],
762
+ * rotation: [0, 0, 0],
763
+ * color: [0.3, 0.3, 1.0]
764
+ * });
765
+ *
766
+ * performanceModel.createEntity({
767
+ * meshIds: ["leg3"],
768
+ * isObject: true
769
+ * });
770
+ *
771
+ * performanceModel.createMesh({
772
+ * id: "leg4",
773
+ * rtcCenter: rtcCenter, // This mesh's positions and transforms are relative to the RTC center
774
+ * primitive: "triangles",
775
+ * positions: [ 1, 1, 1, -1, 1, 1, -1, -1, 1, 1, -1, 1 ... ],
776
+ * normals: [ 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, ... ],
777
+ * indices: [ 0, 1, 2, 0, 2, 3, 4, 5, 6, 4, 6, 7, ... ],
778
+ * position: [-4, -6, 4],
779
+ * scale: [1, 3, 1],
780
+ * rotation: [0, 0, 0],
781
+ * color: [1.0, 1.0, 0.0]
782
+ * });
783
+ *
784
+ * performanceModel.createEntity({
785
+ * meshIds: ["leg4"],
786
+ * isObject: true
787
+ * });
788
+ *
789
+ * performanceModel.createMesh({
790
+ * id: "top",
791
+ * rtcCenter: rtcCenter, // This mesh's positions and transforms are relative to the RTC center
792
+ * primitive: "triangles",
793
+ * positions: [ 1, 1, 1, -1, 1, 1, -1, -1, 1, 1, -1, 1 ... ],
794
+ * normals: [ 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, ... ],
795
+ * indices: [ 0, 1, 2, 0, 2, 3, 4, 5, 6, 4, 6, 7, ... ],
796
+ * position: [0, -3, 0],
797
+ * scale: [6, 0.5, 6],
798
+ * rotation: [0, 0, 0],
799
+ * color: [1.0, 0.3, 1.0]
800
+ * });
801
+ *
802
+ * performanceModel.createEntity({
803
+ * meshIds: ["top"],
804
+ * isObject: true
805
+ * });
806
+ ````
807
+ *
808
+ * @implements {Drawable}
809
+ * @implements {Entity}
810
+ */
811
+ class PerformanceModel extends Component {
812
+
813
+ /**
814
+ * @constructor
815
+ * @param {Component} owner Owner component. When destroyed, the owner will destroy this component as well.
816
+ * @param {*} [cfg] Configs
817
+ * @param {String} [cfg.id] Optional ID, unique among all components in the parent scene, generated automatically when omitted.
818
+ * @param {Boolean} [cfg.isModel] Specify ````true```` if this PerformanceModel represents a model, in which case the PerformanceModel will be registered by {@link PerformanceModel#id} in {@link Scene#models} and may also have a corresponding {@link MetaModel} with matching {@link MetaModel#id}, registered by that ID in {@link MetaScene#metaModels}.
819
+ * @param {Number[]} [cfg.position=[0,0,0]] Local 3D position.
820
+ * @param {Number[]} [cfg.scale=[1,1,1]] Local scale.
821
+ * @param {Number[]} [cfg.rotation=[0,0,0]] Local rotation, as Euler angles given in degrees, for each of the X, Y and Z axis.
822
+ * @param {Number[]} [cfg.matrix=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1] Local modelling transform matrix. Overrides the position, scale and rotation parameters.
823
+ * @param {Boolean} [cfg.visible=true] Indicates if the PerformanceModel is initially visible.
824
+ * @param {Boolean} [cfg.culled=false] Indicates if the PerformanceModel is initially culled from view.
825
+ * @param {Boolean} [cfg.pickable=true] Indicates if the PerformanceModel is initially pickable.
826
+ * @param {Boolean} [cfg.clippable=true] Indicates if the PerformanceModel is initially clippable.
827
+ * @param {Boolean} [cfg.collidable=true] Indicates if the PerformanceModel is initially included in boundary calculations.
828
+ * @param {Boolean} [cfg.xrayed=false] Indicates if the PerformanceModel is initially xrayed.
829
+ * @param {Boolean} [cfg.highlighted=false] Indicates if the PerformanceModel is initially highlighted.
830
+ * @param {Boolean} [cfg.selected=false] Indicates if the PerformanceModel is initially selected.
831
+ * @param {Boolean} [cfg.edges=false] Indicates if the PerformanceModel's edges are initially emphasized.
832
+ * @param {Number[]} [cfg.colorize=[1.0,1.0,1.0]] PerformanceModel's initial RGB colorize color, multiplies by the rendered fragment colors.
833
+ * @param {Number} [cfg.opacity=1.0] PerformanceModel's initial opacity factor, multiplies by the rendered fragment alpha.
834
+ * @param {Number} [cfg.backfaces=false] When we set this ````true````, then we force rendering of backfaces for this PerformanceModel. When
835
+ * we leave this ````false````, then we allow the Viewer to decide when to render backfaces. In that case, the
836
+ * Viewer will hide backfaces on watertight meshes, show backfaces on open meshes, and always show backfaces on meshes when we slice them open with {@link SectionPlane}s.
837
+ * @param {Boolean} [cfg.saoEnabled=true] Indicates if Scalable Ambient Obscurance (SAO) will apply to this PerformanceModel. SAO is configured by the Scene's {@link SAO} component.
838
+ * @param {Boolean} [cfg.pbrEnabled=false] Indicates if physically-based rendering (PBR) will apply to the PerformanceModel. Only works when {@link Scene#pbrEnabled} is also ````true````.
839
+ * @param {Number} [cfg.edgeThreshold=10] When xraying, highlighting, selecting or edging, this is the threshold angle between normals of adjacent triangles, below which their shared wireframe edge is not drawn.
840
+ * @param {Number} [cfg.maxGeometryBatchSize=50000000] Maximum geometry batch size, as number of vertices. This is optionally supplied
841
+ * to limit the size of the batched geometry arrays that PerformanceModel internally creates for batched geometries.
842
+ * A lower value means less heap allocation/de-allocation while creating/loading batched geometries, but more draw calls and
843
+ * slower rendering speed. A high value means larger heap allocation/de-allocation while creating/loading, but less draw calls
844
+ * and faster rendering speed. It's recommended to keep this somewhere roughly between ````50000```` and ````50000000```.
845
+ */
846
+ constructor(owner, cfg = {}) {
847
+
848
+ super(owner, cfg);
849
+
850
+ this._maxGeometryBatchSize = cfg.maxGeometryBatchSize;
851
+
852
+ this._aabb = math.collapseAABB3();
853
+ this._aabbDirty = false;
854
+ this._layerList = []; // For GL state efficiency when drawing, InstancingLayers are in first part, BatchingLayers are in second
855
+ this._nodeList = [];
856
+
857
+ this._lastRTCCenter = null;
858
+ this._lastDecodeMatrix = null;
859
+
860
+ this._instancingLayers = {};
861
+ this._currentBatchingLayers = {};
862
+
863
+ this._scratchMemory = getScratchMemory();
864
+
865
+ this._meshes = {};
866
+ this._nodes = {};
867
+
868
+ /** @private **/
869
+ this.renderFlags = new RenderFlags();
870
+
871
+ /**
872
+ * @private
873
+ */
874
+ this.numGeometries = 0; // Number of instance-able geometries created with createGeometry()
875
+
876
+ // These counts are used to avoid unnecessary render passes
877
+ // They are incremented or decremented exclusively by BatchingLayer and InstancingLayer
878
+ /**
879
+ * @private
880
+ */
881
+ this.numPortions = 0;
882
+
883
+ /**
884
+ * @private
885
+ */
886
+ this.numVisibleLayerPortions = 0;
887
+
888
+ /**
889
+ * @private
890
+ */
891
+ this.numTransparentLayerPortions = 0;
892
+
893
+ /**
894
+ * @private
895
+ */
896
+ this.numXRayedLayerPortions = 0;
897
+
898
+ /**
899
+ * @private
900
+ */
901
+ this.numHighlightedLayerPortions = 0;
902
+
903
+ /**
904
+ * @private
905
+ */
906
+ this.numSelectedLayerPortions = 0;
907
+
908
+ /**
909
+ * @private
910
+ */
911
+ this.numEdgesLayerPortions = 0;
912
+
913
+ /**
914
+ * @private
915
+ */
916
+ this.numPickableLayerPortions = 0;
917
+
918
+ /**
919
+ * @private
920
+ */
921
+ this.numClippableLayerPortions = 0;
922
+
923
+ /**
924
+ * @private
925
+ */
926
+ this.numCulledLayerPortions = 0;
927
+
928
+ /** @private */
929
+ this.numEntities = 0;
930
+
931
+ /** @private */
932
+ this._numTriangles = 0;
933
+
934
+ /** @private */
935
+ this._numLines = 0;
936
+
937
+ /** @private */
938
+ this._numPoints = 0;
939
+
940
+ this._edgeThreshold = cfg.edgeThreshold || 10;
941
+
942
+ this.visible = cfg.visible;
943
+ this.culled = cfg.culled;
944
+ this.pickable = cfg.pickable;
945
+ this.clippable = cfg.clippable;
946
+ this.collidable = cfg.collidable;
947
+ this.castsShadow = cfg.castsShadow;
948
+ this.receivesShadow = cfg.receivesShadow;
949
+ this.xrayed = cfg.xrayed;
950
+ this.highlighted = cfg.highlighted;
951
+ this.selected = cfg.selected;
952
+ this.edges = cfg.edges;
953
+ this.colorize = cfg.colorize;
954
+ this.opacity = cfg.opacity;
955
+ this.backfaces = cfg.backfaces;
956
+
957
+ // Build static matrix
958
+
959
+ this._position = new Float32Array(cfg.position || [0, 0, 0]);
960
+ this._rotation = new Float32Array(cfg.rotation || [0, 0, 0]);
961
+ this._quaternion = new Float32Array(cfg.quaternion || [0, 0, 0, 1]);
962
+ if (cfg.rotation) {
963
+ math.eulerToQuaternion(this._rotation, "XYZ", this._quaternion);
964
+ }
965
+ this._scale = new Float32Array(cfg.scale || [1, 1, 1]);
966
+ this._worldMatrix = math.mat4();
967
+ math.composeMat4(this._position, this._quaternion, this._scale, this._worldMatrix);
968
+ this._worldNormalMatrix = math.mat4();
969
+ math.inverseMat4(this._worldMatrix, this._worldNormalMatrix);
970
+ math.transposeMat4(this._worldNormalMatrix);
971
+
972
+ if (cfg.matrix || cfg.position || cfg.rotation || cfg.scale || cfg.quaternion) {
973
+ this._viewMatrix = math.mat4();
974
+ this._viewNormalMatrix = math.mat4();
975
+ this._viewMatrixDirty = true;
976
+ this._worldMatrixNonIdentity = true;
977
+ }
978
+
979
+ this._opacity = 1.0;
980
+ this._colorize = [1, 1, 1];
981
+
982
+ this._saoEnabled = (cfg.saoEnabled !== false);
983
+
984
+ this._pbrEnabled = (!!cfg.pbrEnabled);
985
+
986
+ this._isModel = cfg.isModel;
987
+ if (this._isModel) {
988
+ this.scene._registerModel(this);
989
+ }
990
+
991
+ this._onCameraViewMatrix = this.scene.camera.on("matrix", () => {
992
+ this._viewMatrixDirty = true;
993
+ });
994
+ }
995
+
996
+ //------------------------------------------------------------------------------------------------------------------
997
+ // PerformanceModel members
998
+ //------------------------------------------------------------------------------------------------------------------
999
+
1000
+ /**
1001
+ * Returns true to indicate that this Component is a PerformanceModel.
1002
+ * @type {Boolean}
1003
+ */
1004
+ get isPerformanceModel() {
1005
+ return true;
1006
+ }
1007
+
1008
+ /**
1009
+ * Gets the PerformanceModel's local translation.
1010
+ *
1011
+ * Default value is ````[0,0,0]````.
1012
+ *
1013
+ * @type {Number[]}
1014
+ */
1015
+ get position() {
1016
+ return this._position;
1017
+ }
1018
+
1019
+ /**
1020
+ * Gets the PerformanceModel's local rotation, as Euler angles given in degrees, for each of the X, Y and Z axis.
1021
+ *
1022
+ * Default value is ````[0,0,0]````.
1023
+ *
1024
+ * @type {Number[]}
1025
+ */
1026
+ get rotation() {
1027
+ return this._rotation;
1028
+ }
1029
+
1030
+ /**
1031
+ * Gets the PerformanceModels's local rotation quaternion.
1032
+ *
1033
+ * Default value is ````[0,0,0,1]````.
1034
+ *
1035
+ * @type {Number[]}
1036
+ */
1037
+ get quaternion() {
1038
+ return this._quaternion;
1039
+ }
1040
+
1041
+ /**
1042
+ * Gets the PerformanceModel's local scale.
1043
+ *
1044
+ * Default value is ````[1,1,1]````.
1045
+ *
1046
+ * @type {Number[]}
1047
+ */
1048
+ get scale() {
1049
+ return this._scale;
1050
+ }
1051
+
1052
+ /**
1053
+ * Gets the PerformanceModel's local modeling transform matrix.
1054
+ *
1055
+ * Default value is ````[1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]````.
1056
+ *
1057
+ * @type {Number[]}
1058
+ */
1059
+ get matrix() {
1060
+ return this._worldMatrix;
1061
+ }
1062
+
1063
+ /**
1064
+ * Gets the PerformanceModel's World matrix.
1065
+ *
1066
+ * @property worldMatrix
1067
+ * @type {Number[]}
1068
+ */
1069
+ get worldMatrix() {
1070
+ return this._worldMatrix;
1071
+ }
1072
+
1073
+ /**
1074
+ * Gets the PerformanceModel's World normal matrix.
1075
+ *
1076
+ * @type {Number[]}
1077
+ */
1078
+ get worldNormalMatrix() {
1079
+ return this._worldNormalMatrix;
1080
+ }
1081
+
1082
+ /**
1083
+ * Called by private renderers in ./lib, returns the view matrix with which to
1084
+ * render this PerformanceModel. The view matrix is the concatenation of the
1085
+ * Camera view matrix with the Performance model's world (modeling) matrix.
1086
+ *
1087
+ * @private
1088
+ */
1089
+ get viewMatrix() {
1090
+ if (!this._viewMatrix) {
1091
+ return this.scene.camera.viewMatrix;
1092
+ }
1093
+ if (this._viewMatrixDirty) {
1094
+ math.mulMat4(this.scene.camera.viewMatrix, this._worldMatrix, this._viewMatrix);
1095
+ math.inverseMat4(this._viewMatrix, this._viewNormalMatrix);
1096
+ math.transposeMat4(this._viewNormalMatrix);
1097
+ this._viewMatrixDirty = false;
1098
+ }
1099
+ return this._viewMatrix;
1100
+ }
1101
+
1102
+ /**
1103
+ * Called by private renderers in ./lib, returns the picking view matrix with which to
1104
+ * ray-pick on this PerformanceModel.
1105
+ *
1106
+ * @private
1107
+ */
1108
+ getPickViewMatrix(pickViewMatrix) {
1109
+ if (!this._viewMatrix) {
1110
+ return pickViewMatrix;
1111
+ }
1112
+ return this._viewMatrix;
1113
+ }
1114
+
1115
+ /**
1116
+ * Called by private renderers in ./lib, returns the view normal matrix with which to render this PerformanceModel.
1117
+ *
1118
+ * @private
1119
+ */
1120
+ get viewNormalMatrix() {
1121
+ if (!this._viewNormalMatrix) {
1122
+ return this.scene.camera.viewNormalMatrix;
1123
+ }
1124
+ if (this._viewMatrixDirty) {
1125
+ math.mulMat4(this.scene.camera.viewMatrix, this._worldMatrix, this._viewMatrix);
1126
+ math.inverseMat4(this._viewMatrix, this._viewNormalMatrix);
1127
+ math.transposeMat4(this._viewNormalMatrix);
1128
+ this._viewMatrixDirty = false;
1129
+ }
1130
+ return this._viewNormalMatrix;
1131
+ }
1132
+
1133
+ /**
1134
+ * Creates a reusable geometry within this PerformanceModel.
1135
+ *
1136
+ * We can then supply the geometry ID to {@link PerformanceModel#createMesh} when we want to create meshes that instance the geometry.
1137
+ *
1138
+ * If provide a ````positionsDecodeMatrix```` , then ````createGeometry()```` will assume
1139
+ * that the ````positions```` and ````normals```` arrays are compressed. When compressed, ````positions```` will be
1140
+ * quantized and in World-space, and ````normals```` will be oct-encoded and in World-space.
1141
+ *
1142
+ * Note that ````positions````, ````normals```` and ````indices```` are all required together.
1143
+ *
1144
+ * @param {*} cfg Geometry properties.
1145
+ * @param {String|Number} cfg.id Mandatory ID for the geometry, to refer to with {@link PerformanceModel#createMesh}.
1146
+ * @param {String} cfg.primitive The primitive type. Accepted values are 'points', 'lines', 'triangles', 'solid' and 'surface'.
1147
+ * @param {Number[]} cfg.positions Flat array of positions.
1148
+ * @param {Number[]} [cfg.normals] Flat array of normal vectors. Required for 'triangles' primitives.
1149
+ * @param {Number[]} [cfg.indices] Array of indices. Not required for `points` primitives.
1150
+ * @param {Number[]} [cfg.edgeIndices] Array of edge line indices. Used only for Required for 'triangles' primitives. These are automatically generated internally if not supplied, using the ````edgeThreshold```` given to the ````PerformanceModel```` constructor.
1151
+ * @param {Number[]} [cfg.positionsDecodeMatrix] A 4x4 matrix for decompressing ````positions````.
1152
+ * @param {Number[]} [cfg.rtcCenter] Relative-to-center (RTC) coordinate system center. When this is given, then ````positions```` are assumed to be relative to this center.
1153
+ */
1154
+ createGeometry(cfg) {
1155
+ if (!instancedArraysSupported) {
1156
+ this.error("WebGL instanced arrays not supported"); // TODO: Gracefully use batching?
1157
+ return;
1158
+ }
1159
+ const geometryId = cfg.id;
1160
+ if (geometryId === undefined || geometryId === null) {
1161
+ this.error("Config missing: id");
1162
+ return;
1163
+ }
1164
+ if (this._instancingLayers[geometryId]) {
1165
+ this.error("Geometry already created: " + geometryId);
1166
+ return;
1167
+ }
1168
+ let instancingLayer;
1169
+ const primitive = cfg.primitive;
1170
+ if (primitive === undefined || primitive === null) {
1171
+ this.error("Config missing: primitive");
1172
+ return;
1173
+ }
1174
+ switch (primitive) {
1175
+ case "triangles":
1176
+ instancingLayer = new TrianglesInstancingLayer(this, utils.apply({
1177
+ layerIndex: 0,
1178
+ solid: true
1179
+ }, cfg));
1180
+ this._numTriangles += (cfg.indices ? Math.round(cfg.indices.length / 3) : 0);
1181
+ break;
1182
+ case "solid":
1183
+ instancingLayer = new TrianglesInstancingLayer(this, utils.apply({
1184
+ layerIndex: 0,
1185
+ solid: true
1186
+ }, cfg));
1187
+ this._numTriangles += (cfg.indices ? Math.round(cfg.indices.length / 3) : 0);
1188
+ break;
1189
+ case "surface":
1190
+ instancingLayer = new TrianglesInstancingLayer(this, utils.apply({
1191
+ layerIndex: 0,
1192
+ solid: false
1193
+ }, cfg));
1194
+ this._numTriangles += (cfg.indices ? Math.round(cfg.indices.length / 3) : 0);
1195
+ break;
1196
+ case "lines":
1197
+ instancingLayer = new LinesInstancingLayer(this, utils.apply({
1198
+ layerIndex: 0
1199
+ }, cfg));
1200
+ this._numLines += (cfg.indices ? Math.round(cfg.indices.length / 2) : 0);
1201
+ break;
1202
+ case "points":
1203
+ instancingLayer = new PointsInstancingLayer(this, utils.apply({
1204
+ layerIndex: 0
1205
+ }, cfg));
1206
+ this._numPoints += (cfg.positions ? Math.round(cfg.positions.length / 3) : 0);
1207
+ break;
1208
+ }
1209
+ this._instancingLayers[geometryId] = instancingLayer;
1210
+ this._layerList.push(instancingLayer);
1211
+ this.numGeometries++;
1212
+ }
1213
+
1214
+ /**
1215
+ * Creates a mesh within this PerformanceModel.
1216
+ *
1217
+ * A mesh can either share geometry with other meshes, or have its own unique geometry.
1218
+ *
1219
+ * To share a geometry with other meshes, provide the ID of a geometry created earlier
1220
+ * with {@link PerformanceModel#createGeometry}.
1221
+ *
1222
+ * To create unique geometry for the mesh, provide geometry data arrays.
1223
+ *
1224
+ * Internally, PerformanceModel will batch all unique mesh geometries into the same arrays, which improves
1225
+ * rendering performance.
1226
+ *
1227
+ * If you accompany the arrays with a ````positionsDecodeMatrix```` , then ````createMesh()```` will assume
1228
+ * that the ````positions```` and ````normals```` arrays are compressed. When compressed, ````positions```` will be
1229
+ * quantized and in World-space, and ````normals```` will be oct-encoded and in World-space.
1230
+ *
1231
+ * If you accompany the arrays with an ````rtcCenter````, then ````createMesh()```` will assume
1232
+ * that the ````positions```` are in relative-to-center (RTC) coordinates, with ````rtcCenter```` being the origin of their
1233
+ * RTC coordinate system.
1234
+ *
1235
+ * When providing either ````positionsDecodeMatrix```` or ````rtcCenter````, ````createMesh()```` will start a new
1236
+ * batch each time either of those two parameters change since the last call. Therefore, to combine arrays into the
1237
+ * minimum number of batches, it's best for performance to create your shared meshes in runs that have the same value
1238
+ * for ````positionsDecodeMatrix```` and ````rtcCenter````.
1239
+ *
1240
+ * Note that ````positions````, ````normals```` and ````indices```` are all required together.
1241
+ *
1242
+ * @param {object} cfg Object properties.
1243
+ * @param {String} cfg.id Mandatory ID for the new mesh. Must not clash with any existing components within the {@link Scene}.
1244
+ * @param {String|Number} [cfg.geometryId] ID of a geometry to instance, previously created with {@link PerformanceModel#createGeometry:method"}}createMesh(){{/crossLink}}. Overrides all other geometry parameters given to this method.
1245
+ * @param {String} [cfg.primitive="triangles"] Geometry primitive type. Ignored when ````geometryId```` is given. Accepted values are 'points', 'lines' and 'triangles'.
1246
+ * @param {Number[]} [cfg.positions] Flat array of vertex positions. Ignored when ````geometryId```` is given.
1247
+ * @param {Number[]} [cfg.colors] Flat array of vertex colors. Ignored when ````geometryId```` is given, overriden by ````color````.
1248
+ * @param {Number[]} [cfg.normals] Flat array of vertex normals. Ignored when ````geometryId```` is given.
1249
+ * @param {Number[]} [cfg.positionsDecodeMatrix] A 4x4 matrix for decompressing ````positions````.
1250
+ * @param {Number[]} [cfg.rtcCenter] Relative-to-center (RTC) coordinate system center. When this is given, then ````positions```` are assumed to be relative to this center.
1251
+ * @param {Number[]} [cfg.indices] Array of triangle indices. Ignored when ````geometryId```` is given.
1252
+ * @param {Number[]} [cfg.edgeIndices] Array of edge line indices. If ````geometryId```` is not given, edge line indices are
1253
+ * automatically generated internally if not given, using the ````edgeThreshold```` given to the ````PerformanceModel````
1254
+ * constructor. This parameter is ignored when ````geometryId```` is given.
1255
+ * @param {Number[]} [cfg.position=[0,0,0]] Local 3D position. of the mesh
1256
+ * @param {Number[]} [cfg.scale=[1,1,1]] Scale of the mesh.
1257
+ * @param {Number[]} [cfg.rotation=[0,0,0]] Rotation of the mesh as Euler angles given in degrees, for each of the X, Y and Z axis.
1258
+ * @param {Number[]} [cfg.matrix=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]] Mesh modelling transform matrix. Overrides the ````position````, ````scale```` and ````rotation```` parameters.
1259
+ * @param {Number[]} [cfg.color=[1,1,1]] RGB color in range ````[0..1, 0..`, 0..1]````. Overrides ````colors````.
1260
+ * @param {Number} [cfg.opacity=1] Opacity in range ````[0..1]````.
1261
+ */
1262
+ createMesh(cfg) {
1263
+
1264
+ let id = cfg.id;
1265
+ if (id === undefined || id === null) {
1266
+ this.error("Config missing: id");
1267
+ return;
1268
+ }
1269
+ if (this._meshes[id]) {
1270
+ this.error("PerformanceModel already has a Mesh with this ID: " + id + "");
1271
+ return;
1272
+ }
1273
+
1274
+ const geometryId = cfg.geometryId;
1275
+ const instancing = (geometryId !== undefined);
1276
+
1277
+ if (instancing) {
1278
+ if (!instancedArraysSupported) {
1279
+ this.error("WebGL instanced arrays not supported"); // TODO: Gracefully use batching?
1280
+ return;
1281
+ }
1282
+ if (!this._instancingLayers[geometryId]) {
1283
+ this.error("Geometry not found: " + geometryId + " - ensure that you create it first with createGeometry()");
1284
+ return;
1285
+ }
1286
+ }
1287
+
1288
+ let layer;
1289
+ let portionId;
1290
+
1291
+ const color = (cfg.color) ? new Uint8Array([Math.floor(cfg.color[0] * 255), Math.floor(cfg.color[1] * 255), Math.floor(cfg.color[2] * 255)]) : [255, 255, 255];
1292
+ const opacity = (cfg.opacity !== undefined && cfg.opacity !== null) ? Math.floor(cfg.opacity * 255) : 255;
1293
+ const metallic = (cfg.metallic !== undefined && cfg.metallic !== null) ? Math.floor(cfg.metallic * 255) : 0;
1294
+ const roughness = (cfg.roughness !== undefined && cfg.roughness !== null) ? Math.floor(cfg.roughness * 255) : 255;
1295
+
1296
+ const mesh = new PerformanceMesh(this, id, color, opacity);
1297
+
1298
+ const pickId = mesh.pickId;
1299
+
1300
+ const a = pickId >> 24 & 0xFF;
1301
+ const b = pickId >> 16 & 0xFF;
1302
+ const g = pickId >> 8 & 0xFF;
1303
+ const r = pickId & 0xFF;
1304
+
1305
+ const pickColor = new Uint8Array([r, g, b, a]); // Quantized pick color
1306
+
1307
+ const aabb = math.collapseAABB3();
1308
+
1309
+ if (instancing) {
1310
+
1311
+ let meshMatrix;
1312
+ let worldMatrix = this._worldMatrixNonIdentity ? this._worldMatrix : null;
1313
+
1314
+ if (cfg.matrix) {
1315
+ meshMatrix = cfg.matrix;
1316
+ } else {
1317
+ const scale = cfg.scale || defaultScale;
1318
+ const position = cfg.position || defaultPosition;
1319
+ const rotation = cfg.rotation || defaultRotation;
1320
+ math.eulerToQuaternion(rotation, "XYZ", defaultQuaternion);
1321
+ meshMatrix = math.composeMat4(position, defaultQuaternion, scale, tempMat4);
1322
+ }
1323
+
1324
+ const instancingLayer = this._instancingLayers[geometryId];
1325
+
1326
+ layer = instancingLayer;
1327
+
1328
+ portionId = instancingLayer.createPortion({
1329
+ color: color,
1330
+ metallic: metallic,
1331
+ roughness: roughness,
1332
+ opacity: opacity,
1333
+ meshMatrix: meshMatrix,
1334
+ worldMatrix: worldMatrix,
1335
+ aabb: aabb,
1336
+ pickColor: pickColor
1337
+ });
1338
+
1339
+ math.expandAABB3(this._aabb, aabb);
1340
+
1341
+ const numTriangles = Math.round(instancingLayer.numIndices / 3);
1342
+ this._numTriangles += numTriangles;
1343
+ mesh.numTriangles = numTriangles;
1344
+
1345
+ mesh.rtcCenter = instancingLayer.rtcCenter;
1346
+
1347
+ } else { // Batching
1348
+
1349
+ let primitive = cfg.primitive || "triangles";
1350
+
1351
+ if (primitive !== "points" && primitive !== "lines" && primitive !== "triangles" && primitive !== "solid" && primitive !== "surface") {
1352
+ this.error(`Unsupported value for 'primitive': '${primitive}' - supported values are 'points', 'lines', 'triangles', 'solid' and 'surface'. Defaulting to 'triangles'.`);
1353
+ primitive = "triangles";
1354
+ }
1355
+
1356
+ let positions = cfg.positions;
1357
+
1358
+ if (!positions) {
1359
+ this.error("Config missing: positions (no meshIds provided, so expecting geometry arrays instead)");
1360
+ return null;
1361
+ }
1362
+
1363
+ let indices = cfg.indices;
1364
+ let edgeIndices = cfg.edgeIndices;
1365
+
1366
+ if (!cfg.indices && primitive === "triangles") {
1367
+ this.error("Config missing for triangles primitive: indices (no meshIds provided, so expecting geometry arrays instead)");
1368
+ return null;
1369
+ }
1370
+
1371
+ let needNewBatchingLayers = false;
1372
+
1373
+ if (cfg.rtcCenter) {
1374
+ if (!this._lastRTCCenter) {
1375
+ needNewBatchingLayers = true;
1376
+ this._lastRTCCenter = math.vec3(cfg.rtcCenter);
1377
+ } else {
1378
+ if (!math.compareVec3(this._lastRTCCenter, cfg.rtcCenter)) {
1379
+ needNewBatchingLayers = true;
1380
+ this._lastRTCCenter.set(cfg.rtcCenter)
1381
+ }
1382
+ }
1383
+ }
1384
+
1385
+ if (cfg.positionsDecodeMatrix) {
1386
+ if (!this._lastDecodeMatrix) {
1387
+ needNewBatchingLayers = true;
1388
+ this._lastDecodeMatrix = math.mat4(cfg.positionsDecodeMatrix);
1389
+
1390
+ } else {
1391
+ if (!math.compareMat4(this._lastDecodeMatrix, cfg.positionsDecodeMatrix)) {
1392
+ needNewBatchingLayers = true;
1393
+ this._lastDecodeMatrix.set(cfg.positionsDecodeMatrix)
1394
+ }
1395
+ }
1396
+ }
1397
+
1398
+ if (needNewBatchingLayers) {
1399
+ for (let prim in this._currentBatchingLayers) {
1400
+ if (this._currentBatchingLayers.hasOwnProperty(prim)) {
1401
+ this._currentBatchingLayers[prim].finalize();
1402
+ }
1403
+ }
1404
+ this._currentBatchingLayers = {};
1405
+ }
1406
+
1407
+ const worldMatrix = this._worldMatrixNonIdentity ? this._worldMatrix : null;
1408
+ let meshMatrix;
1409
+
1410
+ if (!cfg.positionsDecodeMatrix) {
1411
+ if (cfg.matrix) {
1412
+ meshMatrix = cfg.matrix;
1413
+ } else {
1414
+ const scale = cfg.scale || defaultScale;
1415
+ const position = cfg.position || defaultPosition;
1416
+ const rotation = cfg.rotation || defaultRotation;
1417
+ math.eulerToQuaternion(rotation, "XYZ", defaultQuaternion);
1418
+ meshMatrix = math.composeMat4(position, defaultQuaternion, scale, tempMat4);
1419
+ }
1420
+ }
1421
+
1422
+ layer = this._currentBatchingLayers[primitive];
1423
+
1424
+ switch (primitive) {
1425
+
1426
+ case "triangles":
1427
+ case "solid":
1428
+ case "surface":
1429
+
1430
+ if (layer) {
1431
+ if (!layer.canCreatePortion(positions.length, indices.length)) {
1432
+ layer.finalize();
1433
+ delete this._currentBatchingLayers[primitive];
1434
+ layer = null;
1435
+ }
1436
+ }
1437
+
1438
+ if (!layer) {
1439
+ layer = new TrianglesBatchingLayer(this, {
1440
+ layerIndex: 0, // This is set in #finalize()
1441
+ scratchMemory: this._scratchMemory,
1442
+ positionsDecodeMatrix: cfg.positionsDecodeMatrix, // Can be undefined
1443
+ rtcCenter: cfg.rtcCenter, // Can be undefined
1444
+ maxGeometryBatchSize: this._maxGeometryBatchSize,
1445
+ solid: (primitive === "solid")
1446
+ });
1447
+ this._layerList.push(layer);
1448
+ this._currentBatchingLayers[primitive] = layer;
1449
+ }
1450
+
1451
+ if (!edgeIndices) {
1452
+ edgeIndices = buildEdgeIndices(positions, indices, null, this._edgeThreshold);
1453
+ }
1454
+
1455
+ portionId = layer.createPortion({
1456
+ positions: positions,
1457
+ normals: cfg.normals,
1458
+ indices: indices,
1459
+ edgeIndices: edgeIndices,
1460
+ color: color,
1461
+ metallic: metallic,
1462
+ roughness: roughness,
1463
+ colors: cfg.colors,
1464
+ opacity: opacity,
1465
+ meshMatrix: meshMatrix,
1466
+ worldMatrix: worldMatrix,
1467
+ worldAABB: aabb,
1468
+ pickColor: pickColor
1469
+ });
1470
+
1471
+ const numTriangles = Math.round(indices.length / 3);
1472
+ this._numTriangles += numTriangles;
1473
+ mesh.numTriangles = numTriangles;
1474
+
1475
+ break;
1476
+
1477
+ case "lines":
1478
+
1479
+ if (layer) {
1480
+ if (!layer.canCreatePortion(positions.length, indices.length)) {
1481
+ layer.finalize();
1482
+ delete this._currentBatchingLayers[primitive];
1483
+ layer = null;
1484
+ }
1485
+ }
1486
+
1487
+ if (!layer) {
1488
+ layer = new LinesBatchingLayer(this, {
1489
+ layerIndex: 0, // This is set in #finalize()
1490
+ scratchMemory: this._scratchMemory,
1491
+ positionsDecodeMatrix: cfg.positionsDecodeMatrix, // Can be undefined
1492
+ rtcCenter: cfg.rtcCenter, // Can be undefined
1493
+ maxGeometryBatchSize: this._maxGeometryBatchSize
1494
+ });
1495
+ this._layerList.push(layer);
1496
+ this._currentBatchingLayers[primitive] = layer;
1497
+ }
1498
+
1499
+ portionId = layer.createPortion({
1500
+ positions: positions,
1501
+ indices: indices,
1502
+ color: color,
1503
+ colors: cfg.colors,
1504
+ opacity: opacity,
1505
+ meshMatrix: meshMatrix,
1506
+ worldMatrix: worldMatrix,
1507
+ worldAABB: aabb,
1508
+ pickColor: pickColor
1509
+ });
1510
+
1511
+ this._numLines += Math.round(indices.length / 2);
1512
+
1513
+ break;
1514
+
1515
+ case "points":
1516
+
1517
+ if (layer) {
1518
+ if (!layer.canCreatePortion(positions.length)) {
1519
+ layer.finalize();
1520
+ delete this._currentBatchingLayers[primitive];
1521
+ layer = null;
1522
+ }
1523
+ }
1524
+
1525
+ if (!layer) {
1526
+ layer = new PointsBatchingLayer(this, {
1527
+ layerIndex: 0, // This is set in #finalize()
1528
+ scratchMemory: this._scratchMemory,
1529
+ positionsDecodeMatrix: cfg.positionsDecodeMatrix, // Can be undefined
1530
+ rtcCenter: cfg.rtcCenter, // Can be undefined
1531
+ maxGeometryBatchSize: this._maxGeometryBatchSize
1532
+ });
1533
+ this._layerList.push(layer);
1534
+ this._currentBatchingLayers[primitive] = layer;
1535
+ }
1536
+
1537
+ portionId = layer.createPortion({
1538
+ positions: positions,
1539
+ color: color,
1540
+ colors: cfg.colors,
1541
+ opacity: opacity,
1542
+ meshMatrix: meshMatrix,
1543
+ worldMatrix: worldMatrix,
1544
+ worldAABB: aabb,
1545
+ pickColor: pickColor
1546
+ });
1547
+
1548
+ this._numPoints += Math.round(positions.length / 3);
1549
+
1550
+ break;
1551
+ }
1552
+
1553
+ math.expandAABB3(this._aabb, aabb);
1554
+
1555
+ this.numGeometries++;
1556
+
1557
+ mesh.rtcCenter = cfg.rtcCenter;
1558
+ }
1559
+
1560
+ mesh.parent = null; // Will be set within PerformanceModelNode constructor
1561
+ mesh._layer = layer;
1562
+ mesh._portionId = portionId;
1563
+ mesh.aabb = aabb;
1564
+
1565
+ this._meshes[id] = mesh;
1566
+ }
1567
+
1568
+ /**
1569
+ * Creates an {@link Entity} within this PerformanceModel, giving it one or more meshes previously created with {@link PerformanceModel#createMesh}.
1570
+ *
1571
+ * A mesh can only belong to one {@link Entity}, so you'll get an error if you try to reuse a mesh among multiple {@link Entity}s.
1572
+ *
1573
+ * @param {Object} cfg Entity configuration.
1574
+ * @param {String} cfg.id Optional ID for the new Entity. Must not clash with any existing components within the {@link Scene}.
1575
+ * @param {String[]} cfg.meshIds IDs of one or more meshes created previously with {@link PerformanceModel@createMesh}.
1576
+
1577
+ * @param {Boolean} [cfg.isObject] Set ````true```` if the {@link Entity} represents an object, in which case it will be registered by {@link Entity#id} in {@link Scene#objects} and can also have a corresponding {@link MetaObject} with matching {@link MetaObject#id}, registered by that ID in {@link MetaScene#metaObjects}.
1578
+ * @param {Boolean} [cfg.visible=true] Indicates if the Entity is initially visible.
1579
+ * @param {Boolean} [cfg.culled=false] Indicates if the Entity is initially culled from view.
1580
+ * @param {Boolean} [cfg.pickable=true] Indicates if the Entity is initially pickable.
1581
+ * @param {Boolean} [cfg.clippable=true] Indicates if the Entity is initially clippable.
1582
+ * @param {Boolean} [cfg.collidable=true] Indicates if the Entity is initially included in boundary calculations.
1583
+ * @param {Boolean} [cfg.castsShadow=true] Indicates if the Entity initially casts shadows.
1584
+ * @param {Boolean} [cfg.receivesShadow=true] Indicates if the Entity initially receives shadows.
1585
+ * @param {Boolean} [cfg.xrayed=false] Indicates if the Entity is initially xrayed. XRayed appearance is configured by {@link PerformanceModel#xrayMaterial}.
1586
+ * @param {Boolean} [cfg.highlighted=false] Indicates if the Entity is initially highlighted. Highlighted appearance is configured by {@link PerformanceModel#highlightMaterial}.
1587
+ * @param {Boolean} [cfg.selected=false] Indicates if the Entity is initially selected. Selected appearance is configured by {@link PerformanceModel#selectedMaterial}.
1588
+ * @param {Boolean} [cfg.edges=false] Indicates if the Entity's edges are initially emphasized. Edges appearance is configured by {@link PerformanceModel#edgeMaterial}.
1589
+ * @returns {Entity}
1590
+ */
1591
+ createEntity(cfg) {
1592
+ // Validate or generate Entity ID
1593
+ let id = cfg.id;
1594
+ let yjkElementId = cfg.yjkElementId;
1595
+ let yjkType = cfg.yjkType;
1596
+ let FlrID = cfg.FlrID;
1597
+
1598
+ // if (yjkElementId === undefined) {
1599
+ // console.log("YJKID: "+cfg.id);
1600
+ // console.log("yjkNodeId 未定义")
1601
+ // yjkElementId = 0;
1602
+ // }
1603
+ // if (yjkType === undefined) {
1604
+ // console.log("yjkType 未定义")
1605
+ // yjkType = "null";
1606
+ // }
1607
+ // if (FlrID === undefined) {
1608
+ // console.log("FlrID 未定义")
1609
+ // FlrID = "null";
1610
+ // }
1611
+
1612
+ if (id === undefined) {
1613
+ id = math.createUUID();
1614
+ } else if (this.scene.components[id]) {
1615
+ this.error("Scene already has a Component with this ID: " + id + " - will assign random ID");
1616
+ id = math.createUUID();
1617
+ }
1618
+ // Collect PerformanceModelNode's PerformanceModelMeshes
1619
+ const meshIds = cfg.meshIds;
1620
+ if (meshIds === undefined) {
1621
+ this.error("Config missing: meshIds");
1622
+ return;
1623
+ }
1624
+ let meshes = [];
1625
+ for (let i = 0, len = meshIds.length; i < len; i++) {
1626
+ const meshId = meshIds[i];
1627
+ const mesh = this._meshes[meshId];
1628
+ if (!mesh) {
1629
+ this.error("Mesh with this ID not found: " + meshId + " - ignoring this mesh");
1630
+ continue;
1631
+ }
1632
+ if (mesh.parent) {
1633
+ this.error("Mesh with ID " + meshId + " already belongs to object with ID " + mesh.parent.id + " - ignoring this mesh");
1634
+ continue;
1635
+ }
1636
+ meshes.push(mesh);
1637
+ }
1638
+ // Create PerformanceModelNode flags
1639
+ let flags = 0;
1640
+ if (this._visible && cfg.visible !== false) {
1641
+ flags = flags | ENTITY_FLAGS.VISIBLE;
1642
+ }
1643
+ if (this._pickable && cfg.pickable !== false) {
1644
+ flags = flags | ENTITY_FLAGS.PICKABLE;
1645
+ }
1646
+ if (this._culled && cfg.culled !== false) {
1647
+ flags = flags | ENTITY_FLAGS.CULLED;
1648
+ }
1649
+ if (this._clippable && cfg.clippable !== false) {
1650
+ flags = flags | ENTITY_FLAGS.CLIPPABLE;
1651
+ }
1652
+ if (this._collidable && cfg.collidable !== false) {
1653
+ flags = flags | ENTITY_FLAGS.COLLIDABLE;
1654
+ }
1655
+ if (this._edges && cfg.edges !== false) {
1656
+ flags = flags | ENTITY_FLAGS.EDGES;
1657
+ }
1658
+ if (this._xrayed && cfg.xrayed !== false) {
1659
+ flags = flags | ENTITY_FLAGS.XRAYED;
1660
+ }
1661
+ if (this._highlighted && cfg.highlighted !== false) {
1662
+ flags = flags | ENTITY_FLAGS.HIGHLIGHTED;
1663
+ }
1664
+ if (this._selected && cfg.selected !== false) {
1665
+ flags = flags | ENTITY_FLAGS.SELECTED;
1666
+ }
1667
+
1668
+ // Create PerformanceModelNode AABB
1669
+ let aabb;
1670
+ if (meshes.length === 1) {
1671
+ aabb = meshes[0].aabb;
1672
+ } else {
1673
+ aabb = math.collapseAABB3();
1674
+ for (let i = 0, len = meshes.length; i < len; i++) {
1675
+ math.expandAABB3(aabb, meshes[i].aabb);
1676
+ }
1677
+ }
1678
+
1679
+ // const node = new PerformanceNode(this, cfg.isObject, id, meshes, flags, aabb); // Internally sets PerformanceModelMesh#parent to this PerformanceModelNode
1680
+ const node = new PerformanceNode(this, cfg.isObject, id, yjkElementId, yjkType, FlrID, meshes, flags, aabb); // Internally sets PerformanceModelMesh#parent to this PerformanceModelNode
1681
+ this._nodeList.push(node);
1682
+ this._nodes[id] = node;
1683
+ this.numEntities++;
1684
+ return node;
1685
+ }
1686
+
1687
+ /**
1688
+ * Finalizes this PerformanceModel.
1689
+ *
1690
+ * Immediately creates the PerformanceModel's {@link Entity}s within the {@link Scene}.
1691
+ *
1692
+ * Once finalized, you can't add anything more to this PerformanceModel.
1693
+ */
1694
+ finalize() {
1695
+
1696
+ if (this.destroyed) {
1697
+ return;
1698
+ }
1699
+
1700
+ for (const geometryId in this._instancingLayers) {
1701
+ if (this._instancingLayers.hasOwnProperty(geometryId)) {
1702
+ this._instancingLayers[geometryId].finalize();
1703
+ }
1704
+ }
1705
+
1706
+ for (let primitive in this._currentBatchingLayers) {
1707
+ if (this._currentBatchingLayers.hasOwnProperty(primitive)) {
1708
+ this._currentBatchingLayers[primitive].finalize();
1709
+ }
1710
+ }
1711
+ this._currentBatchingLayers = {};
1712
+
1713
+ for (let i = 0, len = this._nodeList.length; i < len; i++) {
1714
+ const node = this._nodeList[i];
1715
+ node._finalize();
1716
+ }
1717
+
1718
+ // Sort layers to reduce WebGL shader switching when rendering them
1719
+
1720
+ this._layerList.sort((a, b) => {
1721
+ if (a.sortId < b.sortId) {
1722
+ return -1;
1723
+ }
1724
+ if (a.sortId > b.sortId) {
1725
+ return 1;
1726
+ }
1727
+ return 0;
1728
+ });
1729
+
1730
+ for (let i = 0, len = this._layerList.length; i < len; i++) {
1731
+ const layer = this._layerList[i];
1732
+ layer.layerIndex = i;
1733
+ }
1734
+
1735
+ this.glRedraw();
1736
+
1737
+ this.scene._aabbDirty = true;
1738
+ }
1739
+
1740
+ //------------------------------------------------------------------------------------------------------------------
1741
+ // PerformanceModel members
1742
+ //------------------------------------------------------------------------------------------------------------------
1743
+
1744
+ /**
1745
+ * Sets if backfaces are rendered for this PerformanceModel.
1746
+ *
1747
+ * Default is ````false````.
1748
+ *
1749
+ * When we set this ````true````, then backfaces are always rendered for this PerformanceModel.
1750
+ *
1751
+ * When we set this ````false````, then we allow the Viewer to decide whether to render backfaces. In this case,
1752
+ * the Viewer will:
1753
+ *
1754
+ * * hide backfaces on watertight meshes,
1755
+ * * show backfaces on open meshes, and
1756
+ * * always show backfaces on meshes when we slice them open with {@link SectionPlane}s.
1757
+ *
1758
+ * @type {Boolean}
1759
+ */
1760
+ set backfaces(backfaces) {
1761
+ backfaces = !!backfaces;
1762
+ this._backfaces = backfaces;
1763
+ this.glRedraw();
1764
+ }
1765
+
1766
+ /**
1767
+ * Sets if backfaces are rendered for this PerformanceModel.
1768
+ *
1769
+ * Default is ````false````.
1770
+ *
1771
+ * @type {Boolean}
1772
+ */
1773
+ get backfaces() {
1774
+ return this._backfaces;
1775
+ }
1776
+
1777
+ /**
1778
+ * Gets the list of {@link Entity}s within this PerformanceModel.
1779
+ *
1780
+ * @returns {Entity[]}
1781
+ */
1782
+ get entityList() {
1783
+ return this._nodeList;
1784
+ }
1785
+
1786
+ //------------------------------------------------------------------------------------------------------------------
1787
+ // Entity members
1788
+ //------------------------------------------------------------------------------------------------------------------
1789
+
1790
+ /**
1791
+ * Returns true to indicate that PerformanceModel is an {@link Entity}.
1792
+ * @type {Boolean}
1793
+ */
1794
+ get isEntity() {
1795
+ return true;
1796
+ }
1797
+
1798
+ /**
1799
+ * Returns ````true```` if this PerformanceModel represents a model.
1800
+ *
1801
+ * When ````true```` the PerformanceModel will be registered by {@link PerformanceModel#id} in
1802
+ * {@link Scene#models} and may also have a {@link MetaObject} with matching {@link MetaObject#id}.
1803
+ *
1804
+ * @type {Boolean}
1805
+ */
1806
+ get isModel() {
1807
+ return this._isModel;
1808
+ }
1809
+
1810
+ /**
1811
+ * Returns ````false```` to indicate that PerformanceModel never represents an object.
1812
+ *
1813
+ * @type {Boolean}
1814
+ */
1815
+ get isObject() {
1816
+ return false;
1817
+ }
1818
+
1819
+ /**
1820
+ * Gets the PerformanceModel's World-space 3D axis-aligned bounding box.
1821
+ *
1822
+ * Represented by a six-element Float64Array containing the min/max extents of the
1823
+ * axis-aligned volume, ie. ````[xmin, ymin,zmin,xmax,ymax, zmax]````.
1824
+ *
1825
+ * @type {Number[]}
1826
+ */
1827
+ get aabb() {
1828
+ if (this._aabbDirty) {
1829
+ this._rebuildAABB();
1830
+ }
1831
+ return this._aabb;
1832
+ }
1833
+
1834
+ _rebuildAABB() {
1835
+ math.collapseAABB3(this._aabb);
1836
+ for (let i = 0, len = this._nodeList.length; i < len; i++) {
1837
+ const node = this._nodeList[i];
1838
+ math.expandAABB3(this._aabb, node.aabb);
1839
+ }
1840
+ this._aabbDirty = false;
1841
+ }
1842
+
1843
+ /**
1844
+ * The approximate number of triangle primitives in this PerformanceModel.
1845
+ *
1846
+ * @type {Number}
1847
+ */
1848
+ get numTriangles() {
1849
+ return this._numTriangles;
1850
+ }
1851
+
1852
+ /**
1853
+ * The approximate number of line primitives in this PerformanceModel.
1854
+ *
1855
+ * @type {Number}
1856
+ */
1857
+ get numLines() {
1858
+ return this._numLines;
1859
+ }
1860
+
1861
+ /**
1862
+ * The approximate number of point primitives in this PerformanceModel.
1863
+ *
1864
+ * @type {Number}
1865
+ */
1866
+ get numPoints() {
1867
+ return this._numPoints;
1868
+ }
1869
+
1870
+ /**
1871
+ * Sets if this PerformanceModel is visible.
1872
+ *
1873
+ * The PerformanceModel is only rendered when {@link PerformanceModel#visible} is ````true```` and {@link PerformanceModel#culled} is ````false````.
1874
+ **
1875
+ * @type {Boolean}
1876
+ */
1877
+ set visible(visible) {
1878
+ visible = visible !== false;
1879
+ this._visible = visible;
1880
+ for (let i = 0, len = this._nodeList.length; i < len; i++) {
1881
+ this._nodeList[i].visible = visible;
1882
+ }
1883
+ this.glRedraw();
1884
+ }
1885
+
1886
+ /**
1887
+ * Gets if any {@link Entity}s in this PerformanceModel are visible.
1888
+ *
1889
+ * The PerformanceModel is only rendered when {@link PerformanceModel#visible} is ````true```` and {@link PerformanceModel#culled} is ````false````.
1890
+ *
1891
+ * @type {Boolean}
1892
+ */
1893
+ get visible() {
1894
+ return (this.numVisibleLayerPortions > 0);
1895
+ }
1896
+
1897
+ /**
1898
+ * Sets if all {@link Entity}s in this PerformanceModel are xrayed.
1899
+ *
1900
+ * @type {Boolean}
1901
+ */
1902
+ set xrayed(xrayed) {
1903
+ xrayed = !!xrayed;
1904
+ this._xrayed = xrayed;
1905
+ for (let i = 0, len = this._nodeList.length; i < len; i++) {
1906
+ this._nodeList[i].xrayed = xrayed;
1907
+ }
1908
+ this.glRedraw();
1909
+ }
1910
+
1911
+ /**
1912
+ * Gets if any {@link Entity}s in this PerformanceModel are xrayed.
1913
+ *
1914
+ * @type {Boolean}
1915
+ */
1916
+ get xrayed() {
1917
+ return (this.numXRayedLayerPortions > 0);
1918
+ }
1919
+
1920
+ /**
1921
+ * Sets if all {@link Entity}s in this PerformanceModel are highlighted.
1922
+ *
1923
+ * @type {Boolean}
1924
+ */
1925
+ set highlighted(highlighted) {
1926
+ highlighted = !!highlighted;
1927
+ this._highlighted = highlighted;
1928
+ for (let i = 0, len = this._nodeList.length; i < len; i++) {
1929
+ this._nodeList[i].highlighted = highlighted;
1930
+ }
1931
+ this.glRedraw();
1932
+ }
1933
+
1934
+ /**
1935
+ * Gets if any {@link Entity}s in this PerformanceModel are highlighted.
1936
+ *
1937
+ * @type {Boolean}
1938
+ */
1939
+ get highlighted() {
1940
+ return (this.numHighlightedLayerPortions > 0);
1941
+ }
1942
+
1943
+ /**
1944
+ * Sets if all {@link Entity}s in this PerformanceModel are selected.
1945
+ *
1946
+ * @type {Boolean}
1947
+ */
1948
+ set selected(selected) {
1949
+ selected = !!selected;
1950
+ this._selected = selected;
1951
+ for (let i = 0, len = this._nodeList.length; i < len; i++) {
1952
+ this._nodeList[i].selected = selected;
1953
+ }
1954
+ this.glRedraw();
1955
+ }
1956
+
1957
+ /**
1958
+ * Gets if any {@link Entity}s in this PerformanceModel are selected.
1959
+ *
1960
+ * @type {Boolean}
1961
+ */
1962
+ get selected() {
1963
+ return (this.numSelectedLayerPortions > 0);
1964
+ }
1965
+
1966
+ /**
1967
+ * Sets if all {@link Entity}s in this PerformanceModel have edges emphasised.
1968
+ *
1969
+ * @type {Boolean}
1970
+ */
1971
+ set edges(edges) {
1972
+ edges = !!edges;
1973
+ this._edges = edges;
1974
+ for (let i = 0, len = this._nodeList.length; i < len; i++) {
1975
+ this._nodeList[i].edges = edges;
1976
+ }
1977
+ this.glRedraw();
1978
+ }
1979
+
1980
+ /**
1981
+ * Gets if any {@link Entity}s in this PerformanceModel have edges emphasised.
1982
+ *
1983
+ * @type {Boolean}
1984
+ */
1985
+ get edges() {
1986
+ return (this.numEdgesLayerPortions > 0);
1987
+ }
1988
+
1989
+ /**
1990
+ * Sets if this PerformanceModel is culled from view.
1991
+ *
1992
+ * The PerformanceModel is only rendered when {@link PerformanceModel#visible} is true and {@link PerformanceModel#culled} is false.
1993
+ *
1994
+ * @type {Boolean}
1995
+ */
1996
+ set culled(culled) {
1997
+ culled = !!culled;
1998
+ this._culled = culled;
1999
+ for (let i = 0, len = this._nodeList.length; i < len; i++) {
2000
+ this._nodeList[i].culled = culled;
2001
+ }
2002
+ this.glRedraw();
2003
+ }
2004
+
2005
+ /**
2006
+ * Gets if this PerformanceModel is culled from view.
2007
+ *
2008
+ * The PerformanceModel is only rendered when {@link PerformanceModel#visible} is true and {@link PerformanceModel#culled} is false.
2009
+ *
2010
+ * @type {Boolean}
2011
+ */
2012
+ get culled() {
2013
+ return this._culled;
2014
+ }
2015
+
2016
+ /**
2017
+ * Sets if {@link Entity}s in this PerformanceModel are clippable.
2018
+ *
2019
+ * Clipping is done by the {@link SectionPlane}s in {@link Scene#sectionPlanes}.
2020
+ *
2021
+ * @type {Boolean}
2022
+ */
2023
+ set clippable(clippable) {
2024
+ clippable = clippable !== false;
2025
+ this._clippable = clippable;
2026
+ for (let i = 0, len = this._nodeList.length; i < len; i++) {
2027
+ this._nodeList[i].clippable = clippable;
2028
+ }
2029
+ this.glRedraw();
2030
+ }
2031
+
2032
+ /**
2033
+ * Gets if {@link Entity}s in this PerformanceModel are clippable.
2034
+ *
2035
+ * Clipping is done by the {@link SectionPlane}s in {@link Scene#sectionPlanes}.
2036
+ *
2037
+ * @type {Boolean}
2038
+ */
2039
+ get clippable() {
2040
+ return this._clippable;
2041
+ }
2042
+
2043
+ /**
2044
+ * Sets if {@link Entity}s in this PerformanceModel are collidable.
2045
+ *
2046
+ * @type {Boolean}
2047
+ */
2048
+ set collidable(collidable) {
2049
+ collidable = collidable !== false;
2050
+ this._collidable = collidable;
2051
+ for (let i = 0, len = this._nodeList.length; i < len; i++) {
2052
+ this._nodeList[i].collidable = collidable;
2053
+ }
2054
+ }
2055
+
2056
+ /**
2057
+ * Gets if this PerformanceModel is collidable.
2058
+ *
2059
+ * @type {Boolean}
2060
+ */
2061
+ get collidable() {
2062
+ return this._collidable;
2063
+ }
2064
+
2065
+ /**
2066
+ * Sets if {@link Entity}s in this PerformanceModel are pickable.
2067
+ *
2068
+ * Picking is done via calls to {@link Scene#pick}.
2069
+ *
2070
+ * @type {Boolean}
2071
+ */
2072
+ set pickable(pickable) {
2073
+ pickable = pickable !== false;
2074
+ this._pickable = pickable;
2075
+ for (let i = 0, len = this._nodeList.length; i < len; i++) {
2076
+ this._nodeList[i].pickable = pickable;
2077
+ }
2078
+ }
2079
+
2080
+ /**
2081
+ * Gets if this PerformanceModel is pickable.
2082
+ *
2083
+ * Picking is done via calls to {@link Scene#pick}.
2084
+ *
2085
+ * @type {Boolean}
2086
+ */
2087
+ get pickable() {
2088
+ return (this.numPickableLayerPortions > 0);
2089
+ }
2090
+
2091
+ /**
2092
+ * Sets the RGB colorize color for this PerformanceModel.
2093
+ *
2094
+ * Multiplies by rendered fragment colors.
2095
+ *
2096
+ * Each element of the color is in range ````[0..1]````.
2097
+ *
2098
+ * @type {Number[]}
2099
+ */
2100
+ set colorize(colorize) {
2101
+ this._colorize = colorize;
2102
+ for (let i = 0, len = this._nodeList.length; i < len; i++) {
2103
+ this._nodeList[i].colorize = colorize;
2104
+ }
2105
+ }
2106
+
2107
+ /**
2108
+ * Gets the RGB colorize color for this PerformanceModel.
2109
+ *
2110
+ * Each element of the color is in range ````[0..1]````.
2111
+ *
2112
+ * @type {Number[]}
2113
+ */
2114
+ get colorize() {
2115
+ return this._colorize;
2116
+ }
2117
+
2118
+ /**
2119
+ * Sets the opacity factor for this PerformanceModel.
2120
+ *
2121
+ * This is a factor in range ````[0..1]```` which multiplies by the rendered fragment alphas.
2122
+ *
2123
+ * @type {Number}
2124
+ */
2125
+ set opacity(opacity) {
2126
+ this._opacity = opacity;
2127
+ for (let i = 0, len = this._nodeList.length; i < len; i++) {
2128
+ this._nodeList[i].opacity = opacity;
2129
+ }
2130
+ }
2131
+
2132
+ /**
2133
+ * Gets this PerformanceModel's opacity factor.
2134
+ *
2135
+ * This is a factor in range ````[0..1]```` which multiplies by the rendered fragment alphas.
2136
+ *
2137
+ * @type {Number}
2138
+ */
2139
+ get opacity() {
2140
+ return this._opacity;
2141
+ }
2142
+
2143
+ /**
2144
+ * Sets if this PerformanceModel casts a shadow.
2145
+ *
2146
+ * @type {Boolean}
2147
+ */
2148
+ set castsShadow(castsShadow) {
2149
+ castsShadow = (castsShadow !== false);
2150
+ if (castsShadow !== this._castsShadow) {
2151
+ this._castsShadow = castsShadow;
2152
+ this.glRedraw();
2153
+ }
2154
+ }
2155
+
2156
+ /**
2157
+ * Gets if this PerformanceModel casts a shadow.
2158
+ *
2159
+ * @type {Boolean}
2160
+ */
2161
+ get castsShadow() {
2162
+ return this._castsShadow;
2163
+ }
2164
+
2165
+ /**
2166
+ * Sets if this PerformanceModel can have shadow cast upon it.
2167
+ *
2168
+ * @type {Boolean}
2169
+ */
2170
+ set receivesShadow(receivesShadow) {
2171
+ receivesShadow = (receivesShadow !== false);
2172
+ if (receivesShadow !== this._receivesShadow) {
2173
+ this._receivesShadow = receivesShadow;
2174
+ this.glRedraw();
2175
+ }
2176
+ }
2177
+
2178
+ /**
2179
+ * Sets if this PerformanceModel can have shadow cast upon it.
2180
+ *
2181
+ * @type {Boolean}
2182
+ */
2183
+ get receivesShadow() {
2184
+ return this._receivesShadow;
2185
+ }
2186
+
2187
+ /**
2188
+ * Gets if Scalable Ambient Obscurance (SAO) will apply to this PerformanceModel.
2189
+ *
2190
+ * SAO is configured by the Scene's {@link SAO} component.
2191
+ *
2192
+ * Only works when {@link SAO#enabled} is also true.
2193
+ *
2194
+ * @type {Boolean}
2195
+ */
2196
+ get saoEnabled() {
2197
+ return this._saoEnabled;
2198
+ }
2199
+
2200
+ /**
2201
+ * Gets if physically-based rendering (PBR) is enabled for this PerformanceModel.
2202
+ *
2203
+ * Only works when {@link Scene#pbrEnabled} is also true.
2204
+ *
2205
+ * @type {Boolean}
2206
+ */
2207
+ get pbrEnabled() {
2208
+ return this._pbrEnabled;
2209
+ }
2210
+
2211
+ //------------------------------------------------------------------------------------------------------------------
2212
+ // Drawable members
2213
+ //------------------------------------------------------------------------------------------------------------------
2214
+
2215
+ /**
2216
+ * Returns true to indicate that PerformanceModel is implements {@link Drawable}.
2217
+ *
2218
+ * @type {Boolean}
2219
+ */
2220
+ get isDrawable() {
2221
+ return true;
2222
+ }
2223
+
2224
+ /** @private */
2225
+ get isStateSortable() {
2226
+ return false
2227
+ }
2228
+
2229
+ /** @private */
2230
+ stateSortCompare(drawable1, drawable2) {}
2231
+
2232
+ /** @private */
2233
+ rebuildRenderFlags() {
2234
+ this.renderFlags.reset();
2235
+ this._updateRenderFlagsVisibleLayers();
2236
+ if (this.renderFlags.numLayers > 0 && this.renderFlags.numVisibleLayers === 0) {
2237
+ this.renderFlags.culled = true;
2238
+ return;
2239
+ }
2240
+ this._updateRenderFlags();
2241
+ }
2242
+
2243
+ /**
2244
+ * @private
2245
+ */
2246
+ _updateRenderFlagsVisibleLayers() {
2247
+ const renderFlags = this.renderFlags;
2248
+ renderFlags.numLayers = this._layerList.length;
2249
+ renderFlags.numVisibleLayers = 0;
2250
+ for (let layerIndex = 0, len = this._layerList.length; layerIndex < len; layerIndex++) {
2251
+ const layer = this._layerList[layerIndex];
2252
+ const layerVisible = this._getActiveSectionPlanesForLayer(layer);
2253
+ if (layerVisible) {
2254
+ renderFlags.visibleLayers[renderFlags.numVisibleLayers++] = layerIndex;
2255
+ }
2256
+ }
2257
+ }
2258
+
2259
+ /** @private */
2260
+ _getActiveSectionPlanesForLayer(layer) {
2261
+
2262
+ const renderFlags = this.renderFlags;
2263
+ const sectionPlanes = this.scene._sectionPlanesState.sectionPlanes;
2264
+ const numSectionPlanes = sectionPlanes.length;
2265
+ const baseIndex = layer.layerIndex * numSectionPlanes;
2266
+
2267
+ if (numSectionPlanes > 0) {
2268
+ for (let i = 0; i < numSectionPlanes; i++) {
2269
+
2270
+ const sectionPlane = sectionPlanes[i];
2271
+
2272
+ if (!sectionPlane.active) {
2273
+ renderFlags.sectionPlanesActivePerLayer[baseIndex + i] = false;
2274
+
2275
+ } else {
2276
+ renderFlags.sectionPlanesActivePerLayer[baseIndex + i] = true;
2277
+ renderFlags.sectioned = true;
2278
+ }
2279
+ }
2280
+ }
2281
+
2282
+ return true;
2283
+ }
2284
+
2285
+ /** @private */
2286
+ _updateRenderFlags() {
2287
+
2288
+ if (this.numVisibleLayerPortions === 0) {
2289
+ return;
2290
+ }
2291
+
2292
+ if (this.numCulledLayerPortions === this.numPortions) {
2293
+ return;
2294
+ }
2295
+
2296
+ const renderFlags = this.renderFlags;
2297
+
2298
+ renderFlags.colorOpaque = (this.numTransparentLayerPortions < this.numPortions);
2299
+
2300
+ if (this.numTransparentLayerPortions > 0) {
2301
+ renderFlags.colorTransparent = true;
2302
+ }
2303
+
2304
+ if (this.numXRayedLayerPortions > 0) {
2305
+ const xrayMaterial = this.scene.xrayMaterial._state;
2306
+ if (xrayMaterial.fill) {
2307
+ if (xrayMaterial.fillAlpha < 1.0) {
2308
+ renderFlags.xrayedSilhouetteTransparent = true;
2309
+ } else {
2310
+ renderFlags.xrayedSilhouetteOpaque = true;
2311
+ }
2312
+ }
2313
+ if (xrayMaterial.edges) {
2314
+ if (xrayMaterial.edgeAlpha < 1.0) {
2315
+ renderFlags.xrayedEdgesTransparent = true;
2316
+ } else {
2317
+ renderFlags.xrayedEdgesOpaque = true;
2318
+ }
2319
+ }
2320
+ }
2321
+
2322
+ if (this.numEdgesLayerPortions > 0) {
2323
+ const edgeMaterial = this.scene.edgeMaterial._state;
2324
+ if (edgeMaterial.edges) {
2325
+ renderFlags.edgesOpaque = (this.numTransparentLayerPortions < this.numPortions);
2326
+ if (this.numTransparentLayerPortions > 0) {
2327
+ renderFlags.edgesTransparent = true;
2328
+ }
2329
+ }
2330
+ }
2331
+
2332
+ if (this.numSelectedLayerPortions > 0) {
2333
+ const selectedMaterial = this.scene.selectedMaterial._state;
2334
+ if (selectedMaterial.fill) {
2335
+ if (selectedMaterial.fillAlpha < 1.0) {
2336
+ renderFlags.selectedSilhouetteTransparent = true;
2337
+ } else {
2338
+ renderFlags.selectedSilhouetteOpaque = true;
2339
+ }
2340
+ }
2341
+ if (selectedMaterial.edges) {
2342
+ if (selectedMaterial.edgeAlpha < 1.0) {
2343
+ renderFlags.selectedEdgesTransparent = true;
2344
+ } else {
2345
+ renderFlags.selectedEdgesOpaque = true;
2346
+ }
2347
+ }
2348
+ }
2349
+
2350
+ if (this.numHighlightedLayerPortions > 0) {
2351
+ const highlightMaterial = this.scene.highlightMaterial._state;
2352
+ if (highlightMaterial.fill) {
2353
+ if (highlightMaterial.fillAlpha < 1.0) {
2354
+ renderFlags.highlightedSilhouetteTransparent = true;
2355
+ } else {
2356
+ renderFlags.highlightedSilhouetteOpaque = true;
2357
+ }
2358
+ }
2359
+ if (highlightMaterial.edges) {
2360
+ if (highlightMaterial.edgeAlpha < 1.0) {
2361
+ renderFlags.highlightedEdgesTransparent = true;
2362
+ } else {
2363
+ renderFlags.highlightedEdgesOpaque = true;
2364
+ }
2365
+ }
2366
+ }
2367
+ }
2368
+
2369
+ /**
2370
+ * Configures the appearance of xrayed {@link Entity}s within this PerformanceModel.
2371
+ *
2372
+ * This is the {@link Scene#xrayMaterial}.
2373
+ *
2374
+ * @type {EmphasisMaterial}
2375
+ */
2376
+ get xrayMaterial() {
2377
+ return this.scene.xrayMaterial;
2378
+ }
2379
+
2380
+ /**
2381
+ * Configures the appearance of highlighted {@link Entity}s within this PerformanceModel.
2382
+ *
2383
+ * This is the {@link Scene#highlightMaterial}.
2384
+ *
2385
+ * @type {EmphasisMaterial}
2386
+ */
2387
+ get highlightMaterial() {
2388
+ return this.scene.highlightMaterial;
2389
+ }
2390
+
2391
+ /**
2392
+ * Configures the appearance of selected {@link Entity}s within this PerformanceModel.
2393
+ *
2394
+ * This is the {@link Scene#selectedMaterial}.
2395
+ *
2396
+ * @type {EmphasisMaterial}
2397
+ */
2398
+ get selectedMaterial() {
2399
+ return this.scene.selectedMaterial;
2400
+ }
2401
+
2402
+ /**
2403
+ * Configures the appearance of edges of {@link Entity}s within this PerformanceModel.
2404
+ *
2405
+ * This is the {@link Scene#edgeMaterial}.
2406
+ *
2407
+ * @type {EdgeMaterial}
2408
+ */
2409
+ get edgeMaterial() {
2410
+ return this.scene.edgeMaterial;
2411
+ }
2412
+
2413
+ // -------------- RENDERING ---------------------------------------------------------------------------------------
2414
+
2415
+ /** @private */
2416
+ drawColorOpaque(frameCtx) {
2417
+ const renderFlags = this.renderFlags;
2418
+ for (let i = 0, len = renderFlags.visibleLayers.length; i < len; i++) {
2419
+ const layerIndex = renderFlags.visibleLayers[i];
2420
+ this._layerList[layerIndex].drawColorOpaque(renderFlags, frameCtx);
2421
+ }
2422
+ }
2423
+
2424
+ /** @private */
2425
+ drawColorTransparent(frameCtx) {
2426
+ const renderFlags = this.renderFlags;
2427
+ for (let i = 0, len = renderFlags.visibleLayers.length; i < len; i++) {
2428
+ const layerIndex = renderFlags.visibleLayers[i];
2429
+ this._layerList[layerIndex].drawColorTransparent(renderFlags, frameCtx);
2430
+ }
2431
+ }
2432
+
2433
+ /** @private */
2434
+ drawDepth(frameCtx) { // Dedicated to SAO because it skips transparent objects
2435
+ const renderFlags = this.renderFlags;
2436
+ for (let i = 0, len = renderFlags.visibleLayers.length; i < len; i++) {
2437
+ const layerIndex = renderFlags.visibleLayers[i];
2438
+ this._layerList[layerIndex].drawDepth(renderFlags, frameCtx);
2439
+ }
2440
+ }
2441
+
2442
+ /** @private */
2443
+ drawNormals(frameCtx) { // Dedicated to SAO because it skips transparent objects
2444
+ const renderFlags = this.renderFlags;
2445
+ for (let i = 0, len = renderFlags.visibleLayers.length; i < len; i++) {
2446
+ const layerIndex = renderFlags.visibleLayers[i];
2447
+ this._layerList[layerIndex].drawNormals(renderFlags, frameCtx);
2448
+ }
2449
+ }
2450
+
2451
+ /** @private */
2452
+ drawSilhouetteXRayed(frameCtx) {
2453
+ const renderFlags = this.renderFlags;
2454
+ for (let i = 0, len = renderFlags.visibleLayers.length; i < len; i++) {
2455
+ const layerIndex = renderFlags.visibleLayers[i];
2456
+ this._layerList[layerIndex].drawSilhouetteXRayed(renderFlags, frameCtx);
2457
+ }
2458
+ }
2459
+
2460
+ /** @private */
2461
+ drawSilhouetteHighlighted(frameCtx) {
2462
+ const renderFlags = this.renderFlags;
2463
+ for (let i = 0, len = renderFlags.visibleLayers.length; i < len; i++) {
2464
+ const layerIndex = renderFlags.visibleLayers[i];
2465
+ this._layerList[layerIndex].drawSilhouetteHighlighted(renderFlags, frameCtx);
2466
+ }
2467
+ }
2468
+
2469
+ /** @private */
2470
+ drawSilhouetteSelected(frameCtx) {
2471
+ const renderFlags = this.renderFlags;
2472
+ for (let i = 0, len = renderFlags.visibleLayers.length; i < len; i++) {
2473
+ const layerIndex = renderFlags.visibleLayers[i];
2474
+ this._layerList[layerIndex].drawSilhouetteSelected(renderFlags, frameCtx);
2475
+ }
2476
+ }
2477
+
2478
+ /** @private */
2479
+ drawEdgesColorOpaque(frameCtx) {
2480
+ const renderFlags = this.renderFlags;
2481
+ for (let i = 0, len = renderFlags.visibleLayers.length; i < len; i++) {
2482
+ const layerIndex = renderFlags.visibleLayers[i];
2483
+ this._layerList[layerIndex].drawEdgesColorOpaque(renderFlags, frameCtx);
2484
+ }
2485
+ }
2486
+
2487
+ /** @private */
2488
+ drawEdgesColorTransparent(frameCtx) {
2489
+ const renderFlags = this.renderFlags;
2490
+ for (let i = 0, len = renderFlags.visibleLayers.length; i < len; i++) {
2491
+ const layerIndex = renderFlags.visibleLayers[i];
2492
+ this._layerList[layerIndex].drawEdgesColorTransparent(renderFlags, frameCtx);
2493
+ }
2494
+ }
2495
+
2496
+ /** @private */
2497
+ drawEdgesXRayed(frameCtx) {
2498
+ const renderFlags = this.renderFlags;
2499
+ for (let i = 0, len = renderFlags.visibleLayers.length; i < len; i++) {
2500
+ const layerIndex = renderFlags.visibleLayers[i];
2501
+ this._layerList[layerIndex].drawEdgesXRayed(renderFlags, frameCtx);
2502
+ }
2503
+ }
2504
+
2505
+ /** @private */
2506
+ drawEdgesHighlighted(frameCtx) {
2507
+ const renderFlags = this.renderFlags;
2508
+ for (let i = 0, len = renderFlags.visibleLayers.length; i < len; i++) {
2509
+ const layerIndex = renderFlags.visibleLayers[i];
2510
+ this._layerList[layerIndex].drawEdgesHighlighted(renderFlags, frameCtx);
2511
+ }
2512
+ }
2513
+
2514
+ /** @private */
2515
+ drawEdgesSelected(frameCtx) {
2516
+ const renderFlags = this.renderFlags;
2517
+ for (let i = 0, len = renderFlags.visibleLayers.length; i < len; i++) {
2518
+ const layerIndex = renderFlags.visibleLayers[i];
2519
+ this._layerList[layerIndex].drawEdgesSelected(renderFlags, frameCtx);
2520
+ }
2521
+ }
2522
+
2523
+ /**
2524
+ * @private
2525
+ */
2526
+ drawOcclusion(frameCtx) {
2527
+ if (this.numVisibleLayerPortions === 0) {
2528
+ return;
2529
+ }
2530
+ const renderFlags = this.renderFlags;
2531
+ for (let i = 0, len = renderFlags.visibleLayers.length; i < len; i++) {
2532
+ const layerIndex = renderFlags.visibleLayers[i];
2533
+ this._layerList[layerIndex].drawOcclusion(renderFlags, frameCtx);
2534
+ }
2535
+ }
2536
+
2537
+ /**
2538
+ * @private
2539
+ */
2540
+ drawShadow(frameCtx) {
2541
+ if (this.numVisibleLayerPortions === 0) {
2542
+ return;
2543
+ }
2544
+ const renderFlags = this.renderFlags;
2545
+ for (let i = 0, len = renderFlags.visibleLayers.length; i < len; i++) {
2546
+ const layerIndex = renderFlags.visibleLayers[i];
2547
+ this._layerList[layerIndex].drawShadow(renderFlags, frameCtx);
2548
+ }
2549
+ }
2550
+
2551
+ /** @private */
2552
+ drawPickMesh(frameCtx) {
2553
+ if (this.numVisibleLayerPortions === 0) {
2554
+ return;
2555
+ }
2556
+ const renderFlags = this.renderFlags;
2557
+ for (let i = 0, len = renderFlags.visibleLayers.length; i < len; i++) {
2558
+ const layerIndex = renderFlags.visibleLayers[i];
2559
+ this._layerList[layerIndex].drawPickMesh(renderFlags, frameCtx);
2560
+ }
2561
+ }
2562
+
2563
+ /**
2564
+ * Called by PerformanceMesh.drawPickDepths()
2565
+ * @private
2566
+ */
2567
+ drawPickDepths(frameCtx) {
2568
+ if (this.numVisibleLayerPortions === 0) {
2569
+ return;
2570
+ }
2571
+ const renderFlags = this.renderFlags;
2572
+ for (let i = 0, len = renderFlags.visibleLayers.length; i < len; i++) {
2573
+ const layerIndex = renderFlags.visibleLayers[i];
2574
+ this._layerList[layerIndex].drawPickDepths(renderFlags, frameCtx);
2575
+ }
2576
+ }
2577
+
2578
+ /**
2579
+ * Called by PerformanceMesh.drawPickNormals()
2580
+ * @private
2581
+ */
2582
+ drawPickNormals(frameCtx) {
2583
+ if (this.numVisibleLayerPortions === 0) {
2584
+ return;
2585
+ }
2586
+ const renderFlags = this.renderFlags;
2587
+ for (let i = 0, len = renderFlags.visibleLayers.length; i < len; i++) {
2588
+ const layerIndex = renderFlags.visibleLayers[i];
2589
+ this._layerList[layerIndex].drawPickNormals(renderFlags, frameCtx);
2590
+ }
2591
+ }
2592
+
2593
+ //------------------------------------------------------------------------------------------------------------------
2594
+ // Component members
2595
+ //------------------------------------------------------------------------------------------------------------------
2596
+
2597
+ /**
2598
+ * Destroys this PerformanceModel.
2599
+ */
2600
+ destroy() {
2601
+ for (let primitive in this._currentBatchingLayers) {
2602
+ if (this._currentBatchingLayers.hasOwnProperty(primitive)) {
2603
+ this._currentBatchingLayers[primitive].destroy();
2604
+ }
2605
+ }
2606
+ this._currentBatchingLayers = {};
2607
+ this.scene.camera.off(this._onCameraViewMatrix);
2608
+ for (let i = 0, len = this._layerList.length; i < len; i++) {
2609
+ this._layerList[i].destroy();
2610
+ }
2611
+ for (let i = 0, len = this._nodeList.length; i < len; i++) {
2612
+ this._nodeList[i]._destroy();
2613
+ }
2614
+ this.scene._aabbDirty = true;
2615
+ if (this._isModel) {
2616
+ this.scene._deregisterModel(this);
2617
+ }
2618
+ putScratchMemory();
2619
+ super.destroy();
2620
+ }
2621
+ }
2622
+
2623
+ export { PerformanceModel };