@configura/babylon-view 2.0.0-alpha.20 → 2.0.0-alpha.21

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 (134) hide show
  1. package/.eslintrc.json +5 -18
  2. package/LICENSE +201 -201
  3. package/README.md +1 -1
  4. package/dist/animation/AnimatableObject.d.ts +8 -8
  5. package/dist/animation/AnimatableObject.js +3 -3
  6. package/dist/animation/animator/Animator.d.ts +33 -33
  7. package/dist/animation/animator/Animator.js +58 -58
  8. package/dist/animation/animator/AnimatorEasing.d.ts +16 -16
  9. package/dist/animation/animator/AnimatorEasing.js +31 -31
  10. package/dist/animation/animator/AnimatorEasingMatrix.d.ts +14 -14
  11. package/dist/animation/animator/AnimatorEasingMatrix.js +16 -16
  12. package/dist/animation/animator/AnimatorHighlight.d.ts +16 -16
  13. package/dist/animation/animator/AnimatorHighlight.js +32 -32
  14. package/dist/animation/animator/AnimatorPointToPoint.d.ts +8 -8
  15. package/dist/animation/animator/AnimatorPointToPoint.js +14 -14
  16. package/dist/animation/animator/AnimatorQueue.d.ts +13 -13
  17. package/dist/animation/animator/AnimatorQueue.js +57 -57
  18. package/dist/animation/animator/AnimatorScale.d.ts +8 -8
  19. package/dist/animation/animator/AnimatorScale.js +13 -13
  20. package/dist/animation/animator/AnimatorSpin.d.ts +10 -10
  21. package/dist/animation/animator/AnimatorSpin.js +13 -13
  22. package/dist/animation/animator/EasingFunctions.d.ts +35 -35
  23. package/dist/animation/animator/EasingFunctions.js +137 -137
  24. package/dist/animation/coordinator/Coordinator.d.ts +28 -28
  25. package/dist/animation/coordinator/Coordinator.js +53 -53
  26. package/dist/animation/coordinator/CoordinatorDropAndSpin.d.ts +22 -22
  27. package/dist/animation/coordinator/CoordinatorDropAndSpin.js +138 -138
  28. package/dist/animation/coordinator/CoordinatorIdentity.d.ts +11 -11
  29. package/dist/animation/coordinator/CoordinatorIdentity.js +14 -14
  30. package/dist/animation/coordinator/CoordinatorNodeQueues.d.ts +18 -18
  31. package/dist/animation/coordinator/CoordinatorNodeQueues.js +50 -50
  32. package/dist/animation/coordinator/CoordinatorPulse.d.ts +21 -21
  33. package/dist/animation/coordinator/CoordinatorPulse.js +47 -47
  34. package/dist/animation/coordinator/CoordinatorPulseBounce.d.ts +14 -14
  35. package/dist/animation/coordinator/CoordinatorPulseBounce.js +35 -35
  36. package/dist/animation/coordinator/CoordinatorPulseHighlight.d.ts +13 -13
  37. package/dist/animation/coordinator/CoordinatorPulseHighlight.js +29 -29
  38. package/dist/animation/coordinator/CoordinatorPulseInflate.d.ts +14 -14
  39. package/dist/animation/coordinator/CoordinatorPulseInflate.js +23 -23
  40. package/dist/camera/CameraCreator.d.ts +5 -5
  41. package/dist/camera/CameraCreator.js +4 -4
  42. package/dist/camera/CfgArcRotateCameraPointersInput.d.ts +26 -26
  43. package/dist/camera/CfgArcRotateCameraPointersInput.js +266 -266
  44. package/dist/camera/CfgOrbitalCamera.d.ts +76 -76
  45. package/dist/camera/CfgOrbitalCamera.js +281 -281
  46. package/dist/camera/CfgOrbitalCameraControlProps.d.ts +14 -14
  47. package/dist/camera/CfgOrbitalCameraControlProps.js +7 -7
  48. package/dist/camera/GradingApplier.d.ts +3 -3
  49. package/dist/camera/GradingApplier.js +48 -48
  50. package/dist/engine/EngineCreator.d.ts +3 -3
  51. package/dist/engine/EngineCreator.js +10 -10
  52. package/dist/geometry/CfgGeometry.d.ts +29 -29
  53. package/dist/geometry/CfgGeometry.js +146 -146
  54. package/dist/geometry/CfgMesh.d.ts +10 -10
  55. package/dist/geometry/CfgMesh.js +38 -38
  56. package/dist/geometry/geoSplitter.d.ts +8 -8
  57. package/dist/geometry/geoSplitter.js +192 -192
  58. package/dist/geometry/stretch/CfgMorphTarget.d.ts +15 -15
  59. package/dist/geometry/stretch/CfgMorphTarget.js +65 -65
  60. package/dist/geometry/stretch/CfgStretchData.d.ts +116 -116
  61. package/dist/geometry/stretch/CfgStretchData.js +350 -350
  62. package/dist/geometry/stretch/CfgStretchMorphGeometry.d.ts +16 -16
  63. package/dist/geometry/stretch/CfgStretchMorphGeometry.js +95 -95
  64. package/dist/index.d.ts +16 -16
  65. package/dist/index.js +16 -16
  66. package/dist/io/CfgHistoryToCameraConfConnector.d.ts +31 -31
  67. package/dist/io/CfgHistoryToCameraConfConnector.js +90 -90
  68. package/dist/io/CfgIOCameraConfConnector.d.ts +35 -35
  69. package/dist/io/CfgIOCameraConfConnector.js +81 -81
  70. package/dist/io/CfgObservableStateToCameraConfConnector.d.ts +10 -10
  71. package/dist/io/CfgObservableStateToCameraConfConnector.js +11 -11
  72. package/dist/io/CfgWindowMessageToCameraConfConnector.d.ts +10 -10
  73. package/dist/io/CfgWindowMessageToCameraConfConnector.js +11 -11
  74. package/dist/light/CfgDirectionalLight.d.ts +8 -8
  75. package/dist/light/CfgDirectionalLight.js +18 -18
  76. package/dist/light/CfgHemisphericLight.d.ts +7 -7
  77. package/dist/light/CfgHemisphericLight.js +17 -17
  78. package/dist/light/CfgPointLight.d.ts +8 -8
  79. package/dist/light/CfgPointLight.js +18 -18
  80. package/dist/light/DefaultLightRig.d.ts +19 -19
  81. package/dist/light/DefaultLightRig.js +77 -77
  82. package/dist/light/LightRigCreator.d.ts +9 -9
  83. package/dist/light/LightRigCreator.js +3 -3
  84. package/dist/material/CfgMaterial.d.ts +68 -68
  85. package/dist/material/CfgMaterial.js +482 -482
  86. package/dist/material/DummyMaterialCreator.d.ts +4 -4
  87. package/dist/material/DummyMaterialCreator.js +15 -15
  88. package/dist/material/material.d.ts +18 -18
  89. package/dist/material/material.js +128 -128
  90. package/dist/material/texture.d.ts +14 -14
  91. package/dist/material/texture.js +306 -306
  92. package/dist/nodes/CfgContentRootNode.d.ts +19 -19
  93. package/dist/nodes/CfgContentRootNode.js +75 -75
  94. package/dist/nodes/CfgDeferredMeshNode.d.ts +55 -55
  95. package/dist/nodes/CfgDeferredMeshNode.js +378 -378
  96. package/dist/nodes/CfgProductNode.d.ts +127 -127
  97. package/dist/nodes/CfgProductNode.js +598 -598
  98. package/dist/nodes/CfgSymNode.d.ts +50 -50
  99. package/dist/nodes/CfgSymNode.js +249 -249
  100. package/dist/nodes/CfgSymRootNode.d.ts +45 -45
  101. package/dist/nodes/CfgSymRootNode.js +229 -229
  102. package/dist/nodes/CfgTransformNode.d.ts +33 -33
  103. package/dist/nodes/CfgTransformNode.js +83 -83
  104. package/dist/scene/SceneCreator.d.ts +6 -6
  105. package/dist/scene/SceneCreator.js +22 -22
  106. package/dist/utilities/CfgBoundingBox.d.ts +21 -21
  107. package/dist/utilities/CfgBoundingBox.js +81 -81
  108. package/dist/utilities/anchor/anchor.d.ts +50 -50
  109. package/dist/utilities/anchor/anchor.js +133 -133
  110. package/dist/utilities/anchor/anchorMap.d.ts +20 -20
  111. package/dist/utilities/anchor/anchorMap.js +111 -111
  112. package/dist/utilities/utilities3D.d.ts +70 -70
  113. package/dist/utilities/utilities3D.js +265 -265
  114. package/dist/utilities/utilitiesColor.d.ts +18 -18
  115. package/dist/utilities/utilitiesColor.js +50 -50
  116. package/dist/utilities/utilitiesImage.d.ts +6 -6
  117. package/dist/utilities/utilitiesImage.js +107 -107
  118. package/dist/utilities/utilitiesSymRootIdentifier.d.ts +7 -7
  119. package/dist/utilities/utilitiesSymRootIdentifier.js +26 -26
  120. package/dist/view/BaseView.d.ts +78 -78
  121. package/dist/view/BaseView.js +303 -303
  122. package/dist/view/BaseViewConfiguration.d.ts +32 -32
  123. package/dist/view/BaseViewConfiguration.js +10 -10
  124. package/dist/view/RenderEnv.d.ts +43 -43
  125. package/dist/view/RenderEnv.js +7 -7
  126. package/dist/view/SingleProductDefaultCameraView.d.ts +38 -38
  127. package/dist/view/SingleProductDefaultCameraView.js +149 -149
  128. package/dist/view/SingleProductDefaultCameraViewConfiguration.d.ts +44 -44
  129. package/dist/view/SingleProductDefaultCameraViewConfiguration.js +11 -11
  130. package/dist/view/SingleProductView.d.ts +44 -44
  131. package/dist/view/SingleProductView.js +212 -212
  132. package/dist/view/SingleProductViewConfiguration.d.ts +32 -32
  133. package/dist/view/SingleProductViewConfiguration.js +19 -19
  134. package/package.json +5 -5
@@ -1,265 +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
- 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
+ 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, 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, 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, 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, number, number];
19
19
  //# sourceMappingURL=utilitiesColor.d.ts.map