@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,17 +1,17 @@
1
- import { Matrix, Vector3 } from "@babylonjs/core/Maths/math.vector.js";
2
- export declare class CfgBoundingBox {
3
- minimum: Vector3;
4
- maximum: Vector3;
5
- constructor(minimum?: Vector3, maximum?: Vector3);
6
- private _isEmpty;
7
- reConstruct(minimum: Vector3, maximum: Vector3): CfgBoundingBox;
8
- copyFrom(otherBoundingBox: CfgBoundingBox): CfgBoundingBox;
9
- clone(): CfgBoundingBox;
10
- get center(): Vector3;
11
- translate(vec: Vector3): CfgBoundingBox;
12
- expand(otherBoundingBox: CfgBoundingBox): CfgBoundingBox;
13
- applyMatrix(matrix: Matrix): CfgBoundingBox;
14
- get spaceDiagonal(): number;
15
- get isEmpty(): boolean;
16
- }
1
+ import { Matrix, Vector3 } from "@babylonjs/core/Maths/math.vector.js";
2
+ export declare class CfgBoundingBox {
3
+ minimum: Vector3;
4
+ maximum: Vector3;
5
+ constructor(minimum?: Vector3, maximum?: Vector3);
6
+ private _isEmpty;
7
+ reConstruct(minimum: Vector3, maximum: Vector3): CfgBoundingBox;
8
+ copyFrom(otherBoundingBox: CfgBoundingBox): CfgBoundingBox;
9
+ clone(): CfgBoundingBox;
10
+ get center(): Vector3;
11
+ translate(vec: Vector3): CfgBoundingBox;
12
+ expand(otherBoundingBox: CfgBoundingBox): CfgBoundingBox;
13
+ applyMatrix(matrix: Matrix): CfgBoundingBox;
14
+ get spaceDiagonal(): number;
15
+ get isEmpty(): boolean;
16
+ }
17
17
  //# sourceMappingURL=CfgBoundingBox.d.ts.map
@@ -1,64 +1,64 @@
1
- import { Vector3 } from "@babylonjs/core/Maths/math.vector.js";
2
- export class CfgBoundingBox {
3
- constructor(minimum, maximum) {
4
- /// Means that the bounding box should be seen as "undefined", which is not the same as "zero".
5
- this._isEmpty = true;
6
- this.minimum = (minimum === null || minimum === void 0 ? void 0 : minimum.clone()) || Vector3.Zero();
7
- this.maximum = (maximum === null || maximum === void 0 ? void 0 : maximum.clone()) || Vector3.Zero();
8
- this._isEmpty = minimum === undefined && maximum === undefined;
9
- }
10
- reConstruct(minimum, maximum) {
11
- this.minimum.copyFrom(minimum);
12
- this.maximum.copyFrom(maximum);
13
- this._isEmpty = false;
14
- return this;
15
- }
16
- copyFrom(otherBoundingBox) {
17
- this.reConstruct(otherBoundingBox.minimum, otherBoundingBox.maximum);
18
- this._isEmpty = otherBoundingBox.isEmpty;
19
- return this;
20
- }
21
- clone() {
22
- return new CfgBoundingBox(this.minimum, this.maximum);
23
- }
24
- get center() {
25
- return Vector3.Center(this.minimum, this.maximum);
26
- }
27
- translate(vec) {
28
- this.minimum.addInPlace(vec);
29
- this.maximum.addInPlace(vec);
30
- return this;
31
- }
32
- expand(otherBoundingBox) {
33
- if (otherBoundingBox.isEmpty) {
34
- return this;
35
- }
36
- if (this.isEmpty) {
37
- this.reConstruct(otherBoundingBox.minimum, otherBoundingBox.maximum);
38
- return this;
39
- }
40
- this.reConstruct(this.minimum.minimizeInPlace(otherBoundingBox.minimum), this.maximum.maximizeInPlace(otherBoundingBox.maximum));
41
- return this;
42
- }
43
- applyMatrix(matrix) {
44
- if (this.isEmpty) {
45
- return this;
46
- }
47
- // Transform can be rotation, in which case we might need to re-minimize/maximize
48
- const transformedMin = Vector3.TransformCoordinates(this.minimum, matrix);
49
- const transformedMax = Vector3.TransformCoordinates(this.maximum, matrix);
50
- this.reConstruct(transformedMin.clone().minimizeInPlace(transformedMax), transformedMax.maximizeInPlace(transformedMin));
51
- return this;
52
- }
53
- get spaceDiagonal() {
54
- if (this.isEmpty) {
55
- return 0;
56
- }
57
- const minimum = this.minimum.asArray();
58
- const maximum = this.maximum.asArray();
59
- return Math.sqrt(minimum.reduce((a, c, i) => a + Math.pow(maximum[i] - c, 2)));
60
- }
61
- get isEmpty() {
62
- return this._isEmpty;
63
- }
64
- }
1
+ import { Vector3 } from "@babylonjs/core/Maths/math.vector.js";
2
+ export class CfgBoundingBox {
3
+ constructor(minimum, maximum) {
4
+ /// Means that the bounding box should be seen as "undefined", which is not the same as "zero".
5
+ this._isEmpty = true;
6
+ this.minimum = (minimum === null || minimum === void 0 ? void 0 : minimum.clone()) || Vector3.Zero();
7
+ this.maximum = (maximum === null || maximum === void 0 ? void 0 : maximum.clone()) || Vector3.Zero();
8
+ this._isEmpty = minimum === undefined && maximum === undefined;
9
+ }
10
+ reConstruct(minimum, maximum) {
11
+ this.minimum.copyFrom(minimum);
12
+ this.maximum.copyFrom(maximum);
13
+ this._isEmpty = false;
14
+ return this;
15
+ }
16
+ copyFrom(otherBoundingBox) {
17
+ this.reConstruct(otherBoundingBox.minimum, otherBoundingBox.maximum);
18
+ this._isEmpty = otherBoundingBox.isEmpty;
19
+ return this;
20
+ }
21
+ clone() {
22
+ return new CfgBoundingBox(this.minimum, this.maximum);
23
+ }
24
+ get center() {
25
+ return Vector3.Center(this.minimum, this.maximum);
26
+ }
27
+ translate(vec) {
28
+ this.minimum.addInPlace(vec);
29
+ this.maximum.addInPlace(vec);
30
+ return this;
31
+ }
32
+ expand(otherBoundingBox) {
33
+ if (otherBoundingBox.isEmpty) {
34
+ return this;
35
+ }
36
+ if (this.isEmpty) {
37
+ this.reConstruct(otherBoundingBox.minimum, otherBoundingBox.maximum);
38
+ return this;
39
+ }
40
+ this.reConstruct(this.minimum.minimizeInPlace(otherBoundingBox.minimum), this.maximum.maximizeInPlace(otherBoundingBox.maximum));
41
+ return this;
42
+ }
43
+ applyMatrix(matrix) {
44
+ if (this.isEmpty) {
45
+ return this;
46
+ }
47
+ // Transform can be rotation, in which case we might need to re-minimize/maximize
48
+ const transformedMin = Vector3.TransformCoordinates(this.minimum, matrix);
49
+ const transformedMax = Vector3.TransformCoordinates(this.maximum, matrix);
50
+ this.reConstruct(transformedMin.clone().minimizeInPlace(transformedMax), transformedMax.maximizeInPlace(transformedMin));
51
+ return this;
52
+ }
53
+ get spaceDiagonal() {
54
+ if (this.isEmpty) {
55
+ return 0;
56
+ }
57
+ const minimum = this.minimum.asArray();
58
+ const maximum = this.maximum.asArray();
59
+ return Math.sqrt(minimum.reduce((a, c, i) => a + Math.pow(maximum[i] - c, 2)));
60
+ }
61
+ get isEmpty() {
62
+ return this._isEmpty;
63
+ }
64
+ }
@@ -1,27 +1,27 @@
1
- import { Matrix, Vector3 } from "@babylonjs/core/Maths/math.vector.js";
2
- import { Transform as ModelTransform } from "@configura/web-api";
3
- import { ATriMeshF } from "@configura/web-core/dist/cm/core3D/ATriMeshF.js";
4
- import { SymTransform } from "@configura/web-core/dist/cm/format/cmsym/components/SymTransform.js";
5
- import { Point } from "@configura/web-core/dist/cm/geometry/Point.js";
6
- import { Transform as GeoTransform } from "@configura/web-core/dist/cm/geometry/Transform.js";
7
- import { CfgBoundingBox } from "./CfgBoundingBox.js";
8
- export declare function vector3Equals(left: Vector3, right: Vector3): boolean;
9
- declare type Axis = "x" | "y" | "z";
10
- export declare const getBoundingBoxChangeForAxis: (bbOld: CfgBoundingBox, bbNew: CfgBoundingBox, forMax: boolean, axis: Axis) => number;
11
- export declare const boundingBoxChangeIsSignificantForAxis: (bbOld: CfgBoundingBox, bbNew: CfgBoundingBox, forMax: boolean, axis: Axis, acceptableDifferenceShrink: number, acceptableDifferenceGrow: number) => boolean;
12
- export declare function boundingBoxesAreSignificantlyDifferent(bbOld: CfgBoundingBox, bbNew: CfgBoundingBox, acceptableDifferenceShrink: number, acceptableDifferenceGrow: number): boolean;
13
- export declare function unifyBoundingRect(boundingRect: ClientRect | DOMRect): {
14
- x: number;
15
- y: number;
16
- width: number;
17
- height: number;
18
- };
19
- export declare function symTransformToMatrix(symTransform: GeoTransform): Matrix;
20
- export declare function modelTransformsEqual(left: ModelTransform, right: ModelTransform): boolean;
21
- export declare function modelTransformToSymTransform(modelTransform: ModelTransform): SymTransform;
22
- export declare function cloneName(name: string): string;
23
- export declare function measureLongestDistanceToCorner(bb: CfgBoundingBox, measureComponents: number[]): number;
24
- export declare function aTriMeshSphere(radius?: number, center?: Point, segments?: number): ATriMeshF;
25
- export declare function aTriMeshBox(p0?: Point, p1?: Point): ATriMeshF;
26
- export {};
1
+ import { Matrix, Vector3 } from "@babylonjs/core/Maths/math.vector.js";
2
+ import { Transform as ModelTransform } from "@configura/web-api";
3
+ import { ATriMeshF } from "@configura/web-core/dist/cm/core3D/ATriMeshF.js";
4
+ import { SymTransform } from "@configura/web-core/dist/cm/format/cmsym/components/SymTransform.js";
5
+ import { Point } from "@configura/web-core/dist/cm/geometry/Point.js";
6
+ import { Transform as GeoTransform } from "@configura/web-core/dist/cm/geometry/Transform.js";
7
+ import { CfgBoundingBox } from "./CfgBoundingBox.js";
8
+ export declare function vector3Equals(left: Vector3, right: Vector3): boolean;
9
+ declare type Axis = "x" | "y" | "z";
10
+ export declare const getBoundingBoxChangeForAxis: (bbOld: CfgBoundingBox, bbNew: CfgBoundingBox, forMax: boolean, axis: Axis) => number;
11
+ export declare const boundingBoxChangeIsSignificantForAxis: (bbOld: CfgBoundingBox, bbNew: CfgBoundingBox, forMax: boolean, axis: Axis, acceptableDifferenceShrink: number, acceptableDifferenceGrow: number) => boolean;
12
+ export declare function boundingBoxesAreSignificantlyDifferent(bbOld: CfgBoundingBox, bbNew: CfgBoundingBox, acceptableDifferenceShrink: number, acceptableDifferenceGrow: number): boolean;
13
+ export declare function unifyBoundingRect(boundingRect: ClientRect | DOMRect): {
14
+ x: number;
15
+ y: number;
16
+ width: number;
17
+ height: number;
18
+ };
19
+ export declare function symTransformToMatrix(symTransform: GeoTransform): Matrix;
20
+ export declare function modelTransformsEqual(left: ModelTransform, right: ModelTransform): boolean;
21
+ export declare function modelTransformToSymTransform(modelTransform: ModelTransform): SymTransform;
22
+ export declare function cloneName(name: string): string;
23
+ export declare function measureLongestDistanceToCorner(bb: CfgBoundingBox, measureComponents: number[]): number;
24
+ export declare function aTriMeshSphere(radius?: number, center?: Point, segments?: number): ATriMeshF;
25
+ export declare function aTriMeshBox(p0?: Point, p1?: Point): ATriMeshF;
26
+ export {};
27
27
  //# sourceMappingURL=utilities3D.d.ts.map
@@ -1,187 +1,187 @@
1
- import { Matrix, Vector3 } from "@babylonjs/core/Maths/math.vector.js";
2
- import { ATriMeshF } from "@configura/web-core/dist/cm/core3D/ATriMeshF.js";
3
- import { SymTransform } from "@configura/web-core/dist/cm/format/cmsym/components/SymTransform.js";
4
- import { Angle } from "@configura/web-core/dist/cm/geometry/Angle.js";
5
- import { Matrix33 } from "@configura/web-core/dist/cm/geometry/Matrix33.js";
6
- import { Orientation } from "@configura/web-core/dist/cm/geometry/Orientation.js";
7
- import { Point } from "@configura/web-core/dist/cm/geometry/Point.js";
8
- export function vector3Equals(left, right) {
9
- return left.x === right.x && left.y === right.y && left.z === right.z;
10
- }
11
- const allAxes = ["x", "y", "z"];
12
- /// Calculates the change in one component for min or max when
13
- /// moving from one bounding box to another.
14
- /// Negative result is shrink, positive is grow. forMax is accounted for.
15
- export const getBoundingBoxChangeForAxis = (bbOld, bbNew, forMax, axis) => {
16
- const getMinMax = forMax
17
- ? (bb) => bb.maximum
18
- : (bb) => bb.minimum;
19
- const getC = axis === "x"
20
- ? (c) => c.x
21
- : axis === "y"
22
- ? (c) => c.y
23
- : (c) => c.z;
24
- return ((forMax ? 1 : -1) *
25
- ((getC(getMinMax(bbNew)) - getC(getMinMax(bbOld))) /
26
- Math.abs(getC(bbOld.maximum) - getC(bbOld.minimum))));
27
- };
28
- /// Given an old bounding box and a new tells if the size difference
29
- /// in one component is significant
30
- export const boundingBoxChangeIsSignificantForAxis = (bbOld, bbNew, forMax, axis, acceptableDifferenceShrink, acceptableDifferenceGrow) => {
31
- const change = getBoundingBoxChangeForAxis(bbOld, bbNew, forMax, axis);
32
- return (change < 0 ? acceptableDifferenceShrink : acceptableDifferenceGrow) < Math.abs(change);
33
- };
34
- /// Returns true if one bb was empty and the other not or
35
- /// There is a size change in any of the six primary directions which
36
- /// is larger than acceptableDifferenceShrink or acceptableDifferenceGrow
37
- /// depending if the change from bbOld to bbNew in that direction is
38
- /// shrink or grow.
39
- export function boundingBoxesAreSignificantlyDifferent(bbOld, bbNew, acceptableDifferenceShrink, acceptableDifferenceGrow) {
40
- if (bbOld.isEmpty !== bbNew.isEmpty) {
41
- return true;
42
- }
43
- for (const axis of allAxes) {
44
- for (const forMax of [true, false]) {
45
- if (boundingBoxChangeIsSignificantForAxis(bbOld, bbNew, forMax, axis, acceptableDifferenceShrink, acceptableDifferenceGrow)) {
46
- return true;
47
- }
48
- }
49
- }
50
- return false;
51
- }
52
- export function unifyBoundingRect(boundingRect) {
53
- function isDomRect(object) {
54
- return typeof object === "object" && object !== null && "x" in object;
55
- }
56
- if (isDomRect(boundingRect)) {
57
- return boundingRect;
58
- }
59
- return {
60
- x: boundingRect.left,
61
- y: boundingRect.top,
62
- width: boundingRect.width,
63
- height: boundingRect.height,
64
- };
65
- }
66
- export function symTransformToMatrix(symTransform) {
67
- const pos = symTransform.pos;
68
- const mapping = symTransform.mapping || Matrix33.identity;
69
- const { c0, c1, c2 } = mapping;
70
- return Matrix.FromValues(c0.x, c0.y, c0.z, 0, c1.x, c1.y, c1.z, 0, c2.x, c2.y, c2.z, 0, pos.x, pos.y, pos.z, 1);
71
- }
72
- export function modelTransformsEqual(left, right) {
73
- const { scale: leftScale, pos: leftPos, rot: leftRot } = left;
74
- const { scale: rightScale, pos: rightPos, rot: rightRot } = right;
75
- return (leftScale.x === rightScale.x &&
76
- leftScale.y === rightScale.y &&
77
- leftScale.z === rightScale.z &&
78
- leftPos.x === rightPos.x &&
79
- leftPos.y === rightPos.y &&
80
- leftPos.z === rightPos.z &&
81
- leftRot.pitch === rightRot.pitch &&
82
- leftRot.roll === rightRot.roll &&
83
- leftRot.yaw === rightRot.yaw);
84
- }
85
- export function modelTransformToSymTransform(modelTransform) {
86
- const { pos, scale, rot } = modelTransform;
87
- return new SymTransform(new Point(pos.x, pos.y, pos.z), new Orientation(new Angle(rot.yaw), new Angle(rot.pitch), new Angle(rot.roll)), undefined, new Point(scale.x, scale.y, scale.z));
88
- }
89
- export function cloneName(name) {
90
- if (!name.endsWith(" ")) {
91
- name += " ";
92
- }
93
- return name + "(clone)";
94
- }
95
- export function measureLongestDistanceToCorner(bb, measureComponents) {
96
- if (bb.isEmpty) {
97
- throw Error("Empty bounding box");
98
- }
99
- const minimum = bb.minimum.asArray();
100
- const maximum = bb.maximum.asArray();
101
- let longestSquaredDistanceFromCenter = 0;
102
- const cornerCount = Math.pow(2, measureComponents.length);
103
- for (let i = 0; i < cornerCount; i++) {
104
- const vectorComponents = measureComponents.map((componentIndex, n) => (i & (1 << n) ? minimum : maximum)[componentIndex]);
105
- const squaredDistance = vectorComponents.reduce((pV, cV) => pV + Math.pow(cV, 2), 0);
106
- longestSquaredDistanceFromCenter = Math.max(longestSquaredDistanceFromCenter, squaredDistance);
107
- }
108
- return Math.sqrt(longestSquaredDistanceFromCenter);
109
- }
110
- /// Creates an ATriMeshF instance containing a mesh of a sphere of the given radius (default 1)
111
- /// centered on the given position (default <0,0,0>). The "resolution" of the mesh is set by the
112
- /// segments value (default 32).
113
- ///
114
- /// UV coordinates are generated by wrapping the texture around the sphere like a world map.
115
- export function aTriMeshSphere(radius, center, segments) {
116
- // Simplified and slightly modified (mostly z-up etc) version of SphereBuilder from Babylon.js
117
- // https://github.com/BabylonJS/Babylon.js/blob/master/src/Meshes/Builders/sphereBuilder.ts
118
- const totalYRotationSteps = 2 + (segments !== null && segments !== void 0 ? segments : 32);
119
- const totalZRotationSteps = 2 * totalYRotationSteps;
120
- radius = radius !== null && radius !== void 0 ? radius : 1;
121
- center = center !== null && center !== void 0 ? center : new Point(0, 0, 0);
122
- const offset = new Vector3(center.x, center.y, center.z);
123
- const indices = [];
124
- const positions = [];
125
- const normals = [];
126
- const uvs = [];
127
- for (let yRotationStep = 0; yRotationStep <= totalYRotationSteps; yRotationStep++) {
128
- const normalizedY = yRotationStep / totalYRotationSteps;
129
- const angleY = normalizedY * Math.PI;
130
- for (let zRotationStep = 0; zRotationStep <= totalZRotationSteps; zRotationStep++) {
131
- const normalizedZ = zRotationStep / totalZRotationSteps;
132
- const angleZ = normalizedZ * Math.PI * 2;
133
- const rotationY = Matrix.RotationY(-angleY);
134
- const rotationZ = Matrix.RotationZ(angleZ);
135
- const afterRotY = Vector3.TransformCoordinates(new Vector3(0, 0, 1), rotationY);
136
- const complete = Vector3.TransformCoordinates(afterRotY, rotationZ);
137
- const vertex = complete.scale(radius).add(offset);
138
- const normal = complete.normalize();
139
- positions.push(vertex.x, vertex.y, vertex.z);
140
- normals.push(normal.x, normal.y, normal.z);
141
- uvs.push(normalizedZ, normalizedY);
142
- }
143
- if (yRotationStep > 0) {
144
- const verticesCount = positions.length / 3;
145
- for (let firstIndex = verticesCount - 2 * (totalZRotationSteps + 1); firstIndex + totalZRotationSteps + 2 < verticesCount; firstIndex++) {
146
- indices.push(firstIndex);
147
- indices.push(firstIndex + totalZRotationSteps + 1);
148
- indices.push(firstIndex + 1);
149
- indices.push(firstIndex + totalZRotationSteps + 1);
150
- indices.push(firstIndex + totalZRotationSteps + 2);
151
- indices.push(firstIndex + 1);
152
- }
153
- }
154
- }
155
- // It would probably be faster if we could avoid this step and use the typed arrays directly.
156
- // On the other hand, during testing the calls below took 0ms for 52k indices...
157
- return ATriMeshF.createWithArrays(Uint32Array.from(indices), Float32Array.from(positions), Float32Array.from(normals), Float32Array.from(uvs));
158
- }
159
- /// Creates an ATriMeshF instance containing a mesh of a box between the two points.
160
- /// Default value of p0 is <0,0,0> and p1 is <1,1,1>.
161
- ///
162
- /// UV coordinates are generated, repeating the texture on each side.
163
- export function aTriMeshBox(p0, p1) {
164
- p0 = p0 !== null && p0 !== void 0 ? p0 : new Point(0, 0, 0);
165
- p1 = p1 !== null && p1 !== void 0 ? p1 : new Point(1, 1, 1);
166
- const scales = [p1.x - p0.x, p1.y - p0.y, p1.z - p0.z];
167
- const offsets = [p0.x, p0.y, p0.z];
168
- const positions = BOX_VERTICES.map((value, index) => {
169
- const component = index % 3;
170
- return value * scales[component] + offsets[component];
171
- });
172
- return ATriMeshF.createWithArrays(BOX_INDICES, positions, BOX_NORMALS, BOX_UVS);
173
- }
174
- // prettier-ignore
175
- const BOX_INDICES = new Uint32Array([0, 2, 1, 0, 3, 2, 4, 6, 5, 4, 7, 6, 8, 10, 9, 8, 11, 10, 12,
176
- 14, 13, 12, 15, 14, 16, 18, 17, 16, 19, 18, 20, 22, 21, 20, 23, 22]);
177
- // prettier-ignore
178
- const BOX_NORMALS = new Float32Array([0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, -1, 0, 0, -1, 0, 0,
179
- -1, 0, 0, -1, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, 0, 1,
180
- 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0]);
181
- // prettier-ignore
182
- const BOX_UVS = new Float32Array([1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0,
183
- 1, 0, 0, 0, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0,]);
184
- // prettier-ignore
185
- const BOX_VERTICES = new Float32Array([1, 0, 1, 0, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 0, 0,
186
- 0, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 1, 1, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 1, 1, 0,
187
- 1, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1]);
1
+ import { Matrix, Vector3 } from "@babylonjs/core/Maths/math.vector.js";
2
+ import { ATriMeshF } from "@configura/web-core/dist/cm/core3D/ATriMeshF.js";
3
+ import { SymTransform } from "@configura/web-core/dist/cm/format/cmsym/components/SymTransform.js";
4
+ import { Angle } from "@configura/web-core/dist/cm/geometry/Angle.js";
5
+ import { Matrix33 } from "@configura/web-core/dist/cm/geometry/Matrix33.js";
6
+ import { Orientation } from "@configura/web-core/dist/cm/geometry/Orientation.js";
7
+ import { Point } from "@configura/web-core/dist/cm/geometry/Point.js";
8
+ export function vector3Equals(left, right) {
9
+ return left.x === right.x && left.y === right.y && left.z === right.z;
10
+ }
11
+ const allAxes = ["x", "y", "z"];
12
+ /// Calculates the change in one component for min or max when
13
+ /// moving from one bounding box to another.
14
+ /// Negative result is shrink, positive is grow. forMax is accounted for.
15
+ export const getBoundingBoxChangeForAxis = (bbOld, bbNew, forMax, axis) => {
16
+ const getMinMax = forMax
17
+ ? (bb) => bb.maximum
18
+ : (bb) => bb.minimum;
19
+ const getC = axis === "x"
20
+ ? (c) => c.x
21
+ : axis === "y"
22
+ ? (c) => c.y
23
+ : (c) => c.z;
24
+ return ((forMax ? 1 : -1) *
25
+ ((getC(getMinMax(bbNew)) - getC(getMinMax(bbOld))) /
26
+ Math.abs(getC(bbOld.maximum) - getC(bbOld.minimum))));
27
+ };
28
+ /// Given an old bounding box and a new tells if the size difference
29
+ /// in one component is significant
30
+ export const boundingBoxChangeIsSignificantForAxis = (bbOld, bbNew, forMax, axis, acceptableDifferenceShrink, acceptableDifferenceGrow) => {
31
+ const change = getBoundingBoxChangeForAxis(bbOld, bbNew, forMax, axis);
32
+ return (change < 0 ? acceptableDifferenceShrink : acceptableDifferenceGrow) < Math.abs(change);
33
+ };
34
+ /// Returns true if one bb was empty and the other not or
35
+ /// There is a size change in any of the six primary directions which
36
+ /// is larger than acceptableDifferenceShrink or acceptableDifferenceGrow
37
+ /// depending if the change from bbOld to bbNew in that direction is
38
+ /// shrink or grow.
39
+ export function boundingBoxesAreSignificantlyDifferent(bbOld, bbNew, acceptableDifferenceShrink, acceptableDifferenceGrow) {
40
+ if (bbOld.isEmpty !== bbNew.isEmpty) {
41
+ return true;
42
+ }
43
+ for (const axis of allAxes) {
44
+ for (const forMax of [true, false]) {
45
+ if (boundingBoxChangeIsSignificantForAxis(bbOld, bbNew, forMax, axis, acceptableDifferenceShrink, acceptableDifferenceGrow)) {
46
+ return true;
47
+ }
48
+ }
49
+ }
50
+ return false;
51
+ }
52
+ export function unifyBoundingRect(boundingRect) {
53
+ function isDomRect(object) {
54
+ return typeof object === "object" && object !== null && "x" in object;
55
+ }
56
+ if (isDomRect(boundingRect)) {
57
+ return boundingRect;
58
+ }
59
+ return {
60
+ x: boundingRect.left,
61
+ y: boundingRect.top,
62
+ width: boundingRect.width,
63
+ height: boundingRect.height,
64
+ };
65
+ }
66
+ export function symTransformToMatrix(symTransform) {
67
+ const pos = symTransform.pos;
68
+ const mapping = symTransform.mapping || Matrix33.identity;
69
+ const { c0, c1, c2 } = mapping;
70
+ return Matrix.FromValues(c0.x, c0.y, c0.z, 0, c1.x, c1.y, c1.z, 0, c2.x, c2.y, c2.z, 0, pos.x, pos.y, pos.z, 1);
71
+ }
72
+ export function modelTransformsEqual(left, right) {
73
+ const { scale: leftScale, pos: leftPos, rot: leftRot } = left;
74
+ const { scale: rightScale, pos: rightPos, rot: rightRot } = right;
75
+ return (leftScale.x === rightScale.x &&
76
+ leftScale.y === rightScale.y &&
77
+ leftScale.z === rightScale.z &&
78
+ leftPos.x === rightPos.x &&
79
+ leftPos.y === rightPos.y &&
80
+ leftPos.z === rightPos.z &&
81
+ leftRot.pitch === rightRot.pitch &&
82
+ leftRot.roll === rightRot.roll &&
83
+ leftRot.yaw === rightRot.yaw);
84
+ }
85
+ export function modelTransformToSymTransform(modelTransform) {
86
+ const { pos, scale, rot } = modelTransform;
87
+ return new SymTransform(new Point(pos.x, pos.y, pos.z), new Orientation(new Angle(rot.yaw), new Angle(rot.pitch), new Angle(rot.roll)), undefined, new Point(scale.x, scale.y, scale.z));
88
+ }
89
+ export function cloneName(name) {
90
+ if (!name.endsWith(" ")) {
91
+ name += " ";
92
+ }
93
+ return name + "(clone)";
94
+ }
95
+ export function measureLongestDistanceToCorner(bb, measureComponents) {
96
+ if (bb.isEmpty) {
97
+ throw Error("Empty bounding box");
98
+ }
99
+ const minimum = bb.minimum.asArray();
100
+ const maximum = bb.maximum.asArray();
101
+ let longestSquaredDistanceFromCenter = 0;
102
+ const cornerCount = Math.pow(2, measureComponents.length);
103
+ for (let i = 0; i < cornerCount; i++) {
104
+ const vectorComponents = measureComponents.map((componentIndex, n) => (i & (1 << n) ? minimum : maximum)[componentIndex]);
105
+ const squaredDistance = vectorComponents.reduce((pV, cV) => pV + Math.pow(cV, 2), 0);
106
+ longestSquaredDistanceFromCenter = Math.max(longestSquaredDistanceFromCenter, squaredDistance);
107
+ }
108
+ return Math.sqrt(longestSquaredDistanceFromCenter);
109
+ }
110
+ /// Creates an ATriMeshF instance containing a mesh of a sphere of the given radius (default 1)
111
+ /// centered on the given position (default <0,0,0>). The "resolution" of the mesh is set by the
112
+ /// segments value (default 32).
113
+ ///
114
+ /// UV coordinates are generated by wrapping the texture around the sphere like a world map.
115
+ export function aTriMeshSphere(radius, center, segments) {
116
+ // Simplified and slightly modified (mostly z-up etc) version of SphereBuilder from Babylon.js
117
+ // https://github.com/BabylonJS/Babylon.js/blob/master/src/Meshes/Builders/sphereBuilder.ts
118
+ const totalYRotationSteps = 2 + (segments !== null && segments !== void 0 ? segments : 32);
119
+ const totalZRotationSteps = 2 * totalYRotationSteps;
120
+ radius = radius !== null && radius !== void 0 ? radius : 1;
121
+ center = center !== null && center !== void 0 ? center : new Point(0, 0, 0);
122
+ const offset = new Vector3(center.x, center.y, center.z);
123
+ const indices = [];
124
+ const positions = [];
125
+ const normals = [];
126
+ const uvs = [];
127
+ for (let yRotationStep = 0; yRotationStep <= totalYRotationSteps; yRotationStep++) {
128
+ const normalizedY = yRotationStep / totalYRotationSteps;
129
+ const angleY = normalizedY * Math.PI;
130
+ for (let zRotationStep = 0; zRotationStep <= totalZRotationSteps; zRotationStep++) {
131
+ const normalizedZ = zRotationStep / totalZRotationSteps;
132
+ const angleZ = normalizedZ * Math.PI * 2;
133
+ const rotationY = Matrix.RotationY(-angleY);
134
+ const rotationZ = Matrix.RotationZ(angleZ);
135
+ const afterRotY = Vector3.TransformCoordinates(new Vector3(0, 0, 1), rotationY);
136
+ const complete = Vector3.TransformCoordinates(afterRotY, rotationZ);
137
+ const vertex = complete.scale(radius).add(offset);
138
+ const normal = complete.normalize();
139
+ positions.push(vertex.x, vertex.y, vertex.z);
140
+ normals.push(normal.x, normal.y, normal.z);
141
+ uvs.push(normalizedZ, normalizedY);
142
+ }
143
+ if (yRotationStep > 0) {
144
+ const verticesCount = positions.length / 3;
145
+ for (let firstIndex = verticesCount - 2 * (totalZRotationSteps + 1); firstIndex + totalZRotationSteps + 2 < verticesCount; firstIndex++) {
146
+ indices.push(firstIndex);
147
+ indices.push(firstIndex + totalZRotationSteps + 1);
148
+ indices.push(firstIndex + 1);
149
+ indices.push(firstIndex + totalZRotationSteps + 1);
150
+ indices.push(firstIndex + totalZRotationSteps + 2);
151
+ indices.push(firstIndex + 1);
152
+ }
153
+ }
154
+ }
155
+ // It would probably be faster if we could avoid this step and use the typed arrays directly.
156
+ // On the other hand, during testing the calls below took 0ms for 52k indices...
157
+ return ATriMeshF.createWithArrays(Uint32Array.from(indices), Float32Array.from(positions), Float32Array.from(normals), Float32Array.from(uvs));
158
+ }
159
+ /// Creates an ATriMeshF instance containing a mesh of a box between the two points.
160
+ /// Default value of p0 is <0,0,0> and p1 is <1,1,1>.
161
+ ///
162
+ /// UV coordinates are generated, repeating the texture on each side.
163
+ export function aTriMeshBox(p0, p1) {
164
+ p0 = p0 !== null && p0 !== void 0 ? p0 : new Point(0, 0, 0);
165
+ p1 = p1 !== null && p1 !== void 0 ? p1 : new Point(1, 1, 1);
166
+ const scales = [p1.x - p0.x, p1.y - p0.y, p1.z - p0.z];
167
+ const offsets = [p0.x, p0.y, p0.z];
168
+ const positions = BOX_VERTICES.map((value, index) => {
169
+ const component = index % 3;
170
+ return value * scales[component] + offsets[component];
171
+ });
172
+ return ATriMeshF.createWithArrays(BOX_INDICES, positions, BOX_NORMALS, BOX_UVS);
173
+ }
174
+ // prettier-ignore
175
+ const BOX_INDICES = new Uint32Array([0, 2, 1, 0, 3, 2, 4, 6, 5, 4, 7, 6, 8, 10, 9, 8, 11, 10, 12,
176
+ 14, 13, 12, 15, 14, 16, 18, 17, 16, 19, 18, 20, 22, 21, 20, 23, 22]);
177
+ // prettier-ignore
178
+ const BOX_NORMALS = new Float32Array([0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, -1, 0, 0, -1, 0, 0,
179
+ -1, 0, 0, -1, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, 0, 1,
180
+ 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0]);
181
+ // prettier-ignore
182
+ const BOX_UVS = new Float32Array([1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0,
183
+ 1, 0, 0, 0, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0,]);
184
+ // prettier-ignore
185
+ const BOX_VERTICES = new Float32Array([1, 0, 1, 0, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 0, 0,
186
+ 0, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 1, 1, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 1, 1, 0,
187
+ 1, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1]);
@@ -1,19 +1,19 @@
1
- import { Color3 } from "@babylonjs/core/Maths/math.color.js";
2
- import { Color } from "@configura/web-core/dist/cm/basic/Color.js";
3
- import { ColorF } from "@configura/web-core/dist/cm/basic/ColorF.js";
4
- /**
5
- * Converts a number of different color formats into Color3 for use with Babylon.js
6
- * Returns White if object is undefined.
7
- */
8
- export declare function toColor3(object: Color3 | ColorF | Color | string | number | undefined): Color3;
9
- /**
10
- * in: r,g,b in [0,1], out: h in [0,360) and s,l in [0,1]
11
- * Original source: https://stackoverflow.com/a/54071699/1488048
12
- */
13
- export declare function rgb2hsl(r: number, g: number, b: number): number[];
14
- /**
15
- * input: h in [0,360] and s,v in [0,1] - output: r,g,b in [0,1]
16
- * Original source: https://stackoverflow.com/a/54014428/1488048
17
- */
18
- export declare function hsl2rgb(h: number, s: number, l: number): number[];
1
+ import { Color3 } from "@babylonjs/core/Maths/math.color.js";
2
+ import { Color } from "@configura/web-core/dist/cm/basic/Color.js";
3
+ import { ColorF } from "@configura/web-core/dist/cm/basic/ColorF.js";
4
+ /**
5
+ * Converts a number of different color formats into Color3 for use with Babylon.js
6
+ * Returns White if object is undefined.
7
+ */
8
+ export declare function toColor3(object: Color3 | ColorF | Color | string | number | undefined): Color3;
9
+ /**
10
+ * in: r,g,b in [0,1], out: h in [0,360) and s,l in [0,1]
11
+ * Original source: https://stackoverflow.com/a/54071699/1488048
12
+ */
13
+ export declare function rgb2hsl(r: number, g: number, b: number): number[];
14
+ /**
15
+ * input: h in [0,360] and s,v in [0,1] - output: r,g,b in [0,1]
16
+ * Original source: https://stackoverflow.com/a/54014428/1488048
17
+ */
18
+ export declare function hsl2rgb(h: number, s: number, l: number): number[];
19
19
  //# sourceMappingURL=utilitiesColor.d.ts.map