@galacean/effects-plugin-model 2.1.0-alpha.7 → 2.1.0-alpha.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/alipay.js +65 -598
- package/dist/alipay.js.map +1 -1
- package/dist/alipay.mjs +66 -594
- package/dist/alipay.mjs.map +1 -1
- package/dist/douyin.js +65 -598
- package/dist/douyin.js.map +1 -1
- package/dist/douyin.mjs +66 -594
- package/dist/douyin.mjs.map +1 -1
- package/dist/gltf/loader-impl.d.ts +6 -12
- package/dist/gltf/protocol.d.ts +2 -3
- package/dist/index.d.ts +0 -1
- package/dist/index.js +66 -599
- package/dist/index.js.map +1 -1
- package/dist/index.min.js +2 -2
- package/dist/index.min.js.map +1 -1
- package/dist/index.mjs +67 -595
- package/dist/index.mjs.map +1 -1
- package/dist/loader.mjs +66 -872
- package/dist/loader.mjs.map +1 -1
- package/dist/plugin/index.d.ts +1 -2
- package/dist/plugin/model-tree-component.d.ts +26 -0
- package/dist/runtime/animation.d.ts +0 -131
- package/dist/weapp.js +65 -598
- package/dist/weapp.js.map +1 -1
- package/dist/weapp.mjs +66 -594
- package/dist/weapp.mjs.map +1 -1
- package/package.json +4 -4
- package/dist/plugin/model-tree-item.d.ts +0 -132
- package/dist/plugin/model-tree-plugin.d.ts +0 -14
package/dist/loader.mjs
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Description: Galacean Effects player model plugin
|
|
4
4
|
* Author: Ant Group CO., Ltd.
|
|
5
5
|
* Contributors: 飂兮
|
|
6
|
-
* Version: v2.1.0-alpha.
|
|
6
|
+
* Version: v2.1.0-alpha.9
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
import * as EFFECTS from '@galacean/effects';
|
|
@@ -400,284 +400,6 @@ function _inherits(subClass, superClass) {
|
|
|
400
400
|
if (superClass) _set_prototype_of(subClass, superClass);
|
|
401
401
|
}
|
|
402
402
|
|
|
403
|
-
var InterpolationSampler = /*#__PURE__*/ function() {
|
|
404
|
-
function InterpolationSampler(time, data, componentCount) {
|
|
405
|
-
this.time = time;
|
|
406
|
-
this.data = data;
|
|
407
|
-
this.componentCount = componentCount;
|
|
408
|
-
this.cachedIndex = 0;
|
|
409
|
-
}
|
|
410
|
-
var _proto = InterpolationSampler.prototype;
|
|
411
|
-
/**
|
|
412
|
-
* 计算当前 t 时刻的插值
|
|
413
|
-
* @param t - 当前时间
|
|
414
|
-
* @returns 插值结果
|
|
415
|
-
*/ _proto.evaluate = function evaluate(t) {
|
|
416
|
-
var pp = this.time;
|
|
417
|
-
var i1 = this.cachedIndex;
|
|
418
|
-
var t1 = pp[i1];
|
|
419
|
-
var t0 = pp[i1 - 1];
|
|
420
|
-
validate_interval: {
|
|
421
|
-
seek: {
|
|
422
|
-
var right;
|
|
423
|
-
linear_scan: {
|
|
424
|
-
//- See http://jsperf.com/comparison-to-undefined/3
|
|
425
|
-
//- slower code:
|
|
426
|
-
//-
|
|
427
|
-
//- if ( t >= t1 || t1 === undefined ) {
|
|
428
|
-
forward_scan: if (!(t < t1)) {
|
|
429
|
-
for(var giveUpAt = i1 + 2;;){
|
|
430
|
-
if (t1 === undefined) {
|
|
431
|
-
if (t < t0) {
|
|
432
|
-
break forward_scan;
|
|
433
|
-
}
|
|
434
|
-
// after end
|
|
435
|
-
i1 = pp.length;
|
|
436
|
-
this.cachedIndex = i1;
|
|
437
|
-
return this.copySampleValue(i1 - 1);
|
|
438
|
-
}
|
|
439
|
-
if (i1 === giveUpAt) {
|
|
440
|
-
break;
|
|
441
|
-
} // this loop
|
|
442
|
-
t0 = t1;
|
|
443
|
-
t1 = pp[++i1];
|
|
444
|
-
if (t < t1) {
|
|
445
|
-
break seek;
|
|
446
|
-
}
|
|
447
|
-
}
|
|
448
|
-
// prepare binary search on the right side of the index
|
|
449
|
-
right = pp.length;
|
|
450
|
-
break linear_scan;
|
|
451
|
-
}
|
|
452
|
-
//- slower code:
|
|
453
|
-
//- if ( t < t0 || t0 === undefined ) {
|
|
454
|
-
if (!(t >= t0)) {
|
|
455
|
-
// looping?
|
|
456
|
-
var t1global = pp[1];
|
|
457
|
-
if (t < t1global) {
|
|
458
|
-
i1 = 2; // + 1, using the scan for the details
|
|
459
|
-
t0 = t1global;
|
|
460
|
-
}
|
|
461
|
-
// linear reverse scan
|
|
462
|
-
for(var giveUpAt1 = i1 - 2;;){
|
|
463
|
-
if (t0 === undefined) {
|
|
464
|
-
// before start
|
|
465
|
-
this.cachedIndex = 0;
|
|
466
|
-
return this.copySampleValue(0);
|
|
467
|
-
}
|
|
468
|
-
if (i1 === giveUpAt1) {
|
|
469
|
-
break;
|
|
470
|
-
} // this loop
|
|
471
|
-
t1 = t0;
|
|
472
|
-
t0 = pp[--i1 - 1];
|
|
473
|
-
if (t >= t0) {
|
|
474
|
-
break seek;
|
|
475
|
-
}
|
|
476
|
-
}
|
|
477
|
-
// prepare binary search on the left side of the index
|
|
478
|
-
right = i1;
|
|
479
|
-
i1 = 0;
|
|
480
|
-
break linear_scan;
|
|
481
|
-
}
|
|
482
|
-
break validate_interval;
|
|
483
|
-
} // linear scan
|
|
484
|
-
// binary search
|
|
485
|
-
while(i1 < right){
|
|
486
|
-
var mid = i1 + right >>> 1;
|
|
487
|
-
if (t < pp[mid]) {
|
|
488
|
-
right = mid;
|
|
489
|
-
} else {
|
|
490
|
-
i1 = mid + 1;
|
|
491
|
-
}
|
|
492
|
-
}
|
|
493
|
-
t1 = pp[i1];
|
|
494
|
-
t0 = pp[i1 - 1];
|
|
495
|
-
// check boundary cases, again
|
|
496
|
-
if (t0 === undefined) {
|
|
497
|
-
this.cachedIndex = 0;
|
|
498
|
-
return this.copySampleValue(0);
|
|
499
|
-
}
|
|
500
|
-
if (t1 === undefined) {
|
|
501
|
-
i1 = pp.length;
|
|
502
|
-
this.cachedIndex = i1;
|
|
503
|
-
return this.copySampleValue(i1 - 1);
|
|
504
|
-
}
|
|
505
|
-
} // seek
|
|
506
|
-
this.cachedIndex = i1;
|
|
507
|
-
this.intervalChanged(i1, t0, t1);
|
|
508
|
-
} // validate_interval
|
|
509
|
-
return this.interpolate(i1, t0, t, t1);
|
|
510
|
-
};
|
|
511
|
-
/**
|
|
512
|
-
* 销毁
|
|
513
|
-
*/ _proto.dispose = function dispose() {
|
|
514
|
-
// @ts-expect-error
|
|
515
|
-
this.time = undefined;
|
|
516
|
-
// @ts-expect-error
|
|
517
|
-
this.data = undefined;
|
|
518
|
-
};
|
|
519
|
-
_proto.copySampleValue = function copySampleValue(index) {
|
|
520
|
-
// copies a sample value to the result buffer
|
|
521
|
-
var values = this.data;
|
|
522
|
-
var stride = this.componentCount;
|
|
523
|
-
var offset = index * stride;
|
|
524
|
-
var result = new Float32Array(stride);
|
|
525
|
-
for(var i = 0; i !== stride; ++i){
|
|
526
|
-
result[i] = values[offset + i];
|
|
527
|
-
}
|
|
528
|
-
return result;
|
|
529
|
-
};
|
|
530
|
-
return InterpolationSampler;
|
|
531
|
-
}();
|
|
532
|
-
var LinearSampler = /*#__PURE__*/ function(InterpolationSampler) {
|
|
533
|
-
_inherits(LinearSampler, InterpolationSampler);
|
|
534
|
-
function LinearSampler(time, data, size) {
|
|
535
|
-
return InterpolationSampler.call(this, time, data, size);
|
|
536
|
-
}
|
|
537
|
-
var _proto = LinearSampler.prototype;
|
|
538
|
-
_proto.intervalChanged = function intervalChanged(i1, t0, t1) {};
|
|
539
|
-
_proto.interpolate = function interpolate(i1, t0, t, t1) {
|
|
540
|
-
var values = this.data;
|
|
541
|
-
var _this_componentCount;
|
|
542
|
-
var stride = (_this_componentCount = this.componentCount) != null ? _this_componentCount : 1;
|
|
543
|
-
var offset1 = i1 * stride;
|
|
544
|
-
var offset0 = offset1 - stride;
|
|
545
|
-
var weight1 = (t - t0) / (t1 - t0);
|
|
546
|
-
var weight0 = 1 - weight1;
|
|
547
|
-
var result = new Float32Array(stride);
|
|
548
|
-
for(var i = 0; i !== stride; ++i){
|
|
549
|
-
result[i] = values[offset0 + i] * weight0 + values[offset1 + i] * weight1;
|
|
550
|
-
}
|
|
551
|
-
return result;
|
|
552
|
-
};
|
|
553
|
-
return LinearSampler;
|
|
554
|
-
}(InterpolationSampler);
|
|
555
|
-
var DiscreteSampler = /*#__PURE__*/ function(InterpolationSampler) {
|
|
556
|
-
_inherits(DiscreteSampler, InterpolationSampler);
|
|
557
|
-
function DiscreteSampler(time, data, size) {
|
|
558
|
-
return InterpolationSampler.call(this, time, data, size);
|
|
559
|
-
}
|
|
560
|
-
var _proto = DiscreteSampler.prototype;
|
|
561
|
-
_proto.intervalChanged = function intervalChanged(i1, t0, t1) {};
|
|
562
|
-
_proto.interpolate = function interpolate(i1, t0, t, t1) {
|
|
563
|
-
var values = this.data;
|
|
564
|
-
var _this_componentCount;
|
|
565
|
-
var stride = (_this_componentCount = this.componentCount) != null ? _this_componentCount : 1;
|
|
566
|
-
var offset = (i1 - 1) * stride;
|
|
567
|
-
var result = new Float32Array(stride);
|
|
568
|
-
for(var i = 0; i !== stride; ++i){
|
|
569
|
-
result[i] = values[offset + i];
|
|
570
|
-
}
|
|
571
|
-
return result;
|
|
572
|
-
};
|
|
573
|
-
return DiscreteSampler;
|
|
574
|
-
}(InterpolationSampler);
|
|
575
|
-
var QuaternionInner = /*#__PURE__*/ function() {
|
|
576
|
-
function QuaternionInner() {}
|
|
577
|
-
QuaternionInner.slerpFlat = function slerpFlat(dst, dstOffset, src0, srcOffset0, src1, srcOffset1, t) {
|
|
578
|
-
// fuzz-free, array-based Quaternion SLERP operation
|
|
579
|
-
var x0 = src0[srcOffset0 + 0];
|
|
580
|
-
var y0 = src0[srcOffset0 + 1];
|
|
581
|
-
var z0 = src0[srcOffset0 + 2];
|
|
582
|
-
var w0 = src0[srcOffset0 + 3];
|
|
583
|
-
var x1 = src1[srcOffset1 + 0];
|
|
584
|
-
var y1 = src1[srcOffset1 + 1];
|
|
585
|
-
var z1 = src1[srcOffset1 + 2];
|
|
586
|
-
var w1 = src1[srcOffset1 + 3];
|
|
587
|
-
if (t === 0) {
|
|
588
|
-
dst[dstOffset + 0] = x0;
|
|
589
|
-
dst[dstOffset + 1] = y0;
|
|
590
|
-
dst[dstOffset + 2] = z0;
|
|
591
|
-
dst[dstOffset + 3] = w0;
|
|
592
|
-
return;
|
|
593
|
-
}
|
|
594
|
-
if (t === 1) {
|
|
595
|
-
dst[dstOffset + 0] = x1;
|
|
596
|
-
dst[dstOffset + 1] = y1;
|
|
597
|
-
dst[dstOffset + 2] = z1;
|
|
598
|
-
dst[dstOffset + 3] = w1;
|
|
599
|
-
return;
|
|
600
|
-
}
|
|
601
|
-
if (w0 !== w1 || x0 !== x1 || y0 !== y1 || z0 !== z1) {
|
|
602
|
-
var s = 1 - t;
|
|
603
|
-
var cos = x0 * x1 + y0 * y1 + z0 * z1 + w0 * w1;
|
|
604
|
-
var dir = cos >= 0 ? 1 : -1;
|
|
605
|
-
var sqrSin = 1 - cos * cos;
|
|
606
|
-
// Skip the Slerp for tiny steps to avoid numeric problems:
|
|
607
|
-
if (sqrSin > Number.EPSILON) {
|
|
608
|
-
var sin = Math.sqrt(sqrSin);
|
|
609
|
-
var len = Math.atan2(sin, cos * dir);
|
|
610
|
-
s = Math.sin(s * len) / sin;
|
|
611
|
-
t = Math.sin(t * len) / sin;
|
|
612
|
-
}
|
|
613
|
-
var tDir = t * dir;
|
|
614
|
-
x0 = x0 * s + x1 * tDir;
|
|
615
|
-
y0 = y0 * s + y1 * tDir;
|
|
616
|
-
z0 = z0 * s + z1 * tDir;
|
|
617
|
-
w0 = w0 * s + w1 * tDir;
|
|
618
|
-
// Normalize in case we just did a lerp:
|
|
619
|
-
if (s === 1 - t) {
|
|
620
|
-
var f = 1 / Math.sqrt(x0 * x0 + y0 * y0 + z0 * z0 + w0 * w0);
|
|
621
|
-
x0 *= f;
|
|
622
|
-
y0 *= f;
|
|
623
|
-
z0 *= f;
|
|
624
|
-
w0 *= f;
|
|
625
|
-
}
|
|
626
|
-
}
|
|
627
|
-
dst[dstOffset] = x0;
|
|
628
|
-
dst[dstOffset + 1] = y0;
|
|
629
|
-
dst[dstOffset + 2] = z0;
|
|
630
|
-
dst[dstOffset + 3] = w0;
|
|
631
|
-
};
|
|
632
|
-
return QuaternionInner;
|
|
633
|
-
}();
|
|
634
|
-
var QuaternionLinearSampler = /*#__PURE__*/ function(InterpolationSampler) {
|
|
635
|
-
_inherits(QuaternionLinearSampler, InterpolationSampler);
|
|
636
|
-
function QuaternionLinearSampler(time, data, size) {
|
|
637
|
-
return InterpolationSampler.call(this, time, data, size);
|
|
638
|
-
}
|
|
639
|
-
var _proto = QuaternionLinearSampler.prototype;
|
|
640
|
-
_proto.intervalChanged = function intervalChanged(i1, t0, t1) {};
|
|
641
|
-
_proto.interpolate = function interpolate(i1, t0, t, t1) {
|
|
642
|
-
var values = this.data;
|
|
643
|
-
var _this_componentCount;
|
|
644
|
-
var stride = (_this_componentCount = this.componentCount) != null ? _this_componentCount : 1;
|
|
645
|
-
var alpha = (t - t0) / (t1 - t0);
|
|
646
|
-
var offset = i1 * stride;
|
|
647
|
-
var result = new Float32Array(stride);
|
|
648
|
-
for(var end = offset + stride; offset !== end; offset += 4){
|
|
649
|
-
QuaternionInner.slerpFlat(result, 0, values, offset - stride, values, offset, alpha);
|
|
650
|
-
}
|
|
651
|
-
return result;
|
|
652
|
-
};
|
|
653
|
-
return QuaternionLinearSampler;
|
|
654
|
-
}(InterpolationSampler);
|
|
655
|
-
/**
|
|
656
|
-
* 创建动画采样器,支持线性和跳变两种模式,类别上支持平移、旋转和缩放
|
|
657
|
-
* @param type - 动画类型,线性和跳变
|
|
658
|
-
* @param times - 时间点数组
|
|
659
|
-
* @param data - 关键帧数组
|
|
660
|
-
* @param size - 数据分量
|
|
661
|
-
* @param path - 动画类别,平移、旋转和缩放
|
|
662
|
-
* @returns 动画采样器
|
|
663
|
-
*/ function createAnimationSampler(type, times, data, size, path) {
|
|
664
|
-
switch(type){
|
|
665
|
-
case "LINEAR":
|
|
666
|
-
if (path === "rotation") {
|
|
667
|
-
return new QuaternionLinearSampler(times, data, size);
|
|
668
|
-
} else {
|
|
669
|
-
return new LinearSampler(times, data, size);
|
|
670
|
-
}
|
|
671
|
-
case "STEP":
|
|
672
|
-
return new DiscreteSampler(times, data, size);
|
|
673
|
-
case "CUBICSPLINE":
|
|
674
|
-
// FIXME: support cubic spline
|
|
675
|
-
return new LinearSampler(times, data, size);
|
|
676
|
-
default:
|
|
677
|
-
return new LinearSampler(times, data, size);
|
|
678
|
-
}
|
|
679
|
-
}
|
|
680
|
-
|
|
681
403
|
function _defineProperties(target, props) {
|
|
682
404
|
for(var i = 0; i < props.length; i++){
|
|
683
405
|
var descriptor = props[i];
|
|
@@ -1226,7 +948,7 @@ var objectIndex = 1;
|
|
|
1226
948
|
|
|
1227
949
|
var primitiveVert = "precision highp float;\n#define FEATURES\n#include <animation.vert.glsl>\nattribute vec4 aPos;varying vec3 v_Position;\n#ifdef HAS_NORMALS\nattribute vec4 aNormal;\n#endif\n#ifdef HAS_TANGENTS\nattribute vec4 aTangent;\n#endif\n#ifdef HAS_NORMALS\n#ifdef HAS_TANGENTS\nvarying mat3 v_TBN;\n#else\nvarying vec3 v_Normal;\n#endif\n#endif\n#ifdef HAS_UV_SET1\nattribute vec2 aUV;\n#endif\n#ifdef HAS_UV_SET2\nattribute vec2 aUV2;\n#endif\nvarying vec2 v_UVCoord1;\n#ifdef HAS_UV_SET2\nvarying vec2 v_UVCoord2;\n#endif\n#ifdef HAS_VERTEX_COLOR_VEC3\nattribute vec3 aColor;varying vec3 v_Color;\n#endif\n#ifdef HAS_VERTEX_COLOR_VEC4\nattribute vec4 aColor;varying vec4 v_Color;\n#endif\nuniform mat4 effects_MatrixVP;uniform mat4 effects_ObjectToWorld;uniform mat4 _NormalMatrix;\n#ifdef EDITOR_TRANSFORM\nuniform vec4 uEditorTransform;\n#endif\n#ifdef USE_SHADOW_MAPPING\nuniform mat4 _LightViewProjectionMatrix;uniform float _DeltaSceneSize;varying vec4 v_PositionLightSpace;varying vec4 v_dPositionLightSpace;\n#endif\nvec4 getPosition(){vec4 pos=vec4(aPos.xyz,1.0);\n#ifdef USE_MORPHING\npos+=getTargetPosition();\n#endif\n#ifdef USE_SKINNING\npos=getSkinningMatrix()*pos;\n#endif\nreturn pos;}\n#ifdef HAS_NORMALS\nvec4 getNormal(){vec4 normal=aNormal;\n#ifdef USE_MORPHING\nnormal+=getTargetNormal();\n#endif\n#ifdef USE_SKINNING\nnormal=getSkinningNormalMatrix()*normal;\n#endif\nreturn normalize(normal);}\n#endif\n#ifdef HAS_TANGENTS\nvec4 getTangent(){vec4 tangent=aTangent;\n#ifdef USE_MORPHING\ntangent+=getTargetTangent();\n#endif\n#ifdef USE_SKINNING\ntangent=getSkinningMatrix()*tangent;\n#endif\nreturn normalize(tangent);}\n#endif\nvoid main(){vec4 pos=effects_ObjectToWorld*getPosition();v_Position=vec3(pos.xyz)/pos.w;\n#ifdef HAS_NORMALS\n#ifdef HAS_TANGENTS\nvec4 tangent=getTangent();vec3 normalW=normalize(vec3(_NormalMatrix*vec4(getNormal().xyz,0.0)));vec3 tangentW=normalize(vec3(effects_ObjectToWorld*vec4(tangent.xyz,0.0)));vec3 bitangentW=cross(normalW,tangentW)*tangent.w;v_TBN=mat3(tangentW,bitangentW,normalW);\n#else\nv_Normal=normalize(vec3(_NormalMatrix*vec4(getNormal().xyz,0.0)));\n#endif\n#endif\nv_UVCoord1=vec2(0.0,0.0);\n#ifdef HAS_UV_SET1\nv_UVCoord1=aUV;\n#endif\n#ifdef HAS_UV_SET2\nv_UVCoord2=aUV2;\n#endif\n#if defined(HAS_VERTEX_COLOR_VEC3) || defined(HAS_VERTEX_COLOR_VEC4)\nv_Color=aColor;\n#endif\n#ifdef USE_SHADOW_MAPPING\nv_PositionLightSpace=_LightViewProjectionMatrix*pos;vec3 dpos=vec3(_DeltaSceneSize);v_dPositionLightSpace=_LightViewProjectionMatrix*(pos+vec4(dpos,0));\n#endif\ngl_Position=effects_MatrixVP*pos;\n#ifdef EDITOR_TRANSFORM\ngl_Position=vec4(gl_Position.xy*uEditorTransform.xy+uEditorTransform.zw*gl_Position.w,gl_Position.zw);\n#endif\n}";
|
|
1228
950
|
|
|
1229
|
-
var metallicRoughnessFrag = "\n#define FEATURES\n#extension GL_OES_standard_derivatives : enable\n#if defined(USE_TEX_LOD)\n#extension GL_EXT_shader_texture_lod : enable\n#endif\n#ifdef USE_HDR\n#extension GL_OES_texture_float : enable\n#extension GL_OES_texture_float_linear : enable\n#endif\n#ifdef GL_FRAGMENT_PRECISION_HIGH\nprecision highp float;\n#else\nprecision mediump float;\n#endif\n#include <extensions.frag.glsl>\n#include <tone-mapping.frag.glsl>\n#include <textures.vert.glsl>\n#include <functions.frag.glsl>\n#include <shadow-common.vert.glsl>\n#include <shadow.frag.glsl>\nstruct Light{vec3 direction;float range;vec3 color;float intensity;vec3 position;float innerConeCos;float outerConeCos;int type;vec2 padding;};const int LightType_Directional=0;const int LightType_Point=1;const int LightType_Spot=2;const int LightType_Ambient=3;\n#ifdef USE_PUNCTUAL\nuniform Light _Lights[LIGHT_COUNT];\n#endif\n#if defined(MATERIAL_SPECULARGLOSSINESS) || defined(MATERIAL_METALLICROUGHNESS)\nuniform float _MetallicFactor;uniform float _RoughnessFactor;uniform vec4 _BaseColorFactor;\n#endif\n#ifdef MATERIAL_SPECULARGLOSSINESS\nuniform vec3 _SpecularFactor;uniform vec4 _DiffuseFactor;uniform float _GlossinessFactor;\n#endif\n#ifdef ALPHAMODE_MASK\nuniform float _AlphaCutoff;\n#endif\n#ifdef ADD_FOG\nuniform vec4 _FogColor;\n#ifdef LINEAR_FOG\nuniform float _FogNear;uniform float _FogFar;\n#endif\n#ifdef EXP_FOG\nuniform float _FogDensity;\n#endif\n#endif\n#ifdef PREVIEW_BORDER\nuniform vec4 uPreviewColor;\n#endif\nuniform vec3 _Camera;uniform int _MipCount;struct MaterialInfo{float perceptualRoughness;vec3 reflectance0;float alphaRoughness;vec3 diffuseColor;vec3 reflectance90;vec3 specularColor;};\n#ifdef ADD_FOG\nvec3 getMixFogColor(vec3 baseColor){vec3 distance=_Camera-v_Position;float fogAmount=0.0;\n#ifdef LINEAR_FOG\nfogAmount=smoothstep(_FogNear,_FogFar,distance[2]);\n#endif\n#ifdef EXP_FOG\n#define LOG2 1.442695\nfogAmount=1.-exp2(-_FogDensity*_FogDensity*distance[2]*distance[2]*LOG2);fogAmount=clamp(fogAmount,0.,1.);\n#endif\nvec3 mixColor=baseColor.rgb+(vec3(_FogColor)-baseColor.rgb)*fogAmount;return mixColor;}\n#endif\n#ifdef IRRADIANCE_COEFFICIENTS\nvec3 getIrradiance(vec3 norm,SHCoefficients c){float x=norm.x;float y=norm.y;float z=norm.z;float c1=0.429043;float c2=0.511664;float c3=0.743125;float c4=0.886227;float c5=0.247708;vec3 irradiance=c1*c.l22*(x*x-y*y)+c3*c.l20*(z*z)+c4*c.l00-c5*c.l20+2.0*c1*(c.l2m2*x*y+c.l21*x*z+c.l2m1*y*z)+2.0*c2*(c.l11*x+c.l1m1*y+c.l10*z);return irradiance;}\n#endif\n#ifdef USE_IBL\nvec3 getIBLContribution(MaterialInfo materialInfo,vec3 n,vec3 v){float NdotV=clamp(dot(n,v),0.0,1.0);float lod=clamp(materialInfo.perceptualRoughness*float(_MipCount),0.0,float(_MipCount));vec3 reflection=normalize(reflect(-v,n));vec2 brdfSamplePoint=clamp(vec2(NdotV,materialInfo.perceptualRoughness),vec2(0.0,0.0),vec2(1.0,1.0));vec2 brdf=texture2D(_brdfLUT,brdfSamplePoint).rg;vec4 diffuseColor=vec4(1.0,0.0,0.0,1.0);\n#ifdef IRRADIANCE_COEFFICIENTS\nvec3 irradiance=getIrradiance(n,_shCoefficients);diffuseColor=vec4(irradiance,1.0);\n#else\ndiffuseColor=textureCube(_DiffuseEnvSampler,n);\n#endif\n#ifdef USE_TEX_LOD\nvec4 specularSample=_textureCubeLodEXT(_SpecularEnvSampler,reflection,lod);\n#else\nvec4 specularSample=textureCube(_SpecularEnvSampler,reflection,lod);\n#endif\n#ifdef USE_HDR\nvec3 diffuseLight=diffuseColor.rgb;vec3 specularLight=specularSample.rgb;\n#else\nvec3 diffuseLight=SRGBtoLINEAR(diffuseColor).rgb;vec3 specularLight=SRGBtoLINEAR(specularSample).rgb;\n#endif\nvec3 diffuse=diffuseLight*materialInfo.diffuseColor;vec3 specular=specularLight*(materialInfo.specularColor*brdf.x+brdf.y);return diffuse*_IblIntensity[0]+specular*_IblIntensity[1];}\n#endif\nvec3 diffuse(MaterialInfo materialInfo){return materialInfo.diffuseColor/M_PI;}vec3 specularReflection(MaterialInfo materialInfo,AngularInfo angularInfo){return materialInfo.reflectance0+(materialInfo.reflectance90-materialInfo.reflectance0)*pow(clamp(1.0-angularInfo.VdotH,0.0,1.0),5.0);}float visibilityOcclusion(MaterialInfo materialInfo,AngularInfo angularInfo){float NdotL=angularInfo.NdotL;float NdotV=angularInfo.NdotV;float alphaRoughnessSq=materialInfo.alphaRoughness*materialInfo.alphaRoughness;float GGXV=NdotL*sqrt(NdotV*NdotV*(1.0-alphaRoughnessSq)+alphaRoughnessSq);float GGXL=NdotV*sqrt(NdotL*NdotL*(1.0-alphaRoughnessSq)+alphaRoughnessSq);float GGX=GGXV+GGXL;if(GGX>0.0){return 0.5/GGX;}return 0.0;}float microfacetDistribution(MaterialInfo materialInfo,AngularInfo angularInfo){float alphaRoughnessSq=materialInfo.alphaRoughness*materialInfo.alphaRoughness;float f=(angularInfo.NdotH*alphaRoughnessSq-angularInfo.NdotH)*angularInfo.NdotH+1.0;return alphaRoughnessSq/(M_PI*f*f);}vec3 getPointShade(vec3 pointToLight,MaterialInfo materialInfo,vec3 normal,vec3 view){AngularInfo angularInfo=getAngularInfo(pointToLight,normal,view);if(angularInfo.NdotL>0.0||angularInfo.NdotV>0.0){vec3 F=specularReflection(materialInfo,angularInfo);float Vis=visibilityOcclusion(materialInfo,angularInfo);float D=microfacetDistribution(materialInfo,angularInfo);vec3 diffuseContrib=(1.0-F)*diffuse(materialInfo);vec3 specContrib=F*Vis*D;return angularInfo.NdotL*(diffuseContrib+specContrib);}return vec3(0.0,0.0,0.0);}float getRangeAttenuation(float range,float distance){if(range<=0.0){return 1.0;}return 1.0/(pow(5.0*distance/range,2.0)+1.0);}float getSpotAttenuation(vec3 pointToLight,vec3 spotDirection,float outerConeCos,float innerConeCos){float actualCos=dot(normalize(spotDirection),normalize(-pointToLight));if(actualCos>outerConeCos){if(actualCos<innerConeCos){return smoothstep(outerConeCos,innerConeCos,actualCos);}return 1.0;}return 0.0;}vec3 applyDirectionalLight(Light light,MaterialInfo materialInfo,vec3 normal,vec3 view,float shadow){vec3 pointToLight=-light.direction;vec3 shade=getPointShade(pointToLight,materialInfo,normal,view)*shadow;return light.intensity*light.color*shade;}vec3 applyPointLight(Light light,MaterialInfo materialInfo,vec3 normal,vec3 view){vec3 pointToLight=light.position-v_Position;float distance=length(pointToLight);float attenuation=getRangeAttenuation(light.range,distance);vec3 shade=getPointShade(pointToLight,materialInfo,normal,view);return light.color*shade*attenuation*light.intensity;}vec3 applySpotLight(Light light,MaterialInfo materialInfo,vec3 normal,vec3 view,float shadow){vec3 pointToLight=light.position-v_Position;float distance=length(pointToLight);float rangeAttenuation=getRangeAttenuation(light.range,distance);float spotAttenuation=getSpotAttenuation(pointToLight,light.direction,light.outerConeCos,light.innerConeCos);vec3 shade=getPointShade(pointToLight,materialInfo,normal,view)*shadow;return rangeAttenuation*spotAttenuation*light.intensity*light.color*shade;}vec3 applyAmbientLight(Light light,MaterialInfo materialInfo){return light.intensity*light.color*diffuse(materialInfo);}float weight(float z,float a){return clamp(pow(min(1.0,a*10.0)+0.01,3.0)*1e8*pow(1.0-z*0.9,3.0),1e-2,3e3);}void main(){float perceptualRoughness=0.0;float metallic=0.0;vec4 baseColor=vec4(0.0,0.0,0.0,1.0);vec3 diffuseColor=vec3(0.0);vec3 specularColor=vec3(0.0);vec3 f0=vec3(0.04);\n#ifdef PREVIEW_BORDER\ngl_FragColor=uPreviewColor;return;\n#endif\n#ifdef MATERIAL_SPECULARGLOSSINESS\n#ifdef HAS_SPECULAR_GLOSSINESS_MAP\nvec4 sgSample=SRGBtoLINEAR(texture2D(_SpecularGlossinessSampler,getSpecularGlossinessUV()));perceptualRoughness=(1.0-sgSample.a*_GlossinessFactor);f0=sgSample.rgb*_SpecularFactor;\n#else\nf0=_SpecularFactor;perceptualRoughness=1.0-_GlossinessFactor;\n#endif\n#ifdef HAS_DIFFUSE_MAP\nbaseColor=SRGBtoLINEAR(texture2D(_DiffuseSampler,getDiffuseUV()))*_DiffuseFactor;\n#else\nbaseColor=SRGBtoLINEAR(_DiffuseFactor);\n#endif\nbaseColor*=getVertexColor();specularColor=f0;float oneMinusSpecularStrength=1.0-max(max(f0.r,f0.g),f0.b);diffuseColor=baseColor.rgb*oneMinusSpecularStrength;\n#ifdef DEBUG_METALLIC\nmetallic=solveMetallic(baseColor.rgb,specularColor,oneMinusSpecularStrength);\n#endif\n#endif\n#ifdef MATERIAL_METALLICROUGHNESS\n#ifdef HAS_METALLIC_ROUGHNESS_MAP\nvec4 mrSample=texture2D(_MetallicRoughnessSampler,getMetallicRoughnessUV());perceptualRoughness=mrSample.g*_RoughnessFactor;metallic=mrSample.b*_MetallicFactor;\n#else\nmetallic=_MetallicFactor;perceptualRoughness=_RoughnessFactor;\n#endif\n#ifdef HAS_BASE_COLOR_MAP\nbaseColor=SRGBtoLINEAR(texture2D(_BaseColorSampler,getBaseColorUV()))*_BaseColorFactor;\n#else\nbaseColor=SRGBtoLINEAR(_BaseColorFactor);\n#endif\nbaseColor*=getVertexColor();diffuseColor=baseColor.rgb*(vec3(1.0)-f0)*(1.0-metallic);specularColor=mix(f0,baseColor.rgb,metallic);\n#endif\n#ifdef ALPHAMODE_MASK\nif(baseColor.a<_AlphaCutoff){discard;}baseColor.a=1.0;\n#endif\n#ifdef ALPHAMODE_OPAQUE\nbaseColor.a=1.0;\n#endif\n#ifdef MATERIAL_UNLIT\n#ifndef DEBUG_OUTPUT\n#ifdef ADD_FOG\nvec3 mixColor=getMixFogColor(baseColor.rgb);vec4 fragColorUnlit=vec4(LINEARtoSRGB(mixColor)*baseColor.a,baseColor.a);\n#else\nvec4 fragColorUnlit=vec4(LINEARtoSRGB(baseColor.rgb)*baseColor.a,baseColor.a);\n#endif\ngl_FragColor=fragColorUnlit;\n#else\n#ifdef DEBUG_UV\ngl_FragColor.rgb=vec3(getDebugUVColor(getBaseColorUV(),getNormal()));\n#endif\n#ifdef DEBUG_METALLIC\ngl_FragColor.rgb=vec3(metallic);\n#endif\n#ifdef DEBUG_ROUGHNESS\ngl_FragColor.rgb=vec3(perceptualRoughness);\n#endif\n#ifdef DEBUG_NORMAL\ngl_FragColor.rgb=getNormal()*0.5+0.5;\n#endif\n#ifdef DEBUG_BASECOLOR\ngl_FragColor.rgb=LINEARtoSRGB(baseColor.rgb);\n#endif\n#ifdef DEBUG_OCCLUSION\ngl_FragColor.rgb=vec3(1.0);\n#endif\n#ifdef DEBUG_EMISSIVE\ngl_FragColor.rgb=vec3(0.0);\n#endif\n#ifdef DEBUG_ALPHA\ngl_FragColor.rgb=vec3(baseColor.a);\n#endif\ngl_FragColor.a=1.0;\n#endif\nreturn;\n#endif\nmetallic=clamp(metallic,0.0,1.0);float alphaRoughness=perceptualRoughness*perceptualRoughness;vec3 normal=getNormal();\n#ifdef USE_SPECULAR_AA\nfloat AARoughnessFactor=getAARoughnessFactor(normal);perceptualRoughness+=AARoughnessFactor;alphaRoughness+=AARoughnessFactor;\n#endif\nperceptualRoughness=clamp(perceptualRoughness,0.04,1.0);alphaRoughness=clamp(alphaRoughness,0.04,1.0);float reflectance=max(max(specularColor.r,specularColor.g),specularColor.b);vec3 specularEnvironmentR0=specularColor.rgb;vec3 specularEnvironmentR90=vec3(clamp(reflectance*50.0,0.0,1.0));MaterialInfo materialInfo=MaterialInfo(perceptualRoughness,specularEnvironmentR0,alphaRoughness,diffuseColor,specularEnvironmentR90,specularColor);vec3 color=vec3(0.0,0.0,0.0);vec3 view=normalize(_Camera-v_Position);float shadow=1.0;\n#ifdef USE_SHADOW_MAPPING\nshadow=getShadowContribution();\n#endif\n#ifdef USE_PUNCTUAL\nfor(int i=0;i<LIGHT_COUNT;++i){Light light=_Lights[i];if(light.type==LightType_Directional){color+=applyDirectionalLight(light,materialInfo,normal,view,shadow);}else if(light.type==LightType_Point){color+=applyPointLight(light,materialInfo,normal,view);}else if(light.type==LightType_Spot){color+=applySpotLight(light,materialInfo,normal,view,shadow);}else if(light.type==LightType_Ambient){color+=applyAmbientLight(light,materialInfo);}}\n#endif\n#ifdef USE_IBL\ncolor+=getIBLContribution(materialInfo,normal,view);\n#endif\nfloat ao=1.0;\n#ifdef HAS_OCCLUSION_MAP\nao=texture2D(_OcclusionSampler,getOcclusionUV()).r;color=mix(color,color*ao,_OcclusionStrength);\n#endif\nvec3 emissive=vec3(0);\n#ifndef DEBUG_OUTPUT\n#ifdef ADD_FOG\nvec4 toneMapColor=SRGBtoLINEAR(vec4(toneMap(color),baseColor.a));color=getMixFogColor(toneMapColor.rgb);vec4 fragColorOut=vec4(LINEARtoSRGB(color.rgb)*baseColor.a,baseColor.a);\n#else\ncolor=toneMap(color)*baseColor.a;\n#ifdef HAS_EMISSIVE\ncolor+=_EmissiveFactor.rgb*_EmissiveIntensity;\n#endif\n#ifdef HAS_EMISSIVE_MAP\nemissive=SRGBtoLINEAR(texture2D(_EmissiveSampler,getEmissiveUV())).rgb*_EmissiveFactor.rgb*_EmissiveIntensity;color+=emissive;\n#endif\nvec4 fragColorOut=vec4(color,baseColor.a);\n#endif\ngl_FragColor=fragColorOut;\n#else\n#ifdef DEBUG_UV\ngl_FragColor.rgb=vec3(getDebugUVColor(getBaseColorUV(),normal));\n#endif\n#ifdef DEBUG_METALLIC\ngl_FragColor.rgb=vec3(metallic);\n#endif\n#ifdef DEBUG_ROUGHNESS\ngl_FragColor.rgb=vec3(perceptualRoughness);\n#endif\n#ifdef DEBUG_NORMAL\ngl_FragColor.rgb=normal*0.5+0.5;\n#endif\n#ifdef DEBUG_BASECOLOR\ngl_FragColor.rgb=LINEARtoSRGB(baseColor.rgb);\n#endif\n#ifdef DEBUG_OCCLUSION\n#ifdef HAS_OCCLUSION_MAP\ngl_FragColor.rgb=vec3(mix(1.0,ao,_OcclusionStrength));\n#else\ngl_FragColor.rgb=vec3(1.0);\n#endif\n#endif\n#ifdef DEBUG_EMISSIVE\n#ifdef HAS_EMISSIVE\nemissive=_EmissiveFactor.rgb*_EmissiveIntensity;\n#endif\n#ifdef HAS_EMISSIVE_MAP\nemissive=SRGBtoLINEAR(texture2D(_EmissiveSampler,getEmissiveUV())).rgb*_EmissiveFactor.rgb*_EmissiveIntensity;\n#endif\ngl_FragColor.rgb=LINEARtoSRGB(emissive);\n#endif\n#ifdef DEBUG_F0\ngl_FragColor.rgb=vec3(f0);\n#endif\n#ifdef DEBUG_ALPHA\ngl_FragColor.rgb=vec3(baseColor.a);\n#endif\n#ifdef DEBUG_DIFFUSE\nvec3 debugDiffuse=vec3(0.0);\n#ifdef USE_PUNCTUAL\nvec3 newBaseColor=vec3(dot(_BaseColorFactor.xyz,vec3(0.3)));MaterialInfo diffuseMaterialInfo=MaterialInfo(1.0,vec3(0.0),1.0,newBaseColor,vec3(0.0),vec3(0.0));for(int i=0;i<LIGHT_COUNT;++i){Light light=_Lights[i];if(light.type==LightType_Directional){debugDiffuse+=applyDirectionalLight(light,diffuseMaterialInfo,normal,view,shadow);}else if(light.type==LightType_Point){debugDiffuse+=applyPointLight(light,diffuseMaterialInfo,normal,view);}else if(light.type==LightType_Spot){debugDiffuse+=applySpotLight(light,diffuseMaterialInfo,normal,view,shadow);}else if(light.type==LightType_Ambient){debugDiffuse+=applyAmbientLight(light,diffuseMaterialInfo);}}\n#endif\ngl_FragColor.rgb=toneMap(debugDiffuse);\n#endif\ngl_FragColor.a=1.0;\n#endif\n}";
|
|
951
|
+
var metallicRoughnessFrag = "\n#define FEATURES\n#extension GL_OES_standard_derivatives : enable\n#if defined(USE_TEX_LOD)\n#extension GL_EXT_shader_texture_lod : enable\n#endif\n#ifdef USE_HDR\n#extension GL_OES_texture_float : enable\n#extension GL_OES_texture_float_linear : enable\n#endif\n#ifdef GL_FRAGMENT_PRECISION_HIGH\nprecision highp float;\n#else\nprecision mediump float;\n#endif\n#include <extensions.frag.glsl>\n#include <tone-mapping.frag.glsl>\n#include <textures.vert.glsl>\n#include <functions.frag.glsl>\n#include <shadow-common.vert.glsl>\n#include <shadow.frag.glsl>\nstruct Light{vec3 direction;float range;vec3 color;float intensity;vec3 position;float innerConeCos;float outerConeCos;int type;vec2 padding;};const int LightType_Directional=0;const int LightType_Point=1;const int LightType_Spot=2;const int LightType_Ambient=3;\n#ifdef USE_PUNCTUAL\nuniform Light _Lights[LIGHT_COUNT];\n#endif\n#if defined(MATERIAL_SPECULARGLOSSINESS) || defined(MATERIAL_METALLICROUGHNESS)\nuniform float _MetallicFactor;uniform float _RoughnessFactor;uniform vec4 _BaseColorFactor;\n#endif\n#ifdef MATERIAL_SPECULARGLOSSINESS\nuniform vec3 _SpecularFactor;uniform vec4 _DiffuseFactor;uniform float _GlossinessFactor;\n#endif\n#ifdef ALPHAMODE_MASK\nuniform float _AlphaCutoff;\n#endif\n#ifdef ADD_FOG\nuniform vec4 _FogColor;\n#ifdef LINEAR_FOG\nuniform float _FogNear;uniform float _FogFar;\n#endif\n#ifdef EXP_FOG\nuniform float _FogDensity;\n#endif\n#endif\n#ifdef PREVIEW_BORDER\nuniform vec4 uPreviewColor;\n#endif\nuniform vec3 _Camera;uniform int _MipCount;struct MaterialInfo{float perceptualRoughness;vec3 reflectance0;float alphaRoughness;vec3 diffuseColor;vec3 reflectance90;vec3 specularColor;};\n#ifdef ADD_FOG\nvec3 getMixFogColor(vec3 baseColor){vec3 distance=_Camera-v_Position;float fogAmount=0.0;\n#ifdef LINEAR_FOG\nfogAmount=smoothstep(_FogNear,_FogFar,distance[2]);\n#endif\n#ifdef EXP_FOG\n#define LOG2 1.442695\nfogAmount=1.-exp2(-_FogDensity*_FogDensity*distance[2]*distance[2]*LOG2);fogAmount=clamp(fogAmount,0.,1.);\n#endif\nvec3 mixColor=baseColor.rgb+(vec3(_FogColor)-baseColor.rgb)*fogAmount;return mixColor;}\n#endif\n#ifdef IRRADIANCE_COEFFICIENTS\nvec3 getIrradiance(vec3 norm,SHCoefficients c){float x=norm.x;float y=norm.y;float z=norm.z;float c1=0.429043;float c2=0.511664;float c3=0.743125;float c4=0.886227;float c5=0.247708;vec3 irradiance=c1*c.l22*(x*x-y*y)+c3*c.l20*(z*z)+c4*c.l00-c5*c.l20+2.0*c1*(c.l2m2*x*y+c.l21*x*z+c.l2m1*y*z)+2.0*c2*(c.l11*x+c.l1m1*y+c.l10*z);return irradiance;}\n#endif\n#ifdef USE_IBL\nvec3 getIBLContribution(MaterialInfo materialInfo,vec3 n,vec3 v){float NdotV=clamp(dot(n,v),0.0,1.0);float lod=clamp(materialInfo.perceptualRoughness*float(_MipCount),0.0,float(_MipCount));vec3 reflection=normalize(reflect(-v,n));vec2 brdfSamplePoint=clamp(vec2(NdotV,materialInfo.perceptualRoughness),vec2(0.0,0.0),vec2(1.0,1.0));vec2 brdf=texture2D(_brdfLUT,brdfSamplePoint).rg;vec4 diffuseColor=vec4(1.0,0.0,0.0,1.0);\n#ifdef IRRADIANCE_COEFFICIENTS\nvec3 irradiance=getIrradiance(n,_shCoefficients);diffuseColor=vec4(irradiance,1.0);\n#else\ndiffuseColor=textureCube(_DiffuseEnvSampler,n);\n#endif\n#ifdef USE_TEX_LOD\nvec4 specularSample=_textureCubeLodEXT(_SpecularEnvSampler,reflection,lod);\n#else\nvec4 specularSample=textureCube(_SpecularEnvSampler,reflection,lod);\n#endif\n#ifdef USE_HDR\nvec3 diffuseLight=diffuseColor.rgb;vec3 specularLight=specularSample.rgb;\n#else\nvec3 diffuseLight=SRGBtoLINEAR(diffuseColor).rgb;vec3 specularLight=SRGBtoLINEAR(specularSample).rgb;\n#endif\nvec3 diffuse=diffuseLight*materialInfo.diffuseColor;vec3 specular=specularLight*(materialInfo.specularColor*brdf.x+brdf.y);return diffuse*_IblIntensity[0]+specular*_IblIntensity[1];}\n#endif\nvec3 diffuse(MaterialInfo materialInfo){return materialInfo.diffuseColor/M_PI;}vec3 specularReflection(MaterialInfo materialInfo,AngularInfo angularInfo){return materialInfo.reflectance0+(materialInfo.reflectance90-materialInfo.reflectance0)*pow(clamp(1.0-angularInfo.VdotH,0.0,1.0),5.0);}float visibilityOcclusion(MaterialInfo materialInfo,AngularInfo angularInfo){float NdotL=angularInfo.NdotL;float NdotV=angularInfo.NdotV;float alphaRoughnessSq=materialInfo.alphaRoughness*materialInfo.alphaRoughness;float GGXV=NdotL*sqrt(NdotV*NdotV*(1.0-alphaRoughnessSq)+alphaRoughnessSq);float GGXL=NdotV*sqrt(NdotL*NdotL*(1.0-alphaRoughnessSq)+alphaRoughnessSq);float GGX=GGXV+GGXL;if(GGX>0.0){return 0.5/GGX;}return 0.0;}float microfacetDistribution(MaterialInfo materialInfo,AngularInfo angularInfo){float alphaRoughnessSq=materialInfo.alphaRoughness*materialInfo.alphaRoughness;float f=(angularInfo.NdotH*alphaRoughnessSq-angularInfo.NdotH)*angularInfo.NdotH+1.0;return alphaRoughnessSq/(M_PI*f*f);}vec3 getPointShade(vec3 pointToLight,MaterialInfo materialInfo,vec3 normal,vec3 view){AngularInfo angularInfo=getAngularInfo(pointToLight,normal,view);if(angularInfo.NdotL>0.0||angularInfo.NdotV>0.0){vec3 F=specularReflection(materialInfo,angularInfo);float Vis=visibilityOcclusion(materialInfo,angularInfo);float D=microfacetDistribution(materialInfo,angularInfo);vec3 diffuseContrib=(1.0-F)*diffuse(materialInfo);vec3 specContrib=F*Vis*D;return angularInfo.NdotL*(diffuseContrib+specContrib);}return vec3(0.0,0.0,0.0);}float getRangeAttenuation(float range,float distance){if(range<=0.0){return 1.0;}return 1.0/(pow(5.0*distance/range,2.0)+1.0);}float getSpotAttenuation(vec3 pointToLight,vec3 spotDirection,float outerConeCos,float innerConeCos){float actualCos=dot(normalize(spotDirection),normalize(-pointToLight));if(actualCos>outerConeCos){if(actualCos<innerConeCos){return smoothstep(outerConeCos,innerConeCos,actualCos);}return 1.0;}return 0.0;}vec3 applyDirectionalLight(Light light,MaterialInfo materialInfo,vec3 normal,vec3 view,float shadow){vec3 pointToLight=-light.direction;vec3 shade=getPointShade(pointToLight,materialInfo,normal,view)*shadow;return light.intensity*light.color*shade;}vec3 applyPointLight(Light light,MaterialInfo materialInfo,vec3 normal,vec3 view){vec3 pointToLight=light.position-v_Position;float distance=length(pointToLight);float attenuation=getRangeAttenuation(light.range,distance);vec3 shade=getPointShade(pointToLight,materialInfo,normal,view);return light.color*shade*attenuation*light.intensity;}vec3 applySpotLight(Light light,MaterialInfo materialInfo,vec3 normal,vec3 view,float shadow){vec3 pointToLight=light.position-v_Position;float distance=length(pointToLight);float rangeAttenuation=getRangeAttenuation(light.range,distance);float spotAttenuation=getSpotAttenuation(pointToLight,light.direction,light.outerConeCos,light.innerConeCos);vec3 shade=getPointShade(pointToLight,materialInfo,normal,view)*shadow;return rangeAttenuation*spotAttenuation*light.intensity*light.color*shade;}vec3 applyAmbientLight(Light light,MaterialInfo materialInfo){return light.intensity*light.color*diffuse(materialInfo);}float weight(float z,float a){return clamp(pow(min(1.0,a*10.0)+0.01,3.0)*1e8*pow(1.0-z*0.9,3.0),1e-2,3e3);}void main(){float perceptualRoughness=0.0;float metallic=0.0;vec4 baseColor=vec4(0.0,0.0,0.0,1.0);vec3 diffuseColor=vec3(0.0);vec3 specularColor=vec3(0.0);vec3 f0=vec3(0.04);\n#ifdef PREVIEW_BORDER\ngl_FragColor=uPreviewColor;return;\n#endif\n#ifdef MATERIAL_SPECULARGLOSSINESS\n#ifdef HAS_SPECULAR_GLOSSINESS_MAP\nvec4 sgSample=SRGBtoLINEAR(texture2D(_SpecularGlossinessSampler,getSpecularGlossinessUV()));perceptualRoughness=(1.0-sgSample.a*_GlossinessFactor);f0=sgSample.rgb*_SpecularFactor;\n#else\nf0=_SpecularFactor;perceptualRoughness=1.0-_GlossinessFactor;\n#endif\n#ifdef HAS_DIFFUSE_MAP\nbaseColor=SRGBtoLINEAR(texture2D(_DiffuseSampler,getDiffuseUV()))*_DiffuseFactor;\n#else\nbaseColor=SRGBtoLINEAR(_DiffuseFactor);\n#endif\nbaseColor*=getVertexColor();specularColor=f0;float oneMinusSpecularStrength=1.0-max(max(f0.r,f0.g),f0.b);diffuseColor=baseColor.rgb*oneMinusSpecularStrength;\n#ifdef DEBUG_METALLIC\nmetallic=solveMetallic(baseColor.rgb,specularColor,oneMinusSpecularStrength);\n#endif\n#endif\n#ifdef MATERIAL_METALLICROUGHNESS\n#ifdef HAS_METALLIC_ROUGHNESS_MAP\nvec4 mrSample=texture2D(_MetallicRoughnessSampler,getMetallicRoughnessUV());perceptualRoughness=mrSample.g*_RoughnessFactor;metallic=mrSample.b*_MetallicFactor;\n#else\nmetallic=_MetallicFactor;perceptualRoughness=_RoughnessFactor;\n#endif\n#ifdef HAS_BASE_COLOR_MAP\nbaseColor=SRGBtoLINEAR(texture2D(_BaseColorSampler,getBaseColorUV()))*_BaseColorFactor;\n#else\nbaseColor=SRGBtoLINEAR(_BaseColorFactor);\n#endif\nbaseColor*=getVertexColor();diffuseColor=baseColor.rgb*(vec3(1.0)-f0)*(1.0-metallic);specularColor=mix(f0,baseColor.rgb,metallic);\n#endif\n#ifdef ALPHAMODE_MASK\nif(baseColor.a<_AlphaCutoff){discard;}baseColor.a=1.0;\n#endif\n#ifdef ALPHAMODE_OPAQUE\nbaseColor.a=1.0;\n#endif\n#ifdef MATERIAL_UNLIT\n#ifndef DEBUG_OUTPUT\n#ifdef ADD_FOG\nvec3 mixColor=getMixFogColor(baseColor.rgb);vec4 fragColorUnlit=vec4(LINEARtoSRGB(mixColor)*baseColor.a,baseColor.a);\n#else\nvec4 fragColorUnlit=vec4(LINEARtoSRGB(baseColor.rgb)*baseColor.a,baseColor.a);\n#endif\ngl_FragColor=fragColorUnlit;\n#else\n#ifdef DEBUG_UV\ngl_FragColor.rgb=vec3(getDebugUVColor(getBaseColorUV(),getNormal()));\n#endif\n#ifdef DEBUG_METALLIC\ngl_FragColor.rgb=vec3(metallic);\n#endif\n#ifdef DEBUG_ROUGHNESS\ngl_FragColor.rgb=vec3(perceptualRoughness);\n#endif\n#ifdef DEBUG_NORMAL\ngl_FragColor.rgb=getNormal()*0.5+0.5;\n#endif\n#ifdef DEBUG_BASECOLOR\ngl_FragColor.rgb=LINEARtoSRGB(baseColor.rgb);\n#endif\n#ifdef DEBUG_OCCLUSION\ngl_FragColor.rgb=vec3(1.0);\n#endif\n#ifdef DEBUG_EMISSIVE\ngl_FragColor.rgb=vec3(0.0);\n#endif\n#ifdef DEBUG_ALPHA\ngl_FragColor.rgb=vec3(baseColor.a);\n#endif\ngl_FragColor.a=1.0;\n#endif\nreturn;\n#endif\nmetallic=clamp(metallic,0.0,1.0);float alphaRoughness=perceptualRoughness*perceptualRoughness;vec3 normal=getNormal();\n#ifdef USE_SPECULAR_AA\nfloat AARoughnessFactor=getAARoughnessFactor(normal);perceptualRoughness+=AARoughnessFactor;alphaRoughness+=AARoughnessFactor;\n#endif\nperceptualRoughness=clamp(perceptualRoughness,0.04,1.0);alphaRoughness=clamp(alphaRoughness,0.04,1.0);float reflectance=max(max(specularColor.r,specularColor.g),specularColor.b);vec3 specularEnvironmentR0=specularColor.rgb;vec3 specularEnvironmentR90=vec3(clamp(reflectance*50.0,0.0,1.0));MaterialInfo materialInfo=MaterialInfo(perceptualRoughness,specularEnvironmentR0,alphaRoughness,diffuseColor,specularEnvironmentR90,specularColor);vec3 color=vec3(0.0,0.0,0.0);vec3 view=normalize(_Camera-v_Position);float shadow=1.0;\n#ifdef USE_SHADOW_MAPPING\nshadow=getShadowContribution();\n#endif\n#ifdef USE_PUNCTUAL\nfor(int i=0;i<LIGHT_COUNT;++i){Light light=_Lights[i];if(light.type==LightType_Directional){color+=applyDirectionalLight(light,materialInfo,normal,view,shadow);}else if(light.type==LightType_Point){color+=applyPointLight(light,materialInfo,normal,view);}else if(light.type==LightType_Spot){color+=applySpotLight(light,materialInfo,normal,view,shadow);}else if(light.type==LightType_Ambient){color+=applyAmbientLight(light,materialInfo);}}\n#endif\n#ifdef USE_IBL\ncolor+=getIBLContribution(materialInfo,normal,view);\n#endif\nfloat ao=1.0;\n#ifdef HAS_OCCLUSION_MAP\nao=texture2D(_OcclusionSampler,getOcclusionUV()).r;color=mix(color,color*ao,_OcclusionStrength);\n#endif\nvec3 emissive=vec3(0);\n#ifndef DEBUG_OUTPUT\n#ifdef ADD_FOG\nvec4 toneMapColor=SRGBtoLINEAR(vec4(toneMap(color),baseColor.a));color=getMixFogColor(toneMapColor.rgb);vec4 fragColorOut=vec4(LINEARtoSRGB(color.rgb)*baseColor.a,baseColor.a);\n#else\ncolor=toneMap(color)*baseColor.a;\n#ifdef HAS_EMISSIVE\ncolor+=_EmissiveFactor.rgb*_EmissiveIntensity;\n#endif\n#ifdef HAS_EMISSIVE_MAP\nemissive=SRGBtoLINEAR(texture2D(_EmissiveSampler,getEmissiveUV())).rgb*_EmissiveFactor.rgb*_EmissiveIntensity;color+=emissive;\n#endif\nvec4 fragColorOut=vec4(color,baseColor.a);\n#endif\ngl_FragColor=fragColorOut;\n#else\n#ifdef DEBUG_UV\ngl_FragColor.rgb=vec3(getDebugUVColor(getBaseColorUV(),normal));\n#endif\n#ifdef DEBUG_METALLIC\ngl_FragColor.rgb=vec3(metallic);\n#endif\n#ifdef DEBUG_ROUGHNESS\ngl_FragColor.rgb=vec3(perceptualRoughness);\n#endif\n#ifdef DEBUG_NORMAL\ngl_FragColor.rgb=normal*0.5+0.5;\n#endif\n#ifdef DEBUG_BASECOLOR\ngl_FragColor.rgb=LINEARtoSRGB(baseColor.rgb);\n#endif\n#ifdef DEBUG_OCCLUSION\n#ifdef HAS_OCCLUSION_MAP\ngl_FragColor.rgb=vec3(mix(1.0,ao,_OcclusionStrength));\n#else\ngl_FragColor.rgb=vec3(1.0);\n#endif\n#endif\n#ifdef DEBUG_EMISSIVE\n#ifdef HAS_EMISSIVE\nemissive=_EmissiveFactor.rgb*_EmissiveIntensity;\n#endif\n#ifdef HAS_EMISSIVE_MAP\nemissive=SRGBtoLINEAR(texture2D(_EmissiveSampler,getEmissiveUV())).rgb*_EmissiveFactor.rgb*_EmissiveIntensity;\n#endif\ngl_FragColor.rgb=LINEARtoSRGB(emissive);\n#endif\n#ifdef DEBUG_F0\ngl_FragColor.rgb=vec3(f0);\n#endif\n#ifdef DEBUG_ALPHA\ngl_FragColor.rgb=vec3(baseColor.a);\n#endif\n#ifdef DEBUG_DIFFUSE\nvec3 debugDiffuse=vec3(0.0);\n#ifdef USE_PUNCTUAL\nMaterialInfo diffuseMaterialInfo=MaterialInfo(1.0,f0,1.0,vec3(0.35),f0,f0);for(int i=0;i<LIGHT_COUNT;++i){Light light=_Lights[i];if(light.type==LightType_Directional){debugDiffuse+=applyDirectionalLight(light,diffuseMaterialInfo,normal,view,shadow);}else if(light.type==LightType_Point){debugDiffuse+=applyPointLight(light,diffuseMaterialInfo,normal,view);}else if(light.type==LightType_Spot){debugDiffuse+=applySpotLight(light,diffuseMaterialInfo,normal,view,shadow);}else if(light.type==LightType_Ambient){debugDiffuse+=applyAmbientLight(light,diffuseMaterialInfo);}}\n#ifdef USE_IBL\ndebugDiffuse+=getIBLContribution(diffuseMaterialInfo,normal,view);\n#endif\n#endif\ngl_FragColor.rgb=toneMap(debugDiffuse);\n#endif\ngl_FragColor.a=1.0;\n#endif\n}";
|
|
1230
952
|
|
|
1231
953
|
var shadowPassFrag = "#define FEATURES\n#include <shadow-common.vert.glsl>\n#if defined(SHADOWMAP_VSM)\n#extension GL_OES_standard_derivatives : enable\n#endif\n#ifdef GL_FRAGMENT_PRECISION_HIGH\nprecision highp float;\n#else\nprecision mediump float;\n#endif\nvec4 CalcMomentVSM(float depth){float dx=0.0;float dy=0.0;\n#if defined(SHADOWMAP_VSM) && (defined(GL_OES_standard_derivatives) || defined(WEBGL2))\ndx=dFdx(depth);dy=dFdy(depth);\n#endif\nfloat moment2=depth*depth+0.25*(dx*dx+dy*dy);return vec4(1.0-depth,1.0-moment2,0.0,1.0);}vec4 CalcMomentEVSM(float depth){float pos=EVSM_FUNC0(depth);float neg=EVSM_FUNC1(depth);return vec4(pos,pos*pos,neg,neg*neg);}void main(){\n#if defined(SHADOWMAP_STANDARD) || defined(SHADOWMAP_VSM)\ngl_FragColor=CalcMomentVSM(gl_FragCoord.z);\n#else\ngl_FragColor=CalcMomentEVSM(gl_FragCoord.z);\n#endif\n}";
|
|
1232
954
|
|
|
@@ -3795,117 +3517,6 @@ ModelPluginComponent = __decorate([
|
|
|
3795
3517
|
return pluginComp == null ? void 0 : pluginComp.scene;
|
|
3796
3518
|
}
|
|
3797
3519
|
|
|
3798
|
-
/**
|
|
3799
|
-
* 场景树元素类,支持插件中节点树相关的动画能力
|
|
3800
|
-
*/ var ModelTreeItem = /*#__PURE__*/ function() {
|
|
3801
|
-
function ModelTreeItem(props, owner) {
|
|
3802
|
-
this.baseTransform = owner.transform;
|
|
3803
|
-
this.animationManager = new PAnimationManager(props, owner);
|
|
3804
|
-
this.build(props);
|
|
3805
|
-
}
|
|
3806
|
-
var _proto = ModelTreeItem.prototype;
|
|
3807
|
-
/**
|
|
3808
|
-
* 场景树更新,主要是动画更新
|
|
3809
|
-
* @param dt - 时间间隔
|
|
3810
|
-
*/ _proto.tick = function tick(dt) {
|
|
3811
|
-
this.animationManager.tick(dt);
|
|
3812
|
-
};
|
|
3813
|
-
/**
|
|
3814
|
-
* 获取所有节点
|
|
3815
|
-
* @returns
|
|
3816
|
-
*/ _proto.getNodes = function getNodes() {
|
|
3817
|
-
return this.nodes;
|
|
3818
|
-
};
|
|
3819
|
-
/**
|
|
3820
|
-
* 根据节点编号,查询节点
|
|
3821
|
-
* @param nodeId - 节点编号
|
|
3822
|
-
* @returns
|
|
3823
|
-
*/ _proto.getNodeById = function getNodeById(nodeId) {
|
|
3824
|
-
var cache = this.cacheMap;
|
|
3825
|
-
if (!cache[nodeId]) {
|
|
3826
|
-
var index = "^" + nodeId;
|
|
3827
|
-
// @ts-expect-error
|
|
3828
|
-
cache[nodeId] = this.allNodes.find(function(node) {
|
|
3829
|
-
return node.id === index;
|
|
3830
|
-
});
|
|
3831
|
-
}
|
|
3832
|
-
return cache[nodeId];
|
|
3833
|
-
};
|
|
3834
|
-
/**
|
|
3835
|
-
* 根据节点名称,查询节点
|
|
3836
|
-
* @param name - 名称
|
|
3837
|
-
* @returns
|
|
3838
|
-
*/ _proto.getNodeByName = function getNodeByName(name) {
|
|
3839
|
-
var cache = this.cacheMap;
|
|
3840
|
-
if (!cache[name]) {
|
|
3841
|
-
// @ts-expect-error
|
|
3842
|
-
cache[name] = this.allNodes.find(function(node) {
|
|
3843
|
-
return node.name === name;
|
|
3844
|
-
});
|
|
3845
|
-
}
|
|
3846
|
-
return cache[name];
|
|
3847
|
-
};
|
|
3848
|
-
/**
|
|
3849
|
-
* 根据节点 id 查询节点变换,如果查询不到节点就直接返回基础变换
|
|
3850
|
-
* @param nodeId - 节点 id
|
|
3851
|
-
* @returns
|
|
3852
|
-
*/ _proto.getNodeTransform = function getNodeTransform(nodeId) {
|
|
3853
|
-
var node = this.getNodeById(nodeId);
|
|
3854
|
-
return node ? node.transform : this.baseTransform;
|
|
3855
|
-
};
|
|
3856
|
-
/**
|
|
3857
|
-
* 销毁场景树对象
|
|
3858
|
-
*/ _proto.dispose = function dispose() {
|
|
3859
|
-
var _this_animationManager;
|
|
3860
|
-
this.allNodes = [];
|
|
3861
|
-
this.nodes = [];
|
|
3862
|
-
this.cacheMap = {};
|
|
3863
|
-
// @ts-expect-error
|
|
3864
|
-
this.baseTransform = null;
|
|
3865
|
-
(_this_animationManager = this.animationManager) == null ? void 0 : _this_animationManager.dispose();
|
|
3866
|
-
// @ts-expect-error
|
|
3867
|
-
this.animationManager = null;
|
|
3868
|
-
};
|
|
3869
|
-
_proto.build = function build(options) {
|
|
3870
|
-
var _this = this;
|
|
3871
|
-
var topTransform = this.baseTransform;
|
|
3872
|
-
var nodes = options.nodes.map(function(node, i) {
|
|
3873
|
-
return {
|
|
3874
|
-
name: node.name || node.id || i + "",
|
|
3875
|
-
transform: new Transform(_extends({}, node.transform, {
|
|
3876
|
-
valid: true
|
|
3877
|
-
}), topTransform),
|
|
3878
|
-
id: "^" + (node.id || i),
|
|
3879
|
-
children: [],
|
|
3880
|
-
tree: _this
|
|
3881
|
-
};
|
|
3882
|
-
});
|
|
3883
|
-
this.cacheMap = {};
|
|
3884
|
-
nodes.forEach(function(node, i) {
|
|
3885
|
-
var children = options.nodes[i].children;
|
|
3886
|
-
// @ts-expect-error
|
|
3887
|
-
node.transform.name = node.name;
|
|
3888
|
-
node.transform.setValid(true);
|
|
3889
|
-
if (children) {
|
|
3890
|
-
children.forEach(function(index) {
|
|
3891
|
-
var child = nodes[index];
|
|
3892
|
-
if (child && child !== node) {
|
|
3893
|
-
if (child.transform.parentTransform !== topTransform) {
|
|
3894
|
-
console.error("Node parent has been set.");
|
|
3895
|
-
}
|
|
3896
|
-
child.transform.parentTransform = node.transform;
|
|
3897
|
-
node.children.push(child);
|
|
3898
|
-
}
|
|
3899
|
-
});
|
|
3900
|
-
}
|
|
3901
|
-
});
|
|
3902
|
-
this.allNodes = nodes;
|
|
3903
|
-
this.nodes = options.children.map(function(i) {
|
|
3904
|
-
return nodes[i];
|
|
3905
|
-
});
|
|
3906
|
-
};
|
|
3907
|
-
return ModelTreeItem;
|
|
3908
|
-
}();
|
|
3909
3520
|
var ModelTreeComponent = /*#__PURE__*/ function(Behaviour) {
|
|
3910
3521
|
_inherits(ModelTreeComponent, Behaviour);
|
|
3911
3522
|
function ModelTreeComponent(engine, options) {
|
|
@@ -3923,56 +3534,6 @@ var ModelTreeComponent = /*#__PURE__*/ function(Behaviour) {
|
|
|
3923
3534
|
*/ _proto.fromData = function fromData(options) {
|
|
3924
3535
|
Behaviour.prototype.fromData.call(this, options);
|
|
3925
3536
|
this.options = options;
|
|
3926
|
-
this.createContent();
|
|
3927
|
-
};
|
|
3928
|
-
/**
|
|
3929
|
-
* 组件开始,查询合成中场景管理器并设置到动画管理器中
|
|
3930
|
-
*/ _proto.onStart = function onStart() {
|
|
3931
|
-
this.item.type = spec.ItemType.tree;
|
|
3932
|
-
this.content.baseTransform.setValid(true);
|
|
3933
|
-
var sceneManager = getSceneManager(this);
|
|
3934
|
-
if (sceneManager) {
|
|
3935
|
-
this.content.animationManager.setSceneManager(sceneManager);
|
|
3936
|
-
}
|
|
3937
|
-
};
|
|
3938
|
-
/**
|
|
3939
|
-
* 组件更新,内部对象更新
|
|
3940
|
-
* @param dt
|
|
3941
|
-
*/ _proto.onUpdate = function onUpdate(dt) {
|
|
3942
|
-
var // this.timeline?.getRenderData(time, true);
|
|
3943
|
-
// TODO: 需要使用lifetime
|
|
3944
|
-
_this_content;
|
|
3945
|
-
(_this_content = this.content) == null ? void 0 : _this_content.tick(dt);
|
|
3946
|
-
};
|
|
3947
|
-
/**
|
|
3948
|
-
* 组件销毁,内部对象销毁
|
|
3949
|
-
*/ _proto.onDestroy = function onDestroy() {
|
|
3950
|
-
var _this_content;
|
|
3951
|
-
(_this_content = this.content) == null ? void 0 : _this_content.dispose();
|
|
3952
|
-
};
|
|
3953
|
-
/**
|
|
3954
|
-
* 创建内部场景树元素
|
|
3955
|
-
*/ _proto.createContent = function createContent() {
|
|
3956
|
-
if (this.options) {
|
|
3957
|
-
var treeOptions = this.options.options.tree;
|
|
3958
|
-
this.content = new ModelTreeItem(treeOptions, this.item);
|
|
3959
|
-
}
|
|
3960
|
-
};
|
|
3961
|
-
/**
|
|
3962
|
-
* 获取元素的变换
|
|
3963
|
-
* @param itemId - 元素索引
|
|
3964
|
-
* @returns
|
|
3965
|
-
*/ _proto.getNodeTransform = function getNodeTransform(itemId) {
|
|
3966
|
-
if (this.content === undefined) {
|
|
3967
|
-
return this.transform;
|
|
3968
|
-
}
|
|
3969
|
-
var idWithSubfix = this.item.id + "^";
|
|
3970
|
-
if (itemId.indexOf(idWithSubfix) === 0) {
|
|
3971
|
-
var nodeId = itemId.substring(idWithSubfix.length);
|
|
3972
|
-
return this.content.getNodeTransform(nodeId);
|
|
3973
|
-
} else {
|
|
3974
|
-
return this.transform;
|
|
3975
|
-
}
|
|
3976
3537
|
};
|
|
3977
3538
|
return ModelTreeComponent;
|
|
3978
3539
|
}(Behaviour);
|
|
@@ -3980,24 +3541,6 @@ ModelTreeComponent = __decorate([
|
|
|
3980
3541
|
effectsClass(spec.DataType.TreeComponent)
|
|
3981
3542
|
], ModelTreeComponent);
|
|
3982
3543
|
|
|
3983
|
-
/**
|
|
3984
|
-
* 场景树插件类,支持 3D 相关的节点动画和骨骼动画等
|
|
3985
|
-
*/ var ModelTreePlugin = /*#__PURE__*/ function(AbstractPlugin) {
|
|
3986
|
-
_inherits(ModelTreePlugin, AbstractPlugin);
|
|
3987
|
-
function ModelTreePlugin() {
|
|
3988
|
-
var _this;
|
|
3989
|
-
_this = AbstractPlugin.apply(this, arguments) || this;
|
|
3990
|
-
/**
|
|
3991
|
-
* 插件名称
|
|
3992
|
-
*/ _this.name = "tree";
|
|
3993
|
-
/**
|
|
3994
|
-
* 高优先级更新
|
|
3995
|
-
*/ _this.order = 2;
|
|
3996
|
-
return _this;
|
|
3997
|
-
}
|
|
3998
|
-
return ModelTreePlugin;
|
|
3999
|
-
}(AbstractPlugin);
|
|
4000
|
-
|
|
4001
3544
|
var CameraGestureType;
|
|
4002
3545
|
(function(CameraGestureType) {
|
|
4003
3546
|
CameraGestureType[CameraGestureType["none"] = 0] = "none";
|
|
@@ -4402,9 +3945,8 @@ var CameraGestureHandlerImp = /*#__PURE__*/ function() {
|
|
|
4402
3945
|
return CameraGestureHandlerImp;
|
|
4403
3946
|
}();
|
|
4404
3947
|
|
|
4405
|
-
registerPlugin("tree", ModelTreePlugin, VFXItem, true);
|
|
4406
3948
|
registerPlugin("model", ModelPlugin, VFXItem);
|
|
4407
|
-
var version = "2.1.0-alpha.
|
|
3949
|
+
var version = "2.1.0-alpha.9";
|
|
4408
3950
|
logger.info("Plugin model version: " + version + ".");
|
|
4409
3951
|
if (version !== EFFECTS.version) {
|
|
4410
3952
|
console.error("注意:请统一 Model 插件与 Player 版本,不统一的版本混用会有不可预知的后果!", "\nAttention: Please ensure the Model plugin is synchronized with the Player version. Mixing and matching incompatible versions may result in unpredictable consequences!");
|
|
@@ -6155,31 +5697,6 @@ var normal = new Vector3();
|
|
|
6155
5697
|
console.error("setupItem3DOptions: Invalid inverseBindMatrices type, " + inverseBindMatrices + ".");
|
|
6156
5698
|
}
|
|
6157
5699
|
}
|
|
6158
|
-
} else if (item.type === spec.ItemType.tree) {
|
|
6159
|
-
var jsonItem = item;
|
|
6160
|
-
var studioItem = item;
|
|
6161
|
-
var jsonAnimations = jsonItem.content.options.tree.animations;
|
|
6162
|
-
var studioAnimations = studioItem.content.options.tree.animations;
|
|
6163
|
-
if (jsonAnimations !== undefined && studioAnimations !== undefined) {
|
|
6164
|
-
jsonAnimations.forEach(function(jsonAnim, i) {
|
|
6165
|
-
var studioAnim = studioAnimations[i];
|
|
6166
|
-
jsonAnim.tracks.forEach(function(jsonTrack, j) {
|
|
6167
|
-
var inputArray = typedArrayFromBinary(scene.bins, jsonTrack.input);
|
|
6168
|
-
var outputArray = typedArrayFromBinary(scene.bins, jsonTrack.output);
|
|
6169
|
-
var studioTrack = studioAnim.tracks[j];
|
|
6170
|
-
if (_instanceof1(inputArray, Float32Array)) {
|
|
6171
|
-
studioTrack.input = inputArray;
|
|
6172
|
-
} else {
|
|
6173
|
-
console.error("setupItem3DOptions: Type of inputArray should be float32, " + inputArray + ".");
|
|
6174
|
-
}
|
|
6175
|
-
if (_instanceof1(outputArray, Float32Array)) {
|
|
6176
|
-
studioTrack.output = outputArray;
|
|
6177
|
-
} else {
|
|
6178
|
-
console.error("setupItem3DOptions: Type of outputArray should be float32, " + outputArray + ".");
|
|
6179
|
-
}
|
|
6180
|
-
});
|
|
6181
|
-
});
|
|
6182
|
-
}
|
|
6183
5700
|
} else if (item.type === spec.ItemType.skybox) {
|
|
6184
5701
|
var skybox = item;
|
|
6185
5702
|
var studioSkybox = item;
|
|
@@ -8118,144 +7635,6 @@ var PAnimPathType;
|
|
|
8118
7635
|
PAnimPathType[PAnimPathType["scale"] = 2] = "scale";
|
|
8119
7636
|
PAnimPathType[PAnimPathType["weights"] = 3] = "weights";
|
|
8120
7637
|
})(PAnimPathType || (PAnimPathType = {}));
|
|
8121
|
-
/**
|
|
8122
|
-
* 动画轨道类
|
|
8123
|
-
*/ var PAnimTrack = /*#__PURE__*/ function() {
|
|
8124
|
-
function PAnimTrack(options) {
|
|
8125
|
-
/**
|
|
8126
|
-
* 路径类型
|
|
8127
|
-
*/ this.path = 0;
|
|
8128
|
-
/**
|
|
8129
|
-
* 插值类型
|
|
8130
|
-
*/ this.interp = 0;
|
|
8131
|
-
var node = options.node, input = options.input, output = options.output, path = options.path, interpolation = options.interpolation;
|
|
8132
|
-
this.node = node;
|
|
8133
|
-
this.timeArray = input;
|
|
8134
|
-
this.dataArray = output;
|
|
8135
|
-
//
|
|
8136
|
-
if (path === "translation") {
|
|
8137
|
-
this.path = 0;
|
|
8138
|
-
this.component = 3;
|
|
8139
|
-
} else if (path === "rotation") {
|
|
8140
|
-
this.path = 1;
|
|
8141
|
-
this.component = 4;
|
|
8142
|
-
} else if (path === "scale") {
|
|
8143
|
-
this.path = 2;
|
|
8144
|
-
this.component = 3;
|
|
8145
|
-
} else if (path === "weights") {
|
|
8146
|
-
this.path = 3;
|
|
8147
|
-
this.component = this.dataArray.length / this.timeArray.length;
|
|
8148
|
-
// special checker for weights animation
|
|
8149
|
-
if (this.component <= 0) {
|
|
8150
|
-
console.error("Invalid weights component: " + this.timeArray.length + ", " + this.component + ", " + this.dataArray.length + ".");
|
|
8151
|
-
} else if (this.timeArray.length * this.component != this.dataArray.length) {
|
|
8152
|
-
console.error("Invalid weights array length: " + this.timeArray.length + ", " + this.component + ", " + this.dataArray.length + ".");
|
|
8153
|
-
}
|
|
8154
|
-
} else {
|
|
8155
|
-
// should never happened
|
|
8156
|
-
console.error("Invalid path status: " + path + ".");
|
|
8157
|
-
}
|
|
8158
|
-
if (this.timeArray.length * this.component > this.dataArray.length) {
|
|
8159
|
-
throw new Error("Data length mismatch: " + this.timeArray.length + ", " + this.component + ", " + this.dataArray.length + ".");
|
|
8160
|
-
}
|
|
8161
|
-
if (interpolation === "LINEAR") {
|
|
8162
|
-
this.interp = 0;
|
|
8163
|
-
} else if (interpolation === "STEP") {
|
|
8164
|
-
this.interp = 1;
|
|
8165
|
-
} else {
|
|
8166
|
-
this.interp = 2;
|
|
8167
|
-
}
|
|
8168
|
-
this.sampler = createAnimationSampler(this.getInterpInfo(), this.timeArray, this.dataArray, this.component, this.getPathInfo());
|
|
8169
|
-
}
|
|
8170
|
-
var _proto = PAnimTrack.prototype;
|
|
8171
|
-
/**
|
|
8172
|
-
* 销毁
|
|
8173
|
-
*/ _proto.dispose = function dispose() {
|
|
8174
|
-
var _this_sampler;
|
|
8175
|
-
// @ts-expect-error
|
|
8176
|
-
this.timeArray = undefined;
|
|
8177
|
-
// @ts-expect-error
|
|
8178
|
-
this.dataArray = undefined;
|
|
8179
|
-
(_this_sampler = this.sampler) == null ? void 0 : _this_sampler.dispose();
|
|
8180
|
-
this.sampler = undefined;
|
|
8181
|
-
};
|
|
8182
|
-
/**
|
|
8183
|
-
* 更新节点动画数据
|
|
8184
|
-
* @param time - 当前播放时间
|
|
8185
|
-
* @param treeItem - 节点树元素
|
|
8186
|
-
* @param sceneManager - 3D 场景管理器
|
|
8187
|
-
*/ _proto.tick = function tick(time, treeItem, sceneManager) {
|
|
8188
|
-
var _treeComponent_content;
|
|
8189
|
-
var treeComponent = treeItem.getComponent(ModelTreeComponent);
|
|
8190
|
-
var node = treeComponent == null ? void 0 : (_treeComponent_content = treeComponent.content) == null ? void 0 : _treeComponent_content.getNodeById(this.node);
|
|
8191
|
-
if (this.sampler !== undefined && node !== undefined) {
|
|
8192
|
-
var result = this.sampler.evaluate(time);
|
|
8193
|
-
switch(this.path){
|
|
8194
|
-
case 0:
|
|
8195
|
-
node.transform.setPosition(result[0], result[1], result[2]);
|
|
8196
|
-
break;
|
|
8197
|
-
case 1:
|
|
8198
|
-
node.transform.setQuaternion(result[0], result[1], result[2], result[3]);
|
|
8199
|
-
break;
|
|
8200
|
-
case 2:
|
|
8201
|
-
node.transform.setScale(result[0], result[1], result[2]);
|
|
8202
|
-
break;
|
|
8203
|
-
case 3:
|
|
8204
|
-
{
|
|
8205
|
-
/**
|
|
8206
|
-
* 先生成Mesh的父节点id,然后通过id查询Mesh对象
|
|
8207
|
-
* 最后更新Mesh对象权重数据
|
|
8208
|
-
*/ var parentId = this.genParentId(treeItem.id, this.node);
|
|
8209
|
-
var mesh = sceneManager == null ? void 0 : sceneManager.queryMesh(parentId);
|
|
8210
|
-
if (mesh !== undefined) {
|
|
8211
|
-
mesh.updateMorphWeights(result);
|
|
8212
|
-
}
|
|
8213
|
-
}
|
|
8214
|
-
break;
|
|
8215
|
-
}
|
|
8216
|
-
} else {
|
|
8217
|
-
if (this.sampler !== undefined) {
|
|
8218
|
-
console.error("AnimTrack: error", this.sampler, node);
|
|
8219
|
-
}
|
|
8220
|
-
}
|
|
8221
|
-
};
|
|
8222
|
-
/**
|
|
8223
|
-
* 获取动画结束时间
|
|
8224
|
-
* @returns
|
|
8225
|
-
*/ _proto.getEndTime = function getEndTime() {
|
|
8226
|
-
var index = this.timeArray.length - 1;
|
|
8227
|
-
return this.timeArray[index];
|
|
8228
|
-
};
|
|
8229
|
-
/**
|
|
8230
|
-
* 生成 Mesh 元素的父节点
|
|
8231
|
-
*
|
|
8232
|
-
* @param parentId - 父节点 id 名称
|
|
8233
|
-
* @param nodeIndex - Mesh 节点索引
|
|
8234
|
-
*
|
|
8235
|
-
* @returns 生成的 Mesh 节点名称
|
|
8236
|
-
*/ _proto.genParentId = function genParentId(parentId, nodeIndex) {
|
|
8237
|
-
return parentId + "^" + nodeIndex;
|
|
8238
|
-
};
|
|
8239
|
-
_proto.getPathInfo = function getPathInfo() {
|
|
8240
|
-
if (this.path === 2) {
|
|
8241
|
-
return "scale";
|
|
8242
|
-
} else if (this.path === 1) {
|
|
8243
|
-
return "rotation";
|
|
8244
|
-
} else {
|
|
8245
|
-
return "translation";
|
|
8246
|
-
}
|
|
8247
|
-
};
|
|
8248
|
-
_proto.getInterpInfo = function getInterpInfo() {
|
|
8249
|
-
if (this.interp === 2) {
|
|
8250
|
-
return "CUBICSPLINE";
|
|
8251
|
-
} else if (this.interp === 1) {
|
|
8252
|
-
return "STEP";
|
|
8253
|
-
} else {
|
|
8254
|
-
return "LINEAR";
|
|
8255
|
-
}
|
|
8256
|
-
};
|
|
8257
|
-
return PAnimTrack;
|
|
8258
|
-
}();
|
|
8259
7638
|
/**
|
|
8260
7639
|
* 动画纹理类
|
|
8261
7640
|
*/ var PAnimTexture = /*#__PURE__*/ function() {
|
|
@@ -8342,148 +7721,6 @@ var PAnimPathType;
|
|
|
8342
7721
|
};
|
|
8343
7722
|
return PAnimTexture;
|
|
8344
7723
|
}();
|
|
8345
|
-
/**
|
|
8346
|
-
* 动画类,负责动画数据创建、更新和销毁
|
|
8347
|
-
*/ var PAnimation = /*#__PURE__*/ function(PObject) {
|
|
8348
|
-
_inherits(PAnimation, PObject);
|
|
8349
|
-
function PAnimation() {
|
|
8350
|
-
var _this;
|
|
8351
|
-
_this = PObject.apply(this, arguments) || this;
|
|
8352
|
-
_this.time = 0;
|
|
8353
|
-
_this.duration = 0;
|
|
8354
|
-
_this.tracks = [];
|
|
8355
|
-
return _this;
|
|
8356
|
-
}
|
|
8357
|
-
var _proto = PAnimation.prototype;
|
|
8358
|
-
/**
|
|
8359
|
-
* 创建动画对象
|
|
8360
|
-
* @param options - 动画参数
|
|
8361
|
-
*/ _proto.create = function create(options) {
|
|
8362
|
-
var _this = this;
|
|
8363
|
-
var _options_name;
|
|
8364
|
-
this.name = this.genName((_options_name = options.name) != null ? _options_name : "Unnamed animation");
|
|
8365
|
-
this.type = PObjectType.animation;
|
|
8366
|
-
//
|
|
8367
|
-
this.time = 0;
|
|
8368
|
-
this.duration = 0;
|
|
8369
|
-
//
|
|
8370
|
-
this.tracks = [];
|
|
8371
|
-
options.tracks.forEach(function(inTrack) {
|
|
8372
|
-
var track = new PAnimTrack(inTrack);
|
|
8373
|
-
_this.tracks.push(track);
|
|
8374
|
-
_this.duration = Math.max(_this.duration, track.getEndTime());
|
|
8375
|
-
});
|
|
8376
|
-
};
|
|
8377
|
-
/**
|
|
8378
|
-
* 动画更新
|
|
8379
|
-
* @param time - 当前时间
|
|
8380
|
-
* @param treeItem - 场景树元素
|
|
8381
|
-
* @param sceneManager - 3D 场景管理器
|
|
8382
|
-
*/ _proto.tick = function tick(time, treeItem, sceneManager) {
|
|
8383
|
-
this.time = time;
|
|
8384
|
-
// TODO: 这里时间事件定义不明确,先兼容原先实现
|
|
8385
|
-
var newTime = this.time % this.duration;
|
|
8386
|
-
this.tracks.forEach(function(track) {
|
|
8387
|
-
track.tick(newTime, treeItem, sceneManager);
|
|
8388
|
-
});
|
|
8389
|
-
};
|
|
8390
|
-
/**
|
|
8391
|
-
* 销毁
|
|
8392
|
-
*/ _proto.dispose = function dispose() {
|
|
8393
|
-
this.tracks.forEach(function(track) {
|
|
8394
|
-
track.dispose();
|
|
8395
|
-
});
|
|
8396
|
-
this.tracks = [];
|
|
8397
|
-
};
|
|
8398
|
-
return PAnimation;
|
|
8399
|
-
}(PObject);
|
|
8400
|
-
/**
|
|
8401
|
-
* 动画管理类,负责管理动画对象
|
|
8402
|
-
*/ var PAnimationManager = /*#__PURE__*/ function(PObject) {
|
|
8403
|
-
_inherits(PAnimationManager, PObject);
|
|
8404
|
-
function PAnimationManager(treeOptions, ownerItem) {
|
|
8405
|
-
var _this;
|
|
8406
|
-
_this = PObject.call(this) || this;
|
|
8407
|
-
_this.animation = 0;
|
|
8408
|
-
_this.speed = 0;
|
|
8409
|
-
_this.delay = 0;
|
|
8410
|
-
_this.time = 0;
|
|
8411
|
-
_this.animations = [];
|
|
8412
|
-
var _ownerItem_name;
|
|
8413
|
-
_this.name = _this.genName((_ownerItem_name = ownerItem.name) != null ? _ownerItem_name : "Unnamed tree");
|
|
8414
|
-
_this.type = PObjectType.animationManager;
|
|
8415
|
-
//
|
|
8416
|
-
_this.ownerItem = ownerItem;
|
|
8417
|
-
var _treeOptions_animation;
|
|
8418
|
-
_this.animation = (_treeOptions_animation = treeOptions.animation) != null ? _treeOptions_animation : -1;
|
|
8419
|
-
_this.speed = 1.0;
|
|
8420
|
-
var _ownerItem_start;
|
|
8421
|
-
_this.delay = (_ownerItem_start = ownerItem.start) != null ? _ownerItem_start : 0;
|
|
8422
|
-
_this.animations = [];
|
|
8423
|
-
if (treeOptions.animations !== undefined) {
|
|
8424
|
-
treeOptions.animations.forEach(function(animOpts) {
|
|
8425
|
-
var anim = _this.createAnimation(animOpts);
|
|
8426
|
-
_this.animations.push(anim);
|
|
8427
|
-
});
|
|
8428
|
-
}
|
|
8429
|
-
return _this;
|
|
8430
|
-
}
|
|
8431
|
-
var _proto = PAnimationManager.prototype;
|
|
8432
|
-
/**
|
|
8433
|
-
* 设置场景管理器
|
|
8434
|
-
* @param sceneManager - 场景管理器
|
|
8435
|
-
*/ _proto.setSceneManager = function setSceneManager(sceneManager) {
|
|
8436
|
-
this.sceneManager = sceneManager;
|
|
8437
|
-
};
|
|
8438
|
-
/**
|
|
8439
|
-
* 创建动画对象
|
|
8440
|
-
* @param animationOpts - 动画参数
|
|
8441
|
-
* @returns 动画对象
|
|
8442
|
-
*/ _proto.createAnimation = function createAnimation(animationOpts) {
|
|
8443
|
-
var animation = new PAnimation();
|
|
8444
|
-
animation.create(animationOpts);
|
|
8445
|
-
return animation;
|
|
8446
|
-
};
|
|
8447
|
-
/**
|
|
8448
|
-
* 动画更新
|
|
8449
|
-
* @param deltaSeconds - 更新间隔
|
|
8450
|
-
*/ _proto.tick = function tick(deltaSeconds) {
|
|
8451
|
-
var _this = this;
|
|
8452
|
-
var newDeltaSeconds = deltaSeconds * this.speed * 0.001;
|
|
8453
|
-
this.time += newDeltaSeconds;
|
|
8454
|
-
// TODO: 需要合并到TreeItem中,通过lifetime进行计算
|
|
8455
|
-
var itemTime = this.time - this.delay;
|
|
8456
|
-
if (itemTime >= 0) {
|
|
8457
|
-
if (this.animation >= 0 && this.animation < this.animations.length) {
|
|
8458
|
-
var anim = this.animations[this.animation];
|
|
8459
|
-
anim.tick(itemTime, this.ownerItem, this.sceneManager);
|
|
8460
|
-
} else if (this.animation == -88888888) {
|
|
8461
|
-
this.animations.forEach(function(anim) {
|
|
8462
|
-
anim.tick(itemTime, _this.ownerItem, _this.sceneManager);
|
|
8463
|
-
});
|
|
8464
|
-
}
|
|
8465
|
-
}
|
|
8466
|
-
};
|
|
8467
|
-
/**
|
|
8468
|
-
* 销毁
|
|
8469
|
-
*/ _proto.dispose = function dispose() {
|
|
8470
|
-
// @ts-expect-error
|
|
8471
|
-
this.ownerItem = null;
|
|
8472
|
-
this.animations.forEach(function(anim) {
|
|
8473
|
-
anim.dispose();
|
|
8474
|
-
});
|
|
8475
|
-
this.animations = [];
|
|
8476
|
-
// @ts-expect-error
|
|
8477
|
-
this.sceneManager = null;
|
|
8478
|
-
};
|
|
8479
|
-
/**
|
|
8480
|
-
* 获取场景树元素
|
|
8481
|
-
* @returns
|
|
8482
|
-
*/ _proto.getTreeItem = function getTreeItem() {
|
|
8483
|
-
return this.ownerItem;
|
|
8484
|
-
};
|
|
8485
|
-
return PAnimationManager;
|
|
8486
|
-
}(PObject);
|
|
8487
7724
|
|
|
8488
7725
|
var deg2rad = Math.PI / 180;
|
|
8489
7726
|
/**
|
|
@@ -9938,15 +9175,6 @@ var EffectsMeshProxy = /*#__PURE__*/ function() {
|
|
|
9938
9175
|
_proto.isHide = function isHide() {
|
|
9939
9176
|
return this.data.hide === true;
|
|
9940
9177
|
};
|
|
9941
|
-
_proto.getParentNode = function getParentNode() {
|
|
9942
|
-
var _this_parentItem;
|
|
9943
|
-
var nodeIndex = this.getParentIndex();
|
|
9944
|
-
var parentTree = (_this_parentItem = this.parentItem) == null ? void 0 : _this_parentItem.getComponent(ModelTreeComponent);
|
|
9945
|
-
if (parentTree !== undefined && nodeIndex >= 0) {
|
|
9946
|
-
return parentTree.content.getNodeById(nodeIndex);
|
|
9947
|
-
}
|
|
9948
|
-
return undefined;
|
|
9949
|
-
};
|
|
9950
9178
|
_proto.getParentIndex = function getParentIndex() {
|
|
9951
9179
|
return -1;
|
|
9952
9180
|
};
|
|
@@ -10337,7 +9565,7 @@ var JSONConverter = /*#__PURE__*/ function() {
|
|
|
10337
9565
|
_proto.processScene = function processScene(sceneData) {
|
|
10338
9566
|
var _this = this;
|
|
10339
9567
|
return _async_to_generator(function() {
|
|
10340
|
-
var sceneJSON, _tmp, oldScene, _oldScene_bins, oldBinUrls, binFiles, _iterator, _step, bin, _, newScene;
|
|
9568
|
+
var sceneJSON, _tmp, oldScene, _oldScene_bins, oldBinUrls, binFiles, v, _iterator, _step, bin, _, newScene;
|
|
10341
9569
|
return __generator(this, function(_state) {
|
|
10342
9570
|
switch(_state.label){
|
|
10343
9571
|
case 0:
|
|
@@ -10374,6 +9602,14 @@ var JSONConverter = /*#__PURE__*/ function() {
|
|
|
10374
9602
|
oldScene = getStandardJSON(sceneJSON);
|
|
10375
9603
|
oldBinUrls = (_oldScene_bins = oldScene.bins) != null ? _oldScene_bins : [];
|
|
10376
9604
|
binFiles = [];
|
|
9605
|
+
//@ts-expect-error
|
|
9606
|
+
v = sceneJSON.version.split(".");
|
|
9607
|
+
if (Number(v[0]) >= 3) {
|
|
9608
|
+
return [
|
|
9609
|
+
2,
|
|
9610
|
+
oldScene
|
|
9611
|
+
];
|
|
9612
|
+
}
|
|
10377
9613
|
if (!oldScene.bins) return [
|
|
10378
9614
|
3,
|
|
10379
9615
|
7
|
|
@@ -10573,7 +9809,6 @@ var JSONConverter = /*#__PURE__*/ function() {
|
|
|
10573
9809
|
this.createItemsFromTreeComponent(comp, newScene, oldScene);
|
|
10574
9810
|
treeComp.options.tree.animation = undefined;
|
|
10575
9811
|
treeComp.options.tree.animations = undefined;
|
|
10576
|
-
newComponents.push(comp);
|
|
10577
9812
|
} else if (comp.dataType !== spec.DataType.MeshComponent) {
|
|
10578
9813
|
newComponents.push(comp);
|
|
10579
9814
|
}
|
|
@@ -11011,6 +10246,7 @@ var JSONConverter = /*#__PURE__*/ function() {
|
|
|
11011
10246
|
});
|
|
11012
10247
|
});
|
|
11013
10248
|
}
|
|
10249
|
+
treeItem.components = [];
|
|
11014
10250
|
treeItem.components.push({
|
|
11015
10251
|
id: animationComponent.id
|
|
11016
10252
|
});
|
|
@@ -12348,6 +11584,59 @@ var LoaderImpl = /*#__PURE__*/ function() {
|
|
|
12348
11584
|
this.items.push(item);
|
|
12349
11585
|
this.components.push(component);
|
|
12350
11586
|
};
|
|
11587
|
+
_proto.addSkybox = function addSkybox(skybox) {
|
|
11588
|
+
var _this_images, // @ts-expect-error
|
|
11589
|
+
_this_textures;
|
|
11590
|
+
var itemId = generateGUID();
|
|
11591
|
+
var skyboxInfo = PSkyboxCreator.createSkyboxComponentData(skybox);
|
|
11592
|
+
var imageList = skyboxInfo.imageList, textureOptionsList = skyboxInfo.textureOptionsList, component = skyboxInfo.component;
|
|
11593
|
+
component.item.id = itemId;
|
|
11594
|
+
if (skybox.intensity !== undefined) {
|
|
11595
|
+
component.intensity = skybox.intensity;
|
|
11596
|
+
}
|
|
11597
|
+
if (skybox.reflectionsIntensity !== undefined) {
|
|
11598
|
+
component.reflectionsIntensity = skybox.reflectionsIntensity;
|
|
11599
|
+
}
|
|
11600
|
+
var _skybox_renderable;
|
|
11601
|
+
component.renderable = (_skybox_renderable = skybox.renderable) != null ? _skybox_renderable : false;
|
|
11602
|
+
var item = {
|
|
11603
|
+
id: itemId,
|
|
11604
|
+
name: "Skybox-Customize",
|
|
11605
|
+
duration: 999,
|
|
11606
|
+
type: spec.ItemType.skybox,
|
|
11607
|
+
pn: 0,
|
|
11608
|
+
visible: true,
|
|
11609
|
+
endBehavior: spec.EndBehavior.freeze,
|
|
11610
|
+
transform: {
|
|
11611
|
+
position: {
|
|
11612
|
+
x: 0,
|
|
11613
|
+
y: 0,
|
|
11614
|
+
z: 0
|
|
11615
|
+
},
|
|
11616
|
+
eulerHint: {
|
|
11617
|
+
x: 0,
|
|
11618
|
+
y: 0,
|
|
11619
|
+
z: 0
|
|
11620
|
+
},
|
|
11621
|
+
scale: {
|
|
11622
|
+
x: 1,
|
|
11623
|
+
y: 1,
|
|
11624
|
+
z: 1
|
|
11625
|
+
}
|
|
11626
|
+
},
|
|
11627
|
+
components: [
|
|
11628
|
+
{
|
|
11629
|
+
id: component.id
|
|
11630
|
+
}
|
|
11631
|
+
],
|
|
11632
|
+
content: {},
|
|
11633
|
+
dataType: spec.DataType.VFXItemData
|
|
11634
|
+
};
|
|
11635
|
+
(_this_images = this.images).push.apply(_this_images, [].concat(imageList));
|
|
11636
|
+
(_this_textures = this.textures).push.apply(_this_textures, [].concat(textureOptionsList));
|
|
11637
|
+
this.items.push(item);
|
|
11638
|
+
this.components.push(component);
|
|
11639
|
+
};
|
|
12351
11640
|
_proto.tryAddSkybox = function tryAddSkybox(skybox) {
|
|
12352
11641
|
var _this = this;
|
|
12353
11642
|
return _async_to_generator(function() {
|
|
@@ -12482,43 +11771,6 @@ var LoaderImpl = /*#__PURE__*/ function() {
|
|
|
12482
11771
|
});
|
|
12483
11772
|
return sceneAABB;
|
|
12484
11773
|
};
|
|
12485
|
-
/**
|
|
12486
|
-
* 按照传入的动画播放参数,计算需要播放的动画索引
|
|
12487
|
-
*
|
|
12488
|
-
* @param treeOptions 节点树属性,需要初始化animations列表。
|
|
12489
|
-
* @returns 返回计算的动画索引,-1表示没有动画需要播放,-88888888表示播放所有动画。
|
|
12490
|
-
*/ _proto.getPlayAnimationIndex = function getPlayAnimationIndex(treeOptions) {
|
|
12491
|
-
var animations = treeOptions.animations;
|
|
12492
|
-
if (animations === undefined || animations.length <= 0) {
|
|
12493
|
-
// 硬编码,内部指定的不播放动画的索引值
|
|
12494
|
-
return -1;
|
|
12495
|
-
}
|
|
12496
|
-
if (this.isPlayAllAnimation()) {
|
|
12497
|
-
// 硬编码,内部指定的播放全部动画的索引值
|
|
12498
|
-
return -88888888;
|
|
12499
|
-
}
|
|
12500
|
-
var animationInfo = this.sceneOptions.effects.playAnimation;
|
|
12501
|
-
if (animationInfo === undefined) {
|
|
12502
|
-
return -1;
|
|
12503
|
-
}
|
|
12504
|
-
if (typeof animationInfo === "number") {
|
|
12505
|
-
if (animationInfo >= 0 && animationInfo < animations.length) {
|
|
12506
|
-
return animationInfo;
|
|
12507
|
-
} else {
|
|
12508
|
-
return -1;
|
|
12509
|
-
}
|
|
12510
|
-
} else {
|
|
12511
|
-
// typeof animationInfo === 'string'
|
|
12512
|
-
var animationIndex = -1;
|
|
12513
|
-
// 通过动画名字查找动画索引
|
|
12514
|
-
animations.forEach(function(anim, index) {
|
|
12515
|
-
if (anim.name === animationInfo) {
|
|
12516
|
-
animationIndex = index;
|
|
12517
|
-
}
|
|
12518
|
-
});
|
|
12519
|
-
return animationIndex;
|
|
12520
|
-
}
|
|
12521
|
-
};
|
|
12522
11774
|
_proto.isPlayAnimation = function isPlayAnimation() {
|
|
12523
11775
|
return this.sceneOptions.effects.playAnimation !== undefined;
|
|
12524
11776
|
};
|
|
@@ -12660,64 +11912,6 @@ var LoaderImpl = /*#__PURE__*/ function() {
|
|
|
12660
11912
|
}
|
|
12661
11913
|
});
|
|
12662
11914
|
};
|
|
12663
|
-
_proto.createTreeOptions = function createTreeOptions(scene) {
|
|
12664
|
-
var nodeList = scene.nodes.map(function(node, nodeIndex) {
|
|
12665
|
-
var children = node.children.map(function(child) {
|
|
12666
|
-
if (child.nodeIndex === undefined) {
|
|
12667
|
-
throw new Error("Undefined nodeIndex for child " + child);
|
|
12668
|
-
}
|
|
12669
|
-
return child.nodeIndex;
|
|
12670
|
-
});
|
|
12671
|
-
var pos;
|
|
12672
|
-
var quat;
|
|
12673
|
-
var scale;
|
|
12674
|
-
if (node.matrix !== undefined) {
|
|
12675
|
-
if (node.matrix.length !== 16) {
|
|
12676
|
-
throw new Error("Invalid matrix length " + node.matrix.length + " for node " + node);
|
|
12677
|
-
}
|
|
12678
|
-
var mat = Matrix4.fromArray(node.matrix);
|
|
12679
|
-
var transform = mat.getTransform();
|
|
12680
|
-
pos = transform.translation.toArray();
|
|
12681
|
-
quat = transform.rotation.toArray();
|
|
12682
|
-
scale = transform.scale.toArray();
|
|
12683
|
-
} else {
|
|
12684
|
-
if (node.translation !== undefined) {
|
|
12685
|
-
pos = node.translation;
|
|
12686
|
-
}
|
|
12687
|
-
if (node.rotation !== undefined) {
|
|
12688
|
-
quat = node.rotation;
|
|
12689
|
-
}
|
|
12690
|
-
if (node.scale !== undefined) {
|
|
12691
|
-
scale = node.scale;
|
|
12692
|
-
}
|
|
12693
|
-
}
|
|
12694
|
-
node.nodeIndex = nodeIndex;
|
|
12695
|
-
var treeNode = {
|
|
12696
|
-
name: node.name,
|
|
12697
|
-
transform: {
|
|
12698
|
-
position: pos,
|
|
12699
|
-
quat: quat,
|
|
12700
|
-
scale: scale
|
|
12701
|
-
},
|
|
12702
|
-
children: children,
|
|
12703
|
-
id: "" + node.nodeIndex
|
|
12704
|
-
};
|
|
12705
|
-
return treeNode;
|
|
12706
|
-
});
|
|
12707
|
-
var rootNodes = scene.rootNodes.map(function(root) {
|
|
12708
|
-
if (root.nodeIndex === undefined) {
|
|
12709
|
-
throw new Error("Undefined nodeIndex for root " + root);
|
|
12710
|
-
}
|
|
12711
|
-
return root.nodeIndex;
|
|
12712
|
-
});
|
|
12713
|
-
var treeOptions = {
|
|
12714
|
-
nodes: nodeList,
|
|
12715
|
-
children: rootNodes,
|
|
12716
|
-
animation: -1,
|
|
12717
|
-
animations: []
|
|
12718
|
-
};
|
|
12719
|
-
return treeOptions;
|
|
12720
|
-
};
|
|
12721
11915
|
_proto.createAnimations = function createAnimations(animations) {
|
|
12722
11916
|
return animations.map(function(anim) {
|
|
12723
11917
|
var tracks = anim.channels.map(function(channel) {
|