Ejemplo n.º 1
0
def decodeValue(jsonData):
    """Returns a constructed math value based on the provided json data.

    Args:
        jsondata (dict): The JSON data to use to decode into a Math value.

    Returns:
        object: The constructed math value

    """

    if type(jsonData) is not dict:
        return jsonData

    if '__mathObjectClass__' not in jsonData:
        raise Exception("Invalid JSON data for constructing value:" +
                        str(jsonData))

    if jsonData['__mathObjectClass__'] == 'Vec2':
        val = Vec2()
        val.jsonDecode(jsonData, decodeValue)
    elif jsonData['__mathObjectClass__'] == 'Vec3':
        val = Vec3()
        val.jsonDecode(jsonData, decodeValue)
    elif jsonData['__mathObjectClass__'] == 'Vec4':
        val = Vec4()
        val.jsonDecode(jsonData, decodeValue)
    elif jsonData['__mathObjectClass__'] == 'Euler':
        val = Euler()
        val.jsonDecode(jsonData, decodeValue)
    elif jsonData['__mathObjectClass__'] == 'Quat':
        val = Quat()
        val.jsonDecode(jsonData, decodeValue)
    elif jsonData['__mathObjectClass__'] == 'Xfo':
        val = Xfo()
        val.jsonDecode(jsonData, decodeValue)
    elif jsonData['__mathObjectClass__'] == 'Mat33':
        val = Mat33()
        val.jsonDecode(jsonData, decodeValue)
    elif jsonData['__mathObjectClass__'] == 'Mat44':
        val = Mat44()
        val.jsonDecode(jsonData, decodeValue)
    else:
        raise Exception("Unsupported Math type:" +
                        jsonData['__mathObjectClass__'])

    return val
Ejemplo n.º 2
0
    def setFromVectors(self, inVec1, inVec2, inVec3, translation):
        """Set Xfo values from 3 axis vectors and a translation vector.

        Args:
            inVec1 (Vec3): X axis vector.
            inVec2 (Vec3): Y axis vector.
            inVec3 (Vec3): Z axis vector.
            translation (Vec3): Translation vector.

        Returns:
            bool: True if successful.

        """

        mat33 = Mat33()
        mat33.setRows(inVec1, inVec2, inVec3)
        self.ori.setFromMat33(mat33.transpose())
        self.tr = translation

        return True