@configura/babylon-view 1.2.1 → 1.3.0-alpha.3

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 (115) hide show
  1. package/LICENSE +201 -201
  2. package/README.md +1 -1
  3. package/dist/animation/AnimatableObject.d.ts +8 -8
  4. package/dist/animation/AnimatableObject.js +3 -3
  5. package/dist/animation/animator/Animator.d.ts +33 -33
  6. package/dist/animation/animator/Animator.js +58 -58
  7. package/dist/animation/animator/AnimatorEasing.d.ts +16 -16
  8. package/dist/animation/animator/AnimatorEasing.js +31 -31
  9. package/dist/animation/animator/AnimatorEasingMatrix.d.ts +14 -14
  10. package/dist/animation/animator/AnimatorEasingMatrix.js +16 -16
  11. package/dist/animation/animator/AnimatorHighlight.d.ts +16 -16
  12. package/dist/animation/animator/AnimatorHighlight.js +32 -32
  13. package/dist/animation/animator/AnimatorPointToPoint.d.ts +8 -8
  14. package/dist/animation/animator/AnimatorPointToPoint.js +14 -14
  15. package/dist/animation/animator/AnimatorQueue.d.ts +13 -13
  16. package/dist/animation/animator/AnimatorQueue.js +57 -57
  17. package/dist/animation/animator/AnimatorScale.d.ts +8 -8
  18. package/dist/animation/animator/AnimatorScale.js +13 -13
  19. package/dist/animation/animator/AnimatorSpin.d.ts +10 -10
  20. package/dist/animation/animator/AnimatorSpin.js +13 -13
  21. package/dist/animation/animator/EasingFunctions.d.ts +35 -35
  22. package/dist/animation/animator/EasingFunctions.js +137 -137
  23. package/dist/animation/coordinator/Coordinator.d.ts +28 -28
  24. package/dist/animation/coordinator/Coordinator.js +47 -47
  25. package/dist/animation/coordinator/CoordinatorDropAndSpin.d.ts +22 -22
  26. package/dist/animation/coordinator/CoordinatorDropAndSpin.js +133 -133
  27. package/dist/animation/coordinator/CoordinatorIdentity.d.ts +11 -11
  28. package/dist/animation/coordinator/CoordinatorIdentity.js +12 -12
  29. package/dist/animation/coordinator/CoordinatorNodeQueues.d.ts +18 -18
  30. package/dist/animation/coordinator/CoordinatorNodeQueues.js +50 -50
  31. package/dist/animation/coordinator/CoordinatorPulse.d.ts +21 -21
  32. package/dist/animation/coordinator/CoordinatorPulse.js +47 -47
  33. package/dist/animation/coordinator/CoordinatorPulseBounce.d.ts +14 -14
  34. package/dist/animation/coordinator/CoordinatorPulseBounce.js +40 -40
  35. package/dist/animation/coordinator/CoordinatorPulseHighlight.d.ts +13 -13
  36. package/dist/animation/coordinator/CoordinatorPulseHighlight.js +34 -34
  37. package/dist/animation/coordinator/CoordinatorPulseInflate.d.ts +14 -14
  38. package/dist/animation/coordinator/CoordinatorPulseInflate.js +30 -30
  39. package/dist/camera/CameraCreator.d.ts +5 -5
  40. package/dist/camera/CameraCreator.js +4 -4
  41. package/dist/camera/CfgArcRotateCameraPointersInput.d.ts +10 -10
  42. package/dist/camera/CfgArcRotateCameraPointersInput.js +262 -262
  43. package/dist/camera/CfgOrbitalCamera.d.ts +68 -64
  44. package/dist/camera/CfgOrbitalCamera.js +250 -233
  45. package/dist/camera/CfgOrbitalCameraControlProps.d.ts +6 -6
  46. package/dist/camera/CfgOrbitalCameraControlProps.js +3 -3
  47. package/dist/camera/GradingApplier.d.ts +3 -3
  48. package/dist/camera/GradingApplier.js +48 -48
  49. package/dist/engine/EngineCreator.d.ts +3 -3
  50. package/dist/engine/EngineCreator.js +10 -10
  51. package/dist/geometry/CfgGeometry.d.ts +12 -12
  52. package/dist/geometry/CfgGeometry.js +117 -117
  53. package/dist/geometry/CfgMesh.d.ts +7 -7
  54. package/dist/geometry/CfgMesh.js +8 -8
  55. package/dist/geometry/geoSplitter.d.ts +8 -8
  56. package/dist/geometry/geoSplitter.js +192 -192
  57. package/dist/index.d.ts +13 -13
  58. package/dist/index.js +13 -13
  59. package/dist/light/CfgDirectionalLight.d.ts +8 -8
  60. package/dist/light/CfgDirectionalLight.js +18 -18
  61. package/dist/light/CfgHemisphericLight.d.ts +7 -7
  62. package/dist/light/CfgHemisphericLight.js +17 -17
  63. package/dist/light/CfgPointLight.d.ts +8 -8
  64. package/dist/light/CfgPointLight.js +18 -18
  65. package/dist/light/DefaultLightRig.d.ts +19 -19
  66. package/dist/light/DefaultLightRig.js +77 -77
  67. package/dist/light/LightRigCreator.d.ts +9 -9
  68. package/dist/light/LightRigCreator.js +3 -3
  69. package/dist/material/CfgMaterial.d.ts +53 -53
  70. package/dist/material/CfgMaterial.js +454 -454
  71. package/dist/material/DummyMaterialCreator.d.ts +4 -4
  72. package/dist/material/DummyMaterialCreator.js +15 -15
  73. package/dist/material/material.d.ts +18 -18
  74. package/dist/material/material.js +128 -128
  75. package/dist/material/texture.d.ts +14 -14
  76. package/dist/material/texture.js +304 -304
  77. package/dist/nodes/CfgContentRootNode.d.ts +19 -19
  78. package/dist/nodes/CfgContentRootNode.js +75 -75
  79. package/dist/nodes/CfgDeferredMeshNode.d.ts +48 -48
  80. package/dist/nodes/CfgDeferredMeshNode.js +347 -347
  81. package/dist/nodes/CfgProductNode.d.ts +61 -61
  82. package/dist/nodes/CfgProductNode.js +486 -486
  83. package/dist/nodes/CfgSymNode.d.ts +42 -42
  84. package/dist/nodes/CfgSymNode.js +216 -216
  85. package/dist/nodes/CfgSymRootNode.d.ts +33 -33
  86. package/dist/nodes/CfgSymRootNode.js +175 -175
  87. package/dist/nodes/CfgTransformNode.d.ts +29 -29
  88. package/dist/nodes/CfgTransformNode.js +81 -81
  89. package/dist/scene/SceneCreator.d.ts +6 -6
  90. package/dist/scene/SceneCreator.js +22 -22
  91. package/dist/utilities/CfgBoundingBox.d.ts +16 -16
  92. package/dist/utilities/CfgBoundingBox.js +64 -64
  93. package/dist/utilities/utilities3D.d.ts +26 -26
  94. package/dist/utilities/utilities3D.js +187 -187
  95. package/dist/utilities/utilitiesColor.d.ts +18 -18
  96. package/dist/utilities/utilitiesColor.js +48 -48
  97. package/dist/utilities/utilitiesImage.d.ts +6 -6
  98. package/dist/utilities/utilitiesImage.js +107 -107
  99. package/dist/utilities/utilitiesSymRootIdentifier.d.ts +5 -5
  100. package/dist/utilities/utilitiesSymRootIdentifier.js +20 -20
  101. package/dist/view/BaseView.d.ts +70 -70
  102. package/dist/view/BaseView.js +291 -291
  103. package/dist/view/BaseViewConfiguration.d.ts +32 -32
  104. package/dist/view/BaseViewConfiguration.js +8 -8
  105. package/dist/view/RenderEnv.d.ts +38 -38
  106. package/dist/view/RenderEnv.js +7 -7
  107. package/dist/view/SingleProductDefaultCameraView.d.ts +33 -33
  108. package/dist/view/SingleProductDefaultCameraView.js +141 -140
  109. package/dist/view/SingleProductDefaultCameraViewConfiguration.d.ts +46 -44
  110. package/dist/view/SingleProductDefaultCameraViewConfiguration.js +11 -11
  111. package/dist/view/SingleProductView.d.ts +42 -42
  112. package/dist/view/SingleProductView.js +205 -205
  113. package/dist/view/SingleProductViewConfiguration.d.ts +32 -32
  114. package/dist/view/SingleProductViewConfiguration.js +19 -19
  115. package/package.json +5 -5
@@ -1,7 +1,7 @@
1
- export interface CfgOrbitalCameraControlProps {
2
- distance?: number;
3
- yaw?: number;
4
- pitch?: number;
5
- }
6
- export declare function orbitalCameraControlPropsEquals(left: CfgOrbitalCameraControlProps, right: CfgOrbitalCameraControlProps): boolean;
1
+ export interface CfgOrbitalCameraControlProps {
2
+ distance?: number;
3
+ yaw?: number;
4
+ pitch?: number;
5
+ }
6
+ export declare function orbitalCameraControlPropsEquals(left: CfgOrbitalCameraControlProps, right: CfgOrbitalCameraControlProps): boolean;
7
7
  //# sourceMappingURL=CfgOrbitalCameraControlProps.d.ts.map
@@ -1,3 +1,3 @@
1
- export function orbitalCameraControlPropsEquals(left, right) {
2
- return left.distance === right.distance && left.yaw === right.yaw && left.pitch === right.pitch;
3
- }
1
+ export function orbitalCameraControlPropsEquals(left, right) {
2
+ return left.distance === right.distance && left.yaw === right.yaw && left.pitch === right.pitch;
3
+ }
@@ -1,4 +1,4 @@
1
- import { Camera } from "@babylonjs/core/Cameras/camera.js";
2
- export declare type GradingApplier = (camera: Camera) => void;
3
- export declare const getDefaultGradingApplier: () => (camera: Camera) => void;
1
+ import { Camera } from "@babylonjs/core/Cameras/camera.js";
2
+ export declare type GradingApplier = (camera: Camera) => void;
3
+ export declare const getDefaultGradingApplier: () => (camera: Camera) => void;
4
4
  //# sourceMappingURL=GradingApplier.d.ts.map
@@ -1,48 +1,48 @@
1
- import { ColorCurves } from "@babylonjs/core/Materials/colorCurves.js";
2
- import { ImageProcessingConfiguration } from "@babylonjs/core/Materials/imageProcessingConfiguration.js";
3
- import { DefaultRenderingPipeline } from "@babylonjs/core/PostProcesses/RenderPipeline/Pipelines/defaultRenderingPipeline.js";
4
- export const getDefaultGradingApplier = () => (camera) => {
5
- const scene = camera.getScene();
6
- // The second parameter below is HDR which is supposed to be enabled "as long as possible"
7
- // according to the documentation. However, doing so causes problems with rendering against
8
- // our transparent background:
9
- // - Anti-aliasing breaks for very white colors (BanquetChair2 in ConfiguraKitchenAccessories)
10
- // - Transparent objects gets rendered very differently against the transparent background
11
- // compared to over a opaque surface (Electric Cart in ConfiguraIndustrialEquipment)
12
- // - Transparent objects gets a very bright and color shifting results (ConfiguraHumans)
13
- //
14
- // The last point can be fixed by disabling premultipliedAlpha in the EngineConstructor,
15
- // resulting in a bit better subjective colors compared to CET for "ConfiguraHumans".
16
- //
17
- // TODO Babylon: Figure out how we can enable the "hdr" flag again. Since we are using
18
- // PBR we really should be using "hdr" to do things the right way, see this discussion:
19
- // https://forum.babylonjs.com/t/enabling-hdr-in-defaultpipeline-disables-aa/14656/9
20
- //
21
- var pipeline = new DefaultRenderingPipeline("defaultPipeline", false, scene, [camera]);
22
- // FXAA is not enabled since it causes excessive blur in detailed textures
23
- // pipeline.fxaaEnabled = true;
24
- // This affects anti-aliasing, more samples is better but also slower.
25
- // Note that this does not seem to do anything unless HDR is enabled in the
26
- // DefaultRenderingPipeline call.
27
- pipeline.samples = 4;
28
- pipeline.imageProcessingEnabled = true;
29
- pipeline.imageProcessing.toneMappingEnabled = true;
30
- pipeline.imageProcessing.toneMappingType = ImageProcessingConfiguration.TONEMAPPING_ACES;
31
- // ACES tone mapping needs manual exposure adjustment in Babylon to look good on a normal
32
- // monitor. More information can be found in the links below, note that "model-viewer" (in
33
- // their "Fidelity" test) ended up using "1 / 0.6" rather than the value of 2.0 that was first
34
- // decided upon in their pull request.
35
- //
36
- // https://github.com/google/model-viewer/pull/1340
37
- // https://github.com/mrdoob/three.js/pull/19621
38
- // https://modelviewer.dev/fidelity/
39
- pipeline.imageProcessing.exposure = 1 / 0.6;
40
- // We add a bit of extra contrast to make the image more appealing. This is highly subjective.
41
- pipeline.imageProcessing.contrast = 1.2;
42
- // The ACES color correction is quite desaturating, add back a bit of punch to the colors.
43
- var curve = new ColorCurves();
44
- curve.midtonesSaturation = 5;
45
- curve.highlightsSaturation = 15;
46
- pipeline.imageProcessing.colorCurves = curve;
47
- pipeline.imageProcessing.colorCurvesEnabled = true;
48
- };
1
+ import { ColorCurves } from "@babylonjs/core/Materials/colorCurves.js";
2
+ import { ImageProcessingConfiguration } from "@babylonjs/core/Materials/imageProcessingConfiguration.js";
3
+ import { DefaultRenderingPipeline } from "@babylonjs/core/PostProcesses/RenderPipeline/Pipelines/defaultRenderingPipeline.js";
4
+ export const getDefaultGradingApplier = () => (camera) => {
5
+ const scene = camera.getScene();
6
+ // The second parameter below is HDR which is supposed to be enabled "as long as possible"
7
+ // according to the documentation. However, doing so causes problems with rendering against
8
+ // our transparent background:
9
+ // - Anti-aliasing breaks for very white colors (BanquetChair2 in ConfiguraKitchenAccessories)
10
+ // - Transparent objects gets rendered very differently against the transparent background
11
+ // compared to over a opaque surface (Electric Cart in ConfiguraIndustrialEquipment)
12
+ // - Transparent objects gets a very bright and color shifting results (ConfiguraHumans)
13
+ //
14
+ // The last point can be fixed by disabling premultipliedAlpha in the EngineConstructor,
15
+ // resulting in a bit better subjective colors compared to CET for "ConfiguraHumans".
16
+ //
17
+ // TODO Babylon: Figure out how we can enable the "hdr" flag again. Since we are using
18
+ // PBR we really should be using "hdr" to do things the right way, see this discussion:
19
+ // https://forum.babylonjs.com/t/enabling-hdr-in-defaultpipeline-disables-aa/14656/9
20
+ //
21
+ var pipeline = new DefaultRenderingPipeline("defaultPipeline", false, scene, [camera]);
22
+ // FXAA is not enabled since it causes excessive blur in detailed textures
23
+ // pipeline.fxaaEnabled = true;
24
+ // This affects anti-aliasing, more samples is better but also slower.
25
+ // Note that this does not seem to do anything unless HDR is enabled in the
26
+ // DefaultRenderingPipeline call.
27
+ pipeline.samples = 4;
28
+ pipeline.imageProcessingEnabled = true;
29
+ pipeline.imageProcessing.toneMappingEnabled = true;
30
+ pipeline.imageProcessing.toneMappingType = ImageProcessingConfiguration.TONEMAPPING_ACES;
31
+ // ACES tone mapping needs manual exposure adjustment in Babylon to look good on a normal
32
+ // monitor. More information can be found in the links below, note that "model-viewer" (in
33
+ // their "Fidelity" test) ended up using "1 / 0.6" rather than the value of 2.0 that was first
34
+ // decided upon in their pull request.
35
+ //
36
+ // https://github.com/google/model-viewer/pull/1340
37
+ // https://github.com/mrdoob/three.js/pull/19621
38
+ // https://modelviewer.dev/fidelity/
39
+ pipeline.imageProcessing.exposure = 1 / 0.6;
40
+ // We add a bit of extra contrast to make the image more appealing. This is highly subjective.
41
+ pipeline.imageProcessing.contrast = 1.2;
42
+ // The ACES color correction is quite desaturating, add back a bit of punch to the colors.
43
+ var curve = new ColorCurves();
44
+ curve.midtonesSaturation = 5;
45
+ curve.highlightsSaturation = 15;
46
+ pipeline.imageProcessing.colorCurves = curve;
47
+ pipeline.imageProcessing.colorCurvesEnabled = true;
48
+ };
@@ -1,4 +1,4 @@
1
- import { Engine } from "@babylonjs/core/Engines/engine.js";
2
- export declare type EngineCreator = (canvas: HTMLCanvasElement, width: number, height: number) => Engine;
3
- export declare function getDefaultEngine(canvas: HTMLCanvasElement, width: number, height: number): Engine;
1
+ import { Engine } from "@babylonjs/core/Engines/engine.js";
2
+ export declare type EngineCreator = (canvas: HTMLCanvasElement, width: number, height: number) => Engine;
3
+ export declare function getDefaultEngine(canvas: HTMLCanvasElement, width: number, height: number): Engine;
4
4
  //# sourceMappingURL=EngineCreator.d.ts.map
@@ -1,10 +1,10 @@
1
- import { Engine } from "@babylonjs/core/Engines/engine.js";
2
- export function getDefaultEngine(canvas, width, height) {
3
- // The xrCompatible flag below is used as a workaround for Babylon.js 4.2 crashing in Safari 15
4
- // see WEB-8493 for additional details. It should be safe to apply to all browsers.
5
- //
6
- // TODO: Remove this workaround when upgrading to Babylon.js 5.0
7
- const engine = new Engine(canvas, true, { xrCompatible: false }, true);
8
- engine.setSize(Math.floor(width), Math.floor(height));
9
- return engine;
10
- }
1
+ import { Engine } from "@babylonjs/core/Engines/engine.js";
2
+ export function getDefaultEngine(canvas, width, height) {
3
+ // The xrCompatible flag below is used as a workaround for Babylon.js 4.2 crashing in Safari 15
4
+ // see WEB-8493 for additional details. It should be safe to apply to all browsers.
5
+ //
6
+ // TODO: Remove this workaround when upgrading to Babylon.js 5.0
7
+ const engine = new Engine(canvas, true, { xrCompatible: false, preserveDrawingBuffer: true }, true);
8
+ engine.setSize(Math.floor(width), Math.floor(height));
9
+ return engine;
10
+ }
@@ -1,13 +1,13 @@
1
- import { Geometry } from "@babylonjs/core/Meshes/geometry.js";
2
- import { Mesh } from "@babylonjs/core/Meshes/mesh.js";
3
- import { Scene } from "@babylonjs/core/scene.js";
4
- import { ATriMeshF } from "@configura/web-core/dist/cm/core3D/ATriMeshF.js";
5
- import { LogObservable, LogProducer } from "@configura/web-utilities";
6
- export declare class CfgGeometry extends Geometry implements LogProducer {
7
- private _aTriMesh;
8
- logger: LogObservable;
9
- constructor(id: string, mesh: ATriMeshF, scene: Scene, indices?: Uint32Array | number[]);
10
- cloneWithSubset(indices: Uint32Array | number[]): CfgGeometry;
11
- releaseForMesh(mesh: Mesh, shouldDispose?: boolean | undefined): void;
12
- }
1
+ import { Geometry } from "@babylonjs/core/Meshes/geometry.js";
2
+ import { Mesh } from "@babylonjs/core/Meshes/mesh.js";
3
+ import { Scene } from "@babylonjs/core/scene.js";
4
+ import { ATriMeshF } from "@configura/web-core/dist/cm/core3D/ATriMeshF.js";
5
+ import { LogObservable, LogProducer } from "@configura/web-utilities";
6
+ export declare class CfgGeometry extends Geometry implements LogProducer {
7
+ private _aTriMesh;
8
+ logger: LogObservable;
9
+ constructor(id: string, mesh: ATriMeshF, scene: Scene, indices?: Uint32Array | number[]);
10
+ cloneWithSubset(indices: Uint32Array | number[]): CfgGeometry;
11
+ releaseForMesh(mesh: Mesh, shouldDispose?: boolean | undefined): void;
12
+ }
13
13
  //# sourceMappingURL=CfgGeometry.d.ts.map
@@ -1,117 +1,117 @@
1
- import { Geometry } from "@babylonjs/core/Meshes/geometry.js";
2
- import { VertexData } from "@babylonjs/core/Meshes/mesh.vertexData.js";
3
- import { LogObservable } from "@configura/web-utilities";
4
- export class CfgGeometry extends Geometry {
5
- constructor(id, mesh, scene, indices) {
6
- super(id, scene);
7
- this.logger = new LogObservable();
8
- // Hold on to the ATriMeshF if we need to split the geometry later. It should be faster to
9
- // do it from the original data than to extract it again from the Geometry object and the
10
- // ATriMeshF seems to be kept around anyway in it's SymMesh. This is however something
11
- // that we should try to optimize further.
12
- this._aTriMesh = mesh;
13
- const hasUVs = mesh.uvs.length > 0;
14
- const hasNor = mesh.normals.length > 0;
15
- const hasCol = mesh.colors.length > 0;
16
- const hasTan = mesh.tangents.length > 0;
17
- let ind;
18
- let pos;
19
- let uvs;
20
- let nor;
21
- let tan;
22
- let col;
23
- if (indices === undefined) {
24
- ind = mesh.indices;
25
- pos = mesh.vertices;
26
- uvs = hasUVs ? mesh.uvs : null;
27
- nor = hasNor ? mesh.normals : null;
28
- tan = hasTan ? mesh.tangents : null;
29
- col = hasCol ? mesh.colors : null;
30
- }
31
- else {
32
- const num = indices.length;
33
- // Babylon will use all vertex positions in the Geometry (not only the ones referenced
34
- // by the indices) to determine the bounding box. As such, we need to go through the
35
- // the new subset of indices and only keep the references values in each attribute.
36
- // Loop through all old index values, creating an index map between each unique old
37
- // index value and their corresponding new index into the shorter arrays.
38
- const newIndices = new Uint32Array(num);
39
- const indexMap = new Map();
40
- for (let i = 0; i < num; i++) {
41
- const index = indices[i];
42
- let newIndex = indexMap.get(index);
43
- if (newIndex === undefined) {
44
- newIndex = indexMap.size;
45
- indexMap.set(index, newIndex);
46
- }
47
- newIndices[i] = newIndex;
48
- }
49
- ind = newIndices;
50
- // The length of the indexMap tells us how many unique index value we found.
51
- const count = indexMap.size;
52
- console.log(`Creating CfgGeometry subset (${num / 3}/${mesh.indices.length / 3} triangles, ${count} unique indices)`);
53
- pos = new Float32Array(count * 3);
54
- uvs = hasUVs ? new Float32Array(count * 2) : null;
55
- nor = hasNor ? new Float32Array(count * 3) : null;
56
- tan = hasTan ? new Float32Array(count * 4) : null;
57
- col = hasCol ? new Float32Array(count * 4) : null;
58
- // Use the index map to move only the referenced used values from all the attributes
59
- // over to new smaller arrays.
60
- //
61
- // A note about the code: The code below is "unrolled" by design since it can be a lot
62
- // of indexes to process. A more compact version with an inner loop of 0..3 with some
63
- // additional if checks turned out to be up to 30 times slower in Chrome (1.5ms vs
64
- // 40ms) for the "repack" call when loading and splitting the forklift model.
65
- for (const [index, newIndex] of indexMap) {
66
- pos[newIndex * 3] = mesh.vertices[index * 3];
67
- pos[newIndex * 3 + 1] = mesh.vertices[index * 3 + 1];
68
- pos[newIndex * 3 + 2] = mesh.vertices[index * 3 + 2];
69
- if (uvs) {
70
- uvs[newIndex * 2] = mesh.uvs[index * 2];
71
- uvs[newIndex * 2 + 1] = mesh.uvs[index * 2 + 1];
72
- }
73
- if (nor) {
74
- nor[newIndex * 3] = mesh.normals[index * 3];
75
- nor[newIndex * 3 + 1] = mesh.normals[index * 3 + 1];
76
- nor[newIndex * 3 + 2] = mesh.normals[index * 3 + 2];
77
- }
78
- if (tan) {
79
- tan[newIndex * 4] = mesh.tangents[index * 4];
80
- tan[newIndex * 4 + 1] = mesh.tangents[index * 4 + 1];
81
- tan[newIndex * 4 + 2] = mesh.tangents[index * 4 + 2];
82
- tan[newIndex * 4 + 3] = mesh.tangents[index * 4 + 3];
83
- }
84
- if (col) {
85
- col[newIndex * 4] = mesh.colors[index * 4];
86
- col[newIndex * 4 + 1] = mesh.colors[index * 4 + 1];
87
- col[newIndex * 4 + 2] = mesh.colors[index * 4 + 2];
88
- col[newIndex * 4 + 3] = mesh.colors[index * 4 + 3];
89
- }
90
- }
91
- }
92
- const vertexData = new VertexData();
93
- vertexData.indices = ind;
94
- vertexData.positions = pos;
95
- vertexData.uvs = uvs;
96
- vertexData.normals = nor;
97
- vertexData.tangents = tan;
98
- vertexData.colors = col;
99
- this.setAllVerticesData(vertexData, false);
100
- }
101
- /// Returns a new CfgGeometry containing a subset of this CfgGeometry based on the given indices
102
- cloneWithSubset(indices) {
103
- return new CfgGeometry(this.id + ` (subset ${indices.length})`, this._aTriMesh, this.getScene(), indices);
104
- }
105
- /* This is a hack to prevent this Geometry subclass to get automatically disposed
106
- * when the last associated mesh is disposed, for example when changing options back and
107
- * forth.
108
- *
109
- * IIRC we are using a geometry cache which is probably holding on firmly to this instance
110
- * and reusing it for the next time we need the same mesh. If that cache is ever cleared,
111
- * it should also dispose the geometry inside it.
112
- *
113
- */
114
- releaseForMesh(mesh, shouldDispose) {
115
- super.releaseForMesh(mesh, false);
116
- }
117
- }
1
+ import { Geometry } from "@babylonjs/core/Meshes/geometry.js";
2
+ import { VertexData } from "@babylonjs/core/Meshes/mesh.vertexData.js";
3
+ import { LogObservable } from "@configura/web-utilities";
4
+ export class CfgGeometry extends Geometry {
5
+ constructor(id, mesh, scene, indices) {
6
+ super(id, scene);
7
+ this.logger = new LogObservable();
8
+ // Hold on to the ATriMeshF if we need to split the geometry later. It should be faster to
9
+ // do it from the original data than to extract it again from the Geometry object and the
10
+ // ATriMeshF seems to be kept around anyway in it's SymMesh. This is however something
11
+ // that we should try to optimize further.
12
+ this._aTriMesh = mesh;
13
+ const hasUVs = mesh.uvs.length > 0;
14
+ const hasNor = mesh.normals.length > 0;
15
+ const hasCol = mesh.colors.length > 0;
16
+ const hasTan = mesh.tangents.length > 0;
17
+ let ind;
18
+ let pos;
19
+ let uvs;
20
+ let nor;
21
+ let tan;
22
+ let col;
23
+ if (indices === undefined) {
24
+ ind = mesh.indices;
25
+ pos = mesh.vertices;
26
+ uvs = hasUVs ? mesh.uvs : null;
27
+ nor = hasNor ? mesh.normals : null;
28
+ tan = hasTan ? mesh.tangents : null;
29
+ col = hasCol ? mesh.colors : null;
30
+ }
31
+ else {
32
+ const num = indices.length;
33
+ // Babylon will use all vertex positions in the Geometry (not only the ones referenced
34
+ // by the indices) to determine the bounding box. As such, we need to go through the
35
+ // the new subset of indices and only keep the references values in each attribute.
36
+ // Loop through all old index values, creating an index map between each unique old
37
+ // index value and their corresponding new index into the shorter arrays.
38
+ const newIndices = new Uint32Array(num);
39
+ const indexMap = new Map();
40
+ for (let i = 0; i < num; i++) {
41
+ const index = indices[i];
42
+ let newIndex = indexMap.get(index);
43
+ if (newIndex === undefined) {
44
+ newIndex = indexMap.size;
45
+ indexMap.set(index, newIndex);
46
+ }
47
+ newIndices[i] = newIndex;
48
+ }
49
+ ind = newIndices;
50
+ // The length of the indexMap tells us how many unique index value we found.
51
+ const count = indexMap.size;
52
+ console.log(`Creating CfgGeometry subset (${num / 3}/${mesh.indices.length / 3} triangles, ${count} unique indices)`);
53
+ pos = new Float32Array(count * 3);
54
+ uvs = hasUVs ? new Float32Array(count * 2) : null;
55
+ nor = hasNor ? new Float32Array(count * 3) : null;
56
+ tan = hasTan ? new Float32Array(count * 4) : null;
57
+ col = hasCol ? new Float32Array(count * 4) : null;
58
+ // Use the index map to move only the referenced used values from all the attributes
59
+ // over to new smaller arrays.
60
+ //
61
+ // A note about the code: The code below is "unrolled" by design since it can be a lot
62
+ // of indexes to process. A more compact version with an inner loop of 0..3 with some
63
+ // additional if checks turned out to be up to 30 times slower in Chrome (1.5ms vs
64
+ // 40ms) for the "repack" call when loading and splitting the forklift model.
65
+ for (const [index, newIndex] of indexMap) {
66
+ pos[newIndex * 3] = mesh.vertices[index * 3];
67
+ pos[newIndex * 3 + 1] = mesh.vertices[index * 3 + 1];
68
+ pos[newIndex * 3 + 2] = mesh.vertices[index * 3 + 2];
69
+ if (uvs) {
70
+ uvs[newIndex * 2] = mesh.uvs[index * 2];
71
+ uvs[newIndex * 2 + 1] = mesh.uvs[index * 2 + 1];
72
+ }
73
+ if (nor) {
74
+ nor[newIndex * 3] = mesh.normals[index * 3];
75
+ nor[newIndex * 3 + 1] = mesh.normals[index * 3 + 1];
76
+ nor[newIndex * 3 + 2] = mesh.normals[index * 3 + 2];
77
+ }
78
+ if (tan) {
79
+ tan[newIndex * 4] = mesh.tangents[index * 4];
80
+ tan[newIndex * 4 + 1] = mesh.tangents[index * 4 + 1];
81
+ tan[newIndex * 4 + 2] = mesh.tangents[index * 4 + 2];
82
+ tan[newIndex * 4 + 3] = mesh.tangents[index * 4 + 3];
83
+ }
84
+ if (col) {
85
+ col[newIndex * 4] = mesh.colors[index * 4];
86
+ col[newIndex * 4 + 1] = mesh.colors[index * 4 + 1];
87
+ col[newIndex * 4 + 2] = mesh.colors[index * 4 + 2];
88
+ col[newIndex * 4 + 3] = mesh.colors[index * 4 + 3];
89
+ }
90
+ }
91
+ }
92
+ const vertexData = new VertexData();
93
+ vertexData.indices = ind;
94
+ vertexData.positions = pos;
95
+ vertexData.uvs = uvs;
96
+ vertexData.normals = nor;
97
+ vertexData.tangents = tan;
98
+ vertexData.colors = col;
99
+ this.setAllVerticesData(vertexData, false);
100
+ }
101
+ /// Returns a new CfgGeometry containing a subset of this CfgGeometry based on the given indices
102
+ cloneWithSubset(indices) {
103
+ return new CfgGeometry(this.id + ` (subset ${indices.length})`, this._aTriMesh, this.getScene(), indices);
104
+ }
105
+ /* This is a hack to prevent this Geometry subclass to get automatically disposed
106
+ * when the last associated mesh is disposed, for example when changing options back and
107
+ * forth.
108
+ *
109
+ * IIRC we are using a geometry cache which is probably holding on firmly to this instance
110
+ * and reusing it for the next time we need the same mesh. If that cache is ever cleared,
111
+ * it should also dispose the geometry inside it.
112
+ *
113
+ */
114
+ releaseForMesh(mesh, shouldDispose) {
115
+ super.releaseForMesh(mesh, false);
116
+ }
117
+ }
@@ -1,8 +1,8 @@
1
- import { PBRMaterial } from "@babylonjs/core/Materials/PBR/pbrMaterial.js";
2
- import { Mesh } from "@babylonjs/core/Meshes/mesh.js";
3
- import { RenderEnv } from "../view/RenderEnv.js";
4
- import { CfgGeometry } from "./CfgGeometry.js";
5
- export declare class CfgMesh extends Mesh {
6
- constructor(name: string, renderEnvironment: RenderEnv, geometry: CfgGeometry, material: PBRMaterial);
7
- }
1
+ import { PBRMaterial } from "@babylonjs/core/Materials/PBR/pbrMaterial.js";
2
+ import { Mesh } from "@babylonjs/core/Meshes/mesh.js";
3
+ import { RenderEnv } from "../view/RenderEnv.js";
4
+ import { CfgGeometry } from "./CfgGeometry.js";
5
+ export declare class CfgMesh extends Mesh {
6
+ constructor(name: string, renderEnvironment: RenderEnv, geometry: CfgGeometry, material: PBRMaterial);
7
+ }
8
8
  //# sourceMappingURL=CfgMesh.d.ts.map
@@ -1,8 +1,8 @@
1
- import { Mesh } from "@babylonjs/core/Meshes/mesh.js";
2
- export class CfgMesh extends Mesh {
3
- constructor(name, renderEnvironment, geometry, material) {
4
- super(name, renderEnvironment.scene);
5
- geometry.applyToMesh(this);
6
- this.material = material;
7
- }
8
- }
1
+ import { Mesh } from "@babylonjs/core/Meshes/mesh.js";
2
+ export class CfgMesh extends Mesh {
3
+ constructor(name, renderEnvironment, geometry, material) {
4
+ super(name, renderEnvironment.scene);
5
+ geometry.applyToMesh(this);
6
+ this.material = material;
7
+ }
8
+ }
@@ -1,9 +1,9 @@
1
- import { Logger } from "@configura/web-utilities";
2
- import { CfgGeometry } from "./CfgGeometry.js";
3
- export declare function splitIndexQuick(logger: Logger, geo: CfgGeometry): number[][] | undefined;
4
- export declare function splitIndexComplete(logger: Logger, geo: CfgGeometry, conf: {
5
- maxFinalGroups: number;
6
- maxProgressGroups: number;
7
- acceptCoordinateMatch?: boolean;
8
- }): number[][] | undefined;
1
+ import { Logger } from "@configura/web-utilities";
2
+ import { CfgGeometry } from "./CfgGeometry.js";
3
+ export declare function splitIndexQuick(logger: Logger, geo: CfgGeometry): number[][] | undefined;
4
+ export declare function splitIndexComplete(logger: Logger, geo: CfgGeometry, conf: {
5
+ maxFinalGroups: number;
6
+ maxProgressGroups: number;
7
+ acceptCoordinateMatch?: boolean;
8
+ }): number[][] | undefined;
9
9
  //# sourceMappingURL=geoSplitter.d.ts.map