How can I load FBX file in Unity runtime?
Asked Answered
W

4

7

I am on a hololens project. My boss says, load the fbx file at runtime (we use unity). Our fbx file changes at runtime, so we must reload it (fbx is change from 3dMAx).

I tried the AssetBundle, but I can't create Assetbundle files without unity or unity editor mode. As far as I know, only resource (in Project tab) can insert assets to assetbundle. If I can build Assetbundle file by fbx file without unity project, I can do all.

To sum it up: I need way how to load fbx in runtime without unity resource. If I make fbx asset to assetbundle in runtime (fbx is not belong in project tab), it's ok.


edit)

Using trilib asset is the best way. I try make own FBX loader, it's too difficult and a big job. I think trilib is not perfect, but it is the best.

Westbrook answered 6/8, 2018 at 6:0 Comment(2)
How to import assets to Unity3d Build on runtime.Sanmicheli
you can use assimp.org but it had some problem a while ago and I have not used it lately #43843048Agar
M
4

You can read follow content:

is-there-an-easy-way-to-import-fbx-files-runtime:

In short: No.

Unity doesn't support importing / loading of any model format at runtime. The only exception are AssetBundles. Your options are basically:

  • Use AssetBundles

  • Find an importer for your desired format for Unity

  • Write such an importer yourself

  • Look for a feature request / write one yourself to ask UT if they add runtime model loading routines.

how-to-convert-3ds-fbx-model-into-asset-bundle-at-run-time:

Is there a tool which converts 3D models to asset bundles ? or is it possible to convert them at run time ?

You can't during the run-time because every Unity API to create Assetbundle is only available on the Editor for Editor plugins only.

I search many website for this question. Finally, I recommand that you could use this asset.It's is not free,but worth.It could save much time for you.

trilib-unity-model-loader

I hope this can help you.

Moral answered 6/8, 2018 at 6:21 Comment(0)
O
7

You could consider converting FBX into glTF, which Unity can load at runtime with UnityGLTF tools.

https://github.com/KhronosGroup/UnityGLTF

Overuse answered 14/5, 2019 at 12:27 Comment(1)
this is the best solution ever, you can simply convert fbx to gltf with a node.js C++ extension on the server side github.com/cyrillef/FBX-glTFColure
M
4

You can read follow content:

is-there-an-easy-way-to-import-fbx-files-runtime:

In short: No.

Unity doesn't support importing / loading of any model format at runtime. The only exception are AssetBundles. Your options are basically:

  • Use AssetBundles

  • Find an importer for your desired format for Unity

  • Write such an importer yourself

  • Look for a feature request / write one yourself to ask UT if they add runtime model loading routines.

how-to-convert-3ds-fbx-model-into-asset-bundle-at-run-time:

Is there a tool which converts 3D models to asset bundles ? or is it possible to convert them at run time ?

You can't during the run-time because every Unity API to create Assetbundle is only available on the Editor for Editor plugins only.

I search many website for this question. Finally, I recommand that you could use this asset.It's is not free,but worth.It could save much time for you.

trilib-unity-model-loader

I hope this can help you.

Moral answered 6/8, 2018 at 6:21 Comment(0)
S
4

Unity can not load the fbx file directly, but can load the obj file at runtime, you can convert fbx file to obj files.

  1. Convert fbx to obj files with command line script.
  2. Load obj at Unity runtime.

One way to convert fbx/dae to obj is using Blender command line, so you should installed Blender (support platform: Linux, Mac, Windows). Create this python file:

import bpy
import sys
for obj in bpy.data.objects:
    if (obj.name == "Lamp") | (obj.name == "Camera") | (obj.name == "Cube"):
        obj.select = False
    else:
        obj.select = True
argv = sys.argv
argv = argv[argv.index("--") + 1:]
inputpath = argv[0]
outputpath = argv[1]
bpy.ops.import_scene.fbx(filepath=inputpath, axis_forward='-Z', axis_up='Y', directory="", filter_glob="*.fbx", ui_tab='MAIN', use_manual_orientation=False, global_scale=1, bake_space_transform=False, use_custom_normals=True, use_image_search=True, use_alpha_decals=False, decal_offset=0, use_anim=True, anim_offset=1, use_custom_props=True, use_custom_props_enum_as_string=True, ignore_leaf_bones=False, force_connect_children=False, automatic_bone_orientation=False, primary_bone_axis='Y', secondary_bone_axis='X', use_prepost_rot=True)
bpy.ops.export_scene.obj(filepath=outputpath, check_existing=False, axis_forward='-Z', axis_up='Y', filter_glob="*.obj;*.mtl", use_selection=True, use_animation=False, use_mesh_modifiers=True, use_mesh_modifiers_render=False, use_edges=True, use_smooth_groups=False, use_smooth_groups_bitflags=False, use_normals=True, use_uvs=True, use_materials=True, use_triangles=False, use_nurbs=False, use_vertex_groups=False, use_blen_objects=True, group_by_object=False, group_by_material=False, keep_vertex_order=False, global_scale=1, path_mode='COPY')
print("finished!")

Run this file in shell:

/your blender path/blender --background --python /your python path/convert.py -- /your input path/xxx.fbx /your output path/xxx.obj

Finally, use this plugin to load obj files at run time: https://assetstore.unity.com/packages/tools/modeling/runtime-obj-importer-49547

More about blender command line to import and export files: https://blender.stackexchange.com/questions/16563/how-can-i-run-blender-from-the-command-line-to-export-and-import-models

Selfdrive answered 22/8, 2019 at 3:8 Comment(0)
T
0

You could try using Trilib. A plugin available in the Unity Asset store, i have personally used it on a project and absolutely love it.

It supports various file formats (OBJ,FBX,PLY,GLTF) and also imports everything from geometry, materials, textures, animations and even blendshapes.

Compatible with Android, iOS, WebGL and Desktop Platform.

Heres the link to make it easier :- https://assetstore.unity.com/packages/tools/modeling/trilib-2-model-loading-package-157548

Tuyere answered 1/12, 2021 at 2:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.