|
@@ -50,7 +50,7 @@
|
|
return this._facetNb;
|
|
return this._facetNb;
|
|
}
|
|
}
|
|
/**
|
|
/**
|
|
- * The number of subdivisions per axis in the partioning space
|
|
|
|
|
|
+ * The number (integer) of subdivisions per axis in the partioning space
|
|
*/
|
|
*/
|
|
public get partitioningSubdivisions(): number {
|
|
public get partitioningSubdivisions(): number {
|
|
return this._partitioningSubdivisions;
|
|
return this._partitioningSubdivisions;
|
|
@@ -59,7 +59,7 @@
|
|
this._partitioningSubdivisions = nb;
|
|
this._partitioningSubdivisions = nb;
|
|
}
|
|
}
|
|
/**
|
|
/**
|
|
- * The ratio to apply to the bouding box size to set to the partioning space.
|
|
|
|
|
|
+ * The ratio (float) to apply to the bouding box size to set to the partioning space.
|
|
* Ex : 1.01 (default) the partioning space is 1% bigger than the bounding box.
|
|
* Ex : 1.01 (default) the partioning space is 1% bigger than the bounding box.
|
|
*/
|
|
*/
|
|
public get partitioningBBoxRatio(): number {
|
|
public get partitioningBBoxRatio(): number {
|
|
@@ -69,7 +69,7 @@
|
|
this._partitioningBBoxRatio = ratio;
|
|
this._partitioningBBoxRatio = ratio;
|
|
}
|
|
}
|
|
/**
|
|
/**
|
|
- * Read-only : is the feature facetData enabled ?
|
|
|
|
|
|
+ * Read-only boolean : is the feature facetData enabled ?
|
|
*/
|
|
*/
|
|
public get isFacetDataEnabled(): boolean {
|
|
public get isFacetDataEnabled(): boolean {
|
|
return this._facetDataEnabled;
|
|
return this._facetDataEnabled;
|
|
@@ -166,12 +166,22 @@
|
|
|
|
|
|
// Collisions
|
|
// Collisions
|
|
private _checkCollisions = false;
|
|
private _checkCollisions = false;
|
|
|
|
+ private _collisionMask = -1;
|
|
public ellipsoid = new Vector3(0.5, 1, 0.5);
|
|
public ellipsoid = new Vector3(0.5, 1, 0.5);
|
|
public ellipsoidOffset = new Vector3(0, 0, 0);
|
|
public ellipsoidOffset = new Vector3(0, 0, 0);
|
|
private _collider = new Collider();
|
|
private _collider = new Collider();
|
|
private _oldPositionForCollisions = new Vector3(0, 0, 0);
|
|
private _oldPositionForCollisions = new Vector3(0, 0, 0);
|
|
private _diffPositionForCollisions = new Vector3(0, 0, 0);
|
|
private _diffPositionForCollisions = new Vector3(0, 0, 0);
|
|
private _newPositionForCollisions = new Vector3(0, 0, 0);
|
|
private _newPositionForCollisions = new Vector3(0, 0, 0);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ public get collisionMask(): number {
|
|
|
|
+ return this._collisionMask;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public set collisionMask(mask: number) {
|
|
|
|
+ this._collisionMask = !isNaN(mask) ? mask : -1;
|
|
|
|
+ }
|
|
|
|
|
|
// Attach to bone
|
|
// Attach to bone
|
|
private _meshToBoneReferal: AbstractMesh;
|
|
private _meshToBoneReferal: AbstractMesh;
|
|
@@ -267,7 +277,7 @@
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * Ratation property : a Vector3 depicting the rotation value in radians around each local axis X, Y, Z.
|
|
|
|
|
|
+ * Rotation property : a Vector3 depicting the rotation value in radians around each local axis X, Y, Z.
|
|
* If rotation quaternion is set, this Vector3 will (almost always) be the Zero vector!
|
|
* If rotation quaternion is set, this Vector3 will (almost always) be the Zero vector!
|
|
* Default : (0.0, 0.0, 0.0)
|
|
* Default : (0.0, 0.0, 0.0)
|
|
*/
|
|
*/
|
|
@@ -312,32 +322,55 @@
|
|
}
|
|
}
|
|
|
|
|
|
// Methods
|
|
// Methods
|
|
- public updatePoseMatrix(matrix: Matrix) {
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Copies the paramater passed Matrix into the mesh Pose matrix.
|
|
|
|
+ * Returns the AbstractMesh.
|
|
|
|
+ */
|
|
|
|
+ public updatePoseMatrix(matrix: Matrix): AbstractMesh {
|
|
this._poseMatrix.copyFrom(matrix);
|
|
this._poseMatrix.copyFrom(matrix);
|
|
|
|
+ return this;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Returns the mesh Pose matrix.
|
|
|
|
+ * Returned object : Matrix
|
|
|
|
+ */
|
|
public getPoseMatrix(): Matrix {
|
|
public getPoseMatrix(): Matrix {
|
|
return this._poseMatrix;
|
|
return this._poseMatrix;
|
|
}
|
|
}
|
|
|
|
|
|
- public disableEdgesRendering(): void {
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Disables the mesh edger rendering mode.
|
|
|
|
+ * Returns the AbstractMesh.
|
|
|
|
+ */
|
|
|
|
+ public disableEdgesRendering(): AbstractMesh {
|
|
if (this._edgesRenderer !== undefined) {
|
|
if (this._edgesRenderer !== undefined) {
|
|
this._edgesRenderer.dispose();
|
|
this._edgesRenderer.dispose();
|
|
this._edgesRenderer = undefined;
|
|
this._edgesRenderer = undefined;
|
|
}
|
|
}
|
|
|
|
+ return this;
|
|
}
|
|
}
|
|
- public enableEdgesRendering(epsilon = 0.95, checkVerticesInsteadOfIndices = false) {
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Enables the edge rendering mode on the mesh.
|
|
|
|
+ * This mode makes the mesh edges visible.
|
|
|
|
+ * Returns the AbstractMesh.
|
|
|
|
+ */
|
|
|
|
+ public enableEdgesRendering(epsilon = 0.95, checkVerticesInsteadOfIndices = false): AbstractMesh {
|
|
this.disableEdgesRendering();
|
|
this.disableEdgesRendering();
|
|
-
|
|
|
|
this._edgesRenderer = new EdgesRenderer(this, epsilon, checkVerticesInsteadOfIndices);
|
|
this._edgesRenderer = new EdgesRenderer(this, epsilon, checkVerticesInsteadOfIndices);
|
|
|
|
+ return this;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Returns true if the mesh is blocked. Used by the class Mesh.
|
|
|
|
+ * Returns the boolean `false` by default.
|
|
|
|
+ */
|
|
public get isBlocked(): boolean {
|
|
public get isBlocked(): boolean {
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * Returns this by default, used by the class Mesh.
|
|
|
|
|
|
+ * Returns the mesh itself by default, used by the class Mesh.
|
|
* Returned type : AbstractMesh
|
|
* Returned type : AbstractMesh
|
|
*/
|
|
*/
|
|
public getLOD(camera: Camera): AbstractMesh {
|
|
public getLOD(camera: Camera): AbstractMesh {
|
|
@@ -392,10 +425,11 @@
|
|
|
|
|
|
/**
|
|
/**
|
|
* Sets a mesh new object BoundingInfo.
|
|
* Sets a mesh new object BoundingInfo.
|
|
- * Returns nothing.
|
|
|
|
|
|
+ * Returns the AbstractMesh.
|
|
*/
|
|
*/
|
|
- public setBoundingInfo(boundingInfo: BoundingInfo): void {
|
|
|
|
|
|
+ public setBoundingInfo(boundingInfo: BoundingInfo): AbstractMesh {
|
|
this._boundingInfo = boundingInfo;
|
|
this._boundingInfo = boundingInfo;
|
|
|
|
+ return this;
|
|
}
|
|
}
|
|
|
|
|
|
public get useBones(): boolean {
|
|
public get useBones(): boolean {
|
|
@@ -420,7 +454,6 @@
|
|
if (this._masterMesh) {
|
|
if (this._masterMesh) {
|
|
return this._masterMesh.getWorldMatrix();
|
|
return this._masterMesh.getWorldMatrix();
|
|
}
|
|
}
|
|
-
|
|
|
|
if (this._currentRenderId !== this.getScene().getRenderId()) {
|
|
if (this._currentRenderId !== this.getScene().getRenderId()) {
|
|
this.computeWorldMatrix();
|
|
this.computeWorldMatrix();
|
|
}
|
|
}
|
|
@@ -437,28 +470,30 @@
|
|
|
|
|
|
/**
|
|
/**
|
|
* Returns the current mesh absolute position.
|
|
* Returns the current mesh absolute position.
|
|
- * Retuns a Vector3
|
|
|
|
|
|
+ * Retuns a Vector3.
|
|
*/
|
|
*/
|
|
public get absolutePosition(): Vector3 {
|
|
public get absolutePosition(): Vector3 {
|
|
return this._absolutePosition;
|
|
return this._absolutePosition;
|
|
}
|
|
}
|
|
/**
|
|
/**
|
|
* Prevents the World matrix to be computed any longer.
|
|
* Prevents the World matrix to be computed any longer.
|
|
- * Returns nothing.
|
|
|
|
|
|
+ * Returns the AbstractMesh.
|
|
*/
|
|
*/
|
|
- public freezeWorldMatrix() {
|
|
|
|
|
|
+ public freezeWorldMatrix(): AbstractMesh {
|
|
this._isWorldMatrixFrozen = false; // no guarantee world is not already frozen, switch off temporarily
|
|
this._isWorldMatrixFrozen = false; // no guarantee world is not already frozen, switch off temporarily
|
|
this.computeWorldMatrix(true);
|
|
this.computeWorldMatrix(true);
|
|
this._isWorldMatrixFrozen = true;
|
|
this._isWorldMatrixFrozen = true;
|
|
|
|
+ return this;
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
* Allows back the World matrix computation.
|
|
* Allows back the World matrix computation.
|
|
- * Returns nothing.
|
|
|
|
|
|
+ * Returns the AbstractMesh.
|
|
*/
|
|
*/
|
|
public unfreezeWorldMatrix() {
|
|
public unfreezeWorldMatrix() {
|
|
this._isWorldMatrixFrozen = false;
|
|
this._isWorldMatrixFrozen = false;
|
|
this.computeWorldMatrix(true);
|
|
this.computeWorldMatrix(true);
|
|
|
|
+ return this;
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -472,11 +507,13 @@
|
|
private static _rotationAxisCache = new Quaternion();
|
|
private static _rotationAxisCache = new Quaternion();
|
|
/**
|
|
/**
|
|
* Rotates the mesh around the axis vector for the passed angle (amount) expressed in radians, in the given space.
|
|
* Rotates the mesh around the axis vector for the passed angle (amount) expressed in radians, in the given space.
|
|
- * space (default LOCAL) can be either BABYLON.Space.LOCAL, either BABYLON.Space.WORLD
|
|
|
|
|
|
+ * space (default LOCAL) can be either BABYLON.Space.LOCAL, either BABYLON.Space.WORLD.
|
|
|
|
+ * Note that the property `rotationQuaternion` is then automatically updated and the property `rotation` is set to (0,0,0) and no longer used.
|
|
|
|
+ * The passed axis is also normalized.
|
|
|
|
+ * Returns the AbstractMesh.
|
|
*/
|
|
*/
|
|
- public rotate(axis: Vector3, amount: number, space?: Space): void {
|
|
|
|
|
|
+ public rotate(axis: Vector3, amount: number, space?: Space): AbstractMesh {
|
|
axis.normalize();
|
|
axis.normalize();
|
|
-
|
|
|
|
if (!this.rotationQuaternion) {
|
|
if (!this.rotationQuaternion) {
|
|
this.rotationQuaternion = Quaternion.RotationYawPitchRoll(this.rotation.y, this.rotation.x, this.rotation.z);
|
|
this.rotationQuaternion = Quaternion.RotationYawPitchRoll(this.rotation.y, this.rotation.x, this.rotation.z);
|
|
this.rotation = Vector3.Zero();
|
|
this.rotation = Vector3.Zero();
|
|
@@ -490,21 +527,21 @@
|
|
if (this.parent) {
|
|
if (this.parent) {
|
|
var invertParentWorldMatrix = this.parent.getWorldMatrix().clone();
|
|
var invertParentWorldMatrix = this.parent.getWorldMatrix().clone();
|
|
invertParentWorldMatrix.invert();
|
|
invertParentWorldMatrix.invert();
|
|
-
|
|
|
|
axis = Vector3.TransformNormal(axis, invertParentWorldMatrix);
|
|
axis = Vector3.TransformNormal(axis, invertParentWorldMatrix);
|
|
}
|
|
}
|
|
rotationQuaternion = Quaternion.RotationAxisToRef(axis, amount, AbstractMesh._rotationAxisCache);
|
|
rotationQuaternion = Quaternion.RotationAxisToRef(axis, amount, AbstractMesh._rotationAxisCache);
|
|
rotationQuaternion.multiplyToRef(this.rotationQuaternion, this.rotationQuaternion);
|
|
rotationQuaternion.multiplyToRef(this.rotationQuaternion, this.rotationQuaternion);
|
|
}
|
|
}
|
|
|
|
+ return this;
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
* Translates the mesh along the axis vector for the passed distance in the given space.
|
|
* Translates the mesh along the axis vector for the passed distance in the given space.
|
|
- * space (default LOCAL) can be either BABYLON.Space.LOCAL, either BABYLON.Space.WORLD
|
|
|
|
|
|
+ * space (default LOCAL) can be either BABYLON.Space.LOCAL, either BABYLON.Space.WORLD.
|
|
|
|
+ * Returns the AbstractMesh.
|
|
*/
|
|
*/
|
|
- public translate(axis: Vector3, distance: number, space?: Space): void {
|
|
|
|
|
|
+ public translate(axis: Vector3, distance: number, space?: Space): AbstractMesh {
|
|
var displacementVector = axis.scale(distance);
|
|
var displacementVector = axis.scale(distance);
|
|
-
|
|
|
|
if (!space || (space as any) === Space.LOCAL) {
|
|
if (!space || (space as any) === Space.LOCAL) {
|
|
var tempV3 = this.getPositionExpressedInLocalSpace().add(displacementVector);
|
|
var tempV3 = this.getPositionExpressedInLocalSpace().add(displacementVector);
|
|
this.setPositionWithLocalVector(tempV3);
|
|
this.setPositionWithLocalVector(tempV3);
|
|
@@ -512,19 +549,22 @@
|
|
else {
|
|
else {
|
|
this.setAbsolutePosition(this.getAbsolutePosition().add(displacementVector));
|
|
this.setAbsolutePosition(this.getAbsolutePosition().add(displacementVector));
|
|
}
|
|
}
|
|
|
|
+ return this;
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
* Adds a rotation step to the mesh current rotation.
|
|
* Adds a rotation step to the mesh current rotation.
|
|
* x, y, z are Euler angles expressed in radians.
|
|
* x, y, z are Euler angles expressed in radians.
|
|
* This methods updates the current mesh rotation, either mesh.rotation, either mesh.rotationQuaternion if it's set.
|
|
* This methods updates the current mesh rotation, either mesh.rotation, either mesh.rotationQuaternion if it's set.
|
|
|
|
+ * This means this rotation is made in the mesh local space only.
|
|
* It's useful to set a custom rotation order different from the BJS standard one YXZ.
|
|
* It's useful to set a custom rotation order different from the BJS standard one YXZ.
|
|
* Example : this rotates the mesh first around its local X axis, then around its local Z axis, finally around its local Y axis.
|
|
* Example : this rotates the mesh first around its local X axis, then around its local Z axis, finally around its local Y axis.
|
|
* ```javascript
|
|
* ```javascript
|
|
* mesh.addRotation(x1, 0, 0).addRotation(0, 0, z2).addRotation(0, 0, y3);
|
|
* mesh.addRotation(x1, 0, 0).addRotation(0, 0, z2).addRotation(0, 0, y3);
|
|
* ```
|
|
* ```
|
|
* Note that `addRotation()` accumulates the passed rotation values to the current ones and computes the .rotation or .rotationQuaternion updated values.
|
|
* Note that `addRotation()` accumulates the passed rotation values to the current ones and computes the .rotation or .rotationQuaternion updated values.
|
|
- * Under the hood, only quaternions are used. So it's a little faster is you use .rotationQuaternion because it doesn't need to translate them back to Euler angles.
|
|
|
|
|
|
+ * Under the hood, only quaternions are used. So it's a little faster is you use .rotationQuaternion because it doesn't need to translate them back to Euler angles.
|
|
|
|
+ * Returns the AbstractMesh.
|
|
*/
|
|
*/
|
|
public addRotation(x: number, y: number, z: number): AbstractMesh {
|
|
public addRotation(x: number, y: number, z: number): AbstractMesh {
|
|
var rotationQuaternion;
|
|
var rotationQuaternion;
|
|
@@ -544,20 +584,26 @@
|
|
return this;
|
|
return this;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Retuns the mesh absolute position in the World.
|
|
|
|
+ * Returns a Vector3.
|
|
|
|
+ */
|
|
public getAbsolutePosition(): Vector3 {
|
|
public getAbsolutePosition(): Vector3 {
|
|
this.computeWorldMatrix();
|
|
this.computeWorldMatrix();
|
|
return this._absolutePosition;
|
|
return this._absolutePosition;
|
|
}
|
|
}
|
|
|
|
|
|
- public setAbsolutePosition(absolutePosition: Vector3): void {
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Sets the mesh absolute position in the World from a Vector3 or an Array(3).
|
|
|
|
+ * Returns the AbstractMesh.
|
|
|
|
+ */
|
|
|
|
+ public setAbsolutePosition(absolutePosition: Vector3): AbstractMesh {
|
|
if (!absolutePosition) {
|
|
if (!absolutePosition) {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
-
|
|
|
|
var absolutePositionX;
|
|
var absolutePositionX;
|
|
var absolutePositionY;
|
|
var absolutePositionY;
|
|
var absolutePositionZ;
|
|
var absolutePositionZ;
|
|
-
|
|
|
|
if (absolutePosition.x === undefined) {
|
|
if (absolutePosition.x === undefined) {
|
|
if (arguments.length < 3) {
|
|
if (arguments.length < 3) {
|
|
return;
|
|
return;
|
|
@@ -571,20 +617,19 @@
|
|
absolutePositionY = absolutePosition.y;
|
|
absolutePositionY = absolutePosition.y;
|
|
absolutePositionZ = absolutePosition.z;
|
|
absolutePositionZ = absolutePosition.z;
|
|
}
|
|
}
|
|
-
|
|
|
|
if (this.parent) {
|
|
if (this.parent) {
|
|
var invertParentWorldMatrix = this.parent.getWorldMatrix().clone();
|
|
var invertParentWorldMatrix = this.parent.getWorldMatrix().clone();
|
|
invertParentWorldMatrix.invert();
|
|
invertParentWorldMatrix.invert();
|
|
-
|
|
|
|
var worldPosition = new Vector3(absolutePositionX, absolutePositionY, absolutePositionZ);
|
|
var worldPosition = new Vector3(absolutePositionX, absolutePositionY, absolutePositionZ);
|
|
-
|
|
|
|
this.position = Vector3.TransformCoordinates(worldPosition, invertParentWorldMatrix);
|
|
this.position = Vector3.TransformCoordinates(worldPosition, invertParentWorldMatrix);
|
|
} else {
|
|
} else {
|
|
this.position.x = absolutePositionX;
|
|
this.position.x = absolutePositionX;
|
|
this.position.y = absolutePositionY;
|
|
this.position.y = absolutePositionY;
|
|
this.position.z = absolutePositionZ;
|
|
this.position.z = absolutePositionZ;
|
|
}
|
|
}
|
|
|
|
+ return this;
|
|
}
|
|
}
|
|
|
|
+
|
|
// ================================== Point of View Movement =================================
|
|
// ================================== Point of View Movement =================================
|
|
/**
|
|
/**
|
|
* Perform relative position change from the point of view of behind the front of the mesh.
|
|
* Perform relative position change from the point of view of behind the front of the mesh.
|
|
@@ -593,9 +638,12 @@
|
|
* @param {number} amountRight
|
|
* @param {number} amountRight
|
|
* @param {number} amountUp
|
|
* @param {number} amountUp
|
|
* @param {number} amountForward
|
|
* @param {number} amountForward
|
|
|
|
+ *
|
|
|
|
+ * Returns the AbstractMesh.
|
|
*/
|
|
*/
|
|
- public movePOV(amountRight: number, amountUp: number, amountForward: number): void {
|
|
|
|
|
|
+ public movePOV(amountRight: number, amountUp: number, amountForward: number): AbstractMesh {
|
|
this.position.addInPlace(this.calcMovePOV(amountRight, amountUp, amountForward));
|
|
this.position.addInPlace(this.calcMovePOV(amountRight, amountUp, amountForward));
|
|
|
|
+ return this;
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -604,7 +652,9 @@
|
|
* Supports definition of mesh facing forward or backward.
|
|
* Supports definition of mesh facing forward or backward.
|
|
* @param {number} amountRight
|
|
* @param {number} amountRight
|
|
* @param {number} amountUp
|
|
* @param {number} amountUp
|
|
- * @param {number} amountForward
|
|
|
|
|
|
+ * @param {number} amountForward
|
|
|
|
+ *
|
|
|
|
+ * Returns a new Vector3.
|
|
*/
|
|
*/
|
|
public calcMovePOV(amountRight: number, amountUp: number, amountForward: number): Vector3 {
|
|
public calcMovePOV(amountRight: number, amountUp: number, amountForward: number): Vector3 {
|
|
var rotMatrix = new Matrix();
|
|
var rotMatrix = new Matrix();
|
|
@@ -623,9 +673,12 @@
|
|
* @param {number} flipBack
|
|
* @param {number} flipBack
|
|
* @param {number} twirlClockwise
|
|
* @param {number} twirlClockwise
|
|
* @param {number} tiltRight
|
|
* @param {number} tiltRight
|
|
|
|
+ *
|
|
|
|
+ * Returns the AbstractMesh.
|
|
*/
|
|
*/
|
|
- public rotatePOV(flipBack: number, twirlClockwise: number, tiltRight: number): void {
|
|
|
|
|
|
+ public rotatePOV(flipBack: number, twirlClockwise: number, tiltRight: number): AbstractMesh {
|
|
this.rotation.addInPlace(this.calcRotatePOV(flipBack, twirlClockwise, tiltRight));
|
|
this.rotation.addInPlace(this.calcRotatePOV(flipBack, twirlClockwise, tiltRight));
|
|
|
|
+ return this;
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -634,6 +687,8 @@
|
|
* @param {number} flipBack
|
|
* @param {number} flipBack
|
|
* @param {number} twirlClockwise
|
|
* @param {number} twirlClockwise
|
|
* @param {number} tiltRight
|
|
* @param {number} tiltRight
|
|
|
|
+ *
|
|
|
|
+ * Returns a new Vector3.
|
|
*/
|
|
*/
|
|
public calcRotatePOV(flipBack: number, twirlClockwise: number, tiltRight: number): Vector3 {
|
|
public calcRotatePOV(flipBack: number, twirlClockwise: number, tiltRight: number): Vector3 {
|
|
var defForwardMult = this.definedFacingForward ? 1 : -1;
|
|
var defForwardMult = this.definedFacingForward ? 1 : -1;
|
|
@@ -642,11 +697,12 @@
|
|
|
|
|
|
/**
|
|
/**
|
|
* Sets a new pivot matrix to the mesh.
|
|
* Sets a new pivot matrix to the mesh.
|
|
- * Returns nothing.
|
|
|
|
|
|
+ * Returns the AbstractMesh.
|
|
*/
|
|
*/
|
|
- public setPivotMatrix(matrix: Matrix): void {
|
|
|
|
|
|
+ public setPivotMatrix(matrix: Matrix): AbstractMesh {
|
|
this._pivotMatrix = matrix;
|
|
this._pivotMatrix = matrix;
|
|
this._cache.pivotMatrixUpdated = true;
|
|
this._cache.pivotMatrixUpdated = true;
|
|
|
|
+ return this;
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -702,34 +758,41 @@
|
|
this._cache.billboardMode = -1;
|
|
this._cache.billboardMode = -1;
|
|
}
|
|
}
|
|
|
|
|
|
- public markAsDirty(property: string): void {
|
|
|
|
|
|
+ public markAsDirty(property: string): AbstractMesh {
|
|
if (property === "rotation") {
|
|
if (property === "rotation") {
|
|
this.rotationQuaternion = null;
|
|
this.rotationQuaternion = null;
|
|
}
|
|
}
|
|
this._currentRenderId = Number.MAX_VALUE;
|
|
this._currentRenderId = Number.MAX_VALUE;
|
|
this._isDirty = true;
|
|
this._isDirty = true;
|
|
|
|
+ return this;
|
|
}
|
|
}
|
|
|
|
|
|
- public _updateBoundingInfo(): void {
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Updates the mesh BoundingInfo object and all its children BoundingInfo objects also.
|
|
|
|
+ * Returns the AbstractMesh.
|
|
|
|
+ */
|
|
|
|
+ public _updateBoundingInfo(): AbstractMesh {
|
|
this._boundingInfo = this._boundingInfo || new BoundingInfo(this.absolutePosition, this.absolutePosition);
|
|
this._boundingInfo = this._boundingInfo || new BoundingInfo(this.absolutePosition, this.absolutePosition);
|
|
-
|
|
|
|
this._boundingInfo.update(this.worldMatrixFromCache);
|
|
this._boundingInfo.update(this.worldMatrixFromCache);
|
|
-
|
|
|
|
this._updateSubMeshesBoundingInfo(this.worldMatrixFromCache);
|
|
this._updateSubMeshesBoundingInfo(this.worldMatrixFromCache);
|
|
|
|
+ return this;
|
|
}
|
|
}
|
|
|
|
|
|
- public _updateSubMeshesBoundingInfo(matrix: Matrix): void {
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Update a mesh's children BoundingInfo objects only.
|
|
|
|
+ * Returns the AbstractMesh.
|
|
|
|
+ */
|
|
|
|
+ public _updateSubMeshesBoundingInfo(matrix: Matrix): AbstractMesh {
|
|
if (!this.subMeshes) {
|
|
if (!this.subMeshes) {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
-
|
|
|
|
for (var subIndex = 0; subIndex < this.subMeshes.length; subIndex++) {
|
|
for (var subIndex = 0; subIndex < this.subMeshes.length; subIndex++) {
|
|
var subMesh = this.subMeshes[subIndex];
|
|
var subMesh = this.subMeshes[subIndex];
|
|
-
|
|
|
|
if (!subMesh.IsGlobal) {
|
|
if (!subMesh.IsGlobal) {
|
|
subMesh.updateBoundingInfo(matrix);
|
|
subMesh.updateBoundingInfo(matrix);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ return this;
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -876,24 +939,33 @@
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * If you'd like to be called back after the mesh position, rotation or scaling has been updated
|
|
|
|
|
|
+ * If you'd like to be called back after the mesh position, rotation or scaling has been updated.
|
|
* @param func: callback function to add
|
|
* @param func: callback function to add
|
|
|
|
+ *
|
|
|
|
+ * Returns the AbstractMesh.
|
|
*/
|
|
*/
|
|
- public registerAfterWorldMatrixUpdate(func: (mesh: AbstractMesh) => void): void {
|
|
|
|
|
|
+ public registerAfterWorldMatrixUpdate(func: (mesh: AbstractMesh) => void): AbstractMesh {
|
|
this.onAfterWorldMatrixUpdateObservable.add(func);
|
|
this.onAfterWorldMatrixUpdateObservable.add(func);
|
|
|
|
+ return this;
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * Removes a registered callback function
|
|
|
|
|
|
+ * Removes a registered callback function.
|
|
|
|
+ * Returns the AbstractMesh.
|
|
*/
|
|
*/
|
|
- public unregisterAfterWorldMatrixUpdate(func: (mesh: AbstractMesh) => void): void {
|
|
|
|
|
|
+ public unregisterAfterWorldMatrixUpdate(func: (mesh: AbstractMesh) => void): AbstractMesh {
|
|
this.onAfterWorldMatrixUpdateObservable.removeCallback(func);
|
|
this.onAfterWorldMatrixUpdateObservable.removeCallback(func);
|
|
|
|
+ return this;
|
|
}
|
|
}
|
|
|
|
|
|
- public setPositionWithLocalVector(vector3: Vector3): void {
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Sets the mesh position in its local space.
|
|
|
|
+ * Returns the AbstractMesh.
|
|
|
|
+ */
|
|
|
|
+ public setPositionWithLocalVector(vector3: Vector3): AbstractMesh {
|
|
this.computeWorldMatrix();
|
|
this.computeWorldMatrix();
|
|
-
|
|
|
|
this.position = Vector3.TransformNormal(vector3, this._localWorld);
|
|
this.position = Vector3.TransformNormal(vector3, this._localWorld);
|
|
|
|
+ return this;
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -908,14 +980,18 @@
|
|
return Vector3.TransformNormal(this.position, invLocalWorldMatrix);
|
|
return Vector3.TransformNormal(this.position, invLocalWorldMatrix);
|
|
}
|
|
}
|
|
|
|
|
|
- public locallyTranslate(vector3: Vector3): void {
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Translates the mesh along the passed Vector3 in its local space.
|
|
|
|
+ * Returns the AbstractMesh.
|
|
|
|
+ */
|
|
|
|
+ public locallyTranslate(vector3: Vector3): AbstractMesh {
|
|
this.computeWorldMatrix(true);
|
|
this.computeWorldMatrix(true);
|
|
-
|
|
|
|
this.position = Vector3.TransformCoordinates(vector3, this._localWorld);
|
|
this.position = Vector3.TransformCoordinates(vector3, this._localWorld);
|
|
|
|
+ return this;
|
|
}
|
|
}
|
|
|
|
|
|
private static _lookAtVectorCache = new Vector3(0, 0, 0);
|
|
private static _lookAtVectorCache = new Vector3(0, 0, 0);
|
|
- public lookAt(targetPoint: Vector3, yawCor: number = 0, pitchCor: number = 0, rollCor: number = 0, space: Space = Space.LOCAL): void {
|
|
|
|
|
|
+ public lookAt(targetPoint: Vector3, yawCor: number = 0, pitchCor: number = 0, rollCor: number = 0, space: Space = Space.LOCAL): AbstractMesh {
|
|
/// <summary>Orients a mesh towards a target point. Mesh must be drawn facing user.</summary>
|
|
/// <summary>Orients a mesh towards a target point. Mesh must be drawn facing user.</summary>
|
|
/// <param name="targetPoint" type="Vector3">The position (must be in same space as current mesh) to look at</param>
|
|
/// <param name="targetPoint" type="Vector3">The position (must be in same space as current mesh) to look at</param>
|
|
/// <param name="yawCor" type="Number">optional yaw (y-axis) correction in radians</param>
|
|
/// <param name="yawCor" type="Number">optional yaw (y-axis) correction in radians</param>
|
|
@@ -931,30 +1007,42 @@
|
|
var pitch = Math.atan2(dv.y, len);
|
|
var pitch = Math.atan2(dv.y, len);
|
|
this.rotationQuaternion = this.rotationQuaternion || new Quaternion();
|
|
this.rotationQuaternion = this.rotationQuaternion || new Quaternion();
|
|
Quaternion.RotationYawPitchRollToRef(yaw + yawCor, pitch + pitchCor, rollCor, this.rotationQuaternion);
|
|
Quaternion.RotationYawPitchRollToRef(yaw + yawCor, pitch + pitchCor, rollCor, this.rotationQuaternion);
|
|
|
|
+ return this;
|
|
}
|
|
}
|
|
|
|
|
|
- public attachToBone(bone: Bone, affectedMesh: AbstractMesh): void {
|
|
|
|
|
|
+ public attachToBone(bone: Bone, affectedMesh: AbstractMesh): AbstractMesh {
|
|
this._meshToBoneReferal = affectedMesh;
|
|
this._meshToBoneReferal = affectedMesh;
|
|
this.parent = bone;
|
|
this.parent = bone;
|
|
|
|
|
|
if (bone.getWorldMatrix().determinant() < 0) {
|
|
if (bone.getWorldMatrix().determinant() < 0) {
|
|
this.scalingDeterminant *= -1;
|
|
this.scalingDeterminant *= -1;
|
|
}
|
|
}
|
|
|
|
+ return this;
|
|
}
|
|
}
|
|
|
|
|
|
- public detachFromBone(): void {
|
|
|
|
|
|
+ public detachFromBone(): AbstractMesh {
|
|
if (this.parent.getWorldMatrix().determinant() < 0) {
|
|
if (this.parent.getWorldMatrix().determinant() < 0) {
|
|
this.scalingDeterminant *= -1;
|
|
this.scalingDeterminant *= -1;
|
|
}
|
|
}
|
|
-
|
|
|
|
this._meshToBoneReferal = null;
|
|
this._meshToBoneReferal = null;
|
|
this.parent = null;
|
|
this.parent = null;
|
|
|
|
+ return this;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Returns `true` if the mesh is within the frustum defined by the passed array of planes.
|
|
|
|
+ * A mesh is in the frustum if its bounding box intersects the frustum.
|
|
|
|
+ * Boolean returned.
|
|
|
|
+ */
|
|
public isInFrustum(frustumPlanes: Plane[]): boolean {
|
|
public isInFrustum(frustumPlanes: Plane[]): boolean {
|
|
return this._boundingInfo.isInFrustum(frustumPlanes);
|
|
return this._boundingInfo.isInFrustum(frustumPlanes);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Returns `true` if the mesh is completely in the frustum defined be the passed array of planes.
|
|
|
|
+ * A mesh is completely in the frustum if its bounding box it completely inside the frustum.
|
|
|
|
+ * Boolean returned.
|
|
|
|
+ */
|
|
public isCompletelyInFrustum(frustumPlanes: Plane[]): boolean {
|
|
public isCompletelyInFrustum(frustumPlanes: Plane[]): boolean {
|
|
return this._boundingInfo.isCompletelyInFrustum(frustumPlanes);;
|
|
return this._boundingInfo.isCompletelyInFrustum(frustumPlanes);;
|
|
}
|
|
}
|
|
@@ -1031,32 +1119,35 @@
|
|
return Vector3.TransformCoordinates(this.absolutePosition, camera.getViewMatrix());
|
|
return Vector3.TransformCoordinates(this.absolutePosition, camera.getViewMatrix());
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Returns the distance from the mesh to the active camera.
|
|
|
|
+ * Returns a float.
|
|
|
|
+ */
|
|
public getDistanceToCamera(camera?: Camera): number {
|
|
public getDistanceToCamera(camera?: Camera): number {
|
|
if (!camera) {
|
|
if (!camera) {
|
|
camera = this.getScene().activeCamera;
|
|
camera = this.getScene().activeCamera;
|
|
}
|
|
}
|
|
-
|
|
|
|
return this.absolutePosition.subtract(camera.position).length();
|
|
return this.absolutePosition.subtract(camera.position).length();
|
|
}
|
|
}
|
|
|
|
|
|
- public applyImpulse(force: Vector3, contactPoint: Vector3): void {
|
|
|
|
|
|
+ public applyImpulse(force: Vector3, contactPoint: Vector3): AbstractMesh {
|
|
if (!this.physicsImpostor) {
|
|
if (!this.physicsImpostor) {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
-
|
|
|
|
this.physicsImpostor.applyImpulse(force, contactPoint);
|
|
this.physicsImpostor.applyImpulse(force, contactPoint);
|
|
|
|
+ return this;
|
|
}
|
|
}
|
|
|
|
|
|
- public setPhysicsLinkWith(otherMesh: Mesh, pivot1: Vector3, pivot2: Vector3, options?: any): void {
|
|
|
|
|
|
+ public setPhysicsLinkWith(otherMesh: Mesh, pivot1: Vector3, pivot2: Vector3, options?: any): AbstractMesh {
|
|
if (!this.physicsImpostor || !otherMesh.physicsImpostor) {
|
|
if (!this.physicsImpostor || !otherMesh.physicsImpostor) {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
-
|
|
|
|
this.physicsImpostor.createJoint(otherMesh.physicsImpostor, PhysicsJoint.HingeJoint, {
|
|
this.physicsImpostor.createJoint(otherMesh.physicsImpostor, PhysicsJoint.HingeJoint, {
|
|
mainPivot: pivot1,
|
|
mainPivot: pivot1,
|
|
connectedPivot: pivot2,
|
|
connectedPivot: pivot2,
|
|
nativeParams: options
|
|
nativeParams: options
|
|
- })
|
|
|
|
|
|
+ });
|
|
|
|
+ return this;
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -1079,6 +1170,10 @@
|
|
|
|
|
|
// Collisions
|
|
// Collisions
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Property checkCollisions : Boolean, whether the camera should check the collisions against the mesh.
|
|
|
|
+ * Default `false`.
|
|
|
|
+ */
|
|
public get checkCollisions(): boolean {
|
|
public get checkCollisions(): boolean {
|
|
return this._checkCollisions;
|
|
return this._checkCollisions;
|
|
}
|
|
}
|
|
@@ -1090,7 +1185,7 @@
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- public moveWithCollisions(velocity: Vector3): void {
|
|
|
|
|
|
+ public moveWithCollisions(velocity: Vector3): AbstractMesh {
|
|
var globalPosition = this.getAbsolutePosition();
|
|
var globalPosition = this.getAbsolutePosition();
|
|
|
|
|
|
globalPosition.subtractFromFloatsToRef(0, this.ellipsoid.y, 0, this._oldPositionForCollisions);
|
|
globalPosition.subtractFromFloatsToRef(0, this.ellipsoid.y, 0, this._oldPositionForCollisions);
|
|
@@ -1098,6 +1193,7 @@
|
|
this._collider.radius = this.ellipsoid;
|
|
this._collider.radius = this.ellipsoid;
|
|
|
|
|
|
this.getScene().collisionCoordinator.getNewPosition(this._oldPositionForCollisions, velocity, this._collider, 3, this, this._onCollisionPositionChange, this.uniqueId);
|
|
this.getScene().collisionCoordinator.getNewPosition(this._oldPositionForCollisions, velocity, this._collider, 3, this, this._onCollisionPositionChange, this.uniqueId);
|
|
|
|
+ return this;
|
|
}
|
|
}
|
|
|
|
|
|
private _onCollisionPositionChange = (collisionId: number, newPosition: Vector3, collidedMesh: AbstractMesh = null) => {
|
|
private _onCollisionPositionChange = (collisionId: number, newPosition: Vector3, collidedMesh: AbstractMesh = null) => {
|
|
@@ -1121,8 +1217,9 @@
|
|
// Submeshes octree
|
|
// Submeshes octree
|
|
|
|
|
|
/**
|
|
/**
|
|
- * This function will create an octree to help select the right submeshes for rendering, picking and collisions
|
|
|
|
- * Please note that you must have a decent number of submeshes to get performance improvements when using octree
|
|
|
|
|
|
+ * This function will create an octree to help to select the right submeshes for rendering, picking and collision computations.
|
|
|
|
+ * Please note that you must have a decent number of submeshes to get performance improvements when using an octree.
|
|
|
|
+ * Returns an Octree of submeshes.
|
|
*/
|
|
*/
|
|
public createOrUpdateSubmeshesOctree(maxCapacity = 64, maxDepth = 2): Octree<SubMesh> {
|
|
public createOrUpdateSubmeshesOctree(maxCapacity = 64, maxDepth = 2): Octree<SubMesh> {
|
|
if (!this._submeshesOctree) {
|
|
if (!this._submeshesOctree) {
|
|
@@ -1139,7 +1236,7 @@
|
|
}
|
|
}
|
|
|
|
|
|
// Collisions
|
|
// Collisions
|
|
- public _collideForSubMesh(subMesh: SubMesh, transformMatrix: Matrix, collider: Collider): void {
|
|
|
|
|
|
+ public _collideForSubMesh(subMesh: SubMesh, transformMatrix: Matrix, collider: Collider): AbstractMesh {
|
|
this._generatePointsArray();
|
|
this._generatePointsArray();
|
|
// Transformation
|
|
// Transformation
|
|
if (!subMesh._lastColliderWorldVertices || !subMesh._lastColliderTransformMatrix.equals(transformMatrix)) {
|
|
if (!subMesh._lastColliderWorldVertices || !subMesh._lastColliderTransformMatrix.equals(transformMatrix)) {
|
|
@@ -1157,9 +1254,10 @@
|
|
if (collider.collisionFound) {
|
|
if (collider.collisionFound) {
|
|
collider.collidedMesh = this;
|
|
collider.collidedMesh = this;
|
|
}
|
|
}
|
|
|
|
+ return this;
|
|
}
|
|
}
|
|
|
|
|
|
- public _processCollisionsForSubMeshes(collider: Collider, transformMatrix: Matrix): void {
|
|
|
|
|
|
+ public _processCollisionsForSubMeshes(collider: Collider, transformMatrix: Matrix): AbstractMesh {
|
|
var subMeshes: SubMesh[];
|
|
var subMeshes: SubMesh[];
|
|
var len: number;
|
|
var len: number;
|
|
|
|
|
|
@@ -1184,18 +1282,19 @@
|
|
|
|
|
|
this._collideForSubMesh(subMesh, transformMatrix, collider);
|
|
this._collideForSubMesh(subMesh, transformMatrix, collider);
|
|
}
|
|
}
|
|
|
|
+ return this;
|
|
}
|
|
}
|
|
|
|
|
|
- public _checkCollision(collider: Collider): void {
|
|
|
|
|
|
+ public _checkCollision(collider: Collider): AbstractMesh {
|
|
// Bounding box test
|
|
// Bounding box test
|
|
if (!this._boundingInfo._checkCollision(collider))
|
|
if (!this._boundingInfo._checkCollision(collider))
|
|
- return;
|
|
|
|
|
|
+ return this;
|
|
|
|
|
|
// Transformation matrix
|
|
// Transformation matrix
|
|
Matrix.ScalingToRef(1.0 / collider.radius.x, 1.0 / collider.radius.y, 1.0 / collider.radius.z, this._collisionsScalingMatrix);
|
|
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.worldMatrixFromCache.multiplyToRef(this._collisionsScalingMatrix, this._collisionsTransformMatrix);
|
|
-
|
|
|
|
this._processCollisionsForSubMeshes(collider, this._collisionsTransformMatrix);
|
|
this._processCollisionsForSubMeshes(collider, this._collisionsTransformMatrix);
|
|
|
|
+ return this;
|
|
}
|
|
}
|
|
|
|
|
|
// Picking
|
|
// Picking
|
|
@@ -1203,6 +1302,10 @@
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Checks if the passed Ray intersects with the mesh.
|
|
|
|
+ * Returns an object PickingInfo.
|
|
|
|
+ */
|
|
public intersects(ray: Ray, fastCheck?: boolean): PickingInfo {
|
|
public intersects(ray: Ray, fastCheck?: boolean): PickingInfo {
|
|
var pickingInfo = new PickingInfo();
|
|
var pickingInfo = new PickingInfo();
|
|
|
|
|
|
@@ -1277,11 +1380,19 @@
|
|
return pickingInfo;
|
|
return pickingInfo;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Clones the mesh, used by the class Mesh.
|
|
|
|
+ * Just returns `null` for an AbstractMesh.
|
|
|
|
+ */
|
|
public clone(name: string, newParent: Node, doNotCloneChildren?: boolean): AbstractMesh {
|
|
public clone(name: string, newParent: Node, doNotCloneChildren?: boolean): AbstractMesh {
|
|
return null;
|
|
return null;
|
|
}
|
|
}
|
|
|
|
|
|
- public releaseSubMeshes(): void {
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Disposes all the mesh submeshes.
|
|
|
|
+ * Returns the AbstractMesh.
|
|
|
|
+ */
|
|
|
|
+ public releaseSubMeshes(): AbstractMesh {
|
|
if (this.subMeshes) {
|
|
if (this.subMeshes) {
|
|
while (this.subMeshes.length) {
|
|
while (this.subMeshes.length) {
|
|
this.subMeshes[0].dispose();
|
|
this.subMeshes[0].dispose();
|
|
@@ -1289,6 +1400,7 @@
|
|
} else {
|
|
} else {
|
|
this.subMeshes = new Array<SubMesh>();
|
|
this.subMeshes = new Array<SubMesh>();
|
|
}
|
|
}
|
|
|
|
+ return this;
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -1408,6 +1520,10 @@
|
|
super.dispose();
|
|
super.dispose();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Returns a new Vector3 what is the localAxis, expressed in the mesh local space, rotated like the mesh.
|
|
|
|
+ * This Vector3 is expressed in the World space.
|
|
|
|
+ */
|
|
public getDirection(localAxis:Vector3): Vector3 {
|
|
public getDirection(localAxis:Vector3): Vector3 {
|
|
var result = Vector3.Zero();
|
|
var result = Vector3.Zero();
|
|
|
|
|
|
@@ -1416,11 +1532,18 @@
|
|
return result;
|
|
return result;
|
|
}
|
|
}
|
|
|
|
|
|
- public getDirectionToRef(localAxis:Vector3, result:Vector3): void {
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Sets the Vector3 "result" as the rotated Vector3 "localAxis" in the same rotation than the mesh.
|
|
|
|
+ * localAxis is expressed in the mesh local space.
|
|
|
|
+ * result is computed in the Wordl space from the mesh World matrix.
|
|
|
|
+ * Returns the AbstractMesh.
|
|
|
|
+ */
|
|
|
|
+ public getDirectionToRef(localAxis:Vector3, result:Vector3): AbstractMesh {
|
|
Vector3.TransformNormalToRef(localAxis, this.getWorldMatrix(), result);
|
|
Vector3.TransformNormalToRef(localAxis, this.getWorldMatrix(), result);
|
|
|
|
+ return this;
|
|
}
|
|
}
|
|
|
|
|
|
- public setPivotPoint(point:Vector3, space:Space = Space.LOCAL): void{
|
|
|
|
|
|
+ public setPivotPoint(point:Vector3, space:Space = Space.LOCAL): AbstractMesh {
|
|
|
|
|
|
if(this.getScene().getRenderId() == 0){
|
|
if(this.getScene().getRenderId() == 0){
|
|
this.computeWorldMatrix(true);
|
|
this.computeWorldMatrix(true);
|
|
@@ -1435,44 +1558,48 @@
|
|
}
|
|
}
|
|
|
|
|
|
Vector3.TransformCoordinatesToRef(point, wm, this.position);
|
|
Vector3.TransformCoordinatesToRef(point, wm, this.position);
|
|
-
|
|
|
|
this._pivotMatrix.m[12] = -point.x;
|
|
this._pivotMatrix.m[12] = -point.x;
|
|
this._pivotMatrix.m[13] = -point.y;
|
|
this._pivotMatrix.m[13] = -point.y;
|
|
this._pivotMatrix.m[14] = -point.z;
|
|
this._pivotMatrix.m[14] = -point.z;
|
|
-
|
|
|
|
this._cache.pivotMatrixUpdated = true;
|
|
this._cache.pivotMatrixUpdated = true;
|
|
-
|
|
|
|
|
|
+ return this;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Returns a new Vector3 set with the mesh pivot point coordinates in the local space.
|
|
|
|
+ */
|
|
public getPivotPoint(): Vector3 {
|
|
public getPivotPoint(): Vector3 {
|
|
-
|
|
|
|
var point = Vector3.Zero();
|
|
var point = Vector3.Zero();
|
|
-
|
|
|
|
this.getPivotPointToRef(point);
|
|
this.getPivotPointToRef(point);
|
|
-
|
|
|
|
return point;
|
|
return point;
|
|
-
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- public getPivotPointToRef(result:Vector3): void{
|
|
|
|
-
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Sets the passed Vector3 "result" with the coordinates of the mesh pivot point in the local space.
|
|
|
|
+ * Returns the AbstractMesh.
|
|
|
|
+ */
|
|
|
|
+ public getPivotPointToRef(result:Vector3): AbstractMesh{
|
|
result.x = -this._pivotMatrix.m[12];
|
|
result.x = -this._pivotMatrix.m[12];
|
|
result.y = -this._pivotMatrix.m[13];
|
|
result.y = -this._pivotMatrix.m[13];
|
|
result.z = -this._pivotMatrix.m[14];
|
|
result.z = -this._pivotMatrix.m[14];
|
|
-
|
|
|
|
|
|
+ return this;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Returns a new Vector3 set with the mesh pivot point World coordinates.
|
|
|
|
+ */
|
|
public getAbsolutePivotPoint(): Vector3 {
|
|
public getAbsolutePivotPoint(): Vector3 {
|
|
-
|
|
|
|
var point = Vector3.Zero();
|
|
var point = Vector3.Zero();
|
|
-
|
|
|
|
this.getAbsolutePivotPointToRef(point);
|
|
this.getAbsolutePivotPointToRef(point);
|
|
-
|
|
|
|
return point;
|
|
return point;
|
|
-
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- public setParent(mesh:AbstractMesh, keepWorldPositionRotation = false): void{
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Defines the passed mesh as the parent of the current mesh.
|
|
|
|
+ * If keepWorldPositionRotation is set to `true` (default `false`), the current mesh position and rotation are kept.
|
|
|
|
+ * Returns the AbstractMesh.
|
|
|
|
+ */
|
|
|
|
+ public setParent(mesh:AbstractMesh, keepWorldPositionRotation = false): AbstractMesh {
|
|
|
|
|
|
var child = this;
|
|
var child = this;
|
|
var parent = mesh;
|
|
var parent = mesh;
|
|
@@ -1541,38 +1668,46 @@
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
-
|
|
|
|
child.parent = parent;
|
|
child.parent = parent;
|
|
-
|
|
|
|
|
|
+ return this;
|
|
}
|
|
}
|
|
|
|
|
|
- public addChild(mesh:AbstractMesh, keepWorldPositionRotation = false): void{
|
|
|
|
-
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Adds the passed mesh as a child to the current mesh.
|
|
|
|
+ * If keepWorldPositionRotation is set to `true` (default `false`), the child world position and rotation are kept.
|
|
|
|
+ * Returns the AbstractMesh.
|
|
|
|
+ */
|
|
|
|
+ public addChild(mesh:AbstractMesh, keepWorldPositionRotation = false): AbstractMesh {
|
|
mesh.setParent(this, keepWorldPositionRotation);
|
|
mesh.setParent(this, keepWorldPositionRotation);
|
|
-
|
|
|
|
|
|
+ return this;
|
|
}
|
|
}
|
|
|
|
|
|
- public removeChild(mesh:AbstractMesh, keepWorldPositionRotation = false): void{
|
|
|
|
-
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Removes the passed mesh from the current mesh children list.
|
|
|
|
+ * Returns the AbstractMesh.
|
|
|
|
+ */
|
|
|
|
+ public removeChild(mesh:AbstractMesh, keepWorldPositionRotation = false): AbstractMesh {
|
|
mesh.setParent(null, keepWorldPositionRotation);
|
|
mesh.setParent(null, keepWorldPositionRotation);
|
|
-
|
|
|
|
|
|
+ return this;
|
|
}
|
|
}
|
|
|
|
|
|
- public getAbsolutePivotPointToRef(result:Vector3): void{
|
|
|
|
-
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Sets the Vector3 "result" coordinates with the mesh pivot point World coordinates.
|
|
|
|
+ * Returns the AbstractMesh.
|
|
|
|
+ */
|
|
|
|
+ public getAbsolutePivotPointToRef(result:Vector3): AbstractMesh {
|
|
result.x = this._pivotMatrix.m[12];
|
|
result.x = this._pivotMatrix.m[12];
|
|
result.y = this._pivotMatrix.m[13];
|
|
result.y = this._pivotMatrix.m[13];
|
|
result.z = this._pivotMatrix.m[14];
|
|
result.z = this._pivotMatrix.m[14];
|
|
-
|
|
|
|
this.getPivotPointToRef(result);
|
|
this.getPivotPointToRef(result);
|
|
-
|
|
|
|
Vector3.TransformCoordinatesToRef(result, this.getWorldMatrix(), result);
|
|
Vector3.TransformCoordinatesToRef(result, this.getWorldMatrix(), result);
|
|
-
|
|
|
|
|
|
+ return this;
|
|
}
|
|
}
|
|
|
|
|
|
// Facet data
|
|
// Facet data
|
|
/**
|
|
/**
|
|
- * Initialize the facet data arrays : facetNormals, facetPositions and facetPartitioning
|
|
|
|
|
|
+ * Initialize the facet data arrays : facetNormals, facetPositions and facetPartitioning.
|
|
|
|
+ * Returns the AbstractMesh.
|
|
*/
|
|
*/
|
|
private _initFacetData(): AbstractMesh {
|
|
private _initFacetData(): AbstractMesh {
|
|
if (!this._facetNormals) {
|
|
if (!this._facetNormals) {
|
|
@@ -1598,7 +1733,8 @@
|
|
/**
|
|
/**
|
|
* Updates the mesh facetData arrays and the internal partitioning when the mesh is morphed or updated.
|
|
* Updates the mesh facetData arrays and the internal partitioning when the mesh is morphed or updated.
|
|
* This method can be called within the render loop.
|
|
* This method can be called within the render loop.
|
|
- * You don't need to call this method by yourself in the render loop when you update/morph a mesh with the methods CreateXXX() as they automatically manage this computation.
|
|
|
|
|
|
+ * You don't need to call this method by yourself in the render loop when you update/morph a mesh with the methods CreateXXX() as they automatically manage this computation.
|
|
|
|
+ * Returns the AbstractMesh.
|
|
*/
|
|
*/
|
|
public updateFacetData(): AbstractMesh {
|
|
public updateFacetData(): AbstractMesh {
|
|
if (!this._facetDataEnabled) {
|
|
if (!this._facetDataEnabled) {
|
|
@@ -1652,7 +1788,7 @@
|
|
return this._facetPositions;
|
|
return this._facetPositions;
|
|
}
|
|
}
|
|
/**
|
|
/**
|
|
- * Returns the facetLocalPartioning array
|
|
|
|
|
|
+ * Returns the facetLocalPartioning array.
|
|
*/
|
|
*/
|
|
public getFacetLocalPartitioning(): number[][] {
|
|
public getFacetLocalPartitioning(): number[][] {
|
|
if (!this._facetPartitioning) {
|
|
if (!this._facetPartitioning) {
|
|
@@ -1671,7 +1807,7 @@
|
|
}
|
|
}
|
|
/**
|
|
/**
|
|
* Sets the reference Vector3 with the i-th facet position in the world system.
|
|
* Sets the reference Vector3 with the i-th facet position in the world system.
|
|
- * Returns the mesh.
|
|
|
|
|
|
+ * Returns the AbstractMesh.
|
|
*/
|
|
*/
|
|
public getFacetPositionToRef(i: number, ref: Vector3): AbstractMesh {
|
|
public getFacetPositionToRef(i: number, ref: Vector3): AbstractMesh {
|
|
var localPos = (this.getFacetLocalPositions())[i];
|
|
var localPos = (this.getFacetLocalPositions())[i];
|
|
@@ -1690,7 +1826,7 @@
|
|
}
|
|
}
|
|
/**
|
|
/**
|
|
* Sets the reference Vector3 with the i-th facet normal in the world system.
|
|
* Sets the reference Vector3 with the i-th facet normal in the world system.
|
|
- * Returns the mesh.
|
|
|
|
|
|
+ * Returns the AbstractMesh.
|
|
*/
|
|
*/
|
|
public getFacetNormalToRef(i: number, ref: Vector3) {
|
|
public getFacetNormalToRef(i: number, ref: Vector3) {
|
|
var localNorm = (this.getFacetLocalNormals())[i];
|
|
var localNorm = (this.getFacetLocalNormals())[i];
|
|
@@ -1801,7 +1937,7 @@
|
|
}
|
|
}
|
|
/**
|
|
/**
|
|
* Disables the feature FacetData and frees the related memory.
|
|
* Disables the feature FacetData and frees the related memory.
|
|
- * Returns the mesh.
|
|
|
|
|
|
+ * Returns the AbstractMesh.
|
|
*/
|
|
*/
|
|
public disableFacetData(): AbstractMesh {
|
|
public disableFacetData(): AbstractMesh {
|
|
if (this._facetDataEnabled) {
|
|
if (this._facetDataEnabled) {
|