Ejemplo n.º 1
0
 public static void Write(string filename, CinematicModel model)
 {
     using (FileStream fs = new FileStream(filename, FileMode.Create))
     {
         xs.Serialize(fs, model);
     }
 }
Ejemplo n.º 2
0
 public static string WriteToXml(this CinematicModel plan)
 {
     using (StringWriter stream = new StringWriter())
     {
         xs.Serialize(stream, plan);
         stream.Flush();
         return(stream.ToString());
     }
 }
Ejemplo n.º 3
0
        public static CinematicModel Parse(string filename)
        {
            CinematicModel model = null;

            using (FileStream fs = new FileStream(filename, FileMode.Open))
            {
                model = (CinematicModel)xs.Deserialize(fs);
            }
            return(model);
        }
Ejemplo n.º 4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="storyPlanPath">path to the story plan to load</param>
        /// <param name="cinematicModelPath">path to the cinematic model to load</param>
        /// <returns></returns>
        public static FireBoltActionList CreateStoryActions(Story <UintV, UintT, IIntervalSet <UintV, UintT> > story, CM.CinematicModel cm, bool implicitActorCreation)
        {
            ActorActionFactory.cm = cm;
            FireBoltActionList aaq = new FireBoltActionList();

            ActorActionFactory.story = story;
            orderedObjectSets        = story.ObjectSetGraph.ReverseTopologicalSort().ToArray();
            //orderedActionTypes = story.ActionTypeGraph.ReverseTopologicalSort().ToArray();

            implicitActorInstantiations = new Dictionary <string, bool>();

            //buildInitialState(aaq);
            if (implicitActorCreation)
            {
                createActors(aaq);
            }

            //generate FireBolt actions for the steps
            foreach (IStoryAction <UintT> storyAction in story.Actions.Values)
            {
                CM.DomainAction domainAction = getStoryDomainAction(storyAction);
                if (domainAction == null)
                {
                    continue;
                }

                CM.Animation effectingAnimation = getEffectingAnimation(storyAction, domainAction);

                enqueueCreateActions(storyAction, domainAction, effectingAnimation, aaq, storyAction.Name);
                enqueueAnimateActions(storyAction, domainAction, effectingAnimation, aaq, storyAction.Name, implicitActorCreation);
                enqueueDestroyActions(storyAction, domainAction, effectingAnimation, aaq, storyAction.Name, implicitActorCreation);
                enqueuetranslateActions(storyAction, domainAction, effectingAnimation, aaq, storyAction.Name, implicitActorCreation);
                enqueueRotateActions(storyAction, domainAction, effectingAnimation, aaq, storyAction.Name, implicitActorCreation);
                enqueueAttachActions(storyAction, domainAction, effectingAnimation, aaq, storyAction.Name, implicitActorCreation);
            }
            return(aaq);
        }
Ejemplo n.º 5
0
 public static void Write(this CinematicModel plan, string filePath)
 {
     Write(filePath, plan);
 }
Ejemplo n.º 6
0
 public static void Write(this CinematicModel plan, Stream stream)
 {
     xs.Serialize(stream, plan);
 }
Ejemplo n.º 7
0
        public static void CreateActions(Story <UintV, UintT, IIntervalSet <UintV, UintT> > story, CM.CinematicModel cinematicModel, string cameraPlanPath,
                                         out CameraActionList cameraActionList, out FireBoltActionList discourseActionList)
        {
            cameraActionList    = new CameraActionList();
            discourseActionList = new FireBoltActionList();
            CameraPlan cameraPlan = Oshmirto.Parser.Parse(cameraPlanPath);

            if (cinematicModel.MillisPerTick != 1)
            {
                scaleTime(cinematicModel.MillisPerTick, cameraPlan);
            }


            uint  currentDiscourseTime    = 0;
            float previousStoryTimeOffset = 0;

            foreach (Block block in cameraPlan.Blocks)
            {
                float blockStartTime = Single.MaxValue;
                float blockEndTime   = Single.MinValue;
                foreach (var fragment in block.ShotFragments)
                {
                    uint fragmentStartTime = currentDiscourseTime;//removing increment.  cameras always execute after discourse actions currentDiscourseTime++;
                    uint fragmentEndTime   = fragmentStartTime + fragment.Duration;

                    if (fragmentStartTime < blockStartTime) //assumes same time scale for discourse and story
                    {
                        blockStartTime = fragmentStartTime;
                    }
                    if (fragmentEndTime > blockEndTime)
                    {
                        blockEndTime = fragmentEndTime;
                    }

                    cameraActionList.Add(new ShotFragmentInit(fragmentStartTime, cameraRig, fragment.Anchor, fragment.Height, fragment.Pan,
                                                              fragment.Lens, fragment.FStop, fragment.Framings, fragment.Direction, fragment.Angle, fragment.FocusPosition));

                    var            movementStartTime = fragmentStartTime + 1; //force moves to sort after inits
                    RotateRelative rotateWith        = null;                  //collect all the relative rotations together for the camera so we can avoid representational nightmares
                    Rotate         rotateTo          = null;                  //similarly collect absolute rotations...eventually we should cross check and/or merge this stuff
                    foreach (var movement in fragment.CameraMovements)
                    {
                        switch (movement.Type)
                        {
                        case CameraMovementType.Dolly:
                            switch (movement.Directive)
                            {
                            case (CameraMovementDirective.With):
                                cameraActionList.Add(new TranslateRelative(movement.Subject, movementStartTime, fragmentEndTime, cameraRig, false, true, false));
                                break;

                            case (CameraMovementDirective.To):
                                Vector2 destination;
                                if (movement.Subject.TryParsePlanarCoords(out destination))
                                {
                                    cameraActionList.Add(new Translate(movementStartTime, fragmentEndTime, cameraRig,
                                                                       null, new Vector3Nullable(destination.x, null, destination.y)));
                                }
                                break;
                            }
                            break;

                        case CameraMovementType.Crane:
                            switch (movement.Directive)
                            {
                            case CameraMovementDirective.With:
                                break;

                            case CameraMovementDirective.To:
                                cameraActionList.Add(new Translate(movementStartTime, fragmentEndTime, cameraRig,
                                                                   null, new Vector3Nullable(null, float.Parse(movement.Subject), null)));
                                break;
                            }
                            break;

                        case CameraMovementType.Pan:
                            switch (movement.Directive)
                            {
                            case CameraMovementDirective.With:
                                if (rotateWith != null)
                                {
                                    rotateWith.AppendAxis(movement.Subject, cameraRig, true, false);
                                }
                                else
                                {
                                    rotateWith = new RotateRelative(movement.Subject, movementStartTime, fragmentEndTime, cameraRig,
                                                                    true, false);
                                }

                                break;

                            case CameraMovementDirective.To:
                                if (rotateTo != null)
                                {
                                    rotateTo.AppendAxisY(float.Parse(movement.Subject));
                                }
                                else
                                {
                                    rotateTo = new Rotate(movementStartTime, fragmentEndTime, cameraRig, new Vector3Nullable(null, float.Parse(movement.Subject), null), null);
                                }
                                break;
                            }
                            break;

                        case CameraMovementType.Tilt:
                            switch (movement.Directive)
                            {
                            case CameraMovementDirective.With:         // will this co-execute with pan-with? not currently
                                if (rotateWith != null)
                                {
                                    rotateWith.AppendAxis(movement.Subject, cameraRig, false, true);
                                }
                                else
                                {
                                    rotateWith = new RotateRelative(movement.Subject, movementStartTime, fragmentEndTime, cameraRig,
                                                                    false, true);
                                }
                                break;

                            case CameraMovementDirective.To:
                                if (rotateTo != null)
                                {
                                    rotateTo.AppendAxisX(float.Parse(movement.Subject));
                                }
                                else
                                {
                                    rotateTo = new Rotate(movementStartTime, fragmentEndTime, cameraRig, new Vector3Nullable(float.Parse(movement.Subject), null, null), null);
                                }
                                break;
                            }
                            break;

                        case CameraMovementType.Focus:
                            switch (movement.Directive)
                            {
                            case CameraMovementDirective.With:
                                cameraActionList.Add(new Focus(movementStartTime, fragmentEndTime, cameraName, movement.Subject, true));
                                break;
                            }
                            break;
                        }
                    }
                    if (rotateWith != null)
                    {
                        cameraActionList.Add(rotateWith);
                    }
                    if (rotateTo != null)
                    {
                        cameraActionList.Add(rotateTo);
                    }
                    // Shake it off
                    if (fragment.Shake > float.Epsilon)
                    {
                        cameraActionList.Add(new Shake(movementStartTime, fragmentEndTime, cameraName, fragment.Shake));
                    }

                    currentDiscourseTime = fragmentEndTime + 1; //set fragments to end and next to start on next tick
                }
                if (block.StoryTime.HasValue)
                {
                    float currentStoryTimeOffset = block.StoryTime.Value - blockStartTime;
                    discourseActionList.Add(new SetStoryTime(currentStoryTimeOffset, previousStoryTimeOffset, blockStartTime, blockEndTime));
                    previousStoryTimeOffset = block.StoryTime.Value;
                }
            }
            cameraActionList.EndDiscourseTime = currentDiscourseTime;
        }
Ejemplo n.º 8
0
    /// <summary>
    /// does the actual re-init work.  should only be called after destroy has had time to process.
    /// currently this involves an elaborate set of bools to keep up with engine execution
    /// </summary>
    private void init()
    {
        var loadStats = new Dictionary <string, string>();
        var loadStart = DateTime.Now;

        createdGameObjects = new GameObjectRegistry();
        createdGameObjects.Add("Rig", GameObject.Find("Rig"));//get the camera where we can find it quickly
        GameObject proCam = GameObject.Find("Pro Cam");

        createdGameObjects.Add(proCam.name, proCam);
        if (reloadStoryPlan)
        {
            Debug.Log(string.Format("loading story plan[{0}] @ [{1}].  last read [{2}]",
                                    currentInputSet.StoryPlanPath, DateTime.Now.ToString(timestampFormat), storyPlanLastReadTimeStamp.ToString(timestampFormat)));
            var impulseLoadStart = DateTime.Now;
            loadStructuredImpulsePlan(currentInputSet.StoryPlanPath);
            loadStats.Add("story plan", getElapsedTimeMillis(impulseLoadStart).ToString());
            storyPlanLastReadTimeStamp = DateTime.Now;
        }

        if (reloadCinematicModel)
        {
            Debug.Log(string.Format("loading cinematic model[{0}] @ [{1}].  last read [{2}]",
                                    currentInputSet.CinematicModelPath, DateTime.Now.ToString(timestampFormat), storyPlanLastReadTimeStamp.ToString(timestampFormat)));
            var cmLoadStart = DateTime.Now;
            cinematicModel = CM.Parser.Parse(currentInputSet.CinematicModelPath);
            loadStats.Add("cinematic model", getElapsedTimeMillis(cmLoadStart).ToString());
            cinematicModelPlanLastReadTimeStamp = DateTime.Now;
        }

        if (actorsAndAnimations != null && reloadActorsAndAnimationsBundle)
        {
            actorsAndAnimations.Unload(true);
        }


        if (reloadActorsAndAnimationsBundle)
        {
            Debug.Log(string.Format("loading actors bundle[{0}] @ [{1}].  last read [{2}]",
                                    currentInputSet.ActorsAndAnimationsBundlePath, DateTime.Now.ToString(timestampFormat), storyPlanLastReadTimeStamp.ToString(timestampFormat)));
            var actorBundleLoadStart = DateTime.Now;
            actorsAndAnimations = AssetBundle.LoadFromFile(currentInputSet.ActorsAndAnimationsBundlePath);
            loadStats.Add("actor bundle", getElapsedTimeMillis(actorBundleLoadStart).ToString());
            actorsAndAnimationsBundleLastReadTimeStamp = DateTime.Now;
        }

        if (terrain != null && reloadTerrainBundle)
        {
            terrain.Unload(true);
        }

        if (reloadTerrainBundle)
        {
            Debug.Log(string.Format("loading terrain bundle[{0}] @ [{1}].  last read [{2}]",
                                    currentInputSet.TerrainBundlePath, DateTime.Now.ToString(timestampFormat), storyPlanLastReadTimeStamp.ToString(timestampFormat)));
            var terrainBundleLoadStart = DateTime.Now;
            terrain = AssetBundle.LoadFromFile(currentInputSet.TerrainBundlePath);
            loadStats.Add("terrain bundle", getElapsedTimeMillis(terrainBundleLoadStart).ToString());
            terrainBundleLastReadTimeStamp = DateTime.Now;
            var terrainCreateStart = DateTime.Now;
            instantiateTerrain();
            loadStats.Add("terrain create", getElapsedTimeMillis(terrainCreateStart).ToString());
        }

        if (reloadStoryPlan || reloadActorsAndAnimationsBundle || reloadCinematicModel)
        {
            Debug.Log(string.Format("upstream components reloaded, rebuilding actor action queue @ [{0}].",
                                    DateTime.Now.ToString(timestampFormat)));
            var actionCreateStart = DateTime.Now;
            actorActionList = ActorActionFactory.CreateStoryActions(story, cinematicModel, implicitActorCreation);
            loadStats.Add("actor action create", getElapsedTimeMillis(actionCreateStart).ToString());
        }

        if (reloadStoryPlan || reloadCameraPlan)
        {
            Debug.Log(string.Format("upstream components reloaded, rebuilding camera action queue @ [{0}].",
                                    DateTime.Now.ToString(timestampFormat)));
            var discourseActionCreateStart = DateTime.Now;
            CameraActionFactory.CreateActions(story, cinematicModel, currentInputSet.CameraPlanPath, out cameraActionList, out discourseActionList);
            loadStats.Add("discourse action create", getElapsedTimeMillis(discourseActionCreateStart).ToString());
            cameraPlanLastReadTimeStamp = DateTime.Now;
        }

        currentDiscourseTime                = 0;
        currentStoryTime                    = 0;
        actorActionList.NextActionIndex     = 0;
        cameraActionList.NextActionIndex    = 0;
        discourseActionList.NextActionIndex = 0;

        executingActorActions     = new FireBoltActionList(new ActionTypeComparer());
        executingCameraActions    = new FireBoltActionList(new ActionTypeComparer());
        executingDiscourseActions = new FireBoltActionList(new ActionTypeComparer());
        GameObject instantiatedObjects = new GameObject("InstantiatedObjects");

        instantiatedObjects.transform.SetParent((GameObject.Find("FireBolt") as GameObject).transform);
        createdGameObjects.Add(instantiatedObjects.name, instantiatedObjects);

        if (generateKeyframes)
        {
            // Call the screenshot coroutine to create keyframe images for scrubbing.
            StartCoroutine(CreateScreenshots());
        }

        if (miniMapController != null)
        {
            List <string> actorNames = new List <string>();
            //get list of main actors to show on the minimap
            if (story.ObjectSets.ContainsKey("Main-Actors"))
            {
                foreach (var actor in (story.ObjectSets["Main-Actors"] as IFiniteObjectSet).Items)
                {
                    actorNames.Add(actor.Value.ToString());
                }
            }
            else
            {
                Debug.Log("Main-Actors group not defined.  Actors will not be shown on the minimap.");
            }
            miniMapController.InitializeMiniMap(actorNames);
        }


        initialized   = true;
        initNext      = false;
        initTriggered = false;

        reloadActorsAndAnimationsBundle = false;
        reloadCameraPlan     = false;
        reloadCinematicModel = false;
        reloadStoryPlan      = false;
        reloadTerrainBundle  = false;
        loadStats.Add("total", getElapsedTimeMillis(loadStart).ToString());
        Extensions.LogStatistics(loadStats);
    }