Jump to content

standardize units in .dae files


Nescio
 Share

Recommended Posts

Today I followed @Stan`'s tutorial to install the io_scene_pyrogenesis Blender plug-in. (Fedora 32, Blender v 2.82a here.)

I noticed the default cube is 2×2×2 and added a flat rectangle (Shift+A → Mesh → Plane). Its default size is 2×2, thus I scaled it by (18, 6, 1), so it occupies 36 by 12 squares, because that's the size of wall long segments in the simulation templates.

I then imported art/actors/structures/fndn_9x3_wall.xml and noticed it practically covered the area of my reference plane. Next I imported art/actors/structures/romans/siege_wall_long.xml into the same value. The wall visibly had the same length as the foundation and the reference plane. To my surprise, however, all meters became inches and locations are given in yards; the reference plane now occupied half of four squares and a quarter of four other squares, i.e. a total area of three squares, which means the Blender raster is now in square feet instead of square meters (36"×12" = 3'×1').

I didn't understand why the units suddenly changed and initially blamed the fact I don't know how Blender works. However, I repeated the above in different orders and with other actors, with the same result. Therefore I concluded the problem was probably with the art files in the 0 A.D. repository.

Using `grep` in the art folder I discovered currently a dozen different <unit> tags are in use:

<unit meter="0.01" name="centimeter"/>
<unit meter="0.0254" name="inch"/>
<unit meter="0.025400"/>
<unit meter="0.025400" name="centimeter"></unit>
<unit name="centimeter" meter="0.01"/>
<unit name="decimeter" meter="0.1"/>
<unit name="decimetre" meter="0.1"/>
<unit name="inch" meter="0.0254"/>
<unit name="meter" meter="0.1"/>
<unit name="meter" meter="0.0254"/>
<unit name="meter" meter="0.0254" />
<unit name="meter" meter="1"/>

Although I'm not an artist, I do think the current situation is rather a mess. I believe it would be much better to standardize to simply:

<unit meter="1"/>

This can be done by running the following command in your 0 A.D. svn repository:

find binaries/data/mods/public/art/ \( -name '*.dae' \) -print0 | xargs -0 sed -i \
  -e 's,<unit meter="0.01" name="centimeter"/>,<unit meter="1"/>,g' \
  -e 's,<unit meter="0.0254" name="inch"/>,<unit meter="1"/>,g' \
  -e 's,<unit meter="0.025400"/>,<unit meter="1"/>,g' \
  -e 's,<unit meter="0.025400" name="centimeter"></unit>,<unit meter="1"/>,g' \
  -e 's,<unit name="centimeter" meter="0.01"/>,<unit meter="1"/>,g' \
  -e 's,<unit name="decimeter" meter="0.1"/>,<unit meter="1"/>,g' \
  -e 's,<unit name="decimetre" meter="0.1"/>,<unit meter="1"/>,g' \
  -e 's,<unit name="inch" meter="0.0254"/>,<unit meter="1"/>,g' \
  -e 's,<unit name="meter" meter="0.1"/>,<unit meter="1"/>,g' \
  -e 's,<unit name="meter" meter="0.0254"/>,<unit meter="1"/>,g' \
  -e 's,<unit name="meter" meter="0.0254" />,<unit meter="1"/>,g' \
  -e 's,<unit name="meter" meter="1"/>,<unit meter="1"/>,g'

 

Link to comment
Share on other sites

If you do that you will break the scaling of all the art files. Depending on how they were exported it might break the files :)

luckily the engine does not support scaling so everything is ignored.

  • Like 1
Link to comment
Share on other sites

53 minutes ago, Stan` said:

If you do that you will break the scaling of all the art files. Depending on how they were exported it might break the files :)

That's what I thought initially. However, importing a wall with a length of 36 meter and a wall with a length of 36 inch into the same Blender file somehow results in both walls being equally long, even though Blender suddenly uses inches, feet, and yards instead of meters, making making changes more complicated.

After I standardized the files to <unit meter="1"/> and imported various actors into the same Blender file, their game sizes were preserved and Blender used meters for everything, which is less confusing.

53 minutes ago, Stan` said:

luckily the engine does not support scaling so everything is ignored.

Which is why it is advisable all art files should use the same units, in case scaling will be supported at some point in the distant future.

 

Try the command listed in the opening post to verify everything still works. You can easily undo it with:

svn revert -R *

 

Link to comment
Share on other sites

It changes units because I told it to import units when I wrote the python script :)

Else the result might be different.

it usually doesn't matter much anyway. So much actually I actually forgot about it XD

Art isn't really held to programming standards.

object could be also be named more nicely but at the end of the day it makes no difference :)

also it's hard to run sed scripts on windows :)

Link to comment
Share on other sites

Just now, GunChleoc said:

sed should work in a Git Bash. Of course, file separators will still be a pain in the butt.

Yeah. It's useful :)
However I don't think changing the units of all those files is.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...