From: Mikko Rasa Date: Tue, 30 Apr 2019 22:00:22 +0000 (+0300) Subject: Move most properties from exporters to the relevant types X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=9d8e4aa5a9573b34fe06455af249c762433d47c0;p=libs%2Fgl.git Move most properties from exporters to the relevant types These properties pertain to the things being exported and should retain their values between exports. It's getting especially difficult to specify object-specific properties when exporting an entire scene. --- diff --git a/blender/io_mspgl/__init__.py b/blender/io_mspgl/__init__.py index 0731c32f..a3bedab5 100644 --- a/blender/io_mspgl/__init__.py +++ b/blender/io_mspgl/__init__.py @@ -36,26 +36,11 @@ class ExportMspGLMeshBase(ExportMspGLBase): max_strip_len = bpy.props.IntProperty(name="Max strip length", description="Maximum length for a triangle strip", default=1024, min=4, max=16384) optimize_cache = bpy.props.BoolProperty(name="Optimize cache", description="Optimize element order for vertex cache", default=True) cache_size = bpy.props.IntProperty(name="Cache size", description="Simulated vertex cache size used in optimization", default=64, min=8, max=1024) - export_lines = bpy.props.BoolProperty(name="Export lines", description="Export edges without faces as lines", default=False) - export_uv = bpy.props.EnumProperty(name="Export UV", description="Export UV coordinates", default="UNIT0", - items=(("NONE", "None", "No UV coordinates are exported"), - ("UNIT0", "Unit 0", "UV coordinates for unit 0 are exported"), - ("ALL", "All", "All UV coordinates are exported"))) - tbn_vecs = bpy.props.BoolProperty(name="TBN vectors", description="Compute tangent and binormal vectors for vertices", default=False) - tbn_uvtex = bpy.props.StringProperty(name="TBN UV layer", description="UV layer to use as basis for TBN vectors", default="") compound = bpy.props.BoolProperty(name="Compound", description="Combine all selected objects into one for exporting", default=False) - smoothing = bpy.props.EnumProperty(name="Smoothing", description="Smoothing method to use", default="MSPGL", - items=(("NONE", "None", "No smoothing"), - ("BLENDER", "Blender", "Use Blender's vertex normals"), - ("MSPGL", "MspGL", "Compute vertex normals internally"))) - export_groups = bpy.props.BoolProperty(name="Vertex groups", description="Export vertex groups and weights", default=False) def draw(self, context): col = self.layout.column() - col.prop(self, "export_lines") col.prop(self, "compound") - col.prop(self, "smoothing") - col.prop(self, "export_groups") self.general_col = col self.layout.separator() @@ -68,15 +53,6 @@ class ExportMspGLMeshBase(ExportMspGLBase): self.layout.separator() - col = self.layout.column() - col.label("Texturing") - col.prop(self, "export_uv") - col.prop(self, "tbn_vecs") - col.prop(self, "tbn_uvtex") - self.texturing_col = col - - self.layout.separator() - col = self.layout.column() col.label("Vertex cache") col.prop(self, "optimize_cache") @@ -104,8 +80,6 @@ class ExportMspGLObject(bpy.types.Operator, ExportMspGLMeshBase): items=(("NONE", "None", "Ignore textures"), ("REF", "Referenced", "Reference external data"), ("INLINE", "Inline", "Embed textures in the object"))) - material_tex = bpy.props.BoolProperty(name="Material texture", description="Generate a texture based on material colors", default=False) - srgb_colors = bpy.props.BoolProperty(name="sRGB colors", description="Export material colors as sRGB instead of linear", default=True) separate_mesh = bpy.props.BoolProperty(name="Separate mesh", description="Write mesh data into a separate file", default=False) shared_mesh = bpy.props.BoolProperty(name="Shared mesh", description="Use mesh name for mesh file to enable sharing", default=True) @@ -124,11 +98,7 @@ class ExportMspGLObject(bpy.types.Operator, ExportMspGLMeshBase): col = self.general_col col.prop(self, "external_tech") col.prop(self, "export_lods") - - col = self.texturing_col col.prop(self, "textures") - col.prop(self, "material_tex") - col.prop(self, "srgb_colors") self.layout.separator(); diff --git a/blender/io_mspgl/export_mesh.py b/blender/io_mspgl/export_mesh.py index 541874b2..3873bf32 100644 --- a/blender/io_mspgl/export_mesh.py +++ b/blender/io_mspgl/export_mesh.py @@ -41,15 +41,8 @@ class MeshExporter: self.max_strip_len = 1024 self.optimize_cache = True self.cache_size = 64 - self.export_lines = False - self.export_uv = "UNIT0" - self.tbn_vecs = False - self.tbn_uvtex = "" self.compound = False self.material_tex = False - self.smoothing = "MSPGL" - self.export_groups = False - self.max_groups = 2 def stripify(self, mesh, progress=None): for f in mesh.faces: @@ -237,6 +230,8 @@ class MeshExporter: for o, m in objs: if o.data.winding_test: winding_test = True + if o.material_tex: + self.material_tex = True bmesh = o.to_mesh(context.scene, True, "PREVIEW") bmeshes.append(bmesh) me = Mesh(bmesh) @@ -248,15 +243,15 @@ class MeshExporter: if progress: progress.set_task("Smoothing", 0.05, 0.35) - if self.smoothing=="NONE": + if mesh.smoothing=="NONE": mesh.flatten_faces() mesh.split_smooth(progress) - if self.smoothing!="BLENDER": + if mesh.smoothing!="BLENDER": mesh.compute_normals() - if self.export_groups: - mesh.sort_vertex_groups(self.max_groups) + if mesh.vertex_groups: + mesh.sort_vertex_groups(mesh.max_groups_per_vertex) # Create a mapping from vertex group indices to bone indices first_obj = objs[0][0] @@ -273,9 +268,9 @@ class MeshExporter: texunits = [] force_unit0 = False - if mesh.uv_layers and (self.export_uv!="NONE" or self.material_tex): + if mesh.uv_layers and (mesh.use_uv!="NONE" or self.material_tex): # Figure out which UV layers to export - if self.export_uv=="ALL": + if mesh.use_uv=="ALL": texunits = range(len(mesh.uv_layers)) elif self.material_tex: # The material UV layer is always the last one @@ -289,11 +284,11 @@ class MeshExporter: texunits = [(i, mesh.uv_layers[i]) for i in texunits] texunits = [u for u in texunits if not u[1].hidden] - if self.tbn_vecs: + if mesh.tbn_vecs: # TBN coordinates must be generated before vertices are split by any other layer uv_names = [u.name for i, u in texunits] - if self.tbn_uvtex in uv_names: - tbn_index = uv_names.index(self.tbn_uvtex) + if mesh.tbn_uvtex in uv_names: + tbn_index = uv_names.index(mesh.tbn_uvtex) unit = texunits[tbn_index] del texunits[tbn_index] texunits.insert(0, unit) @@ -302,7 +297,7 @@ class MeshExporter: if progress: progress.set_task("Splitting UVs", 0.35+0.3*i/len(texunits), 0.35+0.3*(i+1)/len(texunits)) mesh.split_uv(i, progress) - if self.tbn_vecs and u.name==self.tbn_uvtex: + if mesh.tbn_vecs and u.name==mesh.tbn_uvtex: mesh.compute_uv() mesh.compute_tbn(i) @@ -329,10 +324,10 @@ class MeshExporter: fmt.append("TEXCOORD"+size) else: fmt.append("TEXCOORD%s_%d"%(size, u.unit)) - if self.tbn_vecs: + if mesh.tbn_vecs: fmt += ["TANGENT3", "BINORMAL3"] - if self.export_groups: - fmt.append("ATTRIB%d_5"%(self.max_groups*2)) + if mesh.vertex_groups: + fmt.append("ATTRIB%d_5"%(mesh.max_groups_per_vertex*2)) fmt.append("VERTEX3") out_file.begin("vertices", *fmt) normal = None @@ -352,16 +347,16 @@ class MeshExporter: else: out_file.write("multitexcoord"+size, u.unit, *v.uvs[i]) uvs[i] = v.uvs[i] - if self.tbn_vecs: + if mesh.tbn_vecs: if v.tan!=tan: out_file.write("tangent3", *v.tan) tan = v.tan if v.bino!=bino: out_file.write("binormal3", *v.bino) bino = v.bino - if self.export_groups: - group_attr = [(group_index_map[g.group], g.weight*v.group_weight_scale) for g in v.groups[:self.max_groups]] - while len(group_attr)