public override bool Simulate(StoryboardData data, StoryboardNode currentNode, StoryboardNode nextNode, SimulationTargetData targetData) { Vector3 finalPosition = Vector3.zero; Quaternion finalRotation = Quaternion.identity; int counter = 0; while (counter < data.m_implementationTimeout) { Vector3 onSphere1 = targetData.m_targetPosition + Random.onUnitSphere * m_radiusLB; Vector3 onSphere2 = targetData.m_targetPosition + Random.onUnitSphere * m_radiusUB; finalPosition = Vector3.Lerp(onSphere1, onSphere2, Random.value); finalRotation = Quaternion.LookRotation(targetData.m_targetPosition - finalPosition); if (CheckVisibility(data, currentNode, finalPosition, finalRotation, targetData)) { SetSimulationData(currentNode, finalPosition, finalRotation, data.m_defaultFOV); return(true); } counter++; } SetSimulationData(currentNode, finalPosition, finalRotation, data.m_defaultFOV); return(false); }
public override bool Simulate(StoryboardData data, StoryboardNode currentNode, StoryboardNode nextNode, SimulationTargetData targetData) { return(true); }
public override bool Simulate(StoryboardData data, StoryboardNode currentNode, StoryboardNode nextNode, SimulationTargetData targetData) { Vector3 finalPosition = Vector3.zero; Quaternion finalRotation = Quaternion.identity; int counter = 0; while (counter < data.m_implementationTimeout) { float distance = Random.Range(m_distanceLB, m_distanceUB); float directionMultiplier = m_fixedDirection ? (m_isRight ? 1.0f : -1.0f) : ((Random.Range(0.0f, 1.0f) < 0.5f) ? -1.0f : 1.0f); finalPosition = targetData.m_targetPosition + targetData.m_targetRight * directionMultiplier * distance; finalRotation = Quaternion.LookRotation(targetData.m_targetPosition - finalPosition); if (CheckVisibility(data, currentNode, finalPosition, finalRotation, targetData)) { SetSimulationData(currentNode, finalPosition, finalRotation, data.m_defaultFOV); return(true); } counter++; } SetSimulationData(currentNode, finalPosition, finalRotation, data.m_defaultFOV); return(false); }
protected bool CheckVisibility(StoryboardData data, StoryboardNode currentnode, Vector3 finalPosition, Quaternion finalRotation, SimulationTargetData targetData) { ProxySet proxySet = data.m_proxySets[currentnode.m_index]; if (proxySet.CheckIfContains(finalPosition)) { return(false); } RaycastHit hit; Vector3 dir = (targetData.m_targetPosition - finalPosition); if (Physics.SphereCast(finalPosition, data.m_visibilityCapsuleRadius, dir.normalized, out hit, dir.magnitude)) { if (targetData.m_target != null && hit.transform == targetData.m_target) { return(true); } else if (targetData.m_target != null && hit.transform != targetData.m_target) { return(Vector3.Distance(hit.point, targetData.m_target.position) < data.m_visibilityContactThreshold); } else if (targetData.m_target == null) { return(Vector3.Distance(hit.point, targetData.m_targetPosition) < data.m_visibilityContactThreshold); } else { return(false); } } return(true); }
public abstract bool Simulate(StoryboardData data, StoryboardNode currentNode, StoryboardNode nextNode, SimulationTargetData targetData);
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); }
public override bool Simulate(StoryboardData data, StoryboardNode currentNode, StoryboardNode nextNode, SimulationTargetData targetData) { float distance = 0.0f; Vector3 fwPosition = Vector3.zero; Vector3 rightPosition = Vector3.zero; Vector3 leftPosition = Vector3.zero; Vector3 upPosition = Vector3.zero; Vector3 downPosition = Vector3.zero; Vector3 finalPosition = Vector3.zero; Quaternion finalRotation = Quaternion.identity; int counter = 0; while (counter < data.m_implementationTimeout) { float t = Random.Range(-m_xArc, m_xArc); distance = Random.Range(m_distanceLB, m_distanceUB); fwPosition = targetData.m_targetPosition + targetData.m_targetForward * distance; rightPosition = targetData.m_targetPosition + targetData.m_targetRight * distance; leftPosition = targetData.m_targetPosition + -targetData.m_targetRight * distance; upPosition = targetData.m_targetPosition + targetData.m_targetUp * distance; downPosition = targetData.m_targetPosition + -targetData.m_targetUp * distance; finalPosition = fwPosition; if (t > 0) { finalPosition = MathUtility.SampleParabola(fwPosition, leftPosition, m_arcHeight, t, Quaternion.LookRotation(leftPosition - finalPosition) * Vector3.right); } else { finalPosition = MathUtility.SampleParabola(fwPosition, rightPosition, m_arcHeight, -t, Quaternion.LookRotation(rightPosition - finalPosition) * Vector3.left); } t = Random.Range(-m_yArc, m_yArc); if (t > 0) { finalPosition = MathUtility.SampleParabola(finalPosition, upPosition, m_arcHeight, t, Quaternion.LookRotation(upPosition - finalPosition) * Vector3.up); } else { finalPosition = MathUtility.SampleParabola(finalPosition, downPosition, m_arcHeight, -t, Quaternion.LookRotation(downPosition - finalPosition) * Vector3.down); } finalRotation = Quaternion.LookRotation(targetData.m_targetPosition - finalPosition); if (CheckVisibility(data, currentNode, finalPosition, finalRotation, targetData)) { SetSimulationData(currentNode, finalPosition, finalRotation, data.m_defaultFOV); return(true); } counter++; } SetSimulationData(currentNode, finalPosition, finalRotation, data.m_defaultFOV); return(false); }