diff --git a/src/animation/AnimationStates.js b/src/animation/AnimationStates.js index caba03e..e44a6a0 100644 --- a/src/animation/AnimationStates.js +++ b/src/animation/AnimationStates.js @@ -74,8 +74,8 @@ const AnimationStates = Class.create(/** @lends AnimationStates.prototype */ { if (p0.hermite) { p0.hermite(p0, m0.scale(tr), p1, m1.scale(tr), t); } else if (p0.isQuaternion) { - p0.fromArray(this._cubicSpline(p0.elements, m0.elements, p1.elements, m1.elements, tr, t), 0, true); - p0.normalize(true); + p0.fromArray(this._cubicSpline(p0.elements, m0.elements, p1.elements, m1.elements, tr, t), 0); + p0.normalize(); } else { if (!isArrayLike(p0)) { p0 = [p0]; diff --git a/src/core/Node.js b/src/core/Node.js index 70fcfb6..10cc645 100644 --- a/src/core/Node.js +++ b/src/core/Node.js @@ -5,7 +5,7 @@ import Matrix4Notifier from '../math/Matrix4Notifier'; import Vector3 from '../math/Vector3'; import Vector3Notifier from '../math/Vector3Notifier'; import EulerNotifier from '../math/EulerNotifier'; -import Quaternion from '../math/Quaternion'; +import QuaternionNotifier from '../math/QuaternionNotifier'; import math from '../math/math'; import log from '../utils/log'; @@ -194,31 +194,14 @@ const Node = Class.create(/** @lends Node.prototype */ { this._scale = new Vector3Notifier(1, 1, 1); this._pivot = new Vector3Notifier(0, 0, 0); this._rotation = new EulerNotifier(); - this._quaternion = new Quaternion(); - - this._matrix.on('update', () => { - this._onMatrixUpdate(); - }); - - this._position.on('update', () => { - this._onPositionUpdate(); - }); - - this._scale.on('update', () => { - this._onScaleUpdate(); - }); - - this._pivot.on('update', () => { - this._onPivotUpdate(); - }); - - this._rotation.on('update', () => { - this._onRotationUpdate(); - }); - - this._quaternion.on('update', () => { - this._onQuaternionUpdate(); - }); + this._quaternion = new QuaternionNotifier(); + + this._matrix.onUpdate = this._onMatrixUpdate.bind(this); + this._position.onUpdate = this._onPositionUpdate.bind(this); + this._scale.onUpdate = this._onScaleUpdate.bind(this); + this._pivot.onUpdate = this._onPivotUpdate.bind(this); + this._rotation.onUpdate = this._onRotationUpdate.bind(this); + this._quaternion.onUpdate = this._onQuaternionUpdate.bind(this); Object.assign(this, params); }, diff --git a/src/math/EulerNotifier.js b/src/math/EulerNotifier.js index 0fdf819..c1a36e1 100644 --- a/src/math/EulerNotifier.js +++ b/src/math/EulerNotifier.js @@ -1,5 +1,4 @@ import Class from '../core/Class'; -import EventMixin from '../core/EventMixin'; import math from './math'; import Euler from './Euler'; @@ -9,12 +8,9 @@ const RAD2DEG = math.RAD2DEG; /** * 欧拉角, 数据改变会发送事件 * @class - * @mixes EventMixin * @extends Euler - * @fires update 数据更新事件 */ const EulerNotifier = Class.create(/** @lends EulerNotifier.prototype */ { - Mixes: EventMixin, Extends: Euler, /** * 类名 @@ -37,15 +33,22 @@ const EulerNotifier = Class.create(/** @lends EulerNotifier.prototype */ { Euler.call(this, x, y, z); }, + /** + * 更新的回调 + */ + onUpdate() { + + }, + updateDegrees() { EulerNotifier.superclass.updateDegrees.call(this); - this.fire('update'); + this.onUpdate(); return this; }, updateRadians() { EulerNotifier.superclass.updateRadians.call(this); - this.fire('update'); + this.onUpdate(); return this; }, @@ -60,7 +63,7 @@ const EulerNotifier = Class.create(/** @lends EulerNotifier.prototype */ { set(value) { this._degX = value; this.elements[0] = value * DEG2RAD; - this.fire('update'); + this.onUpdate(); } }, @@ -75,7 +78,7 @@ const EulerNotifier = Class.create(/** @lends EulerNotifier.prototype */ { set(value) { this._degY = value; this.elements[1] = value * DEG2RAD; - this.fire('update'); + this.onUpdate(); } }, @@ -90,7 +93,7 @@ const EulerNotifier = Class.create(/** @lends EulerNotifier.prototype */ { set(value) { this._degZ = value; this.elements[2] = value * DEG2RAD; - this.fire('update'); + this.onUpdate(); } }, @@ -105,7 +108,7 @@ const EulerNotifier = Class.create(/** @lends EulerNotifier.prototype */ { set(value) { this.elements[0] = value; this._degX = value * RAD2DEG; - this.fire('update'); + this.onUpdate(); } }, /** @@ -119,7 +122,7 @@ const EulerNotifier = Class.create(/** @lends EulerNotifier.prototype */ { set(value) { this.elements[1] = value; this._degY = value * RAD2DEG; - this.fire('update'); + this.onUpdate(); } }, /** @@ -133,7 +136,7 @@ const EulerNotifier = Class.create(/** @lends EulerNotifier.prototype */ { set(value) { this.elements[2] = value; this._degZ = value * RAD2DEG; - this.fire('update'); + this.onUpdate(); } } }); diff --git a/src/math/Matrix4Notifier.js b/src/math/Matrix4Notifier.js index ac2d2f3..c442055 100644 --- a/src/math/Matrix4Notifier.js +++ b/src/math/Matrix4Notifier.js @@ -2,7 +2,6 @@ import { mat4 } from 'gl-matrix'; import Class from '../core/Class'; -import EventMixin from '../core/EventMixin'; import Vector3 from './Vector3'; import Matrix4 from './Matrix4'; import Quaternion from './Quaternion'; @@ -17,7 +16,6 @@ const tempVector32 = new Vector3(); * @extends {Matrix4} */ const Matrix4Notifier = Class.create(/** @lends Matrix4Notifier.prototype */ { - Mixes: EventMixin, Extends: Matrix4, /** * 类名 @@ -40,6 +38,12 @@ const Matrix4Notifier = Class.create(/** @lends Matrix4Notifier.prototype */ { * @type {Float32Array} */ this.elements = mat4.create(); + }, + /** + * 更新的回调 + */ + onUpdate() { + }, /** * Copy the values from one mat4 to this @@ -48,7 +52,7 @@ const Matrix4Notifier = Class.create(/** @lends Matrix4Notifier.prototype */ { */ copy(m) { mat4.copy(this.elements, m.elements); - this.fire('update'); + this.onUpdate(); return this; }, /** @@ -62,7 +66,7 @@ const Matrix4Notifier = Class.create(/** @lends Matrix4Notifier.prototype */ { for (let i = 0; i < 16; i++) { elements[i] = array[offset + i]; } - this.fire('update'); + this.onUpdate(); return this; }, /** @@ -87,7 +91,7 @@ const Matrix4Notifier = Class.create(/** @lends Matrix4Notifier.prototype */ { */ set(m00, m01, m02, m03, m10, m11, m12, m13, m20, m21, m22, m23, m30, m31, m32, m33) { mat4.set(this.elements, m00, m01, m02, m03, m10, m11, m12, m13, m20, m21, m22, m23, m30, m31, m32, m33); - this.fire('update'); + this.onUpdate(); return this; }, /** @@ -96,7 +100,7 @@ const Matrix4Notifier = Class.create(/** @lends Matrix4Notifier.prototype */ { */ identity() { mat4.identity(this.elements); - this.fire('update'); + this.onUpdate(); return this; }, /** @@ -105,7 +109,7 @@ const Matrix4Notifier = Class.create(/** @lends Matrix4Notifier.prototype */ { */ transpose() { mat4.transpose(this.elements, this.elements); - this.fire('update'); + this.onUpdate(); return this; }, /** @@ -115,7 +119,7 @@ const Matrix4Notifier = Class.create(/** @lends Matrix4Notifier.prototype */ { */ invert(m = this) { mat4.invert(this.elements, m.elements); - this.fire('update'); + this.onUpdate(); return this; }, /** @@ -125,7 +129,7 @@ const Matrix4Notifier = Class.create(/** @lends Matrix4Notifier.prototype */ { */ adjoint(m = this) { mat4.adjoint(this.elements, m.elements); - this.fire('update'); + this.onUpdate(); return this; }, /** @@ -147,7 +151,7 @@ const Matrix4Notifier = Class.create(/** @lends Matrix4Notifier.prototype */ { a = this; } mat4.multiply(this.elements, a.elements, b.elements); - this.fire('update'); + this.onUpdate(); return this; }, /** @@ -157,7 +161,7 @@ const Matrix4Notifier = Class.create(/** @lends Matrix4Notifier.prototype */ { */ premultiply(m) { this.multiply(m, this); - this.fire('update'); + this.onUpdate(); return this; }, /** @@ -167,7 +171,7 @@ const Matrix4Notifier = Class.create(/** @lends Matrix4Notifier.prototype */ { */ translate(v) { mat4.translate(this.elements, this.elements, v.elements); - this.fire('update'); + this.onUpdate(); return this; }, /** @@ -177,7 +181,7 @@ const Matrix4Notifier = Class.create(/** @lends Matrix4Notifier.prototype */ { */ scale(v) { mat4.scale(this.elements, this.elements, v.elements); - this.fire('update'); + this.onUpdate(); return this; }, /** @@ -188,7 +192,7 @@ const Matrix4Notifier = Class.create(/** @lends Matrix4Notifier.prototype */ { */ rotate(rad, axis) { mat4.rotate(this.elements, this.elements, rad, axis.elements); - this.fire('update'); + this.onUpdate(); return this; }, /** @@ -198,7 +202,7 @@ const Matrix4Notifier = Class.create(/** @lends Matrix4Notifier.prototype */ { */ rotateX(rad) { mat4.rotateX(this.elements, this.elements, rad); - this.fire('update'); + this.onUpdate(); return this; }, /** @@ -208,7 +212,7 @@ const Matrix4Notifier = Class.create(/** @lends Matrix4Notifier.prototype */ { */ rotateY(rad) { mat4.rotateY(this.elements, this.elements, rad); - this.fire('update'); + this.onUpdate(); return this; }, /** @@ -218,7 +222,7 @@ const Matrix4Notifier = Class.create(/** @lends Matrix4Notifier.prototype */ { */ rotateZ(rad) { mat4.rotateZ(this.elements, this.elements, rad); - this.fire('update'); + this.onUpdate(); return this; }, /** @@ -228,7 +232,7 @@ const Matrix4Notifier = Class.create(/** @lends Matrix4Notifier.prototype */ { */ fromTranslation(v) { mat4.fromTranslation(this.elements, v.elements); - this.fire('update'); + this.onUpdate(); return this; }, /** @@ -238,7 +242,7 @@ const Matrix4Notifier = Class.create(/** @lends Matrix4Notifier.prototype */ { */ fromScaling(v) { mat4.fromScaling(this.elements, v.elements); - this.fire('update'); + this.onUpdate(); return this; }, /** @@ -249,7 +253,7 @@ const Matrix4Notifier = Class.create(/** @lends Matrix4Notifier.prototype */ { */ fromRotation(rad, axis) { mat4.fromRotation(this.elements, rad, axis.elements); - this.fire('update'); + this.onUpdate(); return this; }, /** @@ -259,7 +263,7 @@ const Matrix4Notifier = Class.create(/** @lends Matrix4Notifier.prototype */ { */ fromXRotation(rad) { mat4.fromXRotation(this.elements, rad); - this.fire('update'); + this.onUpdate(); return this; }, /** @@ -269,7 +273,7 @@ const Matrix4Notifier = Class.create(/** @lends Matrix4Notifier.prototype */ { */ fromYRotation(rad) { mat4.fromYRotation(this.elements, rad); - this.fire('update'); + this.onUpdate(); return this; }, /** @@ -279,7 +283,7 @@ const Matrix4Notifier = Class.create(/** @lends Matrix4Notifier.prototype */ { */ fromZRotation(rad) { mat4.fromZRotation(this.elements, rad); - this.fire('update'); + this.onUpdate(); return this; }, /** @@ -290,7 +294,7 @@ const Matrix4Notifier = Class.create(/** @lends Matrix4Notifier.prototype */ { */ fromRotationTranslation(q, v) { mat4.fromRotationTranslation(this.elements, q.elements, v.elements); - this.fire('update'); + this.onUpdate(); return this; }, /** @@ -339,7 +343,7 @@ const Matrix4Notifier = Class.create(/** @lends Matrix4Notifier.prototype */ { */ fromRotationTranslationScale(q, v, s) { mat4.fromRotationTranslationScale(this.elements, q.elements, v.elements, s.elements); - this.fire('update'); + this.onUpdate(); return this; }, /** @@ -348,13 +352,13 @@ const Matrix4Notifier = Class.create(/** @lends Matrix4Notifier.prototype */ { * @param {Vector3} v Translation vector * @param {Vector3} s Scaling vector * @param {Vector3} o The origin vector around which to scale and rotate - * @param {Boolean} [dontFireEvent=false] dontFireEvent + * @param {Boolean} [notCallUpdate=false] notCallUpdate * @return {Matrix4Notifier} this */ - fromRotationTranslationScaleOrigin(q, v, s, o, dontFireEvent) { + fromRotationTranslationScaleOrigin(q, v, s, o, notCallUpdate) { mat4.fromRotationTranslationScaleOrigin(this.elements, q.elements, v.elements, s.elements, o.elements); - if (!dontFireEvent) { - this.fire('update'); + if (!notCallUpdate) { + this.onUpdate(); } return this; }, @@ -365,7 +369,7 @@ const Matrix4Notifier = Class.create(/** @lends Matrix4Notifier.prototype */ { */ fromQuat(q) { mat4.fromQuat(this.elements, q.elements); - this.fire('update'); + this.onUpdate(); return this; }, /** @@ -380,7 +384,7 @@ const Matrix4Notifier = Class.create(/** @lends Matrix4Notifier.prototype */ { */ frustum(left, right, bottom, top, near, far) { mat4.frustum(this.elements, left, right, bottom, top, near, far); - this.fire('update'); + this.onUpdate(); return this; }, /** @@ -393,7 +397,7 @@ const Matrix4Notifier = Class.create(/** @lends Matrix4Notifier.prototype */ { */ perspective(fovy, aspect, near, far) { mat4.perspective(this.elements, fovy, aspect, near, far); - this.fire('update'); + this.onUpdate(); return this; }, /** @@ -405,7 +409,7 @@ const Matrix4Notifier = Class.create(/** @lends Matrix4Notifier.prototype */ { */ perspectiveFromFieldOfView(fov, near, far) { mat4.perspectiveFromFieldOfView(this.elements, fov, near, far); - this.fire('update'); + this.onUpdate(); return this; }, /** @@ -420,7 +424,7 @@ const Matrix4Notifier = Class.create(/** @lends Matrix4Notifier.prototype */ { */ ortho(left, right, bottom, top, near, far) { mat4.ortho(this.elements, left, right, bottom, top, near, far); - this.fire('update'); + this.onUpdate(); return this; }, /** @@ -440,7 +444,7 @@ const Matrix4Notifier = Class.create(/** @lends Matrix4Notifier.prototype */ { mat4.lookAt(this.elements, eye.elements, center.elements, up.elements); - this.fire('update'); + this.onUpdate(); return this; }, /** @@ -524,7 +528,7 @@ const Matrix4Notifier = Class.create(/** @lends Matrix4Notifier.prototype */ { out[13] = eyey; out[14] = eyez; out[15] = 1; - this.fire('update'); + this.onUpdate(); return this; }, /** @@ -546,7 +550,7 @@ const Matrix4Notifier = Class.create(/** @lends Matrix4Notifier.prototype */ { a = this; } mat4.add(this.elements, a.elements, b.elements); - this.fire('update'); + this.onUpdate(); return this; }, /** @@ -561,7 +565,7 @@ const Matrix4Notifier = Class.create(/** @lends Matrix4Notifier.prototype */ { a = this; } mat4.subtract(this.elements, a.elements, b.elements); - this.fire('update'); + this.onUpdate(); return this; }, /** diff --git a/src/math/Quaternion.js b/src/math/Quaternion.js index dcf95d9..2980df0 100644 --- a/src/math/Quaternion.js +++ b/src/math/Quaternion.js @@ -3,17 +3,13 @@ import { } from 'gl-matrix'; import Matrix3 from './Matrix3'; import Class from '../core/Class'; -import EventMixin from '../core/EventMixin'; const tempMat3 = new Matrix3(); /** * @class - * @mixes EventMixin - * @fires update 数据更新事件 */ const Quaternion = Class.create(/** @lends Quaternion.prototype */ { - Mixes: EventMixin, /** * 类名 * @type {String} @@ -44,14 +40,10 @@ const Quaternion = Class.create(/** @lends Quaternion.prototype */ { /** * Copy the values from one quat to this * @param {Quaternion} q - * @param {Boolean} [dontFireEvent=false] wether or not don`t fire change event. * @return {Quaternion} this */ - copy(q, dontFireEvent) { + copy(q) { quat.copy(this.elements, q.elements); - if (!dontFireEvent) { - this.fire('update'); - } return this; }, /** @@ -83,10 +75,9 @@ const Quaternion = Class.create(/** @lends Quaternion.prototype */ { * 从数组赋值 * @param {number[]|TypedArray} array 数组 * @param {Number} [offset=0] 数组偏移值 - * @param {Boolean} [dontFireEvent=false] wether or not don`t fire change event. * @return {Quaternion} this */ - fromArray(array, offset = 0, dontFireEvent) { + fromArray(array, offset = 0) { const el = this.elements; el[0] = array[offset]; @@ -94,10 +85,6 @@ const Quaternion = Class.create(/** @lends Quaternion.prototype */ { el[2] = array[offset + 2]; el[3] = array[offset + 3]; - if (!dontFireEvent) { - this.fire('update'); - } - return this; }, @@ -107,27 +94,19 @@ const Quaternion = Class.create(/** @lends Quaternion.prototype */ { * @param {Number} y Y component * @param {Number} z Z component * @param {Number} w W component - * @param {Boolean} [dontFireEvent=false] wether or not don`t fire change event. * @return {Quaternion} this */ - set(x, y, z, w, dontFireEvent) { + set(x, y, z, w) { quat.set(this.elements, x, y, z, w); - if (!dontFireEvent) { - this.fire('update'); - } return this; }, /** * Set this to the identity quaternion - * @param {Boolean} [dontFireEvent=false] wether or not don`t fire change event. * @return {Quaternion} this */ - identity(dontFireEvent) { + identity() { quat.identity(this.elements); - if (!dontFireEvent) { - this.fire('update'); - } return this; }, /** @@ -135,14 +114,10 @@ const Quaternion = Class.create(/** @lends Quaternion.prototype */ { * vector to another. * @param {Vector3} a the initial vector * @param {Vector3} b the destination vector - * @param {Boolean} [dontFireEvent=false] wether or not don`t fire change event. * @return {Quaternion} this */ - rotationTo(a, b, dontFireEvent) { + rotationTo(a, b) { quat.rotationTo(this.elements, a.elements, b.elements); - if (!dontFireEvent) { - this.fire('update'); - } return this; }, /** @@ -153,14 +128,10 @@ const Quaternion = Class.create(/** @lends Quaternion.prototype */ { * @param {Vector3} view the vector representing the viewing direction * @param {Vector3} right the vector representing the local "right" direction * @param {Vector3} up the vector representing the local "up" direction - * @param {Boolean} [dontFireEvent=false] wether or not don`t fire change event. * @return {Quaternion} this */ - setAxes(view, right, up, dontFireEvent) { + setAxes(view, right, up) { quat.setAxes(this.elements, view.elements, right.elements, up.elements); - if (!dontFireEvent) { - this.fire('update'); - } return this; }, /** @@ -168,14 +139,10 @@ const Quaternion = Class.create(/** @lends Quaternion.prototype */ { * then returns it. * @param {Vector3} axis the axis around which to rotate * @param {Number} rad the angle in radians - * @param {Boolean} [dontFireEvent=false] wether or not don`t fire change event. * @return {Quaternion} this */ - setAxisAngle(axis, rad, dontFireEvent) { + setAxisAngle(axis, rad) { quat.setAxisAngle(this.elements, axis.elements, rad); - if (!dontFireEvent) { - this.fire('update'); - } return this; }, /** @@ -196,106 +163,74 @@ const Quaternion = Class.create(/** @lends Quaternion.prototype */ { /** * Adds two quat's * @param {Quaternion} q - * @param {Boolean} [dontFireEvent=false] wether or not don`t fire change event. * @return {Quaternion} this */ - add(q, dontFireEvent) { + add(q) { quat.add(this.elements, this.elements, q.elements); - if (!dontFireEvent) { - this.fire('update'); - } return this; }, /** * Multiplies two quat's * @param {Quaternion} q - * @param {Boolean} [dontFireEvent=false] wether or not don`t fire change event. * @return {Quaternion} this */ - multiply(q, dontFireEvent) { + multiply(q) { quat.multiply(this.elements, this.elements, q.elements); - if (!dontFireEvent) { - this.fire('update'); - } return this; }, /** * premultiply the quat * @param {Quaternion} q - * @param {Boolean} [dontFireEvent=false] wether or not don`t fire change event. * @return {Quaternion} this */ - premultiply(q, dontFireEvent) { + premultiply(q) { quat.multiply(this.elements, q.elements, this.elements); - if (!dontFireEvent) { - this.fire('update'); - } return this; }, /** * Scales a quat by a scalar number * @param {Vector3} scale the vector to scale - * @param {Boolean} [dontFireEvent=false] wether or not don`t fire change event. * @return {Quaternion} this */ - scale(scale, dontFireEvent) { + scale(scale) { quat.scale(this.elements, this.elements, scale); - if (!dontFireEvent) { - this.fire('update'); - } return this; }, /** * Rotates a quaternion by the given angle about the X axis * @param {Number} rad angle (in radians) to rotate - * @param {Boolean} [dontFireEvent=false] wether or not don`t fire change event. * @return {Quaternion} this */ - rotateX(rad, dontFireEvent) { + rotateX(rad) { quat.rotateX(this.elements, this.elements, rad); - if (!dontFireEvent) { - this.fire('update'); - } return this; }, /** * Rotates a quaternion by the given angle about the Y axis * @param {Number} rad angle (in radians) to rotate - * @param {Boolean} [dontFireEvent=false] wether or not don`t fire change event. * @return {Quaternion} this */ - rotateY(rad, dontFireEvent) { + rotateY(rad) { quat.rotateY(this.elements, this.elements, rad); - if (!dontFireEvent) { - this.fire('update'); - } return this; }, /** * Rotates a quaternion by the given angle about the Z axis * @param {Number} rad angle (in radians) to rotate - * @param {Boolean} [dontFireEvent=false] wether or not don`t fire change event. * @return {Quaternion} this */ - rotateZ(rad, dontFireEvent) { + rotateZ(rad) { quat.rotateZ(this.elements, this.elements, rad); - if (!dontFireEvent) { - this.fire('update'); - } return this; }, /** * Calculates the W component of a quat from the X, Y, and Z components. * Assumes that quaternion is 1 unit in length. * Any existing W component will be ignored. - * @param {Boolean} [dontFireEvent=false] wether or not don`t fire change event. * @returns {Quaternion} this */ - calculateW(dontFireEvent) { + calculateW() { quat.calculateW(this.elements, this.elements); - if (!dontFireEvent) { - this.fire('update'); - } return this; }, /** @@ -310,28 +245,20 @@ const Quaternion = Class.create(/** @lends Quaternion.prototype */ { * Performs a linear interpolation between two quat's * @param {Quaternion} q * @param {Number} t interpolation amount between the two inputs - * @param {Boolean} [dontFireEvent=false] wether or not don`t fire change event. * @return {Quaternion} this */ - lerp(q, t, dontFireEvent) { + lerp(q, t) { quat.lerp(this.elements, this.elements, q.elements, t); - if (!dontFireEvent) { - this.fire('update'); - } return this; }, /** * Performs a spherical linear interpolation between two quat * @param {Quaternion} q * @param {Number} t interpolation amount between the two inputs - * @param {Boolean} [dontFireEvent=false] wether or not don`t fire change event. * @return {Quaternion} this */ - slerp(q, t, dontFireEvent) { + slerp(q, t) { quat.slerp(this.elements, this.elements, q.elements, t); - if (!dontFireEvent) { - this.fire('update'); - } return this; }, /** @@ -341,39 +268,27 @@ const Quaternion = Class.create(/** @lends Quaternion.prototype */ { * @param {Quaternion} qc * @param {Quaternion} qd * @param {Number} t interpolation amount - * @param {Boolean} [dontFireEvent=false] wether or not don`t fire change event. * @return {Quaternion} this */ - sqlerp(qa, qb, qc, qd, t, dontFireEvent) { + sqlerp(qa, qb, qc, qd, t) { quat.sqlerp(this.elements, qa.elements, qb.elements, qc.elements, qd.elements, t); - if (!dontFireEvent) { - this.fire('update'); - } return this; }, /** * Calculates the inverse of a quat - * @param {Boolean} [dontFireEvent=false] wether or not don`t fire change event. * @return {Quaternion} this */ - invert(dontFireEvent) { + invert() { quat.invert(this.elements, this.elements); - if (!dontFireEvent) { - this.fire('update'); - } return this; }, /** * Calculates the conjugate of a quat * If the quaternion is normalized, this function is faster than quat.inverse and produces the same result. - * @param {Boolean} [dontFireEvent=false] wether or not don`t fire change event. * @return {Quaternion} this */ - conjugate(dontFireEvent) { + conjugate() { quat.conjugate(this.elements, this.elements); - if (!dontFireEvent) { - this.fire('update'); - } return this; }, /** @@ -392,14 +307,10 @@ const Quaternion = Class.create(/** @lends Quaternion.prototype */ { }, /** * Normalize this - * @param {Boolean} [dontFireEvent=false] wether or not don`t fire change event. * @return {Quaternion} this */ - normalize(dontFireEvent) { + normalize() { quat.normalize(this.elements, this.elements); - if (!dontFireEvent) { - this.fire('update'); - } return this; }, /** @@ -409,14 +320,10 @@ const Quaternion = Class.create(/** @lends Quaternion.prototype */ { * to renormalize the quaternion yourself where necessary. * * @param {Matrix3} m rotation matrix - * @param {Boolean} [dontFireEvent=false] wether or not don`t fire change event. * @return {Quaternion} this */ - fromMat3(mat, dontFireEvent) { + fromMat3(mat) { quat.fromMat3(this.elements, mat.elements); - if (!dontFireEvent) { - this.fire('update'); - } return this; }, /** @@ -426,12 +333,11 @@ const Quaternion = Class.create(/** @lends Quaternion.prototype */ { * to renormalize the quaternion yourself where necessary. * * @param {Matrix4} m rotation matrix - * @param {Boolean} [dontFireEvent=false] wether or not don`t fire change event. * @return {Quaternion} this */ - fromMat4(mat, dontFireEvent) { + fromMat4(mat) { tempMat3.fromMat4(mat); - this.fromMat3(tempMat3, dontFireEvent); + this.fromMat3(tempMat3); return this; }, /** @@ -453,10 +359,9 @@ const Quaternion = Class.create(/** @lends Quaternion.prototype */ { /** * Creates a quaternion from the given euler. * @param {Euler} euler - * @param {Boolean} [dontFireEvent=false] wether or not don`t fire change event. * @return {Quaternion} this */ - fromEuler(euler, dontFireEvent) { + fromEuler(euler) { // Based on https://github.com/mrdoob/three.js/blob/dev/src/math/Quaternion.js#L200 // quat.fromEuler(this.elements, euler.x, euler.y, euler.z); @@ -506,10 +411,6 @@ const Quaternion = Class.create(/** @lends Quaternion.prototype */ { out[3] = cx * cy * cz + sx * sy * sz; } - if (!dontFireEvent) { - this.fire('update'); - } - return this; }, /** @@ -522,7 +423,6 @@ const Quaternion = Class.create(/** @lends Quaternion.prototype */ { }, set(value) { this.elements[0] = value; - this.fire('update'); } }, /** @@ -535,7 +435,6 @@ const Quaternion = Class.create(/** @lends Quaternion.prototype */ { }, set(value) { this.elements[1] = value; - this.fire('update'); } }, /** @@ -548,7 +447,6 @@ const Quaternion = Class.create(/** @lends Quaternion.prototype */ { }, set(value) { this.elements[2] = value; - this.fire('update'); } }, /** @@ -561,7 +459,6 @@ const Quaternion = Class.create(/** @lends Quaternion.prototype */ { }, set(value) { this.elements[3] = value; - this.fire('update'); } } }); @@ -569,6 +466,7 @@ const Quaternion = Class.create(/** @lends Quaternion.prototype */ { /** * Alias for {@link Quaternion#multiply} * @function + * @param {Quaternion} q */ Quaternion.prototype.mul = Quaternion.prototype.multiply; diff --git a/src/math/QuaternionNotifier.js b/src/math/QuaternionNotifier.js new file mode 100644 index 0000000..69cd8ae --- /dev/null +++ b/src/math/QuaternionNotifier.js @@ -0,0 +1,524 @@ +import { + quat +} from 'gl-matrix'; +import Matrix3 from './Matrix3'; +import Class from '../core/Class'; + +const tempMat3 = new Matrix3(); + +/** + * @class + */ +const QuaternionNotifier = Class.create(/** @lends Quaternion.prototype */ { + /** + * 类名 + * @type {String} + * @default QuaternionNotifier + */ + className: 'QuaternionNotifier', + /** + * @type {Boolean} + * @default true + */ + isQuaternionNotifier: true, + /** + * Creates a new identity quat + * @constructs + * @param {Number} [x=0] X component + * @param {Number} [y=0] Y component + * @param {Number} [z=0] Z component + * @param {Number} [w=1] W component + */ + constructor(x = 0, y = 0, z = 0, w = 1) { + /** + * 数据 + * @type {Float32Array} + */ + this.elements = quat.fromValues(x, y, z, w); + }, + + /** + * 更新的回调 + */ + onUpdate() { + + }, + + /** + * Copy the values from one quat to this + * @param {Quaternion} q + * @return {Quaternion} this + */ + copy(q) { + quat.copy(this.elements, q.elements); + this.onUpdate(); + return this; + }, + /** + * Creates a new quat initialized with values from an existing quaternion + * @return {Quaternion} a new quaternion + */ + clone() { + const el = this.elements; + return new this.constructor(el[0], el[1], el[2], el[3]); + }, + + /** + * 转换到数组 + * @param {number[]|TypedArray} [array=[]] 数组 + * @param {Number} [offset=0] 数组偏移值 + * @return {Array} + */ + toArray(array = [], offset = 0) { + const el = this.elements; + + array[offset] = el[0]; + array[offset + 1] = el[1]; + array[offset + 2] = el[2]; + array[offset + 3] = el[3]; + + return array; + }, + /** + * 从数组赋值 + * @param {number[]|TypedArray} array 数组 + * @param {Number} [offset=0] 数组偏移值 + * @return {Quaternion} this + */ + fromArray(array, offset = 0) { + const el = this.elements; + + el[0] = array[offset]; + el[1] = array[offset + 1]; + el[2] = array[offset + 2]; + el[3] = array[offset + 3]; + + this.onUpdate(); + + return this; + }, + + /** + * Set the components of a quat to the given values + * @param {Number} x X component + * @param {Number} y Y component + * @param {Number} z Z component + * @param {Number} w W component + * @return {Quaternion} this + */ + set(x, y, z, w) { + quat.set(this.elements, x, y, z, w); + this.onUpdate(); + return this; + }, + + /** + * Set this to the identity quaternion + * @return {Quaternion} this + */ + identity() { + quat.identity(this.elements); + this.onUpdate(); + return this; + }, + /** + * Sets a quaternion to represent the shortest rotation from one + * vector to another. + * @param {Vector3} a the initial vector + * @param {Vector3} b the destination vector + * @return {Quaternion} this + */ + rotationTo(a, b) { + quat.rotationTo(this.elements, a.elements, b.elements); + this.onUpdate(); + return this; + }, + /** + * Sets the specified quaternion with values corresponding to the given + * axes. Each axis is a vec3 and is expected to be unit length and + * perpendicular to all other specified axes. + * + * @param {Vector3} view the vector representing the viewing direction + * @param {Vector3} right the vector representing the local "right" direction + * @param {Vector3} up the vector representing the local "up" direction + * @return {Quaternion} this + */ + setAxes(view, right, up) { + quat.setAxes(this.elements, view.elements, right.elements, up.elements); + this.onUpdate(); + return this; + }, + /** + * Sets a quat from the given angle and rotation axis, + * then returns it. + * @param {Vector3} axis the axis around which to rotate + * @param {Number} rad the angle in radians + * @return {Quaternion} this + */ + setAxisAngle(axis, rad) { + quat.setAxisAngle(this.elements, axis.elements, rad); + this.onUpdate(); + return this; + }, + /** + * Gets the rotation axis and angle for a given + * quaternion. If a quaternion is created with + * setAxisAngle, this method will return the same + * values as providied in the original parameter list + * OR functionally equivalent values. + * Example: The quaternion formed by axis [0, 0, 1] and + * angle -90 is the same as the quaternion formed by + * [0, 0, 1] and 270. This method favors the latter. + * @param {Vector3} out_axis Vector receiving the axis of rotation + * @return {Number} Angle, in radians, of the rotation + */ + getAxisAngle(axis) { + return quat.getAxisAngle(axis.elements, this.elements); + }, + /** + * Adds two quat's + * @param {Quaternion} q + * @return {Quaternion} this + */ + add(q) { + quat.add(this.elements, this.elements, q.elements); + this.onUpdate(); + return this; + }, + /** + * Multiplies two quat's + * @param {Quaternion} q + * @return {Quaternion} this + */ + multiply(q) { + quat.multiply(this.elements, this.elements, q.elements); + this.onUpdate(); + return this; + }, + /** + * premultiply the quat + * @param {Quaternion} q + * @return {Quaternion} this + */ + premultiply(q) { + quat.multiply(this.elements, q.elements, this.elements); + this.onUpdate(); + return this; + }, + /** + * Scales a quat by a scalar number + * @param {Vector3} scale the vector to scale + * @return {Quaternion} this + */ + scale(scale) { + quat.scale(this.elements, this.elements, scale); + this.onUpdate(); + return this; + }, + /** + * Rotates a quaternion by the given angle about the X axis + * @param {Number} rad angle (in radians) to rotate + * @return {Quaternion} this + */ + rotateX(rad) { + quat.rotateX(this.elements, this.elements, rad); + this.onUpdate(); + return this; + }, + /** + * Rotates a quaternion by the given angle about the Y axis + * @param {Number} rad angle (in radians) to rotate + * @return {Quaternion} this + */ + rotateY(rad) { + quat.rotateY(this.elements, this.elements, rad); + this.onUpdate(); + return this; + }, + /** + * Rotates a quaternion by the given angle about the Z axis + * @param {Number} rad angle (in radians) to rotate + * @return {Quaternion} this + */ + rotateZ(rad) { + quat.rotateZ(this.elements, this.elements, rad); + this.onUpdate(); + return this; + }, + /** + * Calculates the W component of a quat from the X, Y, and Z components. + * Assumes that quaternion is 1 unit in length. + * Any existing W component will be ignored. + * @returns {Quaternion} this + */ + calculateW() { + quat.calculateW(this.elements, this.elements); + this.onUpdate(); + return this; + }, + /** + * Calculates the dot product of two quat's + * @param {Quaternion} q + * @return {Number} dot product of two quat's + */ + dot(q) { + return quat.dot(this.elements, q.elements); + }, + /** + * Performs a linear interpolation between two quat's + * @param {Quaternion} q + * @param {Number} t interpolation amount between the two inputs + * @return {Quaternion} this + */ + lerp(q, t) { + quat.lerp(this.elements, this.elements, q.elements, t); + this.onUpdate(); + return this; + }, + /** + * Performs a spherical linear interpolation between two quat + * @param {Quaternion} q + * @param {Number} t interpolation amount between the two inputs + * @return {Quaternion} this + */ + slerp(q, t) { + quat.slerp(this.elements, this.elements, q.elements, t); + this.onUpdate(); + return this; + }, + /** + * Performs a spherical linear interpolation with two control points + * @param {Quaternion} qa + * @param {Quaternion} qb + * @param {Quaternion} qc + * @param {Quaternion} qd + * @param {Number} t interpolation amount + * @return {Quaternion} this + */ + sqlerp(qa, qb, qc, qd, t) { + quat.sqlerp(this.elements, qa.elements, qb.elements, qc.elements, qd.elements, t); + this.onUpdate(); + return this; + }, + /** + * Calculates the inverse of a quat + * @return {Quaternion} this + */ + invert() { + quat.invert(this.elements, this.elements); + this.onUpdate(); + return this; + }, + /** + * Calculates the conjugate of a quat + * If the quaternion is normalized, this function is faster than quat.inverse and produces the same result. + * @return {Quaternion} this + */ + conjugate() { + quat.conjugate(this.elements, this.elements); + this.onUpdate(); + return this; + }, + /** + * Calculates the length of a quat + * @return {Number} length of this + */ + length() { + return quat.length(this.elements); + }, + /** + * Calculates the squared length of a quat + * @return {Number} squared length of this + */ + squaredLength() { + return quat.squaredLength(this.elements); + }, + /** + * Normalize this + * @return {Quaternion} this + */ + normalize() { + quat.normalize(this.elements, this.elements); + this.onUpdate(); + return this; + }, + /** + * Creates a quaternion from the given 3x3 rotation matrix. + * + * NOTE: The resultant quaternion is not normalized, so you should be sure + * to renormalize the quaternion yourself where necessary. + * + * @param {Matrix3} m rotation matrix + * @return {Quaternion} this + */ + fromMat3(mat) { + quat.fromMat3(this.elements, mat.elements); + this.onUpdate(); + return this; + }, + /** + * Creates a quaternion from the given 3x3 rotation matrix. + * + * NOTE: The resultant quaternion is not normalized, so you should be sure + * to renormalize the quaternion yourself where necessary. + * + * @param {Matrix4} m rotation matrix + * @return {Quaternion} this + */ + fromMat4(mat) { + tempMat3.fromMat4(mat); + this.fromMat3(tempMat3); + return this; + }, + /** + * Returns whether or not the quaternions have exactly the same elements in the same position (when compared with ===) + * @param {Quaternion} q + * @return {Boolean} + */ + exactEquals(q) { + return quat.exactEquals(this.elements, q.elements); + }, + /** + * Returns whether or not the quaternions have approximately the same elements in the same position. + * @param {Quaternion} q + * @return {Boolean} + */ + equals(q) { + return quat.equals(this.elements, q.elements); + }, + /** + * Creates a quaternion from the given euler. + * @param {Euler} euler + * @param {Boolean} [notCallUpdate=false] 是否需要调用onUpdate + * @return {Quaternion} this + */ + fromEuler(euler, notCallUpdate) { + // Based on https://github.com/mrdoob/three.js/blob/dev/src/math/Quaternion.js#L200 + + // quat.fromEuler(this.elements, euler.x, euler.y, euler.z); + const x = euler.x * .5; + const y = euler.y * .5; + const z = euler.z * .5; + const order = euler.order || 'ZYX'; + + let sx = Math.sin(x); + let cx = Math.cos(x); + let sy = Math.sin(y); + let cy = Math.cos(y); + let sz = Math.sin(z); + let cz = Math.cos(z); + + const out = this.elements; + + if (order === 'XYZ') { + out[0] = sx * cy * cz + cx * sy * sz; + out[1] = cx * sy * cz - sx * cy * sz; + out[2] = cx * cy * sz + sx * sy * cz; + out[3] = cx * cy * cz - sx * sy * sz; + } else if (order === 'YXZ') { + out[0] = sx * cy * cz + cx * sy * sz; + out[1] = cx * sy * cz - sx * cy * sz; + out[2] = cx * cy * sz - sx * sy * cz; + out[3] = cx * cy * cz + sx * sy * sz; + } else if (order === 'ZXY') { + out[0] = sx * cy * cz - cx * sy * sz; + out[1] = cx * sy * cz + sx * cy * sz; + out[2] = cx * cy * sz + sx * sy * cz; + out[3] = cx * cy * cz - sx * sy * sz; + } else if (order === 'ZYX') { + out[0] = sx * cy * cz - cx * sy * sz; + out[1] = cx * sy * cz + sx * cy * sz; + out[2] = cx * cy * sz - sx * sy * cz; + out[3] = cx * cy * cz + sx * sy * sz; + } else if (order === 'YZX') { + out[0] = sx * cy * cz + cx * sy * sz; + out[1] = cx * sy * cz + sx * cy * sz; + out[2] = cx * cy * sz - sx * sy * cz; + out[3] = cx * cy * cz - sx * sy * sz; + } else if (order === 'XZY') { + out[0] = sx * cy * cz - cx * sy * sz; + out[1] = cx * sy * cz - sx * cy * sz; + out[2] = cx * cy * sz + sx * sy * cz; + out[3] = cx * cy * cz + sx * sy * sz; + } + + if (!notCallUpdate) { + this.onUpdate(); + } + + return this; + }, + /** + * X component + * @type {Number} + */ + x: { + get() { + return this.elements[0]; + }, + set(value) { + this.elements[0] = value; + this.onUpdate(); + } + }, + /** + * Y component + * @type {Number} + */ + y: { + get() { + return this.elements[1]; + }, + set(value) { + this.elements[1] = value; + this.onUpdate(); + } + }, + /** + * Z component + * @type {Number} + */ + z: { + get() { + return this.elements[2]; + }, + set(value) { + this.elements[2] = value; + this.onUpdate(); + } + }, + /** + * W component + * @type {Number} + */ + w: { + get() { + return this.elements[3]; + }, + set(value) { + this.elements[3] = value; + this.onUpdate(); + } + } +}); + +/** + * Alias for {@link QuaternionNotifier#multiply} + * @function + * @param {QuaternionNotifier} q + */ +QuaternionNotifier.prototype.mul = QuaternionNotifier.prototype.multiply; + +/** + * Alias for {@link QuaternionNotifier#length} + * @function + */ +QuaternionNotifier.prototype.len = QuaternionNotifier.prototype.length; + +/** + * Alias for {@link QuaternionNotifier#squaredLength} + * @function + */ +QuaternionNotifier.prototype.sqrLen = QuaternionNotifier.prototype.squaredLength; + +export default QuaternionNotifier; diff --git a/src/math/Vector3Notifier.js b/src/math/Vector3Notifier.js index a92aa9e..ac9de6d 100644 --- a/src/math/Vector3Notifier.js +++ b/src/math/Vector3Notifier.js @@ -2,18 +2,14 @@ import { vec3 } from 'gl-matrix'; import Class from '../core/Class'; -import EventMixin from '../core/EventMixin'; import Vector3 from './Vector3'; /** * 三维向量, 数据改变会发送事件 * @class - * @mixes EventMixin * @extends Vector3 - * @fires update 数据更新事件 */ const Vector3Notifier = Class.create(/** @lends Vector3Notifier.prototype */ { - Mixes: EventMixin, Extends: Vector3, /** * 类名 notify @@ -39,6 +35,12 @@ const Vector3Notifier = Class.create(/** @lends Vector3Notifier.prototype */ { * @type {Float32Array} */ this.elements = vec3.fromValues(x, y, z); + }, + /** + * 更新的回调 + */ + onUpdate() { + }, /** * Copy the values from one vec3 to this @@ -47,7 +49,7 @@ const Vector3Notifier = Class.create(/** @lends Vector3Notifier.prototype */ { */ copy(v) { vec3.copy(this.elements, v.elements); - this.fire('update'); + this.onUpdate(); return this; }, /** @@ -82,7 +84,7 @@ const Vector3Notifier = Class.create(/** @lends Vector3Notifier.prototype */ { elements[0] = array[offset + 0]; elements[1] = array[offset + 1]; elements[2] = array[offset + 2]; - this.fire('update'); + this.onUpdate(); return this; }, /** @@ -94,7 +96,7 @@ const Vector3Notifier = Class.create(/** @lends Vector3Notifier.prototype */ { */ set(x, y, z) { vec3.set(this.elements, x, y, z); - this.fire('update'); + this.onUpdate(); return this; }, /** @@ -109,7 +111,7 @@ const Vector3Notifier = Class.create(/** @lends Vector3Notifier.prototype */ { a = this; } vec3.add(this.elements, a.elements, b.elements); - this.fire('update'); + this.onUpdate(); return this; }, /** @@ -124,7 +126,7 @@ const Vector3Notifier = Class.create(/** @lends Vector3Notifier.prototype */ { a = this; } vec3.subtract(this.elements, a.elements, b.elements); - this.fire('update'); + this.onUpdate(); return this; }, /** @@ -139,7 +141,7 @@ const Vector3Notifier = Class.create(/** @lends Vector3Notifier.prototype */ { a = this; } vec3.multiply(this.elements, a.elements, b.elements); - this.fire('update'); + this.onUpdate(); return this; }, /** @@ -154,7 +156,7 @@ const Vector3Notifier = Class.create(/** @lends Vector3Notifier.prototype */ { a = this; } vec3.divide(this.elements, a.elements, b.elements); - this.fire('update'); + this.onUpdate(); return this; }, /** @@ -163,7 +165,7 @@ const Vector3Notifier = Class.create(/** @lends Vector3Notifier.prototype */ { */ ceil() { vec3.ceil(this.elements, this.elements); - this.fire('update'); + this.onUpdate(); return this; }, /** @@ -172,7 +174,7 @@ const Vector3Notifier = Class.create(/** @lends Vector3Notifier.prototype */ { */ floor() { vec3.floor(this.elements, this.elements); - this.fire('update'); + this.onUpdate(); return this; }, /** @@ -187,7 +189,7 @@ const Vector3Notifier = Class.create(/** @lends Vector3Notifier.prototype */ { a = this; } vec3.min(this.elements, a.elements, b.elements); - this.fire('update'); + this.onUpdate(); return this; }, /** @@ -202,7 +204,7 @@ const Vector3Notifier = Class.create(/** @lends Vector3Notifier.prototype */ { a = this; } vec3.max(this.elements, a.elements, b.elements); - this.fire('update'); + this.onUpdate(); return this; }, /** @@ -211,7 +213,7 @@ const Vector3Notifier = Class.create(/** @lends Vector3Notifier.prototype */ { */ round() { vec3.round(this.elements, this.elements); - this.fire('update'); + this.onUpdate(); return this; }, /** @@ -221,7 +223,7 @@ const Vector3Notifier = Class.create(/** @lends Vector3Notifier.prototype */ { */ scale(scale) { vec3.scale(this.elements, this.elements, scale); - this.fire('update'); + this.onUpdate(); return this; }, /** @@ -237,7 +239,7 @@ const Vector3Notifier = Class.create(/** @lends Vector3Notifier.prototype */ { a = this; } vec3.scaleAndAdd(this.elements, a.elements, b.elements, scale); - this.fire('update'); + this.onUpdate(); return this; }, /** @@ -286,7 +288,7 @@ const Vector3Notifier = Class.create(/** @lends Vector3Notifier.prototype */ { */ negate() { vec3.negate(this.elements, this.elements); - this.fire('update'); + this.onUpdate(); return this; }, /** @@ -299,7 +301,7 @@ const Vector3Notifier = Class.create(/** @lends Vector3Notifier.prototype */ { a = this; } vec3.inverse(this.elements, a.elements); - this.fire('update'); + this.onUpdate(); return this; }, /** @@ -308,7 +310,7 @@ const Vector3Notifier = Class.create(/** @lends Vector3Notifier.prototype */ { */ normalize() { vec3.normalize(this.elements, this.elements); - this.fire('update'); + this.onUpdate(); return this; }, /** @@ -336,7 +338,7 @@ const Vector3Notifier = Class.create(/** @lends Vector3Notifier.prototype */ { a = this; } vec3.cross(this.elements, a.elements, b.elements); - this.fire('update'); + this.onUpdate(); return this; }, /** @@ -347,7 +349,7 @@ const Vector3Notifier = Class.create(/** @lends Vector3Notifier.prototype */ { */ lerp(v, t) { vec3.lerp(this.elements, this.elements, v.elements, t); - this.fire('update'); + this.onUpdate(); return this; }, /** @@ -361,7 +363,7 @@ const Vector3Notifier = Class.create(/** @lends Vector3Notifier.prototype */ { */ hermite(a, b, c, d, t) { vec3.hermite(this.elements, a.elements, b.elements, c.elements, d.elements, t); - this.fire('update'); + this.onUpdate(); return this; }, /** @@ -375,7 +377,7 @@ const Vector3Notifier = Class.create(/** @lends Vector3Notifier.prototype */ { */ bezier(a, b, c, d, t) { vec3.bezier(this.elements, a.elements, b.elements, c.elements, d.elements, t); - this.fire('update'); + this.onUpdate(); return this; }, /** @@ -385,7 +387,7 @@ const Vector3Notifier = Class.create(/** @lends Vector3Notifier.prototype */ { */ random(scale) { vec3.random(this.elements, scale); - this.fire('update'); + this.onUpdate(); return this; }, /** @@ -395,7 +397,7 @@ const Vector3Notifier = Class.create(/** @lends Vector3Notifier.prototype */ { */ transformMat3(m) { vec3.transformMat3(this.elements, this.elements, m.elements); - this.fire('update'); + this.onUpdate(); return this; }, /** @@ -405,7 +407,7 @@ const Vector3Notifier = Class.create(/** @lends Vector3Notifier.prototype */ { */ transformMat4(m) { vec3.transformMat4(this.elements, this.elements, m.elements); - this.fire('update'); + this.onUpdate(); return this; }, /** @@ -424,7 +426,7 @@ const Vector3Notifier = Class.create(/** @lends Vector3Notifier.prototype */ { elements[1] = x * mElements[1] + y * mElements[5] + z * mElements[9]; elements[2] = x * mElements[2] + y * mElements[6] + z * mElements[10]; - this.fire('update'); + this.onUpdate(); return this; }, /** @@ -434,7 +436,7 @@ const Vector3Notifier = Class.create(/** @lends Vector3Notifier.prototype */ { */ transformQuat(q) { vec3.transformQuat(this.elements, this.elements, q.elements); - this.fire('update'); + this.onUpdate(); return this; }, /** @@ -445,7 +447,7 @@ const Vector3Notifier = Class.create(/** @lends Vector3Notifier.prototype */ { */ rotateX(origin, rotation) { vec3.rotateX(this.elements, this.elements, origin.elements, rotation); - this.fire('update'); + this.onUpdate(); return this; }, /** @@ -456,7 +458,7 @@ const Vector3Notifier = Class.create(/** @lends Vector3Notifier.prototype */ { */ rotateY(origin, rotation) { vec3.rotateY(this.elements, this.elements, origin.elements, rotation); - this.fire('update'); + this.onUpdate(); return this; }, /** @@ -467,7 +469,7 @@ const Vector3Notifier = Class.create(/** @lends Vector3Notifier.prototype */ { */ rotateZ(origin, rotation) { vec3.rotateZ(this.elements, this.elements, origin.elements, rotation); - this.fire('update'); + this.onUpdate(); return this; }, /** @@ -506,7 +508,7 @@ const Vector3Notifier = Class.create(/** @lends Vector3Notifier.prototype */ { }, set(value) { this.elements[0] = value; - this.fire('update'); + this.onUpdate(); } }, /** @@ -519,7 +521,7 @@ const Vector3Notifier = Class.create(/** @lends Vector3Notifier.prototype */ { }, set(value) { this.elements[1] = value; - this.fire('update'); + this.onUpdate(); } }, /** @@ -532,7 +534,7 @@ const Vector3Notifier = Class.create(/** @lends Vector3Notifier.prototype */ { }, set(value) { this.elements[2] = value; - this.fire('update'); + this.onUpdate(); } } });