mirror of
https://github.com/LucasDower/ObjToSchematic.git
synced 2025-03-07 14:06:41 +08:00
Improved readability
This commit is contained in:
parent
d1adcd8909
commit
58de48547c
35
src/aabb.js
35
src/aabb.js
@ -10,6 +10,7 @@ class AABB {
|
||||
this.b = Vector3.add(centre, Vector3.mulScalar(size, 0.5));
|
||||
}
|
||||
|
||||
/*
|
||||
subdivide() {
|
||||
const newSize = Vector3.divScalar(this.size, 2);
|
||||
const offset = Vector3.divScalar(this.size, 4);
|
||||
@ -25,7 +26,39 @@ class AABB {
|
||||
new AABB(Vector3.add(this.centre, new Vector3( offset.x, offset.y, offset.z)), newSize),
|
||||
];
|
||||
}
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
module.exports.AABB = AABB;
|
||||
class CubeAABB extends AABB {
|
||||
|
||||
constructor(centre, width) {
|
||||
const sizeVector = new Vector3(width, width, width);
|
||||
super(centre, sizeVector);
|
||||
|
||||
this.width = width;
|
||||
|
||||
}
|
||||
|
||||
subdivide() {
|
||||
const newWidth = this.width / 2;
|
||||
const offset = this.width / 4;
|
||||
|
||||
return [
|
||||
new CubeAABB(Vector3.add(this.centre, new Vector3(-offset, -offset, -offset)), newWidth),
|
||||
new CubeAABB(Vector3.add(this.centre, new Vector3( offset, -offset, -offset)), newWidth),
|
||||
new CubeAABB(Vector3.add(this.centre, new Vector3(-offset, offset, -offset)), newWidth),
|
||||
new CubeAABB(Vector3.add(this.centre, new Vector3( offset, offset, -offset)), newWidth),
|
||||
new CubeAABB(Vector3.add(this.centre, new Vector3(-offset, -offset, offset)), newWidth),
|
||||
new CubeAABB(Vector3.add(this.centre, new Vector3( offset, -offset, offset)), newWidth),
|
||||
new CubeAABB(Vector3.add(this.centre, new Vector3(-offset, offset, offset)), newWidth),
|
||||
new CubeAABB(Vector3.add(this.centre, new Vector3( offset, offset, offset)), newWidth),
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
module.exports.AABB = AABB;
|
||||
module.exports.CubeAABB = CubeAABB;
|
@ -1,4 +1,4 @@
|
||||
const { AABB } = require("./aabb.js");
|
||||
const { AABB, CubeAABB } = require("./aabb.js");
|
||||
const { Vector3 } = require("./vector.js");
|
||||
|
||||
class VoxelManager {
|
||||
@ -32,11 +32,13 @@ class VoxelManager {
|
||||
gridSnappedCentre = Vector3.round(gridSnappedCentre);
|
||||
gridSnappedCentre = Vector3.mulScalar(gridSnappedCentre, this._voxelSize);
|
||||
|
||||
let size = this._voxelSize;
|
||||
let cubeAABB = new AABB(gridSnappedCentre, new Vector3(size, size, size));
|
||||
let width = this._voxelSize;
|
||||
//let cubeAABB = new AABB(gridSnappedCentre, new Vector3(size, size, size));
|
||||
let cubeAABB = new CubeAABB(gridSnappedCentre, width);
|
||||
|
||||
while (!triangle.insideAABB(cubeAABB)) {
|
||||
cubeAABB = new AABB(cubeAABB.centre, Vector3.mulScalar(cubeAABB.size, 2.0));
|
||||
//cubeAABB = new AABB(cubeAABB.centre, Vector3.mulScalar(cubeAABB.size, 2.0));
|
||||
cubeAABB = new CubeAABB(cubeAABB.centre, cubeAABB.width * 2.0);
|
||||
}
|
||||
|
||||
return cubeAABB;
|
||||
@ -51,8 +53,8 @@ class VoxelManager {
|
||||
while (queue.length > 0) {
|
||||
const aabb = queue.shift();
|
||||
if (triangle.intersectAABB(aabb)) {
|
||||
if (aabb.size.x > this._voxelSize) {
|
||||
// Continue to subdivicde
|
||||
if (aabb.width > this._voxelSize) {
|
||||
// Continue to subdivide
|
||||
queue.push(...aabb.subdivide());
|
||||
} else {
|
||||
// We've reached the voxel level, stop
|
||||
@ -60,24 +62,6 @@ class VoxelManager {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//console.log("Main AABB: ", cubeAABB);
|
||||
|
||||
/*
|
||||
const subAABBs = cubeAABB.subdivide();
|
||||
renderer.setStroke(new Vector3(1.0, 1.0, 0.0));
|
||||
|
||||
for (const subAABB of subAABBs) {
|
||||
if (triangle.intersectAABB(subAABB)) {
|
||||
renderer.registerBox(subAABB.centre, subAABB.size);
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
//const subAABB = subAABBs[0];
|
||||
//console.log("Sub AABB: ", subAABB);
|
||||
//console.log(triangle.intersectAABB(subAABB));
|
||||
//renderer.registerBox(subAABB.centre, subAABB.size);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user