private void AddMarker(Mesh objectModel, Color color, int dataSetId, int sessionId, int conditionId) { var dataSet = Services.DataManager().DataSets[dataSetId]; GameObject marker = Instantiate(MarkerPrefab, Anchor); MeshFilter filter = marker.GetComponent <MeshFilter>(); filter.mesh = objectModel; Renderer renderer = marker.GetComponent <Renderer>(); TrajectoryMarker markerData = marker.GetComponent <TrajectoryMarker>(); markerData.DataSetId = dataSetId; markerData.SessionId = sessionId; markerData.ConditionId = conditionId; marker.transform.localPosition = dataSet.LocalPosition; marker.transform.localRotation = dataSet.LocalRotation; marker.transform.localScale = new Vector3(marker.transform.localScale.x * dataSet.LocalScale.x, marker.transform.localScale.y * dataSet.LocalScale.y, marker.transform.localScale.z * dataSet.LocalScale.z); renderer.material.color = color; markers.Add(marker); }
private void AddMarker(Color color, float size, int dataSetId, int sessionId, int conditionId) { GameObject marker = Instantiate(MarkerPrefab, Anchor); Renderer renderer = marker.GetComponent <Renderer>(); TrajectoryMarker markerData = marker.GetComponent <TrajectoryMarker>(); markerData.DataSetId = dataSetId; markerData.SessionId = sessionId; markerData.ConditionId = conditionId; if (visAnchorTransform) { marker.transform.localScale = new Vector3(size / visAnchorTransform.localScale.x, size / visAnchorTransform.localScale.y, 1); } else { marker.transform.localScale = new Vector3(size, size, 1); } renderer.material.color = color; marker.GetComponent <Renderer>().enabled = false; // do not show initially markers.Add(marker); }
private void Update() { if (isInitialized) { long currentTime = Services.StudyManager().CurrentTimestamp; foreach (var markerObject in markers) { TrajectoryMarker marker = markerObject.GetComponent <TrajectoryMarker>(); var dataSet = Services.DataManager().DataSets[marker.DataSetId]; if (dataSet.IsStatic) { continue; // skip static objects } int session = marker.SessionId; int condition = marker.ConditionId; int earlierIndex = dataSet.GetIndexFromTimestamp(currentTime, session, condition); var earlierInfoObject = dataSet.GetInfoObjects(session, condition)[earlierIndex]; if (earlierIndex + 1 >= dataSet.GetInfoObjects(session, condition).Count || earlierInfoObject.Timestamp >= currentTime) { marker.transform.localPosition = earlierInfoObject.Position; marker.transform.localRotation = earlierInfoObject.Rotation; } else { int laterIndex = earlierIndex + 1; var laterInfoObject = dataSet.GetInfoObjects(session, condition)[laterIndex]; float interpolant = (currentTime - earlierInfoObject.Timestamp) * 1.0f / (laterInfoObject.Timestamp - earlierInfoObject.Timestamp) * 1.0f; marker.transform.localPosition = Vector3.Lerp(earlierInfoObject.Position, laterInfoObject.Position, interpolant); marker.transform.localRotation = Quaternion.Lerp(earlierInfoObject.Rotation, laterInfoObject.Rotation, interpolant); } } } }
// Update is called once per frame private void Update() { if (isInitialized) { Transform worldAnchor = GameObject.FindGameObjectWithTag("VisRootAnchor").transform; long currentTime = Services.StudyManager().CurrentTimestamp; if (Services.VisManager().ViewContainers.ContainsKey(Settings.AnchorId)) { visAnchorTransform = Services.VisManager().ViewContainers[Settings.AnchorId].transform; } else { visAnchorTransform = this.transform; // this does not really help us at all, but at least we won't crash. :> } foreach (var markerObject in markers) { TrajectoryMarker marker = markerObject.GetComponent <TrajectoryMarker>(); var dataSet = Services.DataManager().DataSets[marker.DataSetId]; if (dataSet.IsStatic) { continue; } int session = marker.SessionId; int condition = marker.ConditionId; int currentIndex = dataSet.GetIndexFromTimestamp(currentTime, session, condition); var currentInfoObject = dataSet.GetInfoObjects(session, condition)[currentIndex]; if (currentInfoObject.Timestamp > currentTime) { Debug.LogWarning("DataSet.GetValueAtTime returned timestamp larger than argument: " + currentInfoObject.Timestamp + " > " + currentTime); if (currentIndex > 0) { currentInfoObject = dataSet.GetInfoObjects(session, condition)[currentIndex - 1]; // this should never happen but let's get the previous timestamp } } if (currentTime > currentInfoObject.Timestamp + (TimeWindow * TimeSpan.TicksPerSecond)) { // ToDo: Fade out? marker.GetComponent <Renderer>().enabled = false; } else { marker.GetComponent <Renderer>().enabled = true; marker.transform.position = ProjectToAnchorPlane(currentInfoObject.Position, worldAnchor, visAnchorTransform); if (visAnchorTransform) { marker.transform.localScale = new Vector3(currentInfoObject.Scale.x * markerSize / visAnchorTransform.localScale.x, currentInfoObject.Scale.y * markerSize / visAnchorTransform.localScale.y, 1); } else { marker.transform.localScale = new Vector3(currentInfoObject.Scale.x * markerSize, currentInfoObject.Scale.y * markerSize, 1); } } } } }