Peds form progress, playing peds animations and loading some textures

This commit is contained in:
dexy
2019-11-07 23:14:39 +11:00
Unverified
parent 8bfca3a338
commit 465b21d7ac
9 changed files with 687 additions and 395 deletions
+51 -7
View File
@@ -407,8 +407,34 @@ namespace CodeWalker.Rendering
}
private void UpdateAnim(ClipMapEntry cme)
{
var clipanim = cme.Clip as ClipAnimation;//maybe ClipAnimationList?
var clipanim = cme.Clip as ClipAnimation;
var anim = clipanim?.Animation;
if (anim != null)
{
UpdateAnim(anim);
}
var clipanimlist = cme.Clip as ClipAnimationList;
if (clipanimlist?.Animations != null)
{
if (clipanimlist.Animations.Count > 0)
{
UpdateAnim(clipanimlist.Animations[0].Animation);
}
////needs more work to synchronise these... seems to be multi layers, but timings are different
////sort of represents animations LODs, higher detail stuff like fingers and feet movements in the layers
//foreach (var canim in clipanimlist.Animations)
//{
// if (canim?.Animation == null) continue;
// UpdateAnim(canim.Animation);
// //break;
//}
}
}
private void UpdateAnim(Animation anim)
{
if (anim == null)
{ return; }
if (anim.BoneIds?.data_items == null)
@@ -436,6 +462,9 @@ namespace CodeWalker.Rendering
if (bones == null)
{ return; }
Vector4 v0, v1, v;
Quaternion q0, q1, q;
for (int i = 0; i < anim.BoneIds.data_items.Length; i++)
{
var boneiditem = anim.BoneIds.data_items[i];
@@ -454,19 +483,34 @@ namespace CodeWalker.Rendering
switch (track)
{
case 0: //bone position
var v0 = aseq.EvaluateVector(frame0);
var v1 = aseq.EvaluateVector(frame1);
var v = interpolate ? (v0 * ialpha) + (v1 * falpha) : v0;
v0 = aseq.EvaluateVector(frame0);
v1 = aseq.EvaluateVector(frame1);
v = interpolate ? (v0 * ialpha) + (v1 * falpha) : v0;
bone.AnimTranslation = v.XYZ();
break;
case 1: //bone orientation
var q0 = new Quaternion(aseq.EvaluateVector(frame0));
var q1 = new Quaternion(aseq.EvaluateVector(frame1));
var q = interpolate ? Quaternion.Slerp(q0, q1, falpha) : q0;
q0 = new Quaternion(aseq.EvaluateVector(frame0));
q1 = new Quaternion(aseq.EvaluateVector(frame1));
q = interpolate ? Quaternion.Slerp(q0, q1, falpha) : q0;
bone.AnimRotation = q;
break;
case 2: //scale?
break;
case 5://vector3...
//v0 = aseq.EvaluateVector(frame0);
//v1 = aseq.EvaluateVector(frame1);
//v = interpolate ? (v0 * ialpha) + (v1 * falpha) : v0;
//bone.AnimScale = v.XYZ();
break;
case 6://quaternion...
break;
case 134://single float?
case 136:
case 137:
case 138:
case 139:
case 140:
break;
default:
break;
}
+21 -6
View File
@@ -113,6 +113,8 @@ namespace CodeWalker.Rendering
public bool renderhdtextures = true;
public bool swaphemisphere = false;//can be used to get better lighting in model viewers
public MapSelectionMode SelectionMode = MapSelectionMode.Entity; //to assist in rendering embedded collisions properly...
@@ -498,6 +500,11 @@ namespace CodeWalker.Rendering
moonax = Vector3.Normalize(maxis.Multiply(Vector3.UnitY));
//bool usemoon = false;
if (swaphemisphere)
{
sundir.Y = -sundir.Y;
}
lightdir = sundir;
//if (lightdir.Z < -0.5f) lightdir.Z = -lightdir.Z; //make sure the lightsource is always above the horizon...
@@ -2488,17 +2495,24 @@ namespace CodeWalker.Rendering
return res;
}
public bool RenderDrawable(DrawableBase drawable, Archetype arche, YmapEntityDef entity, uint txdHash = 0)
public bool RenderDrawable(DrawableBase drawable, Archetype arche, YmapEntityDef entity, uint txdHash = 0, TextureDictionary txdExtra = null, ClipMapEntry animClip = null)
{
//enqueue a single drawable for rendering.
if (drawable == null)
return false;
Renderable rndbl = TryGetRenderable(arche, drawable, txdHash);
Renderable rndbl = TryGetRenderable(arche, drawable, txdHash, txdExtra);
if (rndbl == null)
return false;
if (animClip != null)
{
rndbl.ClipMapEntry = animClip;
rndbl.ClipDict = animClip.Clip?.Ycd;
rndbl.HasAnims = true;
}
return RenderRenderable(rndbl, arche, entity);
}
@@ -2784,7 +2798,7 @@ namespace CodeWalker.Rendering
private Renderable TryGetRenderable(Archetype arche, DrawableBase drawable, uint txdHash = 0)
private Renderable TryGetRenderable(Archetype arche, DrawableBase drawable, uint txdHash = 0, TextureDictionary txdExtra = null)
{
if (drawable == null) return null;
//BUG: only last texdict used!! needs to cache textures per archetype........
@@ -2836,7 +2850,8 @@ namespace CodeWalker.Rendering
}
var yptTexDict = (drawable.Owner as YptFile)?.PtfxList?.TextureDictionary;
var extraTexDict = (drawable.Owner as YptFile)?.PtfxList?.TextureDictionary;
if (extraTexDict == null) extraTexDict = txdExtra;
bool cacheSD = (rndbl.SDtxds == null);
bool cacheHD = (renderhdtextures && (rndbl.HDtxds == null));
@@ -2939,9 +2954,9 @@ namespace CodeWalker.Rendering
if ((tex != null) && (ttex == null))
{
//TextureRef means this RenderableTexture needs to be loaded from texture dict...
if (yptTexDict != null) //for ypt files, first try the embedded tex dict..
if (extraTexDict != null) //for ypt files, first try the embedded tex dict..
{
dtex = yptTexDict.Lookup(tex.NameHash);
dtex = extraTexDict.Lookup(tex.NameHash);
}
if (dtex == null) //else //if (texDict != 0)