The polygon I created using the CreatePolygon() method cannot be updated

Dear friends,
I am a beginner in Babylon.js and have previously used Cesium. I wanted to implement the measurement functionality of Cesium using Babylon.js, so I created a playground to dynamically draw and edit polygons: Playground Link
(Click to start drawing, left-click to draw, right-click to finish drawing, drag the sphere to edit the polygon)

During the implementation, I consulted the documentation and used the BABYLON.MeshBuilder.CreatePolygon() method to create my polygon. However, what puzzles me is that even though I set ‘updatable’ to true, I don’t understand how to update the mesh. I have tried updating the shape when creating the polygon, but it didn’t work. Therefore, I can only resort to destroying and rebuilding the polygon frequently to achieve the purpose of editing.

I would like to ask everyone, how can I achieve polygon updates?

Welcome to the community!

Are you using updateVerticesData to update the polygon? Irregular Polygon Examples | Babylon.js Playground (babylonjs.com)

Thank you very much for your reply,

Based on your provided hints, I have consulted the documentation and found that VerticesData is an object that contains vertex data for meshes. It can be modified to dynamically modify a polygon. However, if I want to implement modifying a polygon by dragging its points, how can I achieve it?

For example, in the following scenario, after dragging the bottom-right point of the polygon, I can obtain the new coordinates of that point. However, I cannot directly obtain the updated VerticesData of the new polygon. How can I update the polygon in this case?

Hmmm I would try to do something like this: when you click on a point (so, on the pointer down), find the vertex that corresponds to that point and store it somewhere. Then, once the dragging is done, get the updated position, and change that vertex to the updated position, and call update on the vertex data.

Thank you very much. Your words have enlightened me, and the problem has been perfectly solved. You are my guiding light. :smiling_face_with_three_hearts:

1 Like