|
@@ -7,9 +7,11 @@ import { Vector3 } from "../Maths/math";
|
|
export class MeshExploder {
|
|
export class MeshExploder {
|
|
private _centerMesh: Mesh;
|
|
private _centerMesh: Mesh;
|
|
private _meshes: Array<Mesh>;
|
|
private _meshes: Array<Mesh>;
|
|
- private _meshesOrigins: Array<Vector3> = [];
|
|
|
|
- private _toCenterVectors: Array<Vector3> = [];
|
|
|
|
|
|
+ private _meshesOrigins: Array<Vector3>;
|
|
|
|
+ private _toCenterVectors: Array<Vector3>;
|
|
private _scaledDirection = new Vector3(0.0, 0.0, 0.0);
|
|
private _scaledDirection = new Vector3(0.0, 0.0, 0.0);
|
|
|
|
+ private _newPosition = new Vector3(0.0, 0.0, 0.0);
|
|
|
|
+ private _centerPosition = new Vector3(0.0, 0.0, 0.0);
|
|
|
|
|
|
/**
|
|
/**
|
|
* Explodes meshes from a center mesh.
|
|
* Explodes meshes from a center mesh.
|
|
@@ -25,18 +27,19 @@ export class MeshExploder {
|
|
} else {
|
|
} else {
|
|
this._setCenterMesh();
|
|
this._setCenterMesh();
|
|
}
|
|
}
|
|
- this._centerMesh.computeWorldMatrix();
|
|
|
|
|
|
+ this._centerPosition = this._centerMesh.getAbsolutePosition().clone();
|
|
if (this._meshes.indexOf(this._centerMesh) >= 0) {
|
|
if (this._meshes.indexOf(this._centerMesh) >= 0) {
|
|
this._meshes.splice(this._meshes.indexOf(this._centerMesh), 1);
|
|
this._meshes.splice(this._meshes.indexOf(this._centerMesh), 1);
|
|
}
|
|
}
|
|
if (this._meshes.length > 1 && this._centerMesh._boundingInfo) {
|
|
if (this._meshes.length > 1 && this._centerMesh._boundingInfo) {
|
|
|
|
+ this._meshesOrigins = [];
|
|
|
|
+ this._toCenterVectors = [];
|
|
for (var index = 0; index < this._meshes.length; index++) {
|
|
for (var index = 0; index < this._meshes.length; index++) {
|
|
if (this._meshes[index]) {
|
|
if (this._meshes[index]) {
|
|
var mesh = this._meshes[index];
|
|
var mesh = this._meshes[index];
|
|
- mesh.computeWorldMatrix();
|
|
|
|
if (mesh._boundingInfo) {
|
|
if (mesh._boundingInfo) {
|
|
- this._meshesOrigins.push(mesh.position.clone());
|
|
|
|
- this._toCenterVectors.push(mesh._boundingInfo.boundingBox.centerWorld.subtract(this._centerMesh._boundingInfo.boundingBox.centerWorld));
|
|
|
|
|
|
+ this._meshesOrigins.push(mesh.getAbsolutePosition().clone());
|
|
|
|
+ this._toCenterVectors.push(mesh._boundingInfo.boundingBox.centerWorld.subtract(this._centerPosition));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -97,8 +100,11 @@ export class MeshExploder {
|
|
for (var index = 0; index < this._meshes.length; index++) {
|
|
for (var index = 0; index < this._meshes.length; index++) {
|
|
if (this._meshes[index] && this._toCenterVectors[index]) {
|
|
if (this._meshes[index] && this._toCenterVectors[index]) {
|
|
this._toCenterVectors[index].scaleToRef(direction, this._scaledDirection);
|
|
this._toCenterVectors[index].scaleToRef(direction, this._scaledDirection);
|
|
- this._meshesOrigins[index].addToRef(this._scaledDirection, this._meshes[index].position);
|
|
|
|
|
|
+ this._meshesOrigins[index].addToRef(this._scaledDirection, this._newPosition);
|
|
|
|
+ this._meshes[index].setAbsolutePosition(this._newPosition);
|
|
|
|
+ this._meshes[index].computeWorldMatrix();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ this._centerMesh.setAbsolutePosition(this._centerPosition);
|
|
}
|
|
}
|
|
}
|
|
}
|