示例#1
0
def loadmodel(file, words, data):
  def nwprop(file, words, data):
    data['nwnprops'].write('SCENE.%s=%s\n'%(words[0], words[1]))
  modeldict={'beginmodelgeom': loadgeometry, 'donemodel': linereaderbreak,
        'classification': nwprop, 'supermodel': nwprop, 'newanim': loadanim}
  data={'scene': Scene.getCurrent(), 'nwnprops': Text.New('nwnprops'),
          'animnextframe': 2, 'nwnanims': Text.New('nwnanims'), 'fps': 30}
  raise ExitLineReader(linereader(file, modeldict, data))
  # Seems I can't modify the frame settings.
  #data['scene'].startFrame(1)
  #data['scene'].currentFrame(1)
  #data['scene'].endFrame(data['animnextframe']-1)
  data['scene'].update()
示例#2
0
def saveblend():
	"""
	Save the current .blend file as a temporary file.
	@returns: (scn,context,scenename,name)

	scn is the current scene object
	context the current rendering context
	scenename the name of the current scene
	name the name of the temporary file

	@warning: sideeffect: sets displaymode to 0 (=rendering in imagewindow) to
	prevent rendering window popping up
	"""
	Blender.PackAll()
	from tempfile import mkstemp
	fd,name = mkstemp(suffix = '.blend')
	os.close(fd)
	Blender.Set('compressfile',True)
	Blender.Save(name,1)
	scn = Scene.getCurrent()
	scenename = scn.getName()
	context = scn.getRenderingContext()
	context.displayMode=0 #to prevent an additional render window popping up
	return (scn,context,scenename,name)
for line in lines[1:i-1] :
    lineSplit = line.split()
    orientationTimeStamp.append( float(lineSplit[0]) / 1000000000.0 )
    orientationXValues.append( float(lineSplit[1]) )
    orientationYValues.append( float(lineSplit[2]) )
    orientationZValues.append( float(lineSplit[3]) )
for line in lines[i+1:] :
    lineSplit = line.split()
    accelerationTimeStamp.append( float(lineSplit[0]) / 1000000000.0 )
    accelerationXValues.append( float(lineSplit[1]) )
    accelerationYValues.append( float(lineSplit[2]) )
    accelerationZValues.append( float(lineSplit[3]) )

#Create the camera

cur = Scene.getCurrent()

cam = Camera.New('persp')
cam.lens = 35.0
cam.setDrawSize(1.0)
obj = Object.New('Camera')
obj.name = "imported_camera"
obj.link(cam)
cur.link(obj)
cur.setCurrentCamera(obj)

ipo = Blender.Ipo.New('Object','camera_ipo')
obj.setIpo(ipo)

locx = ipo.addCurve('LocX')
locx.setInterpolation('Linear')
示例#4
0
def G3DLoader(filename):            #Main Import Routine
    global imported, sceneID
    print "\nNow Importing File    : " + filename
    fileID = open(filename,"rb")
    header = G3DHeader(fileID)
    print "\nHeader ID             : " + header.id
    print "Version               : " + str(header.version)
    if header.id != "G3D":
        print "This is Not a G3D Model File"
        fileID.close
        return
    if header.version not in (3, 4):
        print "The Version of this G3D File is not Supported"
        fileID.close
        return
    in_editmode = Blender.Window.EditMode()             #Must leave Editmode when active
    if in_editmode: Blender.Window.EditMode(0)
    sceneID=Scene.getCurrent()                          #Get active Scene
    scenecontext=sceneID.getRenderingContext()          #To Access the Start/Endframe its so hidden i searched till i got angry :-)
    basename=str(Blender.sys.makename(filename,"",1))   #Generate the Base Filename without Path + extension
    imported = []
    maxframe=0
    if header.version == 3:
        modelheader = G3DModelHeaderv3(fileID)
        print "Number of Meshes      : " + str(modelheader.meshcount)
        for x in xrange(modelheader.meshcount):
            meshheader = G3DMeshHeaderv3(fileID)
            meshheader.isv4 = False    
            print "\nMesh Number           : " + str(x+1)
            print "framecount            : " + str(meshheader.framecount)
	    print "normalframecount      : " + str(meshheader.normalframecount)
	    print "texturecoordframecount: " + str(meshheader.texturecoordframecount)
	    print "colorframecount       : " + str(meshheader.colorframecount)
	    print "pointcount            : " + str(meshheader.vertexcount)
	    print "indexcount            : " + str(meshheader.indexcount)
	    print "texturename           : " + str(meshheader.texturefilename)
            print "hastexture            : " + str(meshheader.hastexture)
            print "istwosided            : " + str(meshheader.istwosided)
            print "customalpha           : " + str(meshheader.customalpha)
            meshheader.meshname = basename+str(x+1)     #Generate Meshname because V3 has none
            if meshheader.framecount > maxframe: maxframe = meshheader.framecount #Evaluate the maximal animationsteps
	    meshdata = G3DMeshdataV3(fileID,meshheader)
	    createMesh(filename,meshheader,meshdata)
        fileID.close
        print "Imported Objects: ",imported
        scenecontext.startFrame(1)      #Yeah finally found this Options :-)
        scenecontext.endFrame(maxframe) #Set it correctly to the last Animationstep :-))))
        Blender.Set("curframe",1)       #Why the Heck are the above Options not here accessible ????
        anchor = Object.New("Empty",basename) #Build an "empty" to Parent all meshes to it for easy handling
        sceneID.link(anchor)                #Link it to current Scene
        anchor.makeParent(imported)         #Make it Parent for all imported Meshes
        anchor.sel = 1                      #Select it
        if in_editmode: Blender.Window.EditMode(1) # Be nice and restore Editmode when was active
        return
    if header.version == 4:
        modelheader = G3DModelHeaderv4(fileID)
        print "Number of Meshes      : " + str(modelheader.meshcount)
        for x in xrange(modelheader.meshcount):
            meshheader = G3DMeshHeaderv4(fileID)
            meshheader.isv4 = False    
            print "\nMesh Number           : " + str(x+1)
	    print "meshname              : " + str(meshheader.meshname)
	    print "framecount            : " + str(meshheader.framecount)
	    print "vertexcount           : " + str(meshheader.vertexcount)
	    print "indexcount            : " + str(meshheader.indexcount)
	    print "diffusecolor          : %1.6f %1.6f %1.6f" %meshheader.diffusecolor
	    print "specularcolor         : %1.6f %1.6f %1.6f" %meshheader.specularcolor
	    print "specularpower         : %1.6f" %meshheader.specularpower
	    print "opacity               : %1.6f" %meshheader.opacity
	    print "properties            : " + str(meshheader.properties)
	    print "textures              : " + str(meshheader.textures)
	    print "texturename           : " + str(meshheader.texturefilename)
            if len(meshheader.meshname) ==0:    #When no Meshname in File Generate one
                meshheader.meshname = basename+str(x+1)
            if meshheader.framecount > maxframe: maxframe = meshheader.framecount #Evaluate the maximal animationsteps
   	    meshdata = G3DMeshdataV4(fileID,meshheader)
	    createMesh(filename,meshheader,meshdata)
        fileID.close
        scenecontext.startFrame(1)      #Yeah finally found this Options :-)
        scenecontext.endFrame(maxframe) #Set it correctly to the last Animationstep :-))))
        Blender.Set("curframe",1)       #Why the Heck are the above Options not here accessible ????
        anchor = Object.New("Empty",basename) #Build an "empty" to Parent all meshes to it for easy handling
        sceneID.link(anchor)                #Link it to current Scene
        anchor.makeParent(imported)         #Make it Parent for all imported Meshes
        anchor.sel = 1                      #Select it
        if in_editmode: Blender.Window.EditMode(1) # Be nice and restore Editmode when was active
        print "Created a empty Object as 'Grip' where all imported Objects are parented to"
        print "To move the complete Meshes only select this empty Object and move it"
        print "All Done, have a good Day :-)\n\n"
        return
示例#5
0
def Import(fileName):
	log.info("Starting ...")
	
	log.info("Importing MD3 model: %s", fileName)
	
	pathName = StripGamePath(StripModel(fileName))
	log.info("Shader path name: %s", pathName)
	
	modelName = StripExtension(StripPath(fileName))
	log.info("Model name: %s", modelName)
	
	# read the file in
	file = open(fileName,"rb")
	md3 = md3Object()
	md3.Load(file, log)
	md3.Dump(log)
	file.close()
	
	scene = Scene.getCurrent()
	
	for k in range(0, md3.numSurfaces):
		surface = md3.surfaces[k]
		
		# create a new mesh
		mesh = Mesh.New(surface.name)
		#uv = []
		uvList = []

		# make the verts
		for i in range(0, surface.numVerts):
			mesh.verts.extend( [surface.verts[i].xyz] )
	
		# make the faces
		for i in range(0, surface.numTriangles):
			mesh.faces.extend( surface.triangles[i].indexes )

		# use faceUV
		mesh.faceUV=True

		# extend ignores redundant faces
		log.info("Redundant faces for %s: %i", surface.name , surface.numTriangles-len(mesh.faces) )

		# make the UV list
		for tex_coord in surface.uv:
			u = tex_coord.u
			v = tex_coord.v
			uv = Mathutils.Vector([u,v])
			uvList.append(uv)

		# import uv
		log.info("uv")
		for i in range(0, len(mesh.faces)):
			uvData = []
			uvData.append(uvList[surface.triangles[i].indexes[0]])
			uvData.append(uvList[surface.triangles[i].indexes[1]])
			uvData.append(uvList[surface.triangles[i].indexes[2]])
			mesh.faces[i].uv = uvData
			# set smooth
			mesh.faces[i].smooth=1

		# add object
		log.info("addobj")
		meshObject = Object.New('Mesh',surface.name)
		meshObject.link(mesh)
		scene.link(meshObject)
		
		# animate the verts through keyframe animation
		log.info("anim")
		for i in range(0, surface.numFrames):
			
			# update the vertices
			for j in range(0, surface.numVerts):
				# i*sufrace.numVerts+j=where in the surface vertex list the vert position for this frame is
				#x = surface.verts[(i * surface.numVerts) + j].xyz[0]
				#y = surface.verts[(i * surface.numVerts) + j].xyz[1]
				#z = surface.verts[(i * surface.numVerts) + j].xyz[2]
	
				# put the vertex in the right spot
				#mesh.verts[j].co[0] = x
				#mesh.verts[j].co[1] = y
				#mesh.verts[j].co[2] = z
				xyz = Mathutils.Vector(surface.verts[(i * surface.numVerts) + j].xyz)
				mesh.verts[j].co = xyz
				
			meshObject.insertShapeKey()

		#select all and remove doubles
		mesh.sel=1
		mesh.remDoubles(0.0)

		# create materials for surface
		log.info("shade")
		for i in range(0, surface.numShaders):
			
			# create new material if necessary
			matName = StripExtension(StripPath(surface.shaders[i].name))
			if matName == "" :
				matName = "no_texture"
			
			try:
				mat = Material.Get(matName)
			except:
				log.info("Creating new material: %s", matName)
				mat = Material.New(matName)
			
				# create new texture
				texture = Texture.New(matName)
				texture.setType('Image')
			
				# try .tga by default
				imageName = StripExtension(GAMEDIR + surface.shaders[i].name) + '.tga'
				try:
					image = Image.Load(imageName)
				
					texture.image = image
				except:
					try:
						imageName = StripExtension(imageName) + '.png'
						image = Image.Load(imageName)
					
						texture.image = image
					except:
						try:
							imageName = StripExtension(imageName) + '.jpg'
							image = Image.Load(imageName)
						
							texture.image = image
						except:
							log.warning("Unable to load image: %s", imageName)
				
				# texture to material
				mat.setTexture(0, texture, Texture.TexCo.UV, Texture.MapTo.COL)
	
			# append material to the mesh's list of materials
			mesh.materials += [mat]
			mesh.update()

	for key in Key.Get() :
		key.ipo = Ipo.New('Key', "bleh" + "_ipo")
		index = 1
		for curveName in key.ipo.curveConsts :
			# print curveName
			key.ipo.addCurve(curveName)
			key.ipo[curveName].interpolation = IpoCurve.InterpTypes.CONST
			key.ipo[curveName].addBezier((0, 0))
			key.ipo[curveName].addBezier((index, 1))
			key.ipo[curveName].addBezier((index + 1, 0))
			index+=1
	#for key in Key.Get() :
	#	print key.ipo.curveConsts

	log.info("tags")
	# create tags
	for i in range(0, md3.numTags):
		tag = md3.tags[i]
		# this should be an Empty object
		blenderTag = Object.New("Empty", tag.name);
		# set ipo
		ipo = Ipo.New('Object', tag.name + "_ipo")
		locX = ipo.addCurve('LocX')
		locY = ipo.addCurve('LocY')
		locZ = ipo.addCurve('LocZ')
		rotX = ipo.addCurve('RotX')
		rotY = ipo.addCurve('RotY')
		rotZ = ipo.addCurve('RotZ')
		locX.interpolation=IpoCurve.InterpTypes.LINEAR
		locY.interpolation=IpoCurve.InterpTypes.LINEAR
		locZ.interpolation=IpoCurve.InterpTypes.LINEAR
		rotX.interpolation=IpoCurve.InterpTypes.LINEAR
		rotY.interpolation=IpoCurve.InterpTypes.LINEAR
		rotZ.interpolation=IpoCurve.InterpTypes.LINEAR
		#set ipo for tag
		blenderTag.setIpo(ipo)
		scene.link(blenderTag)
		blenderTag.setLocation(tag.origin)

	# FIXME this imports only the baseframe tags
	for i in range(0, md3.numFrames):

		for j in range(0, md3.numTags):
			tag = md3.tags[i * md3.numTags + j]
			#Blender.Set("curframe", i)
			#tagName = tag.name# + '_' + str(i)
			#blenderTag = Object.New("Empty", tagName);
			#tags.append(blenderTag)
			#scene.link(blenderTag)
			#blenderTag = tags[j]
			blenderTag = Object.Get(tag.name)
			ipo = Ipo.Get(tag.name + "_ipo")
			locX = ipo[Ipo.OB_LOCX]
			locY = ipo[Ipo.OB_LOCY]
			locZ = ipo[Ipo.OB_LOCZ]
			rotX = ipo[Ipo.OB_ROTX]
			rotY = ipo[Ipo.OB_ROTY]
			rotZ = ipo[Ipo.OB_ROTZ]

			# Note: Quake3 uses left-hand geometry
			forward = [tag.axis[0], tag.axis[1], tag.axis[2]]
			left = [tag.axis[3], tag.axis[4], tag.axis[5]]
			up = [tag.axis[6], tag.axis[7], tag.axis[8]]
		
			transform = MatrixSetupTransform(forward, left, up, tag.origin)
			transform2 = Blender.Mathutils.Matrix(transform[0], transform[1], transform[2], transform[3])
			rotation = Blender.Mathutils.Matrix(forward, left, up)
			rot_Euler = rotation.toEuler()
			#rot_Euler.unique()
			#blenderTag.setMatrix(transform2)
			#print "org: ", tag.origin
			locX.addBezier((i+1, tag.origin[0]))
			locY.addBezier((i+1, tag.origin[1]))
			locZ.addBezier((i+1, tag.origin[2]))
			rotX.addBezier((i+1, DEG2RAD(rot_Euler.x)))
			rotY.addBezier((i+1, DEG2RAD(rot_Euler.y)))
			rotZ.addBezier((i+1, DEG2RAD(rot_Euler.z)))
			#blenderTag.setLocation(tag.origin)
			#blenderTag.insertKey(i,"relative")

	# locate the Object containing the mesh at the cursor location
	if md3.numSurfaces:
		cursorPos = Blender.Window.GetCursorPos()
		#meshObject.setLocation(float(cursorPos[0]), float(cursorPos[1]), float(cursorPos[2]))
		meshObject.setLocation(float(cursorPos[0]), float(cursorPos[1]), float(cursorPos[2]))
示例#6
0
# ***** END GPL LICENCE BLOCK *****
# --------------------------------------------------------------------------

import Blender
from Blender import Scene
import os

x1 = float(os.getenv('x1'))
x2 = float(os.getenv('x2'))
y1 = float(os.getenv('y1'))
y2 = float(os.getenv('y2'))
part = str(os.getenv('part'))

border = [x1, y1, x2, y2]

scene = Scene.getCurrent()
context = scene.getRenderingContext()

context.enableBorderRender(1)
context.enableRGBAColor()
context.setImageType(Scene.Render.TARGA)
#context.enableCropping(1)
context.partsX(1)
context.partsY(1)

context.enableExtensions(1)
context.setRenderPath('//render_parts/' + "part_" + part +
                      "_")  # // is the currentdir
#w,h = context.imageSizeX(),context.imageSizeY()
print border[0]
print border[1]
示例#7
0
    def exporter(self, strNomFichierXML):
        print "----- debut export ----"
        # Récupération du fichier XML à patcher et vérification de son existence
        if not os.path.isfile(strNomFichierXML):
            strM = "Attention|Le fichier XML n'existe pas (%s)" % (strNomFichierXML)
            Draw.PupMenu(strM)
            print strM
            return

            # Récupération de réglages complémentaires
        EXPORT_FICHIERS_OBJ_VISU = Draw.Create(0)
        EXPORT_FICHIERS_OBJ_COLLISION = Draw.Create(0)

        # Récupération des options de l'utilisateur
        pup_block = []
        pup_block.append("Choix des informations à exporter :")
        pup_block.append(
            (
                "Maillages visualisation",
                EXPORT_FICHIERS_OBJ_VISU,
                "Enregistrer les maillages dans le dossier de visualisation",
            )
        )
        pup_block.append(
            (
                "Maillages collision",
                EXPORT_FICHIERS_OBJ_COLLISION,
                "Enregistrer les maillages dans le dossier de collision",
            )
        )
        if not Draw.PupBlock("Choix des informations à exporter", pup_block):
            return

            # Parcours de la scène à la recherche des objets à traiter
        Window.WaitCursor(1)
        scene = Scene.getCurrent()
        lst_obj = scene.objects

        fxStr = Xstring()
        fxFichier = Xfile()
        fxExportFichiers3D = CExport_fichiers3D()

        # - parcours des objets de la scène et mise à jour du fichier XML
        solide = Solide()
        solide.setParametresXML(strNomFichierXML)
        for obj in lst_obj:
            # obj = lst_obj[0]
            if obj.getType() == "Mesh":
                strNom = obj.getName()
                print strNom
                solide.setParametresObjet(obj)
                solide.afficher()

                strNomFichierObj_visuel = fxFichier.concatenerChemins(self.strChemin_modeles_visuels_, strNom + ".obj")
                strNomFichierObj_collision = fxFichier.concatenerChemins(
                    self.strChemin_modeles_collision_, strNom + ".obj"
                )
                if EXPORT_FICHIERS_OBJ_VISU.val == 1:
                    fxExportFichiers3D.writeObj(obj, strNomFichierObj_visuel)
                else:
                    print 'Pas d\'enregistrement du fichier "%s"' % (strNomFichierObj_visuel)
                if EXPORT_FICHIERS_OBJ_COLLISION.val == 1:
                    fxExportFichiers3D.writeObj(obj, strNomFichierObj_collision)
                else:
                    print 'Pas d\'enregistrement du fichier "%s"' % (strNomFichierObj_collision)

                    # - Patch du fichier XML (positions, couleurs, min et max pour les "regular grid")
                solide.mettre_fichier_XML_a_jour()  # ---->>>>>>>>

        Window.WaitCursor(0)
        return
示例#8
0
def Import(fileName):
    log.info("Starting ...")

    log.info("Importing MD3 model: %s", fileName)

    pathName = StripGamePath(StripModel(fileName))
    log.info("Shader path name: %s", pathName)

    modelName = StripExtension(StripPath(fileName))
    log.info("Model name: %s", modelName)

    # read the file in
    file = open(fileName, "rb")
    md3 = md3Object()
    md3.Load(file, log)
    md3.Dump(log)
    file.close()

    scene = Scene.getCurrent()

    for k in range(0, md3.numSurfaces):
        surface = md3.surfaces[k]

        # create a new mesh
        mesh = Mesh.New(surface.name)
        #uv = []
        uvList = []

        # make the verts
        for i in range(0, surface.numVerts):
            mesh.verts.extend([surface.verts[i].xyz])

        # make the faces
        for i in range(0, surface.numTriangles):
            mesh.faces.extend(surface.triangles[i].indexes)

        # use faceUV
        mesh.faceUV = True

        # extend ignores redundant faces
        log.info("Redundant faces for %s: %i", surface.name,
                 surface.numTriangles - len(mesh.faces))

        # make the UV list
        for tex_coord in surface.uv:
            u = tex_coord.u
            v = tex_coord.v
            uv = Mathutils.Vector([u, v])
            uvList.append(uv)

        # import uv
        log.info("uv")
        for i in range(0, len(mesh.faces)):
            uvData = []
            uvData.append(uvList[surface.triangles[i].indexes[0]])
            uvData.append(uvList[surface.triangles[i].indexes[1]])
            uvData.append(uvList[surface.triangles[i].indexes[2]])
            mesh.faces[i].uv = uvData
            # set smooth
            mesh.faces[i].smooth = 1

        # add object
        log.info("addobj")
        meshObject = Object.New('Mesh', surface.name)
        meshObject.link(mesh)
        scene.link(meshObject)

        # animate the verts through keyframe animation
        log.info("anim")
        for i in range(0, surface.numFrames):

            # update the vertices
            for j in range(0, surface.numVerts):
                # i*sufrace.numVerts+j=where in the surface vertex list the vert position for this frame is
                #x = surface.verts[(i * surface.numVerts) + j].xyz[0]
                #y = surface.verts[(i * surface.numVerts) + j].xyz[1]
                #z = surface.verts[(i * surface.numVerts) + j].xyz[2]

                # put the vertex in the right spot
                #mesh.verts[j].co[0] = x
                #mesh.verts[j].co[1] = y
                #mesh.verts[j].co[2] = z
                xyz = Mathutils.Vector(surface.verts[(i * surface.numVerts) +
                                                     j].xyz)
                mesh.verts[j].co = xyz

            meshObject.insertShapeKey()

        #select all and remove doubles
        mesh.sel = 1
        mesh.remDoubles(0.0)

        # create materials for surface
        log.info("shade")
        for i in range(0, surface.numShaders):

            # create new material if necessary
            matName = StripExtension(StripPath(surface.shaders[i].name))
            if matName == "":
                matName = "no_texture"

            try:
                mat = Material.Get(matName)
            except:
                log.info("Creating new material: %s", matName)
                mat = Material.New(matName)

                # create new texture
                texture = Texture.New(matName)
                texture.setType('Image')

                # try .tga by default
                imageName = StripExtension(GAMEDIR +
                                           surface.shaders[i].name) + '.tga'
                try:
                    image = Image.Load(imageName)

                    texture.image = image
                except:
                    try:
                        imageName = StripExtension(imageName) + '.png'
                        image = Image.Load(imageName)

                        texture.image = image
                    except:
                        try:
                            imageName = StripExtension(imageName) + '.jpg'
                            image = Image.Load(imageName)

                            texture.image = image
                        except:
                            log.warning("Unable to load image: %s", imageName)

                # texture to material
                mat.setTexture(0, texture, Texture.TexCo.UV, Texture.MapTo.COL)

            # append material to the mesh's list of materials
            mesh.materials += [mat]
            mesh.update()

    for key in Key.Get():
        key.ipo = Ipo.New('Key', "bleh" + "_ipo")
        index = 1
        for curveName in key.ipo.curveConsts:
            # print curveName
            key.ipo.addCurve(curveName)
            key.ipo[curveName].interpolation = IpoCurve.InterpTypes.CONST
            key.ipo[curveName].addBezier((0, 0))
            key.ipo[curveName].addBezier((index, 1))
            key.ipo[curveName].addBezier((index + 1, 0))
            index += 1
    #for key in Key.Get() :
    #	print key.ipo.curveConsts

    log.info("tags")
    # create tags
    for i in range(0, md3.numTags):
        tag = md3.tags[i]
        # this should be an Empty object
        blenderTag = Object.New("Empty", tag.name)
        # set ipo
        ipo = Ipo.New('Object', tag.name + "_ipo")
        locX = ipo.addCurve('LocX')
        locY = ipo.addCurve('LocY')
        locZ = ipo.addCurve('LocZ')
        rotX = ipo.addCurve('RotX')
        rotY = ipo.addCurve('RotY')
        rotZ = ipo.addCurve('RotZ')
        locX.interpolation = IpoCurve.InterpTypes.LINEAR
        locY.interpolation = IpoCurve.InterpTypes.LINEAR
        locZ.interpolation = IpoCurve.InterpTypes.LINEAR
        rotX.interpolation = IpoCurve.InterpTypes.LINEAR
        rotY.interpolation = IpoCurve.InterpTypes.LINEAR
        rotZ.interpolation = IpoCurve.InterpTypes.LINEAR
        #set ipo for tag
        blenderTag.setIpo(ipo)
        scene.link(blenderTag)
        blenderTag.setLocation(tag.origin)

    # FIXME this imports only the baseframe tags
    for i in range(0, md3.numFrames):

        for j in range(0, md3.numTags):
            tag = md3.tags[i * md3.numTags + j]
            #Blender.Set("curframe", i)
            #tagName = tag.name# + '_' + str(i)
            #blenderTag = Object.New("Empty", tagName);
            #tags.append(blenderTag)
            #scene.link(blenderTag)
            #blenderTag = tags[j]
            blenderTag = Object.Get(tag.name)
            ipo = Ipo.Get(tag.name + "_ipo")
            locX = ipo[Ipo.OB_LOCX]
            locY = ipo[Ipo.OB_LOCY]
            locZ = ipo[Ipo.OB_LOCZ]
            rotX = ipo[Ipo.OB_ROTX]
            rotY = ipo[Ipo.OB_ROTY]
            rotZ = ipo[Ipo.OB_ROTZ]

            # Note: Quake3 uses left-hand geometry
            forward = [tag.axis[0], tag.axis[1], tag.axis[2]]
            left = [tag.axis[3], tag.axis[4], tag.axis[5]]
            up = [tag.axis[6], tag.axis[7], tag.axis[8]]

            transform = MatrixSetupTransform(forward, left, up, tag.origin)
            transform2 = Blender.Mathutils.Matrix(transform[0], transform[1],
                                                  transform[2], transform[3])
            rotation = Blender.Mathutils.Matrix(forward, left, up)
            rot_Euler = rotation.toEuler()
            #rot_Euler.unique()
            #blenderTag.setMatrix(transform2)
            #print "org: ", tag.origin
            locX.addBezier((i + 1, tag.origin[0]))
            locY.addBezier((i + 1, tag.origin[1]))
            locZ.addBezier((i + 1, tag.origin[2]))
            rotX.addBezier((i + 1, DEG2RAD(rot_Euler.x)))
            rotY.addBezier((i + 1, DEG2RAD(rot_Euler.y)))
            rotZ.addBezier((i + 1, DEG2RAD(rot_Euler.z)))
            #blenderTag.setLocation(tag.origin)
            #blenderTag.insertKey(i,"relative")

    # locate the Object containing the mesh at the cursor location
    if md3.numSurfaces:
        cursorPos = Blender.Window.GetCursorPos()
        #meshObject.setLocation(float(cursorPos[0]), float(cursorPos[1]), float(cursorPos[2]))
        meshObject.setLocation(float(cursorPos[0]), float(cursorPos[1]),
                               float(cursorPos[2]))
示例#9
0
for line in lines[1:i - 1]:
    lineSplit = line.split()
    orientationTimeStamp.append(float(lineSplit[0]) / 1000000000.0)
    orientationXValues.append(float(lineSplit[1]))
    orientationYValues.append(float(lineSplit[2]))
    orientationZValues.append(float(lineSplit[3]))
for line in lines[i + 1:]:
    lineSplit = line.split()
    accelerationTimeStamp.append(float(lineSplit[0]) / 1000000000.0)
    accelerationXValues.append(float(lineSplit[1]))
    accelerationYValues.append(float(lineSplit[2]))
    accelerationZValues.append(float(lineSplit[3]))

#Create the camera

cur = Scene.getCurrent()

cam = Camera.New('persp')
cam.lens = 35.0
cam.setDrawSize(1.0)
obj = Object.New('Camera')
obj.name = "imported_camera"
obj.link(cam)
cur.link(obj)
cur.setCurrentCamera(obj)

ipo = Blender.Ipo.New('Object', 'camera_ipo')
obj.setIpo(ipo)

locx = ipo.addCurve('LocX')
locx.setInterpolation('Linear')
示例#10
0
# Get properties from the 'nwnprops' text.
Props.parse()

# Get logging.
logfile = Props.getlogfile()
if logfile:
	openlogfile(logfile)

# Some banner stuff right here...
putlog(NBLog.SPAM, "NeverBlender Blender->MDL export script")
putlog(NBLog.SPAM, "by Urpo Lankinen, 2003")

# Get the scene, and figure out which objects are whose children.
geometry = Props.getgeometry()
if(not geometry):
	scn = Scene.getCurrent()
else:
	putlog(NBLog.INFO, "Getting geometry from %s" % geometry)
	scn = Scene.Get(geometry)
	if(not scn):
		putlog(NBLog.CRITICAL,
		       "Error: Can't find the scene with the geometry.")
		exit
scnobjchilds = SceneHelpers.scenechildren(scn)

# Get the base object name.
model = Props.getbaseobjectname()
putlog(NBLog.INFO, "Base object: %s" % model)
# Some sanity checking...
if not scnobjchilds.has_key(model):
	putlog(NBLog.CRITICAL,