Example #1
0
        void Solver_OnStepEnd(object sender, System.EventArgs e)
        {
            if (solver == null)
            {
                return;
            }

            ReallocateParticles();

            for (int i = 0; i < alive; ++i)
            {
                positions[i] = particles[i].position;
            }

            Oni.InterpolateDiffuseParticles(solver.OniSolver, solver.velocities.GetIntPtr(), positions.GetIntPtr(), velocities.GetIntPtr(), neighbourCount.GetIntPtr(), alive);

            for (int i = 0; i < alive; ++i)
            {
                // kill the particle if it has very few neighbors:
                if (neighbourCount[i] < minNeighbors)
                {
                    particles[i].remainingLifetime = 0;
                }

                particles[i].velocity = velocities[i];
            }

            ps.SetParticles(particles, alive);
        }
Example #2
0
        public void Initialize()
        {
            // Tear everything down first:
            Teardown();

            try{
                // Create a default material:
                defaultFluidMaterial           = ScriptableObject.CreateInstance <ObiEmitterMaterialFluid>();
                defaultFluidMaterial.hideFlags = HideFlags.HideAndDontSave;

                // Create the Oni solver:
                oniSolver = Oni.CreateSolver(maxParticles);

                // Initialize moving transform:
                InitializeTransformFrame();

                actors               = new List <ObiActor>();
                activeParticles      = new int[maxParticles];
                particleToActor      = new ParticleInActor[maxParticles];
                materialIndices      = new int[maxParticles];
                fluidMaterialIndices = new int[maxParticles];

                positions = new AlignedVector4Array(maxParticles);
                Oni.SetParticlePositions(oniSolver, positions.GetIntPtr());

                startPositions = new AlignedVector4Array(maxParticles);
                Oni.SetParticleStartPositions(oniSolver, startPositions.GetIntPtr());

                prevPositions = new AlignedVector4Array(maxParticles);
                Oni.SetParticlePreviousPositions(oniSolver, prevPositions.GetIntPtr());

                restPositions = new AlignedVector4Array(maxParticles);
                Oni.SetRestPositions(oniSolver, restPositions.GetIntPtr());

                velocities = new AlignedVector4Array(maxParticles);
                Oni.SetParticleVelocities(oniSolver, velocities.GetIntPtr());

                orientations = new AlignedQuaternionArray(maxParticles, Quaternion.identity);
                Oni.SetParticleOrientations(oniSolver, orientations.GetIntPtr());

                startOrientations = new AlignedQuaternionArray(maxParticles, Quaternion.identity);
                Oni.SetParticleStartOrientations(oniSolver, startOrientations.GetIntPtr());

                prevOrientations = new AlignedQuaternionArray(maxParticles, Quaternion.identity);
                Oni.SetParticlePreviousOrientations(oniSolver, prevOrientations.GetIntPtr());

                restOrientations = new AlignedQuaternionArray(maxParticles, Quaternion.identity);
                Oni.SetRestOrientations(oniSolver, restOrientations.GetIntPtr());

                angularVelocities = new AlignedVector4Array(maxParticles);
                Oni.SetParticleAngularVelocities(oniSolver, angularVelocities.GetIntPtr());

                invMasses = new AlignedFloatArray(maxParticles);
                Oni.SetParticleInverseMasses(oniSolver, invMasses.GetIntPtr());

                invRotationalMasses = new AlignedFloatArray(maxParticles);
                Oni.SetParticleInverseRotationalMasses(oniSolver, invRotationalMasses.GetIntPtr());

                principalRadii = new AlignedVector4Array(maxParticles);
                Oni.SetParticlePrincipalRadii(oniSolver, principalRadii.GetIntPtr());

                phases = new AlignedIntArray(maxParticles);
                Oni.SetParticlePhases(oniSolver, phases.GetIntPtr());

                renderablePositions = new AlignedVector4Array(maxParticles);
                Oni.SetRenderableParticlePositions(oniSolver, renderablePositions.GetIntPtr());

                renderableOrientations = new AlignedQuaternionArray(maxParticles, Quaternion.identity);
                Oni.SetRenderableParticleOrientations(oniSolver, renderableOrientations.GetIntPtr());

                anisotropies = new AlignedVector4Array(maxParticles * 3);
                Oni.SetParticleAnisotropies(oniSolver, anisotropies.GetIntPtr());

                smoothingRadii = new AlignedFloatArray(maxParticles);
                Oni.SetParticleSmoothingRadii(oniSolver, smoothingRadii.GetIntPtr());

                buoyancies = new AlignedFloatArray(maxParticles);
                Oni.SetParticleBuoyancy(oniSolver, buoyancies.GetIntPtr());

                restDensities = new AlignedFloatArray(maxParticles);
                Oni.SetParticleRestDensities(oniSolver, restDensities.GetIntPtr());

                viscosities = new AlignedFloatArray(maxParticles);
                Oni.SetParticleViscosities(oniSolver, viscosities.GetIntPtr());

                surfaceTension = new AlignedFloatArray(maxParticles);
                Oni.SetParticleSurfaceTension(oniSolver, surfaceTension.GetIntPtr());

                vortConfinement = new AlignedFloatArray(maxParticles);
                Oni.SetParticleVorticityConfinement(oniSolver, vortConfinement.GetIntPtr());

                atmosphericDrag     = new AlignedFloatArray(maxParticles);
                atmosphericPressure = new AlignedFloatArray(maxParticles);
                Oni.SetParticleAtmosphericDragPressure(oniSolver, atmosphericDrag.GetIntPtr(), atmosphericPressure.GetIntPtr());

                diffusion = new AlignedFloatArray(maxParticles);
                Oni.SetParticleDiffusion(oniSolver, diffusion.GetIntPtr());

                vorticities = new AlignedVector4Array(maxParticles);
                Oni.SetParticleVorticities(oniSolver, vorticities.GetIntPtr());

                fluidData = new AlignedVector4Array(maxParticles);
                Oni.SetParticleFluidData(oniSolver, fluidData.GetIntPtr());

                userData = new AlignedVector4Array(maxParticles);
                Oni.SetParticleUserData(oniSolver, userData.GetIntPtr());

                externalForces = new AlignedVector4Array(maxParticles);
                Oni.SetParticleExternalForces(oniSolver, externalForces.GetIntPtr());

                externalTorques = new AlignedVector4Array(maxParticles);
                Oni.SetParticleExternalTorques(oniSolver, externalTorques.GetIntPtr());

                wind = new AlignedVector4Array(maxParticles);
                Oni.SetParticleWinds(oniSolver, wind.GetIntPtr());

                positionDeltas = new AlignedVector4Array(maxParticles);
                Oni.SetParticlePositionDeltas(oniSolver, positionDeltas.GetIntPtr());

                orientationDeltas = new AlignedQuaternionArray(maxParticles, new Quaternion(0, 0, 0, 0));
                Oni.SetParticleOrientationDeltas(oniSolver, orientationDeltas.GetIntPtr());

                positionConstraintCounts = new AlignedIntArray(maxParticles);
                Oni.SetParticlePositionConstraintCounts(oniSolver, positionConstraintCounts.GetIntPtr());

                orientationConstraintCounts = new AlignedIntArray(maxParticles);
                Oni.SetParticleOrientationConstraintCounts(oniSolver, orientationConstraintCounts.GetIntPtr());

                normals = new AlignedVector4Array(maxParticles);
                Oni.SetParticleNormals(oniSolver, normals.GetIntPtr());

                invInertiaTensors = new AlignedVector4Array(maxParticles);
                Oni.SetParticleInverseInertiaTensors(oniSolver, invInertiaTensors.GetIntPtr());

                // Initialize parameters:
                UpdateParameters();
            }catch (Exception exception) {
                Debug.LogException(exception);
            }finally{
                initialized = true;
            };
        }