ohzi-core 12.5.2 → 12.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (265) hide show
  1. package/README.md +9 -9
  2. package/build/index.mjs +1 -1
  3. package/build/index.mjs.map +1 -1
  4. package/build/index.module.js +2 -0
  5. package/build/index.module.js.map +1 -0
  6. package/package.json +64 -63
  7. package/src/.vscode/settings.json +2 -2
  8. package/src/BaseApplication.js +40 -40
  9. package/src/Browser.js +119 -119
  10. package/src/CameraManager.js +37 -37
  11. package/src/Capabilities.js +13 -13
  12. package/src/CustomBezierCurve.js +58 -58
  13. package/src/Debug.js +359 -359
  14. package/src/Graphics.js +507 -507
  15. package/src/Initializer.js +56 -56
  16. package/src/KeyboardInput.js +177 -177
  17. package/src/OS.js +59 -59
  18. package/src/OScreen.js +90 -90
  19. package/src/OrthographicCamera.js +36 -36
  20. package/src/PerspectiveCamera.js +34 -34
  21. package/src/ReflectionPlaneContext.js +22 -22
  22. package/src/RenderLayers.js +30 -30
  23. package/src/RenderLoop.js +125 -122
  24. package/src/RenderOrder.js +40 -40
  25. package/src/ResourceContainer.js +57 -57
  26. package/src/SceneManager.js +55 -55
  27. package/src/Screen.js +71 -71
  28. package/src/Time.js +99 -98
  29. package/src/UI.js +106 -106
  30. package/src/action_sequencer/ActionEvent.js +22 -22
  31. package/src/action_sequencer/ActionInterpolator.js +39 -39
  32. package/src/action_sequencer/ActionSequencer.js +338 -338
  33. package/src/action_sequencer/NumberInterpolator.js +42 -42
  34. package/src/action_sequencer/VectorInterpolator.js +34 -34
  35. package/src/blitter_index.js +14 -14
  36. package/src/canvas_drawer/CanvasDrawer.js +146 -146
  37. package/src/canvas_drawer/MultiLineTextDrawer.js +58 -58
  38. package/src/canvas_drawer/SimpleTextDrawer.js +55 -55
  39. package/src/components/AudioClip.js +67 -67
  40. package/src/components/AxisHelper.js +60 -60
  41. package/src/components/BaseObject.js +50 -50
  42. package/src/components/EdgeMesh.js +172 -172
  43. package/src/components/GeometryEdgeVisualizer.js +57 -57
  44. package/src/components/Grid.js +40 -40
  45. package/src/components/Line.js +225 -225
  46. package/src/components/MultiLinePath.js +25 -25
  47. package/src/components/MultiLineText2D.js +75 -75
  48. package/src/components/ObjectAxis.js +27 -27
  49. package/src/components/ObjectOrientedBoundingBox.js +228 -228
  50. package/src/components/PlaneHelper.js +38 -38
  51. package/src/components/Shape2D.js +52 -52
  52. package/src/components/Shape3D.js +46 -46
  53. package/src/components/Text2D.js +49 -49
  54. package/src/components/UIElement.js +246 -246
  55. package/src/components/UpdatableMaterialMesh.js +26 -26
  56. package/src/components/WorldImage.js +101 -101
  57. package/src/components/mouse_interactors/ObjectRotator.js +64 -64
  58. package/src/components/sdf_text/SDFText.js +156 -156
  59. package/src/components/sdf_text/SDFTextBatch.js +195 -195
  60. package/src/components/sdf_text/TextGlyph.js +17 -17
  61. package/src/data_textures/CustomDataTexture.js +53 -53
  62. package/src/data_textures/RGBADataTexture.js +14 -14
  63. package/src/data_textures/RGBAFloatDataTexture.js +14 -14
  64. package/src/data_textures/RGBDataTexture.js +14 -14
  65. package/src/data_textures/RGBFloatDataTexture.js +13 -13
  66. package/src/editor/ManipulatorHandle.js +73 -73
  67. package/src/editor/ObjectEditor.js +68 -68
  68. package/src/editor/ObjectManipulator.js +112 -112
  69. package/src/editor/ObjectPicker.js +77 -77
  70. package/src/editor/shaders/object_picker.frag +5 -5
  71. package/src/editor/shaders/object_picker.vert +7 -7
  72. package/src/gpu_particles/GPUParticleSystem.js +111 -111
  73. package/src/gpu_particles/ParticleAttribute.js +89 -89
  74. package/src/gpu_particles/ParticlePositionAttribute.js +42 -42
  75. package/src/html_utilities/CSSAnimator.js +66 -66
  76. package/src/html_utilities/css_animator_states/Animating.js +46 -46
  77. package/src/html_utilities/css_animator_states/Idle.js +27 -27
  78. package/src/index.js +134 -134
  79. package/src/loaders/AsyncAbstractLoader.js +160 -160
  80. package/src/loaders/AsyncAudiosLoader.js +34 -34
  81. package/src/loaders/AsyncObjectsLoader.js +44 -44
  82. package/src/loaders/AsyncTexturesLoader.js +81 -70
  83. package/src/loaders/assets_loader/AsyncAssetsLoaderWorker.js +69 -69
  84. package/src/loaders/assets_loader/ResourceContainer.js +37 -37
  85. package/src/loaders/assets_loader/ResourceLoaderChecker.js +39 -39
  86. package/src/materials/AddMaterial.js +20 -20
  87. package/src/materials/AlphaFilterMaterial.js +23 -23
  88. package/src/materials/BaseShaderMaterial.js +21 -21
  89. package/src/materials/BlitMaterial.js +30 -30
  90. package/src/materials/BloomComposeMaterial.js +24 -24
  91. package/src/materials/BoxBlurMaterial.js +16 -16
  92. package/src/materials/ClearAlphaMaterial.js +15 -15
  93. package/src/materials/ClearColorMaterial.js +33 -33
  94. package/src/materials/ClearDepthNormalMaterial.js +16 -16
  95. package/src/materials/DeferredRendererComposeMaterial.js +35 -35
  96. package/src/materials/DepthNormalMaterial.js +30 -30
  97. package/src/materials/DisplayNormalTextureMaterial.js +18 -18
  98. package/src/materials/DualFilteringBlurMaterial.js +14 -14
  99. package/src/materials/FXAAMaterial.js +12 -12
  100. package/src/materials/GaussianBlurMaterial.js +40 -40
  101. package/src/materials/LuminosityHighPassMaterial.js +26 -26
  102. package/src/materials/MedianFilterMaterial.js +45 -45
  103. package/src/materials/NormalMaterial.js +19 -19
  104. package/src/materials/SDFScreenTextMaterial.js +34 -34
  105. package/src/materials/SDFTextMaterial.js +41 -41
  106. package/src/materials/SSAOComposeMaterial.js +14 -14
  107. package/src/materials/SSAOMaterial.js +65 -65
  108. package/src/materials/ScreenSpaceTextureMaterial.js +67 -67
  109. package/src/materials/UIElementMaterial.js +30 -30
  110. package/src/materials/UnrealBloomComposeMaterial.js +100 -100
  111. package/src/materials/UnrealBlurMaterial.js +20 -20
  112. package/src/materials/UnrealComposeMaterial.js +27 -27
  113. package/src/materials/ViewPositionMaterial.js +19 -19
  114. package/src/materials/deferred/DeferredPointLightMaterial.js +42 -42
  115. package/src/materials/gpu_particles/AttributeUpdateMaterial.js +37 -37
  116. package/src/materials/gpu_particles/BasicParticleMaterial.js +25 -25
  117. package/src/materials/gpu_particles/ParticleStorageMaterial.js +37 -37
  118. package/src/materials/gpu_particles/PositionStorageMaterial.js +26 -26
  119. package/src/object_pool/Pool.js +75 -75
  120. package/src/primitives/Arrow.js +62 -62
  121. package/src/primitives/Cube.js +24 -24
  122. package/src/primitives/HorizontalPlane.js +27 -27
  123. package/src/primitives/Sphere.js +22 -22
  124. package/src/primitives/VerticalPlane.js +26 -26
  125. package/src/raycast/GroupRaycaster.js +43 -43
  126. package/src/raycast/PlaneDragResolver.js +92 -92
  127. package/src/raycast/PlaneRaycastResolver.js +24 -24
  128. package/src/raycast/PlaneRaycaster.js +25 -25
  129. package/src/raycast/RaycastResolver.js +24 -24
  130. package/src/raycast/SurfaceDragResolver.js +80 -80
  131. package/src/raycast/states/BaseState.js +18 -18
  132. package/src/raycast/states/IdleState.js +19 -19
  133. package/src/raycast/states/OnRaycastEnter.js +17 -17
  134. package/src/raycast/states/OnRaycastExit.js +18 -18
  135. package/src/raycast/states/OnRaycastHover.js +27 -27
  136. package/src/render_mode/BaseRender.js +34 -34
  137. package/src/render_mode/BloomRender.js +63 -63
  138. package/src/render_mode/DebugNormalsRender.js +22 -22
  139. package/src/render_mode/DeferredRender.js +110 -110
  140. package/src/render_mode/NormalAORender.js +72 -72
  141. package/src/render_mode/NormalRender.js +38 -38
  142. package/src/render_mode/OutlineRender.js +157 -157
  143. package/src/render_mode/PlanarReflectionsRender.js +121 -121
  144. package/src/render_mode/UnrealBloomRender.js +123 -123
  145. package/src/render_mode/VRRender.js +71 -71
  146. package/src/render_utilities/Blitter.js +101 -101
  147. package/src/render_utilities/Blurrer.js +31 -31
  148. package/src/render_utilities/DepthAndNormalsRenderer.js +47 -47
  149. package/src/render_utilities/DualFilteringBlurrer.js +58 -58
  150. package/src/render_utilities/GaussianBlurrer.js +167 -167
  151. package/src/render_utilities/MedianFilter.js +68 -68
  152. package/src/render_utilities/ViewPositionRenderer.js +50 -50
  153. package/src/resource_loader/BasisLoader.js +51 -51
  154. package/src/resource_loader/FontLoader.js +48 -48
  155. package/src/resource_loader/JSONLoader.js +35 -35
  156. package/src/resource_loader/OBJLoader.js +48 -48
  157. package/src/resource_loader/PointArrayLoader.js +72 -72
  158. package/src/resource_loader/RGBETextureLoader.js +48 -48
  159. package/src/resource_loader/VideoLoader.js +32 -32
  160. package/src/scenes/AbstractScene.js +175 -175
  161. package/src/scenes/loading_states/CompilatorManager.js +41 -41
  162. package/src/scenes/loading_states/HighQualityLoadingState.js +28 -28
  163. package/src/scenes/loading_states/LoadingState.js +117 -117
  164. package/src/scenes/loading_states/RegularLoadingState.js +41 -41
  165. package/src/shaders/add/add.frag +27 -27
  166. package/src/shaders/anti_aliasing/fxaa.frag +72 -72
  167. package/src/shaders/basic_color/basic_color.frag +5 -5
  168. package/src/shaders/basic_color/basic_color.vert +9 -9
  169. package/src/shaders/basic_line/basic_line.frag +36 -36
  170. package/src/shaders/basic_line/basic_line.vert +37 -37
  171. package/src/shaders/basic_texture/basic_texture.frag +9 -9
  172. package/src/shaders/basic_texture/basic_texture.vert +16 -16
  173. package/src/shaders/bloom/bloom_compose_frag.glsl +22 -22
  174. package/src/shaders/bloom/cheap_bloom_compose_frag.glsl +13 -13
  175. package/src/shaders/box_blur/box_blur.frag +24 -24
  176. package/src/shaders/box_blur/compose.frag +31 -31
  177. package/src/shaders/clear/clear_depth_normal.frag +24 -24
  178. package/src/shaders/copy/copy.frag +6 -6
  179. package/src/shaders/copy/copy.vert +5 -5
  180. package/src/shaders/deferred/blit_copy.vert +11 -11
  181. package/src/shaders/deferred/deferred_compose.frag +59 -59
  182. package/src/shaders/deferred/point_light.frag +66 -66
  183. package/src/shaders/deferred/point_light.vert +13 -13
  184. package/src/shaders/depth_normals/debug_normals.frag +47 -47
  185. package/src/shaders/depth_normals/depth_normals.frag +30 -30
  186. package/src/shaders/depth_normals/depth_normals.vert +12 -12
  187. package/src/shaders/dual_filter_blur/alpha_filter.frag +14 -14
  188. package/src/shaders/dual_filter_blur/downsample.frag +21 -21
  189. package/src/shaders/dual_filter_blur/upsample.frag +24 -24
  190. package/src/shaders/edge_visualizer/edge_visualizer.frag +17 -17
  191. package/src/shaders/edge_visualizer/edge_visualizer.vert +15 -15
  192. package/src/shaders/edges/corners.frag +10 -10
  193. package/src/shaders/edges/corners.vert +30 -30
  194. package/src/shaders/edges/edges.frag +6 -6
  195. package/src/shaders/edges/edges.vert +27 -27
  196. package/src/shaders/gaussian_blur/gaussian_blur.frag +43 -43
  197. package/src/shaders/gaussian_blur/unreal_bloom_compose.frag +36 -36
  198. package/src/shaders/gpu_particles/common_utils.glsl +12 -12
  199. package/src/shaders/gpu_particles/generic_storage.frag +6 -6
  200. package/src/shaders/gpu_particles/store/store_position.vert +14 -14
  201. package/src/shaders/gpu_particles/update/basic_update.frag +20 -20
  202. package/src/shaders/gpu_particles/visualize/visualize.frag +10 -10
  203. package/src/shaders/gpu_particles/visualize/visualize.vert +12 -12
  204. package/src/shaders/grid/grid.frag +16 -16
  205. package/src/shaders/grid/grid.vert +9 -9
  206. package/src/shaders/luminosity_high_pass/luminosity_high_pass.frag +37 -37
  207. package/src/shaders/median_filter/median_filter.frag +134 -134
  208. package/src/shaders/normal/normal.frag +6 -6
  209. package/src/shaders/normal/normal.vert +6 -6
  210. package/src/shaders/sdf_text/sdf_screen_text.frag +51 -51
  211. package/src/shaders/sdf_text/sdf_screen_text.vert +41 -41
  212. package/src/shaders/sdf_text/sdf_text.frag +53 -53
  213. package/src/shaders/sdf_text/sdf_text.vert +41 -41
  214. package/src/shaders/ssao/hbao.frag +264 -264
  215. package/src/shaders/ssao/ssao.frag +95 -95
  216. package/src/shaders/ssao/ssao.vert +10 -10
  217. package/src/shaders/ssao/ssao_compose.frag +14 -14
  218. package/src/shaders/transparent_mix/copy.frag +6 -6
  219. package/src/shaders/transparent_mix/transparent_mix.frag +18 -18
  220. package/src/shaders/transparent_mix/transparent_mix.vert +7 -7
  221. package/src/shaders/ui/ss_texture.frag +10 -10
  222. package/src/shaders/ui/ss_texture.vert +31 -31
  223. package/src/shaders/ui/ws_texture.vert +38 -38
  224. package/src/shaders/ui_element/ui_element.frag +11 -11
  225. package/src/shaders/ui_element/ui_element.vert +32 -32
  226. package/src/shaders/unreal_blur/unreal_blur.frag +24 -24
  227. package/src/shaders/unreal_blur/unreal_compose.frag +23 -23
  228. package/src/shaders/write_view_position/write_view_position.frag +6 -6
  229. package/src/shaders/write_view_position/write_view_position.vert +8 -8
  230. package/src/static_batcher/BatchedMesh.js +56 -56
  231. package/src/static_batcher/GeometryBatch.js +308 -308
  232. package/src/static_batcher/GeometryBatcher.js +64 -64
  233. package/src/static_batcher/MeshBatcher.js +58 -58
  234. package/src/ui/ui_element_position/ScreenSpacePosition.js +16 -16
  235. package/src/ui/ui_element_position/WorldSpacePosition.js +23 -23
  236. package/src/ui/ui_element_state/OnIdle.js +24 -24
  237. package/src/ui/ui_element_state/OnMouseEnter.js +39 -39
  238. package/src/ui/ui_element_state/OnMouseExit.js +22 -22
  239. package/src/ui/ui_element_state/OnMouseHover.js +46 -46
  240. package/src/ui/ui_element_state/UIElementState.js +34 -34
  241. package/src/utilities/ArrayUtilities.js +57 -57
  242. package/src/utilities/CameraUtilities.js +283 -283
  243. package/src/utilities/EasingFunctions.js +231 -231
  244. package/src/utilities/FrustumPointFitter.js +257 -257
  245. package/src/utilities/GeometryUtilities.js +76 -76
  246. package/src/utilities/HTMLUtilities.js +76 -76
  247. package/src/utilities/ImageUtilities.js +28 -28
  248. package/src/utilities/MeshSampler.js +206 -206
  249. package/src/utilities/ModelUtilities.js +162 -162
  250. package/src/utilities/OMath.js +158 -158
  251. package/src/utilities/OrthographicFrustumPointFitter.js +49 -49
  252. package/src/utilities/PerspectiveFrustumPointFitter.js +254 -254
  253. package/src/utilities/StringUtilities.js +43 -43
  254. package/src/utilities/TimeUtilities.js +24 -24
  255. package/src/utilities/Validation.js +36 -36
  256. package/src/view_components/ApplicationView.js +73 -73
  257. package/src/view_components/TransitionManager.js +75 -75
  258. package/src/view_components/ViewComponent.js +61 -61
  259. package/src/view_components/ViewComponentManager.js +69 -69
  260. package/src/view_components/ViewManager.js +145 -145
  261. package/src/view_components/ViewState.js +49 -49
  262. package/src/view_components/transition/ActionSequencerBuilder.js +124 -124
  263. package/src/view_components/transition/DrawIOAnimationSheet.js +92 -92
  264. package/src/view_components/transition/TransitionTable.js +54 -54
  265. package/src/view_components/transition/ViewStateTransitionHandler.js +106 -106
@@ -1,76 +1,76 @@
1
- class HTMLUtilities
2
- {
3
- static load_images(container)
4
- {
5
- const images = container.querySelectorAll('img');
6
-
7
- for (let i = 0; i < images.length; i++)
8
- {
9
- const image = images[i];
10
-
11
- if (image.dataset.src)
12
- {
13
- image.src = image.dataset.src;
14
- }
15
- }
16
-
17
- const image_objects = container.querySelectorAll('object');
18
-
19
- for (let i = 0; i < image_objects.length; i++)
20
- {
21
- const image_object = image_objects[i];
22
-
23
- if (image_object.dataset.src)
24
- {
25
- image_object.data = image_object.dataset.src;
26
- }
27
- }
28
- }
29
-
30
- static load_videos(container)
31
- {
32
- const videos = container.querySelectorAll('video');
33
-
34
- for (let i = 0; i < videos.length; i++)
35
- {
36
- const video = videos[i];
37
-
38
- if (video.dataset.src)
39
- {
40
- video.src = video.dataset.src;
41
- }
42
- }
43
- }
44
-
45
- static load_iframes(container)
46
- {
47
- const iframes = container.querySelectorAll('iframe');
48
-
49
- for (let i = 0; i < iframes.length; i++)
50
- {
51
- const iframe = iframes[i];
52
-
53
- if (iframe.dataset.src)
54
- {
55
- iframe.src = iframe.dataset.src;
56
- }
57
- }
58
- }
59
-
60
- static load_elements(container, selector)
61
- {
62
- const elements = container.querySelectorAll(selector);
63
-
64
- for (let i = 0; i < elements.length; i++)
65
- {
66
- const element = elements[i];
67
-
68
- if (element.dataset.src)
69
- {
70
- element.src = element.dataset.src;
71
- }
72
- }
73
- }
74
- }
75
-
76
- export { HTMLUtilities };
1
+ class HTMLUtilities
2
+ {
3
+ static load_images(container)
4
+ {
5
+ const images = container.querySelectorAll('img');
6
+
7
+ for (let i = 0; i < images.length; i++)
8
+ {
9
+ const image = images[i];
10
+
11
+ if (image.dataset.src)
12
+ {
13
+ image.src = image.dataset.src;
14
+ }
15
+ }
16
+
17
+ const image_objects = container.querySelectorAll('object');
18
+
19
+ for (let i = 0; i < image_objects.length; i++)
20
+ {
21
+ const image_object = image_objects[i];
22
+
23
+ if (image_object.dataset.src)
24
+ {
25
+ image_object.data = image_object.dataset.src;
26
+ }
27
+ }
28
+ }
29
+
30
+ static load_videos(container)
31
+ {
32
+ const videos = container.querySelectorAll('video');
33
+
34
+ for (let i = 0; i < videos.length; i++)
35
+ {
36
+ const video = videos[i];
37
+
38
+ if (video.dataset.src)
39
+ {
40
+ video.src = video.dataset.src;
41
+ }
42
+ }
43
+ }
44
+
45
+ static load_iframes(container)
46
+ {
47
+ const iframes = container.querySelectorAll('iframe');
48
+
49
+ for (let i = 0; i < iframes.length; i++)
50
+ {
51
+ const iframe = iframes[i];
52
+
53
+ if (iframe.dataset.src)
54
+ {
55
+ iframe.src = iframe.dataset.src;
56
+ }
57
+ }
58
+ }
59
+
60
+ static load_elements(container, selector)
61
+ {
62
+ const elements = container.querySelectorAll(selector);
63
+
64
+ for (let i = 0; i < elements.length; i++)
65
+ {
66
+ const element = elements[i];
67
+
68
+ if (element.dataset.src)
69
+ {
70
+ element.src = element.dataset.src;
71
+ }
72
+ }
73
+ }
74
+ }
75
+
76
+ export { HTMLUtilities };
@@ -1,28 +1,28 @@
1
- import { Vector4 } from 'three';
2
-
3
- class ImageUtilities
4
- {
5
- constructor()
6
- { }
7
-
8
- static get_image_data(image)
9
- {
10
- const canvas = document.createElement('canvas');
11
- canvas.width = image.width;
12
- canvas.height = image.height;
13
-
14
- const context = canvas.getContext('2d');
15
- context.drawImage(image, 0, 0);
16
-
17
- return context.getImageData(0, 0, image.width, image.height);
18
- }
19
-
20
- static get_pixel(imagedata, x, y)
21
- {
22
- const position = (x + imagedata.width * y) * 4;
23
- const data = imagedata.data;
24
- return new Vector4(data[position + 0], data[position + 1], data[position + 2], data[position + 3]);
25
- }
26
- }
27
-
28
- export { ImageUtilities };
1
+ import { Vector4 } from 'three';
2
+
3
+ class ImageUtilities
4
+ {
5
+ constructor()
6
+ { }
7
+
8
+ static get_image_data(image)
9
+ {
10
+ const canvas = document.createElement('canvas');
11
+ canvas.width = image.width;
12
+ canvas.height = image.height;
13
+
14
+ const context = canvas.getContext('2d');
15
+ context.drawImage(image, 0, 0);
16
+
17
+ return context.getImageData(0, 0, image.width, image.height);
18
+ }
19
+
20
+ static get_pixel(imagedata, x, y)
21
+ {
22
+ const position = (x + imagedata.width * y) * 4;
23
+ const data = imagedata.data;
24
+ return new Vector4(data[position + 0], data[position + 1], data[position + 2], data[position + 3]);
25
+ }
26
+ }
27
+
28
+ export { ImageUtilities };
@@ -1,206 +1,206 @@
1
- import { Vector3 } from 'three';
2
- import { Vector2 } from 'three';
3
- class MeshSampler
4
- {
5
- constructor()
6
- {
7
-
8
- }
9
-
10
- sample(buffer_geometry, sample_count)
11
- {
12
- const face_areas = [];
13
-
14
- let min_area = 99999999;
15
-
16
- const vertices = buffer_geometry.getAttribute('position');
17
- const normals = buffer_geometry.getAttribute('normal');
18
- const tangents = buffer_geometry.getAttribute('tangent');
19
- const uvs = buffer_geometry.getAttribute('uv');
20
- const indices = buffer_geometry.index;
21
-
22
- const faces = [];
23
-
24
- for (let i = 0; i < indices.count; i += 3)
25
- {
26
- const index_0 = indices.array[i + 0];
27
- const index_1 = indices.array[i + 1];
28
- const index_2 = indices.array[i + 2];
29
-
30
- const v1 = new Vector3();
31
- v1.x = vertices.getX(index_0);
32
- v1.y = vertices.getY(index_0);
33
- v1.z = vertices.getZ(index_0);
34
-
35
- const v2 = new Vector3();
36
- v2.x = vertices.getX(index_1);
37
- v2.y = vertices.getY(index_1);
38
- v2.z = vertices.getZ(index_1);
39
-
40
- const v3 = new Vector3();
41
- v3.x = vertices.getX(index_2);
42
- v3.y = vertices.getY(index_2);
43
- v3.z = vertices.getZ(index_2);
44
-
45
- const face = {
46
- a: v1,
47
- b: v2,
48
- c: v3
49
- };
50
-
51
- if (normals)
52
- {
53
- const n1 = new Vector3();
54
- n1.x = normals.getX(index_0);
55
- n1.y = normals.getY(index_0);
56
- n1.z = normals.getZ(index_0);
57
-
58
- const n2 = new Vector3();
59
- n2.x = normals.getX(index_1);
60
- n2.y = normals.getY(index_1);
61
- n2.z = normals.getZ(index_1);
62
-
63
- const n3 = new Vector3();
64
- n3.x = normals.getX(index_2);
65
- n3.y = normals.getY(index_2);
66
- n3.z = normals.getZ(index_2);
67
-
68
- const normal = n1.clone().add(n2).add(n3).normalize();
69
- face.normal = normal;
70
- }
71
-
72
- if (tangents)
73
- {
74
- const n1 = new Vector3();
75
- n1.x = tangents.getX(index_0);
76
- n1.y = tangents.getY(index_0);
77
- n1.z = tangents.getZ(index_0);
78
-
79
- const n2 = new Vector3();
80
- n2.x = tangents.getX(index_1);
81
- n2.y = tangents.getY(index_1);
82
- n2.z = tangents.getZ(index_1);
83
-
84
- const n3 = new Vector3();
85
- n3.x = tangents.getX(index_2);
86
- n3.y = tangents.getY(index_2);
87
- n3.z = tangents.getZ(index_2);
88
-
89
- const tangent = n1.clone().add(n2).add(n3).normalize();
90
- face.tangent = tangent;
91
- }
92
- if (uvs)
93
- {
94
- const uv_a = new Vector2();
95
- uv_a.x = uvs.getX(index_0);
96
- uv_a.y = uvs.getY(index_0);
97
-
98
- const uv_b = new Vector2();
99
- uv_b.x = uvs.getX(index_1);
100
- uv_b.y = uvs.getY(index_1);
101
-
102
- const uv_c = new Vector2();
103
- uv_c.x = uvs.getX(index_2);
104
- uv_c.y = uvs.getY(index_2);
105
-
106
- face.uv_a = uv_a;
107
- face.uv_b = uv_b;
108
- face.uv_c = uv_c;
109
- }
110
-
111
- faces.push(face);
112
-
113
- const area = this.get_face_area(face);
114
- min_area = Math.min(area, min_area);
115
- face_areas.push(area);
116
- }
117
-
118
- const normalized_faces_array = this.get_uniform_face_distribution(face_areas, min_area, faces);
119
- const selected_faces = this.select_random_faces(normalized_faces_array, sample_count);
120
- const sampled_data = this.sample_data_from_faces(selected_faces);
121
- return sampled_data;
122
- }
123
-
124
- sample_data_from_faces(faces)
125
- {
126
- const sampled_points = [];
127
- const sampled_normals = [];
128
- const sampled_tangents = [];
129
- const sampled_uvs = [];
130
-
131
- for (let i = 0; i < faces.length; i++)
132
- {
133
- const face = faces[i];
134
-
135
- const w1 = Math.random();
136
- const w2 = Math.random();
137
-
138
- sampled_points.push(this.sample_point_in_face(w1, w2, face.a, face.b, face.c).clone());
139
- if (face.normal)
140
- {
141
- sampled_normals.push(face.normal.clone());
142
- }
143
- if (face.tangent)
144
- {
145
- sampled_tangents.push(face.tangent.clone());
146
- }
147
- if (face.uv_a)
148
- {
149
- sampled_uvs.push(this.sample_point_in_face(w1, w2, face.uv_a, face.uv_b, face.uv_c).clone());
150
- }
151
- }
152
- return { points: sampled_points, normals: sampled_normals, tangents: sampled_tangents, uvs: sampled_uvs };
153
- }
154
-
155
- select_random_faces(faces, amount)
156
- {
157
- const selected_faces = [];
158
- for (let i = 0; i < amount; i++)
159
- {
160
- const random = Math.floor(Math.random() * faces.length);
161
- const selected_face = faces[random];
162
-
163
- selected_faces.push(selected_face);
164
- }
165
-
166
- return selected_faces;
167
- }
168
-
169
- get_uniform_face_distribution(face_areas, minimum_area, faces)
170
- {
171
- const extended_triangle_indices = [];
172
- for (let i = 0; i < face_areas.length; i++)
173
- {
174
- face_areas[i] /= minimum_area;
175
- const repetitions_needed = Math.floor(Math.round(face_areas[i]));
176
- for (let j = 0; j < repetitions_needed; j++)
177
- {
178
- extended_triangle_indices.push(faces[i]);
179
- }
180
- }
181
- return extended_triangle_indices;
182
- }
183
-
184
- get_face_area(face)
185
- {
186
- const vec1 = face.b.clone().sub(face.a);
187
- const vec2 = face.c.clone().sub(face.a);
188
- return vec1.cross(vec2).length() / 2;
189
- }
190
-
191
- sample_point_in_face(w1, w2, v1, v2, v3)
192
- {
193
- if (w1 + w2 > 1)
194
- {
195
- w1 = 1.0 - w1;
196
- w2 = 1.0 - w2;
197
- }
198
-
199
- const w3 = 1.0 - (w1 + w2);
200
-
201
- return v1.clone().multiplyScalar(w1).add(v2.clone().multiplyScalar(w2)).add(v3.clone().multiplyScalar(w3));
202
- }
203
- }
204
-
205
- const mesh_sampler = new MeshSampler();
206
- export { mesh_sampler as MeshSampler };
1
+ import { Vector3 } from 'three';
2
+ import { Vector2 } from 'three';
3
+ class MeshSampler
4
+ {
5
+ constructor()
6
+ {
7
+
8
+ }
9
+
10
+ sample(buffer_geometry, sample_count)
11
+ {
12
+ const face_areas = [];
13
+
14
+ let min_area = 99999999;
15
+
16
+ const vertices = buffer_geometry.getAttribute('position');
17
+ const normals = buffer_geometry.getAttribute('normal');
18
+ const tangents = buffer_geometry.getAttribute('tangent');
19
+ const uvs = buffer_geometry.getAttribute('uv');
20
+ const indices = buffer_geometry.index;
21
+
22
+ const faces = [];
23
+
24
+ for (let i = 0; i < indices.count; i += 3)
25
+ {
26
+ const index_0 = indices.array[i + 0];
27
+ const index_1 = indices.array[i + 1];
28
+ const index_2 = indices.array[i + 2];
29
+
30
+ const v1 = new Vector3();
31
+ v1.x = vertices.getX(index_0);
32
+ v1.y = vertices.getY(index_0);
33
+ v1.z = vertices.getZ(index_0);
34
+
35
+ const v2 = new Vector3();
36
+ v2.x = vertices.getX(index_1);
37
+ v2.y = vertices.getY(index_1);
38
+ v2.z = vertices.getZ(index_1);
39
+
40
+ const v3 = new Vector3();
41
+ v3.x = vertices.getX(index_2);
42
+ v3.y = vertices.getY(index_2);
43
+ v3.z = vertices.getZ(index_2);
44
+
45
+ const face = {
46
+ a: v1,
47
+ b: v2,
48
+ c: v3
49
+ };
50
+
51
+ if (normals)
52
+ {
53
+ const n1 = new Vector3();
54
+ n1.x = normals.getX(index_0);
55
+ n1.y = normals.getY(index_0);
56
+ n1.z = normals.getZ(index_0);
57
+
58
+ const n2 = new Vector3();
59
+ n2.x = normals.getX(index_1);
60
+ n2.y = normals.getY(index_1);
61
+ n2.z = normals.getZ(index_1);
62
+
63
+ const n3 = new Vector3();
64
+ n3.x = normals.getX(index_2);
65
+ n3.y = normals.getY(index_2);
66
+ n3.z = normals.getZ(index_2);
67
+
68
+ const normal = n1.clone().add(n2).add(n3).normalize();
69
+ face.normal = normal;
70
+ }
71
+
72
+ if (tangents)
73
+ {
74
+ const n1 = new Vector3();
75
+ n1.x = tangents.getX(index_0);
76
+ n1.y = tangents.getY(index_0);
77
+ n1.z = tangents.getZ(index_0);
78
+
79
+ const n2 = new Vector3();
80
+ n2.x = tangents.getX(index_1);
81
+ n2.y = tangents.getY(index_1);
82
+ n2.z = tangents.getZ(index_1);
83
+
84
+ const n3 = new Vector3();
85
+ n3.x = tangents.getX(index_2);
86
+ n3.y = tangents.getY(index_2);
87
+ n3.z = tangents.getZ(index_2);
88
+
89
+ const tangent = n1.clone().add(n2).add(n3).normalize();
90
+ face.tangent = tangent;
91
+ }
92
+ if (uvs)
93
+ {
94
+ const uv_a = new Vector2();
95
+ uv_a.x = uvs.getX(index_0);
96
+ uv_a.y = uvs.getY(index_0);
97
+
98
+ const uv_b = new Vector2();
99
+ uv_b.x = uvs.getX(index_1);
100
+ uv_b.y = uvs.getY(index_1);
101
+
102
+ const uv_c = new Vector2();
103
+ uv_c.x = uvs.getX(index_2);
104
+ uv_c.y = uvs.getY(index_2);
105
+
106
+ face.uv_a = uv_a;
107
+ face.uv_b = uv_b;
108
+ face.uv_c = uv_c;
109
+ }
110
+
111
+ faces.push(face);
112
+
113
+ const area = this.get_face_area(face);
114
+ min_area = Math.min(area, min_area);
115
+ face_areas.push(area);
116
+ }
117
+
118
+ const normalized_faces_array = this.get_uniform_face_distribution(face_areas, min_area, faces);
119
+ const selected_faces = this.select_random_faces(normalized_faces_array, sample_count);
120
+ const sampled_data = this.sample_data_from_faces(selected_faces);
121
+ return sampled_data;
122
+ }
123
+
124
+ sample_data_from_faces(faces)
125
+ {
126
+ const sampled_points = [];
127
+ const sampled_normals = [];
128
+ const sampled_tangents = [];
129
+ const sampled_uvs = [];
130
+
131
+ for (let i = 0; i < faces.length; i++)
132
+ {
133
+ const face = faces[i];
134
+
135
+ const w1 = Math.random();
136
+ const w2 = Math.random();
137
+
138
+ sampled_points.push(this.sample_point_in_face(w1, w2, face.a, face.b, face.c).clone());
139
+ if (face.normal)
140
+ {
141
+ sampled_normals.push(face.normal.clone());
142
+ }
143
+ if (face.tangent)
144
+ {
145
+ sampled_tangents.push(face.tangent.clone());
146
+ }
147
+ if (face.uv_a)
148
+ {
149
+ sampled_uvs.push(this.sample_point_in_face(w1, w2, face.uv_a, face.uv_b, face.uv_c).clone());
150
+ }
151
+ }
152
+ return { points: sampled_points, normals: sampled_normals, tangents: sampled_tangents, uvs: sampled_uvs };
153
+ }
154
+
155
+ select_random_faces(faces, amount)
156
+ {
157
+ const selected_faces = [];
158
+ for (let i = 0; i < amount; i++)
159
+ {
160
+ const random = Math.floor(Math.random() * faces.length);
161
+ const selected_face = faces[random];
162
+
163
+ selected_faces.push(selected_face);
164
+ }
165
+
166
+ return selected_faces;
167
+ }
168
+
169
+ get_uniform_face_distribution(face_areas, minimum_area, faces)
170
+ {
171
+ const extended_triangle_indices = [];
172
+ for (let i = 0; i < face_areas.length; i++)
173
+ {
174
+ face_areas[i] /= minimum_area;
175
+ const repetitions_needed = Math.floor(Math.round(face_areas[i]));
176
+ for (let j = 0; j < repetitions_needed; j++)
177
+ {
178
+ extended_triangle_indices.push(faces[i]);
179
+ }
180
+ }
181
+ return extended_triangle_indices;
182
+ }
183
+
184
+ get_face_area(face)
185
+ {
186
+ const vec1 = face.b.clone().sub(face.a);
187
+ const vec2 = face.c.clone().sub(face.a);
188
+ return vec1.cross(vec2).length() / 2;
189
+ }
190
+
191
+ sample_point_in_face(w1, w2, v1, v2, v3)
192
+ {
193
+ if (w1 + w2 > 1)
194
+ {
195
+ w1 = 1.0 - w1;
196
+ w2 = 1.0 - w2;
197
+ }
198
+
199
+ const w3 = 1.0 - (w1 + w2);
200
+
201
+ return v1.clone().multiplyScalar(w1).add(v2.clone().multiplyScalar(w2)).add(v3.clone().multiplyScalar(w3));
202
+ }
203
+ }
204
+
205
+ const mesh_sampler = new MeshSampler();
206
+ export { mesh_sampler as MeshSampler };