private static CoordSystemPart GetBodyCoordSystemPart([NotNull] SwayBone swayBone) { if (swayBone.IsSkirt) { return(CoordSystemPart.Skirt); } var n = swayBone.Path.LastIndexOf('/'); var seg = swayBone.Path.Substring(n + 1).ToLowerInvariant(); switch (seg) { case "kubi": case "atama": return(CoordSystemPart.Head); } if (swayBone.Path.Contains("hair_")) { return(CoordSystemPart.Hair); } if (swayBone.Path.Contains("skirt_") || swayBone.Path.Contains("skrt_")) { return(CoordSystemPart.Skirt); } if (swayBone.Path.Contains("OPAI_")) { return(CoordSystemPart.Breasts); } return(CoordSystemPart.Accessories); }
private void AddChildBones(Transform transform, bool toplevel) { foreach (Transform t in transform) { if (Exclusions.Contains(t)) { continue; } SwayBone sb = t.gameObject.GetComponent <SwayBone>(); if (sb == null) { sb = t.gameObject.AddComponent <SwayBone>(); } sb.elasticity = elasticity; sb.inertia = inertia; sb.limit = limit; sb.OrientOnly = OrientOnly; sb.Reorient = Reorient; sb.isTopLevel = toplevel; sb.Initialize(); SwayBones.Add(sb); if (t.childCount > 0) { AddChildBones(t, false); } } }
private static bool IsOnSkirtChain([NotNull] SwayBone bone) { Debug.Assert(!bone.IsSkirt); var b = bone; while (b.Parent != null) { b = b.Parent; if (b.IsSkirt) { return(true); } } return(false); }
private static void AddBoneLinks([NotNull] GameObject root, [NotNull] SwayBone bone, [NotNull] Dictionary <string, GameObject> cache) { if (IsOppai(bone)) { return; } var sideLink = bone.SideLink; if (sideLink != null) { var thisObject = SearchObjectByName(root, BreakPath(bone.Path), cache); Debug.Assert(thisObject != null); var thatObject = SearchObjectByName(root, BreakPath(sideLink.Path), cache); Debug.Assert(thatObject != null); var thisBody = thisObject.GetComponent <Rigidbody>(); var thatBody = thatObject.GetComponent <Rigidbody>(); // Don't use SpringJoint on this var joint = thisObject.AddComponent <HingeJoint>(); // joint.tolerance = bone.SideSpringTolerance; joint.connectedBody = thatBody; var thisTransform = thisBody.transform; var thatTransform = thatBody.transform; var midPoint = (thisTransform.position + thatTransform.position) / 2; var toLocal = thisTransform.worldToLocalMatrix; joint.anchor = toLocal * midPoint; var limit = new JointLimits(); limit.max = 180; limit.min = 144; joint.limits = limit; } foreach (var childBone in bone.Children) { AddBoneLinks(root, childBone, cache); } }
private static bool IsOppai([NotNull] SwayBone bone) { return(bone.Path.EndsWith("OPAI_L0") || bone.Path.EndsWith("OPAI_R0")); }
private void AddSwayBone([NotNull] GameObject root, [NotNull] SwayBone bone, [NotNull] Dictionary <string, GameObject> cache) { if (IsOppai(bone)) { return; } var bonePart = BreakPath(bone.Path); var targetObject = SearchObjectByName(root, bonePart, cache); Debug.Assert(targetObject != null); var targetObjectTransform = targetObject.transform; Debug.Assert(targetObject != null); var parent = bone.Parent; Rigidbody body1; if (parent == null) { // Try to add rigid body to its game object parent body1 = GetOrAddKinematicRigidBody(targetObjectTransform.parent.gameObject); } else { var parentObject = SearchObjectByName(root, BreakPath(parent.Path), cache); Debug.Assert(parentObject != null); body1 = parentObject.GetComponent <Rigidbody>(); } Debug.Assert(targetObjectTransform.childCount == 1); var childTransform = targetObjectTransform.GetChild(0); var sphereCenter = childTransform.localPosition; float mass; if (bone.IsSkirt) { mass = 0.2f; } else { // Only layer 0 bones are marked IsSkirt=true if (IsOnSkirtChain(bone)) { mass = 0.1f; } else { mass = 1; } } var body2 = AddRigidBody(targetObject, sphereCenter, mass); if (bonePart.Contains("hair_")) { body2.drag = 1; } Debug.Assert(bone.Type == ColliderType.Sphere); if (bonePart.Contains("hair_")) { var collider = targetObject.AddComponent <CapsuleCollider>(); collider.radius = bone.Radius; collider.direction = 0; // X-axis collider.height = (childTransform.position - targetObjectTransform.position).magnitude; collider.center = sphereCenter; collider.material = defaultPhysicMaterial; } else { var collider = targetObject.AddComponent <SphereCollider>(); collider.radius = bone.Radius; collider.center = sphereCenter; // skirts should be slippery so don't use default phys mat if (!bone.IsSkirt) { collider.material = defaultPhysicMaterial; } } // Add a joint var joint = targetObject.AddComponent <ConfigurableJoint>(); joint.xMotion = ConfigurableJointMotion.Locked; joint.yMotion = ConfigurableJointMotion.Locked; joint.zMotion = ConfigurableJointMotion.Locked; // Don't twist joint.angularXMotion = ConfigurableJointMotion.Limited; joint.connectedBody = body1; foreach (var childBone in bone.Children) { AddSwayBone(root, childBone, cache); } }