Example #1
0
    def controllers(self):
        """Return a list of the controllers that are currently on this 
		cache instance
		
		:return: a list of :class:`cross3d.SceneAnimationController`'s
			
		"""
        from cross3d import SceneAnimationController
        return [
            SceneAnimationController(self._scene, nativeControl)
            for nativeControl in self._nativeControllers()
        ]
Example #2
0
    def controller(self, name):
        """
		Lookup a controller based on the inputed controllerName for this object
		
		:return: :class:`cross3d.SceneAnimationController` or None
		
		"""
        nativeController = self._nativeController(name)
        if (nativeController):
            from cross3d import SceneAnimationController
            return SceneAnimationController(self._scene, nativeController)
        return None
    def createNew(cls, scene, controllerType):
        """Create a new controller in the scene of the inputed controller type
		
		:param scene: :class:`cross3d.Scene`
		:param controllerType: :data:`cross3d.constants.ControllerType`
		:return: the new :class:`cross3d.SceneAnimationController` or None
		
		"""
        nativeController = cls._createNewNative(scene, controllerType)
        if nativeController:
            from cross3d import SceneAnimationController
            return SceneAnimationController(scene, nativeController)
        return None
Example #4
0
    def controllers(self):
        """
		Return a list of SceneAnimationControllers that are linked to this 
		object and its properties
		
		:return: list of :class:`cross3d.SceneAnimationController` objects
			
		"""
        from cross3d import SceneAnimationController
        return [
            SceneAnimationController(self, nativeController)
            for nativeController in self._nativeControllers()
        ]
 def derivatedController(self):
     from cross3d import SceneAnimationController
     nativeController = self._nativeDerivatedController()
     if nativeController:
         return SceneAnimationController(self._scene, nativeController)
     return None
Example #6
0
 def addController(self, name, group='', tpe=float, default=0.0):
     from cross3d import SceneAnimationController
     return SceneAnimationController(
         self._scene, self._addNativeController(name, group, tpe, default))
Example #7
0
    def keyframeTimeControllers(self, alembic=True):
        """ Takes all Alembic, PC and TMC time controllers and keyframe their original time controllers.

		This is used as a base setup for further time alterations.

		Returns:
			SceneAnimationController|boolean: The bezier float keyframed controller used to control time.
		"""

        np = self._nativePointer
        timeController = None
        frameRate = self._scene.animationFPS()

        # Processing Alembic controllers.
        alembicControllers = mxs.getClassInstances(
            mxs.Alembic_Float_Controller, target=np)
        alembicControllers += mxs.getClassInstances(mxs.Alembic_Xform,
                                                    target=np)
        alembicControllers += mxs.getClassInstances(mxs.Alembic_Mesh_Geometry,
                                                    target=np)
        alembicControllers += mxs.getClassInstances(mxs.Alembic_Mesh_Normals,
                                                    target=np)
        for alembicController in alembicControllers:

            # Instantiating if we already computed the time controller.
            if not timeController:

                # Unfortunately the start and end frame of the cache data is not stored on the controller so we have to parse the file.
                import cask
                archive = cask.Archive(str(alembicController.path))
                item = archive.top.children[str(alembicController.identifier)]

                # Sometimes the identifier will point to a Xform object.
                # Unfortunately I did not find a way to access the sample count from there.
                # So instead I am digging through the hierarchy.
                while item.children:
                    item = item.children[item.children.keys()[0]]

                properties = item.iobject.getProperties()
                geometry = properties.getProperty(0)
                core = geometry.getProperty(0)
                sampleCount = core.getNumSamples()
                startTime = core.getTimeSampling().getSampleTime(0)
                endTime = core.getTimeSampling().getSampleTime(
                    (sampleCount - 1))

                # Creating the controller.
                timeController = mxs.bezier_float()
                frames = [(round(startTime * frameRate), startTime),
                          (round(endTime * frameRate), endTime)]
                for frame, value in frames:
                    k = mxs.addNewKey(timeController, frame)
                    k.value = value
                    k.inTangentType = mxs.pyhelper.namify('linear')
                    k.outTangentType = mxs.pyhelper.namify('linear')

            # Assigning the controller.
            mxs.setPropertyController(alembicController, 'time',
                                      timeController)

        # Processing TMCs and PCs.
        nativeCaches = mxs.getClassInstances(
            mxs.Transform_Cache, target=np) + mxs.getClassInstances(
                mxs.Point_Cache, target=np)
        for nativeCache in nativeCaches:

            # Unfortunately the start and end frame of the cache data is not stored on the controller so we have to parse the file.
            if mxs.classof(nativeCache) == mxs.Point_Cache:
                from blur3d.lib.pclib import PointCacheInfo
                cacheInfo = PointCacheInfo.read(nativeCache.filename,
                                                header_only=True)

            elif mxs.classof(nativeCache) == mxs.Transform_Cache:
                # Ensure file exists
                try:
                    from blur3d.lib.tmclib import TMCInfo
                    cacheInfo = TMCInfo.read(nativeCache.CacheFile,
                                             header_only=True)
                except IOError as e:
                    print "Cache file does not exist: {0}".format(
                        nativeCache.CacheFile)
                    continue

            # Playback type 3 is "Playback Graph".
            nativeCache.playbackType = 3

            # Set the playback frame to a float controller with start and end values pulled from the cache.
            mxs.setPropertyController(nativeCache, 'playbackFrame',
                                      mxs.bezier_float())
            timeController = mxs.getPropertyController(nativeCache,
                                                       'playbackFrame')

            # Set keys on the playback frame cache that matches the current frame rate.
            duration = cacheInfo.end_frame - cacheInfo.start_frame + 1
            frames = [(cacheInfo.start_frame, 0),
                      (cacheInfo.end_frame, duration)]
            for frame, value in frames:
                key = mxs.addNewKey(timeController, frame)
                key.value = value
                key.inTangentType = mxs.pyhelper.namify('linear')
                key.outTangentType = mxs.pyhelper.namify('linear')

        # Processing XMeshes.
        xMeshes = mxs.getClassInstances(mxs.XMeshLoader, target=np)
        for xMesh in xMeshes:

            # Enable curve playback.
            xMesh.enablePlaybackGraph = True

            # Create a new bezier float controller for the time.
            mxs.setPropertyController(xMesh, 'playbackGraphTime',
                                      mxs.bezier_float())
            timeController = mxs.getPropertyController(xMesh,
                                                       'playbackGraphTime')

            # Set keys on the playback in and out frames.
            frames = (xMesh.rangeFirstFrame, xMesh.rangeLastFrame)
            for frame in frames:
                key = mxs.addNewKey(timeController, frame)
                key.value = frame
                key.inTangentType = mxs.pyhelper.namify('linear')
                key.outTangentType = mxs.pyhelper.namify('linear')

        # Processing Ray Fire caches.
        rayFireCaches = mxs.getClassInstances(mxs.RF_Cache, target=np)
        for rayFireCache in rayFireCaches:

            # Enable curve playback.
            xMesh.playUseGraph = True

            # Create a new bezier float controller for the time.
            mxs.setPropertyController(rayFireCache, 'playFrame',
                                      mxs.bezier_float())
            timeController = mxs.getPropertyController(rayFireCache,
                                                       'playFrame')

            # Set keys on the playback in and out frames.
            frames = (xMesh.rangeFirstFrame, xMesh.rangeLastFrame)
            for frame in frames:
                key = mxs.addNewKey(timeController, frame)
                key.value = frame
                key.inTangentType = mxs.pyhelper.namify('linear')
                key.outTangentType = mxs.pyhelper.namify('linear')

        # Returning the time controller if defined.
        if timeController:
            # Making the extrapolation linear.
            linear = mxs.pyhelper.namify('linear')
            mxs.setBeforeORT(timeController, linear)
            mxs.setAfterORT(timeController, linear)
            from cross3d import SceneAnimationController
            return SceneAnimationController(self._scene, timeController)

        return None