]> git.tdb.fi Git - libs/gl.git/blob - blender/io_mspgl/properties.py
Remove the scene type property from Blender exporter
[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, "export_disposition")
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.label(text="Render methods")
87                         self.layout.template_list("MATERIAL_UL_mspgl_render_methods", "", mat, "render_methods", mat, "active_render_method_index")
88                         row = self.layout.row()
89                         row.operator("material.add_render_method")
90                         row.operator("material.remove_render_method")
91
92                         if mat.active_render_method_index<len(mat.render_methods):
93                                 method = mat.render_methods[mat.active_render_method_index]
94                                 self.layout.prop(method, "tag")
95                                 self.layout.prop(method, "shader")
96                                 self.layout.prop(method, "use_material")
97
98                         self.layout.separator()
99                 elif mat.render_mode=='EXTERNAL':
100                         self.layout.prop(mat, "technique")
101                 if mat.render_mode=='BUILTIN':
102                         self.layout.prop(mat, "receive_shadows")
103                         self.layout.prop(mat, "image_based_lighting")
104                 self.layout.prop(mat, "array_atlas")
105                 if mat.array_atlas:
106                         self.layout.prop(mat, "array_layer")
107                 if mat.render_mode!='EXTERNAL':
108                         self.layout.prop(mat, "material_atlas")
109                 if mat.render_mode=='CUSTOM':
110                         self.layout.separator()
111                         self.layout.label(text="Uniform values")
112                         self.layout.template_list("MATERIAL_UL_mspgl_uniforms", "", mat, "uniforms", mat, "active_uniform_index")
113                         row = self.layout.row()
114                         row.operator("material.add_uniform")
115                         row.operator("material.remove_uniform")
116
117                         if mat.active_uniform_index<len(mat.uniforms):
118                                 uniform = mat.uniforms[mat.active_uniform_index]
119                                 self.layout.prop(uniform, "name")
120                                 self.layout.prop(uniform, "size")
121                                 row = self.layout.row(align=True)
122                                 row.label(text="Values")
123                                 for i in range(uniform.size):
124                                         row.prop(uniform, "values", text="", index=i)
125
126 class MspGLTextureNodeProperties(bpy.types.Panel):
127         bl_idname = "NODE_PT_mspgl_properties"
128         bl_label = "MspGL properties"
129         bl_space_type = "NODE_EDITOR"
130         bl_region_type = "UI"
131         bl_category = "Item"
132
133         @classmethod
134         def poll(cls, context):
135                 node = context.active_node
136                 return node and node.type=='TEX_IMAGE'
137
138         def draw(self, context):
139                 node = context.active_node
140                 if not node:
141                         return
142
143                 self.layout.prop(node, "use_mipmap")
144                 self.layout.prop(node, "max_anisotropy")
145
146 class MspGLRenderProperties(bpy.types.Panel):
147         bl_idname = "WORLD_PT_mspgl_properties"
148         bl_label = "MspGL properties"
149         bl_space_type = "PROPERTIES"
150         bl_region_type = "WINDOW"
151         bl_context = "render"
152
153         def draw(self, context):
154                 scene = context.scene
155                 self.layout.prop(scene, "use_hdr")
156                 if scene.eevee.use_gtao:
157                         self.layout.prop(scene, "ao_samples")
158
159 class MspGLRenderMethod(bpy.types.PropertyGroup):
160         tag: bpy.props.StringProperty(name="Tag", description="Tag of the render method")
161         shader: bpy.props.StringProperty(name="Shader", description="Shader to use")
162         use_material: bpy.props.BoolProperty(name="Use material", description="Use material properties in this render method")
163
164 class MspGLRenderMethodList(bpy.types.UIList):
165         bl_idname = "MATERIAL_UL_mspgl_render_methods"
166
167         def draw_item(self, context, layout, data, item, icon, active_data, active_propname):
168                 method = item
169                 if self.layout_type=="GRID":
170                         layout.label(text="", icon_value=icon)
171                 else:
172                         layout.prop(method, "tag", text="", emboss=False, icon_value=icon)
173                         layout.label(text=(method.shader or "(no shader)"))
174
175 class MspGLUniform(bpy.types.PropertyGroup):
176         name: bpy.props.StringProperty(name="Name", description="Name of the uniform variable")
177         size: bpy.props.IntProperty(name="Size", description="Number of elements in the uniform", min=1, max=4, default=4)
178         values: bpy.props.FloatVectorProperty(name="Values", description="Values stored in the uniform", size=4)
179
180 class MspGLUniformList(bpy.types.UIList):
181         bl_idname = "MATERIAL_UL_mspgl_uniforms"
182
183         def draw_item(self, context, layout, data, item, icon, active_data, active_propname):
184                 uniform = item
185                 if self.layout_type=="GRID":
186                         layout.label(text="", icon_value=icon)
187                 else:
188                         layout.prop(uniform, "name", text="", emboss=False, icon_value=icon)
189                         layout.label(text="({})".format(", ".join("{:.3f}".format(v) for v in uniform.values[:uniform.size])))
190
191 classes = [MspGLSceneProperties, MspGLMeshProperties, MspGLObjectProperties, MspGLMaterialProperties,
192         MspGLTextureNodeProperties, MspGLLightProperties, MspGLRenderProperties, MspGLRenderMethod,
193         MspGLRenderMethodList, MspGLUniform, MspGLUniformList]
194
195 def register_properties():
196         for c in classes:
197                 bpy.utils.register_class(c)
198
199         bpy.types.Scene.export_disposition = bpy.props.EnumProperty(name="Export disposition", description="What to do with this scene during project export", default="IGNORE",
200                 items=(("IGNORE", "Ignore", "The scene won't be exported"),
201                         ("CONTENTS", "Contents only", "Objects in the scene will be exported, but not the scene itself"),
202                         ("SCENE", "Scene", "The scene will be exported"),
203                         ("SEQUENCE", "Sequence", "The scene will be exported along with a rendering sequence")))
204         bpy.types.Scene.use_hdr = bpy.props.BoolProperty(name="High dynamic range", description="Use a range render target with a floating point format", default=False)
205         bpy.types.Scene.ao_samples = bpy.props.IntProperty(name="Ambient occlusion samples", description="Number of samples to use for ambient occlusion", min=8, max=128, default=32)
206
207         bpy.types.Mesh.winding_test = bpy.props.BoolProperty(name="Winding test", description="Perform winding test to skip back faces")
208         bpy.types.Mesh.smoothing = bpy.props.EnumProperty(name="Smoothing", description="Smoothing method to use", default="MSPGL",
209                 items=(("NONE", "None", "No smoothing"),
210                         ("BLENDER", "Blender", "Use Blender's vertex normals"),
211                         ("MSPGL", "MspGL", "Compute vertex normals internally")))
212         bpy.types.Mesh.use_lines = bpy.props.BoolProperty(name="Include lines", description="Include edges without faces as lines", default=False)
213         bpy.types.Mesh.use_strips = bpy.props.BoolProperty(name="Use strips", description="Combine the mesh's triangles into triangle strips", default=True)
214         bpy.types.Mesh.vertex_groups = bpy.props.BoolProperty(name="Vertex groups", description="Include vertex groups and weights", default=False)
215         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)
216         bpy.types.Mesh.use_uv = bpy.props.EnumProperty(name="Use UV", description="Use UV coordinates", default="UNIT0",
217                 items=(("NONE", "None", "Ignore all UV coordinates"),
218                         ("UNIT0", "Unit 0", "Use UV coordinates for unit 0"),
219                         ("ALL", "All", "Use all UV coordinates")))
220         bpy.types.Mesh.tangent_vecs = bpy.props.EnumProperty(name="Tangent vectors", description="Compute tangent vectors for vertices", default="AUTO",
221                 items=(("NO", "No", "Do not export tangent vectors"),
222                         ("AUTO", "Auto", "Automatically determine the need for tangent vectors"),
223                         ("YES", "Yes", "Always export tangent vectors")))
224         bpy.types.Mesh.tangent_uvtex = bpy.props.StringProperty(name="Tangent UV layer", description="UV layer to use as basis for tangent vectors", default="")
225
226         bpy.types.Object.compound = bpy.props.BoolProperty(name="Compound with parent", description="Join this object to its parent when exporting")
227         bpy.types.Object.lod_for_parent = bpy.props.BoolProperty(name="LoD for parent", description="This object is a level of detail for its parent")
228         bpy.types.Object.lod_index = bpy.props.IntProperty(name="LoD index", description="Index of the level of detail", min=1, max=16, default=1)
229
230         bpy.types.Material.render_mode = bpy.props.EnumProperty(name="Render mode", description="How this material should be rendered", default="BUILTIN",
231                 items=(("BUILTIN", "Built-in", "Use built-in shaders"),
232                         ("CUSTOM", "Custom shaders", "Use custom shaders"),
233                         ("EXTERNAL", "External technique", "Use an externally defined technique")))
234         bpy.types.Material.technique = bpy.props.StringProperty(name="Custom technique", description="Name of an external technique to use for rendering")
235         bpy.types.Material.render_methods = bpy.props.CollectionProperty(type=MspGLRenderMethod, name="Render methods", description="Custom render methods to use for rendering")
236         bpy.types.Material.active_render_method_index = bpy.props.IntProperty("Active render method index")
237         bpy.types.Material.receive_shadows = bpy.props.BoolProperty(name="Receive shadows", description="Receive shadows from a shadow map", default=True)
238         bpy.types.Material.image_based_lighting = bpy.props.BoolProperty(name="Image based lighting", description="Use an environment map for ambient lighting", default=False)
239         bpy.types.Material.array_atlas = bpy.props.BoolProperty(name="Texture array atlas", description="The material is stored in a texture array")
240         bpy.types.Material.array_layer = bpy.props.IntProperty("Texture array layer", description="Layer of the texture array atlas to use")
241         bpy.types.Material.material_atlas = bpy.props.BoolProperty(name="Material atlas", description="Make this material part of a material atlas")
242         bpy.types.Material.uniforms = bpy.props.CollectionProperty(type=MspGLUniform, name="Uniforms", description="Uniform variables to add to the technique")
243         bpy.types.Material.active_uniform_index = bpy.props.IntProperty("Active uniform index")
244
245         bpy.types.ShaderNodeTexImage.use_mipmap = bpy.props.BoolProperty(name="Use mipmaps", description="Use mipmaps (automatically generated) for the texture", default=True)
246         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)
247
248 def unregister_properties():
249         for c in classes:
250                 bpy.utils.unregister_class(c)