Esempio n. 1
0
    /// <summary>
    /// initialize class instance
    /// </summary>
    public override void Initialize()
    {
        if (m_Initialized)
        {
            return;
        }

        base.Initialize();

        // keep track of colliders and rigid bodies
        m_BodyParts = new BodyPartInfo[(int)BodyParts.BODY_PART_COUNT];

        bool ragdollComplete = true;

        for (int i = 0; i < (int)BodyParts.BODY_PART_COUNT; ++i)
        {
            Rigidbody rb  = RagdollBones[i].GetComponent <Rigidbody>();
            Collider  col = RagdollBones[i].GetComponent <Collider>();
            if (rb == null || col == null)
            {
                ragdollComplete = false;
#if DEBUG_INFO
                Debug.LogError("missing ragdoll part: " + ((BodyParts)i).ToString());
#endif
            }

            m_BodyParts[i]             = new BodyPartInfo();
            m_BodyParts[i].transform   = RagdollBones[i];
            m_BodyParts[i].rigidBody   = rb;
            m_BodyParts[i].collider    = col;
            m_BodyParts[i].bodyPart    = (BodyParts)i;
            m_BodyParts[i].orig_parent = RagdollBones[i].parent;
            CharacterJoint cj = RagdollBones[i].GetComponent <CharacterJoint>();
            if (cj != null)
            {
                m_BodyParts[i].constraintJoint  = cj;
                m_BodyParts[i].jointConnectBody = cj.connectedBody;
                cj.enableProjection             = true;
            }
        }

        if (!ragdollComplete)
        {
            Debug.LogError("ragdoll is incomplete or missing");
            return;
        }

        m_RootTransform = m_BodyParts[(int)BodyParts.Spine].transform;
        //setLayer
        var trans = m_RootTransform.GetComponentsInChildren <Transform>();
        for (int i = 0; i < trans.Length; i++)
        {
            trans[i].gameObject.layer = Game.Const.LAYER_RAGDOLL;
        }

        m_Initialized = true;
        disableRagdoll();
    }
Esempio n. 2
0
 public BodyPart()
 {
     PartNode              = new SimpleSubrecord <String>();
     VATSTarget            = new SimpleSubrecord <String>();
     IKDataStartNode       = new SimpleSubrecord <String>();
     Data                  = new BodyPartInfo();
     LimbReplacementModel  = new SimpleSubrecord <String>();
     GoreEffectsTargetBone = new SimpleSubrecord <String>();
 }
Esempio n. 3
0
    public override void DisableCustomRagdoll()
    {
        disableRagdoll();

        for (int i = 1; i < BodypartCount; i++)
        {
            BodyPartInfo b = m_BodyParts[i];
            b.transform.SetParent(b.orig_parent);
        }
    }
Esempio n. 4
0
    // start ragdoll method
    private void RunRagdoll()
    {
#if DEBUG_INFO
        if (m_BodyParts == null)
        {
            Debug.LogError("object cannot be null."); return;
        }
#endif
        enableRagdoll(true);

#if SAVE_ANIMATOR_STATES
        saveAnimatorStates();
#endif

        for (int i = 1; i < BodypartCount; i++)
        {
            if (m_BodyParts[i].ignoreRagdoll == true)
            {
                continue;
            }
            BodyPartInfo b = m_BodyParts[i];
            b.transform.SetParent(transform);
        }

        if (m_ForceVelocityOveral.HasValue)
        {
            for (int i = 0; i < m_BodyParts.Length; i++)
            {
                m_BodyParts[i].rigidBody.velocity = m_ForceVelocityOveral.Value;
            }
        }
#if CALC_CUSTOM_VELOCITY_KINEMATIC
        else
        {
            for (int i = 0; i < m_BodyParts.Length; i++)
            {
                BodyPartInfo b = m_BodyParts[i];
                b.rigidBody.velocity = b.customVelocity;
            }
        }
#endif

        if (m_HitParts != null)
        {
            if (m_ForceVel.HasValue)
            {
                BodyPartInfo b = m_BodyParts[m_HitParts.Value];
                b.rigidBody.velocity = m_ForceVel.Value;
            }
        }

        m_ForceVel            = null;
        m_ForceVelocityOveral = null;
        m_HitParts            = null;
    }
Esempio n. 5
0
    public override void DisableCustomRagdoll()
    {
#if UNITY_EDITOR
        DrawDir = false;
#endif
        disableRagdoll();

        for (int i = 1; i < BodypartCount; i++)
        {
            if (m_BodyParts[i].ignoreRagdoll == true)
            {
                continue;
            }
            BodyPartInfo b = m_BodyParts[i];
            b.transform.SetParent(b.orig_parent);
        }
    }
Esempio n. 6
0
    public BodyData()
    {
        bodySpec = new Dictionary <string, BodyPartInfo>();
        string[] bodyPartNames = { "Hips",  "LeftUpLeg", "LeftLeg", "LeftFoot", "RightUpLeg",   "RightLeg", "RightFoot",
                                   "Spine", "Spine1",    "Neck",    "Head",     "LeftShoulder", "LeftArm",  "LeftForeArm","LeftHand","RightShoulder", "RightArm", "RightForeArm", "RightHand" };
        foreach (string name in bodyPartNames)
        {
            bodySpec[name] = new BodyPartInfo(new List <PrimitiveSpec>(), new JointParameters());
        }

        bodySpec["Hips"].Shapes.Add(new PrimitiveSpec(PrimitiveType.Sphere, Vector3.up * 0.3f, Quaternion.identity, Vector3.one * 0.7f));
        bodySpec["LeftUpLeg"].Shapes.Add(new PrimitiveSpec(PrimitiveType.Sphere, Vector3.zero, Quaternion.identity, Vector3.one * 0.3f));
        bodySpec["LeftUpLeg"].Shapes.Add(new PrimitiveSpec(PrimitiveType.Capsule, Vector3.up * -0.79f, Quaternion.identity, new Vector3(0.4f, 0.78f, 0.4f)));
        bodySpec["LeftLeg"].Shapes.Add(new PrimitiveSpec(PrimitiveType.Sphere, Vector3.zero, Quaternion.identity, Vector3.one * 0.2f));
        bodySpec["LeftLeg"].Shapes.Add(new PrimitiveSpec(PrimitiveType.Capsule, Vector3.up * -0.79f, Quaternion.identity, new Vector3(0.4f, 0.73f, 0.4f)));
        bodySpec["LeftFoot"].Shapes.Add(new PrimitiveSpec(PrimitiveType.Sphere, Vector3.zero, Quaternion.identity, Vector3.one * 0.2f));
        bodySpec["LeftFoot"].Shapes.Add(new PrimitiveSpec(PrimitiveType.Cube, new Vector3(0, -0.1f, 0.26f), Quaternion.Euler(9f, 0, 0), new Vector3(0.3f, 0.2f, 0.6f)));
        bodySpec["RightUpLeg"].Shapes.Add(new PrimitiveSpec(PrimitiveType.Sphere, Vector3.zero, Quaternion.identity, Vector3.one * 0.3f));
        bodySpec["RightUpLeg"].Shapes.Add(new PrimitiveSpec(PrimitiveType.Capsule, Vector3.up * -0.79f, Quaternion.identity, new Vector3(0.4f, 0.78f, 0.4f)));
        bodySpec["RightLeg"].Shapes.Add(new PrimitiveSpec(PrimitiveType.Sphere, Vector3.zero, Quaternion.identity, Vector3.one * 0.2f));
        bodySpec["RightLeg"].Shapes.Add(new PrimitiveSpec(PrimitiveType.Capsule, Vector3.up * -0.79f, Quaternion.identity, new Vector3(0.4f, 0.73f, 0.4f)));
        bodySpec["RightFoot"].Shapes.Add(new PrimitiveSpec(PrimitiveType.Sphere, Vector3.zero, Quaternion.identity, Vector3.one * 0.2f));
        bodySpec["RightFoot"].Shapes.Add(new PrimitiveSpec(PrimitiveType.Cube, new Vector3(0, -0.1f, 0.26f), Quaternion.Euler(9f, 0, 0), new Vector3(0.3f, 0.2f, 0.6f)));
        bodySpec["Spine"].Shapes.Add(new PrimitiveSpec(PrimitiveType.Sphere, Vector3.up * 0.8f, Quaternion.identity, Vector3.one * 0.5f));
        bodySpec["Spine1"].Shapes.Add(new PrimitiveSpec(PrimitiveType.Sphere, Vector3.up * 0.33f, Quaternion.identity, Vector3.one * 0.8f));
        bodySpec["Neck"].Shapes.Add(new PrimitiveSpec(PrimitiveType.Sphere, Vector3.zero, Quaternion.identity, Vector3.one * 0.2f));
        bodySpec["Head"].Shapes.Add(new PrimitiveSpec(PrimitiveType.Sphere, Vector3.up * -0.1f, Quaternion.identity, Vector3.one * 0.8f));
        // left and right reversed
        bodySpec["LeftShoulder"].Shapes.Add(new PrimitiveSpec(PrimitiveType.Capsule, Vector3.right * 0.33f, Quaternion.Euler(0, 0, 90f), new Vector3(0.3f, 0.33f, 0.3f)));
        bodySpec["LeftArm"].Shapes.Add(new PrimitiveSpec(PrimitiveType.Sphere, Vector3.zero, Quaternion.identity, Vector3.one * 0.2f));
        bodySpec["LeftArm"].Shapes.Add(new PrimitiveSpec(PrimitiveType.Capsule, Vector3.right * 0.55f, Quaternion.Euler(0, 0, 90f), new Vector3(0.3f, 0.55f, 0.3f)));
        bodySpec["LeftForeArm"].Shapes.Add(new PrimitiveSpec(PrimitiveType.Sphere, Vector3.zero, Quaternion.identity, Vector3.one * 0.2f));
        bodySpec["LeftForeArm"].Shapes.Add(new PrimitiveSpec(PrimitiveType.Capsule, Vector3.right * 0.43f, Quaternion.Euler(0, 0, 90f), new Vector3(0.3f, 0.45f, 0.3f)));
        bodySpec["LeftHand"].Shapes.Add(new PrimitiveSpec(PrimitiveType.Sphere, Vector3.zero, Quaternion.identity, Vector3.one * 0.2f));
        bodySpec["RightShoulder"].Shapes.Add(new PrimitiveSpec(PrimitiveType.Capsule, Vector3.right * -0.33f, Quaternion.Euler(0, 0, 90f), new Vector3(0.3f, 0.33f, 0.3f)));
        bodySpec["RightArm"].Shapes.Add(new PrimitiveSpec(PrimitiveType.Sphere, Vector3.zero, Quaternion.identity, Vector3.one * 0.2f));
        bodySpec["RightArm"].Shapes.Add(new PrimitiveSpec(PrimitiveType.Capsule, Vector3.right * -0.55f, Quaternion.Euler(0, 0, 90f), new Vector3(0.3f, 0.55f, 0.3f)));
        bodySpec["RightForeArm"].Shapes.Add(new PrimitiveSpec(PrimitiveType.Sphere, Vector3.zero, Quaternion.identity, Vector3.one * 0.2f));
        bodySpec["RightForeArm"].Shapes.Add(new PrimitiveSpec(PrimitiveType.Capsule, Vector3.right * -0.43f, Quaternion.Euler(0, 0, 90f), new Vector3(0.3f, 0.45f, 0.3f)));
        bodySpec["RightHand"].Shapes.Add(new PrimitiveSpec(PrimitiveType.Sphere, Vector3.zero, Quaternion.identity, Vector3.one * 0.2f));

        bodySpec["Spine"].JointParameters = new JointParameters(new Vector3(0, 0.6f, 0));
        bodySpec["Head"].JointParameters  = new JointParameters(new Vector3(0, -0.52f, 0));
    }
Esempio n. 7
0
    public void DisableCustomRagdoll()
    {
        DrawDir = false;

        disableRagdoll();

        for (int i = 1; i < BodypartCount; i++)
        {
            if (m_BodyParts[i].ignoreRagdoll == true)
            {
                continue;
            }
            BodyPartInfo b = m_BodyParts[i];
            b.transform.SetParent(b.orig_parent);
        }

        foreach (BodyPartInfo b in m_BodyParts)
        {
            b.transitionRotation = b.transform.rotation;
            b.transitionPosition = b.transform.position;
        }
    }
Esempio n. 8
0
    private void InitBodyParts()
    {
        int boneCount = RagdollBones.Length;

        if (m_BodyParts.Length > 0)
        {
            Array.Clear(m_BodyParts, 0, boneCount);
        }
        m_BodyParts = new BodyPartInfo[boneCount];
        for (int i = 0; i < boneCount; i++)
        {
            m_BodyParts[i]             = new BodyPartInfo();
            m_BodyParts[i].transform   = RagdollBones[i].transform;
            m_BodyParts[i].orig_parent = RagdollBones[i].transform.parent;
            m_BodyParts[i].collider    = RagdollBones[i].GetComponent <Collider>();
            m_BodyParts[i].rigidBody   = RagdollBones[i].GetComponent <Rigidbody>();
        }
        var trans = m_BodyParts[0].transform.GetComponentsInChildren <Transform>();

        for (int i = 0; i < trans.Length; i++)
        {
            trans[i].gameObject.layer = Game.Const.LAYER_RAGDOLL;
        }
    }
Esempio n. 9
0
    protected void RunRagdoll()
    {
#if DEBUG_INFO
        if (m_BodyParts == null)
        {
            Debug.LogError("object cannot be null."); return;
        }
#endif
        enableRagdoll(true);

#if SAVE_ANIMATOR_STATES
        saveAnimatorStates();
#endif

        for (int i = 1; i < BodypartCount; i++)
        {
            if (m_BodyParts[i].ignoreRagdoll == true)
            {
                continue;
            }
            BodyPartInfo b = m_BodyParts[i];
            b.transform.SetParent(transform);
        }

        if (m_HitParts != null)
        {
            if (m_ForceVel.HasValue)
            {
                BodyPartInfo b = m_BodyParts[m_HitParts.Value];
                b.rigidBody.velocity = m_ForceVel.Value;
            }
        }

        m_ForceVel = null;
        m_HitParts = null;
    }
Esempio n. 10
0
        /// <summary>
        /// Create a rotational joint between the two body parts.
        /// </summary>
        /// <param name="bodyPartA">The first body part being joined.</param>
        /// <param name="bodyPartB">The second body part being joined.</param>
        /// <param name="positionB">The position of the joint relative to the second body part.</param>
        /// <param name="enableLimit">Indicates whether the limit is enabled.</param>
        /// <param name="upperLimit">The upper joint limit in radians.</param>
        /// <param name="lowerLimit">The lower joint limit in radians.</param>
        /// <param name="enableMotor">Indicates whether the motor is enabled.</param>
        /// <param name="maxMotorTorque">The maximum motor torque.</param>
        private void CreateRotationalJoint(
            BodyPartInfo bodyPartA,
            BodyPartInfo bodyPartB,
            Vector2 positionB,
            bool enableLimit,
            float upperLimit,
            float lowerLimit,
            bool enableMotor,
            float maxMotorTorque)
        {
            // Create the joint
            RevoluteJoint joint = JointFactory.CreateRevoluteJoint(
                this.world.Physics,
                bodyPartA.PhysicsComponent.Body,
                bodyPartB.PhysicsComponent.Body,
                positionB);

            // Set the limit and motor properties
            joint.UpperLimit = upperLimit;
            joint.LowerLimit = lowerLimit;
            joint.MaxMotorTorque = maxMotorTorque;
            joint.LimitEnabled = enableLimit;
            joint.MotorEnabled = enableMotor;

            // Register the joint with the two body parts
            bodyPartA.BodyPartComponent.Joints.Add(joint);
            bodyPartB.BodyPartComponent.Joints.Add(joint);
        }
Esempio n. 11
0
        /// <summary>
        /// Create a fixed joint between the two body parts.
        /// </summary>
        /// <param name="bodyPartA">The first body part being joined.</param>
        /// <param name="bodyPartB">The second body part being joined.</param>
        private void CreateFixedJoint(BodyPartInfo bodyPartA, BodyPartInfo bodyPartB)
        {
            // Create the joint
            Joint joint = JointFactory.CreateWeldJoint(
                this.world.Physics,
                bodyPartA.PhysicsComponent.Body,
                bodyPartB.PhysicsComponent.Body,
                Vector2.Zero,
                Vector2.Zero);

            // Register the joint with the two body parts
            bodyPartA.BodyPartComponent.Joints.Add(joint);
            bodyPartB.BodyPartComponent.Joints.Add(joint);
        }
Esempio n. 12
0
 public BodyPart(SimpleSubrecord <String> PartNode, SimpleSubrecord <String> VATSTarget, SimpleSubrecord <String> IKDataStartNode, BodyPartInfo Data, SimpleSubrecord <String> LimbReplacementModel, SimpleSubrecord <String> GoreEffectsTargetBone, SimpleSubrecord <Byte[]> TextureFileHashes)
 {
     this.PartNode              = PartNode;
     this.VATSTarget            = VATSTarget;
     this.IKDataStartNode       = IKDataStartNode;
     this.Data                  = Data;
     this.LimbReplacementModel  = LimbReplacementModel;
     this.GoreEffectsTargetBone = GoreEffectsTargetBone;
     this.TextureFileHashes     = TextureFileHashes;
 }
Esempio n. 13
0
        public override void ReadXML(XElement ele, ElderScrollsPlugin master)
        {
            XElement subEle;

            if (ele.TryPathTo("PartNode", false, out subEle))
            {
                if (PartNode == null)
                {
                    PartNode = new SimpleSubrecord <String>();
                }

                PartNode.ReadXML(subEle, master);
            }
            if (ele.TryPathTo("VATSTarget", false, out subEle))
            {
                if (VATSTarget == null)
                {
                    VATSTarget = new SimpleSubrecord <String>();
                }

                VATSTarget.ReadXML(subEle, master);
            }
            if (ele.TryPathTo("IKData/StartNode", false, out subEle))
            {
                if (IKDataStartNode == null)
                {
                    IKDataStartNode = new SimpleSubrecord <String>();
                }

                IKDataStartNode.ReadXML(subEle, master);
            }
            if (ele.TryPathTo("Data", false, out subEle))
            {
                if (Data == null)
                {
                    Data = new BodyPartInfo();
                }

                Data.ReadXML(subEle, master);
            }
            if (ele.TryPathTo("LimbReplacementModel", false, out subEle))
            {
                if (LimbReplacementModel == null)
                {
                    LimbReplacementModel = new SimpleSubrecord <String>();
                }

                LimbReplacementModel.ReadXML(subEle, master);
            }
            if (ele.TryPathTo("GoreEffectsTargetBone", false, out subEle))
            {
                if (GoreEffectsTargetBone == null)
                {
                    GoreEffectsTargetBone = new SimpleSubrecord <String>();
                }

                GoreEffectsTargetBone.ReadXML(subEle, master);
            }
            if (ele.TryPathTo("TextureFileHashes", false, out subEle))
            {
                if (TextureFileHashes == null)
                {
                    TextureFileHashes = new SimpleSubrecord <Byte[]>();
                }

                TextureFileHashes.ReadXML(subEle, master);
            }
        }