@galacean/effects-plugin-model 2.0.0-alpha.20 → 2.0.0-alpha.21

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.mjs CHANGED
@@ -3,7 +3,7 @@
3
3
  * Description: Galacean Effects player model plugin
4
4
  * Author: Ant Group CO., Ltd.
5
5
  * Contributors: 飂兮
6
- * Version: v2.0.0-alpha.20
6
+ * Version: v2.0.0-alpha.21
7
7
  */
8
8
 
9
9
  import * as EFFECTS from '@galacean/effects';
@@ -2409,7 +2409,7 @@ function _assert_this_initialized(self) {
2409
2409
  get: /**
2410
2410
  * 获取顶点着色器代码
2411
2411
  */ function get() {
2412
- return "\n #version 100\n precision highp float;\n\n uniform mat4 _ModelMatrix;\n uniform mat4 _ViewProjectionMatrix;\n uniform vec3 _PositionList[8];\n attribute vec3 aPos;\n void main(){\n int index = int(aPos.x + 0.5);\n vec4 pos = _ModelMatrix * vec4(_PositionList[index], 1);\n gl_Position = _ViewProjectionMatrix * pos;\n }\n ";
2412
+ return "\n precision highp float;\n\n uniform mat4 _ModelMatrix;\n uniform mat4 _ViewProjectionMatrix;\n uniform vec3 _PositionList[8];\n attribute vec3 aPos;\n void main(){\n int index = int(aPos.x + 0.5);\n vec4 pos = _ModelMatrix * vec4(_PositionList[index], 1);\n gl_Position = _ViewProjectionMatrix * pos;\n }\n ";
2413
2413
  }
2414
2414
  },
2415
2415
  {
@@ -2417,7 +2417,7 @@ function _assert_this_initialized(self) {
2417
2417
  get: /**
2418
2418
  * 获取片段着色器代码
2419
2419
  */ function get() {
2420
- return "\n #version 100\n precision highp float;\n\n uniform vec3 _LineColor;\n void main(){\n gl_FragColor = vec4(_LineColor, 1);\n }\n ";
2420
+ return "\n precision highp float;\n\n uniform vec3 _LineColor;\n void main(){\n gl_FragColor = vec4(_LineColor, 1);\n }\n ";
2421
2421
  }
2422
2422
  },
2423
2423
  {
@@ -3815,11 +3815,18 @@ var EffectsMeshProxy = /*#__PURE__*/ function() {
3815
3815
  return a.priority - b.priority;
3816
3816
  }
3817
3817
  });
3818
+ var prePriority = -99999;
3818
3819
  // 重新赋值渲染优先级
3819
3820
  for(var i = 0; i < meshComponents.length; i++){
3820
3821
  var mesh = meshComponents[i];
3821
3822
  var priority = priorityList[i];
3822
- mesh.priority = priority;
3823
+ if (prePriority < priority) {
3824
+ prePriority = priority;
3825
+ mesh.priority = priority;
3826
+ } else {
3827
+ prePriority += 0.1;
3828
+ mesh.priority = prePriority;
3829
+ }
3823
3830
  }
3824
3831
  };
3825
3832
  /**
@@ -9000,10 +9007,10 @@ var PSkyboxType;
9000
9007
  * @param engine - 引擎
9001
9008
  * @param params - 天空盒参数
9002
9009
  * @returns 天空盒选项
9003
- */ PSkyboxCreator.createSkyboxComponentData = function createSkyboxComponentData(engine, params) {
9010
+ */ PSkyboxCreator.createSkyboxComponentData = function createSkyboxComponentData(params) {
9004
9011
  var _imageList;
9005
- var specularCubeData = this.getSpecularCubeMapData(engine, params);
9006
- var diffuseCubeData = this.getDiffuseCubeMapData(engine, params);
9012
+ var specularCubeData = PSkyboxCreator.getSpecularCubeMapData(params);
9013
+ var diffuseCubeData = PSkyboxCreator.getDiffuseCubeMapData(params);
9007
9014
  var renderable = params.renderable, intensity = params.intensity, reflectionsIntensity = params.reflectionsIntensity, irradianceCoeffs = params.irradianceCoeffs, specularImageSize = params.specularImageSize, specularMipCount = params.specularMipCount;
9008
9015
  var diffuseImage;
9009
9016
  var imageList = [];
@@ -9072,7 +9079,7 @@ var PSkyboxType;
9072
9079
  });
9073
9080
  })();
9074
9081
  };
9075
- PSkyboxCreator.getSpecularCubeMapData = function getSpecularCubeMapData(engine, params) {
9082
+ PSkyboxCreator.getSpecularCubeMapData = function getSpecularCubeMapData(params) {
9076
9083
  var imageDatas = [];
9077
9084
  var mipmaps = [];
9078
9085
  params.specularImage.forEach(function(cubemap) {
@@ -9131,7 +9138,7 @@ var PSkyboxType;
9131
9138
  });
9132
9139
  })();
9133
9140
  };
9134
- PSkyboxCreator.getDiffuseCubeMapData = function getDiffuseCubeMapData(engine, params) {
9141
+ PSkyboxCreator.getDiffuseCubeMapData = function getDiffuseCubeMapData(params) {
9135
9142
  if (params.diffuseImage === undefined) {
9136
9143
  return;
9137
9144
  }
@@ -10630,1497 +10637,120 @@ var LoaderHelper = /*#__PURE__*/ function() {
10630
10637
  return LoaderHelper;
10631
10638
  }();
10632
10639
 
10633
- var globalGLTFLoader;
10634
- function getDefaultEffectsGLTFLoader(engine, options) {
10635
- if (!globalGLTFLoader) {
10636
- globalGLTFLoader = new LoaderImpl();
10640
+ var JSONConverter = /*#__PURE__*/ function() {
10641
+ function JSONConverter(player) {
10642
+ this.treeInfo = new TreeInfo();
10643
+ this.engine = player.renderer.engine;
10644
+ this.renderer = player.renderer;
10645
+ this.downloader = new Downloader();
10637
10646
  }
10638
- globalGLTFLoader.initial(engine, options);
10639
- return globalGLTFLoader;
10640
- }
10641
- function setDefaultEffectsGLTFLoader(loader) {
10642
- globalGLTFLoader = loader;
10643
- }
10644
- var LoaderImpl = /*#__PURE__*/ function() {
10645
- function LoaderImpl() {}
10646
- var _proto = LoaderImpl.prototype;
10647
- _proto.initial = function initial(engine, options) {
10648
- this.engine = engine;
10649
- this._loaderOptions = options != null ? options : {};
10650
- };
10651
- _proto.processLight = function processLight(lights, fromGLTF) {
10652
- var _this = this;
10653
- lights.forEach(function(l) {
10654
- if (l.color === undefined) {
10655
- if (fromGLTF) {
10656
- l.color = [
10657
- 255,
10658
- 255,
10659
- 255,
10660
- 255
10661
- ];
10662
- } else {
10663
- l.color = [
10664
- 1,
10665
- 1,
10666
- 1,
10667
- 1
10668
- ];
10669
- }
10670
- } else {
10671
- l.color[0] = _this.scaleColorVal(l.color[0], fromGLTF);
10672
- l.color[1] = _this.scaleColorVal(l.color[1], fromGLTF);
10673
- l.color[2] = _this.scaleColorVal(l.color[2], fromGLTF);
10674
- l.color[3] = _this.scaleColorVal(l.color[3], fromGLTF);
10675
- }
10676
- });
10677
- };
10678
- _proto.processCamera = function processCamera(cameras, fromGLTF) {
10679
- var scale = fromGLTF ? 180.0 / Math.PI : Math.PI / 180.0;
10680
- cameras.forEach(function(camera) {
10681
- if (camera.perspective !== undefined) {
10682
- camera.perspective.yfov *= scale;
10683
- }
10684
- });
10685
- };
10686
- _proto.processMaterial = function processMaterial(materials, fromGLTF) {
10687
- var _this = this;
10688
- materials.forEach(function(mat) {
10689
- if (mat.baseColorFactor === undefined) {
10690
- if (fromGLTF) {
10691
- mat.baseColorFactor = [
10692
- 255,
10693
- 255,
10694
- 255,
10695
- 255
10696
- ];
10697
- } else {
10698
- mat.baseColorFactor = [
10699
- 1,
10700
- 1,
10701
- 1,
10702
- 1
10703
- ];
10704
- }
10705
- } else {
10706
- mat.baseColorFactor[0] = _this.scaleColorVal(mat.baseColorFactor[0], fromGLTF);
10707
- mat.baseColorFactor[1] = _this.scaleColorVal(mat.baseColorFactor[1], fromGLTF);
10708
- mat.baseColorFactor[2] = _this.scaleColorVal(mat.baseColorFactor[2], fromGLTF);
10709
- mat.baseColorFactor[3] = _this.scaleColorVal(mat.baseColorFactor[3], fromGLTF);
10710
- }
10711
- if (mat.emissiveFactor === undefined) {
10712
- if (fromGLTF) {
10713
- mat.emissiveFactor = [
10714
- 255,
10715
- 255,
10716
- 255,
10717
- 255
10718
- ];
10719
- } else {
10720
- mat.emissiveFactor = [
10721
- 1,
10722
- 1,
10723
- 1,
10724
- 1
10725
- ];
10726
- }
10727
- } else {
10728
- mat.emissiveFactor[0] = _this.scaleColorVal(mat.emissiveFactor[0], fromGLTF);
10729
- mat.emissiveFactor[1] = _this.scaleColorVal(mat.emissiveFactor[1], fromGLTF);
10730
- mat.emissiveFactor[2] = _this.scaleColorVal(mat.emissiveFactor[2], fromGLTF);
10731
- mat.emissiveFactor[3] = _this.scaleColorVal(mat.emissiveFactor[3], fromGLTF);
10732
- }
10733
- if (fromGLTF && mat.occlusionTexture !== undefined && mat.occlusionTexture.strength === undefined) {
10734
- mat.occlusionTexture.strength = _this.isTiny3dMode() ? 0 : 1;
10735
- }
10736
- });
10737
- };
10738
- _proto.createTreeOptions = function createTreeOptions(scene) {
10739
- var nodeList = scene.nodes.map(function(node, nodeIndex) {
10740
- var children = node.children.map(function(child) {
10741
- if (child.nodeIndex === undefined) {
10742
- throw new Error("Undefined nodeIndex for child " + child + ".");
10743
- }
10744
- return child.nodeIndex;
10745
- });
10746
- var pos;
10747
- var quat;
10748
- var scale;
10749
- if (node.matrix !== undefined) {
10750
- if (node.matrix.length !== 16) {
10751
- throw new Error("Invalid matrix length " + node.matrix.length + " for node " + node + ".");
10752
- }
10753
- var mat = Matrix4.fromArray(node.matrix);
10754
- var transform = mat.getTransform();
10755
- pos = transform.translation.toArray();
10756
- quat = transform.rotation.toArray();
10757
- scale = transform.scale.toArray();
10758
- } else {
10759
- if (node.translation !== undefined) {
10760
- pos = node.translation;
10761
- }
10762
- if (node.rotation !== undefined) {
10763
- quat = node.rotation;
10764
- }
10765
- if (node.scale !== undefined) {
10766
- scale = node.scale;
10767
- }
10768
- }
10769
- node.nodeIndex = nodeIndex;
10770
- var treeNode = {
10771
- name: node.name,
10772
- transform: {
10773
- position: pos,
10774
- quat: quat,
10775
- scale: scale
10776
- },
10777
- children: children,
10778
- id: "" + node.nodeIndex
10779
- };
10780
- return treeNode;
10781
- });
10782
- var rootNodes = scene.rootNodes.map(function(root) {
10783
- if (root.nodeIndex === undefined) {
10784
- throw new Error("Undefined nodeIndex for root " + root + ".");
10785
- }
10786
- return root.nodeIndex;
10787
- });
10788
- var treeOptions = {
10789
- nodes: nodeList,
10790
- children: rootNodes,
10791
- animation: -1,
10792
- animations: []
10793
- };
10794
- return treeOptions;
10795
- };
10796
- _proto.createAnimations = function createAnimations(animations) {
10797
- return animations.map(function(anim) {
10798
- var tracks = anim.channels.map(function(channel) {
10799
- var track = {
10800
- input: channel.input.array,
10801
- output: channel.output.array,
10802
- node: channel.target.node,
10803
- path: channel.target.path,
10804
- interpolation: channel.interpolation
10805
- };
10806
- return track;
10807
- });
10808
- var newAnim = {
10809
- name: anim.name,
10810
- tracks: tracks
10811
- };
10812
- return newAnim;
10813
- });
10814
- };
10815
- _proto.createGeometry = function createGeometry(primitive, hasSkinAnim) {
10816
- var proxy = new GeometryProxy(this.engine, primitive, hasSkinAnim);
10817
- return proxy.geometry;
10818
- };
10819
- _proto.createMaterial = function createMaterial(material) {
10820
- var proxy = new MaterialProxy(material, [], this.isTiny3dMode());
10821
- return proxy.material;
10822
- };
10823
- _proto.createTexture2D = function createTexture2D(image, texture, isBaseColor) {
10824
- return WebGLHelper.createTexture2D(this.engine, image, texture, isBaseColor, this.isTiny3dMode());
10825
- };
10826
- _proto.createTextureCube = function createTextureCube(cubeImages, level0Size) {
10827
- var _this = this;
10828
- if (cubeImages.length == 0) {
10829
- throw new Error("createTextureCube: Invalid cubeImages length " + cubeImages + ".");
10830
- }
10831
- var mipmaps = [];
10832
- cubeImages.forEach(function(cubeImage) {
10833
- if (cubeImage.length != 6) {
10834
- throw new Error("createTextureCube: cubeimage count should always be 6, " + cubeImage + ".");
10835
- }
10836
- //
10837
- var imgList = [];
10838
- cubeImage.forEach(function(img) {
10839
- if (img.imageData === undefined) {
10840
- throw new Error("createTextureCube: Invalid image data from " + img + ".");
10841
- }
10842
- //
10843
- imgList.push({
10844
- type: "buffer",
10845
- data: img.imageData,
10846
- mimeType: img.mimeType
10847
- });
10848
- });
10849
- if (_this.isTiny3dMode()) {
10850
- var ref;
10851
- ref = [
10852
- imgList[5],
10853
- imgList[4]
10854
- ], imgList[4] = ref[0], imgList[5] = ref[1];
10855
- }
10856
- mipmaps.push(imgList);
10857
- });
10858
- //
10859
- if (mipmaps.length == 1) {
10860
- // no mipmaps
10861
- return WebGLHelper.createTextureCubeFromBuffer(this.engine, mipmaps[0]);
10862
- } else {
10863
- // has mipmaps
10864
- return WebGLHelper.createTextureCubeMipmapFromBuffer(this.engine, mipmaps, level0Size != null ? level0Size : Math.pow(2, mipmaps.length - 1));
10865
- }
10866
- };
10867
- _proto.createSkybox = function createSkybox(ibl) {
10868
- var _this = this;
10869
- var _ibl_reflectionsIntensity;
10870
- var reflectionsIntensity = (_ibl_reflectionsIntensity = ibl.reflectionsIntensity) != null ? _ibl_reflectionsIntensity : ibl.intensity;
10871
- var irradianceCoeffs = ibl.irradianceCoefficients;
10872
- var inSpecularImages = ibl.specularImages;
10873
- var specularImages = inSpecularImages.map(function(images) {
10874
- var newImages = images.map(function(img) {
10875
- var outImg = {
10876
- type: "buffer",
10877
- data: img.imageData,
10878
- mimeType: img.mimeType
10879
- };
10880
- return outImg;
10881
- });
10882
- if (_this.isTiny3dMode()) {
10883
- var ref;
10884
- ref = [
10885
- newImages[5],
10886
- newImages[4]
10887
- ], newImages[4] = ref[0], newImages[5] = ref[1];
10888
- }
10889
- return newImages;
10890
- });
10891
- var specularMipCount = specularImages.length;
10892
- var _ibl_specularImageSize;
10893
- var specularImageSize = (_ibl_specularImageSize = ibl.specularImageSize) != null ? _ibl_specularImageSize : Math.pow(2, specularMipCount - 1);
10894
- var params = {
10895
- type: "buffer",
10896
- renderable: this.isSkyboxVis(),
10897
- intensity: ibl.intensity,
10898
- reflectionsIntensity: reflectionsIntensity,
10899
- irradianceCoeffs: irradianceCoeffs,
10900
- specularImage: specularImages,
10901
- specularMipCount: specularMipCount,
10902
- specularImageSize: specularImageSize
10903
- };
10904
- return PSkyboxCreator.createSkyboxOptions(this.engine, params);
10905
- };
10906
- _proto.createDefaultSkybox = function createDefaultSkybox(typeName) {
10907
- if (typeName !== "NFT" && typeName !== "FARM") {
10908
- throw new Error("Invalid skybox type specified: '" + typeName + "'. Valid types are: 'NFT', 'FARM'.");
10909
- }
10910
- //
10911
- var typ = typeName === "NFT" ? PSkyboxType.NFT : PSkyboxType.FARM;
10912
- var params = PSkyboxCreator.getSkyboxParams(typ);
10913
- return PSkyboxCreator.createSkyboxOptions(this.engine, params);
10914
- };
10915
- _proto.scaleColorVal = function scaleColorVal(val, fromGLTF) {
10916
- return fromGLTF ? LoaderHelper.scaleTo255(val) : LoaderHelper.scaleTo1(val);
10917
- };
10918
- _proto.scaleColorVec = function scaleColorVec(vec, fromGLTF) {
10919
- var _this = this;
10920
- return vec.map(function(val) {
10921
- return _this.scaleColorVal(val, fromGLTF);
10922
- });
10923
- };
10924
- _proto.loadScene = function loadScene(options) {
10647
+ var _proto = JSONConverter.prototype;
10648
+ _proto.processScene = function processScene(sceneData) {
10925
10649
  var _this = this;
10926
10650
  return _async_to_generator(function() {
10927
- var _options_effects_renderer, gltfResource, modelItems, treeId, itemSkybox, sceneAABB;
10651
+ var sceneJSON, _tmp, oldScene, binFiles, _iterator, _step, bin, _, newScene;
10928
10652
  return __generator(this, function(_state) {
10929
10653
  switch(_state.label){
10930
10654
  case 0:
10931
- _this._clear();
10932
- _this._sceneOptions = options;
10933
- _this.engine = (_options_effects_renderer = options.effects.renderer) == null ? void 0 : _options_effects_renderer.engine;
10934
- _this._loaderOptions = {
10935
- compatibleMode: options.gltf.compatibleMode
10936
- };
10937
- gltfResource = options.gltf.resource;
10938
- if (typeof gltfResource === "string" || _instanceof1(gltfResource, Uint8Array)) {
10939
- throw new Error("Please load the resource using GLTFTools first.");
10940
- }
10941
- _this._gltfScene = gltfResource.scenes[0];
10942
- _this._gltfSkins = _this._gltfScene.skins;
10943
- _this._gltfMeshs = gltfResource.meshes;
10944
- _this._gltfLights = _this._gltfScene.lights;
10945
- _this._gltfCameras = _this._gltfScene.cameras;
10946
- _this._gltfImages = gltfResource.images;
10947
- _this._gltfTextures = gltfResource.textures;
10948
- _this._gltfMaterials = gltfResource.materials;
10949
- _this._gltfAnimations = gltfResource.animations;
10950
- _this._gltfImageBasedLights = gltfResource.imageBasedLights;
10951
- return [
10952
- 4,
10953
- _this._preprocess()
10655
+ if (!isObject(sceneData)) return [
10656
+ 3,
10657
+ 1
10954
10658
  ];
10955
- case 1:
10956
- _state.sent();
10957
- modelItems = [];
10958
- treeId = "sceneTree";
10959
- modelItems.push(_this._createItemTree(treeId, _this._gltfScene));
10960
- //
10961
- itemSkybox = _this._createItemSkybox();
10962
- if (itemSkybox !== undefined) {
10963
- modelItems.push(itemSkybox);
10964
- }
10965
- _this._gltfScene.nodes.forEach(function(node) {
10966
- if (node.mesh !== undefined) {
10967
- var itemMesh = _this._createItemMesh(node, treeId);
10968
- if (itemMesh !== undefined) {
10969
- modelItems.push(itemMesh);
10970
- }
10971
- }
10972
- if (node.light !== undefined) {
10973
- var itemLight = _this._createItemLight(node, treeId);
10974
- if (itemLight !== undefined) {
10975
- modelItems.push(itemLight);
10976
- }
10977
- }
10978
- if (node.camera !== undefined) {
10979
- var itemCamera = _this._createItemCamera(node, treeId);
10980
- if (itemCamera !== undefined) {
10981
- modelItems.push(itemCamera);
10982
- }
10983
- }
10984
- });
10985
- sceneAABB = new Box3();
10986
- _this._gltfScene.rootNodes.forEach(function(root) {
10987
- var parentTransform = new Transform({
10988
- valid: true
10989
- });
10990
- _this._computeSceneAABB(root, parentTransform, sceneAABB);
10991
- });
10659
+ _tmp = sceneData;
10992
10660
  return [
10993
- 2,
10994
- {
10995
- source: _this.getRemarkString(),
10996
- items: modelItems,
10997
- sceneAABB: {
10998
- min: sceneAABB.min.toArray(),
10999
- max: sceneAABB.max.toArray()
11000
- }
11001
- }
11002
- ];
11003
- }
11004
- });
11005
- })();
11006
- };
11007
- _proto._preprocess = function _preprocess() {
11008
- var _this = this;
11009
- return _async_to_generator(function() {
11010
- var i, mat, ibl, inSpecularImages, skyboxType, typeName;
11011
- return __generator(this, function(_state) {
11012
- switch(_state.label){
11013
- case 0:
11014
- _this.getTextureManager().initial(_this._gltfImages, _this._gltfTextures);
11015
- i = 0;
11016
- _state.label = 1;
11017
- case 1:
11018
- if (!(i < _this._gltfMaterials.length)) return [
11019
10661
  3,
11020
- 8
10662
+ 3
11021
10663
  ];
11022
- mat = _this._gltfMaterials[i];
10664
+ case 1:
11023
10665
  return [
11024
10666
  4,
11025
- _this.tryAddTexture2D(i, mat.baseColorTexture, true)
10667
+ _this.loadJSON(sceneData)
11026
10668
  ];
11027
10669
  case 2:
11028
- _state.sent();
11029
- if (!!GLTFHelper.isUnlitMaterial(mat)) return [
10670
+ _tmp = _state.sent();
10671
+ _state.label = 3;
10672
+ case 3:
10673
+ sceneJSON = _tmp;
10674
+ // @ts-expect-error
10675
+ sceneJSON.textures.forEach(function(tex) {
10676
+ if (tex.source === undefined) {
10677
+ tex.source = 0;
10678
+ }
10679
+ });
10680
+ oldScene = getStandardJSON(sceneJSON);
10681
+ binFiles = [];
10682
+ if (!oldScene.bins) return [
11030
10683
  3,
11031
10684
  7
11032
10685
  ];
11033
- return [
11034
- 4,
11035
- _this.tryAddTexture2D(i, mat.metallicRoughnessTexture, false)
11036
- ];
11037
- case 3:
11038
- _state.sent();
11039
- return [
11040
- 4,
11041
- _this.tryAddTexture2D(i, mat.normalTexture, false)
11042
- ];
10686
+ _iterator = _create_for_of_iterator_helper_loose(oldScene.bins);
10687
+ _state.label = 4;
11043
10688
  case 4:
11044
- _state.sent();
11045
- return [
11046
- 4,
11047
- _this.tryAddTexture2D(i, mat.emissiveTexture, false)
11048
- ];
11049
- case 5:
11050
- _state.sent();
11051
- return [
11052
- 4,
11053
- _this.tryAddTexture2D(i, mat.occlusionTexture, false)
11054
- ];
11055
- case 6:
11056
- _state.sent();
11057
- _state.label = 7;
11058
- case 7:
11059
- i++;
11060
- return [
11061
- 3,
11062
- 1
11063
- ];
11064
- case 8:
11065
- if (!(_this._gltfImageBasedLights.length > 0 && !_this.ignoreSkybox())) return [
10689
+ if (!!(_step = _iterator()).done) return [
11066
10690
  3,
11067
- 10
10691
+ 7
11068
10692
  ];
11069
- ibl = _this._gltfImageBasedLights[0];
11070
- if (_this.isEnvironmentTest()) {
11071
- inSpecularImages = ibl.specularImages;
11072
- inSpecularImages.forEach(function(images) {
11073
- if (_this.isTiny3dMode()) {
11074
- var ref;
11075
- ref = [
11076
- images[5],
11077
- images[4]
11078
- ], images[4] = ref[0], images[5] = ref[1];
11079
- }
11080
- var ref1;
11081
- ref1 = [
11082
- images[3],
11083
- images[2]
11084
- ], images[2] = ref1[0], images[3] = ref1[1];
11085
- });
11086
- }
10693
+ bin = _step.value;
10694
+ _ = binFiles.push;
11087
10695
  return [
11088
10696
  4,
11089
- _this.createSkybox(ibl)
10697
+ _this.loadBins(bin.url)
11090
10698
  ];
11091
- case 9:
11092
- _this._skyboxOptions = _state.sent();
10699
+ case 5:
10700
+ _.apply(binFiles, [
10701
+ _state.sent()
10702
+ ]);
10703
+ _state.label = 6;
10704
+ case 6:
11093
10705
  return [
11094
10706
  3,
11095
- 12
11096
- ];
11097
- case 10:
11098
- skyboxType = _this.getSkyboxType();
11099
- if (!(skyboxType !== undefined)) return [
11100
- 3,
11101
- 12
10707
+ 4
11102
10708
  ];
11103
- typeName = skyboxType === PSkyboxType.FARM ? "FARM" : "NFT";
10709
+ case 7:
10710
+ // @ts-expect-error
10711
+ oldScene.bins = binFiles;
10712
+ newScene = _extends({}, oldScene, {
10713
+ version: "3.0",
10714
+ playerVersion: {
10715
+ web: "3.0",
10716
+ native: "3.0"
10717
+ },
10718
+ type: "ge",
10719
+ compositions: [],
10720
+ images: [],
10721
+ textures: [],
10722
+ items: [],
10723
+ components: [],
10724
+ materials: [],
10725
+ shaders: [],
10726
+ geometries: []
10727
+ });
10728
+ _this.setImage(newScene, oldScene);
11104
10729
  return [
11105
10730
  4,
11106
- _this.createDefaultSkybox(typeName)
10731
+ _this.setTexture(newScene, oldScene)
11107
10732
  ];
11108
- case 11:
11109
- _this._skyboxOptions = _state.sent();
11110
- _state.label = 12;
11111
- case 12:
11112
- if (_this._skyboxOptions) {
11113
- _this._skyboxOptions.renderable = _this.isSkyboxVis();
11114
- }
11115
- //
11116
- _this._gltfData2PlayerData(_this._gltfScene, _this._gltfMaterials);
10733
+ case 8:
10734
+ _state.sent();
10735
+ _this.setComponent(newScene, oldScene);
10736
+ _this.setItem(newScene, oldScene);
10737
+ _this.setComposition(newScene, oldScene);
11117
10738
  return [
11118
- 2
10739
+ 2,
10740
+ newScene
11119
10741
  ];
11120
10742
  }
11121
10743
  });
11122
10744
  })();
11123
10745
  };
11124
- // FIXME: texInfo 可选,isBaseColor 不可选,顺序问题
11125
- _proto.tryAddTexture2D = function tryAddTexture2D(matIndex, texInfo, isBaseColor) {
11126
- var _this = this;
11127
- if (texInfo === undefined) {
11128
- return;
11129
- }
11130
- var cacheTex = this.getTexture2D(matIndex, texInfo, isBaseColor, true);
11131
- if (cacheTex !== undefined) {
11132
- return;
11133
- }
11134
- //
11135
- var texIndex = texInfo.index;
11136
- var tex = this._gltfTextures[texIndex];
11137
- var img = this._gltfImages[tex.source];
11138
- return WebGLHelper.createTexture2D(this.engine, img, tex, isBaseColor, this.isTiny3dMode()).then(function(tex) {
11139
- _this.getTextureManager().addTexture(matIndex, texIndex, tex, isBaseColor);
10746
+ _proto.setImage = function setImage(newScene, oldScene) {
10747
+ var newImages = [];
10748
+ oldScene.images.forEach(function(image) {
10749
+ newImages.push(image);
11140
10750
  });
10751
+ newScene.images = newImages;
11141
10752
  };
11142
- // FIXME: 可选顺序问题
11143
- _proto.getTexture2D = function getTexture2D(matIndex, texInfo, isBaseColor, noWarning) {
11144
- if (texInfo === undefined) {
11145
- return;
11146
- }
11147
- var texIndex = texInfo.index;
11148
- var tex = this.getTextureManager().getTexture(matIndex, texIndex, isBaseColor);
11149
- if (tex === undefined && noWarning !== true) {
11150
- console.warn("Can't find texture for mat " + matIndex + ", tex " + JSON.stringify(texInfo) + ", basecolor " + isBaseColor + ".");
11151
- }
11152
- return tex;
11153
- };
11154
- _proto._gltfData2PlayerData = function _gltfData2PlayerData(scene, materials) {
11155
- this.processCamera(scene.cameras, true);
11156
- this.processLight(scene.lights, true);
11157
- this.processMaterial(materials, true);
11158
- };
11159
- _proto._createItemTree = function _createItemTree(treeId, scene) {
11160
- var treeOptions = this.createTreeOptions(scene);
11161
- var animOptions = this.createAnimations(this._gltfAnimations);
11162
- treeOptions.animations = animOptions;
11163
- treeOptions.animation = this.getPlayAnimationIndex(treeOptions);
11164
- var itemTree = {
11165
- id: treeId,
11166
- name: scene.name,
11167
- duration: this.getItemDuration(),
11168
- endBehavior: this.getItemEndBehavior(),
11169
- type: spec.ItemType.tree,
11170
- content: {
11171
- options: {
11172
- tree: treeOptions
11173
- }
11174
- }
11175
- };
11176
- return itemTree;
11177
- };
11178
- _proto._createItemMesh = function _createItemMesh(node, parentId) {
11179
- var _this = this;
11180
- var meshIndex = node.mesh;
11181
- if (meshIndex === undefined) {
11182
- throw new Error("Invalid mesh index in node " + node + ".");
11183
- }
11184
- var skin;
11185
- if (node.skin !== undefined) {
11186
- var gltfSkin = this._gltfSkins[node.skin];
11187
- skin = {
11188
- name: gltfSkin.name,
11189
- joints: gltfSkin.jointIndexList,
11190
- skeleton: gltfSkin.skeleton,
11191
- inverseBindMatrices: gltfSkin.inverseBindMatrices
11192
- };
11193
- }
11194
- var mesh = this._gltfMeshs[meshIndex];
11195
- var primitiveList = mesh.primitives.map(function(prim) {
11196
- var matIndex = prim.material;
11197
- var mat = _this._gltfMaterials[matIndex];
11198
- var geometry = _this.createGeometry(prim, skin !== undefined);
11199
- var material = _this.createMaterial(mat);
11200
- material.baseColorTexture = _this.getTexture2D(matIndex, mat.baseColorTexture, true);
11201
- if (material.type === spec.MaterialType.pbr) {
11202
- material.metallicRoughnessTexture = _this.getTexture2D(matIndex, mat.metallicRoughnessTexture, false);
11203
- material.normalTexture = _this.getTexture2D(matIndex, mat.normalTexture, false);
11204
- material.emissiveTexture = _this.getTexture2D(matIndex, mat.emissiveTexture, false);
11205
- material.occlusionTexture = _this.getTexture2D(matIndex, mat.occlusionTexture, false);
11206
- }
11207
- var primitiveOptions = {
11208
- geometry: geometry,
11209
- material: material
11210
- };
11211
- return primitiveOptions;
11212
- });
11213
- var meshOptions = {
11214
- parent: node.nodeIndex,
11215
- skin: skin,
11216
- primitives: primitiveList,
11217
- weights: mesh.weights
11218
- };
11219
- var aabb = GLTFHelper.createBoxFromGLTFBound(mesh.bounds);
11220
- var boxSize = aabb.getSize(new Vector3());
11221
- var boxCenter = aabb.getCenter(new Vector3());
11222
- var interaction = {
11223
- behavior: spec.InteractBehavior.NOTIFY,
11224
- type: spec.ModelBoundingType.box,
11225
- size: [
11226
- boxSize.x,
11227
- boxSize.y,
11228
- boxSize.z
11229
- ],
11230
- center: [
11231
- boxCenter.x,
11232
- boxCenter.y,
11233
- boxCenter.z
11234
- ]
11235
- };
11236
- var _node_nodeIndex;
11237
- var itemMesh = {
11238
- id: "mesh_ni" + ((_node_nodeIndex = node.nodeIndex) != null ? _node_nodeIndex : 0) + "_mi" + meshIndex,
11239
- parentId: parentId + "^" + node.nodeIndex,
11240
- name: mesh.name,
11241
- duration: this.getItemDuration(),
11242
- endBehavior: this.getItemEndBehavior(),
11243
- type: spec.ItemType.mesh,
11244
- pluginName: "model",
11245
- content: {
11246
- options: meshOptions,
11247
- interaction: interaction
11248
- }
11249
- };
11250
- return itemMesh;
11251
- };
11252
- _proto._createItemLight = function _createItemLight(node, parentId) {
11253
- var lightIndex = node.light;
11254
- if (lightIndex === undefined) {
11255
- return;
11256
- }
11257
- var light = this._gltfLights[lightIndex];
11258
- var lightOptions = this.createLightOptions(light);
11259
- var _node_nodeIndex, _light_name;
11260
- var itemLight = {
11261
- id: "light_ni" + ((_node_nodeIndex = node.nodeIndex) != null ? _node_nodeIndex : 0) + "_li" + lightIndex,
11262
- parentId: parentId + "^" + node.nodeIndex,
11263
- name: (_light_name = light.name) != null ? _light_name : "light",
11264
- duration: this.getItemDuration(),
11265
- endBehavior: this.getItemEndBehavior(),
11266
- type: spec.ItemType.light,
11267
- pluginName: "model",
11268
- content: {
11269
- options: lightOptions
11270
- }
11271
- };
11272
- return itemLight;
11273
- };
11274
- _proto._createItemCamera = function _createItemCamera(node, parentId) {
11275
- var cameraIndex = node.camera;
11276
- if (cameraIndex === undefined) {
11277
- return;
11278
- }
11279
- var camera = this._gltfCameras[cameraIndex];
11280
- var cameraOptions = this.createCameraOptions(camera);
11281
- if (cameraOptions === undefined) {
11282
- return;
11283
- }
11284
- var _node_nodeIndex, _camera_name;
11285
- var itemCamera = {
11286
- id: "camera_ni" + ((_node_nodeIndex = node.nodeIndex) != null ? _node_nodeIndex : 0) + "_ci" + cameraIndex,
11287
- parentId: parentId + "^" + node.nodeIndex,
11288
- name: (_camera_name = camera.name) != null ? _camera_name : "camera",
11289
- duration: this.getItemDuration(),
11290
- endBehavior: this.getItemEndBehavior(),
11291
- type: "camera",
11292
- pluginName: "model",
11293
- content: {
11294
- options: cameraOptions
11295
- }
11296
- };
11297
- return itemCamera;
11298
- };
11299
- _proto._createItemSkybox = function _createItemSkybox() {
11300
- if (this._skyboxOptions === undefined) {
11301
- return;
11302
- }
11303
- var itemSkybox = {
11304
- id: "skybox_0",
11305
- name: "skybox",
11306
- duration: this.getItemDuration(),
11307
- endBehavior: this.getItemEndBehavior(),
11308
- type: spec.ItemType.skybox,
11309
- pluginName: "model",
11310
- content: {
11311
- options: this._skyboxOptions
11312
- }
11313
- };
11314
- return itemSkybox;
11315
- };
11316
- _proto._computeSceneAABB = function _computeSceneAABB(node, parentTransform, sceneAABB) {
11317
- var _this = this;
11318
- var transformData = {};
11319
- if (node.matrix) {
11320
- var trans = Matrix4.fromArray(node.matrix).getTransform();
11321
- transformData.position = trans.translation.toArray();
11322
- transformData.quat = trans.rotation.toArray();
11323
- transformData.scale = trans.scale.toArray();
11324
- } else {
11325
- if (node.translation) {
11326
- transformData.position = node.translation;
11327
- }
11328
- if (node.rotation) {
11329
- transformData.quat = node.rotation;
11330
- }
11331
- if (node.scale) {
11332
- transformData.scale = node.scale;
11333
- }
11334
- }
11335
- var nodeTransform = new Transform(transformData, parentTransform);
11336
- nodeTransform.setValid(true);
11337
- //
11338
- if (node.mesh !== undefined) {
11339
- var mesh = this._gltfMeshs[node.mesh];
11340
- var meshAABB = GLTFHelper.createBoxFromGLTFBound(mesh.bounds);
11341
- meshAABB.applyMatrix4(nodeTransform.getWorldMatrix());
11342
- sceneAABB.union(meshAABB);
11343
- }
11344
- node.children.forEach(function(child) {
11345
- _this._computeSceneAABB(child, nodeTransform, sceneAABB);
11346
- });
11347
- };
11348
- _proto.createLightOptions = function createLightOptions(light) {
11349
- return PluginHelper.createLightOptions(light);
11350
- };
11351
- _proto.createCameraOptions = function createCameraOptions(camera) {
11352
- return PluginHelper.createCameraOptions(camera);
11353
- };
11354
- _proto._clear = function _clear() {
11355
- if (this._textureManager) {
11356
- this._textureManager.dispose();
11357
- this._textureManager = undefined;
11358
- }
11359
- this._textureManager = new TextureManager(this);
11360
- };
11361
- /**
11362
- * 按照传入的动画播放参数,计算需要播放的动画索引
11363
- *
11364
- * @param treeOptions 节点树属性,需要初始化animations列表。
11365
- * @returns 返回计算的动画索引,-1表示没有动画需要播放,-88888888表示播放所有动画。
11366
- */ _proto.getPlayAnimationIndex = function getPlayAnimationIndex(treeOptions) {
11367
- var animations = treeOptions.animations;
11368
- if (animations === undefined || animations.length <= 0) {
11369
- // 硬编码,内部指定的不播放动画的索引值
11370
- return -1;
11371
- }
11372
- if (this.isPlayAllAnimation()) {
11373
- // 硬编码,内部指定的播放全部动画的索引值
11374
- return -88888888;
11375
- }
11376
- var animationInfo = this._sceneOptions.effects.playAnimation;
11377
- if (animationInfo === undefined) {
11378
- return -1;
11379
- }
11380
- if (typeof animationInfo === "number") {
11381
- if (animationInfo >= 0 && animationInfo < animations.length) {
11382
- return animationInfo;
11383
- } else {
11384
- return -1;
11385
- }
11386
- } else {
11387
- // typeof animationInfo === 'string'
11388
- var animationIndex = -1;
11389
- // 通过动画名字查找动画索引
11390
- animations.forEach(function(anim, index) {
11391
- if (anim.name === animationInfo) {
11392
- animationIndex = index;
11393
- }
11394
- });
11395
- return animationIndex;
11396
- }
11397
- };
11398
- _proto.isPlayAnimation = function isPlayAnimation() {
11399
- return this._sceneOptions.effects.playAnimation !== undefined;
11400
- };
11401
- _proto.isPlayAllAnimation = function isPlayAllAnimation() {
11402
- return this._sceneOptions.effects.playAllAnimation === true;
11403
- };
11404
- _proto.getRemarkString = function getRemarkString() {
11405
- var remark = this._sceneOptions.gltf.remark;
11406
- if (remark === undefined) {
11407
- return "Unknown";
11408
- } else if (typeof remark === "string") {
11409
- return remark;
11410
- } else {
11411
- return "BinaryBuffer";
11412
- }
11413
- };
11414
- _proto.isTiny3dMode = function isTiny3dMode() {
11415
- return this._loaderOptions.compatibleMode === "tiny3d";
11416
- };
11417
- _proto.getTextureManager = function getTextureManager() {
11418
- return this._textureManager;
11419
- };
11420
- _proto.getItemDuration = function getItemDuration() {
11421
- var _this__sceneOptions_effects_duration;
11422
- return (_this__sceneOptions_effects_duration = this._sceneOptions.effects.duration) != null ? _this__sceneOptions_effects_duration : 9999;
11423
- };
11424
- _proto.getItemEndBehavior = function getItemEndBehavior() {
11425
- var _this__sceneOptions_effects_endBehavior;
11426
- return (_this__sceneOptions_effects_endBehavior = this._sceneOptions.effects.endBehavior) != null ? _this__sceneOptions_effects_endBehavior : spec.ItemEndBehavior.loop;
11427
- };
11428
- _proto.getSkyboxType = function getSkyboxType() {
11429
- var typeName = this._sceneOptions.gltf.skyboxType;
11430
- switch(typeName){
11431
- case "NFT":
11432
- return PSkyboxType.NFT;
11433
- case "FARM":
11434
- return PSkyboxType.FARM;
11435
- }
11436
- };
11437
- _proto.isSkyboxVis = function isSkyboxVis() {
11438
- return this._sceneOptions.gltf.skyboxVis === true;
11439
- };
11440
- _proto.ignoreSkybox = function ignoreSkybox() {
11441
- return this._sceneOptions.gltf.ignoreSkybox === true;
11442
- };
11443
- _proto.isEnvironmentTest = function isEnvironmentTest() {
11444
- if (typeof this._sceneOptions.gltf.remark === "string") {
11445
- return this._sceneOptions.gltf.remark.includes("EnvironmentTest");
11446
- } else {
11447
- return false;
11448
- }
11449
- };
11450
- return LoaderImpl;
11451
- }();
11452
- var TextureManager = /*#__PURE__*/ function() {
11453
- function TextureManager(owner) {
11454
- this._owner = owner;
11455
- this._gltfImages = [];
11456
- this._gltfTextures = [];
11457
- this._textureMap = new Map();
11458
- }
11459
- var _proto = TextureManager.prototype;
11460
- _proto.initial = function initial(gltfImages, gltfTextures) {
11461
- this._gltfImages = gltfImages;
11462
- this._gltfTextures = gltfTextures;
11463
- this._textureMap.clear();
11464
- };
11465
- _proto.dispose = function dispose() {
11466
- this._textureMap.clear();
11467
- };
11468
- _proto.addTexture = function addTexture(matIndex, texIndex, tex, isBaseColor) {
11469
- var index = isBaseColor ? (matIndex + 1) * 100000 + texIndex : texIndex;
11470
- this._textureMap.set(index, tex);
11471
- };
11472
- _proto.getTexture = function getTexture(matIndex, texIndex, isBaseColor) {
11473
- var index = isBaseColor ? (matIndex + 1) * 100000 + texIndex : texIndex;
11474
- return this._textureMap.get(index);
11475
- };
11476
- return TextureManager;
11477
- }();
11478
- var GeometryProxy = /*#__PURE__*/ function() {
11479
- function GeometryProxy(engine, gltfGeometry, hasSkinAnimation) {
11480
- this.engine = engine;
11481
- this.gltfGeometry = gltfGeometry;
11482
- this.hasSkinAnimation = hasSkinAnimation;
11483
- }
11484
- var _proto = GeometryProxy.prototype;
11485
- _proto._getBufferAttrib = function _getBufferAttrib(inAttrib) {
11486
- var attrib = {
11487
- type: inAttrib.type,
11488
- size: inAttrib.itemSize,
11489
- //stride: inAttrib.stride,
11490
- //offset: inAttrib.offset,
11491
- data: inAttrib.array,
11492
- normalize: inAttrib.normalized
11493
- };
11494
- return attrib;
11495
- };
11496
- _proto.texCoordAttrib = function texCoordAttrib(index) {
11497
- return this.gltfGeometry.getTexCoord(index);
11498
- };
11499
- _proto.getTargetPosition = function getTargetPosition(index) {
11500
- return this.gltfGeometry.getAttribute("POSITION" + index);
11501
- };
11502
- _proto.getTargetNormal = function getTargetNormal(index) {
11503
- return this.gltfGeometry.getAttribute("NORMAL" + index);
11504
- };
11505
- _proto.getTargetTangent = function getTargetTangent(index) {
11506
- return this.gltfGeometry.getAttribute("TANGENT" + index);
11507
- };
11508
- _create_class(GeometryProxy, [
11509
- {
11510
- key: "geometry",
11511
- get: function get() {
11512
- var _this = this;
11513
- var attributes = {};
11514
- if (this.hasPosition) {
11515
- var attrib = this.positionAttrib;
11516
- attributes["aPos"] = this._getBufferAttrib(attrib);
11517
- } else {
11518
- throw new Error("Position attribute missing.");
11519
- }
11520
- if (this.hasNormal) {
11521
- var attrib1 = this.normalAttrib;
11522
- if (attrib1 !== undefined) {
11523
- attributes["aNormal"] = this._getBufferAttrib(attrib1);
11524
- }
11525
- }
11526
- if (this.hasTangent) {
11527
- var attrib2 = this.tangentAttrib;
11528
- if (attrib2 !== undefined) {
11529
- attributes["aTangent"] = this._getBufferAttrib(attrib2);
11530
- }
11531
- }
11532
- this.texCoordList.forEach(function(val) {
11533
- var attrib = _this.texCoordAttrib(val);
11534
- var attribName = "aUV" + (val + 1);
11535
- attributes[attribName] = _this._getBufferAttrib(attrib);
11536
- });
11537
- if (this.hasSkinAnimation) {
11538
- var jointAttrib = this.jointAttribute;
11539
- if (jointAttrib !== undefined) {
11540
- attributes["aJoints"] = this._getBufferAttrib(jointAttrib);
11541
- }
11542
- var weightAttrib = this.weightAttribute;
11543
- if (weightAttrib !== undefined) {
11544
- attributes["aWeights"] = this._getBufferAttrib(weightAttrib);
11545
- }
11546
- }
11547
- /**
11548
- * 设置Morph动画需要的Attribute,主要包括Position,Normal和Tangent
11549
- */ for(var i = 0; i < 8; i++){
11550
- var positionAttrib = this.getTargetPosition(i);
11551
- if (positionAttrib !== undefined) {
11552
- attributes["aTargetPosition" + i] = this._getBufferAttrib(positionAttrib);
11553
- }
11554
- var normalAttrib = this.getTargetNormal(i);
11555
- if (normalAttrib !== undefined) {
11556
- attributes["aTargetNormal" + i] = this._getBufferAttrib(normalAttrib);
11557
- }
11558
- var tangentAttrib = this.getTargetTangent(i);
11559
- if (tangentAttrib !== undefined) {
11560
- attributes["aTargetTangent" + i] = this._getBufferAttrib(tangentAttrib);
11561
- }
11562
- }
11563
- var indexArray = this.indexArray;
11564
- if (indexArray !== undefined) {
11565
- return Geometry.create(this.engine, {
11566
- attributes: attributes,
11567
- indices: {
11568
- data: indexArray
11569
- },
11570
- drawStart: 0,
11571
- drawCount: indexArray.length,
11572
- mode: glContext.TRIANGLES
11573
- });
11574
- } else {
11575
- return Geometry.create(this.engine, {
11576
- attributes: attributes,
11577
- drawStart: 0,
11578
- drawCount: this.positionAttrib.array.length / 3,
11579
- mode: glContext.TRIANGLES
11580
- });
11581
- }
11582
- }
11583
- },
11584
- {
11585
- key: "positionAttrib",
11586
- get: function get() {
11587
- return this.gltfGeometry.getPosition();
11588
- }
11589
- },
11590
- {
11591
- key: "normalAttrib",
11592
- get: function get() {
11593
- return this.gltfGeometry.getNormal();
11594
- }
11595
- },
11596
- {
11597
- key: "tangentAttrib",
11598
- get: function get() {
11599
- return this.gltfGeometry.getTangent();
11600
- }
11601
- },
11602
- {
11603
- key: "jointAttribute",
11604
- get: function get() {
11605
- return this.gltfGeometry.getJoints(0);
11606
- }
11607
- },
11608
- {
11609
- key: "weightAttribute",
11610
- get: function get() {
11611
- return this.gltfGeometry.getWeights(0);
11612
- }
11613
- },
11614
- {
11615
- key: "hasPosition",
11616
- get: function get() {
11617
- return this.positionAttrib !== undefined;
11618
- }
11619
- },
11620
- {
11621
- key: "hasNormal",
11622
- get: function get() {
11623
- return this.normalAttrib !== undefined;
11624
- }
11625
- },
11626
- {
11627
- key: "hasTangent",
11628
- get: function get() {
11629
- return this.tangentAttrib !== undefined;
11630
- }
11631
- },
11632
- {
11633
- key: "hasTexCoord",
11634
- get: function get() {
11635
- return this.texCoordCount > 0;
11636
- }
11637
- },
11638
- {
11639
- key: "texCoordCount",
11640
- get: function get() {
11641
- for(var i = 0; i < 10; i++){
11642
- if (this.texCoordAttrib(i) === undefined) {
11643
- return i;
11644
- }
11645
- }
11646
- return 0;
11647
- }
11648
- },
11649
- {
11650
- key: "hasJointAttribute",
11651
- get: function get() {
11652
- return this.jointAttribute !== undefined;
11653
- }
11654
- },
11655
- {
11656
- key: "hasWeightAttribute",
11657
- get: function get() {
11658
- return this.weightAttribute !== undefined;
11659
- }
11660
- },
11661
- {
11662
- key: "indexArray",
11663
- get: function get() {
11664
- if (this.gltfGeometry.indices === undefined) {
11665
- return undefined;
11666
- }
11667
- switch(this.gltfGeometry.indices.type){
11668
- case WebGLRenderingContext["UNSIGNED_INT"]:
11669
- return this.gltfGeometry.indices.array;
11670
- case WebGLRenderingContext["UNSIGNED_SHORT"]:
11671
- return this.gltfGeometry.indices.array;
11672
- case WebGLRenderingContext["UNSIGNED_BYTE"]:
11673
- return this.gltfGeometry.indices.array;
11674
- }
11675
- return undefined;
11676
- }
11677
- },
11678
- {
11679
- key: "indexCount",
11680
- get: function get() {
11681
- if (this.gltfGeometry.indices !== undefined) {
11682
- return this.gltfGeometry.indices.array.length;
11683
- } else {
11684
- return 0;
11685
- }
11686
- }
11687
- },
11688
- {
11689
- key: "texCoordList",
11690
- get: function get() {
11691
- var texCoords = [];
11692
- for(var i = 0; i < 10; i++){
11693
- if (this.texCoordAttrib(i) !== undefined) {
11694
- texCoords.push(i);
11695
- } else {
11696
- break;
11697
- }
11698
- }
11699
- return texCoords;
11700
- }
11701
- }
11702
- ]);
11703
- return GeometryProxy;
11704
- }();
11705
- var MaterialProxy = /*#__PURE__*/ function() {
11706
- function MaterialProxy(material, textures, tiny3dMode) {
11707
- this.gltfMaterial = material;
11708
- this.textures = textures;
11709
- this.tiny3dMode = tiny3dMode;
11710
- }
11711
- var _proto = MaterialProxy.prototype;
11712
- _proto.getTextureObject = function getTextureObject(index) {
11713
- if (index < 0 || index >= this.textures.length) {
11714
- return;
11715
- }
11716
- return this.textures[index];
11717
- };
11718
- _proto.getTextureObj = function getTextureObj(texInfo) {
11719
- return texInfo ? this.getTextureObject(texInfo.index) : undefined;
11720
- };
11721
- _proto.getTextureCoord = function getTextureCoord(texInfo) {
11722
- return texInfo ? texInfo.texCoord : undefined;
11723
- };
11724
- _proto.getTextureTransform = function getTextureTransform(texInfo) {
11725
- var _texInfo_extensions;
11726
- var transform = texInfo == null ? void 0 : (_texInfo_extensions = texInfo.extensions) == null ? void 0 : _texInfo_extensions.KHR_texture_transform;
11727
- if (transform === undefined) {
11728
- return;
11729
- }
11730
- if (transform.offset === undefined && transform.rotation === undefined && transform.scale === undefined) {
11731
- return;
11732
- }
11733
- return {
11734
- offset: transform.offset,
11735
- rotation: transform.rotation,
11736
- scale: transform.scale
11737
- };
11738
- };
11739
- _proto.getSpecularAA = function getSpecularAA() {
11740
- var _this_gltfMaterial_extras;
11741
- return (_this_gltfMaterial_extras = this.gltfMaterial.extras) == null ? void 0 : _this_gltfMaterial_extras.useSpecularAA;
11742
- };
11743
- _create_class(MaterialProxy, [
11744
- {
11745
- key: "material",
11746
- get: function get() {
11747
- var mat = this.gltfMaterial;
11748
- var isUnlit = GLTFHelper.isUnlitMaterial(mat);
11749
- var blending = spec.MaterialBlending.opaque;
11750
- switch(mat.alphaMode){
11751
- case "OPAQUE":
11752
- blending = spec.MaterialBlending.opaque;
11753
- break;
11754
- case "MASK":
11755
- blending = spec.MaterialBlending.masked;
11756
- break;
11757
- case "BLEND":
11758
- blending = spec.MaterialBlending.translucent;
11759
- break;
11760
- }
11761
- var side = mat.doubleSided ? spec.SideMode.DOUBLE : spec.SideMode.FRONT;
11762
- var enableShadow = false;
11763
- var _mat_alphaCutOff;
11764
- var alphaCutOff = (_mat_alphaCutOff = mat.alphaCutOff) != null ? _mat_alphaCutOff : 0.5;
11765
- var name = mat.name;
11766
- if (isUnlit) {
11767
- var _mat_extras;
11768
- return {
11769
- name: name,
11770
- type: spec.MaterialType.unlit,
11771
- baseColorTexture: this.baseColorTextureObj,
11772
- baseColorTextureCoordinate: this.baseColorTextureCoord,
11773
- baseColorTextureTransform: this.baseColorTextureTransfrom,
11774
- baseColorFactor: this.baseColorFactor,
11775
- //
11776
- depthMask: (_mat_extras = mat.extras) == null ? void 0 : _mat_extras.depthMask,
11777
- blending: blending,
11778
- alphaCutOff: alphaCutOff,
11779
- side: side
11780
- };
11781
- } else {
11782
- var _mat_extras1;
11783
- return {
11784
- name: name,
11785
- type: spec.MaterialType.pbr,
11786
- baseColorTexture: this.baseColorTextureObj,
11787
- baseColorTextureCoordinate: this.baseColorTextureCoord,
11788
- baseColorTextureTransform: this.baseColorTextureTransfrom,
11789
- baseColorFactor: this.baseColorFactor,
11790
- //
11791
- useSpecularAA: this.getSpecularAA(),
11792
- //
11793
- metallicRoughnessTexture: this.metallicRoughnessTextureObj,
11794
- metallicRoughnessTextureCoordinate: this.metallicRoughnessTextureCoord,
11795
- metallicRoughnessTextureTransform: this.metallicRoughnessTextureTransfrom,
11796
- metallicFactor: this.metalicFactor,
11797
- roughnessFactor: this.roughnessFactor,
11798
- //
11799
- normalTexture: this.normalTextureObj,
11800
- normalTextureCoordinate: this.normalTextureCoord,
11801
- normalTextureTransform: this.normalTextureTransfrom,
11802
- normalTextureScale: this.normalTextureScale,
11803
- //
11804
- occlusionTexture: this.occlusionTextureObj,
11805
- occlusionTextureCoordinate: this.occlusionTextureCoord,
11806
- occlusionTextureTransform: this.occlusionTextureTransfrom,
11807
- occlusionTextureStrength: this.occlusionTextureStrength,
11808
- //
11809
- emissiveTexture: this.emissiveTextureObj,
11810
- emissiveTextureCoordinate: this.emissiveTextureCoord,
11811
- emissiveTextureTransform: this.emissiveTextureTransfrom,
11812
- emissiveFactor: this.emissiveFactor,
11813
- emissiveIntensity: 1.0,
11814
- //
11815
- depthMask: (_mat_extras1 = mat.extras) == null ? void 0 : _mat_extras1.depthMask,
11816
- blending: blending,
11817
- alphaCutOff: alphaCutOff,
11818
- side: side,
11819
- enableShadow: enableShadow
11820
- };
11821
- }
11822
- }
11823
- },
11824
- {
11825
- key: "baseColorTextureObj",
11826
- get: function get() {
11827
- return this.getTextureObj(this.gltfMaterial.baseColorTexture);
11828
- }
11829
- },
11830
- {
11831
- key: "baseColorTextureCoord",
11832
- get: function get() {
11833
- return this.getTextureCoord(this.gltfMaterial.baseColorTexture);
11834
- }
11835
- },
11836
- {
11837
- key: "baseColorTextureTransfrom",
11838
- get: function get() {
11839
- return this.getTextureTransform(this.gltfMaterial.baseColorTexture);
11840
- }
11841
- },
11842
- {
11843
- key: "metallicRoughnessTextureObj",
11844
- get: function get() {
11845
- return this.getTextureObj(this.gltfMaterial.metallicRoughnessTexture);
11846
- }
11847
- },
11848
- {
11849
- key: "metallicRoughnessTextureCoord",
11850
- get: function get() {
11851
- return this.getTextureCoord(this.gltfMaterial.metallicRoughnessTexture);
11852
- }
11853
- },
11854
- {
11855
- key: "metallicRoughnessTextureTransfrom",
11856
- get: function get() {
11857
- return this.getTextureTransform(this.gltfMaterial.metallicRoughnessTexture);
11858
- }
11859
- },
11860
- {
11861
- key: "normalTextureObj",
11862
- get: function get() {
11863
- return this.getTextureObj(this.gltfMaterial.normalTexture);
11864
- }
11865
- },
11866
- {
11867
- key: "normalTextureCoord",
11868
- get: function get() {
11869
- return this.getTextureCoord(this.gltfMaterial.normalTexture);
11870
- }
11871
- },
11872
- {
11873
- key: "normalTextureTransfrom",
11874
- get: function get() {
11875
- return this.getTextureTransform(this.gltfMaterial.normalTexture);
11876
- }
11877
- },
11878
- {
11879
- key: "occlusionTextureObj",
11880
- get: function get() {
11881
- return this.getTextureObj(this.gltfMaterial.occlusionTexture);
11882
- }
11883
- },
11884
- {
11885
- key: "occlusionTextureCoord",
11886
- get: function get() {
11887
- return this.getTextureCoord(this.gltfMaterial.occlusionTexture);
11888
- }
11889
- },
11890
- {
11891
- key: "occlusionTextureTransfrom",
11892
- get: function get() {
11893
- return this.getTextureTransform(this.gltfMaterial.occlusionTexture);
11894
- }
11895
- },
11896
- {
11897
- key: "emissiveTextureObj",
11898
- get: function get() {
11899
- return this.getTextureObj(this.gltfMaterial.emissiveTexture);
11900
- }
11901
- },
11902
- {
11903
- key: "emissiveTextureCoord",
11904
- get: function get() {
11905
- return this.getTextureCoord(this.gltfMaterial.emissiveTexture);
11906
- }
11907
- },
11908
- {
11909
- key: "emissiveTextureTransfrom",
11910
- get: function get() {
11911
- return this.getTextureTransform(this.gltfMaterial.emissiveTexture);
11912
- }
11913
- },
11914
- {
11915
- key: "hasEmissive",
11916
- get: function get() {
11917
- var factor = this.emissiveFactor;
11918
- return factor[0] + factor[1] + factor[2] > 0;
11919
- }
11920
- },
11921
- {
11922
- key: "baseColorFactor",
11923
- get: function get() {
11924
- var f = this.gltfMaterial.baseColorFactor;
11925
- if (f === undefined || f.length != 4) {
11926
- return [
11927
- 1,
11928
- 1,
11929
- 1,
11930
- 1
11931
- ];
11932
- } else {
11933
- return [
11934
- f[0],
11935
- f[1],
11936
- f[2],
11937
- f[3]
11938
- ];
11939
- }
11940
- }
11941
- },
11942
- {
11943
- key: "metalicFactor",
11944
- get: function get() {
11945
- var _this_gltfMaterial_metallicFactor;
11946
- return (_this_gltfMaterial_metallicFactor = this.gltfMaterial.metallicFactor) != null ? _this_gltfMaterial_metallicFactor : 1;
11947
- }
11948
- },
11949
- {
11950
- key: "roughnessFactor",
11951
- get: function get() {
11952
- var _this_gltfMaterial_roughnessFactor;
11953
- return (_this_gltfMaterial_roughnessFactor = this.gltfMaterial.roughnessFactor) != null ? _this_gltfMaterial_roughnessFactor : 1;
11954
- }
11955
- },
11956
- {
11957
- key: "normalTextureScale",
11958
- get: function get() {
11959
- var _this_gltfMaterial_normalTexture;
11960
- var _this_gltfMaterial_normalTexture_scale;
11961
- return (_this_gltfMaterial_normalTexture_scale = (_this_gltfMaterial_normalTexture = this.gltfMaterial.normalTexture) == null ? void 0 : _this_gltfMaterial_normalTexture.scale) != null ? _this_gltfMaterial_normalTexture_scale : 1;
11962
- }
11963
- },
11964
- {
11965
- key: "occlusionTextureStrength",
11966
- get: function get() {
11967
- var _this_gltfMaterial_occlusionTexture;
11968
- var _this_gltfMaterial_occlusionTexture_strength;
11969
- return (_this_gltfMaterial_occlusionTexture_strength = (_this_gltfMaterial_occlusionTexture = this.gltfMaterial.occlusionTexture) == null ? void 0 : _this_gltfMaterial_occlusionTexture.strength) != null ? _this_gltfMaterial_occlusionTexture_strength : 1;
11970
- }
11971
- },
11972
- {
11973
- key: "emissiveFactor",
11974
- get: function get() {
11975
- var f = this.gltfMaterial.emissiveFactor;
11976
- if (f === undefined || f.length != 4) {
11977
- return [
11978
- 0,
11979
- 0,
11980
- 0,
11981
- 1
11982
- ];
11983
- } else {
11984
- return [
11985
- f[0],
11986
- f[1],
11987
- f[2],
11988
- 1.0
11989
- ];
11990
- }
11991
- }
11992
- }
11993
- ]);
11994
- return MaterialProxy;
11995
- }();
11996
- var GLTFHelper = /*#__PURE__*/ function() {
11997
- function GLTFHelper() {}
11998
- GLTFHelper.isUnlitMaterial = function isUnlitMaterial(mat) {
11999
- var _mat_extensions;
12000
- return ((_mat_extensions = mat.extensions) == null ? void 0 : _mat_extensions.KHR_materials_unlit) !== undefined;
12001
- };
12002
- GLTFHelper.createBoxFromGLTFBound = function createBoxFromGLTFBound(bound) {
12003
- var boxMin = Vector3.fromArray(bound.box.min);
12004
- var boxMax = Vector3.fromArray(bound.box.max);
12005
- return new Box3(boxMin, boxMax);
12006
- };
12007
- return GLTFHelper;
12008
- }();
12009
-
12010
- var JSONConverter = /*#__PURE__*/ function() {
12011
- function JSONConverter(player) {
12012
- this.treeInfo = new TreeInfo();
12013
- this.engine = player.renderer.engine;
12014
- this.renderer = player.renderer;
12015
- this.downloader = new Downloader();
12016
- }
12017
- var _proto = JSONConverter.prototype;
12018
- _proto.processScene = function processScene(sceneData) {
12019
- var _this = this;
12020
- return _async_to_generator(function() {
12021
- var sceneJSON, _tmp, oldScene, binFiles, _iterator, _step, bin, _, newScene;
12022
- return __generator(this, function(_state) {
12023
- switch(_state.label){
12024
- case 0:
12025
- if (!isObject(sceneData)) return [
12026
- 3,
12027
- 1
12028
- ];
12029
- _tmp = sceneData;
12030
- return [
12031
- 3,
12032
- 3
12033
- ];
12034
- case 1:
12035
- return [
12036
- 4,
12037
- _this.loadJSON(sceneData)
12038
- ];
12039
- case 2:
12040
- _tmp = _state.sent();
12041
- _state.label = 3;
12042
- case 3:
12043
- sceneJSON = _tmp;
12044
- // @ts-expect-error
12045
- sceneJSON.textures.forEach(function(tex) {
12046
- if (tex.source === undefined) {
12047
- tex.source = 0;
12048
- }
12049
- });
12050
- oldScene = getStandardJSON(sceneJSON);
12051
- binFiles = [];
12052
- if (!oldScene.bins) return [
12053
- 3,
12054
- 7
12055
- ];
12056
- _iterator = _create_for_of_iterator_helper_loose(oldScene.bins);
12057
- _state.label = 4;
12058
- case 4:
12059
- if (!!(_step = _iterator()).done) return [
12060
- 3,
12061
- 7
12062
- ];
12063
- bin = _step.value;
12064
- _ = binFiles.push;
12065
- return [
12066
- 4,
12067
- _this.loadBins(bin.url)
12068
- ];
12069
- case 5:
12070
- _.apply(binFiles, [
12071
- _state.sent()
12072
- ]);
12073
- _state.label = 6;
12074
- case 6:
12075
- return [
12076
- 3,
12077
- 4
12078
- ];
12079
- case 7:
12080
- // @ts-expect-error
12081
- oldScene.bins = binFiles;
12082
- newScene = _extends({}, oldScene, {
12083
- version: "3.0",
12084
- playerVersion: {
12085
- web: "3.0",
12086
- native: "3.0"
12087
- },
12088
- type: "ge",
12089
- compositions: [],
12090
- images: [],
12091
- textures: [],
12092
- items: [],
12093
- components: [],
12094
- materials: [],
12095
- shaders: [],
12096
- geometries: []
12097
- });
12098
- _this.setImage(newScene, oldScene);
12099
- return [
12100
- 4,
12101
- _this.setTexture(newScene, oldScene)
12102
- ];
12103
- case 8:
12104
- _state.sent();
12105
- _this.setComponent(newScene, oldScene);
12106
- _this.setItem(newScene, oldScene);
12107
- _this.setComposition(newScene, oldScene);
12108
- return [
12109
- 2,
12110
- newScene
12111
- ];
12112
- }
12113
- });
12114
- })();
12115
- };
12116
- _proto.setImage = function setImage(newScene, oldScene) {
12117
- var newImages = [];
12118
- oldScene.images.forEach(function(image) {
12119
- newImages.push(image);
12120
- });
12121
- newScene.images = newImages;
12122
- };
12123
- _proto.setTexture = function setTexture(newScene, oldScene) {
10753
+ _proto.setTexture = function setTexture(newScene, oldScene) {
12124
10754
  var _this = this;
12125
10755
  return _async_to_generator(function() {
12126
10756
  var newTextures, bins, _iterator, _step, tex, mipmaps, target, jobs, loadedMipmaps, newMipmaps, newTex, source;
@@ -13368,8 +11998,19 @@ var vertexBufferSemanticMap = {
13368
11998
  a_Target_Tangent3: "TANGENT_BS3"
13369
11999
  };
13370
12000
 
13371
- var LoaderECSImpl = /*#__PURE__*/ function() {
13372
- function LoaderECSImpl(composition) {
12001
+ function getDefaultEffectsGLTFLoader(options) {
12002
+ if (!defaultGLTFLoader) {
12003
+ defaultGLTFLoader = new LoaderImpl();
12004
+ }
12005
+ defaultGLTFLoader.initial(options);
12006
+ return defaultGLTFLoader;
12007
+ }
12008
+ function setDefaultEffectsGLTFLoader(loader) {
12009
+ defaultGLTFLoader = loader;
12010
+ }
12011
+ var defaultGLTFLoader;
12012
+ var LoaderImpl = /*#__PURE__*/ function() {
12013
+ function LoaderImpl(composition) {
13373
12014
  this.gltfSkins = [];
13374
12015
  this.gltfMeshs = [];
13375
12016
  this.gltfLights = [];
@@ -13389,6 +12030,7 @@ var LoaderECSImpl = /*#__PURE__*/ function() {
13389
12030
  this.shaders = [];
13390
12031
  this.geometries = [];
13391
12032
  this.animations = [];
12033
+ this.sceneAABB = new Box3();
13392
12034
  if (composition) {
13393
12035
  this.composition = composition;
13394
12036
  } else {
@@ -13422,21 +12064,16 @@ var LoaderECSImpl = /*#__PURE__*/ function() {
13422
12064
  };
13423
12065
  }
13424
12066
  }
13425
- var _proto = LoaderECSImpl.prototype;
13426
- _proto.initial = function initial(engine, options) {
13427
- this.engine = engine;
13428
- this.loaderOptions = options != null ? options : {};
13429
- };
12067
+ var _proto = LoaderImpl.prototype;
13430
12068
  _proto.loadScene = function loadScene(options) {
13431
12069
  var _this = this;
13432
12070
  return _async_to_generator(function() {
13433
- var _this_components, _this_components1, _this_components2, _this_items, _options_effects_renderer, gltfResource, gltfScene, component, clips, index;
12071
+ var _this_components, _this_components1, _this_components2, _this_items, gltfResource, gltfScene, component, clips, index;
13434
12072
  return __generator(this, function(_state) {
13435
12073
  switch(_state.label){
13436
12074
  case 0:
13437
12075
  _this.clear();
13438
12076
  _this.sceneOptions = options;
13439
- _this.engine = (_options_effects_renderer = options.effects.renderer) == null ? void 0 : _options_effects_renderer.engine;
13440
12077
  _this.loaderOptions = {
13441
12078
  compatibleMode: options.gltf.compatibleMode
13442
12079
  };
@@ -13469,7 +12106,7 @@ var LoaderECSImpl = /*#__PURE__*/ function() {
13469
12106
  ];
13470
12107
  case 1:
13471
12108
  _this.imageElements = _state.sent();
13472
- _this.processGLTFResource(gltfResource);
12109
+ _this.processGLTFResource(gltfResource, _this.imageElements);
13473
12110
  _this.gltfScene = gltfResource.scenes[0];
13474
12111
  _this.gltfSkins = _this.gltfScene.skins;
13475
12112
  _this.gltfMeshs = gltfResource.meshes;
@@ -13549,25 +12186,7 @@ var LoaderECSImpl = /*#__PURE__*/ function() {
13549
12186
  });
13550
12187
  })();
13551
12188
  };
13552
- _proto.checkMeshComponentData = function checkMeshComponentData(mesh, resource) {
13553
- if (mesh.materials.length <= 0) {
13554
- throw new Error("Submesh array is empty for mesh with ID: " + mesh.id + ".");
13555
- }
13556
- var geometryData;
13557
- resource.meshes.forEach(function(meshData) {
13558
- if (meshData.geometryData.id === mesh.geometry.id) {
13559
- geometryData = meshData.geometryData;
13560
- }
13561
- });
13562
- if (geometryData === undefined) {
13563
- throw new Error("Unable to find geometry data for mesh with ID: " + mesh.geometry.id + ".");
13564
- }
13565
- if (geometryData.subMeshes.length !== mesh.materials.length) {
13566
- throw new Error("Mismatch between submeshes count (" + geometryData.subMeshes.length + ") and materials count (" + mesh.materials.length + ").");
13567
- }
13568
- //mesh.materials.length !=
13569
- };
13570
- _proto.processGLTFResource = function processGLTFResource(resource) {
12189
+ _proto.processGLTFResource = function processGLTFResource(resource, imageElements) {
13571
12190
  var _loop = function() {
13572
12191
  var baseColorId = _step.value;
13573
12192
  if (emissiveIdSet.has(baseColorId)) {
@@ -13582,23 +12201,23 @@ var LoaderECSImpl = /*#__PURE__*/ function() {
13582
12201
  id: newId
13583
12202
  });
13584
12203
  textures.push(newTexData);
13585
- dataMap[newId] = newTexData.textureOptions;
12204
+ textureDataMap[newId] = newTexData.textureOptions;
13586
12205
  textureIdMap[baseColorId] = newId;
13587
- mapCount += 1;
12206
+ addTextures += 1;
13588
12207
  }
13589
12208
  }
13590
12209
  };
13591
12210
  var _this = this;
13592
- var dataMap = {};
12211
+ var textureDataMap = {};
13593
12212
  var textures = resource.textures, materials = resource.materials, scenes = resource.scenes, imageBasedLights = resource.imageBasedLights;
13594
12213
  textures.forEach(function(tex) {
13595
12214
  var texData = tex.textureOptions;
13596
12215
  var texId = texData.id;
13597
12216
  if (texId) {
13598
- if (dataMap[texId]) {
13599
- console.error("Duplicate GUID found: " + texId + ", old " + dataMap[texId] + ", new " + texData + ".");
12217
+ if (textureDataMap[texId]) {
12218
+ console.error("Duplicate GUID found: " + texId + ", old " + textureDataMap[texId] + ", new " + texData + ".");
13600
12219
  }
13601
- dataMap[texId] = texData;
12220
+ textureDataMap[texId] = texData;
13602
12221
  } else {
13603
12222
  console.error("No GUID in texture Data: " + texData + ".");
13604
12223
  }
@@ -13617,29 +12236,29 @@ var LoaderECSImpl = /*#__PURE__*/ function() {
13617
12236
  emissiveIdSet.add(emissiveTexture.id);
13618
12237
  }
13619
12238
  });
13620
- var mapCount = 0;
12239
+ var addTextures = 0;
13621
12240
  var textureIdMap = {};
13622
12241
  for(var _iterator = _create_for_of_iterator_helper_loose(baseColorIdSet), _step; !(_step = _iterator()).done;)_loop();
13623
- if (mapCount > 0) {
13624
- console.warn("Duplicate emissive texture " + mapCount);
12242
+ if (addTextures > 0) {
12243
+ console.warn("Add base color texture " + addTextures);
13625
12244
  }
13626
12245
  materials.forEach(function(mat) {
13627
12246
  var _materialData_shader, _materialData_shader1;
13628
12247
  var materialData = mat.materialData;
13629
12248
  _this.processMaterialData(materialData);
13630
12249
  if (((_materialData_shader = materialData.shader) == null ? void 0 : _materialData_shader.id) === UnlitShaderGUID) {
13631
- _this.processMaterialTexture(materialData, "_BaseColorSampler", true, dataMap);
12250
+ _this.processMaterialTexture(materialData, "_BaseColorSampler", true, textureDataMap, imageElements);
13632
12251
  } else if (((_materialData_shader1 = materialData.shader) == null ? void 0 : _materialData_shader1.id) === PBRShaderGUID) {
13633
12252
  var _materialData_textures__EmissiveSampler;
13634
12253
  var emissiveTexture = (_materialData_textures__EmissiveSampler = materialData.textures["_EmissiveSampler"]) == null ? void 0 : _materialData_textures__EmissiveSampler.texture;
13635
12254
  if (emissiveTexture && textureIdMap[emissiveTexture.id]) {
13636
12255
  emissiveTexture.id = textureIdMap[emissiveTexture.id];
13637
12256
  }
13638
- _this.processMaterialTexture(materialData, "_BaseColorSampler", true, dataMap);
13639
- _this.processMaterialTexture(materialData, "_MetallicRoughnessSampler", false, dataMap);
13640
- _this.processMaterialTexture(materialData, "_NormalSampler", false, dataMap);
13641
- _this.processMaterialTexture(materialData, "_OcclusionSampler", false, dataMap);
13642
- _this.processMaterialTexture(materialData, "_EmissiveSampler", false, dataMap);
12257
+ _this.processMaterialTexture(materialData, "_BaseColorSampler", true, textureDataMap, imageElements);
12258
+ _this.processMaterialTexture(materialData, "_MetallicRoughnessSampler", false, textureDataMap, imageElements);
12259
+ _this.processMaterialTexture(materialData, "_NormalSampler", false, textureDataMap, imageElements);
12260
+ _this.processMaterialTexture(materialData, "_OcclusionSampler", false, textureDataMap, imageElements);
12261
+ _this.processMaterialTexture(materialData, "_EmissiveSampler", false, textureDataMap, imageElements);
13643
12262
  }
13644
12263
  });
13645
12264
  var gltfScene = scenes[0];
@@ -13649,9 +12268,6 @@ var LoaderECSImpl = /*#__PURE__*/ function() {
13649
12268
  gltfScene.lightsComponentData.forEach(function(comp) {
13650
12269
  return _this.processLightComponentData(comp);
13651
12270
  });
13652
- gltfScene.meshesComponentData.forEach(function(comp) {
13653
- return _this.processMeshComponentData(comp);
13654
- });
13655
12271
  var cubeTextures = [];
13656
12272
  imageBasedLights.forEach(function(ibl) {
13657
12273
  var data = ibl.imageBaseLightData;
@@ -13659,11 +12275,11 @@ var LoaderECSImpl = /*#__PURE__*/ function() {
13659
12275
  data.reflectionsIntensity = data.intensity;
13660
12276
  }
13661
12277
  if (data.diffuseImage) {
13662
- var diffuseTexture = dataMap[data.diffuseImage.id];
12278
+ var diffuseTexture = textureDataMap[data.diffuseImage.id];
13663
12279
  addItem(cubeTextures, diffuseTexture);
13664
12280
  }
13665
12281
  if (data.specularImage) {
13666
- var specularImage = dataMap[data.specularImage.id];
12282
+ var specularImage = textureDataMap[data.specularImage.id];
13667
12283
  addItem(cubeTextures, specularImage);
13668
12284
  }
13669
12285
  });
@@ -13694,8 +12310,6 @@ var LoaderECSImpl = /*#__PURE__*/ function() {
13694
12310
  _this.processLightComponentData(comp);
13695
12311
  } else if (comp.dataType === spec.DataType.CameraComponent) {
13696
12312
  _this.processCameraComponentData(comp);
13697
- } else if (comp.dataType === spec.DataType.MeshComponent) {
13698
- _this.processMeshComponentData(comp);
13699
12313
  } else if (comp.dataType === spec.DataType.SkyboxComponent) {
13700
12314
  _this.processSkyboxComponentData(comp);
13701
12315
  }
@@ -13736,7 +12350,6 @@ var LoaderECSImpl = /*#__PURE__*/ function() {
13736
12350
  }
13737
12351
  }
13738
12352
  };
13739
- _proto.processMeshComponentData = function processMeshComponentData(mesh) {};
13740
12353
  _proto.processSkyboxComponentData = function processSkyboxComponentData(skybox) {
13741
12354
  if (skybox.intensity === undefined) {
13742
12355
  skybox.intensity = 1;
@@ -13850,11 +12463,31 @@ var LoaderECSImpl = /*#__PURE__*/ function() {
13850
12463
  options.premultiplyAlpha = premultiplyAlpha;
13851
12464
  options.generateMipmap = generateMipmap;
13852
12465
  };
13853
- _proto.processMaterialTexture = function processMaterialTexture(material, textureName, isBaseColor, dataMap) {
12466
+ _proto.initial = function initial(options) {
12467
+ this.loaderOptions = options != null ? options : {};
12468
+ };
12469
+ _proto.checkMeshComponentData = function checkMeshComponentData(mesh, resource) {
12470
+ if (mesh.materials.length <= 0) {
12471
+ throw new Error("Submesh array is empty for mesh with ID: " + mesh.id + ".");
12472
+ }
12473
+ var geometryData;
12474
+ resource.meshes.forEach(function(meshData) {
12475
+ if (meshData.geometryData.id === mesh.geometry.id) {
12476
+ geometryData = meshData.geometryData;
12477
+ }
12478
+ });
12479
+ if (geometryData === undefined) {
12480
+ throw new Error("Unable to find geometry data for mesh with ID: " + mesh.geometry.id + ".");
12481
+ }
12482
+ if (geometryData.subMeshes.length !== mesh.materials.length) {
12483
+ throw new Error("Mismatch between submeshes count (" + geometryData.subMeshes.length + ") and materials count (" + mesh.materials.length + ").");
12484
+ }
12485
+ };
12486
+ _proto.processMaterialTexture = function processMaterialTexture(material, textureName, isBaseColor, textureDataMap, imageElements) {
13854
12487
  var texture = material.textures[textureName];
13855
12488
  if (texture) {
13856
12489
  var id = texture.texture.id;
13857
- var texData = dataMap[id];
12490
+ var texData = textureDataMap[id];
13858
12491
  var imageObj;
13859
12492
  // @ts-expect-error
13860
12493
  if (typeof texData.source !== "number") {
@@ -13862,7 +12495,7 @@ var LoaderECSImpl = /*#__PURE__*/ function() {
13862
12495
  throw new Error("Invalid texture option source data, " + texData.source);
13863
12496
  } else {
13864
12497
  // @ts-expect-error
13865
- imageObj = this.imageElements[texData.source];
12498
+ imageObj = imageElements[texData.source];
13866
12499
  }
13867
12500
  if (texData) {
13868
12501
  this.processTextureOptions(texData, isBaseColor, imageObj);
@@ -13907,20 +12540,13 @@ var LoaderECSImpl = /*#__PURE__*/ function() {
13907
12540
  }
13908
12541
  ]
13909
12542
  };
12543
+ var sceneAABB = this.computeSceneAABB();
13910
12544
  return {
13911
12545
  source: this.getRemarkString(),
13912
12546
  jsonScene: jsonScene,
13913
12547
  sceneAABB: {
13914
- min: [
13915
- -1,
13916
- -1,
13917
- -1
13918
- ],
13919
- max: [
13920
- 1,
13921
- 1,
13922
- 1
13923
- ]
12548
+ min: sceneAABB.min.toArray(),
12549
+ max: sceneAABB.max.toArray()
13924
12550
  }
13925
12551
  };
13926
12552
  };
@@ -14091,99 +12717,6 @@ var LoaderECSImpl = /*#__PURE__*/ function() {
14091
12717
  });
14092
12718
  })();
14093
12719
  };
14094
- _proto.createTreeOptions = function createTreeOptions(scene) {
14095
- var nodeList = scene.nodes.map(function(node, nodeIndex) {
14096
- var children = node.children.map(function(child) {
14097
- if (child.nodeIndex === undefined) {
14098
- throw new Error("Undefined nodeIndex for child " + child + ".");
14099
- }
14100
- return child.nodeIndex;
14101
- });
14102
- var pos = [
14103
- 0,
14104
- 0,
14105
- 0
14106
- ];
14107
- var quat = [
14108
- 0,
14109
- 0,
14110
- 0,
14111
- 0
14112
- ];
14113
- var scale = [
14114
- 0,
14115
- 0,
14116
- 0
14117
- ];
14118
- if (node.matrix !== undefined) {
14119
- if (node.matrix.length !== 16) {
14120
- throw new Error("Invalid matrix length " + node.matrix.length + " for node " + node + ".");
14121
- }
14122
- var mat = Matrix4.fromArray(node.matrix);
14123
- var transform = mat.getTransform();
14124
- pos = transform.translation.toArray();
14125
- quat = transform.rotation.toArray();
14126
- scale = transform.scale.toArray();
14127
- } else {
14128
- if (node.translation !== undefined) {
14129
- pos = node.translation;
14130
- }
14131
- if (node.rotation !== undefined) {
14132
- quat = node.rotation;
14133
- }
14134
- if (node.scale !== undefined) {
14135
- scale = node.scale;
14136
- }
14137
- }
14138
- node.nodeIndex = nodeIndex;
14139
- var treeNode = {
14140
- name: node.name,
14141
- transform: {
14142
- position: pos,
14143
- quat: quat,
14144
- scale: scale
14145
- },
14146
- children: children,
14147
- id: "" + node.nodeIndex
14148
- };
14149
- return treeNode;
14150
- });
14151
- var rootNodes = scene.rootNodes.map(function(root) {
14152
- if (root.nodeIndex === undefined) {
14153
- throw new Error("Undefined nodeIndex for root " + root + ".");
14154
- }
14155
- return root.nodeIndex;
14156
- });
14157
- var treeOptions = {
14158
- nodes: nodeList,
14159
- children: rootNodes,
14160
- animation: -1,
14161
- animations: []
14162
- };
14163
- return treeOptions;
14164
- };
14165
- _proto.createAnimations = function createAnimations(animations) {
14166
- return animations.map(function(anim) {
14167
- var tracks = anim.channels.map(function(channel) {
14168
- var track = {
14169
- input: channel.input.array,
14170
- output: channel.output.array,
14171
- node: channel.target.node,
14172
- path: channel.target.path,
14173
- interpolation: channel.interpolation
14174
- };
14175
- return track;
14176
- });
14177
- var newAnim = {
14178
- name: anim.name,
14179
- tracks: tracks
14180
- };
14181
- return newAnim;
14182
- });
14183
- };
14184
- _proto.createTexture2D = function createTexture2D(image, texture, isBaseColor) {
14185
- return WebGLHelper.createTexture2D(this.engine, image, texture, isBaseColor, this.isTiny3dMode());
14186
- };
14187
12720
  _proto.createSkyboxComponentData = function createSkyboxComponentData(typeName) {
14188
12721
  if (typeName !== "NFT" && typeName !== "FARM") {
14189
12722
  throw new Error("Invalid skybox type specified: '" + typeName + "'. Valid types are: 'NFT', 'FARM'.");
@@ -14191,28 +12724,7 @@ var LoaderECSImpl = /*#__PURE__*/ function() {
14191
12724
  //
14192
12725
  var typ = typeName === "NFT" ? PSkyboxType.NFT : PSkyboxType.FARM;
14193
12726
  var params = PSkyboxCreator.getSkyboxParams(typ);
14194
- return PSkyboxCreator.createSkyboxComponentData(this.engine, params);
14195
- };
14196
- _proto.scaleColorVal = function scaleColorVal(val, fromGLTF) {
14197
- return fromGLTF ? LoaderHelper.scaleTo255(val) : LoaderHelper.scaleTo1(val);
14198
- };
14199
- _proto.scaleColorVec = function scaleColorVec(vec, fromGLTF) {
14200
- var _this = this;
14201
- return vec.map(function(val) {
14202
- return _this.scaleColorVal(val, fromGLTF);
14203
- });
14204
- };
14205
- _proto.createLightOptions = function createLightOptions(light) {
14206
- return PluginHelper.createLightOptions(light);
14207
- };
14208
- _proto.createCameraOptions = function createCameraOptions(camera) {
14209
- var _PluginHelper_createCameraOptions;
14210
- return (_PluginHelper_createCameraOptions = PluginHelper.createCameraOptions(camera)) != null ? _PluginHelper_createCameraOptions : {
14211
- fov: 45,
14212
- far: 1000,
14213
- near: 0.01,
14214
- clipMode: spec.CameraClipMode.portrait
14215
- };
12727
+ return PSkyboxCreator.createSkyboxComponentData(params);
14216
12728
  };
14217
12729
  _proto.clear = function clear() {
14218
12730
  this.images = [];
@@ -14223,6 +12735,45 @@ var LoaderECSImpl = /*#__PURE__*/ function() {
14223
12735
  this.shaders = [];
14224
12736
  this.geometries = [];
14225
12737
  };
12738
+ _proto.computeSceneAABB = function computeSceneAABB() {
12739
+ var geometryDataMap = {};
12740
+ this.gltfMeshs.forEach(function(mesh) {
12741
+ var id = mesh.geometryData.id;
12742
+ geometryDataMap[id] = mesh;
12743
+ });
12744
+ var componentDataMap = {};
12745
+ this.components.forEach(function(component) {
12746
+ if (component.dataType === spec.DataType.MeshComponent) {
12747
+ var meshComponent = component;
12748
+ componentDataMap[component.id] = geometryDataMap[meshComponent.geometry.id];
12749
+ }
12750
+ });
12751
+ var sceneAABB = new Box3();
12752
+ var parentTransformMap = {};
12753
+ this.items.forEach(function(item) {
12754
+ var _item_parentId;
12755
+ var parentId = (_item_parentId = item.parentId) != null ? _item_parentId : "";
12756
+ var _parentTransformMap_parentId;
12757
+ var parentTransform = (_parentTransformMap_parentId = parentTransformMap[parentId]) != null ? _parentTransformMap_parentId : new Transform();
12758
+ var props = {};
12759
+ if (item.transform) {
12760
+ props.position = new Vector3().copyFrom(item.transform.position);
12761
+ props.rotation = Euler.fromVector3(item.transform.eulerHint);
12762
+ props.scale = new Vector3().copyFrom(item.transform.scale);
12763
+ }
12764
+ var transform = new Transform(props, parentTransform);
12765
+ parentTransformMap[item.id] = transform;
12766
+ item.components.forEach(function(component) {
12767
+ var mesh = componentDataMap[component.id];
12768
+ if (mesh && mesh.bounds) {
12769
+ var minPos = Vector3.fromArray(mesh.bounds.box.min);
12770
+ var maxPos = Vector3.fromArray(mesh.bounds.box.max);
12771
+ sceneAABB.union(new Box3(minPos, maxPos));
12772
+ }
12773
+ });
12774
+ });
12775
+ return sceneAABB;
12776
+ };
14226
12777
  /**
14227
12778
  * 按照传入的动画播放参数,计算需要播放的动画索引
14228
12779
  *
@@ -14312,19 +12863,8 @@ var LoaderECSImpl = /*#__PURE__*/ function() {
14312
12863
  return false;
14313
12864
  }
14314
12865
  };
14315
- return LoaderECSImpl;
12866
+ return LoaderImpl;
14316
12867
  }();
14317
- var globalLoader;
14318
- function getDefaultEffectsGLTFLoaderECS(engine, options) {
14319
- if (!globalLoader) {
14320
- globalLoader = new LoaderECSImpl();
14321
- }
14322
- globalLoader.initial(engine, options);
14323
- return globalLoader;
14324
- }
14325
- function setDefaultEffectsGLTFLoaderECS(loader) {
14326
- globalLoader = loader;
14327
- }
14328
12868
  function getPBRShaderProperties() {
14329
12869
  return '\n _BaseColorSampler ("基础贴图", 2D) = "" {}\n _BaseColorFactor ("基础颜色", Color) = (1, 1, 1, 1)\n _MetallicRoughnessSampler ("金属贴图", 2D) = "" {}\n _MetallicFactor ("金属度", Range(0, 1)) = 1\n _RoughnessFactor ("粗糙度", Range(0, 1)) = 1\n [Toggle] _SpecularAA ("高光抗锯齿", Float) = 0\n _NormalSampler ("法线贴图", 2D) = "" {}\n _NormalScale ("法线贴图强度", Range(0, 2)) = 1\n _OcclusionSampler ("AO贴图", 2D) = "" {}\n _OcclusionStrength ("AO贴图强度", Range(0, 1)) = 1\n _EmissiveSampler ("自发光贴图", 2D) = "" {}\n _EmissiveIntensity ("自发光贴图强度", Float) = 1\n _EmissiveFactor ("自发光颜色", Color) = (0, 0, 0, 1)\n _AlphaCutoff ("Alpha裁剪值", Range(0, 1)) = 0.5\n ';
14330
12870
  }
@@ -14410,11 +12950,11 @@ function getDefaultUnlitMaterialData() {
14410
12950
 
14411
12951
  registerPlugin("tree", ModelTreePlugin, VFXItem, true);
14412
12952
  registerPlugin("model", ModelPlugin, VFXItem);
14413
- var version = "2.0.0-alpha.20";
12953
+ var version = "2.0.0-alpha.21";
14414
12954
  logger.info("Plugin model version: " + version + ".");
14415
12955
  if (version !== EFFECTS.version) {
14416
12956
  console.error("注意:请统一 Model 插件与 Player 版本,不统一的版本混用会有不可预知的后果!", "\nAttention: Please ensure the Model plugin is synchronized with the Player version. Mixing and matching incompatible versions may result in unpredictable consequences!");
14417
12957
  }
14418
12958
 
14419
- export { AnimationComponent, Box3, BoxMesh, CameraGestureHandlerImp, CameraGestureType, CheckerHelper, Color, CompositionCache, CompositionHitTest, DEG2RAD, Euler, EulerOrder, FBOOptions, Float16ArrayWrapper, GeometryBoxProxy, HitTestingProxy, HookOGLFunc, InterpolationSampler, JSONConverter, LoaderECSImpl, LoaderHelper, LoaderImpl, Matrix3, Matrix4, MeshHelper, ModelCameraComponent, ModelLightComponent, ModelMeshComponent, ModelPlugin, ModelPluginComponent, ModelSkyboxComponent, ModelTreeComponent, ModelTreeItem, ModelTreePlugin, PAnimInterpType, PAnimPathType, PAnimTexture, PAnimTrack, PAnimation, PAnimationManager, PBRShaderGUID, PBlendMode, PCamera, PCameraManager, PCoordinate, PEntity, PFaceSideMode, PGeometry, PGlobalState, PLight, PLightManager, PLightType, PMaterialBase, PMaterialPBR, PMaterialSkyboxFilter, PMaterialType, PMaterialUnlit, PMesh, PMorph, PObject, PObjectType, PSceneManager, PShaderManager, PShadowType, PSkin, PSkybox, PSkyboxCreator, PSkyboxType, PSubMesh, PTextureType, PTransform, PluginHelper, Quaternion, Ray, RayBoxTesting, RayIntersectsBoxWithRotation, RayTriangleTesting, Sphere, TextureDataMode, ToggleItemBounding, TwoStatesSet, UnlitShaderGUID, VFX_ITEM_TYPE_3D, Vector2, Vector3, Vector4, VertexAttribBuffer, WebGLHelper, WebHelper, createAnimationSampler, createPluginMaterial, fetchPBRShaderCode, fetchUnlitShaderCode, getDefaultEffectsGLTFLoader, getDefaultEffectsGLTFLoaderECS, getDefaultPBRMaterialData, getDefaultUnlitMaterialData, getDiffuseOnlyShaderCode, getGaussianBlurShaderCodeV1, getGaussianBlurShaderCodeV2, getGeometryDataFromOptions, getGeometryDataFromPropsList, getKawaseBlurShaderCode, getNormalVisShaderCode, getPBRPassShaderCode, getPBRShaderProperties, getPMeshList, getQuadFilterShaderCode, getRendererGPUInfo, getSceneManager, getShadowPassShaderCode, getSimpleFilterShaderCode, getSkyBoxShaderCode, getTransparecyBaseShader, getTransparecyFilterShader, getUnlitShaderProperties, setDefaultEffectsGLTFLoader, setDefaultEffectsGLTFLoaderECS, version };
12959
+ export { AnimationComponent, Box3, BoxMesh, CameraGestureHandlerImp, CameraGestureType, CheckerHelper, Color, CompositionCache, CompositionHitTest, DEG2RAD, Euler, EulerOrder, FBOOptions, Float16ArrayWrapper, GeometryBoxProxy, HitTestingProxy, HookOGLFunc, InterpolationSampler, JSONConverter, LoaderHelper, LoaderImpl, Matrix3, Matrix4, MeshHelper, ModelCameraComponent, ModelLightComponent, ModelMeshComponent, ModelPlugin, ModelPluginComponent, ModelSkyboxComponent, ModelTreeComponent, ModelTreeItem, ModelTreePlugin, PAnimInterpType, PAnimPathType, PAnimTexture, PAnimTrack, PAnimation, PAnimationManager, PBRShaderGUID, PBlendMode, PCamera, PCameraManager, PCoordinate, PEntity, PFaceSideMode, PGeometry, PGlobalState, PLight, PLightManager, PLightType, PMaterialBase, PMaterialPBR, PMaterialSkyboxFilter, PMaterialType, PMaterialUnlit, PMesh, PMorph, PObject, PObjectType, PSceneManager, PShaderManager, PShadowType, PSkin, PSkybox, PSkyboxCreator, PSkyboxType, PSubMesh, PTextureType, PTransform, PluginHelper, Quaternion, Ray, RayBoxTesting, RayIntersectsBoxWithRotation, RayTriangleTesting, Sphere, TextureDataMode, ToggleItemBounding, TwoStatesSet, UnlitShaderGUID, VFX_ITEM_TYPE_3D, Vector2, Vector3, Vector4, VertexAttribBuffer, WebGLHelper, WebHelper, createAnimationSampler, createPluginMaterial, fetchPBRShaderCode, fetchUnlitShaderCode, getDefaultEffectsGLTFLoader, getDefaultPBRMaterialData, getDefaultUnlitMaterialData, getDiffuseOnlyShaderCode, getGaussianBlurShaderCodeV1, getGaussianBlurShaderCodeV2, getGeometryDataFromOptions, getGeometryDataFromPropsList, getKawaseBlurShaderCode, getNormalVisShaderCode, getPBRPassShaderCode, getPBRShaderProperties, getPMeshList, getQuadFilterShaderCode, getRendererGPUInfo, getSceneManager, getShadowPassShaderCode, getSimpleFilterShaderCode, getSkyBoxShaderCode, getTransparecyBaseShader, getTransparecyFilterShader, getUnlitShaderProperties, setDefaultEffectsGLTFLoader, version };
14420
12960
  //# sourceMappingURL=index.mjs.map