Search Unity

Imported model vertex count doesn't match .obj file

Discussion in 'Editor & General Support' started by ChanzDog, Dec 10, 2019.

  1. ChanzDog

    ChanzDog

    Joined:
    Sep 28, 2017
    Posts:
    24
    I am working with a very old game format and am importing the levels and character models. I have written an exporter which outputs OBJ files for the meshes. Separately, I export a list of any other data (e.g. vertex colors) that was contained in this old format. The problem I am having is that when Unity imports the model, the vertex count is greatly inflated. I checked in my exporter with a simple model and the vertex count is 1419. I loaded it into a 3d modeling program and verified that it has 1419. When I bring it into Unity, the mesh filter has ~2x as many vertices.

    I tried disabling all of the normal generation, and then I am getting fewer than 1419. I really need this number to match so that I can send vertex colors for each mesh and have them line up in the correct vertex.

    Is there any way to ensure this?
     
  2. Olmi

    Olmi

    Joined:
    Nov 29, 2012
    Posts:
    624
    Hi @ChanzDog,

    Disable all import optimizations etc. and set Smoothness Source to From Angle, and set angle to 180.
    If you leave your smoothing off, you will add more vertices to your object. You could also import smoothing from your source. But with those settings 8 vertex smooth shaded cube is exactly 8 vertices and 36 triangle indices (divide that by 3 to get triangle faces, i.e. 12.) when imported as an OBJ to Unity.

    I suggest you do first a few test imports with just cubes and quads etc. to be able to diagnose what is exactly wrong in your process. Otherwise it's much more to pinpoint the exact mistake.

    Also, if you intend to import your vertex colors in OBJ, that will not work as far as I know, although some apps like ZBrush do write vertex colors to the OBJ files.
     
  3. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    5,743
    yeah, unity doesn't import OBJ vertex colors, but at least DAE (or FBX) works.

    i feel like the vertex id order might be mixed up in any case (it file is converted through other tools)

    i tried to solve similar issue while ago, to match vertex index, after the file was converted into unity through several 3d tools (but that didnt go too well)
    https://twitter.com/unitycoder_com/status/1075687438415220738
     
  4. Olmi

    Olmi

    Joined:
    Nov 29, 2012
    Posts:
    624
    If I needed to import some simple-ish obsolete object format, I think the best bet would be to create own importer. Import data as ascii text, parse it, create meshes and so on.
     
  5. ChanzDog

    ChanzDog

    Joined:
    Sep 28, 2017
    Posts:
    24
    Thanks guys. I know OBJ doesn't import vertex colors, that's why the vertex data in Unity needs to match what I export. That way I can import each color and set it to its correct vertex, which doesn't work if my obj has 1000 and the import has 1500.
     
  6. Olmi

    Olmi

    Joined:
    Nov 29, 2012
    Posts:
    624
    @ChanzDog how did you verify that your object has 1000 vertices after you exported it?
     
  7. ChanzDog

    ChanzDog

    Joined:
    Sep 28, 2017
    Posts:
    24
    @Olmi I loaded it up in two external 3d programs and checked the vertex count. Additionally, I am creating the OBJ via a program I wrote so I am sure there is no smoothing or anything else that might be affecting the import if I was doing it via a standard 3d application. It was the same as the number of vertex lines in the OBJ. I may go the route of just using an intermediate format but I'd prefer not to if possible.

    Here's some more information. When exporting the model from the old game format via a C# application I have written, I create the OBJ file and the model contains 1419 vertices. I used vertex colors as an example to keep things simple. What I am really doing is setting vertex bone weights for animations and of course, if I have 1419 bone weights and I try and set them in Unity and the model all of a sudden has twice as many vertices, this doesn't work as these numbers need to match.

    So my options are either to find a way to keep the vertex count the same via importing or use an intermediate format and build the mesh, UVs, and bone weights via an importer (which is okay but I'd prefer not to as OBJ is a solid format for what I am doing).

    Here is the model in question: http://s000.tinyupload.com/index.php?file_id=98184567815443548578
     
    Last edited: Dec 10, 2019
  8. Olmi

    Olmi

    Joined:
    Nov 29, 2012
    Posts:
    624
    @ChanzDog Well, I can't get it to import with that 1419 vertex count as was quite obvious.

    But - I got it import 1419 vertices via Blender roundtrip (I have no idea if the point order is correct yet.)
    I did the following:
    1. Import your model to Blender 2.8
    2. Go to modeling mode, set all faces to render smooth
    3. Export as FBX, with following settings: basically everything off except Apply transform, only export selected objects. Smoothing option was set to "Normals Only".
    4. Import fbx to Unity, disable all optimizations, material imports, animations etc. Just leave Read/Write on.
    Geometry, these settings:
    Normals: Import
    Normals Mode: Area and Angle Weighted (doesn't seem to matter.)
    Smoothness source: From Smoothing Groups
    Tangents: Import
     
    Last edited: Dec 10, 2019
    ChanzDog likes this.
  9. ChanzDog

    ChanzDog

    Joined:
    Sep 28, 2017
    Posts:
    24
    Interesting. So it modified the OBJ but left the FBX alone. If only FBX exporting was as straightforward. Tempted to write my own ASCII FBX exporter but it's so verbose. Thanks for following up. Appreciate it @Olmi .

    Something else I will try: my export doesn't have normals. It's possible in the normal creation, it messes up. But I have disabled normal import/creation and I have sub 1419 verts. Will look a bit more before moving to an intermediate solution.
     
  10. ChanzDog

    ChanzDog

    Joined:
    Sep 28, 2017
    Posts:
    24
    Just included the normals in the OBJ export and set the importer to import normals. Vertex count: 3088.

    Oh well.
     
unityunity