Exemple #1
0
 /// <summary> Check if all RigidBody settings allow us to pick up objects. </summary>
 protected void ValidateRB()
 {
     this.physicsBody = this.GetComponent <Rigidbody>();
     if (this.physicsBody != null)
     {
         if (this.physicsBody.useGravity)
         {
             SG_Debugger.LogWarning(this.name + ".DropZone has a rigidbody that uses gravity, and might move from its desired location.");
         }
     }
     else //we don't have a RigidBody, so one of the ObjectsToGet should have it!
     {
         if (this.objectsToGet.Count > 0)
         {
             bool noRBs = true;
             for (int i = 0; i < this.objectsToGet.Count; i++)
             {
                 if (this.objectsToGet[i].physicsBody == null)
                 {
                     SG_Debugger.LogWarning(this.objectsToGet[i].name + " will not be detected by " + this.name
                                            + ".DropZone, as neither have a RigidBody attached.");
                 }
                 else
                 {
                     noRBs = false;
                 }
             }
             if (noRBs)
             {
                 Debug.LogWarning("Since none of the ObjectsToGet in " + this.name + " have a RigidBody attached, one was autmatically attached to the GameObject.");
                 this.physicsBody             = this.gameObject.AddComponent <Rigidbody>();
                 this.physicsBody.useGravity  = false;
                 this.physicsBody.isKinematic = true;
             }
         }
         else
         {
             SG_Debugger.LogWarning(this.name + ".DropZone has no RigidBody of its own, and will therefore only " +
                                    "detect Grabables with a RigidBody attached.");
         }
     }
 }
Exemple #2
0
        //-----------------------------------------------------------------------------------------------------------------------------------------
        // Hand Model WireFrame Functions

        /// <summary> Generate a base wireframe for the hand: 5 Fingers with 4 joints each. </summary>
        private void GenerateFingers()
        {
            if (fingerJoints == null)
            {
                float baseLength = 0; //all phalanges are 20mm, just for the sake of being able to see them(?)
                if (phalangeModel != null && handBase != null)
                {
                    this.fingerJoints = new Transform[5][];
                    for (int f = 0; f < fingerJoints.Length; f++)
                    {
                        fingerJoints[f] = new Transform[4];
                        for (int i = 0; i < fingerJoints[f].Length; i++)
                        {
                            GameObject handPosition = GameObject.Instantiate(phalangeModel, this.handBase.transform);
                            handPosition.name = "HandPostion" + f + "" + i;
                            handPosition.transform.localRotation = new Quaternion();
                            fingerJoints[f][i] = handPosition.transform;
                            if (i < fingerJoints[f].Length - 1)
                            {
                                if (handPosition.transform.childCount > 0)
                                {
                                    Transform dX = handPosition.transform.GetChild(0);
                                    //Setup correct sizes.
                                    dX.localScale    = new Vector3(dX.localScale.x, baseLength / 2.0f, dX.localScale.z);
                                    dX.localPosition = new Vector3(baseLength / 2.0f, 0, 0);
                                }
                            }
                            else
                            {
                                Transform dX = handPosition.transform.GetChild(0);
                                GameObject.Destroy(dX.gameObject); //remove dX
                            }
                            handPosition.SetActive(true);
                        }
                    }
                }
                else
                {
                    SG_Debugger.Log("WARNING : No base model for Hand Wireframe");
                }
            }
        }
Exemple #3
0
 /// <summary> Begin the interaction between this object and a GrabScript. </summary>
 /// <param name="grabScript"></param>
 /// <param name="fromExternal"></param>
 public bool BeginInteraction(SG_GrabScript grabScript, bool fromExternal = false)
 {
     if (grabScript != null)
     {
         if (this.isInteractable || fromExternal) //interactions only possible through these parameters.
         {
             bool begun = this.InteractionBegin(grabScript, fromExternal);
             if (begun)
             {
                 this.originalDist = (grabScript.grabReference.transform.position - this.transform.position).magnitude;
                 this.OnInteractBegin(grabScript, fromExternal);
                 return(true);
             }
         }
     }
     else
     {
         SG_Debugger.LogError("ERROR: You are attempting to start an interaction with " + this.name + " with grabscript set to NULL");
     }
     return(false);
 }
Exemple #4
0
 /// <summary> Connect this Grabable's rigidBody to another using a FixedJoint </summary>
 /// <param name="other"></param>
 /// <returns>True, if the connection was sucesfully made.</returns>
 public bool ConnectJoint(Rigidbody other, float breakForce = SG_Grabable.defaultBreakForce)
 {
     if (other != null)
     {
         if (this.physicsBody)
         {
             this.connection = this.physicsBody.gameObject.AddComponent <FixedJoint>();
             this.connection.connectedBody   = other;
             this.connection.enableCollision = false;
             this.connection.breakForce      = breakForce;
             return(true);
         }
         else
         {
             SG_Debugger.Log("Using a FixedJoint connection requires a Rigidbody.");
         }
     }
     else
     {
         SG_Debugger.Log("No rigidbody to connect to " + other.name);
     }
     return(false);
 }
Exemple #5
0
    /// <summary> Create a new glove section based on the parameters sent from the Sense Glove. </summary>
    /// <param name="gloveData"></param>
    private void SetupGlove(SenseGlove_Data gloveData)
    {
        if (!this.setupComplete && gloveData != null)
        {
            gloveBase.SetActive(true);
            gloveSectionModel.SetActive(false);

            int x = 0, y = 1, z = 2;

            if (gloveData.dataLoaded)
            {
                this.gloveBase.transform.localPosition = gloveData.commonOriginPos;
                this.gloveBase.transform.localRotation = gloveData.commonOriginRot;

                Vector3[][] glovePos     = gloveData.glovePositions;
                Vector3[][] gloveLengths = gloveData.gloveLengths;
                this.gloveJoints = new Transform[glovePos.Length][];
                for (int f = 0; f < gloveJoints.Length; f++)
                {
                    gloveJoints[f] = new Transform[glovePos[f].Length];
                    for (int i = 0; i < gloveJoints[f].Length; i++)
                    {
                        GameObject gloveJoint = GameObject.Instantiate(gloveSectionModel, this.gloveBase.gameObject.transform);
                        gloveJoint.name = "GlovePostion" + f + "" + i;
                        gloveJoint.transform.localRotation = new Quaternion();
                        gloveJoint.transform.localPosition = glovePos[f][0];
                        if (i < gloveJoints[f].Length - 1)
                        {
                            if (gloveJoint.transform.childCount > 2)
                            {
                                Transform dX = gloveJoint.transform.GetChild(2);
                                Transform dY = gloveJoint.transform.GetChild(1);
                                Transform dZ = gloveJoint.transform.GetChild(0);

                                //Setup correct sizes.
                                if (gloveLengths[f][i][x] != 0)
                                {
                                    dX.localScale = new Vector3(dX.localScale.x, gloveLengths[f][i][x] / 2.0f, dX.localScale.z);
                                }
                                else
                                {
                                    dX.gameObject.SetActive(false);
                                }
                                if (gloveLengths[f][i][y] != 0)
                                {
                                    dY.localScale = new Vector3(dX.localScale.x, gloveLengths[f][i][y] / 2.0f, dX.localScale.z);
                                }
                                else
                                {
                                    dY.gameObject.SetActive(false);
                                }
                                if (gloveLengths[f][i][z] != 0)
                                {
                                    dZ.localScale = new Vector3(dX.localScale.x, gloveLengths[f][i][z] / 2.0f, dX.localScale.z);
                                }
                                else
                                {
                                    dZ.gameObject.SetActive(false);
                                }

                                //set correct positions based on ZYX?
                                dY.localPosition = new Vector3(0, gloveLengths[f][i][y] / 2.0f, 0);
                                dX.localPosition = new Vector3(gloveLengths[f][i][x] / 2.0f, gloveLengths[f][i][y], 0);
                                //dY ?
                            }
                        }
                        else
                        {
                            for (int j = 0; j < gloveJoint.transform.childCount - 1; j++)
                            {
                                gloveJoint.transform.GetChild(j).gameObject.SetActive(false);
                            }
                        }
                        gloveJoint.SetActive(true);
                        gloveJoints[f][i] = gloveJoint.transform;
                    }
                }
            }
            else
            {
                SG_Debugger.Log("ERROR : No Glove Data was found...");
            }
        }
        else
        {
            SG_Debugger.Log("WARNING : No base model for Glove Wireframe");
        }
    }
Exemple #6
0
    /// <summary> Create all the individual finger sections based on the glove's handModel. </summary>
    /// <param name="gloveData"></param>
    private void SetupFingers(SenseGlove_Data gloveData)
    {
        this.resizeFingers = true;
        if (!this.setupComplete && gloveData != null)
        {
            int x = 0;
            if (phalangeModel != null && handBase != null)
            {
                if (gloveData.dataLoaded)
                {
                    this.handBase.transform.localPosition = gloveData.commonOriginPos;
                    this.handBase.transform.localRotation = gloveData.commonOriginRot;

                    Vector3[][] handPos     = gloveData.handPositions;
                    Vector3[][] handLengths = gloveData.handLengths;

                    this.fingerJoints = new Transform[handPos.Length][];
                    for (int f = 0; f < handPos.Length; f++)
                    {
                        List <Transform> joints = new List <Transform>();

                        for (int i = 0; i < handPos[f].Length; i++)
                        {
                            GameObject handPosition = GameObject.Instantiate(phalangeModel, this.handBase.transform);
                            handPosition.name = "HandPostion" + f + "" + i;
                            handPosition.transform.localRotation = new Quaternion();
                            if (i < handPos[f].Length - 1)
                            {
                                if (handPosition.transform.childCount > 0)
                                {
                                    Transform dX = handPosition.transform.GetChild(0);
                                    //Setup correct sizes.
                                    if (handLengths[f][i][x] != 0)
                                    {
                                        dX.localScale = new Vector3(dX.localScale.x, handLengths[f][i][x] / 2.0f, dX.localScale.z);
                                    }
                                    else
                                    {
                                        dX.gameObject.SetActive(false);
                                    }
                                    dX.localPosition = new Vector3(handLengths[f][i][x] / 2.0f, 0, 0);
                                }
                            }
                            else
                            {
                                Transform dX = handPosition.transform.GetChild(0);
                                dX.gameObject.SetActive(false);
                            }
                            handPosition.SetActive(true);
                            joints.Add(handPosition.transform);
                        }
                        this.fingerJoints[f] = (joints).ToArray();
                    }
                }
                else
                {
                    SG_Debugger.Log("ERROR : No Hand Data was found...");
                }
            }
            else
            {
                SG_Debugger.Log("WARNING : No base model for Hand Wireframe");
            }
        }
        else
        {
            SG_Debugger.Log("WARNING : GloveData is null?");
        }
    }
Exemple #7
0
        //-----------------------------------------------------------------------------------------------------------------------------------------
        // Glove Model WireFrame Functions

        /// <summary> Generate a wireframe for a glove, based on its GloveModel </summary>
        /// <param name="gloveModel"></param>
        public void GenerateGlove(SGCore.SG.SG_GloveInfo gloveModel)
        {
            if (gloveModel != null)
            {
                gloveBase.SetActive(true);
                gloveSectionModel.SetActive(true);

                Vector3[][] gloveLengths = SG.Util.SG_Conversions.ToUnityPositions(gloveModel.GloveLengths, true);
                int         x = 0, y = 1, z = 2;
                this.gloveJoints = new Transform[gloveModel.GloveLengths.Length][];
                for (int f = 0; f < gloveJoints.Length; f++)
                {
                    gloveJoints[f] = new Transform[gloveModel.GloveLengths[f].Length + 1];

                    for (int i = 0; i < gloveJoints[f].Length; i++)
                    {
                        GameObject gloveJoint = GameObject.Instantiate(gloveSectionModel, this.gloveBase.gameObject.transform);
                        gloveJoint.name = "GlovePostion" + f + "" + i;
                        gloveJoint.transform.localRotation = Quaternion.identity;
                        gloveJoints[f][i] = gloveJoint.transform;
                        //gloveJoint.SetActive(true);
                        if (i < gloveJoints[f].Length - 1)
                        {
                            if (gloveJoint.transform.childCount > 2)
                            {
                                Transform dX = gloveJoint.transform.GetChild(2);
                                Transform dY = gloveJoint.transform.GetChild(1);
                                Transform dZ = gloveJoint.transform.GetChild(0);

                                //Setup correct sizes.
                                if (gloveLengths[f][i][x] != 0)
                                {
                                    dX.localScale = new Vector3(dX.localScale.x, gloveLengths[f][i][x] / 2.0f, dX.localScale.z);
                                }
                                else
                                {
                                    dX.gameObject.SetActive(false);
                                }
                                if (gloveLengths[f][i][y] != 0)
                                {
                                    dY.localScale = new Vector3(dX.localScale.x, gloveLengths[f][i][y] / 2.0f, dX.localScale.z);
                                }
                                else
                                {
                                    dY.gameObject.SetActive(false);
                                }
                                if (gloveLengths[f][i][z] != 0)
                                {
                                    dZ.localScale = new Vector3(dX.localScale.x, gloveLengths[f][i][z] / 2.0f, dX.localScale.z);
                                }
                                else
                                {
                                    dZ.gameObject.SetActive(false);
                                }

                                //set correct positions based on ZYX?
                                dY.localPosition = new Vector3(0, gloveLengths[f][i][y] / 2.0f, 0);
                                dX.localPosition = new Vector3(gloveLengths[f][i][x] / 2.0f, gloveLengths[f][i][y] / 1.0f, 0);
                                //dY ?
                            }
                        }
                        else
                        {
                            for (int j = 0; j < gloveJoint.transform.childCount - 1; j++) //the last one is just the dot
                            {
                                GameObject.Destroy(gloveJoint.transform.GetChild(j).gameObject);
                            }
                        }
                    }
                }
                gloveSectionModel.SetActive(false);
            }
            else
            {
                SG_Debugger.Log("WARNING : No base model for Glove Wireframe");
            }
        }