Skip to content

Commit

Permalink
Merge branch 'main' into blender-v3.1-release
Browse files Browse the repository at this point in the history
  • Loading branch information
lpierabella committed Apr 11, 2022
2 parents 5634ef2 + a8894ab commit fba0609
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 25 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,14 @@ This repository represents an alpha version of the official FlightSim-Blender Im
Asobo especially thanks:

Vitus of [Wing42](https://wing42.com/), [tml1024](https://github.com/tml1024), [ronh991](https://github.com/ronh991), [pepperoni505](https://github.com/pepperoni505) of [FlyByWire](https://flybywiresim.com/)


Installation
===========

1. Download the latest release
2. Decompress the file
3. Open the `addons` folder
4. Copy-paste the `io_scene_gltf2_msfs` folder into your Blender installation's `scripts/addons/` folder.
1. Windows: this will usually be in `C:\Program Files\Blender Foundation\Blender 3.1\3.1\scripts\addons\`.
2. Mac OS X: this will be in your Library (Press the Option key when in Finder's `Go` menu to open your Library folder): `\Users\<username>\Library\Application Support\Blender\3.1\scripts\addons\`.
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.

from ..msfs_material_function import MSFS_Material
from ..msfs_material_function import MSFS_Material, MSFS_ShaderNodes


class MSFS_Environment_Occluder(MSFS_Material):
def __init__(self, material, buildTree=False):
super().__init__(material, buildTree)

def customShaderTree(self):
super(MSFS_Environment_Occluder, self).defaultShaderStree()
self.principledBSDF = self.getNode(MSFS_ShaderNodes.principledBSDF.value)
self.principledBSDF.inputs[21].default_value = 0
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.

from ..msfs_material_function import MSFS_Material
from ..msfs_material_function import MSFS_Material, MSFS_ShaderNodes


class MSFS_Invisible(MSFS_Material):
def __init__(self, material, buildTree=False):
super().__init__(material, buildTree)

def customShaderTree(self):
super(MSFS_Invisible, self).defaultShaderStree()
self.principledBSDF = self.getNode(MSFS_ShaderNodes.principledBSDF.value)
self.principledBSDF.inputs[21].default_value = 0

12 changes: 12 additions & 0 deletions addons/io_scene_gltf2_msfs/blender/msfs_material_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,10 @@ def setAnisotropicTex(self, tex):
def setBaseColor(self, color):
self.nodeBaseColorRGB = self.getNode(MSFS_ShaderNodes.baseColorRGB.value)
self.nodeBaseColorA = self.getNode(MSFS_ShaderNodes.baseColorA.value)
if not self.nodeBaseColorA:
return
if not self.nodeBaseColorRGB:
return
colorValue = self.nodeBaseColorRGB.outputs[0].default_value
colorValue[0] = color[0]
colorValue[1] = color[1]
Expand All @@ -613,6 +617,8 @@ def setBaseColor(self, color):

def setBaseColorTex(self, tex):
self.nodeBaseColorTex = self.getNode(MSFS_ShaderNodes.baseColorTex.value)
if not self.nodeBaseColorTex:
return
self.nodeBaseColorTex.image = tex
self.updateColorLinks()

Expand Down Expand Up @@ -733,18 +739,24 @@ def setDetailCompTex(self, tex):

def setRoughnessScale(self, scale):
self.nodeRoughnessScale = self.getNode(MSFS_ShaderNodes.roughnessScale.value)
if not self.nodeRoughnessScale:
return
self.nodeRoughnessScale.outputs[0].default_value = scale
self.updateCompLinks()

def setMetallicScale(self, scale):
self.nodeMetallicScale = self.getNode(MSFS_ShaderNodes.metallicScale.value)
if not self.nodeMetallicScale:
return
self.nodeMetallicScale.outputs[0].default_value = scale
self.updateCompLinks()

def setNormalScale(self, scale):
self.nodeNormalMapSampler = self.getNode(
MSFS_ShaderNodes.normalMapSampler.value
)
if not self.nodeNormalMapSampler:
return
self.nodeNormalMapSampler.inputs[0].default_value = scale
self.updateNormalLinks()

Expand Down
14 changes: 12 additions & 2 deletions addons/io_scene_gltf2_msfs/blender/msfs_material_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,26 @@ def execute(self, context):
new_property,
) in MSFS_OT_MigrateMaterialData.old_property_to_new_mapping.items():
if mat.get(old_property) is not None:
# msfs_behind_glass_texture and msfs_detail_albedo_texture are special cases as they are they write to the same property
if mat.get("msfs_material_mode") == "msfs_windshield" and old_property == "msfs_behind_glass_texture":
continue
if mat.get("msfs_material_mode") == "msfs_parallax" and old_property == "msfs_detail_albedo_texture":
continue
mat[new_property] = mat[old_property]

del mat[old_property]

# Base color is a special case - can only have 3 values, we need 4
base_color = [1,1,1,1]
alpha = 1
if mat.get("msfs_color_alpha_mix"):
alpha = mat.get("msfs_color_alpha_mix")
base_color[3] = alpha
if mat.get("msfs_color_albedo_mix"):
base_color = list(mat.get("msfs_color_albedo_mix"))
if len(base_color) == 3:
base_color.append(1) # Append full alpha
mat.msfs_base_color_factor = base_color
base_color.append(alpha)
mat.msfs_base_color_factor = base_color

# Emissive factor is also a special case - old material system had 4 floats, we only need 3
if mat.get("msfs_color_emissive_mix"):
Expand Down
55 changes: 36 additions & 19 deletions addons/io_scene_gltf2_msfs/blender/msfs_material_prop_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def getMaterial(mat):
return MSFS_Fake_Terrain(mat)
elif mat.msfs_material_type == "msfs_fresnel_fade":
return MSFS_Fresnel_Fade(mat)
elif mat.msfs_material_type == "msfs_env_occluder":
elif mat.msfs_material_type == "msfs_environment_occluder":
return MSFS_Environment_Occluder(mat)
elif mat.msfs_material_type == "msfs_ghost":
return MSFS_Ghost(mat)
Expand All @@ -76,45 +76,49 @@ def update_msfs_material_type(self, context):
if self.msfs_material_type == "msfs_standard":
msfs_mat = MSFS_Standard(self, buildTree=True)
elif self.msfs_material_type == "msfs_geo_decal":
self.msfs_alpha_mode = "BLEND"
msfs_mat = MSFS_Geo_Decal(self, buildTree=True)
elif self.msfs_material_type == "msfs_geo_decal_frosted":
self.msfs_alpha_mode = "BLEND"
elif self.msfs_material_type == "msfs_geo_decal_frosted":
msfs_mat = MSFS_Geo_Decal_Frosted(self, buildTree=True)
elif self.msfs_material_type == "msfs_windshield":
self.msfs_metallic_factor = 0.0
self.msfs_alpha_mode = "BLEND"
elif self.msfs_material_type == "msfs_windshield":
msfs_mat = MSFS_Windshield(self, buildTree=True)
self.msfs_alpha_mode = "BLEND"
self.msfs_metallic_factor = 0.0
elif self.msfs_material_type == "msfs_porthole":
self.msfs_alpha_mode = "OPAQUE"
msfs_mat = MSFS_Porthole(self, buildTree=True)
elif self.msfs_material_type == "msfs_glass":
self.msfs_metallic_factor = 0.0
self.msfs_alpha_mode = "BLEND"
msfs_mat = MSFS_Glass(self, buildTree=True)
self.msfs_alpha_mode = "BLEND"
self.msfs_metallic_factor = 0.0
elif self.msfs_material_type == "msfs_clearcoat":
msfs_mat = MSFS_Clearcoat(self, buildTree=True)
elif self.msfs_material_type == "msfs_parallax":
self.msfs_alpha_mode = "MASK"
msfs_mat = MSFS_Parallax(self, buildTree=True)
self.msfs_alpha_mode = "MASK"
elif self.msfs_material_type == "msfs_anisotropic":
msfs_mat = MSFS_Anisotropic(self, buildTree=True)
elif self.msfs_material_type == "msfs_hair":
msfs_mat = MSFS_Hair(self, buildTree=True)
elif self.msfs_material_type == "msfs_sss":
msfs_mat = MSFS_SSS(self, buildTree=True)
elif self.msfs_material_type == "msfs_invisible":
msfs_mat = MSFS_Invisible(self, buildTree=True)
msfs_mat = MSFS_Invisible(self, buildTree=False)
self.msfs_no_cast_shadow = True
self.msfs_alpha_mode = "BLEND"
elif self.msfs_material_type == "msfs_fake_terrain":
msfs_mat = MSFS_Fake_Terrain(self, buildTree=True)
elif self.msfs_material_type == "msfs_fresnel_fade":
msfs_mat = MSFS_Fresnel_Fade(self, buildTree=True)
elif self.msfs_material_type == "msfs_env_occluder":
msfs_mat = MSFS_Environment_Occluder(self, buildTree=True)
elif self.msfs_material_type == "msfs_ghost":
elif self.msfs_material_type == "msfs_environment_occluder":
msfs_mat = MSFS_Environment_Occluder(self, buildTree=False)
self.msfs_no_cast_shadow = True
self.msfs_alpha_mode = "BLEND"
elif self.msfs_material_type == "msfs_ghost":
msfs_mat = MSFS_Ghost(self, buildTree=True)
self.msfs_no_cast_shadow = True
self.msfs_alpha_mode = "BLEND"
else:
msfs_mat = MSFS_Material(self)
msfs_mat.revertToPBRShaderTree()
Expand All @@ -123,20 +127,26 @@ def update_msfs_material_type(self, context):
@staticmethod
def update_base_color_texture(self, context):
msfs = MSFS_Material_Property_Update.getMaterial(self)
if msfs is None:
return
if type(msfs) is MSFS_Invisible:
return
msfs.setBaseColorTex(self.msfs_base_color_texture)

@staticmethod
def update_comp_texture(self, context):
msfs = MSFS_Material_Property_Update.getMaterial(self)
if msfs is None:
return
if type(msfs) is MSFS_Invisible:
return
msfs.setCompTex(self.msfs_occlusion_metallic_roughness_texture)

@staticmethod
def update_normal_texture(self, context):
msfs = MSFS_Material_Property_Update.getMaterial(self)
if msfs is None:
return
if type(msfs) is MSFS_Invisible:
return
msfs.setNormalTex(self.msfs_normal_texture)
Expand All @@ -153,6 +163,8 @@ def update_emissive_texture(self, context):
@staticmethod
def update_detail_color_texture(self, context):
msfs = MSFS_Material_Property_Update.getMaterial(self)
if msfs is None:
return
if type(msfs) is MSFS_Invisible:
return
if type(msfs) is MSFS_Parallax:
Expand Down Expand Up @@ -185,9 +197,10 @@ def update_detail_color_texture(self, context):
@staticmethod
def update_detail_comp_texture(self, context):
msfs = MSFS_Material_Property_Update.getMaterial(self)
if type(msfs) is MSFS_Invisible:
return
msfs.setDetailCompTex(self.msfs_detail_occlusion_metallic_roughness_texture)
if msfs is not None:
if type(msfs) is MSFS_Invisible:
return
msfs.setDetailCompTex(self.msfs_detail_occlusion_metallic_roughness_texture)

@staticmethod
def update_detail_normal_texture(self, context):
Expand Down Expand Up @@ -256,7 +269,8 @@ def update_alpha_mode(self, context):
@staticmethod
def update_base_color(self, context):
msfs = MSFS_Material_Property_Update.getMaterial(self)
msfs.setBaseColor(self.msfs_base_color_factor)
if msfs is not None:
msfs.setBaseColor(self.msfs_base_color_factor)

@staticmethod
def update_emissive_color(self, context):
Expand All @@ -280,17 +294,20 @@ def update_emissive_scale(self, context):
@staticmethod
def update_metallic_scale(self, context):
msfs = MSFS_Material_Property_Update.getMaterial(self)
msfs.setMetallicScale(self.msfs_metallic_factor)
if msfs is not None:
msfs.setMetallicScale(self.msfs_metallic_factor)

@staticmethod
def update_roughness_scale(self, context):
msfs = MSFS_Material_Property_Update.getMaterial(self)
msfs.setRoughnessScale(self.msfs_roughness_factor)
if msfs is not None:
msfs.setRoughnessScale(self.msfs_roughness_factor)

@staticmethod
def update_normal_scale(self, context):
msfs = MSFS_Material_Property_Update.getMaterial(self)
msfs.setNormalScale(self.msfs_normal_scale)
if msfs is not None:
msfs.setNormalScale(self.msfs_normal_scale)

@staticmethod
def update_color_sss(self, context):
Expand Down
3 changes: 3 additions & 0 deletions addons/io_scene_gltf2_msfs/com/msfs_material_props.py
Original file line number Diff line number Diff line change
Expand Up @@ -1781,4 +1781,7 @@ def to_extension(blender_material, gltf2_material, export_settings):
elif blender_material.msfs_material_type == "msfs_clearcoat":
result = AsoboMaterialCode.MaterialCode.ClearCoat

if gltf2_material.extras is None:
gltf2_material.extras = {}

gltf2_material.extras[AsoboMaterialCode.SerializedName] = result
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# glTF-Blender-IO-MSFS
# Copyright 2018-2021 The glTF-Blender-IO authors
# Copyright 2022 The glTF-Blender-IO-MSFS authors
#
Expand Down

0 comments on commit fba0609

Please sign in to comment.