示例#1
0
 def set_file(self):
     self.master.withdraw()
     filename = tkFileDialog.askopenfilename(
         initialdir="~",
         title="Select a sculpt map",
         parent=self.master,
         filetypes=[("targa", "*.tga"), ("bmp", "*.bmp"), ("png", "*.png"), ("all files", ".*")],
     )
     self.master.deiconify()
     self.redraw()
     if filename:
         self.set_shape(Blender.sys.makename(filename), filename)
         i = Blender.Image.Load(filename)
         sculpt_type = sculpty.map_type(i)
         if sculpt_type[:5] == "TORUS":
             self.radius_input.config(state=NORMAL)
         else:
             self.radius_input.config(state=DISABLED)
         x_faces, y_faces = i.size
         x_faces, y_faces = sculpty.face_count(x_faces, y_faces, 32, 32)
         self.x_faces_input.config(to=i.size[0] / 2)
         self.y_faces_input.config(to=i.size[1] / 2)
         levels = 0
         while levels < 2 and not x_faces % 2 and not y_faces % 2 and x_faces > 4 and y_faces > 4:
             levels += 1
             x_faces /= 2
             y_faces /= 2
         self.x_faces.set(x_faces)
         self.y_faces.set(y_faces)
         self.levels.set(levels)
         self.update_info()
示例#2
0
 def set_file(self):
     self.master.withdraw()
     filename = tkFileDialog.askopenfilename(initialdir='~',
                                             title='Select a sculpt map',
                                             parent=self.master,
                                             filetypes=[('targa', '*.tga'),
                                                        ('bmp', '*.bmp'),
                                                        ('png', '*.png'),
                                                        ('all files', '.*')
                                                        ])
     self.master.deiconify()
     self.redraw()
     if filename:
         self.set_shape(Blender.sys.makename(filename), filename)
         i = Blender.Image.Load(filename)
         sculpt_type = sculpty.map_type(i)
         if sculpt_type[:5] == "TORUS":
             self.radius_input.config(state=NORMAL)
         else:
             self.radius_input.config(state=DISABLED)
         x_faces, y_faces = i.size
         x_faces, y_faces = sculpty.face_count(x_faces, y_faces, 32, 32)
         self.x_faces_input.config(to=i.size[0] / 2)
         self.y_faces_input.config(to=i.size[1] / 2)
         levels = 0
         while levels < 2 and not x_faces % 2 and not y_faces % 2 \
                 and x_faces > 4 and y_faces > 4:
             levels += 1
             x_faces /= 2
             y_faces /= 2
         self.x_faces.set(x_faces)
         self.y_faces.set(y_faces)
         self.levels.set(levels)
         self.update_info()
示例#3
0
	def toLSLParams( self ):
		pt = ["missing","missing","missing","missing","missing","missing","missing","SCULPT"][ self.primtype ]
		lsl = "PRIM_TYPE, PRIM_TYPE_%s, "%( pt )
		if self.primtype == 7:
			lsl += "\"%s\", PRIM_SCULPT_TYPE_%s, "%( self.sculptimage.name, sculpty.map_type( self.sculptimage.image ) )
		lsl += "PRIM_SIZE, < %.5f, %.5f, %.5f >, "%( self.scale )
		lsl += "PRIM_ROTATION, < %.5f, %.5f, %.5f, %.5f >, "%( self.rotation )
		lsl += "PRIM_POSITION, < %.5f, %.5f, %.5f >"%( self.location )
		for t in self.textures:
			lsl += ", " + t.toLSLParams()
		return lsl
示例#4
0
def prim2dict(prim, link=0):
    return {
        'prim': PRIM_NAME,
        'name': clean_name(prim.name),
        'position': "< %(x).5f, %(y).5f, %(z).5f >" % prim.location,
        'rotation': "< %.5f, %.5f, %.5f, %.5f >" % prim.rotation,
        'size': "< %(x).5f, %(y).5f, %(z).5f >" % prim.size,
        'sculpt_map': clean_name(prim.sculpt_map.name),
        'link_num': link,
        'sculpt_type': map_type(prim.sculpt_map)
    }
示例#5
0
    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()
示例#6
0
 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
示例#7
0
	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)