Rotating world map data into flat plane

So I have probably a simple question but can’t get my head wrapped around it. So I have some data that’s basically Earth scale XYZ world coordinate data, the meshes origins’ are at world 0,0,0. It also includes other meshes (like the monkey) in world space too.

I’m already doing the equivalent this of this


using TransformNodes by find all the meshes world bounds, offsetting and scaling to a origin and a 10 unit area. Note doing this with ScalingNode->TransformNode->WolrdDataMesh so the map meshes still have their local space position at 0,0,0.

What I’m trying to do is some like this where the content has the correct orientation towards north and mesh data is correctly rotated to lie “flat”.

Was hoping there is a simplier was than doing simplex or simulated annealing. There might be a clever lookAt or slerp I’m not familiar with. Maybe I making too complicated and its some trig to rotate first?

Any ideas?

Hiya D! Cool project!

I am HIGHLY un-qualified for this, but… terms “orthogonal” and “perpendicular” might be good playground/forums search fodder, for this.

Ok, now for the two playgrounds I have bookmarked under my “orthogonals” category…

https://www.babylonjs-playground.com/#53YWDR#1

Click on box to place cylinders that are always oriented orthogonal to box. Notice the Dot and Cross directives in lines 50/51. That might be something worth investigating. :slight_smile: The .rotate() in line 53… is a .rotationQuaternion-based thing… and likely doesn’t affect Euler .rotation. I THINK… using a .rotate() method like that… tells BJS system to automatically install a .rotationQuaternion on that mesh, and use IT instead of .rotation property. Read-on for more about that. :slight_smile:

https://www.babylonjs-playground.com/#2C8LVE#16

After model-load, mouse-around on the canvas. The monkey’s head always stays “upright”, no matter what mesh surface-angle… the pointer crosses. “thoggin’”… staying orTHOGonal. :slight_smile:

See the ‘crossToRef’ in lines 111/112 of #16 PG? BABYLON.Vector3.CrossToRef(axis2, axis1, axis3); The ‘toRef’ part… is talking about the third parameter. The above directive means… calculate the Cross-product of axis2 and axis1, and store result in axis3. (in case you have low-experience in ‘toRef’ things). :slight_smile:

There’s other goodies in that same PG series, too. #17 rocks, #18 rocks, #19 rocks, #20 is a failure by Wingnut to make the rabbit model… do the same as the monkey does in #16. Way to fail, Wingy! :slight_smile:

Lots of .rotate() (pg#1) and mesh.rotationQuaternion (pg#16) stuff… which means that standard Euler-type mesh.rotation is not really used anymore. As you might know, if user wishes, or if BJS system NEEDS to use a Quaternion for mesh rotation, system or user installs a mesh.rotationQuaternion (esp needed for ‘p-mesh’… physics-active mesh). After installing it on a mesh, Euler .rotation property is essentially un-used, and system uses .rotationQuaternion instead (for THAT mesh’s rotation transforms).

Anyway… that’s something. A little intro to Dot and Cross and Quats… all in one gulp. And, that’s all the intelligence that I have… in this topic. I hope I was on-topic and understood the issue correctly. Stay tuned for more/wiser comments, as wanted. :slight_smile:

1 Like

@Wingnut thanks for the writeup.
On a box I get it, modified the first playground to have a sphere. https://www.babylonjs-playground.com/#53YWDR#2 and you see the undefined twisting that happens. I think you are right that its a combo of taking the normal (which i have) and doing a cross with (0,0,1). Will read through the others and see what I’m missing. Thanks again.

I modified that example to have Suzanne face straight down.
https://www.babylonjs-playground.com/#2C8LVE#22

However depending on what face normal you hit the rotation going from what I expect
image

to rotations in a different direction and the next face over on the box acts like what i’d expect.
image

Monkey keeps changing y-axis rotation (90/180-degree change?), when you don’t want it to?

Yeah, that’s classic quat stuff. Various values in the quaternion… are flipping signs… neg/pos… to avoid gimbal lock.

hehe. Do you believe THAT? If so, you’re easy. :slight_smile: (j/k) …but there might be SOME truth to what I say.

We’re going to need some Quaternion experts in here. There’s lots more methods on Quaternion class… to experiment-with - I’m scared of MOST of them. :slight_smile: @RaananW, are you within earshot? Can you visit? (I think he made first “Orthogonal Suzie” demo… and is a pro quat-wrangler.)

I’ll try to sum issue: While monkey is doing proper “orthogonal” rotations as it changes surfaces beneath, monkey is also changing the direction that its FACE… faces, and that is not wanted.

https://www.babylonjs-playground.com/#2C8LVE#23 (monkey spins around local Y - not wanted)

Sound right? I hope so. Calling all Quat-Masters… :slight_smile:

1 Like

I’ll try to sum issue: While monkey is doing proper “orthogonal” rotations as it changes surfaces beneath, monkey is also changing the direction that its FACE… faces, and that is not wanted.

Spot on. Also of note all of this happens on basically a sphere and always want the assets to be aligned in Babylon’s space towards Z+. I think those assumptions can help with the answer.

1 Like

@Wingnut there was enough to get me where I needed from the demos and reading up. Thanks again for taking the time! Truly appreciated

2 Likes

My pleasure. I’m glad you’re rolling - that’s great news. (hi5)

1 Like