@configura/babylon-view 2.1.0-alpha.0 → 2.1.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/CfgArcRotateCameraPointersInput.d.ts +26 -26
- package/dist/camera/CfgArcRotateCameraPointersInput.js +266 -266
- package/dist/camera/CfgOrbitalCamera.d.ts +76 -76
- package/dist/camera/CfgOrbitalCamera.js +281 -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 +350 -350
- 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 +229 -229
- 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 +265 -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 +5 -5
|
@@ -1,133 +1,133 @@
|
|
|
1
|
-
import { Matrix, Vector3 } from "@babylonjs/core";
|
|
2
|
-
import { toStretchedPoint } from "../../geometry/stretch/CfgStretchData.js";
|
|
3
|
-
import { identifierIsUri } from "../utilitiesSymRootIdentifier.js";
|
|
4
|
-
/*
|
|
5
|
-
* MeasurePriorityNodeReferences only uses the url of a Model as identifier. Therefore it
|
|
6
|
-
* can not differentiate between the same Model/CfgSymRootNode used multiple time in the same
|
|
7
|
-
* Product. Future development in Catalogues might make this change.
|
|
8
|
-
*/
|
|
9
|
-
export function nodeEqualsMeasurePriorityNodeReference(node, ref) {
|
|
10
|
-
const nodeIdentifier = node._identifier;
|
|
11
|
-
// The identifier is made from URL when the node was made from an URL
|
|
12
|
-
if (!identifierIsUri(nodeIdentifier)) {
|
|
13
|
-
return false;
|
|
14
|
-
}
|
|
15
|
-
// The last segment of the URL is the Windows-style formatted relative file path to the model
|
|
16
|
-
const pathFromIdentifier = decodeURIComponent(nodeIdentifier.substr(nodeIdentifier.lastIndexOf("/") + 1));
|
|
17
|
-
return pathFromIdentifier === ref.modelLocalFilePath;
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* The measureParamCode points to Measures inside Models. A Model can be used multiple times in a Product.
|
|
21
|
-
* More than one Model can use the same measureParamCode. Therefore what Measure an AnchorRef points to
|
|
22
|
-
* can be ambiguous. To help resolve the ambiguities, an anchorRef can have measurePriorities that
|
|
23
|
-
* governs which target it prefers to be anchored to.
|
|
24
|
-
*
|
|
25
|
-
* This method sorts the targets so that the highest priority (lowest index) one is first.
|
|
26
|
-
* Sorting is done in place on the original array.
|
|
27
|
-
*/
|
|
28
|
-
export const getAnchorTargetPriorityComparer = (measureDefinitions) => (measureParamCode, l, r) => {
|
|
29
|
-
const measureDefinition = measureDefinitions.find((m) => m.measureParamCode === measureParamCode);
|
|
30
|
-
if (measureDefinition === undefined) {
|
|
31
|
-
return 0;
|
|
32
|
-
}
|
|
33
|
-
const measurePriorities = measureDefinition.measurePriorities;
|
|
34
|
-
const lP = measurePriorities.find((m) => nodeEqualsMeasurePriorityNodeReference(l, m));
|
|
35
|
-
const rP = measurePriorities.find((m) => nodeEqualsMeasurePriorityNodeReference(r, m));
|
|
36
|
-
const lIndex = lP === undefined ? Number.POSITIVE_INFINITY : lP.index;
|
|
37
|
-
const rIndex = rP === undefined ? Number.POSITIVE_INFINITY : rP.index;
|
|
38
|
-
const prioDiff = lIndex - rIndex;
|
|
39
|
-
if (prioDiff !== 0) {
|
|
40
|
-
return prioDiff;
|
|
41
|
-
}
|
|
42
|
-
return l._identifier.localeCompare(r._identifier);
|
|
43
|
-
};
|
|
44
|
-
/**
|
|
45
|
-
* It might be possible in the future to anchor to other things than Measures (which are primarily)
|
|
46
|
-
* used for stretch, but for now we can only support anchoring to the ends of a Measure.
|
|
47
|
-
* toSp means anchor to start point, else end point.
|
|
48
|
-
* The DtoMeasureParam class is used in several different contexts. To make the intent inside Stage
|
|
49
|
-
* clear CfgAnchorRef exists, which including only what is relevant for when used for anchoring.
|
|
50
|
-
*/
|
|
51
|
-
export class CfgAnchorRef {
|
|
52
|
-
/**
|
|
53
|
-
* The name stretchSymNodeId might seem confusing. And it is. Turns out CET is implemented so
|
|
54
|
-
* that it bases its anchoring on symNode Id containing the stretch. Not the measureParamId.
|
|
55
|
-
*/
|
|
56
|
-
constructor(stretchSymNodeId, toSp) {
|
|
57
|
-
this.stretchSymNodeId = stretchSymNodeId;
|
|
58
|
-
this.toSp = toSp;
|
|
59
|
-
}
|
|
60
|
-
static make(m) {
|
|
61
|
-
if (m === undefined) {
|
|
62
|
-
return undefined;
|
|
63
|
-
}
|
|
64
|
-
const { anchorPoint, code } = m;
|
|
65
|
-
if (anchorPoint === undefined) {
|
|
66
|
-
console.error("No anchorPoint for measureParam intended to be used as anchorRef");
|
|
67
|
-
return undefined;
|
|
68
|
-
}
|
|
69
|
-
const isSp = anchorPoint === "sp";
|
|
70
|
-
const isEp = anchorPoint === "ep";
|
|
71
|
-
if (!isSp && !isEp) {
|
|
72
|
-
console.error("AnchorPoint is neither sp nor ep");
|
|
73
|
-
return undefined;
|
|
74
|
-
}
|
|
75
|
-
return new CfgAnchorRef(code, isSp);
|
|
76
|
-
}
|
|
77
|
-
equal(other) {
|
|
78
|
-
return this.stretchSymNodeId === other.stretchSymNodeId && this.toSp === other.toSp;
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
/** Gets the coordinates of the anchor point relative the anchor target. */
|
|
82
|
-
export function getRawAnchorPoint(anchorTarget, anchorRef) {
|
|
83
|
-
if (anchorTarget === undefined) {
|
|
84
|
-
return undefined;
|
|
85
|
-
}
|
|
86
|
-
if (anchorRef === undefined) {
|
|
87
|
-
throw new Error("AnchorTo not set even though we got an anchorTarget");
|
|
88
|
-
}
|
|
89
|
-
const { stretchSymNodeId, toSp } = anchorRef;
|
|
90
|
-
const { stretchDatas } = anchorTarget;
|
|
91
|
-
const targetStretchData = stretchDatas.find((stretchData) => stretchSymNodeId === stretchData.stretchSymNodeId);
|
|
92
|
-
if (targetStretchData === undefined) {
|
|
93
|
-
throw new Error("No target stretch data for measureParamCode found");
|
|
94
|
-
}
|
|
95
|
-
return toSp ? targetStretchData.sp : targetStretchData.ep;
|
|
96
|
-
}
|
|
97
|
-
/**
|
|
98
|
-
* Calculate a matrix which is the translation that makes a point move as if it was a child of
|
|
99
|
-
* anchorTarget and then moved to the end of the anchorPoint.
|
|
100
|
-
*
|
|
101
|
-
* It is assumed that all anchoring happens on symRoot/additionalProduct-level and therefore all anchorees are
|
|
102
|
-
* siblings to the anchorers.
|
|
103
|
-
*
|
|
104
|
-
* Application of anchoring happens from anchor tree root and out, so that originalMatrix of
|
|
105
|
-
* anchorTarget will already have any anchoring and stretch applied.
|
|
106
|
-
*/
|
|
107
|
-
export function getStretchedAnchorPointMatrix(anchorRef, anchorTarget) {
|
|
108
|
-
const rawAnchorPoint = getRawAnchorPoint(anchorTarget, anchorRef);
|
|
109
|
-
if (rawAnchorPoint === undefined || anchorTarget === undefined) {
|
|
110
|
-
return undefined;
|
|
111
|
-
}
|
|
112
|
-
// Apply current stretch to the anchor point
|
|
113
|
-
const stretchedAnchorPoint = toStretchedPoint(rawAnchorPoint, anchorTarget.stretchDatas, anchorTarget.cfgProductNode.product.configuration._internal
|
|
114
|
-
.stretchReferenceLengthsByMeasureParamCode);
|
|
115
|
-
// Sometimes, apply the anchorTarget matrix, as if the point was a child to the anchorTarget.
|
|
116
|
-
const anchorTargetMatrixApplied = Vector3.TransformCoordinates(stretchedAnchorPoint, anchorTarget.originalMatrix);
|
|
117
|
-
// We use translation as when we anchor things we do not change their orientation,
|
|
118
|
-
// we only move them to snap to this point
|
|
119
|
-
return Matrix.Identity().setTranslation(anchorTargetMatrixApplied);
|
|
120
|
-
}
|
|
121
|
-
export function updatedStretchedAnchorPointMatrix(anchorRef, anchorTarget, currentStretchedAnchorPointMatrix) {
|
|
122
|
-
const stretchedAnchorPointMatrix = getStretchedAnchorPointMatrix(anchorRef, anchorTarget);
|
|
123
|
-
if (currentStretchedAnchorPointMatrix === undefined &&
|
|
124
|
-
stretchedAnchorPointMatrix === undefined) {
|
|
125
|
-
return undefined;
|
|
126
|
-
}
|
|
127
|
-
if (currentStretchedAnchorPointMatrix !== undefined &&
|
|
128
|
-
stretchedAnchorPointMatrix !== undefined &&
|
|
129
|
-
stretchedAnchorPointMatrix.equals(currentStretchedAnchorPointMatrix)) {
|
|
130
|
-
return undefined;
|
|
131
|
-
}
|
|
132
|
-
return stretchedAnchorPointMatrix;
|
|
133
|
-
}
|
|
1
|
+
import { Matrix, Vector3 } from "@babylonjs/core";
|
|
2
|
+
import { toStretchedPoint } from "../../geometry/stretch/CfgStretchData.js";
|
|
3
|
+
import { identifierIsUri } from "../utilitiesSymRootIdentifier.js";
|
|
4
|
+
/*
|
|
5
|
+
* MeasurePriorityNodeReferences only uses the url of a Model as identifier. Therefore it
|
|
6
|
+
* can not differentiate between the same Model/CfgSymRootNode used multiple time in the same
|
|
7
|
+
* Product. Future development in Catalogues might make this change.
|
|
8
|
+
*/
|
|
9
|
+
export function nodeEqualsMeasurePriorityNodeReference(node, ref) {
|
|
10
|
+
const nodeIdentifier = node._identifier;
|
|
11
|
+
// The identifier is made from URL when the node was made from an URL
|
|
12
|
+
if (!identifierIsUri(nodeIdentifier)) {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
// The last segment of the URL is the Windows-style formatted relative file path to the model
|
|
16
|
+
const pathFromIdentifier = decodeURIComponent(nodeIdentifier.substr(nodeIdentifier.lastIndexOf("/") + 1));
|
|
17
|
+
return pathFromIdentifier === ref.modelLocalFilePath;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* The measureParamCode points to Measures inside Models. A Model can be used multiple times in a Product.
|
|
21
|
+
* More than one Model can use the same measureParamCode. Therefore what Measure an AnchorRef points to
|
|
22
|
+
* can be ambiguous. To help resolve the ambiguities, an anchorRef can have measurePriorities that
|
|
23
|
+
* governs which target it prefers to be anchored to.
|
|
24
|
+
*
|
|
25
|
+
* This method sorts the targets so that the highest priority (lowest index) one is first.
|
|
26
|
+
* Sorting is done in place on the original array.
|
|
27
|
+
*/
|
|
28
|
+
export const getAnchorTargetPriorityComparer = (measureDefinitions) => (measureParamCode, l, r) => {
|
|
29
|
+
const measureDefinition = measureDefinitions.find((m) => m.measureParamCode === measureParamCode);
|
|
30
|
+
if (measureDefinition === undefined) {
|
|
31
|
+
return 0;
|
|
32
|
+
}
|
|
33
|
+
const measurePriorities = measureDefinition.measurePriorities;
|
|
34
|
+
const lP = measurePriorities.find((m) => nodeEqualsMeasurePriorityNodeReference(l, m));
|
|
35
|
+
const rP = measurePriorities.find((m) => nodeEqualsMeasurePriorityNodeReference(r, m));
|
|
36
|
+
const lIndex = lP === undefined ? Number.POSITIVE_INFINITY : lP.index;
|
|
37
|
+
const rIndex = rP === undefined ? Number.POSITIVE_INFINITY : rP.index;
|
|
38
|
+
const prioDiff = lIndex - rIndex;
|
|
39
|
+
if (prioDiff !== 0) {
|
|
40
|
+
return prioDiff;
|
|
41
|
+
}
|
|
42
|
+
return l._identifier.localeCompare(r._identifier);
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* It might be possible in the future to anchor to other things than Measures (which are primarily)
|
|
46
|
+
* used for stretch, but for now we can only support anchoring to the ends of a Measure.
|
|
47
|
+
* toSp means anchor to start point, else end point.
|
|
48
|
+
* The DtoMeasureParam class is used in several different contexts. To make the intent inside Stage
|
|
49
|
+
* clear CfgAnchorRef exists, which including only what is relevant for when used for anchoring.
|
|
50
|
+
*/
|
|
51
|
+
export class CfgAnchorRef {
|
|
52
|
+
/**
|
|
53
|
+
* The name stretchSymNodeId might seem confusing. And it is. Turns out CET is implemented so
|
|
54
|
+
* that it bases its anchoring on symNode Id containing the stretch. Not the measureParamId.
|
|
55
|
+
*/
|
|
56
|
+
constructor(stretchSymNodeId, toSp) {
|
|
57
|
+
this.stretchSymNodeId = stretchSymNodeId;
|
|
58
|
+
this.toSp = toSp;
|
|
59
|
+
}
|
|
60
|
+
static make(m) {
|
|
61
|
+
if (m === undefined) {
|
|
62
|
+
return undefined;
|
|
63
|
+
}
|
|
64
|
+
const { anchorPoint, code } = m;
|
|
65
|
+
if (anchorPoint === undefined) {
|
|
66
|
+
console.error("No anchorPoint for measureParam intended to be used as anchorRef");
|
|
67
|
+
return undefined;
|
|
68
|
+
}
|
|
69
|
+
const isSp = anchorPoint === "sp";
|
|
70
|
+
const isEp = anchorPoint === "ep";
|
|
71
|
+
if (!isSp && !isEp) {
|
|
72
|
+
console.error("AnchorPoint is neither sp nor ep");
|
|
73
|
+
return undefined;
|
|
74
|
+
}
|
|
75
|
+
return new CfgAnchorRef(code, isSp);
|
|
76
|
+
}
|
|
77
|
+
equal(other) {
|
|
78
|
+
return this.stretchSymNodeId === other.stretchSymNodeId && this.toSp === other.toSp;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
/** Gets the coordinates of the anchor point relative the anchor target. */
|
|
82
|
+
export function getRawAnchorPoint(anchorTarget, anchorRef) {
|
|
83
|
+
if (anchorTarget === undefined) {
|
|
84
|
+
return undefined;
|
|
85
|
+
}
|
|
86
|
+
if (anchorRef === undefined) {
|
|
87
|
+
throw new Error("AnchorTo not set even though we got an anchorTarget");
|
|
88
|
+
}
|
|
89
|
+
const { stretchSymNodeId, toSp } = anchorRef;
|
|
90
|
+
const { stretchDatas } = anchorTarget;
|
|
91
|
+
const targetStretchData = stretchDatas.find((stretchData) => stretchSymNodeId === stretchData.stretchSymNodeId);
|
|
92
|
+
if (targetStretchData === undefined) {
|
|
93
|
+
throw new Error("No target stretch data for measureParamCode found");
|
|
94
|
+
}
|
|
95
|
+
return toSp ? targetStretchData.sp : targetStretchData.ep;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Calculate a matrix which is the translation that makes a point move as if it was a child of
|
|
99
|
+
* anchorTarget and then moved to the end of the anchorPoint.
|
|
100
|
+
*
|
|
101
|
+
* It is assumed that all anchoring happens on symRoot/additionalProduct-level and therefore all anchorees are
|
|
102
|
+
* siblings to the anchorers.
|
|
103
|
+
*
|
|
104
|
+
* Application of anchoring happens from anchor tree root and out, so that originalMatrix of
|
|
105
|
+
* anchorTarget will already have any anchoring and stretch applied.
|
|
106
|
+
*/
|
|
107
|
+
export function getStretchedAnchorPointMatrix(anchorRef, anchorTarget) {
|
|
108
|
+
const rawAnchorPoint = getRawAnchorPoint(anchorTarget, anchorRef);
|
|
109
|
+
if (rawAnchorPoint === undefined || anchorTarget === undefined) {
|
|
110
|
+
return undefined;
|
|
111
|
+
}
|
|
112
|
+
// Apply current stretch to the anchor point
|
|
113
|
+
const stretchedAnchorPoint = toStretchedPoint(rawAnchorPoint, anchorTarget.stretchDatas, anchorTarget.cfgProductNode.product.configuration._internal
|
|
114
|
+
.stretchReferenceLengthsByMeasureParamCode);
|
|
115
|
+
// Sometimes, apply the anchorTarget matrix, as if the point was a child to the anchorTarget.
|
|
116
|
+
const anchorTargetMatrixApplied = Vector3.TransformCoordinates(stretchedAnchorPoint, anchorTarget.originalMatrix);
|
|
117
|
+
// We use translation as when we anchor things we do not change their orientation,
|
|
118
|
+
// we only move them to snap to this point
|
|
119
|
+
return Matrix.Identity().setTranslation(anchorTargetMatrixApplied);
|
|
120
|
+
}
|
|
121
|
+
export function updatedStretchedAnchorPointMatrix(anchorRef, anchorTarget, currentStretchedAnchorPointMatrix) {
|
|
122
|
+
const stretchedAnchorPointMatrix = getStretchedAnchorPointMatrix(anchorRef, anchorTarget);
|
|
123
|
+
if (currentStretchedAnchorPointMatrix === undefined &&
|
|
124
|
+
stretchedAnchorPointMatrix === undefined) {
|
|
125
|
+
return undefined;
|
|
126
|
+
}
|
|
127
|
+
if (currentStretchedAnchorPointMatrix !== undefined &&
|
|
128
|
+
stretchedAnchorPointMatrix !== undefined &&
|
|
129
|
+
stretchedAnchorPointMatrix.equals(currentStretchedAnchorPointMatrix)) {
|
|
130
|
+
return undefined;
|
|
131
|
+
}
|
|
132
|
+
return stretchedAnchorPointMatrix;
|
|
133
|
+
}
|
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Returns a map from child to parent guaranteed to be loop free.
|
|
3
|
-
* The anchor children (keys in the map) will all have a "anchorRef" and there is what
|
|
4
|
-
* measureParam they are linked on is found.
|
|
5
|
-
* Sorted so that parents are always before their children
|
|
6
|
-
* This function is a bit of a "best effort". These things are not well defined in CET - you
|
|
7
|
-
* can anchor A on B and B on A at the same time for example. You can also anchor B to A
|
|
8
|
-
* while there exists multiple A:s. The code below is a naive implementation as in it will
|
|
9
|
-
* not make the solution which allows the most things to be linked. But that is fine as you
|
|
10
|
-
* should never create a catalogue with strange anchoring anyhow.
|
|
11
|
-
*/
|
|
12
|
-
export declare function makeAnchoredToAnchorMap<A extends {
|
|
13
|
-
anchorRef: {
|
|
14
|
-
stretchSymNodeId: string;
|
|
15
|
-
} | undefined;
|
|
16
|
-
}, T extends {
|
|
17
|
-
stretchDatas: {
|
|
18
|
-
stretchSymNodeId: string;
|
|
19
|
-
}[];
|
|
20
|
-
}>(nodes: (A | T)[], targetCandidateComparer: (measureParamCode: string, l: T, r: T) => number): Map<A, T>;
|
|
1
|
+
/**
|
|
2
|
+
* Returns a map from child to parent guaranteed to be loop free.
|
|
3
|
+
* The anchor children (keys in the map) will all have a "anchorRef" and there is what
|
|
4
|
+
* measureParam they are linked on is found.
|
|
5
|
+
* Sorted so that parents are always before their children
|
|
6
|
+
* This function is a bit of a "best effort". These things are not well defined in CET - you
|
|
7
|
+
* can anchor A on B and B on A at the same time for example. You can also anchor B to A
|
|
8
|
+
* while there exists multiple A:s. The code below is a naive implementation as in it will
|
|
9
|
+
* not make the solution which allows the most things to be linked. But that is fine as you
|
|
10
|
+
* should never create a catalogue with strange anchoring anyhow.
|
|
11
|
+
*/
|
|
12
|
+
export declare function makeAnchoredToAnchorMap<A extends {
|
|
13
|
+
anchorRef: {
|
|
14
|
+
stretchSymNodeId: string;
|
|
15
|
+
} | undefined;
|
|
16
|
+
}, T extends {
|
|
17
|
+
stretchDatas: {
|
|
18
|
+
stretchSymNodeId: string;
|
|
19
|
+
}[];
|
|
20
|
+
}>(nodes: (A | T)[], targetCandidateComparer: (measureParamCode: string, l: T, r: T) => number): Map<A, T>;
|
|
21
21
|
//# sourceMappingURL=anchorMap.d.ts.map
|
|
@@ -1,111 +1,111 @@
|
|
|
1
|
-
// Tests do not work if we have Babylon-imports in the same file, so this has to be a separate file
|
|
2
|
-
/**
|
|
3
|
-
* Returns a map from child to parent guaranteed to be loop free.
|
|
4
|
-
* The anchor children (keys in the map) will all have a "anchorRef" and there is what
|
|
5
|
-
* measureParam they are linked on is found.
|
|
6
|
-
* Sorted so that parents are always before their children
|
|
7
|
-
* This function is a bit of a "best effort". These things are not well defined in CET - you
|
|
8
|
-
* can anchor A on B and B on A at the same time for example. You can also anchor B to A
|
|
9
|
-
* while there exists multiple A:s. The code below is a naive implementation as in it will
|
|
10
|
-
* not make the solution which allows the most things to be linked. But that is fine as you
|
|
11
|
-
* should never create a catalogue with strange anchoring anyhow.
|
|
12
|
-
*/
|
|
13
|
-
export function makeAnchoredToAnchorMap(nodes, targetCandidateComparer) {
|
|
14
|
-
function isAnchoree(n) {
|
|
15
|
-
return "anchorRef" in n;
|
|
16
|
-
}
|
|
17
|
-
function isTarget(n) {
|
|
18
|
-
return "stretchDatas" in n;
|
|
19
|
-
}
|
|
20
|
-
const anchoredToAnchorMap = new Map();
|
|
21
|
-
// Step 1: build a legal tree
|
|
22
|
-
for (const node of nodes) {
|
|
23
|
-
if (!isAnchoree(node)) {
|
|
24
|
-
continue;
|
|
25
|
-
}
|
|
26
|
-
const anchorRef = node.anchorRef;
|
|
27
|
-
if (anchorRef === undefined) {
|
|
28
|
-
continue;
|
|
29
|
-
}
|
|
30
|
-
const stretchSymNodeId = anchorRef.stretchSymNodeId;
|
|
31
|
-
const targetCandidates = nodes
|
|
32
|
-
.filter((n) => {
|
|
33
|
-
// Ignore self
|
|
34
|
-
if (node === n) {
|
|
35
|
-
return false;
|
|
36
|
-
}
|
|
37
|
-
if (!isTarget(n)) {
|
|
38
|
-
return false;
|
|
39
|
-
}
|
|
40
|
-
// Can we anchor to this node?
|
|
41
|
-
return n.stretchDatas.some((stretchData) => stretchSymNodeId === stretchData.stretchSymNodeId);
|
|
42
|
-
})
|
|
43
|
-
.map((t, i) => ({ t, i }))
|
|
44
|
-
.sort((l, r) => {
|
|
45
|
-
// As sort is not stable in JS-versions older than EcmaScript 2019 we add the
|
|
46
|
-
// array original index to have as a fallback when there is a draw
|
|
47
|
-
const comp = targetCandidateComparer(anchorRef.stretchSymNodeId, l.t, r.t);
|
|
48
|
-
if (comp === 0) {
|
|
49
|
-
return l.i - r.i;
|
|
50
|
-
}
|
|
51
|
-
return comp;
|
|
52
|
-
})
|
|
53
|
-
.map((tt) => tt.t);
|
|
54
|
-
let okay = true;
|
|
55
|
-
for (const otherNode of targetCandidates) {
|
|
56
|
-
okay = true;
|
|
57
|
-
// Loop control, the candidate can not be a child, then we would get a loop
|
|
58
|
-
let loopCandidate = otherNode;
|
|
59
|
-
while (loopCandidate !== undefined) {
|
|
60
|
-
if (!isAnchoree(loopCandidate)) {
|
|
61
|
-
break;
|
|
62
|
-
}
|
|
63
|
-
loopCandidate = anchoredToAnchorMap.get(loopCandidate);
|
|
64
|
-
if (loopCandidate === node) {
|
|
65
|
-
okay = false;
|
|
66
|
-
break;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
if (okay) {
|
|
70
|
-
anchoredToAnchorMap.set(node, otherNode);
|
|
71
|
-
break;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
if (!okay) {
|
|
75
|
-
console.warn("No SymRootNode to anchor to found.");
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
// From anchored to anchor
|
|
79
|
-
const unplaced = Array.from(anchoredToAnchorMap);
|
|
80
|
-
// Step 2: Build a sorted map so that parents are before their children
|
|
81
|
-
const result = [];
|
|
82
|
-
for (;;) {
|
|
83
|
-
const candidate = unplaced.pop();
|
|
84
|
-
if (candidate === undefined) {
|
|
85
|
-
//done
|
|
86
|
-
break;
|
|
87
|
-
}
|
|
88
|
-
const parent = candidate[1];
|
|
89
|
-
const indexInResult = result.findIndex((otherAnchoredToAnchor) => parent === otherAnchoredToAnchor[0]);
|
|
90
|
-
if (indexInResult === -1) {
|
|
91
|
-
// Candidates parent is not in the result, see if it in those waiting
|
|
92
|
-
const indexInUnplaced = unplaced.findIndex((item) => item[0] === parent);
|
|
93
|
-
if (indexInUnplaced === -1) {
|
|
94
|
-
// The parent was not part of the original nodes, so we just add this node.
|
|
95
|
-
result.push(candidate);
|
|
96
|
-
}
|
|
97
|
-
else {
|
|
98
|
-
const toMoveUp = unplaced.splice(indexInUnplaced, 1)[0];
|
|
99
|
-
// Put back to candidate
|
|
100
|
-
unplaced.push(candidate);
|
|
101
|
-
// Move up the parent
|
|
102
|
-
unplaced.push(toMoveUp);
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
else {
|
|
106
|
-
// Parent is in result
|
|
107
|
-
result.splice(indexInResult + 1, 0, candidate);
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
return new Map(result);
|
|
111
|
-
}
|
|
1
|
+
// Tests do not work if we have Babylon-imports in the same file, so this has to be a separate file
|
|
2
|
+
/**
|
|
3
|
+
* Returns a map from child to parent guaranteed to be loop free.
|
|
4
|
+
* The anchor children (keys in the map) will all have a "anchorRef" and there is what
|
|
5
|
+
* measureParam they are linked on is found.
|
|
6
|
+
* Sorted so that parents are always before their children
|
|
7
|
+
* This function is a bit of a "best effort". These things are not well defined in CET - you
|
|
8
|
+
* can anchor A on B and B on A at the same time for example. You can also anchor B to A
|
|
9
|
+
* while there exists multiple A:s. The code below is a naive implementation as in it will
|
|
10
|
+
* not make the solution which allows the most things to be linked. But that is fine as you
|
|
11
|
+
* should never create a catalogue with strange anchoring anyhow.
|
|
12
|
+
*/
|
|
13
|
+
export function makeAnchoredToAnchorMap(nodes, targetCandidateComparer) {
|
|
14
|
+
function isAnchoree(n) {
|
|
15
|
+
return "anchorRef" in n;
|
|
16
|
+
}
|
|
17
|
+
function isTarget(n) {
|
|
18
|
+
return "stretchDatas" in n;
|
|
19
|
+
}
|
|
20
|
+
const anchoredToAnchorMap = new Map();
|
|
21
|
+
// Step 1: build a legal tree
|
|
22
|
+
for (const node of nodes) {
|
|
23
|
+
if (!isAnchoree(node)) {
|
|
24
|
+
continue;
|
|
25
|
+
}
|
|
26
|
+
const anchorRef = node.anchorRef;
|
|
27
|
+
if (anchorRef === undefined) {
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
30
|
+
const stretchSymNodeId = anchorRef.stretchSymNodeId;
|
|
31
|
+
const targetCandidates = nodes
|
|
32
|
+
.filter((n) => {
|
|
33
|
+
// Ignore self
|
|
34
|
+
if (node === n) {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
if (!isTarget(n)) {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
// Can we anchor to this node?
|
|
41
|
+
return n.stretchDatas.some((stretchData) => stretchSymNodeId === stretchData.stretchSymNodeId);
|
|
42
|
+
})
|
|
43
|
+
.map((t, i) => ({ t, i }))
|
|
44
|
+
.sort((l, r) => {
|
|
45
|
+
// As sort is not stable in JS-versions older than EcmaScript 2019 we add the
|
|
46
|
+
// array original index to have as a fallback when there is a draw
|
|
47
|
+
const comp = targetCandidateComparer(anchorRef.stretchSymNodeId, l.t, r.t);
|
|
48
|
+
if (comp === 0) {
|
|
49
|
+
return l.i - r.i;
|
|
50
|
+
}
|
|
51
|
+
return comp;
|
|
52
|
+
})
|
|
53
|
+
.map((tt) => tt.t);
|
|
54
|
+
let okay = true;
|
|
55
|
+
for (const otherNode of targetCandidates) {
|
|
56
|
+
okay = true;
|
|
57
|
+
// Loop control, the candidate can not be a child, then we would get a loop
|
|
58
|
+
let loopCandidate = otherNode;
|
|
59
|
+
while (loopCandidate !== undefined) {
|
|
60
|
+
if (!isAnchoree(loopCandidate)) {
|
|
61
|
+
break;
|
|
62
|
+
}
|
|
63
|
+
loopCandidate = anchoredToAnchorMap.get(loopCandidate);
|
|
64
|
+
if (loopCandidate === node) {
|
|
65
|
+
okay = false;
|
|
66
|
+
break;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
if (okay) {
|
|
70
|
+
anchoredToAnchorMap.set(node, otherNode);
|
|
71
|
+
break;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
if (!okay) {
|
|
75
|
+
console.warn("No SymRootNode to anchor to found.");
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
// From anchored to anchor
|
|
79
|
+
const unplaced = Array.from(anchoredToAnchorMap);
|
|
80
|
+
// Step 2: Build a sorted map so that parents are before their children
|
|
81
|
+
const result = [];
|
|
82
|
+
for (;;) {
|
|
83
|
+
const candidate = unplaced.pop();
|
|
84
|
+
if (candidate === undefined) {
|
|
85
|
+
//done
|
|
86
|
+
break;
|
|
87
|
+
}
|
|
88
|
+
const parent = candidate[1];
|
|
89
|
+
const indexInResult = result.findIndex((otherAnchoredToAnchor) => parent === otherAnchoredToAnchor[0]);
|
|
90
|
+
if (indexInResult === -1) {
|
|
91
|
+
// Candidates parent is not in the result, see if it in those waiting
|
|
92
|
+
const indexInUnplaced = unplaced.findIndex((item) => item[0] === parent);
|
|
93
|
+
if (indexInUnplaced === -1) {
|
|
94
|
+
// The parent was not part of the original nodes, so we just add this node.
|
|
95
|
+
result.push(candidate);
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
const toMoveUp = unplaced.splice(indexInUnplaced, 1)[0];
|
|
99
|
+
// Put back to candidate
|
|
100
|
+
unplaced.push(candidate);
|
|
101
|
+
// Move up the parent
|
|
102
|
+
unplaced.push(toMoveUp);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
// Parent is in result
|
|
107
|
+
result.splice(indexInResult + 1, 0, candidate);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return new Map(result);
|
|
111
|
+
}
|