Forum

Author Topic: Surface from polygon shape  (Read 11524 times)

macsurveyr

  • Jr. Member
  • **
  • Posts: 77
    • View Profile
Surface from polygon shape
« on: July 19, 2025, 08:46:14 PM »
If I select tie points and make a drawing plane then draw a polygon shape, can I turn that shape into a surface?

Any insight welcomed.

Tom

JMR

  • Hero Member
  • *****
  • Posts: 567
    • View Profile
Re: Surface from polygon shape
« Reply #1 on: July 21, 2025, 05:22:54 PM »
If you mean a mesh surface built on tie points inside a given shape this is my suggestion:
Build mesh on all the tie points, draw the polygon you want to use and make it the outer boundary type. Than duplicate the mesh checking trim with boundary shape.
I hope it works for you.

José Martínez. CTO
Geobit &
Accupixel

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 15691
    • View Profile
Re: Surface from polygon shape
« Reply #2 on: July 22, 2025, 05:07:21 PM »
Hello Tom,

With the custom Python scripting you can create a mesh surface that fills the 2D shape laying on certain plane.

If it is a convex polygon, then the script should be rather simple.
Best regards,
Alexey Pasumansky,
Agisoft LLC

macsurveyr

  • Jr. Member
  • **
  • Posts: 77
    • View Profile
Re: Surface from polygon shape
« Reply #3 on: July 23, 2025, 02:19:00 AM »
Hello Alexey,

I thought and hoped it could be accomplished with a script but I don't see what method or function that I would use to create the mesh surface using the shape. Any code snippet that you could share would be most helpful.

Thanks,

Tom

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 15691
    • View Profile
Re: Surface from polygon shape
« Reply #4 on: July 23, 2025, 04:29:07 PM »
Hello Tom,

See the example of the script below. Should work if you have one shape of Polygon type selected (should also shave 3D vertices, i.e. shape should be displayed in the Model view):

Code: [Select]
import Metashape, tempfile

def create_mesh_from_vertices(chunk, vertices, crs):

chunk.model = None
output = ""
for v in vertices:
output += "v {:.5f} {:.5f} {:.5f}\n".format(v.x, v.y, v.z)
for i in range (1, len(vertices)-1):
output += "f 1 {:d} {:d}\n".format(i+1, i+2)

print(output)

temp_obj = tempfile.NamedTemporaryFile(delete=False)
temp_obj.write(output.encode("utf-8"))
temp_obj.close()

print("Temp file saved to " + temp_obj.name)
chunk.importModel(path = temp_obj.name, format = Metashape.ModelFormatOBJ, crs = Metashape.CoordinateSystem('LOCAL_CS["Local Coordinates (m)",LOCAL_DATUM["Local Datum",0],UNIT["metre",1,AUTHORITY["EPSG","9001"]]]'))

chunk.model.transform = None
chunk.model.label = "3D model from shape"
for i in range(len(chunk.model.vertices)):
chunk.model.vertices[i].coord = vertices[i]
print("Created mesh")
return 1


def create_mesh():

print("Script started")
doc = Metashape.app.document
if not doc.chunk:
print("Empty project, script aborted")
return 0
chunk = doc.chunk

if not chunk.shapes:
print("No shapes in the active chunk, script aborted")
return 0

shapes = [s for s in chunk.shapes if s.selected]
if len(shapes) != 1:
print("Only one shape should be selected. Currently selected {:d} shapes. Script aborted.".format(len(shapes)))
return 0

shape = shapes[-1]
if shape.geometry.type != Metashape.Geometry.Type.PolygonType:
print("Polygonal shape should be selected, script aborted.")
return 0

T = chunk.transform.matrix
if chunk.shapes.crs:
crs = chunk.shapes.crs
else:
crs = chunk.crs
vertices = [T.inv().mulp(crs.unproject(v)) for v in shape.geometry.coordinates[0]]
create_mesh_from_vertices(chunk, vertices, crs)

print("Script finished.")
return 1

label = "Custom menu/Create mesh from selected shape"
Metashape.app.addMenuItem(label, create_mesh)
print("To execute this script press {}".format(label))
Best regards,
Alexey Pasumansky,
Agisoft LLC

macsurveyr

  • Jr. Member
  • **
  • Posts: 77
    • View Profile
Re: Surface from polygon shape
« Reply #5 on: July 23, 2025, 08:19:29 PM »
Hello Alexey,

Thank You. Script works perfectly.

Tom

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 15691
    • View Profile
Re: Surface from polygon shape
« Reply #6 on: July 23, 2025, 08:23:50 PM »
For big polygons the created mesh may have long faces. But if necessary, they can be subdivided. I think we've got old script to subdive the faces of existing mesh.
Best regards,
Alexey Pasumansky,
Agisoft LLC