<commit_before>from kraken.core.maths import Xfo, Vec3, Quat

from kraken.core.synchronizer import Synchronizer
from kraken.plugins.maya_plugin.utils import *
from kraken.plugins.maya_plugin.utils.curves import curveToKraken

from kraken.core.objects.components.component import Component
from kraken.core.objects.attributes.attribute_group import AttributeGroup

class Synchronizer(Synchronizer):
    """The Synchronizer is a singleton object used to synchronize data between
    Kraken objects and the DCC objects."""

    def __init__(self):
        super(Synchronizer, self).__init__()


    # ============
    # DCC Methods
    # ============
    def getDCCItem(self, kObject):
        """Gets the DCC Item from the full decorated path.

        Args:
            kObject (object): The Kraken Python object that we must find the corresponding DCC item.

        Returns:
            object: The created DCC object.

        """

        path = kObject.getPath()
        pathSections = path.split('.')
        pathObj = kObject
        mayaPath = ''
        index = len(pathSections) - 1
        for pathSection in reversed(pathSections):

            if pathObj is None:
                raise Exception("parent not specified for object, so a full path cannot be resolved to a maya object:" + path)

            if pathObj.isTypeOf('AttributeGroup'):
                # We don't build an attribute group in Maya, so skip this object
                pass

            elif pathObj.isTypeOf('Attribute'):
                # The attribute object requires a '.' seperator in the Maya path.
                mayaPath = '.' + pathObj.getName()

            else:
                if index > 0:
                    mayaPath = '|' + pathObj.getBuildName() + mayaPath
                else:
                    mayaPath = pathObj.getBuildName() + mayaPath

            pathObj = pathObj.getParent()
            index -= 1

        try:
            foundItem = pm.PyNode(mayaPath)
        except:
            return None

        return foundItem


    def syncXfo(self, kObject):
        """Syncs the xfo from the DCC object to the Kraken object.

        Args:
            kObject (object): Object to sync the xfo for.

        Returns:
            bool: True if successful.

        """

        hrcMap = self.getHierarchyMap()

        if kObject not in hrcMap.keys():
            print "Warning! 3D Object '" + kObject.getName() + "' was not found in the mapping!"
            return False

        dccItem = hrcMap[kObject]['dccItem']

        if dccItem is None:
            print "Warning Syncing. No DCC Item for :" + kObject.getPath()
            return False

        dccPos = dccItem.getTranslation()
        dccQuat = dccItem.getRotation(quaternion=True).get()
        dccScl = dccItem.getScale()

        pos = Vec3(x=dccPos[0], y=dccPos[1], z=dccPos[2])
        quat = Quat(v=Vec3(dccQuat[0], dccQuat[1], dccQuat[2]), w=dccQuat[3])
        scl = Vec3(x=dccScl[0], y=dccScl[1], z=dccScl[2])

        newXfo = Xfo(tr=pos, ori=quat, sc=scl)<commit_msg>get world matrix when synching<commit_after>from kraken.core.maths import Xfo, Vec3, Quat

from kraken.core.synchronizer import Synchronizer
from kraken.plugins.maya_plugin.utils import *
from kraken.plugins.maya_plugin.utils.curves import curveToKraken

from kraken.core.objects.components.component import Component
from kraken.core.objects.attributes.attribute_group import AttributeGroup

class Synchronizer(Synchronizer):
    """The Synchronizer is a singleton object used to synchronize data between
    Kraken objects and the DCC objects."""

    def __init__(self):
        super(Synchronizer, self).__init__()


    # ============
    # DCC Methods
    # ============
    def getDCCItem(self, kObject):
        """Gets the DCC Item from the full decorated path.

        Args:
            kObject (object): The Kraken Python object that we must find the corresponding DCC item.

        Returns:
            object: The created DCC object.

        """

        path = kObject.getPath()
        pathSections = path.split('.')
        pathObj = kObject
        mayaPath = ''
        index = len(pathSections) - 1
        for pathSection in reversed(pathSections):

            if pathObj is None:
                raise Exception("parent not specified for object, so a full path cannot be resolved to a maya object:" + path)

            if pathObj.isTypeOf('AttributeGroup'):
                # We don't build an attribute group in Maya, so skip this object
                pass

            elif pathObj.isTypeOf('Attribute'):
                # The attribute object requires a '.' seperator in the Maya path.
                mayaPath = '.' + pathObj.getName()

            else:
                if index > 0:
                    mayaPath = '|' + pathObj.getBuildName() + mayaPath
                else:
                    mayaPath = pathObj.getBuildName() + mayaPath

            pathObj = pathObj.getParent()
            index -= 1

        try:
            foundItem = pm.PyNode(mayaPath)
        except:
            return None

        return foundItem


    def syncXfo(self, kObject):
        """Syncs the xfo from the DCC object to the Kraken object.

        Args:
            kObject (object): Object to sync the xfo for.

        Returns:
            bool: True if successful.

        """

        hrcMap = self.getHierarchyMap()

        if kObject not in hrcMap.keys():
            print "Warning! 3D Object '" + kObject.getName() + "' was not found in the mapping!"
            return False

        dccItem = hrcMap[kObject]['dccItem']

        if dccItem is None:
            print "Warning Syncing. No DCC Item for :" + kObject.getPath()
            return False

        dccPos = dccItem.getTranslation(space="world")
        dccQuat = dccItem.getRotation(quaternion=True, space="world").get()
        dccScl = dccItem.getScale()

        pos = Vec3(x=dccPos[0], y=dccPos[1], z=dccPos[2])
        quat = Quat(v=Vec3(dccQuat[0], dccQuat[1], dccQuat[2]), w=dccQuat[3])
        scl = Vec3(x=1.0, y=1.0, z=1.0) # we don't want scale recorded

        newXfo = Xfo(tr=pos, ori=quat, sc=scl)
{'fraction_non_alphanumeric': 0.09961064243997404, 'fraction_numerical': 0.006327060350421804, 'mean_word_length': 2.084042021010505, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4146309', 'n_tokens_mistral': 1875, 'n_tokens_neox': 1790, 'n_words': 527}