private void ImportFileSelected(string path) { if (string.IsNullOrEmpty(path)) { return; } try { var json = SuperController.singleton.LoadJSON(path); if (json["AtomType"]?.Value != plugin.containingAtom.type) { SuperController.LogError($"VamTimeline: Loaded animation for {json["AtomType"]} but current atom type is {plugin.containingAtom.type}"); return; } var jc = json.AsObject; if (jc.HasKey("ControllersState")) { var controllersState = jc["ControllersState"].AsObject; foreach (var k in controllersState.Keys) { var fc = plugin.containingAtom.freeControllers.FirstOrDefault(x => x.name == k); if (fc == null) { SuperController.LogError($"VamTimeline: Loaded animation had state for controller {k} but no such controller were found on this atom."); continue; } var state = controllersState[k]; fc.currentPositionState = (FreeControllerV3.PositionState)state["currentPositionState"].AsInt; fc.transform.localPosition = AtomAnimationSerializer.DeserializeVector3(state["localPosition"].AsObject); fc.currentRotationState = (FreeControllerV3.RotationState)state["currentRotationState"].AsInt; fc.transform.localRotation = AtomAnimationSerializer.DeserializeQuaternion(state["localRotation"].AsObject); } } plugin.serializer.DeserializeAnimation(animation, json.AsObject); var lastAnimation = animation.clips.Select(c => c.animationName).LastOrDefault(); // NOTE: Because the animation instance changes, we'll end up with the _old_ "current" not being updated. if (lastAnimation != animation.current.animationName) { plugin.ChangeAnimation(lastAnimation); } else { animation.SelectAnimation(lastAnimation); } animation.Sample(); } catch (Exception exc) { SuperController.LogError($"VamTimeline.{nameof(AdvancedKeyframeToolsScreen)}.{nameof(ImportFileSelected)}: Failed to import animation: {exc}"); } }
private void ExportFileSelected(string path) { if (string.IsNullOrEmpty(path)) { return; } if (!path.ToLower().EndsWith($".{_saveExt}")) { path += $".{_saveExt}"; } try { var jc = plugin.GetAnimationJSON(_exportAnimationsJSON.val == "(All)" ? null : _exportAnimationsJSON.val); jc["AtomType"] = plugin.containingAtom.type; var atomState = new JSONClass(); var allTargets = new HashSet <FreeControllerV3>( animation.clips .Where(c => _exportAnimationsJSON.val == "(All)" || c.animationName == _exportAnimationsJSON.val) .SelectMany(c => c.targetControllers) .Select(t => t.controller) .Distinct()); foreach (var fc in plugin.containingAtom.freeControllers) { if (fc.name == "control") { continue; } if (!fc.name.EndsWith("Control")) { continue; } atomState[fc.name] = new JSONClass { { "currentPositionState", ((int)fc.currentPositionState).ToString() }, { "localPosition", AtomAnimationSerializer.SerializeVector3(fc.transform.localPosition) }, { "currentRotationState", ((int)fc.currentRotationState).ToString() }, { "localRotation", AtomAnimationSerializer.SerializeQuaternion(fc.transform.localRotation) } }; } jc["ControllersState"] = atomState; SuperController.singleton.SaveJSON(jc, path); SuperController.singleton.DoSaveScreenshot(path); } catch (Exception exc) { SuperController.LogError($"VamTimeline: Failed to export animation: {exc}"); } }
public override void Init() { try { serializer = new AtomAnimationSerializer(base.containingAtom); _ui = new ScreensManager(this); InitStorables(); _ui.Init(); StartCoroutine(DeferredInit()); } catch (Exception exc) { SuperController.LogError($"VamTimeline.{nameof(AtomPlugin)}.{nameof(Init)}: " + exc); } }
public override JSONClass GetJSON(bool includePhysical = true, bool includeAppearance = true, bool forceStore = false) { var json = base.GetJSON(includePhysical, includeAppearance, forceStore); try { json["Animation"] = serializer.SerializeAnimation(animation); json["Options"] = AtomAnimationSerializer.SerializeEditContext(animationEditContext); needsStore = true; } catch (Exception exc) { SuperController.LogError($"Timeline.{nameof(AtomPlugin)}.{nameof(GetJSON)} (Serialize): {exc}"); } return(json); }
private JSONClass GetAtomStateJson() { var atomState = new JSONClass(); IEnumerable <FreeControllerV3> controllers; switch (_exportAnimationsJSON.val) { case _poseAndAllAnimations: controllers = plugin.containingAtom.freeControllers; break; case _allAnimations: controllers = animation.clips .SelectMany(c => c.targetControllers) .Select(t => t.controller) .Distinct(); break; default: controllers = animation.clips .First(c => c.animationName == _exportAnimationsJSON.val) .targetControllers .Select(t => t.controller); break; } foreach (var fc in controllers) { if (fc.name == "control") { continue; } if (!fc.name.EndsWith("Control")) { continue; } atomState[fc.name] = new JSONClass { { "currentPositionState", ((int)fc.currentPositionState).ToString() }, { "localPosition", AtomAnimationSerializer.SerializeVector3(fc.transform.localPosition) }, { "currentRotationState", ((int)fc.currentRotationState).ToString() }, { "localRotation", AtomAnimationSerializer.SerializeQuaternion(fc.transform.localRotation) } }; } return(atomState); }
private void ImportFileSelected(string path) { if (string.IsNullOrEmpty(path)) { return; } try { var json = SuperController.singleton.LoadJSON(path); if (json["AtomType"]?.Value != plugin.containingAtom.type) { SuperController.LogError($"VamTimeline: Loaded animation for {json["AtomType"]} but current atom type is {plugin.containingAtom.type}"); return; } var jc = json.AsObject; if (jc.HasKey("ControllersState")) { var controllersState = jc["ControllersState"].AsObject; foreach (var k in controllersState.Keys) { var fc = plugin.containingAtom.freeControllers.FirstOrDefault(x => x.name == k); if (fc == null) { SuperController.LogError($"VamTimeline: Loaded animation had state for controller {k} but no such controller were found on this atom."); continue; } var state = controllersState[k]; fc.currentPositionState = (FreeControllerV3.PositionState)state["currentPositionState"].AsInt; fc.transform.localPosition = AtomAnimationSerializer.DeserializeVector3(state["localPosition"].AsObject); fc.currentRotationState = (FreeControllerV3.RotationState)state["currentRotationState"].AsInt; fc.transform.localRotation = AtomAnimationSerializer.DeserializeQuaternion(state["localRotation"].AsObject); } } plugin.Load(jc); plugin.ChangeAnimation(jc["Clips"][0]["AnimationName"].Value); plugin.animation.Stop(); } catch (Exception exc) { SuperController.LogError($"VamTimeline.{nameof(AdvancedScreen)}.{nameof(ImportFileSelected)}: Failed to import animation: {exc}"); } }
public override void Init() { base.Init(); try { serializer = new AtomAnimationSerializer(base.containingAtom); peers = new PeerManager(base.containingAtom, this); _freeControllerHook = gameObject.AddComponent <FreeControllerV3Hook>(); _freeControllerHook.enabled = false; _freeControllerHook.containingAtom = base.containingAtom; InitStorables(); SuperController.singleton.StartCoroutine(DeferredInit()); } catch (Exception exc) { SuperController.LogError($"Timeline.{nameof(AtomPlugin)}.{nameof(Init)}: {exc}"); } }
private void ImportControllerStates(JSONClass jc) { if (jc.HasKey("ControllersState")) { var controllersState = jc["ControllersState"].AsObject; foreach (var k in controllersState.Keys) { var fc = plugin.containingAtom.freeControllers.FirstOrDefault(x => x.name == k); if (fc == null) { SuperController.LogError($"Timeline: Loaded animation had state for controller {k} but no such controller were found on this atom."); continue; } var state = controllersState[k]; fc.currentPositionState = (FreeControllerV3.PositionState)state["currentPositionState"].AsInt; fc.transform.localPosition = AtomAnimationSerializer.DeserializeVector3(state["localPosition"].AsObject); fc.currentRotationState = (FreeControllerV3.RotationState)state["currentRotationState"].AsInt; fc.transform.localRotation = AtomAnimationSerializer.DeserializeQuaternion(state["localRotation"].AsObject); } } }