public void Explode() { Mesh mesh = new Mesh(); //GetComponent<MeshFilter>().mesh = mesh; // 頂点の指定 var vertices = new Vector2[] { new Vector2(0, 3), new Vector2(0, 2), new Vector2(0, 1), new Vector2(0, 0), new Vector2(3, 3), new Vector2(3, 2), new Vector2(3, 1), new Vector2(3, 0), new Vector2(2, 3), new Vector2(2, 2), new Vector2(2, 1), new Vector2(2, 0), new Vector2(1, 3), new Vector2(1, 2), new Vector2(1, 1), new Vector2(1, 0), }; // メッシュをすべて分割 var triangleMeshes = SubdivisionMesh(tr.CreateInfluencePolygon(vertices)); // メッシュからGameObjectを生成 var objs = CreateShatteredGameObject(triangleMeshes); this.gameObject.GetComponent <MeshRenderer>().enabled = false; foreach (var obj in objs) { var rigid = obj.GetComponent <Rigidbody>(); var powerx = Random.Range(-100f, 100f); var powery = Random.Range(0f, 100f); var powerz = Random.Range(-100f, 100f); rigid.AddForce(new Vector3(powerx, powery, powerz)); } //mesh.RecalculateNormals(); //mesh.RecalculateBounds(); //var filter = s.GetComponent<MeshFilter>(); //filter.sharedMesh = mesh; }
void Update() { ParticleSystem.Particle[] particles = new ParticleSystem.Particle[particleSystem.particleCount]; particleSystem.GetParticles(particles); Vector2[] particlePoss = new Vector2[particles.Length]; for (int i = 0; i < particles.Length; i++) { particlePoss[i].x = particles[i].position.x; particlePoss[i].y = particles[i].position.z; } if (particles.Length > 3) { tr = new Triangulator(); meshFilter.mesh = tr.CreateInfluencePolygon(particlePoss); } }
void Start() { particles = new ParticleSystem.Particle[num]; particlePoss = new Vector2[num]; meshFilter = GetComponentInChildren <MeshFilter>() as MeshFilter; for (int i = 0; i < num; i++) { particles[i].position = radius * Random.insideUnitCircle; particlePoss[i] = particles[i].position; particles[i].color = Color.white; particles[i].size = particlesize; } Triangulator tr = new Triangulator(); meshFilter.mesh = tr.CreateInfluencePolygon(particlePoss); }