Forum

Author Topic: Can’t set mesh CRS in empty project  (Read 1961 times)

ManyPixels

  • Newbie
  • *
  • Posts: 40
    • View Profile
Can’t set mesh CRS in empty project
« on: December 05, 2022, 12:51:54 PM »
When opening an empty project, setting the CRS wherever possible and trying to import a mesh with a well-defined coordinate system, it is only possible to import it in local coordinates. On the other hand, if you import a dense cloud, regardless of its CRS, it is then possible to import the mesh and choose its CRS (even if it is different from the dense cloud)

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 15160
    • View Profile
Re: Can’t set mesh CRS in empty project
« Reply #1 on: December 05, 2022, 03:23:58 PM »
Hello ManyPixels,

Dense point cloud has the option to be referenced in the coordinate system that is different from the chunk's coordinate system, but mesh model doesn't have such option.

There's a workaround script for importing models (from OBJ format) that asks for the coordinate system and properly applied chunk.transform matrix that you can use:

Code: [Select]
import Metashape

def import_mesh():

doc = Metashape.app.document
chunk = doc.chunk

path = Metashape.app.getOpenFileName("Select mesh file for import:", filter = "OBJ files (*.obj)")
if not path:
print("Nothing to import, script aborted.")
return 0

crs = Metashape.app.getCoordinateSystem("Specify CRS for imported mesh:")
if not crs:
print("Invalid CRS, script aborted.")
return 0

chunk.crs = crs
file = open(path, "rt")
lines = file.readlines()
for line in lines:
if line[0] != "v":
continue
params = line.strip().split(" ")
break

x = float(params[1])
y = float(params[2])
z = float(params[3])
file.close()

chunk.transform.matrix = Metashape.Matrix.Translation(crs.unproject((x, y, z)))
chunk.importModel(path, Metashape.ModelFormatOBJ, crs)
chunk.resetRegion()

#doc.save()
#chunk.buildTiledModel(source=Metashape.ModelData, transfer_texture=True)

label = "Custom menu/Import mesh"
Metashape.app.addMenuItem(label, import_mesh)
print("To execute this script press {}".format(label))

If you are interested in different import formats, please name those formats. It should be rather easy to adapt the script for plain-text (i.e. non-binary) formats.
Best regards,
Alexey Pasumansky,
Agisoft LLC

ManyPixels

  • Newbie
  • *
  • Posts: 40
    • View Profile
Re: Can’t set mesh CRS in empty project
« Reply #2 on: December 05, 2022, 04:00:51 PM »
So it seems that the CRS can't be properly defined in an empty chunk...

Thanks for the script, I'll keep it, but for now it's way easier to import any e57 cloud and then import the mesh in the right CRS.

It's a bit weird because once you have imported a dense cloud, you can then import a mesh and choose the CRS.