Пример #1
0
    // Create a sphere collider for each particle
    private void CreateSphereColliders()
    {
        int len = this.particles.Length;

        this.sphereColliders = new SphereCollider[len];

        for (int i = 0; i < len; i++)
        {
            SphereCollider sp = this.gameObject.AddComponent <SphereCollider>();

            sp.isSingleParticle = true;
            sp.AssignSingleParticle(this.particles[i]);
            sp.Radius = this.sphereCollRadius;

            this.sphereColliders[i] = sp;
        }
        UpdateSphereColliderPos();
    }
Пример #2
0
    private void CreateParticlesBasedOnMesh()
    {
        this.particles       = new Particle[this.mesh.vertexCount];
        this.sphereColliders = new SphereCollider[this.mesh.vertexCount];
        for (int i = 0; i < this.mesh.vertexCount; i++)
        {
            this.particles[i] = new Particle(this.mesh.vertices[i], 1f);

            // Add sphere colliders
            SphereCollider sp = this.gameObject.AddComponent <SphereCollider>();
            sp.AssignSingleParticle(this.particles[i]);
            sp.isSingleParticle     = true;
            sp.Radius               = this.clothParams.clothSize / 10f * 1f;
            this.sphereColliders[i] = sp;

            // Clamp end particles
            if (i == (this.dynamicGrid.xSize + 1) * this.dynamicGrid.ySize || i == ((this.dynamicGrid.xSize + 1) * (this.dynamicGrid.ySize + 1) - 1))
            {
                particles[i].invMass = 0;
            }
        }
    }