Skip to content

Commit

Permalink
bugfixes for addon export
Browse files Browse the repository at this point in the history
  • Loading branch information
emperorofmars committed Feb 14, 2024
1 parent f1d8d26 commit 3edfc3b
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 9 deletions.
16 changes: 10 additions & 6 deletions STF/Editor/Tools/STFSetup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,17 +107,21 @@ public static Result FindAndSetupArmaturesInplace(GameObject Root)
if(meshInstance == null) meshInstance = smr.gameObject.AddComponent<STFMeshInstance>();
// Check if an armatureInstance exists
var armatureInstanceGo = smr.rootBone?.parent?.gameObject;
if(armatureInstanceGo == null) throw new Exception("Incorrectly setup SkinnedMeshRenderer: " + smr);
var armatureInstance = armatureInstanceGo.GetComponent<STFArmatureInstanceNode>();

// continue if an armature instance already exists. It can be assumed that its setup correctly.
if(armatureInstance != null) continue;
if(armatureInstanceGo == null)
{
Debug.LogWarning("Incorrectly setup SkinnedMeshRenderer: " + smr);
continue;
}

var armatureInstance = armatureInstanceGo.GetComponent<STFArmatureInstanceNode>();
if(armatureInstance == null) armatureInstance = armatureInstanceGo.AddComponent<STFArmatureInstanceNode>();

// Setup armatureInstance to the definetively correct values
meshInstance.ArmatureInstance = armatureInstance;
armatureInstance.root = smr.rootBone?.gameObject;
armatureInstance.bones = new List<GameObject>(smr.bones.Select(b => b.gameObject));

if(smr.bones != null) armatureInstance.bones = new List<GameObject>(smr.bones.Select(b => b?.gameObject));

// If the armatureInstance doesn't have an armature (eg was just created), then determine the armature from the smr bone hirarchy and the smr bind poses
if(armatureInstance.armature == null && !armatureInstancesToSetup.Contains(armatureInstance))
{
Expand Down
1 change: 0 additions & 1 deletion STF/Runtime/Addon/AddonApplier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ public static class STFAddonApplier
{
public static GameObject Apply(ISTFAsset Base, STFAddonAsset Addon, bool InPlace = false)
{

GameObject ret = InPlace ? Base.gameObject : UnityEngine.Object.Instantiate(Base.gameObject);
ret.name = Base.name + "_applied_" + Addon.Name;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public override void ParseFromJson(ISTFAssetImportState State, JObject Json, str
ParseRelationships(Json, c);
c.Id = Id;
c.Weight = (float)Json["weight"];
c.Target = Json["target"] != null && State.Nodes.ContainsKey((string)Json["target"]) ? State.Nodes[(string)Json["target"]] : null;
c.Target = (string)Json["target"] != null && State.Nodes.ContainsKey((string)Json["target"]) ? State.Nodes[(string)Json["target"]] : null;
c.TargetId = (string)Json["target"];
State.AddComponent(c, Id);
}
Expand Down
1 change: 1 addition & 0 deletions STF/Runtime/Serialisation/Resources/STFMesh.cs
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,7 @@ public void ParseFromJson(ISTFImportState State, JObject Json, string Id)
mesh.SetBoneWeights(bonesPerVertexNat, weights);

State.AddTask(new Task(() => {
Debug.Log(mesh.name);
if(State.Resources.ContainsKey((string)Json["armature"]))
{
var armature = (STFArmature)State.Resources[(string)Json["armature"]];
Expand Down
2 changes: 1 addition & 1 deletion STF/Runtime/Util/SerdeUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public static (string, JObject) SerializeNodeComponent(ISTFExportState State, Co
public static string SerializeResource(ISTFExportState State, UnityEngine.Object Resource, UnityEngine.Object Context = null)
{
if(State.Resources.ContainsKey(Resource)) return State.Resources[Resource].Id;
if(State.Context.ResourceExporters.ContainsKey(Resource.GetType()))
else if(State.Context.ResourceExporters.ContainsKey(Resource.GetType()))
{
return State.Context.ResourceExporters[Resource.GetType()].SerializeToJson(State, Resource, Context);
}
Expand Down

0 comments on commit 3edfc3b

Please sign in to comment.