Model converter utilities

Discussion and information relevant to creating special missions, new ships, skins etc.

Moderators: winston, another_commander

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

Model converter utilities

Post by JensAyton »

The original thread’s head is badly out of date. Rather than rewrite aegidian’s post, I’ve started a new thread.

We provide a set of Python scripts to convert models to and from Oolite’s DAT format. The latest versions can always be found in the repository and downloaded directly using this link. Updates will be announced in this thread.

The tools are:

Obj2DatTexNorm.py: convert a mesh in OBJ format to DAT, preserving texture coordinates and vertex normals. This is now the recommended conversion tool. The meshes it produces require Oolite test release 1.74 or later.

From a Wings3D modelling perspective, preserving vertex normals means that hard and soft edges in Wings3D are preserved, producing a result similar to Wings3D preview mode (Tab key) if all the faces in Wings3D are planar (ensure this by selecting Tesselate → Triangulate in face mode). The smooth key in shipdata.plist has no effect on models with vertex normals.

Usage: python Obj2DatTexNorm.py <filename> for default settings, python Obj2DatTexNorm.py --help for information about options.


Obj2DatTex.py: an older conversion tool which does not preserve normals but does support smooth groups. Models converted with this tool will have a faceted look by default, but can be smoothed using the smooth key in shipdata.plist.

From a Wings3D modelling perspective, complete loops of hard edges will be preserved when using smoothing (the enclosed faces form a smooth group), but lighting may behave differently than in Wings3D preview mode.

Usage: python Obj2DatTex.py <filename>


Dat2ObjTex.py and Dat2Obj.py: partially convert a DAT mesh to OBJ format. Dat2ObjTex.py can handle a single material, while Dat2Obj.py ignores all textures. These tools do not preserve normals, and Dat2ObjTex.py won’t do anything useful with materials from files converted with Obj2DatTexNorm.py unless --pretty-output was used.

Usage: python Dat2ObjTex.py <filename>, python Dat2Obj.py <filename>


DatScale.py: scale a DAT model uniformly on all axes.

Usage: python DatScale.py <filename> <scalefactor>, e.g. python DatScale.py myModel.dat 3. A new file is created, in the example case “myModel x 3.0.dat”.


Mesh2Dat.py, Mesh2DatTex.py, Dat2Mesh.py, Mesh2Obj.py: converters for the obsolete, Mac-specific Meshwork modeller.


The converters require Python (version 2.7 or later for Obj2DatTexNorm.py). Mac OS X and Linux systems generally have Python preinstalled. For Linux systems, check your package manager if necessary. For Windows, download it from python.org.


Bug reports: currently, Obj2DatTexNorm.py is the only one that can be considered actively maintained, and the others have known problems. Crash/exception reports for all tools are welcomed, as well as reports of bad conversions with Obj2DatTexNorm.py. In order for reports to be useful, please ensure that they apply to the latest version – the link at the top of this post is always up-to-date – and include, at minimum, a copy of the file you’re trying to convert (and its associated MTL file in the case of OBJ files).
User avatar
JensAyton
Grand Admiral Emeritus
Grand Admiral Emeritus
Posts: 6657
Joined: Sat Apr 02, 2005 2:43 pm
Location: Sweden
Contact:

Re: Model converter utilities

Post by JensAyton »

Please note that the download link has been changed.
Sindarin
Poor
Poor
Posts: 7
Joined: Wed Nov 23, 2016 9:24 pm

Re: Model converter utilities

Post by Sindarin »

Hi, i'm trying to learn some of the designing habilities.

I try to use the ...Norm.py and i get this:

Code: Select all

$ python Obj2DatTexNorm.py mamba_redux.dat 
  File "Obj2DatTexNorm.py", line 232
    want this.'''
                ^
SyntaxError: invalid syntax
I try to open models from the game to see how they look in the wings3d.
bit coder :o
bit gamer :o

Thou shall not pass.
another_commander
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 6683
Joined: Wed Feb 28, 2007 7:54 am

Re: Model converter utilities

Post by another_commander »

Obj2DatTexNorm.py takes a model .obj file as input, but you seem to be giving it a .dat file. This will not work. You will need the mamba obj file (as well as its associated .mtl file) in the folder where Obj2DatTexNorm.py is run from, then you can run the utility to convert the .obj file to the .dat format that the game uses.
Sindarin
Poor
Poor
Posts: 7
Joined: Wed Nov 23, 2016 9:24 pm

Re: Model converter utilities

Post by Sindarin »

Oh, I see, :oops: how embarassing.

I think there is some syntax problem due to diferences between python 2.6 and 3.
bit coder :o
bit gamer :o

Thou shall not pass.
Sindarin
Poor
Poor
Posts: 7
Joined: Wed Nov 23, 2016 9:24 pm

Re: Model converter utilities

Post by Sindarin »

Well,
I've been researching the issues with this tools,
May I volunteer myself to fix the python compatibility.

I wish to play with the models and I don't see other converters (and in the future python 2.6 would be a bit problematic).

I'm not an expert but I make my own little python scripts for personal purposes.

I'm starting on my own but I would apreciate some advice.
bit coder :o
bit gamer :o

Thou shall not pass.
another_commander
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 6683
Joined: Wed Feb 28, 2007 7:54 am

Re: Model converter utilities

Post by another_commander »

Feel free to experiment with it, although I'd prefer if we also keep the compatibility with Python 2.7 (2.7 is the minimum requirement as per the readme of the oolite-mesh-converters repo and not 2.6).

If you do go ahead and hack it, be aware that I've just pushed a new version of the converter on github:
https://github.com/OoliteProject/oolite ... TexNorm.py. This one contains some tangent space fixes commited by kanthoney prior to 1.84 and is considered the most up to date version of Obj2DatTexNorm.py.
Sindarin
Poor
Poor
Posts: 7
Joined: Wed Nov 23, 2016 9:24 pm

Re: Model converter utilities

Post by Sindarin »

It's nice,

I'm learning how the dats and objs formats stores the positions and information.

Languaje needed only to make some print correction, also the string.split usage and also one collection check ( thing in collection.keys() instead of collection.has_key().

I'll check the 2.7 compatibility.

I have an error in how var vt1 is defined. It happens to not define it.

Code: Select all

$ python prueba.py mamba_redux.obj
mamba_redux.obj -> mamba_redux.dat
  Material library file: mamba_redux.mtl
  Material mamba_redux_auv -> mamba_redux.png
Traceback (most recent call last):
  File "prueba.py", line 496, in <module>
    rv1 = resolve_vertex(vertex[v1], normal[vn1], tc1, index_for_vert_norm_and_tex, vertex_lines_out, normals_lines_out)
NameError: name 'vn1' is not defined
# UPDATED with an ingame model.
# Transformed the dat to obj with my corrected version of Dat2ObjTex.py and then tried to convert it back.
bit coder :o
bit gamer :o

Thou shall not pass.
jackiebean
Dangerous
Dangerous
Posts: 112
Joined: Wed Jan 18, 2017 2:01 pm

Re: Model converter utilities

Post by jackiebean »

May i ask if there are any py scripts that work in the current version of Blender? or how exactly you can use these conversion scripts? What directory structure is recommended? should they be installed in the Python folder? or should they be installed in the same directory as say an existing Oolite model? The instructions are rather vague and imply that the user already knows how to use them, and what directory they need to be in.

I use blender exclusively since 3ds max is not an option in Linux. I would like to be able to import some existing older models and possibly update some of the ships to Griff's standards. I am also working on a test ship (new design) that i would like to add to the game at some point.
Commander_X
---- E L I T E ----
---- E L I T E ----
Posts: 675
Joined: Sat Aug 09, 2014 4:16 pm

Re: Model converter utilities

Post by Commander_X »

As I've been mentioning somewhere else in the forum, I had some work done on Dat2Obj.py and Dat2ObjTex.py. These are two of the conversion scripts provided by the dev team here, but updated for cooperating with the newer .dat files.
The resulted .obj files can be used with Blender, but some minor manual material/UV tweaking needs to be done for the textures (the scripts don't support multitexturing, mainly).
They are not supposed to be used from within Blender, but at the command line, as they require Python v2.x (they don't work with Python v3.x bundled with Blender _and_ they are not Blender add-ons).
Hope this helps.
User avatar
Stormrider
Deadly
Deadly
Posts: 241
Joined: Sat Jan 25, 2014 2:35 am
Location: At work

Re: Model converter utilities

Post by Stormrider »

jackiebean wrote:
May i ask if there are any py scripts that work in the current version of Blender? or how exactly you can use these conversion scripts? What directory structure is recommended? should they be installed in the Python folder? or should they be installed in the same directory as say an existing Oolite model?
You may want to check out this thread for Blender tips: https://bb.oolite.space/viewtopic.php?f= ... 45#p152965

Export your model as a Wavefront .obj into the same directory that the conversion script is in then navigate to that directory in a terminal and enter: python Obj2DatTexNorm.py yourexample.obj

In my experience the only thing that matters with regard to directory structure is that both the obj and associated .mtl file are in the same directory as the conversion script. I just leave the scripts in the oolite-mesh-converters-master dir that they come in and export my .obj files there. Once converted I move the .dat file to the Model directory in the oxp directory it belongs to and move the .obj and .mtl files to a subdirectory that I created within the oolite-mesh-converters-master for backups.
jackiebean wrote:
I am also working on a test ship (new design) that i would like to add to the game at some point.
I saw your pic in the other thread, looks very nice.
Image
jackiebean
Dangerous
Dangerous
Posts: 112
Joined: Wed Jan 18, 2017 2:01 pm

Re: Model converter utilities

Post by jackiebean »

Thanks for the tips, and thanks for the compliment. I will give that method a try and see what i can do.

From what I understand about python, i do have 2.7 and 3.x in my OS natively, but have to research more so I can refresh on how to use older python versions. I think that a simple command using pip or another package can allow switching temporarily to a different python environment so that should not be too difficult once I get the other python versions I use installed, the hard part is getting them to behave correctly and making sure all the directory structures are in the right places to make that possible. Since I already have older versions installed on my old partition, I may be able to just cut and paste those into the correct locations to install them, but I'm not sure.
Commander_X
---- E L I T E ----
---- E L I T E ----
Posts: 675
Joined: Sat Aug 09, 2014 4:16 pm

Re: Model converter utilities

Post by Commander_X »

jackiebean wrote: Mon Jan 30, 2017 12:33 am
From what I understand about python, i do have 2.7 and 3.x in my OS natively, but have to research more so I can refresh on how to use older python versions.
No pip needed. Usually your "default" python would be either 2x or 3x, you can quickly find it out by typing

Code: Select all

python --version
in a terminal. The nice part is that each version will also have an executable named python2 for 2x or python3 for 3x (the default python is just a symbolic link to one of these).
Thus, if you wanted to use python version 2.x for the python scripts provided by Oolite, you can just keep using python2 when running them, e.g.

Code: Select all

python2 Dat2Obj.py cobra3_redux.dat
Of course you can always modify the "#!" line in your python scripts to call either python2 or python3 -- but that's more intrusive than just calling the needed interpreter when you want to run a script.
jackiebean
Dangerous
Dangerous
Posts: 112
Joined: Wed Jan 18, 2017 2:01 pm

Re: Model converter utilities

Post by jackiebean »

Scripts work ok, i downloaded another version of them as well for stubborn ship models that do not want to convert (error out) but so far they seem to work ok for the most part.
User avatar
Old Murgh
Wiki Wizard
Wiki Wizard
Posts: 640
Joined: Sat Dec 04, 2021 11:01 pm

Re: Model converter utilities

Post by Old Murgh »

Being a real old-timer, I was nursed on Aegidian's brilliant drop icons that converted dats and objs back and forth with the supreme ease of a mouse move. I didn't know how good we had it. So, this luxury is now completely obsolete.

It's been over a decade since I tried to make use of the Terminal, but I thought I should install python and give above scripts a try. After all, any query about it I have seen on this board needs only the same brief explanation, and then the enquirer seems to get it instantly. Not so with me.

My errors are all related to Terminal not being able to find the .py file, but there are so many possibilities as to what might be the problem. The location of the scripts, adjacent to the file I'm trying to convert shouldn't be the problem. I suspect more, since I couldn't download the scripts but rather had to copy/paste them to text files, is that the scripts themselves are illegitimate.

I don't suppose anyone has made a youtube vid of the process explaining every step to the oblivious?
I was young, I was naïve. [EliteWiki] Jonny Cuba made me do it!
Post Reply