コード例 #1
0
 void OnEnable()
 {
     treeObjects         = new List <TerrainObject>();
     meshVertices        = new List <Vector3[]>();
     vertPosPerObject    = new List <List <List <int> > >();
     updatedMeshVertices = new List <Vector3[]>();
     lowestVertPerObject = new List <List <float> >();
     randomValues        = new List <List <float> >();
     instance            = this;
     StartCoroutine("AnimateTrees");
 }
コード例 #2
0
    public void DetermineAnimationParameters()
    {
        terrainObject = GetComponent <TerrainObject>();
        objectMesh    = GetComponent <MeshFilter>().mesh;
        TreeAnimationController treeAnimationController = TreeAnimationController.instance;

        vertices = objectMesh.vertices;
        terrainObject.animationNumber = treeAnimationController.meshVertices.Count;
        treeAnimationController.meshVertices.Add(objectMesh.vertices);

        List <float> randomValues = new List <float>();

        for (int i = 0; i < vertices.Length; i++)
        {
            randomValues.Add((float)rand.NextDouble());
        }

        treeAnimationController.randomValues.Add(randomValues);

        int sum = 0;

        foreach (int submesh in terrainObject.numVerticesPerObject)
        {
            sum += submesh;
        }

        totalObjects = vertices.Length / sum;
        List <List <int> > vertPosPerObject = new List <List <int> >();

        for (int i = 0; i < totalObjects; i++)
        {
            List <int> objectVertPos = new List <int>();
            for (int j = 0; j < terrainObject.numVerticesPerObject.Count; j++)
            {
                int add = 0;
                for (int l = 0; l < j; l++)
                {
                    int a = terrainObject.numVerticesPerObject[l];
                    add += totalObjects * a;
                }
                for (int k = 0; k < terrainObject.numVerticesPerObject[j]; k++)
                {
                    int vertPos = k + add + i * terrainObject.numVerticesPerObject[j];
                    objectVertPos.Add(k + add + i * terrainObject.numVerticesPerObject[j]);
                }
            }
            vertPosPerObject.Add(objectVertPos);
        }

        treeAnimationController.vertPosPerObject.Add(vertPosPerObject);
    }