Hi there, I have been trying to solve a problem for a few days with no luck (I am fairly new to programming). So, I thought I should try and find another way of solving my problem. I have a new playground here it is You will see a large object. This is a model imported via an .OBJ file. The file consists of tightly grouped blocks. I have moved one of these blocks up just so you can see the size… there are 16 blocks in all (but you can ignore this out of place block).
As you can see, if you click on any of the smaller (scattered) cubes the camera moves towards them.
So, my question is do you know how I can make the OBJ model that has been imported into separate blocks. At present it is only the large area of blocks that has the behaviour I am looking for. When working, I will be importing a much larger model with many more tightly grouped blocks.
I found two methods of importing the .OBJ file…not sure which one would be best to use for the purpose described.
Cheers, thanks for your help.
Not sure what you need. You can already pick them individually https://www.babylonjs-playground.com/#DXE1CV#33 as you pick them their boundingbox is shown?
Hi JohnK, thanks for your reply.
I want the blocks in my group to behave the same as the scattered cubes. So, on my block group the camera should move over to the corner block, if that is clicked. Then if the opposite corner of the group of blocks is clicked the camera should move to that corner. The goal will be to navigate a large area by clicking on a group of blocks (hundreds). This large group of blocks is to be a floor where I can move the camera along one block at a time.
More a question of camera placement rather than breaking up the cubes. It is about finding the correct target position for the camera. You do not want it over the top of the cube but a little way back so the camera can still see it. You can refine this crude method https://www.babylonjs-playground.com/#DXE1CV#35
Hi JohnK, thanks again for your response.
Sorry, this still isn’t what I am after. You are right it is about camera placement. However, I just would like my large block converted so that the individual blocks work like the small scattered cubes. I do want the camera just above the block, not standing back. I’ve updated my original playground to make the camera shift more noticeable as the block is navigated – I’ve enlarged the block.
Don’t see why they are working differently.
Ah, it’s because all of your individual cubes have their pivot at the origin (0, 0, 0). Each cube needs to have its pivot at the center of its own geometry.
Hi There, I noticed that all the small cubes are objects and my large group of blocks is an array (I used console.log). So, I am just wondering if the programming is treating my large group as a single object. There a 144 individual blocks in my OBJ file (created in Blender). I can’t help thinking that there must be a way of creating a ‘for loop’ to process the array and make separate objects. Kind of how the ‘CreateBox’ function works for the scattered cubes. I just don’t know how to do it, due to my lack of experience programming. Any thoughts?
Your cubes are individual meshes already, you can see them if you show the scene explorer. The problem is that they all have their pivot at
(0, 0, 0), so when you query their positions, you’ll always get
(0, 0, 0). Instead of
position you can instead use the center of the cube’s bounding box, which should produce the behavior I think you’re looking for. See this playground:
A virtual pint is in order I believe. Thank you, this is what I was after.
Thanks to you both. I can move on now to the next stage.