For my own project I will allow end users to upload their own 3D models. For this I needed a simple importer for OBJ files (Also for DAE but that is a different asset store package).
OBJ is an open file format for 3D models, introduced by Wavefront. It is supported by most 3D modeling tools.
SimpleLOD imports vertices, normals, 1 uv map and triangles. (polygons are
automatically converted to triangles). It supports multiple meshes and sub meshes.
This is a runtime importer and there is no Editor interface, since the Unity Editor already imports OBJ files by default.
To import a model at runtime, you simply
download an OBJ file into a string,
pass the string to the import function
and receive a GameObject in return.
Like so:
myGameObject = ObjImporter.Import(objString);
All source code is included and written in C#. There are no DLL’s or hidden stuff.
The web player demo can be found here
The documentation can be found here
The asset store package can be found here
Sounds great, I’ll definitely be picking this up next year to add support for user models in the Adventurezator (Adventurezator: When Pigs Fly on Steam)
For the demo enclosed in the package: Yes, your url would then become:
file:///mylocalpath/mylocalfile.obj (note the 3 slashes after file: )
But this will not work with the webdemo, since the Unity Webplayer has of course no access to local files. If you cant upload it to some server somewhere, you can also email it to me: info (at) orbcreation (dot) com And I will upload it for you or send you the screenshots of the results.
Hello! I’m working on a project in which I need to import very large, detailed models during runtime. I was wondering if there is any upper limit on file size or polygon count in this importer? The same question goes for your DAE importer, I have not yet decided on what file format to use in my project. Thanks in advance!
I would use OBJ if you don’t need any special Collada features that are not available in OBJ.
Collada has so much overhead. It has bigger files and it also takes longer to import them.
Unity has a limit of 64K vertices for all models. This also applies to the SimpleOBJ and SimpleCollada packages. But I could make a new version, that would automatically split large meshes in chunks of 64K and create child gameobjects for them.
The end resut may have slightly more vertices than the original, because when mesh part A and mesh part B have triangles that use the same vertices, those vertices will have to be copied.
If you’d combine this with SimpleLOD, you could simplify those meshes at runtime.
I see, that 64k limit is hardcoded in Unity. Actually, a version of your importer that automatically splits large meshes into child gameobjects would be really awesome, it would solve my problem. I would definitely purchase such a version!
@Fargrey , I never tested that, but don’t see why it shouldn’t. I dont have any android devices here to test it on, else I would have done so for you. But just in case you do have problems I’ll borrow someone’s phone and we’ll find a way to solve them.
Version 1.1 is now available in the assetstore
It has some major improvements:
Import can now run in a background thread (example provided)
Meshes with more than 64K vertices (Unity limit) can be imported. The mesh is automatically split into 2 or more parts.
Material .MTL specifications can be imported along with the .OBJ file (only basic material properties like color, transparency and specularity)
Textures can be automatically applied
Examples have been added of how to download the .OBJ file and automatically download the .MLT file and textures.
The online demo has been updated as well.
I’ve put a new demo online that allows you to drag & drop your own OBJ model directly into Unity at runtime and see how SimpleOBJ imports it.
The drag and drop part is handled by my other Asset Store package 'Drop on Unity". http://orbcreation.com/SimpleObjDrop/Demo.html
Version 1.2 is now available in the assetstore
It has better support for large meshes with more than Unity’s limit of 64K vertices.
The original structure is better preserved and you can optionally add a gameObject for each group that is defined in the OBJ file
By testing the drag & drop demo:
Drag the obj file only works fine.But testing the obj ( 2.9MB ) + mat + textures ( tga-files ) - an message pops up that says:
An exception has occured, but exception handling has been disabled in this build. If you are the developer of this content, enable exceptions in your project’s WebGL player settings to be able to catch the exception or see the stack trace.
I’m whether the developer of this scene or a premium coder just doing simple codings…what’s this message about?
And will it support bump-maps in the near future ?
The error is due to the current limitations of games published on WebGL (or at least it was when this demo was build with the beta version of Unity5) it entails that when you upload data to the WebGL game, at some point it runs out of memory. I test for the max size per file, but the demo does not test the size of all files together.
The bumpmaps are not implemented in the demo. It shouldn’t be hard to do this yourself, since importing textures and assigning them to materials is not something that is OBJ format specific. When you want you can mail me your model + material and texture + bumpmap files and I will test for you how it imports. info (at) orbcreation (dot) com
Very cool asset, exactly what we need.
We have object with over 60 mio vertices (molecule), so I have a few questions:
Would Simple Obj support such a big amount?
How long do you think it will need to process it?
Can it create object instances? e.g our model is composed of spheres and cylinders → instead of creating millions of spheres, just create one + coordinates
Uhm, to be honest, I never tried to import 60 million vertices before. So I have no idea how long this would take.
It should work though. Provided you have enough memory.
If I were you I’d import the positions and rotations with SimpleJson and write a small script to create the spheres and cylinders at runtime. But if all you have is the big OBJ file that holds both positions/rotations and the vertices/triangles, you could edit the script to ignore the vertices and triangles and just instantiate default spheres and cylinders at the transform locations.
Hi - I want to be able to watch the demo video before I buy it but my unity web player is stuffing up and no matter how many times I reinstall it or try to fix it, it just won’t play nice! Any chance you could put the vid up on youtube or something? Cheers
I have been working some time with this library on Windows and all worked fine. But now I need to develop an application for Linux Standalone and I have found that it doesn’t work as it should do. For example objects have wrong scale values, wrong vertex positions and other errors that I couldn’t fix.
Also I have checked the file encoding to match with the reader encoding but still not working.