void Start() { _drawArgsBuffer = new ComputeBuffer( 1, 5 * sizeof(uint), ComputeBufferType.IndirectArguments ); _drawArgsBuffer.SetData(new uint[5] { BoidMesh.GetIndexCount(0), (uint)BoidsCount, 0, 0, 0 }); this.boidsData = new GPUBoid_Skinned_Affector[this.BoidsCount]; this.kernelHandle = _ComputeFlock.FindKernel("CSMain"); for (int i = 0; i < this.BoidsCount; i++) { this.boidsData[i] = this.CreateBoidData(); } BoidBuffer = new ComputeBuffer(BoidsCount, 48); BoidBuffer.SetData(this.boidsData); AffectorBuffer = new ComputeBuffer(NbAffectorsPerRay, 20); GenerateSkinnedAnimationForGPUBuffer(); var dataToPaths = new PointsFromData(); dataToPaths.GeneratePointsFrom(DrawingAffectors, DrawingAffectorsOffset, new Vector3(0, 90, 0), ReverseYAxisDrawingAffectors, ScaleDrawingAffectors); GenerateDrawingAffectors(dataToPaths.Points.ToArray(), 2, 2); }
void Start() { BoidMaterial = new Material(BoidMaterial); _drawArgsBuffer = new ComputeBuffer( 1, 5 * sizeof(uint), ComputeBufferType.IndirectArguments ); _drawArgsBuffer.SetData(new uint[5] { BoidMesh.GetIndexCount(0), (uint)BoidsCount, 0, 0, 0 }); this.boidsData = new GPUBoid[this.BoidsCount]; this.kernelHandle = _ComputeFlock.FindKernel("CSMain"); for (int i = 0; i < this.BoidsCount; i++) { this.boidsData[i] = this.CreateBoidData(); } BoidBuffer = new ComputeBuffer(BoidsCount, Marshal.SizeOf(typeof(GPUBoid))); BoidBuffer.SetData(this.boidsData); GenerateSkinnedAnimationForGPUBuffer(); if (UseAffectors) { if (UseMeshAffectors) { var bounds = MeshAffectors.bounds; var scaledVertices = MeshAffectors.vertices.Select(v => (v) * (ReverseYAxisDrawingAffectors ? -1 : 1) * ScaleDrawingAffectors + DrawingAffectorsOffset).ToArray(); GenerateDrawingAffectors(scaledVertices, 0, 0, 3); } else { var dataToPaths = new PointsFromData(); dataToPaths.GeneratePointsFrom(DrawingAffectors, DrawingAffectorsOffset, new Vector3(0, 90, 0), ReverseYAxisDrawingAffectors, ScaleDrawingAffectors); GenerateDrawingAffectors(dataToPaths.Points.ToArray()); } } else { AffectorBuffer = new ComputeBuffer(1, Marshal.SizeOf(typeof(GPUAffector))); } SetComputeData(); SetMaterialData(); if (DrawILoveUnity) { StartCoroutine(DrawILoveUnityForever()); } }
IEnumerator DrawILoveUnityForever() { var dataToPaths = new PointsFromData(); dataToPaths.GeneratePointsFrom(EyeDrawing, new Vector3(0, 2, -2), new Vector3(0, 90, 0), ReverseYAxisDrawingAffectors, 0.03f); var eyePoints = dataToPaths.Points.ToArray(); dataToPaths.GeneratePointsFrom(HeartDrawing, new Vector3(0, 2, -2), new Vector3(0, 90, 0), ReverseYAxisDrawingAffectors, 0.05f); var heartPoints = dataToPaths.Points.ToArray(); dataToPaths.GeneratePointsFrom(UnityDrawing, new Vector3(0, 0, -1), new Vector3(0, 90, 0), ReverseYAxisDrawingAffectors, 0.1f); var unityPoints = dataToPaths.Points.ToArray(); yield return(new WaitForSeconds(3f)); while (true) { GenerateDrawingAffectors(eyePoints, 0, 0, 0); yield return(new WaitForSeconds(3f)); GenerateDrawingAffectors(new Vector3[1], 0, 0, 0); yield return(new WaitForSeconds(0.5f)); GenerateDrawingAffectors(heartPoints, 0, 0, 0); yield return(new WaitForSeconds(3f)); GenerateDrawingAffectors(new Vector3[1], 0, 0, 0); yield return(new WaitForSeconds(0.5f)); GenerateDrawingAffectors(unityPoints, 2, 0, 0); yield return(new WaitForSeconds(4f)); GenerateDrawingAffectors(new Vector3[1], 0, 0, 0); yield return(new WaitForSeconds(2f)); } }