Megaquarium

Megaquarium

What will you create?
Access an ocean of content for Megaquarium created by players like you. New animals, decorations, tanks and more are available to expand your game and tailor it to your liking.
Learn More
Flaky FBX support and potential pragmatic solution
Hi there

I have tried exporting meshes from both Modo and Blender but never managed to get them to load properly. Now I know there are many many versions of fbx and that it's hard to support even a fraction of them.
That is why I think the best way to support the modding community would be for TwiceCircled to release a small Unity script that preprocesses the meshes and saves them in whatever format the game expects.
- Unity is free to use for non-commercial purposes
- It can load pretty much all fbx formats and even lets you tweak some data after import. For example, some tools don't let you export multiple animations in a single file. This could be handled by letting Unity load a different mesh file for each animation and combine them internally.
- It is the engine behind Megaquarium so compatibility should not be an issue
- The resulting format should in theory load a lot faster than trying to parse a text fbx file.

Now obviously, it's easier said than done, but I really believe that such a tool could really be worth it in the long run. And since the rest of the modding aspect is all text-file based, the community could easily make more scripts around it and turn Unity into a fancy GUI for mod making.

< >
Showing 1-7 of 7 comments
Twice Circled  [developer] 3 6 Jun, 2020 @ 2:19am 
Hey Sgt.Rouflaquettes thanks for the idea.

I don't actually use any of the built in fbx stuff in Unity so this wouldn't be a quick script to write unfortunately. But when I have a bit more time I might look into it. Or even better, if someone else wanted to get it started and send a draft over that would be amazing. ;)

To translate to tc3d we need a script that pulls out raw data arrays from the fbx for:

[per mesh in the model]
- parent transform offset and rotation
- uvs
- normals
- materials
- vertices for every frame of animation, stored by animation name

If someone was able to write a script that could take an fbx and dump out all that information it might not be much work for me to add the bit to get it to tc3d format.
Great news!

I can't get you that data straight from fbx, but I can definitely do it from a mesh imported into Unity. So basically an editor-side data extractor that leverages the Unity mesh importer.
Conveniently, it so happens that I'll be on holiday next week and that with the virus around there won't be much to do apart from staying home, so I'll try to get you some sort of basic tool sorted.

Quick questions before I get started:
- Normals: are they also animated or do you only need the 'untransformed 'value?
- Materials: what is that supposed to be? Just the material name on each object?
- Do you need indices or do I have to 'unroll' the vertex data?
Twice Circled  [developer] 3 7 Jun, 2020 @ 7:23am 
Wow, if you're really sure you can spare the time. Here are the answers:

- Not animated, just untransformed value.

- Materials: two parts.

1. Material index, every triangle will have a material associated with it. This is stored in an int array in the same order as the triangles.

So triangles might be:
[0,1,2,1,2,3] for two triangles: {0,1,2} and {1,2,3}.
Materials could be:
[1,0] for triangle 1 has material 1 and triangle 2 has material 0.

2. The second part is the data about the material itself, in the same order as the material index above:

So material 0 could be:
bool unshaded - this is a special tag we use in the name of the mesh to say whether to use the unshaded shader.
Color color - this is a color tint applied to the texture in the shader.
Color emissive - this is a color tint applied to the pattern texture in the shader.
bool diffuseHasAlpha - this tells the engine whether the material should support transparency or be opaque.

Dictionary<string,string> texturePairs;

Each key value pair assigns a texture to a material channel. The engine only supports two channels:

"DiffuseColor": "mainTexture.png"
"EmissiveColor" : "patternTexture.png"

The emissive/pattern texture is optional but should be included if it's present in the fbx model.



- Yes please, include indices. I forgot to mention that one in my original reply.

So to summarise again:

Per mesh{ vertex array (bind pose) uv array (per vertex, given in same order as vertices) normal array (per vertex, given in same order as vertices) triangle/indices array material index array (per triangle, given in same order as triangles) root translation (bind pose) root rotation (bind pose) Per Animations { nameOfAnimation Per Frame { vertex array } } } Per material, given in same order as the material indices{ bool unshaded Color color Color emissive bool diffuseHasAlpha Dictionary<string,string> texturePairs }

I think that's it. :)
Sgt.Rouflaquettes 8 Jun, 2020 @ 12:26am 
Are there meshes in the game that actually use different materials on a per-triangle basis? For example, the orange juice machine fbx shows 3 separate entities: the main body and 2 glass panels. Should they all be merged into a single mesh for tc3d?
Twice Circled  [developer] 3 8 Jun, 2020 @ 12:54am 
No.

All vanilla meshes are 1 material per mesh because this allows them to take advantage of a special rendering pipeline I've built which improves performance.

However, modders don't always do this so you should have support for multiple meshes and multiple materials per mesh.

Personally I wouldn't do any combining or splitting of the geometry that the fbx contains, even if it would be more optimised. I think it's better to just pull the data out as it is organised in the model file to give the designer more control.

EDIT: When we consider that different meshes might be animated differently it becomes even more important not to combine them.
Last edited by Twice Circled; 8 Jun, 2020 @ 12:58am
OK, so I think I will ignore it for now and just write '0' on all triangles (at least until we manage to get a 'standard' fbx converted and imported into the game and then I can test things myself).
Twice Circled  [developer] 3 8 Jun, 2020 @ 4:06am 
That makes sense. :)
< >
Showing 1-7 of 7 comments
Per page: 1530 50