forked from mirror/ObjToSchematic
Fix for some textures appearing as black when using gl.REPEAT wrapping
* For some reason, non-power-of-two size textures that use 'repeat' wrapping appear as black. Implemented a workaround for now that default sets a material's wrapping to 'clamp' where appropriate which is usually most materials
This commit is contained in:
parent
38cc7e873f
commit
f0e741be05
34
src/mesh.ts
34
src/mesh.ts
@ -9,7 +9,7 @@ import { Texture, TextureConverter, TTransparencyOptions } from './texture';
|
||||
import { Triangle, UVTriangle } from './triangle';
|
||||
import { getRandomID, UV } from './util';
|
||||
import { AppError, ASSERT } from './util/error_util';
|
||||
import { LOG_WARN } from './util/log_util';
|
||||
import { LOG, LOG_WARN } from './util/log_util';
|
||||
import { TTexelExtension, TTexelInterpolation } from './util/type_util';
|
||||
import { Vector3 } from './vector';
|
||||
|
||||
@ -264,6 +264,38 @@ export class Mesh {
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Deduce default texture wrap mode for each material type
|
||||
const materialsWithUVsOutOfBounds = new Set<string>();
|
||||
this._tris.forEach((tri, triIndex) => {
|
||||
if (materialsWithUVsOutOfBounds.has(tri.material)) {
|
||||
// Already know this material has OOB UVs so skip
|
||||
return;
|
||||
}
|
||||
|
||||
const uv = this.getUVs(triIndex);
|
||||
const uvsOutOfBounds =
|
||||
(uv.uv0.u < 0.0) || (uv.uv0.u > 1.0) ||
|
||||
(uv.uv0.v < 0.0) || (uv.uv0.v > 1.0) ||
|
||||
(uv.uv1.u < 0.0) || (uv.uv1.u > 1.0) ||
|
||||
(uv.uv1.v < 0.0) || (uv.uv1.v > 1.0) ||
|
||||
(uv.uv2.u < 0.0) || (uv.uv2.u > 1.0) ||
|
||||
(uv.uv2.v < 0.0) || (uv.uv2.v > 1.0);
|
||||
|
||||
if (uvsOutOfBounds) {
|
||||
materialsWithUVsOutOfBounds.add(tri.material);
|
||||
}
|
||||
});
|
||||
|
||||
LOG(`Materials with OOB UVs`, JSON.stringify(materialsWithUVsOutOfBounds));
|
||||
|
||||
this._materials.forEach((material, materialName) => {
|
||||
if (material.type === MaterialType.textured) {
|
||||
material.extension = materialsWithUVsOutOfBounds.has(materialName) ?
|
||||
'repeat' :
|
||||
'clamp';
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private _centreMesh() {
|
||||
|
Loading…
Reference in New Issue
Block a user