Esempio n. 1
0
	def __init__(self):
		"""
		Initialise scene root /scene and meshes NOH /meshes and delete if they exists to avoid conflicts
		
		"""
		self.CleanUp()
		self.mesh_uv = True
		self.mesh_col = False
		self.mesh_format = "n3d2"
		self.group = "examples"
		
		n2.new("nroot", "/export")
		
		self.model = n2.new("ntransformnode", "/export/model")
		n2.sel(self.model)
		self.tmp_mesh = n2.new("nscriptablemeshbuilder", "/export/meshes/tmp")
		self.mesh = n2.new("nscriptablemeshbuilder", "/export/meshes/model")
Esempio n. 2
0
	def ExportScene(self, scene=None):
		"""
		Export all objects in "scene"
		"""
		scn = Blender.Scene.GetCurrent()
		
		if(scene != None):
			scn = scene
		
		objs = scn.getChildren()
		
		if(len(objs)):
			root = n2.new("ntransformnode", self.filename)
			n2.sel(root)
			model = n2.new("ntransformnode", "model")
			n2.sel(model)
			for obj in objs:
				if(not obj.parent): #parented objects will be exported by parent
					self.ExportObj(obj)
			return True
		else:
			return False
Esempio n. 3
0
	def ExportObj(self, obj):
		"""
		Call for each object to be added to the export hierachy.
		
		"obj's" children will also be exported by this function.
		Usage. Only call directly when you need to export a single or selected objects, otherwise
		use ExportScene(blender_scene).
		Determine Nebula scenenode class by first checking for a property "class" in obj if not found
		determine through obj.getData() and if this fails export as ntransformnode.
		If "obj" has more than one material, create a transform node and export each material 
		group as a different nshapenode
		
		"""
		bl_type = obj.getType()
		obj_name = obj.getName()
		
		n2class = None #self.GetTypeFromProperty(obj)
		if(bl_type == "Mesh" and len(obj.getData(mesh=1).materials)>1):
			# Multimaterial mesh with 'class' property
			n2class = "ntransformnode"
		elif(bl_type == "Mesh" and len(obj.getData(mesh=1).materials)<=1):
			n2class = self.GetTypeFromProperty(obj)
			if(not n2class):
				n2class = "nshapenode"
				
		if(not n2class):
			n2class = self.GetTypeFromData(obj)
		
		node = n2.new(n2class, obj_name)
		n2.sel(node)
		
		# TODO: Set transform properties
		location = obj.getLocation()
		pos = [location[0], location[1], location[2]]
		
		rot = Mathutils.Euler(obj.getEuler())
		rot[0] = math.degrees(rot[0])
		rot[1] = math.degrees(rot[1])
		rot[2] = math.degrees(rot[2])
		
		size = obj.getSize()
		scale = [size[0], size[1], size[2]]
		
		if(obj.parent):
			parent = obj.parent
			parent_world_mat = parent.getMatrix("worldspace")
			
			# Copy wrapped data and Invert
			parent_world_mat = Mathutils.Matrix(parent_world_mat)
			parent_world_mat.invert()
			local_mat = obj.getMatrix("localspace")
			world_mat = obj.getMatrix("worldspace")
	
			local_mat = world_mat * parent_world_mat
			
			# Rotation
			rot = local_mat.rotationPart().toEuler()
			
			# Position
			pos[0] = local_mat[3][0]
			pos[1] = local_mat[3][1]
			pos[2] = local_mat[3][2]
			
			# Scale
			quat = local_mat.toQuat()
			inv_rot_mat = quat.toMatrix()
			inv_rot_mat.resize4x4()
			inv_rot_mat.invert()
			scale_mat = local_mat * inv_rot_mat
			
			scale[0] = scale_mat[0][0]
			scale[1] = scale_mat[1][1]
			scale[2] = scale_mat[2][2]
		
		node.setposition(-pos[0], pos[2], pos[1])
		node.seteuler(-rot[0], rot[2], rot[1])
		node.setscale(scale[0], scale[2], scale[1])	
		
		if(bl_type == "Mesh"):
			self.ExportAsMesh(obj)
		elif(bl_type == "Lamp"):
			self.ExportAsLight(obj)
			
		# TODO: Export Animators
		
		# Get objects children and export each one while still in parent object's working directory
		children = GetChildren(obj)
		for child in children:
			# HACK: Dont export objetcs whose parent is a light and name is <parent>_color
			if(obj.getType()=="Lamp" and child.getName()==(obj.getName()+"_color")):
				# child provides color information
				pass
			else:
				self.ExportObj(child)
		# Select initial working dirctory
		n2.sel("..")
Esempio n. 4
0
	def CleanUp(self):
		n2.sel("/")
		if(n2.exists("/export")):
			n2.delete("/export")