Example #1
0
    private CinematographyTechnique GetTechnique(string categoryID, StoryboardNode previousNode, StoryboardNode node, StoryboardDirectorData dirData, DecisionTechniquePreference pref, float dramThresh, float paceThresh, bool useFX)
    {
        int selectedIndex = -1;
        int it            = 0;

        CinematographyTechniqueCategory category         = dirData.m_categories.Find(o => o.m_title.CompareTo(categoryID) == 0);
        List <CinematographyTechnique>  dataList         = new List <CinematographyTechnique>(category.m_techniques);
        CinematographyTechnique         defaultTechnique = category.m_defaultTechnique;

        if (categoryID.CompareTo("FX") == 0 && !useFX)
        {
            return(dataList.Find(o => o.m_title.CompareTo("NoFX") == 0));
        }


        // Eliminate some techniques from the data list based on the previous node's technique information if necessary.
        if (previousNode != null)
        {
            ApplyShotBasedRuleset(categoryID, ref dataList, previousNode);
        }

        // Eliminate some techniques based on the current node's categories.
        ApplyNodeBasedRuleset(categoryID, ref dataList, node);

        // After we've selected the closest random technique, compare it's dramatization & pace.
        while (it < m_iterationTimeout)
        {
            // Select technique.
            if (pref == DecisionTechniquePreference.ProbabilityDistribution)
            {
                selectedIndex = MathUtility.GetCumulativeDistribution(dataList.Select(o => o.m_probabilityDistribution).ToArray());
            }
            else if (pref == DecisionTechniquePreference.ExponentialDistribution)
            {
                selectedIndex = MathUtility.GetCumulativeDistribution(dataList.Select(o => o.m_classDistribution).ToArray());
            }

            if (selectedIndex != -1)
            {
                // Check dramatization & pace thresholds for the selected technique.
                CinematographyTechnique techniqueData = dataList[selectedIndex];
                bool dramatizationChecks = dramThresh == 1.0f || (node.m_marker.m_dramatization > techniqueData.m_dramatization && node.m_marker.m_dramatization - techniqueData.m_dramatization < dramThresh);
                bool paceChecks          = paceThresh == 1.0f || (node.m_marker.m_pace > techniqueData.m_pace && node.m_marker.m_pace - techniqueData.m_pace < dramThresh);

                if (dramatizationChecks && paceChecks)
                {
                    return(techniqueData);
                }
            }

            it++;
        }
        dataList = null;
        return(defaultTechnique);
    }
Example #2
0
    public bool Simulate(StoryboardWindow window, Transform cameraTransform, StoryboardData data, TimelineAsset timeline, PlayableDirector playable,
                         ref int simulatedMarkerCount, string debugPositioning, string debugLook, string debugTrack, string debugFX, RenderTexture rt, bool simulateAll, int simulatedIndex = -1)
    {
        StoryboardNode previousNode = simulateAll ? null : (simulatedIndex == 0 ? null : data.m_nodes[simulatedIndex - 1]);

        int iStart = simulateAll ? 0 : simulatedIndex;
        int iEnd   = simulateAll ? data.m_nodes.Count : simulatedIndex + 1;

        for (int i = iStart; i < iEnd; i++)
        {
            StoryboardNode currentNode = data.m_nodes[i];

            if (currentNode.m_isLocked)
            {
                previousNode = currentNode;
                simulatedMarkerCount++;
                continue;
            }

            // Calculate target position
            SimulationTargetData targetData = new SimulationTargetData();
            targetData.m_target         = null;
            targetData.m_targetForward  = Vector3.forward;
            targetData.m_targetRight    = Vector3.right;
            targetData.m_targetUp       = Vector3.up;
            targetData.m_targetPosition = Vector3.zero;

            for (int j = 0; j < currentNode.m_marker.m_targets.Length; j++)
            {
                var objects = Resources.FindObjectsOfTypeAll <StoryboardTarget>().Where(obj => obj.gameObject.name == currentNode.m_marker.m_targets[j]);

                if (objects.Count <StoryboardTarget>() > 1)
                {
                    Debug.LogError("Multiple storyboard targets with the same name is found. Please make sure each target has a unique name to avoid any confusions.");
                    currentNode.m_simulationData = null;
                    data.m_nodes.Clear();
                    return(false);
                }

                GameObject go = GameObject.Find(currentNode.m_marker.m_targets[j]);

                if (go == null)
                {
                    Debug.LogError("The target " + currentNode.m_marker.m_targets[j] + " could not be found, aborting simulation.");
                    currentNode.m_simulationData = null;
                    data.m_nodes.Clear();
                    return(false);
                }

                targetData.m_targetPosition += go.transform.position;

                if (currentNode.m_marker.m_targets.Length == 1)
                {
                    targetData.m_target         = go.transform;
                    targetData.m_targetPosition = targetData.m_target.position;
                    targetData.m_targetForward  = targetData.m_target.forward;
                    targetData.m_targetRight    = targetData.m_target.right;
                    targetData.m_targetUp       = targetData.m_target.up;
                }
            }

            // Finalize target position as mid point.
            targetData.m_targetPosition /= currentNode.m_marker.m_targets.Length;

            StoryboardDirectorData      dirData = data.m_directorData;
            DecisionTechniquePreference pref    = data.m_decisionTechnique;
            float          dramThresh           = data.m_dramatizationThreshold;
            float          paceThresh           = data.m_paceThreshold;
            bool           useFX = data.m_useFX;
            bool           simulationSuccessful = false;
            int            timeoutCounter       = 0;
            StoryboardNode nextNode             = i < data.m_nodes.Count - 1 ? data.m_nodes[i + 1] : null;

            while (!simulationSuccessful && timeoutCounter < data.m_techniqueTimeout)
            {
                currentNode.m_positioningTechnique = GetTechnique("Positioning", previousNode, currentNode, dirData, pref, dramThresh, paceThresh, useFX);
                currentNode.m_simulationData       = new SimulationData();
                simulationSuccessful = currentNode.m_positioningTechnique.m_implementation.Simulate(data, currentNode, nextNode, targetData);
                timeoutCounter++;
            }

            // Set simulation's target data.
            currentNode.m_simulationData.m_targetData = targetData;


            //currentNode.m_lookTechnique = GetTechnique("Look", previousNode, currentNode, dirData, pref, dramThresh, paceThresh, useFX);
            //currentNode.m_trackTechnique = GetTechnique("Track", previousNode, currentNode, dirData, pref, dramThresh, paceThresh, useFX);
            //currentNode.m_fxTechnique = GetTechnique("FX", previousNode, currentNode, dirData, pref, dramThresh, paceThresh, useFX);

            // D E B U G
            if (debugPositioning != "")
            {
                currentNode.m_trackTechnique = data.m_directorData.m_categories[0].m_techniques.Find(o => o.m_title.CompareTo(debugPositioning) == 0);
            }
            if (debugLook != "")
            {
                currentNode.m_lookTechnique = data.m_directorData.m_categories[1].m_techniques.Find(o => o.m_title.CompareTo(debugLook) == 0);
            }
            if (debugTrack != "")
            {
                currentNode.m_trackTechnique = data.m_directorData.m_categories[2].m_techniques.Find(o => o.m_title.CompareTo(debugTrack) == 0);
            }
            if (debugFX != "")
            {
                currentNode.m_fxTechnique = data.m_directorData.m_categories[3].m_techniques.Find(o => o.m_title.CompareTo(debugFX) == 0);
            }

            ApplySimulationPropertiesToCamera(currentNode.m_simulationData, cameraTransform);
            currentNode.m_simulationData.m_snapshots.Add(TakeCameraSnapshot(cameraTransform.GetComponent <Camera>(), rt));

            previousNode = currentNode;
            simulatedMarkerCount++;
            targetData = null;
        }

        // Make sure we reset back the playable.
        playable.time = 0.0;
        playable.Evaluate();
        window.OnSimulationEnd();
        return(true);
    }