예제 #1
0
파일: image.py 프로젝트: nttputus/blensor
def new(path, name=False, relative = True, premul = True) :
    path = bel.fs.clean(path)
    # check file
    if bel.fs.isfile(path) == False :
        dprint('Texture image not found')
        return False

    if relative :
        try :
            path = bpy.path.relpath(path)
            path = bel.fs.clean(path)
        except : 
            print('cant turn path into relative one (.blend and img path drive letters ?) ')
        
    # retrieve paths to image file from existing image slot
    # returns img if paths match
    for img in bpy.data.images :
        if img.filepath != '' :
            if bpy.path.abspath(path) == bpy.path.abspath(bel.fs.clean(img.filepath)) :
                return img

    # create a unique name in image slot
    if name == False : 
        name = bpy.path.basename(path)
    name = bel.bpyname(name,bpy.data.images.keys())

    # finally :
    img = bpy.data.images.load(filepath=path)
    img.name = name
    img.use_premultiply = premul
    return img
예제 #2
0
    def getName(l,tokens) :
        xnam = l.split(' ')[1].strip()
        
        #if xnam[0] == '{' : xnam = ''
        if xnam and xnam[-1] == '{' : xnam = xnam[:-1]
        
        name = xnam
        if len(name) == 0 : name = l.split(' ')[0].strip()
        
        namelookup[xnam] = bel.bpyname(name,tokens,4)

        return namelookup[xnam]