Jump to content

how to rotate meshes indepedently


vahith
 Share

Recommended Posts

Hi vahith!  I started making a new version:  http://www.babylonjs-playground.com/#VMFNH#10  ... but I got interrupted and had to SAVE before I finished.  Maybe you can finish.

 

One way to do this... is install some keyUp/keyDown listeners.  Let's use the SHIFT key.  SHIFTED pointer-drag... rotates the object.  Un-shifted... translates it.  (later, maybe CONTROL = scale the object, eh?)

 

.moveWithCollisions is still misnamed, in my opinion.  It should be .translateWithCollisions, and it should have a "sister function" called .rotateWithCollisions.  But it's not here yet (or ever), so you will need to write your own .rotateWithCollisions() function, I suppose.

 

Once you get THAT done, it's easy. 

 

In your onPointerMove function, first thing... check for SHIFT key being up/down.  IF DOWN... take the rotation branch (rotateWithCollisions). 

 

If UP, take the translation branch (moveWithCollisions). 

 

Again, you will need to make your own .rotateWithCollisions()... likely somewhat similar to .moveWithCollisions().

 

As a possible alternative, our ActionManager is capable of all sorts of magic, and can listen for triggers from all three mouse buttons.  You could use these triggers to change "mode" of your mouse/pointer.  Right-click once, you're in rotate mode.  Right-click again, you're in scale mode.  Do it again, you're in translate [position] mode. Browser context popup menus (right-click panels) might get in the way, and need to be disabled, though.

 

Just some ideas, here.  I'm not sure if they are good or correct.  Be well, good luck, keep us posted.  thx.

Link to comment
Share on other sites

Hi vahith.  All of the BJS source code is kept at a GitHub repository.  Go there, and type moveWithCollisions into the search field at the top... and hit enter.  The top file in the search return...  Babylon/Mesh/babylon.abstractMesh.js ...is the one you want.  Click that link to show the source code.

 

Now it's time to use your browser's search-in-this-webpage (maybe control-f).  Search for the same... moveWithCollisions.  You'll find it at lines 589-599.

 

Since we have now found the function, let's copy and paste a slightly-modified version... somewhere... like here:

 // moveWithCollisions...var moveWithCollisions = function (velocity) {    var globalPosition = this.getAbsolutePosition();    globalPosition.subtractFromFloatsToRef(0, this.ellipsoid.y, 0, this._oldPositionForCollisions);    this._oldPositionForCollisions.addInPlace(this.ellipsoidOffset);    this._collider.radius = this.ellipsoid;    this.getScene()._getNewPosition(this._oldPositionForCollisions, velocity, this._collider, 3, this._newPositionForCollisions, this);    this._newPositionForCollisions.subtractToRef(this._oldPositionForCollisions, this._diffPositionForCollisions);    if (this._diffPositionForCollisions.length() > BABYLON.Engine.CollisionsEpsilon) {        this.position.addInPlace(this._diffPositionForCollisions);    }};

You can use code like this... within your project... after you change all 'this' to 'myMesh', or something similar.

 

If you follow my yappings in The Wingnut Chronicles, you might have seen me "localize" (clone) the Babylon particle system in my recent demos.  I take a copy of some framework code, and put it into my playground or project, and then make calls to IT instead-of calls to the framework version.  Then, I can modify the function or system, and not effect/affect any of the other framework users. (wink to DK about affect/effect)  :)

 

How does one copy and modify moveWithCollisions... to create rotateWithCollisions?  I have no idea.  It will take a better coder than I (there's MANY)... to create rotateWithCollisions.  Sorry.  I have very little experience with the BJS collisions system.

 

Some might ask WHY do we need a rotateWithCollisions().  Well, it's because a mesh (character) could be a long boat, with an elongated collision ellipsoid (it runs the length of the boat).  If you try to turn the boat and the rear of the boat hits the dock during a rotation, we want to register that collision event.  X and Z collision-ellipsoid stretching/elongation... is the reason we need it (in my opinion).  But maybe there are better ways to do this.  Suggestions are welcome, from anyone, thanks.

 

Experts, if there's someone who could help code a rotateWithCollisions function for Vahith and the rest of us... please do.  THANKS!  And if you happen to create scaleWithCollisions, that would be handy, too. 

 

Vahith, if you write the function, share it with us here, if you please.  thx! 

 

Maybe someday soon, we will have a tutorial all about 'moving' things when non-physics collisions are active.  And maybe we'll include a section on moving things when physics are active, too.  Maybe someday, we'll have...

 

"Captain Vahith's Moving-Things Toolkit v1.0", eh?  :)  Good luck, be well.  Sorry for the long post.

Link to comment
Share on other sites

Vahith (and others)... I started a new playground for this issue.

http://playground.babylonjs.com/#1TZI08

I cleaned a few things, turned the scene so we are looking in a general +z direction, and I managed to get control, alt, and shifted clicks/drags... working semi-good. (bucky-clicks do alerts).

I grew-up calling alt, shift, or ctrl keys... bucky keys.  It's a term that is as old as I am.  :)  Yay buckies!

The only problem so far... is that after a "bucky click" (a click that uses one of the buckies)... the mesh seems to get stuck onto the end of the pointer (firefox 30).  Weird.  I still have something wrong in the event handlers.  I'm not very good at event handling.

But, this playground is a good test jig to work-on rotateWithCollisions, scaleWithCollisions, and translateUpAndDown functions.

I might get more time to work on this, but, maybe not.  Feel free to advance this thing at will, forum-users and/or Vahith.  Kick it's butt!  :)

Link to comment
Share on other sites

I advanced it a bit.

http://playground.babylonjs.com/#1TZI08#1

Shifted mouse drag is working... a little bit (basic y-axis rotation). 

To test rotation-collision, I x-scaled box3, and did a multiply of that scaling... to the box3 ellipsoid.  (To be brief, I made the ellipsoid as big as the box.  Verify that by dragging it against the other boxes)  

Then, I activated a BASIC .rotateWithCollisions().  It rotates... but is not yet checking for collisions.

I hope I am not ruining your experimenting fun, vahith.  You now have the beginnings of your future-famous rotateWithCollisions function.  It might take major framework changes to get collisions for rotations... operational.  :o

Anyway, my code is your code is our code.  Steal, adjust, ignore, it's all yours.  You "picked" an interesting project, V.   Party on!  :)

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