Skip to content

Commit

Permalink
SAModel Cleanup - Part 1 (#276)
Browse files Browse the repository at this point in the history
* GCAttach

* Remaining GC Cleanup

* Ninja Binary Cleanup

* XJ
  • Loading branch information
IsaacMarovitz authored Dec 19, 2024
1 parent 7affea7 commit 090495c
Show file tree
Hide file tree
Showing 16 changed files with 1,743 additions and 1,588 deletions.
48 changes: 24 additions & 24 deletions Libraries/SAEditorCommon/Import/AssimpStuff.cs
Original file line number Diff line number Diff line change
Expand Up @@ -426,12 +426,12 @@ public static List<int> ExportAttachMeshes(this Attach attach, Scene scene, stri
if (attach is GC.GCAttach gcAttach)
{
int nameMeshIndex = 0;
foreach (GC.GCMesh m in gcAttach.opaqueMeshes)
foreach (GC.GCMesh m in gcAttach.OpaqueMeshes)
{
result.Add(scene.Meshes.Count);
scene.Meshes.Add(ExportGCMesh(gcAttach, m, scene, texInfo, ref nameMeshIndex));
}
foreach (GC.GCMesh m in gcAttach.translucentMeshes)
foreach (GC.GCMesh m in gcAttach.TranslucentMeshes)
{
result.Add(scene.Meshes.Count);
scene.Meshes.Add(ExportGCMesh(gcAttach, m, scene, texInfo, ref nameMeshIndex));
Expand Down Expand Up @@ -511,13 +511,13 @@ private static Assimp.Mesh ExportGCMesh(GC.GCAttach gcAttach, GC.GCMesh m, Scene
List<Vector3D> normals = new List<Vector3D>();
List<Vector3D> texcoords = new List<Vector3D>();
List<Color4D> colors = new List<Color4D>();
foreach (GC.GCParameter param in m.parameters)
foreach (GC.GCParameter param in m.Parameters)
{
if (param.type == GC.ParameterType.Texture)
if (param.Type == GC.ParameterType.Texture)
{
GC.TextureParameter tex = param as GC.TextureParameter;
MaterialBuffer.UseTexture = true;
MaterialBuffer.TextureID = tex.TextureID;
MaterialBuffer.TextureID = tex.TextureId;
if (tex.Tile.HasFlag(GC.GCTileMode.MirrorU))
MaterialBuffer.FlipU = true;
if (tex.Tile.HasFlag(GC.GCTileMode.MirrorV))
Expand All @@ -530,27 +530,27 @@ private static Assimp.Mesh ExportGCMesh(GC.GCAttach gcAttach, GC.GCMesh m, Scene
MaterialBuffer.ClampU &= tex.Tile.HasFlag(GC.GCTileMode.Unk_1);
MaterialBuffer.ClampV &= tex.Tile.HasFlag(GC.GCTileMode.Unk_1);
}
else if (param.type == GC.ParameterType.TexCoordGen)
else if (param.Type == GC.ParameterType.TexCoordGen)
{
GC.TexCoordGenParameter gen = param as GC.TexCoordGenParameter;
if (gen.TexGenSrc == GC.GCTexGenSrc.Normal)
MaterialBuffer.EnvironmentMap = true;
else MaterialBuffer.EnvironmentMap = false;
}
else if (param.type == GC.ParameterType.BlendAlpha)
else if (param.Type == GC.ParameterType.BlendAlpha)
{
GC.BlendAlphaParameter blend = param as GC.BlendAlphaParameter;
MaterialBuffer.SourceAlpha = blend.NJSourceAlpha;
MaterialBuffer.DestinationAlpha = blend.NJDestAlpha;
}
}

List<GC.IOVtx> gcPositions = gcAttach.vertexData.Find(x => x.attribute == GC.GCVertexAttribute.Position)?.data;
List<GC.IOVtx> gcNormals = gcAttach.vertexData.Find(x => x.attribute == GC.GCVertexAttribute.Normal)?.data;
List<GC.IOVtx> gcColors = gcAttach.vertexData.Find(x => x.attribute == GC.GCVertexAttribute.Color0)?.data;
List<GC.IOVtx> gcUVs = gcAttach.vertexData.Find(x => x.attribute == GC.GCVertexAttribute.Tex0)?.data;
List<GC.IOVtx> gcPositions = gcAttach.VertexData.Find(x => x.Attribute == GC.GCVertexAttribute.Position)?.Data;
List<GC.IOVtx> gcNormals = gcAttach.VertexData.Find(x => x.Attribute == GC.GCVertexAttribute.Normal)?.Data;
List<GC.IOVtx> gcColors = gcAttach.VertexData.Find(x => x.Attribute == GC.GCVertexAttribute.Color0)?.Data;
List<GC.IOVtx> gcUVs = gcAttach.VertexData.Find(x => x.Attribute == GC.GCVertexAttribute.Tex0)?.Data;

foreach (GC.GCPrimitive prim in m.primitives)
foreach (GC.GCPrimitive prim in m.Primitives)
{
for (int i = 0; i < prim.ToTriangles().Count; i += 3)
{
Expand All @@ -559,11 +559,11 @@ private static Assimp.Mesh ExportGCMesh(GC.GCAttach gcAttach, GC.GCMesh m, Scene
for (int j = 0; j < 3; j++)
{
GC.Vector3 vertex = (GC.Vector3)gcPositions[prim.ToTriangles()[i + j].PositionIndex];
positions.Add(new Vector3D(vertex.x, vertex.y, vertex.z));
positions.Add(new Vector3D(vertex.X, vertex.Y, vertex.Z));
if (gcNormals != null)
{
GC.Vector3 normal = (GC.Vector3)gcNormals[prim.ToTriangles()[i + j].NormalIndex];
normals.Add(new Vector3D(normal.x, normal.y, normal.z));
normals.Add(new Vector3D(normal.X, normal.Y, normal.Z));
}
if (gcUVs != null)
{
Expand Down Expand Up @@ -1492,7 +1492,7 @@ private static GC.GCAttach AssimpImportGC(List<Material> materials, List<Assimp.
vert.Color0Index = (ushort)(colorStartIndex + grp.Indices[j]);
else if (m.HasNormals)
vert.NormalIndex = (ushort)(normStartIndex + grp.Indices[j]);
prim.loops.Add(vert);
prim.Loops.Add(vert);
}
primitives.Add(prim);
}
Expand All @@ -1509,30 +1509,30 @@ private static GC.GCAttach AssimpImportGC(List<Material> materials, List<Assimp.

//VertexAttribute stuff
GC.GCVertexSet vtxPositions = new GC.GCVertexSet(GC.GCVertexAttribute.Position);
vtxPositions.data.AddRange(gcvertices);
attach.vertexData.Add(vtxPositions);
vtxPositions.Data.AddRange(gcvertices);
attach.VertexData.Add(vtxPositions);

if (texcoords.Count > 0)
{
GC.GCVertexSet vtxUV = new GC.GCVertexSet(GC.GCVertexAttribute.Tex0);
vtxUV.data.AddRange(texcoords);
attach.vertexData.Add(vtxUV);
vtxUV.Data.AddRange(texcoords);
attach.VertexData.Add(vtxUV);
}

if (colors.Count > 0)
{
GC.GCVertexSet vtxColors = new GC.GCVertexSet(GC.GCVertexAttribute.Color0);
vtxColors.data.AddRange(colors);
attach.vertexData.Add(vtxColors);
vtxColors.Data.AddRange(colors);
attach.VertexData.Add(vtxColors);
}
else
{
GC.GCVertexSet vtxNormals = new GC.GCVertexSet(GC.GCVertexAttribute.Normal);
vtxNormals.data.AddRange(gcnormals);
attach.vertexData.Add(vtxNormals);
vtxNormals.Data.AddRange(gcnormals);
attach.VertexData.Add(vtxNormals);
}

attach.opaqueMeshes.AddRange(gcmeshes);
attach.OpaqueMeshes.AddRange(gcmeshes);
return attach;
}
#endregion
Expand Down
Loading

0 comments on commit 090495c

Please sign in to comment.