Last active
January 21, 2025 16:56
-
-
Save tarukosu/b4ef460e4e9616d35e10fc53794a41c3 to your computer and use it in GitHub Desktop.
Unity component for tilesets in the PolySpatial project using Cesium for Unity
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This code is licensed under the CC0 1.0 Universal (CC0 1.0) Public Domain Dedication. | |
// To view a copy of this license, visit http://creativecommons.org/publicdomain/zero/1.0/ | |
using System; | |
using System.Collections; | |
using System.Collections.Generic; | |
using CesiumForUnity; | |
using UnityEngine; | |
public class TilesetForPolySpatial : MonoBehaviour | |
{ | |
private void Start() | |
{ | |
var cesium3DTileset = GetComponent<Cesium3DTileset>(); | |
cesium3DTileset.OnTileGameObjectCreated += Cesium3DTileset_OnTileGameObjectCreated; | |
} | |
private void Cesium3DTileset_OnTileGameObjectCreated(GameObject go) | |
{ | |
var meshFilters = go.GetComponentsInChildren<MeshFilter>(); | |
foreach (var meshFilter in meshFilters) | |
{ | |
var mesh = meshFilter.sharedMesh; | |
// change triangle order | |
var triangles = mesh.triangles; | |
for (var i = 0; i < triangles.Length; i += 3) | |
{ | |
(triangles[i + 1], triangles[i]) = (triangles[i], triangles[i + 1]); | |
} | |
mesh.triangles = triangles; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment