Ejemplo n.º 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;
    }
Ejemplo n.º 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;
    }
Ejemplo n.º 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;
        }
Ejemplo n.º 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;
    }
Ejemplo n.º 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();
            }
        }