部分代码重构,AR起步冲的问题和停车动画调整
This commit is contained in:
1 parent
71b6155946
commit
fb4da81ce2
18 files changed
+3520
-4391
No files matched your search
@@ -323,8 +323,8 @@ namespace Assets.AR
|
||||
//创建轨迹上的转向
|
||||
public void CreateTrajectoryOrientations()
|
||||
{
|
||||
Quaternion[] quaternionArray = new Quaternion[this.FilteredCameraPositions.Length];
|
||||
for (int index = 1; index < this.FilteredCameraPositions.Length - 1; ++index)
|
||||
var quaternionArray = new Quaternion[this.FilteredCameraPositions.Length];
|
||||
for (var index = 1; index < this.FilteredCameraPositions.Length - 1; ++index)
|
||||
quaternionArray[index] = Quaternion.LookRotation(this.FilteredCameraPositions[index + 1] - this.FilteredCameraPositions[index - 1], Vector3.up);
|
||||
quaternionArray[0] = quaternionArray[1];
|
||||
quaternionArray[this.FilteredCameraPositions.Length - 1] = quaternionArray[this.FilteredCameraPositions.Length - 2];
|
||||
@@ -374,7 +374,7 @@ namespace Assets.AR
|
||||
}
|
||||
if (index1 + 1 == this.LightRotations.Length)
|
||||
return this.LightRotations[this.LightRotations.Length - 1];
|
||||
float t = Mathf.InverseLerp(this.LightRotationFrames[index1], this.LightRotationFrames[index1 + 1], distance);
|
||||
var t = Mathf.InverseLerp(this.LightRotationFrames[index1], this.LightRotationFrames[index1 + 1], distance);
|
||||
return Quaternion.Slerp(this.LightRotations[index1], this.LightRotations[index1 + 1], t);
|
||||
}
|
||||
|
||||
@@ -433,7 +433,6 @@ namespace Assets.AR
|
||||
this.SlamSegments = data.SlamSegments;
|
||||
this.CameraHeight = data.CameraHeight;
|
||||
this.RiderScale = (double)data.RiderScale != 0.0 ? data.RiderScale : 1f;
|
||||
this.RiderScale *= 0.9f;
|
||||
this.CameraPositions = ((IEnumerable<VectorData>)data.CameraPositions).Select<VectorData, Vector3>((Func<VectorData, Vector3>)(x => x.ToUnityVector())).ToArray<Vector3>();
|
||||
this.ProjectionParameters = data.CameraProjectionParameters;
|
||||
this.CameraRotations = ((IEnumerable<VectorData>)data.CameraRotations).Select<VectorData, Quaternion>((Func<VectorData, Quaternion>)(x => Quaternion.Euler(x.ToUnityVector()))).ToArray<Quaternion>();
|
||||
|
||||
@@ -18,8 +18,8 @@ namespace Assets.AR
|
||||
ARVideoPlayerControl VideoPlayerControl;
|
||||
ARLaneGameObject[] rides { get; set; }
|
||||
public ARLaneGameObject mainRiderObject { get; set; }
|
||||
private Light arLight;
|
||||
private Light arBackLight;
|
||||
public Light arLight;
|
||||
private Light arBackLight { get; set; }
|
||||
public CameraDistance RiderCameraDistance { get; set; }
|
||||
public VideoPlayMode VideoControlMode { get; private set; }
|
||||
private float autoCameraSwitchTimeCounter = 80f;
|
||||
@@ -55,6 +55,7 @@ namespace Assets.AR
|
||||
//ar数据加载本地,本地没有就下载
|
||||
this.aRData = arData;
|
||||
this.detail = routeDetailData;
|
||||
|
||||
this.RiderCameraDistance = AR.CameraDistance.Middle;
|
||||
videoPointsSync = new VideoPointsSync(detail.VideoPoints.Select(c => new VideoPoint()
|
||||
{
|
||||
@@ -62,14 +63,20 @@ namespace Assets.AR
|
||||
Time = (float)c.VideoTime
|
||||
}));
|
||||
videoSync = videoPointsSync;
|
||||
this.VideoPlayerControl = new ARVideoPlayerControl();
|
||||
this.VideoPlayerControl.VideoSyncSource = videoSync;
|
||||
this.VideoPlayerControl = new ARVideoPlayerControl
|
||||
{
|
||||
VideoSyncSource = videoSync
|
||||
};
|
||||
|
||||
this.videoPlayer = mediaPlayer.gameObject.AddComponent<AVProVideoPlayer>();
|
||||
this.videoPlayer.videoPlayer = mediaPlayer;
|
||||
|
||||
SetArRoute(new ARRoute(aRData.Route), videoSync, videoPlayer);
|
||||
|
||||
this.VideoPlayerControl.VideoFrameOffset = this.Route.VideoFrameOffset;
|
||||
this.VideoPlayerControl.Route = Route;
|
||||
this.VideoPlayerControl.SetVideoPlayer(videoPlayer);
|
||||
|
||||
rides = FindObjectsOfType<ARLaneGameObject>();
|
||||
SetUpLight();
|
||||
}
|
||||
@@ -123,7 +130,7 @@ namespace Assets.AR
|
||||
}
|
||||
}
|
||||
|
||||
timers += 1f;
|
||||
timers += 0.2f;
|
||||
}
|
||||
|
||||
if (mainRiderObject == null || Route == null)
|
||||
@@ -134,16 +141,15 @@ namespace Assets.AR
|
||||
var delta = Time.deltaTime;
|
||||
foreach (var obj in this.riderObjects.Values)
|
||||
{
|
||||
var offset = obj.DeltaDistance * delta;
|
||||
//Debug.Log($"offset:{offset}:{DateTime.Now}");
|
||||
obj.Distance += offset;
|
||||
obj.RouteDistance += offset;
|
||||
if(obj.DeltaDistance == 0 )continue;
|
||||
obj.Distance = Mathf.Lerp(obj.Distance, obj.Distance + obj.DeltaDistance, delta);
|
||||
obj.RouteDistance = Mathf.Lerp(obj.RouteDistance, obj.RouteDistance + obj.DeltaDistance, delta);
|
||||
}
|
||||
|
||||
VideoPlayerControl.UpdateVideoPlayRate(mainRiderObject.PreSpeed, mainRiderObject.Distance);
|
||||
|
||||
this.FrameIndexDistanceCorrection = this.VideoPlayerControl.FrameIndexDistanceCorrection;
|
||||
//this.FollowedRiderId = mainObject.Id;
|
||||
this.UpdateCameraFollowDistance();
|
||||
VideoPlayerControl.UpdateVideoPlayRate(mainRiderObject.PreSpeed, mainRiderObject.Distance);
|
||||
base.Update();
|
||||
this.UpdateRidersVisibility();
|
||||
this.UpdateRidersLean();
|
||||
@@ -159,23 +165,11 @@ namespace Assets.AR
|
||||
//创建
|
||||
private void SetUpLight()
|
||||
{
|
||||
GameObject gameObject1 = new GameObject("ARLight");
|
||||
gameObject1.layer = this.gameObject.layer;
|
||||
gameObject1.transform.SetParent(this.transform);
|
||||
this.arLight = gameObject1.AddComponent<Light>();
|
||||
this.arLight.type = LightType.Directional;
|
||||
this.arLight.transform.rotation = Quaternion.Euler(90f, 0.0f, 0.0f);
|
||||
//if (this.BuildConfig.IsIOs || this.BuildConfig.IsTvOs)
|
||||
//{
|
||||
// this.arLight.shadows = LightShadows.Hard;
|
||||
// this.arLight.shadowStrength = 0.5f;
|
||||
//}
|
||||
//else
|
||||
{
|
||||
this.arLight.shadows = LightShadows.Soft;
|
||||
this.arLight.shadowStrength = 1f;
|
||||
}
|
||||
this.arLight.cullingMask = 512;
|
||||
this.arLight.shadows = LightShadows.Soft;
|
||||
this.arLight.shadowStrength = 1f;
|
||||
|
||||
GameObject gameObject2 = new GameObject("ARBackLight");
|
||||
gameObject2.layer = this.gameObject.layer;
|
||||
gameObject2.transform.SetParent(this.transform);
|
||||
@@ -184,7 +178,7 @@ namespace Assets.AR
|
||||
this.arBackLight.transform.rotation = Quaternion.Euler(0.0f, 0.0f, 0.0f);
|
||||
this.arBackLight.shadows = LightShadows.None;
|
||||
this.arBackLight.intensity = 0.5f;
|
||||
this.arBackLight.cullingMask = 512;
|
||||
//this.arBackLight.cullingMask = 512;
|
||||
}
|
||||
//设置video显示模式
|
||||
public void SetVideoControlMode(VideoPlayMode mode)
|
||||
@@ -202,15 +196,15 @@ namespace Assets.AR
|
||||
//更新摄像机的位置
|
||||
private void UpdateCameraFollowDistance()
|
||||
{
|
||||
this.NearViewMode = this.RiderCameraDistance == AR.CameraDistance.Near;
|
||||
float cameraFollowDistance = GetCameraFollowDistance(this.RiderCameraDistance);
|
||||
//this.NearViewMode = this.RiderCameraDistance == AR.CameraDistance.Near;
|
||||
var cameraFollowDistance = GetCameraFollowDistance(this.RiderCameraDistance);
|
||||
this.VideoPlayerControl.CameraFollowDistance = cameraFollowDistance;
|
||||
}
|
||||
//人物是否显示
|
||||
protected override bool IsObjectActive(ARGameObject arObject)
|
||||
{
|
||||
var flag = base.IsObjectActive(arObject);
|
||||
if ((UnityEngine.Object)arObject != (UnityEngine.Object)this.mainRiderObject)
|
||||
if (arObject != this.mainRiderObject)
|
||||
return flag;
|
||||
if ((double)this.VideoPlayerControl.CameraFollowDistance > 0.0 || this.AR360Version)
|
||||
return flag;
|
||||
@@ -270,7 +264,7 @@ namespace Assets.AR
|
||||
}
|
||||
gameObject.transform.parent = this.transform;
|
||||
gameObject.transform.position = ARGameObjectsController.DefaultObjectPosition;
|
||||
gameObject.layer = 9;
|
||||
//gameObject.layer = 9;
|
||||
riderModel.Route = this.Route;
|
||||
riderModel.VideoSync = this.videoSync;
|
||||
//riderModel.VideoPlayer = this.videoPlayer;
|
||||
@@ -297,7 +291,7 @@ namespace Assets.AR
|
||||
transform = {
|
||||
parent = this.transform
|
||||
},
|
||||
layer = 9
|
||||
//layer = 9
|
||||
}.AddComponent<ARLaneGameObject>();
|
||||
riderObject.Route = this.Route;
|
||||
riderObject.VideoSync = this.videoSync;
|
||||
@@ -660,17 +654,9 @@ namespace Assets.AR
|
||||
}
|
||||
//更新后背的光线
|
||||
private void UpdateBackLight()
|
||||
{
|
||||
//if (this.SelectedPanorama != null)
|
||||
//{
|
||||
// this.arBackLight.transform.position = this.PanoramaCamera.transform.position;
|
||||
// this.arBackLight.transform.rotation = this.PanoramaCamera.transform.rotation;
|
||||
//}
|
||||
//else
|
||||
{
|
||||
this.arBackLight.transform.position = this.UnityCamera.transform.position;
|
||||
this.arBackLight.transform.rotation = this.UnityCamera.transform.rotation;
|
||||
}
|
||||
{
|
||||
this.arBackLight.transform.position = this.UnityCamera.transform.position;
|
||||
this.arBackLight.transform.rotation = this.UnityCamera.transform.rotation;
|
||||
this.arLight.transform.rotation = this.Route.GetLightDirection(this.videoPlayer.CurrentFrame);
|
||||
this.arLight.shadowStrength = this.Route.GetShadowIntensity(this.videoPlayer.CurrentFrame);
|
||||
}
|
||||
|
||||
@@ -82,6 +82,7 @@ namespace Assets.AR
|
||||
|
||||
private void SkipVideoToFrame(long frame) => this.VideoPlayer.Seek(frame);
|
||||
|
||||
private const float TimerInterval = 0.2f;
|
||||
public void UpdateVideoPlayRate(float speed, float routeDistance)
|
||||
{
|
||||
if (!this.AllowUpdate)
|
||||
@@ -103,32 +104,32 @@ namespace Assets.AR
|
||||
}
|
||||
else
|
||||
{
|
||||
float videoFrameAtDistance1 = this.VideoSyncSource.GetVideoFrameAtDistance(routeDistance);
|
||||
float val2 = routeDistance - this.CameraFollowDistance;
|
||||
var videoFrameAtDistance1 = this.VideoSyncSource.GetVideoFrameAtDistance(routeDistance);
|
||||
var val2 = routeDistance - this.CameraFollowDistance;
|
||||
//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;
|
||||
var distance = Math.Max(0.0f, val2);
|
||||
var 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);
|
||||
var distanceForVideoFrame = this.VideoSyncSource.GetDistanceForVideoFrame(this.VideoPlayer.CurrentFrame - (float)this.VideoFrameOffset);
|
||||
float f;
|
||||
if (this.Route != null)
|
||||
{
|
||||
double frameAtDistance = this.Route.GetFrameAtDistance(this.Route.GetDistanceForFrame((double)this.VideoPlayer.CurrentFrame - (double)this.VideoFrameOffset) + (double)Mathf.Min(routeDistance, this.CameraFollowDistance));
|
||||
var frameAtDistance = this.Route.GetFrameAtDistance(this.Route.GetDistanceForFrame((double)this.VideoPlayer.CurrentFrame - (double)this.VideoFrameOffset) + (double)Mathf.Min(routeDistance, this.CameraFollowDistance));
|
||||
f = videoFrameAtDistance1 - (float)frameAtDistance;
|
||||
}
|
||||
else
|
||||
f = frame - (this.VideoPlayer.CurrentFrame - (float)this.VideoFrameOffset);
|
||||
float num1 = Mathf.Clamp01(PFMath.Lerp(0.0f, 1f, 100f, 0.0f, Mathf.Abs(f)));
|
||||
var num1 = Mathf.Clamp01(PFMath.Lerp(0.0f, 1f, 100f, 0.0f, Mathf.Abs(f)));
|
||||
this.FrameIndexDistanceCorrection = f * num1;
|
||||
this.CameraDistanceError = distance - distanceForVideoFrame;
|
||||
if (this.IsMultilap)
|
||||
{
|
||||
float num2 = distance - (distanceForVideoFrame + (float)this.lapLength);
|
||||
var num2 = distance - (distanceForVideoFrame + (float)this.lapLength);
|
||||
if ((double)Math.Abs(num2) < (double)Math.Abs(this.CameraDistanceError) && (double)Math.Abs(num2) < 200.0)
|
||||
return;
|
||||
}
|
||||
@@ -139,7 +140,7 @@ namespace Assets.AR
|
||||
else
|
||||
{
|
||||
var totalSeconds = DateTime.UtcNow.Subtract(this.lastPlaybackSpeedChange).TotalSeconds;
|
||||
if (totalSeconds >= 0.0 && totalSeconds < 0.20000000298023224)
|
||||
if (totalSeconds >= 0.0 && totalSeconds < TimerInterval)
|
||||
return;
|
||||
var num3 = (float)totalSeconds;
|
||||
var num4 = num3 * speed;
|
||||
|
||||
Reference in new issue
Block a user