示例#1
0
def processdownfrom(model,mfile):
	childs = scnobjchilds[model]
	putlog(NBLog.INFO,
	       "%s children: %s" % (model, join(childs, ", ")))

	for mchild in childs:
		processobject(mchild,model,mfile)
示例#2
0
	def setClassification(self,classification):
		if not classification in ['Character', 'Tile', 'Effects', 'Item']:
			putlog(NBLog.WARNING, 
				   "Unknown classification \"%s\", assuming \"Item\"."
				   % classification, "File")
			self._classification = 'Item'
		else:
			self._classification = classification
示例#3
0
	def _addFace(self, f):
		"""Takes a NMFace and puts its information to Trimesh."""
		# reminder: f is of type NMFace (NMesh Face).
		verts = len(f.v)
		if verts == 3:
			self._addTriangleFace(f)
		elif verts == 4:
			self._addQuadFace(f)
		else:
			putlog(NBLog.WARNING, 
			       "Wierd!  This face has %d verts!  " % verts +
				   "I'm going to pretend I didn't see that, but you might want to fix it.",
				   "Trimesh")
示例#4
0
def processdummy(model, parent):
    d = Object.Get(model)
    dt = d.getType()
    putlog(NBLog.INFO, "Processing %s (%s)" % (model, dt))
    if dt != 'Empty':
        putlog(NBLog.CRITICAL, "Internal error: Can't process this type here!")
        return
    dummy = Dummy()
    if parent != "NULL":
        dummy.setParent(parent)
    dummy.setName(model)
    dummyloc = d.getLocation()
    dummy.setPosition(dummyloc)
    return dummy
示例#5
0
def processdummy(model,parent):
	d = Object.Get(model)
	dt = d.getType()
	putlog(NBLog.INFO, "Processing %s (%s)" % (model, dt))
	if dt != 'Empty':
		putlog(NBLog.CRITICAL,
		       "Internal error: Can't process this type here!")
		return
	dummy = Dummy()
	if parent != "NULL":
		dummy.setParent(parent)
	dummy.setName(model)
	dummyloc = d.getLocation()
	dummy.setPosition(dummyloc)
	return dummy
示例#6
0
	def setScale(self, scalelist):
		assert len(scalelist) == 3
		if scalelist[0] != scalelist[1] or \
		  scalelist[1] != scalelist[2] or \
		  scalelist[0] != scalelist[2]:
			self.Scale = \
			      (scalelist[0]+scalelist[1]+scalelist[2]) / 3
			putlog(NBLog.WARNING, 
			       "Object %s scale not uniform! " +
			       "x = %f, y = %f, z = %f "+
			       "Using avg scale as uniform scale: %f" %
			       (self.Name, scalelist[0], scalelist[1], scalelist[2],
					self.Scale), "Trimesh")
		else:
			putlog(NBLog.SPAM, 
			       "Object %s has uniform scale %f." % 
			       (self.Name,self.Scale), "Trimesh")
			self.Scale = scalelist[0]
示例#7
0
	def writeToFile(self):
		"""
		The actual work of exporting Blender data to MDL data is done
		in the Model superclass.  Here we just deal with getting the
		string given to us by Model into a file.  This really should
		know virtually nothing about the MDL format and absolutely
		nothing about Blender.
		"""
		
		odir = self.OutputDirectory or Props.getoutputdirectory()
		ofile = self.Name + '.' + self.FileFormat
		outfile = normpath(join(odir,ofile))

		if exists(outfile):
			# Delete existing file
			try:
				remove(outfile)
			except:
				putlog(NBLog.WARNING, 
					   "Couldn't remove existing file %s." +
					   "Can only hope we'll clobber it properly now..."
					   % outfile, "File")

		of = file(outfile, "w")
		putlog(NBLog.INFO, 
			   "Writing '%s' to file %s." % (self.Name,
											 outfile), "File")

		of.write("""\
# Model written by NeverBlender MDL Export Script
# File name: %s
# Built on: %s
filedependancy %s
""" % (outfile, asctime(), self.FileDependancy))

		# The conversion of a model to a string is defined in the Model class
		of.write(str(self))

		# "...and STAY down!!!" - Warrior, Myth III
		# FIXME: Apparently sometimes the file doesn't close properly?
		of.flush()
		fsync(of.fileno())
		of.close()
		of = 0
示例#8
0
    def writeToFile(self):
        """
		The actual work of exporting Blender data to MDL data is done
		in the Model superclass.  Here we just deal with getting the
		string given to us by Model into a file.  This really should
		know virtually nothing about the MDL format and absolutely
		nothing about Blender.
		"""

        odir = self.OutputDirectory or Props.getoutputdirectory()
        ofile = self.Name + '.' + self.FileFormat
        outfile = normpath(join(odir, ofile))

        if exists(outfile):
            # Delete existing file
            try:
                remove(outfile)
            except:
                putlog(
                    NBLog.WARNING, "Couldn't remove existing file %s." +
                    "Can only hope we'll clobber it properly now..." % outfile,
                    "File")

        of = file(outfile, "w")
        putlog(NBLog.INFO, "Writing '%s' to file %s." % (self.Name, outfile),
               "File")

        of.write("""\
# Model written by NeverBlender MDL Export Script
# File name: %s
# Built on: %s
filedependancy %s
""" % (outfile, asctime(), self.FileDependancy))

        # The conversion of a model to a string is defined in the Model class
        of.write(str(self))

        # "...and STAY down!!!" - Warrior, Myth III
        # FIXME: Apparently sometimes the file doesn't close properly?
        of.flush()
        fsync(of.fileno())
        of.close()
        of = 0
示例#9
0
	def __init__(self, obj=None, parent="NULL"):
		super(Trimesh, self).__init__(obj, parent)
		self.Type = 'trimesh'
		if obj:
			assert obj.getType() == 'Mesh'
			self.setScale(obj.size)
			
			objmats = obj.getMaterials()
			if len(objmats)>=1:
				putlog(NBLog.SPAM,
					   "Object has material(s).")
				# We only take the first material, for now.
				# (We'll do something more elegant later on...we hope)
				m = objmats[0]
				self.Wirecolor = m.rgbCol
				self.Specular = m.specCol
				
			self.SetMesh(obj.getData())
			
		else:
			putlog(NBLog.WARNING, "Eh?  A trimesh that doesn't exist?", "Trimesh")
示例#10
0
def parse():
	proptxt = Text.get('nwnprops')
	if not proptxt:
		putlog(NBLog.WARNING,
		       "Unable to find the configuration ('nwnprops'.) " +
		       "Using defaults...", "Props")
		return
		putlog(NBLog.SPAM, "Found configuration, parsing.", "Props")
	lines = proptxt.asLines()
	for l in lines:
		# Ignore comment lines and empty lines.
		if len(l) == 0:
			continue
		if l[0] == '#':
			continue
		# Find the separators.
		try:
			objectsep=l.index('.')
			valuesep=l.index('=', objectsep)
		except ValueError:
			putlog(NBLog.WARNING,
			       "Ignoring following conf entry " +
			       "(invalid format): " + l, "Props")
			continue
		object = l[0:objectsep]
		property = l[objectsep+1:valuesep]
		value = l[valuesep+1:]
		if not nwnprops.has_key(object):
			nwnprops[object] = {}
		nwnprops[object][property] = value
示例#11
0
def parse():
    proptxt = Text.get('nwnprops')
    if not proptxt:
        putlog(
            NBLog.WARNING, "Unable to find the configuration ('nwnprops'.) " +
            "Using defaults...", "Props")
        return
        putlog(NBLog.SPAM, "Found configuration, parsing.", "Props")
    lines = proptxt.asLines()
    for l in lines:
        # Ignore comment lines and empty lines.
        if len(l) == 0:
            continue
        if l[0] == '#':
            continue
        # Find the separators.
        try:
            objectsep = l.index('.')
            valuesep = l.index('=', objectsep)
        except ValueError:
            putlog(NBLog.WARNING,
                   "Ignoring following conf entry " + "(invalid format): " + l,
                   "Props")
            continue
        object = l[0:objectsep]
        property = l[objectsep + 1:valuesep]
        value = l[valuesep + 1:]
        if not nwnprops.has_key(object):
            nwnprops[object] = {}
        nwnprops[object][property] = value
示例#12
0
def processobject(model,parent,mfile):
	global scnobjchilds

	# Process this object
	#putlog(NBLog.DEBUG, "Processing object %s" % model)

	thismod = Object.Get(model)
	mtype = thismod.getType()
	if mtype == 'Empty':
		dummy = processdummy(model, parent)
		mfile.addObject(dummy)
	elif mtype == 'Mesh':
		# FIXME: Parent
		# new Trimesh class doesn't require processtrimesh
		#trimesh = processtrimesh(model, parent, 1)
		mfile.addObject(Trimesh(Object.Get(model), parent))
	elif mtype == 'Armature':
		# Special code to handle armature: We process the armature's
		# children "by hand" to make them parent to the armature's
		# parent instead of the armature.
		try:
			childs = scnobjchilds[model]
			putlog(NBLog.DEBUG,
			       "%s armature children: %s" % (model,
						       join(childs, ", ")))
			for mchild in childs:
				processobject(mchild,parent,mfile)
			return
		except KeyError:
			return
	else:
		putlog(NBLog.CRITICAL,
		       "Can't handle object of type %s" % mtype)
	# Process the children
	try:
		children = scnobjchilds[model]
	except KeyError:
		return
	processdownfrom(model,mfile)
示例#13
0
def processobject(model, parent, mfile):
    global scnobjchilds

    # Process this object
    #putlog(NBLog.DEBUG, "Processing object %s" % model)

    thismod = Object.Get(model)
    mtype = thismod.getType()
    if mtype == 'Empty':
        dummy = processdummy(model, parent)
        mfile.addObject(dummy)
    elif mtype == 'Mesh':
        # FIXME: Parent
        # new Trimesh class doesn't require processtrimesh
        #trimesh = processtrimesh(model, parent, 1)
        mfile.addObject(Trimesh(Object.Get(model), parent))
    elif mtype == 'Armature':
        # Special code to handle armature: We process the armature's
        # children "by hand" to make them parent to the armature's
        # parent instead of the armature.
        try:
            childs = scnobjchilds[model]
            putlog(NBLog.DEBUG,
                   "%s armature children: %s" % (model, join(childs, ", ")))
            for mchild in childs:
                processobject(mchild, parent, mfile)
            return
        except KeyError:
            return
    else:
        putlog(NBLog.CRITICAL, "Can't handle object of type %s" % mtype)
    # Process the children
    try:
        children = scnobjchilds[model]
    except KeyError:
        return
    processdownfrom(model, mfile)
示例#14
0
def processtrimesh(sobj, parent, details):
    """Process the Object named sobj and return a Trimesh. If
	details is true, also generates texture and such, otherwise
	just location, scale and orientation.

	DEPRECIATED - this should not be used - especially not with the new Trimesh
	"""

    # Get the Object block of the current object.
    obj = Object.Get(sobj)
    putlog(NBLog.INFO, "Processing %s (%s)" % (sobj, obj.getType()))
    if obj.getType() != 'Mesh':
        putlog(NBLog.CRITICAL, "Internal error: can only deal with meshes!")
        return

    # get the Mesh block of the Object.
    mesh = obj.getData()
    if not mesh:
        putlog(NBLog.CRITICAL,
               "Can't get the corresponding mesh. This is strange!")
        return

    # Create a new Trimesh to be output.
    trimesh = Trimesh()
    trimesh.setParent(model)
    trimesh.setName(sobj)

    # Get the object's information.

    # Location.
    objloc = obj.getLocation()
    trimesh.setPosition(objloc)

    # Rotation
    r = obj.getEuler()
    trimesh.setOrientation(r)

    # Scaling.
    s = obj.size  # Is there a getter for this? Goddamnit.
    trimesh.setScale(s)

    if details:
        # Materials.
        objmats = obj.getMaterials()
        if len(objmats) >= 1:
            putlog(NBLog.SPAM, "Object has material(s).")
            # We only take the first material, for now.
            # (We'll do something more elegant later on...)
            m = objmats[0]
            trimesh.setWireColor(m.rgbCol)
            trimesh.setSpecularColor(m.specCol)

        # Texture
        texture = Props.getobjecttex(sobj)
        trimesh.setTexture(texture)

        # Tilefade
        tilefade = Props.getobjecttilefade(sobj)
        trimesh.setTileFade(tilefade)

    # Get vertex list
    trimesh.setVerts(mesh.verts)
    # Get each Face (and Texvert).
    for f in mesh.faces:
        trimesh.addFace(f)
    # Then return it.
    putlog(NBLog.INFO,
           "Done: %d vertices, %d faces, %d texverts" % trimesh.stat())
    return trimesh
示例#15
0
def processdownfrom(model, mfile):
    childs = scnobjchilds[model]
    putlog(NBLog.INFO, "%s children: %s" % (model, join(childs, ", ")))

    for mchild in childs:
        processobject(mchild, model, mfile)
示例#16
0
    for mchild in childs:
        processobject(mchild, model, mfile)


#################################################################

# 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)
示例#17
0
	for mchild in childs:
		processobject(mchild,model,mfile)

#################################################################

# 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)
示例#18
0
def processtrimesh(sobj, parent, details):
	"""Process the Object named sobj and return a Trimesh. If
	details is true, also generates texture and such, otherwise
	just location, scale and orientation.

	DEPRECIATED - this should not be used - especially not with the new Trimesh
	"""

	# Get the Object block of the current object.
	obj = Object.Get(sobj)
	putlog(NBLog.INFO,
	       "Processing %s (%s)" % (sobj, obj.getType()))
	if obj.getType() != 'Mesh':
		putlog(NBLog.CRITICAL,
		       "Internal error: can only deal with meshes!")
		return

	# get the Mesh block of the Object.
	mesh = obj.getData()
	if not mesh:
		putlog(NBLog.CRITICAL,
		       "Can't get the corresponding mesh. This is strange!")
		return

	# Create a new Trimesh to be output.
	trimesh = Trimesh()
	trimesh.setParent(model)
	trimesh.setName(sobj)

	# Get the object's information.

	# Location.
	objloc = obj.getLocation()
	trimesh.setPosition(objloc)

	# Rotation
	r = obj.getEuler()
	trimesh.setOrientation(r)

	# Scaling.
	s = obj.size           # Is there a getter for this? Goddamnit.
	trimesh.setScale(s)

	if details:
		# Materials.
		objmats = obj.getMaterials()
		if len(objmats)>=1:
			putlog(NBLog.SPAM,
			       "Object has material(s).")
			# We only take the first material, for now.
			# (We'll do something more elegant later on...)
			m = objmats[0]
			trimesh.setWireColor(m.rgbCol)
			trimesh.setSpecularColor(m.specCol)
		
		# Texture
		texture = Props.getobjecttex(sobj)
		trimesh.setTexture(texture)
		
		# Tilefade
		tilefade = Props.getobjecttilefade(sobj)
		trimesh.setTileFade(tilefade)

	# Get vertex list
	trimesh.setVerts(mesh.verts)
	# Get each Face (and Texvert).
	for f in mesh.faces:
		trimesh.addFace(f)
	# Then return it.
	putlog(NBLog.INFO,
	       "Done: %d vertices, %d faces, %d texverts" % trimesh.stat())
	return trimesh