Example #1
0
 def updateMatrix(self):
     self._matrix.setToIdentity()
     self._matrix.rotate(self._angle, QVector3D(0, 1, 0))
     self._matrix.translate(self._radius, 0, 0)
     if self._target is not None:
         self._target.setMatrix(self._matrix)
 def setScaleByScalar(self, scalar: float):
     self.__currentObject.scaleVector = QVector3D(scalar, scalar, scalar)
Example #3
0
def anglesQuaternionToSph(quaternion):
    fromVect = QVector3D(1, 0, 0)
    toVect = quaternion.rotatedVector(fromVect)
    phi = atan2(toVect.y(), toVect.x())
    theta = acos(toVect.z() / toVect.length())
    return [phi, theta]
Example #4
0
 def setVector3(self, name, v):
     if self.enabled <= 0:
         raise Exception("shader must be enabled")
     self.program.setUniformValue(name, QVector3D(*v.flat))
 def vector(self) -> QVector3D:
     vector = self.attributes.get_attribute_value(CommonAttrs.VECTOR)
     return (
         QVector3D(vector[0], vector[1], vector[2]) if vector is not None else None
     )
Example #6
0
 def __init__(self, name, scene = None, material = None, translation = QVector3D(), rotation = QVector3D(), scale = QVector3D(1.0, 1.0, 1.0), emitterShape = SceneObjectType.SPHERE, intensity = 1.0, color = QVector4D(1.0, 1.0, 1.0, 1.0), isVisible = True):
     super().__init__(name, scene, material, translation, rotation, scale)
     self.emitterShape = emitterShape
     self.intensity = intensity
     self.color = color
     self.isVisible = isVisible
Example #7
0
    def onDraw(self):
        self.__modelMatrix.setToIdentity()

        self.__modelMatrix.translate(self.__translate)
        self.__modelMatrix.scale(self.__scale)
        self.__modelMatrix.rotate(90, QVector3D(1.0, 0.0, 0.0))
    def _create_transformations(self, json_transformations: list):
        """
        Uses the information contained in the JSON dictionary to construct a list of Transformations.
        :param json_transformations: A list of JSON transformation entries.
        """
        for json_transformation in json_transformations:
            is_nx_log = (CommonKeys.TYPE in json_transformation
                         and json_transformation[CommonKeys.TYPE]
                         == NodeType.GROUP)
            if is_nx_log:
                tmp = json_transformation[CommonKeys.CHILDREN][0]
                if CommonKeys.ATTRIBUTES in tmp:
                    tmp[CommonKeys.ATTRIBUTES] += json_transformation[
                        CommonKeys.ATTRIBUTES]
                else:
                    tmp[CommonKeys.ATTRIBUTES] = json_transformation[
                        CommonKeys.ATTRIBUTES]
                tmp[NodeType.CONFIG][CommonKeys.NAME] = json_transformation[
                    CommonKeys.NAME]
                json_transformation = tmp
            config = self._get_transformation_attribute(
                NodeType.CONFIG, json_transformation)
            if not config:
                continue

            module = self._get_transformation_attribute(
                CommonKeys.MODULE, json_transformation)
            if not module:
                continue

            name = self._get_transformation_attribute(CommonKeys.NAME, config)
            dtype = self._get_transformation_attribute(
                [CommonKeys.DATA_TYPE, CommonKeys.TYPE],
                config,
                name,
            )
            if not dtype:
                continue
            dtype = self._parse_dtype(dtype, name)
            if not dtype:
                continue

            attributes = self._get_transformation_attribute(
                CommonKeys.ATTRIBUTES, json_transformation, name)
            if not attributes:
                continue

            units = self._find_attribute_in_list(CommonAttrs.UNITS, name,
                                                 attributes)
            if not units:
                continue

            transformation_type = self._find_attribute_in_list(
                CommonAttrs.TRANSFORMATION_TYPE,
                name,
                attributes,
            )
            if not transformation_type:
                continue
            transformation_type = self._parse_transformation_type(
                transformation_type, name)
            if not transformation_type:
                continue

            vector = self._find_attribute_in_list(CommonAttrs.VECTOR, name,
                                                  attributes, [0.0, 0.0, 0.0])
            # This attribute is allowed to be missing, missing is equivalent to the value "." which means
            # depends on origin (end of dependency chain)
            depends_on = _find_attribute_from_list_or_dict(
                CommonAttrs.DEPENDS_ON, attributes)
            if module == DATASET:
                values = self._get_transformation_attribute(
                    CommonKeys.VALUES, config, name)
                if values is None:
                    continue
                angle_or_magnitude = values
                values = _create_transformation_dataset(
                    angle_or_magnitude, dtype, name)
            elif module in [writer_mod.value for writer_mod in WriterModules]:
                values = _create_transformation_datastream_group(
                    json_transformation)
                angle_or_magnitude = 0.0
            else:
                continue
            temp_depends_on = None

            transform = self.parent_component._create_and_add_transform(
                name=name,
                transformation_type=transformation_type,
                angle_or_magnitude=angle_or_magnitude,
                units=units,
                vector=QVector3D(*vector),
                depends_on=temp_depends_on,
                values=values,
            )
            if depends_on not in DEPENDS_ON_IGNORE:
                depends_on_id = TransformId(
                    *get_component_and_transform_name(depends_on))
                self._transforms_with_dependencies[TransformId(
                    self.parent_component.name,
                    name)] = (transform, depends_on_id)
            else:
                self._transforms_with_dependencies[TransformId(
                    self.parent_component.name, name)] = (transform, None)
Example #9
0
 def setUp(self):
     self.original = QVector3D(1, 2, 3)