Skip to content

Instantly share code, notes, and snippets.

@tarukosu
Last active January 21, 2025 16:56
Show Gist options
  • Save tarukosu/b4ef460e4e9616d35e10fc53794a41c3 to your computer and use it in GitHub Desktop.
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 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