Display model in the center

i want that my model should be in the center of the of the cavas even if the placing of the model is some soem where else i want the model position to be the 0,0,0. @RaananW @mawa @slin

Hi,
Hope you are well. It looks like your model has its pivot point offseted from the mesh.
If the axis would be set at the center of the object, then you could simply target your object with the arc rotate camera and it would always remain centered.
As you can see in this revised version of your PG the camera does not center on the targeted mesh. The only explanation for this is that the axis are offset of the mesh object in your model.
You have two and more solutions to fix this. For a start:

  1. The easiest, if you do not need this offseted pivot, is to edit the model and center the axis on the object.
  2. Assuming you need to keep this offseted pivot, you can parent your model to a transform node or another mesh and reposition it towards the parent. Next, target the parent with the camera.

Edit: other options are to change the local matrix in BJS (in case you cannot edit the model) or less sexy but also doable is to simply account the offset in the camera targeting. Understand target the mesh x,y,z coordinates + or - the offset from the pivot for each axis. Or you could also work from the mesh bounderies and probably more options… I would however start with number 1 or 2 of the above, if applicable.

well there will be multiple models will be displayed with different names so i want that the model which is being displayed sould be displayed like the model displayed in the sandbox.

Sure. You have two (or more) solutions for that.
Obviously, the easiest would be to have all your models with their axis centered on object and placed at zero world origin.
If this is not possible, the other option is to change the camera target on object import, targeting each time the newly imported object. You do not necessarly have to do it by name. If you run this within your async function, you can just target mesh[0]. This however doesn’t change the issue about the axis offseted from the model. In clear, ideally, if you don’t want to have a specific targeting for each model, it would be best that all of your models would have the same setting for their axis and same coordinates in the world.

I aslo want to pan and zoom to the other parts of the models also so i used that but then i have to remove that so that i to implement the zoom and pan

And i just want that if we import the moel in the asnd box then the model appers in the proper center of the canvas i just want that to happen.

I know. But you have to understand that, in the end, you are looking at your scene/canvas from a camera.
Since you are using an arcRotateCamera, the way to have it centered is to target your object (or target the coordinates of your imported object). I’m afraid there’s no workaround for this. You only need to understand that it is the camera and targeted object that will make it so that your object is centered.
Can you edit your models to set the axis on the center of the object? This would really be the easiest and most straight forward way.

You can still allow panning even though you initially target a model. Actually, you could event make objects ‘pickable’ and on pick, target the picked model. Though, for whatever you do (and unless working from the mesh bounderies) the targeted object will always use the axis of the object. So, if the axis are offseted from the model and each model has a different setting, then, you have a problem (and need to use either the mesh bounderies or implement specific camera targeting for each targeted model)

1 Like

On a same model, I am using a technique I call POI (for Points of Interest). Basically on my model, I define points eventually with an invisible mesh. Next I use these points to set the target of the camera.
If you take a look at my 'Project Chair’ demo and ‘Start a tour’, you will see the arcRotateCamera target a new point of interest on each step (while panning and zooming is still active).

well the problem that i am facing is that when any one will upload the model in the canvas the model should be displayed in the center of the cavas but if the model that is being uploded position was not in the center while uploading the model then his codes display the model in the position on the model in the 3d software but i want that when ever the user upload the model if its pivot or the position is not in the center then also the model shold display in the center like in sand box.

well i implemented that but it does not work for this model
https://raw.githubusercontent.com/Ashishj34/testmodel/dev/הדמיה.obj
i want that this types of models to be displayed in the center of the cavas

Ok, I understand. You should have started with this. The important point here is that it’s a user model and you have no insight on how axis are set on the model. Well, in this case, I believe you are left with just two options. Either you reset the axis/matrix on the local object to be on the center of the object or you work it out from the mesh bounderies. I am not a specialist for working from bounderies. I guess I could figure it out but clearly others know much better how to do this.

Can you confirm the above and if my assessment is correct (user meshes with no control on meshes and all new imported meshes need to be targeted at the center point by the arcRotateCamera)? Upon confirmation, I will quickly callin someone who knows best how to do this…

Edit: @PolygonalSun would you be able to kindly tell @Ashish_Abhiwan how to master camera targeting for user meshes (as per the above - either by resetting the local axis on the mesh or from bounderies or any other technique you are aware of…I know you’re kind of the specialist for this kind of things) while I’m still learning :wink: Thanks a lot,

yeah that what is happening and i want that the model should be in the center

@mawa hii, is there any solution of this i tried somethings but was unable to anything on this.

Indeed. There is a solution. It’s holidays period. :parasol_on_ground: You might need to have some more patience :hourglass_flowing_sand: but I am sure we’ll shortly figure this out.
May be meanwhile you can work out some other parts of your project…

Hi. Maybe you could try this approach I previously explained in one of the threads. You can find the playground example bellow the huge comment I made where I explain the process.

1 Like

no it did not worked for me, is there any other process so that we can do this.

Do you have a new PG with your attempt. When you say ‘it did not work’, it could be just because of an error in your code (no offense here, not as if this thing was ez). Could you share your non-working attempt with us? Thanks,

yeah sure, https://playground.babylonjs.com/#3I55DK#541 is the play gound

Hmm. @Ashish_Abhiwan This PG doesn’t seem to have any part of the code shared by @nogalo.
May be the wrong link?
@nogalo Sry to bother you but you wouldn’t happen by any chance to have some time to quickly implement your code in this PG? I’m sorry, I’m a bit in the middle of a ton of other things and I’m also clearly not an expert on this. Thanks,