Beispiel #1
0
        /**
         * Retrieves the indices of the particles that influece a given vertex. In the weight
         * field of each influence, the squared distance from the particle to the vertex is provided.
         */
        public List <ParticleInfluence> GetParticleInfluences(Vector3 vertex)
        {
            // TODO: try to make it faster.
            List <ParticleInfluence> allInfluences = new List <ParticleInfluence>();

            // Get squared distance to all particles:
            for (int i = 0; i < proxy.positions.Length; ++i)
            {
                ParticleInfluence influence = new ParticleInfluence();
                influence.particleIndex = i;
                influence.bindVector    = transform.InverseTransformVector(transform.TransformPoint(vertex) - proxy.GetParticlePosition(i));
                influence.weight        = influence.bindVector.sqrMagnitude;
                allInfluences.Add(influence);
            }

            // Sort by distance:
            allInfluences.Sort(
                delegate(ParticleInfluence x, ParticleInfluence y)
            {
                return(x.weight.CompareTo(y.weight));
            });

            // Return the K nearest:
            return(allInfluences.GetRange(0, numInfluences));
        }
Beispiel #2
0
        public override void UpdateParticleEditorInformation()
        {
            for (int i = 0; i < cloth.positions.Length; i++)
            {
                wsPositions[i] = cloth.GetParticlePosition(i);
            }

            if (cloth.clothMesh != null)
            {
                for (int i = 0; i < cloth.positions.Length; i++)
                {
                    facingCamera[i] = IsParticleFacingCamera(Camera.current, i);
                }
            }
        }
Beispiel #3
0
        public override void UpdateParticleEditorInformation()
        {
            for (int i = 0; i < cloth.positions.Length; i++)
            {
                wsPositions[i] = cloth.GetParticlePosition(i);
            }

            if (cloth.clothMesh != null && Camera.current != null)
            {
                for (int i = 0; i < cloth.clothMesh.vertexCount; i++)
                {
                    int     particle      = cloth.topology.visualMap[i];
                    Vector3 camToParticle = Camera.current.transform.position - wsPositions[particle];

                    sqrDistanceToCamera[particle] = camToParticle.sqrMagnitude;
                    facingCamera[particle]        = (Vector3.Dot(cloth.transform.TransformVector(cloth.MeshNormals[i]), camToParticle) > 0);
                }
            }
        }