- Home /
why camera is freezing while loading the 3D model
I'm doing Augmented Reality image recognition project (vuforia) and loading the .obj model from server when the image is recognized. The problem is, when my target found the loading text will start to display the percentage of load and if it comes at 99% and the camera is freezing to load the model. I'm not sure why the camera is freezing. How can we load model without freeze the camera?
var objData = ObjReader.use.ConvertFileAsync (modelString, true, standardMaterial);
while (!objData.isDone) {
Debug.Log (" objData is not there");
loadingText.text = "Loading... " + (objData.progress*100).ToString("f0") + "%";
yield return loadingText.text;
}
//myHealth.Progress (100); // done
loadingText.enabled = false;
string modelName = objData.gameObjects [0].name;
model = GameObject.Find (modelName); // find the model reference
model.name = targetIDModel; // change the model name to targetID !!!
}
GameObject modelClone = Instantiate( model ) as GameObject; //clone the model
modelClone.transform.localPosition = Vector3.zero; // bring the clone to origin
modelClone.transform.parent = itbModel.gameObject.transform; // pair the clone to the instantiated image target
modelClone.transform.localScale = Vector3.one;
Answer by CHPedersen · Jan 27, 2015 at 08:06 AM
It freezes during load because Instantiate is sequential and takes place on the main thread. So, if the object is really big, it will take considerable time to load it and create a mesh for it, etc. Unity cannot render any frames while it does that work, too, so the camera freezes in the meantime.
The solution is to split the mesh up into a number of smaller meshes and load them one by one across several frames, such that frames are still rendered in between, user input still processed, etc.
You can still use Mesh.CombineMeshes to combine the loaded objects into one big mesh afterwards, if you really need them to be (though chances are you don't).
The model size is 3 or 4 or 5$$anonymous$$B only and the model is loading from server url. I'm using obj reader plugin to load the model from server.
You might want to download the model to client first then load it in memory.
Your answer
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
How to Switch/Change Front and back Vuforia AR Camera using a button? 0 Answers
Unity3d Vuforia Ground Plane Using UNET 2 Answers
Multiple Cars not working 1 Answer
Moving an object with Slider UI in vuforia Ground Plane (AR project using Unity 2018.2.8f1) 0 Answers