Jump to content

Scaling a TransformCoordinate...


Recommended Posts

This code converts a Screen Pick in World Space down to a Local Space on one side of a rotated cube, so that user can move objects around on each face of the cube...

var invertParentWorldMatrix = northPlane.getWorldMatrix().clone();
var local_position = BABYLON.Vector3.TransformCoordinates(pickPointNext, invertParentWorldMatrix);
pickObj.position.addInPlace(moveVector);  //MOVE-TO-POSITION-.

Problem arises in optimizing the Cube. By making it small and scaling it up.

The translation above didn't scale. 

The pick still moves, but at tiny-scale.

So, the translation (above) needs to scale up to match the parent, northPlane.

But it seems like the scaling is... lost in translation somehow?

Any tips on how to scale up the transform above? Does it need baking?

Thanks much, Looking around... : )




Link to comment
Share on other sites

SOLUTION - here is a solution found to scale the transformCoordinate, thanks to the babylon docs, and a post from 2015( @gwenael ).

If you know of an updated or more performant way please ping, otherwise, hope it helps someone else.

var invertParentWorldMatrix = basePlane.getWorldMatrix().clone().invert();
var pickMoveVector = pickPointNext.subtract(pickPoint); //vector of mouse move, GLOBAL.
var local_position = BABYLON.Vector3.TransformCoordinates(pickPointNext, invertParentWorldMatrix);
var originInLocalSpace = BABYLON.Vector3.Zero();
var move = originInLocalSpace.subtract(local_position).normalize();
var moveScaledInLocalSpace = move.scale(8).add(local_position); 
pickObj.position.addInPlace(pickMoveVector);  //MOVE-TILE-TO-POSITION-.

BONUS: if you have insight on these related concepts, I would love to understand more about:

a) why does a tiny then scaled up version of a mesh seem to perform quaternion rotations faster than a mesh imported at large scale from blender?

(found that tip in a different old-thread, if I'm not mistaken)

b) what is happening conceptually for "invert" ParentWorldMatrix, is it "invert" as in - expand from a smaller local matrix into a larger world matrix?

c) in the subtract() scale() then add() sequence of calls (above), is that basically scaling the difference between the move point and the local origin?

Really curious on how these things work at a deeper level, I'll dip in the src l8r...

Hope this help someone.



Link to comment
Share on other sites

TIP: if you are writing a babylon App in Electron... and you have Web app and Electron app running simultaneously... you should know that your GPU will be split between the two!

I had 5 running. And... it gets slow. : ]

So the best performance optimization (was not scaling down the 3D world in blender, then scaling it up again in babylon) it was closing the Babylon Web App while working on the Babylon electron app. 

: )



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.

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.


  • Recently Browsing   0 members

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