Exemplo n.º 1
0
    void Awake()
    {
        /* ADD:
         * - Сжатие файлов
         * - Фоновые генерация, сохранение, чтение (корутины + флаг статуса)
         * - Функции динамической деформации базового mesh синхронно с wireframe
         * - Затупление наружных углов wireframe, если они длиннее заданного порога
         */

        WireframeVT wireframeVT       = new WireframeVT();
        string      wireframeFileName = Application.streamingAssetsPath + "/" + name + "." + nameExt;

        if ((useSerialize) && (File.Exists(wireframeFileName)))
        {
            Debug.Log("Load wireframe from " + wireframeFileName);

            BinaryFormatter bf   = new BinaryFormatter();
            FileStream      file = File.Open(wireframeFileName, FileMode.Open);
            wireframeVT = (WireframeVT)bf.Deserialize(file);
        }
        else
        {
            Debug.Log("Create wireframe for " + name);

            CalcDataWireframeByMesh(GetComponent <MeshFilter>().mesh);
            MakeWireframe(wireframeVT);

            if (useSerialize)
            {
                Debug.Log("Save wireframe to " + wireframeFileName);

                BinaryFormatter bf   = new BinaryFormatter();
                FileStream      file = File.Create(wireframeFileName);
                bf.Serialize(file, wireframeVT);
                file.Close();
            }
        }

        GameObject Go = new GameObject();

        Go.transform.position   = transform.position;
        Go.transform.rotation   = transform.rotation;
        Go.transform.localScale = transform.lossyScale;
        Go.transform.parent     = transform;
        Go.name = name + "_" + nameExt;

        Go.AddComponent <MeshFilter>().mesh       = wireframeVT.CreateMesh();
        Go.AddComponent <MeshRenderer>().material = wireMaterial;
    }
Exemplo n.º 2
0
    private void MakeWireframe(WireframeVT outVT)
    {
        edges  = new List <List <Edge> >();
        chains = new List <TChain>();

        // Create Faces
        int indEmptyTr = 0;
        int numFaces   = 0;

        do
        {
            edges.Add(new List <Edge>());
            MakeFace(indEmptyTr, numFaces++, null);
            indEmptyTr = FindEmptyTr();
        } while (indEmptyTr != -1);

        // Create Edges Chains
        int numChains = 0;

        for (int i = 0; i < edges.Count; i++)
        {
            int indEmptyEdge = 0;
            do
            {
                chains.Add(new TChain {
                    chainNodes = new List <Node>()
                });
                MakeChain(numChains++, i, indEmptyEdge, edges[i][indEmptyEdge].side.a);
                indEmptyEdge = FindEmptyEdge(i);
            } while (indEmptyEdge != -1);
        }

        for (int i = 0; i < chains.Count; i++)
        {
            // Calculate Wireframe Points

            int lastNode = chains[i].chainNodes.Count - 1;

            TLine offsLineFirst = new TLine();
            offsLineFirst = GetOffsetLine(chains[i].chainNodes[0]);

            TLine offsLinePrev = new TLine();
            offsLinePrev = offsLineFirst;

            TLine offsLineLast = new TLine();
            offsLineLast = GetOffsetLine(chains[i].chainNodes[lastNode]);

            Vector3 vCrossFirst = new Vector3();
            vCrossFirst = GetLinesCrossPoint(GetOffsetLine(chains[i].chainNodes[0]), offsLineLast);

            Vector3 vCrossA = new Vector3();
            vCrossA = vCrossFirst;

            TLine   offsLineNext = new TLine();
            Vector3 vCrossB      = new Vector3();

            for (int j = 0; j < lastNode; j++)
            {
                if ((j + 1) < lastNode)
                {
                    offsLineNext = GetOffsetLine(chains[i].chainNodes[j + 1]);
                }
                else
                {
                    offsLineNext = offsLineLast;
                }

                vCrossB = GetLinesCrossPoint(offsLinePrev, offsLineNext);

                chains[i].chainNodes[j].wfVertA = vCrossA;
                chains[i].chainNodes[j].wfVertB = vCrossB;

                offsLinePrev = offsLineNext;
                vCrossA      = vCrossB;
            }

            chains[i].chainNodes[lastNode].wfVertA = vCrossB;
            chains[i].chainNodes[lastNode].wfVertB = vCrossFirst;

            // Make Result Verts and Tris
            for (int j = 0; j < chains[i].chainNodes.Count; j++)
            {
                int indA1 = outVT.VerticeFindOrAdd(arrVerts[chains[i].chainNodes[j].indVerts.a]);
                int indB1 = outVT.VerticeFindOrAdd(arrVerts[chains[i].chainNodes[j].indVerts.b]);
                int indA2 = outVT.VerticeFindOrAdd(chains[i].chainNodes[j].wfVertA);
                int indB2 = outVT.VerticeFindOrAdd(chains[i].chainNodes[j].wfVertB);

                outVT.AddTr(indA2, indA1, indB1);
                outVT.AddTr(indB1, indB2, indA2);
            }
        }
    }