/// <summary>
        /// Constructs an updater for the provided geometry.
        /// </summary>
        /// <param name="polyhedron"></param>
        /// <param name="options"></param>
        public ParticlePositionUpdater(IPolyhedron polyhedron, IParticleMapOptions options)
        {
            _scaleFactor = (float)(options.ParticleSpeedScaleFactor * options.Timestep);

            _tracker         = new ParticleNeighbourhoodTracker(polyhedron, options.ParticleCount);
            _vertexPositions = GetVertexPositions(polyhedron);

            _vertexVelocities   = new Vector3[polyhedron.Vertices.Count];
            _particleVelocities = new Vector3[options.ParticleCount];
        }
示例#2
0
        /// <summary>
        /// Construct a particle map for the given simulation geometry.
        /// </summary>
        /// <param name="polyhedron"></param>
        /// <param name="options"></param>
        public ParticleMapView(IPolyhedron polyhedron, IParticleMapOptions options)
        {
            _options = options;
            _radius  = (float)_options.Radius;

            _positions = CreateParticles(options.ParticleCount, _radius);

            _renewalScheduler = new ParticleRenewalScheduler(options);
            _positionUpdater  = new ParticlePositionUpdater(polyhedron, options);
            _renderingManager = new ParticleRenderingManager(options);
        }
示例#3
0
        private List <ParticleMapRenderer> InitializeParticleRenderers(IParticleMapOptions options, out GameObject parentObject)
        {
            parentObject = new GameObject("Particle Maps");

            var renderers = new List <ParticleMapRenderer>(_numberOfRenderers);

            for (int i = 0; i < _numberOfRenderers; i++)
            {
                // Delegate a subarray of particles specified by these indices to a new ParticleMapRenderer.
                var indexOfFirstVertex       = _indicesOfFirstParticles[i];
                var indexOfOnePastLastVertex = _indicesOfOnePastLastParticles[i];
                var newRenderer = new ParticleMapRenderer(parentObject.transform, indexOfFirstVertex, indexOfOnePastLastVertex, options);
                renderers.Add(newRenderer);
            }

            return(renderers);
        }
示例#4
0
        /// <summary>
        /// Construct a ParticleRenderingManager with the specified options.
        /// </summary>
        /// <param name="options"></param>
        public ParticleRenderingManager(IParticleMapOptions options)
        {
            _numberOfParticles = options.ParticleCount;

            // Calculate the number of lines needed, the number of vertices needed, the number of ParticleMapRenderers
            // needed, and the number of particles that'll be delegated to each ParticleMapRenderer.
            _numberOfLinesPerParticle = options.ParticleTrailLifespan - 1;
            _numberOfLines            = _numberOfParticles * _numberOfLinesPerParticle;
            var numberOfVertices = 2 * _numberOfLines;

            _numberOfRenderers    = Mathf.FloorToInt((float)numberOfVertices / MaxNumberOfVerticesPerRenderer) + 1;
            _particlesPerRenderer = _numberOfParticles / _numberOfRenderers;

            // Calculate the partition of the particles into chunks. Each chunk will be assigned to a different ParticleMapRenderer.
            _indicesOfFirstParticles       = Enumerable.Range(0, _numberOfRenderers).Select(i => _particlesPerRenderer * i).ToList();
            _indicesOfOnePastLastParticles = Enumerable.Range(0, _numberOfRenderers).Select(i => Mathf.Min(_particlesPerRenderer * (i + 1), _numberOfParticles)).ToList();

            //TODO: Pass in the first & last index arrays, seeing as it depends on them?
            // Create the particle renderers.
            _renderers = InitializeParticleRenderers(options, out _gameObject);
        }
示例#5
0
 public ParticleRenewalScheduler(IParticleMapOptions options)
 {
     _options         = options;
     _renewalSchedule = InitializeRenewalTimes(options.ParticleCount, options.ParticleLifespan);
 }
        /// <summary>
        /// Construct a particle map renderer that'll display the subarray, defined by the two provided indices,
        /// of an array of particles.
        /// </summary>
        /// <param name="parentTransform">The transform to render points relative to</param>
        /// <param name="indexOfFirstParticle"></param>
        /// <param name="indexOfOnePastLastParticle"></param>
        /// <param name="options"></param>
        public ParticleMapRenderer(Transform parentTransform, int indexOfFirstParticle, int indexOfOnePastLastParticle, IParticleMapOptions options)
        {
            _indexOfFirstParticle       = indexOfFirstParticle;
            _indexOfOnePastLastParticle = indexOfOnePastLastParticle;

            // The trail that follows each particle requires (ParticleTrailLifespan - 1) lines, and each line requires
            // two vertices. So the number of vertices per line is
            _verticesPerParticle = 2 * (options.ParticleTrailLifespan - 1);
            // And the total number of vertices is
            _numberOfVertices = (_indexOfOnePastLastParticle - _indexOfFirstParticle) * _verticesPerParticle;
            _particleLines    = new Vector3[_numberOfVertices];

            _particleMapGameObject = CreateParticleMapGameObject(parentTransform, _numberOfVertices, options.ParticleMaterialName);
            _particlesMeshFilter   = _particleMapGameObject.GetComponent <MeshFilter>();
        }