Skip to content

Commit

Permalink
Switched over a lot more stuff over to readonly.
Browse files Browse the repository at this point in the history
  • Loading branch information
MeltyPlayer committed Apr 26, 2024
1 parent a40041e commit 66b83ad
Show file tree
Hide file tree
Showing 32 changed files with 96 additions and 90 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,29 @@
namespace fin.ui.rendering.gl.material {
public class GlColorMaterialShader(
IReadOnlyModel model,
IColorMaterial colorMaterial,
IReadOnlyColorMaterial colorMaterial,
IBoneTransformManager? boneTransformManager,
IReadOnlyLighting? lighting)
: BGlMaterialShader<IColorMaterial>(model,
: BGlMaterialShader<IReadOnlyColorMaterial>(model,
colorMaterial,
boneTransformManager,
lighting) {
private readonly IColorMaterial material_ = colorMaterial;
private IShaderUniform<Vector4> diffuseLightColorUniform_;

protected override void DisposeInternal() { }

protected override void Setup(IColorMaterial material,
protected override void Setup(IReadOnlyColorMaterial material,
GlShaderProgram shaderProgram) {
this.diffuseLightColorUniform_ =
shaderProgram.GetUniformVec4("diffuseColor");
}

protected override void PassUniformsAndBindTextures(GlShaderProgram impl) {
this.diffuseLightColorUniform_.SetAndMaybeMarkDirty(
new Vector4(this.material_.Color.R / 255f,
this.material_.Color.G / 255f,
this.material_.Color.B / 255f,
this.material_.Color.A / 255f));
new Vector4(colorMaterial.Color.R / 255f,
colorMaterial.Color.G / 255f,
colorMaterial.Color.B / 255f,
colorMaterial.Color.A / 255f));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,19 @@ public static IGlMaterialShader FromMaterial(
=> material.GetShaderType() switch {
FinShaderType.FIXED_FUNCTION => new GlFixedFunctionMaterialShader(
model,
Asserts.AsA<IFixedFunctionMaterial>(material),
Asserts.AsA<IReadOnlyFixedFunctionMaterial>(material),
boneTransformManager,
lighting),
FinShaderType.TEXTURE => new GlTextureMaterialShader(model,
Asserts.AsA<ITextureMaterial>(material),
Asserts.AsA<IReadOnlyTextureMaterial>(material),
boneTransformManager,
lighting),
FinShaderType.COLOR => new GlColorMaterialShader(model,
Asserts.AsA<IColorMaterial>(material),
Asserts.AsA<IReadOnlyColorMaterial>(material),
boneTransformManager,
lighting),
FinShaderType.STANDARD => new GlStandardMaterialShader(model,
Asserts.AsA<IStandardMaterial>(material),
Asserts.AsA<IReadOnlyStandardMaterial>(material),
boneTransformManager,
lighting),
FinShaderType.NULL => new GlNullMaterialShader(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@
namespace fin.ui.rendering.gl.material {
public class GlStandardMaterialShader(
IReadOnlyModel model,
IStandardMaterial standardMaterial,
IReadOnlyStandardMaterial standardMaterial,
IBoneTransformManager? boneTransformManager,
IReadOnlyLighting? lighting)
: BGlMaterialShader<IStandardMaterial>(model,
standardMaterial,
boneTransformManager,
lighting) {
: BGlMaterialShader<IReadOnlyStandardMaterial>(model,
standardMaterial,
boneTransformManager,
lighting) {
protected override void DisposeInternal() { }

protected override void Setup(IStandardMaterial material,
protected override void Setup(IReadOnlyStandardMaterial material,
GlShaderProgram shaderProgram) {
var diffuseFinTexture = material.DiffuseTexture;
var diffuseGlTexture =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
namespace fin.ui.rendering.gl.model {
public interface ISkeletonRenderer : IRenderable {
ISkeleton Skeleton { get; }
IBone? SelectedBone { get; set; }
IReadOnlyBone? SelectedBone { get; set; }
float Scale { get; set; }
}

Expand All @@ -28,7 +28,7 @@ public SkeletonRenderer(ISkeleton skeleton,
}

public ISkeleton Skeleton { get; }
public IBone? SelectedBone { get; set; }
public IReadOnlyBone? SelectedBone { get; set; }
public float Scale { get; set; } = 1;

public void Render() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace fin.ui.rendering.gl.model {
public class UseLightingDetector {
public bool ShouldUseLightingFor(IModel model) {
public bool ShouldUseLightingFor(IReadOnlyModel model) {
var useLighting = false;
foreach (var vertex in model.Skin.Vertices) {
if (vertex is IReadOnlyNormalVertex { LocalNormal: { } }) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class SceneModelRenderer : IRenderable, IDisposable {
private readonly ISceneModel sceneModel_;
private readonly IModelRenderer modelRenderer_;

private readonly ListDictionary<IBone, SceneModelRenderer>
private readonly ListDictionary<IReadOnlyBone, SceneModelRenderer>
children_ = new();

public SceneModelRenderer(ISceneModel sceneModel,
Expand Down
3 changes: 2 additions & 1 deletion FinModelUtility/Fin/Fin/src/model/ModelInterfaces.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ public partial interface IModel {
IAnimationManager AnimationManager { get; }
}

public interface IModel<out TSkin> : IModel where TSkin : ISkin {
[GenerateReadOnly]
public partial interface IModel<out TSkin> : IModel where TSkin : ISkin {
new TSkin Skin { get; }
}
}
4 changes: 3 additions & 1 deletion FinModelUtility/Fin/Fin/src/model/SkinInterfaces.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ IBoneWeights CreateBoneWeights(
params IBoneWeight[] weights);
}

public interface ISkin<out TVertex> : ISkin where TVertex : IReadOnlyVertex {
[GenerateReadOnly]
public partial interface ISkin<out TVertex> : ISkin
where TVertex : IReadOnlyVertex {
IReadOnlyList<TVertex> TypedVertices { get; }

TVertex AddVertex(Position position);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@

namespace fin.model.util {
public class ModelMinMaxBoundsScaleCalculator
: BMinMaxBoundsScaleCalculator<IModel> {
: BMinMaxBoundsScaleCalculator<IReadOnlyModel> {
private readonly BoneTransformManager boneTransformManager_ = new();

public override Bounds CalculateBounds(IModel model) {
public override Bounds CalculateBounds(IReadOnlyModel model) {
var minX = float.MaxValue;
var minY = float.MaxValue;
var minZ = float.MaxValue;
Expand All @@ -29,7 +29,7 @@ public override Bounds CalculateBounds(IModel model) {
return new Bounds(minX, minY, minZ, maxX, maxY, maxZ);
}

public Bounds CalculateBounds(IEnumerable<IModel> models) {
public Bounds CalculateBounds(IEnumerable<IReadOnlyModel> models) {
var minX = float.MaxValue;
var minY = float.MaxValue;
var minZ = float.MaxValue;
Expand All @@ -50,7 +50,7 @@ public Bounds CalculateBounds(IEnumerable<IModel> models) {
return new Bounds(minX, minY, minZ, maxX, maxY, maxZ);
}

private void FactorModelIntoBounds_(IModel model,
private void FactorModelIntoBounds_(IReadOnlyModel model,
ref float minX,
ref float minY,
ref float minZ,
Expand Down
8 changes: 4 additions & 4 deletions FinModelUtility/Fin/Fin/src/scene/SceneInterfaces.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,14 @@ ISceneObject SetRotationDegrees(float xDegrees,
/// onto bones.
/// </summary>
public interface ISceneModel : IDisposable {
IReadOnlyListDictionary<IBone, ISceneModel> Children { get; }
ISceneModel AddModelOntoBone(IModel model, IBone bone);
IReadOnlyListDictionary<IReadOnlyBone, ISceneModel> Children { get; }
ISceneModel AddModelOntoBone(IReadOnlyModel model, IReadOnlyBone bone);

IModel Model { get; }
IReadOnlyModel Model { get; }

IBoneTransformManager BoneTransformManager { get; }

IModelAnimation? Animation { get; set; }
IReadOnlyModelAnimation? Animation { get; set; }
IAnimationPlaybackManager AnimationPlaybackManager { get; }

float ViewerScale { get; set; }
Expand Down
19 changes: 11 additions & 8 deletions FinModelUtility/Fin/Fin/src/scene/impl/SceneModelImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,19 @@
namespace fin.scene {
public partial class SceneImpl {
private class SceneModelImpl : ISceneModel {
private readonly ListDictionary<IBone, ISceneModel> children_ = new();
private IModelAnimation? animation_;
private readonly ListDictionary<IReadOnlyBone, ISceneModel> children_ = new();
private IReadOnlyModelAnimation? animation_;

public SceneModelImpl(IModel model) {
public SceneModelImpl(IReadOnlyModel model) {
this.Model = model;
this.BoneTransformManager = new BoneTransformManager();

this.Init_();
}

private SceneModelImpl(IModel model, SceneModelImpl parent, IBone bone) {
private SceneModelImpl(IReadOnlyModel model,
SceneModelImpl parent,
IReadOnlyBone bone) {
this.Model = model;
this.BoneTransformManager =
new BoneTransformManager((parent.BoneTransformManager, bone));
Expand Down Expand Up @@ -54,20 +56,21 @@ private void ReleaseUnmanagedResources_() {
}
}

public IReadOnlyListDictionary<IBone, ISceneModel> Children
public IReadOnlyListDictionary<IReadOnlyBone, ISceneModel> Children
=> this.children_;

public ISceneModel AddModelOntoBone(IModel model, IBone bone) {
public ISceneModel AddModelOntoBone(IReadOnlyModel model,
IReadOnlyBone bone) {
var child = new SceneModelImpl(model, this, bone);
this.children_.Add(bone, child);
return child;
}

public IModel Model { get; }
public IReadOnlyModel Model { get; }

public IBoneTransformManager BoneTransformManager { get; }

public IModelAnimation? Animation {
public IReadOnlyModelAnimation? Animation {
get => this.animation_;
set {
if (this.animation_ == value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public interface ISceneViewerPanel {

ISceneModel? FirstSceneModel { get; }
IAnimationPlaybackManager? AnimationPlaybackManager { get; }
IModelAnimation? Animation { get; set; }
IReadOnlyModelAnimation? Animation { get; set; }
ISkeletonRenderer? SkeletonRenderer { get; }

TimeSpan FrameTime { get; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public ISkeletonRenderer? SkeletonRenderer
?.ModelRenderers.FirstOrDefault()
?.SkeletonRenderer;

public IModelAnimation? Animation {
public IReadOnlyModelAnimation? Animation {
get => this.FirstSceneModel?.Animation;
set {
if (this.FirstSceneModel == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public IAnimationPlaybackManager? AnimationPlaybackManager

public ISkeletonRenderer? SkeletonRenderer => this.impl_.SkeletonRenderer;

public IModelAnimation? Animation {
public IReadOnlyModelAnimation? Animation {
get => this.impl_.Animation;
set => this.impl_.Animation = value;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public ModelTabs() {
InitializeComponent();
}

public (IFileBundle, IModel)? Model {
public (IFileBundle, IReadOnlyModel)? Model {
set {
var modelFileBundle = value?.Item1;
var model = value?.Item2;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace uni.ui.winforms.right_panel {
public partial class AnimationsTab : UserControl {
private IModelAnimation[]? animations_;
private IReadOnlyModelAnimation[]? animations_;

public AnimationsTab() {
InitializeComponent();
Expand All @@ -22,7 +22,7 @@ public AnimationsTab() {
};
}

public IModel? Model {
public IReadOnlyModel? Model {
set {
this.listView_.SelectedIndices.Clear();
this.listView_.Items.Clear();
Expand Down Expand Up @@ -51,7 +51,7 @@ public IAnimationPlaybackManager? AnimationPlaybackManager {
set => this.animationPlaybackPanel_.Impl = value;
}

public delegate void AnimationSelected(IModelAnimation? animation);
public delegate void AnimationSelected(IReadOnlyModelAnimation? animation);

public event AnimationSelected OnAnimationSelected;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

namespace uni.ui.winforms.right_panel.materials {
public interface IMaterialViewerPanel {
public IMaterial? Material { get; set; }
public IReadOnlyMaterial? Material { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

namespace uni.ui.winforms.right_panel.materials {
public partial class MaterialSelector : UserControl {
private IReadOnlyList<IMaterial>? materials_;
private IMaterial? selectedMaterial_ = null;
private IReadOnlyList<IReadOnlyMaterial>? materials_;
private IReadOnlyMaterial? selectedMaterial_ = null;

public MaterialSelector() {
InitializeComponent();
Expand All @@ -20,7 +20,7 @@ public MaterialSelector() {
};
}

public IReadOnlyList<IMaterial>? Materials {
public IReadOnlyList<IReadOnlyMaterial>? Materials {
get => this.materials_;
set {
this.materials_ = value;
Expand All @@ -41,7 +41,7 @@ public IReadOnlyList<IMaterial>? Materials {
}
}

public IMaterial? SelectedMaterial {
public IReadOnlyMaterial? SelectedMaterial {
get => this.selectedMaterial_;
set {
if (this.selectedMaterial_ == value || this.materials_ == null) {
Expand All @@ -58,7 +58,7 @@ public IMaterial? SelectedMaterial {
}
}

public delegate void OnMaterialSelectedHandler(IMaterial? material);
public delegate void OnMaterialSelectedHandler(IReadOnlyMaterial? material);

public event OnMaterialSelectedHandler OnMaterialSelected = delegate { };
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@

namespace uni.ui.winforms.right_panel.materials {
public class MaterialViewerGlPanel : BGlPanel, IMaterialViewerPanel {
private IMaterial? material_;
private IReadOnlyMaterial? material_;
private IGlMaterialShader? materialShader_;

public IMaterial? Material {
public IReadOnlyMaterial? Material {
get => this.material_;
set {
this.material_ = value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public MaterialViewerPanel() {
this.InitializeComponent();
}

public IMaterial? Material {
public IReadOnlyMaterial? Material {
get => this.impl_.Material;
set {
this.groupBox_.Text = value == null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace uni.ui.winforms.right_panel.materials {
public partial class MaterialsTab : UserControl {
private IModel? model_;
private IReadOnlyModel? model_;

public MaterialsTab() {
InitializeComponent();
Expand All @@ -17,7 +17,7 @@ public MaterialsTab() {
};
}

public (IModel, IReadOnlyList<IMaterial>)? ModelAndMaterials {
public (IReadOnlyModel, IReadOnlyList<IReadOnlyMaterial>)? ModelAndMaterials {
set {
this.model_ = value?.Item1;
this.materialSelector_.Materials = value?.Item2;
Expand Down
Loading

0 comments on commit 66b83ad

Please sign in to comment.