示例#1
0
        public void StartPlayback(string sFilename)
        {
            if (FakeStream != null)
            {
                FakeStream.Stop(true);
            }

            if (current_filename != sFilename)
            {
                gs.ARKitStream stream = new gs.ARKitStream();
                stream.InitializeFromFileAscii(sFilename);

                string sVideoFilename = sFilename.Replace("ARStream", "VideoStream");
                sVideoFilename = sVideoFilename.Replace(".txt", ".bin");
                gs.VideoStream video_stream = null;
                if (File.Exists(sVideoFilename))
                {
                    video_stream = new gs.VideoStream();
                    video_stream.InitializeRead(sVideoFilename, true);
                }

                FakeStream = new gs.ARKitStreamPlayback();
                FakeStream.SetSource(stream, video_stream);

                current_filename = sFilename;
            }


            samples_parent = new GameObject("samples_parent");
            planes_parent  = new GameObject("planes_parent");

            Material videoMaterial = null;

            if (VideoPlane != null)
            {
                videoMaterial = VideoPlane.GetComponent <Renderer>().material;
            }

            Texture2D video_texture = null;

            FakeStream.NewFrameF = (time) => {
                reset_all_markers();
            };

            FakeStream.UpdateCameraF = (pos, rot) => {
                Camera.main.transform.position = pos;
                Camera.main.transform.rotation = rot;
            };

            FakeStream.EmitSamplePointF = (pos, screenPos, color) => {
                if (ShowSamplePoints)
                {
                    GameObject sample_go = request_marker_go();
                    sample_go.transform.position = pos;
                    sample_go.GetComponent <MeshRenderer>().material.color = color;
                }
            };

            FakeStream.PlaneChangeF = (ARKitStream.PlaneChange eType, ARKitStream.ARKitPlane plane) => {
                if (eType == ARKitStream.PlaneChange.Removed)
                {
                    remove_plane(plane);
                }
                else
                {
                    update_plane(plane);
                }
            };

            FakeStream.EmitVideoFrameF = (frame) => {
                if (videoMaterial != null)
                {
                    if (video_texture == null)
                    {
                        video_texture = new Texture2D(frame.width, frame.height);
                    }
                    video_texture.LoadImage(frame.rgb);
                    videoMaterial.SetTexture("_MainTex", video_texture);
                }
            };

            FakeStream.Start(Time.realtimeSinceStartup);
        }
    void simulate_ar()
    {
        if (FakeStream != null)
        {
            FakeStream.Stop(true);
        }

        //string sFilename = "/Users/rms/scratch/ARStream_15-7-2017-20-23-23.txt";
        // 5mb
        //string sFilename = "/Users/rms/scratch/ARStream_15-7-2017-18-21-12.txt";
        string sFilename = "/Users/rms/scratch/ARStream_16-7-2017-22-25-2.txt";

        // w/ video
        //string sFilename = "/Users/rms/scratch/ARStream_15-7-2017-22-27-22.txt";
        //string sFilename = "/Users/rms/scratch/ARStream_15-7-2017-23-11-48.txt";

        if (current_filename != sFilename)
        {
            gs.ARKitStream stream = new gs.ARKitStream();
            stream.InitializeFromFileAscii(sFilename);

            string sVideoFilename = sFilename.Replace("ARStream", "VideoStream");
            sVideoFilename = sVideoFilename.Replace(".txt", ".bin");
            gs.VideoStream video_stream = null;
            if (File.Exists(sVideoFilename))
            {
                video_stream = new gs.VideoStream();
                video_stream.InitializeRead(sVideoFilename, true);
            }

            FakeStream = new gs.ARKitStreamPlayback();
            FakeStream.SetSource(stream, video_stream);

            current_filename = sFilename;
        }


        samplesParent = new GameObject("samples_parent");
        GameObject videoPlane = UnityUtil.FindGameObjectByName("VideoPlane");

        videoPlane.SetVisible(true);
        Material  videoMaterial = videoPlane.GetMaterial();
        Texture2D video_texture = null;

        FakeStream.NewFrameF = (time) => {
            GameObject.Destroy(samplesParent);
            samplesParent = new GameObject("samples_parent");
        };
        FakeStream.UpdateCameraF = (pos, rot) => {
            Camera.main.transform.position = pos;
            Camera.main.transform.rotation = rot;
        };
        FakeStream.EmitSamplePointF = (pos, screenPos, color) => {
            GameObject go = DebugUtil.EmitDebugSphere("pt", pos, 0.01f, color, null, true);
            samplesParent.AddChild(go, true);

            if (ParticleGridVizGO != null)
            {
                ParticleGridVizGO.GetComponent <ParticleGridViz>().InjectSample(pos, color);
            }
        };
        FakeStream.EmitVideoFrameF = (frame) => {
            if (video_texture == null)
            {
                video_texture = new Texture2D(frame.width, frame.height);
            }
            video_texture.LoadImage(frame.rgb);
            videoMaterial.SetTexture("_MainTex", video_texture);
        };

        FakeStream.Start(Time.realtimeSinceStartup);
    }