Exemplo n.º 1
0
        IEnumerator DoConvertTake(AMTakeData oldTake, Take newTake, bool isMeta, string assetPath)
        {
            newTake.name            = oldTake.name;
            newTake.frameRate       = oldTake.frameRate;
            newTake.endFramePadding = oldTake.endFramePadding;
            newTake.numLoop         = oldTake.numLoop;
            newTake.loopMode        = oldTake.loopMode;
            newTake.loopBackToFrame = oldTake.loopBackToFrame;
            newTake.trackCounter    = oldTake.track_count;
            newTake.groupCounter    = oldTake.group_count;

            //go through groups
            newTake.rootGroup            = new Group();
            newTake.rootGroup.group_name = oldTake.rootGroup.group_name;
            newTake.rootGroup.group_id   = oldTake.rootGroup.group_id;
            newTake.rootGroup.elements   = new List <int>(oldTake.rootGroup.elements);
            newTake.rootGroup.foldout    = oldTake.rootGroup.foldout;

            newTake.groupValues = new List <Group>();
            foreach (var oldGroup in oldTake.groupValues)
            {
                var newGroup = new Group();
                newGroup.group_name = oldGroup.group_name;
                newGroup.group_id   = oldGroup.group_id;
                newGroup.elements   = new List <int>(oldGroup.elements);
                newGroup.foldout    = oldGroup.foldout;

                newTake.groupValues.Add(newGroup);
            }

            //go through tracks
            newTake.trackValues = new List <Track>();
            foreach (var oldTrack in oldTake.trackValues)
            {
                AddMessage("  - convert track: " + oldTrack.name);

                Track newTrack = null;

                if (oldTrack is AMAnimationTrack)
                {
                    newTrack = new UnityAnimationTrack();

                    ConvertTrackCommonFields(oldTrack, newTrack, true, isMeta);

                    newTrack.keys = new List <Key>();
                    foreach (AMAnimationKey oldKey in oldTrack.keys)
                    {
                        var newKey = new UnityAnimationKey();

                        ConvertKeyCommonFields(oldKey, newKey);

                        newKey.wrapMode      = oldKey.wrapMode;
                        newKey.amClip        = oldKey.amClip;
                        newKey.crossfade     = oldKey.crossfade;
                        newKey.crossfadeTime = oldKey.crossfadeTime;

                        newTrack.keys.Add(newKey);
                    }
                }
                else if (oldTrack is AMAudioTrack)
                {
                    newTrack = new AudioTrack();

                    ConvertTrackCommonFields(oldTrack, newTrack, true, isMeta);

                    newTrack.keys = new List <Key>();
                    foreach (AMAudioKey oldKey in oldTrack.keys)
                    {
                        var newKey = new AudioKey();

                        ConvertKeyCommonFields(oldKey, newKey);

                        newKey.audioClip = oldKey.audioClip;
                        newKey.loop      = oldKey.loop;
                        newKey.oneShot   = oldKey.oneShot;

                        newTrack.keys.Add(newKey);
                    }
                }
                else if (oldTrack is AMCameraSwitcherTrack)
                {
                    newTrack = new CameraSwitcherTrack();

                    ConvertTrackCommonFields(oldTrack, newTrack, true, isMeta);

                    newTrack.keys = new List <Key>();
                    for (int i = 0; i < oldTrack.keys.Count; i++)
                    {
                        var oldKey = (AMCameraSwitcherKey)oldTrack.keys[i];
                        var newKey = new CameraSwitcherKey();

                        ConvertKeyCommonFields(oldKey, newKey);

                        newKey.type                 = oldKey.type;
                        newKey.typeEnd              = oldKey.typeEnd;
                        newKey.color                = oldKey.color;
                        newKey.colorEnd             = oldKey.colorEnd;
                        newKey.cameraFadeType       = oldKey.cameraFadeType;
                        newKey.cameraFadeParameters = new List <float>(oldKey.cameraFadeParameters);
                        newKey.irisShape            = oldKey.irisShape;
                        newKey.still                = oldKey.still;
                        newKey.endFrame             = oldKey.endFrame;

                        if (isMeta)
                        {
                            newKey.SetCameraDirect(null, oldKey.cameraTargetPath);
                            newKey.SetCameraEndDirect(null, oldKey.cameraEndTargetPath);
                        }
                        else
                        {
                            newKey.SetCameraDirect(oldKey.getCamera(null), "");
                            newKey.SetCameraDirect(oldKey.getCameraEnd(null), "");
                        }

                        newTrack.keys.Add(newKey);
                    }
                }
                else if (oldTrack is AMEventTrack)
                {
                    var newEventTrack = new EventTrack();
                    newTrack = newEventTrack;

                    ConvertTrackCommonFields(oldTrack, newTrack, false, isMeta);

                    newTrack.keys = new List <Key>();

                    string eventCompName = null;

                    //TODO: create new tracks per different components from keys
                    //for now we only allow conversion of one component, so the first key will be used.
                    foreach (AMEventKey oldKey in oldTrack.keys)
                    {
                        string keyCompName = oldKey.getComponentName();

                        if (string.IsNullOrEmpty(eventCompName))
                        {
                            if (!string.IsNullOrEmpty(keyCompName))
                            {
                                eventCompName = keyCompName;

                                AddMessage("   - EventTrack using component: " + eventCompName);

                                if (isMeta)
                                {
                                    newEventTrack.SetTargetAsComponentDirect(oldTrack.targetPath, null, eventCompName);
                                }
                                else
                                {
                                    newEventTrack.SetTargetAsComponentDirect("", oldKey.getComponentRef(), eventCompName);
                                }
                            }
                        }

                        //only add if component matched
                        if (string.IsNullOrEmpty(eventCompName) || keyCompName != eventCompName)
                        {
                            AddMessage("   - Cannot add EventKey with Component: " + eventCompName, Color.yellow);
                            continue;
                        }

                        var newKey = new EventKey();

                        ConvertKeyCommonFields(oldKey, newKey);

                        newKey.useSendMessage = oldKey.useSendMessage;
                        newKey.methodName     = oldKey.methodName;

                        newKey.parameters = new List <EventParameter>(oldKey.parameters.Count);
                        for (int i = 0; i < oldKey.parameters.Count; i++)
                        {
                            var oldParm = oldKey.parameters[i];
                            var newParm = new EventParameter();

                            ConvertEventParameter(oldParm, newParm);

                            newKey.parameters.Add(newParm);
                        }

                        newTrack.keys.Add(newKey);
                    }
                }
                else if (oldTrack is AMGOSetActiveTrack)
                {
                    var oldGOTrack = (AMGOSetActiveTrack)oldTrack;
                    var newGOTrack = new GOSetActiveTrack();

                    newTrack = newGOTrack;

                    ConvertTrackCommonFields(oldTrack, newTrack, true, isMeta);

                    newGOTrack.startActive = oldGOTrack.startActive;

                    newTrack.keys = new List <Key>();
                    foreach (AMGOSetActiveKey oldKey in oldTrack.keys)
                    {
                        var newKey = new GOSetActiveKey();

                        ConvertKeyCommonFields(oldKey, newKey);

                        newKey.setActive = oldKey.setActive;
                        newKey.endFrame  = oldKey.endFrame;

                        newTrack.keys.Add(newKey);
                    }
                }
                else if (oldTrack is AMMaterialTrack)
                {
                    var oldMatTrack = (AMMaterialTrack)oldTrack;
                    var newMatTrack = new MaterialTrack();

                    newTrack = newMatTrack;

                    ConvertTrackCommonFields(oldTrack, newTrack, true, isMeta);

                    newMatTrack.materialIndex = oldMatTrack.materialIndex;
                    newMatTrack.property      = oldMatTrack.property;
                    newMatTrack.propertyType  = (MaterialTrack.ValueType)oldMatTrack.propertyType;

                    newTrack.keys = new List <Key>();
                    foreach (AMMaterialKey oldKey in oldTrack.keys)
                    {
                        var newKey = new MaterialKey();

                        ConvertKeyCommonFields(oldKey, newKey);

                        newKey.endFrame = oldKey.endFrame;
                        newKey.texture  = oldKey.texture;
                        newKey.vector   = oldKey.vector;

                        newTrack.keys.Add(newKey);
                    }
                }
                else if (oldTrack is AMOrientationTrack)
                {
                    newTrack = new OrientationTrack();

                    ConvertTrackCommonFields(oldTrack, newTrack, true, isMeta);

                    newTrack.keys = new List <Key>();
                    foreach (AMOrientationKey oldKey in oldTrack.keys)
                    {
                        var newKey = new OrientationKey();

                        ConvertKeyCommonFields(oldKey, newKey);

                        if (isMeta)
                        {
                            newKey.SetTargetDirect(null, oldKey.GetTargetPath());
                        }
                        else
                        {
                            newKey.SetTargetDirect(oldKey.GetTarget(null), "");
                        }

                        newKey.endFrame = oldKey.endFrame;

                        newTrack.keys.Add(newKey);
                    }
                }
                else if (oldTrack is AMPropertyTrack)
                {
                    var oldPropTrack = (AMPropertyTrack)oldTrack;
                    var newPropTrack = new PropertyTrack();

                    newTrack = newPropTrack;

                    ConvertTrackCommonFields(oldTrack, newTrack, true, isMeta);

                    newPropTrack.valueType = (PropertyTrack.ValueType)oldPropTrack.valueType;

                    if (oldPropTrack.isPropertySet())
                    {
                        Component comp      = oldPropTrack.GetTargetComp(null);
                        string    compName  = oldPropTrack.getComponentName();
                        bool      isField   = oldPropTrack.isField;
                        string    fieldName = oldPropTrack.getMemberName();

                        if (isMeta)
                        {
                            newPropTrack.SetTargetCompDirect(null, compName, isField, fieldName);
                        }
                        else
                        {
                            newPropTrack.SetTargetCompDirect(comp, compName, isField, fieldName);
                        }
                    }

                    newTrack.keys = new List <Key>();
                    foreach (AMPropertyKey oldKey in oldTrack.keys)
                    {
                        var newKey = new PropertyKey();

                        ConvertKeyCommonFields(oldKey, newKey);

                        newKey.endFrame  = oldKey.endFrame;
                        newKey.val       = oldKey.val;
                        newKey.valString = oldKey.valString;
                        newKey.valObj    = oldKey.valObj;
                        newKey.vect4     = oldKey.vect4;

                        newTrack.keys.Add(newKey);
                    }
                }
                else if (oldTrack is AMRotationEulerTrack)
                {
                    var oldRotEulerTrack = (AMRotationEulerTrack)oldTrack;
                    var newRotEulerTrack = new RotationEulerTrack();

                    newTrack = newRotEulerTrack;

                    ConvertTrackCommonFields(oldTrack, newTrack, true, isMeta);

                    newRotEulerTrack.axis = (AxisFlags)oldRotEulerTrack.axis;

                    newTrack.keys = new List <Key>();
                    foreach (AMRotationEulerKey oldKey in oldTrack.keys)
                    {
                        var newKey = new RotationEulerKey();

                        ConvertKeyCommonFields(oldKey, newKey);

                        newKey.rotation = oldKey.rotation;
                        newKey.endFrame = oldKey.endFrame;

                        newTrack.keys.Add(newKey);
                    }
                }
                else if (oldTrack is AMRotationTrack)
                {
                    newTrack = new RotationTrack();

                    ConvertTrackCommonFields(oldTrack, newTrack, true, isMeta);

                    newTrack.keys = new List <Key>();
                    foreach (AMRotationKey oldKey in oldTrack.keys)
                    {
                        var newKey = new RotationKey();

                        ConvertKeyCommonFields(oldKey, newKey);

                        newKey.rotation = oldKey.rotation;
                        newKey.endFrame = oldKey.endFrame;

                        newTrack.keys.Add(newKey);
                    }
                }
                else if (oldTrack is AMTranslationTrack)
                {
                    var oldTransTrack = (AMTranslationTrack)oldTrack;
                    var newTransTrack = new TranslationTrack();

                    newTrack = newTransTrack;

                    ConvertTrackCommonFields(oldTrack, newTrack, true, isMeta);

                    newTransTrack.pixelPerUnit = oldTransTrack.pixelPerUnit;
                    newTransTrack.pixelSnap    = oldTransTrack.pixelSnap;

                    newTrack.keys = new List <Key>();
                    foreach (AMTranslationKey oldKey in oldTrack.keys)
                    {
                        var newKey = new TranslationKey();

                        ConvertKeyCommonFields(oldKey, newKey);

                        newKey.position     = oldKey.position;
                        newKey.endFrame     = oldKey.endFrame;
                        newKey.isConstSpeed = oldKey.isConstSpeed;

                        newKey.path = new Vector3[oldKey.path.Length];
                        System.Array.Copy(oldKey.path, newKey.path, newKey.path.Length);

                        newTrack.keys.Add(newKey);
                    }
                }
                else if (oldTrack is AMTriggerTrack)  //convert TriggerTrack to EventTrack with TriggerSignal
                {
                    var newTriggerTrack = new EventTrack();

                    newTrack = newTriggerTrack;

                    ConvertTrackCommonFields(oldTrack, newTrack, false, isMeta);

                    //grab/create signal for this trigger
                    string signalPath = GetTriggerSignalPath(assetPath);

                    TriggerSignal triggerSignal;
                    if (!mTriggerSignalLookup.TryGetValue(signalPath, out triggerSignal))
                    {
                        //try to load it if it exists
                        triggerSignal = AssetDatabase.LoadAssetAtPath <TriggerSignal>(signalPath);
                        if (!triggerSignal)
                        {
                            AddMessage("  - Creating Trigger Signal: " + signalPath);

                            triggerSignal = ScriptableObject.CreateInstance <TriggerSignal>();
                            AssetDatabase.CreateAsset(triggerSignal, signalPath);
                            AssetDatabase.SaveAssets();

                            yield return(new WaitForFixedUpdate());
                        }

                        mTriggerSignalLookup.Add(signalPath, triggerSignal);
                    }

                    newTriggerTrack.SetTargetAsObject(triggerSignal);

                    newTrack.keys = new List <Key>();
                    foreach (AMTriggerKey oldKey in oldTrack.keys)
                    {
                        var newKey = new EventKey();

                        ConvertKeyCommonFields(oldKey, newKey);

                        newKey.useSendMessage = false;
                        newKey.methodName     = "Invoke";

                        newKey.parameters = new List <EventParameter>(3);
                        newKey.parameters.Add(new EventParameter()
                        {
                            valueType = EventData.ValueType.String, val_string = oldKey.valueString
                        });
                        newKey.parameters.Add(new EventParameter()
                        {
                            valueType = EventData.ValueType.Integer, val_int = oldKey.valueInt
                        });
                        newKey.parameters.Add(new EventParameter()
                        {
                            valueType = EventData.ValueType.Float, val_float = oldKey.valueFloat
                        });

                        newTrack.keys.Add(newKey);
                    }
                }

                newTake.trackValues.Add(newTrack);

                yield return(new WaitForFixedUpdate());
            }
        }
Exemplo n.º 2
0
        public ITrackedVideo GetData()
        {
            ITrackedVideo trackedVideo = ModelResolver.Resolve <ITrackedVideo>();

            trackedVideo.FileName     = FileName;
            trackedVideo.Result       = Result;
            trackedVideo.SmoothMotion = SmoothMotion;
            //trackedVideo.SmoothFactor = SmoothFactor;
            trackedVideo.FrameRate         = FrameRate;
            trackedVideo.CentroidSize      = CentroidSize;
            trackedVideo.PelvicArea1       = PelvicArea1;
            trackedVideo.PelvicArea2       = PelvicArea2;
            trackedVideo.PelvicArea3       = PelvicArea3;
            trackedVideo.PelvicArea4       = PelvicArea4;
            trackedVideo.UnitsToMilimeters = UnitsToMilimeters;
            trackedVideo.Message           = Message;

            if (Results != null)
            {
                Dictionary <int, SingleFrameResultXml> headPoints   = Results.GetData();
                Dictionary <int, ISingleFrameResult>   finalResults = new Dictionary <int, ISingleFrameResult>();

                foreach (var entry in headPoints)
                {
                    int key = entry.Key;
                    SingleFrameResultXml currentEntry = entry.Value;

                    if (currentEntry == null)
                    {
                        finalResults.Add(key, null);
                    }
                    else
                    {
                        finalResults.Add(key, currentEntry.GetData());
                    }
                }

                trackedVideo.Results = finalResults;
            }

            //if (WaistSizes != null)
            //{
            //    trackedVideo.WaistSizes = WaistSizes.GetData();
            //}

            if (MotionTrack != null)
            {
                trackedVideo.MotionTrack = MotionTrack.Select(x => x.GetPoint()).ToArray();
            }

            if (SmoothedMotionTrack != null)
            {
                trackedVideo.SmoothedMotionTrack = SmoothedMotionTrack.Select(x => x.GetPoint()).ToArray();
            }

            if (OrientationTrack != null)
            {
                trackedVideo.OrientationTrack = OrientationTrack.Select(x => x.GetVector()).ToArray();
            }

            if (Boundries != null)
            {
                trackedVideo.Boundries = Boundries.Select(x => x.GetBoundary()).ToArray();
            }

            if (Events != null)
            {
                trackedVideo.Events = Events.Select(x => x.GetData()).ToArray();
            }

            if (InteractingBoundries != null)
            {
                trackedVideo.InteractingBoundries = InteractingBoundries.GetData().ToDictionary(kvp => kvp.Key.GetBoundary(), kvp => kvp.Value.Select(x => x.GetData()).ToArray());
            }

            trackedVideo.MinInteractionDistance = MinInteractionDistance;
            trackedVideo.GapDistance            = GapDistance;
            trackedVideo.ThresholdValue         = ThresholdValue;
            trackedVideo.ThresholdValue2        = ThresholdValue2;
            trackedVideo.StartFrame             = StartFrame;
            trackedVideo.EndFrame          = EndFrame;
            trackedVideo.UnitsToMilimeters = UnitsToMilimeters;

            trackedVideo.UpdateTrack();
            return(trackedVideo);
        }