Пример #1
0
        public void ImportSimLog()
        {
            SimLogParser parser = new SimLogParser();

            parser.ParseFile(historyFileName, sourceUpAxisIsZ);
            historyStartTime = parser.historyStartTime;
            historyEndTime   = parser.historyEndTime;
            historyDuration  = (parser.historyEndTime - historyStartTime).Ticks / TimeSpan.TicksPerSecond;
            List <SimLogRecord> history = parser.history;

            entityStates = new EntityState[history.Count];
            int i = 0;

            foreach (var record in history)
            {
                EntityState simKf = new EntityState();
                simKf.startTime = record.startTime; // (record.startTime - historyStartTime).Ticks / TimeSpan.TicksPerSecond;
                simKf.endTime   = record.endTime;   //(record.endTime - historyStartTime).Ticks / TimeSpan.TicksPerSecond;
                simKf.origin    = record.origin;
                simKf.position  = record.position;
                simKf.rotation  = CsConversion.RotMatToQuat(record.rotMatrix, sourceUpAxisIsZ);
#if UNITY_EDITOR
                simKf.eulerAngles = simKf.rotation.eulerAngles;
#endif
                EntityData parent_entity = DataUtil.FindEntity(record.parentId);
                simKf.parentTransform = parent_entity ? parent_entity.transform : null;
                entityStates[i]       = simKf;
                i++;
            }
        }
Пример #2
0
 public void FromTransform(Transform unityTransform, bool zUp)
 {
     position.Set(CsConversion.VecToVecRL(unityTransform.localPosition, zUp), 3);
     ////if(unityTransform.useRotationMatrix)
     ////{
     ////    rotationMatrix.FromMatrix4x4(CsConv.QuatToRotMat(unityTransform.localRotation));
     ////}
     ////else
     ////{
     ////    eulerAngles = unityTransform.localEulerAngles;
     ////}
     useRotationMatrix = false;
     rotationMatrix.FromMatrix4x4(MathUtility.QuaternionToMatrix(unityTransform.localRotation));
     eulerAngles.Set(unityTransform.localEulerAngles, 2);
     scale.Set(unityTransform.localScale, 3);
     if (unityTransform.parent)
     {
         EntityData parentEntity = unityTransform.parent.GetComponent <EntityData>();
         if (parentEntity)
         {
             relToId = unityTransform.parent.GetComponent <EntityData>().id;
         }
         else
         {
             Debug.LogErrorFormat("Transformation {0} is relative to non-entity object {1} (hierarchy will be lost)",
                                  unityTransform.name, unityTransform.parent.name);
         }
     }
     else
     {
         relToId = string.Empty;
     }
 }
Пример #3
0
        private bool ParseStream(StreamReader stream, bool zUp)
        {
            int lineCount = 0;
            DateTimeFormatInfo enUsDTFI = CultureInfo.InvariantCulture.DateTimeFormat;

            while (!stream.EndOfStream)// && lineCount < 10)
            {
                string line = stream.ReadLine();
                lineCount++;
                char[]   delimiter = { ' ', '\t' };
                string[] tokens    = line.Split(delimiter, StringSplitOptions.RemoveEmptyEntries);
                if (tokens.Length == 0)
                {
                    break;
                }
                if (tokens.Length != 17)
                {
                    Debug.LogWarningFormat("{0} line values in line {1}", tokens.Length, lineCount);
                    for (int c = 0; c < tokens.Length; c++)
                    {
                        var t = tokens[c];
                        Debug.LogFormat("{0} {1}", c, t);
                    }
                    return(false);
                }
                int          i     = 0;
                SimLogRecord state = new SimLogRecord();
                //Debug.Log(tokens[i]);
                state.startTime = Convert.ToDateTime(tokens[i++], enUsDTFI);
                if (history.Count == 0)
                {
                    historyStartTime = state.startTime;
                }
                //Debug.Log(tokens[i]);
                state.endTime = Convert.ToDateTime(tokens[i++], enUsDTFI);
                if (historyEndTime < state.endTime)
                {
                    historyEndTime = state.endTime;
                }
                state.origin = tokens[i++];
                Vector3 pos = Vector3.zero;
                pos.x = float.Parse(tokens[i++], CultureInfo.InvariantCulture);
                pos.y = float.Parse(tokens[i++], CultureInfo.InvariantCulture);
                pos.z = float.Parse(tokens[i++], CultureInfo.InvariantCulture);
                float scaleToMeter = float.Parse(tokens[i++], CultureInfo.InvariantCulture);
                state.position = CsConversion.VecToVecRL(pos * scaleToMeter, zUp);
                Matrix4x4 rotMat = Matrix4x4.identity;
                for (int n = 0; n < 9; n++)
                {
                    rotMat[n % 3, n / 3] = float.Parse(tokens[i++], CultureInfo.InvariantCulture);
                }
                state.rotMatrix = rotMat;
                state.parentId  = tokens[i++];
                history.Add(state);
            }
            return(true);
        }
        bool ParseFile(StreamReader stream)
        {
            int lineCount             = 0;
            DateTimeFormatInfo myDTFI = new CultureInfo("en-US", false).DateTimeFormat;

            while (!stream.EndOfStream && lineCount < 10)
            {
                string line = stream.ReadLine();
                lineCount++;
                char[]   delimiter = { ' ', '\t' };
                string[] tokens    = line.Split(delimiter, StringSplitOptions.RemoveEmptyEntries);
                if (tokens.Length != 17)
                {
                    Debug.LogWarningFormat("{0} line values in line {1}", tokens.Length, lineCount);
                    int c = 0;
                    foreach (var t in tokens)
                    {
                        c++;
                        Debug.LogFormat("{0} {1}", c, t);
                    }
                    return(false);
                }
                int             i     = 0;
                AnimationRecord state = new AnimationRecord();
                state.startTime = Convert.ToDateTime(tokens[i++], myDTFI);
                if (history.Count == 0)
                {
                    historyStartTime = state.startTime;
                }
                state.endTime = Convert.ToDateTime(tokens[i++], myDTFI);
                state.origin  = tokens[i++];
                Vector3 pos = Vector3.zero;
                pos.x = float.Parse(tokens[i++]);
                pos.y = float.Parse(tokens[i++]);
                pos.z = float.Parse(tokens[i++]);
                float scaleToMeter = float.Parse(tokens[i++]);
                state.position = CsConversion.VecToVecRL(pos * scaleToMeter, origUpAxisIsZ);
                Matrix4x4 rotMat = Matrix4x4.identity;
                for (int n = 0; n < 9; n++)
                {
                    rotMat[n % 3, n / 3] = float.Parse(tokens[i++]);
                }
                state.rotMatrix = rotMat;
                state.parentId  = tokens[i++];
                history.Add(state);
            }
            return(true);
        }
Пример #5
0
        /// <summary>
        /// Update the given game object with the given XML entity data
        /// </summary>
        /// <param name="destGameObject">The given game object to update</param>
        /// <param name="data">The given source XML entity data</param>
        protected void UpdateObject(GameObject destGameObject, VrXmlEntityData data)
        {
            destGameObject.name = data.name;
            EntityData entityData = destGameObject.GetComponent <EntityData>();

            if (entityData == null)
            {
                entityData = destGameObject.AddComponent <EntityData>();
            }
            entityData.id          = data.id;
            entityData.name        = data.name;
            entityData.type        = data.type;
            entityData.description = data.description;

            if (!string.IsNullOrEmpty(data.localTransform.relToId))
            {
                destGameObject.transform.SetParent(entityObjects[data.localTransform.relToId].transform, false);
            }
            else
            {
                destGameObject.transform.SetParent(null, false);
            }

            destGameObject.transform.localPosition = CsConversion.VecToVecRL(data.localTransform.position.Get(), scenarioData.upAxisIsZ);
            if (data.localTransform.useRotationMatrix)
            {
                Matrix4x4 rotMatrix = (Matrix4x4)(data.localTransform.rotationMatrix);
                destGameObject.transform.localRotation.SetLookRotation(
                    CsConversion.RotMatForward(rotMatrix, scenarioData.upAxisIsZ),
                    CsConversion.RotMatUp(rotMatrix, scenarioData.upAxisIsZ));
            }
            else
            {
                destGameObject.transform.localEulerAngles = (Vector3)data.localTransform.eulerAngles;
            }
            destGameObject.transform.localScale = data.localTransform.scale.Get();
        }