Inheritance: MonoBehaviour
                public void ElbowPointingUp()
                {
                    Vector3 shoulderToElbow = new Vector3(0, 1, 0);
                    double  yaw             = InverseKinematics.GetShoulderYaw(neckToSpine, shoulderR2L, shoulderToElbow);

                    Assert.AreEqual(90, yaw, angleTolerance);
                }
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object can be used to retrieve data from input parameters and
        /// to store data in output parameters.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            // Input variables
            Robot    robot    = null;
            Movement Movement = null;

            // Catch the input data
            if (!DA.GetData(0, ref robot))
            {
                return;
            }
            if (!DA.GetData(1, ref Movement))
            {
                return;
            }

            // Calculate the robot pose
            _inverseKinematics = new InverseKinematics(Movement, robot);
            _inverseKinematics.Calculate();

            // Check the values
            for (int i = 0; i < _inverseKinematics.ErrorText.Count; i++)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, _inverseKinematics.ErrorText[i]);
            }

            // Set forward kinematics (for visualization)
            _forwardKinematics = new ForwardKinematics(robot);

            // Output
            DA.SetData(0, _inverseKinematics.RobotJointPosition);
            DA.SetData(1, _inverseKinematics.ExternalJointPosition);
        }
                    public void WristPointingUp()
                    {
                        Point3 wrist = new Point3(10, 11, 9);
                        double roll  = InverseKinematics.GetShoulderRollRight(neckToSpine, shoulderL, shoulderR, elbow, wrist);

                        Assert.AreEqual(90, roll, angleTolerance);
                    }
                    public void Inline()
                    {
                        Point3 wrist = new Point3(10, 10, 8);
                        double roll  = InverseKinematics.GetShoulderRollRight(neckToSpine, shoulderL, shoulderR, elbow, wrist);

                        Assert.AreEqual(0, roll);
                    }
Beispiel #5
0
        /// <summary>
        /// Initializes a new instance of the Robot class with attached external axes.
        /// </summary>
        /// <param name="name"> The name. </param>
        /// <param name="meshes"> The base and links meshes defined in the world coorindate space. </param>
        /// <param name="internalAxisPlanes"> The internal axes planes defined in the world coorindate space. </param>
        /// <param name="internalAxisLimits"> The internal axes limit. </param>
        /// <param name="basePlane"> The position and orientation of the robot base in the world coordinate space. </param>
        /// <param name="mountingFrame"> The tool mounting frame definied in the world coordinate space. </param>
        /// <param name="tool"> The Robot Tool. </param>
        /// <param name="externalAxes"> The attached external axes. </param>
        public Robot(string name, List <Mesh> meshes, List <Plane> internalAxisPlanes, List <Interval> internalAxisLimits, Plane basePlane, Plane mountingFrame, RobotTool tool, List <ExternalAxis> externalAxes)
        {
            // Robot related fields
            _name               = name;
            _meshes             = meshes;
            _internalAxisPlanes = internalAxisPlanes;
            _internalAxisLimits = internalAxisLimits;
            _basePlane          = basePlane;
            _mountingFrame      = mountingFrame;

            // Tool related fields
            _tool = tool.Duplicate(); // Make a deep copy since we transform it later
            _meshes.Add(GetAttachedToolMesh());
            CalculateAttachedToolPlane();

            // External axis related fields
            _externalAxes       = externalAxes;
            _externalAxisPlanes = new List <Plane>();
            _externalAxisLimits = new List <Interval>();
            UpdateExternalAxisFields();

            // Transform Robot Tool to Mounting Frame
            Transform trans = Transform.PlaneToPlane(_tool.AttachmentPlane, _mountingFrame);

            _tool.Transform(trans);

            // Set kinematics
            _inverseKinematics = new InverseKinematics(new RobotTarget("init", Plane.WorldXY), this);
            _forwardKinematics = new ForwardKinematics(this);
        }
                public void Inline()
                {
                    Vector3 elbowToWrist = new Vector3(1, 0, 0);
                    double  angle        = InverseKinematics.GetElbowAngle(shoulderToElbow, elbowToWrist);

                    Assert.AreEqual(0, angle, angleTolerance);
                }
                public void Inline()
                {
                    Vector3 shoulderToElbow = new Vector3(1, 0, 0);
                    double  yaw             = InverseKinematics.GetShoulderYaw(neckToSpine, shoulderL2R, shoulderToElbow);

                    Assert.AreEqual(0, yaw, angleTolerance);
                }
Beispiel #8
0
    public void RestorePose(Pose pose)
    {
        var bones = GetComponentsInChildren <Bone>();

        Undo.RegisterCompleteObjectUndo(bones, "Assign Pose");

        foreach (RotationValue rv in pose.rotations)
        {
            System.Array.Find <Bone>(bones, b => b.name == rv.name).transform.localRotation = rv.rotation;
        }

        foreach (PositionValue pv in pose.positions)
        {
            System.Array.Find <Bone>(bones, b => b.name == pv.name).transform.localPosition = pv.position;
        }

        foreach (PositionValue tv in pose.targets)
        {
            Bone bone            = System.Array.Find <Bone>(bones, b => b.name == tv.name);
            InverseKinematics ik = bone.GetComponent <InverseKinematics>();

            if (ik != null)
            {
                Undo.RecordObject(ik.target, "Assign Pose");
                ik.target.transform.localPosition = tv.position;
            }
        }
    }
                public void WristPointingUp()
                {
                    Vector3 elbowToWrist = new Vector3(0, 1, 0);
                    double  angle        = InverseKinematics.GetElbowAngle(shoulderToElbow, elbowToWrist);

                    Assert.AreEqual(-90, angle, angleTolerance);
                }
Beispiel #10
0
    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    private void Start()
    {
        Transform lowerLeg = transform.Find("LowerLeg");
        Transform upperLeg = transform.Find("UpperLeg");

        this.kinematics = new InverseKinematics(lowerLeg, upperLeg);

        this.foot = kinematics.Foot();

        this.state = LegState.Stationary;
    }
        private static void AssertProjectionsMatchPointsLeft(Point3 elbow, Point3 wrist)
        {
            // Make sure the lengths of each segment are the expected lengths.
            Assert.AreEqual(1, Vector3.FromPoints(shoulderL, elbow).Magnitude);
            Assert.AreEqual(1, Vector3.FromPoints(elbow, wrist).Magnitude);

            InverseKinematics ik = InverseKinematics.GetInverseKinematicsLeft(neck, spine, shoulderL, shoulderR, elbow, wrist, inRadians: true);
            ForwardKinematics fk = ForwardKinematics.GetForwardKinematicsLeft(shoulderL, ik);

            Assert.AreEqual(elbow, fk.Elbow);
            Assert.AreEqual(wrist, fk.Wrist);
        }
Beispiel #12
0
 public void Clear()
 {
     MarkAsInvalid();
     InverseKinematics.Clear();
     Controller.DeleteAllLayers();
     Controller.Variables.Clear();
     Controller.ResultBonesPool.Reset(null);
     m_characterBones         = null;
     m_boneRelativeTransforms = null;
     m_boneAbsoluteTransforms = null;
     CharacterBonesSorted     = null;
 }
Beispiel #13
0
    private void Init()
    {
        serviceInitializer = new ServiceInitializerIK(sliders);
        serviceInitializer.InitializeSliders();

        serviceRotation = ScriptableObject.CreateInstance <ServiceRotationIK>();
        serviceRotation.Init(topLegs, bottomLegs);

        inverseKinematics = ScriptableObject.CreateInstance <InverseKinematics>();
        ballSimulation    = new BallSimulation(sliders);
        panelDrawing      = new PanelDrawing(panels);
    }
Beispiel #14
0
    private void EditorUpdate()
    {
        foreach (Bone b in gameObject.GetComponentsInChildren <Bone>())
        {
            InverseKinematics ik = b.GetComponent <InverseKinematics>();

            if (ik != null && !editMode && ik.enabled && ik.influence > 0)
            {
                ik.resolveSK2D();
            }
        }
    }
Beispiel #15
0
    void Start()
    {
        this.JointAngles = new float[JointTransforms.Length];
        this.JointBuffer = new float[JointTransforms.Length];

        if (this.physics_enabled)
        {
            this.MJoints = new ManipulatorJoint[7];
            for (int i = 0; i < 7; i++)
            {
                this.MJoints[i] = this.JointTransforms[i].GetComponent <ManipulatorJoint>();
            }
        }
        this.ik         = GetComponent <InverseKinematics>();
        this.reset_pose = false;
        // ResetPose();
    }
Beispiel #16
0
        private List <Interval> _externalAxisLimits;           // The external axis limit
        #endregion

        #region (de)serialization
        /// <summary>
        /// Protected constructor needed for deserialization of the object.
        /// </summary>
        /// <param name="info"> The SerializationInfo to extract the data from. </param>
        /// <param name="context"> The context of this deserialization. </param>
        protected Robot(SerializationInfo info, StreamingContext context)
        {
            _name               = (string)info.GetValue("Name", typeof(string));
            _meshes             = (List <Mesh>)info.GetValue("Meshes", typeof(List <Mesh>));
            _internalAxisPlanes = (List <Plane>)info.GetValue("Internal Axis Planes", typeof(List <Plane>));
            _internalAxisLimits = (List <Interval>)info.GetValue("Internal Axis Limits", typeof(List <Interval>));
            _basePlane          = (Plane)info.GetValue("Base Plane", typeof(Plane));
            _mountingFrame      = (Plane)info.GetValue("Mounting Frame", typeof(Plane));
            _tool               = (RobotTool)info.GetValue("RobotTool", typeof(RobotTool));
            _toolPlane          = (Plane)info.GetValue("Tool Plane", typeof(Plane));
            _externalAxes       = (List <ExternalAxis>)info.GetValue("External Axis", typeof(List <ExternalAxis>));
            _externalAxisPlanes = (List <Plane>)info.GetValue("External Axis Planes", typeof(List <Plane>));
            _externalAxisLimits = (List <Interval>)info.GetValue("External Axis Limits", typeof(List <Interval>));

            _inverseKinematics = new InverseKinematics(new RobotTarget("init", Plane.WorldXY), this);
            _forwardKinematics = new ForwardKinematics(this);
        }
    private void EditorUpdate()
    {
        if (bones != null)
        {
            for (int i = 0; i < bones.Length; i++)
            {
                if (bones[i] != null)
                {
                    InverseKinematics ik = bones[i].GetComponent <InverseKinematics>();

                    if (ik != null && !editMode && ik.enabled && ik.influence > 0)
                    {
                        ik.resolveSK2D();
                    }
                }
            }
        }
    }
Beispiel #18
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object can be used to retrieve data from input parameters and
        /// to store data in output parameters.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            // Warning that this component is OBSOLETE
            AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "This component is OBSOLETE and will be removed " +
                              "in the future. Remove this component from your canvas and replace it by picking the new component " +
                              "from the ribbon.");

            // Input variables
            Robot    robot    = null;
            Movement Movement = null;

            // Catch the input data
            if (!DA.GetData(0, ref robot))
            {
                return;
            }
            if (!DA.GetData(1, ref Movement))
            {
                return;
            }

            // Calculate the robot pose
            InverseKinematics inverseKinematics = new InverseKinematics(Movement, robot);

            inverseKinematics.Calculate();

            // Check the values
            for (int i = 0; i < inverseKinematics.ErrorText.Count; i++)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, inverseKinematics.ErrorText[i]);
            }

            // Create list with externan axis values
            List <double> externalAxisValues = inverseKinematics.ExternalJointPosition.ToList();

            externalAxisValues.RemoveAll(val => val == 9e9);

            // Output
            DA.SetDataList(0, inverseKinematics.RobotJointPosition.ToList());
            DA.SetDataList(1, externalAxisValues);
        }
Beispiel #19
0
        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            _deferral = taskInstance.GetDeferral();

            _display           = new SparkFunSerial16X2Lcd();
            _xboxController    = new XboxController(_display);
            _ntripClient       = new NtripClient("172.16.0.237", 8000, "", "", "", _display); //172.16.0.227
            _ioTClient         = new IoTClient(_display);
            _gps               = new Gps.Gps(_display, _ntripClient);
            _inverseKinematics = new InverseKinematics(_display);
            _ikController      = new IkController(_inverseKinematics, _display, _ioTClient, _gps); //Range and yaw/pitch/roll data from Arduino and SparkFun Razor IMU
            _navigator         = new Navigator(_ikController, _display, _gps);
            _hexapi            = new Hexapi(_ikController, _xboxController, _navigator, _display, _gps, _ioTClient);

            _initializeTasks.Add(_display.InitializeAsync());
            _initializeTasks.Add(_xboxController.InitializeAsync());
            _initializeTasks.Add(_ikController.InitializeAsync());
            _initializeTasks.Add(_ntripClient.InitializeAsync());
            _initializeTasks.Add(_gps.InitializeAsync());
            _initializeTasks.Add(_inverseKinematics.InitializeAsync());
            _initializeTasks.Add(_ioTClient.InitializeAsync());

            _startTasks.Add(_ntripClient.StartAsync());
            _startTasks.Add(_ikController.StartAsync());
            _startTasks.Add(_gps.StartAsync());
            _startTasks.Add(_inverseKinematics.StartAsync());
            //_startTasks.Add(_ioTClient.StartAsync());//only needed if expecting messages from the server

            //foreach (var d in await SerialDeviceHelper.ListAvailablePorts())
            //{
            //    await _ioTClient.SendEvent(d);
            //}

            await Task.WhenAll(_initializeTasks.ToArray());

            await Task.WhenAll(_startTasks.ToArray());
        }
Beispiel #20
0
        /// <summary>
        /// Initializes a new instance of the Robot class by duplicating an existing Robot instance.
        /// </summary>
        /// <param name="robot"> The Robot instance to duplicate. </param>
        public Robot(Robot robot)
        {
            // Robot related fields
            _name   = robot.Name;
            _meshes = robot.Meshes.ConvertAll(mesh => mesh.DuplicateMesh()); // This includes the tool mesh

            _internalAxisPlanes = new List <Plane>(robot.InternalAxisPlanes);
            _internalAxisLimits = new List <Interval>(robot.InternalAxisLimits);
            _basePlane          = new Plane(robot.BasePlane);
            _mountingFrame      = new Plane(robot.MountingFrame);

            // Tool related fields
            _tool      = robot.Tool.Duplicate();
            _toolPlane = new Plane(robot.ToolPlane);

            // External axis related fields
            _externalAxes       = new List <ExternalAxis>(robot.ExternalAxes); //TODO: make deep copy
            _externalAxisPlanes = new List <Plane>(robot.ExternalAxisPlanes);
            _externalAxisLimits = new List <Interval>(robot.ExternalAxisLimits);

            // Kinematics
            _inverseKinematics = new InverseKinematics(robot.InverseKinematics.Movement.Duplicate(), this);
            _forwardKinematics = new ForwardKinematics(this, robot.ForwardKinematics.HideMesh);
        }
 void OnEnable()
 {
     ik = (InverseKinematics)target;
 }
 static void DrawIKGizmo(InverseKinematics ik, GizmoType gizmoType)
 {
     Handles.Label(ik.transform.position + new Vector3(0.1f, 0), "IK");
 }
Beispiel #23
0
    // Restore a saved pose for the Skeleton
    public void RestorePose(Pose pose)
    {
        var bones = GetComponentsInChildren <Bone>();

        /// WILL BE DEPRECIATED IN FUTURE RELEASE AS ControlPoint IS NO LONGER SUPPORTED ///
        var cps = GetComponentsInChildren <ControlPoint>();

        var skin2Ds = GetComponentsInChildren <Skin2D>();

                #if UNITY_EDITOR
        Undo.RegisterCompleteObjectUndo(bones, "Assign Pose");
        Undo.RegisterCompleteObjectUndo(cps, "Assign Pose");
        Undo.RegisterCompleteObjectUndo(skin2Ds, "Assign Pose");
                #endif

        if (bones.Length > 0)
        {
            for (int i = 0; i < pose.rotations.Length; i++)
            {
                bool hasRot = false;
                for (int b = 0; b < bones.Length; b++)
                {
                    if (bones[b].name == pose.rotations[i].name)
                    {
                                                #if UNITY_EDITOR
                        Undo.RecordObject(bones[b].transform, "Assign Pose");
                                                #endif

                        // Set the bone rotation to the pose rotation
                        bones[b].transform.localRotation = pose.rotations[i].rotation;

                                                #if UNITY_EDITOR
                        EditorUtility.SetDirty(bones[b].transform);
                                                #endif
                        hasRot = true;
                    }
                }
                if (!hasRot)
                {
                    Debug.Log("This skeleton has no bone '" + pose.rotations[i].name + "'");
                }
            }

            for (int j = 0; j < pose.positions.Length; j++)
            {
                bool hasPos = false;
                for (int o = 0; o < bones.Length; o++)
                {
                    if (bones[o].name == pose.positions[j].name)
                    {
                                                #if UNITY_EDITOR
                        Undo.RecordObject(bones[o].transform, "Assign Pose");
                                                #endif

                        // Set the bone position to the pose position
                        bones[o].transform.localPosition = pose.positions[j].position;

                                                #if UNITY_EDITOR
                        EditorUtility.SetDirty(bones[o].transform);
                                                #endif
                        hasPos = true;
                    }
                }
                if (!hasPos)
                {
                    Debug.Log("This skeleton has no bone '" + pose.positions[j].name + "'");
                }
            }

            for (int k = 0; k < pose.targets.Length; k++)
            {
                bool hasTarget = false;
                for (int n = 0; n < bones.Length; n++)
                {
                    if (bones[n].name == pose.targets[k].name)
                    {
                        InverseKinematics ik = bones[n].GetComponent <InverseKinematics>();

                        if (ik != null)
                        {
                                                        #if UNITY_EDITOR
                            Undo.RecordObject(ik.target, "Assign Pose");
                                                        #endif

                            // Set IK position to the pose IK target position
                            ik.target.transform.localPosition = pose.targets[k].position;

                                                        #if UNITY_EDITOR
                            EditorUtility.SetDirty(ik.target.transform);
                                                        #endif
                        }
                        else
                        {
                            Debug.Log("This skeleton has no ik for bone '" + bones[n].name + "'");
                        }
                        hasTarget = true;
                    }
                }
                if (!hasTarget)
                {
                    Debug.Log("This skeleton has no bone '" + pose.targets[k].name + "'");
                }
            }
        }

        if (pose.controlPoints.Length > 0)
        {
            for (int l = 0; l < pose.controlPoints.Length; l++)
            {
                bool hasControlPoint = false;

                /// WILL BE DEPRECIATED IN FUTURE RELEASE AS CONTROL POINT IS NO LONGER SUPPORTED ///
                if (cps.Length > 0)
                {
                    for (int c = 0; c < cps.Length; c++)
                    {
                        if (cps[c].name == pose.controlPoints[l].name)
                        {
                                                        #if UNITY_EDITOR
                            Undo.RecordObject(cps[c].transform, "Assign Pose");
                                                        #endif

                            // Set the control point transform position to the control point position
                            cps[c].transform.localPosition = pose.controlPoints[l].position;

                                                        #if UNITY_EDITOR
                            EditorUtility.SetDirty(cps[c].transform);
                                                        #endif
                            hasControlPoint = true;
                        }
                    }
                }

                // Move control points in Skin2D component
                if (skin2Ds.Length > 0)
                {
                    for (int s = 0; s < skin2Ds.Length; s++)
                    {
                        if (skin2Ds[s].points != null && skin2Ds[s].controlPoints != null &&
                            skin2Ds[s].controlPoints.Length > 0 &&
                            pose.controlPoints[l].name.StartsWith(skin2Ds[s].name + " Control Point"))
                        {
                                                        #if UNITY_EDITOR
                            Undo.RecordObject(skin2Ds[s], "Assign Pose");
                            Undo.RecordObject(skin2Ds[s].points, "Assign Pose");
                                                        #endif

                            // Get control point index by name in pose
                            int index = GetControlPointIndex(pose.controlPoints[l].name);
                            skin2Ds[s].controlPoints[index].position = pose.controlPoints[l].position;
                            skin2Ds[s].points.SetPoint(skin2Ds[s].controlPoints[index]);

                                                        #if UNITY_EDITOR
                            EditorUtility.SetDirty(skin2Ds[s]);
                            EditorUtility.SetDirty(skin2Ds[s].points);
                                                        #endif

                            hasControlPoint = true;

                            // Debug.Log("Found " + pose.controlPoints[l].name + " set to " + index + skin2Ds[s].points.GetPoint(skin2Ds[s].controlPoints[index]));
                        }
                    }
                }
                if (!hasControlPoint)
                {
                    Debug.Log("There is no control point '" + pose.controlPoints[l].name + "'");
                }
            }
        }
    }
Beispiel #24
0
    public void AddGun(GunObject addGun)
    {
        if (Application.isPlaying)
        {
            Debug.LogWarning("ONLY CALL THIS OUTSIDE OF PLAY");
            return;
        }
        RemoveBlanks();
        //Find where to place this gun
        PrefabHandler playerPrefab = new PrefabHandler(FindObjectOfType <PlayerController>().transform, playerPrefabPath);
        GunHandler    handler      = gunInventory.Find(x => x.gun.GetHashCode() == addGun.GetHashCode());

        if (handler == null) //If we did not find a handler with the gun using the gun name
        {
            playerPrefab.ChangePrefab(() =>
            {
                GameObject gunParent     = new GameObject();
                gunParent.transform.name = addGun.prefabName;
                gunParent.transform.SetParent(this.transform);
                TransformHelper.ResetLocalTransform(gunParent.transform);

                Animator ani = gunParent.AddComponent(typeof(Animator)) as Animator;
                if (addGun.animationController != null)
                {
                    ani.runtimeAnimatorController = addGun.animationController;
                }

                handler = gunParent.AddComponent(typeof(GunHandler)) as GunHandler;

                handler.gun               = addGun;
                handler.handIKTarget      = new GameObject().transform;
                handler.handIKTarget.name = "IK_Hand";
                handler.handIKTarget.SetParent(gunParent.transform);
                TransformHelper.SetLocalTransformData(handler.handIKTarget, addGun.IK_HandTarget);

                gunInventory.Add(handler);
                handler.gunIndex = gunInventory.Count - 1;
            });
        }
        else
        {
            Debug.Log("Already have gun named : " + addGun.prefabName + " [UPDATING GUN]");

            playerPrefab.ChangePrefab(() =>
            {
                handler.transform.SetParent(this.transform);
                TransformHelper.ResetLocalTransform(handler.transform);

                if (addGun.animationController != null)
                {
                    Animator ani = handler.gameObject.GetComponent <Animator>();
                    ani.runtimeAnimatorController = addGun.animationController;
                }

                handler.gun = addGun;
                handler.handIKTarget.SetParent(handler.transform.parent);
                TransformHelper.DeleteAllChildren(handler.transform);
                handler.handIKTarget.SetParent(handler.transform);
                TransformHelper.SetLocalTransformData(handler.handIKTarget, addGun.IK_HandTarget);
            });
        }

        playerPrefab.ChangePrefab(() =>
        {
            if (addGun.prefabObj != null)
            {
                CreateGunPrefab(handler);
            }
            if (addGun.animationController != null)
            {
                handler.SetAnimations(addGun.gunMotions);
            }

            selectedGun = handler.gunIndex;
            for (int i = 0; i < gunInventory.Count; i++)
            {
                gunInventory[i].gameObject.SetActive(i == selectedGun);
            }

            handler.SetAmmo();
            handler.bulletSpawn = handler.gameObject.GetComponentInChildren <GunBulletSpawn>();

            InverseKinematics ik = null;
            if ((ik = FindObjectOfType <ArmIKController>().armIK) != null)
            {
                ik.target = handler.handIKTarget;
            }
        });

        playerPrefab.RecreatePrefab();
    }
Beispiel #25
0
    public void RestorePose(Pose pose)
    {
        var bones = GetComponentsInChildren <Bone>();
        var cps   = GetComponentsInChildren <ControlPoint>();

        Undo.RegisterCompleteObjectUndo(bones, "Assign Pose");
        Undo.RegisterCompleteObjectUndo(cps, "Assign Pose");

        foreach (RotationValue rv in pose.rotations)
        {
            Bone bone = bones.First(b => b.name == rv.name);
            if (bone != null)
            {
                bone.transform.localRotation = rv.rotation;
            }
            else
            {
                Debug.Log("This skeleton has no bone '" + bone.name + "'");
            }
        }

        foreach (PositionValue pv in pose.positions)
        {
            Bone bone = bones.First(b => b.name == pv.name);
            if (bone != null)
            {
                bone.transform.localPosition = pv.position;
            }
            else
            {
                Debug.Log("This skeleton has no bone '" + bone.name + "'");
            }
        }

        foreach (PositionValue tv in pose.targets)
        {
            Bone bone = bones.First(b => b.name == tv.name);

            if (bone != null)
            {
                InverseKinematics ik = bone.GetComponent <InverseKinematics>();

                if (ik != null)
                {
                    Undo.RecordObject(ik.target, "Assign Pose");
                    ik.target.transform.localPosition = tv.position;
                }
            }
            else
            {
                Debug.Log("This skeleton has no bone '" + bone.name + "'");
            }
        }

        foreach (PositionValue cpv in pose.controlPoints)
        {
            ControlPoint cp = cps.First(c => (c.transform.parent.name + c.name) == cpv.name);

            if (cp != null)
            {
                cp.transform.localPosition = cpv.position;
            }
            else
            {
                Debug.Log("There is no control point '" + cpv.name + "'");
            }
        }
    }
Beispiel #26
0
    public void RestorePose(Pose pose)
    {
        var bones = GetComponentsInChildren <Bone>();
        var cps   = GetComponentsInChildren <ControlPoint>();

                #if UNITY_EDITOR
        Undo.RegisterCompleteObjectUndo(bones, "Assign Pose");
        Undo.RegisterCompleteObjectUndo(cps, "Assign Pose");
                #endif

        if (bones.Length > 0)
        {
            foreach (RotationValue rv in pose.rotations)
            {
                Bone bone = bones.FirstOrDefault(b => b.name == rv.name);
                if (bone != null)
                {
                                        #if UNITY_EDITOR
                    Undo.RecordObject(bone.transform, "Assign Pose");
                                        #endif
                    bone.transform.localRotation = rv.rotation;
                                        #if UNITY_EDITOR
                    EditorUtility.SetDirty(bone.transform);
                                        #endif
                }
                else
                {
                    Debug.Log("This skeleton has no bone '" + rv.name + "'");
                }
            }

            foreach (PositionValue pv in pose.positions)
            {
                Bone bone = bones.FirstOrDefault(b => b.name == pv.name);
                if (bone != null)
                {
                                        #if UNITY_EDITOR
                    Undo.RecordObject(bone.transform, "Assign Pose");
                                        #endif
                    bone.transform.localPosition = pv.position;
                                        #if UNITY_EDITOR
                    EditorUtility.SetDirty(bone.transform);
                                        #endif
                }
                else
                {
                    Debug.Log("This skeleton has no bone '" + pv.name + "'");
                }
            }

            foreach (PositionValue tv in pose.targets)
            {
                Bone bone = bones.FirstOrDefault(b => b.name == tv.name);

                if (bone != null)
                {
                    InverseKinematics ik = bone.GetComponent <InverseKinematics>();

                    if (ik != null)
                    {
                                                #if UNITY_EDITOR
                        Undo.RecordObject(ik.target, "Assign Pose");
                                                #endif
                        ik.target.transform.localPosition = tv.position;
                                                #if UNITY_EDITOR
                        EditorUtility.SetDirty(ik.target.transform);
                                                #endif
                    }
                }
                else
                {
                    Debug.Log("This skeleton has no bone '" + tv.name + "'");
                }
            }
        }

        if (cps.Length > 0)
        {
            foreach (PositionValue cpv in pose.controlPoints)
            {
                ControlPoint cp = cps.FirstOrDefault(c => (c.name) == cpv.name || (c.name) == c.transform.parent.name + c.name);

                if (cp != null)
                {
                                        #if UNITY_EDITOR
                    Undo.RecordObject(cp.transform, "Assign Pose");
                                        #endif
                    cp.transform.localPosition = cpv.position;
                                        #if UNITY_EDITOR
                    EditorUtility.SetDirty(cp.transform);
                                        #endif
                }
                else
                {
                    Debug.Log("There is no control point '" + cpv.name + "'");
                }
            }
        }
    }
Beispiel #27
0
 private void InitializeMember()
 {
     Joint6ToFlangeTrafo = new TransformationMatrix(Transformations.GetIdentityMatrix());
     InvKin = new InverseKinematics();
 }
 static void DrawIKGizmo(InverseKinematics ik, GizmoType gizmoType)
 {
     Handles.Label(ik.transform.position + new Vector3(0.1f, 0), "IK");
 }
Beispiel #29
0
 void OnEnable()
 {
     ik = (InverseKinematics)target;
 }
Beispiel #30
0
    void LoadBot(string path)
    {
        //SceneManager.LoadScene("empty");


        GameObject canvas = GameObject.Find("Canvas");

        canvas.name = "Canvas Del";
        GameObject.DestroyImmediate(canvas);
        UnityEngine.Object cPrefab = Resources.Load("Canvas");
        canvas      = (GameObject)GameObject.Instantiate(cPrefab, new Vector3(0, 0, 0), Quaternion.identity);
        canvas.name = "Canvas";
        Debug.Log(path);
        GameObject parentObj = GameObject.Find("GameObject");

        parentObj.name = "GameObject Del";
        int childs = parentObj.transform.childCount;

        /*for (int i = childs - 1; i >= 0; i--)
         * {
         *      GameObject.DestroyImmediate(transform.GetChild(i).gameObject);
         * }*/
        GameObject.DestroyImmediate(parentObj);
        parentObj = new GameObject("GameObject");
        parentObj.AddComponent <Serial>();
        parentObj.name = "GameObject";
        InverseKinematics ik = parentObj.AddComponent <InverseKinematics>();

        //DontDestroyOnLoad(parentObj);
        UnityEngine.Object bPrefab = Resources.Load("Button");
        GameObject         newButt = (GameObject)GameObject.Instantiate(bPrefab, new Vector3(-109f, -75, 0), Quaternion.identity);

        newButt.transform.SetParent(GameObject.Find("Canvas").transform, false);
        newButt.GetComponentInChildren <Text>().text = "Inverse Kinematics";
        newButt.name = "IK";
        newButt.transform.GetComponent <RectTransform>().anchorMin = new Vector2(1, 1);
        newButt.transform.GetComponent <RectTransform>().anchorMax = new Vector2(1, 1);
        //newButt.GetComponent<Button>().onClick.AddListener(delegate { Load(); });
        newButt.GetComponent <Button>().onClick.AddListener(() => ik.btn_StartIK());
        var sr           = new StreamReader(path);
        var fileContents = sr.ReadToEnd();

        sr.Close();

        string [,] inputs = new string[50, 10];
        var lines = fileContents.Split("\n"[0]);
        int count = 0;

        foreach (string line in lines)
        {
            var lineElements = line.Split(" "[0]);
            int count2       = 0;
            foreach (string word in lineElements)
            {
                //Debug.Log(word);
                inputs[count, count2] = word;
                count2++;
            }
            Debug.Log(count + " " + line);
            count++;
        }

        int sliderCount = 0;
        int armsNo      = Int32.Parse(inputs[0, 0]);

        ik.jointCount = armsNo + 1;
        for (int i = 0; i < armsNo; i++)
        {
            //Debug.Log(inputs[3*armsNo+1+1,0]);
            //Debug.Log(ToLiteral(inputs[3*armsNo+1+1,0]));
            //Debug.Log("C:/Users/Victor/Documents/untitled.obj");
            //Debug.Log(ToLiteral("C:/Users/Victor/Documents/untitled.obj"));
            GameObject obj = loadAndDisplayMesh(inputs[3 * armsNo + 1 + 1 + i, 0].Replace("\r", ""));
            obj.transform.SetParent(parentObj.transform);
            obj.name = i.ToString() + "," + (i + 1).ToString();
            //obj.AddComponent<MeshCollider>();
            //obj.GetComponent<MeshCollider>().convex = true;
            var colli = obj.AddComponent <NonConvexMeshCollider>();
            colli.avoidExceedingMesh = true;
            colli.boxesPerEdge       = 20;
            colli.Calculate();
            Limb lmb = obj.AddComponent <Limb>();
            lmb.otherScale = Int32.Parse(inputs[i + 1, 0]);
            Debug.Log(inputs[5 * armsNo + 9 + i, 0]);;
            lmb.overlap = float.Parse(inputs[5 * armsNo + 9 + i, 0], CultureInfo.InvariantCulture);
            lmb.offsetX = float.Parse(inputs[6 * armsNo + 9 + i, 0], CultureInfo.InvariantCulture);
            GameObject obj2 = loadAndDisplayMesh(inputs[4 * armsNo + 3, 0].Replace("\r", ""));
            //obj2.transform.Rotate(new Vector3(Int32.Parse(inputs[armsNo*2+1+i,0]), Int32.Parse(inputs[armsNo*2+1+i,1]), Int32.Parse(inputs[armsNo*2+1+i,2])));
            obj2.AddComponent <MeshCollider>();
            obj2.GetComponent <MeshCollider>().convex = true;
            obj2.transform.SetParent(parentObj.transform);
            obj2.name = i.ToString();
            if (i == 0)
            {
                RoboJoint rbj2 = obj2.AddComponent <RoboJoint>();
                int       refX = Int32.Parse(inputs[7 * armsNo + 14 + i, 0]);
                int       refY = Int32.Parse(inputs[7 * armsNo + 14 + i, 1]);
                int       refZ = Int32.Parse(inputs[7 * armsNo + 14 + i, 2]);
                rbj2.q2   = Quaternion.Euler(refX, refY, refZ);
                rbj2.yOff = float.Parse(inputs[7 * armsNo + 9, 1], CultureInfo.InvariantCulture);
            }
            else
            {
                RoboJoint3 rbj2 = obj2.AddComponent <RoboJoint3>();
                rbj2.length = Int32.Parse(inputs[armsNo + i, 0]);
                rbj2.d      = float.Parse(inputs[armsNo + i, 1], CultureInfo.InvariantCulture);
                rbj2.xRot   = Int32.Parse(inputs[armsNo * 2 + 1 + i, 0]);
                rbj2.yRot   = Int32.Parse(inputs[armsNo * 2 + 1 + i, 1]);
                rbj2.zRot   = Int32.Parse(inputs[armsNo * 2 + 1 + i, 2]);

                //rbj2.theta = float.Parse(inputs[armsNo+i,1], CultureInfo.InvariantCulture);
                //rbj2.alpha = float.Parse(inputs[armsNo+i,2], CultureInfo.InvariantCulture);
                int refX = Int32.Parse(inputs[7 * armsNo + 14 + i, 0]);
                int refY = Int32.Parse(inputs[7 * armsNo + 14 + i, 1]);
                int refZ = Int32.Parse(inputs[7 * armsNo + 14 + i, 2]);
                rbj2.q2 = Quaternion.Euler(refX, refY, refZ);
            }

            Debug.Log("Joint to render: " + i);
            Debug.Log(" value:  " + inputs[7 * armsNo + 11, i]);
            if (inputs[7 * armsNo + 11, i].Trim() == "0")
            {
                obj2.GetComponent <MeshRenderer>().enabled = false;
                obj2.GetComponent <Collider>().enabled     = false;
            }
            UnityEngine.Object pPrefab   = Resources.Load("Slider (1)");   // note: not .prefab!
            GameObject         newSlider = (GameObject)GameObject.Instantiate(pPrefab, new Vector3(98, -10 - sliderCount * 20, 0), Quaternion.identity);
            //GameObject newSlider = Instantiate(Slider) as GameObject;
            sliderCount++;
            newSlider.transform.SetParent(GameObject.Find("Canvas").transform, false);
            newSlider.transform.GetComponent <RectTransform>().anchorMin = new Vector2(0, 1);
            newSlider.transform.GetComponent <RectTransform>().anchorMax = new Vector2(0, 1);
            newSlider.name = "Slider (" + (2 * i).ToString() + ")";
            //newSlider.GetComponent<Slider>().label = "Slider (" + (i).ToString() + ") Theta";
            if (inputs[4 * armsNo + 4 + i, 0] == "0")
            {
                newSlider.GetComponent <Slider>().interactable      = false;
                newSlider.GetComponent <RectTransform>().localScale = new Vector3(0f, 0f, 0f);
                ;
                sliderCount--;
            }
            else
            {
                GameObject textObj = new GameObject("myTextGO");
                textObj.transform.position = new Vector3(229.4f, -30.4f - sliderCount * 20, 0);
                textObj.transform.SetParent(GameObject.Find("Canvas").transform, false);
                //textObj.transform.SetParent(newSlider.transform);
                Text myText = textObj.AddComponent <Text>();
                myText.text = "Arm " + (i).ToString() + "- Theta";
                myText.font = (Font)Resources.GetBuiltinResource(typeof(Font), "Arial.ttf");
                textObj.transform.GetComponent <RectTransform>().anchorMin = new Vector2(0, 1);
                textObj.transform.GetComponent <RectTransform>().anchorMax = new Vector2(0, 1);
                if (i < armsNo)
                {
                    //if (i >0){
                    //newSlider.GetComponent<Slider>().value = float.Parse(inputs[armsNo+i,2], CultureInfo.InvariantCulture);
                    newSlider.GetComponent <Slider>().value = float.Parse(inputs[armsNo + i + 1, 2], CultureInfo.InvariantCulture);
                }
            }
            GameObject newSlider2 = (GameObject)GameObject.Instantiate(pPrefab, new Vector3(98, -10 - sliderCount * 20, 0), Quaternion.identity);
            //GameObject newSlider = Instantiate(Slider) as GameObject;
            sliderCount++;
            newSlider2.transform.SetParent(GameObject.Find("Canvas").transform, false);
            newSlider2.transform.GetComponent <RectTransform>().anchorMin = new Vector2(0, 1);
            newSlider2.transform.GetComponent <RectTransform>().anchorMax = new Vector2(0, 1);
            newSlider2.name = "Slider (" + (2 * i + 1).ToString() + ")";
            //newSlider2.label = "Slider (" + (i).ToString() + ") Alpha";
            if (inputs[4 * armsNo + 4 + i, 1] == "0")
            {
                sliderCount--;
                newSlider2.GetComponent <Slider>().interactable      = false;
                newSlider2.GetComponent <RectTransform>().localScale = new Vector3(0f, 0f, 0f);
            }
            else
            {
                GameObject textObj = new GameObject("myTextGO");
                textObj.transform.position = new Vector3(229.4f, -30.4f - sliderCount * 20, 0);
                textObj.transform.SetParent(GameObject.Find("Canvas").transform, false);
                //textObj.transform.SetParent(newSlider2.transform);
                //textObj.transform.localPosition = new Vector3(198.6f,-43f,0f);
                Debug.Log(newSlider2.name);
                Text myText = textObj.AddComponent <Text>();
                myText.text = "Arm " + (i).ToString() + "- Alpha";
                myText.font = (Font)Resources.GetBuiltinResource(typeof(Font), "Arial.ttf");
                textObj.transform.GetComponent <RectTransform>().anchorMin = new Vector2(0, 1);
                textObj.transform.GetComponent <RectTransform>().anchorMax = new Vector2(0, 1);
                //if (i > 0){
                //newSlider2.GetComponent<Slider>().value = float.Parse(inputs[armsNo+i,3], CultureInfo.InvariantCulture);
                if (i < armsNo)
                {
                    newSlider2.GetComponent <Slider>().value = float.Parse(inputs[armsNo + i + 1, 3], CultureInfo.InvariantCulture);
                }
            }
            GameObject newSlider8 = (GameObject)GameObject.Instantiate(pPrefab, new Vector3(98, -10 - sliderCount * 20, 0), Quaternion.identity);
            //GameObject newSlider = Instantiate(Slider) as GameObject;
            //sliderCount ++;
            //newSlider8.transform.SetParent(GameObject.Find("Canvas").transform, false);
            newSlider8.name = "Slider (l" + (2 * i).ToString() + ")";
            newSlider8.transform.GetComponent <RectTransform>().anchorMin = new Vector2(0, 1);
            newSlider8.transform.GetComponent <RectTransform>().anchorMax = new Vector2(0, 1);
            //newSlider2.label = "Slider (" + (i).ToString() + ") Alpha";
            if (inputs[4 * armsNo + 4 + i, 2] == "0")
            {
                sliderCount--;
                newSlider8.GetComponent <Slider>().interactable      = false;
                newSlider8.GetComponent <RectTransform>().localScale = new Vector3(0f, 0f, 0f);
                newSlider8.GetComponent <Slider>().maxValue          = 2 * float.Parse(inputs[armsNo + i, 0], CultureInfo.InvariantCulture);
                newSlider8.GetComponent <Slider>().minValue          = float.Parse(inputs[armsNo + i, 0], CultureInfo.InvariantCulture);
                newSlider8.GetComponent <Slider>().value             = float.Parse(inputs[armsNo + i, 0], CultureInfo.InvariantCulture);
                ;
            }
            else
            {
                //GameObject textObj = new GameObject("myTextGO");
                //textObj.transform.position = new Vector3(229.4f, -30.4f -sliderCount*20, 0);
                //textObj.transform.SetParent(GameObject.Find("Canvas").transform, false);
                //textObj.transform.SetParent(newSlider8.transform);
                //textObj.transform.localPosition = new Vector3(198.6f,-43f,0f);
                //Text myText = textObj.AddComponent<Text>();
                //myText.text = "Slider (" + (i).ToString() + ") length";
                //myText.font = (Font)Resources.GetBuiltinResource(typeof(Font), "Arial.ttf");
                //myText.horizontalOverflow = HorizontalWrapMode.Overflow;
                //textObj.transform.GetComponent<RectTransform>().anchorMin = new Vector2(0,1);
                //textObj.transform.GetComponent<RectTransform>().anchorMax = new Vector2(0,1);
                //newSlider8.GetComponent<RectTransform>().SetSizeWithCurrentAnchors( RectTranform.Axis.Horizontal, 150);
            }
        }

        GameObject obj3 = loadAndDisplayMesh(inputs[5 * armsNo + 6, 0].Replace("\r", ""));

        obj3.AddComponent <MeshCollider>();
        obj3.GetComponent <MeshCollider>().convex = true;
        obj3.name = (armsNo).ToString();
        var colli3 = obj3.AddComponent <NonConvexMeshCollider>();

        colli3.avoidExceedingMesh = true;
        colli3.boxesPerEdge       = 20;
        //colli3.Calculate();
        //obj3.AddComponent<MeshCollider>();
        RoboJoint3 rbj3  = obj3.AddComponent <RoboJoint3>();
        int        refX3 = Int32.Parse(inputs[8 * armsNo + 14, 0]);
        int        refY3 = Int32.Parse(inputs[8 * armsNo + 14, 1]);
        int        refZ3 = Int32.Parse(inputs[8 * armsNo + 14, 2]);

        rbj3.q2     = Quaternion.Euler(refX3, refY3, refZ3);
        rbj3.length = Int32.Parse(inputs[armsNo * 2, 0]);
        Debug.Log(inputs[armsNo * 2, 1]);
        rbj3.d          = float.Parse(inputs[armsNo * 2, 1], CultureInfo.InvariantCulture);
        rbj3.otherScale = Int32.Parse(inputs[armsNo, 2]);
        obj3.transform.SetParent(parentObj.transform);
        //Debug.Log(" HERHE " + (inputs[7*armsNo+12,0].Contains("0")));
        //Debug.Log(" HERHE " + (String.Compare(inputs[7*armsNo+12,0],"1")));
        if (inputs[7 * armsNo + 12, 0].Contains("1"))
        {
            rbj3.rotGripper = false;
        }
        UnityEngine.Object pPrefab2   = Resources.Load("Slider (1)");       // note: not .prefab!
        GameObject         newSlider3 = (GameObject)GameObject.Instantiate(pPrefab2, new Vector3(98, -10 - sliderCount * 20, 0), Quaternion.identity);

        sliderCount++;
        //GameObject newSlider = Instantiate(Slider) as GameObject;
        newSlider3.transform.SetParent(GameObject.Find("Canvas").transform, false);
        newSlider3.transform.GetComponent <RectTransform>().anchorMin = new Vector2(0, 1);
        newSlider3.transform.GetComponent <RectTransform>().anchorMax = new Vector2(0, 1);
        newSlider3.name = "Slider (" + (2 * armsNo).ToString() + ")";
        //newSlider3.label = "Slider (" + (armsNo).ToString() + ") Theta";
        if (inputs[4 * armsNo + 4 + armsNo, 0] == "0")
        {
            sliderCount--;
            newSlider3.GetComponent <Slider>().interactable      = false;
            newSlider3.GetComponent <RectTransform>().localScale = new Vector3(0f, 0f, 0f);
        }
        else
        {
            GameObject textObj = new GameObject("myTextGO");
            textObj.transform.position = new Vector3(229.4f, -30.4f - sliderCount * 20, 0);
            textObj.transform.SetParent(GameObject.Find("Canvas").transform, false);
            //textObj.transform.SetParent(newSlider3.transform);
            //textObj.transform.localPosition = new Vector3(198.6f,-43f,0f);
            Text myText = textObj.AddComponent <Text>();
            myText.text = "Hand " + (armsNo).ToString() + "- Theta";
            myText.font = (Font)Resources.GetBuiltinResource(typeof(Font), "Arial.ttf");
            textObj.transform.GetComponent <RectTransform>().anchorMin = new Vector2(0, 1);
            textObj.transform.GetComponent <RectTransform>().anchorMax = new Vector2(0, 1);
            newSlider3.GetComponent <Slider>().value = float.Parse(inputs[armsNo * 2, 2], CultureInfo.InvariantCulture);
        }
        GameObject newSlider4 = (GameObject)GameObject.Instantiate(pPrefab2, new Vector3(98, -10 - sliderCount * 20, 0), Quaternion.identity);

        sliderCount++;
        //GameObject newSlider = Instantiate(Slider) as GameObject;
        newSlider4.transform.SetParent(GameObject.Find("Canvas").transform, false);
        newSlider4.transform.GetComponent <RectTransform>().anchorMin = new Vector2(0, 1);
        newSlider4.transform.GetComponent <RectTransform>().anchorMax = new Vector2(0, 1);
        newSlider4.name = "Slider (" + (2 * armsNo + 1).ToString() + ")";
        //newSlider4.label = "Slider (" + (armsNo).ToString() + ") Alpha";
        if (inputs[4 * armsNo + 4 + armsNo, 1] == "0")
        {
            sliderCount--;
            newSlider4.GetComponent <Slider>().interactable      = false;
            newSlider4.GetComponent <RectTransform>().localScale = new Vector3(0f, 0f, 0f);
        }
        else
        {
            GameObject textObj = new GameObject("myTextGO");
            textObj.transform.position = new Vector3(229.4f, -30.4f - sliderCount * 20, 0);
            textObj.transform.SetParent(GameObject.Find("Canvas").transform, false);
            //textObj.transform.SetParent(newSlider4.transform);
            //textObj.transform.localPosition = new Vector3(198.6f,-43f,0f);
            Text myText = textObj.AddComponent <Text>();
            myText.text = "Hand " + (armsNo).ToString() + "- Alpha";
            myText.font = (Font)Resources.GetBuiltinResource(typeof(Font), "Arial.ttf");
            textObj.transform.GetComponent <RectTransform>().anchorMin = new Vector2(0, 1);
            textObj.transform.GetComponent <RectTransform>().anchorMax = new Vector2(0, 1);
            newSlider4.GetComponent <Slider>().value = float.Parse(inputs[armsNo * 2, 2], CultureInfo.InvariantCulture);
        }


        //Debug.Log(inputs[5*armsNo+6,0].Replace("\r", ""));

        /*GameObject obj4 = loadAndDisplayMesh(inputs[4*armsNo+7,0].Replace("\r", ""));
         * obj4.AddComponent<MeshCollider>();
         * obj4.GetComponent<MeshCollider>().convex = true;
         * obj4.name = "grabber";
         * //obj3.AddComponent<MeshCollider>();
         * grabber g4 = obj4.AddComponent<grabber>();
         * //rbj3.length = Int32.Parse(inputs[armsNo*2,0]);
         * //rbj3.d = Int32.Parse(inputs[armsNo*2,1]);
         * obj4.transform.SetParent(parentObj.transform);
         * g4.parent = obj3;*/

        GameObject newSlider5 = (GameObject)GameObject.Instantiate(pPrefab2, new Vector3(98, -10 - sliderCount * 20, 0), Quaternion.identity);

        sliderCount++;
        //GameObject newSlider = Instantiate(Slider) as GameObject;
        newSlider5.transform.SetParent(GameObject.Find("Canvas").transform, false);
        newSlider5.transform.GetComponent <RectTransform>().anchorMin = new Vector2(0, 1);
        newSlider5.transform.GetComponent <RectTransform>().anchorMax = new Vector2(0, 1);
        newSlider5.name = "Slider (" + (2 * armsNo + 2).ToString() + ")";
        newSlider5.GetComponent <Slider>().maxValue = 100f;
        newSlider5.GetComponent <Slider>().minValue = 30f;
        newSlider5.GetComponent <Slider>().value    = 100f;
        //newSlider4.label = "Slider (" + (armsNo).ToString() + ") Alpha";
        GameObject textObj2 = new GameObject("myTextGO");

        textObj2.transform.position = new Vector3(229.4f, -30.4f - sliderCount * 20, 0);
        textObj2.transform.SetParent(GameObject.Find("Canvas").transform, false);
        //textObj2.transform.SetParent(newSlider5.transform);
        //textObj2.transform.localPosition = new Vector3(198.6f,-43f,0f);
        Text myText2 = textObj2.AddComponent <Text>();

        myText2.text = "Slider grab";
        myText2.font = (Font)Resources.GetBuiltinResource(typeof(Font), "Arial.ttf");
        textObj2.transform.GetComponent <RectTransform>().anchorMin = new Vector2(0, 1);
        textObj2.transform.GetComponent <RectTransform>().anchorMax = new Vector2(0, 1);

        GameObject newSlider9 = (GameObject)GameObject.Instantiate(pPrefab2, new Vector3(98, -10 - sliderCount * 20, 0), Quaternion.identity);

        //GameObject newSlider = Instantiate(Slider) as GameObject;
        //sliderCount ++;
        //newSlider9.transform.SetParent(GameObject.Find("Canvas").transform, false);
        newSlider9.name = "Slider (l" + (2 * armsNo).ToString() + ")";
        newSlider9.transform.GetComponent <RectTransform>().anchorMin = new Vector2(0, 1);
        newSlider9.transform.GetComponent <RectTransform>().anchorMax = new Vector2(0, 1);
        //newSlider2.label = "Slider (" + (i).ToString() + ") Alpha";
        Debug.Log(" ASDasdas" + inputs[5 * armsNo + 4, 2]);
        if (inputs[5 * armsNo + 4, 2] == "0")
        {
            sliderCount--;
            newSlider9.GetComponent <Slider>().interactable      = false;
            newSlider9.GetComponent <RectTransform>().localScale = new Vector3(0f, 0f, 0f);
            ;
        }
        else
        {
            //GameObject textObj = new GameObject("myTextGO");
            //textObj.transform.position = new Vector3(229.4f, -30.4f -sliderCount*20, 0);
            //textObj.transform.SetParent(GameObject.Find("Canvas").transform, false);
            //textObj.transform.SetParent(newSlider9.transform);
            //textObj.transform.localPosition = new Vector3(198.6f,-43f,0f);
            //Text myText = textObj.AddComponent<Text>();
            //myText.text = "Slider (" + (armsNo).ToString() + ") length";
            //myText.font = (Font)Resources.GetBuiltinResource(typeof(Font), "Arial.ttf");
            //myText.horizontalOverflow = HorizontalWrapMode.Overflow;
            //textObj.transform.GetComponent<RectTransform>().anchorMin = new Vector2(0,1);
            //textObj.transform.GetComponent<RectTransform>().anchorMax = new Vector2(0,1);
            newSlider9.GetComponent <Slider>().maxValue = 2 * float.Parse(inputs[armsNo * 2, 0], CultureInfo.InvariantCulture);
            newSlider9.GetComponent <Slider>().minValue = float.Parse(inputs[armsNo * 2, 0], CultureInfo.InvariantCulture);
            newSlider9.GetComponent <Slider>().value    = float.Parse(inputs[armsNo * 2, 0], CultureInfo.InvariantCulture);
            //newSlider8.GetComponent<RectTransform>().SetSizeWithCurrentAnchors( RectTranform.Axis.Horizontal, 150);
        }



        GameObject obj5 = loadAndDisplayMesh(inputs[5 * armsNo + 7, 0].Replace("\r", ""));

        obj5.AddComponent <MeshCollider>();
        obj5.GetComponent <MeshCollider>().convex = true;
        obj5.name = "hand 1";
        //obj3.AddComponent<MeshCollider>();
        grabberHand gh5 = obj5.AddComponent <grabberHand>();

        //rbj3.length = Int32.Parse(inputs[armsNo*2,0]);
        //rbj3.d = Int32.Parse(inputs[armsNo*2,1]);
        obj5.transform.SetParent(parentObj.transform);
        gh5.parent      = obj3;
        gh5.jointParent = obj3;
        gh5.offsets.x   = float.Parse(inputs[7 * armsNo + 13, 0], CultureInfo.InvariantCulture);
        gh5.offsets.y   = float.Parse(inputs[7 * armsNo + 13, 1], CultureInfo.InvariantCulture);
        gh5.offsets.z   = float.Parse(inputs[7 * armsNo + 13, 2], CultureInfo.InvariantCulture);

        //gh5.xscale = 2f;

        gh5.sliderNo = newSlider5.name;

        GameObject obj6 = loadAndDisplayMesh(inputs[5 * armsNo + 8, 0].Replace("\r", ""));

        obj6.AddComponent <MeshCollider>();
        obj6.GetComponent <MeshCollider>().convex = true;
        obj6.name = "hand 2";
        //obj3.AddComponent<MeshCollider>();
        grabberHand gh6 = obj6.AddComponent <grabberHand>();

        //rbj3.length = Int32.Parse(inputs[armsNo*2,0]);
        //rbj3.d = Int32.Parse(inputs[armsNo*2,1]);
        obj6.transform.SetParent(parentObj.transform);
        gh6.parent      = obj3;
        gh6.jointParent = obj3;
        gh6.xscale      = 2f;
        gh6.sliderNo    = gh5.sliderNo;
        gh6.offsets.x   = float.Parse(inputs[7 * armsNo + 13, 0], CultureInfo.InvariantCulture);
        gh6.offsets.y   = float.Parse(inputs[7 * armsNo + 13, 1], CultureInfo.InvariantCulture);
        gh6.offsets.z   = float.Parse(inputs[7 * armsNo + 13, 2], CultureInfo.InvariantCulture);



        GameObject obj7 = loadAndDisplayMesh(inputs[4 * armsNo + 2, 0].Replace("\r", ""));

        //obj7.AddComponent<MeshCollider>();
        //obj7.GetComponent<MeshCollider>().convex = true;
        obj7.name = "base";
        //obj3.AddComponent<MeshCollider>();
        var colli7 = obj7.AddComponent <NonConvexMeshCollider>();

        colli7.avoidExceedingMesh = true;
        colli7.boxesPerEdge       = 30;
        //colli7.Calculate();
        Base b7 = obj7.AddComponent <Base>();

        b7.offset.x = float.Parse(inputs[7 * armsNo + 9, 0], CultureInfo.InvariantCulture);
        b7.offset.y = float.Parse(inputs[7 * armsNo + 9, 1], CultureInfo.InvariantCulture);
        b7.offset.z = float.Parse(inputs[7 * armsNo + 9, 2], CultureInfo.InvariantCulture);
        b7.scale    = float.Parse(inputs[7 * armsNo + 10, 0], CultureInfo.InvariantCulture);

        int        bitsNo = Int32.Parse(inputs[8 * armsNo + 15, 0]);
        GameObject obj8;

        for (int k = 0; k < bitsNo; k++)
        {
            Debug.Log(inputs[8 * armsNo + 15 + k, 0].Replace("\r", ""));
            obj8 = loadAndDisplayMesh(inputs[8 * armsNo + 16 + k, 0].Replace("\r", ""));
            //obj8.AddComponent<MeshCollider>();
            //obj8.GetComponent<MeshCollider>().convex = true;
            obj8.name = "bit" + k.ToString();
            Bits bit = obj8.AddComponent <Bits>();
            bit.jointNum    = (inputs[8 * armsNo + 16 + k, 1].Replace("\r", ""));
            bit.jointRotNum = Int32.Parse(inputs[8 * armsNo + 16 + k, 2].Replace("\r", ""));
            bit.scale       = float.Parse(inputs[8 * armsNo + 16 + k, 3].Replace("\r", ""));
            bit.offset.x    = float.Parse(inputs[8 * armsNo + 16 + k, 4].Replace("\r", ""));
            bit.offset.y    = float.Parse(inputs[8 * armsNo + 16 + k, 5].Replace("\r", ""));
            bit.offset.z    = float.Parse(inputs[8 * armsNo + 16 + k, 6].Replace("\r", ""));
            bit.useLocal    = Int32.Parse(inputs[8 * armsNo + 16 + k, 7].Replace("\r", ""));
        }
    }