LiquidFun setting properties such as colorMixingStrength

Hi there, I’m using the LiquidFun library by Thomas Diewald and am running against a brickwall trying to set the colorMixingStrength so the colours mix more slowly. At this stage Im trying to get any of the sketches in the examples included in the library to do this. I’ve tried extending the ParticleSystem class where the colorMixingStrength field seems to be stored but it is a hidden/private field (this also happens to be about the extent of my programming macgyvering) Maybe there’s a less convoluted way of setting these kind of properties or perhaps its not possible… In any case any guidance would be much appreciated. Thanks.

Perhaps share a minimal working example (MCVE) of a LiquidFun ParticleSystem with colorMixingStrength set (or failing to set it) to get the forum started with helping you. Did you look at the documentation, and do you understand what the method does and what a “simulation step” is? I’m wondering specifically what you mean by “more slowly” in the context of steps.

Determines how fast colors are mixed 1.0f ==> mixed immediately 0.5f ==> mixed half way each simulation step (see b2World::Step()) LiquidFun: b2ParticleSystemDef Struct Reference

Hi Jeremy, Thanks for your response and sorry it took a while for me to reply.

  1. I’ll put the code of the example I’m looking at in the next comment. It is an example included in the library with an attempt to access the particle system class inside the world class. (However its all private/hidden).
  2. I’ve tried making as much sense I can of the documentation but it seems to be a bit fragmented (between box2d, google-liquidfun, dw-liquidfun etc). For example the createParticleSystem class in the b2world class in the google documentation doesn’t seem to be in the world class in box2d world class for processing on which the dw class is extended. (https://google.github.io/liquidfun/API-Ref/html/classb2_world.html#a68b967ae71d8363fe01d37781323e07e)
  3. I imagine the colorMixingStrength parameter and method determines how fast the colors are mixed (as stated in the documentation) So in the example code it would make the mix to pink slower. I don’t know exactly what the ‘step’ is but assume it is how often it is computed/cycled - but I think it also has an impact on the other things such as velocities etc.
  4. Regardless of what these things do they are a bit tricky to access, which seems to be the bulk of my experience with this library which is a pity because it’s a wonderful tool.

As mentioned in my original post I’m in a little over my head, but who knows maybe I just need a simple paradigm shift. And if its not possible to change these type of things that would also be great to know.

Thanks again.

/**
 * 
 * LiquidFunProcessing | Copyright 2017 Thomas Diewald - www.thomasdiewald.com
 * 
 * https://github.com/diwi/LiquidFunProcessing.git
 * 
 * Box2d / LiquidFun Library for Processing.
 * MIT License: https://opensource.org/licenses/MIT
 * 
 */


import com.thomasdiewald.liquidfun.java.DwWorld;

import org.jbox2d.collision.shapes.ChainShape;
import org.jbox2d.collision.shapes.PolygonShape;
import org.jbox2d.common.Color3f;
import org.jbox2d.common.Vec2;
import org.jbox2d.dynamics.Body;
import org.jbox2d.dynamics.BodyDef;
import org.jbox2d.particle.ParticleGroupDef;
import org.jbox2d.particle.ParticleType;
import org.jbox2d.particle.ParticleSystem;

import processing.core.*;
import processing.opengl.PGraphics2D;

  
  //
  // Simulation of a clash of two big particle-groups. 
  // 
  //
  // Controls:
  //
  // LMB         ... drag bodies
  // LMB + SHIFT ... shoot bullet
  // MMB         ... add particles
  // RMB         ... remove particles
  // 'r'         ... reset
  // 't'         ... update/pause physics
  // 'f'         ... toggle debug draw
  //
  
  
  int viewport_w = 500;//1280;
  int viewport_h = 500;//720;
  int viewport_x = 230;
  int viewport_y = 0;
  
  boolean UPDATE_PHYSICS = true;
  boolean USE_DEBUG_DRAW = false;

  DwWorld world;
  ParticleSystem particlesystem;//Particle system inside box2d world class where color mixing parameters and method are

//  PImage sprite;

  public void settings(){
    size(viewport_w, viewport_h, P2D);
    smooth(8);
  }
  
  
  public void setup(){ 
    surface.setLocation(viewport_x, viewport_y);
//    sprite = loadImage("sprite.png");
    reset();
    frameRate(120);
  }
  
  
  public void release(){
    if(world != null) world.release(); world = null;
  }
  
  
  public void reset(){
    // release old resources
    release();
    
    world = new DwWorld(this, 18);
    particlesystem = world.m_particleSystem; // this is not visible/public (or the fields inside it, making it impossible to change the colormixing parameters) 

    // create scene: rigid bodies, particles, etc ...
    initScene();
  }
  
  
  
  public void draw(){
    if(UPDATE_PHYSICS){
      world.update();
    }
    
    PGraphics2D canvas = (PGraphics2D) this.g;
    canvas.background(32);
    canvas.pushMatrix();
    world.applyTransform(canvas);
    world.drawBulletSpawnTrack(canvas);
    if(USE_DEBUG_DRAW){
      world.displayDebugDraw(canvas);
      // DwDebugDraw.display(canvas, world);
    } else {
      world.display(canvas);
    }
    canvas.popMatrix();
    
    // info
    int num_bodies    = world.getBodyCount();
    int num_particles = world.getParticleCount();
    String txt_fps = String.format(getClass().getName()+ " [bodies: %d]  [particles: %d]  [fps %6.2f]", num_bodies, num_particles, frameRate);
    surface.setTitle(txt_fps);
  }
  
  
  
  //////////////////////////////////////////////////////////////////////////////
  // User Interaction
  //////////////////////////////////////////////////////////////////////////////
  public void keyReleased(){
    if(key == 't') UPDATE_PHYSICS = !UPDATE_PHYSICS;
    if(key == 'r') reset();
    if(key == 'f') USE_DEBUG_DRAW = !USE_DEBUG_DRAW;
  }
  

  
  //////////////////////////////////////////////////////////////////////////////
  // Scene Setup
  //////////////////////////////////////////////////////////////////////////////
 
  // https://github.com/jbox2d/jbox2d/blob/master/jbox2d-testbed/src/main/java/org/jbox2d/testbed/tests/DamBreak.java
  public void initScene() {
    
    float dimx = world.transform.box2d_dimx;
    float dimy = world.transform.box2d_dimy;
    
    float dimxh = dimx/2;
    float dimyh = dimy/2;
    
    {
      BodyDef bd = new BodyDef();
      Body ground = world.createBody(bd);

      ChainShape shape = new ChainShape();
      Vec2[] vertices = {new Vec2(-dimxh, 0), new Vec2(dimxh, 0), new Vec2(dimxh, dimy), new Vec2(-dimxh, dimy)};
      shape.createLoop(vertices, 4);
      ground.createFixture(shape, 0.0f);
      
      world.bodies.add(ground, false, color(0), true, color(0), 1f);
    }
    
    

    {
      PolygonShape shape = new PolygonShape();
      ParticleGroupDef pd = new ParticleGroupDef();
       
      pd.flags = 0
         | ParticleType.b2_waterParticle
         | ParticleType.b2_viscousParticle
         | ParticleType.b2_colorMixingParticle
//         | ParticleType.b2_powderParticle
//         | ParticleType.b2_springParticle
//         | ParticleType.b2_tensileParticle
         ;
      
      float sx = dimxh * 0.25f;
      float sy = dimyh * 0.95f;
      
      shape.setAsBox(sx, sy, new Vec2(-dimxh/2, dimyh), 0);
      pd.shape = shape;
      pd.setColor(new Color3f(0.00f, 0.2f, 1));
      world.createParticleGroup(pd);
      
      shape.setAsBox(sx, sy, new Vec2(+dimxh/2, dimyh), 0);
      pd.shape = shape;
      pd.setColor(new Color3f(1.00f, 0.2f, 0.00f));
      world.createParticleGroup(pd);
    }
  }