Forum

Author Topic: Automatic Texture Page Calculation Issue for Sub-Meshes with Python API  (Read 4903 times)

Etienne SOMMER

  • Newbie
  • *
  • Posts: 2
    • View Profile
Hello everyone,

Starting from an initial mesh, I have created several sub-meshes using the script provided by Alexey (https://www.agisoft.com/forum/index.php?topic=14150.0). I now want to texture each of these sub-meshes.

Instead of specifying a number of texture pages for each mesh, I want to define a pixel size so that the number of pages is automatically calculated based on the mesh size. In my algorithm, I specify a pixel size during the buildUV process without setting the page count because I want it to adjust automatically.

However, my problem is that, regardless of the mesh, only one texture file is created. How can I generate multiple texture files without specifying their number in advance?

Thank you in advance for your help,

Best regards,

Etienne

Code: [Select]
import Metashape
import time

# Start counting time
start = time.time()

doc = Metashape.app.document

# Ask the user for the chunk name
chunk_name = Metashape.app.getString("What is the chunk's name ?")

# Search for the chunk specified by the user
chunk = None
for chunk_it in doc.chunks:
    if chunk_name == chunk_it.label:
        chunk = chunk_it
        break

if chunk is None:
    print("Chunk not found. Script aborted.")
    raise SystemExit

# Iterate over all Model components of the active chunk
for i in range(len(chunk.models)):
    chunk.model = chunk.models[i]
    if len(chunk.model.faces)>0 and chunk.model.label != "Modele_3D_final_Landeck":
        # Build UVs for each mesh
        chunk.buildUV(mapping_mode=Metashape.MappingMode.GenericMapping, pixel_size=0.01, texture_size=8192)
           
        # Build the texture for each mesh
        chunk.buildTexture(blending_mode=Metashape.BlendingMode.MosaicBlending, fill_holes=True, ghosting_filter=True)

doc.save()

# Calculate and display execution time
end = time.time()
print(f"Execution time: {end - start} seconds")

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 15369
    • View Profile
Hello Etienne,

Maybe you should consider using the Block Model concept introduced in 2.1 version? Thus you can generate the model blocks with the fixed size and also to build the texture using the same effective resolution for all blocks.

Please check additional information in the following article:
https://agisoft.freshdesk.com/support/solutions/articles/31000171950-block-model

I would suggest to check this approach using GUI for some small model in order to confirm that the approach is applicable to your needs. After that it could be scripted.
Best regards,
Alexey Pasumansky,
Agisoft LLC

Etienne SOMMER

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Automatic Texture Page Calculation Issue for Sub-Meshes with Python API
« Reply #2 on: August 05, 2024, 09:27:34 AM »
Hello Alexey,

Thank you for your response. Unfortunately, the "split in blocks" option is not feasible in this case because the mesh is a photogrammetric mesh reconstructed in Metashape which has been further edited in other software to incorporate laser scanner data and remove certain vegetation areas and objects.

Therefore, I need to use the entire mesh as input and be able to adjust the pixel size for each mesh generated from the original mesh.

Thanks a lot for your help,

Best regards,

Etienne