@galacean/effects-plugin-model 2.0.0-alpha.10 → 2.0.0-alpha.12

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 player model plugin
4
4
  * Author: Ant Group CO., Ltd.
5
5
  * Contributors: 飂兮
6
- * Version: v2.0.0-alpha.10
6
+ * Version: v2.0.0-alpha.12
7
7
  */
8
8
 
9
9
  'use strict';
@@ -1373,38 +1373,38 @@ exports.TextureDataMode = void 0;
1373
1373
  /**
1374
1374
  * Morph 动画中 Position 相关的 Attribute 名称
1375
1375
  */ PMorph.positionNameList = [
1376
- "a_Target_Position0",
1377
- "a_Target_Position1",
1378
- "a_Target_Position2",
1379
- "a_Target_Position3",
1380
- "a_Target_Position4",
1381
- "a_Target_Position5",
1382
- "a_Target_Position6",
1383
- "a_Target_Position7"
1376
+ "aTargetPosition0",
1377
+ "aTargetPosition1",
1378
+ "aTargetPosition2",
1379
+ "aTargetPosition3",
1380
+ "aTargetPosition4",
1381
+ "aTargetPosition5",
1382
+ "aTargetPosition6",
1383
+ "aTargetPosition7"
1384
1384
  ];
1385
1385
  /**
1386
1386
  * Morph 动画中 Normal 相关的 Attribute 名称
1387
1387
  */ PMorph.normalNameList = [
1388
- "a_Target_Normal0",
1389
- "a_Target_Normal1",
1390
- "a_Target_Normal2",
1391
- "a_Target_Normal3",
1392
- "a_Target_Normal4",
1393
- "a_Target_Normal5",
1394
- "a_Target_Normal6",
1395
- "a_Target_Normal7"
1388
+ "aTargetNormal0",
1389
+ "aTargetNormal1",
1390
+ "aTargetNormal2",
1391
+ "aTargetNormal3",
1392
+ "aTargetNormal4",
1393
+ "aTargetNormal5",
1394
+ "aTargetNormal6",
1395
+ "aTargetNormal7"
1396
1396
  ];
1397
1397
  /**
1398
1398
  * Morph 动画中 Tangent 相关的 Attribute 名称
1399
1399
  */ PMorph.tangentNameList = [
1400
- "a_Target_Tangent0",
1401
- "a_Target_Tangent1",
1402
- "a_Target_Tangent2",
1403
- "a_Target_Tangent3",
1404
- "a_Target_Tangent4",
1405
- "a_Target_Tangent5",
1406
- "a_Target_Tangent6",
1407
- "a_Target_Tangent7"
1400
+ "aTargetTangent0",
1401
+ "aTargetTangent1",
1402
+ "aTargetTangent2",
1403
+ "aTargetTangent3",
1404
+ "aTargetTangent4",
1405
+ "aTargetTangent5",
1406
+ "aTargetTangent6",
1407
+ "aTargetTangent7"
1408
1408
  ];
1409
1409
  exports.PAnimInterpType = void 0;
1410
1410
  (function(PAnimInterpType) {
@@ -2433,7 +2433,7 @@ function _assert_this_initialized(self) {
2433
2433
  */ parentIndex = -1;
2434
2434
  _this./**
2435
2435
  * primitive 对象数组
2436
- */ primitives = [];
2436
+ */ subMeshes = [];
2437
2437
  _this./**
2438
2438
  * 是否隐藏,默认是隐藏
2439
2439
  */ hide = true;
@@ -2466,13 +2466,16 @@ function _assert_this_initialized(self) {
2466
2466
  _this.hide = proxy.isHide();
2467
2467
  _this.priority = (owner == null ? void 0 : (_owner_item = owner.item) == null ? void 0 : _owner_item.listIndex) || 0;
2468
2468
  //
2469
- _this.primitives = [];
2470
- proxy.getPrimitives().forEach(function(primOpts) {
2471
- var primObj = new PPrimitive(_this.engine);
2472
- primObj.create(primOpts, _assert_this_initialized(_this));
2473
- _this.primitives.push(primObj);
2469
+ _this.subMeshes = [];
2470
+ var geometry = proxy.getGeometry();
2471
+ var _owner_materials;
2472
+ var materials = (_owner_materials = owner == null ? void 0 : owner.materials) != null ? _owner_materials : [];
2473
+ materials.forEach(function(material) {
2474
+ var subMesh = new PSubMesh(_this.engine);
2475
+ subMesh.create(geometry, material, _assert_this_initialized(_this));
2476
+ _this.subMeshes.push(subMesh);
2474
2477
  });
2475
- if (_this.primitives.length <= 0) {
2478
+ if (_this.subMeshes.length <= 0) {
2476
2479
  console.warn("No primitive inside mesh item " + name);
2477
2480
  }
2478
2481
  _this.boundingBox = _this.getItemBoundingBox(meshData.interaction);
@@ -2488,7 +2491,7 @@ function _assert_this_initialized(self) {
2488
2491
  return;
2489
2492
  }
2490
2493
  this.isBuilt = true;
2491
- this.primitives.forEach(function(prim) {
2494
+ this.subMeshes.forEach(function(prim) {
2492
2495
  prim.build(scene.maxLightCount, {}, scene.skybox);
2493
2496
  });
2494
2497
  if (PGlobalState.getInstance().visBoundingBox) {
@@ -2510,9 +2513,8 @@ function _assert_this_initialized(self) {
2510
2513
  var _this_skin;
2511
2514
  (_this_skin = this.skin) == null ? void 0 : _this_skin.updateSkinMatrices();
2512
2515
  this.updateMaterial(scene);
2513
- this.primitives.forEach(function(prim) {
2514
- var mesh = prim.effectsMesh;
2515
- renderer.drawGeometry(mesh.geometry, mesh.material);
2516
+ this.subMeshes.forEach(function(subMesh, index) {
2517
+ renderer.drawGeometry(subMesh.getEffectsGeometry(), subMesh.getEffectsMaterial(), index);
2516
2518
  });
2517
2519
  if (this.visBoundingBox && this.boundingBoxMesh !== undefined) {
2518
2520
  var mesh = this.boundingBoxMesh.mesh;
@@ -2537,10 +2539,10 @@ function _assert_this_initialized(self) {
2537
2539
  this.skin = undefined;
2538
2540
  (_this_morph = this.morph) == null ? void 0 : _this_morph.dispose();
2539
2541
  this.morph = undefined;
2540
- this.primitives.forEach(function(prim) {
2542
+ this.subMeshes.forEach(function(prim) {
2541
2543
  prim.dispose();
2542
2544
  });
2543
- this.primitives = [];
2545
+ this.subMeshes = [];
2544
2546
  (_this_boundingBoxMesh = this.boundingBoxMesh) == null ? void 0 : _this_boundingBoxMesh.dispose();
2545
2547
  this.boundingBoxMesh = undefined;
2546
2548
  };
@@ -2583,7 +2585,7 @@ function _assert_this_initialized(self) {
2583
2585
  var worldMatrix = this.matrix;
2584
2586
  var normalMatrix = worldMatrix.clone().invert().transpose();
2585
2587
  var sceneStates = scene.sceneStates;
2586
- this.primitives.forEach(function(prim) {
2588
+ this.subMeshes.forEach(function(prim) {
2587
2589
  prim.updateMaterial(worldMatrix, normalMatrix, sceneStates);
2588
2590
  });
2589
2591
  if (this.boundingBoxMesh !== undefined) {
@@ -2637,7 +2639,7 @@ function _assert_this_initialized(self) {
2637
2639
  }
2638
2640
  var mint;
2639
2641
  if (PGlobalState.getInstance().isEditorEnv) {
2640
- this.primitives.forEach(function(prim) {
2642
+ this.subMeshes.forEach(function(prim) {
2641
2643
  var primt = prim.hitTesting(newOrigin, newDirection, worldMatrix, invWorldMatrix);
2642
2644
  if (primt !== undefined) {
2643
2645
  if (mint === undefined || mint > primt) {
@@ -2665,7 +2667,7 @@ function _assert_this_initialized(self) {
2665
2667
  */ _proto.computeBoundingBox = function computeBoundingBox(worldMatrix) {
2666
2668
  var box = this.boundingBox.makeEmpty();
2667
2669
  var inverseWorldMatrix = worldMatrix.clone().invert();
2668
- this.primitives.forEach(function(prim) {
2670
+ this.subMeshes.forEach(function(prim) {
2669
2671
  var subbox = prim.computeBoundingBox(inverseWorldMatrix);
2670
2672
  box.union(subbox);
2671
2673
  });
@@ -2722,24 +2724,14 @@ function _assert_this_initialized(self) {
2722
2724
  */ function get() {
2723
2725
  return this.skin !== undefined;
2724
2726
  }
2725
- },
2726
- {
2727
- key: "mriMeshs",
2728
- get: /**
2729
- * 获取 GE Mesh 数组
2730
- */ function get() {
2731
- return this.primitives.map(function(prim) {
2732
- return prim.effectsMesh;
2733
- });
2734
- }
2735
2727
  }
2736
2728
  ]);
2737
2729
  return PMesh;
2738
2730
  }(PEntity);
2739
2731
  /**
2740
- * Primitive 类,负责 Sub Mesh相关的功能,支持骨骼动画和 PBR 渲染
2741
- */ var PPrimitive = /*#__PURE__*/ function() {
2742
- function PPrimitive(engine) {
2732
+ * PSubMesh 类,负责 Sub Mesh相关的功能,支持骨骼动画和 PBR 渲染
2733
+ */ var PSubMesh = /*#__PURE__*/ function() {
2734
+ function PSubMesh(engine) {
2743
2735
  this.engine = engine;
2744
2736
  this./**
2745
2737
  * 名称
@@ -2754,17 +2746,17 @@ function _assert_this_initialized(self) {
2754
2746
  * 是否压缩,模式不压缩
2755
2747
  */ isCompressed = false;
2756
2748
  }
2757
- var _proto = PPrimitive.prototype;
2749
+ var _proto = PSubMesh.prototype;
2758
2750
  /**
2759
2751
  * 创建 Primitive 对象
2760
2752
  * @param data - Primitive 参数
2761
2753
  * @param parent - 所属 Mesh 对象
2762
- */ _proto.create = function create(data, parent) {
2754
+ */ _proto.create = function create(geometry, material, parent) {
2763
2755
  this.parent = parent;
2764
2756
  this.skin = parent.skin;
2765
2757
  this.morph = parent.morph;
2766
- this.setGeometry(data.geometry);
2767
- this.setMaterial(data.material);
2758
+ this.setGeometry(geometry);
2759
+ this.setMaterial(material);
2768
2760
  this.name = parent.name;
2769
2761
  this.effectsPriority = parent.priority;
2770
2762
  this.geometry.setHide(parent.hide);
@@ -2802,6 +2794,7 @@ function _assert_this_initialized(self) {
2802
2794
  var primitiveMacroList = this.getMacroList(lightCount, true, skybox);
2803
2795
  var materialMacroList = this.material.getMacroList(primitiveMacroList);
2804
2796
  var newSemantics = uniformSemantics != null ? uniformSemantics : {};
2797
+ // FIXME: Semantics整体移除
2805
2798
  newSemantics["_ViewProjectionMatrix"] = "VIEWPROJECTION";
2806
2799
  //newSemantics["uView"] = 'VIEWINVERSE';
2807
2800
  newSemantics["_ModelMatrix"] = "MODEL";
@@ -2810,6 +2803,7 @@ function _assert_this_initialized(self) {
2810
2803
  var isWebGL2 = PGlobalState.getInstance().isWebGL2;
2811
2804
  if (this.material.effectMaterial) {
2812
2805
  material = this.material.effectMaterial;
2806
+ // FIXME: Semantics整体移除
2813
2807
  // @ts-expect-error
2814
2808
  material.uniformSemantics = newSemantics;
2815
2809
  materialMacroList.forEach(function(macro) {
@@ -2827,18 +2821,8 @@ function _assert_this_initialized(self) {
2827
2821
  },
2828
2822
  uniformSemantics: newSemantics
2829
2823
  });
2824
+ this.material.setMaterialStates(material);
2830
2825
  }
2831
- var mesh = effects.Mesh.create(this.engine, {
2832
- name: this.name,
2833
- material: material,
2834
- geometry: this.getEffectsGeometry(),
2835
- priority: this.effectsPriority
2836
- });
2837
- if (this.effectsMesh !== undefined) {
2838
- this.effectsMesh.dispose();
2839
- }
2840
- this.effectsMesh = mesh;
2841
- this.material.setMaterialStates(material);
2842
2826
  };
2843
2827
  _proto.getFeatureList = function getFeatureList(lightCount, pbrPass, skybox) {
2844
2828
  var featureList = [];
@@ -3036,12 +3020,6 @@ function _assert_this_initialized(self) {
3036
3020
  this.jointMatrixTexture = undefined;
3037
3021
  (_this_jointNormalMatTexture = this.jointNormalMatTexture) == null ? void 0 : _this_jointNormalMatTexture.dispose();
3038
3022
  this.jointNormalMatTexture = undefined;
3039
- this.effectsMesh.dispose({
3040
- geometries: effects.DestroyOptions.keep,
3041
- material: effects.DestroyOptions.keep
3042
- });
3043
- // @ts-expect-error
3044
- this.effectsMesh = undefined;
3045
3023
  };
3046
3024
  /**
3047
3025
  * 更新内部 GE 材质着色器 Uniform 数据,根据场景状态
@@ -3051,7 +3029,7 @@ function _assert_this_initialized(self) {
3051
3029
  */ _proto.updateMaterial = function updateMaterial(worldMatrix, nomralMatrix, sceneStates) {
3052
3030
  this.updateUniformsByAnimation(worldMatrix, nomralMatrix);
3053
3031
  this.updateUniformsByScene(sceneStates);
3054
- this.material.updateUniforms(this.getModelMaterial());
3032
+ this.material.updateUniforms(this.getEffectsMaterial());
3055
3033
  };
3056
3034
  /**
3057
3035
  * 点击测试,先进行简单的包围合测试,然后再计算精准的点击测试,这个测试非常耗时不要在移动端上使用
@@ -3124,7 +3102,7 @@ function _assert_this_initialized(self) {
3124
3102
  }
3125
3103
  };
3126
3104
  _proto.updateUniformsByAnimation = function updateUniformsByAnimation(worldMatrix, normalMatrix) {
3127
- var material = this.getModelMaterial();
3105
+ var material = this.getEffectsMaterial();
3128
3106
  material.setMatrix("_ModelMatrix", worldMatrix);
3129
3107
  material.setMatrix("_NormalMatrix", normalMatrix);
3130
3108
  //
@@ -3165,7 +3143,7 @@ function _assert_this_initialized(self) {
3165
3143
  }
3166
3144
  };
3167
3145
  _proto.updateUniformsByScene = function updateUniformsByScene(sceneStates) {
3168
- var material = this.getModelMaterial();
3146
+ var material = this.getEffectsMaterial();
3169
3147
  material.setMatrix("_ViewProjectionMatrix", sceneStates.viewProjectionMatrix);
3170
3148
  material.setVector3("_Camera", sceneStates.cameraPosition);
3171
3149
  //
@@ -3262,8 +3240,8 @@ function _assert_this_initialized(self) {
3262
3240
  /**
3263
3241
  * 获取 GE 材质
3264
3242
  * @returns
3265
- */ _proto.getModelMaterial = function getModelMaterial() {
3266
- return this.effectsMesh.material;
3243
+ */ _proto.getEffectsMaterial = function getEffectsMaterial() {
3244
+ return this.material.effectMaterial;
3267
3245
  };
3268
3246
  /**
3269
3247
  * 是否无光照材质
@@ -3298,7 +3276,7 @@ function _assert_this_initialized(self) {
3298
3276
  return this.boundingBox.clone().applyMatrix4(matrix);
3299
3277
  }
3300
3278
  };
3301
- return PPrimitive;
3279
+ return PSubMesh;
3302
3280
  }();
3303
3281
  /**
3304
3282
  * 3D 几何类
@@ -3374,7 +3352,7 @@ function _assert_this_initialized(self) {
3374
3352
  * 是否有切线属性
3375
3353
  * @returns
3376
3354
  */ _proto.hasTangents = function hasTangents() {
3377
- return this.hasAttribute("a_Tangent");
3355
+ return this.hasAttribute("aTangent");
3378
3356
  };
3379
3357
  /**
3380
3358
  * 是否有纹理坐标属性
@@ -3391,19 +3369,19 @@ function _assert_this_initialized(self) {
3391
3369
  * 是否有颜色属性
3392
3370
  * @returns
3393
3371
  */ _proto.hasColors = function hasColors() {
3394
- return this.hasAttribute("a_Color");
3372
+ return this.hasAttribute("aColor");
3395
3373
  };
3396
3374
  /**
3397
3375
  * 是否有关节点属性
3398
3376
  * @returns
3399
3377
  */ _proto.hasJoints = function hasJoints() {
3400
- return this.hasAttribute("a_Joint1");
3378
+ return this.hasAttribute("aJoints");
3401
3379
  };
3402
3380
  /**
3403
3381
  * 是否有权重属性
3404
3382
  * @returns
3405
3383
  */ _proto.hasWeights = function hasWeights() {
3406
- return this.hasAttribute("a_Weight1");
3384
+ return this.hasAttribute("aWeights");
3407
3385
  };
3408
3386
  return PGeometry;
3409
3387
  }();
@@ -3412,35 +3390,7 @@ var EffectsMeshProxy = /*#__PURE__*/ function() {
3412
3390
  this.itemData = itemData;
3413
3391
  this.parentItem = parentItem;
3414
3392
  this.data = itemData;
3415
- // Morph 对象创建,需要为每个 Primitive 中 Geometry 对象创建 Morph
3416
- // 并且要求创建的 Morph 对象状态是相同的,否则就报错
3417
- var isSuccess = true;
3418
- var morphObj = new PMorph();
3419
- var _this_data = this.data, primitives = _this_data.primitives, morph = _this_data.morph;
3420
- primitives.forEach(function(prim, idx) {
3421
- if (idx === 0) {
3422
- morphObj.create(prim.geometry);
3423
- } else {
3424
- var tempMorph = new PMorph();
3425
- if (!tempMorph.create(prim.geometry)) {
3426
- isSuccess = false;
3427
- } else {
3428
- if (!morphObj.equals(tempMorph)) {
3429
- isSuccess = false;
3430
- console.error("Morpth target mismatch between primtives: " + JSON.stringify(morphObj) + ", " + JSON.stringify(tempMorph));
3431
- }
3432
- }
3433
- }
3434
- });
3435
- if (isSuccess) {
3436
- // 设置初始权重数组
3437
- if ((morph == null ? void 0 : morph.weights) !== undefined) {
3438
- morphObj.initWeights(morph.weights);
3439
- }
3440
- this.morphObj = morphObj;
3441
- } else {
3442
- this.morphObj = new PMorph();
3443
- }
3393
+ this.morphObj = new PMorph();
3444
3394
  }
3445
3395
  var _proto = EffectsMeshProxy.prototype;
3446
3396
  _proto.hasMorphTarget = function hasMorphTarget() {
@@ -3472,11 +3422,14 @@ var EffectsMeshProxy = /*#__PURE__*/ function() {
3472
3422
  _proto.getParentIndex = function getParentIndex() {
3473
3423
  return -1;
3474
3424
  };
3475
- _proto.getPrimitives = function getPrimitives() {
3476
- return this.data.primitives;
3425
+ _proto.getGeometry = function getGeometry() {
3426
+ return this.data.geometry;
3427
+ };
3428
+ _proto.getMaterials = function getMaterials() {
3429
+ return this.data.materials;
3477
3430
  };
3478
- _proto.getPrimitiveCount = function getPrimitiveCount() {
3479
- return this.data.primitives.length;
3431
+ _proto.getMaterialCount = function getMaterialCount() {
3432
+ return this.data.materials.length;
3480
3433
  };
3481
3434
  _proto.hasSkin = function hasSkin() {
3482
3435
  // FIXME: skin
@@ -3882,7 +3835,7 @@ var EffectsMeshProxy = /*#__PURE__*/ function() {
3882
3835
  return PSceneManager;
3883
3836
  }();
3884
3837
 
3885
- var primitiveVert = "precision highp float;\n#define FEATURES\n#include <webglCompatibility.glsl>\n#include <animation.vert.glsl>\nvsIn vec4 aPos;vsOut vec3 v_Position;\n#ifdef HAS_NORMALS\nvsIn vec4 aNormal;\n#endif\n#ifdef HAS_TANGENTS\nvsIn vec4 a_Tangent;\n#endif\n#ifdef HAS_NORMALS\n#ifdef HAS_TANGENTS\nvsOut mat3 v_TBN;\n#else\nvsOut vec3 v_Normal;\n#endif\n#endif\n#ifdef HAS_UV_SET1\nvsIn vec2 aUV;\n#endif\n#ifdef HAS_UV_SET2\nvsIn vec2 aUV2;\n#endif\nvsOut vec2 v_UVCoord1;\n#ifdef HAS_UV_SET2\nvsOut vec2 v_UVCoord2;\n#endif\n#ifdef HAS_VERTEX_COLOR_VEC3\nvsIn vec3 a_Color;vsOut vec3 v_Color;\n#endif\n#ifdef HAS_VERTEX_COLOR_VEC4\nvsIn vec4 a_Color;vsOut vec4 v_Color;\n#endif\nuniform mat4 _ViewProjectionMatrix;uniform mat4 _ModelMatrix;uniform mat4 _NormalMatrix;\n#ifdef EDITOR_TRANSFORM\nuniform vec4 uEditorTransform;\n#endif\n#ifdef USE_SHADOW_MAPPING\nuniform mat4 _LightViewProjectionMatrix;uniform float _DeltaSceneSize;vsOut vec4 v_PositionLightSpace;vsOut 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=a_Tangent;\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=_ModelMatrix*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(_ModelMatrix*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=a_Color;\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=_ViewProjectionMatrix*pos;\n#ifdef EDITOR_TRANSFORM\ngl_Position=vec4(gl_Position.xy*uEditorTransform.xy+uEditorTransform.zw*gl_Position.w,gl_Position.zw);\n#endif\n}";
3838
+ var primitiveVert = "precision highp float;\n#define FEATURES\n#include <webglCompatibility.glsl>\n#include <animation.vert.glsl>\nvsIn vec4 aPos;vsOut vec3 v_Position;\n#ifdef HAS_NORMALS\nvsIn vec4 aNormal;\n#endif\n#ifdef HAS_TANGENTS\nvsIn vec4 aTangent;\n#endif\n#ifdef HAS_NORMALS\n#ifdef HAS_TANGENTS\nvsOut mat3 v_TBN;\n#else\nvsOut vec3 v_Normal;\n#endif\n#endif\n#ifdef HAS_UV_SET1\nvsIn vec2 aUV;\n#endif\n#ifdef HAS_UV_SET2\nvsIn vec2 aUV2;\n#endif\nvsOut vec2 v_UVCoord1;\n#ifdef HAS_UV_SET2\nvsOut vec2 v_UVCoord2;\n#endif\n#ifdef HAS_VERTEX_COLOR_VEC3\nvsIn vec3 aColor;vsOut vec3 v_Color;\n#endif\n#ifdef HAS_VERTEX_COLOR_VEC4\nvsIn vec4 aColor;vsOut vec4 v_Color;\n#endif\nuniform mat4 _ViewProjectionMatrix;uniform mat4 _ModelMatrix;uniform mat4 _NormalMatrix;\n#ifdef EDITOR_TRANSFORM\nuniform vec4 uEditorTransform;\n#endif\n#ifdef USE_SHADOW_MAPPING\nuniform mat4 _LightViewProjectionMatrix;uniform float _DeltaSceneSize;vsOut vec4 v_PositionLightSpace;vsOut 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=_ModelMatrix*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(_ModelMatrix*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=_ViewProjectionMatrix*pos;\n#ifdef EDITOR_TRANSFORM\ngl_Position=vec4(gl_Position.xy*uEditorTransform.xy+uEditorTransform.zw*gl_Position.w,gl_Position.zw);\n#endif\n}";
3886
3839
 
3887
3840
  var metallicRoughnessFrag = "\n#define FEATURES\n#ifndef WEBGL2\n#extension GL_OES_standard_derivatives : enable\n#endif\n#if !defined(WEBGL2) && 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#if !defined(WEBGL2) && defined(USE_WBOIT)\n#extension GL_EXT_draw_buffers: require\n#endif\n#ifdef GL_FRAGMENT_PRECISION_HIGH\nprecision highp float;\n#else\nprecision mediump float;\n#endif\n#ifdef WEBGL2\n#ifdef USE_WBOIT\nlayout(location=0)out vec4 outFragColor0;layout(location=1)out vec4 outFragColor1;\n#else\nout vec4 outFragColor;\n#endif\n#else\n#ifdef USE_WBOIT\n#define outFragColor0 gl_FragData[0]\n#define outFragColor1 gl_FragData[1]\n#else\n#define outFragColor gl_FragColor\n#endif\n#endif\n#include <webglCompatibility.glsl>\n#include <extensions.frag.glsl>\n#include <tonemapping.frag.glsl>\n#include <textures.vert.glsl>\n#include <functions.frag.glsl>\n#include <shadowCommon.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 writeFragmentColor(vec4 fragColor){\n#if !defined(ALPHAMODE_OPAQUE) && defined(USE_WBOIT)\nfloat w=weight(gl_FragCoord.z,fragColor.a);fragColor.rgb*=fragColor.a;outFragColor0=vec4(fragColor.rgb*w,fragColor.a);outFragColor1=vec4(fragColor.a*w);\n#else\noutFragColor=fragColor;\n#endif\n}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\nwriteFragmentColor(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\nwriteFragmentColor(fragColorUnlit);\n#else\n#ifdef DEBUG_UV\noutFragColor.rgb=vec3(getDebugUVColor(getBaseColorUV(),getNormal()));\n#endif\n#ifdef DEBUG_METALLIC\noutFragColor.rgb=vec3(metallic);\n#endif\n#ifdef DEBUG_ROUGHNESS\noutFragColor.rgb=vec3(perceptualRoughness);\n#endif\n#ifdef DEBUG_NORMAL\noutFragColor.rgb=getNormal()*0.5+0.5;\n#endif\n#ifdef DEBUG_BASECOLOR\noutFragColor.rgb=LINEARtoSRGB(baseColor.rgb);\n#endif\n#ifdef DEBUG_OCCLUSION\noutFragColor.rgb=vec3(1.0);\n#endif\n#ifdef DEBUG_EMISSIVE\noutFragColor.rgb=vec3(0.0);\n#endif\n#ifdef DEBUG_ALPHA\noutFragColor.rgb=vec3(baseColor.a);\n#endif\noutFragColor.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\nwriteFragmentColor(fragColorOut);\n#else\n#ifdef DEBUG_UV\noutFragColor.rgb=vec3(getDebugUVColor(getBaseColorUV(),normal));\n#endif\n#ifdef DEBUG_METALLIC\noutFragColor.rgb=vec3(metallic);\n#endif\n#ifdef DEBUG_ROUGHNESS\noutFragColor.rgb=vec3(perceptualRoughness);\n#endif\n#ifdef DEBUG_NORMAL\noutFragColor.rgb=normal*0.5+0.5;\n#endif\n#ifdef DEBUG_BASECOLOR\noutFragColor.rgb=LINEARtoSRGB(baseColor.rgb);\n#endif\n#ifdef DEBUG_OCCLUSION\n#ifdef HAS_OCCLUSION_MAP\noutFragColor.rgb=vec3(mix(1.0,ao,_OcclusionStrength));\n#else\noutFragColor.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\noutFragColor.rgb=LINEARtoSRGB(emissive);\n#endif\n#ifdef DEBUG_F0\noutFragColor.rgb=vec3(f0);\n#endif\n#ifdef DEBUG_ALPHA\noutFragColor.rgb=vec3(baseColor.a);\n#endif\noutFragColor.a=1.0;\n#endif\n}";
3888
3841
 
@@ -3892,7 +3845,7 @@ var skyboxVert = "precision highp float;\n#define FEATURES\n#include <webglCompa
3892
3845
 
3893
3846
  var skyboxFrag = "precision highp float;\n#define FEATURES\n#if !defined(WEBGL2) && defined(USE_TEX_LOD)\n#extension GL_EXT_shader_texture_lod : enable\n#endif\n#if !defined(WEBGL2)\n#extension GL_OES_standard_derivatives : enable\n#endif\n#include <webglCompatibility.glsl>\n#include <extensions.frag.glsl>\n#ifdef WEBGL2\nout vec4 outFragColor;\n#else\n#define outFragColor gl_FragColor\n#endif\nuniform sampler2D _brdfLUT;uniform vec2 _IblIntensity;uniform int _MipCount;uniform samplerCube _DiffuseEnvSampler;uniform samplerCube _SpecularEnvSampler;fsIn vec3 v_CameraDir;\n#ifdef IRRADIANCE_COEFFICIENTS\nstruct SHCoefficients{vec3 l00,l1m1,l10,l11,l2m2,l2m1,l20,l21,l22;};uniform SHCoefficients _shCoefficients;vec3 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\nvec3 getIBLContribution(vec3 n,vec3 v){const float metallic=0.9;const float perceptualRoughness=0.1;const vec4 baseColor=vec4(1.0);const vec3 f0=vec3(0.04);const vec3 diffuseColor=baseColor.rgb*(vec3(1.0)-f0)*(1.0-metallic);const vec3 specularColor=mix(f0,baseColor.rgb,metallic);float NdotV=clamp(dot(n,v),0.0,1.0);float lod=clamp(perceptualRoughness*float(_MipCount),0.0,float(_MipCount));vec3 reflection=normalize(reflect(-v,n));vec2 brdfSamplePoint=clamp(vec2(NdotV,perceptualRoughness),vec2(0.0,0.0),vec2(1.0,1.0));vec2 brdf=texture2D(_brdfLUT,brdfSamplePoint).rg;vec4 diffuseSample=vec4(1.0,0.0,0.0,1.0);\n#ifdef IRRADIANCE_COEFFICIENTS\nvec3 irradiance=getIrradiance(n,_shCoefficients);diffuseSample=vec4(irradiance,1.0);\n#else\ndiffuseSample=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\nvec3 diffuseLight=diffuseSample.rgb;vec3 specularLight=specularSample.rgb;vec3 diffuse=diffuseLight*diffuseColor;vec3 specular=specularLight*(specularColor*brdf.x+brdf.y);return diffuse*_IblIntensity[0]+specular*_IblIntensity[1];}void main(){vec3 dir=normalize(v_CameraDir);outFragColor=vec4(getIBLContribution(dir,dir),1.0);}";
3894
3847
 
3895
- var animationVertGLSL = "#ifdef HAS_TARGET_POSITION0\nvsIn vec3 a_Target_Position0;\n#endif\n#ifdef HAS_TARGET_POSITION1\nvsIn vec3 a_Target_Position1;\n#endif\n#ifdef HAS_TARGET_POSITION2\nvsIn vec3 a_Target_Position2;\n#endif\n#ifdef HAS_TARGET_POSITION3\nvsIn vec3 a_Target_Position3;\n#endif\n#ifdef HAS_TARGET_POSITION4\nvsIn vec3 a_Target_Position4;\n#endif\n#ifdef HAS_TARGET_POSITION5\nvsIn vec3 a_Target_Position5;\n#endif\n#ifdef HAS_TARGET_POSITION6\nvsIn vec3 a_Target_Position6;\n#endif\n#ifdef HAS_TARGET_POSITION7\nvsIn vec3 a_Target_Position7;\n#endif\n#ifdef HAS_TARGET_NORMAL0\nvsIn vec3 a_Target_Normal0;\n#endif\n#ifdef HAS_TARGET_NORMAL1\nvsIn vec3 a_Target_Normal1;\n#endif\n#ifdef HAS_TARGET_NORMAL2\nvsIn vec3 a_Target_Normal2;\n#endif\n#ifdef HAS_TARGET_NORMAL3\nvsIn vec3 a_Target_Normal3;\n#endif\n#ifdef HAS_TARGET_NORMAL4\nvsIn vec3 a_Target_Normal4;\n#endif\n#ifdef HAS_TARGET_TANGENT0\nvsIn vec3 a_Target_Tangent0;\n#endif\n#ifdef HAS_TARGET_TANGENT1\nvsIn vec3 a_Target_Tangent1;\n#endif\n#ifdef HAS_TARGET_TANGENT2\nvsIn vec3 a_Target_Tangent2;\n#endif\n#ifdef HAS_TARGET_TANGENT3\nvsIn vec3 a_Target_Tangent3;\n#endif\n#ifdef HAS_TARGET_TANGENT4\nvsIn vec3 a_Target_Tangent4;\n#endif\n#ifdef USE_MORPHING\nuniform float _morphWeights[WEIGHT_COUNT];\n#endif\n#ifdef HAS_JOINT_SET1\nvsIn vec4 a_Joint1;\n#endif\n#ifdef HAS_JOINT_SET2\nvsIn vec4 a_Joint2;\n#endif\n#ifdef HAS_WEIGHT_SET1\nvsIn vec4 a_Weight1;\n#endif\n#ifdef HAS_WEIGHT_SET2\nvsIn vec4 a_Weight2;\n#endif\n#ifdef USE_SKINNING\n#ifdef USE_SKINNING_TEXTURE\nuniform sampler2D _jointMatrixSampler;uniform sampler2D _jointNormalMatrixSampler;\n#else\nuniform mat4 _jointMatrix[JOINT_COUNT];uniform mat4 _jointNormalMatrix[JOINT_COUNT];\n#endif\n#endif\n#define ROW0_U ((0.5 + 0.0) / 4.0)\n#define ROW1_U ((0.5 + 1.0) / 4.0)\n#define ROW2_U ((0.5 + 2.0) / 4.0)\n#define ROW3_U ((0.5 + 3.0) / 4.0)\n#ifdef USE_SKINNING\nmat4 getJointMatrix(float boneNdx){\n#ifdef USE_SKINNING_TEXTURE\nfloat v=(boneNdx+0.5)/float(JOINT_COUNT);return mat4(texture2D(_jointMatrixSampler,vec2(ROW0_U,v)),texture2D(_jointMatrixSampler,vec2(ROW1_U,v)),texture2D(_jointMatrixSampler,vec2(ROW2_U,v)),texture2D(_jointMatrixSampler,vec2(ROW3_U,v)));\n#else\nreturn _jointMatrix[int(boneNdx)];\n#endif\n}mat4 getJointNormalMatrix(float boneNdx){\n#ifdef USE_SKINNING_TEXTURE\nfloat v=(boneNdx+0.5)/float(JOINT_COUNT);return mat4(texture2D(_jointNormalMatrixSampler,vec2(ROW0_U,v)),texture2D(_jointNormalMatrixSampler,vec2(ROW1_U,v)),texture2D(_jointNormalMatrixSampler,vec2(ROW2_U,v)),texture2D(_jointNormalMatrixSampler,vec2(ROW3_U,v)));\n#else\nreturn _jointNormalMatrix[int(boneNdx)];\n#endif\n}mat4 getSkinningMatrix(){mat4 skin=mat4(0);\n#if defined(HAS_WEIGHT_SET1) && defined(HAS_JOINT_SET1)\nskin+=a_Weight1.x*getJointMatrix(a_Joint1.x)+a_Weight1.y*getJointMatrix(a_Joint1.y)+a_Weight1.z*getJointMatrix(a_Joint1.z)+a_Weight1.w*getJointMatrix(a_Joint1.w);\n#endif\nreturn skin;}mat4 getSkinningNormalMatrix(){mat4 skin=mat4(0);\n#if defined(HAS_WEIGHT_SET1) && defined(HAS_JOINT_SET1)\nskin+=a_Weight1.x*getJointNormalMatrix(a_Joint1.x)+a_Weight1.y*getJointNormalMatrix(a_Joint1.y)+a_Weight1.z*getJointNormalMatrix(a_Joint1.z)+a_Weight1.w*getJointNormalMatrix(a_Joint1.w);\n#endif\nreturn skin;}\n#endif\n#ifdef USE_MORPHING\nvec4 getTargetPosition(){vec4 pos=vec4(0);\n#ifdef HAS_TARGET_POSITION0\npos.xyz+=_morphWeights[0]*a_Target_Position0;\n#endif\n#ifdef HAS_TARGET_POSITION1\npos.xyz+=_morphWeights[1]*a_Target_Position1;\n#endif\n#ifdef HAS_TARGET_POSITION2\npos.xyz+=_morphWeights[2]*a_Target_Position2;\n#endif\n#ifdef HAS_TARGET_POSITION3\npos.xyz+=_morphWeights[3]*a_Target_Position3;\n#endif\n#ifdef HAS_TARGET_POSITION4\npos.xyz+=_morphWeights[4]*a_Target_Position4;\n#endif\nreturn pos;}vec4 getTargetNormal(){vec4 normal=vec4(0);\n#ifdef HAS_TARGET_NORMAL0\nnormal.xyz+=_morphWeights[0]*a_Target_Normal0;\n#endif\n#ifdef HAS_TARGET_NORMAL1\nnormal.xyz+=_morphWeights[1]*a_Target_Normal1;\n#endif\n#ifdef HAS_TARGET_NORMAL2\nnormal.xyz+=_morphWeights[2]*a_Target_Normal2;\n#endif\n#ifdef HAS_TARGET_NORMAL3\nnormal.xyz+=_morphWeights[3]*a_Target_Normal3;\n#endif\n#ifdef HAS_TARGET_NORMAL4\nnormal.xyz+=_morphWeights[4]*a_Target_Normal4;\n#endif\nreturn normal;}vec4 getTargetTangent(){vec4 tangent=vec4(0);\n#ifdef HAS_TARGET_TANGENT0\ntangent.xyz+=_morphWeights[0]*a_Target_Tangent0;\n#endif\n#ifdef HAS_TARGET_TANGENT1\ntangent.xyz+=_morphWeights[1]*a_Target_Tangent1;\n#endif\n#ifdef HAS_TARGET_TANGENT2\ntangent.xyz+=_morphWeights[2]*a_Target_Tangent2;\n#endif\n#ifdef HAS_TARGET_TANGENT3\ntangent.xyz+=_morphWeights[3]*a_Target_Tangent3;\n#endif\n#ifdef HAS_TARGET_TANGENT4\ntangent.xyz+=_morphWeights[4]*a_Target_Tangent4;\n#endif\nreturn tangent;}\n#endif\n";
3848
+ var animationVertGLSL = "#ifdef HAS_TARGET_POSITION0\nvsIn vec3 aTargetPosition0;\n#endif\n#ifdef HAS_TARGET_POSITION1\nvsIn vec3 aTargetPosition1;\n#endif\n#ifdef HAS_TARGET_POSITION2\nvsIn vec3 aTargetPosition2;\n#endif\n#ifdef HAS_TARGET_POSITION3\nvsIn vec3 aTargetPosition3;\n#endif\n#ifdef HAS_TARGET_POSITION4\nvsIn vec3 aTargetPosition4;\n#endif\n#ifdef HAS_TARGET_POSITION5\nvsIn vec3 aTargetPosition5;\n#endif\n#ifdef HAS_TARGET_POSITION6\nvsIn vec3 aTargetPosition6;\n#endif\n#ifdef HAS_TARGET_POSITION7\nvsIn vec3 aTargetPosition7;\n#endif\n#ifdef HAS_TARGET_NORMAL0\nvsIn vec3 aTargetNormal0;\n#endif\n#ifdef HAS_TARGET_NORMAL1\nvsIn vec3 aTargetNormal1;\n#endif\n#ifdef HAS_TARGET_NORMAL2\nvsIn vec3 aTargetNormal2;\n#endif\n#ifdef HAS_TARGET_NORMAL3\nvsIn vec3 aTargetNormal3;\n#endif\n#ifdef HAS_TARGET_NORMAL4\nvsIn vec3 aTargetNormal4;\n#endif\n#ifdef HAS_TARGET_TANGENT0\nvsIn vec3 aTargetTangent0;\n#endif\n#ifdef HAS_TARGET_TANGENT1\nvsIn vec3 aTargetTangent1;\n#endif\n#ifdef HAS_TARGET_TANGENT2\nvsIn vec3 aTargetTangent2;\n#endif\n#ifdef HAS_TARGET_TANGENT3\nvsIn vec3 aTargetTangent3;\n#endif\n#ifdef HAS_TARGET_TANGENT4\nvsIn vec3 aTargetTangent4;\n#endif\n#ifdef USE_MORPHING\nuniform float _morphWeights[WEIGHT_COUNT];\n#endif\n#ifdef HAS_JOINT_SET1\nvsIn vec4 aJoints;\n#endif\n#ifdef HAS_JOINT_SET2\nvsIn vec4 aJoint2;\n#endif\n#ifdef HAS_WEIGHT_SET1\nvsIn vec4 aWeights;\n#endif\n#ifdef HAS_WEIGHT_SET2\nvsIn vec4 aWeight2;\n#endif\n#ifdef USE_SKINNING\n#ifdef USE_SKINNING_TEXTURE\nuniform sampler2D _jointMatrixSampler;uniform sampler2D _jointNormalMatrixSampler;\n#else\nuniform mat4 _jointMatrix[JOINT_COUNT];uniform mat4 _jointNormalMatrix[JOINT_COUNT];\n#endif\n#endif\n#define ROW0_U ((0.5 + 0.0) / 4.0)\n#define ROW1_U ((0.5 + 1.0) / 4.0)\n#define ROW2_U ((0.5 + 2.0) / 4.0)\n#define ROW3_U ((0.5 + 3.0) / 4.0)\n#ifdef USE_SKINNING\nmat4 getJointMatrix(float boneNdx){\n#ifdef USE_SKINNING_TEXTURE\nfloat v=(boneNdx+0.5)/float(JOINT_COUNT);return mat4(texture2D(_jointMatrixSampler,vec2(ROW0_U,v)),texture2D(_jointMatrixSampler,vec2(ROW1_U,v)),texture2D(_jointMatrixSampler,vec2(ROW2_U,v)),texture2D(_jointMatrixSampler,vec2(ROW3_U,v)));\n#else\nreturn _jointMatrix[int(boneNdx)];\n#endif\n}mat4 getJointNormalMatrix(float boneNdx){\n#ifdef USE_SKINNING_TEXTURE\nfloat v=(boneNdx+0.5)/float(JOINT_COUNT);return mat4(texture2D(_jointNormalMatrixSampler,vec2(ROW0_U,v)),texture2D(_jointNormalMatrixSampler,vec2(ROW1_U,v)),texture2D(_jointNormalMatrixSampler,vec2(ROW2_U,v)),texture2D(_jointNormalMatrixSampler,vec2(ROW3_U,v)));\n#else\nreturn _jointNormalMatrix[int(boneNdx)];\n#endif\n}mat4 getSkinningMatrix(){mat4 skin=mat4(0);\n#if defined(HAS_WEIGHT_SET1) && defined(HAS_JOINT_SET1)\nskin+=aWeights.x*getJointMatrix(aJoints.x)+aWeights.y*getJointMatrix(aJoints.y)+aWeights.z*getJointMatrix(aJoints.z)+aWeights.w*getJointMatrix(aJoints.w);\n#endif\nreturn skin;}mat4 getSkinningNormalMatrix(){mat4 skin=mat4(0);\n#if defined(HAS_WEIGHT_SET1) && defined(HAS_JOINT_SET1)\nskin+=aWeights.x*getJointNormalMatrix(aJoints.x)+aWeights.y*getJointNormalMatrix(aJoints.y)+aWeights.z*getJointNormalMatrix(aJoints.z)+aWeights.w*getJointNormalMatrix(aJoints.w);\n#endif\nreturn skin;}\n#endif\n#ifdef USE_MORPHING\nvec4 getTargetPosition(){vec4 pos=vec4(0);\n#ifdef HAS_TARGET_POSITION0\npos.xyz+=_morphWeights[0]*aTargetPosition0;\n#endif\n#ifdef HAS_TARGET_POSITION1\npos.xyz+=_morphWeights[1]*aTargetPosition1;\n#endif\n#ifdef HAS_TARGET_POSITION2\npos.xyz+=_morphWeights[2]*aTargetPosition2;\n#endif\n#ifdef HAS_TARGET_POSITION3\npos.xyz+=_morphWeights[3]*aTargetPosition3;\n#endif\n#ifdef HAS_TARGET_POSITION4\npos.xyz+=_morphWeights[4]*aTargetPosition4;\n#endif\nreturn pos;}vec4 getTargetNormal(){vec4 normal=vec4(0);\n#ifdef HAS_TARGET_NORMAL0\nnormal.xyz+=_morphWeights[0]*aTargetNormal0;\n#endif\n#ifdef HAS_TARGET_NORMAL1\nnormal.xyz+=_morphWeights[1]*aTargetNormal1;\n#endif\n#ifdef HAS_TARGET_NORMAL2\nnormal.xyz+=_morphWeights[2]*aTargetNormal2;\n#endif\n#ifdef HAS_TARGET_NORMAL3\nnormal.xyz+=_morphWeights[3]*aTargetNormal3;\n#endif\n#ifdef HAS_TARGET_NORMAL4\nnormal.xyz+=_morphWeights[4]*aTargetNormal4;\n#endif\nreturn normal;}vec4 getTargetTangent(){vec4 tangent=vec4(0);\n#ifdef HAS_TARGET_TANGENT0\ntangent.xyz+=_morphWeights[0]*aTargetTangent0;\n#endif\n#ifdef HAS_TARGET_TANGENT1\ntangent.xyz+=_morphWeights[1]*aTargetTangent1;\n#endif\n#ifdef HAS_TARGET_TANGENT2\ntangent.xyz+=_morphWeights[2]*aTargetTangent2;\n#endif\n#ifdef HAS_TARGET_TANGENT3\ntangent.xyz+=_morphWeights[3]*aTargetTangent3;\n#endif\n#ifdef HAS_TARGET_TANGENT4\ntangent.xyz+=_morphWeights[4]*aTargetTangent4;\n#endif\nreturn tangent;}\n#endif\n";
3896
3849
 
3897
3850
  var extensionsFragGLSL = "vec3 _dFdx(vec3 coord){\n#if defined(GL_OES_standard_derivatives) || defined(WEBGL2)\nreturn dFdx(coord);\n#endif\nreturn vec3(0.0);}vec3 _dFdy(vec3 coord){\n#if defined(GL_OES_standard_derivatives) || defined(WEBGL2)\nreturn dFdy(coord);\n#endif\nreturn vec3(0.0);}\n#ifdef USE_TEX_LOD\nvec4 _textureCubeLodEXT(samplerCube sampler,vec3 coord,float lod){\n#if defined(WEBGL2) || defined(GL_EXT_shader_texture_lod)\nreturn textureCubeLodEXT(sampler,coord,lod);\n#else\nreturn textureCube(sampler,coord,lod);\n#endif\n}\n#endif\n";
3898
3851
 
@@ -4664,6 +4617,7 @@ exports.ModelCameraComponent = /*#__PURE__*/ function(ItemBehaviour) {
4664
4617
  this.timeline = this.item.getComponent(effects.TimelineComponent);
4665
4618
  var scene = getSceneManager(this);
4666
4619
  scene == null ? void 0 : scene.addItem(this.content);
4620
+ this.updateMainCamera();
4667
4621
  };
4668
4622
  /**
4669
4623
  * 组件更新,更新内部对象状态
@@ -5837,132 +5791,42 @@ var normal = new Vector3();
5837
5791
  * @param compatibleMode - 兼容模式
5838
5792
  * @param autoAdjustScene - 是否自动调整
5839
5793
  * @returns 场景信息描述
5840
- */ PluginHelper.preprocessScene = function preprocessScene(scene, runtimeEnv, compatibleMode, autoAdjustScene) {
5794
+ */ PluginHelper.preprocessScene = function preprocessScene(scene, runtimeEnv, compatibleMode) {
5841
5795
  var _this = this;
5842
5796
  var deviceEnv = runtimeEnv !== effects.PLAYER_OPTIONS_ENV_EDITOR;
5843
5797
  var tiny3dMode = compatibleMode === "tiny3d";
5844
5798
  // 默认skybox如何处理需要讨论
5845
5799
  var jsonScene = scene.jsonScene;
5846
- if (jsonScene === undefined || jsonScene.compositions === undefined) {
5800
+ if (!(jsonScene && jsonScene.textures && jsonScene.materials)) {
5847
5801
  // 安全检查
5848
5802
  return {};
5849
5803
  }
5804
+ var dataMap = {};
5805
+ scene.textureOptions.forEach(function(tex) {
5806
+ var id = tex.id;
5807
+ if (id) {
5808
+ dataMap[id] = tex;
5809
+ }
5810
+ });
5850
5811
  var loadSkybox = false;
5851
5812
  if (deviceEnv) {
5852
- var textures = scene.textureOptions;
5853
- jsonScene.compositions.forEach(function(comp) {
5854
- comp.items.forEach(function(item) {
5855
- if (item.type === effects.spec.ItemType.mesh) {
5856
- var meshItem = item;
5857
- var primitives = meshItem.content.options.primitives;
5858
- primitives.forEach(function(prim) {
5859
- var mat = prim.material;
5860
- if (mat.type === effects.spec.MaterialType.pbr) {
5861
- if (mat.baseColorTexture !== undefined) {
5862
- _this.preprocessTextureOptions(mat.baseColorTexture, textures, true, tiny3dMode);
5863
- }
5864
- if (mat.metallicRoughnessTexture !== undefined) {
5865
- _this.preprocessTextureOptions(mat.metallicRoughnessTexture, textures, false, tiny3dMode);
5866
- }
5867
- if (mat.normalTexture !== undefined) {
5868
- _this.preprocessTextureOptions(mat.normalTexture, textures, false, tiny3dMode);
5869
- }
5870
- if (mat.occlusionTexture !== undefined) {
5871
- _this.preprocessTextureOptions(mat.occlusionTexture, textures, false, tiny3dMode);
5872
- }
5873
- if (mat.emissiveTexture !== undefined) {
5874
- _this.preprocessTextureOptions(mat.emissiveTexture, textures, false, tiny3dMode);
5875
- }
5876
- } else {
5877
- if (mat.baseColorTexture !== undefined) {
5878
- _this.preprocessTextureOptions(mat.baseColorTexture, textures, true, tiny3dMode);
5879
- }
5880
- }
5881
- });
5882
- } else if (item.type === effects.spec.ItemType.skybox) {
5883
- loadSkybox = true;
5884
- //
5885
- var skyboxItem = item;
5886
- var options = skyboxItem.content.options;
5887
- _this.preprocessTextureOptions(options.specularImage, textures, false, tiny3dMode);
5888
- if (options.diffuseImage !== undefined) {
5889
- _this.preprocessTextureOptions(options.diffuseImage, textures, false, tiny3dMode);
5890
- }
5891
- }
5892
- });
5813
+ jsonScene.materials.forEach(function(mat) {
5814
+ _this.preprocessTextureOptions(dataMap, mat.textures["_BaseColorSampler"], true, tiny3dMode);
5815
+ _this.preprocessTextureOptions(dataMap, mat.textures["_MetallicRoughnessSampler"], false, tiny3dMode);
5816
+ _this.preprocessTextureOptions(dataMap, mat.textures["_NormalSampler"], false, tiny3dMode);
5817
+ _this.preprocessTextureOptions(dataMap, mat.textures["_OcclusionSampler"], false, tiny3dMode);
5818
+ _this.preprocessTextureOptions(dataMap, mat.textures["_EmissiveSampler"], false, tiny3dMode);
5893
5819
  });
5894
- } else {
5895
- jsonScene.compositions.forEach(function(comp) {
5896
- comp.items.forEach(function(item) {
5897
- if (item.type === effects.spec.ItemType.skybox) {
5898
- loadSkybox = true;
5820
+ jsonScene.components.forEach(function(comp) {
5821
+ if (comp.dataType === effects.spec.DataType.SkyboxComponent) {
5822
+ loadSkybox = true;
5823
+ var skybox = comp;
5824
+ if (skybox.diffuseImage) {
5825
+ _this.preprocessTextureOptions(dataMap, skybox.diffuseImage, false, tiny3dMode);
5899
5826
  }
5900
- });
5901
- });
5902
- }
5903
- if (autoAdjustScene) {
5904
- jsonScene.compositions.forEach(function(comp) {
5905
- var lightCount = 0;
5906
- comp.items.forEach(function(item) {
5907
- if (item.type === effects.spec.ItemType.light || item.type === effects.spec.ItemType.skybox) {
5908
- ++lightCount;
5827
+ if (skybox.specularImage) {
5828
+ _this.preprocessTextureOptions(dataMap, skybox.specularImage, false, tiny3dMode);
5909
5829
  }
5910
- });
5911
- if (lightCount == 0) {
5912
- comp.items.push({
5913
- id: "dir-light1",
5914
- duration: 100,
5915
- name: "dir-light1",
5916
- type: effects.spec.ItemType.light,
5917
- transform: {
5918
- rotation: [
5919
- 45,
5920
- -45,
5921
- 0
5922
- ]
5923
- },
5924
- pluginName: "model",
5925
- endBehavior: 0,
5926
- content: {
5927
- options: {
5928
- lightType: "directional",
5929
- color: [
5930
- 255,
5931
- 255,
5932
- 255,
5933
- 255
5934
- ],
5935
- intensity: 1.5
5936
- }
5937
- }
5938
- });
5939
- comp.items.push({
5940
- id: "dir-light2",
5941
- duration: 100,
5942
- name: "dir-light2",
5943
- type: effects.spec.ItemType.light,
5944
- transform: {
5945
- rotation: [
5946
- 0,
5947
- 90,
5948
- 0
5949
- ]
5950
- },
5951
- pluginName: "model",
5952
- endBehavior: 0,
5953
- content: {
5954
- options: {
5955
- lightType: "directional",
5956
- color: [
5957
- 255,
5958
- 255,
5959
- 255,
5960
- 255
5961
- ],
5962
- intensity: 0.2
5963
- }
5964
- }
5965
- });
5966
5830
  }
5967
5831
  });
5968
5832
  }
@@ -5977,31 +5841,46 @@ var normal = new Vector3();
5977
5841
  * @param isBaseColor - 是否基础颜色
5978
5842
  * @param tiny3dMode - 是否 Tiny3d 模式
5979
5843
  * @returns
5980
- */ PluginHelper.preprocessTextureOptions = function preprocessTextureOptions(index, textures, isBaseColor, tiny3dMode) {
5981
- if (index < 0 || index >= textures.length) {
5844
+ */ PluginHelper.preprocessTextureOptions = function preprocessTextureOptions(dataMap, textureInfo, isBaseColor, tiny3dMode) {
5845
+ if (!tiny3dMode || !textureInfo) {
5982
5846
  return;
5983
5847
  }
5984
- var texOptions = textures[index];
5985
- if (tiny3dMode && texOptions !== undefined) {
5986
- if (texOptions.target === undefined || texOptions.target === effects.glContext.TEXTURE_2D) {
5987
- texOptions.wrapS = effects.glContext.REPEAT;
5988
- texOptions.wrapT = effects.glContext.REPEAT;
5989
- texOptions.magFilter = effects.glContext.LINEAR;
5990
- texOptions.minFilter = effects.glContext.LINEAR_MIPMAP_LINEAR;
5991
- texOptions.generateMipmap = true;
5992
- if (!isBaseColor) {
5993
- texOptions.premultiplyAlpha = true;
5994
- }
5995
- } else if (texOptions.target === effects.glContext.TEXTURE_CUBE_MAP) {
5996
- texOptions.wrapS = effects.glContext.CLAMP_TO_EDGE;
5997
- texOptions.wrapT = effects.glContext.CLAMP_TO_EDGE;
5998
- if (texOptions.mipmaps !== undefined) {
5848
+ var texId;
5849
+ if ("texture" in textureInfo) {
5850
+ texId = textureInfo.texture.id;
5851
+ } else {
5852
+ texId = textureInfo.id;
5853
+ }
5854
+ if (!texId) {
5855
+ return;
5856
+ }
5857
+ var texOptions = dataMap[texId];
5858
+ if (!texOptions) {
5859
+ return;
5860
+ }
5861
+ if (texOptions.target === undefined || texOptions.target === effects.glContext.TEXTURE_2D) {
5862
+ texOptions.wrapS = effects.glContext.REPEAT;
5863
+ texOptions.wrapT = effects.glContext.REPEAT;
5864
+ texOptions.magFilter = effects.glContext.LINEAR;
5865
+ texOptions.minFilter = effects.glContext.LINEAR_MIPMAP_LINEAR;
5866
+ texOptions.generateMipmap = true;
5867
+ if (!isBaseColor) {
5868
+ texOptions.premultiplyAlpha = true;
5869
+ }
5870
+ } else if (texOptions.target === effects.glContext.TEXTURE_CUBE_MAP) {
5871
+ texOptions.wrapS = effects.glContext.CLAMP_TO_EDGE;
5872
+ texOptions.wrapT = effects.glContext.CLAMP_TO_EDGE;
5873
+ if (texOptions.mipmaps !== undefined) {
5874
+ if (texOptions.mipmaps.length === 1) {
5999
5875
  texOptions.magFilter = effects.glContext.LINEAR;
6000
- texOptions.minFilter = effects.glContext.LINEAR_MIPMAP_LINEAR;
5876
+ texOptions.minFilter = effects.glContext.LINEAR;
6001
5877
  } else {
6002
5878
  texOptions.magFilter = effects.glContext.LINEAR;
6003
- texOptions.minFilter = effects.glContext.LINEAR;
5879
+ texOptions.minFilter = effects.glContext.LINEAR_MIPMAP_LINEAR;
6004
5880
  }
5881
+ } else {
5882
+ texOptions.magFilter = effects.glContext.LINEAR;
5883
+ texOptions.minFilter = effects.glContext.LINEAR;
6005
5884
  }
6006
5885
  }
6007
5886
  };
@@ -6156,20 +6035,20 @@ var normal = new Vector3();
6156
6035
  case "NORMAL":
6157
6036
  return "aNormal";
6158
6037
  case "TANGENT":
6159
- return "a_Tangent";
6038
+ return "aTangent";
6160
6039
  case "TEXCOORD_0":
6161
6040
  return "aUV";
6162
6041
  case "TEXCOORD_1":
6163
6042
  return "aUV2";
6164
6043
  case "JOINTS_0":
6165
- return "a_Joint1";
6044
+ return "aJoints";
6166
6045
  case "WEIGHTS_0":
6167
- return "a_Weight1";
6046
+ return "aWeights";
6168
6047
  }
6169
- if (!name.startsWith("a_")) {
6170
- // aPos, aNormal, a_Tangent,
6171
- // aUV, aUV2, a_Joint1, a_Weight1
6172
- // a_Target_XXX
6048
+ if (!name.startsWith("a")) {
6049
+ // aPos, aNormal, aTangent,
6050
+ // aUV, aUV2, aJoints, aWeights
6051
+ // aTargetXXX
6173
6052
  console.warn("Unknown attribute name: " + name);
6174
6053
  }
6175
6054
  return name;
@@ -6238,7 +6117,9 @@ var normal = new Vector3();
6238
6117
  canvas: canvas,
6239
6118
  renderFramework: "webgl2",
6240
6119
  env: effects.PLAYER_OPTIONS_ENV_EDITOR,
6241
- willCaptureImage: true,
6120
+ renderOptions: {
6121
+ willCaptureImage: true
6122
+ },
6242
6123
  manualRender: manualRender
6243
6124
  });
6244
6125
  };
@@ -6564,11 +6445,11 @@ var AttributeArray = /*#__PURE__*/ function() {
6564
6445
  this.position = new AttributeArray();
6565
6446
  this.position.create(positionAttrib, positionArray);
6566
6447
  //
6567
- var jointAttrib = attributes["a_Joint1"];
6568
- var weightAttrib = attributes["a_Weight1"];
6448
+ var jointAttrib = attributes["aJoints"];
6449
+ var weightAttrib = attributes["aWeights"];
6569
6450
  if (jointAttrib !== undefined && weightAttrib !== undefined) {
6570
- var jointArray = geometry.getAttributeData("a_Joint1");
6571
- var weightArray = geometry.getAttributeData("a_Weight1");
6451
+ var jointArray = geometry.getAttributeData("aJoints");
6452
+ var weightArray = geometry.getAttributeData("aWeights");
6572
6453
  this.joint = new AttributeArray();
6573
6454
  this.joint.create(jointAttrib, jointArray);
6574
6455
  this.weight = new AttributeArray();
@@ -6678,11 +6559,11 @@ var AttributeArray = /*#__PURE__*/ function() {
6678
6559
  this.position = new AttributeArray();
6679
6560
  this.position.create(positionAttrib, positionArray);
6680
6561
  //
6681
- var jointAttrib = attributes["a_Joint1"];
6682
- var weightAttrib = attributes["a_Weight1"];
6562
+ var jointAttrib = attributes["aJoints"];
6563
+ var weightAttrib = attributes["aWeights"];
6683
6564
  if (jointAttrib !== undefined && weightAttrib !== undefined) {
6684
- var jointArray = geometry.getAttributeData("a_Joint1");
6685
- var weightArray = geometry.getAttributeData("a_Weight1");
6565
+ var jointArray = geometry.getAttributeData("aJoints");
6566
+ var weightArray = geometry.getAttributeData("aWeights");
6686
6567
  this.joint = new AttributeArray();
6687
6568
  this.joint.create(jointAttrib, jointArray);
6688
6569
  this.weight = new AttributeArray();
@@ -7104,15 +6985,15 @@ var AttributeArray = /*#__PURE__*/ function() {
7104
6985
  // }
7105
6986
  // this.assertGeometryBuffer(v, 'aPos', maxLength);
7106
6987
  // this.assertGeometryBuffer(v, 'aNormal', maxLength);
7107
- // this.assertGeometryBuffer(v, 'a_Tangent', maxLength);
6988
+ // this.assertGeometryBuffer(v, 'aTangent', maxLength);
7108
6989
  // this.assertGeometryBuffer(v, 'aUV', maxLength);
7109
- // this.assertGeometryBuffer(v, 'a_Joint1', maxLength);
7110
- // this.assertGeometryBuffer(v, 'a_Weight1', maxLength);
6990
+ // this.assertGeometryBuffer(v, 'aJoints', maxLength);
6991
+ // this.assertGeometryBuffer(v, 'aWeights', maxLength);
7111
6992
  // // 索引检查
7112
6993
  // if(s !== undefined){
7113
6994
  // const matLen = s.inverseBindMatrices?.length ?? 0;
7114
6995
  // if(matLen > 0){
7115
- // const jointArray = this.createAttributeArray(v, "a_Joint1");
6996
+ // const jointArray = this.createAttributeArray(v, "aJoints");
7116
6997
  // if(jointArray !== undefined){
7117
6998
  // for(let i = 0; i < maxLength; i++){
7118
6999
  // const data = jointArray.getData(i);
@@ -7841,7 +7722,8 @@ exports.CullMode = void 0;
7841
7722
  */ _proto.setMaterialStates = function setMaterialStates(material) {
7842
7723
  if (this.renderType === "Blend") {
7843
7724
  material.blending = true;
7844
- material.depthTest = true;
7725
+ material.depthTest = this.ZTest;
7726
+ material.depthMask = this.ZWrite;
7845
7727
  material.blendEquation = [
7846
7728
  effects.glContext.FUNC_ADD,
7847
7729
  effects.glContext.FUNC_ADD
@@ -7852,7 +7734,6 @@ exports.CullMode = void 0;
7852
7734
  effects.glContext.ONE,
7853
7735
  effects.glContext.ONE_MINUS_SRC_ALPHA
7854
7736
  ];
7855
- material.depthMask = this.ZWrite;
7856
7737
  } else {
7857
7738
  if (PGlobalState.getInstance().isTiny3dMode) {
7858
7739
  material.blending = false;
@@ -8881,6 +8762,7 @@ exports.PSkyboxType = void 0;
8881
8762
  renderable: renderable,
8882
8763
  intensity: intensity,
8883
8764
  reflectionsIntensity: reflectionsIntensity,
8765
+ // @ts-expect-error
8884
8766
  irradianceCoeffs: irradianceCoeffs,
8885
8767
  diffuseImage: diffuseImage,
8886
8768
  specularImage: specularImage,
@@ -8896,6 +8778,55 @@ exports.PSkyboxType = void 0;
8896
8778
  })();
8897
8779
  };
8898
8780
  /**
8781
+ * 创建天空盒选项
8782
+ * @param engine - 引擎
8783
+ * @param params - 天空盒参数
8784
+ * @returns 天空盒选项
8785
+ */ PSkyboxCreator.createSkyboxComponentData = function createSkyboxComponentData(engine, params) {
8786
+ var _imageList;
8787
+ var specularCubeData = this.getSpecularCubeMapData(engine, params);
8788
+ var diffuseCubeData = this.getDiffuseCubeMapData(engine, params);
8789
+ var renderable = params.renderable, intensity = params.intensity, reflectionsIntensity = params.reflectionsIntensity, irradianceCoeffs = params.irradianceCoeffs, specularImageSize = params.specularImageSize, specularMipCount = params.specularMipCount;
8790
+ var diffuseImage;
8791
+ var imageList = [];
8792
+ var textureOptionsList = [];
8793
+ if (diffuseCubeData) {
8794
+ var _imageList1;
8795
+ (_imageList1 = imageList).push.apply(_imageList1, [].concat(diffuseCubeData.images));
8796
+ textureOptionsList.push(diffuseCubeData.textureOptions);
8797
+ diffuseImage = {
8798
+ id: diffuseCubeData.textureOptions.id
8799
+ };
8800
+ }
8801
+ (_imageList = imageList).push.apply(_imageList, [].concat(specularCubeData.images));
8802
+ textureOptionsList.push(specularCubeData.textureOptions);
8803
+ var specularImage = {
8804
+ id: specularCubeData.textureOptions.id
8805
+ };
8806
+ var componentData = {
8807
+ id: effects.generateGUID(),
8808
+ dataType: effects.spec.DataType.SkyboxComponent,
8809
+ item: {
8810
+ id: effects.generateGUID()
8811
+ },
8812
+ renderable: renderable,
8813
+ intensity: intensity,
8814
+ reflectionsIntensity: reflectionsIntensity,
8815
+ irradianceCoeffs: irradianceCoeffs,
8816
+ // @ts-expect-error
8817
+ diffuseImage: diffuseImage,
8818
+ // @ts-expect-error
8819
+ specularImage: specularImage,
8820
+ specularImageSize: specularImageSize,
8821
+ specularMipCount: specularMipCount
8822
+ };
8823
+ return {
8824
+ imageList: imageList,
8825
+ textureOptionsList: textureOptionsList,
8826
+ component: componentData
8827
+ };
8828
+ };
8829
+ /**
8899
8830
  * 创建高光 Cube Map 纹理
8900
8831
  * @param engine - 引擎
8901
8832
  * @param params - 天空盒参数
@@ -8923,6 +8854,37 @@ exports.PSkyboxType = void 0;
8923
8854
  });
8924
8855
  })();
8925
8856
  };
8857
+ PSkyboxCreator.getSpecularCubeMapData = function getSpecularCubeMapData(engine, params) {
8858
+ var imageDatas = [];
8859
+ var mipmaps = [];
8860
+ params.specularImage.forEach(function(cubemap) {
8861
+ var mipmap = [];
8862
+ cubemap.forEach(function(image) {
8863
+ var imageId = effects.generateGUID();
8864
+ imageDatas.push({
8865
+ id: imageId,
8866
+ // @ts-expect-error
8867
+ url: image
8868
+ });
8869
+ mipmap.push({
8870
+ id: imageId
8871
+ });
8872
+ });
8873
+ mipmaps.push(mipmap);
8874
+ });
8875
+ var textureOptions = _extends({
8876
+ id: effects.generateGUID(),
8877
+ dataType: effects.spec.DataType.Texture,
8878
+ sourceType: effects.TextureSourceType.mipmaps,
8879
+ target: effects.glContext.TEXTURE_CUBE_MAP,
8880
+ // @ts-expect-error
8881
+ mipmaps: mipmaps
8882
+ }, WebGLHelper.cubemapMipTexConfig);
8883
+ return {
8884
+ images: imageDatas,
8885
+ textureOptions: textureOptions
8886
+ };
8887
+ };
8926
8888
  /**
8927
8889
  * 创建漫反射纹理
8928
8890
  * @param engine - 引擎
@@ -8951,6 +8913,38 @@ exports.PSkyboxType = void 0;
8951
8913
  });
8952
8914
  })();
8953
8915
  };
8916
+ PSkyboxCreator.getDiffuseCubeMapData = function getDiffuseCubeMapData(engine, params) {
8917
+ if (params.diffuseImage === undefined) {
8918
+ return;
8919
+ }
8920
+ var imageDatas = [];
8921
+ var cubemap = [];
8922
+ params.diffuseImage.forEach(function(image) {
8923
+ var imageId = effects.generateGUID();
8924
+ imageDatas.push({
8925
+ id: imageId,
8926
+ // @ts-expect-error
8927
+ url: image
8928
+ });
8929
+ cubemap.push({
8930
+ id: imageId
8931
+ });
8932
+ });
8933
+ var textureOptions = _extends({
8934
+ id: effects.generateGUID(),
8935
+ dataType: effects.spec.DataType.Texture,
8936
+ sourceType: effects.TextureSourceType.mipmaps,
8937
+ target: effects.glContext.TEXTURE_CUBE_MAP,
8938
+ // @ts-expect-error
8939
+ mipmaps: [
8940
+ cubemap
8941
+ ]
8942
+ }, WebGLHelper.cubemapTexConfig);
8943
+ return {
8944
+ images: imageDatas,
8945
+ textureOptions: textureOptions
8946
+ };
8947
+ };
8954
8948
  /**
8955
8949
  * 创建天空盒参数
8956
8950
  * @param skyboxType - 天空盒类型
@@ -9041,15 +9035,7 @@ exports.PSkyboxType = void 0;
9041
9035
  ];
9042
9036
  break;
9043
9037
  }
9044
- var returnArray = [];
9045
- for(var i = 0; i < dataArray.length; i += 3){
9046
- returnArray.push([
9047
- dataArray[i],
9048
- dataArray[i + 1],
9049
- dataArray[i + 2]
9050
- ]);
9051
- }
9052
- return returnArray;
9038
+ return dataArray;
9053
9039
  };
9054
9040
  PSkyboxCreator.getDiffuseImageList = function getDiffuseImageList(skyboxType, images) {
9055
9041
  if (skyboxType == 0) {
@@ -9429,7 +9415,8 @@ exports.PSkyboxType = void 0;
9429
9415
  var engine = composition.renderer.engine;
9430
9416
  this.cache = new CompositionCache(engine);
9431
9417
  this.cache.setup(false);
9432
- PluginHelper.setupItem3DOptions(scene, this.cache, composition);
9418
+ // FIXME: 先注释元素参数的配置
9419
+ //PluginHelper.setupItem3DOptions(scene, this.cache, composition);
9433
9420
  };
9434
9421
  /**
9435
9422
  * 每次播放都会执行,包括重播,所以这里执行“小的销毁”和新的初始化
@@ -9467,7 +9454,7 @@ exports.PSkyboxType = void 0;
9467
9454
  * @param options - 加载选项
9468
9455
  */ ModelPlugin.prepareResource = function prepareResource(scene, options) {
9469
9456
  return _async_to_generator(function() {
9470
- var keyList, pluginData, _options_env, runtimeEnv;
9457
+ var _options_pluginData, keyList, pluginData, _options_env, runtimeEnv, _options_pluginData_compatibleMode, compatibleMode;
9471
9458
  return __generator(this, function(_state) {
9472
9459
  switch(_state.label){
9473
9460
  case 0:
@@ -9489,10 +9476,9 @@ exports.PSkyboxType = void 0;
9489
9476
  //
9490
9477
  runtimeEnv = (_options_env = options.env) != null ? _options_env : "";
9491
9478
  scene.storage["runtimeEnv"] = runtimeEnv;
9492
- // const compatibleMode = options.pluginData?.['compatibleMode'] ?? 'gltf';
9493
- // const autoAdjustScene = options.pluginData?.['autoAdjustScene'] ?? false;
9479
+ compatibleMode = (_options_pluginData_compatibleMode = (_options_pluginData = options.pluginData) == null ? void 0 : _options_pluginData["compatibleMode"]) != null ? _options_pluginData_compatibleMode : "gltf";
9494
9480
  //
9495
- //PluginHelper.preprocessScene(scene, runtimeEnv, compatibleMode, autoAdjustScene);
9481
+ PluginHelper.preprocessScene(scene, runtimeEnv, compatibleMode);
9496
9482
  return [
9497
9483
  4,
9498
9484
  CompositionCache.loadStaticResources()
@@ -11322,7 +11308,7 @@ var GeometryProxy = /*#__PURE__*/ function() {
11322
11308
  if (this.hasTangent) {
11323
11309
  var attrib2 = this.tangentAttrib;
11324
11310
  if (attrib2 !== undefined) {
11325
- attributes["a_Tangent"] = this._getBufferAttrib(attrib2);
11311
+ attributes["aTangent"] = this._getBufferAttrib(attrib2);
11326
11312
  }
11327
11313
  }
11328
11314
  this.texCoordList.forEach(function(val) {
@@ -11333,11 +11319,11 @@ var GeometryProxy = /*#__PURE__*/ function() {
11333
11319
  if (this.hasSkinAnimation) {
11334
11320
  var jointAttrib = this.jointAttribute;
11335
11321
  if (jointAttrib !== undefined) {
11336
- attributes["a_Joint1"] = this._getBufferAttrib(jointAttrib);
11322
+ attributes["aJoints"] = this._getBufferAttrib(jointAttrib);
11337
11323
  }
11338
11324
  var weightAttrib = this.weightAttribute;
11339
11325
  if (weightAttrib !== undefined) {
11340
- attributes["a_Weight1"] = this._getBufferAttrib(weightAttrib);
11326
+ attributes["aWeights"] = this._getBufferAttrib(weightAttrib);
11341
11327
  }
11342
11328
  }
11343
11329
  /**
@@ -11345,15 +11331,15 @@ var GeometryProxy = /*#__PURE__*/ function() {
11345
11331
  */ for(var i = 0; i < 8; i++){
11346
11332
  var positionAttrib = this.getTargetPosition(i);
11347
11333
  if (positionAttrib !== undefined) {
11348
- attributes["a_Target_Position" + i] = this._getBufferAttrib(positionAttrib);
11334
+ attributes["aTargetPosition" + i] = this._getBufferAttrib(positionAttrib);
11349
11335
  }
11350
11336
  var normalAttrib = this.getTargetNormal(i);
11351
11337
  if (normalAttrib !== undefined) {
11352
- attributes["a_Target_Normal" + i] = this._getBufferAttrib(normalAttrib);
11338
+ attributes["aTargetNormal" + i] = this._getBufferAttrib(normalAttrib);
11353
11339
  }
11354
11340
  var tangentAttrib = this.getTargetTangent(i);
11355
11341
  if (tangentAttrib !== undefined) {
11356
- attributes["a_Target_Tangent" + i] = this._getBufferAttrib(tangentAttrib);
11342
+ attributes["aTargetTangent" + i] = this._getBufferAttrib(tangentAttrib);
11357
11343
  }
11358
11344
  }
11359
11345
  var indexArray = this.indexArray;
@@ -11803,9 +11789,1076 @@ var GLTFHelper = /*#__PURE__*/ function() {
11803
11789
  return GLTFHelper;
11804
11790
  }();
11805
11791
 
11792
+ function _array_like_to_array(arr, len) {
11793
+ if (len == null || len > arr.length) len = arr.length;
11794
+ for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
11795
+ return arr2;
11796
+ }
11797
+
11798
+ function _unsupported_iterable_to_array(o, minLen) {
11799
+ if (!o) return;
11800
+ if (typeof o === "string") return _array_like_to_array(o, minLen);
11801
+ var n = Object.prototype.toString.call(o).slice(8, -1);
11802
+ if (n === "Object" && o.constructor) n = o.constructor.name;
11803
+ if (n === "Map" || n === "Set") return Array.from(n);
11804
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
11805
+ }
11806
+
11807
+ function _create_for_of_iterator_helper_loose(o, allowArrayLike) {
11808
+ var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
11809
+ if (it) return (it = it.call(o)).next.bind(it);
11810
+ // Fallback for engines without symbol support
11811
+ if (Array.isArray(o) || (it = _unsupported_iterable_to_array(o)) || allowArrayLike && o && typeof o.length === "number") {
11812
+ if (it) o = it;
11813
+ var i = 0;
11814
+ return function() {
11815
+ if (i >= o.length) return {
11816
+ done: true
11817
+ };
11818
+ return {
11819
+ done: false,
11820
+ value: o[i++]
11821
+ };
11822
+ };
11823
+ }
11824
+ throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
11825
+ }
11826
+
11827
+ var JSONConverter = /*#__PURE__*/ function() {
11828
+ function JSONConverter(player) {
11829
+ this.treeItemList = [];
11830
+ this.engine = player.renderer.engine;
11831
+ this.renderer = player.renderer;
11832
+ this.downloader = new effects.Downloader();
11833
+ }
11834
+ var _proto = JSONConverter.prototype;
11835
+ _proto.processScene = function processScene(sceneData) {
11836
+ var _this = this;
11837
+ return _async_to_generator(function() {
11838
+ var sceneJSON, oldScene, binFiles, _iterator, _step, bin, _, newScene;
11839
+ return __generator(this, function(_state) {
11840
+ switch(_state.label){
11841
+ case 0:
11842
+ if (!_instanceof1(sceneData, Object)) return [
11843
+ 3,
11844
+ 1
11845
+ ];
11846
+ sceneJSON = sceneData;
11847
+ return [
11848
+ 3,
11849
+ 3
11850
+ ];
11851
+ case 1:
11852
+ return [
11853
+ 4,
11854
+ _this.loadJSON(sceneData)
11855
+ ];
11856
+ case 2:
11857
+ sceneJSON = _state.sent();
11858
+ _state.label = 3;
11859
+ case 3:
11860
+ // @ts-expect-error
11861
+ sceneJSON.textures.forEach(function(tex) {
11862
+ if (tex.source === undefined) {
11863
+ tex.source = 0;
11864
+ }
11865
+ });
11866
+ oldScene = effects.getStandardJSON(sceneJSON);
11867
+ binFiles = [];
11868
+ if (!oldScene.bins) return [
11869
+ 3,
11870
+ 7
11871
+ ];
11872
+ _iterator = _create_for_of_iterator_helper_loose(oldScene.bins);
11873
+ _state.label = 4;
11874
+ case 4:
11875
+ if (!!(_step = _iterator()).done) return [
11876
+ 3,
11877
+ 7
11878
+ ];
11879
+ bin = _step.value;
11880
+ _ = binFiles.push;
11881
+ return [
11882
+ 4,
11883
+ _this.loadBins(bin.url)
11884
+ ];
11885
+ case 5:
11886
+ _.apply(binFiles, [
11887
+ _state.sent()
11888
+ ]);
11889
+ _state.label = 6;
11890
+ case 6:
11891
+ return [
11892
+ 3,
11893
+ 4
11894
+ ];
11895
+ case 7:
11896
+ // @ts-expect-error
11897
+ oldScene.bins = binFiles;
11898
+ newScene = {
11899
+ version: "3.0",
11900
+ playerVersion: {
11901
+ web: "3.0",
11902
+ native: "3.0"
11903
+ },
11904
+ type: "ge",
11905
+ compositions: [],
11906
+ compositionId: oldScene.compositionId,
11907
+ images: [],
11908
+ shapes: oldScene.shapes,
11909
+ plugins: oldScene.plugins,
11910
+ textures: [],
11911
+ items: [],
11912
+ components: [],
11913
+ materials: [],
11914
+ shaders: [],
11915
+ geometries: []
11916
+ };
11917
+ _this.treeItemList = [];
11918
+ _this.setImage(newScene, oldScene);
11919
+ return [
11920
+ 4,
11921
+ _this.setTexture(newScene, oldScene)
11922
+ ];
11923
+ case 8:
11924
+ _state.sent();
11925
+ _this.setComponent(newScene, oldScene);
11926
+ _this.setItem(newScene, oldScene);
11927
+ _this.setComposition(newScene, oldScene);
11928
+ return [
11929
+ 2,
11930
+ newScene
11931
+ ];
11932
+ }
11933
+ });
11934
+ })();
11935
+ };
11936
+ _proto.setImage = function setImage(newScene, oldScene) {
11937
+ var newImages = [];
11938
+ oldScene.images.forEach(function(image) {
11939
+ newImages.push(image);
11940
+ });
11941
+ newScene.images = newImages;
11942
+ };
11943
+ _proto.setTexture = function setTexture(newScene, oldScene) {
11944
+ var _this = this;
11945
+ return _async_to_generator(function() {
11946
+ var newTextures, bins, _iterator, _step, tex, mipmaps, target, jobs, loadedMipmaps, newMipmaps, newTex, source;
11947
+ return __generator(this, function(_state) {
11948
+ switch(_state.label){
11949
+ case 0:
11950
+ newTextures = [];
11951
+ bins = oldScene.bins;
11952
+ if (!oldScene.textures) return [
11953
+ 3,
11954
+ 5
11955
+ ];
11956
+ _iterator = _create_for_of_iterator_helper_loose(oldScene.textures);
11957
+ _state.label = 1;
11958
+ case 1:
11959
+ if (!!(_step = _iterator()).done) return [
11960
+ 3,
11961
+ 5
11962
+ ];
11963
+ tex = _step.value;
11964
+ if (!(tex.target === 34067)) return [
11965
+ 3,
11966
+ 3
11967
+ ];
11968
+ mipmaps = tex.mipmaps, target = tex.target;
11969
+ jobs = mipmaps.map(function(mipmap) {
11970
+ return Promise.all(mipmap.map(function(pointer) {
11971
+ return _this.loadMipmapImage(pointer, bins);
11972
+ }));
11973
+ });
11974
+ return [
11975
+ 4,
11976
+ Promise.all(jobs)
11977
+ ];
11978
+ case 2:
11979
+ loadedMipmaps = _state.sent();
11980
+ newMipmaps = loadedMipmaps.map(function(mipmaps) {
11981
+ return mipmaps.map(function(img) {
11982
+ var id = effects.generateGUID();
11983
+ var sceneImage = {
11984
+ url: img,
11985
+ id: id
11986
+ };
11987
+ newScene.images.push(sceneImage);
11988
+ var dataPath = {
11989
+ id: id
11990
+ };
11991
+ return dataPath;
11992
+ });
11993
+ });
11994
+ newTex = _extends({
11995
+ keepImageSource: false
11996
+ }, tex, {
11997
+ mipmaps: newMipmaps,
11998
+ sourceFrom: {
11999
+ target: target,
12000
+ type: effects.TextureSourceType.mipmaps,
12001
+ mipmaps: mipmaps.map(function(mipmap) {
12002
+ return mipmap.map(function(pointer) {
12003
+ return [
12004
+ pointer[1][1],
12005
+ pointer[1][2]
12006
+ ];
12007
+ });
12008
+ })
12009
+ }
12010
+ });
12011
+ // @ts-expect-error
12012
+ newTextures.push(newTex);
12013
+ return [
12014
+ 3,
12015
+ 4
12016
+ ];
12017
+ case 3:
12018
+ // @ts-expect-error
12019
+ source = tex.source;
12020
+ if (typeof source === "number") {
12021
+ // @ts-expect-error
12022
+ tex.source = {
12023
+ id: newScene.images[source].id
12024
+ };
12025
+ }
12026
+ newTextures.push(tex);
12027
+ _state.label = 4;
12028
+ case 4:
12029
+ return [
12030
+ 3,
12031
+ 1
12032
+ ];
12033
+ case 5:
12034
+ newScene.textures = newTextures;
12035
+ return [
12036
+ 2
12037
+ ];
12038
+ }
12039
+ });
12040
+ })();
12041
+ };
12042
+ _proto.setComponent = function setComponent(newScene, oldScene) {
12043
+ var newComponents = newScene.components;
12044
+ for(var _iterator = _create_for_of_iterator_helper_loose(oldScene.components), _step; !(_step = _iterator()).done;){
12045
+ var comp = _step.value;
12046
+ if (comp.dataType === effects.spec.DataType.SkyboxComponent) {
12047
+ newComponents.push(this.createSkyboxComponent(comp, newScene));
12048
+ } else if (comp.dataType === effects.spec.DataType.MeshComponent) {
12049
+ newComponents.push(this.createMeshComponent(comp, newScene, oldScene));
12050
+ } else if (comp.dataType === effects.spec.DataType.LightComponent) {
12051
+ newComponents.push(this.createLightComponent(comp, newScene));
12052
+ } else if (comp.dataType === effects.spec.DataType.CameraComponent) {
12053
+ newComponents.push(comp);
12054
+ console.warn("Find camera component", comp);
12055
+ } else if (comp.dataType === effects.spec.DataType.TreeComponent) {
12056
+ var treeComp = comp;
12057
+ this.createItemsFromTreeComponent(comp, newScene, oldScene);
12058
+ treeComp.options.tree.animation = undefined;
12059
+ treeComp.options.tree.animations = undefined;
12060
+ newComponents.push(comp);
12061
+ } else {
12062
+ newComponents.push(comp);
12063
+ }
12064
+ }
12065
+ };
12066
+ _proto.setItem = function setItem(newScene, oldScene) {};
12067
+ _proto.setComposition = function setComposition(newScene, oldScene) {
12068
+ var _newScene_items;
12069
+ newScene.items = oldScene.items;
12070
+ (_newScene_items = newScene.items).push.apply(_newScene_items, [].concat(this.treeItemList));
12071
+ newScene.compositionId = oldScene.compositionId;
12072
+ newScene.compositions = oldScene.compositions;
12073
+ newScene.items.forEach(function(item) {
12074
+ // @ts-expect-error
12075
+ if (item.type === "root") {
12076
+ // @ts-expect-error
12077
+ item.type = "ECS";
12078
+ }
12079
+ });
12080
+ // @ts-expect-error
12081
+ newScene.compositions[0].items = newScene.items.map(function(item) {
12082
+ return {
12083
+ id: item.id
12084
+ };
12085
+ });
12086
+ };
12087
+ _proto.loadJSON = function loadJSON(url) {
12088
+ var _this = this;
12089
+ return _async_to_generator(function() {
12090
+ return __generator(this, function(_state) {
12091
+ return [
12092
+ 2,
12093
+ new Promise(function(resolve, reject) {
12094
+ _this.downloader.downloadJSON(url, resolve, function(status, responseText) {
12095
+ reject(new Error("Couldn't load JSON " + JSON.stringify(url) + ": status " + status + ", " + responseText));
12096
+ });
12097
+ })
12098
+ ];
12099
+ });
12100
+ })();
12101
+ };
12102
+ _proto.loadBins = function loadBins(url) {
12103
+ var _this = this;
12104
+ return _async_to_generator(function() {
12105
+ return __generator(this, function(_state) {
12106
+ return [
12107
+ 2,
12108
+ new Promise(function(resolve, reject) {
12109
+ _this.downloader.downloadBinary(url, resolve, function(status, responseText) {
12110
+ reject("Couldn't load bins " + JSON.stringify(url) + ": status " + status + ", " + responseText);
12111
+ });
12112
+ })
12113
+ ];
12114
+ });
12115
+ })();
12116
+ };
12117
+ _proto.loadMipmapImage = function loadMipmapImage(pointer, bins) {
12118
+ return _async_to_generator(function() {
12119
+ var _pointer_, index, start, length, bin;
12120
+ return __generator(this, function(_state) {
12121
+ _pointer_ = pointer[1], index = _pointer_[0], start = _pointer_[1], length = _pointer_[2];
12122
+ bin = bins[index];
12123
+ if (!bin) {
12124
+ throw new Error("invalid bin pointer: " + JSON.stringify(pointer));
12125
+ }
12126
+ return [
12127
+ 2,
12128
+ URL.createObjectURL(new Blob([
12129
+ new Uint8Array(bin, start, length)
12130
+ ]))
12131
+ ];
12132
+ });
12133
+ })();
12134
+ };
12135
+ _proto.createSkyboxComponent = function createSkyboxComponent(component, scene) {
12136
+ var skyboxOptions = component.options;
12137
+ var irradianceCoeffs;
12138
+ if (skyboxOptions.irradianceCoeffs) {
12139
+ var _irradianceCoeffs;
12140
+ irradianceCoeffs = [];
12141
+ skyboxOptions.irradianceCoeffs.forEach(function(coeffs) {
12142
+ return (_irradianceCoeffs = irradianceCoeffs).push.apply(_irradianceCoeffs, [].concat(coeffs));
12143
+ });
12144
+ }
12145
+ var diffuseImage;
12146
+ if (skyboxOptions.diffuseImage) {
12147
+ // @ts-expect-error
12148
+ diffuseImage = {
12149
+ id: scene.textures[skyboxOptions.diffuseImage].id
12150
+ };
12151
+ }
12152
+ var skyboxComponent = {
12153
+ id: component.id,
12154
+ dataType: component.dataType,
12155
+ item: component.item,
12156
+ renderable: skyboxOptions.renderable,
12157
+ intensity: skyboxOptions.intensity,
12158
+ reflectionsIntensity: skyboxOptions.reflectionsIntensity,
12159
+ irradianceCoeffs: irradianceCoeffs,
12160
+ diffuseImage: diffuseImage,
12161
+ specularImage: {
12162
+ // @ts-expect-error
12163
+ id: scene.textures[skyboxOptions.specularImage].id
12164
+ },
12165
+ specularImageSize: skyboxOptions.specularImageSize,
12166
+ specularMipCount: skyboxOptions.specularMipCount
12167
+ };
12168
+ return skyboxComponent;
12169
+ };
12170
+ _proto.createMeshComponent = function createMeshComponent(component, newScene, oldScene) {
12171
+ var _this = this;
12172
+ var _newScene_materials;
12173
+ var meshOptions = component.options;
12174
+ var geometryPropsList = [];
12175
+ var materialDatas = [];
12176
+ meshOptions.primitives.forEach(function(prim) {
12177
+ var _geomProps_indices;
12178
+ var geomProps = deserializeGeometry(prim.geometry, oldScene.bins);
12179
+ var material = _this.getMaterialData(prim.material, oldScene);
12180
+ if (_instanceof1((_geomProps_indices = geomProps.indices) == null ? void 0 : _geomProps_indices.data, Uint8Array)) {
12181
+ var oldIndices = geomProps.indices.data;
12182
+ var newIndices = new Uint16Array(oldIndices.length);
12183
+ for(var i = 0; i < oldIndices.length; i++){
12184
+ newIndices[i] = oldIndices[i];
12185
+ }
12186
+ geomProps.indices.data = newIndices;
12187
+ }
12188
+ geometryPropsList.push(geomProps);
12189
+ materialDatas.push(material);
12190
+ });
12191
+ var geometryData = getGeometryDataFromPropsList(geometryPropsList);
12192
+ if (!geometryData) {
12193
+ throw new Error("no primitives");
12194
+ }
12195
+ newScene.geometries.push(geometryData);
12196
+ (_newScene_materials = newScene.materials).push.apply(_newScene_materials, [].concat(materialDatas));
12197
+ var meshComponent = {
12198
+ id: component.id,
12199
+ dataType: component.dataType,
12200
+ item: component.item,
12201
+ geometry: {
12202
+ id: geometryData.id
12203
+ },
12204
+ materials: materialDatas.map(function(mat) {
12205
+ var data = {
12206
+ id: mat.id
12207
+ };
12208
+ return data;
12209
+ }),
12210
+ rootBone: {
12211
+ id: ""
12212
+ }
12213
+ };
12214
+ return meshComponent;
12215
+ };
12216
+ _proto.createItemsFromTreeComponent = function createItemsFromTreeComponent(component, newScene, oldScene) {
12217
+ var _this = this;
12218
+ var _this_treeItemList;
12219
+ var treeItem = oldScene.items[0];
12220
+ oldScene.items.forEach(function(item) {
12221
+ if (item.id === component.item.id) {
12222
+ treeItem = item;
12223
+ }
12224
+ });
12225
+ var treeComp = component;
12226
+ var treeData = treeComp.options.tree;
12227
+ var treeItemList = [];
12228
+ treeData.nodes.forEach(function(node) {
12229
+ var _node_name;
12230
+ var item = {
12231
+ id: effects.generateGUID(),
12232
+ parentId: treeItem.id,
12233
+ name: (_node_name = node.name) != null ? _node_name : "<unnamed>",
12234
+ duration: treeItem.duration,
12235
+ // @ts-expect-error
12236
+ type: "ECS",
12237
+ dataType: effects.spec.DataType.VFXItemData,
12238
+ visible: treeItem.visible,
12239
+ endBehavior: treeItem.endBehavior,
12240
+ delay: treeItem.delay,
12241
+ content: {},
12242
+ renderLevel: treeItem.renderLevel,
12243
+ pn: treeItem.pn,
12244
+ pluginName: treeItem.pluginName,
12245
+ transform: _this.getTransformData(node.transform),
12246
+ components: []
12247
+ };
12248
+ treeItemList.push(item);
12249
+ newScene.items.push(item);
12250
+ });
12251
+ treeData.nodes.forEach(function(node, index) {
12252
+ var _node_children;
12253
+ var item = treeItemList[index];
12254
+ (_node_children = node.children) == null ? void 0 : _node_children.forEach(function(child) {
12255
+ var childItem = treeItemList[child];
12256
+ childItem.parentId = item.id;
12257
+ });
12258
+ });
12259
+ oldScene.items.forEach(function(item) {
12260
+ if (item.parentId) {
12261
+ var index = item.parentId.indexOf("^");
12262
+ if (index >= 0) {
12263
+ var parentId = item.parentId.substring(0, index);
12264
+ var subIndex = +item.parentId.substring(index + 1);
12265
+ if (parentId === treeItem.id) {
12266
+ item.parentId = treeItemList[subIndex].id;
12267
+ }
12268
+ }
12269
+ }
12270
+ });
12271
+ (_this_treeItemList = this.treeItemList).push.apply(_this_treeItemList, [].concat(treeItemList));
12272
+ };
12273
+ _proto.createLightComponent = function createLightComponent(component, scene) {
12274
+ var lightOptions = component.options;
12275
+ var lightComponent = {
12276
+ id: component.id,
12277
+ dataType: component.dataType,
12278
+ item: component.item,
12279
+ lightType: lightOptions.lightType,
12280
+ color: {
12281
+ r: lightOptions.color[0] / 255.0,
12282
+ g: lightOptions.color[1] / 255.0,
12283
+ b: lightOptions.color[2] / 255.0,
12284
+ a: lightOptions.color[3] / 255.0
12285
+ },
12286
+ intensity: lightOptions.intensity
12287
+ };
12288
+ if (lightOptions.lightType === "point") {
12289
+ lightComponent.range = lightOptions.range;
12290
+ } else if (lightOptions.lightType === "spot") {
12291
+ lightComponent.range = lightOptions.range;
12292
+ lightComponent.innerConeAngle = lightOptions.innerConeAngle;
12293
+ lightComponent.outerConeAngle = lightOptions.outerConeAngle;
12294
+ }
12295
+ return lightComponent;
12296
+ };
12297
+ _proto.getMaterialData = function getMaterialData(material, scene) {
12298
+ if (material.type === effects.spec.MaterialType.unlit) {
12299
+ var floats = {};
12300
+ if (material.alphaCutOff !== undefined) {
12301
+ floats["_AlphaCutoff"] = material.alphaCutOff;
12302
+ }
12303
+ var colors = {
12304
+ "_BaseColorFactor": new Color(material.baseColorFactor[0], material.baseColorFactor[1], material.baseColorFactor[2], material.baseColorFactor[3]).divide(255)
12305
+ };
12306
+ var textures = {};
12307
+ if (material.baseColorTexture) {
12308
+ textures["_BaseColorSampler"] = this.getTextureData(scene, floats, material.baseColorTexture, material.baseColorTextureTransform);
12309
+ }
12310
+ var newMaterial = {
12311
+ id: effects.generateGUID(),
12312
+ name: material.name,
12313
+ dataType: effects.spec.DataType.Material,
12314
+ shader: {
12315
+ id: UnlitShaderGUID
12316
+ },
12317
+ stringTags: this.getStringTags(material),
12318
+ macros: [],
12319
+ ints: {},
12320
+ floats: floats,
12321
+ vector4s: {},
12322
+ colors: colors,
12323
+ textures: textures
12324
+ };
12325
+ return newMaterial;
12326
+ } else {
12327
+ var floats1 = {
12328
+ "_MetallicFactor": material.metallicFactor,
12329
+ "_RoughnessFactor": material.roughnessFactor
12330
+ };
12331
+ if (material.useSpecularAA !== undefined) {
12332
+ floats1["_SpecularAA"] = material.useSpecularAA ? 1 : 0;
12333
+ }
12334
+ if (material.normalTextureScale !== undefined) {
12335
+ floats1["_NormalScale"] = material.normalTextureScale;
12336
+ }
12337
+ if (material.occlusionTextureStrength !== undefined) {
12338
+ floats1["_OcclusionStrength"] = material.occlusionTextureStrength;
12339
+ }
12340
+ if (material.emissiveIntensity !== undefined) {
12341
+ floats1["_EmissiveIntensity"] = material.emissiveIntensity;
12342
+ }
12343
+ if (material.alphaCutOff !== undefined) {
12344
+ floats1["_AlphaCutoff"] = material.alphaCutOff;
12345
+ }
12346
+ var colors1 = {
12347
+ "_BaseColorFactor": new Color(material.baseColorFactor[0], material.baseColorFactor[1], material.baseColorFactor[2], material.baseColorFactor[3]).divide(255),
12348
+ "_EmissiveFactor": new Color(material.emissiveFactor[0], material.emissiveFactor[1], material.emissiveFactor[2], material.emissiveFactor[3]).divide(255)
12349
+ };
12350
+ var textures1 = {};
12351
+ if (material.baseColorTexture) {
12352
+ textures1["_BaseColorSampler"] = this.getTextureData(scene, floats1, material.baseColorTexture, material.baseColorTextureTransform);
12353
+ }
12354
+ if (material.metallicRoughnessTexture) {
12355
+ textures1["_MetallicRoughnessSampler"] = this.getTextureData(scene, floats1, material.metallicRoughnessTexture, material.metallicRoughnessTextureTransform);
12356
+ }
12357
+ if (material.normalTexture) {
12358
+ textures1["_NormalSampler"] = this.getTextureData(scene, floats1, material.normalTexture, material.normalTextureTransform);
12359
+ }
12360
+ if (material.occlusionTexture) {
12361
+ textures1["_OcclusionSampler"] = this.getTextureData(scene, floats1, material.occlusionTexture, material.occlusionTextureTransform);
12362
+ }
12363
+ if (material.emissiveTexture) {
12364
+ textures1["_EmissiveSampler"] = this.getTextureData(scene, floats1, material.emissiveTexture, material.emissiveTextureTransform);
12365
+ }
12366
+ var newMaterial1 = {
12367
+ id: effects.generateGUID(),
12368
+ name: material.name,
12369
+ dataType: effects.spec.DataType.Material,
12370
+ shader: {
12371
+ id: PBRShaderGUID
12372
+ },
12373
+ stringTags: this.getStringTags(material),
12374
+ macros: [],
12375
+ ints: {},
12376
+ floats: floats1,
12377
+ vector4s: {},
12378
+ colors: colors1,
12379
+ textures: textures1
12380
+ };
12381
+ return newMaterial1;
12382
+ }
12383
+ };
12384
+ _proto.getStringTags = function getStringTags(material) {
12385
+ var stringTags = {};
12386
+ var _material_depthMask;
12387
+ stringTags["ZWrite"] = String((_material_depthMask = material.depthMask) != null ? _material_depthMask : true);
12388
+ stringTags["ZTest"] = String(true);
12389
+ if (material.blending === effects.spec.MaterialBlending.masked) {
12390
+ stringTags["RenderType"] = exports.RenderType.Mask;
12391
+ } else if (material.blending === effects.spec.MaterialBlending.translucent) {
12392
+ stringTags["RenderType"] = exports.RenderType.Blend;
12393
+ } else {
12394
+ stringTags["RenderType"] = exports.RenderType.Opaque;
12395
+ }
12396
+ if (material.side === effects.spec.SideMode.BACK) {
12397
+ stringTags["Cull"] = exports.CullMode.Back;
12398
+ } else if (material.side === effects.spec.SideMode.DOUBLE) {
12399
+ stringTags["Cull"] = exports.CullMode.Double;
12400
+ } else {
12401
+ stringTags["Cull"] = exports.CullMode.Front;
12402
+ }
12403
+ return stringTags;
12404
+ };
12405
+ _proto.getTextureData = function getTextureData(scene, floats, texIndex, texTransform) {
12406
+ var _scene_textures_texIndex_id;
12407
+ var id = (_scene_textures_texIndex_id = scene.textures[texIndex].id) != null ? _scene_textures_texIndex_id : "0";
12408
+ var texProperty = {
12409
+ texture: {
12410
+ id: id
12411
+ }
12412
+ };
12413
+ if (texTransform) {
12414
+ if (texTransform.scale) {
12415
+ texProperty.scale = {
12416
+ x: texTransform.scale[0],
12417
+ y: texTransform.scale[1]
12418
+ };
12419
+ }
12420
+ if (texTransform.offset) {
12421
+ texProperty.offset = {
12422
+ x: texTransform.offset[0],
12423
+ y: texTransform.offset[1]
12424
+ };
12425
+ }
12426
+ if (texTransform.rotation) {
12427
+ floats["_BaseColorRotation"] = texTransform.rotation;
12428
+ }
12429
+ }
12430
+ return texProperty;
12431
+ };
12432
+ _proto.getTransformData = function getTransformData(transform) {
12433
+ var result = {
12434
+ position: {
12435
+ x: 0,
12436
+ y: 0,
12437
+ z: 0
12438
+ },
12439
+ eulerHint: {
12440
+ x: 0,
12441
+ y: 0,
12442
+ z: 0
12443
+ },
12444
+ scale: {
12445
+ x: 1,
12446
+ y: 1,
12447
+ z: 1
12448
+ }
12449
+ };
12450
+ if (transform == null ? void 0 : transform.position) {
12451
+ result.position.x = transform.position[0];
12452
+ result.position.y = transform.position[1];
12453
+ result.position.z = transform.position[2];
12454
+ }
12455
+ if (transform == null ? void 0 : transform.quat) {
12456
+ // @ts-expect-error
12457
+ result.quat = {};
12458
+ // @ts-expect-error
12459
+ result.quat.x = transform.quat[0];
12460
+ // @ts-expect-error
12461
+ result.quat.y = transform.quat[1];
12462
+ // @ts-expect-error
12463
+ result.quat.z = transform.quat[2];
12464
+ // @ts-expect-error
12465
+ result.quat.w = transform.quat[3];
12466
+ } else if (transform == null ? void 0 : transform.rotation) {
12467
+ result.eulerHint.x = transform.rotation[0];
12468
+ result.eulerHint.y = transform.rotation[1];
12469
+ result.eulerHint.z = transform.rotation[2];
12470
+ }
12471
+ if (transform == null ? void 0 : transform.scale) {
12472
+ result.scale.x = transform.scale[0];
12473
+ result.scale.y = transform.scale[1];
12474
+ result.scale.z = transform.scale[2];
12475
+ }
12476
+ return result;
12477
+ };
12478
+ return JSONConverter;
12479
+ }();
12480
+ function getGeometryDataFromOptions(geomOptions) {
12481
+ var vertexCount = 0;
12482
+ var verticesType = effects.spec.VertexFormatType.Float32;
12483
+ var verticesNormalize = false;
12484
+ var uvsType = effects.spec.VertexFormatType.Float32;
12485
+ var uvsNormalize = false;
12486
+ var normalsType = effects.spec.VertexFormatType.Float32;
12487
+ var normalsNormalize = false;
12488
+ var _geomOptions_name;
12489
+ var modelData = {
12490
+ vertices: new Float32Array(),
12491
+ uvs: new Float32Array(),
12492
+ normals: new Float32Array(),
12493
+ indices: new Float32Array(),
12494
+ name: (_geomOptions_name = geomOptions.name) != null ? _geomOptions_name : "<empty>"
12495
+ };
12496
+ for(var attrib in geomOptions.attributes){
12497
+ var attribData = geomOptions.attributes[attrib];
12498
+ if (attrib === "aPosition") {
12499
+ // @ts-expect-error
12500
+ vertexCount = attribData.data.length / attribData.size;
12501
+ // @ts-expect-error
12502
+ modelData.vertices = attribData.data;
12503
+ var _attribData_normalize;
12504
+ verticesNormalize = (_attribData_normalize = attribData.normalize) != null ? _attribData_normalize : false;
12505
+ var _attribData_type;
12506
+ verticesType = effects.glType2VertexFormatType((_attribData_type = attribData.type) != null ? _attribData_type : effects.glContext.FLOAT);
12507
+ } else if (attrib === "aNormal") {
12508
+ // @ts-expect-error
12509
+ modelData.normals = attribData.data;
12510
+ var _attribData_normalize1;
12511
+ normalsNormalize = (_attribData_normalize1 = attribData.normalize) != null ? _attribData_normalize1 : false;
12512
+ var _attribData_type1;
12513
+ normalsType = effects.glType2VertexFormatType((_attribData_type1 = attribData.type) != null ? _attribData_type1 : effects.glContext.FLOAT);
12514
+ } else if (attrib === "aUV1") {
12515
+ // @ts-expect-error
12516
+ modelData.uvs = attribData.data;
12517
+ var _attribData_normalize2;
12518
+ uvsNormalize = (_attribData_normalize2 = attribData.normalize) != null ? _attribData_normalize2 : false;
12519
+ var _attribData_type2;
12520
+ uvsType = effects.glType2VertexFormatType((_attribData_type2 = attribData.type) != null ? _attribData_type2 : effects.glContext.FLOAT);
12521
+ }
12522
+ }
12523
+ var verticesOffset = getOffset(verticesType, 3, vertexCount);
12524
+ var uvsOffset = getOffset(uvsType, 2, vertexCount);
12525
+ var normalsOffset = getOffset(normalsType, 3, vertexCount);
12526
+ if (geomOptions.indices) {
12527
+ modelData.indices = geomOptions.indices.data;
12528
+ } else if (vertexCount <= 65535) {
12529
+ var indices = new Uint16Array(vertexCount);
12530
+ for(var i = 0; i < vertexCount; i++){
12531
+ indices[i] = i;
12532
+ }
12533
+ modelData.indices = indices;
12534
+ } else {
12535
+ var indices1 = new Uint32Array(vertexCount);
12536
+ for(var i1 = 0; i1 < vertexCount; i1++){
12537
+ indices1[i1] = i1;
12538
+ }
12539
+ modelData.indices = indices1;
12540
+ }
12541
+ var indicesType = effects.spec.IndexFormatType.UInt16;
12542
+ if (modelData.indices.BYTES_PER_ELEMENT === 4) {
12543
+ indicesType = effects.spec.IndexFormatType.UInt32;
12544
+ }
12545
+ var geometryData = {
12546
+ id: effects.generateGUID(),
12547
+ dataType: effects.spec.DataType.Geometry,
12548
+ vertexData: {
12549
+ vertexCount: vertexCount,
12550
+ channels: [
12551
+ {
12552
+ semantic: effects.spec.VertexBufferSemantic.Position,
12553
+ offset: 0,
12554
+ format: verticesType,
12555
+ dimension: 3,
12556
+ normalize: verticesNormalize
12557
+ },
12558
+ {
12559
+ semantic: effects.spec.VertexBufferSemantic.Uv,
12560
+ offset: verticesOffset,
12561
+ format: uvsType,
12562
+ dimension: 2,
12563
+ normalize: uvsNormalize
12564
+ },
12565
+ {
12566
+ semantic: effects.spec.VertexBufferSemantic.Normal,
12567
+ offset: verticesOffset + uvsOffset,
12568
+ format: normalsType,
12569
+ dimension: 3,
12570
+ normalize: normalsNormalize
12571
+ }
12572
+ ]
12573
+ },
12574
+ subMeshes: [],
12575
+ mode: effects.spec.GeometryType.TRIANGLES,
12576
+ indexFormat: indicesType,
12577
+ indexOffset: verticesOffset + uvsOffset + normalsOffset,
12578
+ buffer: encodeVertexData(modelData)
12579
+ };
12580
+ return geometryData;
12581
+ }
12582
+ function getGeometryDataFromPropsList(geomPropsList) {
12583
+ var _loop = function(i) {
12584
+ var _geomPropsList__indices;
12585
+ var count = getDrawCount(geomPropsList[i]);
12586
+ var _geomPropsList_i_drawStart;
12587
+ var offset = totalCount + ((_geomPropsList_i_drawStart = geomPropsList[i].drawStart) != null ? _geomPropsList_i_drawStart : 0);
12588
+ var _geomPropsList__indices_data_BYTES_PER_ELEMENT;
12589
+ var scale = (_geomPropsList__indices_data_BYTES_PER_ELEMENT = (_geomPropsList__indices = geomPropsList[0].indices) == null ? void 0 : _geomPropsList__indices.data.BYTES_PER_ELEMENT) != null ? _geomPropsList__indices_data_BYTES_PER_ELEMENT : 1;
12590
+ subMeshes.push({
12591
+ offset: offset * scale,
12592
+ count: count
12593
+ });
12594
+ if (i) {
12595
+ var geom0 = geomPropsList[0];
12596
+ var geom1 = geomPropsList[i];
12597
+ var isSame = true;
12598
+ Object.keys(geom0.attributes).forEach(function(name) {
12599
+ var attrib = geom0.attributes[name];
12600
+ // @ts-expect-error
12601
+ var array1 = attrib.data;
12602
+ // @ts-expect-error
12603
+ var array2 = geom1.attributes[name].data;
12604
+ if (array1.length !== array2.length || array1[0] !== array2[0]) {
12605
+ isSame = false;
12606
+ }
12607
+ });
12608
+ if (isSame) {
12609
+ if (geom0.indices && geom1.indices) {
12610
+ geom0.indices.data = mergeTypedArray(geom0.indices.data, geom1.indices.data);
12611
+ }
12612
+ } else {
12613
+ if (geom0.indices && geom1.indices) {
12614
+ var vertexCount = getVertexCount(geom0);
12615
+ geom0.indices.data = mergeTypedArray(geom0.indices.data, geom1.indices.data, vertexCount);
12616
+ }
12617
+ Object.keys(geom0.attributes).forEach(function(name) {
12618
+ var attrib = geom0.attributes[name];
12619
+ // @ts-expect-error
12620
+ var array1 = attrib.data;
12621
+ // @ts-expect-error
12622
+ var array2 = geom1.attributes[name].data;
12623
+ // @ts-expect-error
12624
+ attrib.data = mergeTypedArray(array1, array2);
12625
+ });
12626
+ }
12627
+ }
12628
+ totalCount = offset + count;
12629
+ };
12630
+ if (geomPropsList.length <= 0) {
12631
+ return;
12632
+ }
12633
+ var totalCount = 0;
12634
+ var subMeshes = [];
12635
+ for(var i = 0; i < geomPropsList.length; i++)_loop(i);
12636
+ return createGeometryData(geomPropsList[0], subMeshes);
12637
+ }
12638
+ function getOffset(formatType, dimension, count) {
12639
+ switch(formatType){
12640
+ case effects.spec.VertexFormatType.Int8:
12641
+ case effects.spec.VertexFormatType.UInt8:
12642
+ return dimension * count;
12643
+ case effects.spec.VertexFormatType.Int16:
12644
+ case effects.spec.VertexFormatType.UInt16:
12645
+ return dimension * count * 2;
12646
+ default:
12647
+ return dimension * count * 4;
12648
+ }
12649
+ }
12650
+ function createGeometryData(props, subMeshes) {
12651
+ var totalByteLength = 0;
12652
+ for(var attrib in props.attributes){
12653
+ var attribData = props.attributes[attrib];
12654
+ // @ts-expect-error
12655
+ totalByteLength += attribData.data.byteLength;
12656
+ }
12657
+ if (props.indices) {
12658
+ totalByteLength += props.indices.data.byteLength;
12659
+ }
12660
+ var vertexCount = 0;
12661
+ var bufferOffset = 0;
12662
+ var buffer = new Uint8Array(totalByteLength);
12663
+ var vertexChannels = [];
12664
+ for(var attrib1 in props.attributes){
12665
+ var attribData1 = props.attributes[attrib1];
12666
+ var semantic = vertexBufferSemanticMap[attrib1];
12667
+ if (!semantic) {
12668
+ throw new Error("Invalid attrib " + attrib1);
12669
+ }
12670
+ // @ts-expect-error
12671
+ vertexCount = attribData1.data.length / attribData1.size;
12672
+ var _attribData_type;
12673
+ var vertexChannel = {
12674
+ semantic: semantic,
12675
+ offset: bufferOffset,
12676
+ format: effects.glType2VertexFormatType((_attribData_type = attribData1.type) != null ? _attribData_type : effects.glContext.FLOAT),
12677
+ dimension: attribData1.size,
12678
+ normalize: attribData1.normalize
12679
+ };
12680
+ vertexChannels.push(vertexChannel);
12681
+ // @ts-expect-error
12682
+ var data = attribData1.data;
12683
+ var subBuffer = new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
12684
+ buffer.set(subBuffer, bufferOffset);
12685
+ bufferOffset += subBuffer.byteLength;
12686
+ }
12687
+ var geometryData = {
12688
+ id: effects.generateGUID(),
12689
+ dataType: effects.spec.DataType.Geometry,
12690
+ vertexData: {
12691
+ vertexCount: vertexCount,
12692
+ channels: vertexChannels
12693
+ },
12694
+ subMeshes: subMeshes,
12695
+ mode: effects.spec.GeometryType.TRIANGLES,
12696
+ indexFormat: effects.spec.IndexFormatType.UInt16,
12697
+ indexOffset: -1,
12698
+ buffer: ""
12699
+ };
12700
+ if (props.indices) {
12701
+ var indices = props.indices.data;
12702
+ var subBuffer1 = new Uint8Array(indices.buffer, indices.byteOffset, indices.byteLength);
12703
+ buffer.set(subBuffer1, bufferOffset);
12704
+ geometryData.indexOffset = bufferOffset;
12705
+ if (_instanceof1(indices, Uint32Array)) {
12706
+ geometryData.indexFormat = effects.spec.IndexFormatType.UInt32;
12707
+ }
12708
+ }
12709
+ geometryData.buffer = toBase64String(buffer);
12710
+ return geometryData;
12711
+ }
12712
+ function encodeVertexData(modelData) {
12713
+ var vertices = new Uint8Array(modelData.vertices.buffer, modelData.vertices.byteOffset, modelData.vertices.byteLength);
12714
+ var uvs = new Uint8Array(modelData.uvs.buffer, modelData.uvs.byteOffset, modelData.uvs.byteLength);
12715
+ var normals = new Uint8Array(modelData.normals.buffer, modelData.normals.byteOffset, modelData.normals.byteLength);
12716
+ var indices = new Uint8Array(modelData.indices.buffer, modelData.indices.byteOffset, modelData.indices.byteLength);
12717
+ // 计算新 ArrayBuffer 的总大小(以字节为单位)
12718
+ var totalSize = vertices.byteLength + uvs.byteLength + normals.byteLength + indices.byteLength;
12719
+ // 创建一个足够大的 ArrayBuffer 来存储两个数组的数据
12720
+ var buffer = new ArrayBuffer(totalSize);
12721
+ // 创建一个视图来按照 Float32 格式写入数据
12722
+ var floatView = new Uint8Array(buffer, 0, vertices.byteLength);
12723
+ floatView.set(vertices);
12724
+ floatView = new Uint8Array(buffer, vertices.byteLength, uvs.byteLength);
12725
+ floatView.set(uvs);
12726
+ floatView = new Uint8Array(buffer, vertices.byteLength + uvs.byteLength, normals.byteLength);
12727
+ floatView.set(normals);
12728
+ // 创建一个视图来按照 Uint16 格式写入数据,紧接着 Float32 数据之后
12729
+ var uint16View = new Uint8Array(buffer, vertices.byteLength + uvs.byteLength + normals.byteLength, indices.byteLength);
12730
+ uint16View.set(indices);
12731
+ // 创建一个 Uint8Array 视图以便逐字节访问 ArrayBuffer 的数据
12732
+ var uint8View = new Uint8Array(buffer);
12733
+ // 将 Uint8Array 转换为二进制字符串
12734
+ var binaryString = "";
12735
+ for(var i = 0; i < uint8View.length; i++){
12736
+ binaryString += String.fromCharCode(uint8View[i]);
12737
+ }
12738
+ // 使用 btoa 函数将二进制字符串转换为 Base64 编码的字符串
12739
+ return btoa(binaryString);
12740
+ }
12741
+ function toBase64String(array) {
12742
+ // 将 Uint8Array 转换为二进制字符串
12743
+ var binaryString = "";
12744
+ for(var i = 0; i < array.length; i++){
12745
+ binaryString += String.fromCharCode(array[i]);
12746
+ }
12747
+ // 使用 btoa 函数将二进制字符串转换为 Base64 编码的字符串
12748
+ return btoa(binaryString);
12749
+ }
12750
+ function getDrawCount(geomProps) {
12751
+ if (geomProps.drawCount) {
12752
+ return geomProps.drawCount;
12753
+ } else if (geomProps.indices) {
12754
+ return geomProps.indices.data.length;
12755
+ } else {
12756
+ var drawCount = 0;
12757
+ // @ts-expect-error
12758
+ geomProps.attributes.forEach(function(attrib) {
12759
+ drawCount = attrib.data.length / attrib.size;
12760
+ });
12761
+ return drawCount;
12762
+ }
12763
+ }
12764
+ function getVertexCount(geomProps) {
12765
+ var vertexCount = 0;
12766
+ Object.keys(geomProps.attributes).forEach(function(name) {
12767
+ var attrib = geomProps.attributes[name];
12768
+ // @ts-expect-error
12769
+ vertexCount = attrib.data.length / attrib.size;
12770
+ });
12771
+ return vertexCount;
12772
+ }
12773
+ function mergeTypedArray(array1, array2, offset) {
12774
+ if (_instanceof1(array1, Float32Array)) {
12775
+ var result = new Float32Array(array1.length + array2.length);
12776
+ result.set(array1);
12777
+ result.set(array2, array1.length);
12778
+ return result;
12779
+ } else if (_instanceof1(array1, Int32Array)) {
12780
+ var result1 = new Int32Array(array1.length + array2.length);
12781
+ result1.set(array1);
12782
+ result1.set(array2, array1.length);
12783
+ return result1;
12784
+ } else if (_instanceof1(array1, Uint32Array)) {
12785
+ var result2 = new Uint32Array(array1.length + array2.length);
12786
+ result2.set(array1);
12787
+ result2.set(array2, array1.length);
12788
+ if (offset) {
12789
+ for(var i = 0; i < array2.length; i++){
12790
+ result2[array1.length + i] += offset;
12791
+ }
12792
+ }
12793
+ return result2;
12794
+ } else if (_instanceof1(array1, Int16Array)) {
12795
+ var result3 = new Int16Array(array1.length + array2.length);
12796
+ result3.set(array1);
12797
+ result3.set(array2, array1.length);
12798
+ return result3;
12799
+ } else if (_instanceof1(array1, Uint16Array)) {
12800
+ var result4 = new Uint16Array(array1.length + array2.length);
12801
+ result4.set(array1);
12802
+ result4.set(array2, array1.length);
12803
+ if (offset) {
12804
+ for(var i1 = 0; i1 < array2.length; i1++){
12805
+ result4[array1.length + i1] += offset;
12806
+ }
12807
+ }
12808
+ return result4;
12809
+ } else if (_instanceof1(array1, Int8Array)) {
12810
+ var result5 = new Int8Array(array1.length + array2.length);
12811
+ result5.set(array1);
12812
+ result5.set(array2, array1.length);
12813
+ return result5;
12814
+ } else {
12815
+ var result6 = new Uint8Array(array1.length + array2.length);
12816
+ result6.set(array1);
12817
+ result6.set(array2, array1.length);
12818
+ return result6;
12819
+ }
12820
+ }
12821
+ var vertexBufferSemanticMap = {
12822
+ aPos: "POSITION",
12823
+ aUV: "TEXCOORD0",
12824
+ aUV2: "TEXCOORD1",
12825
+ aNormal: "NORMAL",
12826
+ aTangent: "TANGENT",
12827
+ aColor: "COLOR",
12828
+ aJoints: "JOINTS",
12829
+ aWeights: "WEIGHTS",
12830
+ //
12831
+ a_Position: "POSITION",
12832
+ a_UV: "TEXCOORD0",
12833
+ a_UV1: "TEXCOORD0",
12834
+ a_UV2: "TEXCOORD1",
12835
+ a_Normal: "NORMAL",
12836
+ a_Tangent: "TANGENT",
12837
+ a_Color: "COLOR",
12838
+ a_Joints: "JOINTS",
12839
+ a_Weights: "WEIGHTS",
12840
+ //
12841
+ a_Target_Position0: "POSITION_BS0",
12842
+ a_Target_Position1: "POSITION_BS1",
12843
+ a_Target_Position2: "POSITION_BS2",
12844
+ a_Target_Position3: "POSITION_BS3",
12845
+ a_Target_Position4: "POSITION_BS4",
12846
+ a_Target_Position5: "POSITION_BS5",
12847
+ a_Target_Position6: "POSITION_BS6",
12848
+ a_Target_Position7: "POSITION_BS7",
12849
+ a_Target_Normal0: "NORMAL_BS0",
12850
+ a_Target_Normal1: "NORMAL_BS1",
12851
+ a_Target_Normal2: "NORMAL_BS2",
12852
+ a_Target_Normal3: "NORMAL_BS3",
12853
+ a_Target_Tangent0: "TANGENT_BS0",
12854
+ a_Target_Tangent1: "TANGENT_BS1",
12855
+ a_Target_Tangent2: "TANGENT_BS2",
12856
+ a_Target_Tangent3: "TANGENT_BS3"
12857
+ };
12858
+
11806
12859
  effects.registerPlugin("tree", ModelTreePlugin, effects.VFXItem, true);
11807
12860
  effects.registerPlugin("model", ModelPlugin, effects.VFXItem);
11808
- var version = "2.0.0-alpha.10";
12861
+ var version = "2.0.0-alpha.12";
11809
12862
  effects.logger.info("plugin model version: " + version);
11810
12863
 
11811
12864
  exports.BoxMesh = BoxMesh;
@@ -11819,6 +12872,7 @@ exports.GeometryBoxProxy = GeometryBoxProxy;
11819
12872
  exports.HitTestingProxy = HitTestingProxy;
11820
12873
  exports.HookOGLFunc = HookOGLFunc;
11821
12874
  exports.InterpolationSampler = InterpolationSampler;
12875
+ exports.JSONConverter = JSONConverter;
11822
12876
  exports.LoaderHelper = LoaderHelper;
11823
12877
  exports.LoaderImpl = LoaderImpl;
11824
12878
  exports.MeshHelper = MeshHelper;
@@ -11845,12 +12899,12 @@ exports.PMaterialUnlit = PMaterialUnlit;
11845
12899
  exports.PMesh = PMesh;
11846
12900
  exports.PMorph = PMorph;
11847
12901
  exports.PObject = PObject;
11848
- exports.PPrimitive = PPrimitive;
11849
12902
  exports.PSceneManager = PSceneManager;
11850
12903
  exports.PShaderManager = PShaderManager;
11851
12904
  exports.PSkin = PSkin;
11852
12905
  exports.PSkybox = PSkybox;
11853
12906
  exports.PSkyboxCreator = PSkyboxCreator;
12907
+ exports.PSubMesh = PSubMesh;
11854
12908
  exports.PTransform = PTransform;
11855
12909
  exports.PluginHelper = PluginHelper;
11856
12910
  exports.RayBoxTesting = RayBoxTesting;
@@ -11871,6 +12925,8 @@ exports.getDefaultEffectsGLTFLoader = getDefaultEffectsGLTFLoader;
11871
12925
  exports.getDiffuseOnlyShaderCode = getDiffuseOnlyShaderCode;
11872
12926
  exports.getGaussianBlurShaderCodeV1 = getGaussianBlurShaderCodeV1;
11873
12927
  exports.getGaussianBlurShaderCodeV2 = getGaussianBlurShaderCodeV2;
12928
+ exports.getGeometryDataFromOptions = getGeometryDataFromOptions;
12929
+ exports.getGeometryDataFromPropsList = getGeometryDataFromPropsList;
11874
12930
  exports.getKawaseBlurShaderCode = getKawaseBlurShaderCode;
11875
12931
  exports.getNormalVisShaderCode = getNormalVisShaderCode;
11876
12932
  exports.getPBRPassShaderCode = getPBRPassShaderCode;