forked from mirror/ObjToSchematic
Code cleanup and optimization
This commit is contained in:
parent
86ab7900f8
commit
8ce17c9e13
@ -59,8 +59,8 @@ export class UI {
|
||||
displayText: 'BVH Ray-based',
|
||||
},
|
||||
{
|
||||
id: 'bvh-ray-thick',
|
||||
displayText: 'BVH But THICK',
|
||||
id: 'bvh-ray-plus-thickness',
|
||||
displayText: 'BVH Ray-based (thicker walls)',
|
||||
},
|
||||
{
|
||||
id: 'ncrb',
|
||||
|
@ -10,15 +10,11 @@ import { IVoxeliser } from './base-voxeliser';
|
||||
|
||||
const bvhtree = require('bvh-tree');
|
||||
|
||||
function cross(v0: Vector3, v1: Vector3) {
|
||||
return new Vector3(v0.y * v1.z - v0.z * v1.y, v0.z * v1.x - v0.x * v1.z, v0.x * v1.y - v0.y * v1.x)
|
||||
}
|
||||
|
||||
/**
|
||||
* This voxeliser works by projecting rays onto each triangle
|
||||
* on each of the principle angles and testing for intersections
|
||||
*/
|
||||
export class BVHRayVoxeliserThick extends IVoxeliser {
|
||||
export class BVHRayVoxeliserPlusThickness extends IVoxeliser {
|
||||
protected override _voxelise(mesh: Mesh, voxeliseParams: VoxeliseParams.Input): VoxelMesh {
|
||||
const voxelMesh = new VoxelMesh(voxeliseParams);
|
||||
const scale = (voxeliseParams.desiredHeight - 1) / Mesh.desiredHeight;
|
||||
@ -81,8 +77,6 @@ export class BVHRayVoxeliserThick extends IVoxeliser {
|
||||
ASSERT(rays.length === rayIndex);
|
||||
LOG('Rays created...');
|
||||
|
||||
const VecZero = new Vector3(0, 0, 0)
|
||||
|
||||
// Ray test BVH
|
||||
const taskHandle = ProgressManager.Get.start('Voxelising');
|
||||
for (rayIndex = 0; rayIndex < rays.length; ++rayIndex) {
|
||||
@ -94,21 +88,13 @@ export class BVHRayVoxeliserThick extends IVoxeliser {
|
||||
const point = intersection.intersectionPoint;
|
||||
const position = new Vector3(point.x, point.y, point.z);
|
||||
|
||||
// // Shrinking towards the center
|
||||
// const centerVector = VecZero.copy().sub(position)
|
||||
// const depthPosition = position.copy().add(centerVector.normalise()).round()
|
||||
|
||||
// Shrinking towards the perpendicular vector
|
||||
const triangle = intersection.triangle
|
||||
const p0 = new Vector3(triangle[0].x, triangle[0].y, triangle[0].z)
|
||||
const p1 = new Vector3(triangle[1].x, triangle[1].y, triangle[1].z)
|
||||
const p2 = new Vector3(triangle[2].x, triangle[2].y, triangle[2].z)
|
||||
const v0 = p1.sub(p0)
|
||||
const v1 = p2.sub(p0)
|
||||
const crossVec = cross(v1, v0)
|
||||
const depthPosition = position.copy().add(crossVec.normalise().mulScalar(0.5)).round()
|
||||
const triangle = mesh.getUVTriangle(intersection.triangleIndex);
|
||||
const v0 = Vector3.sub(triangle.v1, triangle.v0);
|
||||
const v1 = Vector3.sub(triangle.v2, triangle.v0);
|
||||
const crossVec = Vector3.cross(v1, v0);
|
||||
const depthPosition = position.copy().add(crossVec.normalise().mulScalar(0.5)).round();
|
||||
|
||||
// const depthPosition = position.copy().add(scaler.normalise()).round()
|
||||
position.round();
|
||||
|
||||
const voxelColour = this._getVoxelColour(
|
||||
@ -121,12 +107,8 @@ export class BVHRayVoxeliserThick extends IVoxeliser {
|
||||
|
||||
if (voxelColour) {
|
||||
voxelMesh.addVoxel(position, voxelColour);
|
||||
// if (crossVec.magnitude() > 0.5) {
|
||||
// const depthPosition = position.copy().add(crossVec.normalise().mulScalar(0.5)).round()
|
||||
// voxelMesh.addVoxel(depthPosition, voxelColour)
|
||||
// }
|
||||
if (!depthPosition.equals(position)) {
|
||||
voxelMesh.addVoxel(depthPosition, voxelColour)
|
||||
voxelMesh.addVoxel(depthPosition, voxelColour);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,11 +1,11 @@
|
||||
import { ASSERT } from '../util/error_util';
|
||||
import { IVoxeliser } from './base-voxeliser';
|
||||
import { BVHRayVoxeliser } from './bvh-ray-voxeliser';
|
||||
import { BVHRayVoxeliserThick } from './bvh-ray-thick'
|
||||
import { BVHRayVoxeliserPlusThickness } from './bvh-ray-voxeliser-plus-thickness'
|
||||
import { NormalCorrectedRayVoxeliser } from './normal-corrected-ray-voxeliser';
|
||||
import { RayVoxeliser } from './ray-voxeliser';
|
||||
|
||||
export type TVoxelisers = 'bvh-ray' | 'ncrb' | 'ray-based' | 'bvh-ray-thick';
|
||||
export type TVoxelisers = 'bvh-ray' | 'ncrb' | 'ray-based' | 'bvh-ray-plus-thickness';
|
||||
|
||||
export class VoxeliserFactory {
|
||||
public static GetVoxeliser(voxeliser: TVoxelisers): IVoxeliser {
|
||||
@ -16,8 +16,8 @@ export class VoxeliserFactory {
|
||||
return new NormalCorrectedRayVoxeliser();
|
||||
case 'ray-based':
|
||||
return new RayVoxeliser();
|
||||
case 'bvh-ray-thick':
|
||||
return new BVHRayVoxeliserThick()
|
||||
case 'bvh-ray-plus-thickness':
|
||||
return new BVHRayVoxeliserPlusThickness()
|
||||
default:
|
||||
ASSERT(false, 'Unreachable');
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user