public Constraint(Point p1, Point p2, ClothScript clothData)
 {
     this.p1        = p1;
     this.p2        = p2;
     this.length    = clothData.spacing;
     this.clothData = clothData;
 }
Пример #2
0
 public Constraint(Point p1, Point p2, ClothScript clothScript)
 {
     this.p1          = p1;
     this.p2          = p2;
     length           = clothScript.spacing;
     this.clothScript = clothScript;
 }
Пример #3
0
    public void UpdatePortrait()
    {
        characterScript = GetComponent <CharacterScript>();
        stats           = GetComponent <Stats>();
        headScript      = HeadGear.GetComponent <ClothScript>();
        clothScript     = Cloth.GetComponent <ClothScript>();

        headScript.GetHolder(characterScript, stats, characterScript.headId);
        clothScript.GetHolder(characterScript, stats, characterScript.clothId);
    }
Пример #4
0
    private void Start()
    {
        characterScript = GetComponent <CharacterScript>();
        stats           = GetComponent <Stats>();
        headScript      = HeadGear.GetComponent <ClothScript>();
        clothScript     = Cloth.GetComponent <ClothScript>();

        headScript.GetHolder(characterScript, stats, characterScript.headId);
        clothScript.GetHolder(characterScript, stats, characterScript.clothId);
    }
 public Point(float x, float y, ClothScript clothData)
 {
     this.x         = x;
     this.y         = y;
     this.px        = x;
     this.py        = y;
     vx             = 0;
     vy             = 0;
     pinAt          = null;
     this.clothData = clothData;
     constraints    = new List <Constraint>();
 }
Пример #6
0
 public Point(float x, float y, float z, ClothScript clothScript)
 {
     this.x           = pinX = x;
     this.y           = pinY = y;
     this.z           = pinZ = z;
     px               = x;
     py               = y;
     pz               = z;
     vx               = 0;
     vy               = 0;
     vz               = 0;
     this.clothScript = clothScript;
     constraints      = new List <Constraint>();
     hits             = new RaycastHit[1];
     colliders        = new Collider[1];
     isPinAt          = false;
 }
Пример #7
0
    public void ChangeCloth(ClothItemObject newCloth)
    {
        if (characterScript == null)
        {
            stats           = GetComponent <Stats>();
            characterScript = GetComponent <CharacterScript>();
            headScript      = HeadGear.GetComponent <ClothScript>();
            clothScript     = Cloth.GetComponent <ClothScript>();
        }

        switch (newCloth.clothType)
        {
        case ClothType.HeadGear:
            characterScript.headId = newCloth.name;
            headScript.ChangeCloth(newCloth);
            break;

        case ClothType.Cloth:
            characterScript.clothId = newCloth.name;
            clothScript.ChangeCloth(newCloth);
            break;
        }
    }
        public Cloth(ClothScript clothData)
        {
            this.clothData = clothData;
            this.points    = new List <Point>();

            var startX   = 0;
            var vertices = new List <Vector3>();
            var uvs      = new List <Vector2>();

            for (var y = 0; y <= clothData.clothY; y++)
            {
                for (var x = 0; x <= clothData.clothX; x++)
                {
                    var point = new Point(startX + x * clothData.spacing, -y * clothData.spacing, clothData);

                    if (y == 0)
                    {
                        point.pin(point.x, point.y);
                    }
                    if (x != 0)
                    {
                        point.attach(this.points[this.points.Count - 1]);
                    }
                    if (y != 0)
                    {
                        point.attach(this.points[x + (y - 1) * (clothData.clothX + 1)]);
                    }

                    this.points.Add(point);
                    vertices.Add(Vector3.zero);

                    var uv = new Vector2(x * 1f / clothData.clothX, y * 1f / clothData.clothY);
                    uvs.Add(uv);
                }
            }

            var cellCount = clothData.clothX * clothData.clothY;
            var indices   = new int[cellCount * 2 * 3];

            for (var y = 0; y < clothData.clothY; y++)
            {
                for (var x = 0; x < clothData.clothX; x++)
                {
                    var cellInx = y * clothData.clothX + x;
                    indices[cellInx * 6 + 0] = x + y * (clothData.clothX + 1);
                    indices[cellInx * 6 + 1] = x + 1 + y * (clothData.clothX + 1);
                    indices[cellInx * 6 + 2] = x + (y + 1) * (clothData.clothX + 1);

                    indices[cellInx * 6 + 3] = x + 1 + y * (clothData.clothX + 1);
                    indices[cellInx * 6 + 4] = x + 1 + (y + 1) * (clothData.clothX + 1);
                    indices[cellInx * 6 + 5] = x + (y + 1) * (clothData.clothX + 1);
                }
            }

            if (clothData.mesh)
            {
                clothData.mesh.vertices = vertices.ToArray();
                clothData.mesh.uv       = uvs.ToArray();
                clothData.mesh.SetIndices(indices, MeshTopology.Triangles, 0);
                clothData.mesh.RecalculateBounds();
            }
        }
Пример #9
0
        public Cloth(ClothScript clothScript)
        {
            this.clothScript = clothScript;
            points           = new List <Point>();

            var startX  = 0;
            var vectors = new List <Vector3>();
            var uvs     = new List <Vector2>();

            for (var y = 0; y <= clothScript.clothY; y++)
            {
                for (var x = 0; x <= clothScript.clothX; x++)
                {
                    var v = new Vector3(startX + x * clothScript.spacing, -y * clothScript.spacing, 0);

                    Point point = null;

                    if (y == 0)
                    {
                        point = new Point(v.x, v.y, v.z, clothScript);
                        point.Pin();
                    }
                    else
                    {
                        v = clothScript.transform.TransformPoint(v);

                        point = new Point(v.x, v.y, v.z, clothScript);
                    }

                    if (x != 0)
                    {
                        point.Attach(points[points.Count - 1]);
                    }
                    if (y != 0)
                    {
                        point.Attach(points[x + (y - 1) * (clothScript.clothX + 1)]);
                    }

                    points.Add(point);
                    vectors.Add(v);

                    var uv = new Vector2(x * 1f / clothScript.clothX, y * 1f / clothScript.clothY);
                    uvs.Add(uv);
                }
            }

            var cellCount = clothScript.clothX * clothScript.clothY;
            var indices   = new int[cellCount * 2 * 3];

            for (var y = 0; y < clothScript.clothY; y++)
            {
                for (var x = 0; x < clothScript.clothX; x++)
                {
                    var cellInx = y * clothScript.clothX + x;
                    indices[cellInx * 6 + 0] = x + y * (clothScript.clothX + 1);
                    indices[cellInx * 6 + 1] = x + 1 + y * (clothScript.clothX + 1);
                    indices[cellInx * 6 + 2] = x + (y + 1) * (clothScript.clothX + 1);

                    indices[cellInx * 6 + 3] = x + 1 + y * (clothScript.clothX + 1);
                    indices[cellInx * 6 + 4] = x + 1 + (y + 1) * (clothScript.clothX + 1);
                    indices[cellInx * 6 + 5] = x + (y + 1) * (clothScript.clothX + 1);
                }
            }

            if (clothScript.mesh)
            {
                clothScript.mesh.vertices = vectors.ToArray();
                clothScript.mesh.uv       = uvs.ToArray();
                clothScript.mesh.SetIndices(indices, MeshTopology.Triangles, 0);
                clothScript.mesh.RecalculateNormals();
                clothScript.mesh.RecalculateBounds();
            }
        }