Ejemplo n.º 1
0
    public GameObject DrawCeiling3D()
    {
        GameObject polyExtruderGO = new GameObject();

        PolyExtruder polyExtruder = polyExtruderGO.AddComponent <PolyExtruder>();

        polyExtruderGO.name = "TEST EXTRUDER";

        var vertices2D = Points.Select(v => new Vector2(v.x, v.y)).ToArray();

        polyExtruder.createPrism(polyExtruderGO.name, 0.2f, vertices2D, Color.grey, true);

        polyExtruderGO.transform.Translate(new Vector3(2000, LevelBottom, 0), Space.World);

        polyExtruder.prismColor = Color.blue;

        // Combine meshes
        MeshFilter[] allMesheFilters = polyExtruderGO.GetComponentsInChildren <MeshFilter>();

        var mesh = CombineMeshes(allMesheFilters.ToList());

        if (Vertices3D != null && Vertices3D.Length > 0)
        {
            mesh.uv = UvCalculator.CalculateUVs(Vertices3D, 1);
        }
        mesh.RecalculateNormals();

        GameObject newObj = new GameObject();

        newObj.name = Name;

        newObj.transform.position   = polyExtruderGO.transform.position;
        newObj.transform.rotation   = polyExtruderGO.transform.rotation;
        newObj.transform.localScale = polyExtruderGO.transform.localScale;

        var newObjMeshFilter   = newObj.AddComponent <MeshFilter>();
        var newObjMeshRenderer = newObj.AddComponent <MeshRenderer>();

        newObjMeshFilter.mesh       = mesh;
        newObjMeshRenderer.material = Material;

        newObj.AddComponent <MeshCollider>();
        newObj.tag = "Ceiling";

        DestroyImmediate(polyExtruderGO);

        var refInstance3D = Instance3D;

        if (refInstance3D != null)
        {
            DestroyImmediate(refInstance3D);
        }

        newObj.layer            = LayerMask.NameToLayer("3DArea");
        newObj.transform.parent = GameObject.Find("3DArea").transform;

        Instance3D = newObj;

        return(newObj);
    }
Ejemplo n.º 2
0
    void Start()
    {
        // create new GameObject (as a child)
        GameObject polyExtruderGO = new GameObject();

        polyExtruderGO.transform.parent = this.transform;

        // add PolyExtruder script to newly created GameObject and keep track of its reference
        polyExtruder = polyExtruderGO.AddComponent <PolyExtruder>();

        // run poly extruder according to selected example data
        switch (exampleData)
        {
        case ExampleData.Triangle:
            polyExtruderGO.name = "Triangle";
            polyExtruder.createPrism(polyExtruderGO.name, extrusionHeight, MeshDataTriangle, Color.grey, is3D);
            break;

        case ExampleData.Square:
            polyExtruderGO.name = "Square";
            polyExtruder.createPrism(polyExtruderGO.name, extrusionHeight, MeshDataSquare, Color.grey, is3D);
            break;

        case ExampleData.Cross:
            polyExtruderGO.name = "Cross";
            polyExtruder.createPrism(polyExtruderGO.name, extrusionHeight, MeshDataCross, Color.grey, is3D);
            break;

        default:
        case ExampleData.SCB_Gotland:
            polyExtruderGO.name = "SCB_Kommun_RT90_Gotland";
            polyExtruder.createPrism(polyExtruderGO.name, extrusionHeight, MeshDataGotland, Color.grey, is3D);
            break;
        }
    }
Ejemplo n.º 3
0
    private void Awake()
    {
        polyExtruderGO = new GameObject();
        polyExtruderGO.transform.SetParent(this.transform);

// add PolyExtruder script to newly created GameObject,
// keep track of its reference, and name it
        polyExtruder        = polyExtruderGO.AddComponent <PolyExtruder>();
        polyExtruderGO.name = "CarMesh";

// run poly extruder according to input data
        polyExtruder.createPrism(polyExtruderGO.name, .5f, points, Color.grey, true);
    }
    void Start()
    {
        polyExtruderGO  = new GameObject();
        polyExtruderGO2 = new GameObject();
        polyExtruderGO3 = new GameObject();
        polyExtruderGO4 = new GameObject();
        polyExtruderGO5 = new GameObject();


        polyExtruderGO.transform.parent  = this.transform;
        polyExtruderGO2.transform.parent = this.transform;
        polyExtruderGO3.transform.parent = this.transform;
        polyExtruderGO4.transform.parent = this.transform;
        polyExtruderGO5.transform.parent = this.transform;

        // add PolyExtruder script to newly created GameObject and keep track of its reference
        polyExtruder  = polyExtruderGO.AddComponent <PolyExtruder>();
        polyExtruder2 = polyExtruderGO2.AddComponent <PolyExtruder>();
        polyExtruder3 = polyExtruderGO3.AddComponent <PolyExtruder>();
        polyExtruder4 = polyExtruderGO4.AddComponent <PolyExtruder>();
        polyExtruder5 = polyExtruderGO5.AddComponent <PolyExtruder>();

        polyExtruderGO.name  = "Polygon1";
        polyExtruderGO2.name = "Polygon2";
        polyExtruderGO3.name = "Polygon3";
        polyExtruderGO4.name = "Polygon4";
        polyExtruderGO5.name = "Polygon5";


        polyExtruder.createPrism(polyExtruderGO.name, extrusionHeight, Polygon1, Color.grey, is3D, "1");
        polyExtruder2.createPrism(polyExtruderGO2.name, extrusionHeight, Polygon2, Color.grey, is3D, "2");
        polyExtruder3.createPrism(polyExtruderGO3.name, extrusionHeight, Polygon3, Color.grey, is3D, "3");
        polyExtruder4.createPrism(polyExtruderGO4.name, extrusionHeight, Polygon4, Color.grey, is3D, "4");
        polyExtruder5.createPrism(polyExtruderGO5.name, extrusionHeight, Polygon5, Color.grey, is3D, "5");


        //string localPath = "Assets/" + polyExtruderGO.name + ".prefab";

        //localPath = AssetDatabase.GenerateUniqueAssetPath(localPath);

        //PrefabUtility.SaveAsPrefabAssetAndConnect(polyExtruderGO, localPath, InteractionMode.UserAction);



        //Object prefab2 = EditorUtility.CreateEmptyPrefab("Assets/"+polyExtruderGO2.name+".prefab");
        //EditorUtility.ReplacePrefab(polyExtruderGO2, prefab2, ReplacePrefabOptions.ConnectToPrefab);

        //Object prefab3 = EditorUtility.CreateEmptyPrefab("Assets/"+polyExtruderGO3.name+".prefab"//);
        //EditorUtility.ReplacePrefab(polyExtruderGO3, prefab3, ReplacePrefabOptions.ConnectToPrefab)//;

        //Object prefab4 = EditorUtility.CreateEmptyPrefab("Assets/"+polyExtruderGO4.name+".prefab");
        //EditorUtility.ReplacePrefab(polyExtruderGO4, prefab4, ReplacePrefabOptions.ConnectToPrefab);

        //Object prefab5 = EditorUtility.CreateEmptyPrefab("Assets/"+polyExtruderGO5.name+".prefab");
        //EditorUtility.ReplacePrefab(polyExtruderGO5, prefab5, ReplacePrefabOptions.ConnectToPrefab);

        //polyExtruderGO.transform.localScale = new Vector3(-1,60,1);
        //polyExtruderGO2.transform.localScale = new Vector3(-1,60,1);
        //polyExtruderGO3.transform.localScale = new Vector3(-1,60,1);
        //polyExtruderGO4.transform.localScale = new Vector3(-1,60,1);
        //polyExtruderGO5.transform.localScale = new Vector3(-1,60,1);

        //polyExtruderGO.transform.position = new Vector3(0,0.125f,0);
        //polyExtruderGO2.transform.position = new Vector3(0,0.125f,0);
        //polyExtruderGO3.transform.position = new Vector3(0,0.125f,0);
        //polyExtruderGO4.transform.position = new Vector3(0,0.125f,0);
        //polyExtruderGO5.transform.position = new Vector3(0,0.125f,0);

        //polyExtruderGO.transform.Rotate(90,0,0);
        //polyExtruderGO2.transform.Rotate(90,0,0);
        //polyExtruderGO3.transform.Rotate(90,0,0);
        //polyExtruderGO4.transform.Rotate(90,0,0);
        //polyExtruderGO5.transform.Rotate(90,0,0);
    }
Ejemplo n.º 5
0
    void GenerateGeometry(DataTable dataTable)
    {
        GameObject parent = new GameObject("Geodata");

        for (int i = 0; i < dataTable.Rows.Count; i++)
        {
            string polygonText = dataTable.Rows[i].ItemArray[1].ToString().Replace("MULTIPOLYGON(((", "");
            polygonText = polygonText.Replace(")))", "");
            //Debug.Log(polygonText);
            string[] coords = polygonText.Split(',');
            //Debug.Log("Coords " + coords.Length);

            List <Vector3> vertices   = new List <Vector3>();
            List <Vector2> vertices2d = new List <Vector2>();
            for (int j = 0; j < coords.Length - 1; j++)
            {
                coords[j] = coords[j].Replace(".", ",");
                string[] latlonS = coords[j].Split(' ');

                try
                {
                    Vector2d latlon = new Vector2d(double.Parse(latlonS[1]), double.Parse(latlonS[0]));
                    //Debug.Log(latlon.ToString());
                    Vector3 point = map.GeoToWorldPosition(latlon, false);
                    vertices.Add(new Vector3(point.x, point.z, 0));
                    vertices2d.Add(new Vector2(point.x, point.z));
                }
                catch (Exception msg)
                {
                    Debug.Log(msg.ToString());
                }
            }

            float height = 0;
            try
            {
                height = float.Parse(dataTable.Rows[i].ItemArray[2].ToString());
            }
            catch (Exception msg)
            {
                Debug.Log(msg.ToString());
            }

            //------------Generate Mesh------------//
            //vertices2d.Reverse();
            //Mesh mesh = CreateMesh(vertices2d.ToArray(), height);
            TriangulatorSimple triangulator = new TriangulatorSimple(vertices2d.ToArray());
            int[] indices = triangulator.Triangulate();
            //Mesh mesh = new Mesh();
            //mesh.vertices = vertices.ToArray();
            //mesh.triangles = indices;
            //mesh.RecalculateNormals();
            //mesh.RecalculateBounds();
            //mesh.Optimize();

            bool         is3D         = true;
            GameObject   obj          = new GameObject(i.ToString());
            PolyExtruder polyExtruder = obj.AddComponent <PolyExtruder>();
            polyExtruder.createPrism(obj.name, height, vertices2d.ToArray(), Color.white, is3D);
            obj.AddComponent <MeshRenderer>();
            //obj.AddComponent<MeshFilter>();
            //obj.GetComponent<MeshFilter>().mesh = mesh;
            obj.GetComponent <MeshRenderer>().material = mat;
            //obj.transform.localEulerAngles += new Vector3(90, 0, 0);
            obj.transform.parent = parent.transform;
        }
    }
    public void OnTrackableStateChanged(TrackableBehaviour.Status previousStatus, TrackableBehaviour.Status newStatus)
    {
        if (newStatus == TrackableBehaviour.Status.DETECTED ||
            newStatus == TrackableBehaviour.Status.TRACKED ||
            newStatus == TrackableBehaviour.Status.EXTENDED_TRACKED)
        {
            // create new GameObject (as a child)
            if (!created)
            {
                polyExtruderGO  = new GameObject();
                polyExtruderGO2 = new GameObject();
                polyExtruderGO3 = new GameObject();
                polyExtruderGO4 = new GameObject();
                polyExtruderGO5 = new GameObject();


                polyExtruderGO.transform.parent  = this.transform;
                polyExtruderGO2.transform.parent = this.transform;
                polyExtruderGO3.transform.parent = this.transform;
                polyExtruderGO4.transform.parent = this.transform;
                polyExtruderGO5.transform.parent = this.transform;

                // add PolyExtruder script to newly created GameObject and keep track of its reference
                polyExtruder  = polyExtruderGO.AddComponent <PolyExtruder>();
                polyExtruder2 = polyExtruderGO2.AddComponent <PolyExtruder>();
                polyExtruder3 = polyExtruderGO3.AddComponent <PolyExtruder>();
                polyExtruder4 = polyExtruderGO4.AddComponent <PolyExtruder>();
                polyExtruder5 = polyExtruderGO5.AddComponent <PolyExtruder>();

                polyExtruderGO.name  = "Polygon1";
                polyExtruderGO2.name = "Polygon2";
                polyExtruderGO3.name = "Polygon3";
                polyExtruderGO4.name = "Polygon4";
                polyExtruderGO5.name = "Polygon5";


                polyExtruder.createPrism(polyExtruderGO.name, extrusionHeight, Polygon1, Color.grey, is3D, "1");
                polyExtruder2.createPrism(polyExtruderGO2.name, extrusionHeight, Polygon2, Color.grey, is3D, "2");
                polyExtruder3.createPrism(polyExtruderGO3.name, extrusionHeight, Polygon3, Color.grey, is3D, "3");
                polyExtruder4.createPrism(polyExtruderGO4.name, extrusionHeight, Polygon4, Color.grey, is3D, "4");
                polyExtruder5.createPrism(polyExtruderGO5.name, extrusionHeight, Polygon5, Color.grey, is3D, "5");

                //polyExtruderGO.transform.localScale = new Vector3(-0.25f,0.25f,0.25f);
                //polyExtruderGO2.transform.localScale = new Vector3(-0.25f,0.25f,0.25f);
                //polyExtruderGO3.transform.localScale = new Vector3(-0.25f,0.25f,0.25f);
                //polyExtruderGO4.transform.localScale = new Vector3(-0.25f,0.25f,0.25f);
                //polyExtruderGO5.transform.localScale = new Vector3(-0.25f,0.25f,0.25f);

                polyExtruderGO.transform.position  = new Vector3(0, 0.125f, 0);
                polyExtruderGO2.transform.position = new Vector3(0, 0.125f, 0);
                polyExtruderGO3.transform.position = new Vector3(0, 0.125f, 0);
                polyExtruderGO4.transform.position = new Vector3(0, 0.125f, 0);
                polyExtruderGO5.transform.position = new Vector3(0, 0.125f, 0);

                //polyExtruderGO.transform.Rotate(90,0,0);
                //polyExtruderGO2.transform.Rotate(90,0,0);
                //polyExtruderGO3.transform.Rotate(90,0,0);
                //polyExtruderGO4.transform.Rotate(90,0,0);
                //polyExtruderGO5.transform.Rotate(90,0,0);


                created = true;
            }
        }
        else
        {
            if (created)
            {
                Destroy(polyExtruderGO);
                Destroy(polyExtruderGO2);
                Destroy(polyExtruderGO3);
                Destroy(polyExtruderGO4);
                Destroy(polyExtruderGO5);

                created = false;
            }
        }
    }