@configura/web-core 2.1.0-alpha.2 → 2.1.0-alpha.3

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 (173) hide show
  1. package/.eslintrc.json +5 -5
  2. package/LICENSE +201 -201
  3. package/README.md +1 -1
  4. package/dist/cm/basic/Color.d.ts +16 -16
  5. package/dist/cm/basic/Color.js +18 -18
  6. package/dist/cm/basic/ColorF.d.ts +9 -9
  7. package/dist/cm/basic/ColorF.js +10 -10
  8. package/dist/cm/basic/boolean.d.ts +2 -2
  9. package/dist/cm/basic/boolean.js +11 -11
  10. package/dist/cm/basic/number.d.ts +3 -3
  11. package/dist/cm/basic/number.js +18 -18
  12. package/dist/cm/basic/string.d.ts +2 -2
  13. package/dist/cm/basic/string.js +11 -11
  14. package/dist/cm/core3D/ATriMeshF.d.ts +96 -96
  15. package/dist/cm/core3D/ATriMeshF.js +197 -197
  16. package/dist/cm/core3D/GMaterial3D.d.ts +62 -62
  17. package/dist/cm/core3D/GMaterial3D.js +112 -112
  18. package/dist/cm/core3D/GMaterialClassic.d.ts +55 -55
  19. package/dist/cm/core3D/GMaterialClassic.js +171 -171
  20. package/dist/cm/core3D/GMaterialPBR.d.ts +73 -73
  21. package/dist/cm/core3D/GMaterialPBR.js +314 -314
  22. package/dist/cm/core3D/MultiGMaterial3D.d.ts +8 -8
  23. package/dist/cm/core3D/MultiGMaterial3D.js +17 -17
  24. package/dist/cm/core3D/uvmapper/UVMapEnv.d.ts +19 -19
  25. package/dist/cm/core3D/uvmapper/UVMapEnv.js +47 -47
  26. package/dist/cm/core3D/uvmapper/UVMapper.d.ts +41 -41
  27. package/dist/cm/core3D/uvmapper/UVMapper.js +94 -94
  28. package/dist/cm/core3D/uvmapper/UVMapperBox.d.ts +4 -4
  29. package/dist/cm/core3D/uvmapper/UVMapperBox.js +181 -181
  30. package/dist/cm/core3D/uvmapper/UVMapperCylinder.d.ts +9 -9
  31. package/dist/cm/core3D/uvmapper/UVMapperCylinder.js +96 -96
  32. package/dist/cm/core3D/uvmapper/UVMapperPlane.d.ts +3 -3
  33. package/dist/cm/core3D/uvmapper/UVMapperPlane.js +84 -84
  34. package/dist/cm/core3D/uvmapper/UVTransformer.d.ts +5 -5
  35. package/dist/cm/core3D/uvmapper/UVTransformer.js +5 -5
  36. package/dist/cm/core3D/uvmapper/instantiateUVMapper.d.ts +3 -3
  37. package/dist/cm/core3D/uvmapper/instantiateUVMapper.js +4 -4
  38. package/dist/cm/format/cmsym/InvalidationEnv.d.ts +9 -9
  39. package/dist/cm/format/cmsym/InvalidationEnv.js +13 -13
  40. package/dist/cm/format/cmsym/SymImportEnv.d.ts +9 -9
  41. package/dist/cm/format/cmsym/SymImportEnv.js +9 -9
  42. package/dist/cm/format/cmsym/SymInv.d.ts +8 -8
  43. package/dist/cm/format/cmsym/SymInv.js +17 -17
  44. package/dist/cm/format/cmsym/SymNode.d.ts +94 -94
  45. package/dist/cm/format/cmsym/SymNode.js +652 -652
  46. package/dist/cm/format/cmsym/components/SymBox.d.ts +15 -15
  47. package/dist/cm/format/cmsym/components/SymBox.js +39 -39
  48. package/dist/cm/format/cmsym/components/SymComponent.d.ts +29 -29
  49. package/dist/cm/format/cmsym/components/SymComponent.js +56 -56
  50. package/dist/cm/format/cmsym/components/SymConnector.d.ts +5 -5
  51. package/dist/cm/format/cmsym/components/SymConnector.js +10 -10
  52. package/dist/cm/format/cmsym/components/SymDexObj.d.ts +11 -11
  53. package/dist/cm/format/cmsym/components/SymDexObj.js +10 -10
  54. package/dist/cm/format/cmsym/components/SymGFX.d.ts +11 -11
  55. package/dist/cm/format/cmsym/components/SymGFX.js +20 -20
  56. package/dist/cm/format/cmsym/components/SymGMaterial.d.ts +19 -19
  57. package/dist/cm/format/cmsym/components/SymGMaterial.js +88 -88
  58. package/dist/cm/format/cmsym/components/SymGMaterialSelector.d.ts +17 -17
  59. package/dist/cm/format/cmsym/components/SymGMaterialSelector.js +22 -22
  60. package/dist/cm/format/cmsym/components/SymGetMeshEnv.d.ts +9 -9
  61. package/dist/cm/format/cmsym/components/SymGetMeshEnv.js +9 -9
  62. package/dist/cm/format/cmsym/components/SymLODGroup.d.ts +9 -9
  63. package/dist/cm/format/cmsym/components/SymLODGroup.js +13 -13
  64. package/dist/cm/format/cmsym/components/SymLight.d.ts +8 -8
  65. package/dist/cm/format/cmsym/components/SymLight.js +10 -10
  66. package/dist/cm/format/cmsym/components/SymLines2D.d.ts +5 -5
  67. package/dist/cm/format/cmsym/components/SymLines2D.js +7 -7
  68. package/dist/cm/format/cmsym/components/SymMeasure.d.ts +33 -33
  69. package/dist/cm/format/cmsym/components/SymMeasure.js +149 -149
  70. package/dist/cm/format/cmsym/components/SymMesh.d.ts +29 -29
  71. package/dist/cm/format/cmsym/components/SymMesh.js +130 -130
  72. package/dist/cm/format/cmsym/components/SymMeshLight.d.ts +8 -8
  73. package/dist/cm/format/cmsym/components/SymMeshLight.js +10 -10
  74. package/dist/cm/format/cmsym/components/SymMultiSelector.d.ts +13 -13
  75. package/dist/cm/format/cmsym/components/SymMultiSelector.js +48 -48
  76. package/dist/cm/format/cmsym/components/SymParams.d.ts +16 -16
  77. package/dist/cm/format/cmsym/components/SymParams.js +58 -58
  78. package/dist/cm/format/cmsym/components/SymPlane.d.ts +15 -15
  79. package/dist/cm/format/cmsym/components/SymPlane.js +30 -30
  80. package/dist/cm/format/cmsym/components/SymPlaneDivider.d.ts +4 -4
  81. package/dist/cm/format/cmsym/components/SymPlaneDivider.js +7 -7
  82. package/dist/cm/format/cmsym/components/SymPrimitive2D.d.ts +3 -3
  83. package/dist/cm/format/cmsym/components/SymPrimitive2D.js +3 -3
  84. package/dist/cm/format/cmsym/components/SymProgs.d.ts +32 -32
  85. package/dist/cm/format/cmsym/components/SymProgs.js +120 -120
  86. package/dist/cm/format/cmsym/components/SymProps.d.ts +54 -54
  87. package/dist/cm/format/cmsym/components/SymProps.js +171 -171
  88. package/dist/cm/format/cmsym/components/SymRep.d.ts +13 -13
  89. package/dist/cm/format/cmsym/components/SymRep.js +28 -28
  90. package/dist/cm/format/cmsym/components/SymReps.d.ts +36 -36
  91. package/dist/cm/format/cmsym/components/SymReps.js +230 -230
  92. package/dist/cm/format/cmsym/components/SymShape.d.ts +10 -10
  93. package/dist/cm/format/cmsym/components/SymShape.js +17 -17
  94. package/dist/cm/format/cmsym/components/SymSphere.d.ts +18 -18
  95. package/dist/cm/format/cmsym/components/SymSphere.js +33 -33
  96. package/dist/cm/format/cmsym/components/SymSpotlight.d.ts +8 -8
  97. package/dist/cm/format/cmsym/components/SymSpotlight.js +10 -10
  98. package/dist/cm/format/cmsym/components/SymTags.d.ts +11 -11
  99. package/dist/cm/format/cmsym/components/SymTags.js +20 -20
  100. package/dist/cm/format/cmsym/components/SymText2D.d.ts +5 -5
  101. package/dist/cm/format/cmsym/components/SymText2D.js +8 -8
  102. package/dist/cm/format/cmsym/components/SymText3D.d.ts +5 -5
  103. package/dist/cm/format/cmsym/components/SymText3D.js +8 -8
  104. package/dist/cm/format/cmsym/components/SymTransform.d.ts +23 -23
  105. package/dist/cm/format/cmsym/components/SymTransform.js +101 -101
  106. package/dist/cm/format/cmsym/components/SymUVMapper.d.ts +13 -13
  107. package/dist/cm/format/cmsym/components/SymUVMapper.js +50 -50
  108. package/dist/cm/format/cmsym/components/instantiate.d.ts +2 -2
  109. package/dist/cm/format/cmsym/components/instantiate.js +121 -121
  110. package/dist/cm/format/cmsym/components/legacy.d.ts +7 -7
  111. package/dist/cm/format/cmsym/components/legacy.js +27 -27
  112. package/dist/cm/format/cmsym/components/mesh.d.ts +8 -8
  113. package/dist/cm/format/cmsym/components/mesh.js +28 -28
  114. package/dist/cm/format/cmsym/invalidation.d.ts +4 -4
  115. package/dist/cm/format/cmsym/invalidation.js +72 -72
  116. package/dist/cm/format/dex/DexIRef.d.ts +9 -9
  117. package/dist/cm/format/dex/DexIRef.js +18 -18
  118. package/dist/cm/format/dex/DexInt.d.ts +11 -11
  119. package/dist/cm/format/dex/DexInt.js +18 -18
  120. package/dist/cm/format/dex/DexInternalizedXRef.d.ts +19 -19
  121. package/dist/cm/format/dex/DexInternalizedXRef.js +65 -65
  122. package/dist/cm/format/dex/DexLoader.d.ts +8 -8
  123. package/dist/cm/format/dex/DexLoader.js +12 -12
  124. package/dist/cm/format/dex/DexManager.d.ts +20 -20
  125. package/dist/cm/format/dex/DexManager.js +78 -78
  126. package/dist/cm/format/dex/DexObj.d.ts +15 -15
  127. package/dist/cm/format/dex/DexObj.js +86 -86
  128. package/dist/cm/format/dex/DexReader.d.ts +90 -90
  129. package/dist/cm/format/dex/DexReader.js +532 -532
  130. package/dist/cm/format/dex/DexRef.d.ts +6 -6
  131. package/dist/cm/format/dex/DexRef.js +8 -8
  132. package/dist/cm/format/dex/DexReplacedXRefs.d.ts +9 -9
  133. package/dist/cm/format/dex/DexReplacedXRefs.js +22 -22
  134. package/dist/cm/format/dex/DexURL.d.ts +4 -4
  135. package/dist/cm/format/dex/DexURL.js +5 -5
  136. package/dist/cm/format/dex/DexVersion.d.ts +15 -15
  137. package/dist/cm/format/dex/DexVersion.js +53 -53
  138. package/dist/cm/format/dex/DexXRef.d.ts +18 -18
  139. package/dist/cm/format/dex/DexXRef.js +51 -51
  140. package/dist/cm/format/dex/DexXRefTargetFilter.d.ts +4 -4
  141. package/dist/cm/format/dex/DexXRefTargetFilter.js +5 -5
  142. package/dist/cm/geometry/Angle.d.ts +9 -9
  143. package/dist/cm/geometry/Angle.js +18 -18
  144. package/dist/cm/geometry/AngleF.d.ts +5 -5
  145. package/dist/cm/geometry/AngleF.js +8 -8
  146. package/dist/cm/geometry/Box.d.ts +7 -7
  147. package/dist/cm/geometry/Box.js +9 -9
  148. package/dist/cm/geometry/DetailMask.d.ts +37 -37
  149. package/dist/cm/geometry/DetailMask.js +114 -114
  150. package/dist/cm/geometry/LayerExpr.d.ts +2 -2
  151. package/dist/cm/geometry/LayerExpr.js +2 -2
  152. package/dist/cm/geometry/Matrix22.d.ts +7 -7
  153. package/dist/cm/geometry/Matrix22.js +9 -9
  154. package/dist/cm/geometry/Matrix33.d.ts +42 -42
  155. package/dist/cm/geometry/Matrix33.js +124 -124
  156. package/dist/cm/geometry/Orientation.d.ts +7 -7
  157. package/dist/cm/geometry/Orientation.js +7 -7
  158. package/dist/cm/geometry/Plane.d.ts +8 -8
  159. package/dist/cm/geometry/Plane.js +14 -14
  160. package/dist/cm/geometry/Point.d.ts +21 -21
  161. package/dist/cm/geometry/Point.js +65 -65
  162. package/dist/cm/geometry/Point2D.d.ts +9 -9
  163. package/dist/cm/geometry/Point2D.js +23 -23
  164. package/dist/cm/geometry/PointF.d.ts +11 -11
  165. package/dist/cm/geometry/PointF.js +27 -27
  166. package/dist/cm/geometry/Transform.d.ts +11 -11
  167. package/dist/cm/geometry/Transform.js +61 -61
  168. package/dist/cm/geometry/Transform2D.d.ts +7 -7
  169. package/dist/cm/geometry/Transform2D.js +6 -6
  170. package/dist/cm/io/Semver.d.ts +18 -18
  171. package/dist/cm/io/Semver.js +61 -61
  172. package/dist/index.js +1 -1
  173. package/package.json +4 -4
@@ -1,181 +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
- }
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
+ }
@@ -1,10 +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;
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
10
  //# sourceMappingURL=UVMapperCylinder.d.ts.map
@@ -1,96 +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
- }
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
+ }
@@ -1,4 +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;
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
4
  //# sourceMappingURL=UVMapperPlane.d.ts.map