How to find which element is selected

Hi, I am new to Babylon and I am sorry I dont have a playground in Babylon.

I could not convert my code to work on the babylon.js playground.

In my process of learning, I am trying to have a UI that displays the option specifically for the selected primitives.

Right now, i have a cube, cylinder, and icosphere

For the Cube: 3 dimensions: width, height, depth (range 0.1-2.0)

For the Cylinder: Diameter and height (range 0.1-2.0)

For the IcoSphere: Diameter (range 0.1-2.0) and subdivisions (range 1-10)

For the sphere, when a double click is made on the sphere, I want to show the subdivisions of the sphere in UI and let the user change it.

I don’t know if it is the correct way to do but I am trying to do it like this:

Read the subdivision of the sphere and show it in UI in an input element value.

When the user changes the value, create a new sphere in that position.

But my problem is that I am not able to get the subdivision of a sphere.

I am sorry I am very new to Babylon so if question is stupid, i ask for pardon in advance

hello don‘t worry。PG is very simple. Babylon.js Playground (babylonjs.com),open this website and click the “save” button,you will get a new website address.When you modify the code, save it again.

Do you want to change the sphere segments? I can’t understand what 's the subdivisions of the sphere. SomeTimes mesh can’t be changed,you can dispose the old mesh,and create a new mesh in the same position.

I need to show the current attribute of the mesh like radius and subdivision of the sphere, height and radius of cylinder in the UI.

From what I know the options like diameter and segments of Mesh are discarded after creating. Instead you could use getBoundingInfo() on your mesh, with the properties:

Just subtract maximum - minimum values for Boxes.

1 Like

Babylon.js Playground (babylonjs.com) come here!

2 Likes

Hi and Welcome to our Community,
First, you don’t have to apologize for asking questions. Asking is never stupid and we all had to start with something new (and continue to learn new every day).
Your approach would work fine. Just don’t forget to dispose of the old primitive when the user creates the new one.
As for the trick of retrieving the values from the mesh creation kindly shared by @Happy0Ending it will work for any primitive mesh created in BJS. It will not work on custom or imported meshes. For this, you should use the technique shared by @Takemura .
Again, welcome to the community and I hope you are enjoying your discovery of BJS.
Meanwhile, have a great day :sunglasses: