- Home /
Load .fbx from remote http server at runtime to use it as animation clip at runtime
I would like to implement a WebGL application where animationclips will be downloaded from an http remote server and loaded to a 3D model's AnimatorController at runtime. For example, the following code shows that the user can type a url to the input field and when they press the "Submit" button, the system should go connect and login to the server, and then download the fbx which will be used as animationClip for the 3dmodel:
using System;
using System.Collections;
using UnityEngine.UI;
using UnityEngine;
using UnityEditor.Animations;
using System.Net;
public class DownloadAsset : MonoBehaviour{
public InputField nameField;
string url; //the url that contains the path of my animation clip (fbx) to be donwloaded or streamed
public AnimatorController AnimationController; //the animatorController of my 3d model
public AnimationClip AnimationClip;
public void OnSubmit(){
url = nameField.text;
WebClient myClient = new WebClient();
myClient.Credentials = new NetworkCredential( username, password );
myClient.DownloadFile ( url, "C:/Users/myusername/Desktop" );
//Somehow I load my donwloaded or streamed asset to a variable of type AnimationClip and load it to the AnimatorController of my 3dmodel
Motion motion = (Motion)animationClip as Motion;
animationController.AddMotion(motion);
}
}
How can I save the downloaded fbx to a buffer and then load it to unity?
In this code I am using using UnityEditor.Animations which means that I will have problems when building the app.How should I alternatively use functions for animations to add an animationclip to a animatorcontroller at runtime?
Please note that I will build it as WebGL app and everything has to be done at runtime.
Thank you for your patience!
I need an answer to this question as well. If you or anybody knows, please point at the right direction. Thanks.
You need TriLib - Unity model loader package to load animated FBX files at runtime. I'm not sure if it will work with the Animator component, maybe you need to look into using a RuntimeAnimationController. The Animation component works by default, though.
Note that "TriLib" does not explicitly mention WebGL support:
$$anonymous$$ulti-platform: Windows Store, Windows, Linux, OSX, Android and iOS.
It may work but i would contact the creator before buying. Also note that most of this asset consists of open source code. So it's mainly a bit of necessary boilerplate around assimp and to convert the mesh, animation, ... data into Unity's $$anonymous$$esh, animationClip, ... classes.
Note that the native assimp library is rather huge since it supports many different file formats. If you just need FBX support there may be some simpler dedicated pure managed solutions. I haven't tested any of those. This one isn't Unity specific, so it just aids with the pure loading and decoding of the FBX data. The actual $$anonymous$$esh or AnimationClip creation is up to you. You have to decide if you think you are capable of implementing it yourself. If in doubt TriLib may be the better choice (if it actually works for WebGL) if you really need FBS support.
Depending on your restrictions / requirements you may want to use a different format (maybe a propritary format or Unity's asset bundles).
As for TriLib is concerned, this document explicitly states that there is no WebGL Support. https://ricardoreis.net/?p=127
Hi @sdi1000134
same problem here. do you solved your this problem?
I'm trying as well. $$anonymous$$aybe trying to figure it in a different way with Easy Save would make it happen. But please update if you have and so will I.
The way I am doing it now is to parse the fbx out of the unit webgl container. So, i am using three.js to load and parse the fbx file from internet and deliver this data as json (or as by$$anonymous$$rray for better performance) Then, you can re-assembly this data as a mesh in unity.
Your answer
Follow this Question
Related Questions
How to load a large number of fbx files in runtime(files from Navisworks) 0 Answers
FBX Animation Clip Root Transform Rotation ignored in WebGL v2017.1 0 Answers
How to Load external files (.fbx) at runtime? 3 Answers
Problem with adding new Animations to existing FBX 1 Answer
Manually Animating Bones then blending with existing animations or saving importing as fbx 3 Answers