ar Demo完善
This commit is contained in:
1 parent
9552fed2e0
commit
158fab27ab
9 files changed
+307
-74
No files matched your search
@@ -54,13 +54,11 @@ namespace Assets.AR
|
||||
{
|
||||
PositionOffset = Vector3.up * route.CameraHeight * (-1);
|
||||
Quaternion cameraRotation = this.GetCameraRotation(this.frame - this.FrameIndexDistanceCorrection);
|
||||
Vector3 filteredCameraPosition = this.GetFilteredCameraPosition(this.frame + this.FrameIndexDistanceCorrection);
|
||||
|
||||
|
||||
Debug.Log($"{filteredCameraPosition}={this.CameraPositionOffset}:{this.Route.GetFilteredCameraPosition(this.frame )}");
|
||||
|
||||
Vector3 filteredCameraPosition = this.GetFilteredCameraPosition(this.frame - this.FrameIndexDistanceCorrection);
|
||||
Debug.Log(FrameIndexDistanceCorrection);
|
||||
Vector3 vector3 = Vector3.left * (this.route.LeftHanded ? -1f : 1f) * (this.LaneWidth * (this.Lane + this.LaneCamera) - this.BaseOffset);
|
||||
this.transform.position = filteredCameraPosition + cameraRotation * (vector3 + this.PositionOffset);
|
||||
var targetPos = filteredCameraPosition + cameraRotation * (vector3 + this.PositionOffset);
|
||||
this.transform.position = targetPos;
|
||||
this.transform.rotation = cameraRotation * Quaternion.Euler(this.RotationOffset) * Quaternion.Euler(this.Lean);
|
||||
this.transform.localScale = this.Scale;
|
||||
|
||||
|
||||
+34
-1
@@ -28,6 +28,8 @@ namespace Assets.AR
|
||||
|
||||
private float FrameRate = 29.97f;
|
||||
|
||||
public ARObjectTimeTransform[] TimeTransforms { get; set; }
|
||||
|
||||
public string CustomUrl { get; set; }
|
||||
|
||||
public string ArName { get; set; }
|
||||
@@ -64,6 +66,9 @@ namespace Assets.AR
|
||||
}
|
||||
}
|
||||
|
||||
public float DeltaDistance { get; set; }
|
||||
public float PreDistance { get; set; }
|
||||
|
||||
public float Distance
|
||||
{
|
||||
get => this.distance;
|
||||
@@ -86,7 +91,35 @@ namespace Assets.AR
|
||||
this.transform.position = filteredCameraPosition + cameraRotation * this.PositionOffset;
|
||||
this.transform.localScale = this.Scale;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void UpdateByTimeDefinitions(float currentFrame)
|
||||
{
|
||||
if (this.TimeTransforms == null || this.TimeTransforms.Length == 0)
|
||||
return;
|
||||
if (this.nextTimeDefIndex > this.TimeTransforms.Length - 1)
|
||||
this.nextTimeDefIndex = 0;
|
||||
if (this.nextTimeDefIndex > 0 && (double)this.TimeTransforms[this.nextTimeDefIndex - 1].Frame > (double)currentFrame)
|
||||
this.nextTimeDefIndex = 0;
|
||||
while (this.nextTimeDefIndex < this.TimeTransforms.Length - 1 && (double)this.TimeTransforms[this.nextTimeDefIndex].Frame <= (double)currentFrame)
|
||||
++this.nextTimeDefIndex;
|
||||
if (this.nextTimeDefIndex == 0)
|
||||
{
|
||||
this.Distance = this.TimeTransforms[0].Distance;
|
||||
this.PositionOffset = this.TimeTransforms[0].PositionOffset;
|
||||
this.Scale = this.TimeTransforms[0].Scale;
|
||||
this.RotationOffset = this.TimeTransforms[0].RotationOffset;
|
||||
}
|
||||
else
|
||||
{
|
||||
float t = Mathf.Clamp01((currentFrame - (float)this.TimeTransforms[this.nextTimeDefIndex - 1].Frame) / (float)(this.TimeTransforms[this.nextTimeDefIndex].Frame - this.TimeTransforms[this.nextTimeDefIndex - 1].Frame));
|
||||
this.Distance = Mathf.Lerp(this.TimeTransforms[this.nextTimeDefIndex - 1].Distance, this.TimeTransforms[this.nextTimeDefIndex].Distance, t);
|
||||
this.PositionOffset = Vector3.Lerp(this.TimeTransforms[this.nextTimeDefIndex - 1].PositionOffset, this.TimeTransforms[this.nextTimeDefIndex].PositionOffset, t);
|
||||
this.Scale = Vector3.Lerp(this.TimeTransforms[this.nextTimeDefIndex - 1].Scale, this.TimeTransforms[this.nextTimeDefIndex].Scale, t);
|
||||
this.RotationOffset = Vector3.Lerp(this.TimeTransforms[this.nextTimeDefIndex - 1].RotationOffset, this.TimeTransforms[this.nextTimeDefIndex].RotationOffset, t);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void UpdateOffsets()
|
||||
{
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace Assets.AR
|
||||
{
|
||||
public class ARObjectTimeTransform
|
||||
{
|
||||
public int Frame;
|
||||
public float Distance;
|
||||
public Vector3 PositionOffset;
|
||||
public Vector3 RotationOffset;
|
||||
public Vector3 Scale;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 301eba5f832d14449ac634fb05589194
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -100,11 +100,17 @@ namespace Assets.AR
|
||||
arObject.CameraPositionOffset = this.cameraPositionOffset;
|
||||
if (arObject is ARLaneObject arLaneObject)
|
||||
arLaneObject.FrameIndexDistanceCorrection = this.FrameIndexDistanceCorrection;
|
||||
|
||||
//if (this.SelectedPanorama != null && (arObject.ObjectType == ARObjectType.Box || arObject.ObjectType == ARObjectType.Sphere))
|
||||
//{
|
||||
// arObject.gameObject.SetActive(false);
|
||||
//}
|
||||
//else
|
||||
{
|
||||
if (arObject.TimeTransforms != null && arObject.TimeTransforms.Length > 1)
|
||||
arObject.UpdateByTimeDefinitions(videoFrame);
|
||||
arObject.UpdateVisibility(videoFrame, visibilityRear, visibilityFront, this.IsMultilap);
|
||||
bool flag = this.IsArObjectActive(arObject);
|
||||
//arObject.gameObject.SetActive(flag); TODO
|
||||
arObject.gameObject.SetActive(flag);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+21
-36
@@ -6,6 +6,7 @@ using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace Assets.Scripts.Scenes.VideoRide
|
||||
{
|
||||
@@ -27,6 +28,8 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
private Light arLight;
|
||||
private Light arBackLight;
|
||||
|
||||
public Text Fps;
|
||||
|
||||
protected override void Start()
|
||||
{
|
||||
base.Start();
|
||||
@@ -69,7 +72,7 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
float timers = 0f;
|
||||
float timers = 1f;
|
||||
double weight = 70;
|
||||
double bikeWeight = 20;
|
||||
|
||||
@@ -81,9 +84,12 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
{
|
||||
foreach (var item in rides)
|
||||
{
|
||||
if (item.StartPosition == 1)
|
||||
{
|
||||
item.TestPower = new System.Random().Next(90, 120);
|
||||
}
|
||||
item.Speed = (float)(Assets.Scenes.Ride.Scripts.Helper.CalculateSpeed(0, 0, item.TestPower, weight, bikeWeight) / 3.6d);
|
||||
item.Distance += item.Speed;
|
||||
item.RouteDistance = item.Distance;
|
||||
item.DeltaDistance = item.Speed;
|
||||
item.Route = Route;
|
||||
item.VideoSync = videoPointsSync;
|
||||
if (!this.riderObjects.ContainsKey(item.GetInstanceID()))
|
||||
@@ -92,11 +98,16 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
|
||||
timers += 1f;
|
||||
}
|
||||
|
||||
this.FollowedRiderId = 1;
|
||||
this.UpdateCameraFollowDistance();
|
||||
VideoPlayerControl.UpdateVideoPlaybackSpeed(mainObject.Speed, mainObject.distance-this.CameraDistance);
|
||||
this.FrameIndexDistanceCorrection = this.VideoPlayerControl.FrameIndexDistanceCorrection;
|
||||
foreach (var item in rides)
|
||||
{
|
||||
item.Distance += item.DeltaDistance * Time.deltaTime;
|
||||
item.RouteDistance += item.DeltaDistance * Time.deltaTime;
|
||||
}
|
||||
this.UpdateCameraFollowDistance();
|
||||
VideoPlayerControl.UpdateVideoPlaybackSpeed(mainObject.Speed, mainObject.distance);
|
||||
Fps.text = this.mediaPlayer.Control.GetCurrentTimeFrames().ToString();
|
||||
this.FollowedRiderId = 1;
|
||||
base.Update();
|
||||
this.UpdateRidersVisibility();
|
||||
this.UpdateRidersLean();
|
||||
@@ -141,10 +152,10 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
//更新摄像机的位置
|
||||
private void UpdateCameraFollowDistance()
|
||||
{
|
||||
this.RiderCameraDistance = RiderCameraDistance.Near;
|
||||
this.RiderCameraDistance = RiderCameraDistance.Middle;
|
||||
this.NearViewMode = this.RiderCameraDistance == RiderCameraDistance.Near;
|
||||
float cameraFollowDistance = GetCameraFollowDistance(this.RiderCameraDistance);
|
||||
this.VideoPlayerControl.CameraFollowDistance = this.videoPlayer.IsRear ? cameraFollowDistance * -1f : cameraFollowDistance;
|
||||
this.VideoPlayerControl.CameraFollowDistance = cameraFollowDistance;
|
||||
}
|
||||
protected override bool IsArObjectActive(ARObject arObject)
|
||||
{
|
||||
@@ -163,7 +174,7 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
case RiderCameraDistance.FirstPerson:
|
||||
return 0.0f;
|
||||
case RiderCameraDistance.Near:
|
||||
return 1.5f;
|
||||
return 2.5f;
|
||||
case RiderCameraDistance.Middle:
|
||||
return 5f;
|
||||
case RiderCameraDistance.Far:
|
||||
@@ -252,32 +263,6 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
riderObject.Lean = new Vector3(0.0f, y, z1);
|
||||
}
|
||||
}
|
||||
|
||||
DateTime lastPlaybackSpeedChange = DateTime.UtcNow;
|
||||
bool pausedByPlaybackSpeed = false;
|
||||
bool pausedByTrainingPause = false;
|
||||
float frame = 0f;
|
||||
public bool SetPlaybackSpeed(float playbackSpeed)
|
||||
{
|
||||
if (this.mediaPlayer.Control.IsSeeking() || DateTime.UtcNow.Subtract(this.lastPlaybackSpeedChange).TotalSeconds < 1.0)
|
||||
return false;
|
||||
if ((double)playbackSpeed == 0.0 && !this.pausedByPlaybackSpeed)
|
||||
{
|
||||
this.pausedByPlaybackSpeed = true;
|
||||
this.mediaPlayer.Pause();
|
||||
}
|
||||
else if ((double)playbackSpeed > 0.0 && this.pausedByPlaybackSpeed)
|
||||
{
|
||||
this.pausedByPlaybackSpeed = false;
|
||||
if (!this.pausedByTrainingPause)
|
||||
this.mediaPlayer.Play();
|
||||
}
|
||||
this.mediaPlayer.Control.SetPlaybackRate(playbackSpeed);
|
||||
this.lastPlaybackSpeedChange = DateTime.UtcNow;
|
||||
mediaPlayer.Play();
|
||||
return true;
|
||||
}
|
||||
|
||||
#endif
|
||||
//人物状态
|
||||
private string ConfigPath = Application.streamingAssetsPath + "/newdirection.txt";
|
||||
|
||||
@@ -65,18 +65,18 @@ namespace Assets.AR
|
||||
this.VideoPlayer.Seek((long)frame, true);
|
||||
}
|
||||
|
||||
//public void UnFixTime()
|
||||
//{
|
||||
// this.IsTimeFixed = false;
|
||||
// float videoFrameAtDistance = this.VideoSyncSource.GetVideoFrameAtDistance(this.RiderDistance.LapDistance);
|
||||
// float num = this.VideoSyncSource.AverageVideoSpeed(videoFrameAtDistance, videoFrameAtDistance);
|
||||
// float playbackSpeed = (double)num != 0.0 ? this.RiderSpeed.Speed / num : 0.0f;
|
||||
// if (this.VideoPlayer.IsPaused)
|
||||
// this.VideoPlayer.Resume();
|
||||
// this.VideoPlayer.SetPlaybackSpeed(playbackSpeed);
|
||||
// this.lastPlaybackSpeedChange = DateTime.UtcNow;
|
||||
// this.VideoPlayer.Seek((long)videoFrameAtDistance, true);
|
||||
//}
|
||||
public void UnFixTime()
|
||||
{
|
||||
//this.IsTimeFixed = false;
|
||||
//float videoFrameAtDistance = this.VideoSyncSource.GetVideoFrameAtDistance(this.RiderDistance.LapDistance);
|
||||
//float num = this.VideoSyncSource.AverageVideoSpeed(videoFrameAtDistance, videoFrameAtDistance);
|
||||
//float playbackSpeed = (double)num != 0.0 ? this.RiderSpeed.Speed / num : 0.0f;
|
||||
//if (this.VideoPlayer.IsPaused)
|
||||
// this.VideoPlayer.Resume();
|
||||
//this.VideoPlayer.SetPlaybackSpeed(playbackSpeed);
|
||||
//this.lastPlaybackSpeedChange = DateTime.UtcNow;
|
||||
//this.VideoPlayer.Seek((long)videoFrameAtDistance, true);
|
||||
}
|
||||
|
||||
private void SkipVideoToDistance(float distance) => this.SkipVideoToFrame((long)this.VideoSyncSource.GetVideoFrameAtDistance(distance));
|
||||
|
||||
@@ -96,7 +96,8 @@ namespace Assets.AR
|
||||
return;
|
||||
if ((double)this.VideoPlayer.CurrentFrame > (double)this.fixedTimeFrame)
|
||||
this.VideoPlayer.Pause();
|
||||
|
||||
//if (this.VideoPlayer is RouvyVideoPlayer.RouvyVideoPlayer videoPlayer)
|
||||
// videoPlayer.TargetFrame = this.fixedTimeFrame;
|
||||
this.VideoPlayer.UpdateCurrentFrame();
|
||||
this.FrameIndexDistanceCorrection = 0.0f;
|
||||
}
|
||||
@@ -104,15 +105,15 @@ namespace Assets.AR
|
||||
{
|
||||
float videoFrameAtDistance1 = this.VideoSyncSource.GetVideoFrameAtDistance(routeDistance);
|
||||
float val2 = routeDistance - this.CameraFollowDistance;
|
||||
//if (this.IsMultilap && (double)this.RiderDistance.RouteDistance > (double)distance && (double)val2 < 0.0)
|
||||
//if (this.IsMultilap && (double)this.RiderDistance.RouteDistance > (double)this.RiderDistance.LapDistance && (double)val2 < 0.0)
|
||||
// val2 += (float)this.lapLength;
|
||||
float distance = Math.Max(0.0f, val2);
|
||||
float frame = this.VideoSyncSource.GetVideoFrameAtDistance(distance) + (float)this.VideoFrameOffset;
|
||||
if (this.Route != null && (double)this.Route.GetVisibility(frame) > 10.0)
|
||||
frame = (float)this.Route.GetFrameAtDistance(Math.Max(0.0, this.Route.GetDistanceForFrame((double)videoFrameAtDistance1) - (double)this.CameraFollowDistance)) + (float)this.VideoFrameOffset;
|
||||
|
||||
//if (this.VideoPlayer is RouvyLib.Video.RouvyVideoPlayer.RouvyVideoPlayer videoPlayer)
|
||||
// videoPlayer.TargetFrame = frame;
|
||||
this.VideoPlayer.UpdateCurrentFrame();
|
||||
|
||||
float distanceForVideoFrame = this.VideoSyncSource.GetDistanceForVideoFrame(this.VideoPlayer.CurrentFrame - (float)this.VideoFrameOffset);
|
||||
float f;
|
||||
if (this.Route != null)
|
||||
@@ -142,11 +143,18 @@ namespace Assets.AR
|
||||
return;
|
||||
float num3 = 1f;
|
||||
float num4 = num3 * speed;
|
||||
if ((double)Math.Abs(distance + num4 - this.VideoSyncSource.GetDistanceForVideoFrame((float)((double)this.VideoPlayer.CurrentFrame - (double)this.VideoFrameOffset + (double)num3 * (double)this.VideoPlayer.PlaybackSpeed * (double)this.VideoPlayer.FrameRate))) <= (double)Math.Abs(this.CameraDistanceError))
|
||||
var offset = this.VideoSyncSource.GetDistanceForVideoFrame((float)((double)this.VideoPlayer.CurrentFrame - (double)this.VideoFrameOffset + (double)num3 * (double)this.VideoPlayer.PlaybackSpeed * (double)this.VideoPlayer.FrameRate));
|
||||
var left = (double)Math.Abs(distance + num4 - offset);
|
||||
var right = (double)Math.Abs(this.CameraDistanceError);
|
||||
|
||||
if (left <= right)
|
||||
return;
|
||||
float videoFrameAtDistance2 = this.VideoSyncSource.GetVideoFrameAtDistance(routeDistance + num4);
|
||||
float num5 = this.VideoSyncSource.AverageVideoSpeed(videoFrameAtDistance1, videoFrameAtDistance2);
|
||||
float playbackSpeed = Mathf.Clamp(((double)num5 != 0.0 ? speed / num5 : 0.0f) + (float)(((double)frame - ((double)this.VideoPlayer.CurrentFrame - (double)this.VideoFrameOffset)) / 2.0) / this.VideoPlayer.FrameRate, 0.0f, 1.5f);
|
||||
var ratio = ((double)num5 != 0.0 ? speed / num5 : 0.0f);
|
||||
var deltaRatio = (float)(((double)frame - ((double)this.VideoPlayer.CurrentFrame - (double)this.VideoFrameOffset)) / 2.0) / this.VideoPlayer.FrameRate;
|
||||
float playbackSpeed = Mathf.Clamp(ratio + deltaRatio, 0.0f, 1.5f);
|
||||
|
||||
if ((double)playbackSpeed == (double)this.VideoPlayer.PlaybackSpeed || !this.VideoPlayer.SetPlaybackSpeed(playbackSpeed))
|
||||
return;
|
||||
this.lastPlaybackSpeedChange = DateTime.UtcNow;
|
||||
|
||||
Reference in new issue
Block a user