Exemple #1
0
    // Update is called once per frame
    void Update()
    {
        // Map buffers for reading / writing.
        particles  = Flex.Map(_particleBuffer);
        velocities = Flex.Map(_velocityBuffer);
        phases     = Flex.Map(_phaseBuffer);

        // Spawn particles.
        //spawnParticles(particles, velocities, phases);

        // Render particles.
        RenderParticles(particles, velocities, phases);

        // Unmap buffers.
        Flex.Unmap(_particleBuffer);
        Flex.Unmap(_velocityBuffer);
        Flex.Unmap(_phaseBuffer);

        // Write to device (async).
        Flex.SetParticles(_solver, _particleBuffer);
        Flex.SetVelocities(_solver, _velocityBuffer);
        Flex.SetPhases(_solver, _phaseBuffer);

        // Tick.
        Flex.UpdateSolver(_solver, Time.deltaTime, 1);

        // Read back (async).
        Flex.GetParticles(_solver, _particleBuffer);
        Flex.GetVelocities(_solver, _velocityBuffer);
        Flex.GetPhases(_solver, _phaseBuffer);
    }
Exemple #2
0
    public void TestSetGetParticlesVelocities()
    {
        Vector3 GRAVITY = new Vector3(1, 2, 3);
        float   DELTA_T = 0.016f;

        Flex.Library    lib  = Flex.Init(Flex.FLEX_VERSION, ErrorCallback);
        Flex.SolverDesc desc = default(Flex.SolverDesc);
        Flex.SetSolverDescDefaults(ref desc);
        desc.maxParticles        = 1000;
        desc.maxDiffuseParticles = 1000;
        Flex.Solver solver = Flex.CreateSolver(lib, ref desc);

        Flex.Params prms = new Flex.Params();
        Flex.GetParams(solver, ref prms);
        prms.gravity = GRAVITY;
        Flex.SetParams(solver, ref prms);

        Flex.Buffer particles = CreateBuffer(lib, 1, 4, new float[]
        {
            0.0f, 0.0f, 0.0f, 1.0f,
        });
        Flex.SetParticles(solver, particles);

        Flex.Buffer velocities = CreateBuffer(lib, 1, 3, new float[]
        {
            0.0f, 0.0f, 0.0f,
        });
        Flex.SetVelocities(solver, velocities);

        Flex.SetActiveCount(solver, 1);

        Flex.Buffer active = CreateBuffer(lib, 1, 1, new int[]
        {
            0
        });
        Flex.SetActive(solver, active);

        Flex.UpdateSolver(solver, DELTA_T, 1);

        Flex.GetVelocities(solver, velocities);
        float[] values; ReadBuffer(lib, velocities, 1, 3, out values);

        Assert.AreEqual(GRAVITY * DELTA_T, new Vector3(values[0], values[1], values[2]));

        Flex.FreeBuffer(particles);
        Flex.FreeBuffer(velocities);
        Flex.FreeBuffer(active);

        Flex.DestroySolver(solver);
        Flex.Shutdown(lib);
    }
Exemple #3
0
        private void PullParticlesFromGPU(IntPtr solverPtr, FlexContainer cnt, Flex.Memory memory)
        {
            Flex.GetParticles(m_solverPtr, m_cntr.m_particlesHndl.AddrOfPinnedObject(), m_cntr.m_particlesCount, memory);
            Flex.GetVelocities(m_solverPtr, m_cntr.m_velocitiesHndl.AddrOfPinnedObject(), m_cntr.m_particlesCount, memory);
            Flex.GetPhases(m_solverPtr, m_cntr.m_phasesHndl.AddrOfPinnedObject(), m_cntr.m_particlesCount, memory);

            Flex.GetSmoothParticles(m_solverPtr, m_cntr.m_smoothedParticlesHndl.AddrOfPinnedObject(), m_cntr.m_particlesCount, memory);
            Flex.GetNormals(m_solverPtr, m_cntr.m_normalsHndl.AddrOfPinnedObject(), m_cntr.m_particlesCount, memory);
            Flex.GetDensities(m_solverPtr, m_cntr.m_densitiesHndl.AddrOfPinnedObject(), memory);
            Flex.GetBounds(m_solverPtr, ref m_minBounds, ref m_maxBounds, memory);

            if (m_cntr.m_shapeCoefficients.Length > 0)
            {
                Flex.GetRigidTransforms(m_solverPtr, m_cntr.m_shapeRotationHndl.AddrOfPinnedObject(), m_cntr.m_shapeTranslationsHndl.AddrOfPinnedObject(), memory);
            }
        }