public static glTF_VCAST_vci_joint GetglTFJointFromUnityJoint(Joint joint, List <Transform> nodes) { var result = new glTF_VCAST_vci_joint(); result.nodeIndex = nodes.FindIndex(x => x == joint.connectedBody.gameObject.transform); result.anchor = joint.anchor.ReverseZ().ToArray(); result.axis = joint.axis.ReverseZ().ToArray(); result.autoConfigureConnectedAnchor = joint.autoConfigureConnectedAnchor; result.connectedAnchor = joint.connectedAnchor.ReverseZ().ToArray(); result.enableCollision = joint.enableCollision; result.enablePreprocessing = joint.enablePreprocessing; result.massScale = joint.massScale; result.connectedMassScale = joint.connectedMassScale; if (joint.GetType() == typeof(FixedJoint)) { result.type = JointString.Fixed; } else if (joint.GetType() == typeof(HingeJoint)) { var hinge = joint as HingeJoint; result.type = JointString.Hinge; // spring result.useSpring = hinge.useSpring; result.spring = new Spring() { spring = hinge.spring.spring, damper = hinge.spring.damper, targetPosition = hinge.spring.targetPosition }; // limits result.useLimits = hinge.useLimits; result.limits = new Limits() { min = hinge.limits.min, max = hinge.limits.max, bounciness = hinge.limits.bounciness, bounceMinVelocity = hinge.limits.bounceMinVelocity, contactDistance = hinge.limits.contactDistance }; } else if (joint.GetType() == typeof(SpringJoint)) { var spring = joint as SpringJoint; result.type = JointString.Spring; result.spring = new Spring() { spring = spring.spring, damper = spring.damper, minDistance = spring.minDistance, maxDistance = spring.maxDistance, tolerance = spring.tolerance, }; } return(result); }
public static Joint AddJointComponent(GameObject go, glTF_VCAST_vci_joint joint, List <Transform> nodes) { var result = GetJoint(go, joint); if (joint.nodeIndex != -1) { var rigidbody = nodes[joint.nodeIndex].GetComponent <Rigidbody>(); if (rigidbody == null) { Debug.LogWarning("AddJointComponent connect RigidBody is not found."); return(null); } result.connectedBody = rigidbody; } // 共通パラメータ result.anchor = new Vector3(joint.anchor[0], joint.anchor[1], joint.anchor[2]).ReverseZ(); result.axis = new Vector3(joint.axis[0], joint.axis[1], joint.axis[2]).ReverseZ(); result.autoConfigureConnectedAnchor = joint.autoConfigureConnectedAnchor; result.connectedAnchor = new Vector3(joint.connectedAnchor[0], joint.connectedAnchor[1], joint.connectedAnchor[2]).ReverseZ(); result.enableCollision = joint.enableCollision; result.enablePreprocessing = joint.enablePreprocessing; result.massScale = joint.massScale; result.connectedMassScale = joint.connectedMassScale; // 個別パラメータ if (result.GetType() == typeof(HingeJoint)) { var hinge = result as HingeJoint; // spring hinge.useSpring = joint.useSpring; hinge.spring = new JointSpring() { spring = joint.spring.spring, damper = joint.spring.damper, targetPosition = joint.spring.targetPosition }; // limits hinge.useLimits = joint.useLimits; hinge.limits = new JointLimits() { min = joint.limits.min, max = joint.limits.max, bounciness = joint.limits.bounciness, bounceMinVelocity = joint.limits.bounceMinVelocity, contactDistance = joint.limits.contactDistance }; } else if (result.GetType() == typeof(SpringJoint)) { var spring = result as SpringJoint; spring.spring = joint.spring.spring; spring.damper = joint.spring.damper; spring.minDistance = joint.spring.minDistance; spring.maxDistance = joint.spring.maxDistance; spring.tolerance = joint.spring.tolerance; } return(result); }