bpy.*libBlickSeq*.new() - name is now an optiona arg.
moved some more scripts to bpy.* api.
This commit is contained in:
2007-03-27 14:49:37 +00:00
parent 66238eab7c
commit 30fb777971
6 changed files with 34 additions and 45 deletions

View File

@@ -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)

View File

@@ -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

View File

@@ -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

View File

@@ -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)

View File

@@ -457,7 +457,7 @@ PyObject *LibBlockSeq_new(BPy_LibBlockSeq *self, PyObject * args, PyObject *kwd)
/* New Data */
if (self->type == ID_IM) {
/* Image, accepts width and height*/
if( !PyArg_ParseTuple( args, "s|ii", &name, &img_width, &img_height ) )
if( !PyArg_ParseTuple( args, "|sii", &name, &img_width, &img_height ) )
return EXPP_ReturnPyObjError( PyExc_TypeError,
"one string and two ints expected as arguments" );
CLAMP(img_width, 4, 5000);
@@ -497,7 +497,7 @@ PyObject *LibBlockSeq_new(BPy_LibBlockSeq *self, PyObject * args, PyObject *kwd)
} else {
/* Other types only need the name */
if( !PyArg_ParseTuple( args, "s", &name ) )
if( !PyArg_ParseTuple( args, "|s", &name ) )
return EXPP_ReturnPyObjError( PyExc_TypeError,
"new(name) - name must be a string argument" );
}

View File

@@ -132,7 +132,6 @@ Example::
@type actions: L{libBlockSeq}
@var libraries: L{librarySeq<LibData>} submodule
@type libraries: L{librarySeq<LibData>}
"""
@@ -218,6 +217,10 @@ class libBlockSeq:
Most datatypes accept a name for their argument except for L{sounds}, L{fonts}, L{ipos} and L{curves} that need an additional argument.
The name argument is optional if not given a default name will be assigned.
The name given may be modified by blender to make it unique.
Loading From File
=================
For L{images}, L{texts}, L{sounds}, L{fonts} types you can use the filename keyword to make a new datablock from a file.