Beispiel #1
0
 public void Copy(CSpring spring)
 {
     length    = spring.length;
     stiffness = spring.stiffness;
     friction  = spring.friction;
 }
Beispiel #2
0
    public void initialize(int n, int m)
    {
        //float newX = -4.0f;
        //float newY = 4.0f;
        //float newZ = 0.0f;

        float newX = 0.0f;
        float newY = 0.0f;
        float newZ = 0.0f;

        // Node position set up: n by m
        for (int i = 0; i < n; i++)
        {
            for (int j = 0; j < m; j++)
            {
                CNode node = new CNode();
                node.mPosition.x = newX;
                node.mPosition.y = newY;
                node.mPosition.z = newZ;
                mNodeArray.Add(node);
                //Debug.Log("Node["+i+"],["+j+"] :"+node.mPosition);
                newX += IntervalX;
            }
            newZ -= IntervalY;
            newX  = 0f;
        }

        for (int i = 0; i < mNodeArray.Count; i++)
        {
            //mNodeArray.at(i).mMass = (float)totalMass / mNodeArray.size();
            mNodeArray[i].mMass = (float)totalMass / mNodeArray.Count;
        }


        //constrain node
        //mNodeArray[0].SimulationFlag = false;
        //mNodeArray[m-1].SimulationFlag = false;

        Debug.Log("#" + clothID + "Cloth Node Initialization Success... " + mNodeArray.Count + " Node");

        //int Spring_index = 0;
        int index = 0;

        // Structural Spring Connection: horizontal
        for (int i = 0; i < m; i++)
        {
            for (int j = 0; j < (n - 1); j++)
            {
                if (i > 0 && j == 0)
                {
                    index++;
                }
                CSpring spring = new CSpring();
                spring.Kd   = mStrKD;
                spring.Ks   = mStrKS;
                spring.type = 0;
                spring.init(mNodeArray[index], mNodeArray[index + 1]);
                index++;
                mSpringArray.Add(spring);
            }
        }
        //Debug.Log("Horizontal Spring count :" + mSpringArray.Count);
        // Structural Spring Connection: vertical
        for (int i = 0; i < (m - 1); i++)
        {
            for (int j = 0; j < n; j++)
            {
                ++index;
                CSpring spring = new CSpring();
                spring.Kd   = mStrKD;
                spring.Ks   = mStrKS;
                spring.type = 0;
                spring.init(mNodeArray[(n) * i + j], mNodeArray[(n) * i + j + n]);
                mSpringArray.Add(spring);
            }
        }
        //Structural_Spring_Count = mSpringArray.Count;
        //shear Spring Connection: Left right
        int pointindex = 0;

        for (int i = 0; i < (n) * (m - 1); i++)
        {
            if (i % n == (n - 1))
            {
                pointindex++;
                continue;
            }

            CSpring spring = new CSpring();
            spring.Kd   = mShearKD;
            spring.Ks   = mShearKS;
            spring.type = 1;
            spring.init(mNodeArray[pointindex], mNodeArray[pointindex + n + 1]);
            mSpringArray.Add(spring);
            pointindex++;
        }
        //shear Spring Connection:  Top right bottom
        pointindex = 0;
        for (int i = 0; i < (n) * (m - 1); i++)
        {
            if (i % n == (0))
            {
                pointindex++;
                continue;
            }

            CSpring spring = new CSpring();
            spring.Kd   = mShearKD;
            spring.Ks   = mShearKS;
            spring.type = 1;
            spring.init(mNodeArray[pointindex], mNodeArray[pointindex + n - 1]);
            mSpringArray.Add(spring);
            pointindex++;
        }

        // Bend Spring Connection: horizontal
        pointindex = 0;
        for (int i = 0; i < (n) * m; i++)
        {
            if (i % n > n - 3)
            {
                pointindex++;
                continue;
            }

            CSpring spring = new CSpring();
            spring.Kd   = mBendKD;
            spring.Ks   = mBendKS;
            spring.type = 2;
            spring.init(mNodeArray[pointindex], mNodeArray[pointindex + 2]);
            mSpringArray.Add(spring);
            pointindex++;
        }

        // Bend Spring Connection: vertical
        pointindex = 0;
        for (int i = 0; i < (n) * (m - 2); i++)
        {
            if (i % n > n - 3)
            {
                pointindex++;
                continue;
            }

            CSpring spring = new CSpring();
            spring.Kd   = mBendKD;
            spring.Ks   = mBendKS;
            spring.type = 2;
            spring.init(mNodeArray[pointindex], mNodeArray[pointindex + 2 * m]);
            mSpringArray.Add(spring);
            pointindex++;
        }

        Debug.Log("#" + clothID + "Cloth Spring Initialization Success...");
        //Debug.Log("Spring Count : " + mSpringArray.Count);


        //int Face_count = 0;
        //// Face List Setup
        //for (int i = 0; i < m -1; ++i)
        //{
        //	for (int j = 0; j < n-1 ; ++j)
        //	{
        //		int v1 = (i * n) + j;
        //		int v2 = (i * n) + j + 1;
        //		int v3 = (i * n) + n + j;
        //		int v4 = (i * n) + n + j + 1;

        //		mFaceList.Add(new Vector3(v1, v3, v2));
        //		mNodeArray[v1].faceCount++;
        //		mNodeArray[v2].faceCount++;
        //		mNodeArray[v3].faceCount++;
        //		mFaceList.Add(new Vector3(v2, v3, v4));
        //		mNodeArray[v2].faceCount++;
        //		mNodeArray[v3].faceCount++;
        //		mNodeArray[v4].faceCount++;
        //		Face_count++;
        //	}
        // Face List Setup
        triangles = new int[m * n * 6];
        for (int ti = 0, vi = 0, y = 0; y < m; y++, vi++)
        {
            for (int x = 0; x < n; x++, ti += 6, vi++)
            {
                triangles[ti]     = vi;
                triangles[ti + 3] = triangles[ti + 2] = vi + 1;
                triangles[ti + 4] = triangles[ti + 1] = vi + n + 1;
                triangles[ti + 5] = vi + n + 2;
            }
        }
        //Debug.Log(triangles[1535]);
        //for (int i = 0; i < triangles.Length; i++)
        //{
        //	Debug.Log("Triangle vertice :" + triangles[i]);
        //}
    }