@galacean/effects-core 2.6.7 → 2.6.8

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 core for the web
4
4
  * Author: Ant Group CO., Ltd.
5
5
  * Contributors: 燃然,飂兮,十弦,云垣,茂安,意绮
6
- * Version: v2.6.7
6
+ * Version: v2.6.8
7
7
  */
8
8
 
9
9
  'use strict';
@@ -4145,6 +4145,1027 @@ var Blender = /*#__PURE__*/ function() {
4145
4145
  Blender.normalBlendFunction = new NormalBlend();
4146
4146
  Blender.additiveBlendFunction = new AdditiveBlend();
4147
4147
 
4148
+ /**
4149
+ * 四维向量
4150
+ */ var Vector4 = /*#__PURE__*/ function() {
4151
+ function Vector4(x, y, z, w) {
4152
+ if (x === void 0) x = 0;
4153
+ if (y === void 0) y = 0;
4154
+ if (z === void 0) z = 0;
4155
+ if (w === void 0) w = 0;
4156
+ this.x = x;
4157
+ this.y = y;
4158
+ this.z = z;
4159
+ this.w = w;
4160
+ }
4161
+ var _proto = Vector4.prototype;
4162
+ /**
4163
+ * 设置向量
4164
+ * @param x - x 轴分量
4165
+ * @param y - y 轴分量
4166
+ * @param z - z 轴分量
4167
+ * @param w - w 轴分量
4168
+ * @returns
4169
+ */ _proto.set = function set(x, y, z, w) {
4170
+ this.x = x;
4171
+ this.y = y;
4172
+ this.z = z;
4173
+ this.w = w;
4174
+ return this;
4175
+ };
4176
+ /**
4177
+ * 设置零向量
4178
+ * @returns 向量
4179
+ */ _proto.setZero = function setZero() {
4180
+ this.x = 0;
4181
+ this.y = 0;
4182
+ this.z = 0;
4183
+ this.w = 0;
4184
+ return this;
4185
+ };
4186
+ /**
4187
+ * 通过标量数值设置向量
4188
+ * @param num - 数值
4189
+ * @returns 向量
4190
+ */ _proto.setFromNumber = function setFromNumber(num) {
4191
+ this.x = num;
4192
+ this.y = num;
4193
+ this.z = num;
4194
+ this.w = num;
4195
+ return this;
4196
+ };
4197
+ /**
4198
+ * 通过数组创建向量
4199
+ * @param array - 数组
4200
+ * @param [offset=0] - 起始偏移值
4201
+ * @returns 向量
4202
+ */ _proto.setFromArray = function setFromArray(array, offset) {
4203
+ if (offset === void 0) offset = 0;
4204
+ var _array_offset;
4205
+ this.x = (_array_offset = array[offset]) != null ? _array_offset : 0;
4206
+ var _array_;
4207
+ this.y = (_array_ = array[offset + 1]) != null ? _array_ : 0;
4208
+ var _array_1;
4209
+ this.z = (_array_1 = array[offset + 2]) != null ? _array_1 : 0;
4210
+ var _array_2;
4211
+ this.w = (_array_2 = array[offset + 3]) != null ? _array_2 : 0;
4212
+ return this;
4213
+ };
4214
+ /**
4215
+ * 拷贝向量
4216
+ * @param v - 复制对象
4217
+ * @returns 拷贝结果
4218
+ */ _proto.copyFrom = function copyFrom(v) {
4219
+ this.x = v.x;
4220
+ this.y = v.y;
4221
+ this.z = v.z;
4222
+ this.w = v.w;
4223
+ return this;
4224
+ };
4225
+ /**
4226
+ * 克隆向量
4227
+ * @returns 克隆结果
4228
+ */ _proto.clone = function clone() {
4229
+ return new Vector4(this.x, this.y, this.z, this.w);
4230
+ };
4231
+ /**
4232
+ * 根据下标设置向量分量
4233
+ * @param index - 下标值
4234
+ * @param value - 分量值
4235
+ * @returns 向量
4236
+ */ _proto.setElement = function setElement(index, value) {
4237
+ switch(index){
4238
+ case 0:
4239
+ this.x = value;
4240
+ break;
4241
+ case 1:
4242
+ this.y = value;
4243
+ break;
4244
+ case 2:
4245
+ this.z = value;
4246
+ break;
4247
+ case 3:
4248
+ this.w = value;
4249
+ break;
4250
+ default:
4251
+ console.error("index is out of range: " + index);
4252
+ }
4253
+ return this;
4254
+ };
4255
+ /**
4256
+ * 根据下标获取向量分量
4257
+ * @param index - 下标
4258
+ * @returns 分量值
4259
+ */ _proto.getElement = function getElement(index) {
4260
+ switch(index){
4261
+ case 0:
4262
+ return this.x;
4263
+ case 1:
4264
+ return this.y;
4265
+ case 2:
4266
+ return this.z;
4267
+ case 3:
4268
+ return this.w;
4269
+ default:
4270
+ console.error("index is out of range: " + index);
4271
+ }
4272
+ return 0;
4273
+ };
4274
+ /**
4275
+ * 向量相加
4276
+ * @param right - 相加对象,向量 | 数字
4277
+ * @returns 相加结果
4278
+ */ _proto.add = function add(right) {
4279
+ if (typeof right === "number") {
4280
+ this.x += right;
4281
+ this.y += right;
4282
+ this.z += right;
4283
+ this.w += right;
4284
+ } else if (_instanceof1(right, Array)) {
4285
+ this.x += right[0];
4286
+ this.y += right[1];
4287
+ this.z += right[2];
4288
+ this.w += right[3];
4289
+ } else {
4290
+ this.x += right.x;
4291
+ this.y += right.y;
4292
+ this.z += right.z;
4293
+ this.w += right.w;
4294
+ }
4295
+ return this;
4296
+ };
4297
+ /**
4298
+ * 向量相加
4299
+ * @param left - 向量
4300
+ * @param right - 向量
4301
+ * @returns 求和结果
4302
+ */ _proto.addVectors = function addVectors(left, right) {
4303
+ this.x = left.x + right.x;
4304
+ this.y = left.y + right.y;
4305
+ this.z = left.z + right.z;
4306
+ this.w = left.w + right.w;
4307
+ return this;
4308
+ };
4309
+ /**
4310
+ * 向量比例缩放后相加
4311
+ * @param right - 向量
4312
+ * @param s - 比例
4313
+ * @returns 求和结果
4314
+ */ _proto.addScaledVector = function addScaledVector(right, s) {
4315
+ this.x += right.x * s;
4316
+ this.y += right.y * s;
4317
+ this.z += right.z * s;
4318
+ this.w += right.w * s;
4319
+ return this;
4320
+ };
4321
+ /**
4322
+ * 向量相减
4323
+ * @param right - 相减对象,向量 | 数字
4324
+ * @returns 相减结果
4325
+ */ _proto.subtract = function subtract(right) {
4326
+ if (typeof right === "number") {
4327
+ this.x -= right;
4328
+ this.y -= right;
4329
+ this.z -= right;
4330
+ this.w -= right;
4331
+ } else if (_instanceof1(right, Array)) {
4332
+ this.x -= right[0];
4333
+ this.y -= right[1];
4334
+ this.z -= right[2];
4335
+ this.w -= right[3];
4336
+ } else {
4337
+ this.x -= right.x;
4338
+ this.y -= right.y;
4339
+ this.z -= right.z;
4340
+ this.w -= right.w;
4341
+ }
4342
+ return this;
4343
+ };
4344
+ /**
4345
+ * 向量相减
4346
+ * @param left - 向量
4347
+ * @param right - 向量
4348
+ * @returns 向量
4349
+ */ _proto.subtractVectors = function subtractVectors(left, right) {
4350
+ this.x = left.x - right.x;
4351
+ this.y = left.y - right.y;
4352
+ this.z = left.z - right.z;
4353
+ this.w = left.w - right.w;
4354
+ return this;
4355
+ };
4356
+ /**
4357
+ * 向量相乘
4358
+ * @param right - 相乘对象,对象 | 数字
4359
+ * @returns 向量
4360
+ */ _proto.multiply = function multiply(right) {
4361
+ if (typeof right === "number") {
4362
+ this.x *= right;
4363
+ this.y *= right;
4364
+ this.z *= right;
4365
+ this.w *= right;
4366
+ } else if (_instanceof1(right, Array)) {
4367
+ this.x *= right[0];
4368
+ this.y *= right[1];
4369
+ this.z *= right[2];
4370
+ this.w *= right[3];
4371
+ } else {
4372
+ this.x *= right.x;
4373
+ this.y *= right.y;
4374
+ this.z *= right.z;
4375
+ this.w *= right.w;
4376
+ }
4377
+ return this;
4378
+ };
4379
+ /**
4380
+ * 向量相乘
4381
+ * @param left - 向量
4382
+ * @param right - 向量
4383
+ * @returns 向量
4384
+ */ _proto.multiplyVectors = function multiplyVectors(left, right) {
4385
+ this.x = left.x * right.x;
4386
+ this.y = left.y * right.y;
4387
+ this.z = left.z * right.z;
4388
+ this.w = left.w * right.w;
4389
+ return this;
4390
+ };
4391
+ /**
4392
+ * 向量相除
4393
+ * @param right - 相除对象,对象 | 数字
4394
+ * @returns 向量
4395
+ */ _proto.divide = function divide(right) {
4396
+ if (typeof right === "number") {
4397
+ this.x /= right;
4398
+ this.y /= right;
4399
+ this.z /= right;
4400
+ this.w /= right;
4401
+ } else if (_instanceof1(right, Array)) {
4402
+ this.x /= right[0];
4403
+ this.y /= right[1];
4404
+ this.z /= right[2];
4405
+ this.w /= right[3];
4406
+ } else {
4407
+ this.x /= right.x;
4408
+ this.y /= right.y;
4409
+ this.z /= right.z;
4410
+ this.w /= right.w;
4411
+ }
4412
+ return this;
4413
+ };
4414
+ /**
4415
+ * 向量缩放
4416
+ * @param v - 数字
4417
+ * @returns 缩放结果
4418
+ */ _proto.scale = function scale(v) {
4419
+ this.x *= v;
4420
+ this.y *= v;
4421
+ this.z *= v;
4422
+ this.w *= v;
4423
+ return this;
4424
+ };
4425
+ /**
4426
+ * 分量求和
4427
+ * @returns 求和结果
4428
+ */ _proto.sum = function sum() {
4429
+ return this.x + this.y + this.z + this.w;
4430
+ };
4431
+ /**
4432
+ * 向量求最小值
4433
+ * @param v - 向量或数值
4434
+ * @returns 最小值
4435
+ */ _proto.min = function min(v) {
4436
+ if (typeof v === "number") {
4437
+ this.x = Math.min(this.x, v);
4438
+ this.y = Math.min(this.y, v);
4439
+ this.z = Math.min(this.z, v);
4440
+ this.w = Math.min(this.w, v);
4441
+ } else {
4442
+ this.x = Math.min(this.x, v.x);
4443
+ this.y = Math.min(this.y, v.y);
4444
+ this.z = Math.min(this.z, v.z);
4445
+ this.w = Math.min(this.w, v.w);
4446
+ }
4447
+ return this;
4448
+ };
4449
+ /**
4450
+ * 向量求最大值
4451
+ * @param v - 向量或数值
4452
+ * @returns 最大值
4453
+ */ _proto.max = function max(v) {
4454
+ if (typeof v === "number") {
4455
+ this.x = Math.max(this.x, v);
4456
+ this.y = Math.max(this.y, v);
4457
+ this.z = Math.max(this.z, v);
4458
+ this.w = Math.max(this.w, v);
4459
+ } else {
4460
+ this.x = Math.max(this.x, v.x);
4461
+ this.y = Math.max(this.y, v.y);
4462
+ this.z = Math.max(this.z, v.z);
4463
+ this.w = Math.max(this.w, v.w);
4464
+ }
4465
+ return this;
4466
+ };
4467
+ /**
4468
+ * 向量阈值约束
4469
+ * @param min - 最小值
4470
+ * @param max - 最大值
4471
+ * @returns 向量
4472
+ */ _proto.clamp = function clamp(min, max) {
4473
+ return this.max(min).min(max);
4474
+ };
4475
+ /**
4476
+ * 向量向下取整
4477
+ * @returns 取整结果
4478
+ */ _proto.floor = function floor() {
4479
+ this.x = Math.floor(this.x);
4480
+ this.y = Math.floor(this.y);
4481
+ this.z = Math.floor(this.z);
4482
+ this.w = Math.floor(this.w);
4483
+ return this;
4484
+ };
4485
+ /**
4486
+ * 向量向上取整
4487
+ * @returns 取整结果
4488
+ */ _proto.ceil = function ceil() {
4489
+ this.x = Math.ceil(this.x);
4490
+ this.y = Math.ceil(this.y);
4491
+ this.z = Math.ceil(this.z);
4492
+ this.w = Math.ceil(this.w);
4493
+ return this;
4494
+ };
4495
+ /**
4496
+ * 向量四舍五入
4497
+ * @returns 求值结果
4498
+ */ _proto.round = function round() {
4499
+ this.x = Math.round(this.x);
4500
+ this.y = Math.round(this.y);
4501
+ this.z = Math.round(this.z);
4502
+ this.w = Math.round(this.w);
4503
+ return this;
4504
+ };
4505
+ /**
4506
+ * 向量取绝对值
4507
+ * @returns 向量
4508
+ */ _proto.abs = function abs() {
4509
+ this.x = Math.abs(this.x);
4510
+ this.y = Math.abs(this.y);
4511
+ this.z = Math.abs(this.z);
4512
+ this.w = Math.abs(this.w);
4513
+ return this;
4514
+ };
4515
+ /**
4516
+ * 向量取反
4517
+ * @returns 取反结果
4518
+ */ _proto.negate = function negate() {
4519
+ this.x = -this.x;
4520
+ this.y = -this.y;
4521
+ this.z = -this.z;
4522
+ this.w = -this.w;
4523
+ return this;
4524
+ };
4525
+ /**
4526
+ * 向量长度平方
4527
+ * @returns 长度平方
4528
+ */ _proto.lengthSquared = function lengthSquared() {
4529
+ return this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w;
4530
+ };
4531
+ /**
4532
+ * 向量长度
4533
+ * @returns 长度
4534
+ */ _proto.length = function length() {
4535
+ return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w);
4536
+ };
4537
+ /**
4538
+ * 向量归一化
4539
+ * @returns 归一化结果
4540
+ */ _proto.normalize = function normalize() {
4541
+ return this.divide(this.length() || 1);
4542
+ };
4543
+ /**
4544
+ * 设置向量长度
4545
+ * @param length - 长度
4546
+ * @returns 向量
4547
+ */ _proto.setLength = function setLength(length) {
4548
+ return this.normalize().multiply(length);
4549
+ };
4550
+ /**
4551
+ * 向量求线性插值
4552
+ * @param v - 向量
4553
+ * @param alpha - 插值比例
4554
+ * @returns 插值结果
4555
+ */ _proto.lerp = function lerp(v, alpha) {
4556
+ this.x += (v.x - this.x) * alpha;
4557
+ this.y += (v.y - this.y) * alpha;
4558
+ this.z += (v.z - this.z) * alpha;
4559
+ this.w += (v.w - this.w) * alpha;
4560
+ return this;
4561
+ };
4562
+ /**
4563
+ * 两向量求线性插值
4564
+ * @param v1 - 第一个向量
4565
+ * @param v2 - 第二个向量
4566
+ * @param alpha - 插值比例
4567
+ * @returns 插值结果
4568
+ */ _proto.lerpVectors = function lerpVectors(v1, v2, alpha) {
4569
+ this.x = v1.x + (v2.x - v1.x) * alpha;
4570
+ this.y = v1.y + (v2.y - v1.y) * alpha;
4571
+ this.z = v1.z + (v2.z - v1.z) * alpha;
4572
+ this.w = v1.w + (v2.w - v1.w) * alpha;
4573
+ return this;
4574
+ };
4575
+ /**
4576
+ * 向量求点积
4577
+ * @param v - 向量
4578
+ * @returns 点积结果
4579
+ */ _proto.dot = function dot(v) {
4580
+ return this.x * v.x + this.y * v.y + this.z * v.z + this.w * v.w;
4581
+ };
4582
+ /**
4583
+ * 向量判等
4584
+ * @param v - 向量
4585
+ * @returns 判等结果
4586
+ */ _proto.equals = function equals(v) {
4587
+ return v.x === this.x && v.y === this.y && v.z === this.z && v.w === this.w;
4588
+ };
4589
+ /**
4590
+ * 是否零向量
4591
+ * @returns 是否零向量
4592
+ */ _proto.isZero = function isZero() {
4593
+ var eps = NumberEpsilon;
4594
+ var _this = this, x = _this.x, y = _this.y, z = _this.z, w = _this.w;
4595
+ return Math.abs(x) <= eps && Math.abs(y) <= eps && Math.abs(z) <= eps && Math.abs(w) <= eps;
4596
+ };
4597
+ /**
4598
+ * 向量转数组
4599
+ * @returns 数组
4600
+ */ _proto.toArray = function toArray() {
4601
+ return [
4602
+ this.x,
4603
+ this.y,
4604
+ this.z,
4605
+ this.w
4606
+ ];
4607
+ };
4608
+ _proto.toVector3 = function toVector3() {
4609
+ return new Vector3(this.x, this.y, this.z);
4610
+ };
4611
+ _proto.fill = function fill(array, offset) {
4612
+ if (offset === void 0) offset = 0;
4613
+ array[offset] = this.x;
4614
+ array[offset + 1] = this.y;
4615
+ array[offset + 2] = this.z;
4616
+ array[offset + 3] = this.w;
4617
+ };
4618
+ /**
4619
+ * 生成随机向量
4620
+ * @returns 向量
4621
+ */ _proto.random = function random() {
4622
+ this.x = Math.random();
4623
+ this.y = Math.random();
4624
+ this.z = Math.random();
4625
+ this.w = Math.random();
4626
+ return this;
4627
+ };
4628
+ /**
4629
+ * 变换矩阵作用于向量
4630
+ * @param m - 变换矩阵
4631
+ * @param [out] - 输出结果,如果没有设置就直接覆盖当前值
4632
+ * @returns 向量
4633
+ */ _proto.applyMatrix = function applyMatrix(m, out) {
4634
+ return m.transformVector4(this, out);
4635
+ };
4636
+ /**
4637
+ * 通过标量数值创建向量
4638
+ * @param num - 数值
4639
+ * @returns 向量
4640
+ */ Vector4.fromNumber = function fromNumber(num) {
4641
+ return new Vector4().setFromNumber(num);
4642
+ };
4643
+ /**
4644
+ * 通过数组创建向量
4645
+ * @param array - 数组
4646
+ * @param [offset=0] - 起始偏移值
4647
+ * @returns 向量
4648
+ */ Vector4.fromArray = function fromArray(array, offset) {
4649
+ if (offset === void 0) offset = 0;
4650
+ return new Vector4().setFromArray(array, offset);
4651
+ };
4652
+ return Vector4;
4653
+ }();
4654
+ /**
4655
+ * 四维向量的常量
4656
+ */ Vector4.ONE = new Vector4(1.0, 1.0, 1.0, 1.0);
4657
+ Vector4.ZERO = new Vector4(0.0, 0.0, 0.0, 0.0);
4658
+
4659
+ var Color = /*#__PURE__*/ function() {
4660
+ function Color(r, g, b, a) {
4661
+ if (r === void 0) r = 0;
4662
+ if (g === void 0) g = 0;
4663
+ if (b === void 0) b = 0;
4664
+ if (a === void 0) a = 0;
4665
+ this.r = r;
4666
+ this.g = g;
4667
+ this.b = b;
4668
+ this.a = a;
4669
+ }
4670
+ var _proto = Color.prototype;
4671
+ /**
4672
+ * 设置颜色
4673
+ * @param r - r 分量
4674
+ * @param g - g 分量
4675
+ * @param b - b 分量
4676
+ * @param a - a 分量
4677
+ * @returns
4678
+ */ _proto.set = function set(r, g, b, a) {
4679
+ this.r = r;
4680
+ this.g = g;
4681
+ this.b = b;
4682
+ this.a = a;
4683
+ return this;
4684
+ };
4685
+ /**
4686
+ * 设置零颜色
4687
+ * @returns
4688
+ */ _proto.setZero = function setZero() {
4689
+ this.r = 0;
4690
+ this.g = 0;
4691
+ this.b = 0;
4692
+ this.a = 0;
4693
+ return this;
4694
+ };
4695
+ /**
4696
+ * 通过标量数值设置颜色
4697
+ * @param num - 数值
4698
+ * @returns
4699
+ */ _proto.setFromNumber = function setFromNumber(num) {
4700
+ this.r = num;
4701
+ this.g = num;
4702
+ this.b = num;
4703
+ this.a = num;
4704
+ return this;
4705
+ };
4706
+ /**
4707
+ * 通过Vector4创建颜色
4708
+ * @param v - Vector4
4709
+ * @returns
4710
+ */ _proto.setFromVector4 = function setFromVector4(v) {
4711
+ this.r = v.x;
4712
+ this.g = v.y;
4713
+ this.b = v.z;
4714
+ this.a = v.w;
4715
+ return this;
4716
+ };
4717
+ /**
4718
+ * 通过数组创建颜色
4719
+ * @param array - 数组
4720
+ * @param [offset=0] - 起始偏移值
4721
+ * @returns
4722
+ */ _proto.setFromArray = function setFromArray(array, offset) {
4723
+ if (offset === void 0) offset = 0;
4724
+ var _array_offset;
4725
+ this.r = (_array_offset = array[offset]) != null ? _array_offset : 0;
4726
+ var _array_;
4727
+ this.g = (_array_ = array[offset + 1]) != null ? _array_ : 0;
4728
+ var _array_1;
4729
+ this.b = (_array_1 = array[offset + 2]) != null ? _array_1 : 0;
4730
+ var _array_2;
4731
+ this.a = (_array_2 = array[offset + 3]) != null ? _array_2 : 0;
4732
+ return this;
4733
+ };
4734
+ _proto.setFromHSV = function setFromHSV(hue, saturation, value, alpha) {
4735
+ if (alpha === void 0) alpha = 1;
4736
+ var chroma = value * saturation;
4737
+ var h = hue / 60;
4738
+ var x = chroma * (1 - Math.abs(h % 2 - 1));
4739
+ var r = 0;
4740
+ var g = 0;
4741
+ var b = 0;
4742
+ if (h >= 0 && h <= 1) {
4743
+ r = chroma;
4744
+ g = x;
4745
+ } else if (h >= 1 && h <= 2) {
4746
+ r = x;
4747
+ g = chroma;
4748
+ } else if (h >= 2 && h <= 3) {
4749
+ g = chroma;
4750
+ b = x;
4751
+ } else if (h >= 3 && h <= 4) {
4752
+ g = x;
4753
+ b = chroma;
4754
+ } else if (h >= 4 && h <= 5) {
4755
+ r = x;
4756
+ b = chroma;
4757
+ } else if (h >= 5 && h <= 6) {
4758
+ r = chroma;
4759
+ b = x;
4760
+ }
4761
+ var m = value - chroma;
4762
+ return this.set(r + m, g + m, b + m, alpha);
4763
+ };
4764
+ _proto.setFromHexString = function setFromHexString(hex) {
4765
+ if (hex.substring(0, 1) !== "#" || hex.length !== 9 && hex.length !== 7) {
4766
+ return this;
4767
+ }
4768
+ var r = parseInt(hex.substring(1, 3), 16) / 255.0;
4769
+ var g = parseInt(hex.substring(3, 5), 16) / 255.0;
4770
+ var b = parseInt(hex.substring(5, 7), 16) / 255.0;
4771
+ var a = hex.length === 9 ? parseInt(hex.substring(7, 9), 16) / 255.0 : 1.0;
4772
+ return this.set(r, g, b, a);
4773
+ };
4774
+ /**
4775
+ * 拷贝颜色
4776
+ * @param v - 复制对象
4777
+ * @returns 拷贝结果
4778
+ */ _proto.copyFrom = function copyFrom(v) {
4779
+ this.r = v.r;
4780
+ this.g = v.g;
4781
+ this.b = v.b;
4782
+ this.a = v.a;
4783
+ return this;
4784
+ };
4785
+ /**
4786
+ * 克隆颜色
4787
+ * @returns 克隆结果
4788
+ */ _proto.clone = function clone() {
4789
+ return new Color(this.r, this.g, this.b, this.a);
4790
+ };
4791
+ /**
4792
+ * 根据下标设置颜色分量
4793
+ * @param index - 下标值
4794
+ * @param value - 分量值
4795
+ * @returns
4796
+ */ _proto.setElement = function setElement(index, value) {
4797
+ switch(index){
4798
+ case 0:
4799
+ this.r = value;
4800
+ break;
4801
+ case 1:
4802
+ this.g = value;
4803
+ break;
4804
+ case 2:
4805
+ this.b = value;
4806
+ break;
4807
+ case 3:
4808
+ this.a = value;
4809
+ break;
4810
+ default:
4811
+ console.error("index is out of range: " + index);
4812
+ }
4813
+ return this;
4814
+ };
4815
+ /**
4816
+ * 根据下标获取颜色分量
4817
+ * @param index - 下标
4818
+ * @returns 分量值
4819
+ */ _proto.getElement = function getElement(index) {
4820
+ switch(index){
4821
+ case 0:
4822
+ return this.r;
4823
+ case 1:
4824
+ return this.g;
4825
+ case 2:
4826
+ return this.b;
4827
+ case 3:
4828
+ return this.a;
4829
+ default:
4830
+ console.error("index is out of range: " + index);
4831
+ }
4832
+ return 0;
4833
+ };
4834
+ /**
4835
+ * 颜色相加
4836
+ * @param right - 相加对象,颜色 | 数字
4837
+ * @returns 相加结果
4838
+ */ _proto.add = function add(right) {
4839
+ if (typeof right === "number") {
4840
+ this.r += right;
4841
+ this.g += right;
4842
+ this.b += right;
4843
+ this.a += right;
4844
+ } else if (_instanceof1(right, Array)) {
4845
+ this.r += right[0];
4846
+ this.g += right[1];
4847
+ this.b += right[2];
4848
+ this.a += right[3];
4849
+ } else {
4850
+ this.r += right.r;
4851
+ this.g += right.g;
4852
+ this.b += right.b;
4853
+ this.a += right.a;
4854
+ }
4855
+ return this;
4856
+ };
4857
+ /**
4858
+ * 颜色相减
4859
+ * @param right - 相减对象,颜色 | 数字
4860
+ * @returns 相减结果
4861
+ */ _proto.subtract = function subtract(right) {
4862
+ if (typeof right === "number") {
4863
+ this.r -= right;
4864
+ this.g -= right;
4865
+ this.b -= right;
4866
+ this.a -= right;
4867
+ } else if (_instanceof1(right, Array)) {
4868
+ this.r -= right[0];
4869
+ this.g -= right[1];
4870
+ this.b -= right[2];
4871
+ this.a -= right[3];
4872
+ } else {
4873
+ this.r -= right.r;
4874
+ this.g -= right.g;
4875
+ this.b -= right.b;
4876
+ this.a -= right.a;
4877
+ }
4878
+ return this;
4879
+ };
4880
+ /**
4881
+ * 颜色相乘
4882
+ * @param right - 相乘对象,对象 | 数字
4883
+ * @returns 颜色
4884
+ */ _proto.multiply = function multiply(right) {
4885
+ if (typeof right === "number") {
4886
+ this.r *= right;
4887
+ this.g *= right;
4888
+ this.b *= right;
4889
+ this.a *= right;
4890
+ } else if (_instanceof1(right, Array)) {
4891
+ this.r *= right[0];
4892
+ this.g *= right[1];
4893
+ this.b *= right[2];
4894
+ this.a *= right[3];
4895
+ } else {
4896
+ this.r *= right.r;
4897
+ this.g *= right.g;
4898
+ this.b *= right.b;
4899
+ this.a *= right.a;
4900
+ }
4901
+ return this;
4902
+ };
4903
+ /**
4904
+ * 颜色相除
4905
+ * @param right - 相除对象,对象 | 数字
4906
+ * @returns 颜色
4907
+ */ _proto.divide = function divide(right) {
4908
+ if (typeof right === "number") {
4909
+ this.r /= right;
4910
+ this.g /= right;
4911
+ this.b /= right;
4912
+ this.a /= right;
4913
+ } else if (_instanceof1(right, Array)) {
4914
+ this.r /= right[0];
4915
+ this.g /= right[1];
4916
+ this.b /= right[2];
4917
+ this.a /= right[3];
4918
+ } else {
4919
+ this.r /= right.r;
4920
+ this.g /= right.g;
4921
+ this.b /= right.b;
4922
+ this.a /= right.a;
4923
+ }
4924
+ return this;
4925
+ };
4926
+ /**
4927
+ * 颜色缩放
4928
+ * @param v - 数字
4929
+ * @returns 缩放结果
4930
+ */ _proto.scale = function scale(v) {
4931
+ this.r *= v;
4932
+ this.g *= v;
4933
+ this.b *= v;
4934
+ this.a *= v;
4935
+ return this;
4936
+ };
4937
+ /**
4938
+ * 颜色求最小值
4939
+ * @param v - 颜色或数值
4940
+ * @returns 最小值
4941
+ */ _proto.min = function min(v) {
4942
+ if (typeof v === "number") {
4943
+ this.r = Math.min(this.r, v);
4944
+ this.g = Math.min(this.g, v);
4945
+ this.b = Math.min(this.b, v);
4946
+ this.a = Math.min(this.a, v);
4947
+ } else {
4948
+ this.r = Math.min(this.r, v.r);
4949
+ this.g = Math.min(this.g, v.g);
4950
+ this.b = Math.min(this.b, v.b);
4951
+ this.a = Math.min(this.a, v.a);
4952
+ }
4953
+ return this;
4954
+ };
4955
+ /**
4956
+ * 颜色求最大值
4957
+ * @param v - 颜色或数值
4958
+ * @returns 最大值
4959
+ */ _proto.max = function max(v) {
4960
+ if (typeof v === "number") {
4961
+ this.r = Math.max(this.r, v);
4962
+ this.g = Math.max(this.g, v);
4963
+ this.b = Math.max(this.b, v);
4964
+ this.a = Math.max(this.a, v);
4965
+ } else {
4966
+ this.r = Math.max(this.r, v.r);
4967
+ this.g = Math.max(this.g, v.g);
4968
+ this.b = Math.max(this.b, v.b);
4969
+ this.a = Math.max(this.a, v.a);
4970
+ }
4971
+ return this;
4972
+ };
4973
+ /**
4974
+ * 颜色阈值约束
4975
+ * @param min - 最小值
4976
+ * @param max - 最大值
4977
+ * @returns 颜色
4978
+ */ _proto.clamp = function clamp(min, max) {
4979
+ return this.max(min).min(max);
4980
+ };
4981
+ /**
4982
+ * 颜色求线性插值
4983
+ * @param v - 颜色
4984
+ * @param alpha - 插值比例
4985
+ * @returns 插值结果
4986
+ */ _proto.lerp = function lerp(v, alpha) {
4987
+ this.r += (v.r - this.r) * alpha;
4988
+ this.g += (v.g - this.g) * alpha;
4989
+ this.b += (v.b - this.b) * alpha;
4990
+ this.a += (v.a - this.a) * alpha;
4991
+ return this;
4992
+ };
4993
+ /**
4994
+ * 计算颜色亮度值
4995
+ * @returns 亮度值
4996
+ */ _proto.luminance = function luminance() {
4997
+ return this.r * 0.3 + this.g * 0.59 + this.b * 0.11;
4998
+ };
4999
+ /**
5000
+ * 颜色判等
5001
+ * @param v - 颜色
5002
+ * @returns 判等结果
5003
+ */ _proto.equals = function equals(v) {
5004
+ return v.r === this.r && v.g === this.g && v.b === this.b && v.a === this.a;
5005
+ };
5006
+ _proto.toLinear = function toLinear() {
5007
+ this.r = Color.gammaToLinear(this.r);
5008
+ this.g = Color.gammaToLinear(this.g);
5009
+ this.b = Color.gammaToLinear(this.b);
5010
+ return this;
5011
+ };
5012
+ _proto.toGamma = function toGamma() {
5013
+ this.r = Color.linearToGamma(this.r);
5014
+ this.g = Color.linearToGamma(this.g);
5015
+ this.b = Color.linearToGamma(this.b);
5016
+ return this;
5017
+ };
5018
+ /**
5019
+ * 颜色转数组
5020
+ * @returns 数组
5021
+ */ _proto.toArray = function toArray() {
5022
+ return [
5023
+ this.r,
5024
+ this.g,
5025
+ this.b,
5026
+ this.a
5027
+ ];
5028
+ };
5029
+ _proto.toVector4 = function toVector4() {
5030
+ return new Vector4(this.r, this.g, this.b, this.a);
5031
+ };
5032
+ /**
5033
+ * RGB 颜色空间转 HSV
5034
+ * @param result HSV 值
5035
+ */ _proto.toHSV = function toHSV() {
5036
+ var _this = this, r = _this.r, g = _this.g, b = _this.b, a = _this.a;
5037
+ var max = Math.max(r, g, b);
5038
+ var min = Math.min(r, g, b);
5039
+ var v = max;
5040
+ var dm = max - min;
5041
+ var h = 0;
5042
+ var s = 0;
5043
+ if (max !== 0) {
5044
+ s = dm / max;
5045
+ }
5046
+ if (max != min) {
5047
+ if (max == r) {
5048
+ h = (g - b) / dm;
5049
+ if (g < b) {
5050
+ h += 6;
5051
+ }
5052
+ } else if (max == g) {
5053
+ h = (b - r) / dm + 2;
5054
+ } else if (max == b) {
5055
+ h = (r - g) / dm + 4;
5056
+ }
5057
+ h *= 60;
5058
+ }
5059
+ return new Color(h, s, v, a);
5060
+ };
5061
+ _proto.toHexString = function toHexString(includeAlpha) {
5062
+ if (includeAlpha === void 0) includeAlpha = true;
5063
+ var R = Color.ToHex(Math.round(this.r * 255));
5064
+ var G = Color.ToHex(Math.round(this.g * 255));
5065
+ var B = Color.ToHex(Math.round(this.b * 255));
5066
+ var A = Color.ToHex(Math.round(this.a * 255));
5067
+ if (includeAlpha) {
5068
+ return "#" + R + G + B + A;
5069
+ } else {
5070
+ return "#" + R + G + B;
5071
+ }
5072
+ };
5073
+ _proto.fill = function fill(array, offset) {
5074
+ if (offset === void 0) offset = 0;
5075
+ array[offset] = this.r;
5076
+ array[offset + 1] = this.g;
5077
+ array[offset + 2] = this.b;
5078
+ array[offset + 3] = this.a;
5079
+ };
5080
+ /**
5081
+ * 通过标量数值创建颜色
5082
+ * @param num - 数值
5083
+ * @returns
5084
+ */ Color.fromNumber = function fromNumber(num) {
5085
+ return new Color().setFromNumber(num);
5086
+ };
5087
+ /**
5088
+ * 通过数组创建颜色
5089
+ * @param array - 数组
5090
+ * @param [offset=0] - 起始偏移值
5091
+ * @returns
5092
+ */ Color.fromArray = function fromArray(array, offset) {
5093
+ if (offset === void 0) offset = 0;
5094
+ return new Color().setFromArray(array, offset);
5095
+ };
5096
+ /**
5097
+ * 通过 hex 字符串创建颜色
5098
+ * @param hex - hex 字符串
5099
+ * @returns
5100
+ */ Color.fromHexString = function fromHexString(hex) {
5101
+ return new Color().setFromHexString(hex);
5102
+ };
5103
+ Color.fromHSV = function fromHSV(hue, saturation, value, alpha) {
5104
+ if (alpha === void 0) alpha = 1;
5105
+ return new Color().setFromHSV(hue, saturation, value, alpha);
5106
+ };
5107
+ /**
5108
+ * 颜色值从 Gamma 空间转到线性空间
5109
+ * @param v - Gamma 空间颜色值
5110
+ * @returns 线性空间颜色值
5111
+ */ Color.gammaToLinear = function gammaToLinear(v) {
5112
+ if (v <= 0.0) {
5113
+ return 0.0;
5114
+ } else if (v <= 0.04045) {
5115
+ return v / 12.92;
5116
+ } else if (v < 1.0) {
5117
+ return Math.pow((v + 0.055) / 1.055, 2.4);
5118
+ } else {
5119
+ return Math.pow(v, 2.4);
5120
+ }
5121
+ };
5122
+ /**
5123
+ * 颜色值从线性空间转到 Gamma 空间
5124
+ * @param value - 线性空间颜色值
5125
+ * @returns Gamma 空间颜色值
5126
+ */ Color.linearToGamma = function linearToGamma(value) {
5127
+ if (value <= 0.0) {
5128
+ return 0.0;
5129
+ } else if (value < 0.0031308) {
5130
+ return 12.92 * value;
5131
+ } else if (value < 1.0) {
5132
+ return 1.055 * Math.pow(value, 0.41666) - 0.055;
5133
+ } else {
5134
+ return Math.pow(value, 0.41666);
5135
+ }
5136
+ };
5137
+ Color.ToHex = function ToHex(i) {
5138
+ var str = i.toString(16);
5139
+ if (i <= 15) {
5140
+ return ("0" + str).toUpperCase();
5141
+ }
5142
+ return str.toUpperCase();
5143
+ };
5144
+ return Color;
5145
+ }();
5146
+ /**
5147
+ * 颜色的常量
5148
+ */ Color.BLACK = new Color(0, 0, 0, 1) // 纯黑色
5149
+ ;
5150
+ Color.BLUE = new Color(0, 0, 1, 1) // 纯蓝色
5151
+ ;
5152
+ Color.CLEAR = new Color(0, 0, 0, 0) // 完全透明
5153
+ ;
5154
+ Color.CYAN = new Color(0, 1, 1, 1) // 青色
5155
+ ;
5156
+ Color.GRAY = new Color(0.5, 0.5, 0.5, 1) // 灰色
5157
+ ;
5158
+ Color.GREEN = new Color(0, 1, 0, 1) // 纯绿色
5159
+ ;
5160
+ Color.MAGENTA = new Color(1, 0, 1, 1) // 洋红色
5161
+ ;
5162
+ Color.RED = new Color(1, 0, 0, 1) // 纯红色
5163
+ ;
5164
+ Color.WHITE = new Color(1, 1, 1, 1) // 纯白色
5165
+ ;
5166
+ Color.YELLOW = new Color(1, 0.92, 0.016, 1) // 黄色
5167
+ ;
5168
+
4148
5169
  var NodeTransform = /*#__PURE__*/ function() {
4149
5170
  function NodeTransform(transform) {
4150
5171
  this.position = new Vector3();
@@ -4184,7 +5205,7 @@ var Pose = /*#__PURE__*/ function() {
4184
5205
  }
4185
5206
  for(var _iterator2 = _create_for_of_iterator_helper_loose(skeleton.defaultColorPropertyValues), _step2; !(_step2 = _iterator2()).done;){
4186
5207
  var defaultColor = _step2.value;
4187
- this.colorPropertyValues.push(defaultColor);
5208
+ this.colorPropertyValues.push(new Color().copyFrom(defaultColor));
4188
5209
  }
4189
5210
  }
4190
5211
  var _proto = Pose.prototype;
@@ -5600,1059 +6621,548 @@ var Skeleton = /*#__PURE__*/ function() {
5600
6621
  }
5601
6622
  var targetBone = this.findTarget(path);
5602
6623
  if (!targetBone) {
5603
- return;
5604
- }
5605
- this.parentSpaceTransforms.push(new NodeTransform(targetBone.transform));
5606
- this.animatedTransforms.push(targetBone.transform);
5607
- this.pathToBoneIndex.set(path, this.parentSpaceTransforms.length - 1);
5608
- };
5609
- _proto.addRecordedProperty = function addRecordedProperty(path, className, property, type) {
5610
- var totalPath = path + className + property;
5611
- if (this.pathToObjectIndex.get(totalPath) !== undefined) {
5612
- return;
5613
- }
5614
- var targetBone = this.findTarget(path);
5615
- if (!targetBone) {
5616
- return;
5617
- }
5618
- var animatedComponentOrItem;
5619
- // Find target component or VFXItem
5620
- if (className === VFXItemType) {
5621
- animatedComponentOrItem = targetBone;
5622
- } else {
5623
- animatedComponentOrItem = targetBone.getComponent(getClass(className));
5624
- }
5625
- if (!animatedComponentOrItem) {
5626
- console.error("The " + className + " Component was not found.");
5627
- }
5628
- // Find last animated object by path
5629
- var propertyNames = property.split(".");
5630
- var lastPropertyName = propertyNames[propertyNames.length - 1];
5631
- var target = animatedComponentOrItem;
5632
- for(var i = 0; i < propertyNames.length - 1; i++){
5633
- var _$property = target[propertyNames[i]];
5634
- if (_$property === undefined) {
5635
- console.error("The " + propertyNames[i] + " property of " + target + " was not found.");
5636
- }
5637
- target = _$property;
5638
- }
5639
- var animatedObject = {
5640
- target: target,
5641
- property: lastPropertyName
5642
- };
5643
- switch(type){
5644
- case 0:
5645
- this.floatAnimatedObjects.push(animatedObject);
5646
- this.defaultFloatPropertyValues.push(target[lastPropertyName]);
5647
- this.pathToObjectIndex.set(totalPath, this.floatAnimatedObjects.length - 1);
5648
- break;
5649
- case 1:
5650
- this.colorAnimatedObjects.push(animatedObject);
5651
- this.defaultColorPropertyValues.push(target[lastPropertyName]);
5652
- this.pathToObjectIndex.set(totalPath, this.colorAnimatedObjects.length - 1);
5653
- }
5654
- };
5655
- _proto.findTarget = function findTarget(boneName) {
5656
- if (boneName === "") {
5657
- return this.rootBone;
5658
- }
5659
- var itemNames = boneName.split("/");
5660
- var currentItem = this.rootBone;
5661
- for(var _iterator = _create_for_of_iterator_helper_loose(itemNames), _step; !(_step = _iterator()).done;){
5662
- var itemName = _step.value;
5663
- var target = currentItem.find(itemName);
5664
- if (!target) {
5665
- return null;
5666
- }
5667
- currentItem = target;
5668
- }
5669
- return currentItem;
5670
- };
5671
- return Skeleton;
5672
- }();
5673
-
5674
- var GraphInstance = /*#__PURE__*/ function() {
5675
- function GraphInstance(graphAsset, rootBone) {
5676
- this.graphAsset = graphAsset;
5677
- this.nodes = [];
5678
- this.context = new GraphContext();
5679
- // Initialize skeleton
5680
- var recordProperties = {
5681
- position: [],
5682
- scale: [],
5683
- rotation: [],
5684
- euler: [],
5685
- floats: [],
5686
- colors: []
5687
- };
5688
- for(var _iterator = _create_for_of_iterator_helper_loose(graphAsset.graphDataSet.resources), _step; !(_step = _iterator()).done;){
5689
- var animationClip = _step.value;
5690
- if (!animationClip) {
5691
- continue;
5692
- }
5693
- for(var _iterator1 = _create_for_of_iterator_helper_loose(animationClip.positionCurves), _step1; !(_step1 = _iterator1()).done;){
5694
- var positionCurve = _step1.value;
5695
- recordProperties.position.push(positionCurve.path);
5696
- }
5697
- for(var _iterator2 = _create_for_of_iterator_helper_loose(animationClip.rotationCurves), _step2; !(_step2 = _iterator2()).done;){
5698
- var rotationCurve = _step2.value;
5699
- recordProperties.rotation.push(rotationCurve.path);
5700
- }
5701
- for(var _iterator3 = _create_for_of_iterator_helper_loose(animationClip.scaleCurves), _step3; !(_step3 = _iterator3()).done;){
5702
- var scaleCurve = _step3.value;
5703
- recordProperties.scale.push(scaleCurve.path);
5704
- }
5705
- for(var _iterator4 = _create_for_of_iterator_helper_loose(animationClip.eulerCurves), _step4; !(_step4 = _iterator4()).done;){
5706
- var eulerCurve = _step4.value;
5707
- recordProperties.euler.push(eulerCurve.path);
5708
- }
5709
- for(var _iterator5 = _create_for_of_iterator_helper_loose(animationClip.floatCurves), _step5; !(_step5 = _iterator5()).done;){
5710
- var floatCurve = _step5.value;
5711
- recordProperties.floats.push(floatCurve);
5712
- }
5713
- for(var _iterator6 = _create_for_of_iterator_helper_loose(animationClip.colorCurves), _step6; !(_step6 = _iterator6()).done;){
5714
- var colorCurve = _step6.value;
5715
- recordProperties.colors.push(colorCurve);
5716
- }
5717
- }
5718
- this.skeleton = new Skeleton(rootBone, recordProperties);
5719
- // create PoseResult
5720
- this.result = new PoseResult(this.skeleton);
5721
- this.context.skeleton = this.skeleton;
5722
- // instantiate graph nodes
5723
- var instantiationContext = new InstantiationContext();
5724
- instantiationContext.nodes = this.nodes;
5725
- instantiationContext.nodeDatas = graphAsset.nodeDatas;
5726
- instantiationContext.dataSet = graphAsset.graphDataSet;
5727
- for(var i = 0; i < graphAsset.nodeDatas.length; i++){
5728
- if (!instantiationContext.nodes[i]) {
5729
- graphAsset.nodeDatas[i].instantiate(instantiationContext);
5730
- }
5731
- }
5732
- this.rootNode = this.nodes[graphAsset.rootNodeIndex];
5733
- }
5734
- var _proto = GraphInstance.prototype;
5735
- _proto.evaluateGraph = function evaluateGraph(deltaTime) {
5736
- this.context.update(deltaTime);
5737
- if (!this.rootNode.isInitialized()) {
5738
- this.resetGraphState();
5739
- }
5740
- // Evaluate the entire animation graph starting from the rootNode
5741
- if (this.rootNode) {
5742
- this.result = this.rootNode.evaluate(this.context, this.result);
5743
- }
5744
- // Reset trigger nodes
5745
- for(var i = 0; i < this.getNumControlParameters(); i++){
5746
- var controlParameterNode = this.nodes[i];
5747
- if (_instanceof1(controlParameterNode, ControlParameterTriggerNode)) {
5748
- controlParameterNode.setValue(false);
5749
- }
5750
- }
5751
- return this.result;
5752
- };
5753
- _proto.isInitialized = function isInitialized() {
5754
- return this.rootNode && this.rootNode.isInitialized();
5755
- };
5756
- // General Node Info
5757
- //-------------------------------------------------------------------------
5758
- _proto.isNodeActive = function isNodeActive(nodeIdx) {
5759
- return this.isControlParameter(nodeIdx) || this.nodes[nodeIdx].isNodeActive(this.context.updateID);
5760
- };
5761
- // Graph State
5762
- //-------------------------------------------------------------------------
5763
- _proto.resetGraphState = function resetGraphState() {
5764
- if (this.rootNode.isInitialized()) {
5765
- this.rootNode.shutdown(this.context);
5766
- }
5767
- this.context.updateID++; // Bump the update ID to ensure that any initialization code that relies on it is dirtied.
5768
- this.rootNode.initialize(this.context);
5769
- };
5770
- // Control Parameters
5771
- //-------------------------------------------------------------------------
5772
- _proto.getNumControlParameters = function getNumControlParameters() {
5773
- return this.graphAsset.controlParameterIDs.length;
5774
- };
5775
- _proto.getControlParameterIndex = function getControlParameterIndex(parameterID) {
5776
- var parameterLookupMap = this.graphAsset.parameterLookupMap;
5777
- var res = parameterLookupMap.get(parameterID);
5778
- if (res !== undefined) {
5779
- return res;
5780
- }
5781
- console.warn("Parameter '" + parameterID + "' does not exist.");
5782
- return InvalidIndex;
5783
- };
5784
- _proto.getControlParameterID = function getControlParameterID(parameterNodeIndex) {
5785
- return this.graphAsset.controlParameterIDs[parameterNodeIndex];
5786
- };
5787
- _proto.setBool = function setBool(name, value) {
5788
- this.setControlParameterValue(name, value);
5789
- };
5790
- _proto.setFloat = function setFloat(name, value) {
5791
- this.setControlParameterValue(name, value);
5792
- };
5793
- _proto.setTrigger = function setTrigger(name) {
5794
- this.setControlParameterValue(name, true);
5795
- };
5796
- _proto.resetTrigger = function resetTrigger(name) {
5797
- this.setControlParameterValue(name, false);
5798
- };
5799
- // Debug Information
5800
- //-------------------------------------------------------------------------
5801
- _proto.getPoseNodeDebugInfo = function getPoseNodeDebugInfo(nodeIdx) {
5802
- var node = this.nodes[nodeIdx];
5803
- return node.getDebugInfo();
5804
- };
5805
- _proto.getRuntimeNodeDebugValue = function getRuntimeNodeDebugValue(nodeIdx) {
5806
- var valueNode = this.nodes[nodeIdx];
5807
- return valueNode.getValue(this.context);
5808
- };
5809
- _proto.getNodeDebugInstance = function getNodeDebugInstance(nodeIdx) {
5810
- return this.nodes[nodeIdx];
5811
- };
5812
- _proto.isControlParameter = function isControlParameter(nodeIdx) {
5813
- return nodeIdx < this.getNumControlParameters();
5814
- };
5815
- _proto.setControlParameterValue = function setControlParameterValue(name, value) {
5816
- var index = this.getControlParameterIndex(name);
5817
- if (index !== InvalidIndex) {
5818
- this.nodes[index].setValue(value);
5819
- }
5820
- };
5821
- return GraphInstance;
5822
- }();
5823
-
5824
- function _defineProperties(target, props) {
5825
- for(var i = 0; i < props.length; i++){
5826
- var descriptor = props[i];
5827
- descriptor.enumerable = descriptor.enumerable || false;
5828
- descriptor.configurable = true;
5829
- if ("value" in descriptor) descriptor.writable = true;
5830
- Object.defineProperty(target, descriptor.key, descriptor);
5831
- }
5832
- }
5833
- function _create_class(Constructor, protoProps, staticProps) {
5834
- if (protoProps) _defineProperties(Constructor.prototype, protoProps);
5835
- if (staticProps) _defineProperties(Constructor, staticProps);
5836
- return Constructor;
5837
- }
5838
-
5839
- /**
5840
- * @since 2.0.0
5841
- */ var Component = /*#__PURE__*/ function(EffectsObject) {
5842
- _inherits(Component, EffectsObject);
5843
- function Component() {
5844
- var _this;
5845
- _this = EffectsObject.apply(this, arguments) || this;
5846
- _this.isAwakeCalled = false;
5847
- _this.isStartCalled = false;
5848
- _this.isEnableCalled = false;
5849
- _this._enabled = true;
5850
- return _this;
5851
- }
5852
- var _proto = Component.prototype;
5853
- /**
5854
- * 生命周期函数,初始化后调用,生命周期内只调用一次
5855
- */ _proto.onAwake = function onAwake() {
5856
- // OVERRIDE
5857
- };
5858
- /**
5859
- * 在 enabled 变为 true 时触发
5860
- */ _proto.onEnable = function onEnable() {
5861
- // OVERRIDE
5862
- };
5863
- /**
5864
- * 在 enabled 变为 false 时触发
5865
- */ _proto.onDisable = function onDisable() {
5866
- // OVERRIDE
5867
- };
5868
- /**
5869
- * 生命周期函数,在第一次 update 前调用,生命周期内只调用一次
5870
- */ _proto.onStart = function onStart() {
5871
- // OVERRIDE
5872
- };
5873
- /**
5874
- * 生命周期函数,每帧调用一次
5875
- */ _proto.onUpdate = function onUpdate(dt) {
5876
- // OVERRIDE
5877
- };
5878
- /**
5879
- * 生命周期函数,每帧调用一次,在 update 之后调用
5880
- */ _proto.onLateUpdate = function onLateUpdate(dt) {
5881
- // OVERRIDE
5882
- };
5883
- /**
5884
- * 生命周期函数,在组件销毁时调用
5885
- */ _proto.onDestroy = function onDestroy() {
5886
- // OVERRIDE
5887
- };
5888
- /**
5889
- * @internal
5890
- */ _proto.enable = function enable() {
5891
- if (this.item.composition) {
5892
- this.item.composition.sceneTicking.addComponent(this);
5893
- this.isEnableCalled = true;
5894
- }
5895
- this.onEnable();
5896
- };
5897
- /**
5898
- * @internal
5899
- */ _proto.disable = function disable() {
5900
- this.onDisable();
5901
- if (this.item.composition) {
5902
- this.isEnableCalled = false;
5903
- this.item.composition.sceneTicking.removeComponent(this);
5904
- }
5905
- };
5906
- _proto.setVFXItem = function setVFXItem(item) {
5907
- this.item = item;
5908
- if (item.isDuringPlay) {
5909
- if (!this.isAwakeCalled) {
5910
- this.onAwake();
5911
- this.isAwakeCalled = true;
5912
- }
5913
- if (item.isActive && this.enabled) {
5914
- this.start();
5915
- this.enable();
5916
- }
5917
- }
5918
- };
5919
- _proto.fromData = function fromData(data) {
5920
- EffectsObject.prototype.fromData.call(this, data);
5921
- };
5922
- _proto.dispose = function dispose() {
5923
- if (this.isEnableCalled) {
5924
- this.disable();
5925
- }
5926
- if (this.isAwakeCalled) {
5927
- this.isAwakeCalled = false;
5928
- this.onDestroy();
5929
- }
5930
- if (this.item) {
5931
- removeItem(this.item.components, this);
5932
- }
5933
- };
5934
- _proto.start = function start() {
5935
- if (this.isStartCalled) {
5936
- return;
5937
- }
5938
- this.isStartCalled = true;
5939
- this.onStart();
5940
- };
5941
- _create_class(Component, [
5942
- {
5943
- key: "transform",
5944
- get: /**
5945
- * 附加到的 VFXItem 对象 Transform 组件
5946
- */ function get() {
5947
- return this.item.transform;
5948
- }
5949
- },
5950
- {
5951
- key: "isActiveAndEnabled",
5952
- get: /**
5953
- * 组件是否可以更新,true 更新,false 不更新
5954
- */ function get() {
5955
- return this.item.isActive && this.enabled;
5956
- }
5957
- },
5958
- {
5959
- key: "enabled",
5960
- get: function get() {
5961
- return this._enabled;
5962
- },
5963
- set: function set(value) {
5964
- if (this.enabled !== value) {
5965
- this._enabled = value;
5966
- if (value) {
5967
- if (this.isActiveAndEnabled) {
5968
- this.enable();
5969
- if (!this.isStartCalled) {
5970
- this.onStart();
5971
- this.isStartCalled = true;
5972
- }
5973
- }
5974
- } else {
5975
- if (this.isEnableCalled) {
5976
- this.disable();
5977
- }
5978
- }
5979
- }
5980
- }
5981
- }
5982
- ]);
5983
- return Component;
5984
- }(EffectsObject);
5985
- __decorate([
5986
- serialize()
5987
- ], Component.prototype, "item", void 0);
5988
- __decorate([
5989
- serialize()
5990
- ], Component.prototype, "_enabled", void 0);
5991
- /**
5992
- * @since 2.0.0
5993
- * @deprecated 2.4.0 Please use Component instead
5994
- */ var Behaviour = /*#__PURE__*/ function(Component) {
5995
- _inherits(Behaviour, Component);
5996
- function Behaviour() {
5997
- return Component.apply(this, arguments);
5998
- }
5999
- var _proto = Behaviour.prototype;
6000
- _proto.setVFXItem = function setVFXItem(item) {
6001
- Component.prototype.setVFXItem.call(this, item);
6002
- };
6003
- _proto.dispose = function dispose() {
6004
- Component.prototype.dispose.call(this);
6005
- };
6006
- return Behaviour;
6007
- }(Component);
6008
-
6009
- exports.Animator = /*#__PURE__*/ function(Component) {
6010
- _inherits(Animator, Component);
6011
- function Animator() {
6012
- var _this;
6013
- _this = Component.apply(this, arguments) || this;
6014
- /**
6015
- * @internal
6016
- */ _this.graph = null;
6017
- _this.graphAsset = null;
6018
- return _this;
6019
- }
6020
- var _proto = Animator.prototype;
6021
- _proto.setBool = function setBool(name, value) {
6022
- if (this.graph) {
6023
- this.graph.setBool(name, value);
6024
- }
6025
- };
6026
- _proto.setFloat = function setFloat(name, value) {
6027
- if (this.graph) {
6028
- this.graph.setFloat(name, value);
6029
- }
6030
- };
6031
- _proto.setTrigger = function setTrigger(name) {
6032
- if (this.graph) {
6033
- this.graph.setTrigger(name);
6034
- }
6035
- };
6036
- _proto.resetTrigger = function resetTrigger(name) {
6037
- if (this.graph) {
6038
- this.graph.resetTrigger(name);
6624
+ return;
6039
6625
  }
6626
+ this.parentSpaceTransforms.push(new NodeTransform(targetBone.transform));
6627
+ this.animatedTransforms.push(targetBone.transform);
6628
+ this.pathToBoneIndex.set(path, this.parentSpaceTransforms.length - 1);
6040
6629
  };
6041
- _proto.onStart = function onStart() {
6042
- if (this.graphAsset) {
6043
- this.graph = new GraphInstance(this.graphAsset, this.item);
6630
+ _proto.addRecordedProperty = function addRecordedProperty(path, className, property, type) {
6631
+ var totalPath = path + className + property;
6632
+ if (this.pathToObjectIndex.get(totalPath) !== undefined) {
6633
+ return;
6044
6634
  }
6045
- };
6046
- _proto.onUpdate = function onUpdate(dt) {
6047
- if (!this.graph) {
6635
+ var targetBone = this.findTarget(path);
6636
+ if (!targetBone) {
6048
6637
  return;
6049
6638
  }
6050
- var result = this.graph.evaluateGraph(dt / 1000);
6051
- // Apply transform animation
6052
- //-------------------------------------------------------------------------
6053
- var animatedTransforms = this.graph.skeleton.animatedTransforms;
6054
- for(var i = 0; i < animatedTransforms.length; i++){
6055
- var position = result.pose.parentSpaceTransforms[i].position;
6056
- var rotation = result.pose.parentSpaceTransforms[i].rotation;
6057
- var scale = result.pose.parentSpaceTransforms[i].scale;
6058
- var euler = result.pose.parentSpaceTransforms[i].euler;
6059
- animatedTransforms[i].setPosition(position.x, position.y, position.z);
6060
- animatedTransforms[i].setScale(scale.x, scale.y, scale.z);
6061
- if (this.graph.skeleton.useEuler) {
6062
- animatedTransforms[i].setRotation(euler.x, euler.y, euler.z);
6063
- } else {
6064
- animatedTransforms[i].setQuaternion(rotation.x, rotation.y, rotation.z, rotation.w);
6065
- }
6639
+ var animatedComponentOrItem;
6640
+ // Find target component or VFXItem
6641
+ if (className === VFXItemType) {
6642
+ animatedComponentOrItem = targetBone;
6643
+ } else {
6644
+ animatedComponentOrItem = targetBone.getComponent(getClass(className));
6066
6645
  }
6067
- // Apply property animation
6068
- //-------------------------------------------------------------------------
6069
- var floatAnimatedObjects = this.graph.skeleton.floatAnimatedObjects;
6070
- for(var i1 = 0; i1 < floatAnimatedObjects.length; i1++){
6071
- var animatedObject = floatAnimatedObjects[i1];
6072
- var property = animatedObject.property;
6073
- animatedObject.target[property] = result.pose.floatPropertyValues[i1];
6646
+ if (!animatedComponentOrItem) {
6647
+ console.error("The " + className + " Component was not found.");
6074
6648
  }
6075
- var colorAnimatedObjects = this.graph.skeleton.colorAnimatedObjects;
6076
- for(var i2 = 0; i2 < colorAnimatedObjects.length; i2++){
6077
- var animatedObject1 = colorAnimatedObjects[i2];
6078
- var property1 = animatedObject1.property;
6079
- animatedObject1.target[property1] = result.pose.colorPropertyValues[i2];
6649
+ // Find last animated object by path
6650
+ var propertyNames = property.split(".");
6651
+ var lastPropertyName = propertyNames[propertyNames.length - 1];
6652
+ var target = animatedComponentOrItem;
6653
+ for(var i = 0; i < propertyNames.length - 1; i++){
6654
+ var _$property = target[propertyNames[i]];
6655
+ if (_$property === undefined) {
6656
+ console.error("The " + propertyNames[i] + " property of " + target + " was not found.");
6657
+ }
6658
+ target = _$property;
6659
+ }
6660
+ var animatedObject = {
6661
+ target: target,
6662
+ property: lastPropertyName
6663
+ };
6664
+ switch(type){
6665
+ case 0:
6666
+ this.floatAnimatedObjects.push(animatedObject);
6667
+ this.defaultFloatPropertyValues.push(target[lastPropertyName]);
6668
+ this.pathToObjectIndex.set(totalPath, this.floatAnimatedObjects.length - 1);
6669
+ break;
6670
+ case 1:
6671
+ this.colorAnimatedObjects.push(animatedObject);
6672
+ this.defaultColorPropertyValues.push(new Color().copyFrom(target[lastPropertyName]));
6673
+ this.pathToObjectIndex.set(totalPath, this.colorAnimatedObjects.length - 1);
6080
6674
  }
6081
6675
  };
6082
- _proto.fromData = function fromData(data) {
6083
- this.graphAsset = this.engine.findObject(data.graphAsset);
6676
+ _proto.findTarget = function findTarget(boneName) {
6677
+ if (boneName === "") {
6678
+ return this.rootBone;
6679
+ }
6680
+ var itemNames = boneName.split("/");
6681
+ var currentItem = this.rootBone;
6682
+ for(var _iterator = _create_for_of_iterator_helper_loose(itemNames), _step; !(_step = _iterator()).done;){
6683
+ var itemName = _step.value;
6684
+ var target = currentItem.find(itemName);
6685
+ if (!target) {
6686
+ return null;
6687
+ }
6688
+ currentItem = target;
6689
+ }
6690
+ return currentItem;
6084
6691
  };
6085
- return Animator;
6086
- }(Component);
6087
- exports.Animator = __decorate([
6088
- effectsClass("Animator")
6089
- ], exports.Animator);
6692
+ return Skeleton;
6693
+ }();
6090
6694
 
6091
- /**
6092
- * 所有渲染组件的基类
6093
- * @since 2.0.0
6094
- */ var RendererComponent = /*#__PURE__*/ function(Component) {
6095
- _inherits(RendererComponent, Component);
6096
- function RendererComponent() {
6097
- var _this;
6098
- _this = Component.apply(this, arguments) || this;
6099
- _this.materials = [];
6100
- _this._priority = 0;
6101
- return _this;
6102
- }
6103
- var _proto = RendererComponent.prototype;
6104
- _proto.render = function render(renderer) {};
6105
- _proto.onEnable = function onEnable() {
6106
- var _this_item_composition;
6107
- (_this_item_composition = this.item.composition) == null ? void 0 : _this_item_composition.renderFrame.addMeshToDefaultRenderPass(this);
6108
- };
6109
- _proto.onDisable = function onDisable() {
6110
- var _this_item_composition;
6111
- (_this_item_composition = this.item.composition) == null ? void 0 : _this_item_composition.renderFrame.removeMeshFromDefaultRenderPass(this);
6112
- };
6113
- _create_class(RendererComponent, [
6114
- {
6115
- key: "priority",
6116
- get: function get() {
6117
- return this._priority;
6118
- },
6119
- set: function set(value) {
6120
- this._priority = value;
6695
+ var GraphInstance = /*#__PURE__*/ function() {
6696
+ function GraphInstance(graphAsset, rootBone) {
6697
+ this.graphAsset = graphAsset;
6698
+ this.nodes = [];
6699
+ this.context = new GraphContext();
6700
+ // Initialize skeleton
6701
+ var recordProperties = {
6702
+ position: [],
6703
+ scale: [],
6704
+ rotation: [],
6705
+ euler: [],
6706
+ floats: [],
6707
+ colors: []
6708
+ };
6709
+ for(var _iterator = _create_for_of_iterator_helper_loose(graphAsset.graphDataSet.resources), _step; !(_step = _iterator()).done;){
6710
+ var animationClip = _step.value;
6711
+ if (!animationClip) {
6712
+ continue;
6121
6713
  }
6122
- },
6123
- {
6124
- key: "material",
6125
- get: function get() {
6126
- return this.materials[0];
6127
- },
6128
- set: function set(material) {
6129
- if (this.materials.length === 0) {
6130
- this.materials.push(material);
6131
- } else {
6132
- this.materials[0] = material;
6133
- }
6714
+ for(var _iterator1 = _create_for_of_iterator_helper_loose(animationClip.positionCurves), _step1; !(_step1 = _iterator1()).done;){
6715
+ var positionCurve = _step1.value;
6716
+ recordProperties.position.push(positionCurve.path);
6717
+ }
6718
+ for(var _iterator2 = _create_for_of_iterator_helper_loose(animationClip.rotationCurves), _step2; !(_step2 = _iterator2()).done;){
6719
+ var rotationCurve = _step2.value;
6720
+ recordProperties.rotation.push(rotationCurve.path);
6721
+ }
6722
+ for(var _iterator3 = _create_for_of_iterator_helper_loose(animationClip.scaleCurves), _step3; !(_step3 = _iterator3()).done;){
6723
+ var scaleCurve = _step3.value;
6724
+ recordProperties.scale.push(scaleCurve.path);
6725
+ }
6726
+ for(var _iterator4 = _create_for_of_iterator_helper_loose(animationClip.eulerCurves), _step4; !(_step4 = _iterator4()).done;){
6727
+ var eulerCurve = _step4.value;
6728
+ recordProperties.euler.push(eulerCurve.path);
6729
+ }
6730
+ for(var _iterator5 = _create_for_of_iterator_helper_loose(animationClip.floatCurves), _step5; !(_step5 = _iterator5()).done;){
6731
+ var floatCurve = _step5.value;
6732
+ recordProperties.floats.push(floatCurve);
6733
+ }
6734
+ for(var _iterator6 = _create_for_of_iterator_helper_loose(animationClip.colorCurves), _step6; !(_step6 = _iterator6()).done;){
6735
+ var colorCurve = _step6.value;
6736
+ recordProperties.colors.push(colorCurve);
6134
6737
  }
6135
6738
  }
6136
- ]);
6137
- return RendererComponent;
6138
- }(Component);
6139
- __decorate([
6140
- serialize()
6141
- ], RendererComponent.prototype, "materials", void 0);
6142
- __decorate([
6143
- serialize()
6144
- ], RendererComponent.prototype, "_priority", void 0);
6145
-
6146
- /**
6147
- * 四维向量
6148
- */ var Vector4 = /*#__PURE__*/ function() {
6149
- function Vector4(x, y, z, w) {
6150
- if (x === void 0) x = 0;
6151
- if (y === void 0) y = 0;
6152
- if (z === void 0) z = 0;
6153
- if (w === void 0) w = 0;
6154
- this.x = x;
6155
- this.y = y;
6156
- this.z = z;
6157
- this.w = w;
6739
+ this.skeleton = new Skeleton(rootBone, recordProperties);
6740
+ // create PoseResult
6741
+ this.result = new PoseResult(this.skeleton);
6742
+ this.context.skeleton = this.skeleton;
6743
+ // instantiate graph nodes
6744
+ var instantiationContext = new InstantiationContext();
6745
+ instantiationContext.nodes = this.nodes;
6746
+ instantiationContext.nodeDatas = graphAsset.nodeDatas;
6747
+ instantiationContext.dataSet = graphAsset.graphDataSet;
6748
+ for(var i = 0; i < graphAsset.nodeDatas.length; i++){
6749
+ if (!instantiationContext.nodes[i]) {
6750
+ graphAsset.nodeDatas[i].instantiate(instantiationContext);
6751
+ }
6752
+ }
6753
+ this.rootNode = this.nodes[graphAsset.rootNodeIndex];
6158
6754
  }
6159
- var _proto = Vector4.prototype;
6160
- /**
6161
- * 设置向量
6162
- * @param x - x 轴分量
6163
- * @param y - y 轴分量
6164
- * @param z - z 轴分量
6165
- * @param w - w 轴分量
6166
- * @returns
6167
- */ _proto.set = function set(x, y, z, w) {
6168
- this.x = x;
6169
- this.y = y;
6170
- this.z = z;
6171
- this.w = w;
6172
- return this;
6173
- };
6174
- /**
6175
- * 设置零向量
6176
- * @returns 向量
6177
- */ _proto.setZero = function setZero() {
6178
- this.x = 0;
6179
- this.y = 0;
6180
- this.z = 0;
6181
- this.w = 0;
6182
- return this;
6183
- };
6184
- /**
6185
- * 通过标量数值设置向量
6186
- * @param num - 数值
6187
- * @returns 向量
6188
- */ _proto.setFromNumber = function setFromNumber(num) {
6189
- this.x = num;
6190
- this.y = num;
6191
- this.z = num;
6192
- this.w = num;
6193
- return this;
6194
- };
6195
- /**
6196
- * 通过数组创建向量
6197
- * @param array - 数组
6198
- * @param [offset=0] - 起始偏移值
6199
- * @returns 向量
6200
- */ _proto.setFromArray = function setFromArray(array, offset) {
6201
- if (offset === void 0) offset = 0;
6202
- var _array_offset;
6203
- this.x = (_array_offset = array[offset]) != null ? _array_offset : 0;
6204
- var _array_;
6205
- this.y = (_array_ = array[offset + 1]) != null ? _array_ : 0;
6206
- var _array_1;
6207
- this.z = (_array_1 = array[offset + 2]) != null ? _array_1 : 0;
6208
- var _array_2;
6209
- this.w = (_array_2 = array[offset + 3]) != null ? _array_2 : 0;
6210
- return this;
6755
+ var _proto = GraphInstance.prototype;
6756
+ _proto.evaluateGraph = function evaluateGraph(deltaTime) {
6757
+ this.context.update(deltaTime);
6758
+ if (!this.rootNode.isInitialized()) {
6759
+ this.resetGraphState();
6760
+ }
6761
+ // Evaluate the entire animation graph starting from the rootNode
6762
+ if (this.rootNode) {
6763
+ this.result = this.rootNode.evaluate(this.context, this.result);
6764
+ }
6765
+ // Reset trigger nodes
6766
+ for(var i = 0; i < this.getNumControlParameters(); i++){
6767
+ var controlParameterNode = this.nodes[i];
6768
+ if (_instanceof1(controlParameterNode, ControlParameterTriggerNode)) {
6769
+ controlParameterNode.setValue(false);
6770
+ }
6771
+ }
6772
+ return this.result;
6211
6773
  };
6212
- /**
6213
- * 拷贝向量
6214
- * @param v - 复制对象
6215
- * @returns 拷贝结果
6216
- */ _proto.copyFrom = function copyFrom(v) {
6217
- this.x = v.x;
6218
- this.y = v.y;
6219
- this.z = v.z;
6220
- this.w = v.w;
6221
- return this;
6774
+ _proto.isInitialized = function isInitialized() {
6775
+ return this.rootNode && this.rootNode.isInitialized();
6222
6776
  };
6223
- /**
6224
- * 克隆向量
6225
- * @returns 克隆结果
6226
- */ _proto.clone = function clone() {
6227
- return new Vector4(this.x, this.y, this.z, this.w);
6777
+ // General Node Info
6778
+ //-------------------------------------------------------------------------
6779
+ _proto.isNodeActive = function isNodeActive(nodeIdx) {
6780
+ return this.isControlParameter(nodeIdx) || this.nodes[nodeIdx].isNodeActive(this.context.updateID);
6228
6781
  };
6229
- /**
6230
- * 根据下标设置向量分量
6231
- * @param index - 下标值
6232
- * @param value - 分量值
6233
- * @returns 向量
6234
- */ _proto.setElement = function setElement(index, value) {
6235
- switch(index){
6236
- case 0:
6237
- this.x = value;
6238
- break;
6239
- case 1:
6240
- this.y = value;
6241
- break;
6242
- case 2:
6243
- this.z = value;
6244
- break;
6245
- case 3:
6246
- this.w = value;
6247
- break;
6248
- default:
6249
- console.error("index is out of range: " + index);
6782
+ // Graph State
6783
+ //-------------------------------------------------------------------------
6784
+ _proto.resetGraphState = function resetGraphState() {
6785
+ if (this.rootNode.isInitialized()) {
6786
+ this.rootNode.shutdown(this.context);
6250
6787
  }
6251
- return this;
6788
+ this.context.updateID++; // Bump the update ID to ensure that any initialization code that relies on it is dirtied.
6789
+ this.rootNode.initialize(this.context);
6252
6790
  };
6253
- /**
6254
- * 根据下标获取向量分量
6255
- * @param index - 下标
6256
- * @returns 分量值
6257
- */ _proto.getElement = function getElement(index) {
6258
- switch(index){
6259
- case 0:
6260
- return this.x;
6261
- case 1:
6262
- return this.y;
6263
- case 2:
6264
- return this.z;
6265
- case 3:
6266
- return this.w;
6267
- default:
6268
- console.error("index is out of range: " + index);
6269
- }
6270
- return 0;
6791
+ // Control Parameters
6792
+ //-------------------------------------------------------------------------
6793
+ _proto.getNumControlParameters = function getNumControlParameters() {
6794
+ return this.graphAsset.controlParameterIDs.length;
6271
6795
  };
6272
- /**
6273
- * 向量相加
6274
- * @param right - 相加对象,向量 | 数字
6275
- * @returns 相加结果
6276
- */ _proto.add = function add(right) {
6277
- if (typeof right === "number") {
6278
- this.x += right;
6279
- this.y += right;
6280
- this.z += right;
6281
- this.w += right;
6282
- } else if (_instanceof1(right, Array)) {
6283
- this.x += right[0];
6284
- this.y += right[1];
6285
- this.z += right[2];
6286
- this.w += right[3];
6287
- } else {
6288
- this.x += right.x;
6289
- this.y += right.y;
6290
- this.z += right.z;
6291
- this.w += right.w;
6796
+ _proto.getControlParameterIndex = function getControlParameterIndex(parameterID) {
6797
+ var parameterLookupMap = this.graphAsset.parameterLookupMap;
6798
+ var res = parameterLookupMap.get(parameterID);
6799
+ if (res !== undefined) {
6800
+ return res;
6292
6801
  }
6293
- return this;
6294
- };
6295
- /**
6296
- * 向量相加
6297
- * @param left - 向量
6298
- * @param right - 向量
6299
- * @returns 求和结果
6300
- */ _proto.addVectors = function addVectors(left, right) {
6301
- this.x = left.x + right.x;
6302
- this.y = left.y + right.y;
6303
- this.z = left.z + right.z;
6304
- this.w = left.w + right.w;
6305
- return this;
6802
+ console.warn("Parameter '" + parameterID + "' does not exist.");
6803
+ return InvalidIndex;
6306
6804
  };
6307
- /**
6308
- * 向量比例缩放后相加
6309
- * @param right - 向量
6310
- * @param s - 比例
6311
- * @returns 求和结果
6312
- */ _proto.addScaledVector = function addScaledVector(right, s) {
6313
- this.x += right.x * s;
6314
- this.y += right.y * s;
6315
- this.z += right.z * s;
6316
- this.w += right.w * s;
6317
- return this;
6805
+ _proto.getControlParameterID = function getControlParameterID(parameterNodeIndex) {
6806
+ return this.graphAsset.controlParameterIDs[parameterNodeIndex];
6318
6807
  };
6319
- /**
6320
- * 向量相减
6321
- * @param right - 相减对象,向量 | 数字
6322
- * @returns 相减结果
6323
- */ _proto.subtract = function subtract(right) {
6324
- if (typeof right === "number") {
6325
- this.x -= right;
6326
- this.y -= right;
6327
- this.z -= right;
6328
- this.w -= right;
6329
- } else if (_instanceof1(right, Array)) {
6330
- this.x -= right[0];
6331
- this.y -= right[1];
6332
- this.z -= right[2];
6333
- this.w -= right[3];
6334
- } else {
6335
- this.x -= right.x;
6336
- this.y -= right.y;
6337
- this.z -= right.z;
6338
- this.w -= right.w;
6339
- }
6340
- return this;
6808
+ _proto.setBool = function setBool(name, value) {
6809
+ this.setControlParameterValue(name, value);
6341
6810
  };
6342
- /**
6343
- * 向量相减
6344
- * @param left - 向量
6345
- * @param right - 向量
6346
- * @returns 向量
6347
- */ _proto.subtractVectors = function subtractVectors(left, right) {
6348
- this.x = left.x - right.x;
6349
- this.y = left.y - right.y;
6350
- this.z = left.z - right.z;
6351
- this.w = left.w - right.w;
6352
- return this;
6811
+ _proto.setFloat = function setFloat(name, value) {
6812
+ this.setControlParameterValue(name, value);
6353
6813
  };
6354
- /**
6355
- * 向量相乘
6356
- * @param right - 相乘对象,对象 | 数字
6357
- * @returns 向量
6358
- */ _proto.multiply = function multiply(right) {
6359
- if (typeof right === "number") {
6360
- this.x *= right;
6361
- this.y *= right;
6362
- this.z *= right;
6363
- this.w *= right;
6364
- } else if (_instanceof1(right, Array)) {
6365
- this.x *= right[0];
6366
- this.y *= right[1];
6367
- this.z *= right[2];
6368
- this.w *= right[3];
6369
- } else {
6370
- this.x *= right.x;
6371
- this.y *= right.y;
6372
- this.z *= right.z;
6373
- this.w *= right.w;
6374
- }
6375
- return this;
6814
+ _proto.setTrigger = function setTrigger(name) {
6815
+ this.setControlParameterValue(name, true);
6376
6816
  };
6377
- /**
6378
- * 向量相乘
6379
- * @param left - 向量
6380
- * @param right - 向量
6381
- * @returns 向量
6382
- */ _proto.multiplyVectors = function multiplyVectors(left, right) {
6383
- this.x = left.x * right.x;
6384
- this.y = left.y * right.y;
6385
- this.z = left.z * right.z;
6386
- this.w = left.w * right.w;
6387
- return this;
6817
+ _proto.resetTrigger = function resetTrigger(name) {
6818
+ this.setControlParameterValue(name, false);
6388
6819
  };
6389
- /**
6390
- * 向量相除
6391
- * @param right - 相除对象,对象 | 数字
6392
- * @returns 向量
6393
- */ _proto.divide = function divide(right) {
6394
- if (typeof right === "number") {
6395
- this.x /= right;
6396
- this.y /= right;
6397
- this.z /= right;
6398
- this.w /= right;
6399
- } else if (_instanceof1(right, Array)) {
6400
- this.x /= right[0];
6401
- this.y /= right[1];
6402
- this.z /= right[2];
6403
- this.w /= right[3];
6404
- } else {
6405
- this.x /= right.x;
6406
- this.y /= right.y;
6407
- this.z /= right.z;
6408
- this.w /= right.w;
6409
- }
6410
- return this;
6820
+ // Debug Information
6821
+ //-------------------------------------------------------------------------
6822
+ _proto.getPoseNodeDebugInfo = function getPoseNodeDebugInfo(nodeIdx) {
6823
+ var node = this.nodes[nodeIdx];
6824
+ return node.getDebugInfo();
6411
6825
  };
6412
- /**
6413
- * 向量缩放
6414
- * @param v - 数字
6415
- * @returns 缩放结果
6416
- */ _proto.scale = function scale(v) {
6417
- this.x *= v;
6418
- this.y *= v;
6419
- this.z *= v;
6420
- this.w *= v;
6421
- return this;
6826
+ _proto.getRuntimeNodeDebugValue = function getRuntimeNodeDebugValue(nodeIdx) {
6827
+ var valueNode = this.nodes[nodeIdx];
6828
+ return valueNode.getValue(this.context);
6422
6829
  };
6423
- /**
6424
- * 分量求和
6425
- * @returns 求和结果
6426
- */ _proto.sum = function sum() {
6427
- return this.x + this.y + this.z + this.w;
6830
+ _proto.getNodeDebugInstance = function getNodeDebugInstance(nodeIdx) {
6831
+ return this.nodes[nodeIdx];
6428
6832
  };
6429
- /**
6430
- * 向量求最小值
6431
- * @param v - 向量或数值
6432
- * @returns 最小值
6433
- */ _proto.min = function min(v) {
6434
- if (typeof v === "number") {
6435
- this.x = Math.min(this.x, v);
6436
- this.y = Math.min(this.y, v);
6437
- this.z = Math.min(this.z, v);
6438
- this.w = Math.min(this.w, v);
6439
- } else {
6440
- this.x = Math.min(this.x, v.x);
6441
- this.y = Math.min(this.y, v.y);
6442
- this.z = Math.min(this.z, v.z);
6443
- this.w = Math.min(this.w, v.w);
6444
- }
6445
- return this;
6833
+ _proto.isControlParameter = function isControlParameter(nodeIdx) {
6834
+ return nodeIdx < this.getNumControlParameters();
6446
6835
  };
6447
- /**
6448
- * 向量求最大值
6449
- * @param v - 向量或数值
6450
- * @returns 最大值
6451
- */ _proto.max = function max(v) {
6452
- if (typeof v === "number") {
6453
- this.x = Math.max(this.x, v);
6454
- this.y = Math.max(this.y, v);
6455
- this.z = Math.max(this.z, v);
6456
- this.w = Math.max(this.w, v);
6457
- } else {
6458
- this.x = Math.max(this.x, v.x);
6459
- this.y = Math.max(this.y, v.y);
6460
- this.z = Math.max(this.z, v.z);
6461
- this.w = Math.max(this.w, v.w);
6836
+ _proto.setControlParameterValue = function setControlParameterValue(name, value) {
6837
+ var index = this.getControlParameterIndex(name);
6838
+ if (index !== InvalidIndex) {
6839
+ this.nodes[index].setValue(value);
6462
6840
  }
6463
- return this;
6464
6841
  };
6842
+ return GraphInstance;
6843
+ }();
6844
+
6845
+ function _defineProperties(target, props) {
6846
+ for(var i = 0; i < props.length; i++){
6847
+ var descriptor = props[i];
6848
+ descriptor.enumerable = descriptor.enumerable || false;
6849
+ descriptor.configurable = true;
6850
+ if ("value" in descriptor) descriptor.writable = true;
6851
+ Object.defineProperty(target, descriptor.key, descriptor);
6852
+ }
6853
+ }
6854
+ function _create_class(Constructor, protoProps, staticProps) {
6855
+ if (protoProps) _defineProperties(Constructor.prototype, protoProps);
6856
+ if (staticProps) _defineProperties(Constructor, staticProps);
6857
+ return Constructor;
6858
+ }
6859
+
6860
+ /**
6861
+ * @since 2.0.0
6862
+ */ var Component = /*#__PURE__*/ function(EffectsObject) {
6863
+ _inherits(Component, EffectsObject);
6864
+ function Component() {
6865
+ var _this;
6866
+ _this = EffectsObject.apply(this, arguments) || this;
6867
+ _this.isAwakeCalled = false;
6868
+ _this.isStartCalled = false;
6869
+ _this.isEnableCalled = false;
6870
+ _this._enabled = true;
6871
+ return _this;
6872
+ }
6873
+ var _proto = Component.prototype;
6465
6874
  /**
6466
- * 向量阈值约束
6467
- * @param min - 最小值
6468
- * @param max - 最大值
6469
- * @returns 向量
6470
- */ _proto.clamp = function clamp(min, max) {
6471
- return this.max(min).min(max);
6875
+ * 生命周期函数,初始化后调用,生命周期内只调用一次
6876
+ */ _proto.onAwake = function onAwake() {
6877
+ // OVERRIDE
6472
6878
  };
6473
6879
  /**
6474
- * 向量向下取整
6475
- * @returns 取整结果
6476
- */ _proto.floor = function floor() {
6477
- this.x = Math.floor(this.x);
6478
- this.y = Math.floor(this.y);
6479
- this.z = Math.floor(this.z);
6480
- this.w = Math.floor(this.w);
6481
- return this;
6880
+ * 在 enabled 变为 true 时触发
6881
+ */ _proto.onEnable = function onEnable() {
6882
+ // OVERRIDE
6482
6883
  };
6483
6884
  /**
6484
- * 向量向上取整
6485
- * @returns 取整结果
6486
- */ _proto.ceil = function ceil() {
6487
- this.x = Math.ceil(this.x);
6488
- this.y = Math.ceil(this.y);
6489
- this.z = Math.ceil(this.z);
6490
- this.w = Math.ceil(this.w);
6491
- return this;
6885
+ * 在 enabled 变为 false 时触发
6886
+ */ _proto.onDisable = function onDisable() {
6887
+ // OVERRIDE
6492
6888
  };
6493
6889
  /**
6494
- * 向量四舍五入
6495
- * @returns 求值结果
6496
- */ _proto.round = function round() {
6497
- this.x = Math.round(this.x);
6498
- this.y = Math.round(this.y);
6499
- this.z = Math.round(this.z);
6500
- this.w = Math.round(this.w);
6501
- return this;
6890
+ * 生命周期函数,在第一次 update 前调用,生命周期内只调用一次
6891
+ */ _proto.onStart = function onStart() {
6892
+ // OVERRIDE
6502
6893
  };
6503
6894
  /**
6504
- * 向量取绝对值
6505
- * @returns 向量
6506
- */ _proto.abs = function abs() {
6507
- this.x = Math.abs(this.x);
6508
- this.y = Math.abs(this.y);
6509
- this.z = Math.abs(this.z);
6510
- this.w = Math.abs(this.w);
6511
- return this;
6895
+ * 生命周期函数,每帧调用一次
6896
+ */ _proto.onUpdate = function onUpdate(dt) {
6897
+ // OVERRIDE
6512
6898
  };
6513
6899
  /**
6514
- * 向量取反
6515
- * @returns 取反结果
6516
- */ _proto.negate = function negate() {
6517
- this.x = -this.x;
6518
- this.y = -this.y;
6519
- this.z = -this.z;
6520
- this.w = -this.w;
6521
- return this;
6900
+ * 生命周期函数,每帧调用一次,在 update 之后调用
6901
+ */ _proto.onLateUpdate = function onLateUpdate(dt) {
6902
+ // OVERRIDE
6522
6903
  };
6523
6904
  /**
6524
- * 向量长度平方
6525
- * @returns 长度平方
6526
- */ _proto.lengthSquared = function lengthSquared() {
6527
- return this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w;
6905
+ * 生命周期函数,在组件销毁时调用
6906
+ */ _proto.onDestroy = function onDestroy() {
6907
+ // OVERRIDE
6528
6908
  };
6529
6909
  /**
6530
- * 向量长度
6531
- * @returns 长度
6532
- */ _proto.length = function length() {
6533
- return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w);
6910
+ * @internal
6911
+ */ _proto.enable = function enable() {
6912
+ if (this.item.composition) {
6913
+ this.item.composition.sceneTicking.addComponent(this);
6914
+ this.isEnableCalled = true;
6915
+ }
6916
+ this.onEnable();
6534
6917
  };
6535
6918
  /**
6536
- * 向量归一化
6537
- * @returns 归一化结果
6538
- */ _proto.normalize = function normalize() {
6539
- return this.divide(this.length() || 1);
6919
+ * @internal
6920
+ */ _proto.disable = function disable() {
6921
+ this.onDisable();
6922
+ if (this.item.composition) {
6923
+ this.isEnableCalled = false;
6924
+ this.item.composition.sceneTicking.removeComponent(this);
6925
+ }
6540
6926
  };
6541
- /**
6542
- * 设置向量长度
6543
- * @param length - 长度
6544
- * @returns 向量
6545
- */ _proto.setLength = function setLength(length) {
6546
- return this.normalize().multiply(length);
6927
+ _proto.setVFXItem = function setVFXItem(item) {
6928
+ this.item = item;
6929
+ if (item.isDuringPlay) {
6930
+ if (!this.isAwakeCalled) {
6931
+ this.onAwake();
6932
+ this.isAwakeCalled = true;
6933
+ }
6934
+ if (item.isActive && this.enabled) {
6935
+ this.start();
6936
+ this.enable();
6937
+ }
6938
+ }
6547
6939
  };
6548
- /**
6549
- * 向量求线性插值
6550
- * @param v - 向量
6551
- * @param alpha - 插值比例
6552
- * @returns 插值结果
6553
- */ _proto.lerp = function lerp(v, alpha) {
6554
- this.x += (v.x - this.x) * alpha;
6555
- this.y += (v.y - this.y) * alpha;
6556
- this.z += (v.z - this.z) * alpha;
6557
- this.w += (v.w - this.w) * alpha;
6558
- return this;
6940
+ _proto.fromData = function fromData(data) {
6941
+ EffectsObject.prototype.fromData.call(this, data);
6559
6942
  };
6560
- /**
6561
- * 两向量求线性插值
6562
- * @param v1 - 第一个向量
6563
- * @param v2 - 第二个向量
6564
- * @param alpha - 插值比例
6565
- * @returns 插值结果
6566
- */ _proto.lerpVectors = function lerpVectors(v1, v2, alpha) {
6567
- this.x = v1.x + (v2.x - v1.x) * alpha;
6568
- this.y = v1.y + (v2.y - v1.y) * alpha;
6569
- this.z = v1.z + (v2.z - v1.z) * alpha;
6570
- this.w = v1.w + (v2.w - v1.w) * alpha;
6571
- return this;
6943
+ _proto.dispose = function dispose() {
6944
+ if (this.isEnableCalled) {
6945
+ this.disable();
6946
+ }
6947
+ if (this.isAwakeCalled) {
6948
+ this.isAwakeCalled = false;
6949
+ this.onDestroy();
6950
+ }
6951
+ if (this.item) {
6952
+ removeItem(this.item.components, this);
6953
+ }
6572
6954
  };
6573
- /**
6574
- * 向量求点积
6575
- * @param v - 向量
6576
- * @returns 点积结果
6577
- */ _proto.dot = function dot(v) {
6578
- return this.x * v.x + this.y * v.y + this.z * v.z + this.w * v.w;
6955
+ _proto.start = function start() {
6956
+ if (this.isStartCalled) {
6957
+ return;
6958
+ }
6959
+ this.isStartCalled = true;
6960
+ this.onStart();
6579
6961
  };
6580
- /**
6581
- * 向量判等
6582
- * @param v - 向量
6583
- * @returns 判等结果
6584
- */ _proto.equals = function equals(v) {
6585
- return v.x === this.x && v.y === this.y && v.z === this.z && v.w === this.w;
6962
+ _create_class(Component, [
6963
+ {
6964
+ key: "transform",
6965
+ get: /**
6966
+ * 附加到的 VFXItem 对象 Transform 组件
6967
+ */ function get() {
6968
+ return this.item.transform;
6969
+ }
6970
+ },
6971
+ {
6972
+ key: "isActiveAndEnabled",
6973
+ get: /**
6974
+ * 组件是否可以更新,true 更新,false 不更新
6975
+ */ function get() {
6976
+ return this.item.isActive && this.enabled;
6977
+ }
6978
+ },
6979
+ {
6980
+ key: "enabled",
6981
+ get: function get() {
6982
+ return this._enabled;
6983
+ },
6984
+ set: function set(value) {
6985
+ if (this.enabled !== value) {
6986
+ this._enabled = value;
6987
+ if (value) {
6988
+ if (this.isActiveAndEnabled) {
6989
+ this.enable();
6990
+ if (!this.isStartCalled) {
6991
+ this.onStart();
6992
+ this.isStartCalled = true;
6993
+ }
6994
+ }
6995
+ } else {
6996
+ if (this.isEnableCalled) {
6997
+ this.disable();
6998
+ }
6999
+ }
7000
+ }
7001
+ }
7002
+ }
7003
+ ]);
7004
+ return Component;
7005
+ }(EffectsObject);
7006
+ __decorate([
7007
+ serialize()
7008
+ ], Component.prototype, "item", void 0);
7009
+ __decorate([
7010
+ serialize()
7011
+ ], Component.prototype, "_enabled", void 0);
7012
+ /**
7013
+ * @since 2.0.0
7014
+ * @deprecated 2.4.0 Please use Component instead
7015
+ */ var Behaviour = /*#__PURE__*/ function(Component) {
7016
+ _inherits(Behaviour, Component);
7017
+ function Behaviour() {
7018
+ return Component.apply(this, arguments);
7019
+ }
7020
+ var _proto = Behaviour.prototype;
7021
+ _proto.setVFXItem = function setVFXItem(item) {
7022
+ Component.prototype.setVFXItem.call(this, item);
6586
7023
  };
6587
- /**
6588
- * 是否零向量
6589
- * @returns 是否零向量
6590
- */ _proto.isZero = function isZero() {
6591
- var eps = NumberEpsilon;
6592
- var _this = this, x = _this.x, y = _this.y, z = _this.z, w = _this.w;
6593
- return Math.abs(x) <= eps && Math.abs(y) <= eps && Math.abs(z) <= eps && Math.abs(w) <= eps;
7024
+ _proto.dispose = function dispose() {
7025
+ Component.prototype.dispose.call(this);
6594
7026
  };
6595
- /**
6596
- * 向量转数组
6597
- * @returns 数组
6598
- */ _proto.toArray = function toArray() {
6599
- return [
6600
- this.x,
6601
- this.y,
6602
- this.z,
6603
- this.w
6604
- ];
7027
+ return Behaviour;
7028
+ }(Component);
7029
+
7030
+ exports.Animator = /*#__PURE__*/ function(Component) {
7031
+ _inherits(Animator, Component);
7032
+ function Animator() {
7033
+ var _this;
7034
+ _this = Component.apply(this, arguments) || this;
7035
+ /**
7036
+ * @internal
7037
+ */ _this.graph = null;
7038
+ _this.graphAsset = null;
7039
+ return _this;
7040
+ }
7041
+ var _proto = Animator.prototype;
7042
+ _proto.setBool = function setBool(name, value) {
7043
+ if (this.graph) {
7044
+ this.graph.setBool(name, value);
7045
+ }
6605
7046
  };
6606
- _proto.toVector3 = function toVector3() {
6607
- return new Vector3(this.x, this.y, this.z);
7047
+ _proto.setFloat = function setFloat(name, value) {
7048
+ if (this.graph) {
7049
+ this.graph.setFloat(name, value);
7050
+ }
6608
7051
  };
6609
- _proto.fill = function fill(array, offset) {
6610
- if (offset === void 0) offset = 0;
6611
- array[offset] = this.x;
6612
- array[offset + 1] = this.y;
6613
- array[offset + 2] = this.z;
6614
- array[offset + 3] = this.w;
7052
+ _proto.setTrigger = function setTrigger(name) {
7053
+ if (this.graph) {
7054
+ this.graph.setTrigger(name);
7055
+ }
6615
7056
  };
6616
- /**
6617
- * 生成随机向量
6618
- * @returns 向量
6619
- */ _proto.random = function random() {
6620
- this.x = Math.random();
6621
- this.y = Math.random();
6622
- this.z = Math.random();
6623
- this.w = Math.random();
6624
- return this;
7057
+ _proto.resetTrigger = function resetTrigger(name) {
7058
+ if (this.graph) {
7059
+ this.graph.resetTrigger(name);
7060
+ }
6625
7061
  };
6626
- /**
6627
- * 变换矩阵作用于向量
6628
- * @param m - 变换矩阵
6629
- * @param [out] - 输出结果,如果没有设置就直接覆盖当前值
6630
- * @returns 向量
6631
- */ _proto.applyMatrix = function applyMatrix(m, out) {
6632
- return m.transformVector4(this, out);
7062
+ _proto.onStart = function onStart() {
7063
+ if (this.graphAsset) {
7064
+ this.graph = new GraphInstance(this.graphAsset, this.item);
7065
+ }
6633
7066
  };
6634
- /**
6635
- * 通过标量数值创建向量
6636
- * @param num - 数值
6637
- * @returns 向量
6638
- */ Vector4.fromNumber = function fromNumber(num) {
6639
- return new Vector4().setFromNumber(num);
7067
+ _proto.onUpdate = function onUpdate(dt) {
7068
+ if (!this.graph) {
7069
+ return;
7070
+ }
7071
+ var result = this.graph.evaluateGraph(dt / 1000);
7072
+ // Apply transform animation
7073
+ //-------------------------------------------------------------------------
7074
+ var animatedTransforms = this.graph.skeleton.animatedTransforms;
7075
+ for(var i = 0; i < animatedTransforms.length; i++){
7076
+ var position = result.pose.parentSpaceTransforms[i].position;
7077
+ var rotation = result.pose.parentSpaceTransforms[i].rotation;
7078
+ var scale = result.pose.parentSpaceTransforms[i].scale;
7079
+ var euler = result.pose.parentSpaceTransforms[i].euler;
7080
+ animatedTransforms[i].setPosition(position.x, position.y, position.z);
7081
+ animatedTransforms[i].setScale(scale.x, scale.y, scale.z);
7082
+ if (this.graph.skeleton.useEuler) {
7083
+ animatedTransforms[i].setRotation(euler.x, euler.y, euler.z);
7084
+ } else {
7085
+ animatedTransforms[i].setQuaternion(rotation.x, rotation.y, rotation.z, rotation.w);
7086
+ }
7087
+ }
7088
+ // Apply property animation
7089
+ //-------------------------------------------------------------------------
7090
+ var floatAnimatedObjects = this.graph.skeleton.floatAnimatedObjects;
7091
+ for(var i1 = 0; i1 < floatAnimatedObjects.length; i1++){
7092
+ var animatedObject = floatAnimatedObjects[i1];
7093
+ var property = animatedObject.property;
7094
+ animatedObject.target[property] = result.pose.floatPropertyValues[i1];
7095
+ }
7096
+ var colorAnimatedObjects = this.graph.skeleton.colorAnimatedObjects;
7097
+ for(var i2 = 0; i2 < colorAnimatedObjects.length; i2++){
7098
+ var animatedObject1 = colorAnimatedObjects[i2];
7099
+ var property1 = animatedObject1.property;
7100
+ animatedObject1.target[property1] = result.pose.colorPropertyValues[i2];
7101
+ }
6640
7102
  };
6641
- /**
6642
- * 通过数组创建向量
6643
- * @param array - 数组
6644
- * @param [offset=0] - 起始偏移值
6645
- * @returns 向量
6646
- */ Vector4.fromArray = function fromArray(array, offset) {
6647
- if (offset === void 0) offset = 0;
6648
- return new Vector4().setFromArray(array, offset);
7103
+ _proto.fromData = function fromData(data) {
7104
+ this.graphAsset = this.engine.findObject(data.graphAsset);
6649
7105
  };
6650
- return Vector4;
6651
- }();
7106
+ return Animator;
7107
+ }(Component);
7108
+ exports.Animator = __decorate([
7109
+ effectsClass("Animator")
7110
+ ], exports.Animator);
7111
+
6652
7112
  /**
6653
- * 四维向量的常量
6654
- */ Vector4.ONE = new Vector4(1.0, 1.0, 1.0, 1.0);
6655
- Vector4.ZERO = new Vector4(0.0, 0.0, 0.0, 0.0);
7113
+ * 所有渲染组件的基类
7114
+ * @since 2.0.0
7115
+ */ var RendererComponent = /*#__PURE__*/ function(Component) {
7116
+ _inherits(RendererComponent, Component);
7117
+ function RendererComponent() {
7118
+ var _this;
7119
+ _this = Component.apply(this, arguments) || this;
7120
+ _this.materials = [];
7121
+ _this._priority = 0;
7122
+ return _this;
7123
+ }
7124
+ var _proto = RendererComponent.prototype;
7125
+ _proto.render = function render(renderer) {};
7126
+ _proto.onEnable = function onEnable() {
7127
+ var _this_item_composition;
7128
+ (_this_item_composition = this.item.composition) == null ? void 0 : _this_item_composition.renderFrame.addMeshToDefaultRenderPass(this);
7129
+ };
7130
+ _proto.onDisable = function onDisable() {
7131
+ var _this_item_composition;
7132
+ (_this_item_composition = this.item.composition) == null ? void 0 : _this_item_composition.renderFrame.removeMeshFromDefaultRenderPass(this);
7133
+ };
7134
+ _create_class(RendererComponent, [
7135
+ {
7136
+ key: "priority",
7137
+ get: function get() {
7138
+ return this._priority;
7139
+ },
7140
+ set: function set(value) {
7141
+ this._priority = value;
7142
+ }
7143
+ },
7144
+ {
7145
+ key: "material",
7146
+ get: function get() {
7147
+ return this.materials[0];
7148
+ },
7149
+ set: function set(material) {
7150
+ if (this.materials.length === 0) {
7151
+ this.materials.push(material);
7152
+ } else {
7153
+ this.materials[0] = material;
7154
+ }
7155
+ }
7156
+ }
7157
+ ]);
7158
+ return RendererComponent;
7159
+ }(Component);
7160
+ __decorate([
7161
+ serialize()
7162
+ ], RendererComponent.prototype, "materials", void 0);
7163
+ __decorate([
7164
+ serialize()
7165
+ ], RendererComponent.prototype, "_priority", void 0);
6656
7166
 
6657
7167
  /**
6658
7168
  * Mesh 组件
@@ -6781,516 +7291,6 @@ exports.PostProcessVolume = __decorate([
6781
7291
  effectsClass(DataType.PostProcessVolume)
6782
7292
  ], exports.PostProcessVolume);
6783
7293
 
6784
- var Color = /*#__PURE__*/ function() {
6785
- function Color(r, g, b, a) {
6786
- if (r === void 0) r = 0;
6787
- if (g === void 0) g = 0;
6788
- if (b === void 0) b = 0;
6789
- if (a === void 0) a = 0;
6790
- this.r = r;
6791
- this.g = g;
6792
- this.b = b;
6793
- this.a = a;
6794
- }
6795
- var _proto = Color.prototype;
6796
- /**
6797
- * 设置颜色
6798
- * @param r - r 分量
6799
- * @param g - g 分量
6800
- * @param b - b 分量
6801
- * @param a - a 分量
6802
- * @returns
6803
- */ _proto.set = function set(r, g, b, a) {
6804
- this.r = r;
6805
- this.g = g;
6806
- this.b = b;
6807
- this.a = a;
6808
- return this;
6809
- };
6810
- /**
6811
- * 设置零颜色
6812
- * @returns
6813
- */ _proto.setZero = function setZero() {
6814
- this.r = 0;
6815
- this.g = 0;
6816
- this.b = 0;
6817
- this.a = 0;
6818
- return this;
6819
- };
6820
- /**
6821
- * 通过标量数值设置颜色
6822
- * @param num - 数值
6823
- * @returns
6824
- */ _proto.setFromNumber = function setFromNumber(num) {
6825
- this.r = num;
6826
- this.g = num;
6827
- this.b = num;
6828
- this.a = num;
6829
- return this;
6830
- };
6831
- /**
6832
- * 通过Vector4创建颜色
6833
- * @param v - Vector4
6834
- * @returns
6835
- */ _proto.setFromVector4 = function setFromVector4(v) {
6836
- this.r = v.x;
6837
- this.g = v.y;
6838
- this.b = v.z;
6839
- this.a = v.w;
6840
- return this;
6841
- };
6842
- /**
6843
- * 通过数组创建颜色
6844
- * @param array - 数组
6845
- * @param [offset=0] - 起始偏移值
6846
- * @returns
6847
- */ _proto.setFromArray = function setFromArray(array, offset) {
6848
- if (offset === void 0) offset = 0;
6849
- var _array_offset;
6850
- this.r = (_array_offset = array[offset]) != null ? _array_offset : 0;
6851
- var _array_;
6852
- this.g = (_array_ = array[offset + 1]) != null ? _array_ : 0;
6853
- var _array_1;
6854
- this.b = (_array_1 = array[offset + 2]) != null ? _array_1 : 0;
6855
- var _array_2;
6856
- this.a = (_array_2 = array[offset + 3]) != null ? _array_2 : 0;
6857
- return this;
6858
- };
6859
- _proto.setFromHSV = function setFromHSV(hue, saturation, value, alpha) {
6860
- if (alpha === void 0) alpha = 1;
6861
- var chroma = value * saturation;
6862
- var h = hue / 60;
6863
- var x = chroma * (1 - Math.abs(h % 2 - 1));
6864
- var r = 0;
6865
- var g = 0;
6866
- var b = 0;
6867
- if (h >= 0 && h <= 1) {
6868
- r = chroma;
6869
- g = x;
6870
- } else if (h >= 1 && h <= 2) {
6871
- r = x;
6872
- g = chroma;
6873
- } else if (h >= 2 && h <= 3) {
6874
- g = chroma;
6875
- b = x;
6876
- } else if (h >= 3 && h <= 4) {
6877
- g = x;
6878
- b = chroma;
6879
- } else if (h >= 4 && h <= 5) {
6880
- r = x;
6881
- b = chroma;
6882
- } else if (h >= 5 && h <= 6) {
6883
- r = chroma;
6884
- b = x;
6885
- }
6886
- var m = value - chroma;
6887
- return this.set(r + m, g + m, b + m, alpha);
6888
- };
6889
- _proto.setFromHexString = function setFromHexString(hex) {
6890
- if (hex.substring(0, 1) !== "#" || hex.length !== 9 && hex.length !== 7) {
6891
- return this;
6892
- }
6893
- var r = parseInt(hex.substring(1, 3), 16) / 255.0;
6894
- var g = parseInt(hex.substring(3, 5), 16) / 255.0;
6895
- var b = parseInt(hex.substring(5, 7), 16) / 255.0;
6896
- var a = hex.length === 9 ? parseInt(hex.substring(7, 9), 16) / 255.0 : 1.0;
6897
- return this.set(r, g, b, a);
6898
- };
6899
- /**
6900
- * 拷贝颜色
6901
- * @param v - 复制对象
6902
- * @returns 拷贝结果
6903
- */ _proto.copyFrom = function copyFrom(v) {
6904
- this.r = v.r;
6905
- this.g = v.g;
6906
- this.b = v.b;
6907
- this.a = v.a;
6908
- return this;
6909
- };
6910
- /**
6911
- * 克隆颜色
6912
- * @returns 克隆结果
6913
- */ _proto.clone = function clone() {
6914
- return new Color(this.r, this.g, this.b, this.a);
6915
- };
6916
- /**
6917
- * 根据下标设置颜色分量
6918
- * @param index - 下标值
6919
- * @param value - 分量值
6920
- * @returns
6921
- */ _proto.setElement = function setElement(index, value) {
6922
- switch(index){
6923
- case 0:
6924
- this.r = value;
6925
- break;
6926
- case 1:
6927
- this.g = value;
6928
- break;
6929
- case 2:
6930
- this.b = value;
6931
- break;
6932
- case 3:
6933
- this.a = value;
6934
- break;
6935
- default:
6936
- console.error("index is out of range: " + index);
6937
- }
6938
- return this;
6939
- };
6940
- /**
6941
- * 根据下标获取颜色分量
6942
- * @param index - 下标
6943
- * @returns 分量值
6944
- */ _proto.getElement = function getElement(index) {
6945
- switch(index){
6946
- case 0:
6947
- return this.r;
6948
- case 1:
6949
- return this.g;
6950
- case 2:
6951
- return this.b;
6952
- case 3:
6953
- return this.a;
6954
- default:
6955
- console.error("index is out of range: " + index);
6956
- }
6957
- return 0;
6958
- };
6959
- /**
6960
- * 颜色相加
6961
- * @param right - 相加对象,颜色 | 数字
6962
- * @returns 相加结果
6963
- */ _proto.add = function add(right) {
6964
- if (typeof right === "number") {
6965
- this.r += right;
6966
- this.g += right;
6967
- this.b += right;
6968
- this.a += right;
6969
- } else if (_instanceof1(right, Array)) {
6970
- this.r += right[0];
6971
- this.g += right[1];
6972
- this.b += right[2];
6973
- this.a += right[3];
6974
- } else {
6975
- this.r += right.r;
6976
- this.g += right.g;
6977
- this.b += right.b;
6978
- this.a += right.a;
6979
- }
6980
- return this;
6981
- };
6982
- /**
6983
- * 颜色相减
6984
- * @param right - 相减对象,颜色 | 数字
6985
- * @returns 相减结果
6986
- */ _proto.subtract = function subtract(right) {
6987
- if (typeof right === "number") {
6988
- this.r -= right;
6989
- this.g -= right;
6990
- this.b -= right;
6991
- this.a -= right;
6992
- } else if (_instanceof1(right, Array)) {
6993
- this.r -= right[0];
6994
- this.g -= right[1];
6995
- this.b -= right[2];
6996
- this.a -= right[3];
6997
- } else {
6998
- this.r -= right.r;
6999
- this.g -= right.g;
7000
- this.b -= right.b;
7001
- this.a -= right.a;
7002
- }
7003
- return this;
7004
- };
7005
- /**
7006
- * 颜色相乘
7007
- * @param right - 相乘对象,对象 | 数字
7008
- * @returns 颜色
7009
- */ _proto.multiply = function multiply(right) {
7010
- if (typeof right === "number") {
7011
- this.r *= right;
7012
- this.g *= right;
7013
- this.b *= right;
7014
- this.a *= right;
7015
- } else if (_instanceof1(right, Array)) {
7016
- this.r *= right[0];
7017
- this.g *= right[1];
7018
- this.b *= right[2];
7019
- this.a *= right[3];
7020
- } else {
7021
- this.r *= right.r;
7022
- this.g *= right.g;
7023
- this.b *= right.b;
7024
- this.a *= right.a;
7025
- }
7026
- return this;
7027
- };
7028
- /**
7029
- * 颜色相除
7030
- * @param right - 相除对象,对象 | 数字
7031
- * @returns 颜色
7032
- */ _proto.divide = function divide(right) {
7033
- if (typeof right === "number") {
7034
- this.r /= right;
7035
- this.g /= right;
7036
- this.b /= right;
7037
- this.a /= right;
7038
- } else if (_instanceof1(right, Array)) {
7039
- this.r /= right[0];
7040
- this.g /= right[1];
7041
- this.b /= right[2];
7042
- this.a /= right[3];
7043
- } else {
7044
- this.r /= right.r;
7045
- this.g /= right.g;
7046
- this.b /= right.b;
7047
- this.a /= right.a;
7048
- }
7049
- return this;
7050
- };
7051
- /**
7052
- * 颜色缩放
7053
- * @param v - 数字
7054
- * @returns 缩放结果
7055
- */ _proto.scale = function scale(v) {
7056
- this.r *= v;
7057
- this.g *= v;
7058
- this.b *= v;
7059
- this.a *= v;
7060
- return this;
7061
- };
7062
- /**
7063
- * 颜色求最小值
7064
- * @param v - 颜色或数值
7065
- * @returns 最小值
7066
- */ _proto.min = function min(v) {
7067
- if (typeof v === "number") {
7068
- this.r = Math.min(this.r, v);
7069
- this.g = Math.min(this.g, v);
7070
- this.b = Math.min(this.b, v);
7071
- this.a = Math.min(this.a, v);
7072
- } else {
7073
- this.r = Math.min(this.r, v.r);
7074
- this.g = Math.min(this.g, v.g);
7075
- this.b = Math.min(this.b, v.b);
7076
- this.a = Math.min(this.a, v.a);
7077
- }
7078
- return this;
7079
- };
7080
- /**
7081
- * 颜色求最大值
7082
- * @param v - 颜色或数值
7083
- * @returns 最大值
7084
- */ _proto.max = function max(v) {
7085
- if (typeof v === "number") {
7086
- this.r = Math.max(this.r, v);
7087
- this.g = Math.max(this.g, v);
7088
- this.b = Math.max(this.b, v);
7089
- this.a = Math.max(this.a, v);
7090
- } else {
7091
- this.r = Math.max(this.r, v.r);
7092
- this.g = Math.max(this.g, v.g);
7093
- this.b = Math.max(this.b, v.b);
7094
- this.a = Math.max(this.a, v.a);
7095
- }
7096
- return this;
7097
- };
7098
- /**
7099
- * 颜色阈值约束
7100
- * @param min - 最小值
7101
- * @param max - 最大值
7102
- * @returns 颜色
7103
- */ _proto.clamp = function clamp(min, max) {
7104
- return this.max(min).min(max);
7105
- };
7106
- /**
7107
- * 颜色求线性插值
7108
- * @param v - 颜色
7109
- * @param alpha - 插值比例
7110
- * @returns 插值结果
7111
- */ _proto.lerp = function lerp(v, alpha) {
7112
- this.r += (v.r - this.r) * alpha;
7113
- this.g += (v.g - this.g) * alpha;
7114
- this.b += (v.b - this.b) * alpha;
7115
- this.a += (v.a - this.a) * alpha;
7116
- return this;
7117
- };
7118
- /**
7119
- * 计算颜色亮度值
7120
- * @returns 亮度值
7121
- */ _proto.luminance = function luminance() {
7122
- return this.r * 0.3 + this.g * 0.59 + this.b * 0.11;
7123
- };
7124
- /**
7125
- * 颜色判等
7126
- * @param v - 颜色
7127
- * @returns 判等结果
7128
- */ _proto.equals = function equals(v) {
7129
- return v.r === this.r && v.g === this.g && v.b === this.b && v.a === this.a;
7130
- };
7131
- _proto.toLinear = function toLinear() {
7132
- this.r = Color.gammaToLinear(this.r);
7133
- this.g = Color.gammaToLinear(this.g);
7134
- this.b = Color.gammaToLinear(this.b);
7135
- return this;
7136
- };
7137
- _proto.toGamma = function toGamma() {
7138
- this.r = Color.linearToGamma(this.r);
7139
- this.g = Color.linearToGamma(this.g);
7140
- this.b = Color.linearToGamma(this.b);
7141
- return this;
7142
- };
7143
- /**
7144
- * 颜色转数组
7145
- * @returns 数组
7146
- */ _proto.toArray = function toArray() {
7147
- return [
7148
- this.r,
7149
- this.g,
7150
- this.b,
7151
- this.a
7152
- ];
7153
- };
7154
- _proto.toVector4 = function toVector4() {
7155
- return new Vector4(this.r, this.g, this.b, this.a);
7156
- };
7157
- /**
7158
- * RGB 颜色空间转 HSV
7159
- * @param result HSV 值
7160
- */ _proto.toHSV = function toHSV() {
7161
- var _this = this, r = _this.r, g = _this.g, b = _this.b, a = _this.a;
7162
- var max = Math.max(r, g, b);
7163
- var min = Math.min(r, g, b);
7164
- var v = max;
7165
- var dm = max - min;
7166
- var h = 0;
7167
- var s = 0;
7168
- if (max !== 0) {
7169
- s = dm / max;
7170
- }
7171
- if (max != min) {
7172
- if (max == r) {
7173
- h = (g - b) / dm;
7174
- if (g < b) {
7175
- h += 6;
7176
- }
7177
- } else if (max == g) {
7178
- h = (b - r) / dm + 2;
7179
- } else if (max == b) {
7180
- h = (r - g) / dm + 4;
7181
- }
7182
- h *= 60;
7183
- }
7184
- return new Color(h, s, v, a);
7185
- };
7186
- _proto.toHexString = function toHexString(includeAlpha) {
7187
- if (includeAlpha === void 0) includeAlpha = true;
7188
- var R = Color.ToHex(Math.round(this.r * 255));
7189
- var G = Color.ToHex(Math.round(this.g * 255));
7190
- var B = Color.ToHex(Math.round(this.b * 255));
7191
- var A = Color.ToHex(Math.round(this.a * 255));
7192
- if (includeAlpha) {
7193
- return "#" + R + G + B + A;
7194
- } else {
7195
- return "#" + R + G + B;
7196
- }
7197
- };
7198
- _proto.fill = function fill(array, offset) {
7199
- if (offset === void 0) offset = 0;
7200
- array[offset] = this.r;
7201
- array[offset + 1] = this.g;
7202
- array[offset + 2] = this.b;
7203
- array[offset + 3] = this.a;
7204
- };
7205
- /**
7206
- * 通过标量数值创建颜色
7207
- * @param num - 数值
7208
- * @returns
7209
- */ Color.fromNumber = function fromNumber(num) {
7210
- return new Color().setFromNumber(num);
7211
- };
7212
- /**
7213
- * 通过数组创建颜色
7214
- * @param array - 数组
7215
- * @param [offset=0] - 起始偏移值
7216
- * @returns
7217
- */ Color.fromArray = function fromArray(array, offset) {
7218
- if (offset === void 0) offset = 0;
7219
- return new Color().setFromArray(array, offset);
7220
- };
7221
- /**
7222
- * 通过 hex 字符串创建颜色
7223
- * @param hex - hex 字符串
7224
- * @returns
7225
- */ Color.fromHexString = function fromHexString(hex) {
7226
- return new Color().setFromHexString(hex);
7227
- };
7228
- Color.fromHSV = function fromHSV(hue, saturation, value, alpha) {
7229
- if (alpha === void 0) alpha = 1;
7230
- return new Color().setFromHSV(hue, saturation, value, alpha);
7231
- };
7232
- /**
7233
- * 颜色值从 Gamma 空间转到线性空间
7234
- * @param v - Gamma 空间颜色值
7235
- * @returns 线性空间颜色值
7236
- */ Color.gammaToLinear = function gammaToLinear(v) {
7237
- if (v <= 0.0) {
7238
- return 0.0;
7239
- } else if (v <= 0.04045) {
7240
- return v / 12.92;
7241
- } else if (v < 1.0) {
7242
- return Math.pow((v + 0.055) / 1.055, 2.4);
7243
- } else {
7244
- return Math.pow(v, 2.4);
7245
- }
7246
- };
7247
- /**
7248
- * 颜色值从线性空间转到 Gamma 空间
7249
- * @param value - 线性空间颜色值
7250
- * @returns Gamma 空间颜色值
7251
- */ Color.linearToGamma = function linearToGamma(value) {
7252
- if (value <= 0.0) {
7253
- return 0.0;
7254
- } else if (value < 0.0031308) {
7255
- return 12.92 * value;
7256
- } else if (value < 1.0) {
7257
- return 1.055 * Math.pow(value, 0.41666) - 0.055;
7258
- } else {
7259
- return Math.pow(value, 0.41666);
7260
- }
7261
- };
7262
- Color.ToHex = function ToHex(i) {
7263
- var str = i.toString(16);
7264
- if (i <= 15) {
7265
- return ("0" + str).toUpperCase();
7266
- }
7267
- return str.toUpperCase();
7268
- };
7269
- return Color;
7270
- }();
7271
- /**
7272
- * 颜色的常量
7273
- */ Color.BLACK = new Color(0, 0, 0, 1) // 纯黑色
7274
- ;
7275
- Color.BLUE = new Color(0, 0, 1, 1) // 纯蓝色
7276
- ;
7277
- Color.CLEAR = new Color(0, 0, 0, 0) // 完全透明
7278
- ;
7279
- Color.CYAN = new Color(0, 1, 1, 1) // 青色
7280
- ;
7281
- Color.GRAY = new Color(0.5, 0.5, 0.5, 1) // 灰色
7282
- ;
7283
- Color.GREEN = new Color(0, 1, 0, 1) // 纯绿色
7284
- ;
7285
- Color.MAGENTA = new Color(1, 0, 1, 1) // 洋红色
7286
- ;
7287
- Color.RED = new Color(1, 0, 0, 1) // 纯红色
7288
- ;
7289
- Color.WHITE = new Color(1, 1, 1, 1) // 纯白色
7290
- ;
7291
- Color.YELLOW = new Color(1, 0.92, 0.016, 1) // 黄色
7292
- ;
7293
-
7294
7294
  /**
7295
7295
  * 四阶矩阵(列优先矩阵)
7296
7296
  */ var Matrix4 = /*#__PURE__*/ function() {
@@ -24301,7 +24301,7 @@ var LateUpdateTickData = /*#__PURE__*/ function(TickData) {
24301
24301
  return (_this_renderer = this.renderer) == null ? void 0 : _this_renderer.engine;
24302
24302
  };
24303
24303
  /**
24304
- * Item 求交测试,返回求交结果列表,x 和 y 是归一化到[-1, 1]区间的值,原点在左上角
24304
+ * Item 求交测试,返回求交结果列表,x 和 y 是归一化到[-1, 1]区间的值,x 向右,y 向上
24305
24305
  * @param x - 鼠标或触点的 x,已经归一化到[-1, 1]
24306
24306
  * @param y - 鼠标或触点的 y,已经归一化到[-1, 1]
24307
24307
  * @param force - 是否强制求交,没有交互信息的 Item 也要进行求交测试
@@ -31147,7 +31147,7 @@ function getStandardSpriteContent(sprite, transform) {
31147
31147
  return ret;
31148
31148
  }
31149
31149
 
31150
- var version$1 = "2.6.7";
31150
+ var version$1 = "2.6.8";
31151
31151
  var v0 = /^(\d+)\.(\d+)\.(\d+)(-(\w+)\.\d+)?$/;
31152
31152
  var standardVersion = /^(\d+)\.(\d+)$/;
31153
31153
  var reverseParticle = false;
@@ -34401,7 +34401,7 @@ registerPlugin("sprite", SpriteLoader, exports.VFXItem);
34401
34401
  registerPlugin("particle", ParticleLoader, exports.VFXItem);
34402
34402
  registerPlugin("cal", CalculateLoader, exports.VFXItem);
34403
34403
  registerPlugin("interact", InteractLoader, exports.VFXItem);
34404
- var version = "2.6.7";
34404
+ var version = "2.6.8";
34405
34405
  logger.info("Core version: " + version + ".");
34406
34406
 
34407
34407
  exports.AbstractPlugin = AbstractPlugin;