ANN: OBJ model format support - Page 4

ANN: OBJ model format support

Share and discuss visual creations and creation practices like texturing, modelling and musing on the meaning of life.

Moderators: MR.D, Moderators

User avatar
CarRepairer
Cursed Zero-K Developer
Posts: 3359
Joined: 07 Nov 2007, 21:48

Re: ANN: OBJ model format support

Post by CarRepairer »

Some questions...

1) First post says triangles only. Can you make the script automatically triangulate quads? There is an option in blender to do this.

2) First post says ccw winding order only. When mirroring pieces I think that it gets reversed for those pieces. You can flip normals in Blender for selected faces but I'm not sure if that's correct. Is there a way to apply the same winding order to every face in Blender? If so, can that also go into the script?
Kloot
Spring Developer
Posts: 1867
Joined: 08 Oct 2006, 16:58

Re: ANN: OBJ model format support

Post by Kloot »

1) Yep, that would be an easy change. Here's a version which does so:
SpringOBJMetaDataScriptExporter-ATQ.py.txt
(8.57 KiB) Downloaded 131 times
Note: you must have the to-be-triangulated faces selected when exporting, otherwise Blender won't touch them (and obviously you have to save the model afterwards.)

2) AFAIK in Blender the flip-normals operation is equal to reversing the winding order, but that's easily verified by mirroring a group of single-sided faces (they should become black or invisible, then reappear after the flip-op). I don't know if there is a UI option to impose a single ordering for all faces.
User avatar
Hobo Joe
Posts: 1001
Joined: 02 Jan 2008, 21:55

Re: ANN: OBJ model format support

Post by Hobo Joe »

Not totally sure if this is what you're asking for, but ctrl-N makes all normals face outwards.
User avatar
Cremuss
Posts: 364
Joined: 28 Oct 2006, 21:38

Re: ANN: OBJ model format support

Post by Cremuss »

I don't know if I'm stupid or if I'm the only guy testing Obj parser but.. I've new problems :roll:

I'm running Spring 0.82.2.0

1 - X, Y, Z
My first, really strange, problem is about axis in offset lines in Objects3d/X.lua

Your blender exporter and your core_commander example both have offset = {X, Y, Z} but it's not working like that on my machine. I have to switch Y and Z (like offset = {X, Z, Y}) to get it working in spring o_O.

Kloot, I tried your core commander example, and here is what I got (don't take care about the random texture).
Image
Is your core commander example out of date, deprecated or something or is it supposed to works ?

2 - global but local offset ?

In your core_commander.lua example, you say that offset MUST be in a global space.
What I don't understand is that your blender exporter write offset in a global space (which is ok) but also writes that :

Code: Select all

globalvertexoffsets = false, -- vertices in global space?
localpieceoffsets = true, -- offsets in local space?
"Localpieceoffsets = true", hum ?

3 - numpieces

What is it supposed to do ? I tried to write any kind of numbers and it looks likes it's not a problem for spring. No complains at all and no visual changes on the model. Is it really useful ?

4 - Please try this

This unit is fully working on my machine, with script and everything. It has Y, Z switched offsets (X, Z, Y) so if you have time, I'd like to know if it's working on your machine.
http://cremuss.free.fr/3d/2008/longrangeradarjammer.zip

5 - Weird problem

Now I tried a more complex unit but went through a problem that I just can't solve or even explain :shock:

Objects3D/.lua : http://cremuss.free.fr/3d/2008/uar_researchcenter.lua
Objects3D/.obj : http://cremuss.free.fr/3d/2008/uar_researchcenter.obj

Offset are all in a global space. Every pieces are where they should be but the last pieces of the hierarchy seems to waits local offsets.
Image

Now this .lua is written by hand, like I did for the longrangeradarjammer I posted above
Then I tried with your blender exporter but like I said, it exports X,Y,Z offset which give even more weirds results. Otherwise, offset written are the same so I just don't know what's going on here..
Image

Tell me if you want anymore informations.
Thx
Kloot
Spring Developer
Posts: 1867
Joined: 08 Oct 2006, 16:58

Re: ANN: OBJ model format support

Post by Kloot »

Cremuss wrote:My first, really strange, problem is about axis in offset lines in Objects3d/X.lua

Your blender exporter and your core_commander example both have offset = {X, Y, Z} but it's not working like that on my machine. I have to switch Y and Z (like offset = {X, Z, Y}) to get it working in spring o_O
That core_commander.obj model was generated by my own S3O --> OBJ converter, so its offsets (local space) were already in Spring's coordinate system. I hadn't realized Blender works in XZY, but the script can be adjusted to that convention easily.


Cremuss wrote:Is your core commander example out of date, deprecated or something or is it supposed to works ?
It's still supposed to work, but only with the original .lua data. If you tried generating the metadata for it with the new exporter version, then you'll get an inside-out model.


Cremuss wrote:In your core_commander.lua example, you say that offset MUST be in a global space.
Oops, that's an outdated comment (from before the "localpieceoffsets" parameter existed).
What I don't understand is that your blender exporter write offset in a global space
No, the piece offsets are in local space, or at least they should be. (According to Blender's API documentation the function to query the location of an object returns local coordinates if that object has a parent.)

Cremuss wrote: What is numpieces supposed to do ? I tried to write any kind of numbers and it looks likes it's not a problem for spring. No complains at all and no visual changes on the model. Is it really useful ?
It's a sanity check that only has effect when Spring is compiled in debug mode.


Cremuss wrote:This unit is fully working on my machine, with script and everything. It has Y, Z switched offsets (X, Z, Y) so if you have time, I'd like to know if it's working on your machine.
http://cremuss.free.fr/3d/2008/longrangeradarjammer.zip
This is what it looks like:

Image


Cremuss wrote:Now I tried a more complex unit but went through a problem that I just can't solve or even explain :shock:

Objects3D/.lua : http://cremuss.free.fr/3d/2008/uar_researchcenter.lua
Objects3D/.obj : http://cremuss.free.fr/3d/2008/uar_researchcenter.obj

Offset are all in a global space. Every pieces are where they should be but the last pieces of the hierarchy seems to waits local offsets.
Hmm, I'll have to investigate that in more detail.

EDIT: fixed, your uar_researchcenter.lua needs to contain these lines:

Code: Select all

	globalvertexoffsets = true,
	localpieceoffsets = false,
Attachments
uar_longrangeradarjammer.png
(1.61 MiB) Downloaded 2 times
Last edited by Kloot on 14 Aug 2010, 19:07, edited 1 time in total.
User avatar
Cremuss
Posts: 364
Joined: 28 Oct 2006, 21:38

Re: ANN: OBJ model format support

Post by Cremuss »

Thanks Kloot.

About the core commander, I just took the .obj and the .lua on the first page of this topic but I guess it was just a bit old. I added these two lines at the end of core commander.lua and it just worked fine :-) .

Code: Select all

        globalvertexoffsets = false, -- vertices in global space?
        localpieceoffsets = true, -- offsets in local space?
I then did the same thing for my researchcenter, added the two lines, put LOCAL piece offsets and everything was good so it's could be cool to post your first topic and say that these two lines are critical and that offsets must be in local space :-)

One thing though, blender exporter still writes global offsets. Looks likes it doesn't take care about parents. I had two write and calculate manually the local offset to get my researchcenter working.
Kloot
Spring Developer
Posts: 1867
Joined: 08 Oct 2006, 16:58

Re: ANN: OBJ model format support

Post by Kloot »

Cremuss wrote:One thing though, blender exporter still writes global offsets. Looks likes it doesn't take care about parents. I had two write and calculate manually the local offset to get my researchcenter working.
Heh, see my edit. ;)

Image

(textures borrowed from uar_highpowerradar)
Attachments
uar_researchcenter.png
(1.76 MiB) Downloaded 2 times
User avatar
CarRepairer
Cursed Zero-K Developer
Posts: 3359
Joined: 07 Nov 2007, 21:48

Re: ANN: OBJ model format support

Post by CarRepairer »

I'm having two problems, not sure if they are related.

1) When I export as obj from blender, the piece name should come out

Code: Select all

o pelvis
but it comes out as

Code: Select all

o pelvis_body_textures.002
appending the texture link to the object name. I see Crem's obj files don't have this. How do I avoid it?

2) Spring says it fails to parse my obj file.

Code: Select all

/give diablo 
[OBJParser] failed to parse line "mtllib minotaur.mtl" for model "objects3d/minotaur.obj"
[OBJParser] failed to parse line "o pelvis_body_textures.002" for model "objects3d/minotaur.obj"
[OBJParser] failed to parse line "v 0.834383 12.294065 1.253266" for model "objects3d/minotaur.obj"
[OBJParser] failed to parse line "v 0.834382 12.294065 -1.255128" for model "objects3d/minotaur.obj"
[OBJParser] failed to parse line "v -1.425923 12.413027 1.434803" for model "objects3d/minotaur.obj"
...
...
and so on. Tried converting the line-endings, that didn't help.

Edit: Removing the mtllib line doesn't fix it.
Kloot
Spring Developer
Posts: 1867
Joined: 08 Oct 2006, 16:58

Re: ANN: OBJ model format support

Post by Kloot »

1) dunno, Blender noob

2)

The "mtllib" line belongs to the unsupported part of the OBJ specification, which Spring just disregards with a parse error.

The object name "pelvis_body_textures.002" does not match the allowed identifier pattern (which is "[a-zA-Z0-9_]+"), so Spring disregards that line too.

Those last three "v" lines should still be recognized though. Mind uploading the .obj?
User avatar
CarRepairer
Cursed Zero-K Developer
Posts: 3359
Joined: 07 Nov 2007, 21:48

Re: ANN: OBJ model format support

Post by CarRepairer »

Even when I manually rename the piece and remove the mtllib line, I still get the parse errors on every line in the obj.

Thanks in advance Kloot.
Kloot wrote:1) dunno, Blender noob
Yeah I'm hoping Cremuss will respond to this one and help me with Blender :P

Edit: I somehow discovered the solution to problem #1 through random guesswork. Name them the same name. Whatever, Blender is so hard to learn. But I'm happy. Parsing errors still remain.
Attachments
minotaur.lua
(1.38 KiB) Downloaded 121 times
minotaur.obj.txt
(460.49 KiB) Downloaded 129 times
Kloot
Spring Developer
Posts: 1867
Joined: 08 Oct 2006, 16:58

Re: ANN: OBJ model format support

Post by Kloot »

Cheers. There are three problems with your model:

1) line endings still contain carriage returns; I'll have the parser deal with those [done]
2) some objects still have illegal names (I suppose you didn't rename all of them yet?)
3) certain faces are quads ("f a/b/c d/e/f g/h/i j/k/l"), but should be triangles

Also, many of the piece offsets are <0, 0, 0>, which is probably not what you want.
User avatar
CarRepairer
Cursed Zero-K Developer
Posts: 3359
Joined: 07 Nov 2007, 21:48

Re: ANN: OBJ model format support

Post by CarRepairer »

Kloot wrote:Cheers. There are three problems with your model:

1) line endings still contain carriage returns; I'll have the parser deal with those
2) some objects still have illegal names (I suppose you didn't rename all of them yet?)
3) certain faces are quads ("f a/b/c d/e/f g/h/i j/k/l"), but should be triangles

Also, many of the piece offsets are <0, 0, 0>, which is probably not what you want.
Correct, I didn't rename all the pieces yet and haven't yet edited the origins so the offsets are zero, since I wanted to first see it in game.

Strange, I tried converting to Unix style (that's the one without "carriage returns" I believe) line-endings and I still got the parse errors. But I'll double check.

Edit: attached is new obj file, Unix line-endings, removed all offending lines like mtl and stuff that starts with an "s" (no idea what that is), all faces triangulated. Parse errors are all gone, but now spring crashes when I add the unit.

Code: Select all

/give diablo 
Spring 0.82.3.0 (0.82.3) has crashed.
Exception: Access violation (0xc0000005)
Exception Address: 0x0a9dfd3f
DLL information:
0x00400000	spring
0x77cc0000	ntdll
0x76ce0000	kernel32
0x775b0000	KERNELBASE
0x10000000	DevIL
0x76de0000	MSVCRT
0x772b0000	ADVAPI32
0x76ac0000	sechost
0x777a0000	RPCRT4
0x75830000	SspiCli
0x75820000	CRYPTBASE
0x73240000	GLU32
0x73270000	OPENGL32
0x75980000	GDI32
0x76980000	USER32
0x77640000	LPK
0x76c40000	USP10
0x73150000	DDRAW
0x73380000	DCIMAN32
0x76750000	SETUPAPI
0x77890000	CFGMGR32
0x768f0000	OLEAUT32
0x76ae0000	ole32
0x77580000	DEVOBJ
0x73780000	dwmapi
0x77610000	IMAGEHLP
0x6fbc0000	mingwm10
0x75b00000	SHELL32
0x75a10000	SHLWAPI
0x76a80000	WS2_32
0x775a0000	NSI
0x61b80000	zlib1
0x70780000	vorbisfile
0x68140000	ogg
0x64cc0000	vorbis
0x6b600000	OpenAL32
0x73480000	WINMM
0x66fc0000	freetype6
0x62aa0000	glew32
0x01140000	SDL
0x7c340000	MSVCR71
0x75920000	IMM32
0x771d0000	MSCTF
0x75430000	dsound
0x75400000	POWRPROF
0x774f0000	CLBCatQ
0x75680000	MMDevApi
0x75580000	PROPSYS
0x75550000	wdmaud
0x75540000	ksuser
0x75530000	AVRT
0x754f0000	AUDIOSES
0x754e0000	msacm32
0x754c0000	MSACM32
0x754b0000	midimap
0x75210000	profapi
0x737a0000	uxtheme
0x69500000	nvoglv32
0x75890000	WINTRUST
0x77350000	CRYPT32
0x772a0000	MSASN1
0x66740000	DINPUT
0x72c00000	HID
0x73740000	mswsock
0x74d30000	wship6
0x752b0000	dbghelp
Stacktrace:
(0) Unknown [0x0A9DFD3F]
(1) C:\Windows\SysWOW64\ntdll.dll(RtlFreeHeap+0x7e) [0x77CEDE63]
(2) C:\Program Files (x86)\Spring\spring.exe(aiInterfaceCallback_DataDirs_getWriteableDir+0x29cd62) [0x00CBB0E2]
(3) C:\Program Files (x86)\Spring\spring.exe [0x007B800F]
(4) C:\Program Files (x86)\Spring\spring.exe [0x007BA241]
(5) C:\Program Files (x86)\Spring\spring.exe [0x007BEB5A]
(6) C:\Program Files (x86)\Spring\spring.exe [0x00887E75]
(7) C:\Program Files (x86)\Spring\spring.exe [0x008C0110]
(8) C:\Program Files (x86)\Spring\spring.exe [0x0040F688]
(9) C:\Program Files (x86)\Spring\spring.exe [0x00423B4F]
(10) C:\Program Files (x86)\Spring\spring.exe [0x0042B130]
(11) C:\Program Files (x86)\Spring\spring.exe [0x00984B71]
(12) C:\Program Files (x86)\Spring\spring.exe [0x0098FE79]
(13) C:\Program Files (x86)\Spring\spring.exe [0x009901A4]
(14) C:\Program Files (x86)\Spring\spring.exe [0x00990980]
(15) C:\Program Files (x86)\Spring\spring.exe [0x004010A7]
(16) C:\Program Files (x86)\Spring\spring.exe [0x00401123]
(17) C:\Windows\syswow64\kernel32.dll(BaseThreadInitThunk+0x12) [0x76CF3677]
(18) C:\Windows\SysWOW64\ntdll.dll(RtlInitializeExceptionChain+0x63) [0x77CF9D42]
(19) C:\Windows\SysWOW64\ntdll.dll(RtlInitializeExceptionChain+0x36) [0x77CF9D15]
Attachments
minotaur.obj.txt
(494.18 KiB) Downloaded 127 times
Kloot
Spring Developer
Posts: 1867
Joined: 08 Oct 2006, 16:58

Re: ANN: OBJ model format support

Post by Kloot »

CarRepairer wrote: Strange, I tried converting to Unix style (that's the one without "carriage returns" I believe) line-endings and I still got the parse errors. But I'll double check.
You would have gotten parse errors regardless, just different ones without the CR's present.

Your new version makes Spring crash because it is missing a definition for object "base", which according to the metadata should be the root piece. Can be fixed by adding "o base" at the top of the .obj and then borrowing some dead core_commander skin:

Image
Attachments
minotaur.png
(1.5 MiB) Downloaded 2 times
Last edited by Kloot on 11 Feb 2011, 22:03, edited 1 time in total.
User avatar
CarRepairer
Cursed Zero-K Developer
Posts: 3359
Joined: 07 Nov 2007, 21:48

Re: ANN: OBJ model format support

Post by CarRepairer »

Thanks!!!

I do have an empty base piece and I use it in every model for spring. But the blender obj exporter decides to discard it? Blender experts, any help? Anyway this is great, I am very happy so far.

Side note, since I requested that you add an automatic triangulator to the spring script, I found out that obj exporting allows you to select a triangulate feature. So I believe it's not needed in the python script and I commented it out on my end, but if I'm wrong to do so let me know. This way my blender file can have less polygons and only make the triangles when converting to obj.
User avatar
CarRepairer
Cursed Zero-K Developer
Posts: 3359
Joined: 07 Nov 2007, 21:48

Re: ANN: OBJ model format support

Post by CarRepairer »

Okay guys, almost there!

I had to do this to get things to work:

Code: Select all

	globalvertexoffsets = true, -- vertices in global space?
	localpieceoffsets = true, -- offsets in local space?
One last problem (blender issue, not spring). When flipping pieces, the vertex winding order gets reversed from ccw to cw. However the normals are still pointing outward in blender. The piece looks inside out in spring. I can flip the normals in blender to make the piece look correct in spring but then the piece is inside-out in blender. What to do?


And now, a treat (thanks to Kloot for the OBJ support, Crem for the model, jK for normal mapping, and MidKnight for providing a little elf as snack).


Image

Uploaded with ImageShack.us
User avatar
Cremuss
Posts: 364
Joined: 28 Oct 2006, 21:38

Re: ANN: OBJ model format support

Post by Cremuss »

Kloot wrote:
Cremuss wrote:One thing though, blender exporter still writes global offsets. Looks likes it doesn't take care about parents. I had two write and calculate manually the local offset to get my researchcenter working.
Heh, see my edit. ;)

Image

(textures borrowed from uar_highpowerradar)
Have you updated the script ? Because I downloaded it again and it's not working anymore. Same errors we had before :
CarRepairer wrote:I'm getting errors as well. I'm no expert pythonist but perhaps line 172 needs to be changed from

Code: Select all

log.Write("mid-pos distance of piece \"%s\": %.2f, {min, max}Y: %.2f, %.2f\n" % ((rr ** 0.5), minPieceY, maxPieceY))
to

Code: Select all

log.Write("mid-pos distance of piece \"%s\": %.2f, {min, max}Y: %.2f, %.2f\n" % (modelPieceName, (rr ** 0.5), minPieceY, maxPieceY))
Changing this made it so the lua now generates, but I still get this error:

Code: Select all

line 31, in Flush self.logFile.write(logBuff)
NameError: global name 'logBuff' is not defined
Exception NameError: "global name 'logBuff' is not defined" in <bound method SimpleLog.__del__ of <__main__.SimpleLog instance at 0x0400B080>> ignored

Code: Select all

One last problem (blender issue, not spring). When flipping pieces, the vertex winding order gets reversed from ccw to cw. However the normals are still pointing outward in blender. The piece looks inside out in spring. I can flip the normals in blender to make the piece look correct in spring but then the piece is inside-out in blender. What to do?
Why don't you work in quads, make your tweaks and flips in quads, ctrl-n to reset the normals, then ctrl-t to triangulate everything and then export to obj ?
User avatar
Hobo Joe
Posts: 1001
Joined: 02 Jan 2008, 21:55

Re: ANN: OBJ model format support

Post by Hobo Joe »

When I was talking to him last night, he said he was scaling to -1 to mirror stuff, and supposedly ctrl-n didn't fix it, so I was trying to set him up for proper mirroring, don't know if he ever got it though, he stopped responding.
User avatar
Cremuss
Posts: 364
Joined: 28 Oct 2006, 21:38

Re: ANN: OBJ model format support

Post by Cremuss »

I guess the problem is that he is working in tris, so scaling -1 tris mesh reverts vertex winding order from cww to cw that's why I'm telling him to work in quads and only triangulate his model when he wants to export it, once every tweaks are done.
Ctrl-n is just here to reset normals after a scale -1, it doesn't solve the cww/cw problem.
User avatar
CarRepairer
Cursed Zero-K Developer
Posts: 3359
Joined: 07 Nov 2007, 21:48

Re: ANN: OBJ model format support

Post by CarRepairer »

I only convert to triangles now when I export to obj. Even working with quads, when I mirror piece A to piece B, piece B's faces will now have CW vertex winding order while still having outward facing normals. This happens whether I scale -1 or if I use the mirror action. Flipping the normals for the piece does fix the problem in Spring but now it looks bad in Blender. I want it to look correct in both Spring and Blender. Obviously this just a minor problem and I can live with an inside-out arm and leg in Blender without any sleep lost, just hoping for a better solution one day.

Now I have a new problem for Kloot.

Code: Select all

   globalvertexoffsets = true, -- vertices in global space?
   localpieceoffsets = true, -- offsets in local space?
This is the only way that my pieces show correctly (see screenshot). But the animation is messed up as it doesn't use the origins of the pieces themselves to rotate around. I noticed some other configurations of that code makes the pieces animate around their origins, but they are totally in the wrong spots and the minotaur dude is exploded. I can only seem to get one thing working or the other. :(
Kloot
Spring Developer
Posts: 1867
Joined: 08 Oct 2006, 16:58

Re: ANN: OBJ model format support

Post by Kloot »

Cremuss wrote: Have you updated the script ? Because I downloaded it again and it's not working anymore. Same errors we had before :
No, I didn't. The link correctly points to version 1.1 for me, so maybe your browser cache is just stale?
CarRepairer wrote: This is the only way that my pieces show correctly (see screenshot). But the animation is messed up as it doesn't use the origins of the pieces themselves to rotate around. I noticed some other configurations of that code makes the pieces animate around their origins, but they are totally in the wrong spots and the minotaur dude is exploded.
To solve this I need a favor:

1. Create a model consisting of three unit-sized cube objects (call them A, B, and C)
2. Make B a child of A, and make C a child of B (A <-- B <-- C)
3. Move A to <1, 0, 0>, move B to <2, 0, 0> wrt A*, move C to <3, 0, 0> wrt B**
4. Use v1.1 of the exporter, then pastebin the .obj, .lua, and the .log

* meaning to <3, 0, 0> in global space
** meaning to <6, 0, 0> in global space
Post Reply

Return to “Art & Modelling”