Ejemplo n.º 1
0
    // Update is called once per frame
    void LateUpdate()
    {
        if (q != null)
        {
            Points points;
            if (q.PollForFrame <Points>(out points))
            {
                using (points)
                {
                    if (points.Count != mesh.vertexCount)
                    {
                        using (var p = points.GetProfile <VideoStreamProfile>())
                            CreateResources(p.Width, p.Height);
                    }
                    if (points.VertexData != IntPtr.Zero)
                    {
                        points.CopyVertices(vertices);

                        mesh.vertices = vertices;
                        mesh.UploadMeshData(false);
                    }
                }
            }
        }
    }
    void Update()
    {
        if (q != null)
        {
            detected = true;
            PoseFrame frame;
            if (q.PollForFrame <PoseFrame>(out frame))
            {
                using (frame)
                {
                    frame.CopyTo(pose);

                    // Convert T265 coordinate system to Unity's
                    // see https://realsense.intel.com/how-to-getting-imu-data-from-d435i-and-t265/

                    var t = pose.translation;
                    t.Set(-t.x, t.y, t.z);

                    var e = pose.rotation;

                    transform.localRotation = new Quaternion(e.x, -e.y, -e.z, e.w);
                    transform.localPosition = t * multiplier;
                }
            }
        }
    }
Ejemplo n.º 3
0
    protected void LateUpdate()
    {
        if (q != null)
        {
            Points points;
            if (q.PollForFrame <Points>(out points))
            {
                using (points)
                {
                    if (points.Count != mesh.vertexCount)
                    {
                        using (var p = points.GetProfile <VideoStreamProfile>())
                            ResetMesh(p.Width, p.Height);
                    }

                    if (points.TextureData != IntPtr.Zero)
                    {
                        uvmap.LoadRawTextureData(points.TextureData, points.Count * sizeof(float) * 2);
                        uvmap.Apply();
                    }

                    if (points.VertexData != IntPtr.Zero)
                    {
                        points.CopyVertices(vertices);

                        mesh.vertices = vertices;
                        mesh.UploadMeshData(false);
                    }
                }
            }
        }
    }
Ejemplo n.º 4
0
    void Update()
    {
        if (q != null)
        {
            PoseFrame frame;
            if (q.PollForFrame <PoseFrame>(out frame))
            {
                using (frame)
                {
                    frame.CopyTo(pose);

                    // Convert T265 coordinate system to Unity's
                    // see https://realsense.intel.com/how-to-getting-imu-data-from-d435i-and-t265/

                    var t = pose.translation;
                    t.Set(t.x, t.y, -t.z);

                    var e = pose.rotation.eulerAngles;
                    var r = Quaternion.Euler(-e.x, -e.y, e.z);

                    transform.localRotation = r;
                    transform.localPosition = t;
                }
            }
        }
    }
Ejemplo n.º 5
0
    void Update()
    {
        if (q != null)
        {
            Frame f;
            if (!q.PollForFrame(out f))
            {
                return;
            }

            using (var points = f as Points)
            {
                var s = points.Count * sizeof(float);
                if (points.TextureData != IntPtr.Zero)
                {
                    uvmap.LoadRawTextureData(points.TextureData, s * 2);
                    uvmap.Apply();
                }
                if (points.VertexData != IntPtr.Zero)
                {
                    memcpy(verticesPtr, points.VertexData, s * 3);
                    vertexBuffer.SetData(vertices);
                }
            }
        }
    }
Ejemplo n.º 6
0
    void Update()
    {
        if (pause)
        {
            return;
        }
        if (q != null)
        {
            Frame f;
            if (!q.PollForFrame(out f))
            {
                return;
            }

            using (var points = f as Points)
            {
                var s = points.Count * sizeof(float);
                if (points.VertexData != IntPtr.Zero)
                {
                    memcpy(verticesPtr, points.VertexData, s * 3);
                    vertexBuffer.SetData(vertices);
                }
            }
            var kernel = compute.FindKernel("build");
            compute.SetBuffer(kernel, "_ParticleBuffer", particleBuffer);
            compute.SetBuffer(kernel, "_VertBuffer", vertexBuffer);
            compute.SetBuffer(kernel, "_IndicesBuffer", indicesBuffer);
            compute.SetFloat("dt", Time.deltaTime);
            compute.Dispatch(kernel, numParticles / 8 + 1, 1, 1);
        }
    }
 protected void LateUpdate()
 {
     if (q != null)
     {
         VideoFrame frame;
         if (q.PollForFrame <VideoFrame>(out frame))
         {
             using (frame)
                 ProcessFrame(frame);
         }
     }
 }
Ejemplo n.º 8
0
    protected void Update()
    {
        // if (e.WaitOne(0, false))
        // return;

        if (q != null)
        {
            Frame frame;
            if (q.PollForFrame(out frame))
            {
                using (frame)
                    ProcessFrame(frame as VideoFrame);
            }
        }
    }
    protected void Update()
    {
        if (q != null)
        {
            Frame f;
            if (!q.PollForFrame(out f))
            {
                return;
            }

            using (var points = f as Points)
            {
                if (points.Count != mesh.vertexCount)
                {
                    using (var p = f.Profile as VideoStreamProfile)
                        ResetMesh(p.Width, p.Height);
                }

                int s = points.Count * sizeof(float);

                if (points.TextureData != IntPtr.Zero)
                {
                    uvmap.LoadRawTextureData(points.TextureData, s * 2);
                    uvmap.Apply();
                }

                if (points.VertexData != IntPtr.Zero)
                {
                    memcpy(verticesPtr, points.VertexData, s * 3);

                    mesh.vertices = vertices;
                    mesh.UploadMeshData(false);
                }
            }
        }
    }
Ejemplo n.º 10
0
    void Update()
    {
        Frame frame;

        if (pointsQueue.PollForFrame(out frame))
        {
            using (Points points = frame as Points)
            {
                if (points == null)
                {
                    throw new Exception("Frame in queue is not a points frame");
                }

                vertices = vertices ?? new Points.Vertex[points.Count];
                points.CopyTo(vertices);

                lock (l)
                {
                    if (textureCoordinate == null || textureCoordinate.Length != points.Count)
                    {
                        textureCoordinate = new Points.TextureCoordinate[points.Count];
                    }

                    points.CopyTo(textureCoordinate);

                    if (lastColorImage != null)
                    {
                        if (colorTexture == null || colorTexture.width != colorFrameWidth || colorTexture.height != colorFrameHeight)
                        {
                            colorTexture = new Texture2D(colorFrameWidth, colorFrameHeight, TextureFormat.RGB24, false, true)
                            {
                                wrapMode   = TextureWrapMode.Clamp,
                                filterMode = FilterMode.Point
                            };
                        }

                        colorTexture.LoadRawTextureData(lastColorImage);
                        colorTexture.Apply();
                    }
                }
                Debug.Assert(vertices.Length == particles.Length);
                int mirror = mirrored ? -1 : 1;
                for (int index = 0; index < vertices.Length; index += skipParticles)
                {
                    var v = vertices[index];
                    if (v.z > 0)
                    {
                        particles[index].position   = new Vector3(v.x * mirror, v.y, v.z);
                        particles[index].startSize  = pointsSize;
                        particles[index].startColor = colorTexture.GetPixelBilinear(textureCoordinate[index].u, textureCoordinate[index].v);
                    }
                    else //Required since we reuse the array
                    {
                        particles[index].position   = Vector3.zero;
                        particles[index].startSize  = 0;
                        particles[index].startColor = Color.black;
                    }
                }
            }
        }
        //Either way, update particles
        pointCloudParticles.SetParticles(particles, particles.Length);
    }
Ejemplo n.º 11
0
    protected void LateUpdate()
    {
        if (q != null)
        {
            Points points;
            if (q.PollForFrame <Points>(out points))
            {
                using (points)
                {
                    if (points.Count != mesh.vertexCount)
                    {
                        using (var p = points.GetProfile <VideoStreamProfile>())
                            ResetMesh(p.Width, p.Height);
                    }


                    if (points.TextureData != IntPtr.Zero)
                    {
                        uvmap.LoadRawTextureData(points.TextureData, points.Count * sizeof(float) * 2);
                        uvmap.Apply();
                    }

                    if (points.VertexData != IntPtr.Zero)
                    {
                        points.CopyVertices(vertices);

                        List <Vector3> filteredVerts = new List <Vector3>();

                        for (int i = 0; i < vertices.Length; i++)
                        {
                            if (vertices[i].z > floorLevelMin && vertices[i].z < floorLevelMax)
                            {
                                filteredVerts.Add(vertices[i]);
                            }
                            else
                            {
                                filteredVerts.Add(new Vector3(vertices[i].x, vertices[i].y, 0));
                            }
                        }

                        mesh.vertices = filteredVerts.ToArray();

                        //   mesh.vertices = vertices;

                        if (once)
                        {
                            float minX = 0;
                            float maxX = 0;
                            float minY = 0;
                            float maxY = 0;
                            float minZ = 0;
                            float maxZ = 0;
                            for (int pixel = 0; pixel < vertices.Length; pixel++)
                            {
                                if (vertices[pixel].x < minX)
                                {
                                    minX = vertices[pixel].x;
                                }
                                else
                                {
                                    if (vertices[pixel].x > maxX)
                                    {
                                        maxX = vertices[pixel].x;
                                    }
                                }

                                if (vertices[pixel].y < minY)
                                {
                                    minY = vertices[pixel].y;
                                }
                                else
                                {
                                    if (vertices[pixel].y > maxY)
                                    {
                                        maxY = vertices[pixel].y;
                                    }
                                }


                                if (vertices[pixel].z < minZ)
                                {
                                    minZ = vertices[pixel].y;
                                }
                                else
                                {
                                    if (vertices[pixel].z > maxZ)
                                    {
                                        maxZ = vertices[pixel].z;
                                    }
                                }
                            }
                            once = false;
                            Debug.Log(String.Format("minX: {0},maxX: {1}, minY: {2}, maxY{3}, minZ: {4}, maxZ{5}", minX, maxX, minY, maxY, minZ, maxZ));
                        }
                        mesh.UploadMeshData(false);
                    }
                }
            }
        }
    }
Ejemplo n.º 12
0
        Points DequeuePointFrame()
        {
            Points points;

            return(_pointQueue.PollForFrame <Points>(out points) ? points : null);
        }
Ejemplo n.º 13
0
        VideoFrame DequeueColorFrame()
        {
            VideoFrame frame;

            return(_colorQueue.PollForFrame <VideoFrame>(out frame) ? frame : null);
        }
Ejemplo n.º 14
0
        Points DequeuePointFrame()
        {
            Frame frame;

            return(_pointQueue.PollForFrame(out frame) ? (Points)frame : null);
        }
Ejemplo n.º 15
0
        VideoFrame DequeueColorFrame()
        {
            Frame frame;

            return(_colorQueue.PollForFrame(out frame) ? (VideoFrame)frame : null);
        }