@configura/web-core 1.3.0-alpha.3 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (177) hide show
  1. package/LICENSE +201 -201
  2. package/README.md +1 -1
  3. package/dist/cm/basic/Color.d.ts +16 -16
  4. package/dist/cm/basic/Color.js +18 -18
  5. package/dist/cm/basic/ColorF.d.ts +9 -9
  6. package/dist/cm/basic/ColorF.js +10 -10
  7. package/dist/cm/basic/boolean.d.ts +2 -2
  8. package/dist/cm/basic/boolean.js +11 -11
  9. package/dist/cm/basic/number.d.ts +3 -3
  10. package/dist/cm/basic/number.js +18 -18
  11. package/dist/cm/basic/string.d.ts +2 -2
  12. package/dist/cm/basic/string.js +11 -11
  13. package/dist/cm/core3D/ATriMeshF.d.ts +96 -90
  14. package/dist/cm/core3D/ATriMeshF.js +197 -193
  15. package/dist/cm/core3D/GMaterial3D.d.ts +62 -58
  16. package/dist/cm/core3D/GMaterial3D.js +112 -112
  17. package/dist/cm/core3D/GMaterialClassic.d.ts +55 -55
  18. package/dist/cm/core3D/GMaterialClassic.js +171 -171
  19. package/dist/cm/core3D/GMaterialPBR.d.ts +73 -71
  20. package/dist/cm/core3D/GMaterialPBR.js +314 -288
  21. package/dist/cm/core3D/MultiGMaterial3D.d.ts +8 -8
  22. package/dist/cm/core3D/MultiGMaterial3D.js +17 -17
  23. package/dist/cm/core3D/{UVMapEnv.d.ts → uvmapper/UVMapEnv.d.ts} +19 -17
  24. package/dist/cm/core3D/{UVMapEnv.js → uvmapper/UVMapEnv.js} +47 -35
  25. package/dist/cm/core3D/uvmapper/UVMapper.d.ts +42 -0
  26. package/dist/cm/core3D/uvmapper/UVMapper.js +94 -0
  27. package/dist/cm/core3D/uvmapper/UVMapperBox.d.ts +5 -0
  28. package/dist/cm/core3D/uvmapper/UVMapperBox.js +181 -0
  29. package/dist/cm/core3D/uvmapper/UVMapperCylinder.d.ts +10 -0
  30. package/dist/cm/core3D/uvmapper/UVMapperCylinder.js +96 -0
  31. package/dist/cm/core3D/uvmapper/UVMapperPlane.d.ts +4 -0
  32. package/dist/cm/core3D/uvmapper/UVMapperPlane.js +84 -0
  33. package/dist/cm/core3D/uvmapper/UVTransformer.d.ts +6 -0
  34. package/dist/cm/core3D/{UVTransformer.js → uvmapper/UVTransformer.js} +5 -5
  35. package/dist/cm/core3D/uvmapper/instantiateUVMapper.d.ts +4 -0
  36. package/dist/cm/core3D/uvmapper/instantiateUVMapper.js +4 -0
  37. package/dist/cm/format/cmsym/InvalidationEnv.d.ts +9 -9
  38. package/dist/cm/format/cmsym/InvalidationEnv.js +13 -13
  39. package/dist/cm/format/cmsym/SymImportEnv.d.ts +9 -9
  40. package/dist/cm/format/cmsym/SymImportEnv.js +9 -9
  41. package/dist/cm/format/cmsym/SymInv.d.ts +8 -8
  42. package/dist/cm/format/cmsym/SymInv.js +15 -15
  43. package/dist/cm/format/cmsym/SymNode.d.ts +93 -85
  44. package/dist/cm/format/cmsym/SymNode.js +652 -577
  45. package/dist/cm/format/cmsym/components/SymBox.d.ts +15 -14
  46. package/dist/cm/format/cmsym/components/SymBox.js +39 -34
  47. package/dist/cm/format/cmsym/components/SymComponent.d.ts +29 -29
  48. package/dist/cm/format/cmsym/components/SymComponent.js +54 -54
  49. package/dist/cm/format/cmsym/components/SymConnector.d.ts +5 -5
  50. package/dist/cm/format/cmsym/components/SymConnector.js +10 -10
  51. package/dist/cm/format/cmsym/components/SymDexObj.d.ts +11 -11
  52. package/dist/cm/format/cmsym/components/SymDexObj.js +10 -10
  53. package/dist/cm/format/cmsym/components/SymGFX.d.ts +11 -11
  54. package/dist/cm/format/cmsym/components/SymGFX.js +20 -20
  55. package/dist/cm/format/cmsym/components/SymGMaterial.d.ts +19 -19
  56. package/dist/cm/format/cmsym/components/SymGMaterial.js +88 -88
  57. package/dist/cm/format/cmsym/components/SymGMaterialSelector.d.ts +17 -12
  58. package/dist/cm/format/cmsym/components/SymGMaterialSelector.js +22 -20
  59. package/dist/cm/format/cmsym/components/SymGetMeshEnv.d.ts +9 -9
  60. package/dist/cm/format/cmsym/components/SymGetMeshEnv.js +9 -9
  61. package/dist/cm/format/cmsym/components/SymLODGroup.d.ts +9 -9
  62. package/dist/cm/format/cmsym/components/SymLODGroup.js +11 -11
  63. package/dist/cm/format/cmsym/components/SymLight.d.ts +8 -8
  64. package/dist/cm/format/cmsym/components/SymLight.js +10 -10
  65. package/dist/cm/format/cmsym/components/SymLines2D.d.ts +5 -5
  66. package/dist/cm/format/cmsym/components/SymLines2D.js +7 -7
  67. package/dist/cm/format/cmsym/components/SymMeasure.d.ts +33 -34
  68. package/dist/cm/format/cmsym/components/SymMeasure.js +149 -158
  69. package/dist/cm/format/cmsym/components/SymMesh.d.ts +29 -29
  70. package/dist/cm/format/cmsym/components/SymMesh.js +130 -130
  71. package/dist/cm/format/cmsym/components/SymMeshLight.d.ts +8 -8
  72. package/dist/cm/format/cmsym/components/SymMeshLight.js +10 -10
  73. package/dist/cm/format/cmsym/components/SymMultiSelector.d.ts +13 -13
  74. package/dist/cm/format/cmsym/components/SymMultiSelector.js +48 -49
  75. package/dist/cm/format/cmsym/components/SymParams.d.ts +16 -4
  76. package/dist/cm/format/cmsym/components/SymParams.js +58 -7
  77. package/dist/cm/format/cmsym/components/SymPlane.d.ts +14 -14
  78. package/dist/cm/format/cmsym/components/SymPlane.js +30 -27
  79. package/dist/cm/format/cmsym/components/SymPlaneDivider.d.ts +4 -4
  80. package/dist/cm/format/cmsym/components/SymPlaneDivider.js +7 -7
  81. package/dist/cm/format/cmsym/components/SymPrimitive2D.d.ts +3 -3
  82. package/dist/cm/format/cmsym/components/SymPrimitive2D.js +3 -3
  83. package/dist/cm/format/cmsym/components/SymProgs.d.ts +32 -4
  84. package/dist/cm/format/cmsym/components/SymProgs.js +120 -7
  85. package/dist/cm/format/cmsym/components/SymProps.d.ts +54 -54
  86. package/dist/cm/format/cmsym/components/SymProps.js +170 -170
  87. package/dist/cm/format/cmsym/components/SymRep.d.ts +13 -13
  88. package/dist/cm/format/cmsym/components/SymRep.js +28 -28
  89. package/dist/cm/format/cmsym/components/SymReps.d.ts +36 -36
  90. package/dist/cm/format/cmsym/components/SymReps.js +229 -229
  91. package/dist/cm/format/cmsym/components/SymShape.d.ts +10 -10
  92. package/dist/cm/format/cmsym/components/SymShape.js +17 -14
  93. package/dist/cm/format/cmsym/components/SymSphere.d.ts +18 -16
  94. package/dist/cm/format/cmsym/components/SymSphere.js +33 -30
  95. package/dist/cm/format/cmsym/components/SymSpotlight.d.ts +8 -8
  96. package/dist/cm/format/cmsym/components/SymSpotlight.js +10 -10
  97. package/dist/cm/format/cmsym/components/SymTags.d.ts +11 -11
  98. package/dist/cm/format/cmsym/components/SymTags.js +20 -20
  99. package/dist/cm/format/cmsym/components/SymText2D.d.ts +5 -4
  100. package/dist/cm/format/cmsym/components/SymText2D.js +8 -8
  101. package/dist/cm/format/cmsym/components/SymText3D.d.ts +5 -4
  102. package/dist/cm/format/cmsym/components/SymText3D.js +8 -8
  103. package/dist/cm/format/cmsym/components/SymTransform.d.ts +23 -23
  104. package/dist/cm/format/cmsym/components/SymTransform.js +101 -101
  105. package/dist/cm/format/cmsym/components/SymUVMapper.d.ts +13 -13
  106. package/dist/cm/format/cmsym/components/SymUVMapper.js +50 -50
  107. package/dist/cm/format/cmsym/components/instantiate.d.ts +2 -2
  108. package/dist/cm/format/cmsym/components/instantiate.js +121 -121
  109. package/dist/cm/format/cmsym/components/legacy.d.ts +7 -7
  110. package/dist/cm/format/cmsym/components/legacy.js +27 -27
  111. package/dist/cm/format/cmsym/components/mesh.d.ts +8 -8
  112. package/dist/cm/format/cmsym/components/mesh.js +28 -28
  113. package/dist/cm/format/cmsym/invalidation.d.ts +4 -4
  114. package/dist/cm/format/cmsym/invalidation.js +72 -72
  115. package/dist/cm/format/dex/DexIRef.d.ts +9 -9
  116. package/dist/cm/format/dex/DexIRef.js +18 -18
  117. package/dist/cm/format/dex/DexInt.d.ts +11 -11
  118. package/dist/cm/format/dex/DexInt.js +18 -18
  119. package/dist/cm/format/dex/DexInternalizedXRef.d.ts +19 -19
  120. package/dist/cm/format/dex/DexInternalizedXRef.js +64 -64
  121. package/dist/cm/format/dex/DexLoader.d.ts +8 -8
  122. package/dist/cm/format/dex/DexLoader.js +12 -12
  123. package/dist/cm/format/dex/DexManager.d.ts +20 -20
  124. package/dist/cm/format/dex/DexManager.js +78 -78
  125. package/dist/cm/format/dex/DexObj.d.ts +15 -15
  126. package/dist/cm/format/dex/DexObj.js +86 -86
  127. package/dist/cm/format/dex/DexReader.d.ts +90 -86
  128. package/dist/cm/format/dex/DexReader.js +532 -492
  129. package/dist/cm/format/dex/DexRef.d.ts +6 -6
  130. package/dist/cm/format/dex/DexRef.js +8 -8
  131. package/dist/cm/format/dex/DexReplacedXRefs.d.ts +8 -8
  132. package/dist/cm/format/dex/DexReplacedXRefs.js +22 -22
  133. package/dist/cm/format/dex/DexURL.d.ts +4 -4
  134. package/dist/cm/format/dex/DexURL.js +5 -5
  135. package/dist/cm/format/dex/DexVersion.d.ts +15 -15
  136. package/dist/cm/format/dex/DexVersion.js +53 -53
  137. package/dist/cm/format/dex/DexXRef.d.ts +18 -18
  138. package/dist/cm/format/dex/DexXRef.js +51 -51
  139. package/dist/cm/format/dex/DexXRefTargetFilter.d.ts +4 -4
  140. package/dist/cm/format/dex/DexXRefTargetFilter.js +5 -5
  141. package/dist/cm/geometry/Angle.d.ts +9 -9
  142. package/dist/cm/geometry/Angle.js +18 -18
  143. package/dist/cm/geometry/AngleF.d.ts +5 -5
  144. package/dist/cm/geometry/AngleF.js +8 -8
  145. package/dist/cm/geometry/Box.d.ts +7 -7
  146. package/dist/cm/geometry/Box.js +9 -9
  147. package/dist/cm/geometry/DetailMask.d.ts +37 -32
  148. package/dist/cm/geometry/DetailMask.js +114 -112
  149. package/dist/cm/geometry/LayerExpr.d.ts +2 -2
  150. package/dist/cm/geometry/LayerExpr.js +2 -2
  151. package/dist/cm/geometry/Matrix22.d.ts +7 -6
  152. package/dist/cm/geometry/Matrix22.js +9 -6
  153. package/dist/cm/geometry/Matrix33.d.ts +42 -42
  154. package/dist/cm/geometry/Matrix33.js +124 -124
  155. package/dist/cm/geometry/Orientation.d.ts +7 -7
  156. package/dist/cm/geometry/Orientation.js +7 -7
  157. package/dist/cm/geometry/Plane.d.ts +8 -8
  158. package/dist/cm/geometry/Plane.js +14 -14
  159. package/dist/cm/geometry/Point.d.ts +21 -18
  160. package/dist/cm/geometry/Point.js +65 -56
  161. package/dist/cm/geometry/Point2D.d.ts +9 -8
  162. package/dist/cm/geometry/Point2D.js +23 -20
  163. package/dist/cm/geometry/PointF.d.ts +11 -11
  164. package/dist/cm/geometry/PointF.js +27 -27
  165. package/dist/cm/geometry/Transform.d.ts +11 -11
  166. package/dist/cm/geometry/Transform.js +61 -61
  167. package/dist/cm/geometry/Transform2D.d.ts +7 -7
  168. package/dist/cm/geometry/Transform2D.js +6 -6
  169. package/dist/cm/io/Semver.d.ts +18 -17
  170. package/dist/cm/io/Semver.js +61 -58
  171. package/dist/index.js +1 -1
  172. package/package.json +4 -4
  173. package/dist/cm/core3D/DummyUVMapper.d.ts +0 -7
  174. package/dist/cm/core3D/DummyUVMapper.js +0 -6
  175. package/dist/cm/core3D/UVTransformer.d.ts +0 -6
  176. package/dist/cm/core3D/instantiateUVMapper.d.ts +0 -4
  177. package/dist/cm/core3D/instantiateUVMapper.js +0 -5
@@ -1,17 +1,17 @@
1
- export class MultiGMaterial3D {
2
- constructor(materialMap = new Map(), realtimeMaterial3D, renderMaterial3D) {
3
- this.materialMap = materialMap;
4
- if (realtimeMaterial3D !== undefined) {
5
- this.materialMap.set("medium", realtimeMaterial3D);
6
- }
7
- if (renderMaterial3D !== undefined) {
8
- this.materialMap.set("super", renderMaterial3D);
9
- }
10
- }
11
- realtimeMaterial() {
12
- return this.materialMap.get("medium");
13
- }
14
- renderMaterial() {
15
- return this.materialMap.get("super");
16
- }
17
- }
1
+ export class MultiGMaterial3D {
2
+ constructor(materialMap = new Map(), realtimeMaterial3D, renderMaterial3D) {
3
+ this.materialMap = materialMap;
4
+ if (realtimeMaterial3D !== undefined) {
5
+ this.materialMap.set("medium", realtimeMaterial3D);
6
+ }
7
+ if (renderMaterial3D !== undefined) {
8
+ this.materialMap.set("super", renderMaterial3D);
9
+ }
10
+ }
11
+ realtimeMaterial() {
12
+ return this.materialMap.get("medium");
13
+ }
14
+ renderMaterial() {
15
+ return this.materialMap.get("super");
16
+ }
17
+ }
@@ -1,18 +1,20 @@
1
- import { Point } from "../geometry/Point.js";
2
- import { UVTransformer } from "./UVTransformer.js";
3
- export declare enum UVMapperType {
4
- Box = 0,
5
- Spherical = 1,
6
- Planar = 2,
7
- Cylindrical = 3
8
- }
9
- export declare function castUVMapperType(name: string): UVMapperType | undefined;
10
- export declare function fcastUVMapperType(name: string): UVMapperType;
11
- export declare class UVMapEnv {
12
- type: UVMapperType;
13
- transforms?: UVTransformer[] | undefined;
14
- normal: Point;
15
- uniform: boolean;
16
- constructor(type: UVMapperType, transforms?: UVTransformer[] | undefined, normal?: Point, uniform?: boolean);
17
- }
1
+ import { Point } from "../../geometry/Point.js";
2
+ import { UVTransformer } from "./UVTransformer.js";
3
+ export declare enum UVMapperType {
4
+ Box = 0,
5
+ Spherical = 1,
6
+ Planar = 2,
7
+ Cylindrical = 3
8
+ }
9
+ export declare function castUVMapperType(name: string): UVMapperType | undefined;
10
+ export declare function fcastUVMapperType(name: string): UVMapperType;
11
+ export declare class UVMapEnv {
12
+ type: UVMapperType;
13
+ transforms?: UVTransformer[] | undefined;
14
+ normal: Point;
15
+ uniform: boolean;
16
+ constructor(type: UVMapperType, transforms?: UVTransformer[] | undefined, normal?: Point, uniform?: boolean);
17
+ private _hash;
18
+ get hash(): number;
19
+ }
18
20
  //# sourceMappingURL=UVMapEnv.d.ts.map
@@ -1,35 +1,47 @@
1
- import { Point } from "../geometry/Point.js";
2
- export var UVMapperType;
3
- (function (UVMapperType) {
4
- UVMapperType[UVMapperType["Box"] = 0] = "Box";
5
- UVMapperType[UVMapperType["Spherical"] = 1] = "Spherical";
6
- UVMapperType[UVMapperType["Planar"] = 2] = "Planar";
7
- UVMapperType[UVMapperType["Cylindrical"] = 3] = "Cylindrical";
8
- })(UVMapperType || (UVMapperType = {}));
9
- export function castUVMapperType(name) {
10
- switch (name) {
11
- case "box":
12
- return UVMapperType.Box;
13
- case "spherical":
14
- return UVMapperType.Spherical;
15
- case "planar":
16
- return UVMapperType.Planar;
17
- case "cylindrical":
18
- return UVMapperType.Cylindrical;
19
- }
20
- }
21
- export function fcastUVMapperType(name) {
22
- const type = castUVMapperType(name);
23
- if (type === undefined) {
24
- throw new Error(`unknown UVMapperType: ${name}`);
25
- }
26
- return type;
27
- }
28
- export class UVMapEnv {
29
- constructor(type, transforms, normal = new Point(0, 0, 0), uniform = true) {
30
- this.type = type;
31
- this.transforms = transforms;
32
- this.normal = normal;
33
- this.uniform = uniform;
34
- }
35
- }
1
+ import { hashCode } from "@configura/web-utilities";
2
+ import { Point } from "../../geometry/Point.js";
3
+ export var UVMapperType;
4
+ (function (UVMapperType) {
5
+ UVMapperType[UVMapperType["Box"] = 0] = "Box";
6
+ UVMapperType[UVMapperType["Spherical"] = 1] = "Spherical";
7
+ UVMapperType[UVMapperType["Planar"] = 2] = "Planar";
8
+ UVMapperType[UVMapperType["Cylindrical"] = 3] = "Cylindrical";
9
+ })(UVMapperType || (UVMapperType = {}));
10
+ export function castUVMapperType(name) {
11
+ switch (name) {
12
+ case "box":
13
+ return UVMapperType.Box;
14
+ case "spherical":
15
+ return UVMapperType.Spherical;
16
+ case "planar":
17
+ return UVMapperType.Planar;
18
+ case "cylindrical":
19
+ return UVMapperType.Cylindrical;
20
+ }
21
+ }
22
+ export function fcastUVMapperType(name) {
23
+ const type = castUVMapperType(name);
24
+ if (type === undefined) {
25
+ throw new Error(`unknown UVMapperType: ${name}`);
26
+ }
27
+ return type;
28
+ }
29
+ export class UVMapEnv {
30
+ constructor(type, transforms, normal = new Point(0, 0, 0), uniform = true) {
31
+ this.type = type;
32
+ this.transforms = transforms;
33
+ this.normal = normal;
34
+ this.uniform = uniform;
35
+ }
36
+ get hash() {
37
+ if (this._hash === undefined) {
38
+ this._hash = hashCode(`ty${this.type}-tr${(this.transforms || [])
39
+ .map((t) => {
40
+ const { pos, mapping } = t.transform;
41
+ return `po${pos.toString()}-ma${mapping.toString()}`;
42
+ })
43
+ .join("-")}-no${this.normal.toString()}-un${this.uniform}`);
44
+ }
45
+ return this._hash;
46
+ }
47
+ }
@@ -0,0 +1,42 @@
1
+ import { Logger } from "@configura/web-utilities";
2
+ import { UVMapEnv } from "./UVMapEnv.js";
3
+ import { UVTransformer } from "./UVTransformer.js";
4
+ export declare type MinMaxSize = {
5
+ min: number[];
6
+ max: number[];
7
+ size: number[];
8
+ };
9
+ export declare class UVMapper {
10
+ env?: UVMapEnv | undefined;
11
+ /**
12
+ * Applies linear transformations to the UV-coordinates. This is essentially rotating, scaling
13
+ * moving the texture before applying it.
14
+ */
15
+ static applyUvTransform(uv: [number, number], t: UVTransformer): [number, number];
16
+ static calculateLimits(bounds: MinMaxSize, refBounds: MinMaxSize | undefined): {
17
+ refMin: number[];
18
+ refSize: number[];
19
+ textureFixMin: number[];
20
+ textureFixMax: number[];
21
+ };
22
+ static calculateTextureFixLimits(bounds: MinMaxSize, refBounds: MinMaxSize): {
23
+ min: number[];
24
+ max: number[];
25
+ };
26
+ constructor(env?: UVMapEnv | undefined);
27
+ /**
28
+ * Do not use this method if you have prebaked coordinates in the CmSym file generated by CET.
29
+ * It is safer to use the existing ones since CET has already modified the geometry of the
30
+ * mesh by splitting vertices etc.
31
+ */
32
+ createUVCoordinates(logger: Logger, positions: Float32Array, bounds: MinMaxSize, normals: Float32Array): Float32Array;
33
+ /**
34
+ * @param positions Stretched positions
35
+ * @param normals Used both for stretched and non-stretched. We cheat a bit by always using the same normals
36
+ * @param refPositions Non-stretched positions
37
+ * @param refUvs Non-stretched UV coordinates
38
+ * @returns
39
+ */
40
+ createUVCoordinatesForStretched(logger: Logger, positions: Float32Array, bounds: MinMaxSize, normals: Float32Array, refPositions: Float32Array, refBounds: MinMaxSize, refUvs: Float32Array): Float32Array;
41
+ }
42
+ //# sourceMappingURL=UVMapper.d.ts.map
@@ -0,0 +1,94 @@
1
+ import { UVMapperType } from "./UVMapEnv.js";
2
+ import { createUVBoxCoordinates, createUVBoxCoordinatesForStretched } from "./UVMapperBox.js";
3
+ import { createUVCylinderCoordinates, createUVCylinderCoordinatesForStretched, } from "./UVMapperCylinder.js";
4
+ import { createUVPlaneCoordinates, createUVPlaneCoordinatesForStretched } from "./UVMapperPlane.js";
5
+ const xyz = [0, 1, 2];
6
+ export class UVMapper {
7
+ constructor(env) {
8
+ this.env = env;
9
+ }
10
+ /**
11
+ * Applies linear transformations to the UV-coordinates. This is essentially rotating, scaling
12
+ * moving the texture before applying it.
13
+ */
14
+ static applyUvTransform(uv, t) {
15
+ const { mapping, pos } = t.transform;
16
+ const [u, v] = uv;
17
+ const { x, y } = pos;
18
+ let uNew = u;
19
+ let vNew = v;
20
+ const { c0, c1 } = mapping;
21
+ uNew = c0.x * u + c1.x * v;
22
+ vNew = c0.y * u + c1.y * v;
23
+ uNew += x;
24
+ vNew += y;
25
+ return [uNew, vNew];
26
+ }
27
+ static calculateLimits(bounds, refBounds) {
28
+ const { min: refMin, size: refSize } = refBounds || bounds;
29
+ const { min: textureFixMin, max: textureFixMax } = refBounds === undefined
30
+ ? { min: [0, 0, 0], max: [0, 0, 0] }
31
+ : UVMapper.calculateTextureFixLimits(bounds, refBounds);
32
+ return {
33
+ refMin,
34
+ refSize,
35
+ textureFixMin,
36
+ textureFixMax,
37
+ };
38
+ }
39
+ static calculateTextureFixLimits(bounds, refBounds) {
40
+ return {
41
+ min: xyz.map((axis) => (refBounds.min[axis] - bounds.min[axis]) / refBounds.size[axis]),
42
+ max: xyz.map((axis) => (refBounds.max[axis] - bounds.max[axis]) / refBounds.size[axis]),
43
+ };
44
+ }
45
+ /**
46
+ * Do not use this method if you have prebaked coordinates in the CmSym file generated by CET.
47
+ * It is safer to use the existing ones since CET has already modified the geometry of the
48
+ * mesh by splitting vertices etc.
49
+ */
50
+ createUVCoordinates(logger, positions, bounds, normals) {
51
+ const env = this.env;
52
+ if (env === undefined) {
53
+ throw new Error("No UV mapping env");
54
+ }
55
+ switch (env.type) {
56
+ case UVMapperType.Box:
57
+ return createUVBoxCoordinates(env, positions, bounds, normals);
58
+ case UVMapperType.Planar:
59
+ return createUVPlaneCoordinates(env, positions);
60
+ case UVMapperType.Cylindrical:
61
+ return createUVCylinderCoordinates(env, positions, bounds, normals);
62
+ case UVMapperType.Spherical:
63
+ throw logger.errorAsObject(`Unsupported UV-mapper: ${env.type} (Spherical)`);
64
+ default:
65
+ throw logger.errorAsObject("Unknown UV-mapper: " + env.type);
66
+ }
67
+ }
68
+ /**
69
+ * @param positions Stretched positions
70
+ * @param normals Used both for stretched and non-stretched. We cheat a bit by always using the same normals
71
+ * @param refPositions Non-stretched positions
72
+ * @param refUvs Non-stretched UV coordinates
73
+ * @returns
74
+ */
75
+ createUVCoordinatesForStretched(logger, positions, bounds, normals, refPositions, refBounds, refUvs) {
76
+ const env = this.env;
77
+ if (env === undefined) {
78
+ throw new Error("No mapping env");
79
+ }
80
+ switch (env.type) {
81
+ case UVMapperType.Box:
82
+ return createUVBoxCoordinatesForStretched(env, positions, bounds, normals, refPositions, refBounds, refUvs);
83
+ case UVMapperType.Planar:
84
+ return createUVPlaneCoordinatesForStretched(env, positions, refPositions);
85
+ case UVMapperType.Cylindrical:
86
+ return createUVCylinderCoordinatesForStretched(env, positions, bounds, normals, refPositions, refBounds, refUvs);
87
+ case UVMapperType.Spherical:
88
+ logger.warn("Spherical mapping is not implemented for stretch. Original UV-coordinates will be used.");
89
+ return refUvs;
90
+ default:
91
+ throw logger.errorAsObject("Unknown UV-mapper");
92
+ }
93
+ }
94
+ }
@@ -0,0 +1,5 @@
1
+ import { UVMapEnv } from "./UVMapEnv.js";
2
+ import { MinMaxSize } from "./UVMapper.js";
3
+ export declare function createUVBoxCoordinates(env: UVMapEnv | undefined, positions: Float32Array, bounds: MinMaxSize, normals: Float32Array): Float32Array;
4
+ export declare function createUVBoxCoordinatesForStretched(env: UVMapEnv | undefined, positions: Float32Array, bounds: MinMaxSize, normals: Float32Array, refPositions: Float32Array, refBounds: MinMaxSize, refUvs: Float32Array): Float32Array;
5
+ //# sourceMappingURL=UVMapperBox.d.ts.map
@@ -0,0 +1,181 @@
1
+ import { UVMapper } from "./UVMapper.js";
2
+ const XYZ = [0, 1, 2];
3
+ const X = 0, Y = 1, Z = 2;
4
+ const toSide = (axis, negAxis) => axis * 2 + (negAxis ? 1 : 0);
5
+ const toAxisAndIsNeg = (side) => [Math.trunc(side / 2), side % 2 === 1];
6
+ /**
7
+ * This simulates how CET maps xyz-coordinates to uv-coordinates. On certain axis the mapping is
8
+ * flipped, this is handled here.
9
+ */
10
+ function uvFromXyz(axis, negAxis, xyz) {
11
+ let u = axis === X ? xyz[1] : xyz[0];
12
+ let v = axis === Z ? xyz[1] : xyz[2];
13
+ if ((axis === X && negAxis) || (axis === Y && !negAxis)) {
14
+ u = 1 - u;
15
+ }
16
+ if (axis === Z && negAxis) {
17
+ v = 1 - v;
18
+ }
19
+ return [u, v];
20
+ }
21
+ /**
22
+ * The recommended method for calculating what side vertices belong to. It uses already calculated
23
+ * UVs to and as such is useful when doing stretch. If you do not do stretch you don't need to use
24
+ * this mapper at all. Just use the existing UVs.
25
+ */
26
+ function calculateSideMapFromRefUvs(transforms, normals, refPositions, refBounds, refUvs) {
27
+ const vertexCount = refPositions.length / 3;
28
+ const { min: refMin, size: refSize } = refBounds;
29
+ const sideMap = new Uint8Array(vertexCount);
30
+ for (let i = 0; i < vertexCount; i++) {
31
+ const xyzOffset = i * 3;
32
+ const uvOffset = i * 2;
33
+ // Texture is applied as if the image texture was stretched to fit each side of the "cube"
34
+ const refNormalized = XYZ.map((axis) => (refPositions[xyzOffset + axis] - refMin[axis]) / refSize[axis]);
35
+ const refU = refUvs[uvOffset];
36
+ const refV = refUvs[uvOffset + 1];
37
+ // We aim at finding what side of the cube this vertex shall be textured from.
38
+ // We do this by in turn testing what UV-values we would get for non-stretched
39
+ // data and selecting the one which is the closest.
40
+ let diffOnLatestCandidate = Number.POSITIVE_INFINITY;
41
+ let normalComponentAbsOnLatestCandidate = 0;
42
+ let selectedSide;
43
+ for (let axis = 0; axis < 3; axis++) {
44
+ const normalComponent = normals[xyzOffset + axis];
45
+ const normalComponentAbs = Math.abs(normalComponent);
46
+ const negAxis = normalComponent < 0;
47
+ let [u, v] = uvFromXyz(axis, negAxis, refNormalized);
48
+ if (transforms !== undefined) {
49
+ [u, v] = UVMapper.applyUvTransform([u, v], transforms[axis]);
50
+ }
51
+ // How far off are we from the reference UV-coordinates?
52
+ const diffOnCandidate = Math.abs(refU - u) + Math.abs(refV - v);
53
+ // Here we need a lite extra care. For highly regular shapes, such as a cube it is very
54
+ // likely we will end up in a situation where the "pick best UV-match" approach does
55
+ // not work. You can imagine this as the same "color" touching the same corner from
56
+ // more than one side. In this case we also need to take the normals into account.
57
+ //
58
+ // For highly irregular shapes it is more unlikely that the texture coordinates will be
59
+ // identical, and if they are the high polygon count on such a model is likely to mask
60
+ // the error.
61
+ //
62
+ // The factors below are a bit arbitrarily chosen. They might need to be tweaked.
63
+ if (diffOnLatestCandidate - diffOnCandidate > 0.01 ||
64
+ normalComponentAbs - normalComponentAbsOnLatestCandidate > 0.9) {
65
+ selectedSide = toSide(axis, negAxis);
66
+ diffOnLatestCandidate = diffOnCandidate;
67
+ normalComponentAbsOnLatestCandidate = normalComponentAbs;
68
+ }
69
+ }
70
+ if (selectedSide === undefined) {
71
+ throw new Error("Unexpected error when calculating UV side mapping");
72
+ }
73
+ sideMap[i] = selectedSide;
74
+ }
75
+ return sideMap;
76
+ }
77
+ /**
78
+ * Fallback method of calculating what side a vertex belongs to in cases where you have no refUvs.
79
+ * It will give bad results in the boundary areas where mapping from different sides meet.
80
+ *
81
+ * WARNING: Only use it if you have no refUvs.
82
+ */
83
+ function calculateSideMapFromNormals(normals) {
84
+ const vertexCount = normals.length / 3;
85
+ const sideMap = new Uint8Array(vertexCount);
86
+ for (let i = 0; i < vertexCount; i++) {
87
+ const xyzOffset = i * 3;
88
+ const normalX = normals[xyzOffset];
89
+ const normalY = normals[xyzOffset + 1];
90
+ const normalZ = normals[xyzOffset + 2];
91
+ if (Math.abs(normalY) < Math.abs(normalX) && Math.abs(normalZ) < Math.abs(normalX)) {
92
+ sideMap[i] = toSide(0, normalX < 0);
93
+ continue;
94
+ }
95
+ if (Math.abs(normalZ) < Math.abs(normalY)) {
96
+ sideMap[i] = toSide(1, normalY < 0);
97
+ continue;
98
+ }
99
+ sideMap[i] = toSide(2, normalZ < 0);
100
+ }
101
+ return sideMap;
102
+ }
103
+ export function createUVBoxCoordinates(env, positions, bounds, normals) {
104
+ if (normals.length !== positions.length) {
105
+ throw new Error("Normals are wrong count");
106
+ }
107
+ return createUV(env, positions, bounds, undefined, calculateSideMapFromNormals(normals));
108
+ }
109
+ export function createUVBoxCoordinatesForStretched(env, positions, bounds, normals, refPositions, refBounds, refUvs) {
110
+ const transforms = env === null || env === void 0 ? void 0 : env.transforms;
111
+ const xyzCount = positions.length;
112
+ const vertexCount = xyzCount / 3;
113
+ const uvCount = vertexCount * 2;
114
+ if (refPositions.length !== xyzCount) {
115
+ throw new Error(`Position count differs: ${refPositions.length} vs ${xyzCount}.`);
116
+ }
117
+ if (normals.length !== xyzCount) {
118
+ throw new Error(`Normal count differs: ${normals.length} vs ${xyzCount}.`);
119
+ }
120
+ if (refUvs.length !== uvCount) {
121
+ throw new Error(`UV count differs: ${uvCount} vs ${refUvs.length}.`);
122
+ }
123
+ return createUV(env, positions, bounds, refBounds, calculateSideMapFromRefUvs(transforms, normals, refPositions, refBounds, refUvs));
124
+ }
125
+ function createUV(env, positions, bounds, refBounds, sideMap) {
126
+ const transforms = env === null || env === void 0 ? void 0 : env.transforms;
127
+ const xyzCount = positions.length;
128
+ const vertexCount = xyzCount / 3;
129
+ const uvCount = vertexCount * 2;
130
+ const { refMin, refSize, textureFixMin, textureFixMax } = UVMapper.calculateLimits(bounds, refBounds);
131
+ // This is what this entire method aims at populating
132
+ const newUvs = new Float32Array(uvCount);
133
+ for (let i = 0; i < vertexCount; i++) {
134
+ const xyzOffset = i * 3;
135
+ const uvOffset = i * 2;
136
+ // We normalize using the ref-sizes as we want the texture to tile. Normalizing to the
137
+ // stretched positions would make it just stretch (and defeat the entire purpose)
138
+ const normalized = XYZ.map((axis) => (positions[xyzOffset + axis] - refMin[axis]) / refSize[axis]);
139
+ const [axis, isNegAxis] = toAxisAndIsNeg(sideMap[i]);
140
+ let [u, v] = uvFromXyz(axis, isNegAxis, normalized);
141
+ // CET uses different texture origins for different sides of the cube, which makes it look
142
+ // like the texture "moves with" the stretch direction on some sides and stays in place on
143
+ // some sides.
144
+ //
145
+ // The code below emulates the CET behavior even though it can be argued that it is neither
146
+ // expected nor "correct".
147
+ if (axis === 0) {
148
+ if (isNegAxis) {
149
+ u -= textureFixMax[1];
150
+ }
151
+ else {
152
+ u += textureFixMin[1];
153
+ }
154
+ v += textureFixMin[2];
155
+ }
156
+ else if (axis === 1) {
157
+ if (isNegAxis) {
158
+ u += textureFixMin[0];
159
+ }
160
+ else {
161
+ u -= textureFixMax[0];
162
+ }
163
+ v += textureFixMin[2];
164
+ }
165
+ else {
166
+ u += textureFixMin[0];
167
+ if (isNegAxis) {
168
+ v -= textureFixMax[1];
169
+ }
170
+ else {
171
+ v += textureFixMin[1];
172
+ }
173
+ }
174
+ if (transforms !== undefined) {
175
+ [u, v] = UVMapper.applyUvTransform([u, v], transforms[axis]);
176
+ }
177
+ newUvs[uvOffset] = u;
178
+ newUvs[uvOffset + 1] = v;
179
+ }
180
+ return newUvs;
181
+ }
@@ -0,0 +1,10 @@
1
+ import { UVMapEnv } from "./UVMapEnv.js";
2
+ import { MinMaxSize } from "./UVMapper.js";
3
+ /**
4
+ * This mapper gives bad results in the "seam" where the wrapped texture meet itself. If you have
5
+ * access to prebaked UVs then use those, and if you do stretch use the for stretched method with
6
+ * the prebaked UVS as a start point
7
+ */
8
+ export declare function createUVCylinderCoordinates(env: UVMapEnv | undefined, positions: Float32Array, bounds: MinMaxSize, normals: Float32Array): Float32Array;
9
+ export declare function createUVCylinderCoordinatesForStretched(env: UVMapEnv | undefined, positions: Float32Array, bounds: MinMaxSize, normals: Float32Array, refPositions: Float32Array, refBounds: MinMaxSize, refUvs: Float32Array): Float32Array;
10
+ //# sourceMappingURL=UVMapperCylinder.d.ts.map
@@ -0,0 +1,96 @@
1
+ import { UVMapper } from "./UVMapper.js";
2
+ /**
3
+ * This mapper gives bad results in the "seam" where the wrapped texture meet itself. If you have
4
+ * access to prebaked UVs then use those, and if you do stretch use the for stretched method with
5
+ * the prebaked UVS as a start point
6
+ */
7
+ export function createUVCylinderCoordinates(env, positions, bounds, normals) {
8
+ return createUV(env, positions, bounds, normals, undefined, undefined, undefined);
9
+ }
10
+ export function createUVCylinderCoordinatesForStretched(env, positions, bounds, normals, refPositions, refBounds, refUvs) {
11
+ return createUV(env, positions, bounds, normals, refPositions, refBounds, refUvs);
12
+ }
13
+ function createUV(env, positions, bounds, normals, refPositions, refBounds, refUvs) {
14
+ const refPositionsFallbackToPositions = refPositions || positions;
15
+ const transforms = env === null || env === void 0 ? void 0 : env.transforms;
16
+ const transformSide = transforms === null || transforms === void 0 ? void 0 : transforms[0];
17
+ const transformTopBottom = transforms === null || transforms === void 0 ? void 0 : transforms[1];
18
+ const xyzCount = positions.length;
19
+ const vertexCount = xyzCount / 3;
20
+ if (refPositions !== undefined && refPositions.length !== xyzCount) {
21
+ throw new Error(`Position count differs: ${refPositions.length} vs ${xyzCount}.`);
22
+ }
23
+ if (normals.length !== xyzCount) {
24
+ throw new Error(`Normal count differs: ${normals.length} vs ${xyzCount}.`);
25
+ }
26
+ const { refMin, refSize, textureFixMin, textureFixMax } = UVMapper.calculateLimits(bounds, refBounds);
27
+ // This is what this entire method aims at populating
28
+ const newUvs = new Float32Array(vertexCount * 2);
29
+ for (let i = 0; i < vertexCount; i++) {
30
+ const xyzOffset = i * 3;
31
+ const uvOffset = i * 2;
32
+ if (normals[xyzOffset] === 0 &&
33
+ normals[xyzOffset + 1] === 0 &&
34
+ normals[xyzOffset + 2] !== 0) {
35
+ // This is Top / Bottom
36
+ let u = (positions[xyzOffset] - refMin[0]) / refSize[0];
37
+ let v = (positions[xyzOffset + 1] - refMin[1]) / refSize[1];
38
+ const isNegAxis = normals[xyzOffset + 2] < 0;
39
+ if (isNegAxis) {
40
+ // Weird irregularity in how mapping is done in CET
41
+ v -= 1;
42
+ }
43
+ if (refPositions !== undefined) {
44
+ u += textureFixMin[0];
45
+ if (isNegAxis) {
46
+ v += textureFixMax[1];
47
+ }
48
+ else {
49
+ v += textureFixMin[1];
50
+ }
51
+ }
52
+ if (transformTopBottom !== undefined) {
53
+ [u, v] = UVMapper.applyUvTransform([u, v], transformTopBottom);
54
+ }
55
+ newUvs[uvOffset] = u;
56
+ newUvs[uvOffset + 1] = v;
57
+ }
58
+ else {
59
+ // This is a Side
60
+ // It is very, very hard to make a full proper cylindrical stretching UV-mapper.
61
+ // For the seam to look sensible there has to be double (split) vertices. Model Lab does
62
+ // this for us when saving a CmSym file. However, this seam will move as we stretch,
63
+ // and there are no guarantees that it will be straight.
64
+ // As a compromise we stretch the top and bottom and height, but not the curved side.
65
+ // This should give good results for table tops, where the edge is often narrow and not
66
+ // very detailed, and for table legs (where the radius is fairly constant).
67
+ let u = Math.atan2(refPositionsFallbackToPositions[xyzOffset + 1], refPositionsFallbackToPositions[xyzOffset]) /
68
+ (Math.PI * 2) +
69
+ 0.5;
70
+ let refUTest = u;
71
+ let v = (positions[xyzOffset + 2] - refMin[2]) / refSize[2];
72
+ // CET fixes texture to same corner when stretching. This code makes this work
73
+ if (refPositions !== undefined) {
74
+ v += textureFixMin[2];
75
+ }
76
+ if (transformSide !== undefined) {
77
+ [u, v] = UVMapper.applyUvTransform([u, v], transformSide);
78
+ }
79
+ if (refUvs !== undefined && refPositions !== undefined) {
80
+ // We need to find vertices that are at the seam. The seam where nodes are double
81
+ // so that texture mapping can be sharp. By compensating the difference between our
82
+ // equations and what Model Lab has calculated we can adjust our stretched
83
+ // coordinates.
84
+ let refVTest = (refPositions[xyzOffset + 2] - refMin[2]) / refSize[2];
85
+ if (transformSide !== undefined) {
86
+ [refUTest, refVTest] = UVMapper.applyUvTransform([refUTest, refVTest], transformSide);
87
+ }
88
+ u -= refUTest - refUvs[uvOffset];
89
+ v -= refVTest - refUvs[uvOffset + 1];
90
+ }
91
+ newUvs[uvOffset] = u;
92
+ newUvs[uvOffset + 1] = v;
93
+ }
94
+ }
95
+ return newUvs;
96
+ }
@@ -0,0 +1,4 @@
1
+ import { UVMapEnv } from "./UVMapEnv.js";
2
+ export declare function createUVPlaneCoordinates(env: UVMapEnv | undefined, positions: Float32Array): Float32Array;
3
+ export declare function createUVPlaneCoordinatesForStretched(env: UVMapEnv | undefined, positions: Float32Array, refPositions: Float32Array): Float32Array;
4
+ //# sourceMappingURL=UVMapperPlane.d.ts.map