Пример #1
0
    private void GenerateLeaf(Vector3 position, Quaternion orientation, float leafGrowth)
    {
        Quaternion leafOrientation = orientation * Quaternion.Euler(-Species.LeafVerticalAngle, 0, 0);

        float leafScale = Mathf.Pow(leafGrowth, Species.ScaleExponent);

        // generate petiole

        int startVC = mg.VertexCount;

        mg.SetMaterial(0);

        List <int> petioleRing = tempIndices.GetNext();

        petioleRing.Clear();

        petioleRing.Add(mg.AddVertex(Vector3.left * Species.PetioleWidth * 0.5f));
        petioleRing.Add(mg.AddVertex(Vector3.right * Species.PetioleWidth * 0.5f));
        petioleRing.Add(mg.AddVertex(Vector3.down * Species.PetioleDepth));

        int petioleEndPoint = mg.AddVertex(new Vector3(0, 0, Species.PetioleLength));

        for (int i = 0; i < 3; i++)
        {
            int j = (i + 1) % 3;
            mg.AddFace(petioleEndPoint, petioleRing[j], petioleRing[i]);
        }

        // generate blade

        int bladeStartVC = mg.VertexCount;

        mg.SetMaterial(1);

        // blade front faces

        float   bladeX        = Mathf.Cos(Species.BladeFoldAngle * Mathf.Deg2Rad) * Species.BladeWidth * 0.5f;
        float   bladeY        = Mathf.Sin(Species.BladeFoldAngle * Mathf.Deg2Rad) * Species.BladeWidth * 0.5f;
        Vector3 bladeLeftPos  = new Vector3(-bladeX, bladeY, Species.BladeLength * 0.5f);
        Vector3 bladeRightPos = new Vector3(bladeX, bladeY, Species.BladeLength * 0.5f);
        Vector3 bladeTipPos   = new Vector3(0, 0, Species.BladeLength);

        int bladeBase  = mg.AddVertex(Vector3.zero);
        int bladeTip   = mg.AddVertex(bladeTipPos);
        int bladeLeft  = mg.AddVertex(bladeLeftPos);
        int bladeRight = mg.AddVertex(bladeRightPos);

        mg.AddFace(bladeBase, bladeTip, bladeRight);
        mg.AddFace(bladeBase, bladeLeft, bladeTip);

        // blade back faces

        bladeBase  = mg.AddVertex(Vector3.zero);
        bladeTip   = mg.AddVertex(bladeTipPos);
        bladeLeft  = mg.AddVertex(bladeLeftPos);
        bladeRight = mg.AddVertex(bladeRightPos);

        mg.AddFace(bladeBase, bladeRight, bladeTip);
        mg.AddFace(bladeBase, bladeTip, bladeLeft);

        // orient and position leaf

        int endVC = mg.VertexCount;

        mg.TranslateVertices(bladeStartVC, endVC, new Vector3(0, 0, Species.PetioleLength * Species.BladePosition));

        mg.ScaleVertices(startVC, endVC, leafScale);
        mg.RotateVertices(startVC, endVC, leafOrientation);
        mg.TranslateVertices(startVC, endVC, position);
    }