static MeshObjectData CreateFoliage(TreeData data, TreeBranch Branch, int index)
        {
            MeshDraft m;

            switch (data.FoliageBasePrimitiveShape)
            {
            case TreeData.BasePrimitiveShapes.Dodecahedron:
                m = MeshDraft.Dodecahedron(0.5f);
                break;

            case TreeData.BasePrimitiveShapes.Icosahedron:
                m = MeshDraft.Icosahedron(0.5f, false);
                break;

            case TreeData.BasePrimitiveShapes.Prism:
                m = MeshDraft.Prism(0.5f, data.foliageSegments, 0.1f, false);
                break;

            case TreeData.BasePrimitiveShapes.Pyramid:
                m = MeshDraft.Pyramid(0.5f, data.foliageSegments, 0.5f, false);
                break;

            default:
                m = MeshDraft.Sphere(0.5f, data.foliageSegments, data.foliageSegments, false);
                break;
            }

            MeshObjectData plant = new MeshObjectData();

            plant.vertices  = m.vertices.ToArray();
            plant.triangles = m.triangles.ToArray();
            plant.tangents  = m.tangents.ToArray();
            plant.AutoWeldMesh(0.0001f, 0.4f);

            Vector3[] verts        = plant.vertices;
            float     currentNoise = data.noise;

            currentNoise *= 0.4f;
            Vector3 Pos = Branch.To;

            plant.position = Pos;

            int  s = data.TreeSeed + index + Mathf.RoundToInt(Pos.x) + Mathf.RoundToInt(Pos.y) + Mathf.RoundToInt(Pos.z) + Mathf.RoundToInt(Branch.Length);
            Rand r = new Rand(s);

            for (int i = 0; i < verts.Length; i++)
            {
                verts[i].x += r.Range(-currentNoise, currentNoise);
                verts[i].y += r.Range(-currentNoise, currentNoise);
                verts[i].z += r.Range(-currentNoise, currentNoise);
            }

            plant.vertices = verts;

            plant.flatShade();

            Color[] vertexColor = new Color[plant.vertices.Length];
            Color   CC          = data.foliageColors[r.Range(0, data.foliageColors.Length)];

            for (int c = 0; c < plant.vertices.Length; c++)
            {
                vertexColor[c] = CC;
            }
            plant.colors = vertexColor;
            return(plant);
        }
Пример #2
0
 public static void Prism()
 {
     PrimitiveTemplate(prism, () => MeshDraft.Prism(1, 16, 1).ToMesh());
 }
Пример #3
0
 private void Start()
 {
     GetComponent <MeshFilter>().mesh = MeshDraft.Prism(radius, segments, height).ToMesh();
 }
Пример #4
0
        public static void Build(RockThreadReturnData returnData)
        {
            RockData  data = returnData.RockData;
            MeshDraft MD;

            switch (data.RockBasePrimitiveShape)
            {
            case RockData.BasePrimitiveShapes.Dodecahedron:
                MD = MeshDraft.Dodecahedron(0.5f);
                break;

            case RockData.BasePrimitiveShapes.Icosahedron:
                MD = MeshDraft.Icosahedron(0.5f, false);
                break;

            case RockData.BasePrimitiveShapes.Prism:
                MD = MeshDraft.Prism(0.5f, data.Segments, 1f, false);
                break;

            case RockData.BasePrimitiveShapes.Pyramid:
                MD = MeshDraft.Pyramid(0.5f, data.Segments, 1f, false);
                break;

            default:
                MD = MeshDraft.Sphere(0.5f, data.Segments, data.Segments, false);
                break;
            }
            ;
            MeshObjectData rock = new MeshObjectData();

            rock.vertices  = MD.vertices.ToArray();
            rock.triangles = MD.triangles.ToArray();
            rock.tangents  = MD.tangents.ToArray();
            rock.AutoWeldMesh(0.0001f, 0.4f);
            Vector3[] verts = rock.vertices;
            INoise    noise = new SimplexNoise(data.RockSeed, 0.3f, 0.2f);
            Rand      r     = new Rand(data.RockSeed);

            for (int i = 0; i < verts.Length; i++)
            {
                float currentNoise = NoiseGen(noise, 3, verts[i].x / 0.5f, verts[i].y / 0.5f, verts[i].z / 0.5f);
                //currentNoise*=2;
                Vector3 norm = verts[i].normalized;
                verts[i].x += currentNoise * norm.x;
                verts[i].y += currentNoise * norm.y;
                verts[i].z += currentNoise * norm.z;

                verts[i].x *= 3;
                verts[i].y *= 1.2f;
                verts[i].z *= 1.5f;
            }
            rock.vertices = verts;
            rock.flatShade();

            Color[] vertexColor = new Color[rock.vertices.Length];

            for (int i = 0; i < rock.vertices.Length; i++)
            {
                vertexColor[i] = data.RockGradientColor.Color.Evaluate(1 - rock.vertices[i].y);
            }

            rock.colors = vertexColor;
            returnData.RockBuildData = rock;
            returnData.ManagerCallBack(returnData);
        }