Skip to content

Commit

Permalink
Updates
Browse files Browse the repository at this point in the history
  • Loading branch information
0x7c13 committed Jul 28, 2023
1 parent ddce330 commit a62a634
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public override void PerformAction(string actionName,

public override float GetActorHeight()
{
if (_skeletalModelRenderer == null)
if (_skeletalModelRenderer == null || !_skeletalModelRenderer.IsVisible())
{
return _meshBounds.size.y;
}
Expand All @@ -127,13 +127,13 @@ public override float GetActorHeight()

public override Bounds GetRendererBounds()
{
return _skeletalModelRenderer == null ? _rendererBounds :
return (_skeletalModelRenderer == null || !_skeletalModelRenderer.IsVisible()) ? _rendererBounds :
_skeletalModelRenderer.GetRendererBounds();
}

public override Bounds GetMeshBounds()
{
return _skeletalModelRenderer == null ? _meshBounds :
return (_skeletalModelRenderer == null || !_skeletalModelRenderer.IsVisible()) ? _meshBounds :
_skeletalModelRenderer.GetMeshBounds();
}

Expand Down Expand Up @@ -167,11 +167,12 @@ public void Execute(ActorAutoStandCommand command)
public void Execute(ActorStopActionCommand command)
{
if (command.ActorId != _actor.Info.Id ||
_skeletalModelRenderer == null) return;
_skeletalModelRenderer == null ||
!_skeletalModelRenderer.IsVisible()) return;

_skeletalModelRenderer.PauseAnimation();

if (_autoStand)
if (_autoStand && _skeletalModelRenderer.IsVisible())
{
PerformAction(_actor.GetIdleAction());
}
Expand Down
12 changes: 9 additions & 3 deletions Assets/Scripts/Pal3/Renderer/SkeletalModelRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,15 @@ public void Init(MshFile mshFile,
RenderMesh();
}

public void StartAnimation(MovFile mov, int loopCount = -1)
public void StartAnimation(MovFile movFile, int loopCount = -1)
{
if (_renderMeshComponents == null)
{
throw new Exception("Animation model not initialized.");
}

PauseAnimation();
BindJointTrack(mov);
SetupAnimationTrack(movFile);

_animationCts = new CancellationTokenSource();
_animation = StartCoroutine(PlayAnimationInternalAsync(loopCount,
Expand All @@ -134,7 +134,7 @@ public void PauseAnimation()
}
}

private void BindJointTrack(MovFile movFile)
private void SetupAnimationTrack(MovFile movFile)
{
// Reset all existing bone animation tracks
foreach (Bone bone in _bones.Values)
Expand Down Expand Up @@ -203,6 +203,7 @@ private void UpdateBone(Bone bone, uint tick)
{
int currentFrameIndex = Utility.GetFloorIndex(bone.FrameTicks, tick);

// TODO: Interpolate between frames
Vector3 localPosition = track.Value.KeyFrames[currentFrameIndex].Translation;
Quaternion localRotation = track.Value.KeyFrames[currentFrameIndex].Rotation;

Expand Down Expand Up @@ -402,6 +403,11 @@ public Bounds GetMeshBounds()
return bounds;
}

public bool IsVisible()
{
return _meshObjects != null;
}

private void OnDisable()
{
Dispose();
Expand Down
31 changes: 0 additions & 31 deletions Assets/Scripts/ResourceViewer/GameResourceViewer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,37 +120,6 @@ private void OnEnable()
#endif

//__Malicious__Dev_Only__();
DebugMovMsh();
}

private void DebugMovMsh()
{
string movFilePath = "basedata.cpk\\ROLE\\282\\z1.MOV";
string mshFilePath = "basedata.cpk\\ROLE\\282\\282.MSH";

try
{
MshFile mshFile = _resourceProvider.GetGameResourceFile<MshFile>(mshFilePath);
MovFile movFile = _resourceProvider.GetGameResourceFile<MovFile>(movFilePath);

ITextureResourceProvider textureProvider = _resourceProvider.CreateTextureResourceProvider(
Utility.GetRelativeDirectoryPath(mshFilePath));

var boneGo = new GameObject(Utility.GetFileName(movFilePath, CpkConstants.DirectorySeparator));
var skeletalRenderer = boneGo.AddComponent<SkeletalModelRenderer>();
skeletalRenderer.transform.SetParent(_renderingRoot.transform);

skeletalRenderer.Init(mshFile,
_resourceProvider.GetMaterialFactory(),
textureProvider,
"282.tga");

skeletalRenderer.StartAnimation(movFile);
}
catch (Exception ex)
{
Debug.LogException(ex);
}
}

private void __Malicious__Dev_Only__()
Expand Down

0 comments on commit a62a634

Please sign in to comment.