Search Unity

Blender model vertex ordering -> unity

Discussion in 'Asset Importing & Exporting' started by OwenTheProgrammerDev, Apr 11, 2021.

  1. OwenTheProgrammerDev

    OwenTheProgrammerDev

    Joined:
    Jul 26, 2017
    Posts:
    8
    Sorry if this has been asked before, first question here.
    I am working on a game obviously and I was having a problem with importing a blender model (.fbx) to unity,
    the problem is the ordering from blender is not the same compared to unity so there is something going on that unity is doing that puts the vertices in some other order. This is a bit of a problem because I'm trying to do some vertex animation with a python script I wrote in blender that takes the mesh data at each keyframe and exports the positions to a 16bit image. Anything I can do other than having like a hashtable or linked list system to store all the vertex links? The image below is something along the lines of what I get. gives me this.png

    This is the thing that I was going to use if this isn't a feature or at least something like this but this is probably the dumbest way of doing this. If need be I will extend the unity engine but then I need to know what class to extend in the c++ code
    Code (CSharp):
    1. Dictionary<int, Vector3> Vertex_Compressor;
    2.  
    3. void Start() {
    4.     Vertex_Compressor = new Dictionary<int, Vector3>();
    5.     Vertex_Compressor.Add(0, new Vector3(-1.5000f, -1.0000f, 0.0000f));
    6.     Vertex_Compressor.Add(1, new Vector3(-1.4442f, -0.9354f, 1.3404f));
    7.     Vertex_Compressor.Add(2, new Vector3(-1.5000f, 1.0000f, 0.0000f));
    8.     Vertex_Compressor.Add(3, new Vector3(-1.4442f, 0.9354f, 1.3404f));
    9. ... more and more spagetti
    https://docs.unity3d.com/ScriptReference/Mesh.MeshData.html
    found this class but If this is what I want to use then there is a new problem, the vertices are all in order (theoretically) but what is the triangle order?
     
    Last edited: Apr 11, 2021
  2. DimitriX89

    DimitriX89

    Joined:
    Jun 3, 2015
    Posts:
    551
    Check the model import options, Unity forces some optimisations by default, that may affect order
     
  3. OwenTheProgrammerDev

    OwenTheProgrammerDev

    Joined:
    Jul 26, 2017
    Posts:
    8
    Nope cant be that, the zero vertex seems correct but the problem is I tried anything other than the 0 index and its still wrong. In blender the 2th index is at the bottom still but in unity the model is still in the middle side upload_2021-4-13_3-19-45.png upload_2021-4-13_3-20-2.png
     
  4. OwenTheProgrammerDev

    OwenTheProgrammerDev

    Joined:
    Jul 26, 2017
    Posts:
    8
    Wait a minute. I try it two times in a row then it magically starts working???? well alright then. you just have to apply it then restart unity for some reason. now that that is taken care of I have to fix my shader stuff
     
  5. DimitriX89

    DimitriX89

    Joined:
    Jun 3, 2015
    Posts:
    551
    Thats BS, I agree. Another thing I forgot to mention is that the model vertex count often differs between editors and game engines. Real time engines treat things like UV seams and hard shading of the faces as split edges. So, for example, a cube will always have 8 vertices in Blender, but in Unity it can have up to 24 depending on smooth/hard shading and how you unwrapped UVs
     
  6. OwenTheProgrammerDev

    OwenTheProgrammerDev

    Joined:
    Jul 26, 2017
    Posts:
    8
    yeaaaaahhhh figured that one out just now, so I guess my plan for vertex animation is to make an in unity tool to lerp the positions of every model that moves, then make a script that concatenates each mesh into one mesh while also simultaneously generating the vertex displacement map which is a whole other problem and a half to deal with
     
  7. DimitriX89

    DimitriX89

    Joined:
    Jun 3, 2015
    Posts:
    551
    That sounds complicated. I'd advice you to pre-split your models' edges in Blender, but cannot guarantee Unity wont reorder them again for some other reason. What is your end goal anyway? Is it totally impossible with standard tools?
     
  8. OwenTheProgrammerDev

    OwenTheProgrammerDev

    Joined:
    Jul 26, 2017
    Posts:
    8
    So the project is a factory building game, and the problem is I don't want to use animation for all the operative machines and things that move. I want all the animation to happen internally with a shader vert function since they are going to be GPU instanced. Highly efficient and with vulkan it will run smoothly with all the different things happening on the screen so scalability is really important. Making inbuilt tools gets rid of any other complications in between
     
    DimitriX89 likes this.
  9. OwenTheProgrammerDev

    OwenTheProgrammerDev

    Joined:
    Jul 26, 2017
    Posts:
    8
    I just want to bake the animation into a texture then reference it in the vertex shader with a int to tell it to turn on or off with some property block magic
     
  10. DimitriX89

    DimitriX89

    Joined:
    Jun 3, 2015
    Posts:
    551
    Ok, good luck with that. There is definitely no built-in vector displacement baker for Unity.
     
    Last edited: Apr 14, 2021
  11. DimitriX89

    DimitriX89

    Joined:
    Jun 3, 2015
    Posts:
    551
    BTW, any chance it will be available on Asset Store when you finish? There are vector displacement shaders for Unity, but they barely see any use because creating VD maps is too hard. A tangent VDM baker made specifically for Unity, with its coordinate layout and tangent basis taken in consideration, will help a great deal with adoption of this technology.
     
  12. OwenTheProgrammerDev

    OwenTheProgrammerDev

    Joined:
    Jul 26, 2017
    Posts:
    8
    Hmm interesting since I will need it anyways. I can put it on the unity asset store but I would need to know a bit more on what everyone wants in general rather than me making just a specific tool for my game would be happy to make it though!
     
  13. DimitriX89

    DimitriX89

    Joined:
    Jun 3, 2015
    Posts:
    551
    The main use of vector displacement maps is adding extra geometry to models (such as stone walls or muscles on characters) while used in tesselation shaders. Pixlogic provided a good description of these maps and problems the technology is facing: http://docs.pixologic.com/user-guide/3d-modeling/exporting-your-model/vector-displacement-maps/ In short, every 3d engine has its own order of coordinate axes and method of tangent calculation, which hinders the adoption of vector displacement. So I thought that the highpoly-to-lowpoly VDM baking tool made exclusively for Unity would solve most of the compatibility issues. It is understandable if you wont want to bother though, since I only know a single VDM+tesselation shader asset on the store, and it is very old.
     
  14. OwenTheProgrammerDev

    OwenTheProgrammerDev

    Joined:
    Jul 26, 2017
    Posts:
    8
    Well I mean we all have to make money some how, I want to understand a bit more on the matter since this really isn't my forte, it sounds useful but it also sounds like you would need the mesh to be high-poly for there to be verts to move or is that the point of VDM+tesselation where its tesselation -> VDM, you have a discord?