google-ar / arcore-unity-sdk

ARCore SDK for Unity
https://developers.google.com/ar
Other
1.4k stars 402 forks source link

How to disable ground plane surface detection and add 3D object infront of camera #144

Closed rramprasad closed 6 years ago

rramprasad commented 6 years ago

How to disable ground plane surface detection and add 3D object infront of camera as soon as camera launches.

pablisho commented 6 years ago

Hi, to disable plane detection you have to modify the configuration that ARCoreSession script has on it. HelloAR has a DefaultSessionConfiguration with plane detection enabled, you can create your own configuration and set it to ARCoreSession. To place an object, you can create an anchor with Session.CreateAnchor(pose) with the pose where you want your anchor to be. Then you can use that anchor with your game object.

ReiiYuki commented 6 years ago

I think this might help you to disable plane surface tracking.

https://github.com/google-ar/arcore-unity-sdk/issues/126

rramprasad commented 6 years ago

Hi I can't understand this line,

To place an object, you can create an anchor with Session.CreateAnchor(pose) with the pose where you want your anchor to be. Then you can use that anchor with your game object.

How to create Pose without hit,because I dont need to click to show object.It should display as soon as camera launches.

chaosemer commented 6 years ago

Pose is just a mathematical concept. You can take the position and rotation of any arbitrary object and create a pose with it.

rramprasad commented 6 years ago

HelloARController.cs I have placed object infront of camera as soon as launched with following code.But the 3D object is slowly moving (or floating on Air) and it is not stay on same point.How to resolve this issue?

rendered3DObject = render3DObject();
 float distance = 1;
rendered3DObject.transform.position = FirstPersonCamera.transform.position + FirstPersonCamera.transform.forward * distance;

if (mAnchor == null) {
                Pose pose1 = Pose.identity;
                pose1.position = Frame.PointCloud.GetPoint(0);
                mAnchor = Session.CreateAnchor(pose1);
}
rendered3DObject.transform.parent = mAnchor.transform;
private GameObject render3DObject()
        {
            GameObject object3D = Resources.Load("Icon " + mType) as GameObject;
            GameObject objectInstance = Instantiate(object3D) as GameObject;
            Renderer renderer = objectInstance.GetComponent<Renderer>();
            renderer.enabled = true;
            renderer.material.mainTexture = Resources.Load(mType + "_texture") as Texture;

            //Debug.Log("X -> 3D object rendered");

            Mesh meshToCollide = objectInstance.gameObject.GetComponent<MeshFilter>().mesh;
            if (!meshToCollide)
            {
                //Debug.Log("Mesh not assigned to collide...");
                //return;
            }
            else
            {
                objectInstance.transform.gameObject.AddComponent<MeshCollider>();
                objectInstance.transform.GetComponent<MeshCollider>().sharedMesh = null;
                objectInstance.transform.GetComponent<MeshCollider>().sharedMesh = meshToCollide;
                objectInstance.transform.GetComponent<MeshCollider>().name = mType;
            }

            return objectInstance;
        }
chaosemer commented 6 years ago

Your code looks correct, can you share a video of what you see happening? It is likely the object gets created behind a wall (though it appears on top of it). This will manifest as the object appearing to move as you move.

rramprasad commented 6 years ago

@chaosemer I have uploaded video here. The anchor is not same and it is floating on the air. Also If I rotate the mobile randomly and come back to same position,the object disappears and again displays in some other place. Also when camera opens,object stick at center some seconds and anchor on particular place then move around.

Now I checked and getting E/native: status.cc:175 ArStatusErrorSpace::AR_ERROR_NOT_TRACKING: Cannot add anchor, while not tracking error

chaosemer commented 6 years ago

Thanks you so much for the video. It really helps me understand what is going on.

The slight vibration looks expected as when you don't move much, the motion tracking is going to be dominated by noise in the IMU.

However, the anchor disappearing as in the video is unexpected. You stated that the anchor reappears somewhere else. Could you please record a video that shows the anchor reappearing?

rramprasad commented 6 years ago

@chaosemer It reappear because when tracking lost(when rotate device randomly),the icon disappears.To avoid it I make objectAdded = false; Destroy(rendered3DObject);. Now the main issue is the object not stay on same anchor point,it moves around the room.Currently I am using 1.0.0.If i update to 1.1.0,can I get fix for this.Or still this is a open issue.

        public void Update()
        {
            if (Application.platform == RuntimePlatform.Android)
            {
                if (Input.GetKey(KeyCode.Escape))
                {
                    callAndroidActivityMethod("onBackPressed");
                }
                else if ((Input.touchCount > 0)
                                && (Input.GetTouch(0).phase == TouchPhase.Began)
                                && (mType != null)
                                && !mType.Equals(""))
                {
                    Ray ray = FirstPersonCamera.ScreenPointToRay(Input.GetTouch(0).position);
                    RaycastHit hit;

                    if (Physics.Raycast(ray, out hit))
                    {
                        if (hit.collider.name.Equals(mType))
                        {
                            callAndroidActivityMethod("showUI");
                        }
                    }
                }
            }

            _QuitOnConnectionErrors();

            if (Session.Status != SessionStatus.Tracking)
            {
                /*if (!m_IsQuitting && Session.Status.IsValid())
                {
                    showSearchingUI = true;
                    SearchingForPlaneUI.SetActive(true);
                }*/

                objectAdded = false;
                Destroy(rendered3DObject);
            }

            if (objectAdded || string.IsNullOrEmpty(mType))
            {
                Debug.Log("return as object already added");
                if(rendered3DObject != null)
                {
                    rendered3DObject.transform.Rotate(Vector3.up, Time.deltaTime * 60);
                }
                return;
            }

            Screen.sleepTimeout = SleepTimeout.NeverSleep;

            rendered3DObject = render3DObject();

            float distance = 1;

            rendered3DObject.transform.position = FirstPersonCamera.transform.position + FirstPersonCamera.transform.forward * distance;

            /*if (initialPosition == null)
            {
                initialPosition = rendered3DObject.transform.position;
            }*/

            // Create an anchor to allow ARCore to track the hitpoint as understanding of the physical
            // world evolves.
            //if (mAnchor == null && Session.Status == SessionStatus.Tracking)
            if (mAnchor == null)
            {
                Debug.Log("creating Anchor at PointCloud");

                Pose pose1 = Pose.identity;
                pose1.position = Frame.PointCloud.GetPoint(0);
                //pose1.position = rendered3DObject.transform.position;
                //pose1.position = new Vector3(0, 0, -1f);
                //pose1.position = initialPosition;

                //mAnchor = Session.CreateAnchor(pose1);
                mAnchor = Session.CreateAnchor(pose1);

                rendered3DObject.transform.parent = mAnchor.transform;
                Debug.Log("Anchor created");
            }

            objectAdded = true;

            callAndroidActivityMethod("on3DObjectLoaded");
        }
chaosemer commented 6 years ago

I've shared the video you provided me with the motion tracking team.

Given your environment, this is expected, though not ideal. When tracking gets lost (such as when you cover the phone up briefly) ARCore looks for similar looking environments to figure out how to recover its position. In this case, the office environment has a lot of repeating patterns, making ARCore get confused about which cubical is the one it was in before. We will be constantly improving the quality of relocalization with future versions of ARCore.

However, this behavior is expected given your environment. ARCore does not work well in environments that have very similar repeating patterns.

rramprasad commented 6 years ago

Hi @chaosemer Thank you. I have posted another query with more videos on #175. I updated ARCore version 1.1.0 and tried ARCore Codelab. Is that issue also because of similar repeating patterns,because it occurs before tracking lost(before cover phone).Please have look on #175 and provide your comments.

kiraka42 commented 6 years ago

There is no equivalent of Mesh with ARcore sdk for android. ?

kiraka42 commented 6 years ago

I have found no equivalence of Mesh meshToCollide = objectInstance.gameObject.GetComponent().mesh; with arcore java android sdk

akash0208 commented 6 years ago

did you make this with unity?

kiraka42 commented 6 years ago

no just with arcore only

kiraka42 commented 6 years ago

I think we just have to connect a framework with ARCORE but what kind of framework . ?