Bubbles fluidsim script

i’m making a particle-generator for bubbles… it will generate a random start point (x, y, and z coords.) and then make an ipo for the bubble rising to the top, and make duplicate objects (spheres) to act as fluidsim obsticles.

here’s my technical test w/o using the blender api:

# Particle test script...
# Made to help me learn the math involved in
# making a particle emittor script.
# outline:
# import object (in this case make a cube)
# random x,y,z startinc coords
## math: get length of x dir. multiply by random (between 0 and 1)
## then add to lower coord of cube. =start x, same for y and z
# then animate z coord until it hits the top (highest z coord)
# stay for a set amt of time then go away


import random

# test for the function to make the ipo...
# this calculates changes in the z coordinate

def zIpo(z):
    # these will be settings eventually
    force = 1
    a = 0
    speed = 1
    maxSpeed = 10

    locz = [z]
    ## apperantly it starts at 0, locz[0] is the first number
    while z < objHighZ:
        a = a + 1
        z = z + speed
        if speed < maxSpeed:
            speed = speed + force
        locz.append(z)

    locz[len(locz)-1] = objHighZ
    return locz




print "ParticleMaker v0.01"
print "
 By Jesse McMillan"
print "
 Email me at xxx"

partNum = input("how many particles?")

# Get object here... for now just a cube at 0,0,0 (100x100x100)

objLowX = 0
objLowY = 0
objLowZ = 0
objHighX = 100
objHighY = 100
objHighZ = 100

# start loop

a = 1

while a < (partNum + 1):
    xRand = random.randint(objLowX, objHighX)
    yRand = random.randint(objLowY, objHighY)
    zRand = random.randint(objLowZ, objHighZ)
    locZIpo = zIpo(zRand)
    print "particle # ", a, "   x: ", xRand, "y: ", yRand
    print "z: ", locZIpo
    print "
"
    #here we write to an ipo.
    
    a = a + 1
    


output:

ParticleMaker v0.01

 By Jesse McMillan

 Email me at [email protected]
how many particles?4
particle #  1    x:  79 y:  79
z:  [85, 86, 88, 91, 95, 100]


particle #  2    x:  83 y:  26
z:  [32, 33, 35, 38, 42, 47, 53, 60, 68, 77, 87, 97, 100]


particle #  3    x:  31 y:  3
z:  [71, 72, 74, 77, 81, 86, 92, 99, 100]


particle #  4    x:  35 y:  75
z:  [97, 98, 100]

edit: does anyone know how to do this better or the real math?

edit # 2: i’m also going to change the scale later.

This is great!

I don’t know squat about programming Python (though I did some BASIC programming for my TRS-80, way back when) so I’m not sure if these ideas are helpful or not.

My first thoughts are:

  • random size bubbles within a given range

  • bubbles shouldn’t pass through fluid container
    -bubbles seem form on the surface of the container and drift away:
    http://video.google.com/videoplay?docid=-891332223822769802&q=bubbles

  • is it possible to define random points near the surface of a container (no closer than the radius of the largest possible bubble), have the bubble drift away from the surface based on the normals and then rise? or have the bubble generate right on the surface with near 0 volume then scale and drift away at the same time then rise?

hmm… good thoughts.

here’s what I think:

there should be inputs for both surface and volume generation (for differant types of fluids)
and deflection from other bubbles

the bubbles that generate in the middle should scale up as they rise and the bubbles on the surface should scale up, then rise (w/ option to continue scaling?).

bubbles on the surface wouldn’t really need random scaling because it would be a uniform size that they would gain enough bouyancy to rise to the top but the bubbles in the center will get some.

thanks for your help dadcantdraw… I’ll get started right away with my reserch into the python api (i didn’t know squat until about 3 days ago so i’m still living off the docs.)

edit: oh, and I’ll look into normals and trajectory.

edit # 2: ok, I don’t think you can access the normals from python but since i’m constrained to a cube already i’ll just work off of that to do it.
things to do:

inputs to add: amount of random (bubble size), amount of particles split to surface and volume generation, base bubble size (so differant sizes of bubbles and differant emitters can be combined.

functions to write:
one to find out which direction a bubble should go
one to animate size
various to link to blender

edit # 3: found normal module… all is well.

Is that a python script? if it is, what name I give to it?