FBX Import At Runtime - unity3d

I did many tests to import FBX at runtime in unity and I'm testing more. The FBX file has to be in ASCII format when imported. It needs to export to ASCII from 3dsMax or Maya. ASCII FBX file has bigger size depending on the file.
On the other hand, the binary FBX format has a smaller size compared to ASCII.
My script works with ASCII FBX (for most models). It uses a parse method to read all the plain text, including vertices, triangles and normals in a FBX file and constructs the mesh in GameObjects.
The problem is size of model and speed of import. Asset Bundles is not a good solution.
If anyone knows a method to import BINARY FBX at RUNTIME please share your knowledge. Also, if you know how to deserialize binary fbx to ASCII FBX in Unity at runtime please let me know.
I need to deserialize FBX from Binary to ASCII. Because this is a reduced version.

If I understood correctly your problem is that the game stuck while you are importing the FBX.
Have you tried to use a Coroutines?
Coroutine will execute parallel to your update function so it won't get stuck in the middle of the execution.
If you only have 1 FBX it won't be faster unless you divide the work into multiple coroutines (be careful with the performance).

Related

How to save modified mesh at runtime?

In my game, I modify mesh at runtime using a damage algorithm.
After that, I would like to save them.
I get all meshes with:
MeshFilter[] meshfilters = MyObject.GetComponentsInChildren<MeshFilter>();
then i modify single mesh.
How to save that in my original FBX file ?
Thanks
Unity's internal mesh type is not the same as an FBX, FBX is a file storage format, while Unity uses a different internal structure at runtime, for greater efficiency.
As far as I know there is no standard way to save out a runtime mesh as an FBX (this is a feature of 3D modelling software, not a game engine)
You can save your deformations somehow and re-apply them when you reload the model, when I did a similar thing (custom generated terrain meshes at runtime) I would generate a mesh at runtime, then save the data required to generate that mesh, then pass it into the same flow I used to generate the mesh in the first place.
It is possible to serialise meshdata in the unity editor as meshdata is actually a different format from FBX (Unity reads an FBX, then generates a mesh asset from the FBX's data, then associates that mesh with the FBX) You do this by playing with AssetDatabase.CreateAsset() https://docs.unity3d.com/ScriptReference/AssetDatabase.CreateAsset.html
But I don't think this is what you're intending to do.
If you want the full FBX suite of features (skinning, animation, use in other unity projects) and you want them at runtime, you don't really have any options that I know of. Short of implementing your own FBX serialisation library (not really a reasonable solution)

Import 3D model to Xcode with its nodes

I have 3D Models which have many parts and are designed by some 3D editors such as: AutoCad, Blender...
Those 3D Models are combined many parts, so I want to import them to Xcode with same parts, then add Node to each part.
I want to interact with each part in ScenceView.
3D model from:
https://drive.google.com/file/d/11MccUtXd61wDWQldMTleotvg_yoHnzWP/view?usp=sharing
As i can see on the link provided by you, the 3D model is available in FBX and OBJ formate. for using in Xcode you can try using following steps.
Convert your model into DAE or .SCN formate. (you can use Blender) .DAE and .SCN formate contains all the nodes in a single file.
import your Model with associate texture folder in the art.scnassets folder.
Load and use your model.

Quick and efficient way to transfer from an flt object with rgb/rgba textures to fbx with jpg/png textures

I have several really big object files in the flt format. These objects have all of their textures in rgb and rgba files. I used 3DS Max to convert from flt to fbx, but all the textures are still in rgb/rgba format. Unity doesn't seem to accept these image files. For one of them, I converted all of the images by using image magik and then in Unity adding each corresponding texture to the correct material. This was a pain and very time consuming. Not only that, it only applied to the one Unity project so if I wanted to pull it into any other project or software, I would have to do it again. That one model had several hundred textures and so do the other ones I have.
Is there a way to convert a FLT object with RGB/RGBA texture files to a FBX object with JPG/PNG texture files easily? I can easily convert all of the rgb files to jpg and the rgba files to png (if that matters). I have 3DS Max and Maya that I can use.
There's not an easy one-off way to do this -- neither FLT nor RGB are common file formats these days.
Probably the best code solution is to convert all of the images in bulk (changing their extensions) and then write an AssetPostprocesor in Unity that matches finds the new .tga or .jpg files corresponding to the materials referenced by the assets and swap them in. That will save the hand work on the Unity end. If this is going to be something you do often it's worth the work.
You could so something fairly similar in Maya: you'd import the fbx file into a blank maya scene, look for the file texture nodes, and replace the rgb/rgba extensions with tga or jpg or whatever. That would looks something like this:
def update_fbx(filname, source = 'rgb', target = 'tga'):
cmds.file(f=True, new=True) # clear the scene
cmds.FBXImport(f=filename) # import the fbx
#assuming you have materials with file nodes pointing at
# rgb extensions, replace with tga
for each_file_node in cmds.ls(type = 'file'):
oldname = cmds.getAttr(each_file_node + ".ftn")
newname = oldname.replace(source, target)
cmds.setAttr(each_file_node + ".ftn", newname)
then re-export the scene as a new FBX, which will have the correct file references.
There are a lot of variables, depending on how the source files are structured, but this is a general idea of how you could tackle it.

To convert 3d model from obj,3ds to .ac file format

I am having a 3d model of a car in .3ds format.I want to convert .3ds/.obj files into .ac format. Is there any tool to do this?
Here's one solution.
Blender (http://www.blender.org/) can open .3DS and .OBJ formats.
File Formats
Blender comes packed with import/export support for many different programs.
3D
3D Studio (3DS), COLLADA (DAE), Filmbox (FBX), Autodesk (DXF),
Wavefront (OBJ), DirectX (x), Lightwave (LWO), Motion Capture (BVH),
SVG, Stanford PLY, STL, VRML, VRML97, X3D.
And this AC3D Exporter plugin for Blender will allow you to export to .AC.
Export selected meshes to AC3D's .ac file format.

XNA 4: import FBX problem

I have a problem with importing 3D model from FBX file.
Source model contains 575 objects + 1 camera and looks like this: http://habreffect.ru/files/23d/542fa7f67/source_model.png
In XNA prepared with content pipeline model contains 82 meshes, and 576 bones.
So, when I draw my model, I see only part of source model. Result picture like following:
http://habreffect.ru/files/28a/6e61c0215/Result_view.png
My drawing code:
GraphicsDevice.Clear(Color.CornflowerBlue);
Matrix[] transforms = new Matrix[_model.Bones.Count];
_model.CopyAbsoluteBoneTransformsTo(transforms);
foreach (var mesh in _model.Meshes)
{
foreach (BasicEffect effect in mesh.Effects)
{
effect.LightingEnabled = true;
effect.EnableDefaultLighting();
effect.World = transforms[mesh.ParentBone.Index] * _world;
effect.View = _view;
effect.Projection = _proj;
}
mesh.Draw();
}
base.Draw(gameTime);
How can I get all 575 meshes in my Model instance in XNA?
Thanks!
UPD: I tried to import my FBX model to 3ds max, select all meshes and use "Export selected". Result FBX file is 11x bigger. Then I add it as content to XNA project, loaded model contains all 575 meshes, and it rendered correctly.
Unfortunately, this manual converting method don't suit me - I need to render varied fbx models from mutable repository.
So, what FBX file are "good" for XNA content processor (I use XNA 4)?
So, on MSDN I found that FbxImporter designed to work with 2006.11 version of FBX format.
Recently Autodesk released FBX Converter 2012.1, which contains other tools, like FBX Eplorer, FBX Viewer.
FBX explorer can show structure of FBX file, and I compare exported from 3D MAX file, and source FBX file. They have different internal format. I tried to make following conversion: FBX -> Collada -> FBX, and the result FBX file contains similar to exported from MAX data structure.
So, I simply add the result FBX to Content of my XNA app, and it's rendered well :)
Another way to make it work is to use Autodesk FBX SDK to manually read model, and draw it in XNA.
Conclusion:
XNA FbxImporter correct work doesn't depend on version (2006, 2011, etc) and form (binary, ascii) of FBX file. Internal FBX data structure much more important.
To make FBX "readable" for XNA Importer you can use double conversion like FBX -> Collada -> FBX
You also can use FBX SDK to manually load data from FBX
Open the 3d model in latest 3dx max 2012 and export it in .fbx format. This .fbx is loaded properly with the xna model loader. While exporting you can even embed the resources, so you dont have to add textures to it through XNA.
You are using instancing in 3DS MAX. This isn't supported directly by XNA.
You have to draw the mesh for each instance bone yourself.
Ideally you would instead use DirectX instancing to draw each mesh once per bone in a single Draw() call.
But you have to roll your own code to do that, by converting the bones into instance vertices.
By default XNA only supports the most basic operations.