Skip to content

Commit 99da3bb

Browse files
vladimir-tikhonovvladimir.tikhonov
andauthored
Add ability to set useAlphaFromDiffuseTexture from UI (#1141)
Co-authored-by: vladimir.tikhonov <vtikhonov@evolution.com>
1 parent ed830af commit 99da3bb

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

3ds Max/Max2Babylon/Exporter/BabylonExporter.Material.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ public class BabylonCustomAttributeDecorator : MaterialDecorator
123123
public const string EnvironmentIntensityStr = "babylonEnvironmentIntensity";
124124
public const string SpecularIntensityStr = "babylonSpecularIntensity";
125125
public const string TransparencyModeStr = "babylonTransparencyMode";
126+
public const string UseAlphaFromDiffuseTextureStr = "babylonUseAlphaFromDiffuseTexture";
126127

127128
public static IEnumerable<string> ListPrivatePropertyNames()
128129
{
@@ -135,6 +136,7 @@ public static IEnumerable<string> ListPrivatePropertyNames()
135136
yield return EnvironmentIntensityStr;
136137
yield return SpecularIntensityStr;
137138
yield return TransparencyModeStr;
139+
yield return UseAlphaFromDiffuseTextureStr;
138140
}
139141

140142
public BabylonCustomAttributeDecorator(IIGameMaterial node) : base(node)
@@ -151,6 +153,7 @@ public BabylonCustomAttributeDecorator(IIGameMaterial node) : base(node)
151153
public float EnvironementIntensity => Properties?.GetFloatProperty(EnvironmentIntensityStr, 1.0f) ?? 1.0f;
152154
public float SpecularIntensity => Properties?.GetFloatProperty(SpecularIntensityStr, 1.0f) ?? 1.0f;
153155
public int TransparencyMode => Properties?.GetIntProperty(TransparencyModeStr, 0) ?? 0;
156+
public bool UseAlphaFromDiffuseTexture => Properties?.GetBoolProperty(UseAlphaFromDiffuseTextureStr, false) ?? false;
154157
}
155158

156159
/// <summary>
@@ -337,6 +340,7 @@ private void ExportMaterial(IIGameMaterial materialNode, BabylonScene babylonSce
337340
private void ExportStandardMaterial(IIGameMaterial materialNode, IIPropertyContainer attributesContainer, IStdMat2 stdMat, BabylonScene babylonScene, BabylonStandardMaterial babylonMaterial)
338341
{
339342
bool isTransparencyModeFromBabylonAttributes = false;
343+
bool useAlphaFromDiffuseTexture = false;
340344
if (attributesContainer != null)
341345
{
342346
IIGameProperty babylonTransparencyModeGameProperty = attributesContainer.QueryProperty("babylonTransparencyMode");
@@ -345,8 +349,16 @@ private void ExportStandardMaterial(IIGameMaterial materialNode, IIPropertyConta
345349
babylonMaterial.transparencyMode = babylonTransparencyModeGameProperty.GetIntValue();
346350
isTransparencyModeFromBabylonAttributes = true;
347351
}
352+
353+
IIGameProperty babylonUseAlphaFromDiffuseTextureGameProperty = attributesContainer.QueryProperty("babylonUseAlphaFromDiffuseTexture");
354+
if (babylonUseAlphaFromDiffuseTextureGameProperty != null)
355+
{
356+
useAlphaFromDiffuseTexture = babylonUseAlphaFromDiffuseTextureGameProperty.GetBoolValue();
357+
}
348358
}
349359

360+
babylonMaterial.useAlphaFromDiffuseTexture = useAlphaFromDiffuseTexture;
361+
350362
if (isTransparencyModeFromBabylonAttributes == false || babylonMaterial.transparencyMode != 0)
351363
{
352364
// The user specified value in 3ds Max is opacity
@@ -548,6 +560,7 @@ private void ExportStandardMaterial(IIGameMaterial materialNode, IIPropertyConta
548560
excludeAttributes.Add("babylonUnlit");
549561
excludeAttributes.Add("babylonMaxSimultaneousLights");
550562
excludeAttributes.Add("babylonTransparencyMode");
563+
excludeAttributes.Add("babylonUseAlphaFromDiffuseTexture");
551564

552565
// Export the custom attributes of this material
553566
babylonMaterial.metadata = ExportExtraAttributes(materialNode, babylonScene, excludeAttributes);

3ds Max/Max2Babylon/Scripts/STANDARD_MATERIAL_CAT_DEF.ms

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ version:2
99
parameters main rollout:params
1010
(
1111
babylonUnlit type:#boolean ui:babylonUnlit_ui
12+
babylonUseAlphaFromDiffuseTexture type:#boolean ui:babylonUseAlphaFromDiffuseTexture_ui
1213
babylonMaxSimultaneousLights type:#integer ui:babylonMaxSimultaneousLights_ui default:4
1314
babylonTransparencyMode type:#integer default:0
1415
)
@@ -20,5 +21,6 @@ version:2
2021
label babylonTransparencyMode_label "Transparency Mode " Align: #Left across:2
2122
dropdownlist babylonTransparencyMode_dd items:# ("Opaque","Cutoff","Blend") selection:(babylonTransparencyMode+1) Align: #Right
2223
on babylonTransparencyMode_dd selected i do babylonTransparencyMode = i-1
23-
)
24+
checkbox babylonUseAlphaFromDiffuseTexture_ui "Use alpha from diffuse texture" Align: #Left across:3
25+
)
2426
)

SharedProjects/BabylonExport.Entities/BabylonStandardMaterial.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ public class BabylonStandardMaterial: BabylonMaterial
7777
[DataMember]
7878
public bool useGlossinessFromSpecularMapAlpha { get; set; }
7979

80+
[DataMember]
81+
public bool useAlphaFromDiffuseTexture { get; set; }
82+
8083
[DataMember(EmitDefaultValue = false)]
8184
public float? alphaCutOff { get; set; }
8285

0 commit comments

Comments
 (0)