3D model animation in Python

I have an application on PyQt and I want to add a window with animation 3D models.

I have the rig of this model, the model and its textures. Can you tell me how to animate this model and its rig, well, and display it all in the window PyQt? (With 3D working in python for the first time)

Application file .py code:

import sys
from PyQt5.QtWidgets import *
from PyQt5.uic import loadUi

class ModelView(QWidget):
    def __init__(self):
        super(ModelView,self).__init__()
        loadUi('GUI/3DView.ui',self)
        self.setWindowTitle('Модель')
        self.playButton.clicked.connect(self.playBut)
        self.stopButton.clicked.connect(self.stopBut)
    def playBut(self):
        pass
    def stopBut(self):
        pass


app = QApplication(sys.argv)
widget = ModelView()
widget.show()
sys.exit(app.exec())

Code .file ui:

<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
 <class>Form</class>
 <widget class="QWidget" name="Form">
  <property name="geometry">
   <rect>
    <x>0</x>
    <y>0</y>
    <width>332</width>
    <height>547</height>
   </rect>
  </property>
  <property name="windowTitle">
   <string>Form</string>
  </property>
  <widget class="QOpenGLWidget" name="modelView">
   <property name="geometry">
    <rect>
     <x>10</x>
     <y>10</y>
     <width>300</width>
     <height>481</height>
    </rect>
   </property>
  </widget>
  <widget class="QPushButton" name="playButton">
   <property name="geometry">
    <rect>
     <x>10</x>
     <y>500</y>
     <width>91</width>
     <height>23</height>
    </rect>
   </property>
   <property name="text">
    <string>Воспроизвести</string>
   </property>
  </widget>
  <widget class="QPushButton" name="stopButton">
   <property name="geometry">
    <rect>
     <x>220</x>
     <y>500</y>
     <width>91</width>
     <height>23</height>
    </rect>
   </property>
   <property name="text">
    <string>Остановить</string>
   </property>
  </widget>
 </widget>
 <resources/>
 <connections/>
</ui>

Model Application

Author: S. Nick, 2021-01-10

1 answers

I'm not familiar with Blender, but if you use VTK, it looks like this.

VTK - It is an open source software system for image processing, 3D graphics, volumetric rendering, and visualization.

VTK it includes many advanced algorithms (e.g. surface reconstruction, implicit modeling, thinning) and rendering techniques (e.g. volume rendering with hardware acceleration, level control details).

import sys
from PyQt5.QtWidgets import QMainWindow, QApplication, QDesktopWidget
from PyQt5.QtWidgets import QFrame, QVBoxLayout

import vtk
from vtk.util.colors import tomato
from vtk.qt.QVTKRenderWindowInteractor import QVTKRenderWindowInteractor


class MouseInteractorStyle(vtk.vtkInteractorStyleTrackballCamera):
    def __init__(self, parent=None):
        self.AddObserver("LeftButtonPressEvent", self.leftButtonPressEvent)

    def leftButtonPressEvent(self, obj, event):
        self.OnLeftButtonDown()


class Main(QMainWindow):
    def __init__(self):
        super().__init__()

        # source
        cylinder = vtk.vtkCylinderSource()
        cylinder.SetResolution(20)

        # mapper
        mapper = vtk.vtkPolyDataMapper()
        mapper.SetInputConnection(cylinder.GetOutputPort())

        # actor
        actor = vtk.vtkActor()
        actor.SetMapper(mapper)
        actor.GetProperty().SetColor(tomato)
        actor.RotateX(30.)
        actor.RotateY(-45.)

        # renderer
        ren = vtk.vtkRenderer()
        ren.AddActor(actor)
        ren.SetBackground(0.1, 0.2, 0.4)

        # interactor
        frame = QFrame()
        inter = QVTKRenderWindowInteractor(frame)
        inter.SetInteractorStyle(MouseInteractorStyle())

        ren_win = inter.GetRenderWindow()
        ren_win.AddRenderer(ren)

        ren.ResetCamera()
        ren.GetActiveCamera().Zoom(1.5)

        ren_win.Render()
        inter.Initialize()

        layout = QVBoxLayout()
        layout.addWidget(inter)
        frame.setLayout(layout)
        self.setCentralWidget(frame)

        self.setWindowTitle("Qt VTK")
        self.resize(320, 240)
        self.centerOnScreen()
        self.show()

    def centerOnScreen(self):
        res = QDesktopWidget().screenGeometry()
        self.move((res.width()/2) - (self.frameSize().width()/2),
                  (res.height()/2) - (self.frameSize().height()/2))


if __name__ == "__main__":
    app = QApplication(sys.argv)
    win = Main()
    sys.exit(app.exec_())

enter a description of the image here

 1
Author: S. Nick, 2021-01-11 12:11:28