View Single Post
Old 06-11-07, 01:27   #14
sapper
Archaeologist
 
sapper's Avatar
 
Join Date: Sep 2007
Posts: 1,677
Default

Here's Larson's UV tutorial (in German).

Here's an in game pic of Lara with the modified head. Only need to sort out the lighting.



Wadmerger doesn't like it though.



Blender's dxf export is no good for Strpix. Is there an export script for Blender that supports Strpix's version of dxf? TPascal explains the format in his Strpix readme.

Edit: Couldn't find a script that exports to DXF 3DFACE format so wrote a crude Blender python script that exports to dxf in a 3Dface format suitable for StrPix and Meta.

Code:
#!BPY 
""" 
Name: 'TurboPascal DXF ("TurboP.dxf")...' 
Blender: 245 
Group: 'Export' 
Tooltip: 'Exports a mesh to a basic DXF 3DFace format' 
""" 

__author__ = 'sapper'

__version__ = '1.0.1a'
__bpydoc__ = """The DXF 3dFace format used in this script
 is based on that produced by "Metasequoia", so is
compatible with TurboPascal's "StrPix".

No warranty that the DXF file meets official
DXF specifications.
"""


# ***** BEGIN GPL LICENSE BLOCK *****
#
# Script copyright (C) sapper 
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
#
# ***** END GPL LICENCE BLOCK *****
# --------------------------------------------------------------------------


import Blender
from Blender import Scene, Mesh, Window, sys 
import BPyMessages 
from Blender.Window import *
import bpy 


def bar(number,n,msg):
		DrawProgressBar (number / float(n), msg)
			
			
# alert user of something
def alertUser(message, title):
	Blender.Draw.PupMenu('TurboPascal dxf export ' + title + '%t|' + message)

	
def dxf_header(f):
	f.write('0\n')
	f.write('SECTION\n')
	f.write('2\n')
	f.write('ENTITIES\n')
	f.write('999\n')
	f.write('Created by Blender TP_DXF script\n')
	
	
def dxf_3dface(f,layer):
	f.write('0\n')
	f.write('3DFACE\n')
	f.write('8\n')
	f.write('%s\n' %layer)
	f.write('62\n')
	f.write('1\n')	
	
	
def dxf_tail(f):
	f.write('0\n')
	f.write('ENDSEC\n')
	f.write('0\n')
	f.write('EOF\n')
	
 
def write_dxf(me,filename):
						
	# Create the output file.  
	#with open(filename,'w') as fn: #doesn't work yet?
	try:
		fn = open(filename,'w')
		
		# Write the DXF header to the file.
		dxf_header(fn) 
					
		# For each face in the mesh get the x, y, z
		# co-ords for each vertex of the face and
		# print to console and write to file.
		for f in me.faces:
								
			# Give the first 400 faces a unique layer
			# name so in StrPix each face has a unique 
			# texture. Change if you know how many textures
			# in opened wad.
			if f.index <= 399:
				layername = 'Textur_%04u_0_0' %(f.index+1)
			else:
				layername = 'Textur_0400_0_0'
			
			dxf_3dface(fn,layername)
			
			# Draw progress bar at top right of screen that
			# advances as each face is processed
			bar(f.index,len(me.faces), 'Face %d' %f.index)
			
			print
			print 'Face index ', f.index
			if len(f) >3:
				print 'Quad'
			else:
				print 'Tri'
				
			for i in range(len(f)):
				print'-----------------'
				print 10+i
				fn.write('%d\n' %(10+i))
				print '%f' %f.v[i].co.x
				fn.write('%f\n' %f.v[i].co.x)			
				print 20+i
				fn.write('%d\n' %(20+i))
				print '%f' %f.v[i].co.y
				fn.write('%f\n' %f.v[i].co.y)
				print 30+i
				fn.write('%d\n' %(30+i))
		 		print '%f' %f.v[i].co.z
				fn.write('%f\n' %f.v[i].co.z)
			
			# If triangle make a fourth vertex using
			# the same co-ords as the third vertex.	
			if len(f) < 4:
				print'-----------------'
				print 13
				fn.write('13\n')
				print '%f' %f.v[2].co.x
				fn.write('%f\n' %f.v[2].co.x)
				print 23
				fn.write('23\n')
				print '%f' %f.v[2].co.y
				fn.write('%f\n' %f.v[2].co.y)
				print 33
				fn.write('33\n')
				print '%f' %f.v[2].co.z
				fn.write('%f\n' %f.v[2].co.z)
				
		dxf_tail(fn)
		
	finally:
		
		fn.close()


def save_dxf(filename):
		
	if not filename.lower().endswith('.dxf'):
		filename += '.dxf'
	
	if not BPyMessages.Warning_SaveOver(filename):
		return
	
	# Didn't want to use a global variable so get the mesh data here too.
	# Gets the current scene, there can be many scenes in 1 blend file. 
	sce = bpy.data.scenes.active 
	 
	# Get the active object, there can only ever be 1 
	# and the active object is always the editmode object. 
	ob_act = sce.objects.active 
	me = ob_act.getData(mesh=1)
			
	Window.WaitCursor(1)
	
	t = sys.time()
	
	# Print some basic info to the console for the user
	print
	print '=========================' 
	print 'object name', me.name 
	print 'vert count', len(me.verts) 
	print 'edge count', len(me.edges) 
	print 'face count', len(me.faces)
	
	write_dxf(me,filename) 
			
	print
	print 'Data written to %s' %filename
			
	# Timing the script is a good way to be aware on any speed hits when scripting 
	print
	print 'Script finished in %.2f seconds' % (sys.time()-t) 
	
	DrawProgressBar (1.0, "Finished")
	Window.WaitCursor(0) 
	
def main():	
	# Gets the current scene, there can be many scenes in 1 blend file. 
	sce = bpy.data.scenes.active 
	 
	# Get the active object, there can only ever be 1 
	# and the active object is always the editmode object. 
	ob_act = sce.objects.active 
		 
	if not ob_act or ob_act.type != 'Mesh': 
		BPyMessages.Error_NoMeshActive() 
	else:		
		# Saves the editmode state and goes out of  
		# editmode if its enabled since changes to 
		# mesh data only take effect when edit mode 
		# is exited.
		is_editmode = Window.EditMode() 
		if is_editmode: Window.EditMode(0) 
		
		# Only run script if faces exist.
		if len(ob_act.getData(mesh=1).faces) > 0:
			Blender.Window.FileSelector(save_dxf, "Export TP_DXF", Blender.sys.makename('TurboP',ext='.dxf'))
					
		else:
			msg = 'NO FACES!!...No data written to file'
			print
			print msg
			alertUser(msg, 'Notice') 
			
		# Restore editmode if it was enabled 
		if is_editmode: Window.EditMode(1) 

	 
# This lets you can import the script without running it 
if __name__ == '__main__': 
	main()
Planned changes for the script: try and use the face.image property to hold the layer name. This means if you name your images for texturing 0001 etc you can texture in Blender and when you export the layer names will correspond with the textures. Then if you import into StrPix as long as the textures are in order , i.e texture #1 is image 0001 the model should be textured. edit: I managed to get the layer names corresponding to the UV texture image names (not done in script above) but it's beyond me to get the face orientation to match the default orientation in StrPix.

Last edited by sapper; 17-03-08 at 04:39. Reason: refined the script
sapper is offline   Reply With Quote