private void LoadMotion(string path) { var context = new UniHumanoid.ImporterContext { Path = path }; UniHumanoid.BvhImporter.Import(context); SetMotion(context.Root.GetComponent <HumanPoseTransfer>()); }
private void Start() { m_version.text = string.Format("VRMViewer {0}.{1}", VRMVersion.MAJOR, VRMVersion.MINOR); m_open.onClick.AddListener(OnOpenClicked); // load initial bvh var path = Application.streamingAssetsPath + "/test.txt"; var context = new UniHumanoid.ImporterContext { Path = path }; UniHumanoid.BvhImporter.Import(context); SetMotion(context.Root.GetComponent <HumanPoseTransfer>()); }
private void LoadMotion(string path) { try { // Trigger BVH _bvhLoadingTrigger = true; // Save current path _bvhPathLocal = path; var previous_motion = _bvhMotion; if (previous_motion != null) { Destroy(previous_motion.Root); } var context = new UniHumanoid.ImporterContext { Path = path }; _bvhMotion = context; UniHumanoid.BvhImporter.Import(context); if (context.Avatar == null || context.Avatar.isValid == false) { if (context.Root != null) { Destroy(context.Root); } throw new Exception("BVH importer failed"); } // Send BVH _informationUpdate.SetBVH(_bvhMotion.Root); SetMotion(context.Root.GetComponent <HumanPoseTransfer>()); } catch (Exception e) { if (_bvhMotion.Root == true) { Destroy(_bvhMotion.Root); } _errorMessagePanel.SetMessage(MultipleLanguageSupport.BvhLoadErrorMessage + "\nError message: " + e.Message); throw; } }
void LoadBvh(string path) { Debug.LogFormat("ImportBvh: {0}", path); var context = new UniHumanoid.ImporterContext { Path = path }; UniHumanoid.BvhImporter.Import(context); if (m_source != null) { GameObject.Destroy(m_source.gameObject); } m_source = context.Root.GetComponent <UniHumanoid.HumanPoseTransfer>(); SetupTarget(); }
IEnumerator LoadBvhCoroutine(string path) { var www = new WWW("file://" + path); yield return(www); var context = new UniHumanoid.ImporterContext { Path = path, Source = www.text }; ModifiedBvhImporter.Import(context); if (m_source != null) { GameObject.Destroy(m_source.gameObject); } m_source = context.Root.GetComponent <UniHumanoid.HumanPoseTransfer>(); m_source.GetComponent <Renderer>().enabled = false; SetupTarget(); }
public static void Import(ImporterContext context) { // // parse // context.Source = File.ReadAllText(context.Path, Encoding.UTF8); context.Bvh = Bvh.Parse(context.Source); Debug.LogFormat("parsed {0}", context.Bvh); // // build hierarchy // context.Root = new GameObject(Path.GetFileNameWithoutExtension(context.Path)); context.Root.AddComponent <Animator>(); BuildHierarchy(context.Root.transform, context.Bvh.Root, 1.0f); var minY = 0.0f; foreach (var x in context.Root.transform.Traverse()) { if (x.position.y < minY) { minY = x.position.y; } } var toMeter = 1.0f / (-minY); Debug.LogFormat("minY: {0} {1}", minY, toMeter); foreach (var x in context.Root.transform.Traverse()) { x.localPosition *= toMeter; } // foot height to 0 var hips = context.Root.transform.GetChild(0); hips.position = new Vector3(0, -minY * toMeter, 0); // // create AnimationClip // context.Animation = BvhAnimation.CreateAnimationClip(context.Bvh, toMeter); context.Animation.name = context.Root.name; context.Animation.legacy = true; context.Animation.wrapMode = WrapMode.Loop; var animation = context.Root.AddComponent <Animation>(); animation.AddClip(context.Animation, context.Animation.name); animation.clip = context.Animation; animation.Play(); var boneMapping = context.Root.AddComponent <BoneMapping>(); boneMapping.Bones[(int)HumanBodyBones.Hips] = hips.gameObject; boneMapping.GuessBoneMapping(); context.Avatar = boneMapping.CreateAvatar(); context.AvatarDescription = boneMapping.Description; var humanPoseTransfer = context.Root.AddComponent <HumanPoseTransfer>(); humanPoseTransfer.Avatar = context.Avatar; }
public static void Import(ImporterContext context) { // // parse // context.Source = File.ReadAllText(context.Path, Encoding.UTF8); context.Bvh = Bvh.Parse(context.Source); Debug.LogFormat("parsed {0}", context.Bvh); // // build hierarchy // context.Root = new GameObject(Path.GetFileNameWithoutExtension(context.Path)); BuildHierarchy(context.Root.transform, context.Bvh.Root, 1.0f); var hips = context.Root.transform.GetChild(0); var estimater = new BvhSkeletonEstimator(); var skeleton = estimater.Detect(hips.transform); var description = AvatarDescription.Create(); //var values= ((HumanBodyBones[])Enum.GetValues(typeof(HumanBodyBones))); description.SetHumanBones(skeleton.ToDictionary(hips.Traverse().ToArray())); // // scaling. reposition // float scaling = 1.0f; { //var foot = animator.GetBoneTransform(HumanBodyBones.LeftFoot); var foot = hips.Traverse().Skip(skeleton.GetBoneIndex(HumanBodyBones.LeftFoot)).First(); var hipHeight = hips.position.y - foot.position.y; // hips height to a meter scaling = 1.0f / hipHeight; foreach (var x in context.Root.transform.Traverse()) { x.localPosition *= scaling; } var scaledHeight = hipHeight * scaling; hips.position = new Vector3(0, scaledHeight, 0); // foot to ground } // // avatar // context.Avatar = description.CreateAvatar(context.Root.transform); context.Avatar.name = "Avatar"; context.AvatarDescription = description; var animator = context.Root.AddComponent <Animator>(); animator.avatar = context.Avatar; // // create AnimationClip // context.Animation = BvhAnimation.CreateAnimationClip(context.Bvh, scaling); context.Animation.name = context.Root.name; context.Animation.legacy = true; context.Animation.wrapMode = WrapMode.Loop; var animation = context.Root.AddComponent <Animation>(); animation.AddClip(context.Animation, context.Animation.name); animation.clip = context.Animation; animation.Play(); var humanPoseTransfer = context.Root.AddComponent <HumanPoseTransfer>(); humanPoseTransfer.Avatar = context.Avatar; // create SkinnedMesh for bone visualize var renderer = SkeletonMeshUtility.CreateRenderer(animator); context.Material = new Material(Shader.Find("Standard")); renderer.sharedMaterial = context.Material; context.Mesh = renderer.sharedMesh; context.Mesh.name = "box-man"; context.Root.AddComponent <BoneMapping>(); }
public static void Import(ImporterContext context) { // // parse // context.Source = File.ReadAllText(context.Path, Encoding.UTF8); context.Bvh = Bvh.Parse(context.Source); Debug.LogFormat("parsed {0}", context.Bvh); // // build hierarchy // context.Root = new GameObject(Path.GetFileNameWithoutExtension(context.Path)); var animator = context.Root.AddComponent <Animator>(); BuildHierarchy(context.Root.transform, context.Bvh.Root, 1.0f); var minY = 0.0f; foreach (var x in context.Root.transform.Traverse()) { if (x.position.y < minY) { minY = x.position.y; } } var toMeter = 1.0f / (-minY); Debug.LogFormat("minY: {0} {1}", minY, toMeter); foreach (var x in context.Root.transform.Traverse()) { x.localPosition *= toMeter; } // foot height to 0 var hips = context.Root.transform.GetChild(0); hips.position = new Vector3(0, -minY * toMeter, 0); // // create AnimationClip // context.Animation = BvhAnimation.CreateAnimationClip(context.Bvh, toMeter); context.Animation.name = context.Root.name; context.Animation.legacy = true; context.Animation.wrapMode = WrapMode.Loop; var animation = context.Root.AddComponent <Animation>(); animation.AddClip(context.Animation, context.Animation.name); animation.clip = context.Animation; animation.Play(); var boneMapping = context.Root.AddComponent <BoneMapping>(); boneMapping.Bones[(int)HumanBodyBones.Hips] = hips.gameObject; boneMapping.GuessBoneMapping(); var description = AvatarDescription.Create(); BoneMapping.SetBonesToDescription(boneMapping, description); context.Avatar = description.CreateAvatar(context.Root.transform); context.Avatar.name = "Avatar"; context.AvatarDescription = description; animator.avatar = context.Avatar; var humanPoseTransfer = context.Root.AddComponent <HumanPoseTransfer>(); humanPoseTransfer.Avatar = context.Avatar; // create SkinnedMesh for bone visualize var renderer = SkeletonMeshUtility.CreateRenderer(animator); context.Material = new Material(Shader.Find("Standard")); renderer.sharedMaterial = context.Material; context.Mesh = renderer.sharedMesh; context.Mesh.name = "box-man"; }