- Home /
Convert fbx model to gameobjet
For my game I am fetching 3d objects from online server. So I receive fbx object as imported file. So at runtime I want to use this file in game. I need some suggestion to convert this fbx object model into unity gameobject.
Means I need some code to convert this file so that I can use it in actual game. Please give some suggestion in this. If you have any other way then mention that also.
Please friends I need your help in this. Following discussion give you more details about question
Answer by fafase · Mar 23, 2015 at 05:12 AM
You would be better of storing the model as obj. Fbx has the animation but there is no runtime parser for fbx that I know of.
With obj, you would grab the text file from server, parse it using http://wiki.unity3d.com/index.php?title=ObjImporter
Then you need to add a mesh filter, a renderer, connect those together, add the newly created mesh from the parser to the mesh filter, add a material, parse the material info and fetch the matching shader and apply to material.
All in all, you simply parse the file to get the info, create the item via AddComponent and aply the data. That may sound complex, it is actually simple.
WWW www new WWW(url);
yield return www;
string text = www.text
ObjImporter importer = new ObjImporter();
Mesh mesh = importer.ImportFile(text);
GameObject obj = (GameObject)Instantiate(prefab); // Prefab already contains all components
obj.GetComponent.<MeshFilter>().mesh = mesh;
@fafase, Thanks for your suggestion. Wether designer give me this text file as object file? Or I have to process some other task for getting this text file.
You would get it from the guy making the models. It is a setting in the export process for $$anonymous$$aya or 3Dmax. Then you are given an obj file, which is a just a text file with specific pattern to be parsed by obj parser.
@fafase, Thanks for your reply. I got your reply what you are trying to say. I move ahead in same way. If in future I stuck then I post comment at here so please reply next time also.
Your answer
Follow this Question
Related Questions
Syntax for a game object component variable on a transform in an FBX hierarchy? 1 Answer
Scale and Rotation Issue with Model Import 3DS Max to Unity 3 Answers
Transform.gameObject References Itself?! 0 Answers
Warning(s) found while importing this animation file. 0 Answers
How to store player model and then swap the model to an object I Raycast hit? 0 Answers