Forum

Author Topic: Colorize Vertices via Python  (Read 1903 times)

wojtek

  • Sr. Member
  • ****
  • Posts: 284
    • View Profile
Colorize Vertices via Python
« on: October 21, 2021, 02:48:37 PM »
Code: [Select]
docRef = Metashape.app.document
chunk = docRef.chunk
model = chunk.model
faces = model.faces

for f in faces:
    if f.selected:
        v1 = f.vertices[0]
        v2 = f.vertices[1]
        v3 = f.vertices[2]
        model.vertices[v1].color = (255,0,0)
        model.vertices[v2].color = (255,0,0)
        model.vertices[v3].color = (255,0,0)

Tried following code, does not throw an error but also does not change the values if I print them back. Any help would be greatly appreaciated.

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14813
    • View Profile
Re: Colorize Vertices via Python
« Reply #1 on: October 21, 2021, 05:50:26 PM »
Hello wojtek,

Which version of Metashape Pro you are using?

I've just tested it in 1.8.0 pre-release and it works as expected: colors are modified in the Model view and new values are returned for the selected vertices.
Best regards,
Alexey Pasumansky,
Agisoft LLC

wojtek

  • Sr. Member
  • ****
  • Posts: 284
    • View Profile
Re: Colorize Vertices via Python
« Reply #2 on: October 22, 2021, 12:05:02 PM »
Hello wojtek,

Which version of Metashape Pro you are using?

I've just tested it in 1.8.0 pre-release and it works as expected: colors are modified in the Model view and new values are returned for the selected vertices.

Hmm, it works indeed if the model already has Vertex Colors. I've been testing on a model that had no vertex colors to begin with. Any idea how to go around that?

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14813
    • View Profile
Re: Colorize Vertices via Python
« Reply #3 on: October 22, 2021, 05:38:21 PM »
Hello wojtek,

As a workaround - at first use chunk.colorizeModel(), then modify the colors as you need.
Best regards,
Alexey Pasumansky,
Agisoft LLC