Search Unity

SimpleCollada - runtime importer for Collada .DAE models

Discussion in 'Assets and Asset Store' started by Orbcreation, Nov 25, 2014.

  1. Orbcreation

    Orbcreation

    Joined:
    May 4, 2010
    Posts:
    231
    Hi everyone,

    For my own project I will allow end users to upload their own 3D models. For this I needed a simple importer for Collada files (Also for OBJ but that is a different asset store package).

    Collada is an interchange file format for 3D applications, managed by the Khronos group and probably intended as "One format to rule them all". That idle wish never came true, but most 3D modeling tools do support it. Collada files usually have the extension .DAE and are structured like XML files. Collada specs are here

    These Collada specs are way too extensive for my purpose, so SimpleCollada just cherry picks what it needs to import a model. It imports vertices, normals, 1 uv map and triangles. (polygons are
    automatically converted to triangles). Supports multiple meshes and sub meshes. All the other stuff like setting up scenes, lights, material libraries, animations, etc. is ignored.

    This is a runtime importer and there is no Editor interface, since the Unity Editor already imports Collada files by default.

    To import a model at runtime, you simply
    - download a Collada file into a string,
    - pass the string to the import function
    - and receive a GameObject in return.

    Like so:
    myGameObject = ColladaImporter.Import(colladaString);

    All source code is included and written in C#. There are no DLL's or hidden stuff.

    The webplayer demo can be found here
    The documentation can be found here
    The asset store package can be found here

    Notes:
    Also includes the SimpleXML package.
    Does not support skinned meshes


     
  2. Orbcreation

    Orbcreation

    Joined:
    May 4, 2010
    Posts:
    231
    SimpleCollada is now implemented in my own 3D website builder. Check out the blog post here: http://orbcreation.com/orbcreation/page.pl?1211
    (Also uses SimpleOBJ for importing OBJ models, SimpleLOD for reducing mesh triangles and Texture2D Extensions for manipulating textures) Screenshot_2014-12-10_15-49-25.jpg
     
  3. Diemer

    Diemer

    Joined:
    Jan 29, 2015
    Posts:
    5
    Hi,
    does your dae importer supports vertex color information ?
    If i import my mesh with simpleCollada will i be able to see the vertex colors of my mesh (if i set the right shader) ?
     
    Last edited: Jan 29, 2015
  4. Orbcreation

    Orbcreation

    Joined:
    May 4, 2010
    Posts:
    231
    Sorry, no it doesn't at the moment. But mail me your model and I will add it for you. richard (thingy) orbcreation (dot) com
     
  5. Diemer

    Diemer

    Joined:
    Jan 29, 2015
    Posts:
    5
    Thank, but i want the user to load some models :)
     
  6. Orbcreation

    Orbcreation

    Joined:
    May 4, 2010
    Posts:
    231
    oh no worries. I only asked because it would be handy to have a model to test with. Instead I will create a collada model with vertex colors myself and see if I can add this function to it. I'll let you know how it goes in this forum. Or send me a PM with your email address and I will mail you the beta version of the update.
     
  7. Orbcreation

    Orbcreation

    Joined:
    May 4, 2010
    Posts:
    231
    I uploaded version 1.1 to the Asset Store for approval. The review usually takes about a week.

    This version supports vertex colors. Make sure you use a shader that supports vertex coloring to see it though. The default diffuse shader that is used in the demo will not show them.
     
  8. Diemer

    Diemer

    Joined:
    Jan 29, 2015
    Posts:
    5
    Cool ! Thank you :)
     
  9. quelsh

    quelsh

    Joined:
    May 28, 2014
    Posts:
    6
    Hello,

    I bought your plugin a few days ago in order to support modding in my game.
    For that cause I use several "locator" objects to be able to place other objects to where they belong.
    These locator objects obviously don't have any vertex data associated as the meshes will then be placed at their position and rotation.

    In AppendGameObjectsFromNodes you explicitly check if there is an instance_geometry present for a node and you wouldnt include it. So I extended the method with a boolean which causes that the function basically ignores if there is an instance_geometry present and creates a GameObject anyway.

    After that change more (empty) objects were imported but there were still a lot missing. So I checked the Hashtables you create using the SImpleXmlImporter and saw that these nodes actually were not present. To be more precise only the last item from that node in the XML document was added to the hierarchy.

    I think there might be something wrong with the SimpleXmlImporter then. I can give you the collada file in question if you want to debug for this case.

    I also included two pictures showing the XML and the parsed Hashtable:

    Screenshot_XML.png Screenshot_VS.png

    To my understanding the _Locators node should save an ArrayList again with the key "node" instead it has a singular node saved

    Regards
     
  10. Orbcreation

    Orbcreation

    Joined:
    May 4, 2010
    Posts:
    231
    Hey @quelsh The reason I check for the existence of geometry is that I originally created this imported for my own project. End users could upload 3d models, but I didn't want them to import useless stuff like camera's and lights and what not. Therefor only the geometry is imported.

    I had a look at your XML screenshot and none of the nodes you have there are closed with a </node> tag, except for the last one. The importer probably also gives you warnings about this in the console.
     
  11. quelsh

    quelsh

    Joined:
    May 28, 2014
    Posts:
    6
    Hi @Orbcreation,

    The display of the XML code I posted is collapsed by the editor I was viewing it in. So the nodes are actually correctly enclosed in <node> and </node> tags. Sorry for the confusing screenshot!

    I understand why you would want to exclude such objects, but as I already mentioned I need it in my project and the change was actually straight forward to let the Collada importer create the empty GameObject hierarchy.

    Even if there were notions of cameras and whatnot in the Collada file, the Importer itself would have to take care of that if it encounters the corresponding tags in the hashtable if I am not mistaken (unless cameras, lights, etc. are defined in "instance_geometry" nodes of course).

    I get 3 warnings by the importer about three nodes with a missing closing tag. I just checked them and they are actually correctly enclosed as well and the node whose subnodes are missing except for one is not one of them.
     
  12. Orbcreation

    Orbcreation

    Joined:
    May 4, 2010
    Posts:
    231
    Could you mail me your DAE file? and the edited script?
     
  13. quelsh

    quelsh

    Joined:
    May 28, 2014
    Posts:
    6
    Of course!
    Please let me know your E-Mail address via this thread or personal message.
     
  14. Orbcreation

    Orbcreation

    Joined:
    May 4, 2010
    Posts:
    231
    I guess you will have to start the private conversation, because I am not allowed to start one with you.
     
  15. quelsh

    quelsh

    Joined:
    May 28, 2014
    Posts:
    6
    Ok, I sent you a message! Thank you for your help!!
     
  16. CaptainMurphy

    CaptainMurphy

    Joined:
    Jul 15, 2014
    Posts:
    746
    I have a model that uses a JOINT node for the orientation and the gameobject for the node appears but the orientation is off. I tried the same model export/import into several other programs and it is orienting correctly. I dug around in the documentation for Collada format and it appears that joints are handled slightly different than normal geometry. Any chance to get this updated to handle joints?

     
  17. Orbcreation

    Orbcreation

    Joined:
    May 4, 2010
    Posts:
    231
    Hey @CaptainMurphy I have been working on this exact problem together with another client. An update is being tested rght now. Could you contact me so we can test your model as well? richard thingy orbcreation dot com
     
  18. CaptainMurphy

    CaptainMurphy

    Joined:
    Jul 15, 2014
    Posts:
    746
    @Orbcreation, I sent a link to the test model. Our models heavily rely on the joints for the gunportlids, rudder, tiller, etc so thanks for taking a look at this. That matrix info in the Joint node if baffling to me for some reason.
     
  19. S_P_S

    S_P_S

    Joined:
    Feb 25, 2015
    Posts:
    91
    Textures will be also imported, right?
     
  20. S_P_S

    S_P_S

    Joined:
    Feb 25, 2015
    Posts:
    91
    Now, I just tried it.

    I am able to import my model, but only without textures.
    Every mesh has just one texture, nothing complicated. Shouldn't this be possible? What am I doing wrong?

    Regards
     
  21. SunnySunshine

    SunnySunshine

    Joined:
    May 18, 2009
    Posts:
    976
    Are there any plans to support skinned meshes in the future?
     
  22. Orbcreation

    Orbcreation

    Joined:
    May 4, 2010
    Posts:
    231
    Hey Sunny,
    Well, I could add that and I even would enjoy doing that. But uhm... when I look at it objectively, the sales revenue for SimpleCollada is barely worth the time to reply to the messages in this thread. So I'm very sorry, but I doubt it will happen in the near future.
     
  23. SunnySunshine

    SunnySunshine

    Joined:
    May 18, 2009
    Posts:
    976
    I see, thanks for replying.
     
  24. CaptainMurphy

    CaptainMurphy

    Joined:
    Jul 15, 2014
    Posts:
    746
    The code is pretty open and the collada format is pretty well documented for the materials so you could iron it out yourself.
     
  25. SunnySunshine

    SunnySunshine

    Joined:
    May 18, 2009
    Posts:
    976
    Sure, but I'd much rather spend my time elsewhere.
     
    Joy0023 likes this.
  26. CommunityUS

    CommunityUS

    Joined:
    Sep 2, 2011
    Posts:
    240
    Is there a way to return the list/array of child objects into a set of GameObject[]'s.

    I am wanting to add a component to them post import. And then move them into a pooling solution among various other things.
     
  27. Orbcreation

    Orbcreation

    Joined:
    May 4, 2010
    Posts:
    231
    Something like this:
    Code (CSharp):
    1. Transform[] allTransforms = topLevelGameObject.GetComponentsOfType<Transform>(true);
    2. for(int i=0;i<allTransforms.Length;i++) {
    3.     GameObject childGO = allTransforms[i].gameObject;
    4.     childGO.AddComponent........
    5. }
     
    CommunityUS likes this.
  28. LabInno

    LabInno

    Joined:
    May 19, 2016
    Posts:
    6
    Hi,
    I tried for hours to load my Collada file with your plugin I just bought, and I couldn't manage to do it yet.
    I tried with a much simpler object, like just a regular cube and it worked very well.
    So I suspect that your plugin can not load "complicated" Collada.
    I linked my dae file. I tried with online collada viewers, and it worked perfectly, so can you tell me if I did something wrong please ?

    Thanks !
     

    Attached Files:

    Last edited: May 19, 2016
  29. CaptainMurphy

    CaptainMurphy

    Joined:
    Jul 15, 2014
    Posts:
    746
    It can definitely import complex models. Are you getting any errors in console during import?

    We use it to import ship models with joints that work pretty good. UV's align correctly and we were able to write a simple material assign script that gets the materials from a list as well.

     
  30. DarrenP

    DarrenP

    Joined:
    Jun 17, 2014
    Posts:
    7
    Hello,

    I am also having some trouble loading collada files with the plugin. The demo files work great, however anything (even a simple cube) I export from maya throws an "Array index is out of range" error, on line 949 of ColladaImporter.cs. Have attached a cube collada file that fails, hopefully it can be of some help.

    Any ideas?

    Thanks :)
     

    Attached Files:

  31. miragestudio

    miragestudio

    Joined:
    Nov 29, 2014
    Posts:
    3
    Hello, I'm trying to load a simple cube inside the web player demo, but it doesn't work. This cube was created with sketchup and exported in DAE file (see file below).

    What am I missing ?

    Thanks for help !
     

    Attached Files:

  32. Orbcreation

    Orbcreation

    Joined:
    May 4, 2010
    Posts:
    231
    You weren't missing anything. This model was so simple that it uncovered an error that only occurs if there is hardly anything to import. I fixed it now and will send the update to the AssetStore, but it will take a few weeks for them to approve it. Send me an email if you need the fix now. richard (thingie) orbcreation (dot) com
     
  33. Cascho01

    Cascho01

    Joined:
    Mar 19, 2010
    Posts:
    1,347
    I tried the Collada importer Demo with my own *.DAE ( a simple Cube with a texture),
    but the texture doesn´t get imported:

    DAE: www.3d-scapes.de/DAE/MyBox.DAE
    Texture: www.3d-scapes.de/DAE/images/0_bick.jpg

    I think the textures path is correctly defined in the dae-code.

    I used the 3dsmax DAE exporter as well as the OpenCollada exporter for 3dsmax.
     
  34. 2tarotk

    2tarotk

    Joined:
    May 31, 2016
    Posts:
    1
    Hi, I tried to load the Collada files, using SimpleCollada.
    But it cannot load diffuse color parameter.
    Then, I had read ColladaImporter class, and found a bug.

    For applying a patch, I think that it is good to fix just as the follow code.

    https://gist.github.com/2tarotk/faa7d85212425daedf4cd9a56a026d44

    Thank you.
    I have hope that this issue is fixed.
     
    Last edited: Sep 8, 2016
  35. Orbcreation

    Orbcreation

    Joined:
    May 4, 2010
    Posts:
    231
    Sorry for the late response people, but I was on holiday.

    @Cascho01 The demo file contains the code to download the textures. It also add a log entry for every texture it tries to download. Have you checked the console? If it still doesn't work, could you email me the cube and the textures?

    @2tarotk Thanks man!
     
  36. dc06dcj6

    dc06dcj6

    Joined:
    Oct 3, 2016
    Posts:
    1
    Hi, i tried to load the Collada files from local but there is nothing shows on my scene.
    Here is my code,

    Code (CSharp):
    1.  
    2. void Start()
    3. {
    4.      StartCoroutine(DAELoad());
    5. }
    6.  
    7. IEnumerator DAELoad()
    8. {
    9.     WWW www = new WWW("file://" + Application.persistentDataPath + "/filename.dae");
    10.     yield return www;
    11.     GameObject target = ColladaImporter.Import(www.text, ture);
    12.     target.transform.position = new Vector3(0,0,0);
    13.     target.transform.localScale = new Vector3(10,10,10);
    14. }
    15.  
    I tried my Collada files and some of your sample files.
    It works fine with mushroom, donut in SampleColladaFiles folder ( i just change the file extensions to dae ). However i can't see anything with female and some of my Collada files.

    Btw, when i load these files, i see the ImportedColladaScene object shows in my Hierarchy column. Just can't see it on my scene. ( There is no any exception with this code )

    I put all .dae files i tried into the attached file. Thx.
     

    Attached Files:

  37. CarePackage17

    CarePackage17

    Joined:
    Dec 6, 2014
    Posts:
    22
    Does your library work on UWP? I'd need to import models at runtime on a HoloLens.
     
  38. ixdeveloper

    ixdeveloper

    Joined:
    Jan 5, 2016
    Posts:
    14
    So I purchased the package and I can confirm that it runs fine on UWP/HoloLens. Very neat and simple, I appreciate that there are no DLL:s or other dependencies.

    Would love to be able to import meshes with more that 65k triangles but that is a Unity limitation as I understand it.
     
  39. st_lupo

    st_lupo

    Joined:
    Oct 4, 2016
    Posts:
    1
    I just purchased the package and had a little problem importing some simple geometries. The collada files that I am importing are based on a geometry that was originally contained in an stl file, and converted to collada via assimp. Importing the collada data yielded the following error in Unity:
    >>>
    ArgumentOutOfRangeException: Argument is out of range.
    Parameter name: index
    System.Collections.Generic.List`1[System.Int32].get_Item (Int32 index) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Collections.Generic/List.cs:633)
    ColladaImporter.ReadPolygonsInto (System.Collections.Hashtable polylist, System.Collections.Hashtable& meshDef, System.Collections.Generic.List`1& vertices, System.Collections.Generic.List`1& normals, System.Collections.Generic.List`1& uvs, System.Collections.Generic.List`1& colors, System.Collections.Generic.List`1& triangles) (at Assets/SimpleCollada/ColladaImporter.cs:800)
    ColladaImporter.ReadGeometry (System.String url, System.Collections.Hashtable instance_geometry, System.Collections.ArrayList library_geometries, System.Collections.ArrayList library_effects, System.Collections.ArrayList library_materials, System.Collections.ArrayList library_images) (at Assets/SimpleCollada/ColladaImporter.cs:314)
    ColladaImporter.AppendGameObjectsFromNodes (UnityEngine.GameObject parentGo, System.Collections.ArrayList nodes, System.Collections.ArrayList library_effects, System.Collections.ArrayList library_materials, System.Collections.ArrayList library_images, System.Collections.ArrayList library_geometries, System.Collections.ArrayList library_nodes, Boolean includeEmptyNodes, System.String colliderName) (at Assets/SimpleCollada/ColladaImporter.cs:150)
    ColladaImporter.Import (System.String colladaString, Quaternion rotate, Vector3 scale, Vector3 translate, Boolean includeEmptyNodes, System.String colliderName) (at Assets/SimpleCollada/ColladaImporter.cs:91)
    ColladaImporter.Import (System.String colladaString, Boolean includeEmptyNodes, System.String colliderName) (at Assets/SimpleCollada/ColladaImporter.cs:26)
    KilVrApp.GotFile (Status status, System.String path) (at Assets/_scripts/KilVrApp.cs:36)
    FileSelector.DrawFileSelector (Int32 ID) (at Assets/FileSelector/FileSelector.cs:389)
    UnityEngine.GUI.CallWindowDelegate (UnityEngine.WindowFunction func, Int32 id, UnityEngine.GUISkin _skin, Int32 forceRect, Single width, Single height, UnityEngine.GUIStyle style) (at C:/buildslave/unity/build/Runtime/IMGUI/Managed/GUI.cs:1896)
    <<<

    I made a small fix to my local copy of ColladaImporter.cs by changing line 701 from:
    int offsetCount = 1;
    to:
    int offsetCount = 0;
    Now my files import as I would expect, but I'm unsure if I am creating any problems later on down the line.

    AFAIK my fix is a bad hack, and I don't know where the real problem lies (error in STL file, error in AssImp, or if the error was in SimpleCollada). Any feedback.?
     
  40. jhybe

    jhybe

    Joined:
    Feb 3, 2013
    Posts:
    13
    Hi there,
    Just bought the plugin, works fine with a simple cube, but with a more complex model I got the same error as st_lupo (ArgumentOutOfRangeException: Argument is out of range.)

    Tried to change int offsetCount = 1; to int offsetCount = 0;, now show my model but not correctly (some faces are backwards)
     
  41. Nyro

    Nyro

    Joined:
    Aug 23, 2013
    Posts:
    21
    Hi, i'm having some problems with the position and scale of some objects on the model. I'm exporting directly from SketchUp and if I try to Import the model on Maya, everything works fine.
     
  42. aidangig56

    aidangig56

    Joined:
    Aug 10, 2012
    Posts:
    105
    Your Package doesn't import textures properly...
     
  43. gandalfo857

    gandalfo857

    Joined:
    Nov 14, 2017
    Posts:
    1
    import error duck.jpg Hi there, I recently bought your asset to Import collada files. Tried to experiment with a simple duck which is often used to test Imports / Exports. Whereas the direct Import into unity Shows the correct textures, the Colors are completely wrong when importing the same object at runtime with your script. Is there a way to send the .dae file to you to see what is going wrong? The attached Picture shows the static unity import and the import result of the script in the foreground. Thanks for replying!

    March 2018: I'd like to renew my question. Is anybody out there? Thnx!
     
    Last edited: Mar 24, 2018
  44. enne30

    enne30

    Joined:
    Feb 1, 2017
    Posts:
    4
    Hi, I would be interested in buying this plug-in to import at runtime DAE models, so I would like to know if it is currently actively mainteined from the owner (bug fixes, etc..) or it is a discontinued project.

    Thank you very much.
     
  45. PierrotOrkeis

    PierrotOrkeis

    Joined:
    Apr 1, 2019
    Posts:
    2
    Hi, I just bought your asset, but when I want to import my DAE file, it says that's no vertices where found. Whereas, my DAE file works correctly when set directly throw unity editor
     
  46. vrod2000

    vrod2000

    Joined:
    May 28, 2020
    Posts:
    17
    I recently purchased this off the Asset Store. The example online mushroom comes through. My file does not. (In editor it imports fine.)
    I have sent in an email for help. No reply so far. Will submit a refund request if it does not work as intended for my files.
     
  47. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    This (a need to import/export DAE files) is something that circumstances are requiring me to look into as well.

    I'm considering trying to make use of this code, which implements almost the complete DAE spec, and supports export as well as import. It's pure C# code (and from 2010 to boot) so it ought to work. But I haven't tried it yet.

    If anybody else has tried this, or has another solution to suggest (I need to support skinned meshes and blend shapes), or just wants to keep informed of my efforts, please contact me.
     
  48. unity_K_nDtRZtMCIVjg

    unity_K_nDtRZtMCIVjg

    Joined:
    Feb 4, 2021
    Posts:
    8
    Hi. Could you share a Simple Collada package somewhere since it is not available on the asset store anymore? There are no solutions for Unity to support loading Collada files currently. The latest TriLib is not supporting it. So it might be really helpful. Thanks.
     
  49. baruch1723

    baruch1723

    Joined:
    Jun 12, 2019
    Posts:
    1
    Hi. also would like to know if you Could you share a Simple Collada package. There are no solutions for Unity to support loading Collada files. seems like yours is really our only hope