There is a triangulated mesh in the scene.
The file “sl_input_f” contains the vertex indices for all edges of the mesh with the original topology (before its triangulation).
We want to get from the triangulated mesh - a mesh with the original topology.
An algorithm like this:
- Read the vertex indices from the file (The indices are separated by “/ n”).
- We convert each pair of vertex indices into an edge index.
- Remove duplicates, sort, and write the resulting indexes to the array.
- Get the list of edge indices for the triangulated mesh.
- Subtract from this list of indices the previously received list of indices of the edges of the original topology.
- Select the edges with the subtracted indices.
- Delete.
- We get a mesh with the original topology.
Profit!
The execution time of this script in Maya 2019.3.1, or in Maya 2020.4, or in Maya 2022.3 (Python-2) is almost the same for both Maya-UI and Maya-Standalone versions (the differences are insignificant and stochastic).
The only significant difference in Maya 2022.3 (Python-3) is a fourfold increase in speed for parallel parsing (with slicing) and writing from the “list” to two arrays “om.MIntArray ()”:
sl_input_array_0 = om.MIntArray()
sl_input_array_1 = om.MIntArray()
with open(sl_file_wire, 'r') as sl_input_f: sl_lines = sl_input_f.read().splitlines()
for each in sl_lines[slice(0,-1,2)]: sl_input_array_0.append(int(each))
for each in sl_lines[slice(1,-1,2)]: sl_input_array_1.append(int(each))
This part of the code also shows an increase in execution speed for Python-3.
Execution time is reduced by 30% (compared to Python-2):
vtx_iter = om.MItMeshVertex(dag)
edg_iter = om.MItMeshEdge(dag)
edge_count = edg_iter.count()
for each_0, each_1 in zip(sl_input_array_0, sl_input_array_1):
vtx_iter.setIndex(each_0)
sl_set1 = set(vtx_iter.getConnectedEdges())
vtx_iter.setIndex(each_1)
sl_set2 = set(vtx_iter.getConnectedEdges())
sl_set3.add(tuple(sl_set1 & sl_set2)[0])
It is noteworthy: When you try to combine these parts of the code into more compact analogs, the script execution time increases.
The execution time for all operations is acceptable. Except the time spent on the delete operation.
Here are the stats for Maya 2019, 2020, 2022 (Python-2/3). For Maya UI and for Maya standalone:
Total edges on triangle Mesh = 893244
Total edges from wire in input txt-wire-file = 1093392
Total edges from wire, no duble = 619896
For delete - edges count = 273348
MAYA 2022.3, UI, maya.api.OpenMaya, Py-3
input lines = 0.2 s. Total = 0.20 s.
lines to two arrays = 0.53 s. Total = 0.73 s.
output set = 3.03 s. Total = 3.76 s.
set to sort list = 0.03 s. Total = 3.79 s.
edges array out = 0.02 s. Total = 3.81 s.
select edges = 0.01 s. Total = 3.82 s.
delete edges = 30.94 s. Total = 34.76 s.
MAYA 2022.3, UI, maya.api.OpenMaya, Py-2
input lines = 0.11 s. Total = 0.11 s.
lines to two arrays = 4.06 s. Total = 4.17 s.
output set = 3.96 s. Total = 8.13 s.
set to sort list = 0.09 s. Total = 8.22 s.
edges array out = 0.03 s. Total = 8.25 s.
select edges = 0.00 s. Total = 8.25 s.
delete edges = 30.84 s. Total = 39.09 s.
MAYA 2022.3 standalone, maya.api.OpenMaya, Py-3
input lines = 0.19 s. Total = 0.19 s.
lines to two arrays = 0.53 s. Total = 0.72 s.
output set = 3.09 s. Total = 3.81 s.
set to sort list = 0.03 s. Total = 3.84 s.
edges array out = 0.02 s. Total = 3.86 s.
select edges = 0.01 s. Total = 3.87 s.
delete edges = 30.89 s. Total = 34.76 s.
MAYA 2022.3 standalone, maya.api.OpenMaya, Py-2
input lines = 0.13 s. Total = 0.13 s.
lines to two arrays = 4.22 s. Total = 4.35 s.
output set = 3.87 s. Total = 8.22 s.
set to sort list = 0.10 s. Total = 8.32 s.
edges array out = 0.03 s. Total = 8.35 s.
select edges = 0.00 s. Total = 8.35 s.
delete edges = 30.81 s. Total = 39.16 s.
MAYA 2020.4, UI, maya.api.OpenMaya, Py-2
input lines = 0.13 s. Total = 0.13 s.
lines to two arrays = 4.21 s. Total = 4.34 s.
output set = 4.03 s. Total = 8.37 s.
set to sort list = 0.09 s. Total = 8.46 s.
edges array out = 0.02 s. Total = 8.48 s.
select edges = 0.01 s. Total = 8.49 s.
delete edges = 32.26 s. Total = 40.75 s.
MAYA 2020.4 standalone, maya.api.OpenMaya, Py-2
input lines = 0.11 s. Total = 0.11 s.
lines to two arrays = 4.29 s. Total = 4.40 s.
output set = 3.69 s. Total = 8.09 s.
set to sort list = 0.10 s. Total = 8.19 s.
edges array out = 0.03 s. Total = 8.22 s.
select edges = 0.00 s. Total = 8.22 s.
delete edges = 32.26 s. Total = 40.48 s.
MAYA 2019.3.1, UI, maya.api.OpenMaya, Py-2
input lines = 0.13 s. Total = 0.13 s.
lines to two arrays = 4.24 s. Total = 4.37 s.
output set = 3.77 s. Total = 8.14 s.
set to sort list = 0.08 s. Total = 8.22 s.
edges array out = 0.03 s. Total = 8.25 s.
select edges = 0.00 s. Total = 8.25 s.
delete edges = 30.94 s. Total = 39.19 s.
MAYA 2019.3.1, standalone, maya.api.OpenMaya, Py-2
input lines = 0.11 s. Total = 0.11 s.
lines to two arrays = 4.40 s. Total = 4.51 s.
output set = 3.86 s. Total = 8.37 s.
set to sort list = 0.08 s. Total = 8.45 s.
edges array out = 0.03 s. Total = 8.48 s.
select edges = 0.00 s. Total = 8.48 s.
delete edges = 30.94 s. Total = 39.42 s.