public SphereMap GetSphereMap(Frame frame, bool mirrored) { SphereMap sensor = new SphereMap(Radius, Mask); RootModule module = (RootModule)Data.GetModule(ID.Root); sensor.Sense(module == null ? Matrix4x4.identity : module.GetRootTransformation(frame, mirrored)); return(sensor); }
private Matrix4x4 GetRoot(float timestamp, bool mirrored) { RootModule root = GetRootModule(); if (root == null) { return(Matrix4x4.identity); } return(root.GetRootTransformation(timestamp, mirrored)); }
public CuboidMap GetInteractionGeometry(Frame frame, bool mirrored, float delta) { Interaction interaction = FindInteraction(frame); if (interaction == null) { RootModule module = Module.Data.GetModule(ID.Root) == null ? null : (RootModule)Module.Data.GetModule(ID.Root); CuboidMap sensor = new CuboidMap(new Vector3Int(PropResolution, PropResolution, PropResolution)); sensor.Sense(module == null ? Matrix4x4.identity : module.GetRootTransformation(frame, mirrored), LayerMask.GetMask("Interaction"), Vector3.zero); return(sensor); } else { CuboidMap sensor = new CuboidMap(new Vector3Int(PropResolution, PropResolution, PropResolution)); sensor.Sense(interaction.GetCenter(), LayerMask.GetMask("Interaction"), interaction.GetExtents()); Transformation transformation = interaction.GetComponent <Transformation>(); if (transformation != null) { sensor.Retransform(interaction.GetCenter(transformation.GetTransformation(GetTargetFrame(frame, delta), mirrored))); } return(sensor); } }
public void LoadFrame(float timestamp) { Timestamp = timestamp; Actor actor = GetActor(); Scene scene = Data.GetScene(); Frame frame = GetCurrentFrame(); RootModule module = (RootModule)Data.GetModule(Module.ID.Root); Matrix4x4 root = module == null?frame.GetBoneTransformation(0, Mirror) : module.GetRootTransformation(frame, Mirror); actor.transform.position = root.GetPosition(); actor.transform.rotation = root.GetRotation(); UpdateBoneMapping(); for (int i = 0; i < actor.Bones.Length; i++) { if (BoneMapping[i] == -1) { Debug.Log("Bone " + actor.Bones[i].GetName() + " could not be mapped."); } else { Matrix4x4 transformation = frame.GetBoneTransformation(BoneMapping[i], Mirror); Vector3 velocity = frame.GetBoneVelocity(BoneMapping[i], Mirror, 1f / TargetFramerate); Vector3 acceleration = frame.GetBoneAcceleration(BoneMapping[i], Mirror, 1f / TargetFramerate); Vector3 force = frame.GetBoneMass(BoneMapping[i], Mirror) * acceleration; actor.Bones[i].Transform.position = transformation.GetPosition(); actor.Bones[i].Transform.rotation = transformation.GetRotation(); actor.Bones[i].Velocity = velocity; actor.Bones[i].Acceleration = acceleration; actor.Bones[i].Force = force; } } foreach (GameObject instance in scene.GetRootGameObjects()) { instance.transform.localScale = Vector3.one.GetMirror(Mirror ? Data.MirrorAxis : Axis.None); foreach (SceneEvent e in instance.GetComponentsInChildren <SceneEvent>(true)) { if (Callbacks) { e.Callback(this); } else { e.Identity(this); } } } foreach (Module m in Data.Modules) { if (Callbacks) { m.Callback(this); } } if (CameraFocus) { if (SceneView.lastActiveSceneView != null) { /* * Vector3 lastPosition = SceneView.lastActiveSceneView.camera.transform.position; * Quaternion lastRotation = SceneView.lastActiveSceneView.camera.transform.rotation; * Vector3 position = GetActor().GetRoot().position; * position.y += FocusHeight; * Quaternion rotation = GetActor().GetRoot().rotation; * rotation.x = 0f; * rotation.z = 0f; * rotation = Quaternion.Euler(0f, Mirror ? Mathf.Repeat(FocusAngle + 0f, 360f) : FocusAngle, 0f) * rotation; * position += FocusOffset * (rotation * Vector3.right); * SceneView.lastActiveSceneView.LookAtDirect(Vector3.Lerp(lastPosition, position, 1f-FocusSmoothing), Quaternion.Slerp(lastRotation, rotation, (1f-FocusSmoothing)), FocusDistance*(1f-FocusSmoothing)); */ Vector3 lastPosition = SceneView.lastActiveSceneView.camera.transform.position; Quaternion lastRotation = SceneView.lastActiveSceneView.camera.transform.rotation; Vector3 position = GetActor().GetRoot().position; position += Quaternion.Euler(0f, FocusAngle, 0f) * (FocusDistance * Vector3.forward); position.y += FocusHeight; Quaternion rotation = Quaternion.LookRotation(Vector3.ProjectOnPlane(GetActor().GetRoot().position - position, Vector3.up).normalized, Vector3.up); SceneView.lastActiveSceneView.LookAtDirect(Vector3.Lerp(lastPosition, position, 1f - FocusSmoothing), Quaternion.Slerp(lastRotation, rotation, (1f - FocusSmoothing)), FocusDistance * (1f - FocusSmoothing)); } } }
public void ComputeInteraction() { Interactors = new string[Data.Frames.Length]; for (int i = 0; i < Interactors.Length; i++) { Interactors[i] = null; } bool IsValid(MotionData asset) { return(asset.GetName().Contains("_P0")); } string GetID(MotionData asset) { return(asset.GetName().Substring(0, asset.GetName().LastIndexOf("_P0"))); } MotionEditor editor = MotionEditor.GetInstance(); if (editor.GetAsset() != Data) { Debug.Log("Asset " + Data.GetName() + " is not loaded."); return; } if (IsValid(Data)) { int pivot = editor.GetAssetIndex(); //Collect all assets of same capture List <MotionData> assets = new List <MotionData>(); assets.Add(Data); for (int i = pivot - 1; i >= 0; i--) { MotionData asset = editor.GetAsset(i); if (IsValid(asset) && GetID(Data) == GetID(asset)) { assets.Add(asset); } else { break; } } for (int i = pivot + 1; i < editor.Assets.Length; i++) { MotionData asset = editor.GetAsset(i); if (IsValid(asset) && GetID(Data) == GetID(asset)) { assets.Add(asset); } else { break; } } //Find closest interaction inside area for (int i = 0; i < Data.Frames.Length; i++) { Frame frame = Data.Frames[i]; Matrix4x4 root = GetRoot(frame.Timestamp, false); float distance = GetInteractionRadius(); foreach (MotionData data in assets) { if (Data != data) { RootModule m = Data.GetModule <RootModule>(); if (m != null) { Matrix4x4 candidate = m.GetRootTransformation(frame.Timestamp, false); float d = Vector3.Distance(root.GetPosition(), candidate.GetPosition()); if (d < distance) { distance = d; Interactors[i] = Utility.GetAssetGUID(data); } } } } } } }
public TimeSeries GetTimeSeries(Frame frame, bool mirrored, int pastKeys, int futureKeys, float pastWindow, float futureWindow, int resolution, float delta) { TimeSeries timeSeries = new TimeSeries(pastKeys, futureKeys, pastWindow, futureWindow, resolution); foreach (Module module in Data.Modules) { if (module is RootModule) { RootModule m = (RootModule)module; TimeSeries.Root series = new TimeSeries.Root(timeSeries); for (int i = 0; i < timeSeries.Samples.Length; i++) { float t = frame.Timestamp + timeSeries.Samples[i].Timestamp; if (t < 0f || t > Data.GetTotalTime()) { series.Transformations[i] = m.GetEstimatedRootTransformation(frame, timeSeries.Samples[i].Timestamp, mirrored); series.Velocities[i] = m.GetEstimatedRootVelocity(frame, timeSeries.Samples[i].Timestamp, mirrored, delta); } else { series.Transformations[i] = m.GetRootTransformation(Data.GetFrame(t), mirrored); series.Velocities[i] = m.GetRootVelocity(Data.GetFrame(t), mirrored, delta); } } } if (module is StyleModule) { StyleModule m = (StyleModule)module; TimeSeries.Style series = new TimeSeries.Style(timeSeries, m.GetNames()); for (int i = 0; i < timeSeries.Samples.Length; i++) { float t = frame.Timestamp + timeSeries.Samples[i].Timestamp; series.Values[i] = m.GetStyles(Data.GetFrame(t)); } } if (module is GoalModule) { GoalModule m = (GoalModule)module; TimeSeries.Goal series = new TimeSeries.Goal(timeSeries, m.GetNames()); for (int i = 0; i < timeSeries.Samples.Length; i++) { float t = frame.Timestamp + timeSeries.Samples[i].Timestamp; series.Transformations[i] = m.Target.GetGoalTransformation(frame, timeSeries.Samples[i].Timestamp, mirrored, delta); series.Values[i] = m.GetActions(Data.GetFrame(t), delta); } } if (module is ContactModule) { ContactModule m = (ContactModule)module; TimeSeries.Contact series = new TimeSeries.Contact(timeSeries, m.GetNames()); for (int i = 0; i < timeSeries.Samples.Length; i++) { float t = frame.Timestamp + timeSeries.Samples[i].Timestamp; series.Values[i] = m.GetContacts(Data.GetFrame(t), mirrored); } } if (module is PhaseModule) { PhaseModule m = (PhaseModule)module; TimeSeries.Phase series = new TimeSeries.Phase(timeSeries); for (int i = 0; i < timeSeries.Samples.Length; i++) { float t = frame.Timestamp + timeSeries.Samples[i].Timestamp; series.Values[i] = m.GetPhase(Data.GetFrame(t), mirrored); } } } return(timeSeries); }