예제 #1
0
        protected EntityHistory ConvertEntityHistory(VrXmlHistoryData xmlHistory)
        {
            GameObject    ownerObject = string.IsNullOrEmpty(xmlHistory.entityId) ? gameObject : entityObjects[xmlHistory.entityId];
            EntityHistory history     = ownerObject.AddComponent <EntityHistory>();

            history.historyFileName = xmlHistory.fileName;
            history.sourceUpAxisIsZ = xmlHistory.upAxisIsZ;
            return(history);
        }
예제 #2
0
        protected VrXmlHistoryData ConvertObjectHistory(EntityHistory history)
        {
            VrXmlHistoryData xmlHistory = new VrXmlHistoryData();

            xmlHistory.entityId  = history.GetComponent <EntityData>().id;
            xmlHistory.fileName  = history.historyFileName;
            xmlHistory.upAxisIsZ = history.sourceUpAxisIsZ;
            return(xmlHistory);
        }
예제 #3
0
        public override void OnInspectorGUI()
        {
            // Update the serializedProperty - always do this in the beginning of OnInspectorGUI.
            serializedObject.Update();
            DrawDefaultInspector();
            GUILayout.Space(10);
            GUIStyle  guiStyle      = EditorStyles.foldout;
            FontStyle previousStyle = guiStyle.fontStyle;

            guiStyle.fontStyle = FontStyle.Bold;

            EntityHistory history = target as EntityHistory;

            GUI.enabled = false;
            DateTimeTk.DrawDateTime("Start Time", history.historyStartTime);
            DateTimeTk.DrawDateTime("End Time", history.historyEndTime);
            DateTimeTk.DrawTimeSpan("Offset", history.StartOffset);
            DateTimeTk.DrawTimeSpan("Duration", history.Duration);
            GUI.enabled = true;
            //foldOutStates = foldOutStates && history.entityStates.Length > 0;
            previousStyle      = guiStyle.fontStyle;
            guiStyle.fontStyle = FontStyle.Bold;
            foldOutStates      = EditorGUILayout.Foldout(foldOutStates, "States", guiStyle);
            guiStyle.fontStyle = previousStyle;
            GUILayout.Space(2);
            if (foldOutStates && history.entityStates != null)
            {
                EditorGUI.indentLevel++;
                for (int i = 0; i < history.entityStates.Length; i++)
                {
                    EntityState state = history.entityStates[i];
                    EditorGUILayout.LabelField("State " + i + " " + state.state);
                    EditorGUI.indentLevel++;
                    DrawState(state);
                    EditorGUI.indentLevel--;
                }
                EditorGUI.indentLevel--;
            }

            // Apply changes to the serializedProperty - always do this in the end of OnInspectorGUI.
            serializedObject.ApplyModifiedProperties();
        }
예제 #4
0
        public override void UpdateScenarioData()
        {
            UpdateEntityObjectsList();
            ClearScenarioData();
            SimController simController = GetComponent <SimController>();

            if (simController)
            {
                simController.StopSimulation();
                if (scenarioData.simulation == null)
                {
                    scenarioData.simulation = new VrXmlSimulationData();
                }
                scenarioData.simulation.historyUri  = simController.simulationHistory.historyUri;
                scenarioData.simulation.historyName = simController.simulationHistory.historyName;
                scenarioData.simulation.description = simController.simulationHistory.description;
                scenarioData.simulation.details     = simController.simulationHistory.details;
            }

            foreach (var entry in entityObjects)
            {
                var data = scenarioData.entityList.Find(x => x.id == entry.Key);
                if (data == null)
                {
                    data = new VrXmlEntityData();
                    scenarioData.entityList.Add(data);
                }
                UpdateEntity(entry.Value, data);
                // load simulation
                EntityHistory history = entry.Value.GetComponent <EntityHistory>();
                if (history)
                {
                    scenarioData.simulation.historyList.Add(ConvertObjectHistory(history));
                }
            }
        }
예제 #5
0
        public bool UpdateTarget()
        {
            if (entityHistory.entityStates.Length == 0 || targetTransform == null)
            {
                return(false);
            }
            EntityState prev_status;
            EntityState next_status;

            EntityState status = entityHistory.FindKeyFrame(simulationDateTime, out prev_status, out next_status);

            EntityState curr_status = null;

            if (status != null)
            {
                curr_status = status;
            }
            else if (prev_status != null)
            {
                curr_status = prev_status;
            }
            else if (next_status != null)
            {
                curr_status = next_status;
            }
#if UNITY_EDITOR
            foreach (var item in entityHistory.entityStates)
            {
                item.state = "(inactive)";
            }
            if (prev_status != null)
            {
                prev_status.state = " <-- Previous";
            }
            if (next_status != null)
            {
                next_status.state = " --> Next";
            }
            if (status != null)
            {
                status.state = ">Current<";
            }
#endif

            if (curr_status == null)
            {
                return(false);
            }

            // set parent
            if (curr_status.parentTransform != null)
            {
                targetTransform.parent = curr_status.parentTransform;
            }
            bool anim = status == null &&
                        (prev_status != null && next_status != null);
            if (!anim)
            {
                targetTransform.localPosition = curr_status.position;
                targetTransform.localRotation = curr_status.rotation;
            }

            // set representation
            //SimKeyFrame curr_repr_status = status;
            //if (curr_repr_status!=null) curr_repr_status = prev_status;

            //if (curr_repr_status && curr_repr_status->Representation)
            //{
            //    //LoadRepresentation(curr_status->Representation);
            //    SelectRepresentation(curr_repr_status->Representation->Name);
            //}
            //else
            //{
            //    // if no status is defined before this one reset representation
            //    RestoreRepresentation();
            //}

            if (!anim)
            {
                //ResetAnimation();
                return(true);
            }

            Vector3    start_pos = prev_status.position;
            Quaternion start_rot = prev_status.rotation;
            Vector3    end_pos   = next_status.position;
            Quaternion end_rot   = next_status.rotation;

            if (prev_status.parentTransform != next_status.parentTransform)
            {
                Matrix4x4 m1 = Matrix4x4.identity;
                if (prev_status.parentTransform != null)
                {
                    m1 = prev_status.parentTransform.worldToLocalMatrix;
                }
                Matrix4x4 m2 = Matrix4x4.identity;
                if (next_status.parentTransform != null)
                {
                    EntityState   next_status2            = null;
                    EntityHistory next_status_parent_hist = next_status.parentTransform.GetComponent <EntityHistory>();
                    if (next_status_parent_hist)
                    {
                        EntityState tmp1;
                        EntityState tmp2;
                        next_status2 = next_status_parent_hist.FindKeyFrame(next_status.startTime, out tmp1, out tmp2);
                    }
                    if (next_status2 != null)
                    {
                        Vector3    end_pos2 = next_status2.position;
                        Quaternion end_rot2 = next_status2.rotation;
                        if (next_status.parentTransform.parent != null)
                        {
                            m2 = next_status.parentTransform.parent.localToWorldMatrix;
                        }
                        Matrix4x4 mTmp = Matrix4x4.TRS(end_pos2, end_rot2, next_status.parentTransform.parent.lossyScale);
                        m2 *= mTmp;
                    }
                    else
                    {
                        m2 = next_status.parentTransform.localToWorldMatrix;
                    }
                }
                Matrix4x4 m = m1 * m2;
                // pos2 to the same local space as pos1
                end_pos = m.MultiplyPoint(next_status.position);
                // rot2 to the same local space as rot1
                end_rot = MathUtility.MatrixToQuaternion(m) * next_status.rotation;
            }
            float t = 0;
            if (prev_status.endTime != next_status.startTime)
            {
                t = (float)((simulationDateTime - prev_status.endTime).TotalSeconds
                            / (next_status.startTime - prev_status.endTime).TotalSeconds);
            }
            targetTransform.parent        = prev_status.parentTransform;
            targetTransform.localPosition = Vector3.Lerp(start_pos, end_pos, t);
            targetTransform.localRotation = Quaternion.Slerp(start_rot, end_rot, t);

            return(true);
        }