forked from mirror/ObjToSchematic
Improved handling of malformed meshes
This commit is contained in:
parent
affdf247a9
commit
20c92e9afd
@ -1,5 +1,5 @@
|
|||||||
import { UVTriangle, Triangle } from '../triangle';
|
import { UVTriangle, Triangle } from '../triangle';
|
||||||
import { RGB, UV } from '../util';
|
import { ASSERT, RGB, UV } from '../util';
|
||||||
import { Vector3 } from '../vector';
|
import { Vector3 } from '../vector';
|
||||||
import { Mesh } from '../mesh';
|
import { Mesh } from '../mesh';
|
||||||
import { VoxelMesh, VoxelMeshParams} from '../voxel_mesh';
|
import { VoxelMesh, VoxelMeshParams} from '../voxel_mesh';
|
||||||
@ -20,7 +20,7 @@ export abstract class IVoxeliser {
|
|||||||
|
|
||||||
protected abstract _voxelise(mesh: Mesh, voxelMeshParams: VoxelMeshParams): VoxelMesh;
|
protected abstract _voxelise(mesh: Mesh, voxelMeshParams: VoxelMeshParams): VoxelMesh;
|
||||||
|
|
||||||
protected _getVoxelColour(mesh: Mesh, triangle: UVTriangle, materialName: string, location: Vector3, filtering: TextureFiltering): RGB {
|
protected _getVoxelColour(mesh: Mesh, triangle: UVTriangle, materialName: string, location: Vector3, filtering: TextureFiltering): (RGB | undefined) {
|
||||||
const area01 = new Triangle(triangle.v0, triangle.v1, location).getArea();
|
const area01 = new Triangle(triangle.v0, triangle.v1, location).getArea();
|
||||||
const area12 = new Triangle(triangle.v1, triangle.v2, location).getArea();
|
const area12 = new Triangle(triangle.v1, triangle.v2, location).getArea();
|
||||||
const area20 = new Triangle(triangle.v2, triangle.v0, location).getArea();
|
const area20 = new Triangle(triangle.v2, triangle.v0, location).getArea();
|
||||||
@ -35,6 +35,10 @@ export abstract class IVoxeliser {
|
|||||||
triangle.uv0.v * w0 + triangle.uv1.v * w1 + triangle.uv2.v * w2,
|
triangle.uv0.v * w0 + triangle.uv1.v * w1 + triangle.uv2.v * w2,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (isNaN(uv.u) || isNaN(uv.v)) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
return mesh.sampleMaterial(materialName, uv, filtering);
|
return mesh.sampleMaterial(materialName, uv, filtering);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -90,7 +90,10 @@ export class BVHRayVoxeliser extends IVoxeliser {
|
|||||||
position,
|
position,
|
||||||
voxelMeshParams.textureFiltering,
|
voxelMeshParams.textureFiltering,
|
||||||
);
|
);
|
||||||
voxelMesh.addVoxel(position, voxelColour);
|
|
||||||
|
if (voxelColour) {
|
||||||
|
voxelMesh.addVoxel(position, voxelColour);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user