]> git.tdb.fi Git - libs/gl.git/blob - blender/io_mspgl/properties.py
Check the flat qualifier from the correct member
[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 MspGLWorldProperties(bpy.types.Panel):
16         bl_idname = "WORLD_PT_mspgl_properties"
17         bl_label = "MspGL properties"
18         bl_space_type = "PROPERTIES"
19         bl_region_type = "WINDOW"
20         bl_context = "world"
21
22         def draw(self, context):
23                 world = context.scene.world
24                 if not world:
25                         return
26
27                 self.layout.prop(world, "use_sky")
28                 if world.use_sky:
29                         self.layout.prop(world, "sun_light")
30
31 class MspGLMeshProperties(bpy.types.Panel):
32         bl_idname = "MESH_PT_mspgl_properties"
33         bl_label = "MspGL properties"
34         bl_space_type = "PROPERTIES"
35         bl_region_type = "WINDOW"
36         bl_context = "data"
37
38         @classmethod
39         def poll(cls, context):
40                 return context.active_object.type=="MESH"
41
42         def draw(self, context):
43                 mesh = context.active_object.data
44
45                 self.layout.prop(mesh, "smoothing")
46                 self.layout.prop(mesh, "use_patches")
47                 if not mesh.use_patches:
48                         self.layout.prop(mesh, "use_strips")
49
50                 self.layout.separator()
51
52                 col = self.layout.column()
53                 col.label(text="Data selection")
54                 if not mesh.use_patches:
55                         col.prop(mesh, "use_lines")
56                 col.prop(mesh, "vertex_groups")
57                 col.prop(mesh, "max_groups_per_vertex")
58
59                 self.layout.separator()
60
61                 col = self.layout.column()
62                 col.label(text="Texturing")
63                 col.prop(mesh, "use_uv")
64                 col.prop(mesh, "tangent_vecs")
65                 col.prop(mesh, "tangent_uvtex")
66
67 class MspGLObjectProperties(bpy.types.Panel):
68         bl_idname = "OBJECT_PT_mspgl_properties"
69         bl_label = "MspGL properties"
70         bl_space_type = "PROPERTIES"
71         bl_region_type = "WINDOW"
72         bl_context = "object"
73
74         @classmethod
75         def poll(cls, context):
76                 return context.active_object.type=="MESH"
77
78         def draw(self, context):
79                 obj = context.active_object
80
81                 self.layout.prop(obj, "compound")
82                 self.layout.prop(obj, "lod_for_parent")
83                 if obj.lod_for_parent:
84                         self.layout.prop(obj, "lod_index")
85
86 class MspGLMaterialProperties(bpy.types.Panel):
87         bl_idname = "MATERIAL_PT_mspgl_properties"
88         bl_label = "MspGL properties"
89         bl_space_type = "PROPERTIES"
90         bl_region_type = "WINDOW"
91         bl_context = "material"
92
93         @classmethod
94         def poll(cls, context):
95                 return context.active_object.active_material is not None
96
97         def draw(self, context):
98                 mat = context.active_object.active_material
99                 if not mat:
100                         return
101
102                 self.layout.prop(mat, "render_mode")
103                 if mat.render_mode=='CUSTOM':
104                         self.layout.label(text="Render methods")
105                         self.layout.template_list("MATERIAL_UL_mspgl_render_methods", "", mat, "render_methods", mat, "active_render_method_index")
106                         row = self.layout.row()
107                         row.operator("material.add_render_method")
108                         row.operator("material.remove_render_method")
109
110                         if mat.active_render_method_index<len(mat.render_methods):
111                                 method = mat.render_methods[mat.active_render_method_index]
112                                 self.layout.prop(method, "tag")
113                                 self.layout.prop(method, "shader")
114                                 self.layout.prop(method, "use_material")
115
116                         self.layout.separator()
117                 elif mat.render_mode=='EXTERNAL':
118                         self.layout.prop(mat, "technique")
119                 if mat.render_mode=='BUILTIN':
120                         self.layout.prop(mat, "receive_shadows")
121                         self.layout.prop(mat, "image_based_lighting")
122                         self.layout.prop(mat, "instancing")
123                 self.layout.prop(mat, "array_atlas")
124                 if mat.array_atlas:
125                         self.layout.prop(mat, "array_layer")
126                 if mat.render_mode=='CUSTOM':
127                         self.layout.separator()
128                         self.layout.label(text="Uniform values")
129                         self.layout.template_list("MATERIAL_UL_mspgl_uniforms", "", mat, "uniforms", mat, "active_uniform_index")
130                         row = self.layout.row()
131                         row.operator("material.add_uniform")
132                         row.operator("material.remove_uniform")
133
134                         if mat.active_uniform_index<len(mat.uniforms):
135                                 uniform = mat.uniforms[mat.active_uniform_index]
136                                 self.layout.prop(uniform, "name")
137                                 self.layout.prop(uniform, "size")
138                                 row = self.layout.row(align=True)
139                                 row.label(text="Values")
140                                 for i in range(uniform.size):
141                                         row.prop(uniform, "values", text="", index=i)
142
143 class MspGLTextureNodeProperties(bpy.types.Panel):
144         bl_idname = "NODE_PT_mspgl_properties"
145         bl_label = "MspGL properties"
146         bl_space_type = "NODE_EDITOR"
147         bl_region_type = "UI"
148         bl_category = "Item"
149
150         @classmethod
151         def poll(cls, context):
152                 node = context.active_node
153                 return node and node.type=='TEX_IMAGE'
154
155         def draw(self, context):
156                 node = context.active_node
157                 if not node:
158                         return
159
160                 self.layout.prop(node, "use_mipmap")
161                 self.layout.prop(node, "max_anisotropy")
162
163 class MspGLLightProperties(bpy.types.Panel):
164         bl_idname = "LIGHT_PT_mspgl_properties"
165         bl_label = "MspGL properties"
166         bl_space_type = "PROPERTIES"
167         bl_region_type = "WINDOW"
168         bl_context = "data"
169
170         @classmethod
171         def poll(cls, context):
172                 return context.active_object.type=="LIGHT"
173
174         def draw(self, context):
175                 light = context.active_object.data
176
177                 if light.use_shadow:
178                         self.layout.prop(light, "shadow_map_size")
179
180 class MspGLRenderProperties(bpy.types.Panel):
181         bl_idname = "RENDER_PT_mspgl_properties"
182         bl_label = "MspGL properties"
183         bl_space_type = "PROPERTIES"
184         bl_region_type = "WINDOW"
185         bl_context = "render"
186
187         def draw(self, context):
188                 scene = context.scene
189                 self.layout.prop(scene, "use_hdr")
190                 if scene.eevee.use_gtao:
191                         self.layout.prop(scene, "ao_samples")
192
193 class MspGLRenderMethod(bpy.types.PropertyGroup):
194         tag: bpy.props.StringProperty(name="Tag", description="Tag of the render method")
195         shader: bpy.props.StringProperty(name="Shader", description="Shader to use")
196         use_material: bpy.props.BoolProperty(name="Use material", description="Use material properties in this render method")
197
198 class MspGLRenderMethodList(bpy.types.UIList):
199         bl_idname = "MATERIAL_UL_mspgl_render_methods"
200
201         def draw_item(self, context, layout, data, item, icon, active_data, active_propname):
202                 method = item
203                 if self.layout_type=="GRID":
204                         layout.label(text="", icon_value=icon)
205                 else:
206                         layout.prop(method, "tag", text="", emboss=False, icon_value=icon)
207                         layout.label(text=(method.shader or "(no shader)"))
208
209 class MspGLUniform(bpy.types.PropertyGroup):
210         name: bpy.props.StringProperty(name="Name", description="Name of the uniform variable")
211         size: bpy.props.IntProperty(name="Size", description="Number of elements in the uniform", min=1, max=4, default=4)
212         values: bpy.props.FloatVectorProperty(name="Values", description="Values stored in the uniform", size=4)
213
214 class MspGLUniformList(bpy.types.UIList):
215         bl_idname = "MATERIAL_UL_mspgl_uniforms"
216
217         def draw_item(self, context, layout, data, item, icon, active_data, active_propname):
218                 uniform = item
219                 if self.layout_type=="GRID":
220                         layout.label(text="", icon_value=icon)
221                 else:
222                         layout.prop(uniform, "name", text="", emboss=False, icon_value=icon)
223                         layout.label(text="({})".format(", ".join("{:.3f}".format(v) for v in uniform.values[:uniform.size])))
224
225 classes = [MspGLSceneProperties, MspGLWorldProperties, MspGLMeshProperties, MspGLObjectProperties, MspGLMaterialProperties,
226         MspGLTextureNodeProperties, MspGLLightProperties, MspGLRenderProperties, MspGLRenderMethod,
227         MspGLRenderMethodList, MspGLUniform, MspGLUniformList]
228
229 def register_properties():
230         for c in classes:
231                 bpy.utils.register_class(c)
232
233         bpy.types.Scene.export_disposition = bpy.props.EnumProperty(name="Export disposition", description="What to do with this scene during project export", default="IGNORE",
234                 items=(("IGNORE", "Ignore", "The scene won't be exported"),
235                         ("CONTENTS", "Contents only", "Objects in the scene will be exported, but not the scene itself"),
236                         ("SCENE", "Scene", "The scene will be exported"),
237                         ("SEQUENCE", "Sequence", "The scene will be exported along with a rendering sequence")))
238         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)
239         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)
240
241         bpy.types.World.use_sky = bpy.props.BoolProperty(name="Realtime sky", description="Use a realtime rendered sky background", default=False)
242         bpy.types.World.sun_light = bpy.props.PointerProperty(type=bpy.types.Light, name="Sun", description="Light to use as sun for the sky")
243
244         bpy.types.Mesh.smoothing = bpy.props.EnumProperty(name="Smoothing", description="Smoothing method to use", default="MSPGL",
245                 items=(("NONE", "None", "No smoothing"),
246                         ("BLENDER", "Blender", "Use Blender's vertex normals"),
247                         ("MSPGL", "MspGL", "Compute vertex normals internally")))
248         bpy.types.Mesh.use_lines = bpy.props.BoolProperty(name="Include lines", description="Include edges without faces as lines", default=False)
249         bpy.types.Mesh.use_strips = bpy.props.BoolProperty(name="Use strips", description="Combine the mesh's triangles into triangle strips", default=True)
250         bpy.types.Mesh.use_patches = bpy.props.BoolProperty(name="Export as patches", description="Export faces as patches, suitable for tessellation", default=False)
251         bpy.types.Mesh.vertex_groups = bpy.props.BoolProperty(name="Vertex groups", description="Include vertex groups and weights", default=False)
252         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)
253         bpy.types.Mesh.use_uv = bpy.props.EnumProperty(name="Use UV", description="Use UV coordinates", default="UNIT0",
254                 items=(("NONE", "None", "Ignore all UV coordinates"),
255                         ("UNIT0", "Unit 0", "Use UV coordinates for unit 0"),
256                         ("ALL", "All", "Use all UV coordinates")))
257         bpy.types.Mesh.tangent_vecs = bpy.props.EnumProperty(name="Tangent vectors", description="Compute tangent vectors for vertices", default="AUTO",
258                 items=(("NO", "No", "Do not export tangent vectors"),
259                         ("AUTO", "Auto", "Automatically determine the need for tangent vectors"),
260                         ("YES", "Yes", "Always export tangent vectors")))
261         bpy.types.Mesh.tangent_uvtex = bpy.props.StringProperty(name="Tangent UV layer", description="UV layer to use as basis for tangent vectors", default="")
262
263         bpy.types.Object.compound = bpy.props.BoolProperty(name="Compound with parent", description="Join this object to its parent when exporting")
264         bpy.types.Object.lod_for_parent = bpy.props.BoolProperty(name="LoD for parent", description="This object is a level of detail for its parent")
265         bpy.types.Object.lod_index = bpy.props.IntProperty(name="LoD index", description="Index of the level of detail", min=1, max=16, default=1)
266
267         bpy.types.Material.render_mode = bpy.props.EnumProperty(name="Render mode", description="How this material should be rendered", default="BUILTIN",
268                 items=(("BUILTIN", "Built-in", "Use built-in shaders"),
269                         ("CUSTOM", "Custom shaders", "Use custom shaders"),
270                         ("EXTERNAL", "External technique", "Use an externally defined technique")))
271         bpy.types.Material.technique = bpy.props.StringProperty(name="Custom technique", description="Name of an external technique to use for rendering")
272         bpy.types.Material.render_methods = bpy.props.CollectionProperty(type=MspGLRenderMethod, name="Render methods", description="Custom render methods to use for rendering")
273         bpy.types.Material.active_render_method_index = bpy.props.IntProperty("Active render method index")
274         bpy.types.Material.receive_shadows = bpy.props.BoolProperty(name="Receive shadows", description="Receive shadows from a shadow map", default=True)
275         bpy.types.Material.image_based_lighting = bpy.props.BoolProperty(name="Image based lighting", description="Use an environment map for ambient lighting", default=False)
276         bpy.types.Material.instancing = bpy.props.BoolProperty(name="Instanced rendering", description="Use instanced draw calls for objects with this material", default=False)
277         bpy.types.Material.array_atlas = bpy.props.BoolProperty(name="Texture array atlas", description="The material is stored in a texture array")
278         bpy.types.Material.array_layer = bpy.props.IntProperty("Texture array layer", description="Layer of the texture array atlas to use")
279         bpy.types.Material.uniforms = bpy.props.CollectionProperty(type=MspGLUniform, name="Uniforms", description="Uniform variables to add to the technique")
280         bpy.types.Material.active_uniform_index = bpy.props.IntProperty("Active uniform index")
281
282         bpy.types.ShaderNodeTexImage.use_mipmap = bpy.props.BoolProperty(name="Use mipmaps", description="Use mipmaps (automatically generated) for the texture", default=True)
283         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)
284
285         bpy.types.Light.shadow_map_size = bpy.props.EnumProperty(name="Shadow map size", description="Size of shadow map to use for rendering shadows", default="4096",
286                 items=(("256", "256", ""),
287                         ("512", "512", ""),
288                         ("1024", "1024", ""),
289                         ("2048", "2048", ""),
290                         ("4096", "4096", ""),
291                         ("8192", "8192", ""),
292                         ("16384", "16384", "")))
293
294 def unregister_properties():
295         for c in classes:
296                 bpy.utils.unregister_class(c)