mirror of
https://github.com/LucasDower/ObjToSchematic.git
synced 2025-03-07 14:06:41 +08:00
Better mesh centreing
This commit is contained in:
parent
a99fa2b452
commit
a99799d539
@ -1,6 +1,6 @@
|
|||||||
import { Vector3 } from './vector';
|
import { Vector3 } from './vector';
|
||||||
import { UV, Bounds, LOG, ASSERT, CustomError, LOG_WARN } from './util';
|
import { UV, Bounds, LOG, ASSERT, CustomError, LOG_WARN } from './util';
|
||||||
import { Triangle, UVTriangle } from './triangle';
|
import { UVTriangle } from './triangle';
|
||||||
import { RGB } from './util';
|
import { RGB } from './util';
|
||||||
import { AppContext } from './app_context';
|
import { AppContext } from './app_context';
|
||||||
|
|
||||||
@ -126,6 +126,7 @@ export class Mesh {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private _centreMesh() {
|
private _centreMesh() {
|
||||||
|
/*
|
||||||
const centre = new Vector3(0, 0, 0);
|
const centre = new Vector3(0, 0, 0);
|
||||||
let totalWeight = 0.0;
|
let totalWeight = 0.0;
|
||||||
|
|
||||||
@ -139,7 +140,9 @@ export class Mesh {
|
|||||||
centre.add(triangle.getCentre().mulScalar(weight));
|
centre.add(triangle.getCentre().mulScalar(weight));
|
||||||
});
|
});
|
||||||
centre.divScalar(totalWeight);
|
centre.divScalar(totalWeight);
|
||||||
|
*/
|
||||||
|
const centre = this.getBounds().getCentre();
|
||||||
|
|
||||||
if (!centre.isNumber()) {
|
if (!centre.isNumber()) {
|
||||||
throw new CustomError('Could not find centre of mesh');
|
throw new CustomError('Could not find centre of mesh');
|
||||||
}
|
}
|
||||||
|
@ -117,6 +117,11 @@ export class Bounds {
|
|||||||
public get max() {
|
public get max() {
|
||||||
return this._max;
|
return this._max;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public getCentre() {
|
||||||
|
const extents = Vector3.sub(this._max, this._min).divScalar(2);
|
||||||
|
return Vector3.add(this.min, extents);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function ASSERT(condition: any, errorMessage = 'Assertion Failed'): asserts condition {
|
export function ASSERT(condition: any, errorMessage = 'Assertion Failed'): asserts condition {
|
||||||
|
Loading…
Reference in New Issue
Block a user