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) 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)
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_sculptie( sculpt_type, faces_x=8, faces_y=8, multires=2, clean_lods=True, subsurf=False, catmull=True ): Blender.Window.WaitCursor(1) basename = ("Sphere", "Torus", "Plane", "Cylinder", "Hemi")[sculpt_type -1] scene = Blender.Scene.GetCurrent() for ob in scene.objects: ob.sel = False rdict = Blender.Registry.GetKey('ImportSculptie', True) # True to check on disk also if rdict: # if found, get the values saved there try: settings['radius'] = rdict['radius'] except: settings['radius'] = 0.25 if sculpt_type == TORUS: radius = Blender.Draw.Create( settings['radius'] ) Blender.Window.WaitCursor(0) retval = Blender.Draw.PupBlock( "Torus Options", [( "Radius: ", radius, 0.05, 0.5 )] ) Blender.Window.WaitCursor(1) settings['radius'] = radius.val Blender.Registry.SetKey('ImportSculptie', settings, True) # save latest settings mesh = sculpty.new_mesh( basename, ["none","SPHERE","TORUS","PLANE","CYLINDER","HEMI"][sculpt_type], faces_x, faces_y, multires, clean_lods, settings['radius']) s, t, w, h, clean_s, clean_t = sculpty.map_size( faces_x, faces_y, multires ) image = Blender.Image.New( basename, w, h, 32 ) sculpty.bake_lod(image) ob = scene.objects.new( mesh, basename ) if sculpt_type != PLANE: mesh.flipNormals() ob.sel = True ob.setLocation( Blender.Window.GetCursorPos() ) if sculpt_type == PLANE: mesh.flipNormals() sculpty.set_map( mesh, image ) if multires: if subsurf: mods = ob.modifiers mod = mods.append(Blender.Modifier.Types.SUBSURF) mod[Blender.Modifier.Settings.LEVELS] = multires mod[Blender.Modifier.Settings.RENDLEVELS] = multires mod[Blender.Modifier.Settings.UV] = False if not catmull: mod[Blender.Modifier.Settings.TYPES] = 1 else: mesh.multires = True mesh.addMultiresLevel(multires, ('simple', 'catmull-clark')[catmull]) 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 = settings['radius'] * z 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 Blender.Window.WaitCursor(0) return ob