def list_errors(self, menu, context): l = menu.layout if len(self.log_errors): for msg in self.log_errors: l.label("{}: {}".format(pgettext("Error").upper(), msg)) l.separator() if len(self.log_warnings): for msg in self.log_warnings: l.label("{}: {}".format(pgettext("Warning").upper(), msg))
def message_box(title="Message Box", message="", icon="INFO"): def draw(self, context): self.layout.label(text=message) bpy.context.window_manager.popup_menu(draw, title=translations.pgettext(title), icon=icon)
def make_export_list(): s = bpy.context.scene s.vs.export_list.clear() def makeDisplayName(item, name=None): return os.path.join(item.vs.subdir if item.vs.subdir != "." else None, (name if name else item.name) + getFileExt()) if len(p_cache.validObs): ungrouped_objects = p_cache.validObs.copy() groups_sorted = bpy.data.groups[:] groups_sorted.sort(key=lambda g: g.name.lower()) scene_groups = [] for group in groups_sorted: valid = False for object in [ob for ob in group.objects if ob in p_cache.validObs]: if not group.vs.mute and object.type != 'ARMATURE' and object in ungrouped_objects: ungrouped_objects.remove(object) valid = True if valid: scene_groups.append(group) for g in scene_groups: i = s.vs.export_list.add() if g.vs.mute: i.name = "{} {}".format(g.name, pgettext(get_id("exportables_group_mute_suffix", True))) else: i.name = makeDisplayName(g) i.item_name = g.name i.icon = i.ob_type = "GROUP" ungrouped_objects = list(ungrouped_objects) ungrouped_objects.sort(key=lambda ob: ob.name.lower()) for ob in ungrouped_objects: if ob.type == 'FONT': ob.vs.triangulate = True # preserved if the user converts to mesh i_name = i_type = i_icon = None if ob.type == 'ARMATURE': ad = ob.animation_data if ad: i_icon = i_type = "ACTION" if ob.data.vs.action_selection == 'FILTERED': i_name = get_id("exportables_arm_filter_result", True).format(ob.vs.action_filter, len(actionsForFilter(ob.vs.action_filter))) elif ad.action: i_name = makeDisplayName(ob, ad.action.name) elif len(ad.nla_tracks): i_name = makeDisplayName(ob) i_icon = "NLA" else: i_name = makeDisplayName(ob) i_icon = MakeObjectIcon(ob, prefix="OUTLINER_OB_") i_type = "OBJECT" if i_name: i = s.vs.export_list.add() i.name = i_name i.ob_type = i_type i.icon = i_icon i.item_name = ob.name
def get_id(id, format_string=False, data=False): out = p_cache.ids[id] if format_string or ( data and bpy.context.preferences.view.use_translate_new_dataname): return pgettext(out) else: return out
def draw(self, context): cpc_scene_properties = context.scene.cpc_scene_properties if not cpc_scene_properties.script_is_executed: layout = self.layout layout.label("Image Size") layout.prop(cpc_scene_properties, "image_size", text="") layout.row().separator() row = layout.row() row.scale_y = 2.0 row.operator(InitProjectOperator.bl_idname, text=pgettext(InitProjectOperator.bl_label), icon='LOAD_FACTORY') return layout = self.layout col = layout.column(align=True) col.prop(cpc_scene_properties, "material_type", text="") col = layout.column(align=True) col.operator(AddCurveTool.bl_idname, icon='CURVE_BEZCIRCLE') col.operator(AddMeshTool.bl_idname, icon='MESH_GRID') layout.row().separator() col = layout.column(align=True) row = col.row(align=True) row.operator(UpObject.bl_idname, icon='TRIA_UP') row.operator(DownObject.bl_idname, icon='TRIA_DOWN') col.prop(cpc_scene_properties, "slide") col.operator(ResetObject.bl_idname, icon='X') col = layout.column(align=True) col.label(text="Group:") col.operator("group.create", text="New Group") col.operator("group.objects_add_active", text="Add to Active") col.operator("group.objects_remove", text="Remove from Group") props = col.operator("object.select_grouped", text="Grouped") props.type = 'GROUP' layout.row().separator() if context.object is not None: obj = context.object if obj.type == 'CURVE': layout.prop(obj.data, "resolution_u") elif obj.type =='MESH': if "cpc_subsurf" in obj.modifiers: mod = obj.modifiers["cpc_subsurf"] layout.label(text="Subdivisions:") layout.prop(mod, "levels") if obj.type =='MESH' or obj.type == 'CURVE': mat = obj.active_material if "cpc_color_node" in mat.node_tree.nodes: node = mat.node_tree.nodes["cpc_color_node"] out = node.outputs[0] layout.label(text="Color:") layout.prop(out, "default_value", text="")
def draw(self, context): pbi_scene_properties = context.scene.pbi_scene_properties row = self.layout.row() row.scale_y = 2.0 row.operator(importer.ImportPMXBones.bl_idname, text=pgettext(importer.ImportPMXBones.bl_label), icon='IMPORT') layout = self.layout layout.prop(pbi_scene_properties, "test_prop")
def readSMD(self, filepath, upAxis, rotMode, newscene=False, smd_type=None, target_layer=0): if filepath.endswith("dmx"): return self.readDMX(filepath, upAxis, newscene, smd_type) smd = self.initSMD(filepath, smd_type, upAxis, rotMode, target_layer) self.appliedReferencePose = False try: smd.file = file = open(filepath, 'r') except IOError as err: # TODO: work out why errors are swallowed if I don't do this! self.error( get_id("importer_err_smd", True).format(smd.jobName, err)) return 0 if newscene: # BLENDER BUG: this currently doesn't update bpy.context.scene bpy.context.screen.scene = bpy.data.scenes.new(smd.jobName) elif bpy.context.scene.name == pgettext("Scene"): bpy.context.scene.name = smd.jobName print("\nSMD IMPORTER: now working on", smd.jobName) while True: header = self.parseQuoteBlockedLine(file.readline()) if header: break if header != ["version", "1"]: self.warning(get_id("importer_err_smd_ver")) if smd.jobType is None: # What are we dealing with? self.scanSMD() for line in file: if line == "nodes\n": self.readNodes() if line == "skeleton\n": self.readFrames() if line == "triangles\n": self.readPolys() if line == "vertexanimation\n": self.readShapes() file.close() printTimeMessage(smd.startTime, smd.jobName, "import") return 1
def truncate_id_name(self, name, id_type): truncated = bytes(name, 'utf8') if len(truncated) < 64: return name truncated = truncated[:63] while truncated: try: truncated = truncated.decode('utf8') break except UnicodeDecodeError: truncated = truncated[:-1] self.error( get_id( "importer_err_namelength", True ).format( pgettext( id_type if isinstance(id_type, str) else id_type.__name__), name, truncated)) return truncated
def GetCustomPropName(data, prop, suffix=""): return "".join([pgettext(getattr(type(data), prop)[1]["name"]), suffix])
def make_export_list(): s = bpy.context.scene s.vs.export_list.clear() def makeDisplayName(item, name=None): return os.path.join(item.vs.subdir if item.vs.subdir != "." else "", (name if name else item.name) + getFileExt()) if len(p_cache.validObs): ungrouped_objects = p_cache.validObs.copy() groups_sorted = bpy.data.groups[:] groups_sorted.sort(key=lambda g: g.name.lower()) scene_groups = [] for group in groups_sorted: valid = False for object in [ ob for ob in group.objects if ob in p_cache.validObs ]: if not group.vs.mute and object.type != 'ARMATURE' and object in ungrouped_objects: ungrouped_objects.remove(object) valid = True if valid: scene_groups.append(group) for g in scene_groups: i = s.vs.export_list.add() if g.vs.mute: i.name = "{} {}".format( g.name, pgettext(get_id("exportables_group_mute_suffix", True))) else: i.name = makeDisplayName(g) i.item_name = g.name i.icon = i.ob_type = "GROUP" ungrouped_objects = list(ungrouped_objects) ungrouped_objects.sort(key=lambda ob: ob.name.lower()) for ob in ungrouped_objects: if ob.type == 'FONT': ob.vs.triangulate = True # preserved if the user converts to mesh i_name = i_type = i_icon = None if ob.type == 'ARMATURE': ad = ob.animation_data if ad: i_icon = i_type = "ACTION" if ob.data.vs.action_selection == 'FILTERED': i_name = get_id( "exportables_arm_filter_result", True).format( ob.vs.action_filter, len(actionsForFilter(ob.vs.action_filter))) elif ad.action: i_name = makeDisplayName(ob, ad.action.name) elif len(ad.nla_tracks): i_name = makeDisplayName(ob) i_icon = "NLA" else: i_name = makeDisplayName(ob) i_icon = MakeObjectIcon(ob, prefix="OUTLINER_OB_") i_type = "OBJECT" if i_name: i = s.vs.export_list.add() i.name = i_name i.ob_type = i_type i.icon = i_icon i.item_name = ob.name
def GetCustomPropName(data, prop, suffix=""): return "".join([pgettext(getattr(type(data), prop)[1]['name']), suffix])
def GetCustomPropName(data, prop, suffix=""): '''Looks up the name of the bpy property associated with the given property name''' import typing return "".join( [pgettext(typing.get_type_hints(type(data))[prop][1]['name']), suffix])
def readPolys(self): smd = self.smd if smd.jobType not in [REF, PHYS]: return mesh_name = smd.jobName if (smd.jobType == REF and not smd.jobName.lower().find("reference") and not smd.jobName.lower().endswith("ref")): mesh_name += " ref" mesh_name = self.truncate_id_name(mesh_name, bpy.types.Mesh) # Create a new mesh object, # disable double-sided rendering, # link it to the current scene smd.m = bpy.data.objects.new(mesh_name, bpy.data.meshes.new(mesh_name)) smd.m.parent = smd.a smd.g.objects.link(smd.m) if smd.jobType == REF: # can only have flex on a ref mesh if self.qc: # for VTA import self.qc.ref_mesh = smd.m # Create weightmap groups for bone in smd.a.data.bones.values(): smd.m.vertex_groups.new(name=bone.name) # Apply armature modifier modifier = smd.m.modifiers.new( type="ARMATURE", name=pgettext("Armature")) modifier.object = smd.a # Initialisation md = smd.m.data # unused lastWindowUpdate = time.time() # Vertex values norms = [] bm = bmesh.new() bm.from_mesh(md) weightLayer = bm.verts.layers.deform.new() uvLayer = bm.loops.layers.uv.new() # ************************************************************************************************* # There are two loops in this function: # one for polygons which continues until the "end" keyword # and one for the vertices on each polygon that loops three times. # We're entering the poly one now. countPolys = 0 badWeights = 0 vertMap = {} allVertexWeights = set() # unused WeightLink = collections.namedtuple("WeightLink", ["group", "weight"]) for line in smd.file: line = line.rstrip("\n") if line and smdBreak(line): # normally a blank line means a break, # but Milkshape can export SMDs with # zero-length material names... break if smdContinue(line): continue mat, mat_ind = self.getMeshMaterial( line if line else pgettext(get_id("importer_name_nomat", data=True))) # *************************************************************** # Enter the vertex loop. This will run three times for each poly. vertexCount = 0 faceVerts = [] faceWeights = [] faceUVs = [] # which of these vertices are weighted uniquely # and should thus be imported without merging? splitVerts = [] for line in smd.file: if smdBreak(line): break if smdContinue(line): continue values = line.split() vertexCount += 1 co = [0, 0, 0] norm = [0, 0, 0] # Read co-ordinates and normals for i in range(1, 4): # 0 is the deprecated bone weight value co[i - 1] = float(values[i]) norm[i - 1] = float(values[i + 3]) co = tuple(co) faceVerts.append(co) norms.append(norm) # Can't do these in the above for loop since there's only two faceUVs.append((float(values[7]), float(values[8]))) # Read weightmap data vertWeights = [] if len(values) > 10 and values[9] != "0": # got weight links? for i in range(10, 10 + (int(values[9]) * 2), 2): # The range between the first and last weightlinks # (each of which is *two* values) try: bone = smd.a.data.bones[ smd.boneIDs[int(values[i])]] vertWeights.append(( smd.m.vertex_groups.find(bone.name), float(values[i + 1]))) except KeyError: badWeights += 1 else: # Fall back on the deprecated value # at the start of the line try: bone = smd.a.data.bones[smd.boneIDs[int(values[0])]] vertWeights.append(( smd.m.vertex_groups.find(bone.name), 1.0)) except KeyError: badWeights += 1 faceWeights.append(vertWeights) coWeight = tuple([co] + vertWeights) splitVerts.append(coWeight not in allVertexWeights) allVertexWeights.add(coWeight) # Three verts? It's time for a new poly if vertexCount == 3: for _ in range(2): bmVerts = [] # unused newWeights = collections.defaultdict(list) for i in range(3): # if a vertex in this position with # these bone weights exists, re-use it. bmv = ( None if splitVerts[i] else vertMap.get(faceVerts[i])) if bmv is None: bmv = bm.verts.new(faceVerts[i]) for link in faceWeights[i]: bmv[weightLayer][link[0]] = link[1] vertMap[faceVerts[i]] = bmv bmVerts.append(bmv) try: face = bm.faces.new(bmVerts) except ValueError: # face overlaps another, # try again with all-new vertices splitVerts = [True] * 3 continue face.material_index = mat_ind for i in range(3): face.loops[i][uvLayer].uv = faceUVs[i] break break # Back in polyland now, with three verts processed. countPolys += 1 bm.to_mesh(md) vertMap = None bm.free() md.update() if countPolys: ops.object.select_all(action="DESELECT") smd.m.select_set(True) bpy.context.view_layer.objects.active = smd.m ops.object.shade_smooth() for poly in smd.m.data.polygons: poly.select = True smd.m.show_wire = smd.jobType == PHYS md.use_auto_smooth = True md.normals_split_custom_set(norms) if smd.upAxis == 'Y': md.transform(rx90) md.update() if badWeights: self.warning( get_id("importer_err_badweights", True).format( badWeights, smd.jobName)) print("- Imported {} polys".format(countPolys))
def get_id(id, format_string=False, data=False): out = p_cache.ids[id] if format_string or (data and bpy.context.user_preferences.system.use_translate_new_dataname): return pgettext(out) else: return out
def draw(self, context): wpt_scene_properties = context.scene.wpt_scene_properties if not wpt_scene_properties.script_is_executed: row = self.layout.row() row.scale_y = 2.0 row.operator(InitProjectOperator.bl_idname, text=pgettext(InitProjectOperator.bl_label), icon='FILE_BLEND') return layout = self.layout # オブジェクト操作系 row = layout.row() row.operator(AddCurveTool.bl_idname, icon='CURVE_BEZCIRCLE') col = layout.column(align=True) if context.object is not None: obj = context.object col.prop(obj, "location", index=2) row = col.row(align=True) row.operator(UpObject.bl_idname, icon='TRIA_UP') row.operator(DownObject.bl_idname, icon='TRIA_DOWN') col.prop(wpt_scene_properties, "slide") row = col.row(align=True) row.operator(UpObjectSub.bl_idname, icon='TRIA_UP_BAR') row.operator(DownObjectSub.bl_idname, icon='TRIA_DOWN_BAR') col.prop(wpt_scene_properties, "slide_sub") col.operator(ResetObject.bl_idname, icon='X') if context.object is not None: obj = context.object if obj.type == 'CURVE': row = layout.row() row.prop(obj.data, "resolution_u") if len(obj.data.materials) > 0: mat = obj.data.materials[0] row = layout.row() row.template_ID(obj, "active_material", new="material.new") col = layout.column(align=True) # col.label(text="Viewport Color:") col.prop(mat, "diffuse_color", text="") col = layout.column(align=True) col.operator("object.select_grouped").type = 'COLLECTION' col.operator(UnrockObject.bl_idname, icon='UNLOCKED') col.operator(RockObject.bl_idname, icon='LOCKED') col.operator(ApplyObject.bl_idname, icon='FILE_TICK') self.draw_collection(context) # 出力系 layout.row().separator() row = layout.row() row.label(text="Output") row = layout.row() row.prop(wpt_scene_properties, "export_path", text="") if not bpy.data.is_saved: row = layout.row() row.alert = True row.label(text="File has not been saved.") col = layout.column(align=True) row = col.row(align=True) row.scale_y = 2.0 row.operator(SvgExporter.bl_idname, icon='EXPORT') if not bpy.data.is_saved: row.enabled = False row = col.row(align=True) row.operator(OpenSvg.bl_idname, icon='WORLD') # 枠・背景 layout.row().separator() row = layout.row() row.label(text="Background") row = layout.row() if wpt_scene_properties.draw_area is False: icon = 'PLAY' txt = 'Display border' else: icon = "PAUSE" txt = 'Hide border' row.operator("wpt.runopenglbutton", text=txt, icon=icon) # layout.prop(wpt_scene_properties, "property_type", expand=True) col = layout.column(align=True) col.prop(wpt_scene_properties, "height") col.prop(wpt_scene_properties, "width") col.prop(wpt_scene_properties, "scale") row = layout.row() row.prop(wpt_scene_properties, "use_background", text="Use background") row = layout.row() if wpt_scene_properties.use_background: row.prop(wpt_scene_properties, "background_color", text="") row = layout.row() row.prop(wpt_scene_properties, "use_stripe_background", text="Use stripe background") layout.row().separator() self.draw_pattern(context)
def translate(self, text): return pgettext(text)
def draw(self, context): svg_scene_properties = context.scene.svg_scene_properties if not svg_scene_properties.script_is_executed: row = self.layout.row() row.scale_y = 2.0 row.operator(InitProjectOperator.bl_idname, text=pgettext(InitProjectOperator.bl_label), icon='LOAD_FACTORY') return layout = self.layout row = layout.row() if svg_scene_properties.draw_area is False: icon = 'PLAY' txt = 'Display border' else: icon = "PAUSE" txt = 'Hide border' row.operator("svg.runopenglbutton", text=txt, icon=icon) # layout.prop(svg_scene_properties, "property_type", expand=True) col = layout.column(align=True) col.prop(svg_scene_properties, "height") col.prop(svg_scene_properties, "width") col.prop(svg_scene_properties, "scale") row = layout.row() row.prop(svg_scene_properties, "use_background", text="Use background") row = layout.row() if svg_scene_properties.use_background: row.prop(svg_scene_properties, "background_color", text="") row = layout.row() row.label("Export Path") row = layout.row() row.prop(svg_scene_properties, "export_path", text="") row = layout.row() row.operator(OpenSvg.bl_idname, icon='FILE_FOLDER') layout.row().separator() row = layout.row() row.operator(AddCurveTool.bl_idname, icon='CURVE_BEZCIRCLE') col = layout.column(align=True) row = col.row(align=True) row.operator(UpObject.bl_idname, icon='TRIA_UP') row.operator(DownObject.bl_idname, icon='TRIA_DOWN') col.prop(svg_scene_properties, "slide") col.operator(ResetObject.bl_idname, icon='X') layout.row().separator() if context.object is not None: obj = context.object if obj.type == 'CURVE': row = layout.row() row.prop(obj.data, "resolution_u") if len(obj.data.materials) > 0: mat = obj.data.materials[0] col = layout.column(align=True) col.label("Viewport Color:") col.prop(mat, "diffuse_color", text="") col.prop(mat, "alpha") col = layout.column(align=True) props = col.operator("object.make_links_data", text="Link Modifires", icon='MOD_ARRAY') props.type = 'MODIFIERS' layout.row().separator() row = layout.row() row.scale_y = 2.0 row.operator(SvgExporter.bl_idname, icon='EXPORT')
def draw(self, context): wpt_scene_properties = context.scene.wpt_scene_properties if not wpt_scene_properties.script_is_executed: row = self.layout.row() row.scale_y = 2.0 row.operator(InitProjectOperator.bl_idname, text=pgettext(InitProjectOperator.bl_label), icon='LOAD_FACTORY') return layout = self.layout # オブジェクト操作系 row = layout.row() row.operator(AddCurveTool.bl_idname, icon='CURVE_BEZCIRCLE') col = layout.column(align=True) row = col.row(align=True) row.operator(UpObject.bl_idname, icon='TRIA_UP') row.operator(DownObject.bl_idname, icon='TRIA_DOWN') col.prop(wpt_scene_properties, "slide") row = col.row(align=True) row.operator(UpObjectSub.bl_idname, icon='TRIA_UP_BAR') row.operator(DownObjectSub.bl_idname, icon='TRIA_DOWN_BAR') col.prop(wpt_scene_properties, "slide_sub") col.operator(ResetObject.bl_idname, icon='X') if context.object is not None: obj = context.object if obj.type == 'CURVE': row = layout.row() row.prop(obj.data, "resolution_u") if len(obj.data.materials) > 0: mat = obj.data.materials[0] row = layout.row() row.template_ID(obj, "active_material", new="material.new") col = layout.column(align=True) # col.label("Viewport Color:") col.prop(mat, "diffuse_color", text="") col.prop(mat, "alpha") # グループ系 layout.row().separator() if context.object is not None: for group in bpy.data.groups: group_objects = group.objects if context.object.name in group.objects and context.object in group_objects[:]: row = layout.row() row.label("Group") row = layout.row() row.prop(group, "name", text="") wpt_group_properties = group.wpt_group_properties row = layout.row() row.prop(wpt_group_properties, "export") # row = layout.row() # row.prop_search(wpt_scene_properties, "set_group", bpy.data, "groups", text="") # 出力系 layout.row().separator() row = layout.row() row.label("Output") row = layout.row() row.prop(wpt_scene_properties, "export_path", text="") col = layout.column(align=True) row = col.row(align=True) row.scale_y = 2.0 row.operator(SvgExporter.bl_idname, icon='EXPORT') if not bpy.data.is_saved: row.enabled = False row = col.row(align=True) row.operator(OpenSvg.bl_idname, icon='WORLD') # 枠・背景 layout.row().separator() row = layout.row() row.label("Background") row = layout.row() if wpt_scene_properties.draw_area is False: icon = 'PLAY' txt = 'Display border' else: icon = "PAUSE" txt = 'Hide border' row.operator("wpt.runopenglbutton", text=txt, icon=icon) # layout.prop(wpt_scene_properties, "property_type", expand=True) col = layout.column(align=True) col.prop(wpt_scene_properties, "height") col.prop(wpt_scene_properties, "width") col.prop(wpt_scene_properties, "scale") row = layout.row() row.prop(wpt_scene_properties, "use_background", text="Use background") row = layout.row() if wpt_scene_properties.use_background: row.prop(wpt_scene_properties, "background_color", text="") layout.row().separator() # パターン系 row = layout.row() row.label("Pattern") row = layout.row() row.prop(wpt_scene_properties, "pattern_type", text="") pattern = wpt_scene_properties.pattern_type if pattern == "0": # Square lattice col = layout.column(align=True) row = col.row(align=True) row.prop(wpt_scene_properties, "distance_x") row = col.row(align=True) row.prop(wpt_scene_properties, "distance_y") elif pattern == "1" or pattern == "2": # Hexagonal lattice col = layout.column(align=True) row = col.row(align=True) row.prop(wpt_scene_properties, "distance_x") row = col.row(align=True) row.prop(wpt_scene_properties, "offset_y") elif pattern == "1" or pattern == "2": # Hexagonal lattice col = layout.column(align=True) row = col.row(align=True) row.prop(wpt_scene_properties, "distance_x") row = col.row(align=True) row.prop(wpt_scene_properties, "distance_y") row = col.row(align=True) row.prop(wpt_scene_properties, "offset_y") if pattern == "0" or pattern == "1": row = layout.row() row.prop(wpt_scene_properties, "use_location_noise") if wpt_scene_properties.use_location_noise: row = layout.row() row.prop(wpt_scene_properties, "location_noise") row = layout.row() row.prop(wpt_scene_properties, "use_rotation_noise") if wpt_scene_properties.use_rotation_noise: row = layout.row() row.prop(wpt_scene_properties, "rotation_noise") row = layout.row() row.prop(wpt_scene_properties, "random_seed") elif pattern == "2": # Yagasuri row = layout.row() row.prop(wpt_scene_properties, "yagasuri_turn")