Skip to content

Commit 8907c2f

Browse files
committed
Added UI option to generate tangents
1 parent d13c45d commit 8907c2f

9 files changed

Lines changed: 493 additions & 94 deletions

Editor/Cesium3DTilesetEditor.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public class Cesium3DTilesetEditor : Editor
3535
//private SerializedProperty _useLodTransitions;
3636
//private SerializedProperty _lodTransitionLength;
3737
private SerializedProperty _generateSmoothNormals;
38+
private SerializedProperty _generateTangents;
3839

3940
private SerializedProperty _pointCloudShading;
4041

@@ -84,6 +85,9 @@ private void OnEnable()
8485
// this.serializedObject.FindProperty("_lodTransitionLength");
8586
this._generateSmoothNormals =
8687
this.serializedObject.FindProperty("_generateSmoothNormals");
88+
this._generateTangents =
89+
this.serializedObject.FindProperty("_generateTangents");
90+
8791
this._ignoreKhrMaterialsUnlit = this.serializedObject.FindProperty("_ignoreKhrMaterialsUnlit");
8892

8993
this._pointCloudShading = this.serializedObject.FindProperty("_pointCloudShading");
@@ -428,6 +432,12 @@ private void DrawRenderProperties()
428432
);
429433
EditorGUILayout.PropertyField(this._generateSmoothNormals, generateSmoothNormalsContent);
430434

435+
var generateTangentsContent = new GUIContent(
436+
"Generate Tangents",
437+
"Whether to generate per-vertex tangets if they are missing in the source glTF."
438+
);
439+
EditorGUILayout.PropertyField(this._generateTangents, generateTangentsContent);
440+
431441
var ignoreKhrMaterialsUnlitContent = new GUIContent(
432442
"Ignore KHR_materials_unlit",
433443
"Whether to ignore the KHR_materials_unlit extension on the glTF tiles in "+

Editor/ConfigureReinterop.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,4 +252,4 @@ public void ExposeToCPP()
252252
var exceptionMessage = exception.Message;
253253
}
254254
}
255-
}
255+
}

Runtime/Cesium3DTileset.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -587,6 +587,31 @@ public bool generateSmoothNormals
587587
}
588588
}
589589

590+
[SerializeField]
591+
private bool _generateTangents = false;
592+
593+
/// <summary>
594+
/// Whether to generate per-vertex tangents when tangents are missing in the glTF.
595+
/// </summary>
596+
/// <remarks>
597+
/// The glTF 2.0 specification suggests that tangents should be generated when they
598+
/// are missing.
599+
/// "When tangents are not specified, client implementations SHOULD calculate tangents using
600+
/// default MikkTSpace algorithms with the specified vertex positions, normals, and texture
601+
/// coordinates associated with the normal texture."
602+
/// </remarks>
603+
/// <seealso cref="https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html"/>
604+
605+
public bool generateTangents
606+
{
607+
get => _generateTangents;
608+
set
609+
{
610+
this._generateSmoothNormals = value;
611+
this.RecreateTileset();
612+
}
613+
}
614+
590615
[SerializeField]
591616
private bool _ignoreKhrMaterialsUnlit = false;
592617

Runtime/ConfigureReinterop.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,7 @@ public void ExposeToCPP()
279279
//tileset.useLodTransitions = tileset.useLodTransitions;
280280
//tileset.lodTransitionLength = tileset.lodTransitionLength;
281281
tileset.generateSmoothNormals = tileset.generateSmoothNormals;
282+
tileset.generateTangents = tileset.generateTangents;
282283
tileset.ignoreKhrMaterialsUnlit = tileset.ignoreKhrMaterialsUnlit;
283284
tileset.createPhysicsMeshes = tileset.createPhysicsMeshes;
284285
tileset.suspendUpdate = tileset.suspendUpdate;
@@ -949,3 +950,4 @@ Cesium3DTilesetLoadFailureDetails tilesetDetails
949950
}
950951
}
951952
}
953+

Runtime/Resources/CesiumDefaultTilesetMaterial.mat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ Material:
100100
- _AlphaCutoffEnable: 1
101101
- _AlphaDstBlend: 0
102102
- _AlphaSrcBlend: 1
103-
- _AlphaToMask: 0
103+
- _AlphaToMask: 1
104104
- _AlphaToMaskInspectorValue: 0
105105
- _BUILTIN_AlphaClip: 1
106106
- _BUILTIN_Blend: 0

0 commit comments

Comments
 (0)