def main( filename ): image = Blender.Image.Load( filename ) editmode = Blender.Window.EditMode() if editmode: Blender.Window.EditMode(0) Blender.Window.WaitCursor(1) ob = Blender.Scene.GetCurrent().getActiveObject() if ob.type == 'Mesh': mesh = ob.getData( False, True) if "sculptie" in mesh.getUVLayerNames(): update_from_map( mesh, image ) else: Blender.Draw.PupBlock( "Sculptie Error", ["Mesh has no 'sculptie' UV Layer"] ) Blender.Window.WaitCursor(0) Blender.Window.EditMode( editmode )
def main(filename): image = Blender.Image.Load(filename) editmode = Blender.Window.EditMode() if editmode: Blender.Window.EditMode(0) Blender.Window.WaitCursor(1) ob = Blender.Scene.GetCurrent().getActiveObject() if ob.type == 'Mesh': mesh = ob.getData(False, True) if "sculptie" in mesh.getUVLayerNames(): update_from_map(mesh, image) else: Blender.Draw.PupBlock("Sculptie Error", ["Mesh has no 'sculptie' UV Layer"]) #Blender.Window.WaitCursor(0) Blender.Window.EditMode(editmode)
def main(): editmode = Blender.Window.EditMode() if editmode: Blender.Window.EditMode(0) scene = Blender.Scene.GetCurrent() Blender.Window.WaitCursor(1) for ob in scene.objects.selected: if sculpty.active(ob): mesh = ob.getData(False, True) maps = sculpty.map_images(mesh) if len(maps) == 1: mesh.sel = True sculpty.update_from_map(mesh, maps[0]) mesh.update() else: Blender.Draw.PupBlock("Sculptie Reset Error", ["Can't reset joined sculpt mesh", ob.name]) # Blender.Window.WaitCursor(0) Blender.Window.EditMode(editmode) Blender.Redraw()
def main(): editmode = Blender.Window.EditMode() if editmode: Blender.Window.EditMode(0) scene = Blender.Scene.GetCurrent() Blender.Window.WaitCursor(1) for ob in scene.objects.selected: if sculpty.active(ob): mesh = ob.getData(False, True) maps = sculpty.map_images(mesh) if len(maps) == 1: mesh.sel = True sculpty.update_from_map(mesh, maps[0]) mesh.update() else: Blender.Draw.PupBlock( "Sculptie Reset Error", ["Can't reset joined sculpt mesh", ob.name]) #Blender.Window.WaitCursor(0) Blender.Window.EditMode(editmode) Blender.Redraw()
def add(self): Blender.Window.WaitCursor(1) editmode = Blender.Window.EditMode() if editmode: Blender.Window.EditMode(0) name = self.shape_name.get() basename = name.split(os.sep)[-1] if self.shape_file: baseimage = Blender.Image.Load(self.shape_file) sculpt_type = sculpty.map_type(baseimage) else: sculpt_type = name.upper() baseimage = None gui.debug(11, "Add sculptie (%s) of type %s" % (name, sculpt_type), SCRIPT) scene = Blender.Scene.GetCurrent() for ob in scene.objects: ob.sel = False try: mesh = sculpty.new_mesh( basename, sculpt_type, self.x_faces.get(), self.y_faces.get(), self.levels.get(), self.clean_lods.get(), min(0.5, max(self.radius.get(), 0.05)), ) s, t, w, h, clean_s, clean_t = sculpty.map_size(self.x_faces.get(), self.y_faces.get(), self.levels.get()) image = create_new_image(basename, w, h, 32) # print "add_mesh_sculpt_mesh: Packed image", image.getName() sculpty.bake_lod(image) ob = scene.objects.new(mesh, basename) mesh.flipNormals() ob.sel = True ob.setLocation(Blender.Window.GetCursorPos()) sculpty.set_map(mesh, image) if baseimage: sculpty.update_from_map(mesh, baseimage) if self.levels.get(): if self.sub_type.get(): mods = ob.modifiers mod = mods.append(Blender.Modifier.Types.SUBSURF) mod[Blender.Modifier.Settings.LEVELS] = self.levels.get() mod[Blender.Modifier.Settings.RENDLEVELS] = self.levels.get() mod[Blender.Modifier.Settings.UV] = False if not self.subdivision.get(): mod[Blender.Modifier.Settings.TYPES] = 1 else: mesh.multires = True mesh.addMultiresLevel(self.levels.get(), ("simple", "catmull-clark")[self.subdivision.get()]) mesh.sel = True if self.subdivision.get(): for f in mesh.faces: f.smooth = True # adjust scale for subdivision minimum, maximum = sculpty.get_bounding_box(ob) x = 1.0 / (maximum.x - minimum.x) y = 1.0 / (maximum.y - minimum.y) try: z = 1.0 / (maximum.z - minimum.z) except: z = 0.0 if sculpt_type == "TORUS Z": z = min(0.5, max(self.radius.get(), 0.05)) * z elif sculpt_type == "TORUS X": x = min(0.5, max(self.radius.get(), 0.05)) * x elif sculpt_type == "HEMI": z = 0.5 * z tran = Blender.Mathutils.Matrix([x, 0.0, 0.0], [0.0, y, 0.0], [0.0, 0.0, z]).resize4x4() mesh.transform(tran) # align to view try: quat = None if Blender.Get("add_view_align"): quat = Blender.Mathutils.Quaternion(Blender.Window.GetViewQuat()) if quat: mat = quat.toMatrix() mat.invert() mat.resize4x4() ob.setMatrix(mat) except: pass if self.save_settings.get() or self.save_defaults.get(): settings = { "x_faces": self.x_faces.get(), "y_faces": self.y_faces.get(), "levels": self.levels.get(), "subdivision": self.subdivision.get(), "sub_type": self.sub_type.get(), "clean_lods": self.clean_lods.get(), "radius": self.radius.get(), "shape_name": self.shape_name.get(), "shape_file": self.shape_file, "quads": self.quads.get(), "save": self.save_settings.get(), } Blender.Registry.SetKey(REGISTRY, settings, self.save_defaults.get()) except RuntimeError: raise Blender.Window.EditMode(editmode) Blender.Window.WaitCursor(0) self.master.quit()
def add(self): Blender.Window.WaitCursor(1) editmode = Blender.Window.EditMode() if editmode: Blender.Window.EditMode(0) name = self.shape_name basename = name.split(os.sep)[-1] if self.shape_file: baseimage = Blender.Image.Load(self.shape_file) sculpt_type = sculpty.map_type(baseimage) else: sculpt_type = name.upper() baseimage = None gui.debug(11, "Add sculptie (%s) of type %s" % (name, sculpt_type), "add_mesh_sculpt_mesh") scene = Blender.Scene.GetCurrent() for ob in scene.objects: ob.sel = False try: mesh = sculpty.new_mesh(basename, sculpt_type, self.x_faces, self.y_faces, self.levels, self.clean_lods, min(0.5, max(self.radius, 0.05))) s, t, w, h, clean_s, clean_t = sculpty.map_size(self.x_faces, self.y_faces, self.levels) image = create_new_image(basename, w, h, 32) sculpty.bake_lod(image) ob = scene.objects.new(mesh, basename) mesh.flipNormals() ob.sel = True ob.setLocation(Blender.Window.GetCursorPos()) sculpty.set_map(mesh, image) if baseimage: sculpty.update_from_map(mesh, baseimage) if self.levels: if self.sub_type: mods = ob.modifiers mod = mods.append(Blender.Modifier.Types.SUBSURF) mod[Blender.Modifier.Settings.LEVELS] = self.levels mod[Blender.Modifier.Settings.RENDLEVELS] = self.levels mod[Blender.Modifier.Settings.UV] = False if not self.subdivision: mod[Blender.Modifier.Settings.TYPES] = 1 else: mesh.multires = True mesh.addMultiresLevel(self.levels, ('simple', 'catmull-clark')[self.subdivision]) mesh.sel = True if self.subdivision: for f in mesh.faces: f.smooth = True # adjust scale for subdivision minimum, maximum = sculpty.get_bounding_box(ob) x = 1.0 / (maximum.x - minimum.x) y = 1.0 / (maximum.y - minimum.y) try: z = 1.0 / (maximum.z - minimum.z) except: z = 0.0 if sculpt_type == "TORUS Z": z = min(0.5, max(self.radius, 0.05)) * z print "Create a Torus Z with radius ", z elif sculpt_type == "TORUS X": x = min(0.5, max(self.radius, 0.05)) * x print "Create a Torus X with radius ", x elif sculpt_type == "HEMI": z = 0.5 * z tran = Blender.Mathutils.Matrix([x, 0.0, 0.0], [0.0, y, 0.0], [0.0, 0.0, z]).resize4x4() mesh.transform(tran) # align to view try: quat = None if Blender.Get('add_view_align'): quat = Blender.Mathutils.Quaternion( Blender.Window.GetViewQuat()) if quat: mat = quat.toMatrix() mat.invert() mat.resize4x4() ob.setMatrix(mat) except: pass except RuntimeError: raise Blender.Window.EditMode(editmode) Blender.Window.WaitCursor(0) return ob
def add(self): Blender.Window.WaitCursor(1) name = self.map_type.cget('text') if name[:1] == os.sep: basename = name.split(os.sep)[1] baseimage = Blender.Image.Load(os.path.join(sculpty.lib_dir, name[1:]) + '.png') sculpt_type = sculpty.map_type(baseimage) else: basename = name sculpt_type = name.upper() baseimage = None print "Create a [", name, "] of type ", sculpt_type scene = Blender.Scene.GetCurrent() for ob in scene.objects: ob.sel = False try: mesh = sculpty.new_mesh( basename,sculpt_type, self.x_faces.get(), self.y_faces.get(), self.levels.get(), self.clean_lods.get(), 0.25) #todo: 0.25 radius needs gui add.. s, t, w, h, clean_s, clean_t = sculpty.map_size(self.x_faces.get(), self.y_faces.get(), self.levels.get()) image = Blender.Image.New(basename, w, h, 32) sculpty.bake_lod(image) ob = scene.objects.new(mesh, basename) mesh.flipNormals() ob.sel = True ob.setLocation(Blender.Window.GetCursorPos()) sculpty.set_map(mesh, image) if baseimage: sculpty.update_from_map(mesh, baseimage) if self.levels.get(): if self.sub_type.get(): mods = ob.modifiers mod = mods.append(Blender.Modifier.Types.SUBSURF) mod[Blender.Modifier.Settings.LEVELS] = self.levels.get() mod[Blender.Modifier.Settings.RENDLEVELS] = self.levels.get() mod[Blender.Modifier.Settings.UV] = False if not self.subdivision.get(): mod[Blender.Modifier.Settings.TYPES] = 1 else: mesh.multires = True mesh.addMultiresLevel(self.levels.get(), ('simple', 'catmull-clark')[self.subdivision.get()]) mesh.sel = True # adjust scale for subdivision minimum, maximum = sculpty.get_bounding_box(ob) x = 1.0 / (maximum.x - minimum.x) y = 1.0 / (maximum.y - minimum.y) try: z = 1.0 / (maximum.z - minimum.z) except: z = 0.0 if sculpt_type == "TORUS": z = 0.25 * z #todo: radius again elif sculpt_type == "HEMI": z = 0.5 * z tran = Blender.Mathutils.Matrix([ x, 0.0, 0.0 ], [0.0, y, 0.0], [0.0, 0.0, z]).resize4x4() mesh.transform(tran) # align to view try: quat = None if Blender.Get('add_view_align'): quat = Blender.Mathutils.Quaternion(Blender.Window.GetViewQuat()) if quat: mat = quat.toMatrix() mat.invert() mat.resize4x4() ob.setMatrix(mat) except: pass except RuntimeError: #todo tkinter this Blender.Draw.PupBlock("Unable to create sculptie", ["Please decrease face counts","or subdivision levels"]) Blender.Window.WaitCursor(0) self.master.quit() # self.master.destroy() makes blender crash occasionally (thread problems)