please help with local versus global positioning for orbiting meshes

Recommended Posts


I've never done any 3d programming like this before so I'm probably doing something stupid.

I'm messing around with the idea of making an RTS and my stumbling block in developing that is that I can't work out how to place an object on the surface of the planets.  This may be a bad idea but it's fun learning regardless.  I'm blown away by how awesome babylonjs is.

I have made a playground which should place a green sphere on the surface of the planet where you click but the rotation is off...


Any ideas what I'm doing wrong?  I've read a bunch of the forums posts here and tried some of the other things suggested but they don't seem to apply.

Thanks in advance....

Share this post

Link to post
Share on other sites

Hi elvisor, welcome to the forum.  https://www.babylonjs-playground.com/#MZDDK#7

Not a perfect playground, as it doesn't allow click-to-place boxes.  There is a better playground around, but I lost it.  :)

Lines 109-112 do it... rotationFromAxis is the secret, I think.

When you pick/click on a sphere, the pickingInfo object has some "stuff" on it.  One "stuff" is a method called .getNormal().   It is the angle (the normal) of the triangular face that you clicked-on (on the sphere).

That is the angle you need... to place a mesh "orthogonal" or "perpendicular" to the clicked face.  But there is also a pickingRay solution... but I don't know much about that.

Anyway, I did a bunch of forum and playground searching for rotationFromAxis, but again, I am hurried so I did a bad job.  I couldn't find the playground I had in mind.

But maybe... this is enough to help you.  At least you have more to try.  I hope I am on-subject. 

Usually, when programmers want to click mesh onto the surface of a planet, they want it to rotate so that it is perpendicular to the planet surface, and I think that's what you want.

You should use a tall cylinder for testing... instead of a sphere.  A telephone pole.  They are easy to test-with, because... the telephone pole must "stand upright" at the place you picked (for success).  It is easy to see when the rotation is right/wrong.

Hopefully, others are nearby to do further help.  I'll be back later, too... but it is unlikely that I will be any smarter.  :)

Share this post

Link to post
Share on other sites

Thanks Wingnut, I think you're helping with a future problem after my current problem though.  I've switched to cylinders as you suggested and regardless of which way the cylinders are standing on the planet surface they're not being placed in the location where I've clicked.

An interesting post I found which seems a little bit similar to the future problem.. but I'm still stuck on the current problem... https://stackoverflow.com/questions/26907686/babylon-js-place-a-plane-normal-to-the-clicked-surface

Edited by elvisior
added a link to another post

Share this post

Link to post
Share on other sites

Ohhh... ok, sorry.  When you said "the rotation was off", I thought you meant the rotation on the placed green sphere.  I asked myself "how does he know the rotation is off... when he's using a sphere?"  heh.

You meant... well, I now know what you meant.  Sorry about that.


I ONLY tried to make your playground a bit simpler, so forum helpers would like it better.  When doing that, it started working better.  hmm.

Yeah, this rocks planet is not spinning/orbiting, and its 'orbitsAround' is disabled.  You are on the right track.  Good troubleshooting, E! 

I think picking... uses a pickingRay from camera to picked-point, and the camera alpha rotation in your renderLoop... may be causing some problems.  Not sure yet... still studying.  I and others may comment soon, and keep reporting discoveries, thx.

Share this post

Link to post
Share on other sites


Yeah, its a big fat playground... difficult to troubleshoot.

Can you shrink it to super-slim size, and still show crash, Elvi?

Helpers:  Generally, just click on canvas, and then hit the 't' key to start/stop particle trail.

For me, in FF 52 ESR, stable BJS works, latest BJS version... crashes Firefox... "Your tab has crashed" screen... rare.

Further tests were inconsistent... no more crashes... but sometimes 't' key works, sometimes not.


elvisior... to help with bug-fix, can you try to make that playground TINY TINY TINY... and still have the 't' key work/crash like it is doing now?

Likely, it is something particles-related (duh). 

Elvi... if you can remove EVERYTHING from that playground... except the bug-causing code, and basic mesh/lights... then that would make bug-finding MUCH easier and faster.

Try for 30 lines of code, or less... and still show bug/crash.  Good luck.  I can help, too, but... kind of busy in real life right now.

Share this post

Link to post
Share on other sites

Hi again!  I get an instant "out of memory" error in firefox 52 ESR... but... if I change line 86 to be...

planets['planetTrail'] = new BABYLON.GPUParticleSystem("planetTrail", { capacity:100000, randomTextureSize: 4096 }, scene);

... it works for me, in FF.  1 million capacity was too big for my puppy-puter, apparently.  :)

In my IE 11.0.9600.18097, I get "invalid character" playground error, with no line number available (with 1 million capacity OR 100,000 capacity).

Let's ping @Deltakosh again... see if this playground is tolerable, see if he has some ideas.  Let's request info from others, too.  Maybe others have seen this problem and can offer help/info.

Elvisior, could you please try https://www.babylonjs-playground.com/index.html#M37848#7

That is the 100,000 capacity version.  Maybe we have found some evidence/secret to the problem, eh?  (Wingnut crosses fingers and toes for good luck.)  :)

PS:  Thanks for the reduced-size playground/tests... that was nice of you to do for us.  Bug-finding/limitation-finding... could be much easier, now.

Share this post

Link to post
Share on other sites

I've been off learning about electron and node for how I could possibly make this a cross platform app.

I've hit a weird issue.. I thought i had this kind of working as per: https://www.babylonjs-playground.com/indexStable.html#H6XJZ8#95

But if I hit save from the playground and then try and run it from the saved version the columns aren't being placed in the correct location.

So in summary... https://www.babylonjs-playground.com/indexStable.html#H6XJZ8#95 works but the zip attached below which is the result of having hit save from the playground does not.

I'm confused.. 

sample (2).zip

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.