Esempio n. 1
0
        void OnPointCloudChanged(ARPointCloud pointCloud)
        {
            var points = s_Vertices;

            pointCloud.GetPoints(points, Space.Self);

            mesh.Clear();
            mesh.SetVertices(points);

            var indices = new int[points.Count];

            for (int i = 0; i < points.Count; ++i)
            {
                indices[i] = i;
            }

            mesh.SetIndices(indices, MeshTopology.Points, 0);

            var meshFilter = GetComponent <MeshFilter>();

            if (meshFilter != null)
            {
                meshFilter.sharedMesh = mesh;
            }
        }
        void OnPointCloudChanged(ARPointCloud pointCloud)
        {
            var points = s_Vertices;

            pointCloud.GetPoints(points, Space.Self);

            int numParticles = points.Count;

            if (m_Particles == null || m_Particles.Length < numParticles)
            {
                m_Particles = new ParticleSystem.Particle[numParticles];
            }

            var color = m_ParticleSystem.main.startColor.color;
            var size  = m_ParticleSystem.main.startSize.constant;

            for (int i = 0; i < numParticles; ++i)
            {
                m_Particles[i].startColor        = color;
                m_Particles[i].startSize         = size;
                m_Particles[i].position          = points[i];
                m_Particles[i].remainingLifetime = 1f;
            }

            // Remove any existing particles by setting remainingLifetime
            // to a negative value.
            for (int i = numParticles; i < m_NumParticles; ++i)
            {
                m_Particles[i].remainingLifetime = -1f;
            }

            m_ParticleSystem.SetParticles(m_Particles, Math.Max(numParticles, m_NumParticles));
            m_NumParticles = numParticles;
        }
        void OnPointCloudChanged(ARPointCloud pointCloud)
        {
            var points = s_Vertices;

            pointCloud.GetPoints(points, Space.Self);

            int numPoints = points.Count;

            // Get the number of existing particles
            int numParticles = m_ParticleSystem.GetParticles(m_Particles);

            // Count how many particles are alive
            int numAliveParticles = 0;

            for (int i = 0; i < numParticles; i++)
            {
                if (m_Particles[i].remainingLifetime > 0)
                {
                    numAliveParticles++;
                }
            }

            // Emit enough particles to match the number of points
            if (numAliveParticles < numPoints)
            {
                var emitCount = numPoints - numAliveParticles;
                m_ParticleSystem.Emit(emitCount);
            }

            // Resize the particle array if there's not enough room
            if (m_Particles.Length < numPoints)
            {
                m_Particles = new ParticleSystem.Particle[numPoints];
            }

            // Get the particles again, so we have the newly emitted particles
            numParticles = m_ParticleSystem.GetParticles(m_Particles);

            // Update the positions of all the particles to match the points
            for (int i = 0; i < numParticles && i < numPoints; ++i)
            {
                m_Particles[i].position = points[i];
            }

            // Remove any existing particles by setting remainingLifetime
            // to a negative value.
            for (int i = numPoints; i < numParticles; ++i)
            {
                m_Particles[i].remainingLifetime = -1f;
            }

            m_ParticleSystem.SetParticles(m_Particles, numParticles);
        }