Esempio n. 1
0
        void PlaybackFrame(float time)
        {
            if (cache == null || cache.Duration == 0)
            {
                return;
            }

            // Get current frame from cache:
            cache.GetFrame(time, interpolate, ref frame);

            if (solver.allocatedParticles.Count < frame.indices.Count)
            {
                Debug.LogError("The ObiSolver doesn't have enough allocated particles to playback this cache.");
                Playing = false;
                return;
            }

            Matrix4x4 s2world = cache.localSpace ? solver.transform.localToWorldMatrix : Matrix4x4.identity;

            solver.activeParticles.Clear();

            // Apply current frame:
            for (int i = 0; i < frame.indices.Count; ++i)
            {
                if (frame.indices[i] >= 0 && frame.indices[i] < solver.renderablePositions.Length)
                {
                    solver.activeParticles.Add(frame.indices[i]);
                    solver.renderablePositions[frame.indices[i]] = s2world.MultiplyPoint3x4(frame.positions[i]);
                }
            }

            Oni.SetParticlePositions(solver.OniSolver, solver.renderablePositions, solver.renderablePositions.Length, 0);
            solver.UpdateActiveParticles();
        }
Esempio n. 2
0
        /**
         * Flags all particles allocated by this actor as active or inactive depending on the "active array".
         * The solver will then only simulate the active ones.
         */
        public virtual void OnEnable()
        {
            if (InSolver)
            {
                LazyBuildConstraintComponentCache();
                foreach (ObiBatchedConstraints c in constraints)
                {
                    if (c != null && isActiveAndEnabled)
                    {
                        c.OnEnable();
                    }
                }

                // update active status of all particles in the actor:
                solver.UpdateActiveParticles();

                // maybe this actor makes the solver visible to a camera now:
                solver.UpdateVisibility();
            }
        }
Esempio n. 3
0
        /**
         * Flags all particles allocated by this actor as active or inactive depending on the "active array".
         * The solver will then only simulate the active ones.
         */
        public virtual void OnEnable()
        {
            if (!InSolver)
            {
                return;
            }

            // update active status of all particles in the actor:
            for (int i = 0; i < particleIndices.Count; ++i)
            {
                int k = particleIndices[i];
                if (!active[i])
                {
                    solver.activeParticles.Remove(k);
                }
                else
                {
                    solver.activeParticles.Add(k);
                }
            }
            solver.UpdateActiveParticles();
        }
        /**
         * Flags all particles allocated by this actor as active or inactive depending on the "active array".
         * The solver will then only simulate the active ones.
         */
        public virtual void OnEnable()
        {
            // build constraints dictionary:
            constraints.Clear();
            ObiBatchedConstraints[] constraintComponents = GetComponents <ObiBatchedConstraints>();
            foreach (ObiBatchedConstraints c in constraintComponents)
            {
                constraints[c.GetConstraintType()] = c;

                c.GrabActor();
                if (c.isActiveAndEnabled)
                {
                    c.OnEnable();
                }
            }

            if (!InSolver)
            {
                return;
            }

            // update active status of all particles in the actor:
            solver.UpdateActiveParticles();
        }
Esempio n. 5
0
        /**
         * Flags all particles allocated by this actor as active or inactive depending on the "active array".
         * The solver will then only simulate the active ones.
         */
        public virtual void OnEnable()
        {
            // build constraints dictionary:
            constraints.Clear();
            ObiBatchedConstraints[] constraintComponents = GetComponents <ObiBatchedConstraints>();
            foreach (ObiBatchedConstraints c in constraintComponents)
            {
                constraints[c.GetConstraintType()] = c;

                c.GrabActor();
                if (c.isActiveAndEnabled)
                {
                    c.OnEnable();
                }
            }

            if (!InSolver)
            {
                return;
            }

            // update active status of all particles in the actor:
            for (int i = 0; i < particleIndices.Length; ++i)
            {
                int k = particleIndices[i];
                if (!active[i])
                {
                    solver.activeParticles.Remove(k);
                }
                else
                {
                    solver.activeParticles.Add(k);
                }
            }
            solver.UpdateActiveParticles();
        }
Esempio n. 6
0
        void PlaybackFrame(float time)
        {
            if (cache == null)
            {
                return;
            }

            // Get current frame from cache:
            ObiParticleCache.Frame frame = cache.GetFrame(time, interpolate);

            if (frame == null)
            {
                return;
            }

            if (solver.allocatedParticles.Count < frame.indices.Count)
            {
                Debug.LogError("The ObiSolver doesn't have enough allocated particles to playback this cache.");
                Playing = false;
                return;
            }

            // Set active particles:
            solver.activeParticles = new HashSet <int>(frame.indices);

            // Apply current frame:
            for (int i = 0; i < frame.indices.Count; ++i)
            {
                if (frame.indices[i] >= 0 && frame.indices[i] < solver.renderablePositions.Length)
                {
                    if (cache.localSpace)
                    {
                        solver.renderablePositions[frame.indices[i]] = solver.transform.TransformPoint(frame.positions[i]);
                    }
                    else
                    {
                        solver.renderablePositions[frame.indices[i]] = frame.positions[i];
                    }
                }
            }

            Oni.SetParticlePositions(solver.OniSolver, solver.renderablePositions, solver.renderablePositions.Length, 0);
            solver.UpdateActiveParticles();
        }