Exemple #1
0
    // Method that moves, rotates and scales a mesh
    void MoveMesh(TerrainObject terrainObject, Mesh mesh, int subMesh, Vector3 trans, Quaternion rotate, Vector3 scale)
    {
        // make a new list of vector3 which will hold the vertices
        vertNew.Clear();

        // Keep track of the index in the foreach loop
        int index = 0;

        // loop through all vertices in the inputted mesh
        foreach (Vector3 vert in mesh.vertices)
        {
            // scale, rotate and move the vertex according to inputs
            vertNew.Add(new Vector3(vert.x * scale.x, vert.y * scale.y, vert.z * scale.z));
            vertNew[index] = rotate * vertNew[index];
            vertNew[index] = vertNew[index] + trans;

            index++;
        }

        terrainObject.AddTriangles(mesh.triangles, subMesh);
        terrainObject.AddVertices(vertNew);
    }