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