Skip to content

Instantly share code, notes, and snippets.

@ShikouYamaue
Created March 4, 2018 13:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ShikouYamaue/1816b38a50397ac45e2bf7d798a11b1e to your computer and use it in GitHub Desktop.
Save ShikouYamaue/1816b38a50397ac45e2bf7d798a11b1e to your computer and use it in GitHub Desktop.
Visualize lissajuous figure in Maya UI
from maya import cmds
import math
import imp
try:
imp.find_module('PySide2')
from PySide2.QtWidgets import *
from PySide2.QtGui import *
from PySide2.QtCore import *
except ImportError:
from PySide.QtGui import *
from PySide.QtCore import *
from maya.app.general.mayaMixin import MayaQWidgetBaseMixin
class Main(MayaQWidgetBaseMixin, QMainWindow):
def __init__(self, parent = None):
super(Main, self).__init__(parent)
self.create_locators()
wrapper = QWidget()
self.setCentralWidget(wrapper)
self.main_layout = QVBoxLayout()
wrapper.setLayout(self.main_layout)
#Xの角度比率
h_layout = QHBoxLayout()
self.main_layout.addLayout(h_layout)
label = QLabel('X(cos) Ratio :',self)
h_layout.addWidget(label)
self.__x_ratio = QSpinBox(self)
self.__x_ratio.setRange(1, 50)
self.__x_ratio.setValue(1)
h_layout.addWidget(self.__x_ratio)
self.__x_ratio_sld = QSlider(Qt.Horizontal,self)
self.__x_ratio_sld.setRange(1, 50)
self.__x_ratio_sld.setValue(self.__x_ratio.value())
h_layout.addWidget(self.__x_ratio_sld)
self.__x_ratio_sld.valueChanged[int].connect(lambda:self.__x_ratio.setValue(self.__x_ratio_sld.value()))
self.__x_ratio.editingFinished.connect(lambda:self.__x_ratio_sld.setValue(self.__x_ratio.value()))
self.__x_ratio.valueChanged.connect(self.relocate_objects)
#Xの角度オフセット
h_layout = QHBoxLayout()
self.main_layout.addLayout(h_layout)
label = QLabel('X(cos) Offset :',self)
h_layout.addWidget(label)
self.__x_offset = QSpinBox(self)
self.__x_offset.setRange(0, 360)
self.__x_offset.setValue(0)
h_layout.addWidget(self.__x_offset)
self.__x_offset_sld = QSlider(Qt.Horizontal,self)
self.__x_offset_sld.setRange(0, 360)
self.__x_offset_sld.setValue(self.__x_offset.value())
h_layout.addWidget(self.__x_offset_sld)
self.__x_offset_sld.valueChanged[int].connect(lambda:self.__x_offset.setValue(self.__x_offset_sld.value()))
self.__x_offset.editingFinished.connect(lambda:self.__x_offset_sld.setValue(self.__x_offset.value()))
self.__x_offset.valueChanged.connect(self.relocate_objects)
self.main_layout.addWidget(self._make_h_line())
#Yの角度比率
h_layout = QHBoxLayout()
self.main_layout.addLayout(h_layout)
label = QLabel('Y(sin) Ratio :',self)
h_layout.addWidget(label)
self.__y_ratio = QSpinBox(self)
self.__y_ratio.setRange(1, 50)
self.__y_ratio.setValue(1)
h_layout.addWidget(self.__y_ratio)
self.__y_ratio_sld = QSlider(Qt.Horizontal,self)
self.__y_ratio_sld.setRange(1, 50)
self.__y_ratio_sld.setValue(self.__y_ratio.value())
h_layout.addWidget(self.__y_ratio_sld)
self.__y_ratio_sld.valueChanged[int].connect(lambda:self.__y_ratio.setValue(self.__y_ratio_sld.value()))
self.__y_ratio.editingFinished.connect(lambda:self.__y_ratio_sld.setValue(self.__y_ratio.value()))
self.__y_ratio.valueChanged.connect(self.relocate_objects)
#Yの角度オフセット
h_layout = QHBoxLayout()
self.main_layout.addLayout(h_layout)
label = QLabel('Y(sin) Offset :',self)
h_layout.addWidget(label)
self.__y_offset = QSpinBox(self)
self.__y_offset.setRange(0, 360)
self.__y_offset.setValue(0)
h_layout.addWidget(self.__y_offset)
self.__y_offset_sld = QSlider(Qt.Horizontal,self)
self.__y_offset_sld.setRange(0, 360)
self.__y_offset_sld.setValue(self.__y_offset.value())
h_layout.addWidget(self.__y_offset_sld)
self.__y_offset_sld.valueChanged[int].connect(lambda:self.__y_offset.setValue(self.__y_offset_sld.value()))
self.__y_offset.editingFinished.connect(lambda:self.__y_offset_sld.setValue(self.__y_offset.value()))
self.__y_offset.valueChanged.connect(self.relocate_objects)
self.relocate_objects()
self.show()
def _make_h_line(self):
hline = QFrame()
hline.setFrameShape(QFrame.HLine)
hline.setFrameShadow(QFrame.Sunken)
return hline
def create_locators(self):
self.all_locators = [cmds.spaceLocator(p=[0]*3)[0] for i in range(1800)]
def relocate_objects(self):
for i, loc in enumerate(self.all_locators):
a = i*self.__x_ratio.value()/5.0+self.__x_offset.value()
b = i*self.__y_ratio.value()/5.0+self.__y_offset.value()
rad_a = a/180.0*math.pi
rad_b = b/180.0*math.pi
cos = math.cos(rad_a)
sin = math.sin(rad_b)
cmds.move(cos*100, sin*100, 0, loc)
def closeEvent(self, e):
cmds.delete(self.all_locators)
Main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment