Esempio n. 1
0
        protected void GenerateFlowFieldBuffer()
        {
            flowFieldBuffer = new ComputeBuffer(FLOWFIELD_POINTS_NUM, Marshal.SizeOf(typeof(FlowFieldPointData)));
            var flowPoints = new FlowFieldPointData[FLOWFIELD_POINTS_NUM];

            int iterations = 0;

            for (int x = 0; x < xPointCount; x++)
            {
                for (int y = 0; y < yPointCount; y++)
                {
                    for (int z = 0; z < zPointCount; z++)
                    {
                        var index = (x * yPointCount + y) * zPointCount + z;

                        Vector3 position = new Vector3(
                            simulationSpace.x / xPointCount * x + flowfieldCellSize / 2,
                            simulationSpace.y / yPointCount * y + flowfieldCellSize / 2,
                            simulationSpace.z / zPointCount * z + flowfieldCellSize / 2
                            );
                        position += this.transform.position - simulationSpace / 2;

                        flowPoints[index] = CreateFlowFieldPoint(position);
                        iterations++;
                    }
                }
            }

            // Debug.Log(iterations);

            flowFieldBuffer.SetData(flowPoints);
        }
Esempio n. 2
0
        protected FlowFieldPointData CreateFlowFieldPoint(Vector3 position)
        {
            FlowFieldPointData point = new FlowFieldPointData();

            point.position  = position;
            point.direction = Random.insideUnitSphere;
            point.intensity = Random.value;

            return(point);
        }