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