// 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); }
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); } }