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
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)
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) ?
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.
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.
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:
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 tag, except for the last one. The importer probably also gives you warnings about this in the console.
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 and 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.
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?
Hey @CaptainMurphy_1 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
@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.
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?