Exemplo n.º 1
0
 def convertTextureSize(texturePath):
     if int(cmds.about(v=1)) < 2017:
         from PySide import QtCore
         from PySide.QtGui import QPixmap, QImage
         from PySide.QtCore import QFile, QIODevice
     else:
         from PySide2 import QtCore
         from PySide2.QtGui import QPixmap, QImage
         from PySide2.QtCore import QFile, QIODevice
     folder, fileName = ntpath.split(texturePath)
     origFileName = fileName if fileName[:
                                         8] != 'resized_' else fileName[
                                             8:]
     origPath = folder + '/' + origFileName
     if not os.path.exists(origPath):
         cmds.warning("original is not exists : %s" %
                      texturePath)
         return
     convertedFileName = 'resized_%d_' % (
         int(resolusion)) + origFileName
     renamedPath = folder + "/" + convertedFileName
     ext = os.path.splitext(fileName)[-1]
     img = QImage(origPath)
     pixmap = QPixmap()
     pixmap = pixmap.fromImage(
         img.scaled(int(resolusion), int(resolusion),
                    QtCore.Qt.IgnoreAspectRatio,
                    QtCore.Qt.FastTransformation))
     qfile = QFile(renamedPath)
     qfile.open(QIODevice.WriteOnly)
     pixmap.save(qfile, ext[1:], 100)
     qfile.close()
     return renamedPath
Exemplo n.º 2
0
 def savePng(self, filename, filetype='PNG'):
     rect = self.sceneRect()
     pix = QPixmap(rect.width(), rect.height())
     painter = QPainter(pix)
     self.render(painter, painter.window(), rect)
     pix.save(filename, filetype)
     del painter
     del pix
Exemplo n.º 3
0
class Image(object):
    id = None
    hotspot_x = hotspot_y = 0.0

    def __init__(self, filename, hotspot_x = 0, hotspot_y = 0):
        self.pixmap = QPixmap(filename)
        self.hotspot_x, self.hotspot_y = hotspot_x, hotspot_y

    def draw(self, painter, x = 0.0, y = 0.0):
        painter.drawPixmap(x - self.hotspot_x, y - self.hotspot_y, self.pixmap)

    def save(self, filename):
        self.pixmap.save(filename)

    def get_bounding_box(self):
        img = self.pixmap
        return (-self.hotspot_x, -self.hotspot_y, img.width(), img.height())
Exemplo n.º 4
0
class Image(object):
    id = None
    hotspot_x = hotspot_y = 0.0

    def __init__(self, filename, hotspot_x=0, hotspot_y=0):
        self.pixmap = QPixmap(filename)
        self.hotspot_x, self.hotspot_y = hotspot_x, hotspot_y

    def draw(self, painter, x=0.0, y=0.0):
        painter.drawPixmap(x - self.hotspot_x, y - self.hotspot_y, self.pixmap)

    def save(self, filename):
        self.pixmap.save(filename)

    def get_bounding_box(self):
        img = self.pixmap
        return (-self.hotspot_x, -self.hotspot_y, img.width(), img.height())
Exemplo n.º 5
0
class UVViewer(QDialog):
    def __init__(self, model, w, h, parent=None):
        super(UVViewer, self).__init__(parent)
        self.w = w
        self.h = h
        self.mdl = model
        self.white_b = QBrush(Qt.white)
        self.black_b = QBrush(Qt.black)
        self.pen_width = 2
        self.initUI()

    def initUI(self):
        mainlay = QVBoxLayout()
        scn = QGraphicsScene(0, 0, self.w, self.h)

        self.view = QGraphicsView()
        self.view.setScene(scn)
        self.view.setSceneRect(QRectF(0, 0, self.w, self.h))
        self.view.setMaximumWidth(self.w)
        self.view.setMaximumHeight(self.h)

        mainlay.addWidget(self.view)

        btns = QHBoxLayout()
        btns.addStretch()

        self.pen_w = QSpinBox()
        self.pen_w.setValue(self.pen_width)
        redraw = QPushButton('Redraw')
        redraw.clicked.connect(self.draw_uvs)
        save = QPushButton('Save')
        save.clicked.connect(self.save)
        close = QPushButton('Close')
        close.clicked.connect(self.close)

        btns.addWidget(QLabel('Stroke Width'))
        btns.addWidget(self.pen_w)
        btns.addWidget(redraw)
        btns.addWidget(save)
        btns.addWidget(close)

        mainlay.addLayout(btns)

        self.draw_uvs()

        self.setLayout(mainlay)
        self.setGeometry(340, 340, 512, 560)
        self.setWindowTitle('MSH Suite UV Viewer')
        self.show()

    def draw_uvs(self):
        self.img = QPixmap(QSize(self.w, self.h))
        pen = QPen()
        pen.setWidth(int(self.pen_w.text()))
        pen.setBrush(QBrush(Qt.white))
        pen.setColor(QColor('white'))
        painter = QPainter()
        painter.begin(self.img)
        painter.setPen(pen)
        coords = self.get_coords()
        for face in coords:
            for n in xrange(len(face) - 1):
                print face[n][0], face[n][1], face[n + 1][0], face[n + 1][1]
                painter.drawLine(face[n][0], face[n][1], face[n + 1][0], face[n + 1][1])
        painter.end()
        self.view.scene().addPixmap(self.img)

    def get_coords(self):
        coords = []
        for seg in self.mdl.segments:
            if seg.classname == 'SegmentGeometry':
                print 'doing stuff'
                vcoll = seg.vertices
                for face in seg.faces:
                    face_coords = []
                    for v in face.SIindices():
                        face_coords.append((vcoll[v].u * self.w, (1 - vcoll[v].v) * self.h))
                    face_coords.append((vcoll[face.vertices[0]].u * self.w,
                                        (1 - vcoll[face.vertices[0]].v) * self.h))
                    coords.append(face_coords)
                    #print face_coords
        return coords

    def save(self):
        filename, _ = QFileDialog.getSaveFileName(self, 'Save UV Mesh', os.getcwd(), 'PNG Files (*.png)')
        if not filename:
            return
        self.img.save(filename, 'PNG')
        self.close()