public override void OnInspectorGUI() { DrawDefaultInspector(); BVHRecorder bvhRecorder = (BVHRecorder)target; if (GUILayout.Button("Detect bones")) { bvhRecorder.getBones(); Debug.Log("Bone detection done."); } if (GUILayout.Button("Remove empty entries from bone list")) { bvhRecorder.cleanupBones(); Debug.Log("Cleaned up bones."); } if (GUILayout.Button("Clear recorded motion data")) { bvhRecorder.clearCapture(); Debug.Log("Cleared motion data."); } if (GUILayout.Button("Save motion to BVH file")) { try { bvhRecorder.saveBVH(); } catch (Exception ex) { Debug.LogError("An error has occurred while saving the BVH file: " + ex); } } }
public override void OnInspectorGUI() { DrawDefaultInspector(); BVHRecorder bvhRecorder = (BVHRecorder)target; if (GUILayout.Button("Detect bones")) { bvhRecorder.getBones(); Debug.Log("Bone detection done."); } if (GUILayout.Button("Remove empty entries from bone list")) { bvhRecorder.cleanupBones(); Debug.Log("Cleaned up bones."); } if (GUILayout.Button("Clear recorded motion data")) { bvhRecorder.clearCapture(); Debug.Log("Cleared motion data."); } if (GUILayout.Button("Save motion to BVH file")) { try { bvhRecorder.saveBVH(); } catch { Debug.LogError("Motion data can only be saved while the scene is running."); } } }
void Start() { anim = GetComponent <Animator>(); playTime = 0; if (posFilename == "") { Debug.Log("<color=blue>Error! Pos filename is empty.</color>"); return; } if (System.IO.File.Exists(posFilename) == false) { Debug.Log("<color=blue>Error! Pos file not found(" + posFilename + ").</color>"); return; } pos = ReadPosData(posFilename); GetInitInfo(); if (pos != null) { // inspectorで指定した開始フレーム、終了フレーム番号をセット if (startFrame >= 0 && startFrame < pos.Count) { sFrame = startFrame; } else { sFrame = 0; } int ef; if (int.TryParse(endFrame, out ef)) { if (ef >= sFrame && ef < pos.Count) { eFrame = ef; } else { eFrame = pos.Count - 1; } } else { eFrame = pos.Count - 1; } frame = sFrame; } if (saveMotion) { recorder = gameObject.AddComponent <BVHRecorder>(); recorder.scripted = true; recorder.targetAvatar = anim; recorder.blender = false; recorder.enforceHumanoidBones = enforceHumanoidBones; recorder.getBones(); recorder.buildSkeleton(); recorder.genHierarchy(); recorder.frameRate = 30.0f; } }
public void onRecord() { if (isRecording == false) { recorder = gameObject.AddComponent <BVHRecorder>(); var setting = AvatarList[avatars.value]; recorder.targetAvatar = setting.Avatar.GetComponent <Animator>(); recorder.scripted = true; recorder.blender = configurationSetting.Blender == 1; recorder.enforceHumanoidBones = configurationSetting.EnforceHumanoidBones == 1; recorder.getBones(); recorder.rootBone = setting.Avatar.JointPoints[PositionIndex.hip.Int()].Transform; recorder.buildSkeleton(); recorder.genHierarchy(); recorder.capturing = configurationSetting.Capturing == 1; if (configurationSetting.Capturing == 1) { recorder.frameRate = configurationSetting.CapturingFPS; } recorder.catchUp = configurationSetting.CatchUp == 1; isRecording = true; btnRecord.image.color = Color.red; btnRecord.GetComponentInChildren <Text>().text = "Recording"; btnRecord.GetComponentInChildren <Text>().color = Color.white; } else { isRecording = false; recorder.capturing = false; var extensions = new[] { new ExtensionFilter("BVH Files", "bvh"), }; var path = StandaloneFileBrowser.SaveFilePanel("SaveFile", "", "motion.bvh", extensions); if (path.Length != 0) { FileInfo fi = new FileInfo(path); recorder.directory = fi.DirectoryName; recorder.filename = fi.Name; recorder.saveBVH(); } recorder.clearCapture(); recorder = null; btnRecord.image.color = Color.white; btnRecord.GetComponentInChildren <Text>().text = "Record BVH"; btnRecord.GetComponentInChildren <Text>().color = Color.black; } }
private Transform getBoneByName(string name, Transform transform, bool first) { if (nameMap == null) { if (standardBoneNames) { Dictionary <Transform, string> boneMap; BVHRecorder.populateBoneMap(out boneMap, targetAvatar); nameMap = boneMap.ToDictionary(kp => flexibleName(kp.Value), kp => kp.Key); } else { nameMap = new Dictionary <string, Transform>(); } } string targetName = flexibleName(name); if (renamingMap.ContainsKey(targetName)) { targetName = renamingMap[targetName]; } if (first) { if (flexibleName(transform.name) == targetName) { return(transform); } if (nameMap.ContainsKey(targetName) && nameMap[targetName] == transform) { return(transform); } } for (int i = 0; i < transform.childCount; i++) { Transform child = transform.GetChild(i); if (flexibleName(child.name) == targetName) { return(child); } if (nameMap.ContainsKey(targetName) && nameMap[targetName] == child) { return(child); } } throw new InvalidOperationException("Could not find bone \"" + name + "\" under bone \"" + transform.name + "\"."); }
public void loadAnimation() { getTargetAvatar(); if (bp == null) { throw new InvalidOperationException("No BVH file has been parsed."); } //blend if (UseBlend) { if (bp2 == null) { throw new InvalidOperationException("No BVH2 file has been parsed."); } BlendBVH(ref bp.root, bp2.root); } if (nameMap == null) { if (standardBoneNames) { Dictionary <Transform, string> boneMap; BVHRecorder.populateBoneMap(out boneMap, targetAvatar); nameMap = boneMap.ToDictionary(kp => flexibleName(kp.Value), kp => kp.Key); } else { nameMap = new Dictionary <string, Transform>(); } } renamingMap = new Dictionary <string, string>(); foreach (FakeDictionary entry in boneRenamingMap) { if (entry.bvhName != "" && entry.targetName != "") { renamingMap.Add(flexibleName(entry.bvhName), flexibleName(entry.targetName)); } } Queue <Transform> transforms = new Queue <Transform>(); transforms.Enqueue(targetAvatar.transform); string targetName = flexibleName(bp.root.name); if (renamingMap.ContainsKey(targetName)) { targetName = flexibleName(renamingMap[targetName]); } while (transforms.Any()) { Transform transform = transforms.Dequeue(); if (flexibleName(transform.name) == targetName) { rootBone = transform; break; } if (nameMap.ContainsKey(targetName) && nameMap[targetName] == transform) { rootBone = transform; break; } for (int i = 0; i < transform.childCount; i++) { transforms.Enqueue(transform.GetChild(i)); } } if (rootBone == null) { rootBone = BVHRecorder.getRootBone(targetAvatar); Debug.LogWarning("Using \"" + rootBone.name + "\" as the root bone."); } if (rootBone == null) { throw new InvalidOperationException("No root bone \"" + bp.root.name + "\" found."); } if (UseBlend) { frames = bp.frames; clip = new AnimationClip(); clip.name = "BVHClip (" + (clipCount++) + ")"; if (clipName != "") { clip.name = clipName; } clip.legacy = true; prefix = getPathBetween(rootBone, targetAvatar.transform, true, true); Vector3 targetAvatarPosition = targetAvatar.transform.position; Quaternion targetAvatarRotation = targetAvatar.transform.rotation; targetAvatar.transform.position = new Vector3(0.0f, 0.0f, 0.0f); targetAvatar.transform.rotation = Quaternion.identity; getCurves(prefix, bp.root, rootBone, true); targetAvatar.transform.position = targetAvatarPosition; targetAvatar.transform.rotation = targetAvatarRotation; clip.EnsureQuaternionContinuity(); if (anim == null) { anim = targetAvatar.gameObject.GetComponent <Animation>(); if (anim == null) { anim = targetAvatar.gameObject.AddComponent <Animation>(); } } string path = "Assets/" + clip.name + " - " + clipCount + ".anim"; AssetDatabase.CreateAsset(clip, path); AssetDatabase.SaveAssets(); anim.AddClip(clip, clip.name); anim.clip = clip; anim.playAutomatically = autoPlay; if (autoPlay) { anim.Play(clip.name); } } }
public void loadAnimation() { if (targetAvatar == null) { throw new InvalidOperationException("No target avatar set."); } if (bp == null) { throw new InvalidOperationException("No BVH file has been parsed."); } Queue <Transform> transforms = new Queue <Transform>(); transforms.Enqueue(targetAvatar.transform); while (transforms.Any()) { Transform transform = transforms.Dequeue(); if (flexibleName(transform.name) == flexibleName(bp.root.name)) { rootBone = transform; break; } for (int i = 0; i < transform.childCount; i++) { transforms.Enqueue(transform.GetChild(i)); } } if (rootBone == null) { rootBone = BVHRecorder.getRootBone(targetAvatar); Debug.LogWarning("Using \"" + rootBone.name + "\" as the root bone."); } if (rootBone == null) { throw new InvalidOperationException("No root bone \"" + bp.root.name + "\" found."); } renamingMap = new Dictionary <string, string>(); foreach (FakeDictionary entry in boneRenamingMap) { if (entry.bvhName != "" && entry.targetName != "") { renamingMap.Add(flexibleName(entry.bvhName), flexibleName(entry.targetName)); } } frames = bp.frames; clip = new AnimationClip(); clip.name = "BVHClip (" + (clipCount++) + ")"; if (clipName != "") { clip.name = clipName; } clip.legacy = true; prefix = getPathBetween(rootBone, targetAvatar.transform, true, true); getCurves(prefix, bp.root, rootBone, true); clip.EnsureQuaternionContinuity(); if (anim == null) { anim = targetAvatar.gameObject.GetComponent <Animation>(); if (anim == null) { anim = targetAvatar.gameObject.AddComponent <Animation>(); } } anim.AddClip(clip, clip.name); anim.clip = clip; anim.playAutomatically = autoPlay; if (autoPlay) { anim.Play(clip.name); } }