mirror of
https://github.com/LucasDower/ObjToSchematic.git
synced 2025-12-11 20:15:30 +01:00
Convert UV from class to type
This commit is contained in:
parent
c6da004f6e
commit
5aca2d2cda
@ -60,10 +60,10 @@ export class Atlas {
|
|||||||
|
|
||||||
const getTextureUV = (name: string) => {
|
const getTextureUV = (name: string) => {
|
||||||
const tex = atlasData.textures[name];
|
const tex = atlasData.textures[name];
|
||||||
return new UV(
|
return {
|
||||||
(3 * tex.atlasColumn + 1) / (atlas._atlasSize * 3),
|
u: (3 * tex.atlasColumn + 1) / (atlas._atlasSize * 3),
|
||||||
(3 * tex.atlasRow + 1) / (atlas._atlasSize * 3),
|
v: (3 * tex.atlasRow + 1) / (atlas._atlasSize * 3),
|
||||||
);
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
for (const block of atlasData.blocks) {
|
for (const block of atlasData.blocks) {
|
||||||
|
|||||||
@ -76,10 +76,10 @@ export class GltfLoader extends IImporter {
|
|||||||
if (attributes.TEXCOORD_0 !== undefined) {
|
if (attributes.TEXCOORD_0 !== undefined) {
|
||||||
const texcoords = attributes.TEXCOORD_0.value as Float32Array;
|
const texcoords = attributes.TEXCOORD_0.value as Float32Array;
|
||||||
for (let i = 0; i < texcoords.length; i += 2) {
|
for (let i = 0; i < texcoords.length; i += 2) {
|
||||||
meshTexcoords.push(new UV(
|
meshTexcoords.push({
|
||||||
texcoords[i + 0],
|
u: texcoords[i + 0],
|
||||||
1.0 - texcoords[i + 1],
|
v: 1.0 - texcoords[i + 1],
|
||||||
));
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Material
|
// Material
|
||||||
|
|||||||
@ -119,7 +119,7 @@ export class ObjImporter extends IImporter {
|
|||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
this._uvs.push(new UV(u, v));
|
this._uvs.push({ u: u, v: v });
|
||||||
return null;
|
return null;
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
@ -364,15 +364,15 @@ export class Mesh {
|
|||||||
const tri = this._tris[triIndex];
|
const tri = this._tris[triIndex];
|
||||||
if (tri.texcoordIndices) {
|
if (tri.texcoordIndices) {
|
||||||
return {
|
return {
|
||||||
uv0: this._uvs[tri.texcoordIndices.x] || new UV(0.0, 0.0),
|
uv0: this._uvs[tri.texcoordIndices.x] || { u: 0.0, v: 0.0 },
|
||||||
uv1: this._uvs[tri.texcoordIndices.y] || new UV(0.0, 0.0),
|
uv1: this._uvs[tri.texcoordIndices.y] || { u: 0.0, v: 0.0 },
|
||||||
uv2: this._uvs[tri.texcoordIndices.z] || new UV(0.0, 0.0),
|
uv2: this._uvs[tri.texcoordIndices.z] || { u: 0.0, v: 0.0 },
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
uv0: new UV(0.0, 0.0),
|
uv0: { u: 0.0, v: 0.0 },
|
||||||
uv1: new UV(0.0, 0.0),
|
uv1: { u: 0.0, v: 0.0 },
|
||||||
uv2: new UV(0.0, 0.0),
|
uv2: { u: 0.0, v: 0.0 },
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -146,10 +146,10 @@ export class OtS_VoxelMesh_Converter {
|
|||||||
const w1 = area20 / total;
|
const w1 = area20 / total;
|
||||||
const w2 = area01 / total;
|
const w2 = area01 / total;
|
||||||
|
|
||||||
const uv = new UV(
|
const uv = {
|
||||||
triangle.uv0.u * w0 + triangle.uv1.u * w1 + triangle.uv2.u * w2,
|
u: triangle.uv0.u * w0 + triangle.uv1.u * w1 + triangle.uv2.u * w2,
|
||||||
triangle.uv0.v * w0 + triangle.uv1.v * w1 + triangle.uv2.v * w2,
|
v: triangle.uv0.v * w0 + triangle.uv1.v * w1 + triangle.uv2.v * w2,
|
||||||
);
|
};
|
||||||
|
|
||||||
if (isNaN(uv.u) || isNaN(uv.v)) {
|
if (isNaN(uv.u) || isNaN(uv.v)) {
|
||||||
RGBAUtil.copy(RGBAColours.MAGENTA);
|
RGBAUtil.copy(RGBAColours.MAGENTA);
|
||||||
|
|||||||
@ -95,7 +95,7 @@ export class Texture {
|
|||||||
* UV can be in any range and is not limited to [0, 1]
|
* UV can be in any range and is not limited to [0, 1]
|
||||||
*/
|
*/
|
||||||
public getRGBA(inUV: UV, interpolation: TTexelInterpolation, extension: TTexelExtension): RGBA {
|
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') {
|
if (extension === 'clamp') {
|
||||||
uv.u = clamp(inUV.u, 0.0, 1.0);
|
uv.u = clamp(inUV.u, 0.0, 1.0);
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
import { AppMath } from "./math";
|
import { AppMath } from "./math";
|
||||||
|
import { TBrand } from "./util/type_util";
|
||||||
|
|
||||||
export namespace AppUtil {
|
export namespace AppUtil {
|
||||||
export namespace Text {
|
export namespace Text {
|
||||||
@ -57,19 +58,7 @@ export namespace AppTypes {
|
|||||||
export type TNamespacedBlockName = string;
|
export type TNamespacedBlockName = string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class UV {
|
export type UV = { u: number, v: number };
|
||||||
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 TOptional<T> = T | undefined;
|
export type TOptional<T> = T | undefined;
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user