コード例 #1
0
def mesh2Prim(ob, rootprim=None):
    mesh = ob.getData(False, True)
    images, textures = map_images(mesh, 'sculptie', 'UVTex')
    bb = BoundingBox(ob)
    r = ob.getMatrix().rotationPart().toQuat()
    rotation = (r[1], r[2], r[3], r[0])
    l = ob.getLocation('worldspace')
    location = XYZ(l[0], l[1], l[2])
    for i in range(len(images)):
        image = images[i]
        texture = textures[i]
        newprim = Prim(image.name)
        newprim.sculpt_map = image
        if texture:
            newtex = Texture(texture)
            newtex.offset, newtex.repeat, newtex.rotation =\
                    uv_params(mesh, image)
            newprim.textures.append(newtex)
        newprim.rotation = rotation
        newprim.size = XYZ(
            image.properties['primstar']['scale_x'] * bb.scale.x,
            image.properties['primstar']['scale_y'] * bb.scale.y,
            image.properties['primstar']['scale_z'] * bb.scale.z)

        #print "========================================================="
        linksetSize = (image.properties['primstar']['size_x'],
                       image.properties['primstar']['size_y'],
                       image.properties['primstar']['size_z'])
        objectScale = (image.properties['primstar']['scale_x'],
                       image.properties['primstar']['scale_y'],
                       image.properties['primstar']['scale_z'])
        #print "LSL: linkset size         = ", linksetSize
        #print "LSL: object scale         = ", objectScale
        #print "LSL: bbox size from image = ", linksetSize[0]/objectScale[0], linksetSize[1]/objectScale[1], linksetSize[2]/objectScale[2]
        #print "LSL: bbox size from object= ", bb.scale.x, bb.scale.y, bb.scale.z
        #print "LSL: Final size           = ", newprim.size

        newprim.location = location + XYZ(
            image.properties['primstar']['loc_x'],
            image.properties['primstar']['loc_y'],
            image.properties['primstar']['loc_z'])
        if rootprim is None:
            rootprim = newprim
        else:
            rootprim.children.append(newprim)
    return rootprim
コード例 #2
0
ファイル: import_selection.py プロジェクト: sorayaelcar/Sving
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)
コード例 #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
ファイル: import_selection.py プロジェクト: sorayaelcar/Sving
def new_from_selection(scene, target_location, editmode):
    # Create the set BBox
    # Note: We take ALL selected objects into account for the BBox calculation.
    bbox = BoundingBox()

    # Selection contains all selected objects in scene
    # roots contains all selected root objects (objects which have no selected parent)
    selection = []
    roots     = {}
    for ob in scene.objects.selected:
        #print "Add ", ob.getName(), " to BBox"
        bbox.add(ob)
        selection.append(ob)

        key = ob.getName()
        if roots.get(key) == None:
            newRoot = ob
            parent = ob.getParent()
            while parent != None and parent.isSelected():
                key = parent.getName()
                if roots.get(key) != None:
                    #print "Found key", key, "In roots list"
                    newRoot = None
                    break
                else:
                    newRoot = parent
                    parent = newRoot.getParent()
                    #print "key", parent.getName(), "not in roots list"
            if newRoot != None:
                key = newRoot.getName()
                roots[key] = newRoot
                print "Added new root :", key

    # unselect all curently selected objects:
    for ob in selection:
        ob.select(False)

    source_location = bbox.getCollectionLocation()
    offset = target_location - source_location
    
    target_list = []
    report = "";

    #Create copies of all objects in selection (if appropriate)
    image_dict = {}
    
    processed_objects = {}
    for key in roots.iterkeys():
        print "Processing root ", key
        root = roots[key]
        if processed_objects.get(key) == None:
            processed_objects[key] = root
            all_children, new_children, log = new_from_children(root, processed_objects, image_dict, offset)
            if log != "":
                report = report + log
            if sculpty.check(root):
                #print "Copy from ", ob.getName() 
                new_root, log = new_from_object(root,image_dict, offset)
                if new_root != None:
                    new_root.select(False)
                    if len(new_children) > 0:
                        Blender.Redraw()
                        print "Add",len(new_children),"Children to root", new_root.getName()
                        new_root.makeParent(new_children)
                        target_list.extend(new_children)
                    target_list.append(new_root)
                #else:
                #    print "Warn: copy of [", ob.getName(), "] failed."
            else:
                log = "Warn: Not a sculptie [" + root.getName() + "]  (Object not copied)|"
    
            if log != "":
                print log
                report = report + log


    # get over a bug in blender that fails to set 
    # correct lighting after creating a sculptie.
    for ob in target_list:
        ob.select(True)
        Blender.Window.EditMode(1)
        Blender.Window.EditMode(0) 
        ob.select(False)

    for ob in target_list:
        ob.select(True)

    return report
コード例 #5
0
def new_from_selection(scene, target_location, editmode):
    # Create the set BBox
    # Note: We take ALL selected objects into account for the BBox calculation.
    bbox = BoundingBox()

    # Selection contains all selected objects in scene
    # roots contains all selected root objects (objects which have no selected parent)
    selection = []
    roots = {}
    for ob in scene.objects.selected:
        #print "Add ", ob.getName(), " to BBox"
        bbox.add(ob)
        selection.append(ob)

        key = ob.getName()
        if roots.get(key) == None:
            newRoot = ob
            parent = ob.getParent()
            while parent != None and parent.isSelected():
                key = parent.getName()
                if roots.get(key) != None:
                    #print "Found key", key, "In roots list"
                    newRoot = None
                    break
                else:
                    newRoot = parent
                    parent = newRoot.getParent()
                    #print "key", parent.getName(), "not in roots list"
            if newRoot != None:
                key = newRoot.getName()
                roots[key] = newRoot
                print "Added new root :", key

    # unselect all curently selected objects:
    for ob in selection:
        ob.select(False)

    source_location = bbox.getCollectionLocation()
    offset = target_location - source_location

    target_list = []
    report = ""

    #Create copies of all objects in selection (if appropriate)
    image_dict = {}

    processed_objects = {}
    for key in roots.iterkeys():
        print "Processing root ", key
        root = roots[key]
        if processed_objects.get(key) == None:
            processed_objects[key] = root
            all_children, new_children, log = new_from_children(
                root, processed_objects, image_dict, offset)
            if log != "":
                report = report + log
            if sculpty.check(root):
                #print "Copy from ", ob.getName()
                new_root, log = new_from_object(root, image_dict, offset)
                if new_root != None:
                    new_root.select(False)
                    if len(new_children) > 0:
                        Blender.Redraw()
                        print "Add", len(
                            new_children
                        ), "Children to root", new_root.getName()
                        new_root.makeParent(new_children)
                        target_list.extend(new_children)
                    target_list.append(new_root)
                #else:
                #    print "Warn: copy of [", ob.getName(), "] failed."
            else:
                log = "Warn: Not a sculptie [" + root.getName(
                ) + "]  (Object not copied)|"

            if log != "":
                print log
                report = report + log

    # get over a bug in blender that fails to set
    # correct lighting after creating a sculptie.
    for ob in target_list:
        ob.select(True)
        Blender.Window.EditMode(1)
        Blender.Window.EditMode(0)
        ob.select(False)

    for ob in target_list:
        ob.select(True)

    return report