public void LoadFrame(float timestamp) { Timestamp = timestamp; Actor actor = GetActor(); Frame frame = GetCurrentFrame(); Matrix4x4 root = frame.GetBoneTransformation(0, Data.Mirrored); if (actor.TargetRoot) { actor.transform.position = new Vector3(root.GetPosition().x, actor.transform.position.y, root.GetPosition().z); } else { actor.transform.localPosition = new Vector3(0.0f, actor.transform.position.y, 0.0f); } actor.transform.rotation = root.GetRotation(); UpdateBoneMapping(); for (int i = 1; i < actor.Bones.Length; i++) { BoneMap current = Array.Find(Map, x => x.ActorBoneTransform == actor.Bones[i].Transform); BoneMap parent = Array.Find(Map, x => x.ActorBoneTransform == actor.Bones[i].GetParent().Transform); if (current.BvhBoneName != null) { float length = actor.Bones[i].GetLength(); Matrix4x4 currentT = frame.GetBoneTransformation(current.BvhBoneName, Data.Mirrored); Matrix4x4 parentT = frame.GetBoneTransformation(parent.BvhBoneName, Data.Mirrored); actor.Bones[i].Transform.position = actor.Bones[i].GetParent().Transform.position + Vector3.Normalize(currentT.GetPosition() - parentT.GetPosition()) * length; actor.Bones[i].Transform.rotation = currentT.GetRotation(); actor.Bones[i].Velocity = frame.GetBoneVelocity(current.BvhBoneName, Data.Mirrored, 1.0f / 30); } } }
/// <summary> /// /// </summary> /// <param name="args"></param> /// <returns></returns> public bool DoIt(string[] args) { if (args.Length >= 6) { // parse args var inputjoint = Path.GetFullPath(args[1]); var inputBoneMap = new BoneMap(Path.GetFullPath(args[2])); var targetjoint = Path.GetFullPath(args[3]); var targetBoneMap = new BoneMap(Path.GetFullPath(args[4])); var inputfigatree = Path.GetFullPath(args[5]); var outputfigatree = Path.GetFullPath(args[6]); // source joint HSDRawFile inputJoint = new HSDRawFile(inputjoint); var sourceJOBJ = inputJoint.Roots[0].Data as HSD_JOBJ; // target joint HSDRawFile targetJoint = new HSDRawFile(targetjoint); var targetJOBJ = targetJoint.Roots[0].Data as HSD_JOBJ; // retarget animation HSDRawFile inputAnim = new HSDRawFile(inputfigatree); var tree = inputAnim.Roots[0].Data as HSD_FigaTree; inputAnim.Roots[0].Data = AnimationBakery.Port(tree, sourceJOBJ, targetJOBJ, inputBoneMap, targetBoneMap); inputAnim.Save(outputfigatree); return(true); } return(false); }
/* * Initiating and setting defaults * */ protected override void OnInitiate() { if (iterations <= 0) { iterations = 3; } // Creating the bone maps if (spine.Length != spineBones.Length) { spine = new BoneMap[spineBones.Length]; } rootNodeIndex = -1; for (int i = 0; i < spineBones.Length; i++) { if (spine[i] == null) { spine[i] = new BoneMap(); } spine[i].Initiate(spineBones[i], solver); // Finding the root node if (spine[i].isNodeBone) { rootNodeIndex = i; } } leftUpperArm.Initiate(leftUpperArmBone, solver); rightUpperArm.Initiate(rightUpperArmBone, solver); leftThigh.Initiate(leftThighBone, solver); rightThigh.Initiate(rightThighBone, solver); for (int i = 0; i < spine.Length; i++) { spine[i].SetIKPosition(); } // Defining the plane for the first bone spine[0].SetPlane(spine[rootNodeIndex].node, leftThigh.node, rightThigh.node); // Finding bone lengths and axes for (int i = 0; i < spine.Length - 1; i++) { spine[i].SetLength(spine[i + 1]); spine[i].SetLocalSwingAxis(spine[i + 1]); spine[i].SetLocalTwistAxis(leftUpperArm.transform.position - rightUpperArm.transform.position, spine[i + 1].transform.position - spine[i].transform.position); } // Defining the plane for the last bone spine[spine.Length - 1].SetPlane(spine[rootNodeIndex].node, leftUpperArm.node, rightUpperArm.node); spine[spine.Length - 1].SetLocalSwingAxis(leftUpperArm, rightUpperArm); useFABRIK = UseFABRIK(); }
/* * Initiating and setting defaults * */ protected override void OnInitiate() { if (boneMap == null) { boneMap = new BoneMap(); } boneMap.Initiate(bone, solver); }
/* * Initiating and setting defaults * */ public override void Initiate(IKSolverFullBody solver) { if (boneMap == null) { boneMap = new BoneMap(); } boneMap.Initiate(bone, solver); }
/* * Initiating and setting defaults * */ public override void Initiate(IKSolverFullBody solver) { if (boneMapParent == null) { boneMapParent = new BoneMap(); } if (boneMap1 == null) { boneMap1 = new BoneMap(); } if (boneMap2 == null) { boneMap2 = new BoneMap(); } if (boneMap3 == null) { boneMap3 = new BoneMap(); } // Finding the nodes if (parentBone != null) { boneMapParent.Initiate(parentBone, solver); } boneMap1.Initiate(bone1, solver); boneMap2.Initiate(bone2, solver); boneMap3.Initiate(bone3, solver); // Define plane points for the bone maps boneMap1.SetPlane(solver, boneMap1.transform, boneMap2.transform, boneMap3.transform); boneMap2.SetPlane(solver, boneMap2.transform, boneMap3.transform, boneMap1.transform); // Find the swing axis for the parent bone if (parentBone != null) { boneMapParent.SetLocalSwingAxis(boneMap1); } }
/* * Initiating and setting defaults * */ protected override void OnInitiate() { if (boneMapParent == null) { boneMapParent = new BoneMap(); } if (boneMap1 == null) { boneMap1 = new BoneMap(); } if (boneMap2 == null) { boneMap2 = new BoneMap(); } if (boneMap3 == null) { boneMap3 = new BoneMap(); } // Finding the nodes if (parentBone != null) { boneMapParent.Initiate(parentBone, solver); } boneMap1.Initiate(bone1, solver); boneMap2.Initiate(bone2, solver); boneMap3.Initiate(bone3, solver); // Define plane points for the bone maps boneMap1.SetPlane(boneMap1.node, boneMap2.node, boneMap3.node); boneMap2.SetPlane(boneMap2.node, boneMap3.node, boneMap1.node); // Find the swing axis for the parent bone if (parentBone != null) { boneMapParent.SetLocalSwingAxis(boneMap1); } }
public void MapBoneWeightTest() { { var map = new BoneMap(); map.Add(new GameObject("a"), new GameObject("A")); map.Add(new GameObject("b"), new GameObject("B")); map.Add(new GameObject("c"), new GameObject("C")); map.Add(new GameObject("d"), new GameObject("D")); map.Add(null, new GameObject("null")); // map.Add(new GameObject("c"), null); // ありえないので Exception にしてある var boneWeights = map.CreateBoneWeight(64).ToArray(); var newBoneWeight = MeshUtility.BoneNormalizer.MapBoneWeight(boneWeights, map.Map, map.SrcBones.ToArray(), map.DstBones.ToArray()); // 正常系 // exception が出なければよい } { var map = new BoneMap(); map.Add(new GameObject("a"), new GameObject("A")); map.Add(new GameObject("b"), new GameObject("B")); map.Add(new GameObject("c"), new GameObject("C")); map.Add(new GameObject("d"), new GameObject("D")); map.Add(null, new GameObject("null")); // map.Add(new GameObject("c"), null); // ありえないので Exception にしてある var boneWeights = map.CreateBoneWeight(64).ToArray(); var newBoneWeight = MeshUtility.BoneNormalizer.MapBoneWeight(boneWeights, map.Map, map.SrcBones.ToArray(), map.DstBones.ToArray()); // 4 つめが 0 になる Assert.AreEqual(0, newBoneWeight[1].boneIndex0); Assert.AreEqual(0, newBoneWeight[1].weight0); // 5 つめ以降が 0 になる。out of range Assert.AreEqual(0, newBoneWeight[1].boneIndex1); Assert.AreEqual(0, newBoneWeight[1].weight1); } }
/* * Sets the direction to the swing target in local space * */ public void SetLocalSwingAxis(BoneMap swingTarget) { SetLocalSwingAxis(swingTarget, this); }
/* * Calculate length of the bone * */ public void SetLength(BoneMap nextBone) { length = Vector3.Distance(transform.position, nextBone.transform.position); }
/* * Sets the direction to the swing target in local space * */ public void SetLocalSwingAxis(BoneMap bone1, BoneMap bone2) { localSwingAxis = Quaternion.Inverse(transform.rotation) * (bone1.transform.position - bone2.transform.position); }
/* * Initiating and setting defaults * */ protected override void OnInitiate() { if (boneMapParent == null) boneMapParent = new BoneMap(); if (boneMap1 == null) boneMap1 = new BoneMap(); if (boneMap2 == null) boneMap2 = new BoneMap(); if (boneMap3 == null) boneMap3 = new BoneMap(); // Finding the nodes if (parentBone != null) boneMapParent.Initiate(parentBone, solver); boneMap1.Initiate(bone1, solver); boneMap2.Initiate(bone2, solver); boneMap3.Initiate(bone3, solver); // Define plane points for the bone maps boneMap1.SetPlane(boneMap1.node, boneMap2.node, boneMap3.node); boneMap2.SetPlane(boneMap2.node, boneMap3.node, boneMap1.node); // Find the swing axis for the parent bone if (parentBone != null) boneMapParent.SetLocalSwingAxis(boneMap1); }
/* * Initiating and setting defaults * */ protected override void OnInitiate () { if (iterations <= 0) iterations = 3; // Creating the bone maps if (spine == null || spine.Length != spineBones.Length) spine = new BoneMap[spineBones.Length]; rootNodeIndex = -1; for (int i = 0; i < spineBones.Length; i++) { if (spine[i] == null) spine[i] = new BoneMap(); spine[i].Initiate(spineBones[i], solver); // Finding the root node if (spine[i].isNodeBone) rootNodeIndex = i; } if (leftUpperArm == null) leftUpperArm = new BoneMap(); if (rightUpperArm == null) rightUpperArm = new BoneMap(); if (leftThigh == null) leftThigh = new BoneMap(); if (rightThigh == null) rightThigh = new BoneMap(); leftUpperArm.Initiate(leftUpperArmBone, solver); rightUpperArm.Initiate(rightUpperArmBone, solver); leftThigh.Initiate(leftThighBone, solver); rightThigh.Initiate(rightThighBone, solver); for (int i = 0; i < spine.Length; i++) spine[i].SetIKPosition(); // Defining the plane for the first bone spine[0].SetPlane(spine[rootNodeIndex].node, leftThigh.node, rightThigh.node); // Finding bone lengths and axes for (int i = 0; i < spine.Length - 1; i++) { spine[i].SetLength(spine[i + 1]); spine[i].SetLocalSwingAxis(spine[i + 1]); spine[i].SetLocalTwistAxis(leftUpperArm.transform.position - rightUpperArm.transform.position, spine[i + 1].transform.position - spine[i].transform.position); } // Defining the plane for the last bone spine[spine.Length - 1].SetPlane(spine[rootNodeIndex].node, leftUpperArm.node, rightUpperArm.node); spine[spine.Length - 1].SetLocalSwingAxis(leftUpperArm, rightUpperArm); useFABRIK = UseFABRIK(); }
/* * Initiating and setting defaults * */ public override void Initiate(IKSolverFullBody solver) { if (boneMapParent == null) boneMapParent = new BoneMap(); if (boneMap1 == null) boneMap1 = new BoneMap(); if (boneMap2 == null) boneMap2 = new BoneMap(); if (boneMap3 == null) boneMap3 = new BoneMap(); // Finding the nodes if (parentBone != null) boneMapParent.Initiate(parentBone, solver); boneMap1.Initiate(bone1, solver); boneMap2.Initiate(bone2, solver); boneMap3.Initiate(bone3, solver); // Define plane points for the bone maps boneMap1.SetPlane(solver, boneMap1.transform, boneMap2.transform, boneMap3.transform); boneMap2.SetPlane(solver, boneMap2.transform, boneMap3.transform, boneMap1.transform); // Find the swing axis for the parent bone if (parentBone != null) boneMapParent.SetLocalSwingAxis(boneMap1); }
/* * Initiating and setting defaults * */ public override void Initiate(IKSolverFullBody solver) { if (boneMap == null) boneMap = new BoneMap(); boneMap.Initiate(bone, solver); }
} // 0x00000001809A57A0-0x00000001809A5800 public void SetLength(BoneMap nextBone) { } // 0x00000001809A62E0-0x00000001809A63D0
} // 0x00000001809A63D0-0x00000001809A63E0 public void SetLocalSwingAxis(BoneMap bone1, BoneMap bone2) { } // 0x00000001809A63E0-0x00000001809A6590
} // 0x00000001809A62E0-0x00000001809A63D0 public void SetLocalSwingAxis(BoneMap swingTarget) { } // 0x00000001809A63D0-0x00000001809A63E0
/* * Initiating and setting defaults * */ protected override void OnInitiate() { if (boneMap == null) boneMap = new BoneMap(); boneMap.Initiate(bone, solver); }
/// <summary> /// /// </summary> /// <param name="args"></param> /// <returns></returns> public bool DoIt(string[] args) { if (args.Length >= 6) { // parse args var targetAnimFile = Path.GetFullPath(args[1]); var destAnimFile = Path.GetFullPath(args[2]); var newSymbol = args[3]; var boneIniTarget = Path.GetFullPath(args[4]); var boneInitDest = Path.GetFullPath(args[5]); // load bone inis var target = new BoneMap(boneIniTarget); var dest = new BoneMap(boneInitDest); SkeletonPorter port = null; List <HSD_JOBJ> jobjsFrom = null; List <HSD_JOBJ> jobjsTo = null; if (args.Length >= 8) { jobjsFrom = (new HSDRawFile(args[6]).Roots[0].Data as HSD_JOBJ).BreathFirstList; jobjsTo = (new HSDRawFile(args[7]).Roots[0].Data as HSD_JOBJ).BreathFirstList; port = new SkeletonPorter( new HSDRawFile(args[6]).Roots[0].Data as HSD_JOBJ, new HSDRawFile(args[7]).Roots[0].Data as HSD_JOBJ, target, dest); } // retarget animation HSDRawFile inputAnim = new HSDRawFile(targetAnimFile); var targetTree = inputAnim.Roots[0].Data as HSD_FigaTree; List <FigaTreeNode> newNodes = new List <FigaTreeNode>(); for (int i = 0; i < dest.Count; i++) { newNodes.Add(new FigaTreeNode()); } int nodeIndex = 0; foreach (var n in targetTree.Nodes) { string boneName = ""; boneName = target.GetName(nodeIndex); var ind = dest.GetIndex(boneName); if (ind != -1) { //System.Diagnostics.Debug.WriteLine($"{boneName} {nodeIndex} {ind}"); if (port != null && port.HasBone(boneName)) { var jobj = jobjsFrom[nodeIndex]; FOBJ_Player rx = new FOBJ_Player(); rx.Keys.Add(new FOBJKey() { Value = jobj.RX, InterpolationType = GXInterpolationType.HSD_A_OP_CON }); FOBJ_Player ry = new FOBJ_Player(); ry.Keys.Add(new FOBJKey() { Value = jobj.RY, InterpolationType = GXInterpolationType.HSD_A_OP_CON }); FOBJ_Player rz = new FOBJ_Player(); rz.Keys.Add(new FOBJKey() { Value = jobj.RZ, InterpolationType = GXInterpolationType.HSD_A_OP_CON }); HSD_Track rotXTrack = new HSD_Track(); HSD_Track rotYTrack = new HSD_Track(); HSD_Track rotZTrack = new HSD_Track(); foreach (var track in n.Tracks) { var fobj = track.ToFOBJ(); var keys = fobj.GetDecodedKeys(); switch (fobj.JointTrackType) { case JointTrackType.HSD_A_J_ROTX: rx.Keys = keys; break; case JointTrackType.HSD_A_J_ROTY: ry.Keys = keys; break; case JointTrackType.HSD_A_J_ROTZ: rz.Keys = keys; break; default: //newNodes[ind].Tracks.Add(track); break; } } rotXTrack.FromFOBJ(OrientTrack(boneName, port, rx.Keys, JointTrackType.HSD_A_J_ROTX, jobj, jobjsTo[nodeIndex])); rotYTrack.FromFOBJ(OrientTrack(boneName, port, ry.Keys, JointTrackType.HSD_A_J_ROTY, jobj, jobjsTo[nodeIndex])); rotZTrack.FromFOBJ(OrientTrack(boneName, port, rz.Keys, JointTrackType.HSD_A_J_ROTZ, jobj, jobjsTo[nodeIndex])); newNodes[ind].Tracks.Add(rotXTrack); newNodes[ind].Tracks.Add(rotYTrack); newNodes[ind].Tracks.Add(rotZTrack); foreach (var track in newNodes[ind].Tracks) { //System.Diagnostics.Debug.WriteLine(track.FOBJ.JointTrackType + " " + track.FOBJ.GetDecodedKeys().Count); } } else if (ind < newNodes.Count && ind >= 0) { newNodes[ind] = n; } } nodeIndex++; } // save new file HSD_FigaTree figatree = new HSD_FigaTree(); figatree.FrameCount = targetTree.FrameCount; figatree.Type = targetTree.Type; figatree.Nodes = newNodes; System.Console.WriteLine(destAnimFile); HSDRawFile file = new HSDRawFile(); file.Roots.Add(new HSDRootNode() { Name = newSymbol, Data = figatree }); file.Save(destAnimFile); return(true); } return(false); }