示例#1
0
    public GameObject copy(int newID)
    {
        GameObject newCreature = new GameObject();

        Creature      creature   = newCreature.AddComponent <Creature>();
        List <Node>   newNodes   = new List <Node>(0);
        List <Muscle> newMuscles = new List <Muscle>(0);

        for (int i = 0; i < nodeCount; i++)
        {
            Node node = nodes[i];
            CreateNode(node.Pos, newCreature.transform, node.prevX, node.prevY, node.M, node.friction, node.value, node.operation, node.axon1, node.axon2);
        }

        for (int i = 0; i < muscleCount; i++)
        {
            Muscle cM = muscles[i].copy();
            CreateMuscle(newCreature.transform, cM.axon, cM.p1, cM.p2, cM.Length, cM.rigidity);
        }

        if (newID == -1)
        {
            newID = ID;
        }
        creature.SetInititationValues(newID, newNodes, newMuscles, cFitness, alive, creatureTimer, mutability);

        return(newCreature);
    }
示例#2
0
 // Start is called before the first frame update
 void Start()
 {
     joint  = this.GetComponentInChildren <Joint>();
     muscle = this.GetComponentInChildren <Muscle>();
     bone1  = this.GetComponentInChildren <Bone>();
     bone2  = this.GetComponentInChildren <Bone>();
 }
示例#3
0
    void CmdNeuronFiredMuscle(GameObject toInform)
    {
        Muscle informed = toInform.GetComponent <Muscle>();

        informed.currentInputs.Add(new Muscle.Input(Time.time));
        //RpcNeuronFiredMuscle(toInform);  //TODO: Do we need this?
    }
示例#4
0
        /// <summary>
        /// Create data in database
        /// </summary>
        /// <param name="muscle">Data</param>
        /// <returns>insert data</returns>
        public Muscle Create(Muscle muscle)
        {
            if (muscle == null)
            {
                return(null);
            }

            if (muscle.Id == 0)
            {
                var key = new MuscleKey();
                var sequencerManager = new SequencerManager();
                do
                {
                    key.Id = sequencerManager.GetNextValue(_dbContext, 4, "muscle");
                }while (Get(key) != null); // Test Record exist
                muscle.Id = key.Id;
            }

            if (muscle.Id == 0)
            {
                return(null);
            }

            var row = new MuscleRow();

            MuscleTransformer.ToRow(muscle, row);
            _dbContext.Muscle.Add(row);
            _dbContext.SaveChanges();

            return(MuscleTransformer.ToBean(row));
        }
示例#5
0
        public async Task <IActionResult> PutMuscle(int id, Muscle muscle)
        {
            if (id != muscle.Id)
            {
                return(BadRequest());
            }

            _context.Entry(muscle).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!MuscleExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
示例#6
0
        public async Task <IActionResult> Create(MuscleViewModel muscleVM, IFormFile file)
        {
            var    filePath = Path.GetTempFileName();
            Muscle muscle   = new Muscle
            {
                BodyPartId  = muscleVM.BodyPartId,
                Description = muscleVM.Description,
                MuscleId    = muscleVM.MuscleId,
                Name        = muscleVM.Name
            };

            if (file != null)
            {
                using (var memoryStream = new MemoryStream())
                {
                    await file.CopyToAsync(memoryStream);

                    muscle.Image = memoryStream.ToArray();
                }
            }

            if (ModelState.IsValid)
            {
                muscleRepository.SaveMuscle(muscle);
                TempData["Message"] = $"{muscle.Name} has been created";
                return(RedirectToAction("Index", "BodyArea", bodyAreaRepository.BodyAreas.ToList().CreateListBAreaVM(bodyPartRepository, bodyAreaRepository, dbGetter)));
            }
            else
            {
                return(RedirectToAction("Index", "BodyArea", bodyAreaRepository.BodyAreas.ToList().CreateListBAreaVM(bodyPartRepository, bodyAreaRepository, dbGetter)));
            }
        }
示例#7
0
        public async Task <ActionResult <Muscle> > PostMuscle(Muscle muscle)
        {
            _context.Muscle.Add(muscle);
            await _context.SaveChangesAsync();

            return(Ok(muscle));
        }
示例#8
0
    // Sets colliders of a muscle to puppet or unpinned mode
    private void SetColliders(Muscle m, bool unpinned)
    {
        var props = GetProps(m);

        if (unpinned)
        {
            foreach (Collider c in m.colliders)
            {
                c.material = props.unpinnedMaterial != null ? props.unpinnedMaterial : defaults.unpinnedMaterial;

                // Enable colliders
                if (props.disableColliders)
                {
                    c.enabled = true;
                }
            }
        }
        else
        {
            foreach (Collider c in m.colliders)
            {
                c.material = props.puppetMaterial != null ? props.puppetMaterial : defaults.puppetMaterial;

                // Enable colliders
                if (props.disableColliders)
                {
                    c.enabled = false;
                }
            }
        }
    }
示例#9
0
    /// <summary>
    /// Makes a mutation of the current node
    /// </summary>
    /// <returns>Muscle</returns>
    public Muscle modify(int nodeNum, float mutability, float mutationChance, List <Node> nodes)
    {
        // makes a new instance of the parent1, parent2 and axon values
        Node newp1   = p1;
        Node newp2   = p2;
        int  newAxon = axon;

        if (Random.Range(0f, 1f) < mutationChance)
        {
            newp1 = nodes[Random.Range(0, nodeNum)];
        }

        if (Random.Range(0f, 1f) < mutationChance)
        {
            newp2 = nodes[Random.Range(0, nodeNum)];
        }

        if (Random.Range(0f, 1f) < mutationChance)
        {
            newAxon = getNewMuscleAxon(nodeNum);
        }

        float newRigidity = Mathf.Min(Mathf.Max(rigidity * (1 + Creature.randGet() * 0.9f * mutability), 0.01f), 0.08f);
        float newLenght   = Mathf.Min(Mathf.Max(length + Creature.randGet() * mutability, 0.4f), 1.25f);

        Muscle newMuscle = new Muscle();

        newMuscle.SetInitiationValues(newAxon, newp1, newp2, newLenght, newRigidity);
        return(newMuscle);
    }
示例#10
0
 private void ActivateMuscle(Muscle muscle)
 {
     if (muscle.Properties.MuscleLevel != MuscleLevels.Where(x => x.Key == muscle.Properties.TypeMuscle).First().Value)
     {
         muscle.gameObject.SetActive(false);
     }
 }
    // Returns true is the groups match directly OR in the group overrides.
    private bool InGroup(Muscle muscle1, Muscle muscle2)
    {
        if (muscle1 == muscle2)
        {
            return(true);
        }

        foreach (MuscleBasePropsGroup musclePropsGroup in groupOverrides)
        {
            foreach (Muscle m in musclePropsGroup.muscleGroup.muscles)
            {
                if (m == muscle1)
                {
                    foreach (Muscle m2 in musclePropsGroup.muscleGroup.muscles)
                    {
                        if (m2 == muscle2)
                        {
                            return(true);
                        }
                    }
                }
            }
        }

        return(false);
    }
示例#12
0
        /// <summary>
        /// Checks to see if the current muscle is valid (attached to two joints) and if so
        /// adds it to the list of muscles.
        /// </summary>
        /// <returns>Returns whether the current muscle was placed</returns>
        public bool PlaceCurrentMuscle()
        {
            if (currentMuscle == null)
            {
                return(false);
            }

            if (currentMuscle.endingBone == null)
            {
                // The connection has no connected ending -> Destroy
                UnityEngine.Object.Destroy(currentMuscle.gameObject);
                currentMuscle = null;
                return(false);
            }
            else
            {
                // Validate the muscle doesn't exist already
                foreach (Muscle muscle in muscles)
                {
                    if (muscle.Equals(currentMuscle))
                    {
                        UnityEngine.Object.Destroy(currentMuscle.gameObject);
                        currentMuscle = null;
                        return(false);
                    }
                }

                currentMuscle.ConnectToJoints();
                currentMuscle.AddCollider();
                muscles.Add(currentMuscle);
                currentMuscle = null;
                // The creature was modified
                return(true);
            }
        }
示例#13
0
    // Called by PM when a muscle is removed (once for each removed muscle)
    void OnMuscleRemoved(Muscle m)
    {
        bool isLeft = false;

        // If one of the legs is missing, play the "jump on one leg" animation. If both, set PM state to Dead.
        if (IsLegMuscle(m, out isLeft))
        {
            if (isLeft)
            {
                leftLegRemoved = true;
            }
            else
            {
                rightLegRemoved = true;
            }

            if (leftLegRemoved && rightLegRemoved)
            {
                puppetMaster.state = PuppetMaster.State.Dead;
            }
            else
            {
                animator.SetBool("OneLeg", true);
            }
        }
    }
示例#14
0
 public void SetParent(Muscle parentMuscle)
 {
     joint.xMotion       = ConfigurableJointMotion.Locked;
     joint.yMotion       = ConfigurableJointMotion.Locked;
     joint.zMotion       = ConfigurableJointMotion.Locked;
     joint.connectedBody = parentMuscle.boneRb;
 }
示例#15
0
    /// <summary>
    /// Makes a copy of the current muscle
    /// </summary>
    /// <returns>Muscle</returns>
    public Muscle copy()
    {
        Muscle muscle = new Muscle();

        muscle.SetInitiationValues(axon, p1, p2, length, rigidity);
        return(muscle);
    }
示例#16
0
    /**
     * Checks to see if the current muscle is valid (attached to two joints) and if so
     * adds it to the list of muscles.
     */
    private void PlaceCurrentMuscle()
    {
        if (currentMuscle == null)
        {
            return;
        }

        if (currentMuscle.endingJoint == null || GetHoveringObject <Bone>(bones) == null)
        {
            // The connection has no connected ending -> Destroy
            Destroy(currentMuscle.gameObject);
        }
        else
        {
            // Validate the muscle doesn't exist already
            foreach (Muscle muscle in muscles)
            {
                if (muscle.Equals(currentMuscle))
                {
                    Destroy(currentMuscle.gameObject);
                    currentMuscle = null;
                    return;
                }
            }

            currentMuscle.ConnectToJoints();
            currentMuscle.AddCollider();
            muscles.Add(currentMuscle);

            ResetCurrentCreatureName();             // The creature was modified
        }

        currentMuscle = null;
    }
示例#17
0
        internal Muscle Update(Muscle muscle)
        {
            //Update Translation Name
            //Translation.UpdateInDB(MuscleTransformer.GetTranslationKey(muscle.Id), muscle.Name, _dbContext);

            return(_module.Update(muscle));
        }
示例#18
0
 private void CompleteTranslation(Muscle muscle)
 {
     if (muscle != null)
     {
         string trKey = MuscleTransformer.GetTranslationKey(muscle.Id);
         muscle.Name = Translation.GetInDB(trKey, DbContext);
     }
 }
示例#19
0
 private void SaveTranslation(Muscle muscle)
 {
     if (muscle != null)
     {
         string trKey = BodyExerciseTransformer.GetTranslationKey(muscle.Id);
         Translation.UpdateInDB(trKey, muscle.Name, DbContext);
     }
 }
示例#20
0
 public MuscleModel Create(Muscle muscle)
 {
     return(new MuscleModel()
     {
         Id = muscle.Id,
         Name = muscle.Name
     });
 }
示例#21
0
        public ActionResult DeleteConfirmed(int id)
        {
            Muscle muscle = db.Muscles.Find(id);

            db.Muscles.Remove(muscle);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
示例#22
0
    void removeRandMuscle()
    {
        int    removed = (int)Mathf.Floor(Random.Range(0f, muscleCount));
        Muscle muscle  = muscles[removed];

        muscles.Remove(muscle);
        Destroy(muscle);
    }
示例#23
0
        /// <summary>
        /// Instantiates a muscle at the specified point.
        /// </summary>
        private void CreateMuscleFromBone(Bone bone)
        {
            var muscleData = new MuscleData(idCounter++, bone.BoneData.id, bone.BoneData.id, Muscle.Defaults.MaxForce, true);

            currentMuscle = Muscle.CreateFromData(muscleData);
            currentMuscle.startingBone = bone;
            currentMuscle.SetLinePoints(bone.Center, bone.Center);
        }
示例#24
0
    public static void MuscleConnectionRemoved(MuscleConnection mus)
    {
        MuscleConnectionFile file;
        Controller           start = mus.GetStart().GetComponent <Controller>();
        Muscle end = mus.GetEnd().GetComponent <Muscle>();

        MuscleType type;

        if (end is SwingMuscle)
        {
            //What type?
            SwingMuscle swing = end as SwingMuscle;
            switch (swing.moveDirection)
            {
            case SwingMuscle.SwingFunction.Backward: {
                type = MuscleType.Backward;
                break;
            }

            case SwingMuscle.SwingFunction.Forward: {
                type = MuscleType.Forward;
                break;
            }

            default: {
                //So we have something
                type = MuscleType.Forward;
                break;
            }
            }
        }
        else
        {
            //Stance muscle
            type = MuscleType.Stance;
        }

        file = new MuscleConnectionFile(end.table, type, start.GetTableNum(), start.GetSeatNum());

        int endpoint = muscleConnectionsToReset.Count;          //Avoid changing list while iterating.

        for (int i = endpoint - 1; i >= 0; i--)
        {
            if (muscleConnectionsToReset[i].Equals(mus.gameObject))
            {
                muscleConnectionsToReset.Remove(mus.gameObject);
            }
        }

        endpoint = spawnedMuscleConnections.Count;
        for (int i = endpoint - 1; i >= 0; i--)
        {
            if (spawnedMuscleConnections[i].Equals(file))
            {
                spawnedMuscleConnections.Remove(file);
            }
        }
    }
示例#25
0
        public int Update(Muscle entity)
        {
            Muscle fromDatabase = Get(entity.Id);

            DatabaseContext.Entry(fromDatabase).CurrentValues.SetValues(entity);
            DatabaseContext.Entry(fromDatabase).State = EntityState.Modified;

            return(DatabaseContext.SaveChanges());
        }
示例#26
0
 public void CreateRefMuscles(GameObject parent, GameObject child, List <Muscle> refMuscle, Vector3 refAxis)
 {
     foreach (Muscle muscle in refMuscle)
     {
         Muscle m = new Muscle(parent, child);
         m.CreateRefMuscle(muscle, refAxis);
         muscles.Add(m);
     }
 }
示例#27
0
 public void CreateRecurssionMuscles(GameObject parent, GameObject child, List <Muscle> refMuscle)
 {
     foreach (Muscle muscle in refMuscle)
     {
         Muscle m = new Muscle(parent, child);
         m.CreateRecurssionMuscle(muscle);
         muscles.Add(m);
     }
 }
 private FallParams GetFallParams(Muscle.Group group)
 {
     foreach (FallParamsGroup g in groupOverrides) {
         foreach (Muscle.Group muscleGroup in g.groups) {
             if (muscleGroup == group) return g.fallParams;
         }
     }
     return defaults;
 }
示例#29
0
        internal Muscle UpdateMuscle(Muscle muscle)
        {
            SaveTranslation(muscle);

            Muscle result = _muscleModule.Update(muscle);

            CompleteTranslation(result);
            return(result);
        }
示例#30
0
        private Muscle CreateMuscleBetween(Bone startingBone, Bone endingBone, MuscleData data)
        {
            var muscle = Muscle.CreateFromData(data);

            muscle.startingBone = startingBone;
            muscle.endingBone   = endingBone;

            muscle.SetLinePoints(startingBone.Center, endingBone.Center);
            return(muscle);
        }
示例#31
0
        public IActionResult DispMuscle(int muscle_Id)
        {
            Muscle DispMuscle = dbContext.Muscles.Include(w => w.mTrains).ThenInclude(t => t.tWorkout).FirstOrDefault(w => w.MuscleId == muscle_Id);

            User userInDb = dbContext.Users.FirstOrDefault(u => u.Email == HttpContext.Session.GetString("UserEmail"));

            ViewBag.LogUser = userInDb;

            return(View("DispMuscle", DispMuscle));
        }
示例#32
0
 protected bool MusclesContainsGroup(Muscle.Group group)
 {
     foreach (Muscle m in puppetMaster.muscles) {
         if (m.props.group == group) return true;
     }
     return false;
 }
        /// <summary>
        /// NB! Make sure to call this from FixedUpdate!
        /// Creates a new muscle for the specified "joint" and targets it to the "target". The joint will be connected to the specified "connectTo" Muscle.
        /// Note that the joint will be binded to it's current position and rotation relative to the "connectTo", so make sure the added object is positioned correctly when calling this.
        /// This method allocates memory, avoid using it each frame.
        /// </summary>
        public void AddMuscle(ConfigurableJoint joint, Transform target, Rigidbody connectTo, Transform targetParent, Muscle.Props muscleProps = null)
        {
            if (!CheckIfInitiated()) return;

            if (!initiated) {
                Debug.LogWarning("PuppetMaster has not been initiated.", transform);
                return;
            }

            if (ContainsJoint(joint)) {
                Debug.LogWarning("Joint " + joint.name + " is already used by a Muscle", transform);
                return;
            }

            if (target == null) {
                Debug.LogWarning("AddMuscle was called with a null 'target' reference.", transform);
                return;
            }

            if (connectTo == joint.GetComponent<Rigidbody>()) {
                Debug.LogWarning("ConnectTo is the joint's own Rigidbody, can not add muscle.", transform);
                return;
            }

            if (!isActive) {
                Debug.LogWarning("Adding muscles to inactive PuppetMasters is not currently supported.", transform);
                return;
            }

            if (muscleProps == null) muscleProps = new Muscle.Props();

            Muscle muscle = new Muscle();
            muscle.props = muscleProps;
            muscle.joint = joint;
            muscle.target = target;
            muscle.joint.transform.parent = HierarchyIsFlat() || connectTo == null? transform: connectTo.transform;
            joint.gameObject.layer = gameObject.layer; //@todo what if collider is on a child gameobject?
            target.gameObject.layer = targetRoot.gameObject.layer;

            if (connectTo != null) {
                muscle.target.parent = targetParent;

                Vector3 relativePosition = GetMuscle(connectTo).transform.InverseTransformPoint(muscle.target.position);
                Quaternion relativeRotation = Quaternion.Inverse(GetMuscle(connectTo).transform.rotation) * muscle.target.rotation;

                joint.transform.position = connectTo.transform.TransformPoint(relativePosition);
                joint.transform.rotation = connectTo.transform.rotation * relativeRotation;

                joint.connectedBody = connectTo;
            }

            muscle.Initiate(muscles);

            if (connectTo != null) {
                muscle.rigidbody.velocity = connectTo.velocity;
                muscle.rigidbody.angularVelocity = connectTo.angularVelocity;
            }

            // Ignore internal collisions
            if (!internalCollisions) {
                for (int i = 0; i < muscles.Length; i++) {
                    muscle.IgnoreCollisions(muscles[i], true);
                }
            }

            Array.Resize(ref muscles, muscles.Length + 1);
            muscles[muscles.Length - 1] = muscle;

            // Update angular limit ignoring
            muscle.IgnoreAngularLimits(!angularLimits);

            if (behaviours.Length > 0) {
                muscle.broadcaster = muscle.joint.gameObject.AddComponent<MuscleCollisionBroadcaster>();
                muscle.broadcaster.puppetMaster = this;
                muscle.broadcaster.muscleIndex = muscles.Length - 1;
            }

            UpdateHierarchies();
            CheckMassVariation(100f, true);
        }
        /// <summary>
        /// NB! Make sure to call this from FixedUpdate!
        /// Completely replaces the muscle structure. Make sure the new muscle objects are positioned and rotated correctly relative to their targets.
        /// This method allocates memory, avoid using it each frame.
        /// </summary>
        public void SetMuscles(Muscle[] newMuscles)
        {
            if (!CheckIfInitiated()) return;

            // @todo
            Debug.LogWarning("@todo", transform);
        }
示例#35
0
文件: Node.cs 项目: tyharbert/Unity3D
	public void attach(Muscle m) {
		this.attached.Add(m);
	}
        // Builds muscles
        private void SetUpMuscles(Transform setUpTo)
        {
            // Auto-detect targets
            ConfigurableJoint[] joints = transform.GetComponentsInChildren<ConfigurableJoint>();

            if (joints.Length == 0) {
                Debug.LogWarning("No ConfigurableJoints found, can not build PuppetMaster. Please create ConfigurableJoints to connect the ragdoll bones together.", transform);
                return;
            }

            var animator = targetRoot.GetComponentInChildren<Animator>();
            Transform[] children = setUpTo.GetComponentsInChildren<Transform>();

            muscles = new Muscle[joints.Length];
            int hipIndex = -1;

            for (int i = 0; i < joints.Length; i++) {
                muscles[i] = new Muscle();
                muscles[i].joint = joints[i];
                muscles[i].name = joints[i].name;
                muscles[i].props = new Muscle.Props(1f, 1f, 1f, 1f, muscles[i].joint.connectedBody == null);
                if (muscles[i].joint.connectedBody == null && hipIndex == -1) hipIndex = i;

                foreach (Transform c in children) {
                    if (c.name == joints[i].name) {
                        muscles[i].target = c;
                        if (animator != null) muscles[i].props.group = FindGroup(animator, muscles[i].target);
                        break;
                    }
                }
            }

            // The hip muscle is not first in hierarchy
            if (hipIndex != 0) {
                var firstMuscle = muscles[0];
                var hipMuscle = muscles[hipIndex];
                muscles[hipIndex] = firstMuscle;
                muscles[0] = hipMuscle;
            }

            bool allSameGroup = true;

            foreach (Muscle m in muscles) {
                if (m.target == null) {
                    Debug.LogWarning("No target Transform found for PuppetMaster muscle " + m.joint.name + ". Please assign manually.", transform);
                }

                if (m.props.group != muscles[0].props.group) allSameGroup = false;
            }

            if (allSameGroup) {
                Debug.LogWarning("Muscle groups need to be assigned in the PuppetMaster!", transform);
            }
        }
示例#37
0
        private IDomainIdentifiable<long> CreateMuscle(string name = "Calves")
        {
            var muscle = new Muscle("Soleus") { BelongsToMuscleGroup = new MuscleGroup(name) };

            IDomainIdentifiable<long> createdMuscle = _service.Create(muscle);

            return createdMuscle;
        }
示例#38
0
 protected void RemoveMusclesOfGroup(Muscle.Group group)
 {
     while (MusclesContainsGroup(group)) {
         for (int i = 0; i < puppetMaster.muscles.Length; i++) {
             if (puppetMaster.muscles[i].props.group == group) {
                 puppetMaster.RemoveMuscleRecursive(puppetMaster.muscles[i].joint, true);
                 break;
             }
         }
     }
 }
        /// <summary>
        /// Sets the muscle weights for all muscles in the specified group.
        /// </summary>
        public void SetMuscleWeights(Muscle.Group group, float muscleWeight, float pinWeight = 1f, float mappingWeight = 1f, float muscleDamper = 1f)
        {
            if (!CheckIfInitiated()) return;

            foreach (Muscle m in muscles) {
                if (m.props.group == group) {
                    m.props.muscleWeight = muscleWeight;
                    m.props.pinWeight = pinWeight;
                    m.props.mappingWeight = mappingWeight;
                    m.props.muscleDamper = muscleDamper;
                }
            }
        }
        /// <summary>
        /// Removes the muscle with the specified joint and all muscles connected to it from PuppetMaster management. This will not destroy the body part/prop, but just release it from following the target.
        /// If you call RemoveMuscleRecursive on an upper arm muscle, the entire arm will be disconnected from the rest of the body.
        /// If attachTarget is true, the target Transform of the first muscle will be parented to the disconnected limb.
        /// This method allocates some memory, avoid using it each frame.
        /// </summary>
        public void RemoveMuscleRecursive(ConfigurableJoint joint, bool attachTarget)
        {
            if (!CheckIfInitiated()) return;

            if (joint == null) {
                Debug.LogWarning("RemoveMuscleRecursive was called with a null 'joint' reference.", transform);
                return;
            }

            if (!ContainsJoint(joint)) {
                Debug.LogWarning("No Muscle with the specified joint was found, can not remove muscle.", transform);
                return;
            }

            int index = GetMuscleIndex(joint);
            Muscle[] newMuscles = new Muscle[muscles.Length - (muscles[index].childIndexes.Length + 1)];

            int added = 0;
            for (int i = 0; i < muscles.Length; i++) {
                if (i != index && !muscles[index].childFlags[i]) {
                    newMuscles[added] = muscles[i];
                    added ++;
                } else {
                    if (muscles[i].broadcaster != null) Destroy(muscles[i].broadcaster);
                }
            }

            muscles[index].joint.connectedBody = null;

            muscles[index].joint.targetRotation = Quaternion.identity;
            JointDrive j = new JointDrive();
            j.positionSpring = 0f;
            #if UNITY_5_2
            j.mode = JointDriveMode.None;
            #endif
            muscles[index].joint.slerpDrive = j;
            muscles[index].joint.xMotion = ConfigurableJointMotion.Free;
            muscles[index].joint.yMotion = ConfigurableJointMotion.Free;
            muscles[index].joint.zMotion = ConfigurableJointMotion.Free;
            muscles[index].joint.angularXMotion = ConfigurableJointMotion.Free;
            muscles[index].joint.angularYMotion = ConfigurableJointMotion.Free;
            muscles[index].joint.angularZMotion = ConfigurableJointMotion.Free;

            muscles[index].transform.parent = null;

            if (attachTarget) {
                muscles[index].target.parent = muscles[index].transform;
                muscles[index].target.position = muscles[index].transform.position;
                muscles[index].target.rotation = muscles[index].transform.rotation * muscles[index].targetRotationRelative;
            }

            muscles = newMuscles;

            UpdateHierarchies();
        }