protected void DebugParticleData() { BoidsData[] particleArr = new BoidsData[PARTICLE_COUNT]; particleBuffer.GetData(particleArr); for (int i = 0; i < 15; i++) { int index = Random.Range(0, particleArr.Length); Vector3 position = particleArr[i].position; Vector3 direction = particleArr[i].velocity; float size = particleArr[i].size; Debug.Log($"Agent #{index}: Position {position}, Vel {direction}"); } }
private void InitializeBoidsDataBuffer() { var boidsData = new BoidsData[m_instanceCount]; for (int i = 0; i < m_instanceCount; ++i) { boidsData[i].position = Random.insideUnitSphere * m_boundaryRange; var velocity = new Vector3(Random.Range(-1f, 1f), Random.Range(-1f, 1f), Random.Range(-1f, 1f)); boidsData[i].velocity = velocity.normalized * m_minVelocity; } m_boidsDataBuffer = new ComputeBuffer(m_instanceCount, Marshal.SizeOf(typeof(BoidsData))); m_boidsDataBuffer.SetData(boidsData); }
protected void InitializeParticles() { //initialize the buffer particleBuffer = new ComputeBuffer(PARTICLE_COUNT, Marshal.SizeOf(typeof(BoidsData))); //temp array to initialize particles BoidsData[] arr = new BoidsData[PARTICLE_COUNT]; //fill that array with particle for (int i = 0; i < arr.Length; i++) { arr[i] = CreateParticle(); } //put that array into a compute buffer particleBuffer.SetData(arr); }
protected BoidsData CreateParticle() { BoidsData p = new BoidsData(); //random inside the bounds p.position = (Random.insideUnitSphere); // p.position = (Random.insideUnitSphere * 2 - Vector3.one); // p.position.x *= bounds.x/2; // p.position.y *= bounds.y/2; // p.position.z *= bounds.z/2; // p.position += this.transform.position; //add gameobject position //random direction p.velocity = Random.insideUnitSphere * 2 - Vector3.one; //random size p.size = Random.value; return(p); }