Jump to content

Dumb question about using intervals to scale an object


dbawel
 Share

Recommended Posts

Hello,

What am I missing in scaling an object over time? I feel dumb even asking...:unsure: 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

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

@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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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!:D

DB

Link to comment
Share on other sites

  • 4 weeks later...

(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!

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...