@configura/babylon-view 1.3.0-alpha.3 → 1.3.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 (125) 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 +26 -10
  42. package/dist/camera/CfgArcRotateCameraPointersInput.js +264 -262
  43. package/dist/camera/CfgOrbitalCamera.d.ts +68 -68
  44. package/dist/camera/CfgOrbitalCamera.js +250 -250
  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 +29 -12
  52. package/dist/geometry/CfgGeometry.js +146 -117
  53. package/dist/geometry/CfgMesh.d.ts +10 -7
  54. package/dist/geometry/CfgMesh.js +38 -8
  55. package/dist/geometry/geoSplitter.d.ts +8 -8
  56. package/dist/geometry/geoSplitter.js +192 -192
  57. package/dist/geometry/stretch/CfgMorphTarget.d.ts +16 -0
  58. package/dist/geometry/stretch/CfgMorphTarget.js +65 -0
  59. package/dist/geometry/stretch/CfgStretchData.d.ts +115 -0
  60. package/dist/geometry/stretch/CfgStretchData.js +340 -0
  61. package/dist/geometry/stretch/CfgStretchMorphGeometry.d.ts +17 -0
  62. package/dist/geometry/stretch/CfgStretchMorphGeometry.js +95 -0
  63. package/dist/index.d.ts +13 -13
  64. package/dist/index.js +13 -13
  65. package/dist/light/CfgDirectionalLight.d.ts +8 -8
  66. package/dist/light/CfgDirectionalLight.js +18 -18
  67. package/dist/light/CfgHemisphericLight.d.ts +7 -7
  68. package/dist/light/CfgHemisphericLight.js +17 -17
  69. package/dist/light/CfgPointLight.d.ts +8 -8
  70. package/dist/light/CfgPointLight.js +18 -18
  71. package/dist/light/DefaultLightRig.d.ts +19 -19
  72. package/dist/light/DefaultLightRig.js +77 -77
  73. package/dist/light/LightRigCreator.d.ts +9 -9
  74. package/dist/light/LightRigCreator.js +3 -3
  75. package/dist/material/CfgMaterial.d.ts +68 -53
  76. package/dist/material/CfgMaterial.js +482 -454
  77. package/dist/material/DummyMaterialCreator.d.ts +4 -4
  78. package/dist/material/DummyMaterialCreator.js +15 -15
  79. package/dist/material/material.d.ts +18 -18
  80. package/dist/material/material.js +128 -128
  81. package/dist/material/texture.d.ts +14 -14
  82. package/dist/material/texture.js +306 -304
  83. package/dist/nodes/CfgContentRootNode.d.ts +19 -19
  84. package/dist/nodes/CfgContentRootNode.js +75 -75
  85. package/dist/nodes/CfgDeferredMeshNode.d.ts +55 -48
  86. package/dist/nodes/CfgDeferredMeshNode.js +377 -347
  87. package/dist/nodes/CfgProductNode.d.ts +126 -61
  88. package/dist/nodes/CfgProductNode.js +578 -486
  89. package/dist/nodes/CfgSymNode.d.ts +50 -42
  90. package/dist/nodes/CfgSymNode.js +249 -216
  91. package/dist/nodes/CfgSymRootNode.d.ts +45 -33
  92. package/dist/nodes/CfgSymRootNode.js +220 -175
  93. package/dist/nodes/CfgTransformNode.d.ts +33 -29
  94. package/dist/nodes/CfgTransformNode.js +83 -81
  95. package/dist/scene/SceneCreator.d.ts +6 -6
  96. package/dist/scene/SceneCreator.js +22 -22
  97. package/dist/utilities/CfgBoundingBox.d.ts +21 -16
  98. package/dist/utilities/CfgBoundingBox.js +81 -64
  99. package/dist/utilities/anchor/anchor.d.ts +52 -0
  100. package/dist/utilities/anchor/anchor.js +136 -0
  101. package/dist/utilities/anchor/anchorMap.d.ts +21 -0
  102. package/dist/utilities/anchor/anchorMap.js +111 -0
  103. package/dist/utilities/utilities3D.d.ts +70 -26
  104. package/dist/utilities/utilities3D.js +265 -187
  105. package/dist/utilities/utilitiesColor.d.ts +18 -18
  106. package/dist/utilities/utilitiesColor.js +48 -48
  107. package/dist/utilities/utilitiesImage.d.ts +6 -6
  108. package/dist/utilities/utilitiesImage.js +107 -107
  109. package/dist/utilities/utilitiesSymRootIdentifier.d.ts +7 -5
  110. package/dist/utilities/utilitiesSymRootIdentifier.js +26 -20
  111. package/dist/view/BaseView.d.ts +78 -70
  112. package/dist/view/BaseView.js +297 -291
  113. package/dist/view/BaseViewConfiguration.d.ts +32 -32
  114. package/dist/view/BaseViewConfiguration.js +8 -8
  115. package/dist/view/RenderEnv.d.ts +43 -38
  116. package/dist/view/RenderEnv.js +7 -7
  117. package/dist/view/SingleProductDefaultCameraView.d.ts +33 -33
  118. package/dist/view/SingleProductDefaultCameraView.js +141 -141
  119. package/dist/view/SingleProductDefaultCameraViewConfiguration.d.ts +46 -46
  120. package/dist/view/SingleProductDefaultCameraViewConfiguration.js +11 -11
  121. package/dist/view/SingleProductView.d.ts +49 -42
  122. package/dist/view/SingleProductView.js +206 -205
  123. package/dist/view/SingleProductViewConfiguration.d.ts +32 -32
  124. package/dist/view/SingleProductViewConfiguration.js +19 -19
  125. package/package.json +5 -5
@@ -1,187 +1,265 @@
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
+ export function cmPointToVector3(point) {
12
+ return new Vector3(point.x, point.y, point.z);
13
+ }
14
+ const allAxes = ["x", "y", "z"];
15
+ /**
16
+ * Calculates the change in one component for min or max when moving from one bounding box to
17
+ * another. Negative result is shrink, positive is grow. forMax is accounted for.
18
+ */
19
+ export const getBoundingBoxChangeForAxis = (bbOld, bbNew, forMax, axis) => {
20
+ const getMinMax = forMax
21
+ ? (bb) => bb.maximum
22
+ : (bb) => bb.minimum;
23
+ const getC = axis === "x"
24
+ ? (c) => c.x
25
+ : axis === "y"
26
+ ? (c) => c.y
27
+ : (c) => c.z;
28
+ return ((forMax ? 1 : -1) *
29
+ ((getC(getMinMax(bbNew)) - getC(getMinMax(bbOld))) /
30
+ Math.abs(getC(bbOld.maximum) - getC(bbOld.minimum))));
31
+ };
32
+ /**
33
+ * Given an old bounding box and a new tells if the size difference in one component is significant.
34
+ */
35
+ export const boundingBoxChangeIsSignificantForAxis = (bbOld, bbNew, forMax, axis, acceptableDifferenceShrink, acceptableDifferenceGrow) => {
36
+ const change = getBoundingBoxChangeForAxis(bbOld, bbNew, forMax, axis);
37
+ return (change < 0 ? acceptableDifferenceShrink : acceptableDifferenceGrow) < Math.abs(change);
38
+ };
39
+ /**
40
+ * Returns true if either:
41
+ * - One bounding box was empty and the other not.
42
+ * - There is a size change in any of the six primary directions which is larger than
43
+ * acceptableDifferenceShrink or acceptableDifferenceGrow depending if the change from bbOld to
44
+ * bbNew in that direction is shrink or grow.
45
+ */
46
+ export function boundingBoxesAreSignificantlyDifferent(bbOld, bbNew, acceptableDifferenceShrink, acceptableDifferenceGrow) {
47
+ if (bbOld.isEmpty !== bbNew.isEmpty) {
48
+ return true;
49
+ }
50
+ for (const axis of allAxes) {
51
+ for (const forMax of [true, false]) {
52
+ if (boundingBoxChangeIsSignificantForAxis(bbOld, bbNew, forMax, axis, acceptableDifferenceShrink, acceptableDifferenceGrow)) {
53
+ return true;
54
+ }
55
+ }
56
+ }
57
+ return false;
58
+ }
59
+ export function unifyBoundingRect(boundingRect) {
60
+ function isDomRect(object) {
61
+ return typeof object === "object" && object !== null && "x" in object;
62
+ }
63
+ if (isDomRect(boundingRect)) {
64
+ return boundingRect;
65
+ }
66
+ return {
67
+ x: boundingRect.left,
68
+ y: boundingRect.top,
69
+ width: boundingRect.width,
70
+ height: boundingRect.height,
71
+ };
72
+ }
73
+ export function symTransformToMatrix(symTransform) {
74
+ const pos = symTransform.pos;
75
+ const mapping = symTransform.mapping || Matrix33.identity;
76
+ const { c0, c1, c2 } = mapping;
77
+ 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);
78
+ }
79
+ export function modelTransformsEqual(left, right) {
80
+ const { scale: leftScale, pos: leftPos, rot: leftRot } = left;
81
+ const { scale: rightScale, pos: rightPos, rot: rightRot } = right;
82
+ return (leftScale.x === rightScale.x &&
83
+ leftScale.y === rightScale.y &&
84
+ leftScale.z === rightScale.z &&
85
+ leftPos.x === rightPos.x &&
86
+ leftPos.y === rightPos.y &&
87
+ leftPos.z === rightPos.z &&
88
+ leftRot.pitch === rightRot.pitch &&
89
+ leftRot.roll === rightRot.roll &&
90
+ leftRot.yaw === rightRot.yaw);
91
+ }
92
+ export function modelTransformToSymTransform(modelTransform) {
93
+ const { pos, scale, rot } = modelTransform;
94
+ 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));
95
+ }
96
+ export function cloneName(name) {
97
+ if (!name.endsWith(" ")) {
98
+ name += " ";
99
+ }
100
+ return name + "(clone)";
101
+ }
102
+ export function measureLongestDistanceToCorner(bb, measureComponents) {
103
+ if (bb.isEmpty) {
104
+ throw Error("Empty bounding box");
105
+ }
106
+ const minimum = bb.minimum.asArray();
107
+ const maximum = bb.maximum.asArray();
108
+ let longestSquaredDistanceFromCenter = 0;
109
+ const cornerCount = Math.pow(2, measureComponents.length);
110
+ for (let i = 0; i < cornerCount; i++) {
111
+ const vectorComponents = measureComponents.map((componentIndex, n) => (i & (1 << n) ? minimum : maximum)[componentIndex]);
112
+ const squaredDistance = vectorComponents.reduce((pV, cV) => pV + Math.pow(cV, 2), 0);
113
+ longestSquaredDistanceFromCenter = Math.max(longestSquaredDistanceFromCenter, squaredDistance);
114
+ }
115
+ return Math.sqrt(longestSquaredDistanceFromCenter);
116
+ }
117
+ /**
118
+ * Creates an ATriMeshF instance containing a mesh of a sphere of the given radius (default 1)
119
+ * centered on the given position (default <0,0,0>). The "resolution" of the mesh is set by the
120
+ * segments value (default 32).
121
+ *
122
+ * UV coordinates are generated by wrapping the texture around the sphere like a world map.
123
+ */
124
+ export function aTriMeshSphere(radius, center, segments) {
125
+ // Simplified and slightly modified (mostly z-up etc) version of SphereBuilder from Babylon.js
126
+ // https://github.com/BabylonJS/Babylon.js/blob/master/src/Meshes/Builders/sphereBuilder.ts
127
+ const totalYRotationSteps = 2 + (segments !== null && segments !== void 0 ? segments : 32);
128
+ const totalZRotationSteps = 2 * totalYRotationSteps;
129
+ radius = radius !== null && radius !== void 0 ? radius : 1;
130
+ center = center !== null && center !== void 0 ? center : new Point(0, 0, 0);
131
+ const offset = new Vector3(center.x, center.y, center.z);
132
+ const indices = [];
133
+ const positions = [];
134
+ const normals = [];
135
+ const uvs = [];
136
+ for (let yRotationStep = 0; yRotationStep <= totalYRotationSteps; yRotationStep++) {
137
+ const normalizedY = yRotationStep / totalYRotationSteps;
138
+ const angleY = normalizedY * Math.PI;
139
+ for (let zRotationStep = 0; zRotationStep <= totalZRotationSteps; zRotationStep++) {
140
+ const normalizedZ = zRotationStep / totalZRotationSteps;
141
+ const angleZ = normalizedZ * Math.PI * 2;
142
+ const rotationY = Matrix.RotationY(-angleY);
143
+ const rotationZ = Matrix.RotationZ(angleZ);
144
+ const afterRotY = Vector3.TransformCoordinates(new Vector3(0, 0, 1), rotationY);
145
+ const complete = Vector3.TransformCoordinates(afterRotY, rotationZ);
146
+ const vertex = complete.scale(radius).add(offset);
147
+ const normal = complete.normalize();
148
+ positions.push(vertex.x, vertex.y, vertex.z);
149
+ normals.push(normal.x, normal.y, normal.z);
150
+ uvs.push(normalizedZ, normalizedY);
151
+ }
152
+ if (yRotationStep > 0) {
153
+ const verticesCount = positions.length / 3;
154
+ for (let firstIndex = verticesCount - 2 * (totalZRotationSteps + 1); firstIndex + totalZRotationSteps + 2 < verticesCount; firstIndex++) {
155
+ indices.push(firstIndex);
156
+ indices.push(firstIndex + totalZRotationSteps + 1);
157
+ indices.push(firstIndex + 1);
158
+ indices.push(firstIndex + totalZRotationSteps + 1);
159
+ indices.push(firstIndex + totalZRotationSteps + 2);
160
+ indices.push(firstIndex + 1);
161
+ }
162
+ }
163
+ }
164
+ // It would probably be faster if we could avoid this step and use the typed arrays directly.
165
+ // On the other hand, during testing the calls below took 0ms for 52k indices...
166
+ return ATriMeshF.createWithArrays(Uint32Array.from(indices), Float32Array.from(positions), Float32Array.from(normals), Float32Array.from(uvs));
167
+ }
168
+ /**
169
+ * Creates an ATriMeshF instance containing a mesh of a box between the two points.
170
+ * Default value of p0 is <0,0,0> and p1 is <1,1,1>.
171
+ *
172
+ * UV coordinates are generated, repeating the texture on each side.
173
+ */
174
+ export function aTriMeshBox(p0, p1) {
175
+ p0 = p0 !== null && p0 !== void 0 ? p0 : new Point(0, 0, 0);
176
+ p1 = p1 !== null && p1 !== void 0 ? p1 : new Point(1, 1, 1);
177
+ const scales = [p1.x - p0.x, p1.y - p0.y, p1.z - p0.z];
178
+ const offsets = [p0.x, p0.y, p0.z];
179
+ const positions = BOX_VERTICES.map((value, index) => {
180
+ const component = index % 3;
181
+ return value * scales[component] + offsets[component];
182
+ });
183
+ return ATriMeshF.createWithArrays(BOX_INDICES, positions, BOX_NORMALS, BOX_UVS);
184
+ }
185
+ // prettier-ignore
186
+ const BOX_INDICES = new Uint32Array([0, 2, 1, 0, 3, 2, 4, 6, 5, 4, 7, 6, 8, 10, 9, 8, 11, 10, 12,
187
+ 14, 13, 12, 15, 14, 16, 18, 17, 16, 19, 18, 20, 22, 21, 20, 23, 22]);
188
+ // prettier-ignore
189
+ 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,
190
+ -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,
191
+ 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0]);
192
+ // prettier-ignore
193
+ 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,
194
+ 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,]);
195
+ // prettier-ignore
196
+ 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,
197
+ 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,
198
+ 1, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1]);
199
+ /**
200
+ * Creates an ATriMeshF instance containing a mesh representing an infinite plane with the given
201
+ * normal, offset by the given distance along the normal.
202
+ *
203
+ * Due to automatic bounding box calculations, the infinite plane is represented by a circular disc
204
+ * with the given radius centered on a point offset from the origin along the normal vector.
205
+ *
206
+ * The number of triangles in the disc is controlled by the refine parameter. The minimum number of
207
+ * triangles is 4, each refine step doubles the triangle count.
208
+ *
209
+ * Default normal: 1, 0, 0
210
+ * Default offset: 0
211
+ * Default radius: 1
212
+ * Default refinement: 4 (64 triangles)
213
+ */
214
+ export function aTriMeshPlane(normal, offset, radius, refine) {
215
+ normal = normal !== null && normal !== void 0 ? normal : new Point(0, 0, 1);
216
+ offset = offset !== null && offset !== void 0 ? offset : 0;
217
+ radius = radius !== null && radius !== void 0 ? radius : 1;
218
+ refine = refine !== null && refine !== void 0 ? refine : 4;
219
+ const normalVec = new Vector3(normal.x, normal.y, normal.z).normalize();
220
+ let base1 = normalVec.cross(new Vector3(1, 0, 0));
221
+ if (base1.length() < 0.2) {
222
+ // Normal was pretty close to 1, 0, 0, try another base vector
223
+ base1 = normalVec.cross(new Vector3(0, 1, 0));
224
+ }
225
+ base1 = base1.normalize();
226
+ const base2 = base1.cross(normalVec);
227
+ let points = new Array(5);
228
+ points[0] = Vector3.Zero();
229
+ points[1] = base1;
230
+ points[2] = base2;
231
+ points[3] = base1.negate();
232
+ points[4] = base2.negate();
233
+ for (let i = 0; i < refine; i++) {
234
+ points = refineCircle(points);
235
+ }
236
+ const numTriangles = points.length - 1;
237
+ const indices = new Uint32Array(numTriangles * 3);
238
+ for (let i = 0; i < numTriangles; i++) {
239
+ const index = i * 3;
240
+ indices[index] = 0;
241
+ indices[index + 1] = i + 1;
242
+ indices[index + 2] = i >= numTriangles - 1 ? 1 : i + 2;
243
+ }
244
+ const vertices = new Float32Array(points.length * 3);
245
+ for (let i = 0; i < points.length; i++) {
246
+ const point = points[i];
247
+ const index = i * 3;
248
+ vertices[index] = point.x * radius + normal.x * offset;
249
+ vertices[index + 1] = point.y * radius + normal.y * offset;
250
+ vertices[index + 2] = point.z * radius + normal.z * offset;
251
+ }
252
+ const mesh = ATriMeshF.createWithArrays(indices, vertices);
253
+ mesh.doubleSided = true;
254
+ return mesh;
255
+ }
256
+ function refineCircle(points) {
257
+ const refined = new Array(points.length * 2 - 1);
258
+ refined[0] = points[0];
259
+ for (let i = 1; i < points.length; i++) {
260
+ const next = (i >= points.length - 1 ? 0 : i) + 1;
261
+ refined[i * 2 - 1] = points[i];
262
+ refined[i * 2] = points[i].add(points[next]).normalize();
263
+ }
264
+ return refined;
265
+ }
@@ -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
@@ -1,48 +1,48 @@
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 function toColor3(object) {
9
- if (object === undefined) {
10
- return Color3.White();
11
- }
12
- if (typeof object === "number") {
13
- // Assume object is a 24 bit integer
14
- return Color3.FromInts((object >>> 16) & 0xff, (object >>> 8) & 0xff, object & 0xff);
15
- }
16
- if (typeof object === "string") {
17
- // Assume object is a hex-string
18
- return Color3.FromHexString(object);
19
- }
20
- if (object instanceof ColorF) {
21
- // Object is a DEX ColorF (floats, 0-1)
22
- return new Color3(object.r, object.g, object.b);
23
- }
24
- if (object instanceof Color) {
25
- // Object is a DEX Color (integers 0-255)
26
- return Color3.FromInts(object.r, object.g, object.b);
27
- }
28
- // Must be Color3 already
29
- return object;
30
- }
31
- /**
32
- * in: r,g,b in [0,1], out: h in [0,360) and s,l in [0,1]
33
- * Original source: https://stackoverflow.com/a/54071699/1488048
34
- */
35
- export function rgb2hsl(r, g, b) {
36
- let a = Math.max(r, g, b), n = a - Math.min(r, g, b), f = 1 - Math.abs(a + a - n - 1);
37
- let h = n && (a === r ? (g - b) / n : a === g ? 2 + (b - r) / n : 4 + (r - g) / n);
38
- return [60 * (h < 0 ? h + 6 : h), f ? n / f : 0, (a + a - n) / 2];
39
- }
40
- /**
41
- * input: h in [0,360] and s,v in [0,1] - output: r,g,b in [0,1]
42
- * Original source: https://stackoverflow.com/a/54014428/1488048
43
- */
44
- export function hsl2rgb(h, s, l) {
45
- let a = s * Math.min(l, 1 - l);
46
- let f = (n, k = (n + h / 30) % 12) => l - a * Math.max(Math.min(k - 3, 9 - k, 1), -1);
47
- return [f(0), f(8), f(4)];
48
- }
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 function toColor3(object) {
9
+ if (object === undefined) {
10
+ return Color3.White();
11
+ }
12
+ if (typeof object === "number") {
13
+ // Assume object is a 24 bit integer
14
+ return Color3.FromInts((object >>> 16) & 0xff, (object >>> 8) & 0xff, object & 0xff);
15
+ }
16
+ if (typeof object === "string") {
17
+ // Assume object is a hex-string
18
+ return Color3.FromHexString(object);
19
+ }
20
+ if (object instanceof ColorF) {
21
+ // Object is a DEX ColorF (floats, 0-1)
22
+ return new Color3(object.r, object.g, object.b);
23
+ }
24
+ if (object instanceof Color) {
25
+ // Object is a DEX Color (integers 0-255)
26
+ return Color3.FromInts(object.r, object.g, object.b);
27
+ }
28
+ // Must be Color3 already
29
+ return object;
30
+ }
31
+ /**
32
+ * in: r,g,b in [0,1], out: h in [0,360) and s,l in [0,1]
33
+ * Original source: https://stackoverflow.com/a/54071699/1488048
34
+ */
35
+ export function rgb2hsl(r, g, b) {
36
+ let a = Math.max(r, g, b), n = a - Math.min(r, g, b), f = 1 - Math.abs(a + a - n - 1);
37
+ let h = n && (a === r ? (g - b) / n : a === g ? 2 + (b - r) / n : 4 + (r - g) / n);
38
+ return [60 * (h < 0 ? h + 6 : h), f ? n / f : 0, (a + a - n) / 2];
39
+ }
40
+ /**
41
+ * input: h in [0,360] and s,v in [0,1] - output: r,g,b in [0,1]
42
+ * Original source: https://stackoverflow.com/a/54014428/1488048
43
+ */
44
+ export function hsl2rgb(h, s, l) {
45
+ let a = s * Math.min(l, 1 - l);
46
+ let f = (n, k = (n + h / 30) % 12) => l - a * Math.max(Math.min(k - 3, 9 - k, 1), -1);
47
+ return [f(0), f(8), f(4)];
48
+ }
@@ -1,7 +1,7 @@
1
- import { Color } from "@configura/web-core/dist/cm/basic/Color.js";
2
- export declare function aggregateImage<T>(image: HTMLImageElement, aggregator: (imgData: ImageData) => T): T | undefined;
3
- export declare function calculateLightnessFromImage(image: HTMLImageElement): number | undefined;
4
- export declare function allPixelsAreColor(image: HTMLImageElement): false | Color;
5
- export declare function isLikelyBumpMap(image: HTMLImageElement, acceptableDeviationFromGray?: number): boolean;
6
- export declare function isLikelyNormalMap(image: HTMLImageElement): boolean;
1
+ import { Color } from "@configura/web-core/dist/cm/basic/Color.js";
2
+ export declare function aggregateImage<T>(image: HTMLImageElement, aggregator: (imgData: ImageData) => T): T | undefined;
3
+ export declare function calculateLightnessFromImage(image: HTMLImageElement): number | undefined;
4
+ export declare function allPixelsAreColor(image: HTMLImageElement): false | Color;
5
+ export declare function isLikelyBumpMap(image: HTMLImageElement, acceptableDeviationFromGray?: number): boolean;
6
+ export declare function isLikelyNormalMap(image: HTMLImageElement): boolean;
7
7
  //# sourceMappingURL=utilitiesImage.d.ts.map