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

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/loader.mjs CHANGED
@@ -3,7 +3,7 @@
3
3
  * Description: Galacean Effects player model plugin
4
4
  * Author: Ant Group CO., Ltd.
5
5
  * Contributors: 飂兮
6
- * Version: v2.0.0-alpha.21
6
+ * Version: v2.0.0-alpha.23
7
7
  */
8
8
 
9
9
  import * as EFFECTS from '@galacean/effects';
@@ -4416,7 +4416,7 @@ var CameraGestureHandlerImp = /*#__PURE__*/ function() {
4416
4416
 
4417
4417
  registerPlugin("tree", ModelTreePlugin, VFXItem, true);
4418
4418
  registerPlugin("model", ModelPlugin, VFXItem);
4419
- var version = "2.0.0-alpha.21";
4419
+ var version = "2.0.0-alpha.23";
4420
4420
  logger.info("Plugin model version: " + version + ".");
4421
4421
  if (version !== EFFECTS.version) {
4422
4422
  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!");
@@ -11666,11 +11666,11 @@ var vertexBufferSemanticMap = {
11666
11666
  a_Target_Tangent3: "TANGENT_BS3"
11667
11667
  };
11668
11668
 
11669
- function getDefaultEffectsGLTFLoader(options) {
11669
+ function getDefaultEffectsGLTFLoader(engine, options) {
11670
11670
  if (!defaultGLTFLoader) {
11671
11671
  defaultGLTFLoader = new LoaderImpl();
11672
11672
  }
11673
- defaultGLTFLoader.initial(options);
11673
+ defaultGLTFLoader.initial(engine, options);
11674
11674
  return defaultGLTFLoader;
11675
11675
  }
11676
11676
  function setDefaultEffectsGLTFLoader(loader) {
@@ -11863,11 +11863,8 @@ var LoaderImpl = /*#__PURE__*/ function() {
11863
11863
  });
11864
11864
  if (texData) {
11865
11865
  var newId = generateGUID();
11866
- // @ts-expect-error
11867
- var newTexData = _extends({}, texData);
11868
- newTexData.textureOptions = _extends({}, texData.textureOptions, {
11869
- id: newId
11870
- });
11866
+ var newTexData = texData.clone();
11867
+ newTexData.textureOptions.id = newId;
11871
11868
  textures.push(newTexData);
11872
11869
  textureDataMap[newId] = newTexData.textureOptions;
11873
11870
  textureIdMap[baseColorId] = newId;
@@ -12131,7 +12128,8 @@ var LoaderImpl = /*#__PURE__*/ function() {
12131
12128
  options.premultiplyAlpha = premultiplyAlpha;
12132
12129
  options.generateMipmap = generateMipmap;
12133
12130
  };
12134
- _proto.initial = function initial(options) {
12131
+ _proto.initial = function initial(engine, options) {
12132
+ this.engine = engine;
12135
12133
  this.loaderOptions = options != null ? options : {};
12136
12134
  };
12137
12135
  _proto.checkMeshComponentData = function checkMeshComponentData(mesh, resource) {
@@ -12531,6 +12529,286 @@ var LoaderImpl = /*#__PURE__*/ function() {
12531
12529
  return false;
12532
12530
  }
12533
12531
  };
12532
+ /**
12533
+ * for old scene compatibility
12534
+ */ _proto.processLight = function processLight(lights, fromGLTF) {
12535
+ var _this = this;
12536
+ lights.forEach(function(l) {
12537
+ if (l.color === undefined) {
12538
+ if (fromGLTF) {
12539
+ l.color = [
12540
+ 255,
12541
+ 255,
12542
+ 255,
12543
+ 255
12544
+ ];
12545
+ } else {
12546
+ l.color = [
12547
+ 1,
12548
+ 1,
12549
+ 1,
12550
+ 1
12551
+ ];
12552
+ }
12553
+ } else {
12554
+ l.color[0] = _this.scaleColorVal(l.color[0], fromGLTF);
12555
+ l.color[1] = _this.scaleColorVal(l.color[1], fromGLTF);
12556
+ l.color[2] = _this.scaleColorVal(l.color[2], fromGLTF);
12557
+ l.color[3] = _this.scaleColorVal(l.color[3], fromGLTF);
12558
+ }
12559
+ });
12560
+ };
12561
+ _proto.processCamera = function processCamera(cameras, fromGLTF) {
12562
+ var scale = fromGLTF ? 180.0 / Math.PI : Math.PI / 180.0;
12563
+ cameras.forEach(function(camera) {
12564
+ if (camera.perspective !== undefined) {
12565
+ camera.perspective.yfov *= scale;
12566
+ }
12567
+ });
12568
+ };
12569
+ _proto.processMaterial = function processMaterial(materials, fromGLTF) {
12570
+ var _this = this;
12571
+ materials.forEach(function(mat) {
12572
+ if (mat.baseColorFactor === undefined) {
12573
+ if (fromGLTF) {
12574
+ mat.baseColorFactor = [
12575
+ 255,
12576
+ 255,
12577
+ 255,
12578
+ 255
12579
+ ];
12580
+ } else {
12581
+ mat.baseColorFactor = [
12582
+ 1,
12583
+ 1,
12584
+ 1,
12585
+ 1
12586
+ ];
12587
+ }
12588
+ } else {
12589
+ mat.baseColorFactor[0] = _this.scaleColorVal(mat.baseColorFactor[0], fromGLTF);
12590
+ mat.baseColorFactor[1] = _this.scaleColorVal(mat.baseColorFactor[1], fromGLTF);
12591
+ mat.baseColorFactor[2] = _this.scaleColorVal(mat.baseColorFactor[2], fromGLTF);
12592
+ mat.baseColorFactor[3] = _this.scaleColorVal(mat.baseColorFactor[3], fromGLTF);
12593
+ }
12594
+ if (mat.emissiveFactor === undefined) {
12595
+ if (fromGLTF) {
12596
+ mat.emissiveFactor = [
12597
+ 255,
12598
+ 255,
12599
+ 255,
12600
+ 255
12601
+ ];
12602
+ } else {
12603
+ mat.emissiveFactor = [
12604
+ 1,
12605
+ 1,
12606
+ 1,
12607
+ 1
12608
+ ];
12609
+ }
12610
+ } else {
12611
+ mat.emissiveFactor[0] = _this.scaleColorVal(mat.emissiveFactor[0], fromGLTF);
12612
+ mat.emissiveFactor[1] = _this.scaleColorVal(mat.emissiveFactor[1], fromGLTF);
12613
+ mat.emissiveFactor[2] = _this.scaleColorVal(mat.emissiveFactor[2], fromGLTF);
12614
+ mat.emissiveFactor[3] = _this.scaleColorVal(mat.emissiveFactor[3], fromGLTF);
12615
+ }
12616
+ if (fromGLTF && mat.occlusionTexture !== undefined && mat.occlusionTexture.strength === undefined) {
12617
+ mat.occlusionTexture.strength = _this.isTiny3dMode() ? 0 : 1;
12618
+ }
12619
+ });
12620
+ };
12621
+ _proto.createTreeOptions = function createTreeOptions(scene) {
12622
+ var nodeList = scene.nodes.map(function(node, nodeIndex) {
12623
+ var children = node.children.map(function(child) {
12624
+ if (child.nodeIndex === undefined) {
12625
+ throw new Error("Undefined nodeIndex for child " + child);
12626
+ }
12627
+ return child.nodeIndex;
12628
+ });
12629
+ var pos;
12630
+ var quat;
12631
+ var scale;
12632
+ if (node.matrix !== undefined) {
12633
+ if (node.matrix.length !== 16) {
12634
+ throw new Error("Invalid matrix length " + node.matrix.length + " for node " + node);
12635
+ }
12636
+ var mat = Matrix4.fromArray(node.matrix);
12637
+ var transform = mat.getTransform();
12638
+ pos = transform.translation.toArray();
12639
+ quat = transform.rotation.toArray();
12640
+ scale = transform.scale.toArray();
12641
+ } else {
12642
+ if (node.translation !== undefined) {
12643
+ pos = node.translation;
12644
+ }
12645
+ if (node.rotation !== undefined) {
12646
+ quat = node.rotation;
12647
+ }
12648
+ if (node.scale !== undefined) {
12649
+ scale = node.scale;
12650
+ }
12651
+ }
12652
+ node.nodeIndex = nodeIndex;
12653
+ var treeNode = {
12654
+ name: node.name,
12655
+ transform: {
12656
+ position: pos,
12657
+ quat: quat,
12658
+ scale: scale
12659
+ },
12660
+ children: children,
12661
+ id: "" + node.nodeIndex
12662
+ };
12663
+ return treeNode;
12664
+ });
12665
+ var rootNodes = scene.rootNodes.map(function(root) {
12666
+ if (root.nodeIndex === undefined) {
12667
+ throw new Error("Undefined nodeIndex for root " + root);
12668
+ }
12669
+ return root.nodeIndex;
12670
+ });
12671
+ var treeOptions = {
12672
+ nodes: nodeList,
12673
+ children: rootNodes,
12674
+ animation: -1,
12675
+ animations: []
12676
+ };
12677
+ return treeOptions;
12678
+ };
12679
+ _proto.createAnimations = function createAnimations(animations) {
12680
+ return animations.map(function(anim) {
12681
+ var tracks = anim.channels.map(function(channel) {
12682
+ var track = {
12683
+ input: channel.input.array,
12684
+ output: channel.output.array,
12685
+ node: channel.target.node,
12686
+ path: channel.target.path,
12687
+ interpolation: channel.interpolation
12688
+ };
12689
+ return track;
12690
+ });
12691
+ var newAnim = {
12692
+ name: anim.name,
12693
+ tracks: tracks
12694
+ };
12695
+ return newAnim;
12696
+ });
12697
+ };
12698
+ _proto.createGeometry = function createGeometry(primitive, hasSkinAnim) {
12699
+ var proxy = new GeometryProxy(this.engine, primitive, hasSkinAnim);
12700
+ return proxy.geometry;
12701
+ };
12702
+ _proto.createMaterial = function createMaterial(material) {
12703
+ var proxy = new MaterialProxy(material, [], this.isTiny3dMode());
12704
+ return proxy.material;
12705
+ };
12706
+ _proto.createTexture2D = function createTexture2D(image, texture, isBaseColor) {
12707
+ return WebGLHelper.createTexture2D(this.engine, image, texture, isBaseColor, this.isTiny3dMode());
12708
+ };
12709
+ _proto.createTextureCube = function createTextureCube(cubeImages, level0Size) {
12710
+ var _this = this;
12711
+ if (cubeImages.length == 0) {
12712
+ throw new Error("createTextureCube: Invalid cubeImages length " + cubeImages);
12713
+ }
12714
+ var mipmaps = [];
12715
+ cubeImages.forEach(function(cubeImage) {
12716
+ if (cubeImage.length != 6) {
12717
+ throw new Error("createTextureCube: cubeimage count should always be 6, " + cubeImage);
12718
+ }
12719
+ //
12720
+ var imgList = [];
12721
+ cubeImage.forEach(function(img) {
12722
+ if (img.imageData === undefined) {
12723
+ throw new Error("createTextureCube: Invalid image data from " + img);
12724
+ }
12725
+ //
12726
+ imgList.push({
12727
+ type: "buffer",
12728
+ data: img.imageData,
12729
+ mimeType: img.mimeType
12730
+ });
12731
+ });
12732
+ if (_this.isTiny3dMode()) {
12733
+ var ref;
12734
+ ref = [
12735
+ imgList[5],
12736
+ imgList[4]
12737
+ ], imgList[4] = ref[0], imgList[5] = ref[1];
12738
+ }
12739
+ mipmaps.push(imgList);
12740
+ });
12741
+ //
12742
+ if (mipmaps.length == 1) {
12743
+ // no mipmaps
12744
+ return WebGLHelper.createTextureCubeFromBuffer(this.engine, mipmaps[0]);
12745
+ } else {
12746
+ // has mipmaps
12747
+ return WebGLHelper.createTextureCubeMipmapFromBuffer(this.engine, mipmaps, level0Size != null ? level0Size : Math.pow(2, mipmaps.length - 1));
12748
+ }
12749
+ };
12750
+ _proto.createSkybox = function createSkybox(ibl) {
12751
+ var _this = this;
12752
+ var _ibl_reflectionsIntensity;
12753
+ var reflectionsIntensity = (_ibl_reflectionsIntensity = ibl.reflectionsIntensity) != null ? _ibl_reflectionsIntensity : ibl.intensity;
12754
+ var irradianceCoeffs = ibl.irradianceCoefficients;
12755
+ var inSpecularImages = ibl.specularImages;
12756
+ var specularImages = inSpecularImages.map(function(images) {
12757
+ var newImages = images.map(function(img) {
12758
+ var outImg = {
12759
+ type: "buffer",
12760
+ data: img.imageData,
12761
+ mimeType: img.mimeType
12762
+ };
12763
+ return outImg;
12764
+ });
12765
+ if (_this.isTiny3dMode()) {
12766
+ var ref;
12767
+ ref = [
12768
+ newImages[5],
12769
+ newImages[4]
12770
+ ], newImages[4] = ref[0], newImages[5] = ref[1];
12771
+ }
12772
+ return newImages;
12773
+ });
12774
+ var specularMipCount = specularImages.length - 1;
12775
+ var _ibl_specularImageSize;
12776
+ var specularImageSize = (_ibl_specularImageSize = ibl.specularImageSize) != null ? _ibl_specularImageSize : Math.pow(2, specularMipCount);
12777
+ var newIrradianceCoeffs = [];
12778
+ irradianceCoeffs.forEach(function(coeffs) {
12779
+ var _newIrradianceCoeffs;
12780
+ (_newIrradianceCoeffs = newIrradianceCoeffs).push.apply(_newIrradianceCoeffs, [].concat(coeffs));
12781
+ });
12782
+ var params = {
12783
+ type: "buffer",
12784
+ renderable: this.isSkyboxVis(),
12785
+ intensity: ibl.intensity,
12786
+ reflectionsIntensity: reflectionsIntensity,
12787
+ irradianceCoeffs: newIrradianceCoeffs,
12788
+ specularImage: specularImages,
12789
+ specularMipCount: specularMipCount,
12790
+ specularImageSize: specularImageSize
12791
+ };
12792
+ return PSkyboxCreator.createSkyboxOptions(this.engine, params);
12793
+ };
12794
+ _proto.createDefaultSkybox = function createDefaultSkybox(typeName) {
12795
+ if (typeName !== "NFT" && typeName !== "FARM") {
12796
+ throw new Error("Invalid skybox type name " + typeName);
12797
+ }
12798
+ //
12799
+ var typ = typeName === "NFT" ? PSkyboxType.NFT : PSkyboxType.FARM;
12800
+ var params = PSkyboxCreator.getSkyboxParams(typ);
12801
+ return PSkyboxCreator.createSkyboxOptions(this.engine, params);
12802
+ };
12803
+ _proto.scaleColorVal = function scaleColorVal(val, fromGLTF) {
12804
+ return fromGLTF ? LoaderHelper.scaleTo255(val) : LoaderHelper.scaleTo1(val);
12805
+ };
12806
+ _proto.scaleColorVec = function scaleColorVec(vec, fromGLTF) {
12807
+ var _this = this;
12808
+ return vec.map(function(val) {
12809
+ return _this.scaleColorVal(val, fromGLTF);
12810
+ });
12811
+ };
12534
12812
  return LoaderImpl;
12535
12813
  }();
12536
12814
  function getPBRShaderProperties() {
@@ -12615,6 +12893,537 @@ function getDefaultUnlitMaterialData() {
12615
12893
  };
12616
12894
  return material;
12617
12895
  }
12896
+ var GeometryProxy = /*#__PURE__*/ function() {
12897
+ function GeometryProxy(engine, gltfGeometry, hasSkinAnimation) {
12898
+ this.engine = engine;
12899
+ this.gltfGeometry = gltfGeometry;
12900
+ this.hasSkinAnimation = hasSkinAnimation;
12901
+ }
12902
+ var _proto = GeometryProxy.prototype;
12903
+ _proto._getBufferAttrib = function _getBufferAttrib(inAttrib) {
12904
+ var attrib = {
12905
+ type: inAttrib.type,
12906
+ size: inAttrib.itemSize,
12907
+ //stride: inAttrib.stride,
12908
+ //offset: inAttrib.offset,
12909
+ data: inAttrib.array,
12910
+ normalize: inAttrib.normalized
12911
+ };
12912
+ return attrib;
12913
+ };
12914
+ _proto.texCoordAttrib = function texCoordAttrib(index) {
12915
+ return this.gltfGeometry.getTexCoord(index);
12916
+ };
12917
+ _proto.getTargetPosition = function getTargetPosition(index) {
12918
+ return this.gltfGeometry.getAttribute("POSITION" + index);
12919
+ };
12920
+ _proto.getTargetNormal = function getTargetNormal(index) {
12921
+ return this.gltfGeometry.getAttribute("NORMAL" + index);
12922
+ };
12923
+ _proto.getTargetTangent = function getTargetTangent(index) {
12924
+ return this.gltfGeometry.getAttribute("TANGENT" + index);
12925
+ };
12926
+ _create_class(GeometryProxy, [
12927
+ {
12928
+ key: "geometry",
12929
+ get: function get() {
12930
+ var _this = this;
12931
+ var attributes = {};
12932
+ if (this.hasPosition) {
12933
+ var attrib = this.positionAttrib;
12934
+ attributes["a_Position"] = this._getBufferAttrib(attrib);
12935
+ } else {
12936
+ throw new Error("Position attribute missing");
12937
+ }
12938
+ if (this.hasNormal) {
12939
+ var attrib1 = this.normalAttrib;
12940
+ if (attrib1 !== undefined) {
12941
+ attributes["a_Normal"] = this._getBufferAttrib(attrib1);
12942
+ }
12943
+ }
12944
+ if (this.hasTangent) {
12945
+ var attrib2 = this.tangentAttrib;
12946
+ if (attrib2 !== undefined) {
12947
+ attributes["a_Tangent"] = this._getBufferAttrib(attrib2);
12948
+ }
12949
+ }
12950
+ this.texCoordList.forEach(function(val) {
12951
+ var attrib = _this.texCoordAttrib(val);
12952
+ var attribName = "a_UV" + (val + 1);
12953
+ attributes[attribName] = _this._getBufferAttrib(attrib);
12954
+ });
12955
+ if (this.hasSkinAnimation) {
12956
+ var jointAttrib = this.jointAttribute;
12957
+ if (jointAttrib !== undefined) {
12958
+ attributes["a_Joint1"] = this._getBufferAttrib(jointAttrib);
12959
+ }
12960
+ var weightAttrib = this.weightAttribute;
12961
+ if (weightAttrib !== undefined) {
12962
+ attributes["a_Weight1"] = this._getBufferAttrib(weightAttrib);
12963
+ }
12964
+ }
12965
+ /**
12966
+ * 设置Morph动画需要的Attribute,主要包括Position,Normal和Tangent
12967
+ */ for(var i = 0; i < 8; i++){
12968
+ var positionAttrib = this.getTargetPosition(i);
12969
+ if (positionAttrib !== undefined) {
12970
+ attributes["a_Target_Position" + i] = this._getBufferAttrib(positionAttrib);
12971
+ }
12972
+ var normalAttrib = this.getTargetNormal(i);
12973
+ if (normalAttrib !== undefined) {
12974
+ attributes["a_Target_Normal" + i] = this._getBufferAttrib(normalAttrib);
12975
+ }
12976
+ var tangentAttrib = this.getTargetTangent(i);
12977
+ if (tangentAttrib !== undefined) {
12978
+ attributes["a_Target_Tangent" + i] = this._getBufferAttrib(tangentAttrib);
12979
+ }
12980
+ }
12981
+ var indexArray = this.indexArray;
12982
+ if (indexArray !== undefined) {
12983
+ return Geometry.create(this.engine, {
12984
+ attributes: attributes,
12985
+ indices: {
12986
+ data: indexArray
12987
+ },
12988
+ drawStart: 0,
12989
+ drawCount: indexArray.length,
12990
+ mode: glContext.TRIANGLES
12991
+ });
12992
+ } else {
12993
+ return Geometry.create(this.engine, {
12994
+ attributes: attributes,
12995
+ drawStart: 0,
12996
+ drawCount: this.positionAttrib.array.length / 3,
12997
+ mode: glContext.TRIANGLES
12998
+ });
12999
+ }
13000
+ }
13001
+ },
13002
+ {
13003
+ key: "positionAttrib",
13004
+ get: function get() {
13005
+ return this.gltfGeometry.getPosition();
13006
+ }
13007
+ },
13008
+ {
13009
+ key: "normalAttrib",
13010
+ get: function get() {
13011
+ return this.gltfGeometry.getNormal();
13012
+ }
13013
+ },
13014
+ {
13015
+ key: "tangentAttrib",
13016
+ get: function get() {
13017
+ return this.gltfGeometry.getTangent();
13018
+ }
13019
+ },
13020
+ {
13021
+ key: "jointAttribute",
13022
+ get: function get() {
13023
+ return this.gltfGeometry.getJoints(0);
13024
+ }
13025
+ },
13026
+ {
13027
+ key: "weightAttribute",
13028
+ get: function get() {
13029
+ return this.gltfGeometry.getWeights(0);
13030
+ }
13031
+ },
13032
+ {
13033
+ key: "hasPosition",
13034
+ get: function get() {
13035
+ return this.positionAttrib !== undefined;
13036
+ }
13037
+ },
13038
+ {
13039
+ key: "hasNormal",
13040
+ get: function get() {
13041
+ return this.normalAttrib !== undefined;
13042
+ }
13043
+ },
13044
+ {
13045
+ key: "hasTangent",
13046
+ get: function get() {
13047
+ return this.tangentAttrib !== undefined;
13048
+ }
13049
+ },
13050
+ {
13051
+ key: "hasTexCoord",
13052
+ get: function get() {
13053
+ return this.texCoordCount > 0;
13054
+ }
13055
+ },
13056
+ {
13057
+ key: "texCoordCount",
13058
+ get: function get() {
13059
+ for(var i = 0; i < 10; i++){
13060
+ if (this.texCoordAttrib(i) === undefined) {
13061
+ return i;
13062
+ }
13063
+ }
13064
+ return 0;
13065
+ }
13066
+ },
13067
+ {
13068
+ key: "hasJointAttribute",
13069
+ get: function get() {
13070
+ return this.jointAttribute !== undefined;
13071
+ }
13072
+ },
13073
+ {
13074
+ key: "hasWeightAttribute",
13075
+ get: function get() {
13076
+ return this.weightAttribute !== undefined;
13077
+ }
13078
+ },
13079
+ {
13080
+ key: "indexArray",
13081
+ get: function get() {
13082
+ if (this.gltfGeometry.indices === undefined) {
13083
+ return undefined;
13084
+ }
13085
+ switch(this.gltfGeometry.indices.type){
13086
+ case WebGLRenderingContext["UNSIGNED_INT"]:
13087
+ return this.gltfGeometry.indices.array;
13088
+ case WebGLRenderingContext["UNSIGNED_SHORT"]:
13089
+ return this.gltfGeometry.indices.array;
13090
+ case WebGLRenderingContext["UNSIGNED_BYTE"]:
13091
+ return this.gltfGeometry.indices.array;
13092
+ }
13093
+ return undefined;
13094
+ }
13095
+ },
13096
+ {
13097
+ key: "indexCount",
13098
+ get: function get() {
13099
+ if (this.gltfGeometry.indices !== undefined) {
13100
+ return this.gltfGeometry.indices.array.length;
13101
+ } else {
13102
+ return 0;
13103
+ }
13104
+ }
13105
+ },
13106
+ {
13107
+ key: "texCoordList",
13108
+ get: function get() {
13109
+ var texCoords = [];
13110
+ for(var i = 0; i < 10; i++){
13111
+ if (this.texCoordAttrib(i) !== undefined) {
13112
+ texCoords.push(i);
13113
+ } else {
13114
+ break;
13115
+ }
13116
+ }
13117
+ return texCoords;
13118
+ }
13119
+ }
13120
+ ]);
13121
+ return GeometryProxy;
13122
+ }();
13123
+ var MaterialProxy = /*#__PURE__*/ function() {
13124
+ function MaterialProxy(material, textures, tiny3dMode) {
13125
+ this.gltfMaterial = material;
13126
+ this.textures = textures;
13127
+ this.tiny3dMode = tiny3dMode;
13128
+ }
13129
+ var _proto = MaterialProxy.prototype;
13130
+ _proto.getTextureObject = function getTextureObject(index) {
13131
+ if (index < 0 || index >= this.textures.length) {
13132
+ return;
13133
+ }
13134
+ return this.textures[index];
13135
+ };
13136
+ _proto.getTextureObj = function getTextureObj(texInfo) {
13137
+ return texInfo ? this.getTextureObject(texInfo.index) : undefined;
13138
+ };
13139
+ _proto.getTextureCoord = function getTextureCoord(texInfo) {
13140
+ return texInfo ? texInfo.texCoord : undefined;
13141
+ };
13142
+ _proto.getTextureTransform = function getTextureTransform(texInfo) {
13143
+ var _texInfo_extensions;
13144
+ var transform = texInfo == null ? void 0 : (_texInfo_extensions = texInfo.extensions) == null ? void 0 : _texInfo_extensions.KHR_texture_transform;
13145
+ if (transform === undefined) {
13146
+ return;
13147
+ }
13148
+ if (transform.offset === undefined && transform.rotation === undefined && transform.scale === undefined) {
13149
+ return;
13150
+ }
13151
+ return {
13152
+ offset: transform.offset,
13153
+ rotation: transform.rotation,
13154
+ scale: transform.scale
13155
+ };
13156
+ };
13157
+ _proto.getSpecularAA = function getSpecularAA() {
13158
+ var _this_gltfMaterial_extras;
13159
+ return (_this_gltfMaterial_extras = this.gltfMaterial.extras) == null ? void 0 : _this_gltfMaterial_extras.useSpecularAA;
13160
+ };
13161
+ _create_class(MaterialProxy, [
13162
+ {
13163
+ key: "material",
13164
+ get: function get() {
13165
+ var mat = this.gltfMaterial;
13166
+ var isUnlit = GLTFHelper.isUnlitMaterial(mat);
13167
+ var blending = spec.MaterialBlending.opaque;
13168
+ switch(mat.alphaMode){
13169
+ case "OPAQUE":
13170
+ blending = spec.MaterialBlending.opaque;
13171
+ break;
13172
+ case "MASK":
13173
+ blending = spec.MaterialBlending.masked;
13174
+ break;
13175
+ case "BLEND":
13176
+ blending = spec.MaterialBlending.translucent;
13177
+ break;
13178
+ }
13179
+ var side = mat.doubleSided ? spec.SideMode.DOUBLE : spec.SideMode.FRONT;
13180
+ var enableShadow = false;
13181
+ var _mat_alphaCutOff;
13182
+ var alphaCutOff = (_mat_alphaCutOff = mat.alphaCutOff) != null ? _mat_alphaCutOff : 0.5;
13183
+ var name = mat.name;
13184
+ if (isUnlit) {
13185
+ var _mat_extras;
13186
+ return {
13187
+ name: name,
13188
+ type: spec.MaterialType.unlit,
13189
+ baseColorTexture: this.baseColorTextureObj,
13190
+ baseColorTextureCoordinate: this.baseColorTextureCoord,
13191
+ baseColorTextureTransform: this.baseColorTextureTransfrom,
13192
+ baseColorFactor: this.baseColorFactor,
13193
+ //
13194
+ depthMask: (_mat_extras = mat.extras) == null ? void 0 : _mat_extras.depthMask,
13195
+ blending: blending,
13196
+ alphaCutOff: alphaCutOff,
13197
+ side: side
13198
+ };
13199
+ } else {
13200
+ var _mat_extras1;
13201
+ return {
13202
+ name: name,
13203
+ type: spec.MaterialType.pbr,
13204
+ baseColorTexture: this.baseColorTextureObj,
13205
+ baseColorTextureCoordinate: this.baseColorTextureCoord,
13206
+ baseColorTextureTransform: this.baseColorTextureTransfrom,
13207
+ baseColorFactor: this.baseColorFactor,
13208
+ //
13209
+ useSpecularAA: this.getSpecularAA(),
13210
+ //
13211
+ metallicRoughnessTexture: this.metallicRoughnessTextureObj,
13212
+ metallicRoughnessTextureCoordinate: this.metallicRoughnessTextureCoord,
13213
+ metallicRoughnessTextureTransform: this.metallicRoughnessTextureTransfrom,
13214
+ metallicFactor: this.metalicFactor,
13215
+ roughnessFactor: this.roughnessFactor,
13216
+ //
13217
+ normalTexture: this.normalTextureObj,
13218
+ normalTextureCoordinate: this.normalTextureCoord,
13219
+ normalTextureTransform: this.normalTextureTransfrom,
13220
+ normalTextureScale: this.normalTextureScale,
13221
+ //
13222
+ occlusionTexture: this.occlusionTextureObj,
13223
+ occlusionTextureCoordinate: this.occlusionTextureCoord,
13224
+ occlusionTextureTransform: this.occlusionTextureTransfrom,
13225
+ occlusionTextureStrength: this.occlusionTextureStrength,
13226
+ //
13227
+ emissiveTexture: this.emissiveTextureObj,
13228
+ emissiveTextureCoordinate: this.emissiveTextureCoord,
13229
+ emissiveTextureTransform: this.emissiveTextureTransfrom,
13230
+ emissiveFactor: this.emissiveFactor,
13231
+ emissiveIntensity: 1.0,
13232
+ //
13233
+ depthMask: (_mat_extras1 = mat.extras) == null ? void 0 : _mat_extras1.depthMask,
13234
+ blending: blending,
13235
+ alphaCutOff: alphaCutOff,
13236
+ side: side,
13237
+ enableShadow: enableShadow
13238
+ };
13239
+ }
13240
+ }
13241
+ },
13242
+ {
13243
+ key: "baseColorTextureObj",
13244
+ get: function get() {
13245
+ return this.getTextureObj(this.gltfMaterial.baseColorTexture);
13246
+ }
13247
+ },
13248
+ {
13249
+ key: "baseColorTextureCoord",
13250
+ get: function get() {
13251
+ return this.getTextureCoord(this.gltfMaterial.baseColorTexture);
13252
+ }
13253
+ },
13254
+ {
13255
+ key: "baseColorTextureTransfrom",
13256
+ get: function get() {
13257
+ return this.getTextureTransform(this.gltfMaterial.baseColorTexture);
13258
+ }
13259
+ },
13260
+ {
13261
+ key: "metallicRoughnessTextureObj",
13262
+ get: function get() {
13263
+ return this.getTextureObj(this.gltfMaterial.metallicRoughnessTexture);
13264
+ }
13265
+ },
13266
+ {
13267
+ key: "metallicRoughnessTextureCoord",
13268
+ get: function get() {
13269
+ return this.getTextureCoord(this.gltfMaterial.metallicRoughnessTexture);
13270
+ }
13271
+ },
13272
+ {
13273
+ key: "metallicRoughnessTextureTransfrom",
13274
+ get: function get() {
13275
+ return this.getTextureTransform(this.gltfMaterial.metallicRoughnessTexture);
13276
+ }
13277
+ },
13278
+ {
13279
+ key: "normalTextureObj",
13280
+ get: function get() {
13281
+ return this.getTextureObj(this.gltfMaterial.normalTexture);
13282
+ }
13283
+ },
13284
+ {
13285
+ key: "normalTextureCoord",
13286
+ get: function get() {
13287
+ return this.getTextureCoord(this.gltfMaterial.normalTexture);
13288
+ }
13289
+ },
13290
+ {
13291
+ key: "normalTextureTransfrom",
13292
+ get: function get() {
13293
+ return this.getTextureTransform(this.gltfMaterial.normalTexture);
13294
+ }
13295
+ },
13296
+ {
13297
+ key: "occlusionTextureObj",
13298
+ get: function get() {
13299
+ return this.getTextureObj(this.gltfMaterial.occlusionTexture);
13300
+ }
13301
+ },
13302
+ {
13303
+ key: "occlusionTextureCoord",
13304
+ get: function get() {
13305
+ return this.getTextureCoord(this.gltfMaterial.occlusionTexture);
13306
+ }
13307
+ },
13308
+ {
13309
+ key: "occlusionTextureTransfrom",
13310
+ get: function get() {
13311
+ return this.getTextureTransform(this.gltfMaterial.occlusionTexture);
13312
+ }
13313
+ },
13314
+ {
13315
+ key: "emissiveTextureObj",
13316
+ get: function get() {
13317
+ return this.getTextureObj(this.gltfMaterial.emissiveTexture);
13318
+ }
13319
+ },
13320
+ {
13321
+ key: "emissiveTextureCoord",
13322
+ get: function get() {
13323
+ return this.getTextureCoord(this.gltfMaterial.emissiveTexture);
13324
+ }
13325
+ },
13326
+ {
13327
+ key: "emissiveTextureTransfrom",
13328
+ get: function get() {
13329
+ return this.getTextureTransform(this.gltfMaterial.emissiveTexture);
13330
+ }
13331
+ },
13332
+ {
13333
+ key: "hasEmissive",
13334
+ get: function get() {
13335
+ var factor = this.emissiveFactor;
13336
+ return factor[0] + factor[1] + factor[2] > 0;
13337
+ }
13338
+ },
13339
+ {
13340
+ key: "baseColorFactor",
13341
+ get: function get() {
13342
+ var f = this.gltfMaterial.baseColorFactor;
13343
+ if (f === undefined || f.length != 4) {
13344
+ return [
13345
+ 1,
13346
+ 1,
13347
+ 1,
13348
+ 1
13349
+ ];
13350
+ } else {
13351
+ return [
13352
+ f[0],
13353
+ f[1],
13354
+ f[2],
13355
+ f[3]
13356
+ ];
13357
+ }
13358
+ }
13359
+ },
13360
+ {
13361
+ key: "metalicFactor",
13362
+ get: function get() {
13363
+ var _this_gltfMaterial_metallicFactor;
13364
+ return (_this_gltfMaterial_metallicFactor = this.gltfMaterial.metallicFactor) != null ? _this_gltfMaterial_metallicFactor : 1;
13365
+ }
13366
+ },
13367
+ {
13368
+ key: "roughnessFactor",
13369
+ get: function get() {
13370
+ var _this_gltfMaterial_roughnessFactor;
13371
+ return (_this_gltfMaterial_roughnessFactor = this.gltfMaterial.roughnessFactor) != null ? _this_gltfMaterial_roughnessFactor : 1;
13372
+ }
13373
+ },
13374
+ {
13375
+ key: "normalTextureScale",
13376
+ get: function get() {
13377
+ var _this_gltfMaterial_normalTexture;
13378
+ var _this_gltfMaterial_normalTexture_scale;
13379
+ return (_this_gltfMaterial_normalTexture_scale = (_this_gltfMaterial_normalTexture = this.gltfMaterial.normalTexture) == null ? void 0 : _this_gltfMaterial_normalTexture.scale) != null ? _this_gltfMaterial_normalTexture_scale : 1;
13380
+ }
13381
+ },
13382
+ {
13383
+ key: "occlusionTextureStrength",
13384
+ get: function get() {
13385
+ var _this_gltfMaterial_occlusionTexture;
13386
+ var _this_gltfMaterial_occlusionTexture_strength;
13387
+ return (_this_gltfMaterial_occlusionTexture_strength = (_this_gltfMaterial_occlusionTexture = this.gltfMaterial.occlusionTexture) == null ? void 0 : _this_gltfMaterial_occlusionTexture.strength) != null ? _this_gltfMaterial_occlusionTexture_strength : 1;
13388
+ }
13389
+ },
13390
+ {
13391
+ key: "emissiveFactor",
13392
+ get: function get() {
13393
+ var f = this.gltfMaterial.emissiveFactor;
13394
+ if (f === undefined || f.length != 4) {
13395
+ return [
13396
+ 0,
13397
+ 0,
13398
+ 0,
13399
+ 1
13400
+ ];
13401
+ } else {
13402
+ return [
13403
+ f[0],
13404
+ f[1],
13405
+ f[2],
13406
+ 1.0
13407
+ ];
13408
+ }
13409
+ }
13410
+ }
13411
+ ]);
13412
+ return MaterialProxy;
13413
+ }();
13414
+ var GLTFHelper = /*#__PURE__*/ function() {
13415
+ function GLTFHelper() {}
13416
+ GLTFHelper.isUnlitMaterial = function isUnlitMaterial(mat) {
13417
+ var _mat_extensions;
13418
+ return ((_mat_extensions = mat.extensions) == null ? void 0 : _mat_extensions.KHR_materials_unlit) !== undefined;
13419
+ };
13420
+ GLTFHelper.createBoxFromGLTFBound = function createBoxFromGLTFBound(bound) {
13421
+ var boxMin = Vector3.fromArray(bound.box.min);
13422
+ var boxMax = Vector3.fromArray(bound.box.max);
13423
+ return new Box3(boxMin, boxMax);
13424
+ };
13425
+ return GLTFHelper;
13426
+ }();
12618
13427
 
12619
13428
  export { CameraGestureHandlerImp, CameraGestureType, JSONConverter, LoaderHelper, LoaderImpl, getDefaultEffectsGLTFLoader, getDefaultPBRMaterialData, getDefaultUnlitMaterialData, getGeometryDataFromOptions, getGeometryDataFromPropsList, getPBRShaderProperties, getUnlitShaderProperties, setDefaultEffectsGLTFLoader };
12620
13429
  //# sourceMappingURL=loader.mjs.map