Skip to content

Commit

Permalink
Merge pull request #435 from umasteeringgroup/Feature-13
Browse files Browse the repository at this point in the history
Feature 13
  • Loading branch information
Jaimi authored Jun 8, 2024
2 parents 933bffe + 78be8ab commit e497ca2
Show file tree
Hide file tree
Showing 22 changed files with 3,554 additions and 3,542 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ private void EnsureRoot()
globalTransform = _umaData.umaRoot.transform.Find ("Global");
if (globalTransform != null)
{
_umaData.skeleton = new UMASkeleton (globalTransform);
_umaData.skeleton = new UMASkeleton (globalTransform,_umaData.umaGenerator);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -417,19 +417,25 @@ public override void OnGUI(Rect position, SerializedProperty property, GUIConten
for (int cr = 0; cr < compatibleRacesArraySize; cr++)
{
string race = thisElement.FindPropertyRelative("_compatibleRaces").GetArrayElementAtIndex(cr).stringValue;
compatibleRaces = compatibleRaces +race;
if (thisDCA.activeRace.data.IsCrossCompatibleWith(race))
compatibleRaces = compatibleRaces + race;
if (thisDCA.activeRace != null)
{
compatible = true;
}
if (race == thisDCA.activeRace.name)
{
compatible = true;
}
if (thisDCA.activeRace.data != null)
{
if (thisDCA.activeRace.data.IsCrossCompatibleWith(race))
{
compatible = true;
}
if (race == thisDCA.activeRace.name)
{
compatible = true;
}

if (cr < compatibleRacesArraySize - 1)
{
compatibleRaces = compatibleRaces + ", ";
if (cr < compatibleRacesArraySize - 1)
{
compatibleRaces = compatibleRaces + ", ";
}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1639,7 +1639,7 @@ public bool OnGUI(ref bool _dnaDirty, ref bool _textureDirty, ref bool _meshDirt
#endregion

EditorGUILayout.HelpBox("Expand Along Normal is used to expand the slot along the normal of the mesh. This is useful for offsetting to address zfighting issues. In micrometers", MessageType.Info);

GUI.changed = false;
_slotData.expandAlongNormal = EditorGUILayout.DelayedIntField("Expand Along Normal", _slotData.expandAlongNormal);
if (GUI.changed)
{
Expand Down
14 changes: 9 additions & 5 deletions UMAProject/Assets/UMA/Core/Editor/Scripts/ImportProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,18 +90,22 @@ private static void EnsureTags()
{
// Open tag manager
SerializedObject tagManager = new SerializedObject(AssetDatabase.LoadAllAssetsAtPath("ProjectSettings/TagManager.asset")[0]);
EnsureTag("UMAIgnore", tagManager);
EnsureTag("UMAKeepChain", tagManager);
}

private static void EnsureTag(string s, SerializedObject tagManager)
{
SerializedProperty tagsProp = tagManager.FindProperty("tags");

// Adding a Tag
string s = "UMAIgnore";

// First check if it is not already present
for (int i = 0; i < tagsProp.arraySize; i++)
{
SerializedProperty t = tagsProp.GetArrayElementAtIndex(i);
if (t.stringValue.Equals(s))
{
return;
if (t.stringValue.Equals(s))
{
return;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public struct SlotBuilderParameters
public bool binarySerialization;
public bool useRootFolder;
public bool nameByMaterial;
public bool keepAllBones;

public string stripBones;
public string rootBone;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,17 +163,16 @@ public static SlotDataAsset CreateSlotData(SlotBuilderParameters sbp)
Transform[] bones = resultingSkinnedMesh.bones;
List<int> KeepBoneIndexes = new List<int>();

for(int i=0;i<bones.Length;i++)

int j = 0;
for (int i = 0; i < bones.Length; i++)
{
Transform t = bones[i];
foreach(string keep in sbp.keepList)
Transform _bone = bones[i];
if (sbp.keepList.Contains(_bone.name) || sbp.keepAllBones)
{
if (t.name.Contains(keep))
{
KeepBoneIndexes.Add(i);
break; // only add to keeplist once.
}
KeepBoneIndexes.Add(j);
}
j++;
}

Mesh resultingMesh;
Expand Down
9 changes: 2 additions & 7 deletions UMAProject/Assets/UMA/Core/Editor/Scripts/UmaAboutWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@ namespace UMA
public class UmaAboutWindow : EditorWindow
{
public static string umaVersion { get { return _version; } }
private static readonly string _version = "2.13";
private static readonly string _version = "2.13.f0";
private string windowTitle = "UMA About";
private string wikiLink = "http://umadocs.secretanorak.com/doku.php";
private string wikiLink = "https://github.com/umasteeringgroup/UMA/wiki";
private string githubLink = "https://github.com/umasteeringgroup";
private string unityThreadLink = "https://forum.unity.com/threads/uma-unity-multipurpose-avatar-on-the-asset-store.219175/";
private string umaForumLink = "http://umacommunity.boards.net/forum";
private string discordLink = "https://discord.gg/KdteVKd";

private Vector2 size = new Vector2(400, 300);
Expand Down Expand Up @@ -69,10 +68,6 @@ void OnGUI()
{
Application.OpenURL(unityThreadLink);
}
if(GUILayout.Button("UMA Forum"))
{
Application.OpenURL(umaForumLink);
}

if(GUILayout.Button("Secret Anorak's Discord Channel"))
{
Expand Down
19 changes: 12 additions & 7 deletions UMAProject/Assets/UMA/Core/Editor/Scripts/UmaSlotBuilderWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public BoneName(string val)
private bool boneListInitialized;
public string BoneStripper;
private bool useRootFolder=false;
public bool keepAllBones = false;

string GetAssetFolder()
{
Expand Down Expand Up @@ -161,8 +162,10 @@ void OnGUI()
calcTangents = EditorGUILayout.Toggle("Calculate Tangents", calcTangents);
udimAdjustment = EditorGUILayout.Toggle("Adjust for UDIM", udimAdjustment);
EditorGUILayout.EndHorizontal();
EditorGUILayout.BeginHorizontal();
useRootFolder = EditorGUILayout.Toggle("Write to Root Folder", useRootFolder);

keepAllBones = EditorGUILayout.Toggle("Keep All Bones", keepAllBones);
EditorGUILayout.EndHorizontal();
BoneStripper = EditorGUILayout.TextField("Strip from Bones:", BoneStripper);
boneList.DoLayoutList();
GUIHelper.EndVerticalPadded(10);
Expand All @@ -178,13 +181,14 @@ void OnGUI()
GUILayout.Label("Single Slot Processing", EditorStyles.boldLabel);

var newslotMesh = EditorGUILayout.ObjectField("Slot Mesh ", slotMesh, typeof(SkinnedMeshRenderer), false) as SkinnedMeshRenderer;
if (newslotMesh != slotMesh)
{
errmsg = "";
slotMesh = newslotMesh;
}
if (newslotMesh != slotMesh)
{
errmsg = "";
slotMesh = newslotMesh;
slotName = newslotMesh.name;
}

slotName = EditorGUILayout.TextField("Slot Name", slotName);
slotName = EditorGUILayout.TextField("Slot Name", slotName);



Expand Down Expand Up @@ -430,6 +434,7 @@ private SlotDataAsset CreateSlot_Internal()
sbp.material = material;
sbp.udimAdjustment = udimAdjustment;
sbp.useRootFolder = false;
sbp.keepAllBones = keepAllBones;

SlotDataAsset slot = UMASlotProcessingUtil.CreateSlotData(sbp);
slot.tags = Tags.ToArray();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,154 +322,76 @@ public static void CombineMeshes(UMAMeshData target, CombineInstance[] sources,
}
}

if (has_blendShapes)
{
// calculate the group of blendshapes
// use that instead of source.meshData.blendShapes.
List<UMABlendShape> sourceShapes = GetBlendshapeSources(source.meshData, recipe);
// int sourceBlendShapeLength = source.meshData.blendShapes.Length;
// for (int shapeIndex = 0; shapeIndex < sourceBlendShapeLength; shapeIndex++)
for (int j = 0; j < sourceShapes.Count; j++)
{
UMABlendShape ubs = sourceShapes[j];
string shapeName = ubs.shapeName;// source.meshData.blendShapes[shapeIndex].shapeName;

// load only the blendshapes that are in the filtered list, if any are set.
if (blendShapeSettings.filteredBlendshapes.Count > 0 && (!blendShapeSettings.filteredBlendshapes.Contains(shapeName)))
if (has_blendShapes)
{
if (source.meshData.blendShapes != null && source.meshData.blendShapes.Length > 0)
{
int sourceBlendShapeLength = source.meshData.blendShapes.Length;
for (int shapeIndex = 0; shapeIndex < sourceBlendShapeLength; shapeIndex++)
{
continue;
}
string shapeName = source.meshData.blendShapes[shapeIndex].shapeName;

#region BlendShape Baking
if (BakeBlendShape(blendShapeSettings.blendShapes, ubs /*source.meshData.blendShapes[shapeIndex]*/, ref vertexIndex, vertices, normals, tangents, has_normals, has_tangents))
{
continue; //If we baked this blendshape, then continue to the next one and skip adding the regular blendshape.
}
#endregion

//If our dictionary contains the shape name, which it should
if (blendShapeNames.ContainsKey(shapeName))
{
if (blendShapeSettings.loadAllFrames)
{
//UMABlendShape[] sourceBlendShapes = source.meshData.blendShapes;
int currentShape = blendShapeNames[shapeName].index;

if (blendShapes[currentShape].frames.Length != ubs.frames.Length)
{
if (Debug.isDebugBuild)
{
Debug.LogError("SkinnedMeshCombiner: mesh blendShape frame counts don't match!");
}
//If we aren't loading all blendshapes and we don't find the blendshape name in the list of explicit blendshapes to combine, then skip to the next one.
if (blendShapeSettings.ignoreBlendShapes && !blendShapeSettings.blendShapes.ContainsKey(shapeName))
continue;

break;
}
#region BlendShape Baking
if (BakeBlendShape(blendShapeSettings.blendShapes, source.meshData.blendShapes[shapeIndex], ref vertexIndex, vertices, normals, tangents, has_normals, has_tangents))
continue; //If we baked this blendshape, then continue to the next one and skip adding the regular blendshape.
#endregion

for (int frameIndex = 0; frameIndex < ubs.frames.Length; frameIndex++)
{
bool normalsCopied = false;
bool tangentsCopied = false;
Array.Copy(ubs.frames[frameIndex].deltaVertices, 0, blendShapes[currentShape].frames[frameIndex].deltaVertices, vertexIndex, sourceVertexCount);
//If our dictionary contains the shape name, which it should
if (blendShapeNames.ContainsKey(shapeName))
{
UMABlendShape[] sourceBlendShapes = source.meshData.blendShapes;
int i = blendShapeNames[shapeName].index;

Vector3[] sourceDeltaNormals = ubs.frames[frameIndex].deltaNormals;
Vector3[] sourceDeltaTangents = ubs.frames[frameIndex].deltaTangents;
if (blendShapes[i].frames.Length != sourceBlendShapes[shapeIndex].frames.Length)
{
if (Debug.isDebugBuild)
Debug.LogError("SkinnedMeshCombiner: mesh blendShape frame counts don't match!");
break;
}

//if out dictionary says at least one source has normals or tangents and the current source has normals or tangents then copy them.
if (blendShapeNames[shapeName].hasNormals && sourceDeltaNormals.Length > 0)
{
if (blendShapes[currentShape].frames[0].deltaNormals == null || blendShapes[currentShape].frames[0].deltaNormals.Length == sourceVertexCount)
{
blendShapes[currentShape].frames[0].deltaNormals = new Vector3[sourceVertexCount];
}
Array.Copy(sourceDeltaNormals, 0, blendShapes[currentShape].frames[frameIndex].deltaNormals, vertexIndex, sourceVertexCount);
normalsCopied = true;
}
for (int frameIndex = 0; frameIndex < sourceBlendShapes[shapeIndex].frames.Length; frameIndex++)
{
Array.Copy(sourceBlendShapes[shapeIndex].frames[frameIndex].deltaVertices, 0, blendShapes[i].frames[frameIndex].deltaVertices, vertexIndex, sourceVertexCount);

if (blendShapeNames[shapeName].hasTangents && sourceDeltaTangents.Length > 0)
{
if (blendShapes[currentShape].frames[0].deltaTangents == null || blendShapes[currentShape].frames[0].deltaTangents.Length == sourceVertexCount)
{
blendShapes[currentShape].frames[0].deltaTangents = new Vector3[sourceVertexCount];
}
tangentsCopied = true;
Array.Copy(sourceDeltaTangents, 0, blendShapes[currentShape].frames[frameIndex].deltaTangents, vertexIndex, sourceVertexCount);
}
Vector3[] sourceDeltaNormals = sourceBlendShapes[shapeIndex].frames[frameIndex].deltaNormals;
Vector3[] sourceDeltaTangents = sourceBlendShapes[shapeIndex].frames[frameIndex].deltaTangents;

if (!normalsCopied)
{
blendShapes[currentShape].frames[frameIndex].deltaNormals = new Vector3[0];
}
if (!tangentsCopied)
if (blendShapeSettings.loadNormals)
{
blendShapes[currentShape].frames[frameIndex].deltaTangents = new Vector3[0];
//if out dictionary says at least one source has normals or tangents and the current source has normals or tangents then copy them.
if (blendShapeNames[shapeName].hasNormals && sourceDeltaNormals.Length > 0)
Array.Copy(sourceDeltaNormals, 0, blendShapes[i].frames[frameIndex].deltaNormals, vertexIndex, sourceVertexCount);
}
}
}
else
{
int currentShape = blendShapeNames[shapeName].index;
int lastFrame = ubs.frames.Length - 1;
bool normalsCopied = false;
bool tangentsCopied = false;

if (blendShapes[currentShape].frames != null && blendShapes[currentShape].frames.Length > 1)
{
blendShapes[currentShape].frames = new UMABlendFrame[1];
}

blendShapes[currentShape].frames = new UMABlendFrame[1];

Array.Copy(ubs.frames[lastFrame].deltaVertices, 0, blendShapes[currentShape].frames[0].deltaVertices, vertexIndex, sourceVertexCount);

if (blendShapeSettings.loadNormals && blendShapeNames[shapeName].hasNormals)
{
Vector3[] sourceDeltaNormals = ubs.frames[lastFrame].deltaNormals;
if (sourceDeltaNormals.Length > 0)
else
{
normalsCopied = true;
if (blendShapes[currentShape].frames[0].deltaNormals == null || blendShapes[currentShape].frames[0].deltaNormals.Length == sourceVertexCount)
{
blendShapes[currentShape].frames[0].deltaNormals = new Vector3[sourceVertexCount];
}
Array.Copy(sourceDeltaNormals, 0, blendShapes[currentShape].frames[0].deltaNormals, vertexIndex, sourceVertexCount);
}

}
blendShapes[i].frames[frameIndex].deltaNormals = new Vector3[0];
}

if (blendShapeSettings.loadTangents && blendShapeNames[shapeName].hasTangents)
{
Vector3[] sourceDeltaTangents = ubs.frames[lastFrame].deltaTangents;
if (sourceDeltaTangents.Length > 0)
if (blendShapeSettings.loadTangents)
{
tangentsCopied = true;
if (blendShapes[currentShape].frames[0].deltaTangents == null || blendShapes[currentShape].frames[0].deltaTangents.Length == sourceVertexCount)
{
blendShapes[currentShape].frames[0].deltaTangents = new Vector3[sourceVertexCount];
}
Array.Copy(sourceDeltaTangents, 0, blendShapes[currentShape].frames[0].deltaTangents, vertexIndex, sourceVertexCount);
if (blendShapeNames[shapeName].hasTangents && sourceDeltaTangents.Length > 0)
Array.Copy(sourceDeltaTangents, 0, blendShapes[i].frames[frameIndex].deltaTangents, vertexIndex, sourceVertexCount);
}
}

if (!normalsCopied)
{
blendShapes[currentShape].frames[0].deltaNormals = new Vector3[0];
}
if (!tangentsCopied)
{
blendShapes[currentShape].frames[0].deltaTangents = new Vector3[0];
}
}
}
else
{
if (Debug.isDebugBuild)
else
{
blendShapes[i].frames[frameIndex].deltaTangents = new Vector3[0];
}
}
}
else
{
Debug.LogError("BlendShape " + shapeName + " not found in dictionary!");
if (Debug.isDebugBuild)
Debug.LogError("BlendShape " + shapeName + " not found in dictionary!");
}
}
}
}

}
}
if (has_clothSkinning)
{
localClothVertices.Clear();
Expand Down
Loading

0 comments on commit e497ca2

Please sign in to comment.