Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
RegenerateRestPositions strange code
#4
(08-04-2019, 01:49 PM)Teolog Wrote: So, if I understand you right, this code may work as original implementation but not flow to GC:
public override void RegenerateRestPositions(){
            ObiDistanceConstraintBatch distanceBatch = DistanceConstraints.GetFirstBatch();
            if (distanceBatch.ConstraintCount > 0)
            {
                Vector3 right=Vector3.right;
                // Iterate trough all distance constraints in order:
                float accumulatedDistance = 0;
                restPositions[0] = new Vector4(0, 0, 0, 1);
                float mindistance = Mathf.Min(interParticleDistance, principalRadii[distanceBatch.springIndices[0]][0]);
                for (int i = 1; i < distanceBatch.ConstraintCount; ++i)
                {
                    int particle = distanceBatch.springIndices[i * 2 + 1];
                    accumulatedDistance += Math.Min(principalRadii[particle][0],mindistance);
                    var ditanceoffset = right * accumulatedDistance;
                    restPositions[particle] =new Vector4(ditanceoffset.x,ditanceoffset.y,ditanceoffset.z,1);
                }
                PushDataToSolver(ParticleData.REST_POSITIONS);
            }
        }

Yes, as long as you don't use the array version of Mathf.Min() garbage will not be generated. However I'm curious as how often you're calling this method, it should only be called one at initialization, or when adding new particles using ObiCursor.
Reply


Messages In This Thread
RegenerateRestPositions strange code - by Teolog - 08-04-2019, 12:02 PM
RE: RegenerateRestPositions strange code - by josemendez - 09-04-2019, 12:35 PM