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