Pixelflow lib / getting individual particle positions

Hello,

I am trying to find a way to get the individual particle positions in a pixelflow particle sim.
Is this even possible considering the texture based physics calcs?

Pixelflow is a pretty big library. Can you be more concrete about how you are using it, with what kind of example, and what your particles do?

For example, if you are using DwParticle2D, it has x() and y() methods to retrieve its current position.

Im using DwFlowFieldParticles to sim a large number of grain-like particles.
Pretty simple movements, collisions obstacles etc.
I need a way to grab an “instance” of the positions , not on every frame.
Like pause the sim, store x,y for each particle in an array, continue.

I searched in the javadocs but couldnt find any methods or fields.
Even looked at decoding some texture into positions but my knowledge of gpu computing
is kinda limited.

Perhaps I should look into implementing the sim using DwParticle2D?
I dont really need the existence of flowfield atm but it can be useful in future iterations of the app.

To make the problem more specific, in the example scene of the Pixelflow library
FlowFieldParticles_Basic is there any way to get individual particle positions?
What im trying to do is be able to save the locations on an array when i hit a button.

With my limited understanding I think the positions are encoded in the
particles.tex_particle.src DwGLTexture but i cant find a way to decode them.

I’m not familiar with it, but possibly relevant:

  1. source code in question: https://github.com/diwi/PixelFlow/blob/master/src/com/thomasdiewald/pixelflow/java/dwgl/DwGLTexture.java
  2. past issue on copying data out of DwGLTexture: https://github.com/diwi/PixelFlow/issues/11

At a certain point if you are stuck you might consider posting an issue asking if it is possible.

Actually the links you provided helped!
Ive seen the getFloatTextureData in the reference but I expected it to throw color values.
For anyone in the future that needs it here is a crude solution:

DwGLTexture tex_pos_copy;
float[] data_pos;

void foo() {
  if (tex_pos_copy == null) {
    tex_pos_copy = particles.tex_particle.src.createEmtpyCopy();
  }

  DwFilter.get(context).copy.apply(particles.tex_particle.src, tex_pos_copy);

  context.begin();
  data_pos = tex_pos_copy.getFloatTextureData(data_pos);
  context.end();

  for (int i=0; i<particles.getCount()*4; i+=2) {
    float xpos = data_pos[i]*width;
    float ypos = data_pos[i+1]*height * (-1.0) + height;
  }
}

thank you very much Jeremy!

1 Like