]> git.tdb.fi Git - libs/gl.git/blob - blender/io_mspgl/properties.py
Include only tangent in mesh data and calculate binormal on the fly
[libs/gl.git] / blender / io_mspgl / properties.py
1 import bpy
2
3 class MspGLMeshProperties(bpy.types.Panel):
4         bl_idname = "MESH_PT_mspgl_properties"
5         bl_label = "MspGL properties"
6         bl_space_type = "PROPERTIES"
7         bl_region_type = "WINDOW"
8         bl_context = "data"
9
10         @classmethod
11         def poll(cls, context):
12                 return context.active_object.type=="MESH"
13
14         def draw(self, context):
15                 mesh = context.active_object.data
16
17                 self.layout.prop(mesh, "winding_test")
18                 self.layout.prop(mesh, "smoothing")
19
20                 self.layout.separator()
21
22                 col = self.layout.column()
23                 col.label(text="Data selection")
24                 col.prop(mesh, "use_lines")
25                 col.prop(mesh, "vertex_groups")
26                 col.prop(mesh, "max_groups_per_vertex")
27
28                 self.layout.separator()
29
30                 col = self.layout.column()
31                 col.label(text="Texturing")
32                 col.prop(mesh, "use_uv")
33                 col.prop(mesh, "tangent_vecs")
34                 col.prop(mesh, "tangent_uvtex")
35
36 class MspGLObjectProperties(bpy.types.Panel):
37         bl_idname = "OBJECT_PT_mspgl_properties"
38         bl_label = "MspGL properties"
39         bl_space_type = "PROPERTIES"
40         bl_region_type = "WINDOW"
41         bl_context = "object"
42
43         def draw(self, context):
44                 obj = context.active_object
45
46                 self.layout.prop(obj, "compound")
47                 self.layout.prop(obj, "lod_for_parent")
48                 if obj.lod_for_parent:
49                         self.layout.prop(obj, "lod_index")
50
51 class MspGLMaterialProperties(bpy.types.Panel):
52         bl_idname = "MATERIAL_PT_mspgl_properties"
53         bl_label = "MspGL properties"
54         bl_space_type = "PROPERTIES"
55         bl_region_type = "WINDOW"
56         bl_context = "material"
57
58         @classmethod
59         def poll(cls, context):
60                 return context.active_object.active_material is not None
61
62         def draw(self, context):
63                 mat = context.active_object.active_material
64                 if not mat:
65                         return
66
67                 self.layout.prop(mat, "render_mode")
68                 if mat.render_mode=='CUSTOM':
69                         self.layout.prop(mat, "shader")
70                 elif mat.render_mode=='EXTERNAL':
71                         self.layout.prop(mat, "technique")
72                 self.layout.prop(mat, "array_atlas")
73                 if mat.array_atlas:
74                         self.layout.prop(mat, "array_layer")
75                 if mat.render_mode!='EXTERNAL':
76                         self.layout.prop(mat, "material_atlas")
77                 if mat.render_mode=='CUSTOM':
78                         self.layout.separator()
79                         self.layout.label(text="Uniform values")
80                         self.layout.template_list("MATERIAL_UL_mspgl_uniforms", "", mat, "uniforms", mat, "active_uniform_index")
81                         row = self.layout.row()
82                         row.operator("material.add_uniform")
83                         row.operator("material.remove_uniform")
84
85                         if mat.active_uniform_index<len(mat.uniforms):
86                                 uniform = mat.uniforms[mat.active_uniform_index]
87                                 self.layout.prop(uniform, "name")
88                                 self.layout.prop(uniform, "size")
89                                 row = self.layout.row(align=True)
90                                 row.label(text="Values")
91                                 for i in range(uniform.size):
92                                         row.prop(uniform, "values", text="", index=i)
93
94 class MspGLTextureNodeProperties(bpy.types.Panel):
95         bl_idname = "NODE_PT_mspgl_properties"
96         bl_label = "MspGL properties"
97         bl_space_type = "NODE_EDITOR"
98         bl_region_type = "UI"
99         bl_category = "Item"
100
101         @classmethod
102         def poll(cls, context):
103                 node = context.active_node
104                 return node and node.type=='TEX_IMAGE'
105
106         def draw(self, context):
107                 node = context.active_node
108                 if not node:
109                         return
110
111                 self.layout.prop(node, "default_filter")
112                 if not node.default_filter:
113                         self.layout.prop(node, "use_mipmap")
114                         self.layout.prop(node, "max_anisotropy")
115
116 class MspGLUniform(bpy.types.PropertyGroup):
117         name: bpy.props.StringProperty(name="Name", description="Name of the uniform variable")
118         size: bpy.props.IntProperty(name="Size", description="Number of elements in the uniform", min=1, max=4, default=4)
119         values: bpy.props.FloatVectorProperty(name="Values", description="Values stored in the uniform", size=4)
120
121 class MspGLUniformList(bpy.types.UIList):
122         bl_idname = "MATERIAL_UL_mspgl_uniforms"
123
124         def draw_item(self, context, layout, data, item, icon, active_data, active_propname):
125                 uniform = item
126                 if self.layout_type=="GRID":
127                         layout.label(text="", icon_value=icon)
128                 else:
129                         layout.prop(uniform, "name", text="", emboss=False, icon_value=icon)
130                         layout.label(text="({})".format(", ".join("{:.3f}".format(v) for v in uniform.values[:uniform.size])))
131
132 classes = [MspGLMeshProperties, MspGLObjectProperties, MspGLMaterialProperties, MspGLTextureNodeProperties, MspGLUniform, MspGLUniformList]
133
134 def register_properties():
135         for c in classes:
136                 bpy.utils.register_class(c)
137
138         bpy.types.Mesh.winding_test = bpy.props.BoolProperty(name="Winding test", description="Perform winding test to skip back faces")
139         bpy.types.Mesh.smoothing = bpy.props.EnumProperty(name="Smoothing", description="Smoothing method to use", default="MSPGL",
140                 items=(("NONE", "None", "No smoothing"),
141                         ("BLENDER", "Blender", "Use Blender's vertex normals"),
142                         ("MSPGL", "MspGL", "Compute vertex normals internally")))
143         bpy.types.Mesh.use_lines = bpy.props.BoolProperty(name="Include lines", description="Include edges without faces as lines", default=False)
144         bpy.types.Mesh.vertex_groups = bpy.props.BoolProperty(name="Vertex groups", description="Include vertex groups and weights", default=False)
145         bpy.types.Mesh.max_groups_per_vertex = bpy.props.IntProperty(name="Max groups", description="Maximum amount of groups per vertex", min=1, max=4, default=2)
146         bpy.types.Mesh.use_uv = bpy.props.EnumProperty(name="Use UV", description="Use UV coordinates", default="UNIT0",
147                 items=(("NONE", "None", "Ignore all UV coordinates"),
148                         ("UNIT0", "Unit 0", "Use UV coordinates for unit 0"),
149                         ("ALL", "All", "Use all UV coordinates")))
150         bpy.types.Mesh.tangent_vecs = bpy.props.BoolProperty(name="Tangent vectors", description="Compute tangent vectors for vertices", default=False)
151         bpy.types.Mesh.tangent_uvtex = bpy.props.StringProperty(name="Tangent UV layer", description="UV layer to use as basis for tangent vectors", default="")
152
153         bpy.types.Object.compound = bpy.props.BoolProperty(name="Compound with parent", description="Join this object to its parent when exporting")
154         bpy.types.Object.lod_for_parent = bpy.props.BoolProperty(name="LoD for parent", description="This object is a level of detail for its parent")
155         bpy.types.Object.lod_index = bpy.props.IntProperty(name="LoD index", description="Index of the level of detail", min=1, max=16, default=1)
156
157         bpy.types.Material.render_mode = bpy.props.EnumProperty(name="Render mode", description="How this material should be rendered", default="BUILTIN",
158                 items=(("BUILTIN", "Built-in", "Use built-in shaders"),
159                         ("CUSTOM", "Custom shader", "Use a custom shader"),
160                         ("EXTERNAL", "External technique", "Use an externally defined technique")))
161         bpy.types.Material.technique = bpy.props.StringProperty(name="Custom technique", description="Name of an external technique to use for rendering")
162         bpy.types.Material.shader = bpy.props.StringProperty(name="Custom shader", description="Name of an external technique to use for rendering")
163         bpy.types.Material.array_atlas = bpy.props.BoolProperty(name="Texture array atlas", description="The material is stored in a texture array")
164         bpy.types.Material.array_layer = bpy.props.IntProperty("Texture array layer", description="Layer of the texture array atlas to use")
165         bpy.types.Material.material_atlas = bpy.props.BoolProperty(name="Material atlas", description="Make this material part of a material atlas")
166         bpy.types.Material.uniforms = bpy.props.CollectionProperty(type=MspGLUniform, name="Uniform", description="Uniform variables to add to the technique")
167         bpy.types.Material.active_uniform_index = bpy.props.IntProperty("Active uniform index")
168
169         bpy.types.ShaderNodeTexImage.default_filter = bpy.props.BoolProperty(name="Default filter", description="Let the loading program determine filtering options")
170         bpy.types.ShaderNodeTexImage.use_mipmap = bpy.props.BoolProperty(name="Use mipmaps", description="Use mipmaps (automatically generated) for the texture", default=True)
171         bpy.types.ShaderNodeTexImage.max_anisotropy = bpy.props.FloatProperty(name="Maximum anisotropy", description="Maximum anisotropy to use in texture filtering", min=1, max=16, default=1)
172
173 def unregister_properties():
174         for c in classes:
175                 bpy.utils.unregister_class(c)