I’m downloading 3d model dynamically using Obj Reader and displaying in the scene but sometimes model showing too small and too big. I can’t place in center of the screen for all the model. How to do this?
// duplicate the referenced image target
newImageTarget3d = Instantiate (ImageTargetTemplate3Dload.gameObject) as GameObject;
// enable the new result with the same ImageTargetBehaviour: ???
ImageTracker tracker = TrackerManager.Instance.GetTracker<ImageTracker> ();
ImageTargetBehaviour imageTargetBehaviour = (ImageTargetBehaviour)tracker.TargetFinder.EnableTracking
(targetSearchResult, newImageTarget3d);
StartCoroutine (seperateJsonLoad3D (mTargetMetadata, targetSearchResult.UniqueTargetId , imageTargetBehaviour ));
Obj Reader Library to get the model from server url:
IEnumerator seperateJsonLoad3D ( string jsonURL, string targetID, ImageTargetBehaviour itb ){
WWW www = new WWW (jsonURL);
yield return www;
jsonText = www.text;
Debug.Log("3D Url load is "+ jsonURL);
JSONObject json = JSONObject.Parse(jsonURL);
type=json.GetString("type");
url=json.GetString("link");
modelShowGUIButton=true;
if(type.Equals("3d")){
modal = GameObject.Find (targetID);
if (!modal) { //fetch model from the URL
Debug.Log("3D !modal is "+ url);
loadingText = (GUIText)GameObject.Find ("LoadingText").GetComponent(typeof(GUIText));
// loadingText = GameObject.Find("LoadingText").GetComponent(GUIText);
loadingText.enabled = true;
var objData = ObjReader.use.ConvertFileAsync (url , true);
while (!objData.isDone) {
loadingText.text = "Loading... " + (objData.progress*100).ToString("f0") + "%";
yield return null;
}
loadingText.enabled = false;
string modelName = objData.gameObjects[0].name;
modal = GameObject.Find (modelName); // find the model reference
modal.name = targetID; // change the model name to targetID !!!
// store the original model somewhere safe!!
modal.transform.position = new Vector3 (modal.transform.position.x, 500f, modal.transform.position.z);
}
modalClone = Instantiate( modal ) as GameObject; //clone the model
modalClone.transform.localScale += new Vector3(250,250,250);
/modalClone.AddComponent(MeshCollider);
mesh = modalClone.AddComponent<MeshCollider>();
modalClone.transform.parent = itb.gameObject.transform; // pair the clone to the instantiated image target
modalClone.transform.localPosition = new Vector3(0,0,0);
}
}