Ejemplo n.º 1
0
        /**
         * Adds this actor to a solver. No simulation will take place for this actor
         * unless it has been added to a solver. Returns true if the actor was succesfully added,
         * false if it was already added or couldn't add it for any other reason.
         */
        public virtual bool AddToSolver(object info)
        {
            if (solver != null && !InSolver)
            {
                // Allocate particles in the solver:
                particleIndices = solver.AllocateParticles(positions.Length);
                if (particleIndices == null)
                {
                    Debug.LogWarning("Obi: Solver could not allocate enough particles for this actor. Please increase max particles.");
                    return(false);
                }

                inSolver = true;

                // Get an actor ID from the solver:
                actorID = solver.SetActor(actorID, this);

                // Update particle phases before sending data to the solver, as layers/flags settings might have changed.
                UpdateParticlePhases();

                // Send our particle data to the solver:
                PushDataToSolver(new ObiSolverData(ObiSolverData.ParticleData.ALL));

                return(true);
            }

            return(false);
        }
Ejemplo n.º 2
0
        /**
         * Adds this actor to a solver. No simulation will take place for this actor
         * unless it has been added to a solver. Returns true if the actor was succesfully added,
         * false if it was already added or couldn't add it for any other reason.
         */
        public virtual bool AddToSolver(object info)
        {
            if (solver != null && !InSolver)
            {
                // Allocate particles in the solver:
                particleIndices = solver.AllocateParticles(positions.Length);
                if (particleIndices == null)
                {
                    Debug.LogWarning("Obi: Solver could not allocate enough particles for this actor. Please increase max particles.");
                    return(false);
                }

                inSolver = true;

                // Get an actor ID from the solver:
                actorID = solver.SetActor(actorID, this);

                // Update particle phases before sending data to the solver, as layers/flags settings might have changed.
                UpdateParticlePhases();

                // find our offset in the deformable triangles array.
                trianglesOffset = Oni.GetDeformableTriangleCount(solver.OniSolver);

                // Send deformable triangle indices to the solver:
                UpdateDeformableTriangles();

                // Send our particle data to the solver:
                PushDataToSolver(ParticleData.ALL);

                // Add constraints to solver:
                foreach (ObiBatchedConstraints c in constraints.Values)
                {
                    c.AddToSolver(null);
                }

                if (OnAddedToSolver != null)
                {
                    OnAddedToSolver(this, null);
                }

                return(true);
            }

            return(false);
        }