can sum1 make me something? please...


(ShadowDust) #1

ok, here’s what i wish i could make myself, but i find it hard learning lots of languages at once, lol, anyways if any1’s willing i’ll put the credits on any projects i use the exporter in, just give ppl more motivation, hehe… anyways as you’ve probably guessed it’s an export, import function but i mainly need an export function, here’s the format of the file:
the entire file is a normal txt file you could litteraly read in notepad.
a polygon(tri) is declared with

poly

then needs 9 values after it in this order
it doesnt say “vertex.x = blahblah” it just says “blahblah”


Vertex1.X
Vertex1.Y
Vertex1.Z
Vertex2.X
Vertex2.Y
Vertex2.Z
Vertex3.X
Vertex3.Y
Vertex3.Z

for quads

polyq

and twelve digits after


Vertex1.X
Vertex1.Y
Vertex1.Z
Vertex2.X
Vertex2.Y
Vertex2.Z
Vertex3.X
Vertex3.Y
Vertex3.Z
Vertex4.X
Vertex4.Y
Vertex4.Z

here’s wat a model file that is just a triangle looks like:


poly
0.0
1.0
0.0
-1.0
-1.0
0.0
1.0
-1.0
0.0
done

oh, i almost forgot, the model file must always have a ‘done’ at the end, other-wise the loader tries to load it eternally, until some one end tasks it…
i hope some can please help, if you can BIG thanks :smiley:

P.S at the moment there is no need for materials…


(LetterRip) #2

does it only take tris and quads?

It is fairly trivial to write it, but it is a ridiculously simple format, what is it used for?

LetterRip


(ShadowDust) #3

yup :slight_smile: it’s gonna be used for some games that dont require textured models, also they’re written in FreeBASIC… the poly’s are colored but i got a seprate program for that, because blender cant quite color them the way i need… thank you for your help.


(LetterRip) #4

how many decimal places do you want? Generally Blenders decimal place is only significant to four places or so.

LetterRip


(ShadowDust) #5

doesn’t matter, the model loading library can take any, so just give it the best blender can do :slight_smile:


(emackey) #6

ShadowDust, I hope you don’t mind my saying, but as 3D formats go that has to be one of the least useful I’ve ever seen.

Still, the simplicity made it easy to adapt another exporter to the task…

If you use it, please, don’t put my name anywhere near it. Thanks so much!! :smiley:

#!BPY

"""
Name: 'Lousy format (.txt)...'
Blender: 232
Group: 'Export'
Tooltip: 'Who would use this?'
"""

import Blender, os, time

#
# This function checks to make sure you've selected a mesh,
# then calls the file selector.
#
def precheck():
	objects = Blender.Object.GetSelected()
	if len(objects) != 1:
		Blender.Draw.PupMenu("Export%t|Please select just one mesh.")
		return

	type = objects[0].getType()
	if (type != "Mesh"):
		Blender.Draw.PupMenu("Export%t|Please select just one mesh.")
		return

	defname = Blender.sys.makename(Blender.Get('filename'), ext='.txt')
	Blender.Window.FileSelector(fs_callback, "Export TXT", defname)

#
# The file selector will call this when it's done.
#
def fs_callback(filename):
	if filename.find('.txt', -4) <= 0: filename += '.txt'
	write(filename)

#
# Main write function
#
def write(filename):
	start = time.clock()
	object = Blender.Object.GetSelected()[0]
	try:
		mesh = Blender.NMesh.GetRawFromObject(object.name)	# for SubSurf
	except:
		mesh = Blender.NMesh.GetRaw(object.data.name)

	file = open(filename, "w")
	for face in mesh.faces:
		numverts = len(face.v)
		if (numverts == 3):
			file.write("poly
")
		elif (numverts == 4):
			file.write("polyq
")
		else:
			continue
		for vert in face.v:
			file.write("%f
%f
%f
" % (vert.co[0], vert.co[1], vert.co[2]))
	file.write("done
")
	file.close()
	end = time.clock()
	seconds = " in %.2f %s" % (end-start, "seconds")
	message = "Successfully exported " + os.path.basename(filename) + seconds
	print message

################
# MAIN PROGRAM #
################
# This is effectively the main program, which just calls the precheck
# function and then triggers the file selector if things are all OK.

precheck()


(ShadowDust) #7

thx 4 the help :slight_smile: if you must know what exactly im using it for, it’s gonna be used for street racing game, in opengl, this file type can record changes in it’s structure(so when the player saves, so does the damage), and the true extension is .SDW, and for texturing, i’ve got another program, that will use a completely different way to texturing then blender, but i guess i probably would be the only one to use this %| anyways thx again…


(ShadowDust) #8

it doesn’t work :frowning: i would copy/paste the error messege but i cant it says something like:
Traceback (most recent call last):
File “<string>”, line 10, in ?
File “Python24\LIB\os.py”, line 133…

can some1 please fix it?

EDIT: i changed to python version 2.01 here’s the new error
File “<string>”, line 72, in ?
File “<string>”, line 27, in precheck
runtime error path too long


(Crouch) #9

You were right in changing the python version, but the correct python version for blender 2.37a is python 2.3.x
I just tested the script and it works fine for me.


(emackey) #10

Crouch is right, get the right version of Python… :slight_smile:

Anyway that os stuff isn’t needed by the export, it’s just printing a little status message there at the end. You can kill off those last two lines of the write() function, or just allow it to print the whole filename without calling the os module.


(ShadowDust) #11

ummm, can u change it for me please, cause im useless with python, lol, 2 me this language is strange, compared to what i usually work with c/javascript/basic


(Crouch) #12

#!BPY

"""
Name: 'Lousy format (.txt)...'
Blender: 232
Group: 'Export'
Tooltip: 'Who would use this?'
"""

import Blender

#
# This function checks to make sure you've selected a mesh,
# then calls the file selector.
#
def precheck():
   objects = Blender.Object.GetSelected()
   if len(objects) != 1:
      Blender.Draw.PupMenu("Export%t|Please select just one mesh.")
      return

   type = objects[0].getType()
   if (type != "Mesh"):
      Blender.Draw.PupMenu("Export%t|Please select just one mesh.")
      return
   
   filename = 'Blender_export.txt' 
   write(filename)

#
# Main write function
#
def write(filename):
   object = Blender.Object.GetSelected()[0]
   try:
      mesh = Blender.NMesh.GetRawFromObject(object.name)   # for SubSurf
   except:
      mesh = Blender.NMesh.GetRaw(object.data.name)

   file = open(filename, "w")
   for face in mesh.faces:
      numverts = len(face.v)
      if (numverts == 3):
         file.write("poly
")
      elif (numverts == 4):
         file.write("polyq
")
      else:
         continue
      for vert in face.v:
         file.write("%f
%f
%f
" % (vert.co[0], vert.co[1], vert.co[2]))
   file.write("done
")
   file.close()
   print "Successfully exported"

################
# MAIN PROGRAM #
################
# This is effectively the main program, which just calls the precheck
# function and then triggers the file selector if things are all OK.

precheck() 

This is a stripped down version of the previously posted script. It doesn’t need a python install, and it always exports the same: a file called ‘Blender_export’ in the folder where blender itself is installed. No calls to os, or anything like that.
Emackey: I agree with the BPY info. :stuck_out_tongue:


(ShadowDust) #13

the models seem to come out screwed up, the poly’s are linked to the wrong vertices :-?