Skip to content

Commit

Permalink
added import options: import BlendShape Names
Browse files Browse the repository at this point in the history
  • Loading branch information
pfcDorn committed Sep 12, 2023
1 parent d8e9909 commit 1d78e17
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 3 deletions.
5 changes: 4 additions & 1 deletion Editor/Scripts/GLTFImporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ private static void EnsureShadersAreLoaded()
[SerializeField] internal bool _generateColliders = false;
[SerializeField] internal bool _swapUvs = false;
[SerializeField] internal bool _generateLightmapUVs = false;
[Tooltip("When false, the index of the BlendShape is used as name.")]
[SerializeField] internal bool _importBlendShapeNames = true;
[SerializeField] internal GLTFImporterNormals _importNormals = GLTFImporterNormals.Import;
[SerializeField] internal GLTFImporterNormals _importTangents = GLTFImporterNormals.Import;
[SerializeField] internal AnimationMethod _importAnimations = AnimationMethod.Mecanim;
Expand Down Expand Up @@ -797,7 +799,8 @@ private static void UpdateColorSpace()
ImportContext = context,
SwapUVs = _swapUvs,
ImportNormals = _importNormals,
ImportTangents = _importTangents
ImportTangents = _importTangents,
ImportBlendShapeNames = _importBlendShapeNames
};

using (var stream = File.OpenRead(projectFilePath))
Expand Down
2 changes: 2 additions & 0 deletions Editor/Scripts/GLTFImporterInspector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ private void ModelInspectorGUI()
EditorGUILayout.LabelField("Meshes", EditorStyles.boldLabel);
EditorGUILayout.PropertyField(serializedObject.FindProperty(nameof(GLTFImporter._readWriteEnabled)), new GUIContent("Read/Write"));
EditorGUILayout.PropertyField(serializedObject.FindProperty(nameof(GLTFImporter._generateColliders)));
EditorGUILayout.PropertyField(serializedObject.FindProperty(nameof(GLTFImporter._importBlendShapeNames)));

EditorGUILayout.Separator();

EditorGUILayout.LabelField("Geometry", EditorStyles.boldLabel);
Expand Down
1 change: 1 addition & 0 deletions Runtime/Scripts/GLTFSceneImporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public class ImportOptions
public bool SwapUVs = false;
public GLTFImporterNormals ImportNormals = GLTFImporterNormals.Import;
public GLTFImporterNormals ImportTangents = GLTFImporterNormals.Import;
public bool ImportBlendShapeNames = true;

#if UNITY_EDITOR
public GLTFImportContext ImportContext = new GLTFImportContext(null, new List<GltfImportPluginContext>());
Expand Down
2 changes: 1 addition & 1 deletion Runtime/Scripts/SceneImporter/ImporterAnimation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ protected async Task<AnimationClip> ConstructClip(Transform root, int animationI
var targetNames = prim.TargetNames;
propertyNames = new string[targetCount];
for (var i = 0; i < targetCount; i++)
propertyNames[i] = "blendShape." + (targetNames != null ? targetNames[i] : ("Morphtarget" + i));
propertyNames[i] = _options.ImportBlendShapeNames ? ("blendShape." + (targetNames != null ? targetNames[i] : ("Morphtarget" + i))) : i.ToString();

var frameFloats = new float[targetCount];

Expand Down
2 changes: 1 addition & 1 deletion Runtime/Scripts/SceneImporter/ImporterMeshes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ private void AddBlendShapesToMesh(UnityMeshData unityMeshData, int meshIndex, Me
var firstPrim = _gltfRoot.Meshes[meshIndex].Primitives[0];
for (int i = 0; i < firstPrim.Targets.Count; i++)
{
var targetName = firstPrim.TargetNames != null ? firstPrim.TargetNames[i] : $"Morphtarget{i}";
var targetName = _options.ImportBlendShapeNames ? (firstPrim.TargetNames != null ? firstPrim.TargetNames[i] : $"Morphtarget{i}") : i.ToString();
mesh.AddBlendShapeFrame(targetName, 1f,
unityMeshData.MorphTargetVertices[i],
unityMeshData.MorphTargetNormals != null ? unityMeshData.MorphTargetNormals[i] : null,
Expand Down

0 comments on commit 1d78e17

Please sign in to comment.