How to increase the processing speed of vertex position acquisition

This article is the 7th day article of ** Maya Advent Calender 2019 **.

When you create a modeling tool in Maya, you may get the vertex positions of the selected object. However, in a model with many vertices, it is slow to acquire all vertex positions with ** MEL ** or ** cmds **, which is a level that hinders modeling work. ** Open Maya ** is often introduced as a way to increase the processing speed, but it is a high threshold for me, and I was wondering if there was a way to increase the processing speed with ** cmds **.

Previous way of writing

I used to write this way.

from maya import cmds

sel_obj = cmds.ls(sl=True)
verts = cmds.ls(sel_obj[0] + '.vtx[*]', fl=True)
vert_pos = [cmds.xform(vert, t=True, ws=True, q=True) for vert in verts]

However, if you get it in this way, it will take a long time if the object has many vertices.

Try to measure the processing speed

First, create a very beautiful sphere with ** Subdivisions Axis ** and ** Subdivisions Height ** in the scene, both ** 200 **.

The number of vertices is ** 39802 **.

Select this sphere and measure the above script using Python's time module.

It took about 2 seconds. At this speed, modeling work will be hindered.

New way of writing

from maya import cmds

sel_obj = cmds.ls(sl=True)
verts = cmds.ls(sel_obj[0] + '.vtx[*]')
vert_pos = cmds.xform(verts, t=True, ws=True, q=True)

The ** fl ** flag of the ** ls ** command is removed, and the list of acquired vertices is collectively given to the argument of ** xform **. Now let's measure the processing speed again.

** About 0.06 seconds! It's about 33 times faster. ** **

Replace with a list by XYZ

However, if you look at the returned values, it is a one-dimensional array, so in order to return the same values as when processing with for, you need to add the following code and replace it with a two-dimensional array for each XYZ.

vert_pos = [vert_pos[i:i + 3] for i in range(0, len(vert_pos), 3)]

Summary

As mentioned above, it was a method to increase the processing speed of vertex position acquisition.

It's a very small article, but it was a discovery for me, so I wrote a memo. Maya has a function that can take such a list as an argument, which can be considerably faster than processing with for, or even when giving a list, it can be faster by eliminating duplication.

As far as I can see, I can't see in the official docs if the argument can be listed, so it's annoying to just test it ...

If you have any mistakes or unclear points in the article, I would appreciate it if you could write them down. Until the end Thank you for reading.

Recommended Posts

How to increase the processing speed of vertex position acquisition
How to increase the axis
How to increase the number of machine learning dataset images
Consider the speed of processing to shift the image buffer with numpy.ndarray
How to get the vertex coordinates of a feature in ArcPy
How to speed up instantiation of BeautifulSoup
How to check the version of Django
[Python] How to specify the window display position and size of matplotlib
How to calculate the volatility of a brand
How to find the area of the Voronoi diagram
About the processing speed of SVM (SVC) of scikit-learn
How to measure line speed from the terminal
I checked the processing speed of numpy one-dimensionalization
How to know the port number of the xinetd service
How to get the number of digits in Python
How to visualize the decision tree model of scikit-learn
[Blender] How to dynamically set the selection of EnumProperty
[Python] Summary of how to specify the color of the figure
How to hit the document of Magic Function (Line Magic)
How to access the global variable of the imported module
[Selenium] How to specify the relative path of chromedriver?
I want to increase the security of ssh connections
An easy way to measure the processing speed of a disk recognized by Linux
I tried to compare the processing speed with dplyr of R and pandas of Python
Increase the speed of the Monte Carlo method of Cython cut-out implementation.
[Ubuntu] How to delete the entire contents of a directory
How to find the optimal number of clusters in k-means
python3 Measure the processing speed.
How to test the attributes added by add_request_method of pyramid
How to use the generator
How to calculate the amount of calculation learned from ABC134-D
(Note) How to pass the path of your own module
How to summarize the results of FreeSurfer ~ aparc, aseg, wmparc ~
How to run the Export function of GCP Datastore automatically
Attempt to automatically adjust the speed of time-lapse movies (Part 2)
How to see the contents of the Jupyter notebook ipynb file
How to find the scaling factor of a biorthogonal wavelet
How to use the decorator
How to start the program
How to connect the contents of a list into a string
How to handle multiple versions of CUDA in the same environment
How to determine the existence of a selenium element in Python
How to change the log level of Azure SDK for Python
How to implement Java code in the background of RedHat (LinuxONE)
How to know the internal structure of an object in Python
How to change the color of just the button pressed in Tkinter
How to get the ID of Type2Tag NXP NTAG213 with nfcpy
[Python] How to get divisors of natural numbers at high speed
[EC2] How to install chrome and the contents of each command
How to check the memory size of a variable in Python
Make the theme of Pythonista 3 like Monokai (how to make your own theme)
[Python] How to get the first and last days of the month
How to check the memory size of a dictionary in Python
[TensorFlow 2] How to check the contents of Tensor in graph mode
[Linux] How to disable the automatic update of the /etc/resolv.conf file (AmazonLinux2)
How to find the memory address of a Pandas dataframe value
How to output the output result of the Linux man command to a file
How to monitor the execution status of sqlldr with the pv command
How to use Jupyter on the front end of supercomputer ITO
The first artificial intelligence. How to check the version of Tensorflow installed.
How to use machine learning for work? 01_ Understand the purpose of machine learning