Beispiel #1
0
    /// <summary>
    /// Updates all particles positions, if resolution changed, it will initialize new particles
    /// </summary>
    private void UpdateParticles()
    {
        Debug.Log("Updating Particles");
        int shouldBe = GetNumParticles();

        if (particles.Length != shouldBe)
        {
            CreateParticles();
        }

        Vector2 uRange = repository.GetURange(), vRange = repository.GetVRange();
        float   uSpan = uRange.y - uRange.x, vSpan = vRange.y - vRange.x;
        float   uRes = uSpan / this.resolution, vRes = vSpan / this.resolution;
        float   u, v;

        for (int i = 0; i < this.resolution; i++)
        {
            u = uRange.x + i * uRes;
            for (int j = 0; j < this.resolution; j++)
            {
                v = vRange.x + j * vRes;
                ParticleSystem.Particle part = particles[GetIndex(i, j)];
                Vector3 p = repository.GetVect(u, v);
                //Vector3 p = new Vector3((float)i / this.resolution, (float) j / this.resolution, 0);
                part.position = p;
                part.color    = Color.red;
                part.size     = 0.5f;
            }
        }

        system.SetParticles(particles, particles.Length);
        //GetComponent<ParticleSystem>().SetParticles(particles, particles.Length);
    }
Beispiel #2
0
    private void ReDoMesh()
    {
        Mesh       mesh;
        MeshFilter filter = parent.GetComponent <MeshFilter>();

        filter.mesh = null;
        filter.mesh = mesh = new Mesh();
        mesh.name   = "Procedural Grid";

        Vector2 uBounds = repository.GetURange(), vBounds = repository.GetVRange();
        float   uSpan = uBounds.y - uBounds.x, vSpan = vBounds.y - vBounds.x;
        float   uRes = uSpan / (this.resolution - 1), vRes = vSpan / (this.resolution - 1);

        vertices = new Vector3[resolution * resolution];
        Vector2[] uv = new Vector2[vertices.Length];

        float u, v;

        for (int y = 0, a = 0; y < this.resolution; y++)
        {
            v = vBounds.x + y * vRes;
            for (int x = 0; x < this.resolution; x++, a++)
            {
                u           = uBounds.x + x * uRes;
                vertices[a] = repository.GetVect(u, v);
                uv[y]       = new Vector2(x / this.resolution, y / this.resolution);
            }
        }

        mesh.vertices = vertices;
        mesh.uv       = uv;



        int[] triangles = new int[this.resolution * this.resolution * 6];
        int   verts     = this.resolution * this.resolution;

        for (int i = 0; i < verts; i++)
        {
            triangles[i * 6]       = i;
            triangles[(i * 6) + 1] = (i + 1) % verts;
            triangles[(i * 6) + 2] = (i + this.resolution + 1) % verts;
            triangles[(i * 6) + 3] = i;
            triangles[(i * 6 + 4)] = (i + 1 + this.resolution) % verts;
            triangles[(i * 6) + 5] = (i + this.resolution) % verts;
        }

        mesh.triangles = triangles;
        mesh.RecalculateTangents();
        mesh.RecalculateNormals();
    }
Beispiel #3
0
    private void UpdateParticles()
    {
        Vector2 uRange = repository.GetURange(), vRange = repository.GetVRange();
        float   uSpan = uRange.y - uRange.x, vSpan = vRange.y - vRange.x;
        float   uRes = uSpan / this.resolution, vRes = vSpan / this.resolution;

        //float scale = Mathf.Max(uRes, vRes);
        Debug.Log("Scale " + scale);
        float u, v;

        for (int i = 0; i < this.resolution; i++)
        {
            u = uRange.x + i * uRes;
            for (int j = 0; j < this.resolution; j++)
            {
                v = vRange.x + j * vRes;
                GameObject part = points[GetIndex(i, j)];

                Vector3 p = repository.GetVect(u, v);
                part.transform.SetPositionAndRotation(p, Quaternion.identity);
                part.transform.localScale = Vector3.one * scale;
            }
        }
    }