Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Issue about Move/Zoom/Rotate

Discussion in 'Scripting' started by vankhoa01, Aug 4, 2016.

  1. vankhoa01

    vankhoa01

    Joined:
    Mar 9, 2016
    Posts:
    6
    Hi,

    I'm being implement Move/Zoom/Rotate with Vuforia SDK.
    I followed article : https://www.ourtechart.com/augmented-reality/tutorial/augmented-reality-touchscreen-events/
    And I have problem when load .fbx GameObject. If .fbx GameObject have multiple child, I can not interact on it.
    I think, if I want to move/rotate/zoom GameObject, I have to add MeshCollider for GameObject.
    So I tried to use code bellow to add MeshCollider. But it don't work.
    Code (CSharp):
    1. GameObject instance = Instantiate (Resources.Load ("cube001") as GameObject);
    2.             // Re-parent the cube as child of the trackable gameObject
    3.             instance.transform.parent = theTrackable.transform;
    4.  
    5.             // Adjust the position and scale
    6.             // so that it fits nicely on the target
    7.             instance.transform.localPosition = new Vector3 (0, 0, 0);
    8. //        instance.transform.localRotation = Quaternion.identity;
    9.             instance.transform.localScale = new Vector3 (0.1f, 0.1f, 0.1f);
    10. //            instance.AddComponent<MeshCollider>();
    11.             MeshFilter[] meshFilters = instance.GetComponentsInChildren<MeshFilter> ();
    12.  
    13.             CombineInstance[] combineCollider = new CombineInstance[meshFilters.Length];
    14.             Debug.Log ("Length of meshFilters === " + meshFilters.Length);
    15.             for (var i = 0; i < meshFilters.Length; i++) {
    16.  
    17.                 if (meshFilters [i].transform == transform) {
    18.                     continue;
    19.                 }
    20.                 combineCollider[i].mesh = meshFilters[i].sharedMesh;
    21.                 combineCollider[i].transform = meshFilters[i].transform.localToWorldMatrix;
    22.                 Debug.Log ("Name of combineCollider === " + combineCollider[i].mesh.name);
    23.             }
    24.             instance.AddComponent<MeshCollider> ();
    25.             MeshCollider meshCollider = instance.AddComponent<MeshCollider>();
    26.             meshCollider.sharedMesh = new Mesh();
    27.             meshCollider.sharedMesh.CombineMeshes(combineCollider);
    28.             // Make sure it is active
    29.             instance.SetActive (true);
    Here's my model : https://drive.google.com/file/d/0B9mkkxI7rfnuandUNkpDUURRNGM/view?usp=sharing

    If you have any idea to resolve, please share for me.
    Thanks a lot