Пример #1
0
        public GameObject ToGameObject()
        {
            Poly2Mesh.Polygon polygon = this.Geometry.ToPolygonMesh();
            GameObject        go      = Poly2Mesh.CreateGameObject(polygon, this.FID);

            return(go);
        }
Пример #2
0
    void GenMesh(List <Vector3> myVerts, float gravityScale, int pushDir, Vector3 pos, Vector3 scale, float weight)
    {
        Poly2Mesh.Polygon poly = new Poly2Mesh.Polygon();
        poly.outside = myVerts;

        GameObject myObj = Poly2Mesh.CreateGameObject(poly);

        myObj.transform.position   = pos;
        myObj.transform.localScale = scale;
        myObj.gameObject.tag       = "Target";

        myObj.AddComponent <PolygonCollider2D>().points = myHelpers.L3ToV2(myVerts);

        myObj.GetComponent <Renderer>().material.shader      = Shader.Find("Sprites/Default");
        myObj.GetComponent <Renderer>().material.mainTexture = tex;

        Mesh myMesh = myObj.GetComponent <MeshFilter>().mesh;

        myMesh.uv = GetUV(myMesh.vertices);

        MeshScript meshScript = myObj.AddComponent <MeshScript>();

        meshScript.CurrentRotation = 0f;
        meshScript.OriginWeight    = weight;
        meshScript.OriginArea      = meshScript.MyArea = myHelpers.getArea(myObj);
        meshScript.MyCenter        = myHelpers.GetCentroid(myVerts);

        myObj.AddComponent <Rigidbody2D>().gravityScale = gravityScale;
    }
Пример #3
0
    private static void RegisterFloor(string localType, float lowestHeight, string lowestFaceName, Poly2Mesh.Polygon floorPolygon)
    {
        GameObject floorObj = Poly2Mesh.CreateGameObject(floorPolygon);

        floorObj.name = lowestHeight + "_" + lowestFaceName;

        // 하나의 솔리드에서 공간타입이 2개 이상 존재할 수는 없다
        ApplyCellSpaceMaterial(localType, floorObj);

        floorObj.transform.parent = CommonObjs.gmlRootFloor.transform;
    }
Пример #4
0
    void GenMeshSplit(Vector3[] parentVerts, Vector2[] parentUV, List <Vector3> myVerts, Vector3 centerInterPoint, Texture tex, float rotAngle, Vector2 parentVelocity, float parentGravity, float originArea, float originWeight)
    {
        Poly2Mesh.Polygon poly = new Poly2Mesh.Polygon();
        poly.outside = myVerts;
        GameObject myObj = Poly2Mesh.CreateGameObject(poly);

        myObj.gameObject.tag = "Target";

        Material myMat = myObj.GetComponent <Renderer>().material;

        myMat.shader      = Shader.Find("Sprites/Default");
        myMat.mainTexture = tex;

        Mesh myMesh = myObj.GetComponent <MeshFilter>().mesh;

        myMesh.uv = deductUV(parentVerts, parentUV, myMesh.vertices);


        MeshScript meshScript = myObj.AddComponent <MeshScript>();

        meshScript.ShowPerc        = ShowPercentage;
        meshScript.CurrentRotation = rotAngle;
        meshScript.OriginWeight    = originWeight;
        meshScript.OriginArea      = originArea;

        float myArea = myHelpers.getArea(myObj);

        meshScript.MyArea = myArea;

        meshScript.MyCenter = myHelpers.GetCentroid(myVerts);

        myObj.AddComponent <PolygonCollider2D>().points = myHelpers.L3ToV2(myVerts);

        Rigidbody2D myRB = myObj.AddComponent <Rigidbody2D>();

        myRB.gravityScale = parentGravity;

        myRB.velocity = parentVelocity;

        myRB.mass = (myArea * originWeight) / originArea;
        applyForceObj.MyRBS.Add(myRB);

        Vector3 myDir = myHelpers.GetCentroid(myVerts) - centerInterPoint;

        applyForceObj.MyDirs.Add(myDir.normalized);
    }
Пример #5
0
    private void OnCellSpaceBoundaryMember(XmlReader reader)
    {
        List <Vector2> localUVs = new List <Vector2>();

        Poly2Mesh.Polygon localPolygon  = new Poly2Mesh.Polygon();
        string            localFileName = string.Empty;
        string            localName     = string.Empty;

        while (isEndElement(reader, "cellSpaceBoundaryMember") == false)
        {
            reader.Read();

            if (string.IsNullOrWhiteSpace(localName))
            {
                reader.Read();
                localName = reader.GetAttribute("gml:id");
            }

            if (isStartElement(reader, "Polygon") || isStartElement(reader, "PolygonPatch"))
            {
                localPolygon = OnPolygon(reader);
            }

            if (isStartElement(reader, "TextureImage"))
            {
                reader.Read();
                localFileName = reader.Value;
            }

            if (isStartElement(reader, "TextureCoordinate"))
            {
                localUVs = new List <Vector2>();
                while (isEndElement(reader, "TextureCoordinate") == false)
                {
                    reader.Read();

                    if (isStartElement(reader, "pos"))
                    {
                        reader.Read();

                        localUVs.Add(GetPos2D(reader));
                    }
                }
            }

            if (isStartElement(reader, "OrientableSurface"))
            {
                // Now, Viewer shows always both of sides.
                // So nothing to do for viewing for other side.
                return;
            }
        }

        //tagStack.Pop();

        if (localUVs.Count() > 2)
        {
            localPolygon.outsideUVs = localUVs;
            localPolygon.holesUVs   = new List <List <Vector2> >();
            localPolygon.outsideUVs.Reverse();
        }

        localPolygon.outside.Reverse();

        for (int i = 0; i < localPolygon.holes.Count(); i++)
        {
            localPolygon.holes[i].Reverse();
            localPolygon.holesUVs.Add(new List <Vector2>());
        }

        // Texture 구멍 무시.
        if (string.IsNullOrWhiteSpace(localFileName) == false)
        {
            localPolygon.holes    = new List <List <Vector3> >();
            localPolygon.holesUVs = new List <List <Vector2> >();
        }

        GameObject cellSpaceBoundary = Poly2Mesh.CreateGameObject(localPolygon);

        cellSpaceBoundary.name = localName;

        if (string.IsNullOrWhiteSpace(localFileName))
        {
            // 일반 벽과 지오메트리 정보가 겹칠경우를 대비하여 앞쪽으로 조금 이동
            cellSpaceBoundary.transform.Translate(localPolygon.planeNormal * 0.01f);
        }
        else
        {
            //덱스쳐가 면별로 긴밀하게 붙어있는 경우 기둥사이가 보이는 현상이 발생하므로 적절히 수치를 조절하여 사용.
            //cellSpaceBoundary.transform.Translate(localPolygon.planeNormal * 0.005f);
        }

        if (string.IsNullOrWhiteSpace(localFileName) == false)
        {
            //Debug.Log(GetDirectoryName() + "\\" + localFileName);
            IEnumerator tmpRunner = ApplyTexture(cellSpaceBoundary, GetDirectoryName() + "\\" + localFileName);
            StartCoroutine(tmpRunner);
        }
        else
        {
            cellSpaceBoundary.GetComponent <Renderer>().material = CommonObjs.materialCellSpaceBoundary;
        }

        cellSpaceBoundary.tag = CommonObjs.TAG_CELLSPACEBOUNDARY;
        cellSpaceBoundary.transform.parent = CommonObjs.gmlRootCellSpaceBoundary.transform;
    }
Пример #6
0
    private void OnCellSpace(XmlReader reader)
    {
        GameObject solid = new GameObject();

        string localName = string.Empty;
        string localType = string.Empty;

        while (isEndElement(reader, "cellSpaceMember") == false)
        {
            reader.Read();

            if (string.IsNullOrWhiteSpace(localName))
            {
                reader.Read();
                localName = reader.GetAttribute("gml:id");
                localType = reader.LocalName;

                if (localType.Equals("TransitionSpace"))
                {
                    solid.tag = CommonObjs.TAG_TRANSITIONSPACE;
                    solid.transform.parent = CommonObjs.gmlRootTransitionSpace.transform;
                }
                else if (localType.Equals("GeneralSpace"))
                {
                    solid.tag = CommonObjs.TAG_GENERALSPACE;
                    solid.transform.parent = CommonObjs.gmlRootGeneralSpace.transform;
                }
                else
                {
                    solid.tag = CommonObjs.TAG_CELLSPACE;
                    solid.transform.parent = CommonObjs.gmlRootCellSpace.transform;
                }
            }

            if (isStartElement(reader, "Solid"))
            {
                int faceCnt = 1;
                solid.name = localName;
                reader.Read();

                float             lowestHeight   = float.MaxValue;
                string            lowestFaceName = "";
                Poly2Mesh.Polygon floorPolygon   = new Poly2Mesh.Polygon();

                while (isEndElement(reader, "Solid") == false)
                {
                    reader.Read();
                    if (isStartElement(reader, "Polygon") || isStartElement(reader, "PolygonPatch"))
                    {
                        Poly2Mesh.Polygon polygon    = OnPolygon(reader);
                        GameObject        genPolygon = Poly2Mesh.CreateGameObject(polygon);

                        genPolygon.name             = string.Format("{0}_Face:{1}", localName, faceCnt++);
                        genPolygon.transform.parent = solid.transform;

                        // 각 솔리드에서 가장 낮은 면을 바닥으로 잡음.
                        // 조금은 기울어진 바닥이라 할지라도 잡아낼 수 있게끔한게 의도.
                        // 현재까지의 모든 데이터는 바닥이 모두 평면으로 되어 있음.
                        float thisMinY = polygon.outside.Average(v => v.y);
                        if (thisMinY < lowestHeight)
                        {
                            lowestHeight   = thisMinY;
                            floorPolygon   = polygon;
                            lowestFaceName = localName;
                        }
                        ApplyCellSpaceMaterial(localType, genPolygon);
                    }
                }

                //RegisterFloor(localType, lowestHeight, lowestFaceName, floorPolygon);
            }
        }
    }
Пример #7
0
    public void CreateFace()
    {
        Action action = new Action(Nothing);

        if (selected.Count < 3)
        {
            Debug.Log("-----ERROR MUST BELONG SAME OBJECT-----");
            MobileNativePopups.OpenAlertDialog("Error", "Please select at least 3 vertices", "Cancel", action);
            return;
        }

        CADObject cadObject = selected [0].transform.parent.GetComponent <CADObject> ();

        string            objName = selected [0].transform.parent.name;
        List <GameObject> pool    = new List <GameObject> ();

        foreach (GameObject g in selected)
        {
            pool.Add(g);
            if (!g.transform.parent.name.Equals(objName))
            {
                Debug.Log("-----ERROR MUST BELONG SAME OBJECT-----");
                MobileNativePopups.OpenAlertDialog("Error", "Please select vertices that belong to the same object", "Cancel", action);
                return;
            }
        }

        GameObject startingPoint = pool [0];
        GameObject recent        = startingPoint;

        pool.Remove(startingPoint);

        List <GameObject> orderedList        = new List <GameObject> ();
        List <Vector3>    orderListPositions = new List <Vector3> ();

        orderedList.Add(recent);
        orderListPositions.Add(recent.transform.position);

        //action += Nothing;
        int toFind = pool.Count;

        while (true)
        {
            if (pool.Count == 0)
            {
                break;
            }

            GameObject found = null;
            foreach (GameObject checkNeighbor in pool)
            {
                HashSet <GameObject> key = new HashSet <GameObject> ();
                key.Add(checkNeighbor);
                key.Add(recent);
                if (cadObject.edges.ContainsKey(key))
                {
                    found = checkNeighbor;
                    toFind--;
                    break;
                }
            }

            if (found == null)
            {
                Debug.Log("-error form loop");
                MobileNativePopups.OpenAlertDialog("Error", "Please select vertices that form a single, complete loop", "Cancel", action);
                return;
            }
            else
            {
                recent = found;
                pool.Remove(found);
                orderedList.Add(found);
                orderListPositions.Add(found.transform.position);
            }
        }

        HashSet <GameObject> keyEnd = new HashSet <GameObject> ();

        keyEnd.Add(orderedList[0]);
        keyEnd.Add(orderedList[orderedList.Count - 1]);
        if (!cadObject.edges.ContainsKey(keyEnd))
        {
            Debug.Log("-error form loop");
            MobileNativePopups.OpenAlertDialog("Error", "Please select vertices that form a single, complete loop", "Cancel", action);
            return;
        }



        if (orderedList.Count != selected.Count)
        {
            Debug.Log("-error form loop");
            MobileNativePopups.OpenAlertDialog("Error", "You need to select vertices that form a single loop", "Cancel", action);
            return;
        }



        Poly2Mesh.Polygon poly = new Poly2Mesh.Polygon();
        poly.outside = orderListPositions;
        GameObject a = Poly2Mesh.CreateGameObject(poly);

        a.transform.parent = cadObject.gameObject.transform;
        a.GetComponent <Renderer> ().material = meshTexture;
        orderListPositions.Reverse();
        Poly2Mesh.Polygon poly2 = new Poly2Mesh.Polygon();
        poly2.outside = orderListPositions;
        GameObject a2 = Poly2Mesh.CreateGameObject(poly2);

        a2.transform.parent = cadObject.gameObject.transform;
        a2.GetComponent <Renderer> ().material = meshTexture;


        Debug.Log("CREATE FACE NOW");
        Debug.Log(orderedList.Count);
    }
    private void OnCellSpaceBoundaryMember(XmlReader reader)
    {
        List <Vector2> localUVs = new List <Vector2>();

        Poly2Mesh.Polygon localPolygon  = new Poly2Mesh.Polygon();
        string            localFileName = string.Empty;
        string            localName     = string.Empty;

        while (IsEndElement(reader, "cellSpaceBoundaryMember") == false)
        {
            reader.Read();

            if (string.IsNullOrWhiteSpace(localName))
            {
                reader.Read();
                localName = reader.GetAttribute("gml:id");
            }

            if (IsStartElement(reader, "Polygon") || IsStartElement(reader, "PolygonPatch"))
            {
                localPolygon = OnPolygon(reader);
            }

            if (IsStartElement(reader, "TextureImage"))
            {
                reader.Read();
                localFileName = reader.Value;
            }

            if (IsStartElement(reader, "TextureCoordinate"))
            {
                localUVs = new List <Vector2>();
                while (IsEndElement(reader, "TextureCoordinate") == false)
                {
                    reader.Read();

                    if (IsStartElement(reader, "pos"))
                    {
                        reader.Read();

                        localUVs.Add(GetPos2D(reader));
                    }
                }
            }
        }


        if (localUVs.Count() > 2)
        {
            localPolygon.outsideUVs = localUVs;
            localPolygon.holesUVs   = new List <List <Vector2> >();
            localPolygon.outsideUVs.Reverse();
        }

        localPolygon.outside.Reverse();

        for (int i = 0; i < localPolygon.holes.Count(); i++)
        {
            localPolygon.holes[i].Reverse();
            localPolygon.holesUVs.Add(new List <Vector2>());
        }

        // Texture 구멍 무시.
        if (string.IsNullOrWhiteSpace(localFileName) == false)
        {
            localPolygon.holes    = new List <List <Vector3> >();
            localPolygon.holesUVs = new List <List <Vector2> >();
        }

        GameObject cellSpaceBoundary = Poly2Mesh.CreateGameObject(localPolygon, true);

        cellSpaceBoundary.name = localName;
        cellSpaceBoundary.GetComponent <MeshCollider>().enabled   = true;
        cellSpaceBoundary.GetComponent <MeshCollider>().convex    = true;
        cellSpaceBoundary.GetComponent <MeshCollider>().isTrigger = true;


        if (string.IsNullOrWhiteSpace(localFileName))
        {
            cellSpaceBoundary.transform.Translate(localPolygon.planeNormal * 0.01f);
        }
        else
        {
            //cellSpaceBoundary.transform.Translate(localPolygon.planeNormal * 0.005f);
        }

        if (string.IsNullOrWhiteSpace(localFileName) == false)
        {
            //Debug.Log(GetDirectoryName() + "\\" + localFileName);
            IEnumerator tmpRunner = ApplyTexture(cellSpaceBoundary, Path.GetDirectoryName(fileUrl) + "\\" + localFileName);
            StartCoroutine(tmpRunner);
        }
        else
        {
            cellSpaceBoundary.GetComponent <Renderer>().material = CommonObjs.materialCellSpaceBoundary;
        }

        cellSpaceBoundary.tag = CommonObjs.TAG_CELLSPACEBOUNDARY;
        cellSpaceBoundary.transform.parent = CommonObjs.gmlRootCellSpaceBoundary.transform;
    }
    private void OnCellSpace(XmlReader reader) //read room data
    {
        GameObject solid = new GameObject();

        string     cellname  = null;
        string     localType = null;
        GameObject genPolygon;
        bool       isWorkshop = false;


        while (IsEndElement(reader, "cellSpaceMember") == false)
        {
            reader.Read();

            if (string.IsNullOrWhiteSpace(localType))
            {
                reader.Read();
                localType = reader.GetAttribute("gml:id");

                if (localType.Equals("TransitionSpace"))
                {
                    solid.tag = CommonObjs.TAG_TRANSITIONSPACE;
                    solid.transform.parent = CommonObjs.gmlRootTransitionSpace.transform;
                }
                else if (localType.Equals("GeneralSpace"))
                {
                    solid.tag = CommonObjs.TAG_GENERALSPACE;
                    solid.transform.parent = CommonObjs.gmlRootGeneralSpace.transform;
                }
                else
                {
                    solid.tag = CommonObjs.TAG_CELLSPACE;
                    solid.transform.parent = CommonObjs.gmlRootCellSpace.transform;
                }
            }

            if (IsStartElement(reader, "name"))
            {
                cellname   = reader.ReadInnerXml();
                isWorkshop = cellname.Contains("Workshop");
            }

            if (IsStartElement(reader, "Solid"))
            {
                int faceCnt = 1;
                solid.name = cellname;

                reader.Read();
                while (IsEndElement(reader, "Solid") == false)
                {
                    reader.Read();
                    if (IsStartElement(reader, "Polygon") || IsStartElement(reader, "PolygonPatch"))
                    {
                        var polygon = OnPolygon(reader);
                        genPolygon = Poly2Mesh.CreateGameObject(polygon, isWorkshop);

                        genPolygon.name = string.Format("{0}_Face:{1}", localType, faceCnt++);

                        genPolygon.transform.parent = solid.transform;

                        if (localType.Equals("TransitionSpace"))
                        {
                            genPolygon.GetComponent <Renderer>().material = CommonObjs.machineFront;
                        }
                        else if (localType.Equals("GeneralSpace"))
                        {
                            genPolygon.GetComponent <Renderer>().material = CommonObjs.materialGeneralSpace;
                        }
                        if (isWorkshop)
                        {
                            genPolygon.GetComponent <Renderer>().material = CommonObjs.materialWorkshop;
                            workshopObjects.Add(genPolygon);
                        }
                        else
                        {
                            genPolygon.GetComponent <Renderer>().material = CommonObjs.materialCellSpace;
                        }
                    }

                    #region machines

                    if (IsStartElement(reader, "Objects"))
                    {
                        while (IsEndElement(reader, "Objects") == false)
                        {
                            reader.Read();


                            if (IsStartElement(reader, "Machine")) //read machine data
                            {
                                string   machineName  = reader.GetAttribute("name");
                                string[] machineState = new string[2];

                                if (reader.GetAttribute("extRef") == "true")
                                {
                                    reader.Read();
                                    Vector3 machinePosition = new Vector3();

                                    string machineFileURL = fileUrl;
                                    string machineFileName;

                                    machineFileURL = machineFileURL.Substring(8);
                                    string last            = machineFileURL[machineFileURL.Length - 1].ToString();
                                    float  machineRotation = 0;

                                    while (last != @"/") //delete IndoorGML Filename from URL
                                    {
                                        machineFileURL = machineFileURL.TrimEnd(machineFileURL[machineFileURL.Length - 1]);
                                        last           = machineFileURL[machineFileURL.Length - 1].ToString();
                                    }

                                    while (IsEndElement(reader, "Machine") == false)
                                    {
                                        reader.Read();

                                        if (IsStartElement(reader, "ref"))
                                        {
                                            while (IsEndElement(reader, "ref") == false)
                                            {
                                                reader.Read();

                                                if (IsStartElement(reader, "objectfile"))
                                                {
                                                    machineFileName = reader.GetAttribute("file");
                                                    refFileURL      = machineFileURL + machineFileName + "/";
                                                    machineFileURL += machineFileName + "/" + machineFileName + ".obj";
                                                }

                                                if (IsStartElement(reader, "picture"))
                                                {
                                                    machineRefs.Add(new string[4] {
                                                        machineName, "picture", null, refFileURL + reader.GetAttribute("file")
                                                    });
                                                }

                                                if (IsStartElement(reader, "documents"))
                                                {
                                                    while (IsEndElement(reader, "documents") == false)
                                                    {
                                                        reader.Read();

                                                        if (IsStartElement(reader, "document"))
                                                        {
                                                            machineRefs.Add(new string[4] {
                                                                machineName, "document", reader.GetAttribute("name"), refFileURL + reader.GetAttribute("file")
                                                            });
                                                        }
                                                    }
                                                }
                                            }
                                        }

                                        if (IsStartElement(reader, "pos"))
                                        {
                                            reader.Read();
                                            machinePosition = GetPos3D(reader);
                                        }

                                        if (IsStartElement(reader, "rot"))
                                        {
                                            float.TryParse(reader.ReadInnerXml(), out machineRotation);
                                        }

                                        if (IsStartElement(reader, "partialboundedBy"))
                                        {
                                            machineState[1] = reader.GetAttribute("xlink:href");
                                        }
                                    }

                                    GameObject machineObj = new GameObject {
                                        name = machineName
                                    };

                                    machineObj.AddComponent(typeof(MeshRenderer));
                                    MeshFilter  filter   = machineObj.AddComponent(typeof(MeshFilter)) as MeshFilter;
                                    ObjImporter importer = new ObjImporter();
                                    Mesh        mesh     = importer.ImportFile(machineFileURL);
                                    filter.mesh = mesh;
                                    mesh.RecalculateNormals();

                                    machineObj.AddComponent(typeof(MeshCollider));
                                    machineObj.GetComponent <MeshCollider>().sharedMesh = mesh;
                                    machineObj.GetComponent <MeshCollider>().convex     = true;
                                    machineObj.transform.position         = machinePosition;
                                    machineObj.transform.localScale       = new Vector3(0.001f, 0.001f, 0.001f);
                                    machineObj.transform.localEulerAngles = new Vector3(0, machineRotation, 0);

                                    machineObj.transform.parent = solid.transform;
                                    Assembly asm  = Assembly.Load("Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null");
                                    Type     type = asm.GetType("MachineStatus");
                                    machineObj.AddComponent(type);
                                    machines.Add(machineObj);

                                    if (inspection)
                                    {
                                        machineState[0] = machineName;
                                        machineStates.Add(machineState);
                                        machineObj.GetComponent <Renderer>().material = Resources.Load("Materials/Machine_INSPECTION", typeof(Material)) as Material;

                                        foreach (Dropdown dropdown in machineChoiceOption)
                                        {
                                            dropdown.options.Add(new Dropdown.OptionData()
                                            {
                                                text = machineName
                                            });
                                        }
                                    }
                                }
                            }
                        }
                    }
                    #endregion
                }
            }

            if (IsStartElement(reader, "partialboundedBy"))
            {
                string[] boundedBy = new string[2];
                boundedBy[0] = localType;
                boundedBy[1] = reader.GetAttribute("xlink:href");

                if (!inspection)
                {
                    player.GetComponent <PlayerController>().roomBoundaries.Add(boundedBy);
                }
            }
        }
    }
Пример #10
0
    //End m2



    public void Generation()
    {
        if (points.Count >= 3)
        {
            points.Add(points[0]);

            lineRenderer.positionCount += 1;
            lineRenderer.SetPosition(transform.childCount - 1, lineRenderer.GetPosition(0));

            Poly2Mesh.Polygon poly = new Poly2Mesh.Polygon();
            poly.outside = points;

            // Set up game object with mesh;

            GameObject gob = new GameObject();
            gob.name = "Polygon";
            gob.tag  = "Polygon";
            gob.AddComponent(typeof(MeshRenderer));
            MeshFilter filter = gob.AddComponent(typeof(MeshFilter)) as MeshFilter;

            GameObject polyMesh = Poly2Mesh.CreateGameObject(poly);
            filter.mesh = polyMesh.GetComponent <MeshFilter>().mesh;

            if (filter != null)
            {
                Mesh mesh2 = filter.mesh;

                Vector3[] normals = mesh2.normals;
                for (int i = 0; i < normals.Length; i++)
                {
                    normals[i] = -normals[i];
                }
                mesh2.normals = normals;

                for (int m = 0; m < mesh2.subMeshCount; m++)
                {
                    int[] triangles = mesh2.GetTriangles(m);
                    for (int i = 0; i < triangles.Length; i += 3)
                    {
                        int temp = triangles[i + 0];
                        triangles[i + 0] = triangles[i + 1];
                        triangles[i + 1] = temp;
                    }
                    mesh2.SetTriangles(triangles, m);
                }
            }

            //gob.AddComponent<BoxCollider>().size = new Vector3(1f, 1f, 0.001f);

            //m2
            areaSum          = AreaOfMesh(polyMesh.GetComponent <MeshFilter>().sharedMesh);
            xyArea           = areaSum;
            txt_areaSum.text = "~ " + areaSum.ToString("#.##") + " m2";
            if (areaSum < 1)
            {
                txt_areaSum.text = "~ 0" + areaSum.ToString("#.##") + " m2";
            }
            _changeMaterial.work = true;
            start = true;

            lineRenderer.positionCount = 0;
            punkDot.positionCount      = 0;
            ClearAllDots();
            _changeMaterial.Material1();
            _swipeAnim.UpSwipe();


            first_Toturial = false;

            _TextBox_3.SetActive(false);
            _TextBox_1.SetActive(false);
            _TextBox_2.SetActive(false);
            _TextBox_4.SetActive(false);

            first_Box_1 = false;
            first_Box_2 = false;
            first_Box_3 = false;
            first_Box_4 = false;

            _ToturialUI.SetActive(false);
        }
    }
Пример #11
0
    private void OnCellSpace(XmlReader reader)
    {
        GameObject solid = new GameObject();

        string localName = string.Empty;
        string localType = string.Empty;

        while (isEndElement(reader, "cellSpaceMember") == false)
        {
            reader.Read();

            if (string.IsNullOrWhiteSpace(localName))
            {
                reader.Read();
                localName = reader.GetAttribute("gml:id");
                localType = reader.LocalName;

                if (localType.Equals("TransitionSpace"))
                {
                    solid.tag = CommonObjs.TAG_TRANSITIONSPACE;
                    solid.transform.parent = CommonObjs.gmlRootTransitionSpace.transform;
                }
                else if (localType.Equals("GeneralSpace"))
                {
                    solid.tag = CommonObjs.TAG_GENERALSPACE;
                    solid.transform.parent = CommonObjs.gmlRootGeneralSpace.transform;
                }
                else
                {
                    solid.tag = CommonObjs.TAG_CELLSPACE;
                    solid.transform.parent = CommonObjs.gmlRootCellSpace.transform;
                }
            }

            if (isStartElement(reader, "Solid"))
            {
                int faceCnt = 1;
                solid.name = localName;
                reader.Read();
                while (isEndElement(reader, "Solid") == false)
                {
                    reader.Read();
                    if (isStartElement(reader, "Polygon") || isStartElement(reader, "PolygonPatch"))
                    {
                        var        polygon    = OnPolygon(reader);
                        GameObject genPolygon = Poly2Mesh.CreateGameObject(polygon);
                        genPolygon.name = string.Format("{0}_Face:{1}", localName, faceCnt++);

                        genPolygon.transform.parent = solid.transform;

                        if (localType.Equals("TransitionSpace"))
                        {
                            genPolygon.GetComponent <Renderer>().material = CommonObjs.materialTransitionSpace;
                        }
                        else if (localType.Equals("GeneralSpace"))
                        {
                            genPolygon.GetComponent <Renderer>().material = CommonObjs.materialGeneralSpace;
                        }
                        else
                        {
                            // CellSpace
                            genPolygon.GetComponent <Renderer>().material = CommonObjs.materialCellSpace;
                        }
                    }
                }
            }
        }
    }
Пример #12
0
        public static GameObject PolyToMesh(XmlReader reader, string id, CityGml2GO cityGml2Go, SemanticType semanticType = null)
        {
            var extPositions = new List <Vector3>();
            var intPositions = new List <List <Vector3> >();
            var polyName     = "";

            while (reader.MoveToNextAttribute())
            {
                if (reader.LocalName == "id")
                {
                    polyName = reader.Value;
                }
            }

            while (reader.Read())
            {
                if (((IXmlLineInfo)reader).LineNumber >= 14459)
                {
                    int idfg = 0;
                }
                if (string.IsNullOrEmpty(polyName))
                {
                    while (reader.MoveToNextAttribute())
                    {
                        if (reader.LocalName == "id")
                        {
                            polyName = reader.Value;
                        }
                    }
                }

                if (reader.NodeType == XmlNodeType.Element && reader.LocalName == "exterior")
                {
                    while (reader.Read())
                    {
                        if (reader.NodeType == XmlNodeType.Element && reader.LocalName == "posList")
                        {
                            var range = PositionHandler.GetPosList(reader, cityGml2Go.ActualTranslate);
                            if (range != null)
                            {
                                extPositions.AddRange(range);
                            }
                        }

                        if (reader.NodeType == XmlNodeType.Element && reader.LocalName == "pos")
                        {
                            extPositions.Add(PositionHandler.GetPos(reader, cityGml2Go.ActualTranslate));
                        }

                        if (reader.NodeType == XmlNodeType.EndElement && reader.LocalName == "exterior")
                        {
                            break;
                        }
                    }
                }

                if (reader.NodeType == XmlNodeType.Element && reader.LocalName == "interior")
                {
                    var curInt = new List <Vector3>();
                    while (reader.Read())
                    {
                        if (reader.NodeType == XmlNodeType.Element && reader.LocalName == "posList")
                        {
                            var range = PositionHandler.GetPosList(reader, cityGml2Go.ActualTranslate);
                            if (range != null)
                            {
                                curInt.AddRange(range);
                            }
                        }

                        if (reader.NodeType == XmlNodeType.Element && reader.LocalName == "pos")
                        {
                            curInt.Add(PositionHandler.GetPos(reader, cityGml2Go.ActualTranslate));
                        }
                        if (reader.NodeType == XmlNodeType.EndElement && reader.LocalName == "interior")
                        {
                            break;
                        }
                    }
                    intPositions.Add(curInt);
                }
                if (reader.NodeType == XmlNodeType.EndElement && reader.LocalName == "Polygon")
                {
                    break;
                }
            }

            var lastPoint = extPositions.Last();

            //extPositions = extPositions.Distinct().ToList();
            extPositions.Add(lastPoint);

            for (var index = 0; index < intPositions.Count; index++)
            {
                lastPoint = intPositions[index].Last();
                //intPositions[index] = intPositions[index].Distinct().ToList();
                intPositions[index].Add(lastPoint);
            }


            if (!PolygonHandler.IsPolyValid(extPositions))
            {
                IXmlLineInfo xmlInfo    = (IXmlLineInfo)reader;
                int          lineNumber = xmlInfo.LineNumber;
                Debug.Log(lineNumber);
                return(null);
            }

            foreach (var intRing in intPositions)
            {
                if (!IsPolyValid(intRing))
                {
                    IXmlLineInfo xmlInfo    = (IXmlLineInfo)reader;
                    int          lineNumber = xmlInfo.LineNumber;
                    Debug.Log(lineNumber);
                    return(null);
                }
            }

            var polygon = new Poly2Mesh.Polygon();

            extPositions.Reverse();
            intPositions.Reverse();

            polygon.outside = extPositions;
            polygon.holes   = intPositions;

            GameObject go = null;

            try
            {
                go = Poly2Mesh.CreateGameObject(polygon, string.IsNullOrEmpty(polyName) ? id : polyName);
            }
            catch (Exception ex)
            {
                Debug.Log(ex);
            }

            if (cityGml2Go.GenerateColliders)
            {
                //go.AddComponent<MeshCollider>();
            }

            if (go != null)
            {
                if (cityGml2Go.Semantics && semanticType != null)
                {
                    SemanticsHandler.HandleSemantics(go, semanticType, cityGml2Go);
                }
                else if (cityGml2Go.DefaultMaterial != null)
                {
                    var mr = go.GetComponent <MeshRenderer>();
                    if (mr != null)
                    {
                        mr.sharedMaterial = cityGml2Go.DefaultMaterial;
                    }
                }
            }

            cityGml2Go.Polygons.Add(go);

            return(go);
        }