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