Beispiel #1
0
def assign_new_image(ob, could_be_mirror=False):
        mesh = ob.getData(False, True)
        name = ob.getName()

        activeUV = mesh.activeUVLayer
        mesh.activeUVLayer = "sculptie"
        image = mesh.faces[0].image
        try:
           width  = image.getSize()[0]
           height = image.getSize()[1]
        except:
           if image == None:
               print "No image data available for object", name
           else:
               print "Can not get image data from object", name,"image",image.getName()
           print "Need to Resculptify object ..."
           sculptify(ob, force_new_image=True)
           mesh = ob.getData(False, True)
           image = mesh.faces[0].image
           #print "image",sel.name,"is assigned to ", ob.getName()
           #print "Resculptify created image", image.name, "of type", image.source
           if could_be_mirror:
               adjust_image_name(ob,image)
           return image

        object_name = ob.getName().split(os.sep)[-1]
        new_image = create_new_image(object_name, width, height, 32)
        selected_verts = mesh.verts.selected()
        mesh.sel = True
        set_map(mesh, new_image)    
        mesh.sel = False
        for i in selected_verts:
            mesh.verts[i].sel=1
        mesh.update()
        mesh.activeUVLayer = activeUV
        if could_be_mirror:
            adjust_image_name(ob,new_image)
        print "assign_new_image()ob.name:",ob.name,"new_image:",new_image.name
        return new_image
    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()
Beispiel #3
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