Skip to content

Commit

Permalink
Changes to how you add shaders in the UI (#182)
Browse files Browse the repository at this point in the history
* fix(shader): Prevent resetting parameters in shader settings

Introduce an early return check for the shader's variation. If the selected variation is the same as the previously active one, the function exits early, preventing any unnecessary resetting of shader parameters.

Fix #180

* feat(material): New way of adding shaders

- The shaders will now be automatically loaded in a EnumProperty through the data path set in addon preferences
- This includes a operator that will migrate the old "source" property over to the new "shader" enum property (and preserve all the other shader related data)
- Made it possible to add "material_name" to the load_shader and load_shader_variation operators so it can be called through API without needing to have a active object with a active material to run the operators

* Added support to export new shader setup
  • Loading branch information
NMC-TBone committed Nov 29, 2023
1 parent 4ed9d82 commit c73843b
Show file tree
Hide file tree
Showing 2 changed files with 285 additions and 41 deletions.
11 changes: 8 additions & 3 deletions addon/i3dio/node_classes/material.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,16 @@ def _write_properties(self):
self._write_attribute('alphaBlending', True)

def _export_shader_settings(self):
data_path = bpy.context.preferences.addons['i3dio'].preferences.fs_data_path
shader_settings = self.blender_material.i3d_attributes
if shader_settings.source != shader_picker.shader_unselected_default_text:
shader_file_id = self.i3d.add_file_shader(shader_settings.source)
if shader_settings.shader != shader_picker.shader_default:
shader_path = data_path + "shaders\\" + shader_settings.shader + ".xml"
if shader_settings.shader == shader_picker.shader_custom and shader_settings.custom_shader != '':
shader_path = shader_settings.custom_shader
shader_file_id = self.i3d.add_file_shader(shader_path)
self._write_attribute('customShaderId', shader_file_id)
if shader_settings.source.endswith("mirrorShader.xml"):

if shader_settings.shader == "mirrorShader":
params = {'type': 'planar', 'refractiveIndex': '10', 'bumpScale': '0.1'}
xml_i3d.SubElement(self.element, 'Reflectionmap', params)

Expand Down
Loading

0 comments on commit c73843b

Please sign in to comment.