Has anyone tried using fluid effects with AR using 8th Wall?
8th Wall uses FreeCamera but then adds its own behaviour that utilises the device camera like this: camera.addBehavior(XR8.Babylonjs.xrCameraBehavior())
I can enableFluidRenderer() but as soon as I addParticleSystem to that renderer the 8th Wall camera goes blank. Does anyone have any ideas of what I could try to get them working together?
Unfortunately I can’t make a BabylonJS Playground because its using an 8th Wall camera. However I can point to an 8th Wall template and the code to add. Its this template babylon.js: Place Ground | 8th Wall | 8th Wall and you’ll need to replace the code in babylonjs-scene-init.js with this
let engine
let scene
let camera
const initXrScene = () => {
const light = new BABYLON.DirectionalLight('light', new BABYLON.Vector3(-5, -10, 7), scene)
light.intensity = 1.0
camera.position = new BABYLON.Vector3(0, 2, -2)
}
export const startScene = async (canvas) => {
engine = new BABYLON.Engine(canvas, true)
scene = new BABYLON.Scene(engine)
camera = new BABYLON.FreeCamera('camera', new BABYLON.Vector3(0, 0, 0), scene)
initXrScene({scene, camera})
// Special behavior that turns camera into AR camera
camera.addBehavior(XR8.Babylonjs.xrCameraBehavior())
engine.runRenderLoop(() => scene.render())
window.addEventListener('resize', () => engine.resize())
const sphere = BABYLON.MeshBuilder.CreateSphere('sphere', {diameter: 1}, scene)
sphere.position.x = 0.2
const material = new BABYLON.StandardMaterial('mat', scene)
material.diffuseColor = BABYLON.Color3.Red()
material.alpha = 0.5
sphere.material = material
const numParticlesEmitRate = 1500 * 2
const fluidRenderer = scene.enableFluidRenderer()
const particleSystem = new BABYLON.ParticleSystem('particles', 40000, scene)
particleSystem.particleTexture = new BABYLON.Texture(
'https://playground.babylonjs.com/textures/flare32bits.png',
scene
)
particleSystem.blendMode = BABYLON.ParticleSystem.BLENDMODE_ADD
// Where the particles come from
particleSystem.createConeEmitter(4, Math.PI / 2)
// Colors of all particles
particleSystem.color1 = new BABYLON.Color4(0.4, 1.5, 0.3, 1.0)
particleSystem.color2 = new BABYLON.Color4(0.4, 1.5, 0.3, 1.0)
particleSystem.colorDead = new BABYLON.Color4(0, 0, 0.2, 0.0)
particleSystem.colorDead = new BABYLON.Color4(0.4, 1.0, 0.3, 1.0)
// Size of each particle (random between...
particleSystem.minSize = 0.25
particleSystem.maxSize = 0.25
// Life time of each particle (random between...
particleSystem.minLifeTime = 2.0
particleSystem.maxLifeTime = 2.5
// Emission rate
particleSystem.emitRate = numParticlesEmitRate
// Set the gravity of all particles
particleSystem.gravity = new BABYLON.Vector3(0, -10.81, 0)
// Speed
particleSystem.minEmitPower = 2.5
particleSystem.maxEmitPower = 6.5
particleSystem.updateSpeed = 0.02
// Start the particle system
particleSystem.preWarmCycles = 60 * 8
// THIS BIT RUINS THE XR CAMERA FEED
fluidRenderer.addParticleSystem(particleSystem, false)
particleSystem.start()
}
If anyone has any suggestions how I can make this easier for people (likely @Evgeni_Popov ) to test pls mention it here
That works! There is a file in the 8th Wall workspace called head.html which imports the BabylonJS files and other files you might need, such as jszip.min.js. You can simply change the BabylonJS files being imported to the latest version, which is what I’ve done.
Also people, remember to put that window.setTimeout code after running the fluid renderer. On phone devices the contents of the timeout must happen after user approves of camera, etc… and the fluid animation begins
@Evgeni_Popov you’ve just enabled fluid particles for AR. You’re a legend mate!