// Start is called before the first frame update
    void Start()
    {
        var objMesh = trans.GetComponent <MeshFilter>().mesh;

        for (int i = 0; i < objMesh.triangles.Length; i += 3)
        {
            myTriangle tempV = new myTriangle(objMesh.vertices[objMesh.triangles[i]], objMesh.vertices[objMesh.triangles[i + 1]], objMesh.vertices[objMesh.triangles[i + 2]], objMesh.normals[objMesh.triangles[i]]);
            triangleList.Add(tempV);
        }
    }
Example #2
0
    // Start is called before the first frame update
    void Start()
    {
        tSet.Clear();
        //mC=gameObject.GetComponent<MeshCollider>();
        mF            = gameObject.GetComponent <MeshFilter> ();
        originalMesh  = mF.mesh;
        trianglesList = mF.sharedMesh.triangles;
        normalList    = mF.sharedMesh.normals;
        softVerts     = mF.sharedMesh.vertices;
        foreach (Collider cld in GetComponents <Collider>())
        {
            Destroy(cld);
        }
        //mC = gameObject.AddComponent<MeshCollider> ();
        //mC.sharedMesh = originalMesh;
        //mC.convex = true;

        for (int i = 0; i < originalMesh.vertexCount; i++)
        {
            myParticle temp = new myParticle(originalMesh.vertices[i], Vector3.zero, Vector3.zero);
            particlesList.Add(temp);
        }
        F = new Vector3[particlesList.Count];
        for (int i = 0; i < originalMesh.triangles.Length; i += 3)
        {
            if (!particlesList[originalMesh.triangles[i]].linkParticle.ContainsKey(originalMesh.triangles[i + 1]))
            {
                particlesList[originalMesh.triangles[i]].linkParticle.Add(originalMesh.triangles[i + 1], (particlesList[originalMesh.triangles[i]].position - particlesList[originalMesh.triangles[i + 1]].position).magnitude);
            }
            if (!particlesList[originalMesh.triangles[i]].linkParticle.ContainsKey(originalMesh.triangles[i + 2]))
            {
                particlesList[originalMesh.triangles[i]].linkParticle.Add(originalMesh.triangles[i + 2], (particlesList[originalMesh.triangles[i]].position - particlesList[originalMesh.triangles[i + 2]].position).magnitude);
            }
            if (!particlesList[originalMesh.triangles[i + 1]].linkParticle.ContainsKey(originalMesh.triangles[i]))
            {
                particlesList[originalMesh.triangles[i + 1]].linkParticle.Add(originalMesh.triangles[i], (particlesList[originalMesh.triangles[i + 1]].position - particlesList[originalMesh.triangles[i]].position).magnitude);
            }
            if (!particlesList[originalMesh.triangles[i + 1]].linkParticle.ContainsKey(originalMesh.triangles[i + 2]))
            {
                particlesList[originalMesh.triangles[i + 1]].linkParticle.Add(originalMesh.triangles[i + 2], (particlesList[originalMesh.triangles[i + 1]].position - particlesList[originalMesh.triangles[i + 2]].position).magnitude);
            }
            if (!particlesList[originalMesh.triangles[i + 2]].linkParticle.ContainsKey(originalMesh.triangles[i]))
            {
                particlesList[originalMesh.triangles[i + 2]].linkParticle.Add(originalMesh.triangles[i], (particlesList[originalMesh.triangles[i]].position - particlesList[originalMesh.triangles[i + 2]].position).magnitude);
            }
            if (!particlesList[originalMesh.triangles[i + 2]].linkParticle.ContainsKey(originalMesh.triangles[i + 1]))
            {
                particlesList[originalMesh.triangles[i + 2]].linkParticle.Add(originalMesh.triangles[i + 1], (particlesList[originalMesh.triangles[i + 2]].position - particlesList[originalMesh.triangles[i + 1]].position).magnitude);
            }
            //Debug.Log(originalMesh.triangles[i]);
        }
        for (int i = 0; i < particlesList.Count; i++)
        {
            for (int n = i + 1; n < particlesList.Count; n++)
            {
                if (particlesList[i].position == particlesList[n].position)
                {
                    if (!particlesList[i].sameParticle.Contains(n))
                    {
                        particlesList[i].sameParticle.Add(n);
                    }
                    if (!particlesList[n].sameParticle.Contains(i))
                    {
                        particlesList[n].sameParticle.Add(i);
                    }
                }
            }
        }
        var objMesh = ColliderObj.GetComponent <MeshFilter>().mesh;

        for (int i = 0; i < objMesh.triangles.Length; i += 3)
        {
            myTriangle tempV = new myTriangle(objMesh.vertices[objMesh.triangles[i]], objMesh.vertices[objMesh.triangles[i + 1]], objMesh.vertices[objMesh.triangles[i + 2]], objMesh.normals[objMesh.triangles[i]]);
            triangleList.Add(tempV);
        }

        //ContainR=ColliderObj.localScale.x>ColliderObj.localScale.y?ColliderObj.localScale.x:ColliderObj.localScale.y;
        //ContainR=ContainR>ColliderObj.localScale.z?ContainR:ColliderObj.localScale.z;
    }