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 OnPointCloudUpdated(PointCloudUpdatedEventArgs eventArgs)
        {
            if (pointCloud == null)
            {
                GameObject newGameObject;
                if (pointCloudPrefab != null)
                {
                    newGameObject = Instantiate(pointCloudPrefab, m_SessionOrigin.trackablesParent);
                    newGameObject.transform.localPosition = Vector3.zero;
                    newGameObject.transform.localRotation = Quaternion.identity;
                    newGameObject.transform.localScale    = Vector3.one;
                }
                else
                {
                    newGameObject = new GameObject();
                    newGameObject.transform.SetParent(m_SessionOrigin.trackablesParent, false);
                }

                newGameObject.layer = gameObject.layer;

                pointCloud = newGameObject.GetComponent <ARPointCloud>();
                if (pointCloud == null)
                {
                    pointCloud = newGameObject.AddComponent <ARPointCloud>();
                }
            }

            pointCloud.OnUpdated();

            if (pointCloudUpdated != null)
            {
                pointCloudUpdated(new ARPointCloudUpdatedEventArgs(pointCloud));
            }
        }
        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 OnSessionDestroyed()
 {
     if (pointCloud != null)
     {
         Destroy(pointCloud.gameObject);
         pointCloud = null;
     }
 }
        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);
        }
Esempio n. 6
0
 /// <summary>
 /// Constructor for the <see cref="ARPointCloudUpdatedEventArgs"/>. This is normally only used by an <see cref="ARSessionOrigin"/>.
 /// </summary>
 /// <param name="pointCloud">The <see cref="ARPointCloud"/> whose update triggered this event.</param>
 public ARPointCloudUpdatedEventArgs(ARPointCloud pointCloud)
 {
     this.pointCloud = pointCloud;
 }