Fix bug with morphs with missing normal deltas

This commit is contained in:
Ammar Askar 2023-08-08 20:49:42 -04:00
parent c980bea304
commit 66dd166834
5 changed files with 17 additions and 3 deletions

View file

@ -223,7 +223,6 @@ namespace OpenTS2.Content.DBPF.Scenegraph
// 3rd delta map.
var deltaMapIdx = (3 - byteIdx);
Debug.Assert(deltaMapIdx < vertexPosDeltas.Length);
Debug.Assert(deltaMapIdx < vertexNormDeltas.Length);
var morphTarget = morphTargets[(int)vertexMapByte];
if (animations[vertexMapByte] == null)
@ -232,9 +231,13 @@ namespace OpenTS2.Content.DBPF.Scenegraph
}
animations[vertexMapByte].VertexPositionDeltas[i] = vertexPosDeltas[deltaMapIdx].Data[i];
// Optionally the normal morph might be defined.
if (deltaMapIdx < vertexNormDeltas.Length)
{
animations[vertexMapByte].VertexNormalDeltas[i] = vertexNormDeltas[deltaMapIdx].Data[i];
}
}
}
// Now we can actually attach the subset of morphs this mesh uses for unity. Only catch is unity requires
// the frameWeight parameter to be increasing, so we just start at 99% and increment. Not sure if it should

View file

@ -16,7 +16,7 @@ public class ScenegraphGMDCTest : MonoBehaviour
Filesystem.GetPackagesInDirectory(Filesystem.GetDataPathForProduct(ProductFlags.BaseGame) + "/Res/Sims3D"));
var resource = contentProvider.GetAsset<ScenegraphResourceAsset>(
new ResourceKey("chairReclinerPuffy_cres", GroupIDs.Scenegraph, TypeIDs.SCENEGRAPH_CRES));
new ResourceKey("puFace_cres", GroupIDs.Scenegraph, TypeIDs.SCENEGRAPH_CRES));
Debug.Log($"scenegraphModel: {resource.GlobalTGI}");
var gameObject = resource.CreateRootGameObject();

View file

@ -29,6 +29,7 @@ namespace OpenTS2.Rendering
RegisterMaterial<PhongTextureMaterial>();
RegisterMaterial<SimSkinMaterial>();
RegisterMaterial<SimStandardMaterial>();
// Ideally we'd just disable the mesh renderer to save a draw call but Maxis had to make it weird of course.
// Could maybe have an ApplyToRenderer(MeshRenderer, MaterialDef) function that does just that if the material def is Null instead.

View file

@ -0,0 +1,7 @@
namespace OpenTS2.Rendering.Materials
{
public class SimStandardMaterial : StandardMaterial
{
public override string Name => "SimStandardMaterial";
}
}

View file

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 4b25adaa292949a5a9ae02a93159de09
timeCreated: 1691541379