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