Exemplo n.º 1
0
        void BuildFromMesh()
        {
            if (m_boundaryMesh)
            {
                Vector3[] vertices = m_boundaryMesh.vertices;
                if (vertices != null && vertices.Length > 0)
                {
                    for (int i = 0; i < vertices.Length; ++i)
                    {
                        Vector3 v = vertices[i];
                        vertices[i] = new Vector3(v.x * m_meshLocalScale.x, v.y * m_meshLocalScale.y, v.z * m_meshLocalScale.z);
                    }
                    int[] indices = m_boundaryMesh.triangles;
                    if (indices != null && indices.Length > 0)
                    {
                        FlexExt.Asset.Handle assetHandle = FlexExt.CreateSoftFromMesh(ref vertices[0], vertices.Length, ref indices[0], indices.Length, m_particleSpacing, m_volumeSampling, m_surfaceSampling, m_clusterSpacing, m_clusterRadius, m_clusterStiffness, m_linkRadius, m_linkStiffness);
                        if (assetHandle)
                        {
                            StoreAsset(assetHandle.asset);

                            FlexExt.DestroyAsset(assetHandle);

                            foreach (var i in fixedParticles)
                            {
                                if (i < particles.Length)
                                {
                                    particles[i].w = 0.0f;
                                }
                            }

                            m_referenceShape = -1;
                            if (fixedParticles.Length == 0)
                            {
                                float   minDist2 = float.MaxValue;
                                Vector3 center   = m_boundaryMesh.bounds.center;
                                //Debug.Log(" center of asset bounds: " + center);
                                for (int i = 0; i < shapeCenters.Length; ++i)
                                {
                                    float dist2 = (shapeCenters[i] - center).sqrMagnitude;
                                    if (dist2 < minDist2)
                                    {
                                        minDist2         = dist2;
                                        m_referenceShape = i;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
    public void TestCreateSoftFromMesh()
    {
        Vector3[] vertices         = { new Vector3(1, 1, 1), new Vector3(-1, -1, 1), new Vector3(-1, 1, -1), new Vector3(1, -1, -1) };
        int[]     indices          = { 0, 1, 2, 0, 3, 1, 0, 2, 3, 1, 3, 2 };
        float     particleSpacing  = 0.1f;
        float     volumeSampling   = 0.1f;
        float     surfaceSampling  = 0.1f;
        float     clusterSpacing   = 0.1f;
        float     clusterRadius    = 0.3f;
        float     clusterStiffness = 0.5f;
        float     linkRadius       = 0.2f;
        float     linkStiffness    = 0.5f;

        FlexExt.Asset.Handle handle = FlexExt.CreateSoftFromMesh(ref vertices[0], vertices.Length, ref indices[0], indices.Length, particleSpacing, volumeSampling, surfaceSampling, clusterSpacing, clusterRadius, clusterStiffness, linkRadius, linkStiffness);
        FlexExt.Asset        asset  = handle.asset;

        Assert.AreEqual(668, asset.numParticles);
        Assert.AreEqual(502, asset.numShapes);
        Assert.AreEqual(3856, asset.numSprings);

        FlexExt.DestroyAsset(handle);
    }