コード例 #1
0
        //void Start()
        //{
        //    m_Dropdown = FindObjectOfType<Dropdown>().GetComponent<Dropdown>();
        //    m_Dropdown.onValueChanged.AddListener(delegate { DeformCharacter(m_Dropdown); });
        //    //m_Deform.AddListener(delegate { deformParticle(flexCont, pInd, pVect); });
        //    //m_Dropdown.onValueChanged.AddListener(delegate { assignDeform = true; PostContainerUpdate(flexSolver, flexCont, flexParams); });

        //}

        // Start is called before the first frame update
        public override void PostContainerUpdate(FlexSolver solver, FlexContainer cntr, FlexParameters parameters)
        {
            //flexSolver.m_solverSubSteps = (int) solverSubSteps;
            //flexParams.m_numIterations = (int) numOfIterations;

            //solver.m_solverSubSteps = (int)solverSubSteps;
            //parameters.m_numIterations = (int)numOfIterations;

            //In Child objects
            //if OntriggerEnter(Coll)
            //  if (Coll.tag = "fear", "happy", "sad", "excited")
            //     Set appropriate behavior/change box collider position/change iterations or solver substeps
            if (assignDeform)
            {
                //print(pInd);
                //print(pVect);
                print("Assign Deform");
                deformParticle(/*flexCont*/ cntr, pInd, pVect);
                assignDeform = false;
            }

            if (resetDeform)
            {
                resetParticle(cntr, pInd);
                resetDeform = false;
            }
        }
コード例 #2
0
        public override void PreContainerUpdate(FlexSolver solver, FlexContainer cntr, FlexParameters parameters)
        {
            Vector3 vel = transform.forward * m_speed;
            Vector3 pos = transform.position;


            if (Input.GetKeyDown(m_key))
            {
                m_color = new Color(Random.value, Random.value, Random.value, 1);
            }

            if (Input.GetKey(m_key) || m_alwaysOn)
            {
                for (int i = m_id; i < m_id + m_rate && i < m_particles.m_particlesCount; i++)
                {
                    m_particles.m_particlesActivity[i] = true;
                    m_particles.m_particles[i].pos     = pos + UnityEngine.Random.insideUnitSphere * m_radius;
                    m_particles.m_velocities[i]        = vel;
                    m_particles.m_colours[i]           = m_color;
                }

                m_id += m_rate;

                if (m_loop && m_id > m_particles.m_particlesCount - 1)
                {
                    m_id = 0;
                }
            }
        }
コード例 #3
0
ファイル: FlexMouseDrag.cs プロジェクト: may1702/Liquids
        public override void PostContainerUpdate(FlexSolver solver, FlexContainer cntr, FlexParameters parameters)
        {
            if (Input.GetMouseButtonDown(0))
            {
                // need up to date positions
                //    Flex.GetParticles(m_solverPtr, m_cntr.m_particlesHndl.AddrOfPinnedObject(), m_cntr.m_maxParticlesCount, Flex.Memory.eFlexMemoryHost);
                //    Flex.GetVelocities(m_solverPtr, m_cntr.m_velocitiesHndl.AddrOfPinnedObject(), m_cntr.m_maxParticlesCount, Flex.Memory.eFlexMemoryHost);

                Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
                m_mouseParticle = PickParticle(ray.origin, ray.direction, cntr.m_particles, cntr.m_phases, cntr.m_particlesCount, parameters.m_radius * 0.8f, ref m_mouseT);

                if (m_mouseParticle != -1)
                {
                    Debug.Log("picked: " + m_mouseParticle);

                    m_mousePos  = ray.origin + ray.direction * m_mouseT;
                    m_mouseMass = cntr.m_particles[m_mouseParticle].invMass;
                    cntr.m_particles[m_mouseParticle].invMass = 0.0f;

                    //     Flex.SetParticles(m_solverPtr, m_cntr.m_particles, m_cntr.m_particlesCount, Flex.Memory.eFlexMemoryHost);
                }
            }

            if (Input.GetMouseButtonUp(0))
            {
                if (m_mouseParticle != -1)
                {
                    cntr.m_particles[m_mouseParticle].invMass = m_mouseMass;
                    m_mouseParticle = -1;

                    // need to update positions straight away otherwise particle might be left with increased mass
                    //       Flex.SetParticles(m_solverPtr, m_cntr.m_particles, m_cntr.m_particlesCount, Flex.Memory.eFlexMemoryHost);
                }
            }

            if (m_mouseParticle != -1)
            {
                //    Flex.GetParticles(m_solverPtr, m_cntr.m_particlesHndl.AddrOfPinnedObject(), m_cntr.m_maxParticlesCount, Flex.Memory.eFlexMemoryHost);
                //    Flex.GetVelocities(m_solverPtr, m_cntr.m_velocitiesHndl.AddrOfPinnedObject(), m_cntr.m_maxParticlesCount, Flex.Memory.eFlexMemoryHost);

                Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
                m_mousePos = ray.origin + ray.direction * m_mouseT;

                Vector3 pos   = cntr.m_particles[m_mouseParticle].pos;
                Vector3 p     = Vector3.Lerp(pos, m_mousePos, 0.8f);
                Vector3 delta = p - pos;

                cntr.m_particles[m_mouseParticle].pos = p;
                cntr.m_velocities[m_mouseParticle]    = delta / Time.fixedTime;

                //    Flex.SetParticles(m_solverPtr, m_cntr.m_particlesHndl.AddrOfPinnedObject(), m_cntr.m_particlesCount, Flex.Memory.eFlexMemoryHost);
                //    Flex.SetVelocities(m_solverPtr, m_cntr.m_velocitiesHndl.AddrOfPinnedObject(), m_cntr.m_particlesCount, Flex.Memory.eFlexMemoryHost);
            }
        }
コード例 #4
0
        // Override to modify the data after the flex game objects were updated but before the data from them was copied to the container arrays
        // In other words, use this for working with flex game objects.
        public override void PreContainerUpdate(FlexSolver solver, FlexContainer cntr, FlexParameters parameters)
        {
            const int maxCopies = 2048;
            const int maxEdits  = 2048;

            FlexExt.FlexExtTearingParticleClone[] particleCopies = new FlexExt.FlexExtTearingParticleClone[maxCopies];
            int numParticleCopies = 0;

            FlexExt.FlexExtTearingMeshEdit[] triangleEdits = new FlexExt.FlexExtTearingMeshEdit[maxEdits];
            int numTriangleEdits = 0;

            int numParticles = m_flexParticles.m_particlesCount;
            int numSprings   = m_flexSprings.m_springsCount;

            uFlexAPI.uFlexTearClothMesh(ref numParticles, numParticles * 2, numSprings, m_flexParticles.m_particles, m_flexSprings.m_springIndices, m_flexSprings.m_springRestLengths, m_flexSprings.m_springCoefficients, m_flexTriangles.m_triangleIndices, m_clothMeshPtr,
                                        m_maxStrain, m_maxSplits, particleCopies, ref numParticleCopies, maxCopies, triangleEdits, ref numTriangleEdits, maxEdits);

            // copy particles
            for (int i = 0; i < numParticleCopies; ++i)
            {
                int srcIndex  = particleCopies[i].srcIndex;
                int destIndex = particleCopies[i].destIndex;

                m_flexParticles.m_particles[destIndex]         = m_flexParticles.m_particles[srcIndex];
                m_flexParticles.m_restParticles[destIndex]     = m_flexParticles.m_restParticles[srcIndex];
                m_flexParticles.m_velocities[destIndex]        = m_flexParticles.m_velocities[srcIndex];
                m_flexParticles.m_colours[destIndex]           = m_flexParticles.m_colours[srcIndex];
                m_flexParticles.m_phases[destIndex]            = m_flexParticles.m_phases[srcIndex];
                m_flexParticles.m_particlesActivity[destIndex] = m_flexParticles.m_particlesActivity[srcIndex];

                mappingsRev[destIndex] = mappingsRev[srcIndex];

                //deactivate inflation if there is any break
                if (m_flexInflatable != null)
                {
                    m_flexInflatable.enabled = false;
                }
            }

            // apply triangle modifications to index buffer
            for (int i = 0; i < numTriangleEdits; ++i)
            {
                int index    = triangleEdits[i].triIndex;
                int newValue = triangleEdits[i].newParticleIndex;

                m_flexTriangles.m_triangleIndices[index] = newValue;
            }


            m_flexParticles.m_particlesCount += numParticleCopies;
        }
コード例 #5
0
 public override void PostContainerUpdate(FlexSolver solver, FlexContainer cntr, FlexParameters parameters)
 {
     for (int i = 0; i < m_lockedParticlesIds.Count; i++)
     {
         if (m_lock)
         {
             cntr.m_particles[m_lockedParticlesIds[i]].invMass = 0.0f;
         }
         else
         {
             cntr.m_particles[m_lockedParticlesIds[i]].invMass = m_lockedParticlesMasses[i];
         }
     }
 }
コード例 #6
0
 public override void FlexStart(FlexSolver solver, FlexContainer cntr, FlexParameters parameters)
 {
     for (int i = 0; i < cntr.m_particlesCount; i++)
     {
         Collider   collider  = GetComponent <Collider>();
         Collider[] colliders = Physics.OverlapSphere(cntr.m_particles[i].pos, 1.0f);
         foreach (Collider c in colliders)
         {
             if (c == collider)
             {
                 m_lockedParticlesIds.Add(i);
                 m_lockedParticlesMasses.Add(cntr.m_particles[i].invMass);
                 cntr.m_particles[i].invMass = 0.0f;
             }
         }
     }
 }
コード例 #7
0
 // Override this method to modify the data just before the solver is closed
 public override void FlexClose(FlexSolver solver, FlexContainer cntr, FlexParameters parameters)
 {
 }
コード例 #8
0
 // Override to modify the data after the container was updated
 // In other words, use for working directly with the container data.
 public override void PostContainerUpdate(FlexSolver solver, FlexContainer cntr, FlexParameters parameters)
 {
 }
コード例 #9
0
 // Override this method to modify the data just before the solver is closed
 public virtual void FlexClose(FlexSolver solver, FlexContainer cntr, FlexParameters parameters)
 {
 }
コード例 #10
0
 // Override to modify the data after the container was updated
 // In other words, use for working directly with the container data.
 public virtual void PostContainerUpdate(FlexSolver solver, FlexContainer cntr, FlexParameters parameters)
 {
 }