Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Download 3d object file inside the Assets folder in run-time and load the object

Discussion in 'Scripting' started by ki_ha1984, May 7, 2015.

  1. ki_ha1984

    ki_ha1984

    Joined:
    Aug 24, 2014
    Posts:
    111
    Hi,

    I would like to ask if is there any way to load 3d objects in runtime ?
    or
    to download the 3d object inside the Resources folder, create the prefab and instantiate it?

    I would appreciate for any sample c# code.

    Thank you very much
     
  2. ki_ha1984

    ki_ha1984

    Joined:
    Aug 24, 2014
    Posts:
    111
    Any help ?
     
  3. ki_ha1984

    ki_ha1984

    Joined:
    Aug 24, 2014
    Posts:
    111
    I try to use this -> http://wiki.unity3d.com/index.php/ObjImporter
    the problem is that it gives this errors:

    Mesh.vertices is too large. A mesh may not have more than 65000 vertices.
    UnityEngine.Mesh:set_vertices(Vector3[])

    Mesh.uv is out of bounds. The supplied array needs to be the same size as the Mesh.vertices array.
    UnityEngine.Mesh:set_uv(Vector2[])

    Mesh.normals is out of bounds. The supplied array needs to be the same size as the Mesh.vertices array.
    UnityEngine.Mesh:set_normals(Vector3[])

    Failed setting triangles. Some indices are referencing out of bounds vertices. IndexCount: 150000, VertexCount: 0
    UnityEngine.Mesh:set_triangles(Int32[])
     
  4. pws-devs

    pws-devs

    Joined:
    Feb 2, 2015
    Posts:
    63
    Simple, when reading in the vertices and triangles, once your vertex count exceeds the limit, just split your mesh into submeshes and you can get past the limit.
     
  5. ki_ha1984

    ki_ha1984

    Joined:
    Aug 24, 2014
    Posts:
    111
    pws devs Can you please give me code example based on ObjImporter ?

    Thank you in advcence
     
  6. pws-devs

    pws-devs

    Joined:
    Feb 2, 2015
    Posts:
    63
    When you are reading it from the file, in the filestream portion of the code, there is a part where you are incrementing the vertex count. From that part, you might want to amend that to once you hit the 64k limit, stop increamenting and prepare a second mesh.
     
  7. ki_ha1984

    ki_ha1984

    Joined:
    Aug 24, 2014
    Posts:
    111
    i will try it ut i am not sure that i can make it, if you have any sample code i will appreciate it .

    Also, can i use the online asset bundle loader (link) to load the mesh (obj file) ?

    Thanks
     
  8. pws-devs

    pws-devs

    Joined:
    Feb 2, 2015
    Posts:
    63
    Nope. AssetBundle is AssetBundle. To create an asset bundle, one has to use Unity to recompile the obj into assetbundle.

    What exactly are you trying to achieve, runtime loading of 3d assets or runtime loading of meshes?
     
  9. ki_ha1984

    ki_ha1984

    Joined:
    Aug 24, 2014
    Posts:
    111
    I exactly try to get large 3d objects (.obj or .fbx ....) in run time.

    Thank you again.