/// <summary> /// this function actually moves models on their associated targe using 'MoveModelOnTarget' function. /// </summary> public void UpdateModelStatus() { foreach (GameObject model in modelList) { NCARModelInfo modelInfo = model.GetComponent <NCARModelInfo>(); //if the model is combined to any other targets then its default target if (modelInfo.isModelCombined == true) { //and if the target has been changed if (modelInfo.previousTarget != modelInfo.currentTarget) { //need this to exclude context model. if (modelInfo.GetComponent <NCARTouchController>() != null) { modelInfo.GetComponent <NCARTouchController>().ResetAnimation(); } MoveModelOnTarget(modelInfo, modelInfo.currentTarget); } } //if model is not combined to any other target else if (modelInfo.isModelCombined == false) { //and if the model does have the default target && target has been changed. if (modelInfo.defaultTarget != null && modelInfo.defaultTarget != modelInfo.currentTarget) { //Move the model on its default taret MoveModelOnTarget(modelInfo, model.GetComponent <NCARModelInfo>().defaultTarget); } // and if the model does not have the default target associated && target has been changed. if (modelInfo.defaultTarget == null && modelInfo.defaultTarget != modelInfo.currentTarget) { model.transform.SetParent(goModelList.transform); modelInfo.resetPosToDefault(); } // set the target to its default modelInfo.currentTarget = modelInfo.defaultTarget; } if (modelInfo.currentTarget != null && modelInfo.currentTarget.GetComponent <NCARTrackableEventHandler>().IsTracked != true) { modelInfo.HideModel(); } //set the preious target to the current one. modelInfo.previousTarget = modelInfo.currentTarget; //reset the combination target to false; model.GetComponent <NCARModelInfo>().isModelCombined = false; } }
//based on the function above, this function moves the model onto the target setting it as the model's parent public void MoveModelOnTarget(NCARModelInfo modelInfo, global::NCARTargetInfo targetInfo) { Transform modelTransfrom = modelInfo.transform; Vector3 initLocal = CalcInitialLocalPosOfModelToTarget(modelInfo, targetInfo); modelTransfrom.position = targetInfo.transform.TransformPoint(initLocal); modelTransfrom.rotation = (modelInfo.rotInit * targetInfo.transform.rotation) * Quaternion.Inverse(targetInfo.rotTargetInit); modelTransfrom.SetParent(targetInfo.transform); if (modelInfo.GetComponent <NCARTouchController>() != null) { modelInfo.GetComponent <NCARTouchController>().setInitialLocalPosition(); } modelInfo.currentTarget = targetInfo; //show model in case it was hidden; modelInfo.ShowModel(); }