diff options
author | Campbell Barton <ideasman42@gmail.com> | 2007-03-27 18:49:37 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2007-03-27 18:49:37 +0400 |
commit | 30fb777971de40db481074e4ac3ab3de6502d8f3 (patch) | |
tree | 0b022839bdffee4c69776d8cff2912efdae019ff /release | |
parent | 66238eab7c618286f4097254e255db44b29d4e61 (diff) |
py api
bpy.*libBlickSeq*.new() - name is now an optiona arg.
moved some more scripts to bpy.* api.
Diffstat (limited to 'release')
-rw-r--r-- | release/scripts/3ds_import.py | 28 | ||||
-rw-r--r-- | release/scripts/bpymodules/BPyImage.py | 10 | ||||
-rw-r--r-- | release/scripts/bvh_import.py | 21 | ||||
-rw-r--r-- | release/scripts/import_obj.py | 11 |
4 files changed, 28 insertions, 42 deletions
diff --git a/release/scripts/3ds_import.py b/release/scripts/3ds_import.py index 6cec591ac4f..2931e45c274 100644 --- a/release/scripts/3ds_import.py +++ b/release/scripts/3ds_import.py @@ -143,7 +143,7 @@ BOUNDS_3DS= [] #which shold be more useful. def createBlenderTexture(material, name, image): - texture= Texture.New(name) + texture= bpy.textures.new(name) texture.setType('Image') texture.image= image material.setTexture(0, texture, Texture.TexCo.UV, Texture.MapTo.COL) @@ -365,8 +365,8 @@ def process_next_chunk(file, previous_chunk, importedObjects, IMAGE_SEARCH): vertsToUse = [i for i in xrange(len(myContextMesh_vertls)) if faceVertUsers[i]] myVertMapping = dict( [ (ii, i) for i, ii in enumerate(vertsToUse) ] ) - ##bmesh = Mesh.New(contextMesh.name) - bmesh = Mesh.New() + tempName= '%s_%s' % (contextObName, matName) # matName may be None. + bmesh = bpy.meshes.new(tempName) if matName == None: img= None @@ -398,12 +398,7 @@ def process_next_chunk(file, previous_chunk, importedObjects, IMAGE_SEARCH): if img: targetFace.image= img - tempName= '%s_%s' % (contextObName, matName) # matName may be None. - bmesh.name= tempName - # bmesh.transform(contextMatrix) - # ob = Object.New('Mesh', tempName) - # ob.link(bmesh) ob = SCN_OBJECTS.new(bmesh, tempName) ''' if contextMatrix_tx: @@ -466,7 +461,7 @@ def process_next_chunk(file, previous_chunk, importedObjects, IMAGE_SEARCH): #is it a material chunk? elif (new_chunk.ID==MATERIAL): #print 'elif (new_chunk.ID==MATERIAL):' - contextMaterial= Material.New() + contextMaterial= bpy.materials.new('Material') elif (new_chunk.ID==MAT_NAME): #print 'elif (new_chunk.ID==MAT_NAME):' @@ -525,7 +520,7 @@ def process_next_chunk(file, previous_chunk, importedObjects, IMAGE_SEARCH): elif (new_chunk.ID==MAT_TEXTURE_MAP): #print 'elif (new_chunk.ID==MAT_TEXTURE_MAP):' - new_texture= Blender.Texture.New('Diffuse') + new_texture= bpy.textures.new('Diffuse') new_texture.setType('Image') img = None while (new_chunk.bytes_read<new_chunk.length): @@ -549,7 +544,7 @@ def process_next_chunk(file, previous_chunk, importedObjects, IMAGE_SEARCH): elif (new_chunk.ID==MAT_SPECULAR_MAP): #print 'elif (new_chunk.ID==MAT_SPECULAR_MAP):' - new_texture= Blender.Texture.New('Specular') + new_texture= bpy.textures.new('Specular') new_texture.setType('Image') img = None while (new_chunk.bytes_read<new_chunk.length): @@ -571,7 +566,7 @@ def process_next_chunk(file, previous_chunk, importedObjects, IMAGE_SEARCH): elif (new_chunk.ID==MAT_OPACITY_MAP): #print 'new_texture=Blender.Texture.New('Opacity')' - new_texture= Blender.Texture.New('Opacity') + new_texture= bpy.textures.new('Opacity') new_texture.setType('Image') img = None while (new_chunk.bytes_read<new_chunk.length): @@ -592,7 +587,7 @@ def process_next_chunk(file, previous_chunk, importedObjects, IMAGE_SEARCH): elif (new_chunk.ID==MAT_BUMP_MAP): #print 'elif (new_chunk.ID==MAT_BUMP_MAP):' - new_texture= Blender.Texture.New('Bump') + new_texture= bpy.textures.new('Bump') new_texture.setType('Image') img = None while (new_chunk.bytes_read<new_chunk.length): @@ -624,20 +619,17 @@ def process_next_chunk(file, previous_chunk, importedObjects, IMAGE_SEARCH): elif (new_chunk.ID==OBJECT_LAMP): # Basic lamp support. - #print 'LAMP!!!!!!!!!' temp_data=file.read(STRUCT_SIZE_3FLOAT) x,y,z=unpack('<3f', temp_data) new_chunk.bytes_read+=STRUCT_SIZE_3FLOAT - contextLamp[0]= Object.New('Lamp') - contextLamp[1]= Lamp.New() + contextLamp[1]= bpy.lamps.new() + contextLamp[0]= SCN_OBJECTS.link(contextLamp[1]) contextLamp[0].link(contextLamp[1]) ##scn.link(contextLamp[0]) importedObjects.append(contextLamp[0]) - - #print 'number of faces: ', num_faces #print x,y,z contextLamp[0].setLocation(x,y,z) diff --git a/release/scripts/bpymodules/BPyImage.py b/release/scripts/bpymodules/BPyImage.py index 7f6de5366c6..ac61264662f 100644 --- a/release/scripts/bpymodules/BPyImage.py +++ b/release/scripts/bpymodules/BPyImage.py @@ -26,7 +26,7 @@ # Comprehensive image loader, will search and find the image # # Will return a blender image or a new image if the image is missing # #===========================================================================# -import Blender +import bpy from Blender import sys try: import os @@ -101,7 +101,7 @@ def comprehensiveImageLoad(imagePath, filePath, PLACE_HOLDER= True, RECURSIVE=Tr #if path.endswith('\\') or path.endswith('/'): # raise 'INVALID PATH' try: - img = Blender.Image.Load(path) + img = bpy.images.new(filename=path) if VERBOSE: print '\t\tImage loaded "%s"' % path return img except: @@ -109,7 +109,7 @@ def comprehensiveImageLoad(imagePath, filePath, PLACE_HOLDER= True, RECURSIVE=Tr if sys.exists(path): print '\t\tImage failed loading "%s", mabe its not a format blender can read.' % (path) else: print '\t\tImage not found, making a place holder "%s"' % (path) if PLACE_HOLDER: - img= Blender.Image.New(stripPath(path),1,1,24) + img= bpy.images.new(stripPath(path),4,4) img.filename= path return img #blank image else: @@ -123,7 +123,7 @@ def comprehensiveImageLoad(imagePath, filePath, PLACE_HOLDER= True, RECURSIVE=Tr imageFileName_lower = imageFileName.lower() # image path only if VERBOSE: print '\tSearchingExisting Images for "%s"' % imagePath - for i in Blender.Image.Get(): + for i in bpy.images: if stripPath(i.filename.lower()) == imageFileName_lower: if VERBOSE: print '\t\tUsing existing image.' return i @@ -188,7 +188,7 @@ def comprehensiveImageLoad(imagePath, filePath, PLACE_HOLDER= True, RECURSIVE=Tr else: if VERBOSE: print '\tNo Path: "%s"' % tmpPath - tmpPath = addSlash(Blender.Get('texturesdir')) + tmpPath = addSlash(bpy.config.textureDir) if tmpPath and sys.exists(tmpPath): if VERBOSE: print '\t\tSearching in %s' % tmpPath paths[tmpPath] = [os.listdir(tmpPath)] # Orig name for loading diff --git a/release/scripts/bvh_import.py b/release/scripts/bvh_import.py index 68e4bf3aac4..8d54a9e0fe5 100644 --- a/release/scripts/bvh_import.py +++ b/release/scripts/bvh_import.py @@ -358,10 +358,9 @@ def bvh_node_dict2objects(bvh_nodes, IMPORT_START_FRAME= 1, IMPORT_LOOP= False): scn.update(1) return objects - -#TODO, armature loading + def bvh_node_dict2armature(bvh_nodes, IMPORT_START_FRAME= 1, IMPORT_LOOP= False): if IMPORT_START_FRAME<1: @@ -369,10 +368,13 @@ def bvh_node_dict2armature(bvh_nodes, IMPORT_START_FRAME= 1, IMPORT_LOOP= False) # Add the new armature, - arm_ob= Blender.Object.New('Armature') - arm_data= Blender.Armature.Armature('myArmature') - arm_ob.link(arm_data) + scn = bpy.scenes.active + scn.objects.selected = [] + arm_data= bpy.armatures.new() + arm_ob = scn.objects.new(arm_data) + scn.objects.context = [arm_ob] + scn.objects.active = arm_ob # Put us into editmode arm_data.makeEditable() @@ -441,15 +443,6 @@ def bvh_node_dict2armature(bvh_nodes, IMPORT_START_FRAME= 1, IMPORT_LOOP= False) arm_data.update() - - - scn= bpy.scenes.active - - scn.objects.selected = [] - - scn.link(arm_ob) - scn.objects.context = [arm_ob] - # Now Apply the animation to the armature # Get armature animation data diff --git a/release/scripts/import_obj.py b/release/scripts/import_obj.py index 6c66b2097a8..699be0a265e 100644 --- a/release/scripts/import_obj.py +++ b/release/scripts/import_obj.py @@ -41,6 +41,7 @@ Note, This loads mesh objects and materials only, nurbs and curves are not suppo # -------------------------------------------------------------------------- from Blender import * +import bpy import BPyMesh import BPyImage import BPyMessages @@ -117,7 +118,7 @@ def create_materials(filepath, material_libs, unique_materials, unique_material_ #==================================================================================# def load_material_image(blender_material, context_material_name, imagepath, type): - texture= Texture.New(type) + texture= bpy.textures.new(type) texture.setType('Image') # Absolute path - c:\.. etc would work here @@ -167,7 +168,7 @@ def create_materials(filepath, material_libs, unique_materials, unique_material_ #Create new materials for name in unique_materials.iterkeys(): - unique_materials[name]= Material.New(name) + unique_materials[name]= bpy.materials.new(name) unique_material_images[name]= None, False # assign None to all material images to start with, add to later. @@ -426,7 +427,7 @@ def create_mesh(new_objects, has_ngons, CREATE_FGONS, CREATE_EDGES, verts_loc, v for name, index in material_mapping.iteritems(): materials[index]= unique_materials[name] - me= Mesh.New(dataname) + me= bpy.meshes.new(dataname) me.materials= materials[0:16] # make sure the list isnt too big. #me.verts.extend([(0,0,0)]) # dummy vert @@ -796,7 +797,7 @@ def load_obj_ui(filepath, BATCH_LOAD= False): return for f in files: - scn= Scene.New( stripExt(f) ) + scn= bpy.scenes.new( stripExt(f) ) scn.makeCurrent() load_obj(sys.join(filepath, f),\ @@ -861,7 +862,7 @@ else: _obj= _obj[:-1] print 'Importing', _obj, '\nNUMBER', i, 'of', len(lines) _obj_file= _obj.split('/')[-1].split('\\')[-1] - newScn= Scene.New(_obj_file) + newScn= bpy.scenes.new(_obj_file) newScn.makeCurrent() load_obj(_obj, False) |