AR book page turning effect in Unity

Purpose:

  1. Read and learn Vuforia for Unity development to realize AR effect on mobile platform.

  2. Write a shader for video background in AR, and use it to effectively cover specific parts of book pages in AR books. Complete Experiment 1 in Weeks 3-4, scoring method, realize basic AR effect on your mobile phone, fill in the basic AR function experiment report, put forward the idea of ​​video background shader in AR, and realize effective video background shader in AR.


Implementation steps:

1.  First read the tutorial of Vuforia for Unity.

2.  Registered on vuforia, and then downloaded the vuforia file into unity.

3.  Added ARCamera camera.

4.  We upload a photo to vuforia, and then create a plane in the three-dimensional space of unity and use this picture as the material of this plane. and adjusted the position of the camera.

5.  Then get the AR key and paste it to the location

6. At this time, the interaction between the camera and the screen is completed.

7. Import the model into it, and then you will find that when you point the image to the camera, there will be a model floating on the plane.


8. Create a new scene, create an imageplane, and use the image already identified in the previous experiment.

9. Create two buttons, named next and front in text.

10. Set the ARcamera and button to the appropriate angle.

11. Create a C# script.

Int count is used as the representation of turning pages forward or backward, and lastorder is the current number of pages. Use the page method to get the number of pages to turn to.

    public void paging(int count)

    {

        Bookorder = Mathf.Clamp(Bookorder + count, 0, 11);

    }

To turn the pages, in order to prevent the pages from overlapping, there are slight differences in the angle of turning the pages.

    void Update()

    {

        Hashtable args = new Hashtable();

        args.Add("x", 0);

        args.Add("y", 0);

        args.Add("delay", 0f);

        args.Add("easeType", iTween.EaseType.easeOutCubic);

 

        if (Bookorder - lastBookorder > 0)

        {

            switch (Bookorder)

            {

                case 1:

                    args.Add("z", 180f);

                    iTween.RotateAdd(page1.gameObject, args);

                    //iTween.RotateAdd (page1.gameObject, null, time, 0, 0, 180, iTween.EaseType.easeOutCubic);

                    break;

                case 2:

                    args.Add("z", 179.9f);

                    iTween.RotateAdd(page2.gameObject,args);

                    //iTween.RotateAdd (page2.gameObject, null, time, 0, 0, 179.999f, iTween.EaseType.easeOutCubic);

                    break;

                case 3:

                    args.Add("z", 179.8f);

                    iTween.RotateAdd(page3.gameObject, args);

                    //iTween.RotateAdd (page3.gameObject, null, time, 0, 0, 179.998f, iTween.EaseType.easeOutCubic);

                    break;

            }

        }

        else if (Bookorder - lastBookorder < 0)

        {

            switch (Bookorder)

            {

                case 0:

                    args.Add("z",-180f);

                    iTween.RotateAdd(page1.gameObject, args);

                    //iTween.RotateAdd (page1.gameObject, null, time, 0, 0, -180f, iTween.EaseType.easeOutCubic);

                    break;

                case 1:

                    args.Add("z", -179.999f);

                    iTween.RotateAdd(page2.gameObject, args);

                    //iTween.RotateAdd (page2.gameObject, null, time,

        0, 0, -179.999f, iTween.EaseType.easeOutCubic);

                    break;

                case 2:

                    args.Add("z", -179.998f);

                    iTween.RotateAdd(page3.gameObject, args);

                    //iTween.RotateAdd (page3.gameObject, null, time, 0, 0, -179.998f, iTween.EaseType.easeOutCubic);

                    break;

            }

        }

 

        lastBookorder = Bookorder;

}

Saved script.

12. Set the various parameters required by the script in unity.



Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326456953&siteId=291194637