|
 |
I used one of those fancy new tools to generate some starter code.
I think creating a liquid object and then using insidedness tests would be the
way to go. Maybe define a central axis to correct everything towards - that
would even work with a tilted container.
#macro Bubble(id, startX, startZ, startY, radius, fluidMinX, fluidMaxX,
fluidMinZ, fluidMaxZ, fluidSurfaceY)
// Rise speed based on radius
#local riseSpeed = radius * 2;
// Vertical position based on clock
#local currentY = startY + (clock * riseSpeed);
#if (currentY > fluidSurfaceY)
#local currentY = fluidSurfaceY;
#end
// Expansion as bubble rises
#local scaleFactor = 1 + (currentY - startY) / (fluidSurfaceY - startY) * 0.2;
#local currentRadius = radius * scaleFactor;
// Turbulence: horizontal wobble using sine waves
#local wobbleX = sin(clock * 10 + id) * 0.2;
#local wobbleZ = cos(clock * 10 + id) * 0.2;
// Apply turbulence to position
#local posX = startX + wobbleX;
#local posZ = startZ + wobbleZ;
// Clamp to container bounds
#if (posX < fluidMinX + currentRadius)
#local posX = fluidMinX + currentRadius;
#end
#if (posX > fluidMaxX - currentRadius)
#local posX = fluidMaxX - currentRadius;
#end
#if (posZ < fluidMinZ + currentRadius)
#local posZ = fluidMinZ + currentRadius;
#end
#if (posZ > fluidMaxZ - currentRadius)
#local posZ = fluidMaxZ - currentRadius;
#end
// Create the bubble
sphere {
<posX, currentY, posZ>, currentRadius
texture {
pigment { color rgbt <1, 1, 1, 0.9> }
finish { specular 0.6 reflection 0.1 }
}
interior { ior 1.0 }
}
#end
#declare fluidMinX = -2;
#declare fluidMaxX = 2;
#declare fluidMinZ = -2;
#declare fluidMaxZ = 2;
#declare fluidSurfaceY = 10;
#declare bubbleCount = 10;
#declare i = 0;
#while (i < bubbleCount)
#declare startX = RRand(fluidMinX + 0.3, fluidMaxX - 0.3, i);
#declare startZ = RRand(fluidMinZ + 0.3, fluidMaxZ - 0.3, i + 100);
#declare startY = RRand(0.5, 2.0, i + 200);
#declare radius = RRand(0.1, 0.3, i + 300);
Bubble(i, startX, startZ, startY, radius, fluidMinX, fluidMaxX, fluidMinZ,
fluidMaxZ, fluidSurfaceY)
#declare i = i + 1;
#end
If interested, I have access to a better verion, and GPT-5 at work, which seems
to be able to spit out a ton of higher-level code.
There's still a lot of mistakes regarding lowercase reserved identifiers,
macro-vs-function, passing undeclared identifiers into "functions", etc.,
however it gives you a lot of preliminary ideas to work with, and can help
implement tricky equations in code a lot faster.
-BW
Post a reply to this message
Attachments:
Download 'bubblephysics.png' (106 KB)
Preview of image 'bubblephysics.png'

|
 |