Exemple #1
0
        private void ProcessInflatables(bool sizeChanged)
        {
            if (sizeChanged)
            {
                m_inflatableStarts    = new int[m_inflatablesCount];
                m_inflatableCounts    = new int[m_inflatablesCount];
                m_inflatableVolumes   = new float[m_inflatablesCount];
                m_inflatablePressures = new float[m_inflatablesCount];
                m_inflatableStiffness = new float[m_inflatablesCount];
            }

            int inflatableId = 0;

            for (int iId = 0; iId < m_flexGameObjects.Count && iId < m_activeInstacesCount; iId++)
            {
                FlexTriangles  triangles  = m_flexGameObjects[iId].GetComponent <FlexTriangles>();
                FlexInflatable inflatable = m_flexGameObjects[iId].GetComponent <FlexInflatable>();

                if (inflatable && inflatable.enabled)
                {
                    m_inflatableStarts[inflatableId]    = triangles.m_trianglesIndex;
                    m_inflatableCounts[inflatableId]    = triangles.m_trianglesCount;
                    m_inflatableVolumes[inflatableId]   = inflatable.m_restVolume;
                    m_inflatablePressures[inflatableId] = inflatable.m_pressure;
                    m_inflatableStiffness[inflatableId] = inflatable.m_stiffness;
                    inflatableId++;
                }
            }
        }
Exemple #2
0
        private void ProcessTriangles(bool sizeChanged)
        {
            if (sizeChanged)
            {
                m_triangleIndices = new int[m_trianglesCount * 3];
                m_triangleNormals = new Vector3[m_trianglesCount];
            }

            for (int iId = 0; iId < m_flexGameObjects.Count && iId < m_activeInstacesCount; iId++)
            {
                FlexParticles particles = m_flexGameObjects[iId].GetComponent <FlexParticles>();
                FlexTriangles triangles = m_flexGameObjects[iId].GetComponent <FlexTriangles>();

                if (triangles && triangles.enabled)
                {
                    for (int tId = 0; tId < triangles.m_trianglesCount; tId++)
                    {
                        m_triangleIndices[tId * 3 + 0 + triangles.m_trianglesIndex * 3] = triangles.m_triangleIndices[tId * 3 + 0] + particles.m_particlesIndex;
                        m_triangleIndices[tId * 3 + 1 + triangles.m_trianglesIndex * 3] = triangles.m_triangleIndices[tId * 3 + 1] + particles.m_particlesIndex;
                        m_triangleIndices[tId * 3 + 2 + triangles.m_trianglesIndex * 3] = triangles.m_triangleIndices[tId * 3 + 2] + particles.m_particlesIndex;
                    }
                }
            }
        }
Exemple #3
0
        void Start()
        {
            m_flexParticles  = GetComponent <FlexParticles>();
            m_flexSprings    = GetComponent <FlexSprings>();
            m_flexTriangles  = GetComponent <FlexTriangles>();
            m_flexInflatable = GetComponent <FlexInflatable>();

            m_mesh = GetComponent <MeshFilter>().mesh;

            m_vertices  = m_mesh.vertices;
            m_triangles = m_mesh.triangles;
            m_uvs       = m_mesh.uv;
            m_origUvs   = m_mesh.uv;

            //if(m_uvs.Length == 0)
            //{
            //    m_uvs = new Vector2[m_vertices.Length];
            //    m_origUvs = new Vector2[m_vertices.Length];
            //}

            //texture seams (duplicate vertices) are currently not supported during tearing
            if (m_mesh.vertexCount != m_flexParticles.m_particlesCount)
            {
                Debug.LogWarning("Closed mesh with texture seams detected. This is currently not supported by uFlex v0.5. You may still tear closed meshes but plase remove any textures from object's material as UV mapping will be removed");


                m_mesh = new Mesh();

                m_vertices = new Vector3[m_flexParticles.m_particlesCount];
                //  m_uvs = new Vector2[m_flexParticles.m_particlesCount];
                m_uvs = new Vector2[0];

                for (int i = 0; i < m_flexParticles.m_particlesCount; i++)
                {
                    m_vertices[i] = transform.InverseTransformPoint(m_flexParticles.m_particles[i].pos);
                    //  m_uvs[i] = m_origUvs[mappingsRev[i]];
                }


                m_mesh.vertices = m_vertices;
                //  m_mesh.uv = m_uvs;
                m_mesh.triangles = m_flexTriangles.m_triangleIndices;

                m_mesh.RecalculateNormals();
                m_mesh.RecalculateBounds();

                GetComponent <MeshFilter>().mesh = m_mesh;
            }


            this.mappings    = new int[m_mesh.vertexCount * 2];
            this.mappingsRev = new int[m_mesh.vertexCount * 2];
            for (int i = 0; i < m_mesh.vertexCount; i++)
            {
                Vector3 v            = m_vertices[i];
                bool    mappingFound = false;

                float minDistance = 100000.0f;
                int   minId       = 0;

                for (int j = 0; j < m_flexParticles.m_particlesCount; j++)
                {
                    // float dist = Vector3.Distance(v, transform.InverseTransformPoint(m_flexBody.m_particles[j]));
                    float dist = Vector3.Distance(v, m_flexParticles.m_particles[j].pos);
                    if (dist < minDistance)
                    {
                        minDistance = dist;
                        minId       = j;
                    }
                }

                if (minDistance < this.m_maxSearchDistance)
                {
                    this.mappings[i]        = minId;
                    this.mappingsRev[minId] = i;
                    mappingFound            = true;
                }

                if (!mappingFound)
                {
                    Debug.Log("MappingMissing: " + i);
                }
            }



            //int vertexCount = m_mesh.vertexCount;

            //int[] triangles = m_mesh.triangles;
            //int triIndicesCount = triangles.Length;
            //int trianglesCount = triIndicesCount / 3;

            //int[] uniqueVerticesIds = new int[vertexCount];
            //int[] origToUniqueVertMapping = new int[vertexCount];
            //int uniqueVerticesCount = FlexExt.flexExtCreateWeldedMeshIndices(m_vertices, vertexCount, uniqueVerticesIds, origToUniqueVertMapping, 0.00001f);

            //Debug.Log("Welding Mesh: " + uniqueVerticesCount + "/" + vertexCount);

            //Vector4[] uniqueVertices4 = new Vector4[uniqueVerticesCount];
            //for (int i = 0; i < uniqueVerticesCount; i++)
            //{
            //    uniqueVertices4[i] = m_vertices[uniqueVerticesIds[i]];
            //}

            //int[] uniqueTriangles = new int[trianglesCount * 3];
            //for (int i = 0; i < trianglesCount * 3; i++)
            //{
            //    uniqueTriangles[i] = origToUniqueVertMapping[triangles[i]];
            //}


            //m_clothMeshPtr = uFlexAPI.uFlexCreateTearableClothMesh(uniqueVertices4, uniqueVerticesCount, uniqueVerticesCount * 2, uniqueTriangles, trianglesCount, m_stretchKs, m_bendKs, 0);

            m_clothMeshPtr = uFlexAPI.uFlexCreateTearableClothMesh(m_flexParticles.m_particles, m_flexParticles.m_particlesCount, m_flexParticles.m_particlesCount * 2, m_flexTriangles.m_triangleIndices, m_flexTriangles.m_trianglesCount, m_stretchKs, m_bendKs, 0.0f);
        }
Exemple #4
0
        private void UpdateCounts()
        {
            m_particlesCount      = 0;
            m_springsCount        = 0;
            m_shapesCount         = 0;
            m_shapeIndicesCount   = 0;
            m_trianglesCount      = 0;
            m_inflatablesCount    = 0;
            m_activeInstacesCount = 0;

            for (int iId = 0; iId < m_flexGameObjects.Count; iId++)
            {
                m_flexGameObjects[iId].m_instanceId = iId;

                FlexParticles     particles  = m_flexGameObjects[iId].GetComponent <FlexParticles>();
                FlexTriangles     triangles  = m_flexGameObjects[iId].GetComponent <FlexTriangles>();
                FlexSprings       springs    = m_flexGameObjects[iId].GetComponent <FlexSprings>();
                FlexShapeMatching shapes     = m_flexGameObjects[iId].GetComponent <FlexShapeMatching>();
                FlexInflatable    inflatable = m_flexGameObjects[iId].GetComponent <FlexInflatable>();

                if (particles && particles.enabled)
                {
                    if (m_particlesCount + particles.m_particlesCount <= m_maxParticlesCount)
                    {
                        particles.m_particlesIndex = m_particlesCount;
                        m_particlesCount          += particles.m_particlesCount;

                        m_activeInstacesCount++;
                    }
                    else
                    {
                        Debug.Log("Current particles count exceeded their maximum number for this container");
                    }
                }

                if (springs && springs.enabled)
                {
                    springs.m_springsIndex = m_springsCount;
                    m_springsCount        += springs.m_springsCount;
                }

                if (shapes && shapes.enabled)
                {
                    shapes.m_shapesIndex        = m_shapesCount;
                    shapes.m_shapesIndicesIndex = m_shapeIndicesCount;

                    m_shapesCount       += shapes.m_shapesCount;
                    m_shapeIndicesCount += shapes.m_shapeIndicesCount;
                }

                if (triangles && triangles.enabled)
                {
                    triangles.m_trianglesIndex = m_trianglesCount;
                    m_trianglesCount          += triangles.m_trianglesCount;
                }

                if (inflatable && inflatable.enabled)
                {
                    inflatable.m_inflatableIndex = m_inflatablesCount;
                    m_inflatablesCount++;
                }
            }
        }