From be2d4eb0b735500a50d20ee2d9979c9f17d79e3a Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sun, 28 Mar 2021 14:12:05 +0300 Subject: [PATCH] Support defining uniform values for materials in Blender --- blender/io_mspgl/__init__.py | 26 +++++++++++++++++- blender/io_mspgl/export_material.py | 6 +++++ blender/io_mspgl/properties.py | 42 ++++++++++++++++++++++++++--- 3 files changed, 69 insertions(+), 5 deletions(-) diff --git a/blender/io_mspgl/__init__.py b/blender/io_mspgl/__init__.py index 55661f51..b5892b1c 100644 --- a/blender/io_mspgl/__init__.py +++ b/blender/io_mspgl/__init__.py @@ -172,6 +172,30 @@ class ExportMspGLCamera(bpy.types.Operator, ExportMspGLBase): from .export_camera import CameraExporter return CameraExporter() +class AddUniform(bpy.types.Operator): + bl_idname = "material.add_uniform" + bl_label = "Add Uniform" + bl_description = "Add a new uniform value to the material" + + def execute(self, context): + mat = context.active_object.active_material + mat.uniforms.add() + mat.active_uniform_index = len(mat.uniforms)-1 + + return {"FINISHED"} + +class RemoveUniform(bpy.types.Operator): + bl_idname = "material.remove_uniform" + bl_label = "Remove Uniform" + bl_description = "Remove the selected uniform from the material" + + def execute(self, context): + mat = context.active_object.active_material + mat.uniforms.remove(mat.active_uniform_index) + mat.active_uniform_index = min(mat.active_uniform_index, len(mat.uniforms)-1) + + return {"FINISHED"} + def menu_func_export(self, context): self.layout.operator(ExportMspGLMesh.bl_idname, text="Msp GL mesh") self.layout.operator(ExportMspGLObject.bl_idname, text="Msp GL object") @@ -180,7 +204,7 @@ def menu_func_export(self, context): self.layout.operator(ExportMspGLScene.bl_idname, text="Msp GL scene") self.layout.operator(ExportMspGLCamera.bl_idname, text="Msp GL camera") -classes = [ExportMspGLMesh, ExportMspGLObject, ExportMspGLArmature, ExportMspGLAnimation, ExportMspGLScene, ExportMspGLCamera] +classes = [ExportMspGLMesh, ExportMspGLObject, ExportMspGLArmature, ExportMspGLAnimation, ExportMspGLScene, ExportMspGLCamera, AddUniform, RemoveUniform] def register(): for c in classes: diff --git a/blender/io_mspgl/export_material.py b/blender/io_mspgl/export_material.py index 5411280d..c7ca765c 100644 --- a/blender/io_mspgl/export_material.py +++ b/blender/io_mspgl/export_material.py @@ -16,6 +16,12 @@ def create_technique_resource(material, resources): shader += ".shader" st.sub.append(Statement("shader", shader)) + if material.uniforms: + ss = Statement("uniforms") + for u in material.uniforms: + ss.sub.append(Statement("uniform", u.name, *u.values[:u.size])) + st.sub.append(ss) + tech_res.statements.append(st) return tech_res diff --git a/blender/io_mspgl/properties.py b/blender/io_mspgl/properties.py index df18d444..baf9ac95 100644 --- a/blender/io_mspgl/properties.py +++ b/blender/io_mspgl/properties.py @@ -74,6 +74,22 @@ class MspGLMaterialProperties(bpy.types.Panel): self.layout.prop(mat, "array_layer") if mat.render_mode!='EXTERNAL': self.layout.prop(mat, "material_atlas") + if mat.render_mode=='CUSTOM': + self.layout.separator() + self.layout.label(text="Uniform values") + self.layout.template_list("MATERIAL_UL_mspgl_uniforms", "", mat, "uniforms", mat, "active_uniform_index") + row = self.layout.row() + row.operator("material.add_uniform") + row.operator("material.remove_uniform") + + if mat.active_uniform_index