@configura/babylon-view 1.3.0-alpha.2 → 1.3.0-alpha.7

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 (47) hide show
  1. package/dist/animation/coordinator/CoordinatorDropAndSpin.js +1 -1
  2. package/dist/animation/coordinator/CoordinatorPulseBounce.js +1 -1
  3. package/dist/animation/coordinator/CoordinatorPulseHighlight.js +1 -1
  4. package/dist/animation/coordinator/CoordinatorPulseInflate.js +1 -1
  5. package/dist/camera/CfgArcRotateCameraPointersInput.d.ts +16 -0
  6. package/dist/camera/CfgArcRotateCameraPointersInput.js +17 -15
  7. package/dist/geometry/CfgGeometry.d.ts +22 -5
  8. package/dist/geometry/CfgGeometry.js +131 -102
  9. package/dist/geometry/CfgMesh.d.ts +4 -1
  10. package/dist/geometry/CfgMesh.js +32 -2
  11. package/dist/geometry/stretch/CfgMorphTarget.d.ts +16 -0
  12. package/dist/geometry/stretch/CfgMorphTarget.js +65 -0
  13. package/dist/geometry/stretch/CfgStretchData.d.ts +115 -0
  14. package/dist/geometry/stretch/CfgStretchData.js +340 -0
  15. package/dist/geometry/stretch/CfgStretchMorphGeometry.d.ts +17 -0
  16. package/dist/geometry/stretch/CfgStretchMorphGeometry.js +95 -0
  17. package/dist/material/CfgMaterial.d.ts +19 -4
  18. package/dist/material/CfgMaterial.js +38 -30
  19. package/dist/material/material.js +3 -3
  20. package/dist/material/texture.js +10 -8
  21. package/dist/nodes/CfgDeferredMeshNode.d.ts +8 -1
  22. package/dist/nodes/CfgDeferredMeshNode.js +48 -18
  23. package/dist/nodes/CfgProductNode.d.ts +68 -3
  24. package/dist/nodes/CfgProductNode.js +130 -38
  25. package/dist/nodes/CfgSymNode.d.ts +14 -6
  26. package/dist/nodes/CfgSymNode.js +50 -17
  27. package/dist/nodes/CfgSymRootNode.d.ts +18 -6
  28. package/dist/nodes/CfgSymRootNode.js +62 -17
  29. package/dist/nodes/CfgTransformNode.d.ts +4 -0
  30. package/dist/nodes/CfgTransformNode.js +4 -2
  31. package/dist/utilities/CfgBoundingBox.d.ts +5 -0
  32. package/dist/utilities/CfgBoundingBox.js +18 -1
  33. package/dist/utilities/anchor/anchor.d.ts +52 -0
  34. package/dist/utilities/anchor/anchor.js +136 -0
  35. package/dist/utilities/anchor/anchorMap.d.ts +21 -0
  36. package/dist/utilities/anchor/anchorMap.js +111 -0
  37. package/dist/utilities/utilities3D.d.ts +44 -0
  38. package/dist/utilities/utilities3D.js +97 -19
  39. package/dist/utilities/utilitiesSymRootIdentifier.d.ts +3 -1
  40. package/dist/utilities/utilitiesSymRootIdentifier.js +10 -4
  41. package/dist/view/BaseView.d.ts +9 -1
  42. package/dist/view/BaseView.js +16 -10
  43. package/dist/view/RenderEnv.d.ts +6 -1
  44. package/dist/view/SingleProductDefaultCameraView.js +1 -1
  45. package/dist/view/SingleProductView.d.ts +8 -1
  46. package/dist/view/SingleProductView.js +1 -0
  47. package/package.json +5 -5
@@ -8,10 +8,14 @@ import { Point } from "@configura/web-core/dist/cm/geometry/Point.js";
8
8
  export function vector3Equals(left, right) {
9
9
  return left.x === right.x && left.y === right.y && left.z === right.z;
10
10
  }
11
+ export function cmPointToVector3(point) {
12
+ return new Vector3(point.x, point.y, point.z);
13
+ }
11
14
  const allAxes = ["x", "y", "z"];
12
- /// Calculates the change in one component for min or max when
13
- /// moving from one bounding box to another.
14
- /// Negative result is shrink, positive is grow. forMax is accounted for.
15
+ /**
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
+ */
15
19
  export const getBoundingBoxChangeForAxis = (bbOld, bbNew, forMax, axis) => {
16
20
  const getMinMax = forMax
17
21
  ? (bb) => bb.maximum
@@ -25,17 +29,20 @@ export const getBoundingBoxChangeForAxis = (bbOld, bbNew, forMax, axis) => {
25
29
  ((getC(getMinMax(bbNew)) - getC(getMinMax(bbOld))) /
26
30
  Math.abs(getC(bbOld.maximum) - getC(bbOld.minimum))));
27
31
  };
28
- /// Given an old bounding box and a new tells if the size difference
29
- /// in one component is significant
32
+ /**
33
+ * Given an old bounding box and a new tells if the size difference in one component is significant.
34
+ */
30
35
  export const boundingBoxChangeIsSignificantForAxis = (bbOld, bbNew, forMax, axis, acceptableDifferenceShrink, acceptableDifferenceGrow) => {
31
36
  const change = getBoundingBoxChangeForAxis(bbOld, bbNew, forMax, axis);
32
37
  return (change < 0 ? acceptableDifferenceShrink : acceptableDifferenceGrow) < Math.abs(change);
33
38
  };
34
- /// Returns true if one bb was empty and the other not or
35
- /// There is a size change in any of the six primary directions which
36
- /// is larger than acceptableDifferenceShrink or acceptableDifferenceGrow
37
- /// depending if the change from bbOld to bbNew in that direction is
38
- /// shrink or grow.
39
+ /**
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
+ */
39
46
  export function boundingBoxesAreSignificantlyDifferent(bbOld, bbNew, acceptableDifferenceShrink, acceptableDifferenceGrow) {
40
47
  if (bbOld.isEmpty !== bbNew.isEmpty) {
41
48
  return true;
@@ -107,11 +114,13 @@ export function measureLongestDistanceToCorner(bb, measureComponents) {
107
114
  }
108
115
  return Math.sqrt(longestSquaredDistanceFromCenter);
109
116
  }
110
- /// Creates an ATriMeshF instance containing a mesh of a sphere of the given radius (default 1)
111
- /// centered on the given position (default <0,0,0>). The "resolution" of the mesh is set by the
112
- /// segments value (default 32).
113
- ///
114
- /// UV coordinates are generated by wrapping the texture around the sphere like a world map.
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
+ */
115
124
  export function aTriMeshSphere(radius, center, segments) {
116
125
  // Simplified and slightly modified (mostly z-up etc) version of SphereBuilder from Babylon.js
117
126
  // https://github.com/BabylonJS/Babylon.js/blob/master/src/Meshes/Builders/sphereBuilder.ts
@@ -156,10 +165,12 @@ export function aTriMeshSphere(radius, center, segments) {
156
165
  // On the other hand, during testing the calls below took 0ms for 52k indices...
157
166
  return ATriMeshF.createWithArrays(Uint32Array.from(indices), Float32Array.from(positions), Float32Array.from(normals), Float32Array.from(uvs));
158
167
  }
159
- /// Creates an ATriMeshF instance containing a mesh of a box between the two points.
160
- /// Default value of p0 is <0,0,0> and p1 is <1,1,1>.
161
- ///
162
- /// UV coordinates are generated, repeating the texture on each side.
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
+ */
163
174
  export function aTriMeshBox(p0, p1) {
164
175
  p0 = p0 !== null && p0 !== void 0 ? p0 : new Point(0, 0, 0);
165
176
  p1 = p1 !== null && p1 !== void 0 ? p1 : new Point(1, 1, 1);
@@ -185,3 +196,70 @@ const BOX_UVS = new Float32Array([1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0
185
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,
186
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,
187
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,6 +1,8 @@
1
1
  import { RootNodeSource, Transform as ModelTransform } from "@configura/web-api";
2
+ import { CfgAnchorRef } from "./anchor/anchor.js";
2
3
  export declare function makeIdentifier(type: "uri" | "file", v: string): string;
4
+ export declare function identifierIsUri(identifier: string): boolean;
3
5
  export declare function makeIdentifierFromRootNodeSource(source: RootNodeSource): string;
4
- export declare function isSameIdentifierAndTransform(identifier1: string, transform1: ModelTransform | undefined, identifier2: string, transform2: ModelTransform | undefined): boolean;
6
+ export declare function isSameIdentifierTransformAndAnchor(identifier1: string, transform1: ModelTransform | undefined, anchor1: CfgAnchorRef | undefined, identifier2: string, transform2: ModelTransform | undefined, anchor2: CfgAnchorRef | undefined): boolean;
5
7
  export declare function isSameRootNodeSource(source1: RootNodeSource, source2: RootNodeSource): boolean;
6
8
  //# sourceMappingURL=utilitiesSymRootIdentifier.d.ts.map
@@ -1,20 +1,26 @@
1
1
  import { isModel } from "@configura/web-api";
2
+ import { CfgAnchorRef } from "./anchor/anchor.js";
2
3
  import { modelTransformsEqual } from "./utilities3D.js";
3
4
  export function makeIdentifier(type, v) {
4
- return `${type}${v}`;
5
+ return `${type}:${v}`;
6
+ }
7
+ export function identifierIsUri(identifier) {
8
+ return identifier.startsWith("uri:");
5
9
  }
6
10
  export function makeIdentifierFromRootNodeSource(source) {
7
11
  return isModel(source)
8
12
  ? makeIdentifier("uri", source.uri)
9
13
  : makeIdentifier("file", source.name);
10
14
  }
11
- export function isSameIdentifierAndTransform(identifier1, transform1, identifier2, transform2) {
15
+ export function isSameIdentifierTransformAndAnchor(identifier1, transform1, anchor1, identifier2, transform2, anchor2) {
12
16
  return (identifier1 === identifier2 &&
13
17
  ((transform1 === undefined && transform2 === undefined) ||
14
18
  (transform1 !== undefined &&
15
19
  transform2 !== undefined &&
16
- modelTransformsEqual(transform1, transform2))));
20
+ modelTransformsEqual(transform1, transform2))) &&
21
+ ((anchor1 === undefined && anchor2 === undefined) ||
22
+ (anchor1 !== undefined && anchor2 !== undefined && anchor1.equal(anchor2))));
17
23
  }
18
24
  export function isSameRootNodeSource(source1, source2) {
19
- return isSameIdentifierAndTransform(makeIdentifierFromRootNodeSource(source1), isModel(source1) ? source1.t : undefined, makeIdentifierFromRootNodeSource(source2), isModel(source2) ? source2.t : undefined);
25
+ return isSameIdentifierTransformAndAnchor(makeIdentifierFromRootNodeSource(source1), isModel(source1) ? source1.t : undefined, isModel(source1) ? CfgAnchorRef.make(source1.anchor) : undefined, makeIdentifierFromRootNodeSource(source2), isModel(source2) ? source2.t : undefined, isModel(source2) ? CfgAnchorRef.make(source2.anchor) : undefined);
20
26
  }
@@ -12,9 +12,17 @@ import { DummyMaterialCreator } from "../material/DummyMaterialCreator.js";
12
12
  import { CfgContentRootNode } from "../nodes/CfgContentRootNode.js";
13
13
  import { SceneCreator } from "../scene/SceneCreator.js";
14
14
  import { BaseViewConfiguration, BaseViewEventMap, CameraConfigurationProps, DetailLevel, ImageDumpCallback } from "./BaseViewConfiguration.js";
15
- import { RenderEnv } from "./RenderEnv.js";
15
+ import { RenderEnv } from "./RenderEnv";
16
16
  export declare const CET_TO_BABYLON_MATRIX: Matrix;
17
17
  export declare const BABYLON_TO_CET_MATRIX: Matrix;
18
+ /**
19
+ * Load the highest quality meshes by default.
20
+ *
21
+ * @remarks We only use "base" as a last fallback. The reason is that even though this LOD level
22
+ * could theoretically include a better version than "super" it is not normally included in CmSym
23
+ * files and never used by CET, which makes it unpredictable. See WRD-387 for a case where it
24
+ * caused problems when it was the first choice.
25
+ */
18
26
  export declare const DEFAULT_DETAIL_LEVELS: DetailLevel[];
19
27
  export declare type BaseViewConstructorOptions<C extends Camera> = {
20
28
  canvas: HTMLCanvasElement;
@@ -18,12 +18,14 @@ export const CET_TO_BABYLON_MATRIX = Matrix.RotationX(-Math.PI / 2);
18
18
  export const BABYLON_TO_CET_MATRIX = Matrix.RotationX(Math.PI / 2);
19
19
  const ENABLE_CONTINUOUS_RENDER = false;
20
20
  const CULL_EMPTY_NODES = true;
21
- /// Load the highest quality meshes by default.
22
- ///
23
- /// @remarks We only use "base" as a last fallback. The reason is that even though this LOD level
24
- /// could theoretically include a better version than "super" it is not normally included in CmSym
25
- /// files and never used by CET, which makes it unpredictable. See WRD-387 for a case where it
26
- /// caused problems when it was the first choice.
21
+ /**
22
+ * Load the highest quality meshes by default.
23
+ *
24
+ * @remarks We only use "base" as a last fallback. The reason is that even though this LOD level
25
+ * could theoretically include a better version than "super" it is not normally included in CmSym
26
+ * files and never used by CET, which makes it unpredictable. See WRD-387 for a case where it
27
+ * caused problems when it was the first choice.
28
+ */
27
29
  export const DEFAULT_DETAIL_LEVELS = [
28
30
  DetailLevel.super,
29
31
  DetailLevel.high,
@@ -31,10 +33,14 @@ export const DEFAULT_DETAIL_LEVELS = [
31
33
  DetailLevel.low,
32
34
  DetailLevel.base,
33
35
  ];
34
- // As this cache contains items read from a another resource undefined
35
- // is an acceptable cache value representing a value that will not be
36
- // anything but undefined no mather how many times you try.
37
- const geometryCache = new PromiseCache();
36
+ /**
37
+ * @remarks As this cache contains items read from a another resource undefined is an acceptable
38
+ * cache value representing a value that will not be anything but undefined no mather how many
39
+ * times you try.
40
+ */
41
+ const geometryCache = new PromiseCache((i1, i2) => i1.component === i2.component &&
42
+ i1.stretchDatasHash === i2.stretchDatasHash &&
43
+ i1.uvMapperHash === i2.uvMapperHash);
38
44
  const symNodeCache = new PromiseCache();
39
45
  const materialCache = new PromiseCache();
40
46
  const textureImageCache = new PromiseCache();
@@ -13,11 +13,16 @@ import { CfgMaterial } from "../material/CfgMaterial.js";
13
13
  import { MaterialWithMetaData } from "../material/material.js";
14
14
  import { TextureImageWithMetaData } from "../material/texture.js";
15
15
  import { ScheduleRerender } from "./BaseViewConfiguration.js";
16
+ export declare type GeometryCacheIdentifierObject = {
17
+ component: SymComponent;
18
+ stretchDatasHash: number;
19
+ uvMapperHash: number | undefined;
20
+ };
16
21
  export interface RenderEnv {
17
22
  scene: Scene;
18
23
  assetsManager: AssetsManager;
19
24
  dummyMaterial: CfgMaterial;
20
- geometryCache: PromiseCache<SymComponent, GeometryCacheEntry | undefined>;
25
+ geometryCache: PromiseCache<GeometryCacheIdentifierObject, GeometryCacheEntry | undefined>;
21
26
  symNodeCache: PromiseCache<string, SymNode>;
22
27
  materialCache: PromiseCache<string | GMaterial3D, MaterialWithMetaData>;
23
28
  textureImageCache: PromiseCache<string, TextureImageWithMetaData>;
@@ -17,7 +17,7 @@ export class SingleProductDefaultCameraView extends SingleProductView {
17
17
  const { distance, pitch, yaw } = this._cameraConf;
18
18
  let change = false;
19
19
  if (distance !== undefined) {
20
- this._camera.radius = distance;
20
+ this._camera.forceRadius(distance);
21
21
  change = true;
22
22
  }
23
23
  if (pitch !== undefined) {
@@ -1,5 +1,5 @@
1
1
  import { Camera } from "@babylonjs/core/Cameras/camera.js";
2
- import { ApplicationArea, CfgProduct } from "@configura/web-api";
2
+ import { ApplicationArea, CfgProduct, Model, MtrlApplication, PartsData } from "@configura/web-api";
3
3
  import { EventListener } from "@configura/web-utilities";
4
4
  import { CoordinatorWithMeta } from "../animation/coordinator/Coordinator.js";
5
5
  import { CameraCreator } from "../camera/CameraCreator.js";
@@ -19,6 +19,13 @@ export declare type SingleProductViewConstructorOptions<C extends Camera> = {
19
19
  sceneCreator?: SceneCreator;
20
20
  dummyMaterialCreator?: DummyMaterialCreator;
21
21
  };
22
+ export declare type RootNodeSource = Model | File;
23
+ export declare type CfgProductViewProductData = {
24
+ mtrlApplications?: MtrlApplication[];
25
+ sku: string;
26
+ models?: RootNodeSource[];
27
+ partsData: PartsData;
28
+ };
22
29
  export declare class SingleProductView<C extends Camera = Camera, T extends SingleProductViewEventMap = SingleProductViewEventMap> extends BaseView<C, T> {
23
30
  private _currentProductNode;
24
31
  private _scheduledForRemoval;
@@ -61,6 +61,7 @@ export class SingleProductView extends BaseView {
61
61
  };
62
62
  try {
63
63
  this.notifyPhaseChange(SingleProductViewPhase.SetModelsAndLoadGeo);
64
+ currentProductNode.refreshStretch();
64
65
  yield currentProductNode.loadGeo(animationCoordinator);
65
66
  if (isNewProduct) {
66
67
  // New products needs resizing before rendering the first time
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@configura/babylon-view",
3
- "version": "1.3.0-alpha.2",
3
+ "version": "1.3.0-alpha.7",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -16,16 +16,16 @@
16
16
  },
17
17
  "dependencies": {
18
18
  "@babylonjs/core": "4.2.0",
19
- "@configura/web-core": "^1.3.0-alpha.2",
20
- "@configura/web-utilities": "^1.3.0-alpha.2"
19
+ "@configura/web-core": "^1.3.0-alpha.7",
20
+ "@configura/web-utilities": "^1.3.0-alpha.7"
21
21
  },
22
22
  "devDependencies": {
23
- "@configura/web-api": "^1.3.0-alpha.2",
23
+ "@configura/web-api": "^1.3.0-alpha.7",
24
24
  "del-cli": "^3.0.0",
25
25
  "typescript": "4.2"
26
26
  },
27
27
  "publishConfig": {
28
28
  "access": "public"
29
29
  },
30
- "gitHead": "ecc00b624310c03a59c0ac5933e06df92326436d"
30
+ "gitHead": "1c5c089a31e6662b6da365b7038254e70a1cc8ff"
31
31
  }