Skip to content

Commit

Permalink
Merge pull request #100 from MilchRatchet/dev-branch
Browse files Browse the repository at this point in the history
Small bugfixes for the model viewer.
  • Loading branch information
MilchRatchet authored Feb 18, 2024
2 parents 2838712 + 35018c3 commit 0ce4d7f
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 28 deletions.
2 changes: 1 addition & 1 deletion LibReplanetizer/Models/Model.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public int vertexCount
}

[Category("Attributes"), DisplayName("Face Count")]
public int faceCount
public virtual int faceCount
{
get
{
Expand Down
12 changes: 10 additions & 2 deletions LibReplanetizer/Models/TerrainModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,15 @@ public class TerrainModel : Model
private static short STATIC_ID = 0;

public List<int> lights = new List<int>();
int faceCount;

private int _faceCount;
public override int faceCount
{
get
{
return _faceCount;
}
}
public TerrainModel(FileStream fs, TerrainHead head, byte[] tfragBlock, int num)
{
id = GetIDAssigned();
Expand All @@ -36,7 +44,7 @@ public TerrainModel(FileStream fs, TerrainHead head, byte[] tfragBlock, int num)
int faceStart = ReadInt(ReadBlock(fs, texturePointer + 4, 4), 0);

textureConfig = GetTextureConfigs(fs, texturePointer, textureCount, 0x10, true);
faceCount = GetFaceCount();
_faceCount = GetFaceCount();

vertexBuffer = GetVertices(fs, head.vertexPointers[slotNum] + vertexIndex * 0x1C, head.uvPointers[slotNum] + vertexIndex * 0x08, vertexCount, 0x1C, 0x08);
indexBuffer = GetIndices(fs, head.indexPointers[slotNum] + faceStart * 2, faceCount, vertexIndex);
Expand Down
52 changes: 27 additions & 25 deletions Replanetizer/Frames/ModelFrame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ private void RenderTree()
for (int i = 0; i < level.armorModels.Count; i++)
{
Model armor = level.armorModels[i];
RenderModelEntry(armor, level.armorTextures[i], GetDisplayName(armor));
RenderModelEntry(armor, level.armorTextures[i], "Armor " + i);
}
ImGui.TreePop();
}
Expand Down Expand Up @@ -566,37 +566,39 @@ private void UpdateTextures()
}
}

private bool PrepareForArrowInputList(List<Model> models, List<Texture>? textures = null, List<List<Texture>>? textureSet = null)
{
var idx = models.FindIndex(m => ReferenceEquals(m, selectedModel));
if (idx == -1) return false;

selectedModelIndex = idx;
selectedModelList = models;

// This is a little weird because armorTextures is a list
// of a list of textures -- one list per armor set.
selectedModelTexturesSet = textures;
selectedModelArmorTexturesSet = textureSet;

return true;
}

/// <summary>
/// Use selectedModel to prepare selectedModelIndex and
/// selectedModelList for using arrows to navigate through models.
/// </summary>
private void PrepareForArrowInput()
{
List<Model>[] modelLists = {
sortedMobyModels, sortedTieModels, sortedShrubModels,
sortedGadgetModels, level.armorModels
};
foreach (var models in modelLists)
{
var idx = models.FindIndex(m => ReferenceEquals(m, selectedModel));
if (idx == -1) continue;

selectedModelIndex = idx;
selectedModelList = models;

// This is a little weird because armorTextures is a list
// of a list of textures -- one list per armor set.
selectedModelTexturesSet = null;
selectedModelArmorTexturesSet = null;
if (ReferenceEquals(models, sortedGadgetModels))
selectedModelTexturesSet = (level.game == GameType.RaC1) ? level.textures : level.gadgetTextures;
else if (ReferenceEquals(models, level.armorModels))
selectedModelArmorTexturesSet = level.armorTextures;
else
selectedModelTexturesSet = level.textures;
if (PrepareForArrowInputList(sortedMobyModels, level.textures)) return;
if (PrepareForArrowInputList(sortedTieModels, level.textures)) return;
if (PrepareForArrowInputList(sortedShrubModels, level.textures)) return;
if (PrepareForArrowInputList(sortedGadgetModels, (level.game == GameType.RaC1) ? level.textures : level.gadgetTextures)) return;
if (PrepareForArrowInputList(level.armorModels, null, level.armorTextures)) return;

return;
}
for (int i = 0; i < sortedMissionModels.Count; i++)
if (PrepareForArrowInputList(sortedMissionModels[i], level.missions[i].textures)) return;

for (int i = 0; i < sortedMobyloadModels.Count; i++)
if (PrepareForArrowInputList(sortedMobyloadModels[i], level.mobyloadTextures[i])) return;
}

private void SelectModel(Model? model)
Expand Down

0 comments on commit 0ce4d7f

Please sign in to comment.