dbawel Posted October 24, 2016 Share Posted October 24, 2016 Hello, What am I missing in scaling an object over time? I feel dumb even asking... The code attempt is below: setInterval(function() { for (i = 1; i < 35; i++){ var size = sphere.getBoundingInfo().boundingBox.extendSize; //cylinder1.scaling.multiply(new BABYLON.Vector3(2, 2, 2)); } cylinder1.scaling.x = (size + 1) cylinder1.scaling.y = (size + 1) cylinder1.scaling.z = (size + 1) console.log(i); } }, 1000); Thanks, DB Quote Link to comment Share on other sites More sharing options...
aWeirdo Posted October 24, 2016 Share Posted October 24, 2016 @dbawel http://www.babylonjs-playground.com/#NWAJU#1 ? dbawel 1 Quote Link to comment Share on other sites More sharing options...
dbawel Posted October 24, 2016 Author Share Posted October 24, 2016 Hi @aWeirdo - I've tried this with other logic, as I need to set a maximum for the mesh and it's imposter. However, I can't dispose the physices imposter - it simply won't dispose - although I have no trouble scaling it - but it slows down my scene from 60 fps to 10fps. Below is the code which should dispose of the imposter. All help would be deeply appriciated. Perhaps @Temechon and/or @adam might be of great assistance when I'm up against a deadline. cylinder1.setPhysicsState(BABYLON.PhysicsEngine.SphereImpostor, {mass: 0, restitution: 0.05}) var limitsize; var counter = 0; var looper = setInterval(function(){ counter++; cylinder1.scaling.x += 0.1; cylinder1.scaling.y += 0.1; cylinder1.scaling.z += 0.1; limitsize = cylinder1.scaling.x console.log("Counter is: " + counter); if (counter >= 35) { clearInterval(looper); cylinder1.physicsImpostor.dispose(); cylinder1.setPhysicsState(BABYLON.PhysicsEngine.SphereImpostor, {mass: 0, restitution: 0.05}) } }, 100); A link to the entire scene is here: http://qedsoft.com/DEMOS2014/PE_KYP/index17.html As always, I am grateful for any help in tackling this problem. Cheers, DB EDIT - I left out that this is on a canvas.addEventListener("pointerdown", onPointerDown, false); event and on the canvas.addEventListener("pointerup", onPointerUp, false); I use cylinder1.physicsImpostor.dispose(); But yet the collision imposter is not being disposed. I'm also using the Oimo.js physics engine. Quote Link to comment Share on other sites More sharing options...
adam Posted October 24, 2016 Share Posted October 24, 2016 I haven't looked at the PG, but you should be able to scale the physics body directly. I'm pretty sure there is a mesh.physicsImpostor.physicsBody.scale vector. Quote Link to comment Share on other sites More sharing options...
dbawel Posted October 24, 2016 Author Share Posted October 24, 2016 Even using this.physicsImpostor.forceUpdate(); does nothing when added. I hope I can find a solution by tomorrow, as sleep would be nice. Cheers, DB Quote Link to comment Share on other sites More sharing options...
Nabroski Posted October 24, 2016 Share Posted October 24, 2016 Yes, but what is the desired result? when i press the mouse a big sphere appears grows bigger, when i release the mouse, the sphere disappear and the balls surrounding it start to colliding each other and get out of screen. @dbawel Quote Link to comment Share on other sites More sharing options...
adam Posted October 24, 2016 Share Posted October 24, 2016 There isn't a scale vector for the physicsBody. You could do something like this though: http://www.babylonjs-playground.com/#1MJ09V#27 Quote Link to comment Share on other sites More sharing options...
Nabroski Posted October 24, 2016 Share Posted October 24, 2016 so the problem is that the balls are going out of screen ? sorry dump question. but its looks interesting, and i have few secs to investigate Quote Link to comment Share on other sites More sharing options...
adam Posted October 24, 2016 Share Posted October 24, 2016 5 minutes ago, Nabroski said: so the problem is that the balls are going out of screen ? I think the problem is that he needs the physics imposter to sync with the size of the mesh. He was trying to do it by creating a new imposter whenever the scale changed, but since the dispose function for the imposter wasn't working, he needed another solution. Quote Link to comment Share on other sites More sharing options...
Nabroski Posted October 24, 2016 Share Posted October 24, 2016 Okay. So you already solved it. Quote Link to comment Share on other sites More sharing options...
dbawel Posted October 24, 2016 Author Share Posted October 24, 2016 @Nabroski @adam- That was simply the last code I tried, as I have had no issues in scaling the mesh and it's imposter - it was just to show you a different method I was trying. I still need to dispose of the imposter(s) in the scene, as there will be many in the final scene which will be at a trade show running next week all day with people touching the scren to create areas to clear and then disappear. Any one know why I'm not able to dispose of the imposters? What I might do to dispose of them as expected? Thank you both for your help thus far, and I hope I can find a way to dispose of these - or the overhead will get high after periods of use. Cheers, DB Quote Link to comment Share on other sites More sharing options...
Nabroski Posted October 24, 2016 Share Posted October 24, 2016 @dbawel than dont use dispose() set restitution to 0 instead be creative Best Quote Link to comment Share on other sites More sharing options...
adam Posted October 24, 2016 Share Posted October 24, 2016 The removePhysicsBody function should probably be removing the body from the _tmpImpostersArray. https://github.com/BabylonJS/Babylon.js/blob/master/src/Physics/Plugins/babylon.oimoJSPlugin.ts#L216 https://github.com/BabylonJS/Babylon.js/blob/master/src/Physics/Plugins/babylon.oimoJSPlugin.ts#L25 edit: removePhysicsBody might not always be used for disposing a physics body. If that is the case, then there should be a disposePhysicsBody function that calls removePhysicsBody and then removes the body from the _tmpImpostersArray. Also, the mesh needs to release the imposter. dbawel 1 Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted October 24, 2016 Share Posted October 24, 2016 Ping @RaananW Quote Link to comment Share on other sites More sharing options...
dbawel Posted October 25, 2016 Author Share Posted October 25, 2016 Hello @adam, @Nabroski, @aWeirdo, and @Deltakosh - I tried removePhysicsBody and I get a console error telling me it doesn't exist. However, I was way overcomplicating my functions, as I wasn't quite certain when to use mesh.physicsImpostor.forceUpdate(); and if you use this or identify your imposter in any way within the function to dispose, the imposter simply won't dispose. So I completely rebuilt my function and now I simply dispose of the object without any other calls, and it automatically diposes of the imposter as well. But only if you ForceUpdate() the imposter when you are scaling or any other transforms; otherwise, the imposter still belongs to the mesh, but won't dispose the imposter when you dispose the mesh - an again, don't address the imposter or physics engine in any way within the function or the imposter won't dispose. I'm certain there are cercumstances where you are able to do this, but I haven't discovered them as of yet. I'm certain it's all in where you call your functions in each script and/or loop. Wow, was this a tough thing to discover. Thanks for looking at this one. I know Oimo.js pretty well now. Solved! Yea! Oimo.js rules! DB GameMonetize 1 Quote Link to comment Share on other sites More sharing options...
RaananW Posted November 17, 2016 Share Posted November 17, 2016 (as in any other post of mine today - I apologize for being SO super late) forceUpdate will completely recreate the physics body of the selected impostor. The physics engine's object. The impostor will, of course, stay the same. Dispose SHOULD take care of the physics body as well, and if it doesn't, it is a bug. If someone wants to reproduce a playground of the bug, I will be more than happy to look into it! Thanks guys! 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.