Exemplo n.º 1
0
        SoftBody CreateFromIndexedMesh(Vector3Array vertexArray, IntArray triangleVertexIndexArray, bool createBendLinks)
        {
            SoftBody softBody = new SoftBody(SoftWorld.WorldInfo, vertexArray, null);
            Material structuralMaterial = softBody.AppendMaterial();
            Material bendMaterial;
            if (createBendLinks)
            {
                bendMaterial = softBody.AppendMaterial();
                bendMaterial.Lst = 0.7f;
            }
            else
            {
                bendMaterial = null;
            }
            structuralMaterial.Lst = 1.0f;

            int numVertices = vertexArray.Count;
            int numTriangles = triangleVertexIndexArray.Count / 3;

            // List of values for each link saying which triangle is associated with that link
            // -1 to start. Once a value is entered we know the "other" triangle
            // and can add a link across the link
            AlignedIntArray triangleForLinks = new AlignedIntArray();
            triangleForLinks.Resize(numVertices * numVertices, -1);

            for (int triangle = 0; triangle < numTriangles; ++triangle)
            {
                int[] index = new int[] { triangleVertexIndexArray[triangle * 3], triangleVertexIndexArray[triangle * 3 + 1], triangleVertexIndexArray[triangle * 3 + 2] };
                softBody.AppendFace(index[0], index[1], index[2]);

                // Generate the structural links directly from the triangles
                TestAndAddLink(triangleForLinks, softBody, triangle, triangleVertexIndexArray, numVertices, index[0], index[1], index[2], structuralMaterial, createBendLinks, bendMaterial);
                TestAndAddLink(triangleForLinks, softBody, triangle, triangleVertexIndexArray, numVertices, index[1], index[2], index[0], structuralMaterial, createBendLinks, bendMaterial);
                TestAndAddLink(triangleForLinks, softBody, triangle, triangleVertexIndexArray, numVertices, index[2], index[0], index[1], structuralMaterial, createBendLinks, bendMaterial);
            }

            return softBody;
        }