|
@@ -18920,7 +18920,6 @@ var BABYLON;
|
|
|
(function (BABYLON) {
|
|
|
// This matrix is used as a value to reset the bounding box.
|
|
|
var _identityMatrix = BABYLON.Matrix.Identity();
|
|
|
- var _tempRadiusVector = new BABYLON.Vector3(0, 0, 0);
|
|
|
/**
|
|
|
* Class used to store bounding sphere information
|
|
|
*/
|
|
@@ -18933,6 +18932,8 @@ var BABYLON;
|
|
|
function BoundingSphere(min, max) {
|
|
|
this.center = BABYLON.Vector3.Zero();
|
|
|
this.centerWorld = BABYLON.Vector3.Zero();
|
|
|
+ this.minimum = BABYLON.Vector3.Zero();
|
|
|
+ this.maximum = BABYLON.Vector3.Zero();
|
|
|
this.reConstruct(min, max);
|
|
|
}
|
|
|
/**
|
|
@@ -18941,8 +18942,8 @@ var BABYLON;
|
|
|
* @param max defines the new maximum vector (in local space)
|
|
|
*/
|
|
|
BoundingSphere.prototype.reConstruct = function (min, max) {
|
|
|
- this.minimum = min.clone();
|
|
|
- this.maximum = max.clone();
|
|
|
+ this.minimum.copyFrom(min);
|
|
|
+ this.maximum.copyFrom(max);
|
|
|
var distance = BABYLON.Vector3.Distance(min, max);
|
|
|
BABYLON.Vector3.LerpToRef(min, max, 0.5, this.center);
|
|
|
this.radius = distance * 0.5;
|
|
@@ -18956,9 +18957,9 @@ var BABYLON;
|
|
|
*/
|
|
|
BoundingSphere.prototype.scale = function (factor) {
|
|
|
var newRadius = this.radius * factor;
|
|
|
- _tempRadiusVector.set(newRadius, newRadius, newRadius);
|
|
|
- var min = this.center.subtract(_tempRadiusVector);
|
|
|
- var max = this.center.add(_tempRadiusVector);
|
|
|
+ var tempRadiusVector = BABYLON.Tmp.Vector3[0].set(newRadius, newRadius, newRadius);
|
|
|
+ var min = BABYLON.Tmp.Vector3[1].copyFrom(this.center).subtractInPlace(tempRadiusVector);
|
|
|
+ var max = BABYLON.Tmp.Vector3[2].copyFrom(this.center).addInPlace(tempRadiusVector);
|
|
|
this.reConstruct(min, max);
|
|
|
return this;
|
|
|
};
|
|
@@ -18966,8 +18967,9 @@ var BABYLON;
|
|
|
/** @hidden */
|
|
|
BoundingSphere.prototype._update = function (world) {
|
|
|
BABYLON.Vector3.TransformCoordinatesToRef(this.center, world, this.centerWorld);
|
|
|
- BABYLON.Vector3.TransformNormalFromFloatsToRef(1.0, 1.0, 1.0, world, _tempRadiusVector);
|
|
|
- this.radiusWorld = Math.max(Math.abs(_tempRadiusVector.x), Math.abs(_tempRadiusVector.y), Math.abs(_tempRadiusVector.z)) * this.radius;
|
|
|
+ var tempVector = BABYLON.Tmp.Vector3[0];
|
|
|
+ BABYLON.Vector3.TransformNormalFromFloatsToRef(1.0, 1.0, 1.0, world, tempVector);
|
|
|
+ this.radiusWorld = Math.max(Math.abs(tempVector.x), Math.abs(tempVector.y), Math.abs(tempVector.z)) * this.radius;
|
|
|
};
|
|
|
/**
|
|
|
* Tests if the bounding sphere is intersecting the frustum planes
|
|
@@ -19031,11 +19033,52 @@ var BABYLON;
|
|
|
*/
|
|
|
function BoundingBox(min, max) {
|
|
|
/**
|
|
|
+ * Gets the 8 vectors representing the bounding box in local space
|
|
|
+ */
|
|
|
+ this.vectors = [BABYLON.Vector3.Zero(), BABYLON.Vector3.Zero(), BABYLON.Vector3.Zero(), BABYLON.Vector3.Zero(), BABYLON.Vector3.Zero(), BABYLON.Vector3.Zero(), BABYLON.Vector3.Zero(), BABYLON.Vector3.Zero()];
|
|
|
+ /**
|
|
|
+ * Gets the center of the bounding box in local space
|
|
|
+ */
|
|
|
+ this.center = BABYLON.Vector3.Zero();
|
|
|
+ /**
|
|
|
+ * Gets the center of the bounding box in world space
|
|
|
+ */
|
|
|
+ this.centerWorld = BABYLON.Vector3.Zero();
|
|
|
+ /**
|
|
|
+ * Gets the extend size in local space
|
|
|
+ */
|
|
|
+ this.extendSize = BABYLON.Vector3.Zero();
|
|
|
+ /**
|
|
|
+ * Gets the extend size in world space
|
|
|
+ */
|
|
|
+ this.extendSizeWorld = BABYLON.Vector3.Zero();
|
|
|
+ /**
|
|
|
+ * Gets the OBB (object bounding box) directions
|
|
|
+ */
|
|
|
+ this.directions = [BABYLON.Vector3.Zero(), BABYLON.Vector3.Zero(), BABYLON.Vector3.Zero()];
|
|
|
+ /**
|
|
|
* Gets the 8 vectors representing the bounding box in world space
|
|
|
*/
|
|
|
- this.vectorsWorld = new Array();
|
|
|
+ this.vectorsWorld = [BABYLON.Vector3.Zero(), BABYLON.Vector3.Zero(), BABYLON.Vector3.Zero(), BABYLON.Vector3.Zero(), BABYLON.Vector3.Zero(), BABYLON.Vector3.Zero(), BABYLON.Vector3.Zero(), BABYLON.Vector3.Zero()];
|
|
|
+ /**
|
|
|
+ * Gets the minimum vector in world space
|
|
|
+ */
|
|
|
+ this.minimumWorld = BABYLON.Vector3.Zero();
|
|
|
+ /**
|
|
|
+ * Gets the maximum vector in world space
|
|
|
+ */
|
|
|
+ this.maximumWorld = BABYLON.Vector3.Zero();
|
|
|
+ /**
|
|
|
+ * Gets the minimum vector in local space
|
|
|
+ */
|
|
|
+ this.minimum = BABYLON.Vector3.Zero();
|
|
|
+ /**
|
|
|
+ * Gets the maximum vector in local space
|
|
|
+ */
|
|
|
+ this.maximum = BABYLON.Vector3.Zero();
|
|
|
this.reConstruct(min, max);
|
|
|
}
|
|
|
+ ;
|
|
|
// Methods
|
|
|
/**
|
|
|
* Recreates the entire bounding box from scratch
|
|
@@ -19043,19 +19086,17 @@ var BABYLON;
|
|
|
* @param max defines the new maximum vector (in local space)
|
|
|
*/
|
|
|
BoundingBox.prototype.reConstruct = function (min, max) {
|
|
|
- this.minimum = min.clone();
|
|
|
- this.maximum = max.clone();
|
|
|
+ this.minimum.copyFrom(min);
|
|
|
+ this.maximum.copyFrom(max);
|
|
|
// Bounding vectors
|
|
|
- this.vectors = [
|
|
|
- this.minimum.clone(),
|
|
|
- this.maximum.clone(),
|
|
|
- this.minimum.clone(),
|
|
|
- this.minimum.clone(),
|
|
|
- this.minimum.clone(),
|
|
|
- this.maximum.clone(),
|
|
|
- this.maximum.clone(),
|
|
|
- this.maximum.clone()
|
|
|
- ];
|
|
|
+ this.vectors[0].copyFrom(this.minimum);
|
|
|
+ this.vectors[1].copyFrom(this.maximum);
|
|
|
+ this.vectors[2].copyFrom(this.minimum);
|
|
|
+ this.vectors[3].copyFrom(this.minimum);
|
|
|
+ this.vectors[4].copyFrom(this.minimum);
|
|
|
+ this.vectors[5].copyFrom(this.maximum);
|
|
|
+ this.vectors[6].copyFrom(this.maximum);
|
|
|
+ this.vectors[7].copyFrom(this.maximum);
|
|
|
this.vectors[2].x = this.maximum.x;
|
|
|
this.vectors[3].y = this.maximum.y;
|
|
|
this.vectors[4].z = this.maximum.z;
|
|
@@ -19063,17 +19104,19 @@ var BABYLON;
|
|
|
this.vectors[6].x = this.minimum.x;
|
|
|
this.vectors[7].y = this.minimum.y;
|
|
|
// OBB
|
|
|
- this.center = this.maximum.add(this.minimum).scale(0.5);
|
|
|
- this.extendSize = this.maximum.subtract(this.minimum).scale(0.5);
|
|
|
- this.directions = [BABYLON.Vector3.Zero(), BABYLON.Vector3.Zero(), BABYLON.Vector3.Zero()];
|
|
|
+ this.center.copyFrom(this.maximum).addInPlace(this.minimum).scaleInPlace(0.5);
|
|
|
+ this.extendSize.copyFrom(this.maximum).subtractInPlace(this.minimum).scaleInPlace(0.5);
|
|
|
+ for (var index = 0; index < 3; index++) {
|
|
|
+ this.directions[index].copyFromFloats(0, 0, 0);
|
|
|
+ }
|
|
|
// World
|
|
|
- for (var index = 0; index < this.vectors.length; index++) {
|
|
|
- this.vectorsWorld[index] = BABYLON.Vector3.Zero();
|
|
|
+ for (var index = 0; index < 8; index++) {
|
|
|
+ this.vectorsWorld[index].copyFromFloats(0, 0, 0);
|
|
|
}
|
|
|
- this.minimumWorld = BABYLON.Vector3.Zero();
|
|
|
- this.maximumWorld = BABYLON.Vector3.Zero();
|
|
|
- this.centerWorld = BABYLON.Vector3.Zero();
|
|
|
- this.extendSizeWorld = BABYLON.Vector3.Zero();
|
|
|
+ this.minimumWorld.copyFromFloats(0, 0, 0);
|
|
|
+ this.maximumWorld.copyFromFloats(0, 0, 0);
|
|
|
+ this.centerWorld.copyFromFloats(0, 0, 0);
|
|
|
+ this.extendSizeWorld.copyFromFloats(0, 0, 0);
|
|
|
this._update(this._worldMatrix || BABYLON.Matrix.Identity());
|
|
|
};
|
|
|
/**
|
|
@@ -19082,12 +19125,12 @@ var BABYLON;
|
|
|
* @returns the current bounding box
|
|
|
*/
|
|
|
BoundingBox.prototype.scale = function (factor) {
|
|
|
- var diff = this.maximum.subtract(this.minimum);
|
|
|
+ var diff = BABYLON.Tmp.Vector3[0].copyFrom(this.maximum).subtractInPlace(this.minimum);
|
|
|
var distance = diff.length() * factor;
|
|
|
diff.normalize();
|
|
|
- var newRadius = diff.scale(distance / 2);
|
|
|
- var min = this.center.subtract(newRadius);
|
|
|
- var max = this.center.add(newRadius);
|
|
|
+ var newRadius = diff.scaleInPlace(distance * 0.5);
|
|
|
+ var min = BABYLON.Tmp.Vector3[1].copyFrom(this.center).subtractInPlace(newRadius);
|
|
|
+ var max = BABYLON.Tmp.Vector3[2].copyFrom(this.center).addInPlace(newRadius);
|
|
|
this.reConstruct(min, max);
|
|
|
return this;
|
|
|
};
|
|
@@ -19111,21 +19154,11 @@ var BABYLON;
|
|
|
BoundingBox.prototype._update = function (world) {
|
|
|
BABYLON.Vector3.FromFloatsToRef(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE, this.minimumWorld);
|
|
|
BABYLON.Vector3.FromFloatsToRef(-Number.MAX_VALUE, -Number.MAX_VALUE, -Number.MAX_VALUE, this.maximumWorld);
|
|
|
- for (var index = 0; index < this.vectors.length; index++) {
|
|
|
+ for (var index = 0; index < 8; index++) {
|
|
|
var v = this.vectorsWorld[index];
|
|
|
BABYLON.Vector3.TransformCoordinatesToRef(this.vectors[index], world, v);
|
|
|
- if (v.x < this.minimumWorld.x)
|
|
|
- this.minimumWorld.x = v.x;
|
|
|
- if (v.y < this.minimumWorld.y)
|
|
|
- this.minimumWorld.y = v.y;
|
|
|
- if (v.z < this.minimumWorld.z)
|
|
|
- this.minimumWorld.z = v.z;
|
|
|
- if (v.x > this.maximumWorld.x)
|
|
|
- this.maximumWorld.x = v.x;
|
|
|
- if (v.y > this.maximumWorld.y)
|
|
|
- this.maximumWorld.y = v.y;
|
|
|
- if (v.z > this.maximumWorld.z)
|
|
|
- this.maximumWorld.z = v.z;
|
|
|
+ this.minimumWorld.minimizeInPlace(v);
|
|
|
+ this.maximumWorld.maximizeInPlace(v);
|
|
|
}
|
|
|
// Extend
|
|
|
this.maximumWorld.subtractToRef(this.minimumWorld, this.extendSizeWorld);
|
|
@@ -19294,21 +19327,31 @@ var BABYLON;
|
|
|
* @param minimum min vector of the bounding box/sphere
|
|
|
* @param maximum max vector of the bounding box/sphere
|
|
|
*/
|
|
|
- function BoundingInfo(
|
|
|
- /**
|
|
|
- * min vector of the bounding box/sphere
|
|
|
- */
|
|
|
- minimum,
|
|
|
- /**
|
|
|
- * max vector of the bounding box/sphere
|
|
|
- */
|
|
|
- maximum) {
|
|
|
- this.minimum = minimum;
|
|
|
- this.maximum = maximum;
|
|
|
+ function BoundingInfo(minimum, maximum) {
|
|
|
this._isLocked = false;
|
|
|
this.boundingBox = new BABYLON.BoundingBox(minimum, maximum);
|
|
|
this.boundingSphere = new BABYLON.BoundingSphere(minimum, maximum);
|
|
|
}
|
|
|
+ Object.defineProperty(BoundingInfo.prototype, "minimum", {
|
|
|
+ /**
|
|
|
+ * min vector of the bounding box/sphere
|
|
|
+ */
|
|
|
+ get: function () {
|
|
|
+ return this.boundingBox.minimum;
|
|
|
+ },
|
|
|
+ enumerable: true,
|
|
|
+ configurable: true
|
|
|
+ });
|
|
|
+ Object.defineProperty(BoundingInfo.prototype, "maximum", {
|
|
|
+ /**
|
|
|
+ * max vector of the bounding box/sphere
|
|
|
+ */
|
|
|
+ get: function () {
|
|
|
+ return this.boundingBox.maximum;
|
|
|
+ },
|
|
|
+ enumerable: true,
|
|
|
+ configurable: true
|
|
|
+ });
|
|
|
Object.defineProperty(BoundingInfo.prototype, "isLocked", {
|
|
|
/**
|
|
|
* If the info is locked and won't be updated to avoid perf overhead
|
|
@@ -19341,10 +19384,10 @@ var BABYLON;
|
|
|
* @returns the current bounding info
|
|
|
*/
|
|
|
BoundingInfo.prototype.centerOn = function (center, extend) {
|
|
|
- this.minimum = center.subtract(extend);
|
|
|
- this.maximum = center.add(extend);
|
|
|
- this.boundingBox = new BABYLON.BoundingBox(this.minimum, this.maximum);
|
|
|
- this.boundingSphere = new BABYLON.BoundingSphere(this.minimum, this.maximum);
|
|
|
+ var minimum = BABYLON.Tmp.Vector3[0].copyFrom(center).subtractInPlace(extend);
|
|
|
+ var maximum = BABYLON.Tmp.Vector3[1].copyFrom(center).addInPlace(extend);
|
|
|
+ this.boundingBox.reConstruct(minimum, maximum);
|
|
|
+ this.boundingSphere.reConstruct(minimum, maximum);
|
|
|
return this;
|
|
|
};
|
|
|
/**
|
|
@@ -20580,9 +20623,6 @@ var BABYLON;
|
|
|
* @see https://www.babylonjs-playground.com/#10OJSG#13
|
|
|
*/
|
|
|
_this.edgesColor = new BABYLON.Color4(1, 0, 0, 1);
|
|
|
- // Cache
|
|
|
- _this._collisionsTransformMatrix = BABYLON.Matrix.Zero();
|
|
|
- _this._collisionsScalingMatrix = BABYLON.Matrix.Zero();
|
|
|
/** @hidden */
|
|
|
_this._renderId = 0;
|
|
|
/** @hidden */
|
|
@@ -21601,9 +21641,11 @@ var BABYLON;
|
|
|
if (!this._boundingInfo || !this._boundingInfo._checkCollision(collider))
|
|
|
return this;
|
|
|
// Transformation matrix
|
|
|
- BABYLON.Matrix.ScalingToRef(1.0 / collider._radius.x, 1.0 / collider._radius.y, 1.0 / collider._radius.z, this._collisionsScalingMatrix);
|
|
|
- this.worldMatrixFromCache.multiplyToRef(this._collisionsScalingMatrix, this._collisionsTransformMatrix);
|
|
|
- this._processCollisionsForSubMeshes(collider, this._collisionsTransformMatrix);
|
|
|
+ var collisionsScalingMatrix = BABYLON.Tmp.Matrix[0];
|
|
|
+ var collisionsTransformMatrix = BABYLON.Tmp.Matrix[1];
|
|
|
+ BABYLON.Matrix.ScalingToRef(1.0 / collider._radius.x, 1.0 / collider._radius.y, 1.0 / collider._radius.z, collisionsScalingMatrix);
|
|
|
+ this.worldMatrixFromCache.multiplyToRef(collisionsScalingMatrix, collisionsTransformMatrix);
|
|
|
+ this._processCollisionsForSubMeshes(collider, collisionsTransformMatrix);
|
|
|
return this;
|
|
|
};
|
|
|
// Picking
|