Jump to content
The Dark Mod Forums

LWO exporter


Bikerdude

Recommended Posts

The obj exporter isn't very useful for modelling, as the resulting polys are flipped and the uvmaps are messed up. I've never been able to use it for anything other than scale comparisons.

Link to comment
Share on other sites

File > Export selection as OBJ

Doh, I keep forgetting about that.

The obj exporter isn't very useful for modelling, as the resulting polys are flipped and the uvmaps are messed up. I've never been able to use it for anything other than scale comparisons.

And thats why, Springs reminded me of the above the last time .OBJ's were suggested.

Link to comment
Share on other sites

We already have this, what we need is a .LWO exporter. So Springs can tweak models made in DR etc.

As long as someone can't point me to a description of how this binary format works, I cannot write an exporter for it. Object is text-based, though, and if the current exporter is messed up, I could write a new one exporting as obj.

FM's: Builder Roads, Old Habits, Old Habits Rebuild

Mapping and Scripting: Apples and Peaches

Sculptris Models and Tutorials: Obsttortes Models

My wiki articles: Obstipedia

Texture Blending in DR: DR ASE Blend Exporter

Link to comment
Share on other sites

The official file format spec is in the sdk, browsable on the lightwave3d site here: http://static.lightwave3d.com/sdk/2015/html/filefmts.html

 

This article looks very helpful too. Much easier to read and broken down with a hello world type example of a simple cube: http://content.gpwiki.org/index.php/LWO

 

I don't know whether blender needs a specific version, but all the previous specs are linked on the same site.

Link to comment
Share on other sites

Writing the data in the utlined form isn'T a big deal, but how do I get Python Script to store it in the binary format?

FM's: Builder Roads, Old Habits, Old Habits Rebuild

Mapping and Scripting: Apples and Peaches

Sculptris Models and Tutorials: Obsttortes Models

My wiki articles: Obstipedia

Texture Blending in DR: DR ASE Blend Exporter

Link to comment
Share on other sites

It's a long time since I used it, but isn't struct the standard way of handling binary data?

Not one that I've used. Python's file() is enough. It can write a binary string created using the built in bytearray() function as easily as it can read and write text strings.

e.g.

>>> data = [127, 255, 64, 63, 0, 1, 255]
>>> f = file('binfile.bin', 'w+b') # 'w+b' means create or overwrite this binary file
>>> f.write( bytearray(data) )
>>> f.close()
>>>
>>> data2 = file('binfile.bin', 'r').read() # open, read, and close in one step
>>> data2
'\x7f\xff@?\x00\x01\xff'
>>> int_data = [ ord( for b in data2 ]
>>> int_data
[127, 255, 64, 63, 0, 1, 255]
Link to comment
Share on other sites

I think it would be cool if Biker could export his work as LWO for Springheel to review but I get the impression that the results

might still be less than optimal because the proper workflow requires two models so that a "proper" normal bake can be made.

 

It's a shame that the addnormals command is so low-fidelity and limited, it would be nice to be able to mix and match high quality

normal bakes with tiled normal maps too but I imagine that would slow down rendering or map load times if we ever changed it.

 

As it stands now, it's either one or the other. If only the normal bake in Doom 3 could take the high poly model "and it's normal maps"

and bake both to the low-poly at once. I think Blender can do this though, now sure about LightWave.

Please visit TDM's IndieDB site and help promote the mod:

 

http://www.indiedb.com/mods/the-dark-mod

 

(Yeah, shameless promotion... but traffic is traffic folks...)

Link to comment
Share on other sites

struct isn't a replacement for file() IO; it's for converting Python types to and from packed binary data. Here's what happens if I take the bytearray() example and naively try to plug signed integers into it:

 

Python 2.6.5 (r265:79063, Feb 27 2014, 19:44:14)
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> data = [127, -3, 64, 63, 0, 1, -6]
>>> f = file('binfile.bin', 'w+b')
>>> f.write( bytearray(data) )
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: byte must be in range(0, 256)

Some things I'm repeatedly thinking about...

 

- louder scream when you're dying

Link to comment
Share on other sites

Ah, thanks for the clarification. I'll remember that as a more compact alternative to Pickle() next time I need to do it :)

 

In this case, writing a converter, it's not python types that want to be saved but some specific format for another program, so you'd likely want to write code that creates an exact sequence of bytes accordng to a spec. file() + bytearray() are ideal for that.

Link to comment
Share on other sites

That's exactly what struct is useful for. If you need to save, say, three doubles and a signed 8-bit int, you can feed struct a format string that tells it to convert your Python variables to the corresponding C types and output them as binary data, optionally with defined endianness and padding.

Some things I'm repeatedly thinking about...

 

- louder scream when you're dying

Link to comment
Share on other sites

struct.pack is the way to do it in Python. You can dump byte arrays to a file easily, but if you want to write a 32-bit integer you are going to need to convert it into bytes first, and struct.pack is the way to do that.

Link to comment
Share on other sites

Yeah I can see that higher-bit ints and floats would be awkward, but what if you are working to a file spec that isn't laid out as a c-struct with padding etc? Where each byte is determined by a file format spec? Assuming no library modules, isn't it easier just to write your own conversion functions for the output that you need and to specify it byte by byte? You could still use struct.pack to convert your numbers and then embed them in the file, if its result happens to coincide with the target spec.

Link to comment
Share on other sites

Yeah I can see that higher-bit ints and floats would be awkward, but what if you are working to a file spec that isn't laid out as a c-struct with padding etc? Where each byte is determined by a file format spec?

struct.pack has nothing to do with C-structs, the name is perhaps something of a misnomer. It is an unbound method (like a C++ static method) that accepts a format string and some values to format, and basically works a lot like sprintf (except without literal string output; everything in the format string is a format character). You can easily run it in a loop, or on a number of individual values, without needing to define any kind of "struct".

 

E.g. to convert a single 16-bit short value:

>>> struct.pack('h', 32767)
'\xff\x7f'

You could write your own conversion functions of course, but this wouldn't provide any advantage over what the pack method is already giving you.

Link to comment
Share on other sites

Useful to know, thanks. I did look it up and saw the article talking about it inserting padding to match the layout that a c compiler would use for a struct, but if that behaviour is optional and you can have full control while not needing to decode your own ints and floats, then great.

Link to comment
Share on other sites

Right. The docs do make mention of C struct compatibility, and the default behaviour seems to be to use the padding and endianness that a C compiler would use on your current system, but you have full control over what padding and enddianness you actually want by using the appropriate format strings.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recent Status Updates

    • nbohr1more

      The FAQ wiki is almost a proper FAQ now. Probably need to spin-off a bunch of the "remedies" for playing older TDM versions into their own article.
      · 1 reply
    • nbohr1more

      Was checking out old translation packs and decided to fire up TDM 1.07. Rightful Property with sub-20 FPS areas yay! ( same areas run at 180FPS with cranked eye candy on 2.12 )
      · 3 replies
    • taffernicus

      i am so euphoric to see new FMs keep coming out and I am keen to try it out in my leisure time, then suddenly my PC is spouting a couple of S.M.A.R.T errors...
      tbf i cannot afford myself to miss my network emulator image file&progress, important ebooks, hyper-v checkpoint & hyper-v export and the precious thief & TDM gamesaves. Don't fall yourself into & lay your hands on crappy SSD
       
      · 7 replies
    • OrbWeaver

      Does anyone actually use the Normalise button in the Surface inspector? Even after looking at the code I'm not quite sure what it's for.
      · 7 replies
    • Ansome

      Turns out my 15th anniversary mission idea has already been done once or twice before! I've been beaten to the punch once again, but I suppose that's to be expected when there's over 170 FMs out there, eh? I'm not complaining though, I love learning new tricks and taking inspiration from past FMs. Best of luck on your own fan missions!
      · 4 replies
×
×
  • Create New...