Model Utilities. python script bug in obj2dattex.py

News and discussion of the PC port of Oolite.

Moderators: winston, another_commander

Post Reply
User avatar
Frame
---- E L I T E ----
---- E L I T E ----
Posts: 1477
Joined: Fri Mar 30, 2007 8:32 am
Location: Witchspace

Model Utilities. python script bug in obj2dattex.py

Post by Frame »

i recently created my first model for oolite..

I created my model in 3d max 7.0 and exported it to wavefront object. mymodel.obj

i struck upon a problem when i tried to convert it using the python script

i have installed python 2.5 on windows XP enterprise (updated all across the line)

when the script obj2dattex.py was executed..

"it said, error in line 73 empty float"
x = -float(tokens[1])

i looked at the script and the object file..

The section of the script in Question looks like this

Code: Select all

	for line in lines:
		tokens = string.split(line, ' ')
		if (tokens[0] == 'v'):
			n_verts = n_verts + 1
	#		x = float(tokens[1])
	# negate x value for vertex to allow correct texturing...
			x = -float(tokens[1])
			y = float(tokens[2])
			z = float(tokens[3])
			vertex.append( ( x, y, z) )
What happens here is ofcourse it looks for for the Character 'V'
after which it puts the next Character into X, and makes it negative

The obj file i was using lookes like this at the first line where it has 'v'

Code: Select all


v  -0.01808810 6.54705524 -7.28214598

Notice that following immiditately after the 'v' is 2 spaces

this means that as far as i can understand that now during the scripts
first loop here that

token[0]='v '
token[1]=' ' <--- notice it holds a space a white space
token[2]='-0.01808810 '
token[3]='6.54705524 '

i have no idea how string.split(line, ' ') works but can understand how it is supposed to work..

i figured it had that empty slot in

token[1], and therefore

token[2] would hold the X value
token[3] would hold the Y value
token[4] would hold the Z value

so, i alterd the script accordingly to

Code: Select all


			x = -float(tokens[2])
			y = float(tokens[3])
			z = float(tokens[4])
and viola it works, and proof of it is that my model/s is ingame... :-D
i have no clue who to report this to but i figured someone here prolly has something todo with it..

Cheers

Frame
User avatar
JensAyton
Grand Admiral Emeritus
Grand Admiral Emeritus
Posts: 6657
Joined: Sat Apr 02, 2005 2:43 pm
Location: Sweden
Contact:

Post by JensAyton »

Hmm. The script is by Giles, who’s mostly not here any more. The problem seems to be that it’s expecting tokens to be separated specifically by spaces, but should be allowing arbitrary whitespace. I don’t know how to do this in Python, though. Anyone?

Edit: actually, it seems that all that’s needed is to remove the explicit separator, i.e. change string.split(line, ' ') to string.split(line).
zevans
---- E L I T E ----
---- E L I T E ----
Posts: 332
Joined: Mon Jul 06, 2009 11:12 pm
Location: Uncharted backwaters of the unfashionable end of the western spiral arm

Post by zevans »

I don't know python 2.6, but I do know Cobra Mk III. (Sorry, couldn't resist.)

There appears to be the stub of a tutorial which does not seem related to Giles's "Flying Brick" job - looks like Draco Caeles ('im again :-) ) started it. I wonder if Draco would object to creating a bastard child that was slightly less good than either of these tutorials but contained all the info from both, plus the two threads on the go here?

http://wiki.alioth.net/index.php?title= ... _your_Mind
User avatar
Thargoid
Thargoid
Thargoid
Posts: 5528
Joined: Thu Jun 12, 2008 6:55 pm

Post by Thargoid »

If I remember rightly some of these oddities can be overcome by installing Wings3D, and rather than using it to actually do the modelling just use it to import and then re-export the .obj file.

The output of Wings seems to play quite well with the scripts (better than the output of other packages) so you end up using it as an .obj --> .obj convertor.
Post Reply