Skip to content

Commit

Permalink
Update for issue #13 fixes
Browse files Browse the repository at this point in the history
Update for issue #13 fixes
update for Vertex Color addon preferences issues
Code Clean up
Readme changes
  • Loading branch information
Ron Haertel committed Apr 18, 2024
1 parent 7e9bd17 commit 6f6d73e
Show file tree
Hide file tree
Showing 8 changed files with 103 additions and 90 deletions.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ If you want to go back to using the ASOBO exporter, this may or may not be possi

This repository contains the current version of a non-official Microsoft Flight Simulator Blender Import/Export plugin. The flight sim community has already developed and forked the original project many times, and Asobo's intention is to fully support Blender with the help and contributions of all the developers that have already implemented features in the different unofficial Blender plugins.

:warning: This plugin is a fork of the ASOBO plugin version 1.3.2 - and has the following mods/fixes
:warning: This plugin is a fork of the ASOBO plugin version 1.3.3 - and has the following mods/fixes

v1.6.2.x (Blender 3.3.x and 3.6.x) v2.1.0.x (Blender 4.1.x)
v1.6.3.x (Blender 3.3.x and 3.6.x) v2.2.0.x (Blender 4.2.x)

# ASOBO issues and enhancements

Expand Down Expand Up @@ -55,9 +55,11 @@ v1.6.2.x (Blender 3.3.x and 3.6.x) v2.1.0.x (Blender 4.1.x)
#11 Base Color not being used in export - fixed - bug introduced

#12 Forced use of Vertex Color nodes - fixed - added an option in the add-on install - File Preferences
default is not checked and no Vertex color nodes will be linked in shaedr nodes. If checked then Vertex Color
default is not checked and no Vertex color nodes will be linked in shader nodes. If checked then Vertex Color
nodes will be used.

#13 Vertex Color addon Preferences option - fixed issues

# Enhancements

Some default values for Metallic, Roughness, Emissive, Base Color have been reset
Expand Down
34 changes: 17 additions & 17 deletions addons/io_scene_gltf2_msfs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"author": "Luca Pierabella, Yasmine Khodja, Wing42, pepperoni505, ronh991, and others",
"description": "This toolkit prepares your 3D assets to be used for Microsoft Flight Simulator",
"blender": (4, 1, 0),
"version": (2, 2, 1, 1),
"version": (2, 2, 1, 2),
"location": "File > Import-Export",
"category": "Import-Export",
"tracker_url": "https://github.com/ronh991/glTF-Blender-IO-MSFS"
Expand All @@ -41,7 +41,7 @@ def get_name():
return os.path.basename(get_path())

## somehow these should also update the gltf export settings
def on_export_texture_changed(self, context):
def on_export_texture_folder_changed(self, context):
# Update the texture folder name
# changes
settings = bpy.context.scene.msfs_multi_exporter_settings
Expand All @@ -55,12 +55,12 @@ def on_export_copyright_changed(self, context):
settings.export_copyright = self.export_copyright
return

def on_export_vertexcolor_project_changed(self, context):
# Update the copyright data
# changes
settings = bpy.context.scene.msfs_multi_exporter_settings
settings.export_vertexcolor_project = self.export_vertexcolor_project
return
# def on_export_vertexcolor_project_changed(self, context):
# # Update the vertex color setting data
# # changes
# settings = bpy.context.scene.msfs_multi_exporter_settings
# settings.export_vertexcolor_project = self.export_vertexcolor_project
# return


#now that we have the addons name we can get the preferences
Expand All @@ -72,24 +72,24 @@ class addSettingsPanel(bpy.types.AddonPreferences):
bl_idname = __package__

export_texture_dir: bpy.props.StringProperty (
name = "Default Texture Location",
#name = "Default Texture Location",
description = "Default Texture Location",
default = "../texture/",
update=on_export_texture_changed
update=on_export_texture_folder_changed
)

export_copyright: bpy.props.StringProperty (
name = "Default Copyright Name",
#name = "Default Copyright Name",
description = "Default Copyright Name",
default = "Your Copyright Here",
update=on_export_copyright_changed
)

export_vertexcolor_project: bpy.props.BoolProperty (
name = "This Project uses Vertex Color Nodes",
#name = "This Project uses Vertex Color Nodes",
description = "Indicates if the project uses Vertex Color on mesh",
default = False,
update=on_export_vertexcolor_project_changed
default = False
#update=on_export_vertexcolor_project_changed
)

## draw the panel in the addon preferences
Expand All @@ -103,13 +103,13 @@ def draw(self, context):
col = box.column(align = False)

## texture default location
col.prop(self, 'export_texture_dir', expand=False)
col.prop(self, "export_texture_dir", text="Default Texture Location")

## default copyright
col.prop(self, 'export_copyright', expand=False)
col.prop(self, "export_copyright", text="Default Copyright Name")

## default vertex color project
col.prop(self, 'export_vertexcolor_project', expand=False)
col.prop(self, "export_vertexcolor_project", text="This Project uses Vertex Color Nodes")

def get_version_string():
return str(bl_info['version'][0]) + '.' + str(bl_info['version'][1]) + '.' + str(bl_info['version'][2])
Expand Down
26 changes: 10 additions & 16 deletions addons/io_scene_gltf2_msfs/blender/msfs_material_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
MSFS_MixNodeOutputs,
MSFS_BSDFNodeInputs,
MSFS_GroupNodes)
from .. import get_prefs


class MSFS_Material:
Expand Down Expand Up @@ -852,7 +853,6 @@ def defaultShadersTree(self):

## Links
self.link(compTexNode.outputs[0], blendCompMapNode.inputs[0])
#self.link(clampDetailOMR.outputs[1], blendCompMapNode.inputs[self.inputs1])
self.link(clampDetailOMR.outputs[1], blendCompMapNode.inputs[1])

## Split Occlusion Metallic Roughness
Expand Down Expand Up @@ -1190,7 +1190,7 @@ def setUV(self, uvScale, offset_u, offset_v, normalScale):

##############################################
def updateColorLinks(self):
settings = bpy.context.scene.msfs_multi_exporter_settings
settings = get_prefs()
# relink nodes
nodeBaseColorRGB = self.getNodeByName(MSFS_ShaderNodes.baseColorRGB.value)
nodeBaseColorA = self.getNodeByName(MSFS_ShaderNodes.baseColorA.value)
Expand All @@ -1216,8 +1216,6 @@ def updateColorLinks(self):
if nodeVertexColorBaseColorRGB is not None and settings.export_vertexcolor_project:
self.link(nodeVertexColor.outputs[0], nodeVertexColorBaseColorRGB.inputs[self.inputs2])
self.link(nodeVertexColorBaseColorRGB.outputs[self.outputs0], nodePrincipledBSDF.inputs[MSFS_PrincipledBSDFInputs.baseColor.value])
#else:
# self.link(nodeMulBaseColorRGB.outputs[self.outputs0], nodePrincipledBSDF.inputs[MSFS_PrincipledBSDFInputs.baseColor.value])

# no tex
if not nodeBaseColorTex.image and not nodeDetailColorTex.image:
Expand All @@ -1230,31 +1228,34 @@ def updateColorLinks(self):
# has basecolor - no detailColor
elif nodeBaseColorTex.image and not nodeDetailColorTex.image:
nodeBlendColorMap.blend_type = "ADD"
self.link(nodeMulBaseColorRGB.outputs[self.outputs0], nodePrincipledBSDF.inputs[MSFS_PrincipledBSDFInputs.baseColor.value])
self.link(nodeBaseColorTex.outputs[1], nodeMulBaseColorA.inputs[0])
self.link(nodeMulBaseColorA.outputs[0], nodePrincipledBSDF.inputs[MSFS_PrincipledBSDFInputs.alpha.value])
if nodeVertexColorBaseColorRGB is not None and settings.export_vertexcolor_project:
self.link(nodeVertexColorBaseColorRGB.inputs[self.inputs1], nodeMulBaseColorRGB.outputs[self.outputs0])
else:
self.link(nodeMulBaseColorRGB.outputs[self.outputs0], nodePrincipledBSDF.inputs[MSFS_PrincipledBSDFInputs.baseColor.value])

# no basecolor - has detailColor - Is this a thing????
# Blender 4.0+ issue with finding a texture here on alpha channel - puts DetailColor in BaseColor slot also along with ASOBO extension
elif not nodeBaseColorTex.image and nodeDetailColorTex.image:
nodeBlendColorMap.blend_type = "ADD"
self.link(nodeMulBaseColorRGB.outputs[self.outputs0], nodePrincipledBSDF.inputs[MSFS_PrincipledBSDFInputs.baseColor.value])
# Alpha links
self.link(nodeDetailColorTex.outputs[1],nodeMulBaseColorA.inputs[0])
self.link(nodeMulBaseColorA.outputs[0], nodePrincipledBSDF.inputs[MSFS_PrincipledBSDFInputs.alpha.value])
if nodeVertexColorBaseColorRGB is not None and settings.export_vertexcolor_project:
self.link(nodeVertexColorBaseColorRGB.inputs[self.inputs1], nodeMulBaseColorRGB.outputs[self.outputs0])
else:
self.link(nodeMulBaseColorRGB.outputs[self.outputs0], nodePrincipledBSDF.inputs[MSFS_PrincipledBSDFInputs.baseColor.value])

# has both tex
else:
nodeBlendColorMap.blend_type = "MULTIPLY"
nodeMulBaseColorRGB.blend_type = "MULTIPLY"
self.link(nodeMulBaseColorRGB.outputs[self.outputs0], nodePrincipledBSDF.inputs[MSFS_PrincipledBSDFInputs.baseColor.value])
self.link(nodeBlendAlphaMap.outputs[0], nodeMulBaseColorA.inputs[0])
if nodeVertexColorBaseColorRGB is not None and settings.export_vertexcolor_project:
self.link(nodeVertexColorBaseColorRGB.inputs[self.inputs1], nodeMulBaseColorRGB.outputs[self.outputs0])
else:
self.link(nodeMulBaseColorRGB.outputs[self.outputs0], nodePrincipledBSDF.inputs[MSFS_PrincipledBSDFInputs.baseColor.value])

def updateNormalLinks(self):
nodeNormalTex = self.getNodeByName(MSFS_ShaderNodes.normalTex.value)
Expand Down Expand Up @@ -1316,13 +1317,7 @@ def updateCompLinks(self):
nodeGltfSettings = self.getNodeByName(MSFS_ShaderNodes.glTFSettings.value)
nodePrincipledBSDF = self.getNodeByName(MSFS_ShaderNodes.principledBSDF.value)

# blend comp
# !!!! input orders matters for the exporter here
#self.link(nodeCompTex.outputs[0], nodeBlendCompMap.inputs[self.inputs1])
#self.link(nodeDetailCompTex.outputs[0], nodeBlendCompMap.inputs[self.inputs2])

# occlMetalRough
#self.link(nodeBlendCompMap.outputs[self.outputs0], nodeSeparateComp.inputs[0])
self.link(nodeBlendCompMap.outputs[0], nodeSeparateComp.inputs[0])
self.link(nodeMetallicScale.outputs[0], nodeMulMetallic.inputs[0])
self.link(nodeRoughnessScale.outputs[0], nodeMulRoughness.inputs[0])
Expand Down Expand Up @@ -1357,11 +1352,9 @@ def toggleVertexBlendMapMask(self, useVertex=True):
# vertexcolor mask
if useVertex:
self.link(nodeVertexColor.outputs[1], nodeBlendColorMap.inputs[self.inputs0])
#self.link(nodeVertexColor.outputs[1], nodeBlendCompMap.inputs[self.inputs0])
self.link(nodeVertexColor.outputs[1], nodeBlendNormalMap.inputs[0])
else:
self.link(nodeBlendMaskTex.outputs[0], nodeBlendColorMap.inputs[self.inputs0])
#self.link(nodeBlendMaskTex.outputs[0], nodeBlendCompMap.inputs[self.inputs0])
self.link(nodeBlendMaskTex.outputs[0], nodeBlendNormalMap.inputs[0])

def makeOpaque(self):
Expand Down Expand Up @@ -1446,7 +1439,8 @@ def set_vertex_color_white(self, mat, tex):
print("update_base_color_texture - found mesh object with material base color texture - update", obj, mat.name, mat.msfs_base_color_texture, mat.msfs_detail_color_texture)
color_attribute = obj.data.color_attributes.new(
name='Col',
type='BYTE_COLOR',
#type='BYTE_COLOR',
type='FLOAT_COLOR',
domain='CORNER',
)

Expand Down
86 changes: 51 additions & 35 deletions addons/io_scene_gltf2_msfs/blender/msfs_material_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,16 @@
MSFS_BSDFNodeInputs,
MSFS_ShaderNodes)
from bpy.types import Material
from .. import get_prefs

def equality_check(arr1, arr2, size1, size2):
if (size1 != size2):
return False
for i in range(0, size2):
# blender python color channel issues in floats ???
if (int(arr1[i] * 10000000)/10000000 != int(arr2[i] * 10000000)/10000000):
return False
return True
if (size1 != size2):
return False
for i in range(0, size2):
# blender python color channel issues in floats ???
if (int(arr1[i] * 10000000)/10000000 != int(arr2[i] * 10000000)/10000000):
return False
return True

def Is_it_FBW_Material(mat):
# ToDo: FBW msfs_material_type mapping
Expand All @@ -54,21 +55,22 @@ def Is_it_FBW_Material(mat):
def set_vertex_color_white(mat, obj):
# now adding a base color triggers vertex color links - they make object black in blender - show texture by making mesh color attribute white
# add color attribute to all meshes in material
if mat.msfs_base_color_texture or mat.msfs_detail_color_texture:
if obj.type == 'MESH':
for mat_slot in obj.material_slots:
if mat_slot.material.name == mat.name:
#print("update_base_color_texture - found mesh object with material base color texture", obj, mat.name, mat.msfs_base_color_texture, mat.msfs_detail_color_texture)
for ca in obj.data.color_attributes:
if len(obj.data.color_attributes) > 0:
return
# None found - make new Vertex_Color_white and assing to mesh
# Create a new color attribute - seems to be white already ????
color_attribute = obj.data.color_attributes.new(
name='Col',
type='BYTE_COLOR',
domain='CORNER',
)
#if mat.msfs_base_color_texture or mat.msfs_detail_color_texture:
if obj.type == 'MESH':
for mat_slot in obj.material_slots:
if mat_slot.material.name == mat.name:
#print("update_base_color_texture - found mesh object with material base color texture", obj, mat.name, mat.msfs_base_color_texture, mat.msfs_detail_color_texture)
for ca in obj.data.color_attributes:
if len(obj.data.color_attributes) > 0:
return
# None found - make new Vertex_Color_white and assing to mesh
# Create a new color attribute - seems to be white already ????
color_attribute = obj.data.color_attributes.new(
name='Col',
#type='BYTE_COLOR',
type='FLOAT_COLOR',
domain='CORNER',
)


# def reset_base_color_links(mat, obj):
Expand Down Expand Up @@ -109,11 +111,21 @@ def vertex_color_white_attribute_is_required(mat, obj):
for n in mat.node_tree.nodes:
if n.label == MSFS_ShaderNodes.baseColorTex.value and n.image:
if not MSFS_OT_vertex_color_white_Data.vertex_color_attribute_isfound(obj):
#print("vertex_color_white_attribute_is_required - required")
#print("vertex_color_white_attribute_is_required - required Tex")
return True
if n.label == MSFS_ShaderNodes.detailColorTex.value and n.image:
if not MSFS_OT_vertex_color_white_Data.vertex_color_attribute_isfound(obj):
#print("vertex_color_white_attribute_is_required - required")
#print("vertex_color_white_attribute_is_required - required Det Tex")
return True
if n.label == MSFS_ShaderNodes.baseColorRGB.value:
#print("mat, obj", mat, obj)
#color = n.outputs[0].default_value
#print("color", color, color[0], color[1], color[2])
#if (color[0] != 1 or color[1] != 1 or color[2] != 1):
if not MSFS_OT_vertex_color_white_Data.vertex_color_attribute_isfound(obj):
#print("vertex_color_white_attribute_is_required - required base")
# for this need to reset the links Base Color to BSDF to base color to Vertex Base Color Mul
# reset the links
return True
except:
print("*** MSFS Warning *** vertex color white attribute error")
Expand Down Expand Up @@ -164,15 +176,17 @@ def execute(self, context):
if n.label == MSFS_ShaderNodes.detailColorTex.value and n.image:
if not self.vertex_color_attribute_isfound(obj):
set_vertex_color_white(mat, obj)
# if n.label == MSFS_ShaderNodes.baseColorRGB.value:
# #print("mat, obj", mat, obj)
# color = n.outputs[0].default_value
# #print("color", color, color[0], color[1], color[2])
# if (color[0] != 1 or color[1] != 1 or color[2] != 1):
# if self.vertex_color_attribute_isfound(obj):
# # for this need to reset the links Base Color to BSDF to base color to Vertex Base Color Mul
# # reset the links
# reset_base_color_links(mat, obj)
if n.label == MSFS_ShaderNodes.baseColorRGB.value:
#print("mat, obj", mat, obj)
#color = n.outputs[0].default_value
#print("color", color, color[0], color[1], color[2])
#if (color[0] != 1 or color[1] != 1 or color[2] != 1):
if not self.vertex_color_attribute_isfound(obj):
# for this need to reset the links Base Color to BSDF to base color to Vertex Base Color Mul
# reset the links
#print("set vertex color white")
set_vertex_color_white(mat, obj)
#reset_base_color_links(mat, obj)
except:
print("*** MSFS Warning *** vertex color white attribute error")
return {"FINISHED"}
Expand Down Expand Up @@ -930,10 +944,12 @@ def draw(self, context):

mat = context.active_object.active_material
obj = context.active_object
settings = bpy.context.scene.msfs_multi_exporter_settings
# this seems to be the only place I can check if the addon prefs match the
# the multi export settings that in clude all the addon settings
addonpreferences = get_prefs()
if mat:
# test if project needs vertex colors
if settings.export_vertexcolor_project and MSFS_OT_vertex_color_white_Data.vertex_color_white_attribute_is_required(mat, obj):
if addonpreferences.export_vertexcolor_project and MSFS_OT_vertex_color_white_Data.vertex_color_white_attribute_is_required(mat, obj):
layout.operator(MSFS_OT_vertex_color_white_Data.bl_idname)

if MSFS_OT_glTfSettingsMaterialData.gltf_settings_with_dot_present():
Expand Down

0 comments on commit 6f6d73e

Please sign in to comment.