Пример #1
0
def uv_corners(mesh, image=None):
    '''returns the four corner points of the UVTex layout
    for the sculpt map image'''
    debug(40, "primitive.uv_corners(%s, %s)" % (mesh.name, image.name))
    max_vu = XYZ(-99999.0, -99999.0, 0.0)
    min_vu = XYZ(99999.0, 99999.0, 0.0)
    max_uv = XYZ(-99999.0, -99999.0, 0.0)
    min_uv = XYZ(99999.0, 99999.0, 0.0)
    current_uv = mesh.activeUVLayer
    mesh.activeUVLayer = 'sculptie'
    if image:
        faces = [f for f in mesh.faces if f.image == image]
    else:
        faces = mesh.faces
    mesh.activeUVLayer = 'UVTex'
    for f in faces:
        for i in range(len(f.verts)):
            v = XYZ(round(f.uv[i][0], 6), round(f.uv[i][1], 6), 0.0)
            max_uv = max(max_uv, v)
            min_uv = min(min_uv, v)
            v = XYZ(round(f.uv[i][1], 6), round(f.uv[i][0], 6), 0.0)
            max_vu = max(max_vu, v)
            min_vu = min(min_vu, v)
    min_vu = XYZ(min_vu.y, min_vu.x, 0.0)
    max_vu = XYZ(max_vu.y, max_vu.x, 0.0)
    if min_vu == min_uv:
        min_uv.y = max_uv.y
    if max_vu == max_uv:
        max_vu.y = min_vu.y
    mesh.activeUVLayer = current_uv
    return min_vu, min_uv, max_vu, max_uv
Пример #2
0
 def __init__(self, name):
     self.name = name
     self.children = []
     self.textures = []
     self.sculpt_map = None
     self.size = XYZ(1.0, 1.0, 1.0)
     self.rotation = (0.0, 0.0, 0.0, 1.0)
     self.location = XYZ(0.0, 0.0, 0.0)
Пример #3
0
def uv_params(mesh, image=None):
    '''returns the offset, scale and rotation of the UVTex layout
    for the sculpt map image'''
    debug(40, "primitive.uv_params(%s, %s)" % (mesh.name, image.name))
    if 'UVTex' not in mesh.getUVLayerNames():
        return XYZ(0.0, 0.0, 0.0), XYZ(1.0, 1.0, 0.0), 0.0
    bl, tl, br, tr = uv_corners(mesh, image)
    hv = tl - bl
    wv = br - bl
    a = atan2(hv.x, hv.y)
    s = XYZ(
        Blender.Mathutils.Vector(wv.x, wv.y).length,
        Blender.Mathutils.Vector(hv.x, hv.y).length, 0.0)
    return bl + (tr - bl) / 2.0 - XYZ(0.5, 0.5, 0.0), s, a
Пример #4
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
Пример #5
0
def color_range(image):
    c = image.getPixelI(0, 0)
    min = XYZ(c[0], c[1], c[2])
    max = XYZ(c[0], c[1], c[2])

    for x in range(image.size[0]):
        for y in range(image.size[1]):
            c = image.getPixelI(x, y)
            if c[0] < min.x: min.x = c[0]
            if c[1] < min.y: min.y = c[1]
            if c[2] < min.z: min.z = c[2]
            if c[0] > max.x: max.x = c[0]
            if c[1] > max.y: max.y = c[1]
            if c[2] > max.z: max.z = c[2]
    color_range = max - min
    #print "min:", min
    #print "max:", max
    #bprint "dif:", color_range
    return color_range
Пример #6
0
def color_range(image):
    c = image.getPixelI(0,0)
    min = XYZ(c[0], c[1], c[2])
    max = XYZ(c[0], c[1], c[2])

    for x in range(image.size[0]):
        for y in range(image.size[1]):
            c = image.getPixelI(x, y)
            if c[0] < min.x : min.x = c[0]
            if c[1] < min.y : min.y = c[1]
            if c[2] < min.z : min.z = c[2]
            if c[0] > max.x : max.x = c[0]
            if c[1] > max.y : max.y = c[1]
            if c[2] > max.z : max.z = c[2]
    color_range = max - min
    #print "min:", min
    #print "max:", max
    #bprint "dif:", color_range
    return color_range
Пример #7
0
def main():

    Blender.Window.WaitCursor(1)
    editmode = Blender.Window.EditMode()
    if editmode:
        Blender.Window.EditMode(0)

    scene = Blender.Scene.GetCurrent()
    cpos = Blender.Window.GetCursorPos()
    target_location = XYZ(cpos[0], cpos[1], cpos[2])
    report = new_from_selection(scene, target_location, editmode)
    Blender.Redraw()

    if editmode:
        Blender.Window.EditMode(1)

    if report != "":
        text = "Preview Report %t|" + report + "|OK"
        Blender.Draw.PupMenu(text)
    Blender.Window.WaitCursor(0)
Пример #8
0
 def __init__(self, image):
     self.image = image
     self.offset = XYZ(0.0, 0.0, 0.0)
     self.repeat = XYZ(1.0, 1.0, 0.0)
     self.rotation = 0.0
     self.face = 0
Пример #9
0
def uv_corners(mesh, image=None):
    '''returns the four corner points of the UVTex layout
    for the sculpt map image'''
    debug(40, "primitive.uv_corners(%s, %s)" % (mesh.name, image.name))
    max_vu = XYZ(-99999.0, -99999.0, 0.0)
    min_vu = XYZ(99999.0, 99999.0, 0.0)
    max_uv = XYZ(-99999.0, -99999.0, 0.0)
    min_uv = XYZ(99999.0, 99999.0, 0.0)
    current_uv = mesh.activeUVLayer
    mesh.activeUVLayer = 'sculptie'
    if image:
        faces = [f for f in mesh.faces if f.image == image]
    else:
        faces = mesh.faces
    mesh.activeUVLayer = 'UVTex'
    for f in faces:
        for i in range(len(f.verts)):
            v = XYZ(round(f.uv[i][0], 6), round(f.uv[i][1], 6), 0.0)
            max_uv = max(max_uv, v)
            min_uv = min(min_uv, v)
            v = XYZ(round(f.uv[i][1], 6), round(f.uv[i][0], 6), 0.0)
            max_vu = max(max_vu, v)
            min_vu = min(min_vu, v)
    min_vu = XYZ(min_vu.y, min_vu.x, 0.0)
    max_vu = XYZ(max_vu.y, max_vu.x, 0.0)
    if min_vu == min_uv:
        min_uv.y = max_uv.y
    if max_vu == max_uv:
        max_vu.y = min_vu.y
    mesh.activeUVLayer = current_uv
    return min_vu, min_uv, max_vu, max_uv