diff --git a/README.md b/README.md index 69089d3864723295bc0dfbf39c817dc65338a31d..54ecd9548f792b0d35b5410f178cb760305f3e28 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ ## CityJson Loads a cityjson (*.json or *.city.json) file and provides acces to its -vertices, appearance. +vertices, appearance, materials, etc. ### No dependencies to Unity! - This can se used in any C# project. @@ -21,6 +21,22 @@ cj.Materials // Vertices var unityVertices = cj.Vertices.Select( v => new Vector3(v.x, v.z, v.y) ).ToArray(); +for (int i=0; i<cj.CityObjects.Count;i++ ) +{ + var geom = cj.CityObjects[i].geometry; + Mesh m = new Mesh(); + m.indexFormat = UnityEngine.Rendering.IndexFormat.UInt32; + m.subMeshCount = geom.indices.Count; + m.SetVertices( unityVertices ); + for ( int j=0; j<geom.indices.Count; j++) + { + m.SetTriangles( geom.indices[j], j ); + } + m.RecalculateNormals(); + m.Optimize(); + m.UploadMeshData( true ); +} + ``` ### Important: diff --git a/README.md.backup b/README.md.backup index db66e00229ab1093a71a4245e1c712049f52ec45..c24dfd062d9c8c33f66805de553b84239969f2f1 100644 --- a/README.md.backup +++ b/README.md.backup @@ -19,7 +19,23 @@ cj.Geometries cj.Materials // Vertices -var unityVertices = cj.Vertices.Select( v => new Vector3(v.x, v.z, v.y) ).ToArra +var unityVertices = cj.Vertices.Select( v => new Vector3(v.x, v.z, v.y) ).ToArray(); + +for (int i=0; i<cj.CityObjects.Count;i++ ) +{ + var geom = cj.CityObjects[i].geometry; + Mesh m = new Mesh(); + m.indexFormat = UnityEngine.Rendering.IndexFormat.UInt32; + m.subMeshCount = geom.indices.Count; + m.SetVertices( unityVertices ); + for ( int j=0; j<geom.indices.Count; j++) + { + m.SetTriangles( geom.indices[j], j ); + } + m.RecalculateNormals(); + m.Optimize(); + m.UploadMeshData( true ); +} ``` diff --git a/Runtime/CityJson.cs b/Runtime/CityJson.cs index a671a28cfcfb874b7949b0fc3a022df1a3d9e6aa..4541152745394bde00d50738eb2fabb3cba9ba5a 100644 --- a/Runtime/CityJson.cs +++ b/Runtime/CityJson.cs @@ -61,7 +61,6 @@ namespace Wander List<int> geometryIndices = new List<int>(); // Output - string path; string title; string crs; string referenceDate; @@ -76,6 +75,7 @@ namespace Wander Dictionary<string, int> errors = new Dictionary<string, int>(); // Output properties + public string Title => title; public Dictionary<string, long> Timings => timings; public Dictionary<string, int> Errors => errors; public List<(long x, long y, long z)> Vertices => vertices; diff --git a/package.json b/package.json index 082c24a8a5434647720c0c48b63a0122febe3339..84835ae9a7767b245b67b58016e5cb924c4f70e6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "com.wurwander.cityjson", - "version": "1.0.0", + "version": "1.0.1", "displayName": "CityJson", "description": "Provides a way to load CityJson and generate geometries with materials for direct engine use (Unity, Unreal). No dependencies to Unity or Unreal. Only 'System'", "unity": "2021.3",