How to pan glb and obj assets?

Hi all,
I was working with the glb and obj files where i need to move the assets based on shift+left click and i am trying to move assets using actions in babylonjs but its not working properly.

The dragging options works when i remove the defaultcamera, but without default camera the obj and glb files are getting zoomed in or zoomed out …

can anyone help me out with this.!!

The dimensions of your assets are very tiny. Either you increase scaling:

scene.meshes[1].scaling.scaleInPlace(1000)

Or adjust camera, my values might need a bit more tweaking to your likings:

camera.minZ = 0.05
camera.wheelPrecision = 1500

WheelPrecision will avoid zooming out or through too fast and tiny minZ-value decreases z-fighting on small meshes, because it defines the min. distance for camera.

I additionally edited cameraRadius and lightPosition of your playground:

1 Like

Thanks @Takemura
but this doesn’t work, the glb assets gets zoomed out and the obj assets get zoomed in too much. When I remove the scene.createDefaultCamera() inside my scene loader.
But if I include creaeDefatCamera the actions which I defined for shift + click is not working. It only takes ctrl+click for panning the obj and glb files.

If you use 2 different scalings, then you can use BoundingInfo to set camera radius etc.

First the max absolute value of boundingInfo measures is determined:

const boomBoundingBox = scene.meshes[1].getBoundingInfo().boundingBox;
const measures = [boomBoundingBox.maximum.x, boomBoundingBox.maximum.y, boomBoundingBox.maximum.z,
Math.abs(boomBoundingBox.minimum.x), Math.abs(boomBoundingBox.minimum.y), Math.abs(boomBoundingBox.minimum.z)];
let maxRadius = 0;
for(const measure of measures) {
   maxRadius = Math.max(maxRadius, measure);
}

Then set camera properties:

camera.radius = 5*maxRadius;
camera.minZ = 0.05*maxRadius;
camera.wheelPrecision = 50000*maxRadius;

The playground:

Thanks you @Takemura :+1: for your insights it was helpful but still the pixel are breaking. Is there any replacement(any babylonjs documentation) there for creaeDefatCamera which doesn’t affect the panning action which I have created.

Hi and welcome to the forum,
Can you be a bit more explicit on what you want to achieve.
You are using an arc rotate camera and actually, objects are not zoomed in or out in your PG when panning (check the radius value of the camera when panning). What happens is that you are offseting the arc rotate camera target in the 3d space with your mouse move on panning.

So what is it exactly you want to do? Do you want to pan only horizontally (alpha) and vertically (beta) keeping the target on this axis (= moving the camera position while panning?) May be you should use a free or a custom camera instead.

Also for

Can you rephrase or explain?

May be you could make a small draw/schema of how you want to do your camera panning because I’m afraid we do not fully understand your question here (at least, I don’t).
Again welcome to BJS and I hope you are having a good experience.
Talk to you later,

Hi @mawa ,

I was trying to pan the 3assets like obj glb formats whenever the shift + left click is pressed. I am using arc rotate camera inside my scene loader I am using scene.createDefaultCamera () when use that the panning function which I defined is not working. But when I remove the createDefaultCamera the obj and glb assets quality is reduced like the pixels are breaking.
So my question is like why do this happens is there any way to improve the pixels quality.

Hey there. :slight_smile: The reason why your custom panning controls aren’t working is because you’re creating them for the old, disposed camera. The camera created by createDefaultCameraOrLight is assigned to scene.activeCamera.

Alternatively if you want to create the camera yourself, you could try setting minZ and maxZ like createDefaultCamera does and see if it helps clear up the distortion for you.

camera.minZ = radius * 0.01;
camera.maxZ = radius * 1000;
1 Like

Thank you @Blake

But i don’t know why normal rotation does not properly after panning. Like after panning the asset rotates in the circular rotation when i tried to rotate rather then the actual self rotation. Is that because of camera radius??

Panning the camera works by changing the camera’s target position, which the camera rotates around.

Maybe it’s confusing because there’s only one mesh and at first the camera target and the mesh center are the same, so it looks like the mesh is rotating.

1 Like

Yeah is there any property to set the camera to follow the assets position. Like the camera target.

Well, for the arcRotateCamera, it is setTarget. But then, there is also a follow camera May be this one will better match your needs.