@galacean/effects-threejs 2.1.0-alpha.8 → 2.1.0-alpha.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -3,7 +3,7 @@
3
3
  * Description: Galacean Effects runtime threejs plugin for the web
4
4
  * Author: Ant Group CO., Ltd.
5
5
  * Contributors: 燃然,飂兮,十弦,云垣,茂安,意绮
6
- * Version: v2.1.0-alpha.8
6
+ * Version: v2.1.0-alpha.9
7
7
  */
8
8
 
9
9
  'use strict';
@@ -2178,41 +2178,6 @@ __decorate([
2178
2178
  serialize()
2179
2179
  ], RendererComponent.prototype, "_priority", void 0);
2180
2180
 
2181
- function _array_like_to_array(arr, len) {
2182
- if (len == null || len > arr.length) len = arr.length;
2183
- for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
2184
- return arr2;
2185
- }
2186
-
2187
- function _unsupported_iterable_to_array(o, minLen) {
2188
- if (!o) return;
2189
- if (typeof o === "string") return _array_like_to_array(o, minLen);
2190
- var n = Object.prototype.toString.call(o).slice(8, -1);
2191
- if (n === "Object" && o.constructor) n = o.constructor.name;
2192
- if (n === "Map" || n === "Set") return Array.from(n);
2193
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
2194
- }
2195
-
2196
- function _create_for_of_iterator_helper_loose(o, allowArrayLike) {
2197
- var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
2198
- if (it) return (it = it.call(o)).next.bind(it);
2199
- // Fallback for engines without symbol support
2200
- if (Array.isArray(o) || (it = _unsupported_iterable_to_array(o)) || allowArrayLike && o && typeof o.length === "number") {
2201
- if (it) o = it;
2202
- var i = 0;
2203
- return function() {
2204
- if (i >= o.length) return {
2205
- done: true
2206
- };
2207
- return {
2208
- done: false,
2209
- value: o[i++]
2210
- };
2211
- };
2212
- }
2213
- throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
2214
- }
2215
-
2216
2181
  var PI2 = Math.PI * 2;
2217
2182
  var DEG2RAD = Math.PI / 180;
2218
2183
  var RAD2DEG = 180 / Math.PI;
@@ -3219,26 +3184,26 @@ Vector3.ONE = new Vector3(1.0, 1.0, 1.0);
3219
3184
  Vector3.ZERO = new Vector3(0.0, 0.0, 0.0);
3220
3185
 
3221
3186
  /**
3222
- * 四元数
3223
- */ var Quaternion = /*#__PURE__*/ function() {
3224
- function Quaternion(x, y, z, w) {
3187
+ * 四维向量
3188
+ */ var Vector4 = /*#__PURE__*/ function() {
3189
+ function Vector4(x, y, z, w) {
3225
3190
  if (x === void 0) x = 0;
3226
3191
  if (y === void 0) y = 0;
3227
3192
  if (z === void 0) z = 0;
3228
- if (w === void 0) w = 1;
3193
+ if (w === void 0) w = 0;
3229
3194
  this.x = x;
3230
3195
  this.y = y;
3231
3196
  this.z = z;
3232
3197
  this.w = w;
3233
3198
  }
3234
- var _proto = Quaternion.prototype;
3199
+ var _proto = Vector4.prototype;
3235
3200
  /**
3236
- * 四元数设置
3237
- * @param x - x 分量
3238
- * @param y - y 分量
3239
- * @param z - z 分量
3240
- * @param w - w 分量
3241
- * @returns 四元数
3201
+ * 设置向量
3202
+ * @param x - x 轴分量
3203
+ * @param y - y 轴分量
3204
+ * @param z - z 轴分量
3205
+ * @param w - w 轴分量
3206
+ * @returns
3242
3207
  */ _proto.set = function set(x, y, z, w) {
3243
3208
  this.x = x;
3244
3209
  this.y = y;
@@ -3247,1356 +3212,1165 @@ Vector3.ZERO = new Vector3(0.0, 0.0, 0.0);
3247
3212
  return this;
3248
3213
  };
3249
3214
  /**
3250
- * 通过欧拉角设置四元数
3251
- * @param euler - 欧拉角
3252
- * @returns
3253
- */ _proto.setFromEuler = function setFromEuler(euler) {
3254
- euler.toQuaternion(this);
3255
- return this;
3256
- };
3257
- /**
3258
- * 通过旋转轴和旋转角度设置四元数
3259
- * @param axis - 旋转轴
3260
- * @param angle - 旋转角度(弧度)
3261
- * @returns
3262
- */ _proto.setFromAxisAngle = function setFromAxisAngle(axis, angle) {
3263
- var halfAngle = angle / 2;
3264
- var s = Math.sin(halfAngle);
3265
- var v = Quaternion.tempVec0;
3266
- v.copyFrom(axis).normalize();
3267
- this.x = v.x * s;
3268
- this.y = v.y * s;
3269
- this.z = v.z * s;
3270
- this.w = Math.cos(halfAngle);
3215
+ * 设置零向量
3216
+ * @returns 向量
3217
+ */ _proto.setZero = function setZero() {
3218
+ this.x = 0;
3219
+ this.y = 0;
3220
+ this.z = 0;
3221
+ this.w = 0;
3271
3222
  return this;
3272
3223
  };
3273
3224
  /**
3274
- * 通过 Vector4Like 创建四元数
3275
- * @param v - Vector4Like
3276
- * @returns
3277
- */ _proto.setFromVector4 = function setFromVector4(v) {
3278
- this.x = v.x;
3279
- this.y = v.y;
3280
- this.z = v.z;
3281
- this.w = v.w;
3225
+ * 通过标量数值设置向量
3226
+ * @param num - 数值
3227
+ * @returns 向量
3228
+ */ _proto.setFromNumber = function setFromNumber(num) {
3229
+ this.x = num;
3230
+ this.y = num;
3231
+ this.z = num;
3232
+ this.w = num;
3282
3233
  return this;
3283
3234
  };
3284
3235
  /**
3285
- * 通过数组设置四元数
3236
+ * 通过数组创建向量
3286
3237
  * @param array - 数组
3287
3238
  * @param [offset=0] - 起始偏移值
3288
- * @returns
3239
+ * @returns 向量
3289
3240
  */ _proto.setFromArray = function setFromArray(array, offset) {
3290
3241
  if (offset === void 0) offset = 0;
3291
- this.x = array[offset];
3292
- this.y = array[offset + 1];
3293
- this.z = array[offset + 2];
3294
- this.w = array[offset + 3];
3295
- return this;
3296
- };
3297
- /**
3298
- * 通过矩阵设置四元数
3299
- * @param m - 矩阵
3300
- * @returns
3301
- */ _proto.setFromRotationMatrix = function setFromRotationMatrix(m) {
3302
- // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/index.htm
3303
- // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
3304
- var te = m.elements;
3305
- var m11 = te[0];
3306
- var m12 = te[4];
3307
- var m13 = te[8];
3308
- var m21 = te[1];
3309
- var m22 = te[5];
3310
- var m23 = te[9];
3311
- var m31 = te[2];
3312
- var m32 = te[6];
3313
- var m33 = te[10];
3314
- var trace = m11 + m22 + m33;
3315
- if (trace > 0) {
3316
- var s = 0.5 / Math.sqrt(trace + 1.0);
3317
- this.w = 0.25 / s;
3318
- this.x = (m32 - m23) * s;
3319
- this.y = (m13 - m31) * s;
3320
- this.z = (m21 - m12) * s;
3321
- } else if (m11 > m22 && m11 > m33) {
3322
- var s1 = 2.0 * Math.sqrt(1.0 + m11 - m22 - m33);
3323
- this.w = (m32 - m23) / s1;
3324
- this.x = 0.25 * s1;
3325
- this.y = (m12 + m21) / s1;
3326
- this.z = (m13 + m31) / s1;
3327
- this.negate();
3328
- } else if (m22 > m33) {
3329
- var s2 = 2.0 * Math.sqrt(1.0 + m22 - m11 - m33);
3330
- this.w = (m13 - m31) / s2;
3331
- this.x = (m12 + m21) / s2;
3332
- this.y = 0.25 * s2;
3333
- this.z = (m23 + m32) / s2;
3334
- this.negate();
3335
- } else {
3336
- var s3 = 2.0 * Math.sqrt(1.0 + m33 - m11 - m22);
3337
- this.w = (m21 - m12) / s3;
3338
- this.x = (m13 + m31) / s3;
3339
- this.y = (m23 + m32) / s3;
3340
- this.z = 0.25 * s3;
3341
- this.negate();
3342
- }
3343
- // 兼容原先数学库
3242
+ var _array_offset;
3243
+ this.x = (_array_offset = array[offset]) != null ? _array_offset : 0;
3244
+ var _array_;
3245
+ this.y = (_array_ = array[offset + 1]) != null ? _array_ : 0;
3246
+ var _array_1;
3247
+ this.z = (_array_1 = array[offset + 2]) != null ? _array_1 : 0;
3248
+ var _array_2;
3249
+ this.w = (_array_2 = array[offset + 3]) != null ? _array_2 : 0;
3344
3250
  return this;
3345
3251
  };
3346
3252
  /**
3347
- * 通过开始和结束向量设置四元数
3348
- * @param from - 开始向量
3349
- * @param to - 结束向量
3350
- * @returns
3351
- */ _proto.setFromUnitVectors = function setFromUnitVectors(from, to) {
3352
- // assumes direction vectors vFrom and vTo are normalized
3353
- var r = from.dot(to) + 1;
3354
- if (r < Number.EPSILON) {
3355
- r = 0;
3356
- if (Math.abs(from.x) > Math.abs(from.z)) {
3357
- this.x = -from.y;
3358
- this.y = from.x;
3359
- this.z = 0;
3360
- this.w = r;
3361
- } else {
3362
- this.x = 0;
3363
- this.y = -from.z;
3364
- this.z = from.y;
3365
- this.w = r;
3366
- }
3367
- } else {
3368
- this.x = from.y * to.z - from.z * to.y;
3369
- this.y = from.z * to.x - from.x * to.z;
3370
- this.z = from.x * to.y - from.y * to.x;
3371
- this.w = r;
3372
- }
3373
- return this.normalize();
3374
- };
3375
- /**
3376
- * 四元数拷贝
3377
- * @param quat - 拷贝目标四元数
3378
- * @returns 拷贝四元数
3379
- */ _proto.copyFrom = function copyFrom(quat) {
3380
- this.x = quat.x;
3381
- this.y = quat.y;
3382
- this.z = quat.z;
3383
- this.w = quat.w;
3253
+ * 拷贝向量
3254
+ * @param v - 复制对象
3255
+ * @returns 拷贝结果
3256
+ */ _proto.copyFrom = function copyFrom(v) {
3257
+ this.x = v.x;
3258
+ this.y = v.y;
3259
+ this.z = v.z;
3260
+ this.w = v.w;
3384
3261
  return this;
3385
3262
  };
3386
3263
  /**
3387
- * 四元数克隆
3264
+ * 克隆向量
3388
3265
  * @returns 克隆结果
3389
3266
  */ _proto.clone = function clone() {
3390
- return new Quaternion(this.x, this.y, this.z, this.w);
3391
- };
3392
- /**
3393
- * 四元数间的夹角计算
3394
- * @param other - 其他四元数
3395
- * @returns 夹角
3396
- */ _proto.angleTo = function angleTo(other) {
3397
- return 2 * Math.acos(Math.abs(clamp$1(this.dot(other), -1, 1)));
3267
+ return new Vector4(this.x, this.y, this.z, this.w);
3398
3268
  };
3399
3269
  /**
3400
- * 四元数向目标旋转
3401
- * @param q - 四元数
3402
- * @param step - 旋转弧度
3403
- * @returns 目标四元数
3404
- */ _proto.rotateTowards = function rotateTowards(q, step) {
3405
- var angle = this.angleTo(q);
3406
- if (angle === 0) {
3407
- return this;
3270
+ * 根据下标设置向量分量
3271
+ * @param index - 下标值
3272
+ * @param value - 分量值
3273
+ * @returns 向量
3274
+ */ _proto.setElement = function setElement(index, value) {
3275
+ switch(index){
3276
+ case 0:
3277
+ this.x = value;
3278
+ break;
3279
+ case 1:
3280
+ this.y = value;
3281
+ break;
3282
+ case 2:
3283
+ this.z = value;
3284
+ break;
3285
+ case 3:
3286
+ this.w = value;
3287
+ break;
3288
+ default:
3289
+ console.error("index is out of range: " + index);
3408
3290
  }
3409
- var t = Math.min(1, step / angle);
3410
- this.slerp(q, t);
3411
3291
  return this;
3412
3292
  };
3413
3293
  /**
3414
- * 四元数单位化
3415
- * @returns 单位四元数
3416
- */ _proto.identity = function identity() {
3417
- return this.set(0, 0, 0, 1);
3294
+ * 根据下标获取向量分量
3295
+ * @param index - 下标
3296
+ * @returns 分量值
3297
+ */ _proto.getElement = function getElement(index) {
3298
+ switch(index){
3299
+ case 0:
3300
+ return this.x;
3301
+ case 1:
3302
+ return this.y;
3303
+ case 2:
3304
+ return this.z;
3305
+ case 3:
3306
+ return this.w;
3307
+ default:
3308
+ console.error("index is out of range: " + index);
3309
+ }
3310
+ return 0;
3418
3311
  };
3419
3312
  /**
3420
- * 四元数求逆
3421
- * @returns 四元数的逆
3422
- */ _proto.invert = function invert() {
3423
- return this.conjugate();
3313
+ * 向量相加
3314
+ * @param right - 相加对象,向量 | 数字
3315
+ * @returns 相加结果
3316
+ */ _proto.add = function add(right) {
3317
+ if (typeof right === "number") {
3318
+ this.x += right;
3319
+ this.y += right;
3320
+ this.z += right;
3321
+ this.w += right;
3322
+ } else if (_instanceof1(right, Array)) {
3323
+ this.x += right[0];
3324
+ this.y += right[1];
3325
+ this.z += right[2];
3326
+ this.w += right[3];
3327
+ } else {
3328
+ this.x += right.x;
3329
+ this.y += right.y;
3330
+ this.z += right.z;
3331
+ this.w += right.w;
3332
+ }
3333
+ return this;
3424
3334
  };
3425
3335
  /**
3426
- * 四元数取负
3427
- * @returns 负四元数
3428
- */ _proto.negate = function negate() {
3429
- this.x = -this.x;
3430
- this.y = -this.y;
3431
- this.z = -this.z;
3432
- this.w = -this.w;
3336
+ * 向量相加
3337
+ * @param left - 向量
3338
+ * @param right - 向量
3339
+ * @returns 求和结果
3340
+ */ _proto.addVectors = function addVectors(left, right) {
3341
+ this.x = left.x + right.x;
3342
+ this.y = left.y + right.y;
3343
+ this.z = left.z + right.z;
3344
+ this.w = left.w + right.w;
3433
3345
  return this;
3434
3346
  };
3435
3347
  /**
3436
- * 四元数求共轭值
3437
- * @returns 四元数的共轭值
3438
- */ _proto.conjugate = function conjugate() {
3439
- this.x = -this.x;
3440
- this.y = -this.y;
3441
- this.z = -this.z;
3348
+ * 向量比例缩放后相加
3349
+ * @param right - 向量
3350
+ * @param s - 比例
3351
+ * @returns 求和结果
3352
+ */ _proto.addScaledVector = function addScaledVector(right, s) {
3353
+ this.x += right.x * s;
3354
+ this.y += right.y * s;
3355
+ this.z += right.z * s;
3356
+ this.w += right.w * s;
3442
3357
  return this;
3443
3358
  };
3444
3359
  /**
3445
- * 四元数点乘结果
3446
- * @param v
3447
- * @return
3448
- */ _proto.dot = function dot(v) {
3449
- return this.x * v.x + this.y * v.y + this.z * v.z + this.w * v.w;
3360
+ * 向量相减
3361
+ * @param right - 相减对象,向量 | 数字
3362
+ * @returns 相减结果
3363
+ */ _proto.subtract = function subtract(right) {
3364
+ if (typeof right === "number") {
3365
+ this.x -= right;
3366
+ this.y -= right;
3367
+ this.z -= right;
3368
+ this.w -= right;
3369
+ } else if (_instanceof1(right, Array)) {
3370
+ this.x -= right[0];
3371
+ this.y -= right[1];
3372
+ this.z -= right[2];
3373
+ this.w -= right[3];
3374
+ } else {
3375
+ this.x -= right.x;
3376
+ this.y -= right.y;
3377
+ this.z -= right.z;
3378
+ this.w -= right.w;
3379
+ }
3380
+ return this;
3450
3381
  };
3451
3382
  /**
3452
- * 四元数的模平方
3453
- * @return
3454
- */ _proto.lengthSquared = function lengthSquared() {
3455
- return this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w;
3383
+ * 向量相减
3384
+ * @param left - 向量
3385
+ * @param right - 向量
3386
+ * @returns 向量
3387
+ */ _proto.subtractVectors = function subtractVectors(left, right) {
3388
+ this.x = left.x - right.x;
3389
+ this.y = left.y - right.y;
3390
+ this.z = left.z - right.z;
3391
+ this.w = left.w - right.w;
3392
+ return this;
3456
3393
  };
3457
3394
  /**
3458
- * 四元数的欧式长度
3459
- * @returns 长度
3460
- */ _proto.length = function length() {
3461
- return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w);
3395
+ * 向量相乘
3396
+ * @param right - 相乘对象,对象 | 数字
3397
+ * @returns 向量
3398
+ */ _proto.multiply = function multiply(right) {
3399
+ if (typeof right === "number") {
3400
+ this.x *= right;
3401
+ this.y *= right;
3402
+ this.z *= right;
3403
+ this.w *= right;
3404
+ } else if (_instanceof1(right, Array)) {
3405
+ this.x *= right[0];
3406
+ this.y *= right[1];
3407
+ this.z *= right[2];
3408
+ this.w *= right[3];
3409
+ } else {
3410
+ this.x *= right.x;
3411
+ this.y *= right.y;
3412
+ this.z *= right.z;
3413
+ this.w *= right.w;
3414
+ }
3415
+ return this;
3462
3416
  };
3463
3417
  /**
3464
- * 四元数归一化
3465
- * @returns 归一化值
3466
- */ _proto.normalize = function normalize() {
3467
- var l = this.length();
3468
- if (l === 0) {
3469
- this.x = 0;
3470
- this.y = 0;
3471
- this.z = 0;
3472
- this.w = 1;
3418
+ * 向量相乘
3419
+ * @param left - 向量
3420
+ * @param right - 向量
3421
+ * @returns 向量
3422
+ */ _proto.multiplyVectors = function multiplyVectors(left, right) {
3423
+ this.x = left.x * right.x;
3424
+ this.y = left.y * right.y;
3425
+ this.z = left.z * right.z;
3426
+ this.w = left.w * right.w;
3427
+ return this;
3428
+ };
3429
+ /**
3430
+ * 向量相除
3431
+ * @param right - 相除对象,对象 | 数字
3432
+ * @returns 向量
3433
+ */ _proto.divide = function divide(right) {
3434
+ if (typeof right === "number") {
3435
+ this.x /= right;
3436
+ this.y /= right;
3437
+ this.z /= right;
3438
+ this.w /= right;
3439
+ } else if (_instanceof1(right, Array)) {
3440
+ this.x /= right[0];
3441
+ this.y /= right[1];
3442
+ this.z /= right[2];
3443
+ this.w /= right[3];
3473
3444
  } else {
3474
- l = 1 / l;
3475
- this.x = this.x * l;
3476
- this.y = this.y * l;
3477
- this.z = this.z * l;
3478
- this.w = this.w * l;
3445
+ this.x /= right.x;
3446
+ this.y /= right.y;
3447
+ this.z /= right.z;
3448
+ this.w /= right.w;
3479
3449
  }
3480
3450
  return this;
3481
3451
  };
3482
3452
  /**
3483
- * 四元数右乘
3484
- * @param right - 右乘的四元数
3485
- * @returns
3486
- */ _proto.multiply = function multiply(right) {
3487
- return this.multiplyQuaternions(this, right);
3453
+ * 向量缩放
3454
+ * @param v - 数字
3455
+ * @returns 缩放结果
3456
+ */ _proto.scale = function scale(v) {
3457
+ this.x *= v;
3458
+ this.y *= v;
3459
+ this.z *= v;
3460
+ this.w *= v;
3461
+ return this;
3488
3462
  };
3489
3463
  /**
3490
- * 四元数左乘
3491
- * @param left - 左乘的四元数
3492
- * @returns
3493
- */ _proto.premultiply = function premultiply(left) {
3494
- return this.multiplyQuaternions(left, this);
3464
+ * 分量求和
3465
+ * @returns 求和结果
3466
+ */ _proto.sum = function sum() {
3467
+ return this.x + this.y + this.z + this.w;
3495
3468
  };
3496
3469
  /**
3497
- * 四元数乘法
3498
- * @param left - 四元数
3499
- * @param right - 四元数
3500
- * @returns 四元数
3501
- */ _proto.multiplyQuaternions = function multiplyQuaternions(left, right) {
3502
- // from http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/code/index.htm
3503
- var qax = left.x;
3504
- var qay = left.y;
3505
- var qaz = left.z;
3506
- var qaw = left.w;
3507
- var qbx = right.x;
3508
- var qby = right.y;
3509
- var qbz = right.z;
3510
- var qbw = right.w;
3511
- this.x = qax * qbw + qaw * qbx + qay * qbz - qaz * qby;
3512
- this.y = qay * qbw + qaw * qby + qaz * qbx - qax * qbz;
3513
- this.z = qaz * qbw + qaw * qbz + qax * qby - qay * qbx;
3514
- this.w = qaw * qbw - qax * qbx - qay * qby - qaz * qbz;
3470
+ * 向量求最小值
3471
+ * @param v - 向量或数值
3472
+ * @returns 最小值
3473
+ */ _proto.min = function min(v) {
3474
+ if (typeof v === "number") {
3475
+ this.x = Math.min(this.x, v);
3476
+ this.y = Math.min(this.y, v);
3477
+ this.z = Math.min(this.z, v);
3478
+ this.w = Math.min(this.w, v);
3479
+ } else {
3480
+ this.x = Math.min(this.x, v.x);
3481
+ this.y = Math.min(this.y, v.y);
3482
+ this.z = Math.min(this.z, v.z);
3483
+ this.w = Math.min(this.w, v.w);
3484
+ }
3515
3485
  return this;
3516
3486
  };
3517
3487
  /**
3518
- * 四元数线性插值
3519
- * @see http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/slerp/
3520
- * @param other - 四元数
3521
- * @param t - 插值比
3522
- * @returns 插值结果
3523
- */ _proto.slerp = function slerp(other, t) {
3524
- if (t === 0) {
3525
- return this;
3526
- }
3527
- if (t === 1) {
3528
- return this.copyFrom(other);
3529
- }
3530
- var _this = this, x = _this.x, y = _this.y, z = _this.z, w = _this.w;
3531
- var cosHalfTheta = w * other.w + x * other.x + y * other.y + z * other.z;
3532
- if (cosHalfTheta < 0) {
3533
- this.w = -other.w;
3534
- this.x = -other.x;
3535
- this.y = -other.y;
3536
- this.z = -other.z;
3537
- cosHalfTheta = -cosHalfTheta;
3488
+ * 向量求最大值
3489
+ * @param v - 向量或数值
3490
+ * @returns 最大值
3491
+ */ _proto.max = function max(v) {
3492
+ if (typeof v === "number") {
3493
+ this.x = Math.max(this.x, v);
3494
+ this.y = Math.max(this.y, v);
3495
+ this.z = Math.max(this.z, v);
3496
+ this.w = Math.max(this.w, v);
3538
3497
  } else {
3539
- this.copyFrom(other);
3540
- }
3541
- if (cosHalfTheta >= 1.0) {
3542
- this.w = w;
3543
- this.x = x;
3544
- this.y = y;
3545
- this.z = z;
3546
- return this;
3547
- }
3548
- var sqrSinHalfTheta = 1.0 - cosHalfTheta * cosHalfTheta;
3549
- if (sqrSinHalfTheta <= Number.EPSILON) {
3550
- var s = 1 - t;
3551
- this.w = s * w + t * this.w;
3552
- this.x = s * x + t * this.x;
3553
- this.y = s * y + t * this.y;
3554
- this.z = s * z + t * this.z;
3555
- this.normalize();
3556
- return this;
3498
+ this.x = Math.max(this.x, v.x);
3499
+ this.y = Math.max(this.y, v.y);
3500
+ this.z = Math.max(this.z, v.z);
3501
+ this.w = Math.max(this.w, v.w);
3557
3502
  }
3558
- var sinHalfTheta = Math.sqrt(sqrSinHalfTheta);
3559
- var halfTheta = Math.atan2(sinHalfTheta, cosHalfTheta);
3560
- var ratioA = Math.sin((1 - t) * halfTheta) / sinHalfTheta;
3561
- var ratioB = Math.sin(t * halfTheta) / sinHalfTheta;
3562
- this.w = w * ratioA + this.w * ratioB;
3563
- this.x = x * ratioA + this.x * ratioB;
3564
- this.y = y * ratioA + this.y * ratioB;
3565
- this.z = z * ratioA + this.z * ratioB;
3566
3503
  return this;
3567
3504
  };
3568
3505
  /**
3569
- * 两个四元数的线性插值
3570
- * @param qa - 四元数
3571
- * @param qb - 四元数
3572
- * @param t - 插值比
3573
- */ _proto.slerpQuaternions = function slerpQuaternions(qa, qb, t) {
3574
- this.copyFrom(qa).slerp(qb, t);
3506
+ * 向量阈值约束
3507
+ * @param min - 最小值
3508
+ * @param max - 最大值
3509
+ * @returns 向量
3510
+ */ _proto.clamp = function clamp(min, max) {
3511
+ return this.max(min).min(max);
3575
3512
  };
3576
3513
  /**
3577
- * 通过四元数旋转向量
3578
- * @param v - 待旋转向量
3579
- * @param [out] - 旋转结果,如果没有传入直接覆盖输入值
3580
- * @returns
3581
- */ _proto.rotateVector3 = function rotateVector3(v, out) {
3582
- var _this = this, qx = _this.x, qy = _this.y, qz = _this.z, qw = _this.w;
3583
- var vx = v.x, vy = v.y, vz = v.z;
3584
- var ix = qw * vx + qy * vz - qz * vy;
3585
- var iy = qw * vy + qz * vx - qx * vz;
3586
- var iz = qw * vz + qx * vy - qy * vx;
3587
- var iw = -qx * vx - qy * vy - qz * vz;
3588
- var res = out != null ? out : v;
3589
- res.x = ix * qw + iw * -qx + iy * -qz - iz * -qy;
3590
- res.y = iy * qw + iw * -qy + iz * -qx - ix * -qz;
3591
- res.z = iz * qw + iw * -qz + ix * -qy - iy * -qx;
3592
- return res;
3514
+ * 向量向下取整
3515
+ * @returns 取整结果
3516
+ */ _proto.floor = function floor() {
3517
+ this.x = Math.floor(this.x);
3518
+ this.y = Math.floor(this.y);
3519
+ this.z = Math.floor(this.z);
3520
+ this.w = Math.floor(this.w);
3521
+ return this;
3593
3522
  };
3594
3523
  /**
3595
- * 四元数判等
3596
- * @param quaternion - 四元数
3597
- * @returns 判等结果
3598
- */ _proto.equals = function equals(quaternion) {
3599
- return quaternion.x === this.x && quaternion.y === this.y && quaternion.z === this.z && quaternion.w === this.w;
3524
+ * 向量向上取整
3525
+ * @returns 取整结果
3526
+ */ _proto.ceil = function ceil() {
3527
+ this.x = Math.ceil(this.x);
3528
+ this.y = Math.ceil(this.y);
3529
+ this.z = Math.ceil(this.z);
3530
+ this.w = Math.ceil(this.w);
3531
+ return this;
3600
3532
  };
3601
3533
  /**
3602
- * 四元数保存为数组
3603
- * @returns
3604
- */ _proto.toArray = function toArray() {
3605
- return [
3606
- this.x,
3607
- this.y,
3608
- this.z,
3609
- this.w
3610
- ];
3534
+ * 向量四舍五入
3535
+ * @returns 求值结果
3536
+ */ _proto.round = function round() {
3537
+ this.x = Math.round(this.x);
3538
+ this.y = Math.round(this.y);
3539
+ this.z = Math.round(this.z);
3540
+ this.w = Math.round(this.w);
3541
+ return this;
3611
3542
  };
3612
3543
  /**
3613
- * 四元数转四维向量数组
3614
- * @param vec - 目标保存对象
3615
- * @returns 保存结果
3616
- */ _proto.toVector4 = function toVector4(vec) {
3617
- return vec.set(this.x, this.y, this.z, this.w);
3544
+ * 向量取绝对值
3545
+ * @returns 向量
3546
+ */ _proto.abs = function abs() {
3547
+ this.x = Math.abs(this.x);
3548
+ this.y = Math.abs(this.y);
3549
+ this.z = Math.abs(this.z);
3550
+ this.w = Math.abs(this.w);
3551
+ return this;
3618
3552
  };
3619
3553
  /**
3620
- * 四元数转欧拉角
3621
- * @param euler - 目标欧拉角
3622
- * @returns 欧拉角
3623
- */ _proto.toEuler = function toEuler(euler) {
3624
- return euler.setFromQuaternion(this);
3554
+ * 向量取反
3555
+ * @returns 取反结果
3556
+ */ _proto.negate = function negate() {
3557
+ this.x = -this.x;
3558
+ this.y = -this.y;
3559
+ this.z = -this.z;
3560
+ this.w = -this.w;
3561
+ return this;
3625
3562
  };
3626
3563
  /**
3627
- * 四元数转矩阵
3628
- * @param mat - 目标矩阵
3629
- * @returns
3630
- */ _proto.toMatrix4 = function toMatrix4(mat) {
3631
- return mat.compose(Vector3.ZERO, this, Vector3.ONE);
3564
+ * 向量长度平方
3565
+ * @returns 长度平方
3566
+ */ _proto.lengthSquared = function lengthSquared() {
3567
+ return this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w;
3632
3568
  };
3633
3569
  /**
3634
- * 通过欧拉角创建四元数
3635
- * @param euler - 欧拉角
3636
- * @returns 四元数
3637
- */ Quaternion.fromEuler = function fromEuler(euler) {
3638
- return new Quaternion().setFromEuler(euler);
3570
+ * 向量长度
3571
+ * @returns 长度
3572
+ */ _proto.length = function length() {
3573
+ return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w);
3639
3574
  };
3640
3575
  /**
3641
- * 通过旋转轴和旋转角度创建四元数
3642
- * @param axis - 旋转轴
3643
- * @param angle - 旋转角(弧度值)
3644
- * @returns 四元数
3645
- */ Quaternion.fromAxisAngle = function fromAxisAngle(axis, angle) {
3646
- return new Quaternion().setFromAxisAngle(axis, angle);
3576
+ * 向量归一化
3577
+ * @returns 归一化结果
3578
+ */ _proto.normalize = function normalize() {
3579
+ return this.divide(this.length() || 1);
3647
3580
  };
3648
3581
  /**
3649
- * 通过 Vector4Like 创建四元数
3650
- * @param v - Vector4Like
3651
- * @returns 四元数
3652
- */ Quaternion.fromVector4 = function fromVector4(v) {
3653
- return new Quaternion().setFromVector4(v);
3582
+ * 设置向量长度
3583
+ * @param length - 长度
3584
+ * @returns 向量
3585
+ */ _proto.setLength = function setLength(length) {
3586
+ return this.normalize().multiply(length);
3654
3587
  };
3655
3588
  /**
3656
- * 通过数组创建四元数
3657
- * @param array - 数组
3658
- * @param [offset=0] - 起始偏移值
3659
- * @returns 四元数
3660
- */ Quaternion.fromArray = function fromArray(array, offset) {
3661
- if (offset === void 0) offset = 0;
3662
- return new Quaternion().setFromArray(array, offset);
3589
+ * 向量求线性插值
3590
+ * @param v - 向量
3591
+ * @param alpha - 插值比例
3592
+ * @returns 插值结果
3593
+ */ _proto.lerp = function lerp(v, alpha) {
3594
+ this.x += (v.x - this.x) * alpha;
3595
+ this.y += (v.y - this.y) * alpha;
3596
+ this.z += (v.z - this.z) * alpha;
3597
+ this.w += (v.w - this.w) * alpha;
3598
+ return this;
3663
3599
  };
3664
3600
  /**
3665
- * 通过旋转矩阵创建四元数
3666
- * @param m - 旋转矩阵
3667
- * @returns 四元数
3668
- */ Quaternion.fromRotationMatrix = function fromRotationMatrix(m) {
3669
- return new Quaternion().setFromRotationMatrix(m);
3601
+ * 两向量求线性插值
3602
+ * @param v1 - 第一个向量
3603
+ * @param v2 - 第二个向量
3604
+ * @param alpha - 插值比例
3605
+ * @returns 插值结果
3606
+ */ _proto.lerpVectors = function lerpVectors(v1, v2, alpha) {
3607
+ this.x = v1.x + (v2.x - v1.x) * alpha;
3608
+ this.y = v1.y + (v2.y - v1.y) * alpha;
3609
+ this.z = v1.z + (v2.z - v1.z) * alpha;
3610
+ this.w = v1.w + (v2.w - v1.w) * alpha;
3611
+ return this;
3670
3612
  };
3671
3613
  /**
3672
- * 通过开始和结束向量创建四元数
3673
- * @param from - 开始向量
3674
- * @param to - 结束向量
3675
- * @returns
3676
- */ Quaternion.fromUnitVectors = function fromUnitVectors(from, to) {
3677
- return new Quaternion().setFromUnitVectors(from, to);
3614
+ * 向量求点积
3615
+ * @param v - 向量
3616
+ * @returns 点积结果
3617
+ */ _proto.dot = function dot(v) {
3618
+ return this.x * v.x + this.y * v.y + this.z * v.z + this.w * v.w;
3678
3619
  };
3679
- return Quaternion;
3680
- }();
3681
- Quaternion.tempVec0 = new Vector3();
3682
-
3683
- /**
3684
- * 四阶矩阵(列优先矩阵)
3685
- */ var Matrix4 = /*#__PURE__*/ function() {
3686
- function Matrix4(m11, m21, m31, m41, m12, m22, m32, m42, m13, m23, m33, m43, m14, m24, m34, m44) {
3687
- if (m11 === void 0) m11 = 1;
3688
- if (m21 === void 0) m21 = 0;
3689
- if (m31 === void 0) m31 = 0;
3690
- if (m41 === void 0) m41 = 0;
3691
- if (m12 === void 0) m12 = 0;
3692
- if (m22 === void 0) m22 = 1;
3693
- if (m32 === void 0) m32 = 0;
3694
- if (m42 === void 0) m42 = 0;
3695
- if (m13 === void 0) m13 = 0;
3696
- if (m23 === void 0) m23 = 0;
3697
- if (m33 === void 0) m33 = 1;
3698
- if (m43 === void 0) m43 = 0;
3699
- if (m14 === void 0) m14 = 0;
3700
- if (m24 === void 0) m24 = 0;
3701
- if (m34 === void 0) m34 = 0;
3702
- if (m44 === void 0) m44 = 1;
3703
- this.elements = [
3704
- m11,
3705
- m21,
3706
- m31,
3707
- m41,
3708
- m12,
3709
- m22,
3710
- m32,
3711
- m42,
3712
- m13,
3713
- m23,
3714
- m33,
3715
- m43,
3716
- m14,
3717
- m24,
3718
- m34,
3719
- m44
3720
- ];
3721
- }
3722
- var _proto = Matrix4.prototype;
3723
3620
  /**
3724
- * 设置矩阵
3725
- * @param m11 - 第 1 行,第 1 列
3726
- * @param m21 - 第 2 行,第 1 列
3727
- * @param m31 - 3 行,第 1 列
3728
- * @param m41 - 4 行,第 1
3729
- * @param m12 - 第 1 行,第 2 列
3730
- * @param m22 - 第 2 行,第 2 列
3731
- * @param m32 - 第 3 行,第 2 列
3732
- * @param m42 - 第 4 行,第 2 列
3733
- * @param m13 - 第 1 行,第 3 列
3734
- * @param m23 - 第 2 行,第 3 列
3735
- * @param m33 - 第 3 行,第 3 列
3736
- * @param m43 - 第 4 行,第 3 列
3737
- * @param m14 - 第 1 行,第 4 列
3738
- * @param m24 - 第 2 行,第 4 列
3739
- * @param m34 - 第 3 行,第 4 列
3740
- * @param m44 - 第 4 行,第 4 列
3741
- * @returns 矩阵
3742
- */ _proto.set = function set(m11, m21, m31, m41, m12, m22, m32, m42, m13, m23, m33, m43, m14, m24, m34, m44) {
3743
- var e = this.elements;
3744
- e[0] = m11;
3745
- e[1] = m21;
3746
- e[2] = m31;
3747
- e[3] = m41;
3748
- e[4] = m12;
3749
- e[5] = m22;
3750
- e[6] = m32;
3751
- e[7] = m42;
3752
- e[8] = m13;
3753
- e[9] = m23;
3754
- e[10] = m33;
3755
- e[11] = m43;
3756
- e[12] = m14;
3757
- e[13] = m24;
3758
- e[14] = m34;
3759
- e[15] = m44;
3760
- return this;
3621
+ * 向量判等
3622
+ * @param v - 向量
3623
+ * @returns 判等结果
3624
+ */ _proto.equals = function equals(v) {
3625
+ return v.x === this.x && v.y === this.y && v.z === this.z && v.w === this.w;
3761
3626
  };
3762
3627
  /**
3763
- * 通过行优先数据设置矩阵
3764
- * @param m11 - 第 1 行,第 1 列
3765
- * @param m12 - 1 行,第 2 列
3766
- * @param m13 - 第 1 行,第 3 列
3767
- * @param m14 - 1 行,第 4
3768
- * @param m21 - 2 行,第 1
3769
- * @param m22 - 第 2 行,第 2 列
3770
- * @param m23 - 第 2 行,第 3 列
3771
- * @param m24 - 第 2 行,第 4 列
3772
- * @param m31 - 第 3 行,第 1 列
3773
- * @param m32 - 第 3 行,第 2 列
3774
- * @param m33 - 第 3 行,第 3 列
3775
- * @param m34 - 第 3 行,第 4 列
3776
- * @param m41 - 第 4 行,第 1 列
3777
- * @param m42 - 第 4 行,第 2 列
3778
- * @param m43 - 第 4 行,第 3 列
3779
- * @param m44 - 第 4 行,第 4 列
3780
- * @returns 矩阵
3781
- */ _proto.setFromRowMajorData = function setFromRowMajorData(m11, m12, m13, m14, m21, m22, m23, m24, m31, m32, m33, m34, m41, m42, m43, m44) {
3782
- var e = this.elements;
3783
- e[0] = m11;
3784
- e[4] = m12;
3785
- e[8] = m13;
3786
- e[12] = m14;
3787
- e[1] = m21;
3788
- e[5] = m22;
3789
- e[9] = m23;
3790
- e[13] = m24;
3791
- e[2] = m31;
3792
- e[6] = m32;
3793
- e[10] = m33;
3794
- e[14] = m34;
3795
- e[3] = m41;
3796
- e[7] = m42;
3797
- e[11] = m43;
3798
- e[15] = m44;
3799
- return this;
3628
+ * 是否零向量
3629
+ * @returns 是否零向量
3630
+ */ _proto.isZero = function isZero() {
3631
+ var eps = NumberEpsilon;
3632
+ var _this = this, x = _this.x, y = _this.y, z = _this.z, w = _this.w;
3633
+ return Math.abs(x) <= eps && Math.abs(y) <= eps && Math.abs(z) <= eps && Math.abs(w) <= eps;
3800
3634
  };
3801
3635
  /**
3802
- * 通过四个列向量设置矩阵
3803
- * @param c1 - 第一列
3804
- * @param c2 - 第二列
3805
- * @param c3 - 第三列
3806
- * @param c4 - 第四列
3807
- * @returns 矩阵
3808
- */ _proto.setFromColumnVectors = function setFromColumnVectors(c1, c2, c3, c4) {
3809
- return this.set(c1.x, c1.y, c1.z, c1.w, c2.x, c2.y, c2.z, c2.w, c3.x, c3.y, c3.z, c3.w, c4.x, c4.y, c4.z, c4.w);
3636
+ * 向量转数组
3637
+ * @returns 数组
3638
+ */ _proto.toArray = function toArray() {
3639
+ return [
3640
+ this.x,
3641
+ this.y,
3642
+ this.z,
3643
+ this.w
3644
+ ];
3810
3645
  };
3811
- /**
3812
- * 通过三维矩阵设置矩阵
3813
- * @param m - 三维矩阵
3814
- * @returns 设置结果
3815
- */ _proto.setFromMatrix3 = function setFromMatrix3(m) {
3816
- var me = m.elements;
3817
- this.set(me[0], me[1], me[2], 0, me[3], me[4], me[5], 0, me[6], me[7], me[8], 0, 0, 0, 0, 1);
3818
- return this;
3646
+ _proto.toVector3 = function toVector3() {
3647
+ return new Vector3(this.x, this.y, this.z);
3819
3648
  };
3820
- /**
3821
- * 通过数组设置矩阵
3822
- * @param array - 数组
3823
- * @param [offset=0] - 起始偏移值
3824
- * @returns 矩阵
3825
- */ _proto.setFromArray = function setFromArray(array, offset) {
3649
+ _proto.fill = function fill(array, offset) {
3826
3650
  if (offset === void 0) offset = 0;
3827
- for(var i = 0; i < 16; i++){
3828
- this.elements[i] = array[offset + i];
3829
- }
3830
- return this;
3651
+ array[offset] = this.x;
3652
+ array[offset + 1] = this.y;
3653
+ array[offset + 2] = this.z;
3654
+ array[offset + 3] = this.w;
3831
3655
  };
3832
3656
  /**
3833
- * 通过缩放设置矩阵
3834
- * @param x - x 方向缩放
3835
- * @param y - y 方向缩放
3836
- * @param z - z 方向缩放
3837
- * @returns 缩放矩阵
3838
- */ _proto.setFromScale = function setFromScale(x, y, z) {
3839
- return this.set(x, 0, 0, 0, 0, y, 0, 0, 0, 0, z, 0, 0, 0, 0, 1);
3657
+ * 生成随机向量
3658
+ * @returns 向量
3659
+ */ _proto.random = function random() {
3660
+ this.x = Math.random();
3661
+ this.y = Math.random();
3662
+ this.z = Math.random();
3663
+ this.w = Math.random();
3664
+ return this;
3840
3665
  };
3841
3666
  /**
3842
- * 通过平移设置矩阵
3843
- * @param x - x 方向平移
3844
- * @param y - y 方向平移
3845
- * @param z - z 方向平移
3846
- * @returns 平移矩阵
3847
- */ _proto.setFromTranslation = function setFromTranslation(x, y, z) {
3848
- return this.set(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, x, y, z, 1);
3667
+ * 变换矩阵作用于向量
3668
+ * @param m - 变换矩阵
3669
+ * @param [out] - 输出结果,如果没有设置就直接覆盖当前值
3670
+ * @returns 向量
3671
+ */ _proto.applyMatrix = function applyMatrix(m, out) {
3672
+ return m.transformVector4(this, out);
3849
3673
  };
3850
3674
  /**
3851
- * 通过 x 轴旋转角度设置矩阵
3852
- * @param theta - x 轴旋转弧度
3853
- * @returns 矩阵
3854
- */ _proto.setFromRotationX = function setFromRotationX(theta) {
3855
- var c = Math.cos(theta);
3856
- var s = Math.sin(theta);
3857
- return this.set(1, 0, 0, 0, 0, c, s, 0, 0, -s, c, 0, 0, 0, 0, 1);
3675
+ * 通过标量数值创建向量
3676
+ * @param num - 数值
3677
+ * @returns 向量
3678
+ */ Vector4.fromNumber = function fromNumber(num) {
3679
+ return new Vector4().setFromNumber(num);
3858
3680
  };
3859
3681
  /**
3860
- * 通过 y 轴旋转角度设置矩阵
3861
- * @param theta - y 轴旋转弧度
3862
- * @returns 矩阵
3863
- */ _proto.setFromRotationY = function setFromRotationY(theta) {
3864
- var c = Math.cos(theta);
3865
- var s = Math.sin(theta);
3866
- return this.set(c, 0, -s, 0, 0, 1, 0, 0, s, 0, c, 0, 0, 0, 0, 1);
3682
+ * 通过数组创建向量
3683
+ * @param array - 数组
3684
+ * @param [offset=0] - 起始偏移值
3685
+ * @returns 向量
3686
+ */ Vector4.fromArray = function fromArray(array, offset) {
3687
+ if (offset === void 0) offset = 0;
3688
+ return new Vector4().setFromArray(array, offset);
3867
3689
  };
3868
- /**
3869
- * 通过 z 轴旋转角度设置矩阵
3870
- * @param theta - z 轴旋转弧度
3871
- * @returns 矩阵
3872
- */ _proto.setFromRotationZ = function setFromRotationZ(theta) {
3873
- var c = Math.cos(theta);
3874
- var s = Math.sin(theta);
3875
- return this.set(c, s, 0, 0, -s, c, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
3690
+ return Vector4;
3691
+ }();
3692
+ /**
3693
+ * 四维向量的常量
3694
+ */ Vector4.ONE = new Vector4(1.0, 1.0, 1.0, 1.0);
3695
+ Vector4.ZERO = new Vector4(0.0, 0.0, 0.0, 0.0);
3696
+
3697
+ var MeshComponent = /*#__PURE__*/ function(RendererComponent) {
3698
+ _inherits(MeshComponent, RendererComponent);
3699
+ function MeshComponent() {
3700
+ var _this;
3701
+ _this = RendererComponent.apply(this, arguments) || this;
3702
+ /**
3703
+ * 用于点击测试的碰撞器
3704
+ */ _this.meshCollider = new MeshCollider();
3705
+ // TODO 点击测试后续抽象一个 Collider 组件
3706
+ _this.getHitTestParams = function(force) {
3707
+ var area = _this.getBoundingBox();
3708
+ if (area) {
3709
+ return {
3710
+ type: area.type,
3711
+ triangles: area.area
3712
+ };
3713
+ }
3714
+ };
3715
+ return _this;
3716
+ }
3717
+ var _proto = MeshComponent.prototype;
3718
+ _proto.render = function render(renderer) {
3719
+ if (renderer.renderingData.currentFrame.globalUniforms) {
3720
+ renderer.setGlobalMatrix("effects_ObjectToWorld", this.transform.getWorldMatrix());
3721
+ }
3722
+ renderer.drawGeometry(this.geometry, this.material);
3876
3723
  };
3877
- /**
3878
- * 根据三维旋转轴与弧度设置矩阵
3879
- * @param axis - 三维旋转轴
3880
- * @param angle - 旋转弧度
3881
- * @returns 矩阵
3882
- */ _proto.setFromRotationAxis = function setFromRotationAxis(axis, angle) {
3883
- // Based on http://www.gamedev.net/reference/articles/article1199.asp
3884
- var v = Matrix4.tempVec0;
3885
- v.copyFrom(axis).normalize();
3886
- var c = Math.cos(angle);
3887
- var s = Math.sin(angle);
3888
- var t = 1 - c;
3889
- var x = v.x, y = v.y, z = v.z;
3890
- var tx = t * x;
3891
- var ty = t * y;
3892
- return this.set(tx * x + c, tx * y + s * z, tx * z - s * y, 0, tx * y - s * z, ty * y + c, ty * z + s * x, 0, tx * z + s * y, ty * z - s * x, t * z * z + c, 0, 0, 0, 0, 1);
3724
+ _proto.getBoundingBox = function getBoundingBox() {
3725
+ var worldMatrix = this.transform.getWorldMatrix();
3726
+ this.meshCollider.setGeometry(this.geometry, worldMatrix);
3727
+ var boundingBoxData = this.meshCollider.getBoundingBoxData();
3728
+ return boundingBoxData;
3893
3729
  };
3894
- /**
3895
- * 通过欧拉角设置矩阵
3896
- * @param euler - 欧拉角
3897
- * @returns 矩阵
3898
- */ _proto.setFromEuler = function setFromEuler(euler) {
3899
- euler.toMatrix4(this);
3900
- return this;
3730
+ return MeshComponent;
3731
+ }(RendererComponent);
3732
+ __decorate([
3733
+ serialize()
3734
+ ], MeshComponent.prototype, "geometry", void 0);
3735
+
3736
+ exports.EffectComponent = /*#__PURE__*/ function(MeshComponent) {
3737
+ _inherits(EffectComponent, MeshComponent);
3738
+ function EffectComponent(engine) {
3739
+ var _this;
3740
+ _this = MeshComponent.call(this, engine) || this;
3741
+ _this.name = "EffectComponent";
3742
+ return _this;
3743
+ }
3744
+ var _proto = EffectComponent.prototype;
3745
+ _proto.onStart = function onStart() {
3746
+ this.item.getHitTestParams = this.getHitTestParams;
3901
3747
  };
3902
- /**
3903
- * 通过四元数设置矩阵
3904
- * @param quat - 四元数
3905
- * @returns 矩阵
3906
- */ _proto.setFromQuaternion = function setFromQuaternion(quat) {
3907
- return this.compose(Vector3.ZERO, quat, Vector3.ONE);
3908
- };
3909
- /**
3910
- * 通过倾斜参数设置矩阵
3911
- * @param x - x 方向倾斜分量
3912
- * @param y - y 方向倾斜分量
3913
- * @param z - z 方向倾斜分量
3914
- * @returns 倾斜矩阵
3915
- */ _proto.setFromShear = function setFromShear(x, y, z) {
3916
- return this.set(1, x, x, 0, y, 1, y, 0, z, z, 1, 0, 0, 0, 0, 1);
3917
- };
3918
- /**
3919
- * 通过基轴设置矩阵
3920
- * @param xAxis - x 轴
3921
- * @param yAxis - y 轴
3922
- * @param zAxis - z 轴
3923
- * @returns 倾斜矩阵
3924
- */ _proto.setFromBasis = function setFromBasis(xAxis, yAxis, zAxis) {
3925
- return this.set(xAxis.x, xAxis.y, xAxis.z, 0, yAxis.x, yAxis.y, yAxis.z, 0, zAxis.x, zAxis.y, zAxis.z, 0, 0, 0, 0, 1);
3926
- };
3927
- /**
3928
- * 矩阵清零
3929
- * @returns 零矩阵
3930
- */ _proto.setZero = function setZero() {
3931
- for(var i = 0; i < 16; i++){
3932
- this.elements[i] = 0;
3933
- }
3934
- return this;
3935
- };
3936
- /**
3937
- * 矩阵单位化
3938
- * @returns 单位矩阵
3939
- */ _proto.identity = function identity() {
3940
- return this.set(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
3941
- };
3942
- /**
3943
- * 单位阵判断
3944
- * @returns 判断结果
3945
- */ _proto.isIdentity = function isIdentity() {
3946
- var e = this.elements;
3947
- return e[0] === 1 && e[4] === 0 && e[8] === 0 && e[12] === 0 && e[1] === 0 && e[5] === 1 && e[9] === 0 && e[13] === 0 && e[2] === 0 && e[6] === 0 && e[10] === 1 && e[14] === 0 && e[3] === 0 && e[7] === 0 && e[11] === 0 && e[15] === 1;
3948
- };
3949
- /**
3950
- * 矩阵克隆
3951
- * @returns 克隆结果
3952
- */ _proto.clone = function clone() {
3953
- var e = this.elements;
3954
- return new Matrix4(e[0], e[1], e[2], e[3], e[4], e[5], e[6], e[7], e[8], e[9], e[10], e[11], e[12], e[13], e[14], e[15]);
3955
- };
3956
- /**
3957
- * 矩阵复制
3958
- * @param m - 复制对象
3959
- * @returns 复制结果
3960
- */ _proto.copyFrom = function copyFrom(m) {
3961
- this.elements = [].concat(m.elements);
3962
- return this;
3963
- };
3964
- /**
3965
- * 得到列向量
3966
- * @param i - 列向量索引,从 0 开始
3967
- * @param v
3968
- * @returns 矩阵
3969
- */ _proto.getColumnVector = function getColumnVector(i, v) {
3970
- return v.set(this.elements[i * 4], this.elements[i * 4 + 1], this.elements[i * 4 + 2], this.elements[i * 4 + 3]);
3971
- };
3972
- /**
3973
- * 设置相机矩阵
3974
- * @param eye - 相机位置
3975
- * @param target - 目标位置
3976
- * @param up - 相机方向
3977
- * @returns 矩阵
3978
- */ _proto.lookAt = function lookAt(eye, target, up) {
3979
- var vX = Matrix4.tempVec0;
3980
- var vY = Matrix4.tempVec1;
3981
- var vZ = Matrix4.tempVec2;
3982
- vZ.subtractVectors(eye, target);
3983
- vZ.normalize();
3984
- vX.crossVectors(up, vZ);
3985
- vX.normalize();
3986
- vY.crossVectors(vZ, vX);
3987
- var te = this.elements;
3988
- te[0] = vX.x;
3989
- te[1] = vY.x;
3990
- te[2] = vZ.x;
3991
- te[3] = 0;
3992
- te[4] = vX.y;
3993
- te[5] = vY.y;
3994
- te[6] = vZ.y;
3995
- te[7] = 0;
3996
- te[8] = vX.z;
3997
- te[9] = vY.z;
3998
- te[10] = vZ.z;
3999
- te[11] = 0;
4000
- te[12] = -vX.dot(eye);
4001
- te[13] = -vY.dot(eye);
4002
- te[14] = -vZ.dot(eye);
4003
- te[15] = 1;
4004
- return this;
3748
+ _proto.onUpdate = function onUpdate(dt) {
3749
+ var time = this.item.time;
3750
+ var _this_material_getVector4;
3751
+ var _Time = (_this_material_getVector4 = this.material.getVector4("_Time")) != null ? _this_material_getVector4 : new Vector4();
3752
+ this.material.setVector4("_Time", _Time.set(time / 20, time, time * 2, time * 3));
4005
3753
  };
4006
- /**
4007
- * 矩阵乘比例后相加
4008
- * @param right - 矩阵
4009
- * @param s - 比例
4010
- * @returns 相加结果
4011
- */ _proto.addScaledMatrix = function addScaledMatrix(right, s) {
4012
- var te = this.elements;
4013
- var re = right.elements;
4014
- for(var i = 0; i < 16; i++){
4015
- te[i] += re[i] * s;
4016
- }
4017
- return this;
3754
+ _proto.fromData = function fromData(data) {
3755
+ MeshComponent.prototype.fromData.call(this, data);
3756
+ this.material = this.materials[0];
4018
3757
  };
4019
- /**
4020
- * 矩阵右乘
4021
- * @param right - 右侧矩阵或数值
4022
- * @returns 右乘结果
4023
- */ _proto.multiply = function multiply(right) {
4024
- if (typeof right === "number") {
4025
- for(var i = 0; i < 16; i++){
4026
- this.elements[i] *= right;
4027
- }
4028
- return this;
4029
- } else {
4030
- return this.multiplyMatrices(this, right);
3758
+ return EffectComponent;
3759
+ }(MeshComponent);
3760
+ exports.EffectComponent = __decorate([
3761
+ effectsClass(DataType.EffectComponent)
3762
+ ], exports.EffectComponent);
3763
+
3764
+ exports.PostProcessVolume = /*#__PURE__*/ function(Behaviour) {
3765
+ _inherits(PostProcessVolume, Behaviour);
3766
+ function PostProcessVolume() {
3767
+ var _this;
3768
+ _this = Behaviour.apply(this, arguments) || this;
3769
+ // Bloom
3770
+ _this.bloomEnabled = true;
3771
+ _this.threshold = 1.0;
3772
+ _this.bloomIntensity = 1.0;
3773
+ // ColorAdjustments
3774
+ _this.brightness = 1.0;
3775
+ _this.saturation = 1.0;
3776
+ _this.contrast = 1.0;
3777
+ // Vignette
3778
+ _this.vignetteIntensity = 0.2;
3779
+ _this.vignetteSmoothness = 0.4;
3780
+ _this.vignetteRoundness = 1.0;
3781
+ // ToneMapping
3782
+ _this.toneMappingEnabled = true // 1: true, 0: false
3783
+ ;
3784
+ return _this;
3785
+ }
3786
+ var _proto = PostProcessVolume.prototype;
3787
+ _proto.onStart = function onStart() {
3788
+ var composition = this.item.composition;
3789
+ if (composition) {
3790
+ composition.renderFrame.globalVolume = this;
4031
3791
  }
4032
3792
  };
3793
+ return PostProcessVolume;
3794
+ }(Behaviour);
3795
+ __decorate([
3796
+ serialize()
3797
+ ], exports.PostProcessVolume.prototype, "bloomEnabled", void 0);
3798
+ __decorate([
3799
+ serialize()
3800
+ ], exports.PostProcessVolume.prototype, "threshold", void 0);
3801
+ __decorate([
3802
+ serialize()
3803
+ ], exports.PostProcessVolume.prototype, "bloomIntensity", void 0);
3804
+ __decorate([
3805
+ serialize()
3806
+ ], exports.PostProcessVolume.prototype, "brightness", void 0);
3807
+ __decorate([
3808
+ serialize()
3809
+ ], exports.PostProcessVolume.prototype, "saturation", void 0);
3810
+ __decorate([
3811
+ serialize()
3812
+ ], exports.PostProcessVolume.prototype, "contrast", void 0);
3813
+ __decorate([
3814
+ serialize()
3815
+ ], exports.PostProcessVolume.prototype, "vignetteIntensity", void 0);
3816
+ __decorate([
3817
+ serialize()
3818
+ ], exports.PostProcessVolume.prototype, "vignetteSmoothness", void 0);
3819
+ __decorate([
3820
+ serialize()
3821
+ ], exports.PostProcessVolume.prototype, "vignetteRoundness", void 0);
3822
+ __decorate([
3823
+ serialize()
3824
+ ], exports.PostProcessVolume.prototype, "toneMappingEnabled", void 0);
3825
+ exports.PostProcessVolume = __decorate([
3826
+ effectsClass("PostProcessVolume")
3827
+ ], exports.PostProcessVolume);
3828
+
3829
+ function _assert_this_initialized(self) {
3830
+ if (self === void 0) throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
3831
+ return self;
3832
+ }
3833
+
3834
+ /**
3835
+ * 四元数
3836
+ */ var Quaternion = /*#__PURE__*/ function() {
3837
+ function Quaternion(x, y, z, w) {
3838
+ if (x === void 0) x = 0;
3839
+ if (y === void 0) y = 0;
3840
+ if (z === void 0) z = 0;
3841
+ if (w === void 0) w = 1;
3842
+ this.x = x;
3843
+ this.y = y;
3844
+ this.z = z;
3845
+ this.w = w;
3846
+ }
3847
+ var _proto = Quaternion.prototype;
4033
3848
  /**
4034
- * 矩阵左乘
4035
- * @param left - 左侧矩阵
4036
- * @returns 左乘结果
4037
- */ _proto.premultiply = function premultiply(left) {
4038
- return this.multiplyMatrices(left, this);
4039
- };
4040
- /**
4041
- * 矩阵相乘
4042
- * @param left - 矩阵
4043
- * @param right - 矩阵
4044
- * @returns 相乘结果
4045
- */ _proto.multiplyMatrices = function multiplyMatrices(left, right) {
4046
- var ae = left.elements;
4047
- var be = right.elements;
4048
- var te = this.elements;
4049
- var a11 = ae[0], a12 = ae[4], a13 = ae[8], a14 = ae[12];
4050
- var a21 = ae[1], a22 = ae[5], a23 = ae[9], a24 = ae[13];
4051
- var a31 = ae[2], a32 = ae[6], a33 = ae[10], a34 = ae[14];
4052
- var a41 = ae[3], a42 = ae[7], a43 = ae[11], a44 = ae[15];
4053
- var b11 = be[0], b12 = be[4], b13 = be[8], b14 = be[12];
4054
- var b21 = be[1], b22 = be[5], b23 = be[9], b24 = be[13];
4055
- var b31 = be[2], b32 = be[6], b33 = be[10], b34 = be[14];
4056
- var b41 = be[3], b42 = be[7], b43 = be[11], b44 = be[15];
4057
- te[0] = a11 * b11 + a12 * b21 + a13 * b31 + a14 * b41;
4058
- te[4] = a11 * b12 + a12 * b22 + a13 * b32 + a14 * b42;
4059
- te[8] = a11 * b13 + a12 * b23 + a13 * b33 + a14 * b43;
4060
- te[12] = a11 * b14 + a12 * b24 + a13 * b34 + a14 * b44;
4061
- te[1] = a21 * b11 + a22 * b21 + a23 * b31 + a24 * b41;
4062
- te[5] = a21 * b12 + a22 * b22 + a23 * b32 + a24 * b42;
4063
- te[9] = a21 * b13 + a22 * b23 + a23 * b33 + a24 * b43;
4064
- te[13] = a21 * b14 + a22 * b24 + a23 * b34 + a24 * b44;
4065
- te[2] = a31 * b11 + a32 * b21 + a33 * b31 + a34 * b41;
4066
- te[6] = a31 * b12 + a32 * b22 + a33 * b32 + a34 * b42;
4067
- te[10] = a31 * b13 + a32 * b23 + a33 * b33 + a34 * b43;
4068
- te[14] = a31 * b14 + a32 * b24 + a33 * b34 + a34 * b44;
4069
- te[3] = a41 * b11 + a42 * b21 + a43 * b31 + a44 * b41;
4070
- te[7] = a41 * b12 + a42 * b22 + a43 * b32 + a44 * b42;
4071
- te[11] = a41 * b13 + a42 * b23 + a43 * b33 + a44 * b43;
4072
- te[15] = a41 * b14 + a42 * b24 + a43 * b34 + a44 * b44;
4073
- return this;
4074
- };
4075
- /**
4076
- * 矩阵缩放
4077
- * @param s - 缩放比例
4078
- * @returns 缩放结果
4079
- */ _proto.multiplyScalar = function multiplyScalar(s) {
4080
- var e = this.elements;
4081
- e[0] *= s;
4082
- e[4] *= s;
4083
- e[8] *= s;
4084
- e[12] *= s;
4085
- e[1] *= s;
4086
- e[5] *= s;
4087
- e[9] *= s;
4088
- e[13] *= s;
4089
- e[2] *= s;
4090
- e[6] *= s;
4091
- e[10] *= s;
4092
- e[14] *= s;
4093
- e[3] *= s;
4094
- e[7] *= s;
4095
- e[11] *= s;
4096
- e[15] *= s;
3849
+ * 四元数设置
3850
+ * @param x - x 分量
3851
+ * @param y - y 分量
3852
+ * @param z - z 分量
3853
+ * @param w - w 分量
3854
+ * @returns 四元数
3855
+ */ _proto.set = function set(x, y, z, w) {
3856
+ this.x = x;
3857
+ this.y = y;
3858
+ this.z = z;
3859
+ this.w = w;
4097
3860
  return this;
4098
3861
  };
4099
3862
  /**
4100
- * 矩阵求行列式值
4101
- * @returns 行列式值
4102
- */ _proto.determinant = function determinant() {
4103
- var e = this.elements;
4104
- var m11 = e[0], m12 = e[4], m13 = e[8], m14 = e[12];
4105
- var m21 = e[1], m22 = e[5], m23 = e[9], m24 = e[13];
4106
- var m31 = e[2], m32 = e[6], m33 = e[10], m34 = e[14];
4107
- var m41 = e[3], m42 = e[7], m43 = e[11], m44 = e[15];
4108
- return m41 * (+m14 * m23 * m32 - m13 * m24 * m32 - m14 * m22 * m33 + m12 * m24 * m33 + m13 * m22 * m34 - m12 * m23 * m34) + m42 * (+m11 * m23 * m34 - m11 * m24 * m33 + m14 * m21 * m33 - m13 * m21 * m34 + m13 * m24 * m31 - m14 * m23 * m31) + m43 * (+m11 * m24 * m32 - m11 * m22 * m34 - m14 * m21 * m32 + m12 * m21 * m34 + m14 * m22 * m31 - m12 * m24 * m31) + m44 * (-m13 * m22 * m31 - m11 * m23 * m32 + m11 * m22 * m33 + m13 * m21 * m32 - m12 * m21 * m33 + m12 * m23 * m31);
4109
- };
4110
- /**
4111
- * 矩阵转置
4112
- * @returns 转置结果
4113
- */ _proto.transpose = function transpose() {
4114
- var e = this.elements;
4115
- var t;
4116
- t = e[1];
4117
- e[1] = e[4];
4118
- e[4] = t;
4119
- t = e[2];
4120
- e[2] = e[8];
4121
- e[8] = t;
4122
- t = e[3];
4123
- e[3] = e[12];
4124
- e[12] = t;
4125
- //
4126
- t = e[6];
4127
- e[6] = e[9];
4128
- e[9] = t;
4129
- t = e[7];
4130
- e[7] = e[13];
4131
- e[13] = t;
4132
- t = e[11];
4133
- e[11] = e[14];
4134
- e[14] = t;
3863
+ * 通过欧拉角设置四元数
3864
+ * @param euler - 欧拉角
3865
+ * @returns
3866
+ */ _proto.setFromEuler = function setFromEuler(euler) {
3867
+ euler.toQuaternion(this);
4135
3868
  return this;
4136
3869
  };
4137
3870
  /**
4138
- * 矩阵求逆
4139
- * @returns 逆矩阵
4140
- */ _proto.invert = function invert() {
4141
- // based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm
4142
- var e = this.elements;
4143
- var m11 = e[0], m21 = e[1], m31 = e[2], m41 = e[3];
4144
- var m12 = e[4], m22 = e[5], m32 = e[6], m42 = e[7];
4145
- var m13 = e[8], m23 = e[9], m33 = e[10], m43 = e[11];
4146
- var m14 = e[12], m24 = e[13], m34 = e[14], m44 = e[15];
4147
- var t11 = m23 * m34 * m42 - m24 * m33 * m42 + m24 * m32 * m43 - m22 * m34 * m43 - m23 * m32 * m44 + m22 * m33 * m44;
4148
- var t12 = m14 * m33 * m42 - m13 * m34 * m42 - m14 * m32 * m43 + m12 * m34 * m43 + m13 * m32 * m44 - m12 * m33 * m44;
4149
- var t13 = m13 * m24 * m42 - m14 * m23 * m42 + m14 * m22 * m43 - m12 * m24 * m43 - m13 * m22 * m44 + m12 * m23 * m44;
4150
- var t14 = m14 * m23 * m32 - m13 * m24 * m32 - m14 * m22 * m33 + m12 * m24 * m33 + m13 * m22 * m34 - m12 * m23 * m34;
4151
- var det = m11 * t11 + m21 * t12 + m31 * t13 + m41 * t14;
4152
- if (det === 0) {
4153
- return this.set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
4154
- }
4155
- var detInv = 1 / det;
4156
- e[0] = t11 * detInv;
4157
- e[1] = (m24 * m33 * m41 - m23 * m34 * m41 - m24 * m31 * m43 + m21 * m34 * m43 + m23 * m31 * m44 - m21 * m33 * m44) * detInv;
4158
- e[2] = (m22 * m34 * m41 - m24 * m32 * m41 + m24 * m31 * m42 - m21 * m34 * m42 - m22 * m31 * m44 + m21 * m32 * m44) * detInv;
4159
- e[3] = (m23 * m32 * m41 - m22 * m33 * m41 - m23 * m31 * m42 + m21 * m33 * m42 + m22 * m31 * m43 - m21 * m32 * m43) * detInv;
4160
- e[4] = t12 * detInv;
4161
- e[5] = (m13 * m34 * m41 - m14 * m33 * m41 + m14 * m31 * m43 - m11 * m34 * m43 - m13 * m31 * m44 + m11 * m33 * m44) * detInv;
4162
- e[6] = (m14 * m32 * m41 - m12 * m34 * m41 - m14 * m31 * m42 + m11 * m34 * m42 + m12 * m31 * m44 - m11 * m32 * m44) * detInv;
4163
- e[7] = (m12 * m33 * m41 - m13 * m32 * m41 + m13 * m31 * m42 - m11 * m33 * m42 - m12 * m31 * m43 + m11 * m32 * m43) * detInv;
4164
- e[8] = t13 * detInv;
4165
- e[9] = (m14 * m23 * m41 - m13 * m24 * m41 - m14 * m21 * m43 + m11 * m24 * m43 + m13 * m21 * m44 - m11 * m23 * m44) * detInv;
4166
- e[10] = (m12 * m24 * m41 - m14 * m22 * m41 + m14 * m21 * m42 - m11 * m24 * m42 - m12 * m21 * m44 + m11 * m22 * m44) * detInv;
4167
- e[11] = (m13 * m22 * m41 - m12 * m23 * m41 - m13 * m21 * m42 + m11 * m23 * m42 + m12 * m21 * m43 - m11 * m22 * m43) * detInv;
4168
- e[12] = t14 * detInv;
4169
- e[13] = (m13 * m24 * m31 - m14 * m23 * m31 + m14 * m21 * m33 - m11 * m24 * m33 - m13 * m21 * m34 + m11 * m23 * m34) * detInv;
4170
- e[14] = (m14 * m22 * m31 - m12 * m24 * m31 - m14 * m21 * m32 + m11 * m24 * m32 + m12 * m21 * m34 - m11 * m22 * m34) * detInv;
4171
- e[15] = (m12 * m23 * m31 - m13 * m22 * m31 + m13 * m21 * m32 - m11 * m23 * m32 - m12 * m21 * m33 + m11 * m22 * m33) * detInv;
3871
+ * 通过旋转轴和旋转角度设置四元数
3872
+ * @param axis - 旋转轴
3873
+ * @param angle - 旋转角度(弧度)
3874
+ * @returns
3875
+ */ _proto.setFromAxisAngle = function setFromAxisAngle(axis, angle) {
3876
+ var halfAngle = angle / 2;
3877
+ var s = Math.sin(halfAngle);
3878
+ var v = Quaternion.tempVec0;
3879
+ v.copyFrom(axis).normalize();
3880
+ this.x = v.x * s;
3881
+ this.y = v.y * s;
3882
+ this.z = v.z * s;
3883
+ this.w = Math.cos(halfAngle);
4172
3884
  return this;
4173
3885
  };
4174
3886
  /**
4175
- * 提取基轴
4176
- * @param xAxis - 提取的 x 轴
4177
- * @param yAxis - 提取的 y 轴
4178
- * @param zAxis - 提取的 z 轴
3887
+ * 通过 Vector4Like 创建四元数
3888
+ * @param v - Vector4Like
4179
3889
  * @returns
4180
- */ _proto.extractBasis = function extractBasis(xAxis, yAxis, zAxis) {
4181
- var te = this.elements;
4182
- xAxis.set(te[0], te[1], te[2]);
4183
- yAxis.set(te[4], te[5], te[6]);
4184
- zAxis.set(te[8], te[9], te[10]);
3890
+ */ _proto.setFromVector4 = function setFromVector4(v) {
3891
+ this.x = v.x;
3892
+ this.y = v.y;
3893
+ this.z = v.z;
3894
+ this.w = v.w;
4185
3895
  return this;
4186
3896
  };
4187
3897
  /**
4188
- * 根据基础信息组装矩阵
4189
- * @param translation - 位置信息
4190
- * @param rotation - 旋转信息
4191
- * @param scale - 缩放信息
4192
- * @param [anchor] - 锚点信息
4193
- * @returns 矩阵
4194
- */ _proto.compose = function compose(translation, rotation, scale, anchor) {
4195
- if (anchor === void 0) anchor = Vector3.ZERO;
4196
- var te = this.elements;
4197
- var x = rotation.x, y = rotation.y, z = rotation.z, w = rotation.w;
4198
- var l = -anchor.x;
4199
- var m = -anchor.y;
4200
- var n = -anchor.z;
4201
- var x2 = x + x;
4202
- var y2 = y + y;
4203
- var z2 = z + z;
4204
- var xx = x * x2;
4205
- var xy = x * y2;
4206
- var xz = x * z2;
4207
- var yy = y * y2;
4208
- var yz = y * z2;
4209
- var zz = z * z2;
4210
- var wx = w * x2;
4211
- var wy = w * y2;
4212
- var wz = w * z2;
4213
- var sx = scale.x, sy = scale.y, sz = scale.z;
4214
- te[0] = (1 - (yy + zz)) * sx;
4215
- te[1] = (xy + wz) * sx;
4216
- te[2] = (xz - wy) * sx;
4217
- te[3] = 0;
4218
- te[4] = (xy - wz) * sy;
4219
- te[5] = (1 - (xx + zz)) * sy;
4220
- te[6] = (yz + wx) * sy;
4221
- te[7] = 0;
4222
- te[8] = (xz + wy) * sz;
4223
- te[9] = (yz - wx) * sz;
4224
- te[10] = (1 - (xx + yy)) * sz;
4225
- te[11] = 0;
4226
- te[12] = l * te[0] + m * te[4] + n * te[8] - l + translation.x;
4227
- te[13] = l * te[1] + m * te[5] + n * te[9] - m + translation.y;
4228
- te[14] = l * te[2] + m * te[6] + n * te[10] - n + translation.z;
3898
+ * 通过数组设置四元数
3899
+ * @param array - 数组
3900
+ * @param [offset=0] - 起始偏移值
3901
+ * @returns
3902
+ */ _proto.setFromArray = function setFromArray(array, offset) {
3903
+ if (offset === void 0) offset = 0;
3904
+ this.x = array[offset];
3905
+ this.y = array[offset + 1];
3906
+ this.z = array[offset + 2];
3907
+ this.w = array[offset + 3];
4229
3908
  return this;
4230
3909
  };
4231
3910
  /**
4232
- * 矩阵拆分为基础信息
4233
- * @param translation - 位置信息
4234
- * @param rotation - 旋转信息
4235
- * @param scale - 缩放信息
4236
- * @returns 矩阵
4237
- */ _proto.decompose = function decompose(translation, rotation, scale) {
4238
- var v = Matrix4.tempVec0;
4239
- var te = this.elements;
4240
- var sx = v.set(te[0], te[1], te[2]).length();
4241
- var sy = v.set(te[4], te[5], te[6]).length();
4242
- var sz = v.set(te[8], te[9], te[10]).length();
4243
- // if determine is negative, we need to invert one scale
4244
- var det = this.determinant();
4245
- if (det < 0) {
4246
- sx = -sx;
3911
+ * 通过矩阵设置四元数
3912
+ * @param m - 矩阵
3913
+ * @returns
3914
+ */ _proto.setFromRotationMatrix = function setFromRotationMatrix(m) {
3915
+ // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/index.htm
3916
+ // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
3917
+ var te = m.elements;
3918
+ var m11 = te[0];
3919
+ var m12 = te[4];
3920
+ var m13 = te[8];
3921
+ var m21 = te[1];
3922
+ var m22 = te[5];
3923
+ var m23 = te[9];
3924
+ var m31 = te[2];
3925
+ var m32 = te[6];
3926
+ var m33 = te[10];
3927
+ var trace = m11 + m22 + m33;
3928
+ if (trace > 0) {
3929
+ var s = 0.5 / Math.sqrt(trace + 1.0);
3930
+ this.w = 0.25 / s;
3931
+ this.x = (m32 - m23) * s;
3932
+ this.y = (m13 - m31) * s;
3933
+ this.z = (m21 - m12) * s;
3934
+ } else if (m11 > m22 && m11 > m33) {
3935
+ var s1 = 2.0 * Math.sqrt(1.0 + m11 - m22 - m33);
3936
+ this.w = (m32 - m23) / s1;
3937
+ this.x = 0.25 * s1;
3938
+ this.y = (m12 + m21) / s1;
3939
+ this.z = (m13 + m31) / s1;
3940
+ this.negate();
3941
+ } else if (m22 > m33) {
3942
+ var s2 = 2.0 * Math.sqrt(1.0 + m22 - m11 - m33);
3943
+ this.w = (m13 - m31) / s2;
3944
+ this.x = (m12 + m21) / s2;
3945
+ this.y = 0.25 * s2;
3946
+ this.z = (m23 + m32) / s2;
3947
+ this.negate();
3948
+ } else {
3949
+ var s3 = 2.0 * Math.sqrt(1.0 + m33 - m11 - m22);
3950
+ this.w = (m21 - m12) / s3;
3951
+ this.x = (m13 + m31) / s3;
3952
+ this.y = (m23 + m32) / s3;
3953
+ this.z = 0.25 * s3;
3954
+ this.negate();
4247
3955
  }
4248
- translation.x = te[12];
4249
- translation.y = te[13];
4250
- translation.z = te[14];
4251
- // scale the rotation part
4252
- var m = Matrix4.tempMat0;
4253
- m.copyFrom(this);
4254
- var invSX = 1 / sx;
4255
- var invSY = 1 / sy;
4256
- var invSZ = 1 / sz;
4257
- m.elements[0] *= invSX;
4258
- m.elements[1] *= invSX;
4259
- m.elements[2] *= invSX;
4260
- m.elements[4] *= invSY;
4261
- m.elements[5] *= invSY;
4262
- m.elements[6] *= invSY;
4263
- m.elements[8] *= invSZ;
4264
- m.elements[9] *= invSZ;
4265
- m.elements[10] *= invSZ;
4266
- rotation.setFromRotationMatrix(m);
4267
- scale.x = sx;
4268
- scale.y = sy;
4269
- scale.z = sz;
3956
+ // 兼容原先数学库
4270
3957
  return this;
4271
3958
  };
4272
- _proto.getTranslation = function getTranslation(translation) {
4273
- var te = this.elements;
4274
- return translation.set(te[12], te[13], te[14]);
3959
+ /**
3960
+ * 通过开始和结束向量设置四元数
3961
+ * @param from - 开始向量
3962
+ * @param to - 结束向量
3963
+ * @returns
3964
+ */ _proto.setFromUnitVectors = function setFromUnitVectors(from, to) {
3965
+ // assumes direction vectors vFrom and vTo are normalized
3966
+ var r = from.dot(to) + 1;
3967
+ if (r < Number.EPSILON) {
3968
+ r = 0;
3969
+ if (Math.abs(from.x) > Math.abs(from.z)) {
3970
+ this.x = -from.y;
3971
+ this.y = from.x;
3972
+ this.z = 0;
3973
+ this.w = r;
3974
+ } else {
3975
+ this.x = 0;
3976
+ this.y = -from.z;
3977
+ this.z = from.y;
3978
+ this.w = r;
3979
+ }
3980
+ } else {
3981
+ this.x = from.y * to.z - from.z * to.y;
3982
+ this.y = from.z * to.x - from.x * to.z;
3983
+ this.z = from.x * to.y - from.y * to.x;
3984
+ this.w = r;
3985
+ }
3986
+ return this.normalize();
4275
3987
  };
4276
- _proto.getScale = function getScale(scale) {
4277
- var te = this.elements;
4278
- return scale.set(Math.hypot(te[0], te[1], te[2]), Math.hypot(te[4], te[5], te[6]), Math.hypot(te[8], te[9], te[10]));
3988
+ /**
3989
+ * 四元数拷贝
3990
+ * @param quat - 拷贝目标四元数
3991
+ * @returns 拷贝四元数
3992
+ */ _proto.copyFrom = function copyFrom(quat) {
3993
+ this.x = quat.x;
3994
+ this.y = quat.y;
3995
+ this.z = quat.z;
3996
+ this.w = quat.w;
3997
+ return this;
4279
3998
  };
4280
3999
  /**
4281
- * 获得矩阵分解的结果
4282
- * @returns 分解的结果
4283
- */ _proto.getTransform = function getTransform() {
4284
- var translation = new Vector3();
4285
- var rotation = new Quaternion();
4286
- var scale = new Vector3();
4287
- this.decompose(translation, rotation, scale);
4288
- return {
4289
- translation: translation,
4290
- rotation: rotation,
4291
- scale: scale
4292
- };
4000
+ * 四元数克隆
4001
+ * @returns 克隆结果
4002
+ */ _proto.clone = function clone() {
4003
+ return new Quaternion(this.x, this.y, this.z, this.w);
4293
4004
  };
4294
4005
  /**
4295
- * 根据视窗信息设置正交相机投影矩阵
4296
- * @param left - 视窗左平面位置
4297
- * @param right - 视窗右平面位置
4298
- * @param top - 视窗上平面位置
4299
- * @param bottom - 视窗下平面位置
4300
- * @param near - 视窗近平面位置
4301
- * @param far - 视窗远平面位置
4302
- * @returns 矩阵
4303
- */ _proto.orthographic = function orthographic(left, right, top, bottom, near, far) {
4304
- var a = 1.0 / (right - left);
4305
- var b = 1.0 / (top - bottom);
4306
- var c = 1.0 / (far - near);
4307
- var tx = -(right + left) * a;
4308
- var ty = -(top + bottom) * b;
4309
- var tz = -(far + near) * c;
4310
- a *= 2.0;
4311
- b *= 2.0;
4312
- c *= -2.0;
4313
- var te = this.elements;
4314
- te[0] = a;
4315
- te[1] = 0.0;
4316
- te[2] = 0.0;
4317
- te[3] = 0.0;
4318
- //
4319
- te[4] = 0.0;
4320
- te[5] = b;
4321
- te[6] = 0.0;
4322
- te[7] = 0.0;
4323
- //
4324
- te[8] = 0.0;
4325
- te[9] = 0.0;
4326
- te[10] = c;
4327
- te[11] = 0.0;
4328
- //
4329
- te[12] = tx;
4330
- te[13] = ty;
4331
- te[14] = tz;
4332
- te[15] = 1.0;
4333
- return this;
4006
+ * 四元数间的夹角计算
4007
+ * @param other - 其他四元数
4008
+ * @returns 夹角
4009
+ */ _proto.angleTo = function angleTo(other) {
4010
+ return 2 * Math.acos(Math.abs(clamp$1(this.dot(other), -1, 1)));
4334
4011
  };
4335
4012
  /**
4336
- * 通过透视相机基础参数设置投影矩阵
4337
- * @param fov - 视角(弧度)
4338
- * @param aspect - 视窗比例
4339
- * @param near - 近平面
4340
- * @param far - 远平面
4341
- * @param [reverse] - 视锥体长宽反转(3D这里反了?)
4342
- * @returns 投影矩阵
4343
- */ _proto.perspective = function perspective(fov, aspect, near, far, reverse) {
4344
- var f = 1.0 / Math.tan(fov * 0.5);
4345
- var nf = 1 / (near - far);
4346
- var te = this.elements;
4347
- te[0] = reverse ? f : f / aspect;
4348
- te[1] = 0;
4349
- te[2] = 0;
4350
- te[3] = 0;
4351
- //
4352
- te[4] = 0;
4353
- te[5] = reverse ? f * aspect : f;
4354
- te[6] = 0;
4355
- te[7] = 0;
4356
- //
4357
- te[8] = 0;
4358
- te[9] = 0;
4359
- te[10] = (far + near) * nf;
4360
- te[11] = -1;
4361
- //
4362
- te[12] = 0;
4363
- te[13] = 0;
4364
- te[14] = 2 * far * near * nf;
4365
- te[15] = 0;
4366
- if (far === null || far === Infinity) {
4367
- te[10] = -1;
4368
- te[14] = -2 * near;
4013
+ * 四元数向目标旋转
4014
+ * @param q - 四元数
4015
+ * @param step - 旋转弧度
4016
+ * @returns 目标四元数
4017
+ */ _proto.rotateTowards = function rotateTowards(q, step) {
4018
+ var angle = this.angleTo(q);
4019
+ if (angle === 0) {
4020
+ return this;
4369
4021
  }
4022
+ var t = Math.min(1, step / angle);
4023
+ this.slerp(q, t);
4370
4024
  return this;
4371
4025
  };
4372
4026
  /**
4373
- * 对点进行投影变换
4374
- * @param v - 输入点
4375
- * @param [out] - 输出点,如果没有就覆盖输入的数据
4376
- * @returns 投影后的点
4377
- */ _proto.projectPoint = function projectPoint(v, out) {
4378
- var x = v.x, y = v.y, z = v.z;
4379
- var e = this.elements;
4380
- var res = out != null ? out : v;
4381
- res.x = e[0] * x + e[4] * y + e[8] * z + e[12];
4382
- res.y = e[1] * x + e[5] * y + e[9] * z + e[13];
4383
- res.z = e[2] * x + e[6] * y + e[10] * z + e[14];
4384
- var w = e[3] * x + e[7] * y + e[11] * z + e[15];
4385
- return res.multiply(1 / w);
4027
+ * 四元数单位化
4028
+ * @returns 单位四元数
4029
+ */ _proto.identity = function identity() {
4030
+ return this.set(0, 0, 0, 1);
4386
4031
  };
4387
4032
  /**
4388
- * 对点进行矩阵变换
4389
- * @param v - 输入点
4390
- * @param [out] - 输出点,如果没有就覆盖输入的数据
4391
- * @returns 变换后的点
4392
- */ _proto.transformPoint = function transformPoint(v, out) {
4393
- var x = v.x, y = v.y, z = v.z;
4394
- var e = this.elements;
4395
- var res = out != null ? out : v;
4396
- res.x = e[0] * x + e[4] * y + e[8] * z + e[12];
4397
- res.y = e[1] * x + e[5] * y + e[9] * z + e[13];
4398
- res.z = e[2] * x + e[6] * y + e[10] * z + e[14];
4399
- return res;
4033
+ * 四元数求逆
4034
+ * @returns 四元数的逆
4035
+ */ _proto.invert = function invert() {
4036
+ return this.conjugate();
4400
4037
  };
4401
4038
  /**
4402
- * 对法向量进行矩阵变换
4403
- * @param v - 输入法向量
4404
- * @param [out] - 输出法向量,如果没有就覆盖输入的数据
4405
- * @returns 变换后的法向量
4406
- */ _proto.transformNormal = function transformNormal(v, out) {
4407
- var x = v.x, y = v.y, z = v.z;
4408
- var e = this.elements;
4409
- var res = out != null ? out : v;
4410
- res.x = e[0] * x + e[4] * y + e[8] * z;
4411
- res.y = e[1] * x + e[5] * y + e[9] * z;
4412
- res.z = e[2] * x + e[6] * y + e[10] * z;
4413
- return res.normalize();
4039
+ * 四元数取负
4040
+ * @returns 负四元数
4041
+ */ _proto.negate = function negate() {
4042
+ this.x = -this.x;
4043
+ this.y = -this.y;
4044
+ this.z = -this.z;
4045
+ this.w = -this.w;
4046
+ return this;
4414
4047
  };
4415
4048
  /**
4416
- * 对四维向量进行矩阵变换
4417
- * @param v - 输入向量
4418
- * @param [out] - 输出向量,如果没有就覆盖输入的数据
4419
- * @returns 变换后向量
4420
- */ _proto.transformVector4 = function transformVector4(v, out) {
4421
- var x = v.x, y = v.y, z = v.z, w = v.w;
4422
- var e = this.elements;
4423
- var res = out != null ? out : v;
4424
- res.x = e[0] * x + e[4] * y + e[8] * z + e[12] * w;
4425
- res.y = e[1] * x + e[5] * y + e[9] * z + e[13] * w;
4426
- res.z = e[2] * x + e[6] * y + e[10] * z + e[14] * w;
4427
- res.w = e[3] * x + e[7] * y + e[11] * z + e[15] * w;
4428
- return res;
4049
+ * 四元数求共轭值
4050
+ * @returns 四元数的共轭值
4051
+ */ _proto.conjugate = function conjugate() {
4052
+ this.x = -this.x;
4053
+ this.y = -this.y;
4054
+ this.z = -this.z;
4055
+ return this;
4056
+ };
4057
+ /**
4058
+ * 四元数点乘结果
4059
+ * @param v
4060
+ * @return
4061
+ */ _proto.dot = function dot(v) {
4062
+ return this.x * v.x + this.y * v.y + this.z * v.z + this.w * v.w;
4063
+ };
4064
+ /**
4065
+ * 四元数的模平方
4066
+ * @return
4067
+ */ _proto.lengthSquared = function lengthSquared() {
4068
+ return this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w;
4429
4069
  };
4430
4070
  /**
4431
- * 矩阵判等
4432
- * @param matrix - 矩阵
4433
- * @returns 判等结果
4434
- */ _proto.equals = function equals(matrix) {
4435
- var te = this.elements;
4436
- var me = matrix.elements;
4437
- for(var i = 0; i < 16; i++){
4438
- if (!isEqual(te[i], me[i])) {
4439
- return false;
4440
- }
4071
+ * 四元数的欧式长度
4072
+ * @returns 长度
4073
+ */ _proto.length = function length() {
4074
+ return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w);
4075
+ };
4076
+ /**
4077
+ * 四元数归一化
4078
+ * @returns 归一化值
4079
+ */ _proto.normalize = function normalize() {
4080
+ var l = this.length();
4081
+ if (l === 0) {
4082
+ this.x = 0;
4083
+ this.y = 0;
4084
+ this.z = 0;
4085
+ this.w = 1;
4086
+ } else {
4087
+ l = 1 / l;
4088
+ this.x = this.x * l;
4089
+ this.y = this.y * l;
4090
+ this.z = this.z * l;
4091
+ this.w = this.w * l;
4441
4092
  }
4442
- return true;
4093
+ return this;
4443
4094
  };
4444
4095
  /**
4445
- * 矩阵转数组
4096
+ * 四元数右乘
4097
+ * @param right - 右乘的四元数
4446
4098
  * @returns
4447
- */ _proto.toArray = function toArray() {
4448
- return [].concat(this.elements);
4449
- };
4450
- _proto.fill = function fill(array, offset) {
4451
- if (offset === void 0) offset = 0;
4452
- var te = this.elements;
4453
- array[offset] = te[0];
4454
- array[offset + 1] = te[1];
4455
- array[offset + 2] = te[2];
4456
- array[offset + 3] = te[3];
4457
- array[offset + 4] = te[4];
4458
- array[offset + 5] = te[5];
4459
- array[offset + 6] = te[6];
4460
- array[offset + 7] = te[7];
4461
- array[offset + 8] = te[8];
4462
- array[offset + 9] = te[9];
4463
- array[offset + 10] = te[10];
4464
- array[offset + 11] = te[11];
4465
- array[offset + 12] = te[12];
4466
- array[offset + 13] = te[13];
4467
- array[offset + 14] = te[14];
4468
- array[offset + 15] = te[15];
4099
+ */ _proto.multiply = function multiply(right) {
4100
+ return this.multiplyQuaternions(this, right);
4469
4101
  };
4470
4102
  /**
4471
- * 创建单位阵
4472
- * @returns 单位矩阵
4473
- */ Matrix4.fromIdentity = function fromIdentity() {
4474
- return new Matrix4(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
4103
+ * 四元数左乘
4104
+ * @param left - 左乘的四元数
4105
+ * @returns
4106
+ */ _proto.premultiply = function premultiply(left) {
4107
+ return this.multiplyQuaternions(left, this);
4475
4108
  };
4476
4109
  /**
4477
- * 创建相机矩阵
4478
- * @param eye - 相机位置
4479
- * @param target - 目标位置
4480
- * @param up - 相机方向
4481
- * @returns 矩阵
4482
- */ Matrix4.fromLookAt = function fromLookAt(eye, target, up) {
4483
- return new Matrix4().lookAt(eye, target, up);
4110
+ * 四元数乘法
4111
+ * @param left - 四元数
4112
+ * @param right - 四元数
4113
+ * @returns 四元数
4114
+ */ _proto.multiplyQuaternions = function multiplyQuaternions(left, right) {
4115
+ // from http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/code/index.htm
4116
+ var qax = left.x;
4117
+ var qay = left.y;
4118
+ var qaz = left.z;
4119
+ var qaw = left.w;
4120
+ var qbx = right.x;
4121
+ var qby = right.y;
4122
+ var qbz = right.z;
4123
+ var qbw = right.w;
4124
+ this.x = qax * qbw + qaw * qbx + qay * qbz - qaz * qby;
4125
+ this.y = qay * qbw + qaw * qby + qaz * qbx - qax * qbz;
4126
+ this.z = qaz * qbw + qaw * qbz + qax * qby - qay * qbx;
4127
+ this.w = qaw * qbw - qax * qbx - qay * qby - qaz * qbz;
4128
+ return this;
4484
4129
  };
4485
4130
  /**
4486
- * 创建投影矩阵
4487
- * @param fov - 视角
4488
- * @param aspect - 视窗比例
4489
- * @param near - 近平面
4490
- * @param far - 远平面
4491
- * @param [reverse] - 视锥体长宽反转
4492
- * @returns 投影矩阵
4493
- */ Matrix4.fromPerspective = function fromPerspective(fov, aspect, near, far, reverse) {
4494
- return new Matrix4().perspective(fov, aspect, near, far, reverse);
4131
+ * 四元数线性插值
4132
+ * @see http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/slerp/
4133
+ * @param other - 四元数
4134
+ * @param t - 插值比
4135
+ * @returns 插值结果
4136
+ */ _proto.slerp = function slerp(other, t) {
4137
+ if (t === 0) {
4138
+ return this;
4139
+ }
4140
+ if (t === 1) {
4141
+ return this.copyFrom(other);
4142
+ }
4143
+ var _this = this, x = _this.x, y = _this.y, z = _this.z, w = _this.w;
4144
+ var cosHalfTheta = w * other.w + x * other.x + y * other.y + z * other.z;
4145
+ if (cosHalfTheta < 0) {
4146
+ this.w = -other.w;
4147
+ this.x = -other.x;
4148
+ this.y = -other.y;
4149
+ this.z = -other.z;
4150
+ cosHalfTheta = -cosHalfTheta;
4151
+ } else {
4152
+ this.copyFrom(other);
4153
+ }
4154
+ if (cosHalfTheta >= 1.0) {
4155
+ this.w = w;
4156
+ this.x = x;
4157
+ this.y = y;
4158
+ this.z = z;
4159
+ return this;
4160
+ }
4161
+ var sqrSinHalfTheta = 1.0 - cosHalfTheta * cosHalfTheta;
4162
+ if (sqrSinHalfTheta <= Number.EPSILON) {
4163
+ var s = 1 - t;
4164
+ this.w = s * w + t * this.w;
4165
+ this.x = s * x + t * this.x;
4166
+ this.y = s * y + t * this.y;
4167
+ this.z = s * z + t * this.z;
4168
+ this.normalize();
4169
+ return this;
4170
+ }
4171
+ var sinHalfTheta = Math.sqrt(sqrSinHalfTheta);
4172
+ var halfTheta = Math.atan2(sinHalfTheta, cosHalfTheta);
4173
+ var ratioA = Math.sin((1 - t) * halfTheta) / sinHalfTheta;
4174
+ var ratioB = Math.sin(t * halfTheta) / sinHalfTheta;
4175
+ this.w = w * ratioA + this.w * ratioB;
4176
+ this.x = x * ratioA + this.x * ratioB;
4177
+ this.y = y * ratioA + this.y * ratioB;
4178
+ this.z = z * ratioA + this.z * ratioB;
4179
+ return this;
4495
4180
  };
4496
4181
  /**
4497
- * 通过四个列向量创建矩阵
4498
- * @param c1 - 第一列
4499
- * @param c2 - 第二列
4500
- * @param c3 - 第三列
4501
- * @param c4 - 第四列
4502
- * @returns
4503
- */ Matrix4.fromColumnVectors = function fromColumnVectors(c1, c2, c3, c4) {
4504
- return new Matrix4().setFromColumnVectors(c1, c2, c3, c4);
4182
+ * 两个四元数的线性插值
4183
+ * @param qa - 四元数
4184
+ * @param qb - 四元数
4185
+ * @param t - 插值比
4186
+ */ _proto.slerpQuaternions = function slerpQuaternions(qa, qb, t) {
4187
+ this.copyFrom(qa).slerp(qb, t);
4505
4188
  };
4506
4189
  /**
4507
- * 通过三阶矩阵创建矩阵
4508
- * @param m - 三阶矩阵
4509
- * @returns 创建的矩阵
4510
- */ Matrix4.fromMatrix3 = function fromMatrix3(m) {
4511
- return new Matrix4().setFromMatrix3(m);
4190
+ * 通过四元数旋转向量
4191
+ * @param v - 待旋转向量
4192
+ * @param [out] - 旋转结果,如果没有传入直接覆盖输入值
4193
+ * @returns
4194
+ */ _proto.rotateVector3 = function rotateVector3(v, out) {
4195
+ var _this = this, qx = _this.x, qy = _this.y, qz = _this.z, qw = _this.w;
4196
+ var vx = v.x, vy = v.y, vz = v.z;
4197
+ var ix = qw * vx + qy * vz - qz * vy;
4198
+ var iy = qw * vy + qz * vx - qx * vz;
4199
+ var iz = qw * vz + qx * vy - qy * vx;
4200
+ var iw = -qx * vx - qy * vy - qz * vz;
4201
+ var res = out != null ? out : v;
4202
+ res.x = ix * qw + iw * -qx + iy * -qz - iz * -qy;
4203
+ res.y = iy * qw + iw * -qy + iz * -qx - ix * -qz;
4204
+ res.z = iz * qw + iw * -qz + ix * -qy - iy * -qx;
4205
+ return res;
4512
4206
  };
4513
4207
  /**
4514
- * 通过数组创建矩阵
4515
- * @param array - 数组
4516
- * @param [offset=0] - 起始偏移值
4517
- * @returns 矩阵
4518
- */ Matrix4.fromArray = function fromArray(array, offset) {
4519
- if (offset === void 0) offset = 0;
4520
- return new Matrix4().setFromArray(array, offset);
4208
+ * 四元数判等
4209
+ * @param quaternion - 四元数
4210
+ * @returns 判等结果
4211
+ */ _proto.equals = function equals(quaternion) {
4212
+ return quaternion.x === this.x && quaternion.y === this.y && quaternion.z === this.z && quaternion.w === this.w;
4521
4213
  };
4522
4214
  /**
4523
- * 通过缩放创建矩阵
4524
- * @param x - x 缩放
4525
- * @param y - y 缩放
4526
- * @param z - z 缩放
4527
- * @returns 缩放结果
4528
- */ Matrix4.fromScale = function fromScale(x, y, z) {
4529
- return new Matrix4().setFromScale(x, y, z);
4215
+ * 四元数保存为数组
4216
+ * @returns
4217
+ */ _proto.toArray = function toArray() {
4218
+ return [
4219
+ this.x,
4220
+ this.y,
4221
+ this.z,
4222
+ this.w
4223
+ ];
4530
4224
  };
4531
4225
  /**
4532
- * 通过平移创建矩阵
4533
- * @param x - x 平移
4534
- * @param y - y 平移
4535
- * @param z - z 平移
4536
- * @returns 平移结果
4537
- */ Matrix4.fromTranslation = function fromTranslation(x, y, z) {
4538
- return new Matrix4().setFromTranslation(x, y, z);
4226
+ * 四元数转四维向量数组
4227
+ * @param vec - 目标保存对象
4228
+ * @returns 保存结果
4229
+ */ _proto.toVector4 = function toVector4(vec) {
4230
+ return vec.set(this.x, this.y, this.z, this.w);
4539
4231
  };
4540
4232
  /**
4541
- * 通过 x 轴旋转创建矩阵
4542
- * @param theta - x 轴旋转弧度
4543
- * @returns 矩阵
4544
- */ Matrix4.fromRotationX = function fromRotationX(theta) {
4545
- return new Matrix4().setFromRotationX(theta);
4233
+ * 四元数转欧拉角
4234
+ * @param euler - 目标欧拉角
4235
+ * @returns 欧拉角
4236
+ */ _proto.toEuler = function toEuler(euler) {
4237
+ return euler.setFromQuaternion(this);
4546
4238
  };
4547
4239
  /**
4548
- * 通过 y 轴旋转创建矩阵
4549
- * @param theta - y 轴旋转弧度
4550
- * @returns 矩阵
4551
- */ Matrix4.fromRotationY = function fromRotationY(theta) {
4552
- return new Matrix4().setFromRotationY(theta);
4240
+ * 四元数转矩阵
4241
+ * @param mat - 目标矩阵
4242
+ * @returns
4243
+ */ _proto.toMatrix4 = function toMatrix4(mat) {
4244
+ return mat.compose(Vector3.ZERO, this, Vector3.ONE);
4553
4245
  };
4554
4246
  /**
4555
- * 通过 z 轴旋转创建矩阵
4556
- * @param theta - z 轴旋转弧度
4557
- * @returns
4558
- */ Matrix4.fromRotationZ = function fromRotationZ(theta) {
4559
- return new Matrix4().setFromRotationZ(theta);
4247
+ * 通过欧拉角创建四元数
4248
+ * @param euler - 欧拉角
4249
+ * @returns 四元数
4250
+ */ Quaternion.fromEuler = function fromEuler(euler) {
4251
+ return new Quaternion().setFromEuler(euler);
4560
4252
  };
4561
4253
  /**
4562
- * 通过旋转轴与旋转弧度创建矩阵
4254
+ * 通过旋转轴和旋转角度创建四元数
4563
4255
  * @param axis - 旋转轴
4564
- * @param angle - 旋转弧度
4565
- * @returns
4566
- */ Matrix4.fromRotationAxis = function fromRotationAxis(axis, angle) {
4567
- return new Matrix4().setFromRotationAxis(axis, angle);
4256
+ * @param angle - 旋转角(弧度值)
4257
+ * @returns 四元数
4258
+ */ Quaternion.fromAxisAngle = function fromAxisAngle(axis, angle) {
4259
+ return new Quaternion().setFromAxisAngle(axis, angle);
4568
4260
  };
4569
4261
  /**
4570
- * 通过欧拉角创建矩阵
4571
- * @param euler - 欧拉角
4572
- * @returns
4573
- */ Matrix4.fromEuler = function fromEuler(euler) {
4574
- return new Matrix4().setFromEuler(euler);
4262
+ * 通过 Vector4Like 创建四元数
4263
+ * @param v - Vector4Like
4264
+ * @returns 四元数
4265
+ */ Quaternion.fromVector4 = function fromVector4(v) {
4266
+ return new Quaternion().setFromVector4(v);
4575
4267
  };
4576
4268
  /**
4577
- * 通过四元数创建矩阵
4578
- * @param quat - 四元数
4579
- * @returns
4580
- */ Matrix4.fromQuaternion = function fromQuaternion(quat) {
4581
- return new Matrix4().setFromQuaternion(quat);
4269
+ * 通过数组创建四元数
4270
+ * @param array - 数组
4271
+ * @param [offset=0] - 起始偏移值
4272
+ * @returns 四元数
4273
+ */ Quaternion.fromArray = function fromArray(array, offset) {
4274
+ if (offset === void 0) offset = 0;
4275
+ return new Quaternion().setFromArray(array, offset);
4582
4276
  };
4583
4277
  /**
4584
- * 通过倾斜创建矩阵
4585
- * @param x - x 方向倾斜分量
4586
- * @param y - y 方向倾斜分量
4587
- * @param z - z 方向倾斜分量
4588
- * @returns 倾斜矩阵
4589
- */ Matrix4.fromShear = function fromShear(x, y, z) {
4590
- return new Matrix4().setFromShear(x, y, z);
4278
+ * 通过旋转矩阵创建四元数
4279
+ * @param m - 旋转矩阵
4280
+ * @returns 四元数
4281
+ */ Quaternion.fromRotationMatrix = function fromRotationMatrix(m) {
4282
+ return new Quaternion().setFromRotationMatrix(m);
4591
4283
  };
4592
4284
  /**
4593
- * 通过基轴创建矩阵
4594
- * @param xAxis - x 轴
4595
- * @param yAxis - y 轴
4596
- * @param zAxis - z 轴
4285
+ * 通过开始和结束向量创建四元数
4286
+ * @param from - 开始向量
4287
+ * @param to - 结束向量
4597
4288
  * @returns
4598
- */ Matrix4.fromBasis = function fromBasis(xAxis, yAxis, zAxis) {
4599
- return new Matrix4().setFromBasis(xAxis, yAxis, zAxis);
4289
+ */ Quaternion.fromUnitVectors = function fromUnitVectors(from, to) {
4290
+ return new Quaternion().setFromUnitVectors(from, to);
4291
+ };
4292
+ return Quaternion;
4293
+ }();
4294
+ Quaternion.tempVec0 = new Vector3();
4295
+
4296
+ /**
4297
+ * 四阶矩阵(列优先矩阵)
4298
+ */ var Matrix4 = /*#__PURE__*/ function() {
4299
+ function Matrix4(m11, m21, m31, m41, m12, m22, m32, m42, m13, m23, m33, m43, m14, m24, m34, m44) {
4300
+ if (m11 === void 0) m11 = 1;
4301
+ if (m21 === void 0) m21 = 0;
4302
+ if (m31 === void 0) m31 = 0;
4303
+ if (m41 === void 0) m41 = 0;
4304
+ if (m12 === void 0) m12 = 0;
4305
+ if (m22 === void 0) m22 = 1;
4306
+ if (m32 === void 0) m32 = 0;
4307
+ if (m42 === void 0) m42 = 0;
4308
+ if (m13 === void 0) m13 = 0;
4309
+ if (m23 === void 0) m23 = 0;
4310
+ if (m33 === void 0) m33 = 1;
4311
+ if (m43 === void 0) m43 = 0;
4312
+ if (m14 === void 0) m14 = 0;
4313
+ if (m24 === void 0) m24 = 0;
4314
+ if (m34 === void 0) m34 = 0;
4315
+ if (m44 === void 0) m44 = 1;
4316
+ this.elements = [
4317
+ m11,
4318
+ m21,
4319
+ m31,
4320
+ m41,
4321
+ m12,
4322
+ m22,
4323
+ m32,
4324
+ m42,
4325
+ m13,
4326
+ m23,
4327
+ m33,
4328
+ m43,
4329
+ m14,
4330
+ m24,
4331
+ m34,
4332
+ m44
4333
+ ];
4334
+ }
4335
+ var _proto = Matrix4.prototype;
4336
+ /**
4337
+ * 设置矩阵
4338
+ * @param m11 - 第 1 行,第 1 列
4339
+ * @param m21 - 第 2 行,第 1 列
4340
+ * @param m31 - 第 3 行,第 1 列
4341
+ * @param m41 - 第 4 行,第 1 列
4342
+ * @param m12 - 第 1 行,第 2 列
4343
+ * @param m22 - 第 2 行,第 2 列
4344
+ * @param m32 - 第 3 行,第 2 列
4345
+ * @param m42 - 第 4 行,第 2 列
4346
+ * @param m13 - 第 1 行,第 3 列
4347
+ * @param m23 - 第 2 行,第 3 列
4348
+ * @param m33 - 第 3 行,第 3 列
4349
+ * @param m43 - 第 4 行,第 3 列
4350
+ * @param m14 - 第 1 行,第 4 列
4351
+ * @param m24 - 第 2 行,第 4 列
4352
+ * @param m34 - 第 3 行,第 4 列
4353
+ * @param m44 - 第 4 行,第 4 列
4354
+ * @returns 矩阵
4355
+ */ _proto.set = function set(m11, m21, m31, m41, m12, m22, m32, m42, m13, m23, m33, m43, m14, m24, m34, m44) {
4356
+ var e = this.elements;
4357
+ e[0] = m11;
4358
+ e[1] = m21;
4359
+ e[2] = m31;
4360
+ e[3] = m41;
4361
+ e[4] = m12;
4362
+ e[5] = m22;
4363
+ e[6] = m32;
4364
+ e[7] = m42;
4365
+ e[8] = m13;
4366
+ e[9] = m23;
4367
+ e[10] = m33;
4368
+ e[11] = m43;
4369
+ e[12] = m14;
4370
+ e[13] = m24;
4371
+ e[14] = m34;
4372
+ e[15] = m44;
4373
+ return this;
4600
4374
  };
4601
4375
  /**
4602
4376
  * 通过行优先数据设置矩阵
@@ -4616,732 +4390,891 @@ Quaternion.tempVec0 = new Vector3();
4616
4390
  * @param m42 - 第 4 行,第 2 列
4617
4391
  * @param m43 - 第 4 行,第 3 列
4618
4392
  * @param m44 - 第 4 行,第 4 列
4619
- * @returns
4620
- */ Matrix4.fromRowMajorData = function fromRowMajorData(m11, m12, m13, m14, m21, m22, m23, m24, m31, m32, m33, m34, m41, m42, m43, m44) {
4621
- return new Matrix4(m11, m21, m31, m41, m12, m22, m32, m42, m13, m23, m33, m43, m14, m24, m34, m44);
4393
+ * @returns 矩阵
4394
+ */ _proto.setFromRowMajorData = function setFromRowMajorData(m11, m12, m13, m14, m21, m22, m23, m24, m31, m32, m33, m34, m41, m42, m43, m44) {
4395
+ var e = this.elements;
4396
+ e[0] = m11;
4397
+ e[4] = m12;
4398
+ e[8] = m13;
4399
+ e[12] = m14;
4400
+ e[1] = m21;
4401
+ e[5] = m22;
4402
+ e[9] = m23;
4403
+ e[13] = m24;
4404
+ e[2] = m31;
4405
+ e[6] = m32;
4406
+ e[10] = m33;
4407
+ e[14] = m34;
4408
+ e[3] = m41;
4409
+ e[7] = m42;
4410
+ e[11] = m43;
4411
+ e[15] = m44;
4412
+ return this;
4622
4413
  };
4623
- return Matrix4;
4624
- }();
4625
- Matrix4.IDENTITY = new Matrix4(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
4626
- Matrix4.ZERO = new Matrix4(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
4627
- Matrix4.tempVec0 = new Vector3();
4628
- Matrix4.tempVec1 = new Vector3();
4629
- Matrix4.tempVec2 = new Vector3();
4630
- Matrix4.tempMat0 = new Matrix4();
4631
-
4632
- /**
4633
- * 四维向量
4634
- */ var Vector4 = /*#__PURE__*/ function() {
4635
- function Vector4(x, y, z, w) {
4636
- if (x === void 0) x = 0;
4637
- if (y === void 0) y = 0;
4638
- if (z === void 0) z = 0;
4639
- if (w === void 0) w = 0;
4640
- this.x = x;
4641
- this.y = y;
4642
- this.z = z;
4643
- this.w = w;
4644
- }
4645
- var _proto = Vector4.prototype;
4646
4414
  /**
4647
- * 设置向量
4648
- * @param x - x 轴分量
4649
- * @param y - y 轴分量
4650
- * @param z - z 轴分量
4651
- * @param w - w 轴分量
4652
- * @returns
4653
- */ _proto.set = function set(x, y, z, w) {
4654
- this.x = x;
4655
- this.y = y;
4656
- this.z = z;
4657
- this.w = w;
4415
+ * 通过四个列向量设置矩阵
4416
+ * @param c1 - 第一列
4417
+ * @param c2 - 第二列
4418
+ * @param c3 - 第三列
4419
+ * @param c4 - 第四列
4420
+ * @returns 矩阵
4421
+ */ _proto.setFromColumnVectors = function setFromColumnVectors(c1, c2, c3, c4) {
4422
+ return this.set(c1.x, c1.y, c1.z, c1.w, c2.x, c2.y, c2.z, c2.w, c3.x, c3.y, c3.z, c3.w, c4.x, c4.y, c4.z, c4.w);
4423
+ };
4424
+ /**
4425
+ * 通过三维矩阵设置矩阵
4426
+ * @param m - 三维矩阵
4427
+ * @returns 设置结果
4428
+ */ _proto.setFromMatrix3 = function setFromMatrix3(m) {
4429
+ var me = m.elements;
4430
+ this.set(me[0], me[1], me[2], 0, me[3], me[4], me[5], 0, me[6], me[7], me[8], 0, 0, 0, 0, 1);
4431
+ return this;
4432
+ };
4433
+ /**
4434
+ * 通过数组设置矩阵
4435
+ * @param array - 数组
4436
+ * @param [offset=0] - 起始偏移值
4437
+ * @returns 矩阵
4438
+ */ _proto.setFromArray = function setFromArray(array, offset) {
4439
+ if (offset === void 0) offset = 0;
4440
+ for(var i = 0; i < 16; i++){
4441
+ this.elements[i] = array[offset + i];
4442
+ }
4658
4443
  return this;
4659
4444
  };
4660
4445
  /**
4661
- * 设置零向量
4662
- * @returns 向量
4663
- */ _proto.setZero = function setZero() {
4664
- this.x = 0;
4665
- this.y = 0;
4666
- this.z = 0;
4667
- this.w = 0;
4668
- return this;
4446
+ * 通过缩放设置矩阵
4447
+ * @param x - x 方向缩放
4448
+ * @param y - y 方向缩放
4449
+ * @param z - z 方向缩放
4450
+ * @returns 缩放矩阵
4451
+ */ _proto.setFromScale = function setFromScale(x, y, z) {
4452
+ return this.set(x, 0, 0, 0, 0, y, 0, 0, 0, 0, z, 0, 0, 0, 0, 1);
4453
+ };
4454
+ /**
4455
+ * 通过平移设置矩阵
4456
+ * @param x - x 方向平移
4457
+ * @param y - y 方向平移
4458
+ * @param z - z 方向平移
4459
+ * @returns 平移矩阵
4460
+ */ _proto.setFromTranslation = function setFromTranslation(x, y, z) {
4461
+ return this.set(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, x, y, z, 1);
4462
+ };
4463
+ /**
4464
+ * 通过 x 轴旋转角度设置矩阵
4465
+ * @param theta - x 轴旋转弧度
4466
+ * @returns 矩阵
4467
+ */ _proto.setFromRotationX = function setFromRotationX(theta) {
4468
+ var c = Math.cos(theta);
4469
+ var s = Math.sin(theta);
4470
+ return this.set(1, 0, 0, 0, 0, c, s, 0, 0, -s, c, 0, 0, 0, 0, 1);
4471
+ };
4472
+ /**
4473
+ * 通过 y 轴旋转角度设置矩阵
4474
+ * @param theta - y 轴旋转弧度
4475
+ * @returns 矩阵
4476
+ */ _proto.setFromRotationY = function setFromRotationY(theta) {
4477
+ var c = Math.cos(theta);
4478
+ var s = Math.sin(theta);
4479
+ return this.set(c, 0, -s, 0, 0, 1, 0, 0, s, 0, c, 0, 0, 0, 0, 1);
4480
+ };
4481
+ /**
4482
+ * 通过 z 轴旋转角度设置矩阵
4483
+ * @param theta - z 轴旋转弧度
4484
+ * @returns 矩阵
4485
+ */ _proto.setFromRotationZ = function setFromRotationZ(theta) {
4486
+ var c = Math.cos(theta);
4487
+ var s = Math.sin(theta);
4488
+ return this.set(c, s, 0, 0, -s, c, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
4669
4489
  };
4670
4490
  /**
4671
- * 通过标量数值设置向量
4672
- * @param num - 数值
4673
- * @returns 向量
4674
- */ _proto.setFromNumber = function setFromNumber(num) {
4675
- this.x = num;
4676
- this.y = num;
4677
- this.z = num;
4678
- this.w = num;
4679
- return this;
4491
+ * 根据三维旋转轴与弧度设置矩阵
4492
+ * @param axis - 三维旋转轴
4493
+ * @param angle - 旋转弧度
4494
+ * @returns 矩阵
4495
+ */ _proto.setFromRotationAxis = function setFromRotationAxis(axis, angle) {
4496
+ // Based on http://www.gamedev.net/reference/articles/article1199.asp
4497
+ var v = Matrix4.tempVec0;
4498
+ v.copyFrom(axis).normalize();
4499
+ var c = Math.cos(angle);
4500
+ var s = Math.sin(angle);
4501
+ var t = 1 - c;
4502
+ var x = v.x, y = v.y, z = v.z;
4503
+ var tx = t * x;
4504
+ var ty = t * y;
4505
+ return this.set(tx * x + c, tx * y + s * z, tx * z - s * y, 0, tx * y - s * z, ty * y + c, ty * z + s * x, 0, tx * z + s * y, ty * z - s * x, t * z * z + c, 0, 0, 0, 0, 1);
4680
4506
  };
4681
4507
  /**
4682
- * 通过数组创建向量
4683
- * @param array - 数组
4684
- * @param [offset=0] - 起始偏移值
4685
- * @returns 向量
4686
- */ _proto.setFromArray = function setFromArray(array, offset) {
4687
- if (offset === void 0) offset = 0;
4688
- var _array_offset;
4689
- this.x = (_array_offset = array[offset]) != null ? _array_offset : 0;
4690
- var _array_;
4691
- this.y = (_array_ = array[offset + 1]) != null ? _array_ : 0;
4692
- var _array_1;
4693
- this.z = (_array_1 = array[offset + 2]) != null ? _array_1 : 0;
4694
- var _array_2;
4695
- this.w = (_array_2 = array[offset + 3]) != null ? _array_2 : 0;
4508
+ * 通过欧拉角设置矩阵
4509
+ * @param euler - 欧拉角
4510
+ * @returns 矩阵
4511
+ */ _proto.setFromEuler = function setFromEuler(euler) {
4512
+ euler.toMatrix4(this);
4696
4513
  return this;
4697
4514
  };
4698
4515
  /**
4699
- * 拷贝向量
4700
- * @param v - 复制对象
4701
- * @returns 拷贝结果
4702
- */ _proto.copyFrom = function copyFrom(v) {
4703
- this.x = v.x;
4704
- this.y = v.y;
4705
- this.z = v.z;
4706
- this.w = v.w;
4707
- return this;
4516
+ * 通过四元数设置矩阵
4517
+ * @param quat - 四元数
4518
+ * @returns 矩阵
4519
+ */ _proto.setFromQuaternion = function setFromQuaternion(quat) {
4520
+ return this.compose(Vector3.ZERO, quat, Vector3.ONE);
4708
4521
  };
4709
4522
  /**
4710
- * 克隆向量
4711
- * @returns 克隆结果
4712
- */ _proto.clone = function clone() {
4713
- return new Vector4(this.x, this.y, this.z, this.w);
4523
+ * 通过倾斜参数设置矩阵
4524
+ * @param x - x 方向倾斜分量
4525
+ * @param y - y 方向倾斜分量
4526
+ * @param z - z 方向倾斜分量
4527
+ * @returns 倾斜矩阵
4528
+ */ _proto.setFromShear = function setFromShear(x, y, z) {
4529
+ return this.set(1, x, x, 0, y, 1, y, 0, z, z, 1, 0, 0, 0, 0, 1);
4714
4530
  };
4715
4531
  /**
4716
- * 根据下标设置向量分量
4717
- * @param index - 下标值
4718
- * @param value - 分量值
4719
- * @returns 向量
4720
- */ _proto.setElement = function setElement(index, value) {
4721
- switch(index){
4722
- case 0:
4723
- this.x = value;
4724
- break;
4725
- case 1:
4726
- this.y = value;
4727
- break;
4728
- case 2:
4729
- this.z = value;
4730
- break;
4731
- case 3:
4732
- this.w = value;
4733
- break;
4734
- default:
4735
- console.error("index is out of range: " + index);
4532
+ * 通过基轴设置矩阵
4533
+ * @param xAxis - x 轴
4534
+ * @param yAxis - y 轴
4535
+ * @param zAxis - z 轴
4536
+ * @returns 倾斜矩阵
4537
+ */ _proto.setFromBasis = function setFromBasis(xAxis, yAxis, zAxis) {
4538
+ return this.set(xAxis.x, xAxis.y, xAxis.z, 0, yAxis.x, yAxis.y, yAxis.z, 0, zAxis.x, zAxis.y, zAxis.z, 0, 0, 0, 0, 1);
4539
+ };
4540
+ /**
4541
+ * 矩阵清零
4542
+ * @returns 零矩阵
4543
+ */ _proto.setZero = function setZero() {
4544
+ for(var i = 0; i < 16; i++){
4545
+ this.elements[i] = 0;
4736
4546
  }
4737
4547
  return this;
4738
4548
  };
4739
4549
  /**
4740
- * 根据下标获取向量分量
4741
- * @param index - 下标
4742
- * @returns 分量值
4743
- */ _proto.getElement = function getElement(index) {
4744
- switch(index){
4745
- case 0:
4746
- return this.x;
4747
- case 1:
4748
- return this.y;
4749
- case 2:
4750
- return this.z;
4751
- case 3:
4752
- return this.w;
4753
- default:
4754
- console.error("index is out of range: " + index);
4755
- }
4756
- return 0;
4550
+ * 矩阵单位化
4551
+ * @returns 单位矩阵
4552
+ */ _proto.identity = function identity() {
4553
+ return this.set(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
4757
4554
  };
4758
4555
  /**
4759
- * 向量相加
4760
- * @param right - 相加对象,向量 | 数字
4761
- * @returns 相加结果
4762
- */ _proto.add = function add(right) {
4763
- if (typeof right === "number") {
4764
- this.x += right;
4765
- this.y += right;
4766
- this.z += right;
4767
- this.w += right;
4768
- } else if (_instanceof1(right, Array)) {
4769
- this.x += right[0];
4770
- this.y += right[1];
4771
- this.z += right[2];
4772
- this.w += right[3];
4773
- } else {
4774
- this.x += right.x;
4775
- this.y += right.y;
4776
- this.z += right.z;
4777
- this.w += right.w;
4778
- }
4779
- return this;
4556
+ * 单位阵判断
4557
+ * @returns 判断结果
4558
+ */ _proto.isIdentity = function isIdentity() {
4559
+ var e = this.elements;
4560
+ return e[0] === 1 && e[4] === 0 && e[8] === 0 && e[12] === 0 && e[1] === 0 && e[5] === 1 && e[9] === 0 && e[13] === 0 && e[2] === 0 && e[6] === 0 && e[10] === 1 && e[14] === 0 && e[3] === 0 && e[7] === 0 && e[11] === 0 && e[15] === 1;
4780
4561
  };
4781
4562
  /**
4782
- * 向量相加
4783
- * @param left - 向量
4784
- * @param right - 向量
4785
- * @returns 求和结果
4786
- */ _proto.addVectors = function addVectors(left, right) {
4787
- this.x = left.x + right.x;
4788
- this.y = left.y + right.y;
4789
- this.z = left.z + right.z;
4790
- this.w = left.w + right.w;
4791
- return this;
4563
+ * 矩阵克隆
4564
+ * @returns 克隆结果
4565
+ */ _proto.clone = function clone() {
4566
+ var e = this.elements;
4567
+ return new Matrix4(e[0], e[1], e[2], e[3], e[4], e[5], e[6], e[7], e[8], e[9], e[10], e[11], e[12], e[13], e[14], e[15]);
4792
4568
  };
4793
4569
  /**
4794
- * 向量比例缩放后相加
4795
- * @param right - 向量
4796
- * @param s - 比例
4797
- * @returns 求和结果
4798
- */ _proto.addScaledVector = function addScaledVector(right, s) {
4799
- this.x += right.x * s;
4800
- this.y += right.y * s;
4801
- this.z += right.z * s;
4802
- this.w += right.w * s;
4570
+ * 矩阵复制
4571
+ * @param m - 复制对象
4572
+ * @returns 复制结果
4573
+ */ _proto.copyFrom = function copyFrom(m) {
4574
+ this.elements = [].concat(m.elements);
4803
4575
  return this;
4804
4576
  };
4805
4577
  /**
4806
- * 向量相减
4807
- * @param right - 相减对象,向量 | 数字
4808
- * @returns 相减结果
4809
- */ _proto.subtract = function subtract(right) {
4810
- if (typeof right === "number") {
4811
- this.x -= right;
4812
- this.y -= right;
4813
- this.z -= right;
4814
- this.w -= right;
4815
- } else if (_instanceof1(right, Array)) {
4816
- this.x -= right[0];
4817
- this.y -= right[1];
4818
- this.z -= right[2];
4819
- this.w -= right[3];
4820
- } else {
4821
- this.x -= right.x;
4822
- this.y -= right.y;
4823
- this.z -= right.z;
4824
- this.w -= right.w;
4825
- }
4578
+ * 得到列向量
4579
+ * @param i - 列向量索引,从 0 开始
4580
+ * @param v
4581
+ * @returns 矩阵
4582
+ */ _proto.getColumnVector = function getColumnVector(i, v) {
4583
+ return v.set(this.elements[i * 4], this.elements[i * 4 + 1], this.elements[i * 4 + 2], this.elements[i * 4 + 3]);
4584
+ };
4585
+ /**
4586
+ * 设置相机矩阵
4587
+ * @param eye - 相机位置
4588
+ * @param target - 目标位置
4589
+ * @param up - 相机方向
4590
+ * @returns 矩阵
4591
+ */ _proto.lookAt = function lookAt(eye, target, up) {
4592
+ var vX = Matrix4.tempVec0;
4593
+ var vY = Matrix4.tempVec1;
4594
+ var vZ = Matrix4.tempVec2;
4595
+ vZ.subtractVectors(eye, target);
4596
+ vZ.normalize();
4597
+ vX.crossVectors(up, vZ);
4598
+ vX.normalize();
4599
+ vY.crossVectors(vZ, vX);
4600
+ var te = this.elements;
4601
+ te[0] = vX.x;
4602
+ te[1] = vY.x;
4603
+ te[2] = vZ.x;
4604
+ te[3] = 0;
4605
+ te[4] = vX.y;
4606
+ te[5] = vY.y;
4607
+ te[6] = vZ.y;
4608
+ te[7] = 0;
4609
+ te[8] = vX.z;
4610
+ te[9] = vY.z;
4611
+ te[10] = vZ.z;
4612
+ te[11] = 0;
4613
+ te[12] = -vX.dot(eye);
4614
+ te[13] = -vY.dot(eye);
4615
+ te[14] = -vZ.dot(eye);
4616
+ te[15] = 1;
4826
4617
  return this;
4827
4618
  };
4828
4619
  /**
4829
- * 向量相减
4830
- * @param left - 向量
4831
- * @param right - 向量
4832
- * @returns 向量
4833
- */ _proto.subtractVectors = function subtractVectors(left, right) {
4834
- this.x = left.x - right.x;
4835
- this.y = left.y - right.y;
4836
- this.z = left.z - right.z;
4837
- this.w = left.w - right.w;
4620
+ * 矩阵乘比例后相加
4621
+ * @param right - 矩阵
4622
+ * @param s - 比例
4623
+ * @returns 相加结果
4624
+ */ _proto.addScaledMatrix = function addScaledMatrix(right, s) {
4625
+ var te = this.elements;
4626
+ var re = right.elements;
4627
+ for(var i = 0; i < 16; i++){
4628
+ te[i] += re[i] * s;
4629
+ }
4838
4630
  return this;
4839
4631
  };
4840
4632
  /**
4841
- * 向量相乘
4842
- * @param right - 相乘对象,对象 | 数字
4843
- * @returns 向量
4633
+ * 矩阵右乘
4634
+ * @param right - 右侧矩阵或数值
4635
+ * @returns 右乘结果
4844
4636
  */ _proto.multiply = function multiply(right) {
4845
4637
  if (typeof right === "number") {
4846
- this.x *= right;
4847
- this.y *= right;
4848
- this.z *= right;
4849
- this.w *= right;
4850
- } else if (_instanceof1(right, Array)) {
4851
- this.x *= right[0];
4852
- this.y *= right[1];
4853
- this.z *= right[2];
4854
- this.w *= right[3];
4638
+ for(var i = 0; i < 16; i++){
4639
+ this.elements[i] *= right;
4640
+ }
4641
+ return this;
4855
4642
  } else {
4856
- this.x *= right.x;
4857
- this.y *= right.y;
4858
- this.z *= right.z;
4859
- this.w *= right.w;
4643
+ return this.multiplyMatrices(this, right);
4860
4644
  }
4645
+ };
4646
+ /**
4647
+ * 矩阵左乘
4648
+ * @param left - 左侧矩阵
4649
+ * @returns 左乘结果
4650
+ */ _proto.premultiply = function premultiply(left) {
4651
+ return this.multiplyMatrices(left, this);
4652
+ };
4653
+ /**
4654
+ * 矩阵相乘
4655
+ * @param left - 矩阵
4656
+ * @param right - 矩阵
4657
+ * @returns 相乘结果
4658
+ */ _proto.multiplyMatrices = function multiplyMatrices(left, right) {
4659
+ var ae = left.elements;
4660
+ var be = right.elements;
4661
+ var te = this.elements;
4662
+ var a11 = ae[0], a12 = ae[4], a13 = ae[8], a14 = ae[12];
4663
+ var a21 = ae[1], a22 = ae[5], a23 = ae[9], a24 = ae[13];
4664
+ var a31 = ae[2], a32 = ae[6], a33 = ae[10], a34 = ae[14];
4665
+ var a41 = ae[3], a42 = ae[7], a43 = ae[11], a44 = ae[15];
4666
+ var b11 = be[0], b12 = be[4], b13 = be[8], b14 = be[12];
4667
+ var b21 = be[1], b22 = be[5], b23 = be[9], b24 = be[13];
4668
+ var b31 = be[2], b32 = be[6], b33 = be[10], b34 = be[14];
4669
+ var b41 = be[3], b42 = be[7], b43 = be[11], b44 = be[15];
4670
+ te[0] = a11 * b11 + a12 * b21 + a13 * b31 + a14 * b41;
4671
+ te[4] = a11 * b12 + a12 * b22 + a13 * b32 + a14 * b42;
4672
+ te[8] = a11 * b13 + a12 * b23 + a13 * b33 + a14 * b43;
4673
+ te[12] = a11 * b14 + a12 * b24 + a13 * b34 + a14 * b44;
4674
+ te[1] = a21 * b11 + a22 * b21 + a23 * b31 + a24 * b41;
4675
+ te[5] = a21 * b12 + a22 * b22 + a23 * b32 + a24 * b42;
4676
+ te[9] = a21 * b13 + a22 * b23 + a23 * b33 + a24 * b43;
4677
+ te[13] = a21 * b14 + a22 * b24 + a23 * b34 + a24 * b44;
4678
+ te[2] = a31 * b11 + a32 * b21 + a33 * b31 + a34 * b41;
4679
+ te[6] = a31 * b12 + a32 * b22 + a33 * b32 + a34 * b42;
4680
+ te[10] = a31 * b13 + a32 * b23 + a33 * b33 + a34 * b43;
4681
+ te[14] = a31 * b14 + a32 * b24 + a33 * b34 + a34 * b44;
4682
+ te[3] = a41 * b11 + a42 * b21 + a43 * b31 + a44 * b41;
4683
+ te[7] = a41 * b12 + a42 * b22 + a43 * b32 + a44 * b42;
4684
+ te[11] = a41 * b13 + a42 * b23 + a43 * b33 + a44 * b43;
4685
+ te[15] = a41 * b14 + a42 * b24 + a43 * b34 + a44 * b44;
4861
4686
  return this;
4862
4687
  };
4863
4688
  /**
4864
- * 向量相乘
4865
- * @param left - 向量
4866
- * @param right - 向量
4867
- * @returns 向量
4868
- */ _proto.multiplyVectors = function multiplyVectors(left, right) {
4869
- this.x = left.x * right.x;
4870
- this.y = left.y * right.y;
4871
- this.z = left.z * right.z;
4872
- this.w = left.w * right.w;
4689
+ * 矩阵缩放
4690
+ * @param s - 缩放比例
4691
+ * @returns 缩放结果
4692
+ */ _proto.multiplyScalar = function multiplyScalar(s) {
4693
+ var e = this.elements;
4694
+ e[0] *= s;
4695
+ e[4] *= s;
4696
+ e[8] *= s;
4697
+ e[12] *= s;
4698
+ e[1] *= s;
4699
+ e[5] *= s;
4700
+ e[9] *= s;
4701
+ e[13] *= s;
4702
+ e[2] *= s;
4703
+ e[6] *= s;
4704
+ e[10] *= s;
4705
+ e[14] *= s;
4706
+ e[3] *= s;
4707
+ e[7] *= s;
4708
+ e[11] *= s;
4709
+ e[15] *= s;
4873
4710
  return this;
4874
4711
  };
4875
4712
  /**
4876
- * 向量相除
4877
- * @param right - 相除对象,对象 | 数字
4878
- * @returns 向量
4879
- */ _proto.divide = function divide(right) {
4880
- if (typeof right === "number") {
4881
- this.x /= right;
4882
- this.y /= right;
4883
- this.z /= right;
4884
- this.w /= right;
4885
- } else if (_instanceof1(right, Array)) {
4886
- this.x /= right[0];
4887
- this.y /= right[1];
4888
- this.z /= right[2];
4889
- this.w /= right[3];
4890
- } else {
4891
- this.x /= right.x;
4892
- this.y /= right.y;
4893
- this.z /= right.z;
4894
- this.w /= right.w;
4713
+ * 矩阵求行列式值
4714
+ * @returns 行列式值
4715
+ */ _proto.determinant = function determinant() {
4716
+ var e = this.elements;
4717
+ var m11 = e[0], m12 = e[4], m13 = e[8], m14 = e[12];
4718
+ var m21 = e[1], m22 = e[5], m23 = e[9], m24 = e[13];
4719
+ var m31 = e[2], m32 = e[6], m33 = e[10], m34 = e[14];
4720
+ var m41 = e[3], m42 = e[7], m43 = e[11], m44 = e[15];
4721
+ return m41 * (+m14 * m23 * m32 - m13 * m24 * m32 - m14 * m22 * m33 + m12 * m24 * m33 + m13 * m22 * m34 - m12 * m23 * m34) + m42 * (+m11 * m23 * m34 - m11 * m24 * m33 + m14 * m21 * m33 - m13 * m21 * m34 + m13 * m24 * m31 - m14 * m23 * m31) + m43 * (+m11 * m24 * m32 - m11 * m22 * m34 - m14 * m21 * m32 + m12 * m21 * m34 + m14 * m22 * m31 - m12 * m24 * m31) + m44 * (-m13 * m22 * m31 - m11 * m23 * m32 + m11 * m22 * m33 + m13 * m21 * m32 - m12 * m21 * m33 + m12 * m23 * m31);
4722
+ };
4723
+ /**
4724
+ * 矩阵转置
4725
+ * @returns 转置结果
4726
+ */ _proto.transpose = function transpose() {
4727
+ var e = this.elements;
4728
+ var t;
4729
+ t = e[1];
4730
+ e[1] = e[4];
4731
+ e[4] = t;
4732
+ t = e[2];
4733
+ e[2] = e[8];
4734
+ e[8] = t;
4735
+ t = e[3];
4736
+ e[3] = e[12];
4737
+ e[12] = t;
4738
+ //
4739
+ t = e[6];
4740
+ e[6] = e[9];
4741
+ e[9] = t;
4742
+ t = e[7];
4743
+ e[7] = e[13];
4744
+ e[13] = t;
4745
+ t = e[11];
4746
+ e[11] = e[14];
4747
+ e[14] = t;
4748
+ return this;
4749
+ };
4750
+ /**
4751
+ * 矩阵求逆
4752
+ * @returns 逆矩阵
4753
+ */ _proto.invert = function invert() {
4754
+ // based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm
4755
+ var e = this.elements;
4756
+ var m11 = e[0], m21 = e[1], m31 = e[2], m41 = e[3];
4757
+ var m12 = e[4], m22 = e[5], m32 = e[6], m42 = e[7];
4758
+ var m13 = e[8], m23 = e[9], m33 = e[10], m43 = e[11];
4759
+ var m14 = e[12], m24 = e[13], m34 = e[14], m44 = e[15];
4760
+ var t11 = m23 * m34 * m42 - m24 * m33 * m42 + m24 * m32 * m43 - m22 * m34 * m43 - m23 * m32 * m44 + m22 * m33 * m44;
4761
+ var t12 = m14 * m33 * m42 - m13 * m34 * m42 - m14 * m32 * m43 + m12 * m34 * m43 + m13 * m32 * m44 - m12 * m33 * m44;
4762
+ var t13 = m13 * m24 * m42 - m14 * m23 * m42 + m14 * m22 * m43 - m12 * m24 * m43 - m13 * m22 * m44 + m12 * m23 * m44;
4763
+ var t14 = m14 * m23 * m32 - m13 * m24 * m32 - m14 * m22 * m33 + m12 * m24 * m33 + m13 * m22 * m34 - m12 * m23 * m34;
4764
+ var det = m11 * t11 + m21 * t12 + m31 * t13 + m41 * t14;
4765
+ if (det === 0) {
4766
+ return this.set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
4895
4767
  }
4768
+ var detInv = 1 / det;
4769
+ e[0] = t11 * detInv;
4770
+ e[1] = (m24 * m33 * m41 - m23 * m34 * m41 - m24 * m31 * m43 + m21 * m34 * m43 + m23 * m31 * m44 - m21 * m33 * m44) * detInv;
4771
+ e[2] = (m22 * m34 * m41 - m24 * m32 * m41 + m24 * m31 * m42 - m21 * m34 * m42 - m22 * m31 * m44 + m21 * m32 * m44) * detInv;
4772
+ e[3] = (m23 * m32 * m41 - m22 * m33 * m41 - m23 * m31 * m42 + m21 * m33 * m42 + m22 * m31 * m43 - m21 * m32 * m43) * detInv;
4773
+ e[4] = t12 * detInv;
4774
+ e[5] = (m13 * m34 * m41 - m14 * m33 * m41 + m14 * m31 * m43 - m11 * m34 * m43 - m13 * m31 * m44 + m11 * m33 * m44) * detInv;
4775
+ e[6] = (m14 * m32 * m41 - m12 * m34 * m41 - m14 * m31 * m42 + m11 * m34 * m42 + m12 * m31 * m44 - m11 * m32 * m44) * detInv;
4776
+ e[7] = (m12 * m33 * m41 - m13 * m32 * m41 + m13 * m31 * m42 - m11 * m33 * m42 - m12 * m31 * m43 + m11 * m32 * m43) * detInv;
4777
+ e[8] = t13 * detInv;
4778
+ e[9] = (m14 * m23 * m41 - m13 * m24 * m41 - m14 * m21 * m43 + m11 * m24 * m43 + m13 * m21 * m44 - m11 * m23 * m44) * detInv;
4779
+ e[10] = (m12 * m24 * m41 - m14 * m22 * m41 + m14 * m21 * m42 - m11 * m24 * m42 - m12 * m21 * m44 + m11 * m22 * m44) * detInv;
4780
+ e[11] = (m13 * m22 * m41 - m12 * m23 * m41 - m13 * m21 * m42 + m11 * m23 * m42 + m12 * m21 * m43 - m11 * m22 * m43) * detInv;
4781
+ e[12] = t14 * detInv;
4782
+ e[13] = (m13 * m24 * m31 - m14 * m23 * m31 + m14 * m21 * m33 - m11 * m24 * m33 - m13 * m21 * m34 + m11 * m23 * m34) * detInv;
4783
+ e[14] = (m14 * m22 * m31 - m12 * m24 * m31 - m14 * m21 * m32 + m11 * m24 * m32 + m12 * m21 * m34 - m11 * m22 * m34) * detInv;
4784
+ e[15] = (m12 * m23 * m31 - m13 * m22 * m31 + m13 * m21 * m32 - m11 * m23 * m32 - m12 * m21 * m33 + m11 * m22 * m33) * detInv;
4896
4785
  return this;
4897
4786
  };
4898
4787
  /**
4899
- * 向量缩放
4900
- * @param v - 数字
4901
- * @returns 缩放结果
4902
- */ _proto.scale = function scale(v) {
4903
- this.x *= v;
4904
- this.y *= v;
4905
- this.z *= v;
4906
- this.w *= v;
4788
+ * 提取基轴
4789
+ * @param xAxis - 提取的 x 轴
4790
+ * @param yAxis - 提取的 y 轴
4791
+ * @param zAxis - 提取的 z 轴
4792
+ * @returns
4793
+ */ _proto.extractBasis = function extractBasis(xAxis, yAxis, zAxis) {
4794
+ var te = this.elements;
4795
+ xAxis.set(te[0], te[1], te[2]);
4796
+ yAxis.set(te[4], te[5], te[6]);
4797
+ zAxis.set(te[8], te[9], te[10]);
4798
+ return this;
4799
+ };
4800
+ /**
4801
+ * 根据基础信息组装矩阵
4802
+ * @param translation - 位置信息
4803
+ * @param rotation - 旋转信息
4804
+ * @param scale - 缩放信息
4805
+ * @param [anchor] - 锚点信息
4806
+ * @returns 矩阵
4807
+ */ _proto.compose = function compose(translation, rotation, scale, anchor) {
4808
+ if (anchor === void 0) anchor = Vector3.ZERO;
4809
+ var te = this.elements;
4810
+ var x = rotation.x, y = rotation.y, z = rotation.z, w = rotation.w;
4811
+ var l = -anchor.x;
4812
+ var m = -anchor.y;
4813
+ var n = -anchor.z;
4814
+ var x2 = x + x;
4815
+ var y2 = y + y;
4816
+ var z2 = z + z;
4817
+ var xx = x * x2;
4818
+ var xy = x * y2;
4819
+ var xz = x * z2;
4820
+ var yy = y * y2;
4821
+ var yz = y * z2;
4822
+ var zz = z * z2;
4823
+ var wx = w * x2;
4824
+ var wy = w * y2;
4825
+ var wz = w * z2;
4826
+ var sx = scale.x, sy = scale.y, sz = scale.z;
4827
+ te[0] = (1 - (yy + zz)) * sx;
4828
+ te[1] = (xy + wz) * sx;
4829
+ te[2] = (xz - wy) * sx;
4830
+ te[3] = 0;
4831
+ te[4] = (xy - wz) * sy;
4832
+ te[5] = (1 - (xx + zz)) * sy;
4833
+ te[6] = (yz + wx) * sy;
4834
+ te[7] = 0;
4835
+ te[8] = (xz + wy) * sz;
4836
+ te[9] = (yz - wx) * sz;
4837
+ te[10] = (1 - (xx + yy)) * sz;
4838
+ te[11] = 0;
4839
+ te[12] = l * te[0] + m * te[4] + n * te[8] - l + translation.x;
4840
+ te[13] = l * te[1] + m * te[5] + n * te[9] - m + translation.y;
4841
+ te[14] = l * te[2] + m * te[6] + n * te[10] - n + translation.z;
4907
4842
  return this;
4908
4843
  };
4909
4844
  /**
4910
- * 分量求和
4911
- * @returns 求和结果
4912
- */ _proto.sum = function sum() {
4913
- return this.x + this.y + this.z + this.w;
4914
- };
4915
- /**
4916
- * 向量求最小值
4917
- * @param v - 向量或数值
4918
- * @returns 最小值
4919
- */ _proto.min = function min(v) {
4920
- if (typeof v === "number") {
4921
- this.x = Math.min(this.x, v);
4922
- this.y = Math.min(this.y, v);
4923
- this.z = Math.min(this.z, v);
4924
- this.w = Math.min(this.w, v);
4925
- } else {
4926
- this.x = Math.min(this.x, v.x);
4927
- this.y = Math.min(this.y, v.y);
4928
- this.z = Math.min(this.z, v.z);
4929
- this.w = Math.min(this.w, v.w);
4845
+ * 矩阵拆分为基础信息
4846
+ * @param translation - 位置信息
4847
+ * @param rotation - 旋转信息
4848
+ * @param scale - 缩放信息
4849
+ * @returns 矩阵
4850
+ */ _proto.decompose = function decompose(translation, rotation, scale) {
4851
+ var v = Matrix4.tempVec0;
4852
+ var te = this.elements;
4853
+ var sx = v.set(te[0], te[1], te[2]).length();
4854
+ var sy = v.set(te[4], te[5], te[6]).length();
4855
+ var sz = v.set(te[8], te[9], te[10]).length();
4856
+ // if determine is negative, we need to invert one scale
4857
+ var det = this.determinant();
4858
+ if (det < 0) {
4859
+ sx = -sx;
4930
4860
  }
4861
+ translation.x = te[12];
4862
+ translation.y = te[13];
4863
+ translation.z = te[14];
4864
+ // scale the rotation part
4865
+ var m = Matrix4.tempMat0;
4866
+ m.copyFrom(this);
4867
+ var invSX = 1 / sx;
4868
+ var invSY = 1 / sy;
4869
+ var invSZ = 1 / sz;
4870
+ m.elements[0] *= invSX;
4871
+ m.elements[1] *= invSX;
4872
+ m.elements[2] *= invSX;
4873
+ m.elements[4] *= invSY;
4874
+ m.elements[5] *= invSY;
4875
+ m.elements[6] *= invSY;
4876
+ m.elements[8] *= invSZ;
4877
+ m.elements[9] *= invSZ;
4878
+ m.elements[10] *= invSZ;
4879
+ rotation.setFromRotationMatrix(m);
4880
+ scale.x = sx;
4881
+ scale.y = sy;
4882
+ scale.z = sz;
4931
4883
  return this;
4932
4884
  };
4933
- /**
4934
- * 向量求最大值
4935
- * @param v - 向量或数值
4936
- * @returns 最大值
4937
- */ _proto.max = function max(v) {
4938
- if (typeof v === "number") {
4939
- this.x = Math.max(this.x, v);
4940
- this.y = Math.max(this.y, v);
4941
- this.z = Math.max(this.z, v);
4942
- this.w = Math.max(this.w, v);
4943
- } else {
4944
- this.x = Math.max(this.x, v.x);
4945
- this.y = Math.max(this.y, v.y);
4946
- this.z = Math.max(this.z, v.z);
4947
- this.w = Math.max(this.w, v.w);
4948
- }
4949
- return this;
4885
+ _proto.getTranslation = function getTranslation(translation) {
4886
+ var te = this.elements;
4887
+ return translation.set(te[12], te[13], te[14]);
4888
+ };
4889
+ _proto.getScale = function getScale(scale) {
4890
+ var te = this.elements;
4891
+ return scale.set(Math.hypot(te[0], te[1], te[2]), Math.hypot(te[4], te[5], te[6]), Math.hypot(te[8], te[9], te[10]));
4950
4892
  };
4951
4893
  /**
4952
- * 向量阈值约束
4953
- * @param min - 最小值
4954
- * @param max - 最大值
4955
- * @returns 向量
4956
- */ _proto.clamp = function clamp(min, max) {
4957
- return this.max(min).min(max);
4894
+ * 获得矩阵分解的结果
4895
+ * @returns 分解的结果
4896
+ */ _proto.getTransform = function getTransform() {
4897
+ var translation = new Vector3();
4898
+ var rotation = new Quaternion();
4899
+ var scale = new Vector3();
4900
+ this.decompose(translation, rotation, scale);
4901
+ return {
4902
+ translation: translation,
4903
+ rotation: rotation,
4904
+ scale: scale
4905
+ };
4958
4906
  };
4959
4907
  /**
4960
- * 向量向下取整
4961
- * @returns 取整结果
4962
- */ _proto.floor = function floor() {
4963
- this.x = Math.floor(this.x);
4964
- this.y = Math.floor(this.y);
4965
- this.z = Math.floor(this.z);
4966
- this.w = Math.floor(this.w);
4908
+ * 根据视窗信息设置正交相机投影矩阵
4909
+ * @param left - 视窗左平面位置
4910
+ * @param right - 视窗右平面位置
4911
+ * @param top - 视窗上平面位置
4912
+ * @param bottom - 视窗下平面位置
4913
+ * @param near - 视窗近平面位置
4914
+ * @param far - 视窗远平面位置
4915
+ * @returns 矩阵
4916
+ */ _proto.orthographic = function orthographic(left, right, top, bottom, near, far) {
4917
+ var a = 1.0 / (right - left);
4918
+ var b = 1.0 / (top - bottom);
4919
+ var c = 1.0 / (far - near);
4920
+ var tx = -(right + left) * a;
4921
+ var ty = -(top + bottom) * b;
4922
+ var tz = -(far + near) * c;
4923
+ a *= 2.0;
4924
+ b *= 2.0;
4925
+ c *= -2.0;
4926
+ var te = this.elements;
4927
+ te[0] = a;
4928
+ te[1] = 0.0;
4929
+ te[2] = 0.0;
4930
+ te[3] = 0.0;
4931
+ //
4932
+ te[4] = 0.0;
4933
+ te[5] = b;
4934
+ te[6] = 0.0;
4935
+ te[7] = 0.0;
4936
+ //
4937
+ te[8] = 0.0;
4938
+ te[9] = 0.0;
4939
+ te[10] = c;
4940
+ te[11] = 0.0;
4941
+ //
4942
+ te[12] = tx;
4943
+ te[13] = ty;
4944
+ te[14] = tz;
4945
+ te[15] = 1.0;
4967
4946
  return this;
4968
4947
  };
4969
4948
  /**
4970
- * 向量向上取整
4971
- * @returns 取整结果
4972
- */ _proto.ceil = function ceil() {
4973
- this.x = Math.ceil(this.x);
4974
- this.y = Math.ceil(this.y);
4975
- this.z = Math.ceil(this.z);
4976
- this.w = Math.ceil(this.w);
4949
+ * 通过透视相机基础参数设置投影矩阵
4950
+ * @param fov - 视角(弧度)
4951
+ * @param aspect - 视窗比例
4952
+ * @param near - 近平面
4953
+ * @param far - 远平面
4954
+ * @param [reverse] - 视锥体长宽反转(3D这里反了?)
4955
+ * @returns 投影矩阵
4956
+ */ _proto.perspective = function perspective(fov, aspect, near, far, reverse) {
4957
+ var f = 1.0 / Math.tan(fov * 0.5);
4958
+ var nf = 1 / (near - far);
4959
+ var te = this.elements;
4960
+ te[0] = reverse ? f : f / aspect;
4961
+ te[1] = 0;
4962
+ te[2] = 0;
4963
+ te[3] = 0;
4964
+ //
4965
+ te[4] = 0;
4966
+ te[5] = reverse ? f * aspect : f;
4967
+ te[6] = 0;
4968
+ te[7] = 0;
4969
+ //
4970
+ te[8] = 0;
4971
+ te[9] = 0;
4972
+ te[10] = (far + near) * nf;
4973
+ te[11] = -1;
4974
+ //
4975
+ te[12] = 0;
4976
+ te[13] = 0;
4977
+ te[14] = 2 * far * near * nf;
4978
+ te[15] = 0;
4979
+ if (far === null || far === Infinity) {
4980
+ te[10] = -1;
4981
+ te[14] = -2 * near;
4982
+ }
4977
4983
  return this;
4978
4984
  };
4979
4985
  /**
4980
- * 向量四舍五入
4981
- * @returns 求值结果
4982
- */ _proto.round = function round() {
4983
- this.x = Math.round(this.x);
4984
- this.y = Math.round(this.y);
4985
- this.z = Math.round(this.z);
4986
- this.w = Math.round(this.w);
4987
- return this;
4986
+ * 对点进行投影变换
4987
+ * @param v - 输入点
4988
+ * @param [out] - 输出点,如果没有就覆盖输入的数据
4989
+ * @returns 投影后的点
4990
+ */ _proto.projectPoint = function projectPoint(v, out) {
4991
+ var x = v.x, y = v.y, z = v.z;
4992
+ var e = this.elements;
4993
+ var res = out != null ? out : v;
4994
+ res.x = e[0] * x + e[4] * y + e[8] * z + e[12];
4995
+ res.y = e[1] * x + e[5] * y + e[9] * z + e[13];
4996
+ res.z = e[2] * x + e[6] * y + e[10] * z + e[14];
4997
+ var w = e[3] * x + e[7] * y + e[11] * z + e[15];
4998
+ return res.multiply(1 / w);
4988
4999
  };
4989
5000
  /**
4990
- * 向量取绝对值
4991
- * @returns 向量
4992
- */ _proto.abs = function abs() {
4993
- this.x = Math.abs(this.x);
4994
- this.y = Math.abs(this.y);
4995
- this.z = Math.abs(this.z);
4996
- this.w = Math.abs(this.w);
4997
- return this;
5001
+ * 对点进行矩阵变换
5002
+ * @param v - 输入点
5003
+ * @param [out] - 输出点,如果没有就覆盖输入的数据
5004
+ * @returns 变换后的点
5005
+ */ _proto.transformPoint = function transformPoint(v, out) {
5006
+ var x = v.x, y = v.y, z = v.z;
5007
+ var e = this.elements;
5008
+ var res = out != null ? out : v;
5009
+ res.x = e[0] * x + e[4] * y + e[8] * z + e[12];
5010
+ res.y = e[1] * x + e[5] * y + e[9] * z + e[13];
5011
+ res.z = e[2] * x + e[6] * y + e[10] * z + e[14];
5012
+ return res;
4998
5013
  };
4999
5014
  /**
5000
- * 向量取反
5001
- * @returns 取反结果
5002
- */ _proto.negate = function negate() {
5003
- this.x = -this.x;
5004
- this.y = -this.y;
5005
- this.z = -this.z;
5006
- this.w = -this.w;
5007
- return this;
5015
+ * 对法向量进行矩阵变换
5016
+ * @param v - 输入法向量
5017
+ * @param [out] - 输出法向量,如果没有就覆盖输入的数据
5018
+ * @returns 变换后的法向量
5019
+ */ _proto.transformNormal = function transformNormal(v, out) {
5020
+ var x = v.x, y = v.y, z = v.z;
5021
+ var e = this.elements;
5022
+ var res = out != null ? out : v;
5023
+ res.x = e[0] * x + e[4] * y + e[8] * z;
5024
+ res.y = e[1] * x + e[5] * y + e[9] * z;
5025
+ res.z = e[2] * x + e[6] * y + e[10] * z;
5026
+ return res.normalize();
5008
5027
  };
5009
5028
  /**
5010
- * 向量长度平方
5011
- * @returns 长度平方
5012
- */ _proto.lengthSquared = function lengthSquared() {
5013
- return this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w;
5029
+ * 对四维向量进行矩阵变换
5030
+ * @param v - 输入向量
5031
+ * @param [out] - 输出向量,如果没有就覆盖输入的数据
5032
+ * @returns 变换后向量
5033
+ */ _proto.transformVector4 = function transformVector4(v, out) {
5034
+ var x = v.x, y = v.y, z = v.z, w = v.w;
5035
+ var e = this.elements;
5036
+ var res = out != null ? out : v;
5037
+ res.x = e[0] * x + e[4] * y + e[8] * z + e[12] * w;
5038
+ res.y = e[1] * x + e[5] * y + e[9] * z + e[13] * w;
5039
+ res.z = e[2] * x + e[6] * y + e[10] * z + e[14] * w;
5040
+ res.w = e[3] * x + e[7] * y + e[11] * z + e[15] * w;
5041
+ return res;
5014
5042
  };
5015
5043
  /**
5016
- * 向量长度
5017
- * @returns 长度
5018
- */ _proto.length = function length() {
5019
- return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w);
5044
+ * 矩阵判等
5045
+ * @param matrix - 矩阵
5046
+ * @returns 判等结果
5047
+ */ _proto.equals = function equals(matrix) {
5048
+ var te = this.elements;
5049
+ var me = matrix.elements;
5050
+ for(var i = 0; i < 16; i++){
5051
+ if (!isEqual(te[i], me[i])) {
5052
+ return false;
5053
+ }
5054
+ }
5055
+ return true;
5020
5056
  };
5021
5057
  /**
5022
- * 向量归一化
5023
- * @returns 归一化结果
5024
- */ _proto.normalize = function normalize() {
5025
- return this.divide(this.length() || 1);
5058
+ * 矩阵转数组
5059
+ * @returns
5060
+ */ _proto.toArray = function toArray() {
5061
+ return [].concat(this.elements);
5026
5062
  };
5027
- /**
5028
- * 设置向量长度
5029
- * @param length - 长度
5030
- * @returns 向量
5031
- */ _proto.setLength = function setLength(length) {
5032
- return this.normalize().multiply(length);
5063
+ _proto.fill = function fill(array, offset) {
5064
+ if (offset === void 0) offset = 0;
5065
+ var te = this.elements;
5066
+ array[offset] = te[0];
5067
+ array[offset + 1] = te[1];
5068
+ array[offset + 2] = te[2];
5069
+ array[offset + 3] = te[3];
5070
+ array[offset + 4] = te[4];
5071
+ array[offset + 5] = te[5];
5072
+ array[offset + 6] = te[6];
5073
+ array[offset + 7] = te[7];
5074
+ array[offset + 8] = te[8];
5075
+ array[offset + 9] = te[9];
5076
+ array[offset + 10] = te[10];
5077
+ array[offset + 11] = te[11];
5078
+ array[offset + 12] = te[12];
5079
+ array[offset + 13] = te[13];
5080
+ array[offset + 14] = te[14];
5081
+ array[offset + 15] = te[15];
5033
5082
  };
5034
5083
  /**
5035
- * 向量求线性插值
5036
- * @param v - 向量
5037
- * @param alpha - 插值比例
5038
- * @returns 插值结果
5039
- */ _proto.lerp = function lerp(v, alpha) {
5040
- this.x += (v.x - this.x) * alpha;
5041
- this.y += (v.y - this.y) * alpha;
5042
- this.z += (v.z - this.z) * alpha;
5043
- this.w += (v.w - this.w) * alpha;
5044
- return this;
5084
+ * 创建单位阵
5085
+ * @returns 单位矩阵
5086
+ */ Matrix4.fromIdentity = function fromIdentity() {
5087
+ return new Matrix4(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
5045
5088
  };
5046
5089
  /**
5047
- * 两向量求线性插值
5048
- * @param v1 - 第一个向量
5049
- * @param v2 - 第二个向量
5050
- * @param alpha - 插值比例
5051
- * @returns 插值结果
5052
- */ _proto.lerpVectors = function lerpVectors(v1, v2, alpha) {
5053
- this.x = v1.x + (v2.x - v1.x) * alpha;
5054
- this.y = v1.y + (v2.y - v1.y) * alpha;
5055
- this.z = v1.z + (v2.z - v1.z) * alpha;
5056
- this.w = v1.w + (v2.w - v1.w) * alpha;
5057
- return this;
5090
+ * 创建相机矩阵
5091
+ * @param eye - 相机位置
5092
+ * @param target - 目标位置
5093
+ * @param up - 相机方向
5094
+ * @returns 矩阵
5095
+ */ Matrix4.fromLookAt = function fromLookAt(eye, target, up) {
5096
+ return new Matrix4().lookAt(eye, target, up);
5058
5097
  };
5059
5098
  /**
5060
- * 向量求点积
5061
- * @param v - 向量
5062
- * @returns 点积结果
5063
- */ _proto.dot = function dot(v) {
5064
- return this.x * v.x + this.y * v.y + this.z * v.z + this.w * v.w;
5099
+ * 创建投影矩阵
5100
+ * @param fov - 视角
5101
+ * @param aspect - 视窗比例
5102
+ * @param near - 近平面
5103
+ * @param far - 远平面
5104
+ * @param [reverse] - 视锥体长宽反转
5105
+ * @returns 投影矩阵
5106
+ */ Matrix4.fromPerspective = function fromPerspective(fov, aspect, near, far, reverse) {
5107
+ return new Matrix4().perspective(fov, aspect, near, far, reverse);
5065
5108
  };
5066
5109
  /**
5067
- * 向量判等
5068
- * @param v - 向量
5069
- * @returns 判等结果
5070
- */ _proto.equals = function equals(v) {
5071
- return v.x === this.x && v.y === this.y && v.z === this.z && v.w === this.w;
5110
+ * 通过四个列向量创建矩阵
5111
+ * @param c1 - 第一列
5112
+ * @param c2 - 第二列
5113
+ * @param c3 - 第三列
5114
+ * @param c4 - 第四列
5115
+ * @returns
5116
+ */ Matrix4.fromColumnVectors = function fromColumnVectors(c1, c2, c3, c4) {
5117
+ return new Matrix4().setFromColumnVectors(c1, c2, c3, c4);
5072
5118
  };
5073
5119
  /**
5074
- * 是否零向量
5075
- * @returns 是否零向量
5076
- */ _proto.isZero = function isZero() {
5077
- var eps = NumberEpsilon;
5078
- var _this = this, x = _this.x, y = _this.y, z = _this.z, w = _this.w;
5079
- return Math.abs(x) <= eps && Math.abs(y) <= eps && Math.abs(z) <= eps && Math.abs(w) <= eps;
5120
+ * 通过三阶矩阵创建矩阵
5121
+ * @param m - 三阶矩阵
5122
+ * @returns 创建的矩阵
5123
+ */ Matrix4.fromMatrix3 = function fromMatrix3(m) {
5124
+ return new Matrix4().setFromMatrix3(m);
5080
5125
  };
5081
5126
  /**
5082
- * 向量转数组
5083
- * @returns 数组
5084
- */ _proto.toArray = function toArray() {
5085
- return [
5086
- this.x,
5087
- this.y,
5088
- this.z,
5089
- this.w
5090
- ];
5091
- };
5092
- _proto.toVector3 = function toVector3() {
5093
- return new Vector3(this.x, this.y, this.z);
5094
- };
5095
- _proto.fill = function fill(array, offset) {
5127
+ * 通过数组创建矩阵
5128
+ * @param array - 数组
5129
+ * @param [offset=0] - 起始偏移值
5130
+ * @returns 矩阵
5131
+ */ Matrix4.fromArray = function fromArray(array, offset) {
5096
5132
  if (offset === void 0) offset = 0;
5097
- array[offset] = this.x;
5098
- array[offset + 1] = this.y;
5099
- array[offset + 2] = this.z;
5100
- array[offset + 3] = this.w;
5133
+ return new Matrix4().setFromArray(array, offset);
5101
5134
  };
5102
5135
  /**
5103
- * 生成随机向量
5104
- * @returns 向量
5105
- */ _proto.random = function random() {
5106
- this.x = Math.random();
5107
- this.y = Math.random();
5108
- this.z = Math.random();
5109
- this.w = Math.random();
5110
- return this;
5136
+ * 通过缩放创建矩阵
5137
+ * @param x - x 缩放
5138
+ * @param y - y 缩放
5139
+ * @param z - z 缩放
5140
+ * @returns 缩放结果
5141
+ */ Matrix4.fromScale = function fromScale(x, y, z) {
5142
+ return new Matrix4().setFromScale(x, y, z);
5111
5143
  };
5112
5144
  /**
5113
- * 变换矩阵作用于向量
5114
- * @param m - 变换矩阵
5115
- * @param [out] - 输出结果,如果没有设置就直接覆盖当前值
5116
- * @returns 向量
5117
- */ _proto.applyMatrix = function applyMatrix(m, out) {
5118
- return m.transformVector4(this, out);
5145
+ * 通过平移创建矩阵
5146
+ * @param x - x 平移
5147
+ * @param y - y 平移
5148
+ * @param z - z 平移
5149
+ * @returns 平移结果
5150
+ */ Matrix4.fromTranslation = function fromTranslation(x, y, z) {
5151
+ return new Matrix4().setFromTranslation(x, y, z);
5119
5152
  };
5120
5153
  /**
5121
- * 通过标量数值创建向量
5122
- * @param num - 数值
5123
- * @returns 向量
5124
- */ Vector4.fromNumber = function fromNumber(num) {
5125
- return new Vector4().setFromNumber(num);
5154
+ * 通过 x 轴旋转创建矩阵
5155
+ * @param theta - x 轴旋转弧度
5156
+ * @returns 矩阵
5157
+ */ Matrix4.fromRotationX = function fromRotationX(theta) {
5158
+ return new Matrix4().setFromRotationX(theta);
5126
5159
  };
5127
5160
  /**
5128
- * 通过数组创建向量
5129
- * @param array - 数组
5130
- * @param [offset=0] - 起始偏移值
5131
- * @returns 向量
5132
- */ Vector4.fromArray = function fromArray(array, offset) {
5133
- if (offset === void 0) offset = 0;
5134
- return new Vector4().setFromArray(array, offset);
5135
- };
5136
- return Vector4;
5137
- }();
5138
- /**
5139
- * 四维向量的常量
5140
- */ Vector4.ONE = new Vector4(1.0, 1.0, 1.0, 1.0);
5141
- Vector4.ZERO = new Vector4(0.0, 0.0, 0.0, 0.0);
5142
-
5143
- exports.EffectComponent = /*#__PURE__*/ function(RendererComponent) {
5144
- _inherits(EffectComponent, RendererComponent);
5145
- function EffectComponent(engine) {
5146
- var _this;
5147
- _this = RendererComponent.call(this, engine) || this;
5148
- /**
5149
- * Mesh 的世界矩阵
5150
- */ _this.worldMatrix = Matrix4.fromIdentity();
5151
- _this.triangles = [];
5152
- _this.destroyed = false;
5153
- // TODO 点击测试后续抽象一个 Collider 组件
5154
- _this.getHitTestParams = function(force) {
5155
- var area = _this.getBoundingBox();
5156
- if (area) {
5157
- return {
5158
- type: area.type,
5159
- triangles: area.area
5160
- };
5161
- }
5162
- };
5163
- _this.name = "EffectComponent";
5164
- _this._priority = 0;
5165
- return _this;
5166
- }
5167
- var _proto = EffectComponent.prototype;
5168
- _proto.onStart = function onStart() {
5169
- this.item.getHitTestParams = this.getHitTestParams;
5170
- };
5171
- _proto.onUpdate = function onUpdate(dt) {
5172
- var time = this.item.time;
5173
- var _this_material_getVector4;
5174
- var _Time = (_this_material_getVector4 = this.material.getVector4("_Time")) != null ? _this_material_getVector4 : new Vector4();
5175
- this.material.setVector4("_Time", _Time.set(time / 20, time, time * 2, time * 3));
5161
+ * 通过 y 轴旋转创建矩阵
5162
+ * @param theta - y 轴旋转弧度
5163
+ * @returns 矩阵
5164
+ */ Matrix4.fromRotationY = function fromRotationY(theta) {
5165
+ return new Matrix4().setFromRotationY(theta);
5176
5166
  };
5177
- _proto.render = function render(renderer) {
5178
- if (renderer.renderingData.currentFrame.globalUniforms) {
5179
- renderer.setGlobalMatrix("effects_ObjectToWorld", this.transform.getWorldMatrix());
5180
- }
5181
- renderer.drawGeometry(this.geometry, this.material);
5167
+ /**
5168
+ * 通过 z 轴旋转创建矩阵
5169
+ * @param theta - z 轴旋转弧度
5170
+ * @returns
5171
+ */ Matrix4.fromRotationZ = function fromRotationZ(theta) {
5172
+ return new Matrix4().setFromRotationZ(theta);
5182
5173
  };
5183
5174
  /**
5184
- * 设置当前 Mesh 的材质
5185
- * @param material - 要设置的材质
5186
- * @param destroy - 可选的材质销毁选项
5187
- */ _proto.setMaterial = function setMaterial(material, destroy) {
5188
- if (destroy !== exports.DestroyOptions.keep) {
5189
- this.material.dispose(destroy);
5190
- }
5191
- this.material = material;
5175
+ * 通过旋转轴与旋转弧度创建矩阵
5176
+ * @param axis - 旋转轴
5177
+ * @param angle - 旋转弧度
5178
+ * @returns
5179
+ */ Matrix4.fromRotationAxis = function fromRotationAxis(axis, angle) {
5180
+ return new Matrix4().setFromRotationAxis(axis, angle);
5192
5181
  };
5193
- _proto.getBoundingBox = function getBoundingBox() {
5194
- var worldMatrix = this.transform.getWorldMatrix();
5195
- if (this.hitTestGeometry !== this.geometry) {
5196
- this.triangles = geometryToTriangles(this.geometry);
5197
- this.hitTestGeometry = this.geometry;
5198
- }
5199
- var area = [];
5200
- for(var _iterator = _create_for_of_iterator_helper_loose(this.triangles), _step; !(_step = _iterator()).done;){
5201
- var triangle = _step.value;
5202
- area.push({
5203
- p0: triangle.p0,
5204
- p1: triangle.p1,
5205
- p2: triangle.p2
5206
- });
5207
- }
5208
- area.forEach(function(triangle) {
5209
- triangle.p0 = worldMatrix.transformPoint(triangle.p0, new Vector3());
5210
- triangle.p1 = worldMatrix.transformPoint(triangle.p1, new Vector3());
5211
- triangle.p2 = worldMatrix.transformPoint(triangle.p2, new Vector3());
5212
- });
5213
- return {
5214
- type: exports.HitTestType.triangle,
5215
- area: area
5216
- };
5182
+ /**
5183
+ * 通过欧拉角创建矩阵
5184
+ * @param euler - 欧拉角
5185
+ * @returns
5186
+ */ Matrix4.fromEuler = function fromEuler(euler) {
5187
+ return new Matrix4().setFromEuler(euler);
5217
5188
  };
5218
- _proto.fromData = function fromData(data) {
5219
- RendererComponent.prototype.fromData.call(this, data);
5220
- this.material = this.materials[0];
5189
+ /**
5190
+ * 通过四元数创建矩阵
5191
+ * @param quat - 四元数
5192
+ * @returns
5193
+ */ Matrix4.fromQuaternion = function fromQuaternion(quat) {
5194
+ return new Matrix4().setFromQuaternion(quat);
5221
5195
  };
5222
- _proto.toData = function toData() {
5223
- this.taggedProperties.id = this.guid;
5196
+ /**
5197
+ * 通过倾斜创建矩阵
5198
+ * @param x - x 方向倾斜分量
5199
+ * @param y - y 方向倾斜分量
5200
+ * @param z - z 方向倾斜分量
5201
+ * @returns 倾斜矩阵
5202
+ */ Matrix4.fromShear = function fromShear(x, y, z) {
5203
+ return new Matrix4().setFromShear(x, y, z);
5224
5204
  };
5225
5205
  /**
5226
- * 销毁当前资源
5227
- * @param options - 可选的销毁选项
5228
- */ _proto.dispose = function dispose(options) {
5229
- if (this.destroyed) {
5230
- return;
5231
- }
5232
- this.destroyed = true;
5233
- RendererComponent.prototype.dispose.call(this);
5206
+ * 通过基轴创建矩阵
5207
+ * @param xAxis - x 轴
5208
+ * @param yAxis - y
5209
+ * @param zAxis - z 轴
5210
+ * @returns
5211
+ */ Matrix4.fromBasis = function fromBasis(xAxis, yAxis, zAxis) {
5212
+ return new Matrix4().setFromBasis(xAxis, yAxis, zAxis);
5234
5213
  };
5235
- return EffectComponent;
5236
- }(RendererComponent);
5237
- __decorate([
5238
- serialize()
5239
- ], exports.EffectComponent.prototype, "geometry", void 0);
5240
- exports.EffectComponent = __decorate([
5241
- effectsClass(DataType.EffectComponent)
5242
- ], exports.EffectComponent);
5243
- function geometryToTriangles(geometry) {
5244
- var _geometry_getIndexData;
5245
- var indices = (_geometry_getIndexData = geometry.getIndexData()) != null ? _geometry_getIndexData : [];
5246
- var _geometry_getAttributeData;
5247
- var vertices = (_geometry_getAttributeData = geometry.getAttributeData("aPos")) != null ? _geometry_getAttributeData : [];
5248
- var res = [];
5249
- for(var i = 0; i < indices.length; i += 3){
5250
- var index0 = indices[i] * 3;
5251
- var index1 = indices[i + 1] * 3;
5252
- var index2 = indices[i + 2] * 3;
5253
- var p0 = {
5254
- x: vertices[index0],
5255
- y: vertices[index0 + 1],
5256
- z: vertices[index0 + 2]
5257
- };
5258
- var p1 = {
5259
- x: vertices[index1],
5260
- y: vertices[index1 + 1],
5261
- z: vertices[index1 + 2]
5262
- };
5263
- var p2 = {
5264
- x: vertices[index2],
5265
- y: vertices[index2 + 1],
5266
- z: vertices[index2 + 2]
5267
- };
5268
- res.push({
5269
- p0: p0,
5270
- p1: p1,
5271
- p2: p2
5272
- });
5273
- }
5274
- return res;
5214
+ /**
5215
+ * 通过行优先数据设置矩阵
5216
+ * @param m11 - 第 1 行,第 1 列
5217
+ * @param m12 - 第 1 行,第 2 列
5218
+ * @param m13 - 第 1 行,第 3 列
5219
+ * @param m14 - 第 1 行,第 4 列
5220
+ * @param m21 - 第 2 行,第 1 列
5221
+ * @param m22 - 第 2 行,第 2 列
5222
+ * @param m23 - 第 2 行,第 3 列
5223
+ * @param m24 - 第 2 行,第 4 列
5224
+ * @param m31 - 3 行,第 1
5225
+ * @param m32 - 第 3 行,第 2 列
5226
+ * @param m33 - 3 行,第 3
5227
+ * @param m34 - 第 3 行,第 4 列
5228
+ * @param m41 - 4 行,第 1
5229
+ * @param m42 - 4 行,第 2 列
5230
+ * @param m43 - 4 行,第 3
5231
+ * @param m44 - 4 行,第 4 列
5232
+ * @returns
5233
+ */ Matrix4.fromRowMajorData = function fromRowMajorData(m11, m12, m13, m14, m21, m22, m23, m24, m31, m32, m33, m34, m41, m42, m43, m44) {
5234
+ return new Matrix4(m11, m21, m31, m41, m12, m22, m32, m42, m13, m23, m33, m43, m14, m24, m34, m44);
5235
+ };
5236
+ return Matrix4;
5237
+ }();
5238
+ Matrix4.IDENTITY = new Matrix4(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
5239
+ Matrix4.ZERO = new Matrix4(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
5240
+ Matrix4.tempVec0 = new Vector3();
5241
+ Matrix4.tempVec1 = new Vector3();
5242
+ Matrix4.tempVec2 = new Vector3();
5243
+ Matrix4.tempMat0 = new Matrix4();
5244
+
5245
+ function _array_like_to_array(arr, len) {
5246
+ if (len == null || len > arr.length) len = arr.length;
5247
+ for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
5248
+ return arr2;
5275
5249
  }
5276
5250
 
5277
- exports.PostProcessVolume = /*#__PURE__*/ function(Behaviour) {
5278
- _inherits(PostProcessVolume, Behaviour);
5279
- function PostProcessVolume() {
5280
- var _this;
5281
- _this = Behaviour.apply(this, arguments) || this;
5282
- // Bloom
5283
- _this.bloomEnabled = true;
5284
- _this.threshold = 1.0;
5285
- _this.bloomIntensity = 1.0;
5286
- // ColorAdjustments
5287
- _this.brightness = 1.0;
5288
- _this.saturation = 1.0;
5289
- _this.contrast = 1.0;
5290
- // Vignette
5291
- _this.vignetteIntensity = 0.2;
5292
- _this.vignetteSmoothness = 0.4;
5293
- _this.vignetteRoundness = 1.0;
5294
- // ToneMapping
5295
- _this.toneMappingEnabled = true // 1: true, 0: false
5296
- ;
5297
- return _this;
5298
- }
5299
- var _proto = PostProcessVolume.prototype;
5300
- _proto.onStart = function onStart() {
5301
- var composition = this.item.composition;
5302
- if (composition) {
5303
- composition.renderFrame.globalVolume = this;
5304
- }
5305
- };
5306
- return PostProcessVolume;
5307
- }(Behaviour);
5308
- __decorate([
5309
- serialize()
5310
- ], exports.PostProcessVolume.prototype, "bloomEnabled", void 0);
5311
- __decorate([
5312
- serialize()
5313
- ], exports.PostProcessVolume.prototype, "threshold", void 0);
5314
- __decorate([
5315
- serialize()
5316
- ], exports.PostProcessVolume.prototype, "bloomIntensity", void 0);
5317
- __decorate([
5318
- serialize()
5319
- ], exports.PostProcessVolume.prototype, "brightness", void 0);
5320
- __decorate([
5321
- serialize()
5322
- ], exports.PostProcessVolume.prototype, "saturation", void 0);
5323
- __decorate([
5324
- serialize()
5325
- ], exports.PostProcessVolume.prototype, "contrast", void 0);
5326
- __decorate([
5327
- serialize()
5328
- ], exports.PostProcessVolume.prototype, "vignetteIntensity", void 0);
5329
- __decorate([
5330
- serialize()
5331
- ], exports.PostProcessVolume.prototype, "vignetteSmoothness", void 0);
5332
- __decorate([
5333
- serialize()
5334
- ], exports.PostProcessVolume.prototype, "vignetteRoundness", void 0);
5335
- __decorate([
5336
- serialize()
5337
- ], exports.PostProcessVolume.prototype, "toneMappingEnabled", void 0);
5338
- exports.PostProcessVolume = __decorate([
5339
- effectsClass("PostProcessVolume")
5340
- ], exports.PostProcessVolume);
5251
+ function _unsupported_iterable_to_array(o, minLen) {
5252
+ if (!o) return;
5253
+ if (typeof o === "string") return _array_like_to_array(o, minLen);
5254
+ var n = Object.prototype.toString.call(o).slice(8, -1);
5255
+ if (n === "Object" && o.constructor) n = o.constructor.name;
5256
+ if (n === "Map" || n === "Set") return Array.from(n);
5257
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
5258
+ }
5341
5259
 
5342
- function _assert_this_initialized(self) {
5343
- if (self === void 0) throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
5344
- return self;
5260
+ function _create_for_of_iterator_helper_loose(o, allowArrayLike) {
5261
+ var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
5262
+ if (it) return (it = it.call(o)).next.bind(it);
5263
+ // Fallback for engines without symbol support
5264
+ if (Array.isArray(o) || (it = _unsupported_iterable_to_array(o)) || allowArrayLike && o && typeof o.length === "number") {
5265
+ if (it) o = it;
5266
+ var i = 0;
5267
+ return function() {
5268
+ if (i >= o.length) return {
5269
+ done: true
5270
+ };
5271
+ return {
5272
+ done: false,
5273
+ value: o[i++]
5274
+ };
5275
+ };
5276
+ }
5277
+ throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
5345
5278
  }
5346
5279
 
5347
5280
  exports.ShaderCompileResultStatus = void 0;
@@ -15517,14 +15450,14 @@ var GraphicsPath = /*#__PURE__*/ function() {
15517
15450
  return GraphicsPath;
15518
15451
  }();
15519
15452
 
15520
- exports.ShapeComponent = /*#__PURE__*/ function(RendererComponent) {
15521
- _inherits(ShapeComponent, RendererComponent);
15453
+ exports.ShapeComponent = /*#__PURE__*/ function(MeshComponent) {
15454
+ _inherits(ShapeComponent, MeshComponent);
15522
15455
  function ShapeComponent(engine) {
15523
15456
  var _this;
15524
- _this = RendererComponent.call(this, engine) || this;
15457
+ _this = MeshComponent.call(this, engine) || this;
15525
15458
  _this.path = new GraphicsPath();
15526
15459
  _this.curveValues = [];
15527
- _this.animated = false;
15460
+ _this.animated = true;
15528
15461
  _this.vert = "\nprecision highp float;\n\nattribute vec3 aPos;//x y\n\nuniform mat4 effects_MatrixVP;\nuniform mat4 effects_MatrixInvV;\nuniform mat4 effects_ObjectToWorld;\n\nvoid main() {\n vec4 pos = vec4(aPos.xyz, 1.0);\n gl_Position = effects_MatrixVP * effects_ObjectToWorld * pos;\n}\n";
15529
15462
  _this.frag = "\nprecision highp float;\n\nuniform vec4 _Color;\n\nvoid main() {\n vec4 color = _Color;\n gl_FragColor = color;\n}\n";
15530
15463
  if (!_this.geometry) {
@@ -15575,18 +15508,15 @@ exports.ShapeComponent = /*#__PURE__*/ function(RendererComponent) {
15575
15508
  return _this;
15576
15509
  }
15577
15510
  var _proto = ShapeComponent.prototype;
15511
+ _proto.onStart = function onStart() {
15512
+ this.item.getHitTestParams = this.getHitTestParams;
15513
+ };
15578
15514
  _proto.onUpdate = function onUpdate(dt) {
15579
15515
  if (this.animated) {
15580
15516
  this.buildPath(this.data);
15581
15517
  this.buildGeometryFromPath(this.path.shapePath);
15582
15518
  }
15583
15519
  };
15584
- _proto.render = function render(renderer) {
15585
- if (renderer.renderingData.currentFrame.globalUniforms) {
15586
- renderer.setGlobalMatrix("effects_ObjectToWorld", this.transform.getWorldMatrix());
15587
- }
15588
- renderer.drawGeometry(this.geometry, this.material);
15589
- };
15590
15520
  _proto.buildGeometryFromPath = function buildGeometryFromPath(shapePath) {
15591
15521
  var shapePrimitives = shapePath.shapePrimitives;
15592
15522
  var vertices = [];
@@ -15683,12 +15613,11 @@ exports.ShapeComponent = /*#__PURE__*/ function(RendererComponent) {
15683
15613
  }
15684
15614
  };
15685
15615
  _proto.fromData = function fromData(data) {
15686
- RendererComponent.prototype.fromData.call(this, data);
15616
+ MeshComponent.prototype.fromData.call(this, data);
15687
15617
  this.data = data;
15688
- this.animated = true;
15689
15618
  };
15690
15619
  return ShapeComponent;
15691
- }(RendererComponent);
15620
+ }(MeshComponent);
15692
15621
  exports.ShapeComponent = __decorate([
15693
15622
  effectsClass("ShapeComponent")
15694
15623
  ], exports.ShapeComponent);
@@ -16340,6 +16269,76 @@ function shouldIgnoreBouncing(arg, mul) {
16340
16269
  return arg && Math.abs(arg.vx || 0) < threshold && Math.abs(arg.vy || 0) < threshold;
16341
16270
  }
16342
16271
 
16272
+ var MeshCollider = /*#__PURE__*/ function() {
16273
+ function MeshCollider() {
16274
+ this.triangles = [];
16275
+ }
16276
+ var _proto = MeshCollider.prototype;
16277
+ _proto.getBoundingBoxData = function getBoundingBoxData() {
16278
+ return this.boundingBoxData;
16279
+ };
16280
+ _proto.setGeometry = function setGeometry(geometry, worldMatrix) {
16281
+ if (this.geometry !== geometry) {
16282
+ this.triangles = this.geometryToTriangles(geometry);
16283
+ this.geometry = geometry;
16284
+ }
16285
+ var area = [];
16286
+ for(var _iterator = _create_for_of_iterator_helper_loose(this.triangles), _step; !(_step = _iterator()).done;){
16287
+ var triangle = _step.value;
16288
+ area.push({
16289
+ p0: triangle.p0,
16290
+ p1: triangle.p1,
16291
+ p2: triangle.p2
16292
+ });
16293
+ }
16294
+ if (worldMatrix) {
16295
+ area.forEach(function(triangle) {
16296
+ triangle.p0 = worldMatrix.transformPoint(triangle.p0, new Vector3());
16297
+ triangle.p1 = worldMatrix.transformPoint(triangle.p1, new Vector3());
16298
+ triangle.p2 = worldMatrix.transformPoint(triangle.p2, new Vector3());
16299
+ });
16300
+ }
16301
+ this.boundingBoxData = {
16302
+ type: exports.HitTestType.triangle,
16303
+ area: area
16304
+ };
16305
+ };
16306
+ _proto.geometryToTriangles = function geometryToTriangles(geometry) {
16307
+ var _geometry_getIndexData;
16308
+ var indices = (_geometry_getIndexData = geometry.getIndexData()) != null ? _geometry_getIndexData : [];
16309
+ var _geometry_getAttributeData;
16310
+ var vertices = (_geometry_getAttributeData = geometry.getAttributeData("aPos")) != null ? _geometry_getAttributeData : [];
16311
+ var res = [];
16312
+ for(var i = 0; i < indices.length; i += 3){
16313
+ var index0 = indices[i] * 3;
16314
+ var index1 = indices[i + 1] * 3;
16315
+ var index2 = indices[i + 2] * 3;
16316
+ var p0 = {
16317
+ x: vertices[index0],
16318
+ y: vertices[index0 + 1],
16319
+ z: vertices[index0 + 2]
16320
+ };
16321
+ var p1 = {
16322
+ x: vertices[index1],
16323
+ y: vertices[index1 + 1],
16324
+ z: vertices[index1 + 2]
16325
+ };
16326
+ var p2 = {
16327
+ x: vertices[index2],
16328
+ y: vertices[index2 + 1],
16329
+ z: vertices[index2 + 2]
16330
+ };
16331
+ res.push({
16332
+ p0: p0,
16333
+ p1: p1,
16334
+ p2: p2
16335
+ });
16336
+ }
16337
+ return res;
16338
+ };
16339
+ return MeshCollider;
16340
+ }();
16341
+
16343
16342
  exports.maxSpriteMeshItemCount = 8;
16344
16343
  function setSpriteMeshMaxItemCountByGPU(gpuCapability) {
16345
16344
  if (gpuCapability.maxVertexUniforms >= 256) {
@@ -30670,7 +30669,7 @@ registerPlugin("sprite", SpriteLoader, exports.VFXItem, true);
30670
30669
  registerPlugin("particle", ParticleLoader, exports.VFXItem, true);
30671
30670
  registerPlugin("cal", CalculateLoader, exports.VFXItem, true);
30672
30671
  registerPlugin("interact", InteractLoader, exports.VFXItem, true);
30673
- var version$1 = "2.1.0-alpha.8";
30672
+ var version$1 = "2.1.0-alpha.9";
30674
30673
  logger.info("Core version: " + version$1 + ".");
30675
30674
 
30676
30675
  var _obj;
@@ -32314,7 +32313,7 @@ setMaxSpriteMeshItemCount(8);
32314
32313
  */ Mesh.create = function(engine, props) {
32315
32314
  return new ThreeMesh(engine, props);
32316
32315
  };
32317
- var version = "2.1.0-alpha.8";
32316
+ var version = "2.1.0-alpha.9";
32318
32317
  logger.info("THREEJS plugin version: " + version + ".");
32319
32318
 
32320
32319
  exports.AbstractPlugin = AbstractPlugin;
@@ -32373,6 +32372,7 @@ exports.LinearValue = LinearValue;
32373
32372
  exports.Material = Material;
32374
32373
  exports.MaterialDataBlock = MaterialDataBlock;
32375
32374
  exports.Mesh = Mesh;
32375
+ exports.MeshCollider = MeshCollider;
32376
32376
  exports.PLAYER_OPTIONS_ENV_EDITOR = PLAYER_OPTIONS_ENV_EDITOR;
32377
32377
  exports.POST_PROCESS_SETTINGS = POST_PROCESS_SETTINGS;
32378
32378
  exports.ParticleBehaviourPlayable = ParticleBehaviourPlayable;