wade Posted July 18, 2018 Share Posted July 18, 2018 Please try this playground, when you click on the balls, they will pop, and in the mean while a particle system will emit particles. This is working fine with Edge, but in chrome the particle system cannot restart for the 3rd click and so forth. And both the _started and _stop properties are set to "true", this is strange. : https://www.babylonjs-playground.com/#7149G4#19 playground code: var createScene = function () { var scene = new BABYLON.Scene(engine); scene.clearColor = BABYLON.Color3.Purple(); var camera = new BABYLON.FreeCamera("Camera", new BABYLON.Vector3(0, 0, -20), scene); camera.attachControl(canvas, true); camera.checkCollisions = true; camera.applyGravity = true; camera.setTarget(new BABYLON.Vector3(0, 0, 0)); var light = new BABYLON.DirectionalLight("dir02", new BABYLON.Vector3(0.2, -1, 0), scene); light.position = new BABYLON.Vector3(0, 80, 0); // Shadows var shadowGenerator = new BABYLON.ShadowGenerator(2048, light); // Physics scene.enablePhysics(null, new BABYLON.CannonJSPlugin()); scene.enablePhysics(null, new BABYLON.OimoJSPlugin()); var fountain = BABYLON.Mesh.CreateBox("foutain", 0.01, scene); fountain.visibility = 0.1; var createNewSystem = function(newPosition) { var particleSystem; if (BABYLON.GPUParticleSystem.IsSupported) { console.log("GPU supported!") particleSystem = new BABYLON.GPUParticleSystem("particles", { capacity:1000000 }, scene); particleSystem.activeParticleCount = 200000; } else { particleSystem = new BABYLON.ParticleSystem("particles", 50000 , scene); } particleSystem.emitRate = 10000; particleSystem.particleEmitterType = new BABYLON.SphereParticleEmitter(1); particleSystem.particleTexture = new BABYLON.Texture("/textures/flare.png", scene); particleSystem.maxLifeTime = 10; particleSystem.minSize = 0.01; particleSystem.maxSize = 0.1; particleSystem.emitter = fountain; //fountain.position = newPosition; particleSystem.disposeOnStop = false; particleSystem.targetStopDuration = 1; return particleSystem;; } particleSystem = createNewSystem(); var materialAmiga = new BABYLON.StandardMaterial("amiga", scene); materialAmiga.diffuseTexture = new BABYLON.Texture("textures/amiga.jpg", scene); materialAmiga.emissiveColor = new BABYLON.Color3(0.5, 0.5, 0.5); materialAmiga.diffuseTexture.uScale = 5; materialAmiga.diffuseTexture.vScale = 5; var materialAmiga2 = new BABYLON.StandardMaterial("amiga", scene); materialAmiga2.diffuseTexture = new BABYLON.Texture("textures/amiga.jpg", scene); materialAmiga2.emissiveColor = new BABYLON.Color3(0.5, 0.5, 0.5); // Spheres var y = 0; var particleSystems = {}; for (var index = 0; index < 100; index++) { // Material var sphere = BABYLON.Mesh.CreateSphere("Sphere" + index, 16, 3, scene); sphere.material = materialAmiga; sphere.position = new BABYLON.Vector3(Math.random() * 20 - 10, y, Math.random() * 10 - 5); shadowGenerator.addShadowCaster(sphere); sphere.physicsImpostor = new BABYLON.PhysicsImpostor(sphere, BABYLON.PhysicsImpostor.SphereImpostor, { mass: 1 }, scene); var goToColorAction = new BABYLON.InterpolateValueAction(BABYLON.ActionManager.OnPickTrigger, light, "diffuse", BABYLON.Color3.Red(), 1000, null, true); var popAction = new BABYLON.ExecuteCodeAction(BABYLON.ActionManager.OnPickTrigger, () => { createNewSystem() }); sphere.actionManager = new BABYLON.ActionManager(scene); sphere.actionManager.registerAction(new BABYLON.ExecuteCodeAction(BABYLON.ActionManager.OnPickTrigger, (evt) => { evt.source.dispose(); fountain.position = evt.source.absolutePosition; //console.log(particleSystem); particleSystem.start(); })); sphere.actionManager.registerAction(new BABYLON.InterpolateValueAction(BABYLON.ActionManager.OnPointerOutTrigger, sphere, "scaling", new BABYLON.Vector3(1, 1, 1), 150)); sphere.actionManager.registerAction(new BABYLON.InterpolateValueAction(BABYLON.ActionManager.OnPointerOverTrigger, sphere, "scaling", new BABYLON.Vector3(1.1, 1.1, 1.1), 150)); y += 2; } // Link var spheres = []; for (index = 0; index < 10; index++) { sphere = BABYLON.Mesh.CreateSphere("Sphere0", 16, 1, scene); spheres.push(sphere); sphere.material = materialAmiga2; sphere.position = new BABYLON.Vector3(Math.random() * 20 - 10, y, Math.random() * 10 - 5); shadowGenerator.addShadowCaster(sphere); sphere.physicsImpostor = new BABYLON.PhysicsImpostor(sphere, BABYLON.PhysicsImpostor.SphereImpostor, { mass: 1 }, scene); } for (index = 0; index < 9; index++) { spheres[index].setPhysicsLinkWith(spheres[index + 1], new BABYLON.Vector3(0, 0.5, 0), new BABYLON.Vector3(0, -0.5, 0)); } // Box var box0 = BABYLON.Mesh.CreateBox("Box0", 3, scene); box0.position = new BABYLON.Vector3(3, 30, 0); var materialWood = new BABYLON.StandardMaterial("wood", scene); materialWood.diffuseTexture = new BABYLON.Texture("textures/crate.png", scene); materialWood.emissiveColor = new BABYLON.Color3(0.5, 0.5, 0.5); box0.material = materialWood; shadowGenerator.addShadowCaster(box0); // Compound var part0 = BABYLON.Mesh.CreateBox("part0", 3, scene); part0.position = new BABYLON.Vector3(3, 30, 0); part0.material = materialWood; var part1 = BABYLON.Mesh.CreateBox("part1", 3, scene); part1.parent = part0; // We need a hierarchy for compound objects part1.position = new BABYLON.Vector3(0, 3, 0); part1.material = materialWood; shadowGenerator.addShadowCaster(part0); shadowGenerator.addShadowCaster(part1); shadowGenerator.useBlurExponentialShadowMap = true; shadowGenerator.useKernelBlur = true; shadowGenerator.blurKernel = 32; // Playground var ground = BABYLON.Mesh.CreateBox("Ground", 1, scene); ground.scaling = new BABYLON.Vector3(100, 1, 100); ground.position.y = -5.0; ground.checkCollisions = true; var border0 = BABYLON.Mesh.CreateBox("border0", 1, scene); border0.scaling = new BABYLON.Vector3(1, 100, 100); border0.position.y = -5.0; border0.position.x = -50.0; border0.checkCollisions = true; var border1 = BABYLON.Mesh.CreateBox("border1", 1, scene); border1.scaling = new BABYLON.Vector3(1, 100, 100); border1.position.y = -5.0; border1.position.x = 50.0; border1.checkCollisions = true; var border2 = BABYLON.Mesh.CreateBox("border2", 1, scene); border2.scaling = new BABYLON.Vector3(100, 100, 1); border2.position.y = -5.0; border2.position.z = 50.0; border2.checkCollisions = true; var border3 = BABYLON.Mesh.CreateBox("border3", 1, scene); border3.scaling = new BABYLON.Vector3(100, 100, 1); border3.position.y = -5.0; border3.position.z = -50.0; border3.checkCollisions = true; var groundMat = new BABYLON.StandardMaterial("groundMat", scene); groundMat.diffuseColor = new BABYLON.Color3(0.5, 0.5, 0.5); groundMat.emissiveColor = new BABYLON.Color3(0.2, 0.2, 0.2); groundMat.backFaceCulling = false; ground.material = groundMat; border0.material = groundMat; border1.material = groundMat; border2.material = groundMat; border3.material = groundMat; ground.receiveShadows = true; // Physics box0.physicsImpostor = new BABYLON.PhysicsImpostor(box0, BABYLON.PhysicsImpostor.BoxImpostor, { mass: 2, friction: 0.4, restitution: 0.3 }, scene); ground.physicsImpostor = new BABYLON.PhysicsImpostor(ground, BABYLON.PhysicsImpostor.BoxImpostor, { mass: 0, friction: 0.5, restitution: 0.7 }, scene); border0.physicsImpostor = new BABYLON.PhysicsImpostor(border0, BABYLON.PhysicsImpostor.BoxImpostor, { mass: 0 }, scene); border1.physicsImpostor = new BABYLON.PhysicsImpostor(border1, BABYLON.PhysicsImpostor.BoxImpostor, { mass: 0 }, scene); border2.physicsImpostor = new BABYLON.PhysicsImpostor(border2, BABYLON.PhysicsImpostor.BoxImpostor, { mass: 0 }, scene); border3.physicsImpostor = new BABYLON.PhysicsImpostor(border3, BABYLON.PhysicsImpostor.BoxImpostor, { mass: 0 }, scene); part0.physicsImpostor = new BABYLON.PhysicsImpostor(part0, BABYLON.PhysicsImpostor.BoxImpostor, { mass: 2, friction: 0.4, restitution: 0.3 }, scene); return scene; } Quote Link to comment Share on other sites More sharing options...
Guest Posted July 18, 2018 Share Posted July 18, 2018 This is because Chrome supports Webgl2 and thus uses the GPUParticleSystem instead of regular particles. The problem is that GPUParticleSystem needs to be disposed and recreated: http://doc.babylonjs.com/babylon101/particles#stopping-a-gpu-particle-system Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.