Convert UV from class to type

This commit is contained in:
Lucas Dower 2023-09-15 19:43:48 +01:00
parent c6da004f6e
commit 5aca2d2cda
7 changed files with 22 additions and 33 deletions

View File

@ -60,10 +60,10 @@ export class Atlas {
const getTextureUV = (name: string) => {
const tex = atlasData.textures[name];
return new UV(
(3 * tex.atlasColumn + 1) / (atlas._atlasSize * 3),
(3 * tex.atlasRow + 1) / (atlas._atlasSize * 3),
);
return {
u: (3 * tex.atlasColumn + 1) / (atlas._atlasSize * 3),
v: (3 * tex.atlasRow + 1) / (atlas._atlasSize * 3),
};
};
for (const block of atlasData.blocks) {

View File

@ -76,10 +76,10 @@ export class GltfLoader extends IImporter {
if (attributes.TEXCOORD_0 !== undefined) {
const texcoords = attributes.TEXCOORD_0.value as Float32Array;
for (let i = 0; i < texcoords.length; i += 2) {
meshTexcoords.push(new UV(
texcoords[i + 0],
1.0 - texcoords[i + 1],
));
meshTexcoords.push({
u: texcoords[i + 0],
v: 1.0 - texcoords[i + 1],
});
}
}
// Material

View File

@ -119,7 +119,7 @@ export class ObjImporter extends IImporter {
return err;
}
this._uvs.push(new UV(u, v));
this._uvs.push({ u: u, v: v });
return null;
},
},

View File

@ -364,15 +364,15 @@ export class Mesh {
const tri = this._tris[triIndex];
if (tri.texcoordIndices) {
return {
uv0: this._uvs[tri.texcoordIndices.x] || new UV(0.0, 0.0),
uv1: this._uvs[tri.texcoordIndices.y] || new UV(0.0, 0.0),
uv2: this._uvs[tri.texcoordIndices.z] || new UV(0.0, 0.0),
uv0: this._uvs[tri.texcoordIndices.x] || { u: 0.0, v: 0.0 },
uv1: this._uvs[tri.texcoordIndices.y] || { u: 0.0, v: 0.0 },
uv2: this._uvs[tri.texcoordIndices.z] || { u: 0.0, v: 0.0 },
};
}
return {
uv0: new UV(0.0, 0.0),
uv1: new UV(0.0, 0.0),
uv2: new UV(0.0, 0.0),
uv0: { u: 0.0, v: 0.0 },
uv1: { u: 0.0, v: 0.0 },
uv2: { u: 0.0, v: 0.0 },
};
}

View File

@ -146,10 +146,10 @@ export class OtS_VoxelMesh_Converter {
const w1 = area20 / total;
const w2 = area01 / total;
const uv = new UV(
triangle.uv0.u * w0 + triangle.uv1.u * w1 + triangle.uv2.u * w2,
triangle.uv0.v * w0 + triangle.uv1.v * w1 + triangle.uv2.v * w2,
);
const uv = {
u: triangle.uv0.u * w0 + triangle.uv1.u * w1 + triangle.uv2.u * w2,
v: triangle.uv0.v * w0 + triangle.uv1.v * w1 + triangle.uv2.v * w2,
};
if (isNaN(uv.u) || isNaN(uv.v)) {
RGBAUtil.copy(RGBAColours.MAGENTA);

View File

@ -95,7 +95,7 @@ export class Texture {
* UV can be in any range and is not limited to [0, 1]
*/
public getRGBA(inUV: UV, interpolation: TTexelInterpolation, extension: TTexelExtension): RGBA {
const uv = new UV(0.0, 0.0);
const uv = { u: 0.0, v: 0.0 };
if (extension === 'clamp') {
uv.u = clamp(inUV.u, 0.0, 1.0);

View File

@ -1,4 +1,5 @@
import { AppMath } from "./math";
import { TBrand } from "./util/type_util";
export namespace AppUtil {
export namespace Text {
@ -57,19 +58,7 @@ export namespace AppTypes {
export type TNamespacedBlockName = string;
}
export class UV {
public u: number;
public v: number;
constructor(u: number, v: number) {
this.u = u;
this.v = v;
}
public copy() {
return new UV(this.u, this.v);
}
}
export type UV = { u: number, v: number };
export type TOptional<T> = T | undefined;