mirror of
https://github.com/alicevision/Meshroom.git
synced 2025-04-29 02:08:08 +02:00
48 lines
2 KiB
Python
48 lines
2 KiB
Python
from PySide2.QtCore import QObject, Slot
|
|
from PySide2.Qt3DCore import Qt3DCore
|
|
from PySide2.Qt3DRender import Qt3DRender
|
|
from PySide2.QtGui import QVector3D, QQuaternion
|
|
|
|
|
|
class Scene3DHelper(QObject):
|
|
|
|
@Slot(Qt3DCore.QEntity, str, result="QVariantList")
|
|
def findChildrenByProperty(self, entity, propertyName):
|
|
""" Recursively get all children of an entity that have a property named 'propertyName'. """
|
|
children = []
|
|
for child in entity.childNodes():
|
|
try:
|
|
if child.metaObject().indexOfProperty(propertyName) != -1:
|
|
children.append(child)
|
|
except RuntimeError:
|
|
continue
|
|
children += self.findChildrenByProperty(child, propertyName)
|
|
return children
|
|
|
|
@Slot(Qt3DCore.QEntity, Qt3DCore.QComponent)
|
|
def addComponent(self, entity, component):
|
|
""" Adds a component to an entity. """
|
|
entity.addComponent(component)
|
|
|
|
@Slot(Qt3DCore.QEntity, Qt3DCore.QComponent)
|
|
def removeComponent(self, entity, component):
|
|
""" Removes a component from an entity. """
|
|
entity.removeComponent(component)
|
|
|
|
@Slot(Qt3DCore.QEntity, result=int)
|
|
def vertexCount(self, entity):
|
|
""" Return vertex count based on children QGeometryRenderer 'vertexCount'."""
|
|
return sum([renderer.vertexCount() for renderer in entity.findChildren(Qt3DRender.QGeometryRenderer)])
|
|
|
|
@Slot(Qt3DCore.QEntity, result=int)
|
|
def faceCount(self, entity):
|
|
""" Returns face count based on children QGeometry buffers size."""
|
|
count = 0
|
|
for geo in entity.findChildren(Qt3DRender.QGeometry):
|
|
count += sum([attr.count() for attr in geo.attributes() if attr.name() == "vertexPosition"])
|
|
return count / 3
|
|
|
|
@Slot(QQuaternion, QVector3D, result=QVector3D)
|
|
def rotatedVector(self, quaternion, vector):
|
|
""" Returns the rotation of 'vector' with 'quaternion'. """
|
|
return quaternion.rotatedVector(vector)
|