Converting to .dat

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

Moderators: winston, another_commander

User avatar
Cholmondely
Archivist
Archivist
Posts: 5543
Joined: Tue Jul 07, 2020 11:00 am
Location: The Delightful Domains of His Most Britannic Majesty (industrial? agricultural? mainly anything?)
Contact:

Re: Converting to .dat

Post by Cholmondely »

I've not noticed any .mtl files in any of the ship.oxps so far.

1) I've failed to get Obj2DatTexNorm.py up and running (surprise!). I seem to have a number of versions of Python floating around my hard drive - 2.7, 2.7.1, 3.7, 3.7.1, 3.8, 3.83, 3.9, 3.10
No idea as to how to handle all of them.

2) I've not noticed any .mtl files in any of my downloaded ship.oxps - what do I do with these?

3) The ReadMe with the Obj2DatTexNorm.py says this:
# Oolite Mesh Converters #

A set of Python scripts to convert models to and from Oolite’s DAT format.

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).
Comments wanted:
Missing OXPs? What do you think is missing?
Lore: The economics of ship building How many built for Aronar?
Lore: The Space Traders Flight Training Manual: Cowell & MgRath Do you agree with Redspear?
another_commander
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 6757
Joined: Wed Feb 28, 2007 7:54 am

Re: Converting to .dat

Post by another_commander »

Cholmondely wrote: Fri Feb 14, 2025 3:56 pm
I've not noticed any .mtl files in any of the ship.oxps so far.
[...]
2) I've not noticed any .mtl files in any of my downloaded ship.oxps - what do I do with these?
.mtls are needed for the conversion step from .obj to .dat. If you don't have them the conversion will fail. You will not find them in any OXPs, once the .objs have been successfully converted to .dat the .mtls are not needed anymore.
User avatar
MrFlibble
---- E L I T E ----
---- E L I T E ----
Posts: 376
Joined: Sun Feb 18, 2024 12:13 pm

Re: Converting to .dat

Post by MrFlibble »

Cholmondely wrote: Fri Feb 14, 2025 3:56 pm
I've not noticed any .mtl files in any of the ship.oxps so far.

1) I've failed to get Obj2DatTexNorm.py up and running (surprise!). I seem to have a number of versions of Python floating around my hard drive - 2.7, 2.7.1, 3.7, 3.7.1, 3.8, 3.83, 3.9, 3.10
No idea as to how to handle all of them.
I'm using pyenv to have several versions of python.

Here's my first stab at the conversion based on the files from the first link of the post here dated Thu Feb 13, 2025 7:45 pm

Code: Select all

$ cd ~/oolite-mesh-converters-master/Model_C1104104
$ python2.7 ../Obj2DatTexNorm.py dcs2.obj
dcs2.obj -> dcs2.dat
  Material library file: dcs2.mtl
  Material Material__13 -> maps\ALUM_8L2.JPG
  Material Material__a -> maps\ALUM_8L2.JPG
  Material Material__b -> maps\Aluminum6.jpg
  Material Material__15 -> maps\ALUM_8L2.JPG
  Material Material__1 -> maps\ALUM_8L2.JPG
  Material Material__2 -> maps\ALUM_8L2.JPG
  Material Material__16 -> maps\ALUM_8L2.JPG
Traceback (most recent call last):
  File "../Obj2DatTexNorm.py", line 468, in <module>
    if (bits[2] > ''): vn1 = vertex_reference(int(bits[2]), normal_count)
IndexError: list index out of range
Ok, so here's what happened with the second download.

Code: Select all

cd ~/oolite-mesh-converters-master/78121$ python2.7
../Obj2DatTexNorm.py 78121.obj 
78121.obj -> 78121.dat
  Material library file: scene1.mtl
Traceback (most recent call last):
  File "../Obj2DatTexNorm.py", line 387, in <module>
    material_file = open(material_file_name, 'r')
IOError: [Errno 2] No such file or directory: 'scene1.mtl'

#Ok... at a guess...
$ cp 78121.mtl scene1.mtl

$ python2.7 ../Obj2DatTexNorm.py 78121.obj 
78121.obj -> 78121.dat
  Material library file: scene1.mtl
  Material TCBaseBottom -> C:\Users\huydo\Downloads\___OPEN3D\Sketchfab\Temp\78121\textures\TCBaseBottom_baseColor.jpeg
  Material TCBuilding02 -> C:\Users\huydo\Downloads\___OPEN3D\Sketchfab\Temp\78121\textures\TCBuilding02_baseColor.jpeg
  Material TCBuilding01 -> C:\Users\huydo\Downloads\___OPEN3D\Sketchfab\Temp\78121\textures\TCBuilding01_baseColor.jpeg
  Material TCBaseTop -> C:\Users\huydo\Downloads\___OPEN3D\Sketchfab\Temp\78121\textures\TCBaseTop_baseColor.jpeg
  Material TCBuilding03 -> C:\Users\huydo\Downloads\___OPEN3D\Sketchfab\Temp\78121\textures\TCBuilding03_baseColor.jpeg
Traceback (most recent call last):
  File "../Obj2DatTexNorm.py", line 468, in <module>
    if (bits[2] > ''): vn1 = vertex_reference(int(bits[2]), normal_count)
IndexError: list index out of range
Failed at the same point. Luckily, the DTT Warlance oxp contains the sources, so that should work to test the tool-chain.

Code: Select all

$ cd ~/oolite-mesh-converters-master/WarLance/Extras$ python2.7 ../../Obj2DatTexNorm.py DTT_War_Lance.obj 
DTT_War_Lance.obj -> dtt_war_lance.dat
  Material library file: DTT_War_Lance.mtl
  Material DTT_War_Lance_Diffuse -> DTT_War_Lance_Diffuse.png
Done.
So... there's something in those downloaded models that causes Obj2DatTexNorm.py to choke. Beyond my available time today.

FWIW, the generated WarLance dat file came out a different size (726998 bytes) than the one in the oxp (715635 bytes), but that may have just been due to different command line arguments passed to Obj2DatTexNorm.py.
User avatar
cbr
---- E L I T E ----
---- E L I T E ----
Posts: 1455
Joined: Thu Aug 27, 2015 4:24 pm

Re: Converting to .dat

Post by cbr »

I do remember some difficulty with multi material objects eg more than one diffuse map...
another_commander
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 6757
Joined: Wed Feb 28, 2007 7:54 am

Re: Converting to .dat

Post by another_commander »

The problem is that file 78121.obj contains only 2 numbers per token in its 'f' sections, intead of 3 expected by Obj2DatTexNorm.py. I'ts just a very old model format, I guess.

The solution: Use the older Obj2DatTex.py instead. This generates the .dat successfully and I have uploaded the result here.

Before you can use the model make sure that the textures are all converted to .png format so Oolite can read them. The uploaded .dat alrady contains references to the textures as .pngs.
User avatar
Cholmondely
Archivist
Archivist
Posts: 5543
Joined: Tue Jul 07, 2020 11:00 am
Location: The Delightful Domains of His Most Britannic Majesty (industrial? agricultural? mainly anything?)
Contact:

Re: Converting to .dat

Post by Cholmondely »

another_commander wrote: Fri Feb 14, 2025 7:31 pm
The problem is that file 78121.obj contains only 2 numbers per token in its 'f' sections, intead of 3 expected by Obj2DatTexNorm.py. I'ts just a very old model format, I guess.

The solution: Use the older Obj2DatTex.py instead. This generates the .dat successfully and I have uploaded the result here.

Before you can use the model make sure that the textures are all converted to .png format so Oolite can read them. The uploaded .dat alrady contains references to the textures as .pngs.
Thank you for this!
Comments wanted:
Missing OXPs? What do you think is missing?
Lore: The economics of ship building How many built for Aronar?
Lore: The Space Traders Flight Training Manual: Cowell & MgRath Do you agree with Redspear?
User avatar
Cholmondely
Archivist
Archivist
Posts: 5543
Joined: Tue Jul 07, 2020 11:00 am
Location: The Delightful Domains of His Most Britannic Majesty (industrial? agricultural? mainly anything?)
Contact:

Re: Converting to .dat

Post by Cholmondely »

cbr wrote: Fri Feb 14, 2025 9:49 am
Image

station or ship ;)
Oh dear. What do you think? Any chance it might be a spaceship-making factory station?



(The other one which I found seems all too small, has a platform with cranes which can presumably hold just the one ship, and no ships being worked on: SolCommand: https://www.solcommand.com/2013/09/liss ... .html#more)
Comments wanted:
Missing OXPs? What do you think is missing?
Lore: The economics of ship building How many built for Aronar?
Lore: The Space Traders Flight Training Manual: Cowell & MgRath Do you agree with Redspear?
Post Reply