Search Unity

How to recreate Unity's Vector3 class?

Discussion in 'Editor & General Support' started by Whimsical, Mar 4, 2010.

  1. Whimsical

    Whimsical

    Joined:
    Mar 29, 2008
    Posts:
    155
    Hi folks!

    My code monkey was asking me if I could cary this question to you beloved Unity fellowship.

    What we are trying right now is to creade a custom made converter/optimizer (outside of Unity but based on Mono) for huge meshes that were exported from CAD tools like Catia or Power Engineer.
    We made great progress until yesterday when we bumped into a, well, bump.

    We are creating three arrays to use with Unity's mesh class holding the triangle, vertex and normal data. We have no problems with the triangle array since that just consists of integers. But the arrays for vertex and normal data is another animal since it consists of Vector3.

    My question now is: Can I recreate the Vector3 struct outside of Unity so that I can stream the finished array directly into mesh.vertices and mesh.normals without having to recreate the arrays inside Unity and having to put my floats into Vector3s? That's kind of bad because we talk about really REALLY huge objects with a total of up to three million polys and recreating these two arrays on runtime would take a while and we would like to avoid that.

    I'd appreciate any hint that will lead me into a good direction. 8)

    - Martin
     
  2. SavaB

    SavaB

    Joined:
    Feb 11, 2010
    Posts:
    39
    apart from the problem that unity meshes cannot use more then 64,000 polys (or something like that) I don't think there's a possibility to actually recreate the struct.
    But runtime importing the triangle-array and vertices is actually very fast. I can import meshes each containing 10.000 tris in about 0.1 seconds per mesh, so I don't think you'll have to worry too much.
     
  3. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    the vector3 struct is nothing but a float[3] memory block. Thats how vectors are always defined.

    Whats important (much more important) are the index arrays to fill the triangles with vertex indices and naturally the triangle index arrays


    But independent of what you do: you can not go above 65000 vertices on a single mesh, even if you use black magic.
    Reason is that the vertex array for the meshes is short indexed and shorts don't go over 65536, that simple it is
     
  4. Whimsical

    Whimsical

    Joined:
    Mar 29, 2008
    Posts:
    155
    I didn't mention that my object is split into smaller objects because of the 65k-barrier because I think that this restriction is obvious. Thank you guys though for mentioning this point anyway since I guess that some guys around here don't know that yet and may be happy to read about why their large objects aren't loading. :)

    I'll look into what you said about the float[3] arrays, dreamora. Thanks for that hint.