@configura/babylon-view 2.1.0 → 2.2.0-alpha.1
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.
- package/.eslintrc.json +5 -5
- package/LICENSE +201 -201
- package/README.md +1 -1
- package/dist/animation/AnimatableObject.d.ts +8 -8
- package/dist/animation/AnimatableObject.js +3 -3
- package/dist/animation/animator/Animator.d.ts +33 -33
- package/dist/animation/animator/Animator.js +58 -58
- package/dist/animation/animator/AnimatorEasing.d.ts +16 -16
- package/dist/animation/animator/AnimatorEasing.js +31 -31
- package/dist/animation/animator/AnimatorEasingMatrix.d.ts +14 -14
- package/dist/animation/animator/AnimatorEasingMatrix.js +16 -16
- package/dist/animation/animator/AnimatorHighlight.d.ts +16 -16
- package/dist/animation/animator/AnimatorHighlight.js +32 -32
- package/dist/animation/animator/AnimatorPointToPoint.d.ts +8 -8
- package/dist/animation/animator/AnimatorPointToPoint.js +14 -14
- package/dist/animation/animator/AnimatorQueue.d.ts +13 -13
- package/dist/animation/animator/AnimatorQueue.js +57 -57
- package/dist/animation/animator/AnimatorScale.d.ts +8 -8
- package/dist/animation/animator/AnimatorScale.js +13 -13
- package/dist/animation/animator/AnimatorSpin.d.ts +10 -10
- package/dist/animation/animator/AnimatorSpin.js +13 -13
- package/dist/animation/animator/EasingFunctions.d.ts +35 -35
- package/dist/animation/animator/EasingFunctions.js +137 -137
- package/dist/animation/coordinator/Coordinator.d.ts +28 -28
- package/dist/animation/coordinator/Coordinator.js +53 -53
- package/dist/animation/coordinator/CoordinatorDropAndSpin.d.ts +22 -22
- package/dist/animation/coordinator/CoordinatorDropAndSpin.js +138 -138
- package/dist/animation/coordinator/CoordinatorIdentity.d.ts +11 -11
- package/dist/animation/coordinator/CoordinatorIdentity.js +14 -14
- package/dist/animation/coordinator/CoordinatorNodeQueues.d.ts +18 -18
- package/dist/animation/coordinator/CoordinatorNodeQueues.js +50 -50
- package/dist/animation/coordinator/CoordinatorPulse.d.ts +21 -21
- package/dist/animation/coordinator/CoordinatorPulse.js +47 -47
- package/dist/animation/coordinator/CoordinatorPulseBounce.d.ts +14 -14
- package/dist/animation/coordinator/CoordinatorPulseBounce.js +35 -35
- package/dist/animation/coordinator/CoordinatorPulseHighlight.d.ts +13 -13
- package/dist/animation/coordinator/CoordinatorPulseHighlight.js +29 -29
- package/dist/animation/coordinator/CoordinatorPulseInflate.d.ts +14 -14
- package/dist/animation/coordinator/CoordinatorPulseInflate.js +23 -23
- package/dist/camera/CameraCreator.d.ts +5 -5
- package/dist/camera/CameraCreator.js +4 -4
- package/dist/camera/CfgOrbitalCamera.d.ts +76 -76
- package/dist/camera/CfgOrbitalCamera.js +277 -281
- package/dist/camera/CfgOrbitalCameraControlProps.d.ts +14 -14
- package/dist/camera/CfgOrbitalCameraControlProps.js +7 -7
- package/dist/camera/GradingApplier.d.ts +3 -3
- package/dist/camera/GradingApplier.js +48 -48
- package/dist/engine/EngineCreator.d.ts +3 -3
- package/dist/engine/EngineCreator.js +10 -10
- package/dist/geometry/CfgGeometry.d.ts +29 -29
- package/dist/geometry/CfgGeometry.js +146 -146
- package/dist/geometry/CfgMesh.d.ts +10 -10
- package/dist/geometry/CfgMesh.js +38 -38
- package/dist/geometry/geoSplitter.d.ts +8 -8
- package/dist/geometry/geoSplitter.js +192 -192
- package/dist/geometry/stretch/CfgMorphTarget.d.ts +15 -15
- package/dist/geometry/stretch/CfgMorphTarget.js +65 -65
- package/dist/geometry/stretch/CfgStretchData.d.ts +116 -116
- package/dist/geometry/stretch/CfgStretchData.js +347 -347
- package/dist/geometry/stretch/CfgStretchMorphGeometry.d.ts +16 -16
- package/dist/geometry/stretch/CfgStretchMorphGeometry.js +95 -95
- package/dist/index.d.ts +16 -16
- package/dist/index.js +16 -16
- package/dist/io/CfgHistoryToCameraConfConnector.d.ts +31 -31
- package/dist/io/CfgHistoryToCameraConfConnector.js +90 -90
- package/dist/io/CfgIOCameraConfConnector.d.ts +35 -35
- package/dist/io/CfgIOCameraConfConnector.js +81 -81
- package/dist/io/CfgObservableStateToCameraConfConnector.d.ts +10 -10
- package/dist/io/CfgObservableStateToCameraConfConnector.js +11 -11
- package/dist/io/CfgWindowMessageToCameraConfConnector.d.ts +10 -10
- package/dist/io/CfgWindowMessageToCameraConfConnector.js +11 -11
- package/dist/light/CfgDirectionalLight.d.ts +8 -8
- package/dist/light/CfgDirectionalLight.js +18 -18
- package/dist/light/CfgHemisphericLight.d.ts +7 -7
- package/dist/light/CfgHemisphericLight.js +17 -17
- package/dist/light/CfgPointLight.d.ts +8 -8
- package/dist/light/CfgPointLight.js +18 -18
- package/dist/light/DefaultLightRig.d.ts +19 -19
- package/dist/light/DefaultLightRig.js +77 -77
- package/dist/light/LightRigCreator.d.ts +9 -9
- package/dist/light/LightRigCreator.js +3 -3
- package/dist/material/CfgMaterial.d.ts +68 -68
- package/dist/material/CfgMaterial.js +482 -482
- package/dist/material/DummyMaterialCreator.d.ts +4 -4
- package/dist/material/DummyMaterialCreator.js +15 -15
- package/dist/material/material.d.ts +18 -18
- package/dist/material/material.js +128 -128
- package/dist/material/texture.d.ts +14 -14
- package/dist/material/texture.js +306 -306
- package/dist/nodes/CfgContentRootNode.d.ts +19 -19
- package/dist/nodes/CfgContentRootNode.js +75 -75
- package/dist/nodes/CfgDeferredMeshNode.d.ts +55 -55
- package/dist/nodes/CfgDeferredMeshNode.js +378 -378
- package/dist/nodes/CfgProductNode.d.ts +127 -127
- package/dist/nodes/CfgProductNode.js +598 -598
- package/dist/nodes/CfgSymNode.d.ts +50 -50
- package/dist/nodes/CfgSymNode.js +249 -249
- package/dist/nodes/CfgSymRootNode.d.ts +45 -45
- package/dist/nodes/CfgSymRootNode.js +240 -239
- package/dist/nodes/CfgTransformNode.d.ts +33 -33
- package/dist/nodes/CfgTransformNode.js +83 -83
- package/dist/scene/SceneCreator.d.ts +6 -6
- package/dist/scene/SceneCreator.js +22 -22
- package/dist/utilities/CfgBoundingBox.d.ts +21 -21
- package/dist/utilities/CfgBoundingBox.js +81 -81
- package/dist/utilities/anchor/anchor.d.ts +50 -50
- package/dist/utilities/anchor/anchor.js +133 -133
- package/dist/utilities/anchor/anchorMap.d.ts +20 -20
- package/dist/utilities/anchor/anchorMap.js +111 -111
- package/dist/utilities/utilities3D.d.ts +70 -70
- package/dist/utilities/utilities3D.js +259 -265
- package/dist/utilities/utilitiesColor.d.ts +18 -18
- package/dist/utilities/utilitiesColor.js +50 -50
- package/dist/utilities/utilitiesImage.d.ts +6 -6
- package/dist/utilities/utilitiesImage.js +107 -107
- package/dist/utilities/utilitiesSymRootIdentifier.d.ts +7 -7
- package/dist/utilities/utilitiesSymRootIdentifier.js +26 -26
- package/dist/view/BaseView.d.ts +78 -78
- package/dist/view/BaseView.js +303 -303
- package/dist/view/BaseViewConfiguration.d.ts +32 -32
- package/dist/view/BaseViewConfiguration.js +10 -10
- package/dist/view/RenderEnv.d.ts +43 -43
- package/dist/view/RenderEnv.js +7 -7
- package/dist/view/SingleProductDefaultCameraView.d.ts +38 -38
- package/dist/view/SingleProductDefaultCameraView.js +149 -149
- package/dist/view/SingleProductDefaultCameraViewConfiguration.d.ts +44 -44
- package/dist/view/SingleProductDefaultCameraViewConfiguration.js +11 -11
- package/dist/view/SingleProductView.d.ts +44 -44
- package/dist/view/SingleProductView.js +212 -212
- package/dist/view/SingleProductViewConfiguration.d.ts +32 -32
- package/dist/view/SingleProductViewConfiguration.js +19 -19
- package/package.json +16 -7
- package/dist/camera/CfgArcRotateCameraPointersInput.d.ts +0 -27
- package/dist/camera/CfgArcRotateCameraPointersInput.js +0 -266
|
@@ -1,265 +1,259 @@
|
|
|
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
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
}
|
|
73
|
-
export function
|
|
74
|
-
const pos =
|
|
75
|
-
const
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
return
|
|
95
|
-
}
|
|
96
|
-
export function
|
|
97
|
-
if (
|
|
98
|
-
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
const
|
|
128
|
-
const
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
const
|
|
141
|
-
const
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
const
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
0, 0, 1,
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
*
|
|
201
|
-
*
|
|
202
|
-
*
|
|
203
|
-
*
|
|
204
|
-
*
|
|
205
|
-
*
|
|
206
|
-
*
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
let
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
refined
|
|
259
|
-
|
|
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
|
+
return {
|
|
61
|
+
x: boundingRect.left,
|
|
62
|
+
y: boundingRect.top,
|
|
63
|
+
width: boundingRect.width,
|
|
64
|
+
height: boundingRect.height,
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
export function symTransformToMatrix(symTransform) {
|
|
68
|
+
const pos = symTransform.pos;
|
|
69
|
+
const mapping = symTransform.mapping || Matrix33.identity;
|
|
70
|
+
const { c0, c1, c2 } = mapping;
|
|
71
|
+
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);
|
|
72
|
+
}
|
|
73
|
+
export function modelTransformsEqual(left, right) {
|
|
74
|
+
const { scale: leftScale, pos: leftPos, rot: leftRot } = left;
|
|
75
|
+
const { scale: rightScale, pos: rightPos, rot: rightRot } = right;
|
|
76
|
+
return (leftScale.x === rightScale.x &&
|
|
77
|
+
leftScale.y === rightScale.y &&
|
|
78
|
+
leftScale.z === rightScale.z &&
|
|
79
|
+
leftPos.x === rightPos.x &&
|
|
80
|
+
leftPos.y === rightPos.y &&
|
|
81
|
+
leftPos.z === rightPos.z &&
|
|
82
|
+
leftRot.pitch === rightRot.pitch &&
|
|
83
|
+
leftRot.roll === rightRot.roll &&
|
|
84
|
+
leftRot.yaw === rightRot.yaw);
|
|
85
|
+
}
|
|
86
|
+
export function modelTransformToSymTransform(modelTransform) {
|
|
87
|
+
const { pos, scale, rot } = modelTransform;
|
|
88
|
+
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));
|
|
89
|
+
}
|
|
90
|
+
export function cloneName(name) {
|
|
91
|
+
if (!name.endsWith(" ")) {
|
|
92
|
+
name += " ";
|
|
93
|
+
}
|
|
94
|
+
return name + "(clone)";
|
|
95
|
+
}
|
|
96
|
+
export function measureLongestDistanceToCorner(bb, measureComponents) {
|
|
97
|
+
if (bb.isEmpty) {
|
|
98
|
+
throw Error("Empty bounding box");
|
|
99
|
+
}
|
|
100
|
+
const minimum = bb.minimum.asArray();
|
|
101
|
+
const maximum = bb.maximum.asArray();
|
|
102
|
+
let longestSquaredDistanceFromCenter = 0;
|
|
103
|
+
const cornerCount = Math.pow(2, measureComponents.length);
|
|
104
|
+
for (let i = 0; i < cornerCount; i++) {
|
|
105
|
+
const vectorComponents = measureComponents.map((componentIndex, n) => (i & (1 << n) ? minimum : maximum)[componentIndex]);
|
|
106
|
+
const squaredDistance = vectorComponents.reduce((pV, cV) => pV + Math.pow(cV, 2), 0);
|
|
107
|
+
longestSquaredDistanceFromCenter = Math.max(longestSquaredDistanceFromCenter, squaredDistance);
|
|
108
|
+
}
|
|
109
|
+
return Math.sqrt(longestSquaredDistanceFromCenter);
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Creates an ATriMeshF instance containing a mesh of a sphere of the given radius (default 1)
|
|
113
|
+
* centered on the given position (default <0,0,0>). The "resolution" of the mesh is set by the
|
|
114
|
+
* segments value (default 32).
|
|
115
|
+
*
|
|
116
|
+
* UV coordinates are generated by wrapping the texture around the sphere like a world map.
|
|
117
|
+
*/
|
|
118
|
+
export function aTriMeshSphere(radius, center, segments) {
|
|
119
|
+
// Simplified and slightly modified (mostly z-up etc) version of SphereBuilder from Babylon.js
|
|
120
|
+
// https://github.com/BabylonJS/Babylon.js/blob/master/src/Meshes/Builders/sphereBuilder.ts
|
|
121
|
+
const totalYRotationSteps = 2 + (segments !== null && segments !== void 0 ? segments : 32);
|
|
122
|
+
const totalZRotationSteps = 2 * totalYRotationSteps;
|
|
123
|
+
radius = radius !== null && radius !== void 0 ? radius : 1;
|
|
124
|
+
center = center !== null && center !== void 0 ? center : new Point(0, 0, 0);
|
|
125
|
+
const offset = new Vector3(center.x, center.y, center.z);
|
|
126
|
+
const indices = [];
|
|
127
|
+
const positions = [];
|
|
128
|
+
const normals = [];
|
|
129
|
+
const uvs = [];
|
|
130
|
+
for (let yRotationStep = 0; yRotationStep <= totalYRotationSteps; yRotationStep++) {
|
|
131
|
+
const normalizedY = yRotationStep / totalYRotationSteps;
|
|
132
|
+
const angleY = normalizedY * Math.PI;
|
|
133
|
+
for (let zRotationStep = 0; zRotationStep <= totalZRotationSteps; zRotationStep++) {
|
|
134
|
+
const normalizedZ = zRotationStep / totalZRotationSteps;
|
|
135
|
+
const angleZ = normalizedZ * Math.PI * 2;
|
|
136
|
+
const rotationY = Matrix.RotationY(-angleY);
|
|
137
|
+
const rotationZ = Matrix.RotationZ(angleZ);
|
|
138
|
+
const afterRotY = Vector3.TransformCoordinates(new Vector3(0, 0, 1), rotationY);
|
|
139
|
+
const complete = Vector3.TransformCoordinates(afterRotY, rotationZ);
|
|
140
|
+
const vertex = complete.scale(radius).add(offset);
|
|
141
|
+
const normal = complete.normalize();
|
|
142
|
+
positions.push(vertex.x, vertex.y, vertex.z);
|
|
143
|
+
normals.push(normal.x, normal.y, normal.z);
|
|
144
|
+
uvs.push(normalizedZ, normalizedY);
|
|
145
|
+
}
|
|
146
|
+
if (yRotationStep > 0) {
|
|
147
|
+
const verticesCount = positions.length / 3;
|
|
148
|
+
for (let firstIndex = verticesCount - 2 * (totalZRotationSteps + 1); firstIndex + totalZRotationSteps + 2 < verticesCount; firstIndex++) {
|
|
149
|
+
indices.push(firstIndex);
|
|
150
|
+
indices.push(firstIndex + totalZRotationSteps + 1);
|
|
151
|
+
indices.push(firstIndex + 1);
|
|
152
|
+
indices.push(firstIndex + totalZRotationSteps + 1);
|
|
153
|
+
indices.push(firstIndex + totalZRotationSteps + 2);
|
|
154
|
+
indices.push(firstIndex + 1);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
// It would probably be faster if we could avoid this step and use the typed arrays directly.
|
|
159
|
+
// On the other hand, during testing the calls below took 0ms for 52k indices...
|
|
160
|
+
return ATriMeshF.createWithArrays(Uint32Array.from(indices), Float32Array.from(positions), Float32Array.from(normals), Float32Array.from(uvs));
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Creates an ATriMeshF instance containing a mesh of a box between the two points.
|
|
164
|
+
* Default value of p0 is <0,0,0> and p1 is <1,1,1>.
|
|
165
|
+
*
|
|
166
|
+
* UV coordinates are generated, repeating the texture on each side.
|
|
167
|
+
*/
|
|
168
|
+
export function aTriMeshBox(p0, p1) {
|
|
169
|
+
p0 = p0 !== null && p0 !== void 0 ? p0 : new Point(0, 0, 0);
|
|
170
|
+
p1 = p1 !== null && p1 !== void 0 ? p1 : new Point(1, 1, 1);
|
|
171
|
+
const scales = [p1.x - p0.x, p1.y - p0.y, p1.z - p0.z];
|
|
172
|
+
const offsets = [p0.x, p0.y, p0.z];
|
|
173
|
+
const positions = BOX_VERTICES.map((value, index) => {
|
|
174
|
+
const component = index % 3;
|
|
175
|
+
return value * scales[component] + offsets[component];
|
|
176
|
+
});
|
|
177
|
+
return ATriMeshF.createWithArrays(BOX_INDICES, positions, BOX_NORMALS, BOX_UVS);
|
|
178
|
+
}
|
|
179
|
+
// prettier-ignore
|
|
180
|
+
const BOX_INDICES = new Uint32Array([0, 2, 1, 0, 3, 2, 4, 6, 5, 4, 7, 6, 8, 10, 9, 8, 11, 10, 12,
|
|
181
|
+
14, 13, 12, 15, 14, 16, 18, 17, 16, 19, 18, 20, 22, 21, 20, 23, 22]);
|
|
182
|
+
// prettier-ignore
|
|
183
|
+
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,
|
|
184
|
+
-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,
|
|
185
|
+
0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0]);
|
|
186
|
+
// prettier-ignore
|
|
187
|
+
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,
|
|
188
|
+
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,]);
|
|
189
|
+
// prettier-ignore
|
|
190
|
+
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,
|
|
191
|
+
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,
|
|
192
|
+
1, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1]);
|
|
193
|
+
/**
|
|
194
|
+
* Creates an ATriMeshF instance containing a mesh representing an infinite plane with the given
|
|
195
|
+
* normal, offset by the given distance along the normal.
|
|
196
|
+
*
|
|
197
|
+
* Due to automatic bounding box calculations, the infinite plane is represented by a circular disc
|
|
198
|
+
* with the given radius centered on a point offset from the origin along the normal vector.
|
|
199
|
+
*
|
|
200
|
+
* The number of triangles in the disc is controlled by the refine parameter. The minimum number of
|
|
201
|
+
* triangles is 4, each refine step doubles the triangle count.
|
|
202
|
+
*
|
|
203
|
+
* Default normal: 1, 0, 0
|
|
204
|
+
* Default offset: 0
|
|
205
|
+
* Default radius: 1
|
|
206
|
+
* Default refinement: 4 (64 triangles)
|
|
207
|
+
*/
|
|
208
|
+
export function aTriMeshPlane(normal, offset, radius, refine) {
|
|
209
|
+
normal = normal !== null && normal !== void 0 ? normal : new Point(0, 0, 1);
|
|
210
|
+
offset = offset !== null && offset !== void 0 ? offset : 0;
|
|
211
|
+
radius = radius !== null && radius !== void 0 ? radius : 1;
|
|
212
|
+
refine = refine !== null && refine !== void 0 ? refine : 4;
|
|
213
|
+
const normalVec = new Vector3(normal.x, normal.y, normal.z).normalize();
|
|
214
|
+
let base1 = normalVec.cross(new Vector3(1, 0, 0));
|
|
215
|
+
if (base1.length() < 0.2) {
|
|
216
|
+
// Normal was pretty close to 1, 0, 0, try another base vector
|
|
217
|
+
base1 = normalVec.cross(new Vector3(0, 1, 0));
|
|
218
|
+
}
|
|
219
|
+
base1 = base1.normalize();
|
|
220
|
+
const base2 = base1.cross(normalVec);
|
|
221
|
+
let points = new Array(5);
|
|
222
|
+
points[0] = Vector3.Zero();
|
|
223
|
+
points[1] = base1;
|
|
224
|
+
points[2] = base2;
|
|
225
|
+
points[3] = base1.negate();
|
|
226
|
+
points[4] = base2.negate();
|
|
227
|
+
for (let i = 0; i < refine; i++) {
|
|
228
|
+
points = refineCircle(points);
|
|
229
|
+
}
|
|
230
|
+
const numTriangles = points.length - 1;
|
|
231
|
+
const indices = new Uint32Array(numTriangles * 3);
|
|
232
|
+
for (let i = 0; i < numTriangles; i++) {
|
|
233
|
+
const index = i * 3;
|
|
234
|
+
indices[index] = 0;
|
|
235
|
+
indices[index + 1] = i + 1;
|
|
236
|
+
indices[index + 2] = i >= numTriangles - 1 ? 1 : i + 2;
|
|
237
|
+
}
|
|
238
|
+
const vertices = new Float32Array(points.length * 3);
|
|
239
|
+
for (let i = 0; i < points.length; i++) {
|
|
240
|
+
const point = points[i];
|
|
241
|
+
const index = i * 3;
|
|
242
|
+
vertices[index] = point.x * radius + normal.x * offset;
|
|
243
|
+
vertices[index + 1] = point.y * radius + normal.y * offset;
|
|
244
|
+
vertices[index + 2] = point.z * radius + normal.z * offset;
|
|
245
|
+
}
|
|
246
|
+
const mesh = ATriMeshF.createWithArrays(indices, vertices);
|
|
247
|
+
mesh.doubleSided = true;
|
|
248
|
+
return mesh;
|
|
249
|
+
}
|
|
250
|
+
function refineCircle(points) {
|
|
251
|
+
const refined = new Array(points.length * 2 - 1);
|
|
252
|
+
refined[0] = points[0];
|
|
253
|
+
for (let i = 1; i < points.length; i++) {
|
|
254
|
+
const next = (i >= points.length - 1 ? 0 : i) + 1;
|
|
255
|
+
refined[i * 2 - 1] = points[i];
|
|
256
|
+
refined[i * 2] = points[i].add(points[next]).normalize();
|
|
257
|
+
}
|
|
258
|
+
return refined;
|
|
259
|
+
}
|
|
@@ -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
|