# 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();
invertParentWorldMatrix.invert();
var local_position = BABYLON.Vector3.TransformCoordinates(pickPointNext, invertParentWorldMatrix);
pickObj.position.copyFrom(local_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... : )

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

``````//TRANSFORM-FROM-2D-PROJECTION-TO-WORLD-TO-LOCAL-SPACE-.
var invertParentWorldMatrix = basePlane.getWorldMatrix().clone().invert();
var pickMoveVector = pickPointNext.subtract(pickPoint); //vector of mouse move, GLOBAL.
var local_position = BABYLON.Vector3.TransformCoordinates(pickPointNext, invertParentWorldMatrix);
//SCALE-TRANSFORMATION-TO-MATCH-PARENT-SCALING-.
var originInLocalSpace = BABYLON.Vector3.Zero();
var move = originInLocalSpace.subtract(local_position).normalize();
//SET-SCALED-LOCAL-POSITION-.
pickObj.position.copyFrom(moveScaledInLocalSpace);

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.

Thanks.

##### Share on other sites

3 hours ago, aFalcon said:

what is happening conceptually for﻿ "invert﻿﻿﻿﻿﻿﻿"﻿﻿﻿

The inverse matrix. Q is the inverse of P when PQ = I, the identity matrix.

##### Share on other sites

Thank you @JohnK! I get identity matrix, so that relation makes sense and is very helpful. Also... I will look for that ref in the src. +1!

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

: )

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

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.