@configura/web-core 2.0.0 → 2.1.0-alpha.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.
- package/.eslintrc.json +5 -5
- package/LICENSE +201 -201
- package/README.md +1 -1
- package/dist/cm/basic/Color.d.ts +16 -16
- package/dist/cm/basic/Color.js +18 -18
- package/dist/cm/basic/ColorF.d.ts +9 -9
- package/dist/cm/basic/ColorF.js +10 -10
- package/dist/cm/basic/boolean.d.ts +2 -2
- package/dist/cm/basic/boolean.js +11 -11
- package/dist/cm/basic/number.d.ts +3 -3
- package/dist/cm/basic/number.js +18 -18
- package/dist/cm/basic/string.d.ts +2 -2
- package/dist/cm/basic/string.js +11 -11
- package/dist/cm/core3D/ATriMeshF.d.ts +96 -96
- package/dist/cm/core3D/ATriMeshF.js +197 -197
- package/dist/cm/core3D/GMaterial3D.d.ts +62 -62
- package/dist/cm/core3D/GMaterial3D.js +112 -112
- package/dist/cm/core3D/GMaterialClassic.d.ts +55 -55
- package/dist/cm/core3D/GMaterialClassic.js +171 -171
- package/dist/cm/core3D/GMaterialPBR.d.ts +73 -73
- package/dist/cm/core3D/GMaterialPBR.js +314 -314
- package/dist/cm/core3D/MultiGMaterial3D.d.ts +8 -8
- package/dist/cm/core3D/MultiGMaterial3D.js +17 -17
- package/dist/cm/core3D/uvmapper/UVMapEnv.d.ts +19 -19
- package/dist/cm/core3D/uvmapper/UVMapEnv.js +47 -47
- package/dist/cm/core3D/uvmapper/UVMapper.d.ts +41 -41
- package/dist/cm/core3D/uvmapper/UVMapper.js +94 -94
- package/dist/cm/core3D/uvmapper/UVMapperBox.d.ts +4 -4
- package/dist/cm/core3D/uvmapper/UVMapperBox.js +181 -181
- package/dist/cm/core3D/uvmapper/UVMapperCylinder.d.ts +9 -9
- package/dist/cm/core3D/uvmapper/UVMapperCylinder.js +96 -96
- package/dist/cm/core3D/uvmapper/UVMapperPlane.d.ts +3 -3
- package/dist/cm/core3D/uvmapper/UVMapperPlane.js +84 -84
- package/dist/cm/core3D/uvmapper/UVTransformer.d.ts +5 -5
- package/dist/cm/core3D/uvmapper/UVTransformer.js +5 -5
- package/dist/cm/core3D/uvmapper/instantiateUVMapper.d.ts +3 -3
- package/dist/cm/core3D/uvmapper/instantiateUVMapper.js +4 -4
- package/dist/cm/format/cmsym/InvalidationEnv.d.ts +9 -9
- package/dist/cm/format/cmsym/InvalidationEnv.js +13 -13
- package/dist/cm/format/cmsym/SymImportEnv.d.ts +9 -9
- package/dist/cm/format/cmsym/SymImportEnv.js +9 -9
- package/dist/cm/format/cmsym/SymInv.d.ts +8 -8
- package/dist/cm/format/cmsym/SymInv.js +17 -17
- package/dist/cm/format/cmsym/SymNode.d.ts +94 -94
- package/dist/cm/format/cmsym/SymNode.js +652 -652
- package/dist/cm/format/cmsym/components/SymBox.d.ts +15 -15
- package/dist/cm/format/cmsym/components/SymBox.js +39 -39
- package/dist/cm/format/cmsym/components/SymComponent.d.ts +29 -29
- package/dist/cm/format/cmsym/components/SymComponent.js +56 -56
- package/dist/cm/format/cmsym/components/SymConnector.d.ts +5 -5
- package/dist/cm/format/cmsym/components/SymConnector.js +10 -10
- package/dist/cm/format/cmsym/components/SymDexObj.d.ts +11 -11
- package/dist/cm/format/cmsym/components/SymDexObj.js +10 -10
- package/dist/cm/format/cmsym/components/SymGFX.d.ts +11 -11
- package/dist/cm/format/cmsym/components/SymGFX.js +20 -20
- package/dist/cm/format/cmsym/components/SymGMaterial.d.ts +19 -19
- package/dist/cm/format/cmsym/components/SymGMaterial.js +88 -88
- package/dist/cm/format/cmsym/components/SymGMaterialSelector.d.ts +17 -17
- package/dist/cm/format/cmsym/components/SymGMaterialSelector.js +22 -22
- package/dist/cm/format/cmsym/components/SymGetMeshEnv.d.ts +9 -9
- package/dist/cm/format/cmsym/components/SymGetMeshEnv.js +9 -9
- package/dist/cm/format/cmsym/components/SymLODGroup.d.ts +9 -9
- package/dist/cm/format/cmsym/components/SymLODGroup.js +13 -13
- package/dist/cm/format/cmsym/components/SymLight.d.ts +8 -8
- package/dist/cm/format/cmsym/components/SymLight.js +10 -10
- package/dist/cm/format/cmsym/components/SymLines2D.d.ts +5 -5
- package/dist/cm/format/cmsym/components/SymLines2D.js +7 -7
- package/dist/cm/format/cmsym/components/SymMeasure.d.ts +33 -33
- package/dist/cm/format/cmsym/components/SymMeasure.js +149 -149
- package/dist/cm/format/cmsym/components/SymMesh.d.ts +29 -29
- package/dist/cm/format/cmsym/components/SymMesh.js +130 -130
- package/dist/cm/format/cmsym/components/SymMeshLight.d.ts +8 -8
- package/dist/cm/format/cmsym/components/SymMeshLight.js +10 -10
- package/dist/cm/format/cmsym/components/SymMultiSelector.d.ts +13 -13
- package/dist/cm/format/cmsym/components/SymMultiSelector.js +48 -48
- package/dist/cm/format/cmsym/components/SymParams.d.ts +16 -16
- package/dist/cm/format/cmsym/components/SymParams.js +58 -58
- package/dist/cm/format/cmsym/components/SymPlane.d.ts +15 -15
- package/dist/cm/format/cmsym/components/SymPlane.js +30 -30
- package/dist/cm/format/cmsym/components/SymPlaneDivider.d.ts +4 -4
- package/dist/cm/format/cmsym/components/SymPlaneDivider.js +7 -7
- package/dist/cm/format/cmsym/components/SymPrimitive2D.d.ts +3 -3
- package/dist/cm/format/cmsym/components/SymPrimitive2D.js +3 -3
- package/dist/cm/format/cmsym/components/SymProgs.d.ts +32 -32
- package/dist/cm/format/cmsym/components/SymProgs.js +120 -120
- package/dist/cm/format/cmsym/components/SymProps.d.ts +54 -54
- package/dist/cm/format/cmsym/components/SymProps.js +171 -171
- package/dist/cm/format/cmsym/components/SymRep.d.ts +13 -13
- package/dist/cm/format/cmsym/components/SymRep.js +28 -28
- package/dist/cm/format/cmsym/components/SymReps.d.ts +36 -36
- package/dist/cm/format/cmsym/components/SymReps.js +230 -230
- package/dist/cm/format/cmsym/components/SymShape.d.ts +10 -10
- package/dist/cm/format/cmsym/components/SymShape.js +17 -17
- package/dist/cm/format/cmsym/components/SymSphere.d.ts +18 -18
- package/dist/cm/format/cmsym/components/SymSphere.js +33 -33
- package/dist/cm/format/cmsym/components/SymSpotlight.d.ts +8 -8
- package/dist/cm/format/cmsym/components/SymSpotlight.js +10 -10
- package/dist/cm/format/cmsym/components/SymTags.d.ts +11 -11
- package/dist/cm/format/cmsym/components/SymTags.js +20 -20
- package/dist/cm/format/cmsym/components/SymText2D.d.ts +5 -5
- package/dist/cm/format/cmsym/components/SymText2D.js +8 -8
- package/dist/cm/format/cmsym/components/SymText3D.d.ts +5 -5
- package/dist/cm/format/cmsym/components/SymText3D.js +8 -8
- package/dist/cm/format/cmsym/components/SymTransform.d.ts +23 -23
- package/dist/cm/format/cmsym/components/SymTransform.js +101 -101
- package/dist/cm/format/cmsym/components/SymUVMapper.d.ts +13 -13
- package/dist/cm/format/cmsym/components/SymUVMapper.js +50 -50
- package/dist/cm/format/cmsym/components/instantiate.d.ts +2 -2
- package/dist/cm/format/cmsym/components/instantiate.js +121 -121
- package/dist/cm/format/cmsym/components/legacy.d.ts +7 -7
- package/dist/cm/format/cmsym/components/legacy.js +27 -27
- package/dist/cm/format/cmsym/components/mesh.d.ts +8 -8
- package/dist/cm/format/cmsym/components/mesh.js +28 -28
- package/dist/cm/format/cmsym/invalidation.d.ts +4 -4
- package/dist/cm/format/cmsym/invalidation.js +72 -72
- package/dist/cm/format/dex/DexIRef.d.ts +9 -9
- package/dist/cm/format/dex/DexIRef.js +18 -18
- package/dist/cm/format/dex/DexInt.d.ts +11 -11
- package/dist/cm/format/dex/DexInt.js +18 -18
- package/dist/cm/format/dex/DexInternalizedXRef.d.ts +19 -19
- package/dist/cm/format/dex/DexInternalizedXRef.js +65 -65
- package/dist/cm/format/dex/DexLoader.d.ts +8 -8
- package/dist/cm/format/dex/DexLoader.js +12 -12
- package/dist/cm/format/dex/DexManager.d.ts +20 -20
- package/dist/cm/format/dex/DexManager.js +78 -78
- package/dist/cm/format/dex/DexObj.d.ts +15 -15
- package/dist/cm/format/dex/DexObj.js +86 -86
- package/dist/cm/format/dex/DexReader.d.ts +90 -90
- package/dist/cm/format/dex/DexReader.js +532 -532
- package/dist/cm/format/dex/DexRef.d.ts +6 -6
- package/dist/cm/format/dex/DexRef.js +8 -8
- package/dist/cm/format/dex/DexReplacedXRefs.d.ts +9 -9
- package/dist/cm/format/dex/DexReplacedXRefs.js +22 -22
- package/dist/cm/format/dex/DexURL.d.ts +4 -4
- package/dist/cm/format/dex/DexURL.js +5 -5
- package/dist/cm/format/dex/DexVersion.d.ts +15 -15
- package/dist/cm/format/dex/DexVersion.js +53 -53
- package/dist/cm/format/dex/DexXRef.d.ts +18 -18
- package/dist/cm/format/dex/DexXRef.js +51 -51
- package/dist/cm/format/dex/DexXRefTargetFilter.d.ts +4 -4
- package/dist/cm/format/dex/DexXRefTargetFilter.js +5 -5
- package/dist/cm/geometry/Angle.d.ts +9 -9
- package/dist/cm/geometry/Angle.js +18 -18
- package/dist/cm/geometry/AngleF.d.ts +5 -5
- package/dist/cm/geometry/AngleF.js +8 -8
- package/dist/cm/geometry/Box.d.ts +7 -7
- package/dist/cm/geometry/Box.js +9 -9
- package/dist/cm/geometry/DetailMask.d.ts +37 -37
- package/dist/cm/geometry/DetailMask.js +114 -114
- package/dist/cm/geometry/LayerExpr.d.ts +2 -2
- package/dist/cm/geometry/LayerExpr.js +2 -2
- package/dist/cm/geometry/Matrix22.d.ts +7 -7
- package/dist/cm/geometry/Matrix22.js +9 -9
- package/dist/cm/geometry/Matrix33.d.ts +42 -42
- package/dist/cm/geometry/Matrix33.js +124 -124
- package/dist/cm/geometry/Orientation.d.ts +7 -7
- package/dist/cm/geometry/Orientation.js +7 -7
- package/dist/cm/geometry/Plane.d.ts +8 -8
- package/dist/cm/geometry/Plane.js +14 -14
- package/dist/cm/geometry/Point.d.ts +21 -21
- package/dist/cm/geometry/Point.js +65 -65
- package/dist/cm/geometry/Point2D.d.ts +9 -9
- package/dist/cm/geometry/Point2D.js +23 -23
- package/dist/cm/geometry/PointF.d.ts +11 -11
- package/dist/cm/geometry/PointF.js +27 -27
- package/dist/cm/geometry/Transform.d.ts +11 -11
- package/dist/cm/geometry/Transform.js +61 -61
- package/dist/cm/geometry/Transform2D.d.ts +7 -7
- package/dist/cm/geometry/Transform2D.js +6 -6
- package/dist/cm/io/Semver.d.ts +18 -18
- package/dist/cm/io/Semver.js +61 -61
- package/dist/index.js +1 -1
- package/package.json +4 -4
|
@@ -1,97 +1,97 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* "Advanced Triangle Mesh Float", a mesh normally from CmSym components and later used to
|
|
3
|
-
* instantiate geometry for the 3D engine.
|
|
4
|
-
*
|
|
5
|
-
* @remarks
|
|
6
|
-
* The class can be created by supplying OpenCTM encoded mesh data in the constructor, which will
|
|
7
|
-
* be loaded, decoded and stores in the member variables when load() is called. Alternatively, you
|
|
8
|
-
* can supply a set of typed arrays directly via the createWithArrays(...) factory method.
|
|
9
|
-
*
|
|
10
|
-
* Specification: {@link https://www.configura.com/cmsym/#SymMesh CmSym - SymMesh}
|
|
11
|
-
*/
|
|
12
|
-
export declare class ATriMeshF {
|
|
13
|
-
private _indices;
|
|
14
|
-
private _vertices;
|
|
15
|
-
private _normals;
|
|
16
|
-
private _uvs;
|
|
17
|
-
private _colors;
|
|
18
|
-
private _tangents;
|
|
19
|
-
private data?;
|
|
20
|
-
loaded: boolean;
|
|
21
|
-
/**
|
|
22
|
-
* True means that texture applied to this mesh should NOT be flipped vertically.
|
|
23
|
-
*
|
|
24
|
-
* It is expected that modern models sets this to "true", so we optimize for that case.
|
|
25
|
-
* An undefined value in the CmSym means "false".
|
|
26
|
-
*
|
|
27
|
-
* @remarks
|
|
28
|
-
* From the CmSym specification:
|
|
29
|
-
* If lowerLeftTextureOrigin is true it means that uv=(0, 0) will refer to the lower left
|
|
30
|
-
* corner of the texture.
|
|
31
|
-
* If lowerLeftTextureOrigin is false it mean that uv=(0, 0) will refer to the upper left
|
|
32
|
-
* corner of the texture.
|
|
33
|
-
*
|
|
34
|
-
* The specification states that "material can override this" but no such way exists in the
|
|
35
|
-
* spec it self. After checking with CET developers it turns out that the specification is
|
|
36
|
-
* incorrect; the material can not override this flag.
|
|
37
|
-
*/
|
|
38
|
-
readonly lowerLeftTextureOrigin: boolean;
|
|
39
|
-
/**
|
|
40
|
-
* True if this mesh is double sided.
|
|
41
|
-
* Default value in CmSym is false.
|
|
42
|
-
*
|
|
43
|
-
* Note: This flag is to be considered readonly. It isn't due to SymMesh.js
|
|
44
|
-
* currently applying an SymGetMeshEnv after this class has been created.
|
|
45
|
-
*
|
|
46
|
-
* @remarks
|
|
47
|
-
* From the specification:
|
|
48
|
-
* Defines the double sidedness of the mesh.
|
|
49
|
-
* Material can override this.
|
|
50
|
-
*/
|
|
51
|
-
doubleSided: boolean;
|
|
52
|
-
constructor(data: Uint8Array | undefined, lowerLeftTextureOrigin: boolean, doubleSided: boolean);
|
|
53
|
-
/** Creates and returns a new ATriMeshF with the mesh data supplied. */
|
|
54
|
-
static createWithArrays(indices: Uint32Array, vertices: Float32Array, normals?: Float32Array, uvs?: Float32Array, colors?: Float32Array, tangents?: Float32Array): ATriMeshF;
|
|
55
|
-
get indices(): Uint32Array;
|
|
56
|
-
get vertices(): Float32Array;
|
|
57
|
-
get normals(): Float32Array;
|
|
58
|
-
get uvs(): Float32Array;
|
|
59
|
-
get colors(): Float32Array;
|
|
60
|
-
/**
|
|
61
|
-
* Tangents and bi-tangents are normally calculated in the shaders for effects like normal
|
|
62
|
-
* mapping. However, those calculations rely on "uv gradients" which is not well defined if
|
|
63
|
-
* all vertices in a face (triangle) has the same UV coordinates, making the light calculations
|
|
64
|
-
* fail in those cases, visually showing up much darker or even black in the render.
|
|
65
|
-
*
|
|
66
|
-
* The load code will detect the most probable edge case of this type, the only one encountered
|
|
67
|
-
* so far, which is when all U and V coordinates are constant with respect to each group. In
|
|
68
|
-
* such cases, it will automatically calculate a set of tangents corresponding to the normals,
|
|
69
|
-
* if any. These tangents then need to be supplied to the 3D rendering engine.
|
|
70
|
-
*
|
|
71
|
-
* Additional information on the subject can be found here:
|
|
72
|
-
* https://forum.babylonjs.com/t/odd-uv-coordinates-edge-cases/14729/4
|
|
73
|
-
*/
|
|
74
|
-
get tangents(): Float32Array;
|
|
75
|
-
/**
|
|
76
|
-
* Loads the actually geometry from the data array, unless it has already
|
|
77
|
-
* been loaded. Currently only OpenCTM is supported, but other 3D formats
|
|
78
|
-
* could be hooked into this method.
|
|
79
|
-
*
|
|
80
|
-
* You can call this method explicitly to load the geometry at the time
|
|
81
|
-
* you want, or it will be implicitly called when accessing any of the
|
|
82
|
-
* public geometry getters.
|
|
83
|
-
*/
|
|
84
|
-
load(): void;
|
|
85
|
-
/**
|
|
86
|
-
* Calculates and sets tangent data if this ATriMeshF has normals but no gradient (constant) UV
|
|
87
|
-
* coordinates. Without this fix, shader calculations that depends on UV gradients can fail.
|
|
88
|
-
* This is only a workaround since a the tangent is not well defined without a UV gradient.
|
|
89
|
-
*/
|
|
90
|
-
private computeTangentsIfNeeded;
|
|
91
|
-
hasNormals(): boolean;
|
|
92
|
-
hasUVCoordinates(): boolean;
|
|
93
|
-
reverse(): void;
|
|
94
|
-
autoNormals(): void;
|
|
95
|
-
copy(): ATriMeshF;
|
|
96
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* "Advanced Triangle Mesh Float", a mesh normally from CmSym components and later used to
|
|
3
|
+
* instantiate geometry for the 3D engine.
|
|
4
|
+
*
|
|
5
|
+
* @remarks
|
|
6
|
+
* The class can be created by supplying OpenCTM encoded mesh data in the constructor, which will
|
|
7
|
+
* be loaded, decoded and stores in the member variables when load() is called. Alternatively, you
|
|
8
|
+
* can supply a set of typed arrays directly via the createWithArrays(...) factory method.
|
|
9
|
+
*
|
|
10
|
+
* Specification: {@link https://www.configura.com/cmsym/#SymMesh CmSym - SymMesh}
|
|
11
|
+
*/
|
|
12
|
+
export declare class ATriMeshF {
|
|
13
|
+
private _indices;
|
|
14
|
+
private _vertices;
|
|
15
|
+
private _normals;
|
|
16
|
+
private _uvs;
|
|
17
|
+
private _colors;
|
|
18
|
+
private _tangents;
|
|
19
|
+
private data?;
|
|
20
|
+
loaded: boolean;
|
|
21
|
+
/**
|
|
22
|
+
* True means that texture applied to this mesh should NOT be flipped vertically.
|
|
23
|
+
*
|
|
24
|
+
* It is expected that modern models sets this to "true", so we optimize for that case.
|
|
25
|
+
* An undefined value in the CmSym means "false".
|
|
26
|
+
*
|
|
27
|
+
* @remarks
|
|
28
|
+
* From the CmSym specification:
|
|
29
|
+
* If lowerLeftTextureOrigin is true it means that uv=(0, 0) will refer to the lower left
|
|
30
|
+
* corner of the texture.
|
|
31
|
+
* If lowerLeftTextureOrigin is false it mean that uv=(0, 0) will refer to the upper left
|
|
32
|
+
* corner of the texture.
|
|
33
|
+
*
|
|
34
|
+
* The specification states that "material can override this" but no such way exists in the
|
|
35
|
+
* spec it self. After checking with CET developers it turns out that the specification is
|
|
36
|
+
* incorrect; the material can not override this flag.
|
|
37
|
+
*/
|
|
38
|
+
readonly lowerLeftTextureOrigin: boolean;
|
|
39
|
+
/**
|
|
40
|
+
* True if this mesh is double sided.
|
|
41
|
+
* Default value in CmSym is false.
|
|
42
|
+
*
|
|
43
|
+
* Note: This flag is to be considered readonly. It isn't due to SymMesh.js
|
|
44
|
+
* currently applying an SymGetMeshEnv after this class has been created.
|
|
45
|
+
*
|
|
46
|
+
* @remarks
|
|
47
|
+
* From the specification:
|
|
48
|
+
* Defines the double sidedness of the mesh.
|
|
49
|
+
* Material can override this.
|
|
50
|
+
*/
|
|
51
|
+
doubleSided: boolean;
|
|
52
|
+
constructor(data: Uint8Array | undefined, lowerLeftTextureOrigin: boolean, doubleSided: boolean);
|
|
53
|
+
/** Creates and returns a new ATriMeshF with the mesh data supplied. */
|
|
54
|
+
static createWithArrays(indices: Uint32Array, vertices: Float32Array, normals?: Float32Array, uvs?: Float32Array, colors?: Float32Array, tangents?: Float32Array): ATriMeshF;
|
|
55
|
+
get indices(): Uint32Array;
|
|
56
|
+
get vertices(): Float32Array;
|
|
57
|
+
get normals(): Float32Array;
|
|
58
|
+
get uvs(): Float32Array;
|
|
59
|
+
get colors(): Float32Array;
|
|
60
|
+
/**
|
|
61
|
+
* Tangents and bi-tangents are normally calculated in the shaders for effects like normal
|
|
62
|
+
* mapping. However, those calculations rely on "uv gradients" which is not well defined if
|
|
63
|
+
* all vertices in a face (triangle) has the same UV coordinates, making the light calculations
|
|
64
|
+
* fail in those cases, visually showing up much darker or even black in the render.
|
|
65
|
+
*
|
|
66
|
+
* The load code will detect the most probable edge case of this type, the only one encountered
|
|
67
|
+
* so far, which is when all U and V coordinates are constant with respect to each group. In
|
|
68
|
+
* such cases, it will automatically calculate a set of tangents corresponding to the normals,
|
|
69
|
+
* if any. These tangents then need to be supplied to the 3D rendering engine.
|
|
70
|
+
*
|
|
71
|
+
* Additional information on the subject can be found here:
|
|
72
|
+
* https://forum.babylonjs.com/t/odd-uv-coordinates-edge-cases/14729/4
|
|
73
|
+
*/
|
|
74
|
+
get tangents(): Float32Array;
|
|
75
|
+
/**
|
|
76
|
+
* Loads the actually geometry from the data array, unless it has already
|
|
77
|
+
* been loaded. Currently only OpenCTM is supported, but other 3D formats
|
|
78
|
+
* could be hooked into this method.
|
|
79
|
+
*
|
|
80
|
+
* You can call this method explicitly to load the geometry at the time
|
|
81
|
+
* you want, or it will be implicitly called when accessing any of the
|
|
82
|
+
* public geometry getters.
|
|
83
|
+
*/
|
|
84
|
+
load(): void;
|
|
85
|
+
/**
|
|
86
|
+
* Calculates and sets tangent data if this ATriMeshF has normals but no gradient (constant) UV
|
|
87
|
+
* coordinates. Without this fix, shader calculations that depends on UV gradients can fail.
|
|
88
|
+
* This is only a workaround since a the tangent is not well defined without a UV gradient.
|
|
89
|
+
*/
|
|
90
|
+
private computeTangentsIfNeeded;
|
|
91
|
+
hasNormals(): boolean;
|
|
92
|
+
hasUVCoordinates(): boolean;
|
|
93
|
+
reverse(): void;
|
|
94
|
+
autoNormals(): void;
|
|
95
|
+
copy(): ATriMeshF;
|
|
96
|
+
}
|
|
97
97
|
//# sourceMappingURL=ATriMeshF.d.ts.map
|
|
@@ -1,197 +1,197 @@
|
|
|
1
|
-
import { create_ctm_file } from "@configura/internal";
|
|
2
|
-
import { memory } from "@configura/internal/web_core_internal_bg.wasm";
|
|
3
|
-
/**
|
|
4
|
-
* "Advanced Triangle Mesh Float", a mesh normally from CmSym components and later used to
|
|
5
|
-
* instantiate geometry for the 3D engine.
|
|
6
|
-
*
|
|
7
|
-
* @remarks
|
|
8
|
-
* The class can be created by supplying OpenCTM encoded mesh data in the constructor, which will
|
|
9
|
-
* be loaded, decoded and stores in the member variables when load() is called. Alternatively, you
|
|
10
|
-
* can supply a set of typed arrays directly via the createWithArrays(...) factory method.
|
|
11
|
-
*
|
|
12
|
-
* Specification: {@link https://www.configura.com/cmsym/#SymMesh CmSym - SymMesh}
|
|
13
|
-
*/
|
|
14
|
-
export class ATriMeshF {
|
|
15
|
-
constructor(data, lowerLeftTextureOrigin, doubleSided) {
|
|
16
|
-
this.loaded = false;
|
|
17
|
-
this.lowerLeftTextureOrigin = lowerLeftTextureOrigin;
|
|
18
|
-
this.doubleSided = doubleSided;
|
|
19
|
-
this.data = data;
|
|
20
|
-
// Mostly to make TypeScript happy, but also a safeguard if the
|
|
21
|
-
// actual load fails.
|
|
22
|
-
this._indices = new Uint32Array(0);
|
|
23
|
-
this._vertices = new Float32Array(0);
|
|
24
|
-
this._normals = new Float32Array(0);
|
|
25
|
-
this._uvs = new Float32Array(0);
|
|
26
|
-
this._colors = new Float32Array(0);
|
|
27
|
-
this._tangents = new Float32Array(0);
|
|
28
|
-
}
|
|
29
|
-
/** Creates and returns a new ATriMeshF with the mesh data supplied. */
|
|
30
|
-
static createWithArrays(indices, vertices, normals, uvs, colors, tangents) {
|
|
31
|
-
const mesh = new ATriMeshF(undefined, false, false);
|
|
32
|
-
mesh._indices = indices;
|
|
33
|
-
mesh._vertices = vertices;
|
|
34
|
-
if (normals !== undefined) {
|
|
35
|
-
mesh._normals = normals;
|
|
36
|
-
}
|
|
37
|
-
if (uvs !== undefined) {
|
|
38
|
-
mesh._uvs = uvs;
|
|
39
|
-
}
|
|
40
|
-
if (colors !== undefined) {
|
|
41
|
-
mesh._colors = colors;
|
|
42
|
-
}
|
|
43
|
-
if (tangents !== undefined) {
|
|
44
|
-
mesh._tangents = tangents;
|
|
45
|
-
}
|
|
46
|
-
mesh.computeTangentsIfNeeded();
|
|
47
|
-
mesh.loaded = true;
|
|
48
|
-
return mesh;
|
|
49
|
-
}
|
|
50
|
-
get indices() {
|
|
51
|
-
this.load();
|
|
52
|
-
return this._indices;
|
|
53
|
-
}
|
|
54
|
-
get vertices() {
|
|
55
|
-
this.load();
|
|
56
|
-
return this._vertices;
|
|
57
|
-
}
|
|
58
|
-
get normals() {
|
|
59
|
-
this.load();
|
|
60
|
-
return this._normals;
|
|
61
|
-
}
|
|
62
|
-
get uvs() {
|
|
63
|
-
this.load();
|
|
64
|
-
return this._uvs;
|
|
65
|
-
}
|
|
66
|
-
get colors() {
|
|
67
|
-
this.load();
|
|
68
|
-
return this._colors;
|
|
69
|
-
}
|
|
70
|
-
/**
|
|
71
|
-
* Tangents and bi-tangents are normally calculated in the shaders for effects like normal
|
|
72
|
-
* mapping. However, those calculations rely on "uv gradients" which is not well defined if
|
|
73
|
-
* all vertices in a face (triangle) has the same UV coordinates, making the light calculations
|
|
74
|
-
* fail in those cases, visually showing up much darker or even black in the render.
|
|
75
|
-
*
|
|
76
|
-
* The load code will detect the most probable edge case of this type, the only one encountered
|
|
77
|
-
* so far, which is when all U and V coordinates are constant with respect to each group. In
|
|
78
|
-
* such cases, it will automatically calculate a set of tangents corresponding to the normals,
|
|
79
|
-
* if any. These tangents then need to be supplied to the 3D rendering engine.
|
|
80
|
-
*
|
|
81
|
-
* Additional information on the subject can be found here:
|
|
82
|
-
* https://forum.babylonjs.com/t/odd-uv-coordinates-edge-cases/14729/4
|
|
83
|
-
*/
|
|
84
|
-
get tangents() {
|
|
85
|
-
this.load();
|
|
86
|
-
return this._tangents;
|
|
87
|
-
}
|
|
88
|
-
/**
|
|
89
|
-
* Loads the actually geometry from the data array, unless it has already
|
|
90
|
-
* been loaded. Currently only OpenCTM is supported, but other 3D formats
|
|
91
|
-
* could be hooked into this method.
|
|
92
|
-
*
|
|
93
|
-
* You can call this method explicitly to load the geometry at the time
|
|
94
|
-
* you want, or it will be implicitly called when accessing any of the
|
|
95
|
-
* public geometry getters.
|
|
96
|
-
*/
|
|
97
|
-
load() {
|
|
98
|
-
if (this.loaded || this.data === undefined) {
|
|
99
|
-
return;
|
|
100
|
-
}
|
|
101
|
-
// Set load directly, so that any load failure won't get stuck trying
|
|
102
|
-
// to load the data over and over again.
|
|
103
|
-
this.loaded = true;
|
|
104
|
-
// const tick1 = performance.now();
|
|
105
|
-
const ctm = create_ctm_file(this.data);
|
|
106
|
-
// const tick2 = performance.now();
|
|
107
|
-
// We don't need to keep the packed data around now that we decoded it.
|
|
108
|
-
// If we implemented an "unload" it would still be usable though.
|
|
109
|
-
this.data = undefined;
|
|
110
|
-
// create_ctm_file is written in Wasm (Rust). Data needs to be copied
|
|
111
|
-
// out of wasm memory buffer before discarding it, hence slice() part.
|
|
112
|
-
const mem = memory.buffer;
|
|
113
|
-
this._indices = new Uint32Array(mem, ctm.indices_ptr(), ctm.indices_len()).slice();
|
|
114
|
-
this._vertices = new Float32Array(mem, ctm.vertices_ptr(), ctm.vertices_len()).slice();
|
|
115
|
-
this._normals = new Float32Array(mem, ctm.normals_ptr(), ctm.normals_len()).slice();
|
|
116
|
-
this._vertices = new Float32Array(mem, ctm.vertices_ptr(), ctm.vertices_len()).slice();
|
|
117
|
-
const uvsLength = ctm.uvs_len();
|
|
118
|
-
if (uvsLength !== 0) {
|
|
119
|
-
this._uvs = new Float32Array(mem, ctm.uvs_ptr(), uvsLength).slice();
|
|
120
|
-
}
|
|
121
|
-
const colorsLength = ctm.colors_len();
|
|
122
|
-
if (colorsLength !== 0) {
|
|
123
|
-
this._colors = new Float32Array(mem, ctm.uvs_ptr(), colorsLength).slice();
|
|
124
|
-
}
|
|
125
|
-
// Release the wasm memory buffer now that we are done with it.
|
|
126
|
-
ctm.free();
|
|
127
|
-
// console.log(
|
|
128
|
-
// `CTM data loaded (${this.vertexCount()} vertices). Decode: ${Math.round(
|
|
129
|
-
// tick2 - tick1
|
|
130
|
-
// )}ms. Copying & dealloc ${Math.round(performance.now() - tick2)}ms`
|
|
131
|
-
// );
|
|
132
|
-
this.computeTangentsIfNeeded();
|
|
133
|
-
}
|
|
134
|
-
/**
|
|
135
|
-
* Calculates and sets tangent data if this ATriMeshF has normals but no gradient (constant) UV
|
|
136
|
-
* coordinates. Without this fix, shader calculations that depends on UV gradients can fail.
|
|
137
|
-
* This is only a workaround since a the tangent is not well defined without a UV gradient.
|
|
138
|
-
*/
|
|
139
|
-
computeTangentsIfNeeded() {
|
|
140
|
-
if (this._uvs.length < 2 || this._normals.length < 3) {
|
|
141
|
-
return;
|
|
142
|
-
}
|
|
143
|
-
// Check if all U and V values are constant. Primitive check that does not take into
|
|
144
|
-
// account possible "flat" areas inside a varying UV mapping.
|
|
145
|
-
const u = this._uvs[0];
|
|
146
|
-
const v = this._uvs[1];
|
|
147
|
-
for (let i = 2; i < this._uvs.length - 1; i += 2) {
|
|
148
|
-
if (this._uvs[i] !== u || this._uvs[i + 1] !== v) {
|
|
149
|
-
return;
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
// const tick = performance.now();
|
|
153
|
-
const num = this._normals.length / 3;
|
|
154
|
-
const tangents = new Float32Array(num * 4);
|
|
155
|
-
for (let i = 0; i < num; i++) {
|
|
156
|
-
// Normally tangents are aligned along the U/V gradient axis, but since our UV
|
|
157
|
-
// coordinates are constant we have no gradient. As such, the only real constraint is
|
|
158
|
-
// that the tangent is, well, tangent to the normal. None of these are "correct", so
|
|
159
|
-
// simply pick any one of them...
|
|
160
|
-
// The code below is what is left after optimizing:
|
|
161
|
-
// 1. Take the cross product of the normal and (1, 0, 0) & (0, 1, 0).
|
|
162
|
-
// 2. Select the longest of the two results (one might be zero).
|
|
163
|
-
// 3. Normalize it and store it as a tangent (with 1 as the fourth component).
|
|
164
|
-
const nx = this._normals[i * 3];
|
|
165
|
-
const ny = this._normals[i * 3 + 1];
|
|
166
|
-
const nz = this._normals[i * 3 + 2];
|
|
167
|
-
if (Math.abs(ny) > Math.abs(nx)) {
|
|
168
|
-
const len = Math.sqrt(nz * nz + ny * ny);
|
|
169
|
-
tangents[i * 4 + 1] = nz / len;
|
|
170
|
-
tangents[i * 4 + 2] = -ny / len;
|
|
171
|
-
}
|
|
172
|
-
else {
|
|
173
|
-
const len = Math.sqrt(nz * nz + nx * nx);
|
|
174
|
-
tangents[i * 4] = -nz / len;
|
|
175
|
-
tangents[i * 4 + 2] = nx / len;
|
|
176
|
-
}
|
|
177
|
-
tangents[i * 4 + 3] = 1;
|
|
178
|
-
}
|
|
179
|
-
this._tangents = tangents;
|
|
180
|
-
// console.log(`Computing ${num} tangents took ${Math.round(performance.now() - tick)}ms.`);
|
|
181
|
-
}
|
|
182
|
-
hasNormals() {
|
|
183
|
-
return this.normals.length > 0 || this._vertices.length === 0;
|
|
184
|
-
}
|
|
185
|
-
hasUVCoordinates() {
|
|
186
|
-
return this.uvs.length > 0 || this._vertices.length === 0;
|
|
187
|
-
}
|
|
188
|
-
reverse() {
|
|
189
|
-
throw Error("ATriMeshF.reverse");
|
|
190
|
-
}
|
|
191
|
-
autoNormals() {
|
|
192
|
-
throw Error("ATriMeshF.autoNormals");
|
|
193
|
-
}
|
|
194
|
-
copy() {
|
|
195
|
-
throw Error("ATriMeshF.copy");
|
|
196
|
-
}
|
|
197
|
-
}
|
|
1
|
+
import { create_ctm_file } from "@configura/internal";
|
|
2
|
+
import { memory } from "@configura/internal/web_core_internal_bg.wasm";
|
|
3
|
+
/**
|
|
4
|
+
* "Advanced Triangle Mesh Float", a mesh normally from CmSym components and later used to
|
|
5
|
+
* instantiate geometry for the 3D engine.
|
|
6
|
+
*
|
|
7
|
+
* @remarks
|
|
8
|
+
* The class can be created by supplying OpenCTM encoded mesh data in the constructor, which will
|
|
9
|
+
* be loaded, decoded and stores in the member variables when load() is called. Alternatively, you
|
|
10
|
+
* can supply a set of typed arrays directly via the createWithArrays(...) factory method.
|
|
11
|
+
*
|
|
12
|
+
* Specification: {@link https://www.configura.com/cmsym/#SymMesh CmSym - SymMesh}
|
|
13
|
+
*/
|
|
14
|
+
export class ATriMeshF {
|
|
15
|
+
constructor(data, lowerLeftTextureOrigin, doubleSided) {
|
|
16
|
+
this.loaded = false;
|
|
17
|
+
this.lowerLeftTextureOrigin = lowerLeftTextureOrigin;
|
|
18
|
+
this.doubleSided = doubleSided;
|
|
19
|
+
this.data = data;
|
|
20
|
+
// Mostly to make TypeScript happy, but also a safeguard if the
|
|
21
|
+
// actual load fails.
|
|
22
|
+
this._indices = new Uint32Array(0);
|
|
23
|
+
this._vertices = new Float32Array(0);
|
|
24
|
+
this._normals = new Float32Array(0);
|
|
25
|
+
this._uvs = new Float32Array(0);
|
|
26
|
+
this._colors = new Float32Array(0);
|
|
27
|
+
this._tangents = new Float32Array(0);
|
|
28
|
+
}
|
|
29
|
+
/** Creates and returns a new ATriMeshF with the mesh data supplied. */
|
|
30
|
+
static createWithArrays(indices, vertices, normals, uvs, colors, tangents) {
|
|
31
|
+
const mesh = new ATriMeshF(undefined, false, false);
|
|
32
|
+
mesh._indices = indices;
|
|
33
|
+
mesh._vertices = vertices;
|
|
34
|
+
if (normals !== undefined) {
|
|
35
|
+
mesh._normals = normals;
|
|
36
|
+
}
|
|
37
|
+
if (uvs !== undefined) {
|
|
38
|
+
mesh._uvs = uvs;
|
|
39
|
+
}
|
|
40
|
+
if (colors !== undefined) {
|
|
41
|
+
mesh._colors = colors;
|
|
42
|
+
}
|
|
43
|
+
if (tangents !== undefined) {
|
|
44
|
+
mesh._tangents = tangents;
|
|
45
|
+
}
|
|
46
|
+
mesh.computeTangentsIfNeeded();
|
|
47
|
+
mesh.loaded = true;
|
|
48
|
+
return mesh;
|
|
49
|
+
}
|
|
50
|
+
get indices() {
|
|
51
|
+
this.load();
|
|
52
|
+
return this._indices;
|
|
53
|
+
}
|
|
54
|
+
get vertices() {
|
|
55
|
+
this.load();
|
|
56
|
+
return this._vertices;
|
|
57
|
+
}
|
|
58
|
+
get normals() {
|
|
59
|
+
this.load();
|
|
60
|
+
return this._normals;
|
|
61
|
+
}
|
|
62
|
+
get uvs() {
|
|
63
|
+
this.load();
|
|
64
|
+
return this._uvs;
|
|
65
|
+
}
|
|
66
|
+
get colors() {
|
|
67
|
+
this.load();
|
|
68
|
+
return this._colors;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Tangents and bi-tangents are normally calculated in the shaders for effects like normal
|
|
72
|
+
* mapping. However, those calculations rely on "uv gradients" which is not well defined if
|
|
73
|
+
* all vertices in a face (triangle) has the same UV coordinates, making the light calculations
|
|
74
|
+
* fail in those cases, visually showing up much darker or even black in the render.
|
|
75
|
+
*
|
|
76
|
+
* The load code will detect the most probable edge case of this type, the only one encountered
|
|
77
|
+
* so far, which is when all U and V coordinates are constant with respect to each group. In
|
|
78
|
+
* such cases, it will automatically calculate a set of tangents corresponding to the normals,
|
|
79
|
+
* if any. These tangents then need to be supplied to the 3D rendering engine.
|
|
80
|
+
*
|
|
81
|
+
* Additional information on the subject can be found here:
|
|
82
|
+
* https://forum.babylonjs.com/t/odd-uv-coordinates-edge-cases/14729/4
|
|
83
|
+
*/
|
|
84
|
+
get tangents() {
|
|
85
|
+
this.load();
|
|
86
|
+
return this._tangents;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Loads the actually geometry from the data array, unless it has already
|
|
90
|
+
* been loaded. Currently only OpenCTM is supported, but other 3D formats
|
|
91
|
+
* could be hooked into this method.
|
|
92
|
+
*
|
|
93
|
+
* You can call this method explicitly to load the geometry at the time
|
|
94
|
+
* you want, or it will be implicitly called when accessing any of the
|
|
95
|
+
* public geometry getters.
|
|
96
|
+
*/
|
|
97
|
+
load() {
|
|
98
|
+
if (this.loaded || this.data === undefined) {
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
// Set load directly, so that any load failure won't get stuck trying
|
|
102
|
+
// to load the data over and over again.
|
|
103
|
+
this.loaded = true;
|
|
104
|
+
// const tick1 = performance.now();
|
|
105
|
+
const ctm = create_ctm_file(this.data);
|
|
106
|
+
// const tick2 = performance.now();
|
|
107
|
+
// We don't need to keep the packed data around now that we decoded it.
|
|
108
|
+
// If we implemented an "unload" it would still be usable though.
|
|
109
|
+
this.data = undefined;
|
|
110
|
+
// create_ctm_file is written in Wasm (Rust). Data needs to be copied
|
|
111
|
+
// out of wasm memory buffer before discarding it, hence slice() part.
|
|
112
|
+
const mem = memory.buffer;
|
|
113
|
+
this._indices = new Uint32Array(mem, ctm.indices_ptr(), ctm.indices_len()).slice();
|
|
114
|
+
this._vertices = new Float32Array(mem, ctm.vertices_ptr(), ctm.vertices_len()).slice();
|
|
115
|
+
this._normals = new Float32Array(mem, ctm.normals_ptr(), ctm.normals_len()).slice();
|
|
116
|
+
this._vertices = new Float32Array(mem, ctm.vertices_ptr(), ctm.vertices_len()).slice();
|
|
117
|
+
const uvsLength = ctm.uvs_len();
|
|
118
|
+
if (uvsLength !== 0) {
|
|
119
|
+
this._uvs = new Float32Array(mem, ctm.uvs_ptr(), uvsLength).slice();
|
|
120
|
+
}
|
|
121
|
+
const colorsLength = ctm.colors_len();
|
|
122
|
+
if (colorsLength !== 0) {
|
|
123
|
+
this._colors = new Float32Array(mem, ctm.uvs_ptr(), colorsLength).slice();
|
|
124
|
+
}
|
|
125
|
+
// Release the wasm memory buffer now that we are done with it.
|
|
126
|
+
ctm.free();
|
|
127
|
+
// console.log(
|
|
128
|
+
// `CTM data loaded (${this.vertexCount()} vertices). Decode: ${Math.round(
|
|
129
|
+
// tick2 - tick1
|
|
130
|
+
// )}ms. Copying & dealloc ${Math.round(performance.now() - tick2)}ms`
|
|
131
|
+
// );
|
|
132
|
+
this.computeTangentsIfNeeded();
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Calculates and sets tangent data if this ATriMeshF has normals but no gradient (constant) UV
|
|
136
|
+
* coordinates. Without this fix, shader calculations that depends on UV gradients can fail.
|
|
137
|
+
* This is only a workaround since a the tangent is not well defined without a UV gradient.
|
|
138
|
+
*/
|
|
139
|
+
computeTangentsIfNeeded() {
|
|
140
|
+
if (this._uvs.length < 2 || this._normals.length < 3) {
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
// Check if all U and V values are constant. Primitive check that does not take into
|
|
144
|
+
// account possible "flat" areas inside a varying UV mapping.
|
|
145
|
+
const u = this._uvs[0];
|
|
146
|
+
const v = this._uvs[1];
|
|
147
|
+
for (let i = 2; i < this._uvs.length - 1; i += 2) {
|
|
148
|
+
if (this._uvs[i] !== u || this._uvs[i + 1] !== v) {
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
// const tick = performance.now();
|
|
153
|
+
const num = this._normals.length / 3;
|
|
154
|
+
const tangents = new Float32Array(num * 4);
|
|
155
|
+
for (let i = 0; i < num; i++) {
|
|
156
|
+
// Normally tangents are aligned along the U/V gradient axis, but since our UV
|
|
157
|
+
// coordinates are constant we have no gradient. As such, the only real constraint is
|
|
158
|
+
// that the tangent is, well, tangent to the normal. None of these are "correct", so
|
|
159
|
+
// simply pick any one of them...
|
|
160
|
+
// The code below is what is left after optimizing:
|
|
161
|
+
// 1. Take the cross product of the normal and (1, 0, 0) & (0, 1, 0).
|
|
162
|
+
// 2. Select the longest of the two results (one might be zero).
|
|
163
|
+
// 3. Normalize it and store it as a tangent (with 1 as the fourth component).
|
|
164
|
+
const nx = this._normals[i * 3];
|
|
165
|
+
const ny = this._normals[i * 3 + 1];
|
|
166
|
+
const nz = this._normals[i * 3 + 2];
|
|
167
|
+
if (Math.abs(ny) > Math.abs(nx)) {
|
|
168
|
+
const len = Math.sqrt(nz * nz + ny * ny);
|
|
169
|
+
tangents[i * 4 + 1] = nz / len;
|
|
170
|
+
tangents[i * 4 + 2] = -ny / len;
|
|
171
|
+
}
|
|
172
|
+
else {
|
|
173
|
+
const len = Math.sqrt(nz * nz + nx * nx);
|
|
174
|
+
tangents[i * 4] = -nz / len;
|
|
175
|
+
tangents[i * 4 + 2] = nx / len;
|
|
176
|
+
}
|
|
177
|
+
tangents[i * 4 + 3] = 1;
|
|
178
|
+
}
|
|
179
|
+
this._tangents = tangents;
|
|
180
|
+
// console.log(`Computing ${num} tangents took ${Math.round(performance.now() - tick)}ms.`);
|
|
181
|
+
}
|
|
182
|
+
hasNormals() {
|
|
183
|
+
return this.normals.length > 0 || this._vertices.length === 0;
|
|
184
|
+
}
|
|
185
|
+
hasUVCoordinates() {
|
|
186
|
+
return this.uvs.length > 0 || this._vertices.length === 0;
|
|
187
|
+
}
|
|
188
|
+
reverse() {
|
|
189
|
+
throw Error("ATriMeshF.reverse");
|
|
190
|
+
}
|
|
191
|
+
autoNormals() {
|
|
192
|
+
throw Error("ATriMeshF.autoNormals");
|
|
193
|
+
}
|
|
194
|
+
copy() {
|
|
195
|
+
throw Error("ATriMeshF.copy");
|
|
196
|
+
}
|
|
197
|
+
}
|