示例#1
0
    public void DrawMeshOnEachBranch()
    {
        CombineInstance[] finalMeshes = new CombineInstance[SplinePlus.SPData.DictBranches.Count];
        foreach (var branch in  SplinePlus.SPData.DictBranches)
        {
            var mesh = DrawMesh(branch.Value);
            finalMeshes[branch.Key].mesh      = mesh;
            finalMeshes[branch.Key].transform = transform.worldToLocalMatrix * transform.localToWorldMatrix;
        }

        var finalMesh = new Mesh();

        finalMesh.CombineMeshes(finalMeshes, true, true);
        finalMesh.RecalculateNormals(60.0f);

        if (TwoSided)
        {
            var tempMesh = FacesSettings.TwoSided(finalMesh);
            finalMesh = tempMesh;
        }
        if (FlipFaces)
        {
            finalMesh = FacesSettings.FlipFaces(finalMesh);
        }
        Mesh.sharedMesh = finalMesh;
    }
示例#2
0
    public void DrawMeshOnEachBranch()
    {
        var finalMeshes = new List <CombineInstance>();

        foreach (var branch in SplinePlus.SPData.DictBranches)
        {
            if (branch.Value.Nodes.Count <= 1)
            {
                continue;
            }
            var temp = new CombineInstance();
            var mesh = DrawMesh(branch.Value, branch.Key);
            temp.mesh      = mesh;
            temp.transform = transform.worldToLocalMatrix * transform.localToWorldMatrix;

            finalMeshes.Add(temp);
        }

        var finalMesh = new Mesh();

        finalMesh.CombineMeshes(finalMeshes.ToArray(), true, true);
        finalMesh.RecalculateNormals(60.0f);

        if (TwoSided)
        {
            finalMesh = FacesSettings.TwoSided(finalMesh);
        }
        if (FlipFaces)
        {
            finalMesh = FacesSettings.FlipFaces(finalMesh);
        }
        Mesh.sharedMesh             = finalMesh;
        MeshRenderer.sharedMaterial = Material;
    }
示例#3
0
        public void DrawMesh( )
        {
            var rings        = SPData.Vertices.Count;
            var vertexNumber = ((Segments + 1) * rings);

            _Data.Vertices  = new Vector3[vertexNumber];
            _Data.Normals   = new Vector3[vertexNumber];
            _Data.Tangents  = new Vector4[vertexNumber];
            _Data.Triangles = new int[(Segments * (rings - 1) * 6)];
            _Data.Uvs       = new Vector2[vertexNumber];

            for (int n = 0, t = 0; n < rings; n++)
            {
                var branchVert    = SPData.Vertices[n];
                var branchNormal  = SPData.Normals[n];
                var branchTangent = SPData.Tangents[n];

                Quaternion rot = Quaternion.LookRotation(branchTangent, branchNormal);

                for (int i = 0; i <= Segments; i++, t++)
                {
                    Vertices(t, n, rot, i);
                    Tangents(t, n);
                    Normals(t, n);
                    Uvs(t, n, i);
                }
            }

            int u = 0;

            for (int n = 0; n < _Data.Vertices.Length - (Segments + 1); n++)
            {
                if (n % (Segments + 1) == 0)
                {
                    continue;
                }
                u = Triangles(n, u);
            }

            var finalMesh = CreateMesh();

            if (TwoSided == Switch.On)
            {
                finalMesh = FacesSettings.TwoSided(finalMesh);
            }
            if (FlipFaces == Switch.On)
            {
                finalMesh = FacesSettings.FlipFaces(finalMesh);
            }
            Mesh.sharedMesh             = finalMesh;
            MeshRenderer.sharedMaterial = Material;
        }
示例#4
0
    public void DrawMeshOnEachBranch()
    {
        if (BranchData.Count < SplinePlus.SPData.DictBranches.Count)
        {
            for (int n = BranchData.Count; n < SplinePlus.SPData.DictBranches.Count; n++)
            {
                BranchData.Add(new BranchData());
            }
        }
        else if (BranchData.Count > SplinePlus.SPData.DictBranches.Count)
        {
            BranchData.RemoveRange(SplinePlus.SPData.DictBranches.Count, (BranchData.Count - SplinePlus.SPData.DictBranches.Count));
        }

        List <CombineInstance> finalMeshes = new List <CombineInstance>();
        int i = 0;

        foreach (var branch in SplinePlus.SPData.DictBranches)
        {
            if (branch.Value.Nodes.Count > 1)
            {
                var temp = new CombineInstance();

                var mesh = DrawMesh(branch.Value, i);
                temp.mesh      = mesh;
                temp.transform = transform.worldToLocalMatrix;

                finalMeshes.Add(temp);
            }
            i++;
        }

        var finalMesh = new Mesh();

        finalMesh.CombineMeshes(finalMeshes.ToArray(), true, true);


        if (TwoSided)
        {
            finalMesh = FacesSettings.TwoSided(finalMesh);
        }
        if (FlipFaces)
        {
            finalMesh = FacesSettings.FlipFaces(finalMesh);
        }
        Mesh.sharedMesh             = finalMesh;
        MeshRenderer.sharedMaterial = Material;
    }
示例#5
0
        public void DrawMesh()
        {
            if (SPData.Vertices.Count < 2)
            {
                return;
            }
            vertices.Clear();
            normals.Clear();
            tangents.Clear();


            for (int i = 0; i < SPData.Vertices.Count; i++)//vertices normals tangents
            {
                Vertices(i);
                Normals(i);
                Tangents(i);
            }

            Triangles();
            Uvs();

            var finalMesh = CreateMesh();

            if (TwoSided == Switch.On)
            {
                finalMesh = FacesSettings.TwoSided(finalMesh);
            }
            if (FlipFaces == Switch.On)
            {
                finalMesh = FacesSettings.FlipFaces(finalMesh);
            }
            Mesh.sharedMesh = finalMesh;

            MeshRenderer.sharedMaterial = Material;
            if (SPData.MeshUpdate != null)
            {
                SPData.MeshUpdate.Update();
            }
        }
示例#6
0
    public Mesh CreateMesh(Branch branch)
    {
        Mesh returnedMesh = new Mesh();
        Mesh body1 = new Mesh(), body2 = new Mesh();

        body1.vertices  = BodyData.Vertices;
        body1.triangles = BodyData.Triangles;
        body1.tangents  = BodyData.Tangents;
        body1.normals   = BodyData.Normals;
        body1.uv        = BodyData.Uvs;

        if (Shell)
        {
            body2.vertices  = BodyData.Vertices;
            body2.tangents  = BodyData.Tangents;
            body2.normals   = BodyData.Normals;
            body2.triangles = BodyData.Triangles;
            body2.uv        = BodyData.Uvs;

            var vert = new Vector3[body2.vertices.Length];

            for (int n = 0, t = 0; n <= Rings + 1; n++)
            {
                for (int i = 0; i < branch.Vertices.Count; i++, t++)
                {
                    vert[t] = body2.vertices[t] + body2.normals[t] * ShellPower;
                }
            }

            body2.vertices = vert;
            body1          = FacesSettings.FlipFaces(body1);
        }

        if (CapHoles)
        {
            Mesh cap1 = new Mesh(), cap2 = new Mesh();
            cap1.vertices  = CapData.Vertices;
            cap1.triangles = CapData.Triangles;
            cap1.tangents  = CapData.Tangents;
            cap1.uv        = CapData.Uvs;

            cap2.vertices  = CapData.Vertices;
            cap2.triangles = CapData.Triangles;
            cap2.tangents  = CapData.Tangents;
            cap2.uv        = CapData.Uvs;


            var vert = new Vector3[cap2.vertices.Length];

            for (int i = 0, n = 0; i < CapData.Vertices.Length && n < branch.Vertices.Count; i = i + 2, n++)
            {
                var normal = Vector3.Cross(branch.Tangents[n], branch.Normals[n]).normalized;
                vert[i] = cap1.vertices[i] + Vector3.up * Height + normal * Curvature.Evaluate(1) - normal * Curvature.Evaluate(0);
                if ((i + 1) < CapData.Vertices.Length)
                {
                    vert[i + 1] = cap1.vertices[i + 1] + Vector3.up * Height + normal * Curvature.Evaluate(1) - normal * Curvature.Evaluate(0);
                }
            }

            cap2.vertices = vert;
            cap2          = FacesSettings.FlipFaces(cap2);

            CombineInstance[] bodyMesh = new CombineInstance[2];

            bodyMesh[0].mesh      = body1;
            bodyMesh[0].transform = transform.worldToLocalMatrix * transform.localToWorldMatrix;

            bodyMesh[1].mesh      = body2;
            bodyMesh[1].transform = transform.worldToLocalMatrix * transform.localToWorldMatrix;

            Mesh bodyComMesh = new Mesh();
            bodyComMesh.CombineMeshes(bodyMesh, true);

            CombineInstance[] capMesh = new CombineInstance[2];
            capMesh[0].mesh      = cap1;
            capMesh[0].transform = transform.worldToLocalMatrix * transform.localToWorldMatrix;

            capMesh[1].mesh      = cap2;
            capMesh[1].transform = transform.worldToLocalMatrix * transform.localToWorldMatrix;


            Mesh capComMesh = new Mesh();
            capComMesh.CombineMeshes(capMesh, true);

            CombineInstance[] totalMesh = new CombineInstance[2];

            totalMesh[0].mesh      = bodyComMesh;
            totalMesh[0].transform = transform.worldToLocalMatrix * transform.localToWorldMatrix;

            totalMesh[1].mesh      = capComMesh;
            totalMesh[1].transform = transform.worldToLocalMatrix * transform.localToWorldMatrix;

            Mesh totalComMesh = new Mesh();
            totalComMesh.CombineMeshes(totalMesh, true);

            totalComMesh.RecalculateNormals();
            returnedMesh = totalComMesh;
        }
        else
        {
            if (Shell)
            {
                CombineInstance[] totalMesh = new CombineInstance[2];

                totalMesh[0].mesh      = body1;
                totalMesh[0].transform = transform.worldToLocalMatrix * transform.localToWorldMatrix;


                totalMesh[1].mesh      = body2;
                totalMesh[1].transform = transform.worldToLocalMatrix * transform.localToWorldMatrix;

                Mesh combinedAllMesh = new Mesh();
                combinedAllMesh.CombineMeshes(totalMesh, true);

                combinedAllMesh.RecalculateNormals();
                returnedMesh = combinedAllMesh;
            }
            else
            {
                body1.RecalculateNormals();
                returnedMesh = body1;
            }
        }
        MeshRenderer.sharedMaterial = Material;

        return(returnedMesh);
    }