예제 #1
0
def main():
    in_editmode = Blender.Window.EditMode()
    # MUST leave edit mode before changing an active mesh:
    if in_editmode:
        Blender.Window.EditMode(0)
    else:
        try:
            in_editmode = Blender.Get('add_editmode')
        except:
            pass
    image = Blender.Image.GetCurrent()
    if image:
        ob = new_from_map(image, False)
    else:
        Blender.Draw.PupBlock("Can't add Sculptie", ["No current image"])
    if in_editmode:
        Blender.Window.EditMode(1)
    Blender.Redraw()
예제 #2
0
def main():
    in_editmode = Blender.Window.EditMode()
    # MUST leave edit mode before changing an active mesh:
    if in_editmode:
        Blender.Window.EditMode(0)
    else:
        try:
            in_editmode = Blender.Get("add_editmode")
        except:
            pass
    image = Blender.Image.GetCurrent()
    if image:
        ob = new_from_map(image, False)
    else:
        Blender.Draw.PupBlock("Can't add Sculptie", ["No current image"])
    if in_editmode:
        Blender.Window.EditMode(1)
    Blender.Redraw()
예제 #3
0
def create_from_object(ob, offset):

    # Create the new sculptie:
    mesh = ob.getData(False, True)

    activeUV = mesh.activeUVLayer
    mesh.activeUVLayer = "sculptie"
    image = mesh.faces[0].image
    mesh.activeUVLayer = activeUV
    new_object = new_from_map(image, False, False)
    
    # Workaround for a bug in the object display.
    # Just jump to edit mode and then back to object mode.
    editmode = Blender.Window.EditMode()
    if not editmode:
       Blender.Window.EditMode(1)
    Blender.Window.EditMode(0)

    ## Copy mesh mode:
    me = new_object.getData(False,True)
    me.mode = mesh.mode

    bb = BoundingBox(ob, False)
    dim   = bb.getDim()

    ## Copy rotation:
    mat = ob.getMatrix()
    scale = mat.scalePart()
    rot_quat = mat.toQuat()
    rot = rot_quat.toMatrix().resize4x4().invert()

    dim = Blender.Mathutils.Vector ( dim.x, dim.y, dim.z )

    me.transform(rot)
    rot.invert()
    me.transform(rot)

    new_object.rot = ob.rot

    ## Copy setting of smoothness:
    if is_smooth(mesh):
        make_smooth(me)
            
    # Move location to offset.
    loc = ob.getLocation()
    loc = (loc[0] + offset.x,
           loc[1] + offset.y,
           loc[2] + offset.z)    
    new_object.setLocation(loc)

    # ==========================================
    # Copy scaling
    # ==========================================

    c_range = color_range(image)
    c_range.x = dim.x * 255 / c_range.x
    c_range.y = dim.y * 255 / c_range.y
    c_range.z = dim.z * 255 / c_range.z

    new_object.setSize( c_range.x, c_range.y, c_range.z )

    # ==========================================
    # Copy material settings
    materials = ob.getMaterials()
    if materials != None:
        print "Copy", len(materials),"materials"
        new_object.setMaterials(materials)
    me.materials = mesh.materials
    new_object.colbits = ob.colbits

    # update and cleanup
    me.update()

    if editmode:
       Blender.Window.EditMode(1)

    return new_object, is_inside_out(me)
예제 #4
0
def create_from_object(ob, offset):

    # Create the new sculptie:
    mesh = ob.getData(False, True)

    activeUV = mesh.activeUVLayer
    mesh.activeUVLayer = "sculptie"
    image = mesh.faces[0].image
    mesh.activeUVLayer = activeUV
    new_object = new_from_map(image, False, False)

    # Workaround for a bug in the object display.
    # Just jump to edit mode and then back to object mode.
    editmode = Blender.Window.EditMode()
    if not editmode:
        Blender.Window.EditMode(1)
    Blender.Window.EditMode(0)

    ## Copy mesh mode:
    me = new_object.getData(False, True)
    me.mode = mesh.mode

    bb = BoundingBox(ob, False)
    dim = bb.getDim()

    ## Copy rotation:
    mat = ob.getMatrix()
    scale = mat.scalePart()
    rot_quat = mat.toQuat()
    rot = rot_quat.toMatrix().resize4x4().invert()

    dim = Blender.Mathutils.Vector(dim.x, dim.y, dim.z)

    me.transform(rot)
    rot.invert()
    me.transform(rot)

    new_object.rot = ob.rot

    ## Copy setting of smoothness:
    if is_smooth(mesh):
        make_smooth(me)

    # Move location to offset.
    loc = ob.getLocation()
    loc = (loc[0] + offset.x, loc[1] + offset.y, loc[2] + offset.z)
    new_object.setLocation(loc)

    # ==========================================
    # Copy scaling
    # ==========================================

    c_range = color_range(image)
    c_range.x = dim.x * 255 / c_range.x
    c_range.y = dim.y * 255 / c_range.y
    c_range.z = dim.z * 255 / c_range.z

    new_object.setSize(c_range.x, c_range.y, c_range.z)

    # ==========================================
    # Copy material settings
    materials = ob.getMaterials()
    if materials != None:
        print "Copy", len(materials), "materials"
        new_object.setMaterials(materials)
    me.materials = mesh.materials
    new_object.colbits = ob.colbits

    # update and cleanup
    me.update()

    if editmode:
        Blender.Window.EditMode(1)

    return new_object, is_inside_out(me)