void Start()
        {
            Positions = new PositionService(compute, capacity);
            Velocities = new VelocityService(compute, capacity);
            Lifes = new LifeService(compute, capacity);
            Constants = new ConstantService(constants);
            VelSimulation = new VelocitySimulation(compute, Velocities);
            PosSimulation = new PositionSimulation(compute, Velocities, Positions);
            Broadphase = new BroadPhase(compute, computeSort, Lifes, Positions);
            ParticleSolver = new ParticleCollisionSolver(compute, Velocities, Positions, Lifes, Broadphase);
            BoundsChecker = new BoundsChecker(compute, Lifes, Positions);
            Walls = BuildWalls(wallColliders);
            WallSolver = new WallCollisionSolver(compute, Velocities, Positions, Walls);

            var particles = new GameObject[capacity];
            foreach (var p in particlefabs)
                p.transform.localScale = 2f * constants.radius * Vector3.one;
            for (var i = 0; i < capacity; i++)
                particles[i] = particlefabs[Random.Range(0, particlefabs.Length)];
            Combiner = new MeshCombiner(containerfab);
            Combiner.Rebuild(particles);
            Combiner.SetParent(transform, false);

            UpdateConstantData();
        }
Example #2
0
        void Start()
        {
            capacity = ShaderUtil.PowerOfTwo(capacity);

            Positions = new PositionService(compute, capacity);
            Velocities = new VelocityService(compute, capacity);
            Lifes = new LifeService(compute, capacity);
            Constants = new ConstantService(capacity, constants);
            VelSimulation = new VelocitySimulation(compute, Velocities, Constants);
            PosSimulation = new PositionSimulation(compute, Velocities, Positions);
            Collisions = new HashGrid(compute, computeSort, Lifes, Positions, GenerateGrid());
            ParticleSolver = new ParticleCollisionSolver(compute, Velocities, Positions, Lifes, Collisions);
            BoundsChecker = new BoundsChecker(compute, Lifes, Positions);
            Polygons = new PolygonColliderService();
            PolygonSolver = new PolygonCollisionSolver(compute, Velocities, Positions, Lifes, Polygons);

            var particles = new GameObject[capacity];
            foreach (var pfab in particlefabs)
                pfab.transform.localScale = 2f * constants.radius * Vector3.one;
            Profiler.BeginSample("Instantiate Particles");
            for (var i = 0; i < capacity; i++) {
                var pfab = particlefabs[Random.Range(0, particlefabs.Length)];
                particles[i] = (GameObject)Instantiate(pfab, Vector3.zero, Random.rotationUniform);
            }
            Profiler.EndSample();
            Combiner = new MeshCombiner(containerfab);
            Combiner.Rebuild(particles);
            Combiner.SetParent(transform, false);
            for (var i = 0; i < capacity; i++)
                Destroy(particles[i]);

            UpdateConstantData();
            _initialized = true;
        }