Jump to content

Physics Materials?


Pryme8
 Share

Recommended Posts

Hi P8!    Friction, restitution, mass, these are characteristics of a "physics impostor" and not of the mesh itself.  Pardon my over-teaching... I don't know your experience.  You can think of the impostor as an invisible "inner mesh".  After mesh.setPhysicsState(...), the impostor... essentially, commandeers the mesh... controlling it's forces and movements.

Let's pretend that you have a 3-colored box such as this.  Let's pretend that the blue sides = ice, the red sides = sandpaper, and the green sides = wood.  You get the idea. You must determine the orientation of the physics impostor... to determine which surface is currently contacting the ground. The physics impostor is color blind.  It has no material, and cannot see the box colors.  I don't know which physics engine you are using, but the physics body that is returned ( var body = mesh.setPhysicsState(..) )...  has an orientation property.  (or body.body does, depending upon the engine).  It is likely a Quaternion, but look for a toEuler() or toEulerAngles() on any Quaternion... you will often find them.  Ask if you need more help finding it and seeing it's values.

Maybe more important... the mesh.rotationQuaternion.toEulerAngles() might be staying in sync with physics body orientation.  So, perhaps you can use that method to deduce which color-side of the box... is currently contacting the ground or sliding-ramp.  Smarter people than I are nearby... should you have troubles.

On another subject, spheres have no friction, so if you are using a sphere... you will see little or no friction affect/effect.  Spheres do not provide enough surface contact.  Possibly, you can get SOME sphere surface friction... by using a physics heightMap ground (meshImposter - CannonJS only) to create a ground with tiny little bumps... spread uniformly.  Do this by using a bitmap image for the heightMap... that has alternating pixels white-lightgray-white-lightgray, etc. 

(Actually, you can use white-black-white-black, etc... and then set the max-height of the heightMap... to a tiny value.)

Search the forum carefully, because SOME similar tests were done, and conversations have happened about friction (and air-resistance) for spheres.

Lastly, Schteppe, the author of CannonJS... recently visited our forum (my nipples got erect cuz he's a superstar), and he told us that we should "expose" a way for programmers to monitor and intervene during each "step" (schtepp?) of a physics motion, and with that... we could apply a force PER STEP  (wind resistance, sphere friction, curved trajectories, etc). 

Just after that, local superhero Raanan... reprogrammed our physics plugins.  I have not looked at the new interfaces... but I hear they ROCK!  SO... ahem... using our render loop, you can continuously apply some resisting forces to "stuff".  (Although we could ALWAYS do that by using a little continuous applyImpulse(), too.  hmm.)  :)

I hope this helps.  Stay in touch.  Thanks for hanging out with us... I look forward to your experiments/playgrounds.

Link to comment
Share on other sites

I figured out that the friction was not a divider but a multiplier  setting my fiction to 0.1 ended up working.

Also, what I mean is if I have lets say a Grass material, and a Stone material on the same mesh, is there a way like in unity to have the material of the mesh matter?

I figured I could always split the object up, but seeing how some of the areas of texture will transition in areas other then polygons it seems this method will be limited.

Link to comment
Share on other sites

I think it can be done, but it just hasn't been built-into BJS, yet (or an extension).  Not that I know-of. 

You know how it would work, though.  Build a set of 3 materials as stated in my last post, over-load them with a .friction value, then build "the determiner"... some unGodly contraption that uses UVs and physics to determine which material is rubbing against which material, and how large of a surface (if possible).  Then live-set the friction values of the mesh impostors, depending upon what 'the determiner' wants.  If the object is tumbling, and each bounce is landing on a different material (or a combination of materials @ intersection between mats), you have your work cut-out for you.  :o

Gruesome project!  Please wait for others to add answers, as this puppy is pretty far over my head.  :)

Link to comment
Share on other sites

Wingnut, your a boss! you just inspired me to figure this out!  I think what I am going to do it write a sub process, that takes the contact point from the physics method and checks that point for the closest point on the actual mesh check the uV of that point and then have the meshs Imposters change properties.

So to make this happen first I need to figure out:
- How to listen for a "hit" from the physics system and have a callback
- Convert Location of hit to Global coordinates, and then check this global point for the closest uV point on the original mesh
- Get the information for the material from the current UV in the form of [Texture A: 0.8, Texture: B 0.2] in case there are blended textures
- Check my object that I constructed to hold the Texture references to their physical properties and do what ever blending is needed so like in the above example of a return if Texture A's friction was stored as 0.5 and texture B was a friction of 1 so the blended physics properties would be like a 0.55 friction or something like that off the top of my head
- Change the Imposters Physics attributes to match response from Object.

does this sound about right or am I a loony toon?

Link to comment
Share on other sites

haha!  I love it!  I think you've got a plan.  As far as sounding "right", I'm not sure there IS such a thing, here. 

Also, if possible, I would consider trying to incorporate SIMD and webWorkers... both of which I know ZERO about, but I hear good things.  Both are available in BJS... search the source for examples.  Good luck!

Link to comment
Share on other sites

Setting the friction and restitution when creating the mesh impostor creates a physics material for your physics body. This physics material will be used when the impostor collides against other meshes.

Changing it dynamically (if that is the question) will force you to recreate the physics material of this object (and, honestly, it is easier to recreate the physics body, due to initializations both oimo and cannon are doing to the rigid body objects).

Check restitution for example - 

http://www.babylonjs-playground.com/#STVJ2

vs 

http://www.babylonjs-playground.com/#STVJ2#1

you can see that the ball's restitution is not taken into account in this case - it's the ground's restitution that is important. Note also, that those factors are being taken into account only when the body actually collides. friction is not "air" friction. The ball will free fall until it collides against the ground.

Link to comment
Share on other sites

6 hours ago, Pryme8 said:

So to make this happen first I need to figure out:
- How to listen for a "hit" from the physics system and have a callback
- Convert Location of hit to Global coordinates, and then check this global point for the closest uV point on the original mesh
- Get the information for the material from the current UV in the form of [Texture A: 0.8, Texture: B 0.2] in case there are blended textures
- Check my object that I constructed to hold the Texture references to their physical properties and do what ever blending is needed so like in the above example of a return if Texture A's friction was stored as 0.5 and texture B was a friction of 1 so the blended physics properties would be like a 0.55 friction or something like that off the top of my head
- Change the Imposters Physics attributes to match response from Object.

Answering your questions:

1) There is an onCollide callback, added just now. I need to document it, so stay tuned.

2) you will get the collision point in world coordinates, and will have to find that yourself :) but PickingInfo does that nicely, check how it is being done there.

3) Not sure what you mean. I think you mix styling material (color, texture etc') with physics material, which is constant to the entire mesh/body

4) I need an explanation for this one :)

5) Same as 4 :)

But, and I know I repeat myself, I think you will get all your questions answered once I finish the documentation. My fault, I know, but it is first on my todo list, now that the challenge is over.

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...