Beispiel #1
0
    private void ScaleMesh()
    {
        float minx, maxx, miny, maxy, minz, maxz;
        float scalex = 0.02F, scaley = 0.05F, scalez = 0.02F;
        float x, y, z;

        minx = miny = minz = 1000000000.0F;
        maxx = maxy = maxz = -minx;

        for (int h = 0; h < jsondata.gmfdata.data3d.mesh.horizonts.Length; h++)
        {
            THorizontData horz = jsondata.gmfdata.data3d.mesh.horizonts[h];
            Vector3[]     vertices;

            for (int j = 0; j < 3; j++)
            {
                vertices = horz.surfaceup.vertices;
                if (j == 1)
                {
                    vertices = horz.surfacedn.vertices;
                }
                if (j == 2)
                {
                    vertices = horz.surfacesd.vertices;
                }

                for (int i = 0; i < vertices.Length; i++)
                {
                    x = vertices[i].x *= scalex;
                    y = vertices[i].y *= scaley;
                    z = vertices[i].z *= scalez;
                    if (x > maxx)
                    {
                        maxx = x;
                    }
                    if (x < minx)
                    {
                        minx = x;
                    }
                    if (y != 0.0F && y > maxy)
                    {
                        maxy = y;
                    }
                    if (y != 0.0F && y < miny)
                    {
                        miny = y;
                    }
                    if (z > maxz)
                    {
                        maxz = z;
                    }
                    if (z < minz)
                    {
                        minz = z;
                    }
                }
            }
        }

        x = -(minx + maxx) * 0.5F;
        y = -miny;
        z = -(minz + maxz) * 0.5F;

        for (int h = 0; h < jsondata.gmfdata.data3d.mesh.horizonts.Length; h++)
        {
            THorizontData horz = jsondata.gmfdata.data3d.mesh.horizonts[h];
            Vector3[]     vertices;

            for (int j = 0; j < 3; j++)
            {
                vertices = horz.surfaceup.vertices;

                if (j == 1)
                {
                    vertices = horz.surfacedn.vertices;
                }
                if (j == 2)
                {
                    vertices = horz.surfacesd.vertices;
                }

                for (int i = 0; i < vertices.Length; i++)
                {
                    vertices[i].x += x;
                    if (vertices[i].y != 0.0F)
                    {
                        vertices[i].y += y;
                    }
                    vertices[i].z += z;
                }
            }
        }

        for (int i = 0; i < jsondata.gmfdata.data3d.bores.Length; i++)
        {
            TModelBore Bore = jsondata.gmfdata.data3d.bores[i];

            jsondata.gmfdata.data3d.bores[i].x_dn *= scalex;
            jsondata.gmfdata.data3d.bores[i].x_dn += z;
            jsondata.gmfdata.data3d.bores[i].y_dn *= scalex;
            jsondata.gmfdata.data3d.bores[i].y_dn += x;
            jsondata.gmfdata.data3d.bores[i].z_dn *= scaley;
            jsondata.gmfdata.data3d.bores[i].z_dn += y;

            jsondata.gmfdata.data3d.bores[i].x_up *= scalex;
            jsondata.gmfdata.data3d.bores[i].x_up += z;
            jsondata.gmfdata.data3d.bores[i].y_up *= scalex;
            jsondata.gmfdata.data3d.bores[i].y_up += x;
            jsondata.gmfdata.data3d.bores[i].z_up *= scaley;
            jsondata.gmfdata.data3d.bores[i].z_up += y;

//            jsondata.gmfdata.data3d.bores[i] = Bore;
        }
    }
Beispiel #2
0
    // Start is called before the first frame update
    void Start()
    {
        for (int h = 0; h < 1; h++)// jsondata.gmfdata.data3d.mesh.horizonts.Length; h++)
        {
            THorizontData horzmesh = jsondata.gmfdata.data3d.mesh.horizonts[h];
            string        name;

            name = "mesh" + h;

            GameObject horz;
            horz = new GameObject(name);
            horz.AddComponent <MeshFilter>();

            Mesh mesh1;

            Mesh meshup, meshdn, meshsd;

            meshup           = new Mesh();
            meshup.vertices  = horzmesh.surfaceup.vertices;
            meshup.triangles = horzmesh.surfaceup.triangles;
            meshdn           = new Mesh();
            meshdn.vertices  = horzmesh.surfacedn.vertices;
            meshdn.triangles = horzmesh.surfacedn.triangles;
            meshsd           = new Mesh();
            meshsd.vertices  = horzmesh.surfacesd.vertices;
            meshsd.triangles = horzmesh.surfacesd.triangles;

            CombineInstance[] combine = new CombineInstance[3];

            combine[0].mesh      = meshup;
            combine[0].transform = Matrix4x4.identity;
            combine[1].mesh      = meshdn;
            combine[1].transform = Matrix4x4.identity;
            combine[2].mesh      = meshsd;
            combine[2].transform = Matrix4x4.identity;

            horz.GetComponent <MeshFilter>().mesh = mesh1 = new Mesh();
            mesh1.name = "Mesh" + h;

            mesh1.CombineMeshes(combine);

//*
//                        mesh1.vertices = horzmesh.surfacesd.vertices;
//                        mesh1.triangles = horzmesh.surfacesd.triangles;

/*
 *                      mesh1.vertices = new Vector3[horzmesh.surfacesd.vertices.Length];
 *                      mesh1.triangles = new int[horzmesh.surfacesd.triangles.Length];
 *
 *                      for (int i = 0; i < horzmesh.surfacesd.vertices.Length; i++)
 *                      {
 *                          mesh1.vertices[i] = horzmesh.surfacesd.vertices[i];
 *                      }
 *
 *                      for (int i = 0; i < horzmesh.surfacesd.triangles.Length; i++)
 *                          mesh1.triangles[i] = horzmesh.surfacesd.triangles[i];
 *
 *                      string ss;
 *                      ss = JsonUtility.ToJson(mesh1.vertices);
 *                      print("v (" + mesh1.vertices.Length + "): " + ss + ": " + horzmesh.surfacesd.vertices[0].x + "=" + (float)mesh1.vertices[0].x);
 *                      ss = JsonUtility.ToJson(mesh1.vertices);
 *                      print("v (" + mesh1.triangles.Length + "): " + ss + ": " + horzmesh.surfacesd.triangles[0] + "=" + (float)mesh1.triangles[0]);
 */
            //            horzmesh.surfacesd.vertices.CopyTo(mesh.vertices, 0);
            //            horzmesh.surfacesd.triangles.CopyTo(mesh.triangles, 0);
            mesh1.RecalculateNormals();

            MeshRenderer meshRenderer = horz.AddComponent <MeshRenderer>();
            meshRenderer.material       = gameObject.GetComponent <MeshRenderer>().material;
            meshRenderer.material.color = new Color32((byte)(horzmesh.color % (256 * 256)), (byte)((horzmesh.color / 256) % 256), (byte)(horzmesh.color / (256 * 256)), 255);

            Rigidbody rigibody = horz.AddComponent <Rigidbody>();
            rigibody.isKinematic = true;

            MeshCollider meshCollider = horz.AddComponent <MeshCollider>();
            meshCollider.sharedMesh = mesh1;
        }
    }
Beispiel #3
0
    private void GeneratePlotMesh()
    {
        for (int h = 0; h < jsondata.gmfdata.data3d.mesh.horizonts.Length; h++)
        {
            THorizontData horzmesh = jsondata.gmfdata.data3d.mesh.horizonts[h];
            string        name;

            name = "mesh" + h;

            GameObject horz;
            horz = new GameObject(name);
            horz.transform.parent = transform;
            horz.AddComponent <MeshFilter>();

            Mesh mesh;

            CombineInstance[] combine = new CombineInstance[3];

            combine[0].mesh      = mesh = new Mesh();
            combine[0].transform = Matrix4x4.identity;
            mesh.vertices        = horzmesh.surfaceup.vertices;
            mesh.triangles       = horzmesh.surfaceup.triangles;

            combine[1].mesh      = mesh = new Mesh();
            combine[1].transform = Matrix4x4.identity;
            mesh.vertices        = horzmesh.surfacedn.vertices;
            mesh.triangles       = horzmesh.surfacedn.triangles;

            combine[2].mesh      = mesh = new Mesh();
            combine[2].transform = Matrix4x4.identity;
            mesh.vertices        = horzmesh.surfacesd.vertices;
            mesh.triangles       = horzmesh.surfacesd.triangles;

            horz.GetComponent <MeshFilter>().mesh = mesh = new Mesh();
            mesh.name = "Mesh" + h;
            mesh.CombineMeshes(combine);
            mesh.RecalculateNormals();

            MeshRenderer meshRenderer = horz.AddComponent <MeshRenderer>();
            meshRenderer.material = Resources.Load("OnePlaneCrossSection", typeof(Material)) as Material;
            Material material = meshRenderer.material;
            material.color = new Color32((byte)(horzmesh.color % (256 * 256)), (byte)((horzmesh.color / 256) % 256), (byte)(horzmesh.color / (256 * 256)), 255);
            material.SetColor("_CrossColor", new Color32((byte)(horzmesh.color % (256 * 256)), (byte)((horzmesh.color / 256) % 256), (byte)(horzmesh.color / (256 * 256)), 255));

            var        foundObjects = FindObjectsOfType <GameObject>();
            GameObject quad         = foundObjects[0];

            foreach (object o in foundObjects)
            {
                GameObject g = (GameObject)o;
                if (g.name == "Quad")
                {
                    quad = g;
                }
            }

            OnePlaneCuttingController ctrl = horz.AddComponent <OnePlaneCuttingController>();
            ctrl.plane            = quad;
            ctrl.transform.parent = transform;


            Rigidbody rigibody = horz.AddComponent <Rigidbody>();
            rigibody.isKinematic = true;

            MeshCollider meshCollider = horz.AddComponent <MeshCollider>();
            meshCollider.sharedMesh = mesh;

            horz.transform.position = new Vector3(0F, 0.0F, 0F);
        }
    }
Beispiel #4
0
    private void LoadMeshData()
    {
/*
 *      string filePath = Path.Combine(Application.streamingAssetsPath, meshDataFileName);
 *      print(filePath);
 *
 *      if (File.Exists(filePath))
 *      {
 *          string meshAsJson = File.ReadAllText(filePath);
 *          modelmesh = JsonUtility.FromJson<TModelMeshData>(meshAsJson);
 *
 *          print("horizonts: " +  modelmesh.horizonts.Length + " " + modelmesh.horizonts[0].name);
 *
 *      }
 *      else
 *      {
 *          Debug.LogError("Cannot load game data!");
 *      }
 */
        string gmfFilePath = Path.Combine(Application.streamingAssetsPath, gmfFileName);

        print(gmfFilePath);

        if (File.Exists(gmfFilePath))
        {
            string gmfAsJson = File.ReadAllText(gmfFilePath);
            jsondata = JsonUtility.FromJson <TJSONdata>(gmfAsJson);

//            string json;
//            json = JsonUtility.ToJson(jsondata);
//            print(json);

            print("bores (" + jsondata.gmfdata.data3d.bores.Length + "): " + jsondata.gmfdata.data3d.bores[0].name + ", ...");
            print("horizonts (" + jsondata.gmfdata.data3d.mesh.horizonts.Length + "): " + jsondata.gmfdata.data3d.mesh.horizonts[0].name + ", ...");
        }
        else
        {
            Debug.LogError("Cannot load game data!");
        }

        float minx, maxx, miny, maxy, minz, maxz;
        float x, y, z;

        minx = miny = minz = 1000000000.0F;
        maxx = maxy = maxz = -minx;

        for (int h = 0; h < jsondata.gmfdata.data3d.mesh.horizonts.Length; h++)
        {
            THorizontData horz = jsondata.gmfdata.data3d.mesh.horizonts[h];
            Vector3[]     vertices;

            for (int j = 0; j < 3; j++)
            {
                vertices = horz.surfaceup.vertices;
                if (j == 1)
                {
                    vertices = horz.surfacedn.vertices;
                }
                if (j == 2)
                {
                    vertices = horz.surfacesd.vertices;
                }

                for (int i = 0; i < vertices.Length; i++)
                {
                    x = vertices[i].x *= 0.02F;
                    y = vertices[i].y *= 0.05F;
                    z = vertices[i].z *= 0.02F;
                    if (x > maxx)
                    {
                        maxx = x;
                    }
                    if (x < minx)
                    {
                        minx = x;
                    }
                    if (y != 0.0F && y > maxy)
                    {
                        maxy = y;
                    }
                    if (y != 0.0F && y < miny)
                    {
                        miny = y;
                    }
                    if (z > maxz)
                    {
                        maxz = z;
                    }
                    if (z < minz)
                    {
                        minz = z;
                    }
                }
            }
        }

        print("box: " + minx + ", " + maxx + ", " + miny + ", " + maxy + ", " + minz + ", " + maxz);

        x = -(minx + maxx) * 0.5F;
        y = -miny;
        z = -(minz + maxz) * 0.5F;

        for (int h = 0; h < jsondata.gmfdata.data3d.mesh.horizonts.Length; h++)
        {
            THorizontData horz = jsondata.gmfdata.data3d.mesh.horizonts[h];
            Vector3[]     vertices;

            for (int j = 0; j < 3; j++)
            {
                vertices = horz.surfaceup.vertices;

                if (j == 1)
                {
                    vertices = horz.surfacedn.vertices;
                }
                if (j == 2)
                {
                    vertices = horz.surfacesd.vertices;
                }

                for (int i = 0; i < vertices.Length; i++)
                {
                    vertices[i].x += x;
                    if (vertices[i].y != 0.0F)
                    {
                        vertices[i].y += y;
                    }
                    vertices[i].z += z;
                }
            }
        }

        minx = miny = minz = 1000000000.0F;
        maxx = maxy = maxz = -minx;

        for (int h = 0; h < jsondata.gmfdata.data3d.mesh.horizonts.Length; h++)
        {
            THorizontData horz = jsondata.gmfdata.data3d.mesh.horizonts[h];
            Vector3[]     vertices;

            for (int j = 0; j < 3; j++)
            {
                vertices = horz.surfaceup.vertices;

                if (j == 1)
                {
                    vertices = horz.surfacedn.vertices;
                }
                if (j == 2)
                {
                    vertices = horz.surfacesd.vertices;
                }

                for (int i = 0; i < vertices.Length; i++)
                {
                    x = vertices[i].x;
                    y = vertices[i].y;
                    z = vertices[i].z;
                    if (x > maxx)
                    {
                        maxx = x;
                    }
                    if (x < minx)
                    {
                        minx = x;
                    }
                    if (y != 0.0F && y > maxy)
                    {
                        maxy = y;
                    }
                    if (y != 0.0F && y < miny)
                    {
                        miny = y;
                    }
                    if (z > maxz)
                    {
                        maxz = z;
                    }
                    if (z < minz)
                    {
                        minz = z;
                    }
                }
            }
        }

        print("box: " + minx + ", " + maxx + ", " + miny + ", " + maxy + ", " + minz + ", " + maxz);
    }