Forum

Author Topic: Export normal map from Python  (Read 2561 times)

edz

  • Newbie
  • *
  • Posts: 11
    • View Profile
Export normal map from Python
« on: May 21, 2020, 04:33:32 PM »
Is there a way to export the Normal map from the python API ? (I am refering to the Model NormalMap, not the per-camera normal map)

I am using this code, but I do not get any normal maps output as a file:


    # Import new mesh
    chunk.importModel(mesh_file)

    # Bake DiffuseMap Texture
    chunk.buildTexture(texture_size=4096, texture_type=Metashape.Model.DiffuseMap)

    # Export Model and Texture
    chunk.exportModel(os.path.join(output_folder, chunk.label + '.obj'))

    # Bake NormalMap Texture
    chunk.buildTexture(texture_size=4096, texture_type=Metashape.Model.NormalMap)

    # Export Model and Texture (still exports the diffuse JPG....)
    chunk.exportModel(os.path.join(output_folder, chunk.label + '_NORMAL.obj'))


edz

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: Export normal map from Python
« Reply #1 on: May 21, 2020, 04:45:21 PM »
It would be useful to add a function with this signature: model.exportTexture(path=’‘, type=Model.DiffuseMap, image_format=ImageFormatJPEG)

wojtek

  • Sr. Member
  • ****
  • Posts: 284
    • View Profile
Re: Export normal map from Python
« Reply #2 on: May 22, 2020, 12:52:09 PM »
Hey,

use:

Model.setActiveTexture()
Model.saveTexture()

or

Tasks.ExportTexture()

edz

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: Export normal map from Python
« Reply #3 on: May 22, 2020, 04:31:59 PM »
But Model.setActiveTexture() takes a texture as input parameter... I don't have that texture yet.

Besides, after running these two lines:

    chunk.buildTexture(texture_size=4096, texture_type=Metashape.Model.DiffuseMap)
    chunk.buildTexture(texture_size=4096, texture_type=Metashape.Model.NormalMap)

the size of the array chunk.model.textures is still 1, so something is not clear here.

wojtek

  • Sr. Member
  • ****
  • Posts: 284
    • View Profile
Re: Export normal map from Python
« Reply #4 on: May 23, 2020, 11:47:45 AM »
But Model.setActiveTexture() takes a texture as input parameter... I don't have that texture yet.

Besides, after running these two lines:

    chunk.buildTexture(texture_size=4096, texture_type=Metashape.Model.DiffuseMap)
    chunk.buildTexture(texture_size=4096, texture_type=Metashape.Model.NormalMap)

the size of the array chunk.model.textures is still 1, so something is not clear here.

use this to add a texture:

Model.addTexture(type=Model.DiffuseMap)
Add new texture to the model.
Parameters type (Model.TextureType) – Texture type.
Returns Created texture.
Return type Model.Texture