예제 #1
0
        public void RemoveRuntimeCondition(RuntimeCondition condition)
        {
            positions     = NativeArrayUtils.RemoveRange(positions, condition.startIndex, condition.numberOfParticles);
            positionsCopy = NativeArrayUtils.RemoveRange(positionsCopy, condition.startIndex, condition.numberOfParticles);
            velocities    = NativeArrayUtils.RemoveRange(velocities, condition.startIndex, condition.numberOfParticles);
            masses        = NativeArrayUtils.RemoveRange(masses, condition.startIndex, condition.numberOfParticles);
            particles     = NativeArrayUtils.RemoveRange(particles, condition.startIndex, condition.numberOfParticles);

            nTotal -= condition.numberOfParticles;
            pSystem.SetParticles(particles, nTotal);

            int conditionIndex = runtimeConditionsSet.IndexOf(condition);

            for (int i = conditionIndex + 1; i < runtimeConditionsSet.Count; i++)
            {
                runtimeConditionsSet[i].startIndex -= condition.numberOfParticles;
            }

            runtimeConditionsSet.Remove(condition);
        }
예제 #2
0
        public void AddInitialConditions(List <InitialCondition> initialConditions)
        {
            int nTotalOld = nTotal;
            int n         = nTotalOld;

            for (int j = 0; j < initialConditions.Count; j++)
            {
                runtimeConditionsSet.Add(
                    new RuntimeCondition
                {
                    startIndex        = n,
                    numberOfParticles = initialConditions[j].numberOfParticles
                }
                    );

                for (int i = 0; i < initialConditions[j].numberOfParticles; i++)
                {
                    n++;
                }
            }

            nTotal = n;

            if (!positions.IsCreated || positions.Length == 0)
            {
                positions     = new NativeArray <double3>(n, Allocator.Persistent);
                positionsCopy = new NativeArray <double3>(n, Allocator.Persistent);
                velocities    = new NativeArray <double3>(n, Allocator.Persistent);
                masses        = new NativeArray <double>(n, Allocator.Persistent);

                particles = new ParticleSystem.Particle[n];
            }
            else
            {
                positions     = NativeArrayUtils.Append(positions, new NativeArray <double3>(nTotal - nTotalOld, Allocator.Persistent));
                positionsCopy = NativeArrayUtils.Append(positionsCopy, new NativeArray <double3>(nTotal - nTotalOld, Allocator.Persistent));
                velocities    = NativeArrayUtils.Append(velocities, new NativeArray <double3>(nTotal - nTotalOld, Allocator.Persistent));
                masses        = NativeArrayUtils.Append(masses, new NativeArray <double>(nTotal - nTotalOld, Allocator.Persistent));

                particles = NativeArrayUtils.Append(particles, new ParticleSystem.Particle[nTotal - nTotalOld]);
            }

            n = 0;

            for (int j = 0; j < initialConditions.Count; j++)
            {
                UnityEngine.Random.InitState(initialConditions[j].seed);

                for (int i = 0; i < initialConditions[j].numberOfParticles; i++)
                {
                    float3 randPos = ElipsoidRandom(initialConditions[j].shapeElipsoid, initialConditions[j].center, initialConditions[j].radius);

                    int k = n + nTotalOld;

                    positions[k]     = randPos;
                    positionsCopy[k] = randPos;

                    float3 crossProd = initialConditions[j].angularVelocity * Vector3.Cross(Vector3.up, randPos);
                    velocities[k] = crossProd;

                    float3 turbulence = ElipsoidRandom(initialConditions[j].turbulenceElipsoid, float3.zero, initialConditions[j].turbulenceStrength);
                    velocities[k] += turbulence;

                    masses[k] = UnityEngine.Random.Range(0.1f, 100f);

                    particles[k].position          = randPos;
                    particles[k].angularVelocity   = 0f;
                    particles[k].rotation          = 0f;
                    particles[k].velocity          = new Vector3(0f, 0f, 0f);
                    particles[k].startLifetime     = 10f;
                    particles[k].remainingLifetime = 10f - UnityEngine.Random.Range(0f, 1f);
                    particles[k].startSize         = 0.1f;
                    particles[k].startColor        = Color.white;

                    n++;
                }
            }

            pSystem.SetParticles(particles, nTotal);
        }