Exemplo n.º 1
0
    // Start is called before the first frame update
    public void SetGateInteraction()
    {
        Cloth gateCloth = this.GetComponent <Cloth>();

        if (gateCloth != null)
        {
            GameObject[] players = GameObject.FindGameObjectsWithTag("Player");
            if (players.Length > 0)
            {
                for (int i = 0; i < players.Length; i++)
                {
                    if (players[i] != null)
                    {
                        ClothSphereColliderPair[] collider = new ClothSphereColliderPair[players.Length];

                        collider[i] = new ClothSphereColliderPair(players[0].GetComponent <SphereCollider>());
                        gateCloth.sphereColliders = collider;
                    }
                }
            }
            else
            {
                Debug.Log("Victory Gate setter : Player not found.");
            }
        }
    }
Exemplo n.º 2
0
    void CreateBasketball()
    {
        _basketball = (GameObject)Instantiate(basketballPrefab, basketballPosition.position, basketballPrefab.transform.rotation);
        _basketball.transform.parent = transform.root;
        ClothSphereColliderPair cscp = new ClothSphereColliderPair(_basketball.GetComponent <SphereCollider>());

        netCloth.sphereColliders = new ClothSphereColliderPair[] { cscp };
    }
 void Start()
 {
     // Initialise ClothSphereColliderPair array
     for (int i = 0; i < 20; i++)
     {
         spheres[i] = new ClothSphereColliderPair();
     }
 }
Exemplo n.º 4
0
        public float lowerYAtEdge = .179f; // linear but should be curved

        public void SetTextureMapping()
        {
            float incrementX = 1f / mapDimensionsX;
            float incrementY = 1f / mapDimensionsY;

            float startPosX = -(rowWidth * spacing) / 2f;
            float startPosY = -(mapDimensionsY * spacing) / 2f;
            float zMove     = zSetback;

            writeableTexture = new Texture2D(templateTexture.width, templateTexture.height);
            Color32[] pixels = templateTexture.GetPixels32();
            writeableTexture.SetPixels32(pixels);
            writeableTexture.Apply();

            templateRenderer.gameObject.SetActive(true);

            for (int y = 0; y < mapDimensionsY; y++)
            {
                int   colCount = 0;
                float xOffset  = y * (spacing / 2f);

                for (int x = 0; x < mapDimensionsX; x++)
                {
                    if (colCount == rowWidth)
                    {
                        colCount = 0;
                        zMove   += spacing;
                    }
                    Renderer r = Instantiate <Renderer>(templateRenderer);
                    r.sharedMaterial = new Material(templateMaterial)
                    {
                        mainTextureOffset = new Vector2((float)x * incrementX, (float)y * incrementY),
                        mainTexture       = writeableTexture
                    };
                    r.gameObject.name = string.Format("{0}_{1}", x, y);
                    r.transform.SetParent(this.transform, false);
                    r.transform.localRotation = Quaternion.identity;

                    float midX          = (float)rowWidth / 2f;
                    float deviationX    = Mathf.Abs((float)colCount - midX);
                    float unitDeviation = deviationX / (float)midX;

                    float ySubtractY = unitDeviation * lowerYAtEdge;

                    r.transform.localPosition = centreLocation.localPosition + new Vector3(xOffset + startPosX + colCount * spacing, -ySubtractY, zSetback + startPosY + y * spacing);
                    var scale = r.transform.localScale;
                    r.transform.localScale = new Vector3(scale.x, scale.y, scale.z * (1f + (1f - unitDeviation)));
                    var cloth     = r.gameObject.GetComponent <Cloth>();
                    var colliders = new ClothSphereColliderPair[1];
                    colliders[0]          = new ClothSphereColliderPair(head, neck);
                    cloth.sphereColliders = colliders;
                    colCount++;
                }
            }

            templateRenderer.gameObject.SetActive(false);
        }
Exemplo n.º 5
0
 void removeCollider()
 {
     clothColliders.Remove(new ClothSphereColliderPair(GetComponent <SphereCollider>())); //在碰撞列表中移除自身
     ClothSphereColliderPair[] cscp = new ClothSphereColliderPair[clothColliders.Count];  //重新声明碰撞列表
     for (int i = 0; i < cscp.Length; i++)
     {
         cscp[i] = (ClothSphereColliderPair)clothColliders[i];               //初始化碰撞列表
     }
     cloth.sphereColliders = cscp;                                           //设置碰撞列表
 }
Exemplo n.º 6
0
    void Update()
    {
        bball = GameObject.FindGameObjectsWithTag("BBall");

        foreach (GameObject bballs in bball)
        {
            var sphereColliderArray = new ClothSphereColliderPair[1];
            sphereColliderArray[0]         = new ClothSphereColliderPair(bballs.GetComponent <SphereCollider>());
            clothComponent.sphereColliders = sphereColliderArray;
        }
    }
Exemplo n.º 7
0
 private void addCollider(ref Cloth c, SphereCollider sc)
 {
     ClothSphereColliderPair[] cscp = new ClothSphereColliderPair[c.sphereColliders.Length + 1]; //重新声明碰撞器数组
     for (int i = 0; i < c.sphereColliders.Length; i++)
     {
         cscp[i] = c.sphereColliders[i];                             //初始化碰撞器数组
     }
     cscp[cscp.Length - 1] = new ClothSphereColliderPair(sc);        //添加碰撞器
     BallListener.clothColliders.Add(cscp[cscp.Length - 1]);         //储存碰撞器至列表
     c.sphereColliders = cscp;                                       //设置碰撞列表
 }
Exemplo n.º 8
0
    void setDoorNet()
    {
        var cloths = FindObjectsOfType <Cloth>();

        if (cloths.isNullOrEmpty())
        {
            return;
        }

        ClothSphereColliderPair[] cs2 = new ClothSphereColliderPair[] { new ClothSphereColliderPair(ball.sphereCollider) };
        cloths.forEach(a => { a.sphereColliders = cs2; });
    }
Exemplo n.º 9
0
    public void SpawnBall()
    {
        clone = Instantiate(ball, new Vector3(Camera.main.transform.position.x, Camera.main.transform.position.y - 0.117f, Camera.main.transform.position.z + 0.35f), Quaternion.identity);


        clone.GetComponent <Rigidbody>().isKinematic = true;

        var colliders = new ClothSphereColliderPair[1];

        colliders[0] = new ClothSphereColliderPair(clone.GetComponent <SphereCollider>());

        cloth.sphereColliders = colliders;
    }
    // Use this for initialization
    public void RegisterWithCloth(SphereCollider collider)
    {
        // Move all ClothSphereColliderPairs in the array up
        for (int i = 19; i > 0; i--)
        {
            spheres[i] = spheres[i - 1];
        }

        // Add the new ClothSphereColliderPair to the array
        spheres[0] = new ClothSphereColliderPair(collider);

        // Assign the ClothSphereColliderPair array to the cloth
        cloth.sphereColliders = spheres;
    }
 private void CreateSpheres()
 {
     spheres = new GameObject[(int)(mesh.vertices.Length / (1 + skipVertex))];
     ClothSphereColliderPair[] clothSpheres = new ClothSphereColliderPair[spheres.Length];
     for (int i = 0; i < spheres.Length; ++i)
     {
         spheres[i] = new GameObject("Sphere");
         spheres[i].transform.position = mesh.vertices[i * (1 + skipVertex)]
                                         - (mesh.normals[i * (1 + skipVertex)] * sphereRadius);
         SphereCollider collider = spheres[i].AddComponent <SphereCollider>();
         collider.radius       = sphereRadius;
         clothSpheres[i].first = collider;
     }
     cloth.sphereColliders = clothSpheres;
 }
Exemplo n.º 12
0
    public void AddBallCollider(GameObject ballGameObject)
    {
        int currentAmountOfColliders = mClothComponent.sphereColliders.Length;

        SphereCollider newBallSphereCollider = ballGameObject.GetComponent <SphereCollider>();

        ClothSphereColliderPair[] newSphereColliders = new ClothSphereColliderPair[currentAmountOfColliders + 1];


        for (int i = 0; i < currentAmountOfColliders; ++i)
        {
            newSphereColliders[i] = mClothComponent.sphereColliders[i];
        }


        newSphereColliders[currentAmountOfColliders] = new ClothSphereColliderPair(newBallSphereCollider);

        mClothComponent.sphereColliders = newSphereColliders;
    }
Exemplo n.º 13
0
        void ChargeBall()
        {
            if (objBall == null)
            {
                objBall = (GameObject)Instantiate(ballPrefab);
                objBall.AddComponent <ShotBall>();
                ballRigidbody = objBall.GetComponent <Rigidbody>();

                if (cloth != null)
                {
                    ClothSphereColliderPair[] cscp = new ClothSphereColliderPair[ballCount + 1];
                    int index = 0;
                    for (int i = 0; i < cloth.sphereColliders.Length; i++)
                    {
                        if (cloth.sphereColliders[i].first != null)
                        {
                            cscp[index] = cloth.sphereColliders[i];
                            index++;
                        }
                    }
                    cscp[cscp.Length - 1] = new ClothSphereColliderPair(objBall.GetComponent <SphereCollider>());
                    cloth.sphereColliders = cscp;

                    ballCount = index + 1;
                }

                Vector3 shotPos = shotPoint.transform.localPosition;
                shotPos.z -= offsetZShotPoint;
                objBall.transform.position    = shotPoint.transform.TransformPoint(shotPos);
                objBall.transform.eulerAngles = shotPoint.transform.eulerAngles;
                ballRigidbody.velocity        = Vector3.zero;

                ballRigidbody.AddForce(shotPoint.transform.TransformDirection(new Vector3(0.0f, 0.0f, powerToRoll)), ForceMode.Impulse);
            }

            float dis = Vector3.Distance(shotPoint.transform.position, objBall.transform.position);

            if (dis <= 0.2f)
            {
                state = ShotState.Ready;
                objBall.transform.position = shotPoint.transform.position;
            }
        }
    private IEnumerator Spawn()
    {
        yield return(null);

        bool spawned = false;

        while (!spawned)
        {
            GameObject go = Instantiate(basketballPrefab);
            go.transform.position         = new Vector3(3.0f, 2.0f, 0.0f);
            go.transform.localEulerAngles = new Vector3(-90.0f, 0.0f, 0.0f);
            go.name = "Basketball";
            ClothSphereColliderPair[] a = new ClothSphereColliderPair[1];
            a[0] = new ClothSphereColliderPair(go.GetComponentInChildren <SphereCollider>());
            GameObject.FindObjectOfType <Cloth>().sphereColliders = a;
            spawned = true;

            yield return(null);
        }
    }
Exemplo n.º 15
0
    private void ClearMissingColliders()
    {
        List <ClothSphereColliderPair> n = new List <ClothSphereColliderPair>();

        foreach (ClothSphereColliderPair colliderPair in mClothComponent.sphereColliders)
        {
            if (colliderPair.first != null)
            {
                n.Add(colliderPair);
            }
        }

        ClothSphereColliderPair[] newSphereColliders = new ClothSphereColliderPair[n.Count];
        for (int i = 0; i < n.Count; ++i)
        {
            newSphereColliders[i] = n[i];
        }

        mClothComponent.sphereColliders = newSphereColliders;
    }
Exemplo n.º 16
0
    void CollectJoints(Transform _tr)
    {
        for (int i = 0; i < _tr.childCount; i++)
        {
            if (HasContainWord(_tr.GetChild(i)))
            {
                return;
            }

            Undo.RecordObject(_tr, "c");
            Undo.RecordObject(_tr.GetChild(i), "c");
            if (_tr.GetComponent <SphereCollider>() == null)
            {
                _tr.gameObject.AddComponent <SphereCollider>();                                            //if child doesn't have collider. add one
            }
            if (_tr.GetChild(i).GetComponent <SphereCollider>() == null)
            {
                _tr.GetChild(i).gameObject.AddComponent <SphereCollider>();                                                         //if child doesn't have collider. add one
            }
            cloth.sphereColliders = cloth.sphereColliders;
            first  = _tr.GetComponent <SphereCollider>();
            second = _tr.GetChild(i).GetComponent <SphereCollider>();

            ///setup specifics
            Undo.RecordObject(second, "offset size");
            second.radius += sphereSizeOffset; //offset size
            first.enabled  = false;
            second.enabled = false;

            pair[listCounti] = new ClothSphereColliderPair(first, second);
            listCounti      += 1;
            Debug.Log("list num " + listCounti);

            if (_tr.GetChild(i).childCount > 0)
            {
                CollectJoints(_tr.GetChild(i));
            }
        }
    }
Exemplo n.º 17
0
    public void AttachObject(GameObject obj)
    {
        ValidateVariables();

        if (attachedObjects.Contains(obj))
        {
            Debug.LogError("Attempted to attach a item that was already attached");
            return;
        }

        var sc = obj.AddComponent <SphereCollider>();

        if (clothA == null)
        {
            clothA = BoxA.transform.GetComponentInChildren <Cloth>();
        }
        if (clothB == null)
        {
            clothB = BoxB.transform.GetComponentInChildren <Cloth>();
        }


        attachedObjects.Add(obj);
        obj.GetComponent <Rigidbody>().isKinematic = true;
        obj.transform.SetParent(transform);
        obj.transform.localPosition = AttachPoint.localPosition;

        clothA.enabled = false;

        var colliders = new ClothSphereColliderPair[1];

        colliders[0] = new ClothSphereColliderPair(sc);

        clothA.sphereColliders = colliders;
        clothB.sphereColliders = colliders;

        clothA.enabled = true;
    }
Exemplo n.º 18
0
    // Start is called before the first frame update
    void Start()
    {
        Sprite[] bas = GameController.instance.SpriteBas();

        bas1.sprite = bas[1];
        bas2.sprite = bas[0];


        if (gameObject.tag == "BoardLeft")
        {
            transform.position = new Vector2(Camera.main.ScreenToWorldPoint(GameController.instance.leftbottom).x, transform.position.y);
        }
        else
        {
            transform.position = new Vector2(Camera.main.ScreenToWorldPoint(GameController.instance.rightbottom).x, transform.position.y);
        }

        switch (GameController.instance.Game_Type)
        {
        case GAME_MODE_TYPE.MODE_1:

            break;

        case GAME_MODE_TYPE.MODE_2:
            break;
        }

        init();
        int i1 = Random.Range(0, 100);

        if (i1 > 0 && i1 < 25)
        {
            visibleStar = true;
            if (visibleStar)
            {
                SpawnEffect.instance.Set_System(Paractice_Type.STAR, PosStar.position, "", null);
            }
        }

        if (GameController.instance.Game_Type == GAME_MODE_TYPE.MODE_1)
        {
            ClothSphereColliderPair[] clothSphereColliderPairs = new ClothSphereColliderPair[3];

            clothSphereColliderPairs[0].first = GameObject.Find("Ball").GetComponent <SphereCollider>();

            clothSphereColliderPairs[0].second = GameObject.Find("Ball").GetComponent <SphereCollider>();

            transform.Find("Hoot/Net").GetComponent <Cloth>().sphereColliders = clothSphereColliderPairs;
        }
        else if (GameController.instance.Game_Type == GAME_MODE_TYPE.MODE_2)
        {
            Transform[] trs = GameObject.Find("Mode_3/GunShootBall/PositonBullet").transform.GetComponentsInChildren <Transform>();
            ClothSphereColliderPair[] clothSphereColliderPairs = new ClothSphereColliderPair[trs.Length];
            for (int i = 0; i < trs.Length; i++)
            {
                clothSphereColliderPairs[i].first = trs[i].GetComponent <SphereCollider>();

                clothSphereColliderPairs[i].second = trs[i].GetComponent <SphereCollider>();
            }
            transform.Find("Hoot/Net").GetComponent <Cloth>().sphereColliders = clothSphereColliderPairs;
        }
    }
Exemplo n.º 19
0
        internal static void SetupColliders(Transform root, Cloth cloth, out List <CapsuleCollider> newCapsules, out List <ClothSphereColliderPair> newSpheres)
        {
            newCapsules = new List <CapsuleCollider>();
            newSpheres  = new List <ClothSphereColliderPair>();
            foreach (var cc in cloth.capsuleColliders)
            {
                var newTransform = Transform_Utility.FindTransform(root, cc.transform.name);
                if (newTransform == null)
                {
                    if (cc.transform.parent == null)
                    {
                        continue;
                    }
                    newTransform = Transform_Utility.FindTransform(root, cc.transform.parent.name);
                    if (newTransform == null)
                    {
                        continue;
                    }
                }
                var newcc = Instantiate(cc, newTransform, false);
                Destroy(cc);
                newCapsules.Add(newcc);

                //cc.enabled = false;
                Console.WriteLine("Add new Capsule collider on: " + newcc.name);
            }
            foreach (var sc in cloth.sphereColliders)
            {
                if (sc.first != null)
                {
                    Console.WriteLine("1st sphereColliders: " + sc.first.transform.name);
                    var newTransform1 = Transform_Utility.FindTransform(root, sc.first.transform.name);
                    var newscp        = new ClothSphereColliderPair();
                    if (newTransform1 == null)
                    {
                        if (sc.first.transform.parent == null)
                        {
                            continue;
                        }
                        newTransform1 = Transform_Utility.FindTransform(root, sc.first.transform.parent.name);
                        if (newTransform1 == null)
                        {
                            continue;
                        }
                    }
                    newscp.first = Instantiate(sc.first, newTransform1, false);
                    Destroy(sc.first);
                    Console.WriteLine("Add new Sphere collider on: " + newscp.first.name);

                    if (sc.second != null)
                    {
                        Console.WriteLine("2nd sphereColliders: " + sc.second.transform.name);
                        var newTransform2 = Transform_Utility.FindTransform(root, sc.second.transform.name);
                        if (newTransform2 == null)
                        {
                            if (sc.second.transform.parent == null)
                            {
                                goto addnew;
                            }
                            newTransform2 = Transform_Utility.FindTransform(root, sc.second.transform.parent.name);
                            if (newTransform2 == null)
                            {
                                goto addnew;
                            }
                        }
                        newscp.second = Instantiate(sc.second, newTransform2, false);
                        Destroy(sc.second);
                        Console.WriteLine("Add new Sphere collider on: " + newscp.second.name);
                    }
addnew:
                    newSpheres.Add(newscp);
                }
            }
        }
Exemplo n.º 20
0
    // Use this for initialization
    void Start()
    {
        //var geometry = FileReader.ReadPolyFile("Assets/Plugins/Data/superior.poly");

        var p = new Polygon();

        //p.Add ( ClacSegments ( -2, -2, 2, -2, 1 ) );
        //p.Add ( ClacSegments ( 2, -2, 2, 2, 2 ) );
        //p.Add ( ClacSegments ( 2, 2, -2, 2, 3 ) );
        //p.Add ( ClacSegments ( -2, 2, -2, -2, 4 ) );

        p.Add(ClacSegments(-3, -3, 3, -3, 1));
        p.Add(ClacSegments(3, -3, 3, 3, 2));
        p.Add(ClacSegments(3, 3, -3, 3, 3));
        p.Add(ClacSegments(-3, 3, -3, -3, 4));

        // Add the outer box contour with boundary marker 1.
        // p.Add ( new Contour ( new Vertex [ 4 ]
        //{
        //   new Vertex(-3,-3, 1),
        //   new Vertex(3, -3, 1),
        //   new Vertex(3, 3, 1),
        //   new Vertex(-3, 3, 1)
        //}, 1 ) );

        // p.Add ( new Contour ( new Vertex [ 4 ]
        //{
        // new Vertex(-2.9,-2.9, 1),
        // new Vertex(2.9, -2.9, 1),
        // new Vertex(2.9, 2.9, 1),
        // new Vertex(-2.9, 2.9, 1)
        //}, 1 ) );

        // Add the inner box contour with boundary marker 2.
        p.Add(new Contour(new Vertex [4]
        {
            new Vertex(1.0, 1.0, 2),
            new Vertex(2.0, 1.0, 2),
            new Vertex(2.0, 2.0, 2),
            new Vertex(1.0, 2.0, 2)
        }, 5)
              , new Point(1.5, 1.5)); // Make it a hole.

        //var polygon = FileProcessor.Read("Assets/Plugins/Data/box_with_a_hole.poly");

        var options = new ConstraintOptions()
        {
            ConformingDelaunay = true
        };
        var quality = new QualityOptions()
        {
            MinimumAngle = 25F, MaximumArea = 0.04F
        };

        var triMesh = (TriangleNet.Mesh)p.Triangulate(options, quality);

        var smoothing = new SimpleSmoother();

        smoothing.Smooth(triMesh);

        triMesh.Refine(quality, true);

        triMesh.Renumber( );

        //var bounds = new Rectangle(-1.0, -1.0, 2.0, 2.0);

        //var triMesh = GenericMesher.StructuredMesh(bounds, 20, 20);

        var vertices  = triMesh.Vertices.Select(v => new Vector3((float)v.x, (float)v.y, 0)).ToArray();
        var triangles = triMesh.Triangles.SelectMany(t => t.vertices.Select(v => v.id)).ToArray();//.Reverse()
        var normals   = triMesh.Vertices.Select(v => transform.forward).ToArray();

        var bounds = triMesh.bounds;
        var l      = bounds.Left;
        var b      = bounds.Bottom;
        var w      = bounds.Width;
        var h      = bounds.Height;
        var uvs    = triMesh.Vertices.Select(v => new Vector2(-(float)((v.x - l) / w), (float)((v.y - b) / h))).ToArray();

        var skinnedRenderer = GetComponent <SkinnedMeshRenderer>();
        var uniMesh         = new Mesh( );

        uniMesh.vertices  = vertices;
        uniMesh.triangles = triangles;
        uniMesh.uv        = uvs;
        uniMesh.normals   = normals;

        skinnedRenderer.sharedMesh = uniMesh;

        var cloth = GetComponent <Cloth>();

        if (!cloth)
        {
            cloth = gameObject.AddComponent <Cloth> ( );
        }

        var coes = new List <ClothSkinningCoefficient>();

        foreach (var v in vertices)
        {
            coes.Add(new ClothSkinningCoefficient( )
            {
                maxDistance = 10, collisionSphereDistance = 0.1F
            });
        }

        cloth.coefficients = coes.ToArray( );

        ClothSphereColliderPair pair = new ClothSphereColliderPair(sphereFirst, null);

        cloth.sphereColliders = new ClothSphereColliderPair [] { pair };

        //cloth.externalAcceleration = new Vector3 ( 0, -10, 0 );

        cloth.stretchingStiffness = 0.9F;
        cloth.bendingStiffness    = 0.1F;

        cloth.collisionMassScale = 0.1F;
        cloth.friction           = 1F;

        cloth.SetEnabledFading(true);
        cloth.sleepThreshold = 0.1F;

        cloth.damping = 0.2F;
    }
    // Use this for initialization
    void Start()
    {
        var p = new Polygon();

        //Add the outer box contour with boundary marker 1.
        p.Add(new Contour(new Vertex [4]
        {
            new Vertex(-3, -3, 1),
            new Vertex(3, -3, 1),
            new Vertex(3, 3, 1),
            new Vertex(-3, 3, 1)
        }, 1));

        var options = new ConstraintOptions()
        {
            ConformingDelaunay = true
        };
        var quality = new QualityOptions()
        {
            MinimumAngle = 25F, MaximumArea = 0.04F
        };

        var triMesh = (TriangleNet.Mesh)p.Triangulate(options, quality);

        var smoothing = new SimpleSmoother();

        smoothing.Smooth(triMesh);

        triMesh.Refine(quality, true);

        triMesh.Renumber( );

        var vertices  = triMesh.Vertices.Select(v => new Vector3((float)v.x, (float)v.y, 0)).ToArray();
        var triangles = triMesh.Triangles.SelectMany(t => t.vertices.Select(v => v.id)).ToArray();//.Reverse()
        var normals   = triMesh.Vertices.Select(v => transform.forward).ToArray();

        var bounds = triMesh.bounds;
        var l      = bounds.Left;
        var b      = bounds.Bottom;
        var w      = bounds.Width;
        var h      = bounds.Height;
        var uvs    = triMesh.Vertices.Select(v => new Vector2(-(float)((v.x - l) / w), (float)((v.y - b) / h))).ToArray();

        //SkinnedMeshRenderer
        var skinnedRenderer = GetComponent <SkinnedMeshRenderer>();
        var uniMesh         = new Mesh( );

        uniMesh.vertices  = vertices;
        uniMesh.triangles = triangles;
        uniMesh.uv        = uvs;
        uniMesh.normals   = normals;


        //Bones

        int boneIndex0 = 0;
        var bindposes  = new List <Matrix4x4>();
        var bones      = new List <Transform>();

        var fBoneWeights = new List <BoneWeight>();

        Root = new GameObject( );
        Root.transform.parent        = transform;
        Root.transform.localRotation = Quaternion.identity;

        var handler = new GameObject();

        handler.name                    = "Handler";
        handler.transform.parent        = Root.transform;
        handler.transform.localRotation = Quaternion.identity;


        foreach (var vertex in triMesh.Vertices)                        //.Where(v=>v.y > 2.9F) )
        {
            var obj = GameObject.CreatePrimitive(PrimitiveType.Sphere); //new GameObject();

            obj.transform.localScale = Vector3.one * 0.1F;
            var renderer = obj.GetComponent <MeshRenderer> ( );
            if (renderer)
            {
                renderer.enabled = false;
            }
            var worldPosition = transform.TransformPoint(new Vector3(( float )vertex.x, ( float )vertex.y, 0));
            obj.transform.position = worldPosition;
            if (vertex.y > 2.9F)
            {
                obj.name             = "HERE";
                obj.transform.parent = handler.transform;
            }
            else
            {
                obj.transform.parent = Root.transform;
            }

            bones.Add(obj.transform);
            bindposes.Add(obj.transform.worldToLocalMatrix * transform.localToWorldMatrix);

            var weight = new BoneWeight();

            weight.boneIndex0 = boneIndex0;
            weight.weight0    = 1.0F;
            fBoneWeights.Add(weight);

            boneIndex0++;
        }

        uniMesh.boneWeights = fBoneWeights.ToArray( );
        uniMesh.bindposes   = bindposes.ToArray( );

        skinnedRenderer.sharedMesh = uniMesh;
        skinnedRenderer.bones      = bones.ToArray( );
        skinnedRenderer.rootBone   = Root.transform;

        //Cloth

        var cloth = GetComponent <Cloth>();

        if (!cloth)
        {
            cloth = gameObject.AddComponent <Cloth> ( );
        }

        var coes = new List <ClothSkinningCoefficient>();

        foreach (var v in vertices)
        {
            if (v.y < 2.9F)
            {
                coes.Add(new ClothSkinningCoefficient( )
                {
                    maxDistance = 10, collisionSphereDistance = 0.1F
                });
            }
            else
            {
                coes.Add(new ClothSkinningCoefficient( )
                {
                    maxDistance = 0, collisionSphereDistance = 0.1F
                });
            }
        }

        cloth.coefficients = coes.ToArray( );

        ClothSphereColliderPair pair = new ClothSphereColliderPair(sphereFirst, null);

        cloth.sphereColliders = new ClothSphereColliderPair [] { pair };

        //cloth.externalAcceleration = new Vector3 ( 0, -10, 0 );

        cloth.stretchingStiffness = 0.9F;
        cloth.bendingStiffness    = 0.1F;

        cloth.collisionMassScale = 0.1F;
        cloth.friction           = 1F;

        cloth.SetEnabledFading(true);
        cloth.sleepThreshold = 0.1F;

        cloth.damping = 0.2F;
    }