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.CreateRigidFromMesh(ref vertices[0], vertices.Length, ref indices[0], indices.Length, m_particleSpacing, m_meshExpansion); if (assetHandle) { FlexExt.Asset asset = assetHandle.asset; FlexExt.Asset particlesOnly = new FlexExt.Asset(); particlesOnly.numParticles = asset.numParticles; particlesOnly.maxParticles = asset.numParticles; particlesOnly.particles = asset.particles; StoreAsset(particlesOnly); FlexExt.DestroyAsset(assetHandle); } } } } }
public void TestCreateRigidFromMesh() { 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 radius = 0.1f; float expand = 0.0f; FlexExt.Asset.Handle handle = FlexExt.CreateRigidFromMesh(ref vertices[0], vertices.Length, ref indices[0], indices.Length, radius, expand); FlexExt.Asset asset = handle.asset; Assert.AreEqual(2680, asset.numParticles); Assert.AreEqual(1, asset.numShapes); FlexExt.DestroyAsset(handle); }