Page 1 of 2

Error creating a 3D assets mod

Posted: Thu May 13, 2021 6:53 pm
by PascalCase
Hi all

I've been trying to create a 3d model mod, following the guide on steam, but it's not working. It's creating the empty mod folders for the package, but doesn't create any models or textures or anything.

The error msg I'm getting is:

Code: Select all

Traceback (most recent call last):
  File "E:\Env\Py38\lib\site-packages\cx_Freeze\initscripts\__startup__.py", line 40, in run
  File "E:\Env\Py38\lib\site-packages\cx_Freeze\initscripts\Console.py", line 37, in run
  File "prep.py", line 423, in <module>
  File "prep.py", line 166, in execute
  File "prep.py", line 225, in models
  File "E:\code\uoc2\tools\prep\models.py", line 104, in build
  File "E:\code\uoc2\tools\prep\models.py", line 44, in _process_models
  File "E:\code\uoc2\tools\prep\models.py", line 141, in _load_model
  File "E:\code\uoc2\tools\model_tools.py", line 221, in load_materials
AttributeError: 'str' object has no attribute 'get'


I'm using a tank model from the web, merging it into body and turret (so maybe the turret is turning the way the german tanks are) and exporting as .obj with Blender.
I exported all textures as .tga with both Krita and Gimp. I don't have a specular map, so I first ignored it and later exported the diffuse map as grayscale. Both didn't work though.

Since this didn't work, I tried to copy-paste the example .yml from the guide and also created a nonsense .yml, which both return the same error as long as the .yml's name is correct and it has a "materials:"-body. Which makes me think maybe the script is at fault here. But in that case, others should have discovered this bug too, right?

Do you have any advice what else I could try?

Re: Error creating a 3D assets mod

Posted: Fri May 14, 2021 7:06 am
by Tomislav Uzelac
Hi, please post the yml you are using.

That guide has problems with formatting, I will check to make sure your yml is correct for our importer.

Cheers!

Re: Error creating a 3D assets mod

Posted: Fri May 14, 2021 10:05 am
by PascalCase
I couldn't attach it as .yml, so I'm posting it as .txt (probably because it could be a virus).

My folder structure looks like this:

Code: Select all

Unity of Command 2
 assets_in
  unit_models
   can_arm_43
    can_arm_43.yml
    jap_type_95_hago.obj
    Type_95_Ha_Go_Kd.tga
    Type_95_Ha_Go_Ks.tga
    Type_95_Ha_Go_N.tga


My command line looks like this:

Code: Select all

prep models can_arm_43 --package=test


I'm using Windows, so maybe it's just some Linux-Windows-thing like the new-line-character?

Thank you for your help

Re: Error creating a 3D assets mod

Posted: Sat May 15, 2021 5:35 am
by Tomislav Uzelac
I have edited the can_arm_43.yml file for you.

Note the minus before map_Kd, and how everything that follows is indented by exactly two spaces ("materials" should be a "list" in yml syntax).

Code: Select all

materials:
- map_Kd: Type_95_Ha_Go_Kd.tga
  map_Ks: Type_95_Ha_Go_Ks.tga
  map_bump: Type_95_Ha_Go_N.tga
  shininess: 25.0
  Kd: [1, 1, 1]
  Ks: [1, 1, 1]
mesh_file: jap_type_95_hago.obj
properties:
 scale: 1
# rotation: 0.0
 offset: [0.0, 0.0, 0.0]


There could potentially be a further issue, with the OBJ file: if this still doesn't work, rename the OBJ file to can_arm_43.obj and remove the "mesh_file" line from the yml.

Let me know if this helps.

Cheers!

Re: Error creating a 3D assets mod

Posted: Sat May 15, 2021 1:15 pm
by PascalCase
It did indeed help and you were right with the .obj. If I name it anything but can_arm_43, I get this error:

Code: Select all

Traceback (most recent call last):
  File "E:\Env\Py38\lib\site-packages\cx_Freeze\initscripts\__startup__.py", line 40, in run
  File "E:\Env\Py38\lib\site-packages\cx_Freeze\initscripts\Console.py", line 37, in run
  File "prep.py", line 423, in <module>
  File "prep.py", line 166, in execute
  File "prep.py", line 225, in models
  File "E:\code\uoc2\tools\prep\models.py", line 104, in build
  File "E:\code\uoc2\tools\prep\models.py", line 44, in _process_models
  File "E:\code\uoc2\tools\prep\models.py", line 159, in _load_model
  File "E:\code\uoc2\tools\model_tools.py", line 31, in load_model
  File "E:\Env\Py38\lib\site-packages\pyassimp\core.py", line 293, in load
pyassimp.errors.AssimpError: could not import file: F:\Steam\SteamApps\common\Unity of Command 2\assets_in\meshes\can_arm_43_test.obj

The "mesh_file"-line doesn't matter; if the .obj file name matches it works.

-

Next I got this error:

Code: Select all

Traceback (most recent call last):
  File "E:\Env\Py38\lib\site-packages\cx_Freeze\initscripts\__startup__.py", line 40, in run
  File "E:\Env\Py38\lib\site-packages\cx_Freeze\initscripts\Console.py", line 37, in run
  File "prep.py", line 423, in <module>
  File "prep.py", line 166, in execute
  File "prep.py", line 225, in models
  File "E:\code\uoc2\tools\prep\models.py", line 104, in build
  File "E:\code\uoc2\tools\prep\models.py", line 44, in _process_models
  File "E:\code\uoc2\tools\prep\models.py", line 169, in _load_model
  File "E:\code\uoc2\tools\model_tools.py", line 112, in load_meshes
  File "E:\code\uoc2\tools\model_tools.py", line 68, in _pack_normals
IndexError: too many indices for array


Turns out I was able to fix it by merging the body and turret mesh of my tank. I'm still getting a warning, but at least no more errors:

Code: Select all

WAR -- Insufficient pixel density for texture F:\Steam\SteamApps\common\Unity of Command 2\assets_in\unit_models\can_arm_43\Type_95_Ha_Go_Kd.tga: 251 (at least 300 needed)

Sounds like something I can fix.

Now behold the new canadian 1943 tank model, codenamed "Godzilla":

JapaneseGogzillaTank.jpg

:D

The scaling and shininess is obviously way off, I'll have to play around with it a bit and will probably post another picture with better settings in a couple days.

At least the model made it into the game thanks to your help ;) .

Re: Error creating a 3D assets mod

Posted: Sat May 15, 2021 3:04 pm
by PascalCase
Fixed the scale and added localization, .yml and thumbnails so I could add it as a new unit and not as a replacement:
NewUnit.jpg


Now all I have to do is repeat this process for 10 other units and I could release it as a mod :lol:

Re: Error creating a 3D assets mod

Posted: Sat May 15, 2021 5:08 pm
by Tomislav Uzelac
Awesome! :D

A single-mesh tank will work just fine. If you want the turret to rotate as it does for the other tanks in the game, the OBJ needs to contain exactly two meshes: one named "body" and the other named "turret". It's not always easy to force 3D software to assign these exact names - if it comes to worst, you can always edit the OBJ file, it's just text.

Cheers!

Re: Error creating a 3D assets mod

Posted: Mon Aug 30, 2021 12:33 pm
by TheLastSterling
PascalCase wrote:It did indeed help and you were right with the .obj. If I name it anything but can_arm_43, I get this error:
...
At least the model made it into the game thanks to your help ;) .



Sorry to respond, but could you possible help me as I'm having my own problem since you've seem like you managed to get a model to work. I'm trying to add in a 'uk_arm_44" unit but it keeps making an empty folder much like your first post.

1. Create the folder path "Unity of Command 2\assets_in\unit_models\uk_arm_44"
2a. Place my model "uk_arm_44.obj" into the "uk_arm_44" folder
2b. Placed textures:
a27m_Cromwell_dd.tga
a27m_Cromwell_Ks.tga # I don't have a spectacular image so I just copied my normal, idk if that's a problem.
a27m_Cromwell_n.tga
2c. Created uk_arm_44.yml with the code:

Code: Select all

materials:
- map_Kd: a27m_Cromwell_dd.tga
  map_Ks: a27m_Cromwell_Ks.tga
  map_bump: a27m_Cromwell_n.tga
  shininess: 25.0
  Kd: [1, 1, 1]
  Ks: [1, 1, 1]
mesh_file: uk_arm_44.obj
properties:
 scale: 1
# rotation: 0.0
 offset: [0.0, 0.0, 0.0]
 

3. Create a Prep.exe shortcut and changing the Target line to:
"Unity of Command 2\prep.exe" models uk_arm_41 --package=uk_arm_44

Re: Error creating a 3D assets mod

Posted: Tue Sep 14, 2021 3:14 pm
by PascalCase
Hi Sterling

Sorry it took me so long; I didn't get a notification and wasn't on the forums for a while.

Not sure, why it didn't work for you though. Some points which might point you in the right direction:

- I didn't have a specular map neither, that's why it looked so horribly shiny. In the end, I just didn't include one, worked anyway.
- I didn't use tabs in the .yml file, but added white spaces with the space bar: One space after the '-' and 'map_Kd' and two spaces in front of all the other lines of materials.
- It worked using Windows, the devs use Linux afaik, so shouldn't be an OS-thing
- prep.exe does create a log file in the AppData/local/.uoc2 called prep_log.txt, it's best to have a look at it.

Edit:
- I used cmd directly and not a shortcut, worth a try too I guess.

Re: Error creating a 3D assets mod

Posted: Wed Sep 15, 2021 5:42 am
by TheLastSterling
No problem, I wouldn't assuming you'd be on this forums to check frequently.

From your response it might be due to me using a shortcut. I'm not familiar with cmd so I assumed it had to do with shortcuts. I tried clicking the prep.exe but that ends up closing right after opening.