- Home /
OBJ runtime import
Hello! I am looking to import an obj file at runtime so my game users can make their own maps.
I am not looking to spend a cent on this, I have found one on the wiki (http://wiki.unity3d.com/index.php?title=ObjImporter)
So if someone would be able to show me how to use this script from javascript, it would be greatly appreciated
I have tried already using SendMessage but to no avail. I simply do not know where to start to achieve this.
Thanks!
EDIT: The code I have tried is this: var existing : GameObject;
function Start () {
var newGO : Mesh;
var sc = gameObject.GetComponent("ObjImporter");
existing.GetComponent(MeshFilter).mesh = sc.SendMessage("ImportFile", "test.obj");
}
where existing is the gameobject i want to change the mesh, but it gives me a cannot convert void to unityengine.mesh.
Answer by whydoidoit · Feb 22, 2014 at 02:01 PM
So firstly you need to put that ObjImporter code in the Plugins folder for the project.
Next:
var objImporter = new ObjImporter();
existing.GetComponent(MeshFilter).mesh = objImporter.ImportFile("SomeFile");
Thanks for the reply! I seem to be getting pink models, in the project view they appear textured and if i drag them on to the scene they are textured, but with the importer they are pink, would you $$anonymous$$d giving it a shot at trying to import them? Do you reckon Im doing something wrong or the importer just doesnt support textures.
Obj format doesn't support texturing. You would have to handle the materials yourself.
Your answer
