From 1c219447e57b2722be5b517710c2e806eda4c2da Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Thu, 24 Mar 2016 18:31:28 +1100 Subject: [PATCH] Fix mirroring and thin arms on 64x64 skins. (Thanks goodlyay) --- ClassicalSharp/Model/BlockModel.cs | 5 +++-- ClassicalSharp/Model/ChibiModel.cs | 4 +++- ClassicalSharp/Model/ChickenModel.cs | 4 +++- ClassicalSharp/Model/CreeperModel.cs | 4 +++- ClassicalSharp/Model/CustomModel.cs | 5 +++-- ClassicalSharp/Model/HumanoidModel.cs | 16 +++++++++------- ClassicalSharp/Model/IModel.cs | 2 ++ ClassicalSharp/Model/ModelCache.cs | 7 +++++-- ClassicalSharp/Model/PigModel.cs | 4 +++- ClassicalSharp/Model/SheepModel.cs | 4 +++- ClassicalSharp/Model/SkeletonModel.cs | 4 +++- ClassicalSharp/Model/SpiderModel.cs | 4 +++- ClassicalSharp/Model/ZombieModel.cs | 4 +++- 13 files changed, 46 insertions(+), 21 deletions(-) diff --git a/ClassicalSharp/Model/BlockModel.cs b/ClassicalSharp/Model/BlockModel.cs index 8c368e9c2..7746b5546 100644 --- a/ClassicalSharp/Model/BlockModel.cs +++ b/ClassicalSharp/Model/BlockModel.cs @@ -14,8 +14,9 @@ namespace ClassicalSharp.Model { bool bright; Vector3 minBB, maxBB; - public BlockModel( Game game ) : base( game ) { - } + public BlockModel( Game game ) : base( game ) { } + + internal override void CreateParts() { } public override bool Bobbing { get { return false; } } diff --git a/ClassicalSharp/Model/ChibiModel.cs b/ClassicalSharp/Model/ChibiModel.cs index 27e6f0ae1..6de214236 100644 --- a/ClassicalSharp/Model/ChibiModel.cs +++ b/ClassicalSharp/Model/ChibiModel.cs @@ -6,7 +6,9 @@ namespace ClassicalSharp.Model { public class ChibiModel : IModel { - public ChibiModel( Game window ) : base( window ) { + public ChibiModel( Game window ) : base( window ) { } + + internal override void CreateParts() { vertices = new ModelVertex[boxVertices * (7 + 2)]; Head = BuildBox( MakeBoxBounds( -4, 12, -4, 4, 20, 4 ) diff --git a/ClassicalSharp/Model/ChickenModel.cs b/ClassicalSharp/Model/ChickenModel.cs index d427bd485..38cf1dd3f 100644 --- a/ClassicalSharp/Model/ChickenModel.cs +++ b/ClassicalSharp/Model/ChickenModel.cs @@ -6,7 +6,9 @@ namespace ClassicalSharp.Model { public class ChickenModel : IModel { - public ChickenModel( Game window ) : base( window ) { + public ChickenModel( Game window ) : base( window ) { } + + internal override void CreateParts() { vertices = new ModelVertex[boxVertices * 6 + quadVertices * 2 * 2]; Head = BuildBox( MakeBoxBounds( -2, 9, -6, 2, 15, -3 ) .TexOrigin( 0, 0 ) diff --git a/ClassicalSharp/Model/CreeperModel.cs b/ClassicalSharp/Model/CreeperModel.cs index 461d9bfe5..76a3451da 100644 --- a/ClassicalSharp/Model/CreeperModel.cs +++ b/ClassicalSharp/Model/CreeperModel.cs @@ -6,7 +6,9 @@ namespace ClassicalSharp.Model { public class CreeperModel : IModel { - public CreeperModel( Game window ) : base( window ) { + public CreeperModel( Game window ) : base( window ) { } + + internal override void CreateParts() { vertices = new ModelVertex[boxVertices * 6]; Head = BuildBox( MakeBoxBounds( -4, 18, -4, 4, 26, 4 ) .TexOrigin( 0, 0 ) diff --git a/ClassicalSharp/Model/CustomModel.cs b/ClassicalSharp/Model/CustomModel.cs index 1a0ac5eac..0ad23c120 100644 --- a/ClassicalSharp/Model/CustomModel.cs +++ b/ClassicalSharp/Model/CustomModel.cs @@ -6,8 +6,9 @@ namespace ClassicalSharp.Model { public class CustomModel : IModel { - public CustomModel( Game window ) : base( window ) { - } + public CustomModel( Game window ) : base( window ) { } + + internal override void CreateParts() { } internal bool bobbing; public override bool Bobbing { get { return bobbing; } } diff --git a/ClassicalSharp/Model/HumanoidModel.cs b/ClassicalSharp/Model/HumanoidModel.cs index fce85196e..dd5903057 100644 --- a/ClassicalSharp/Model/HumanoidModel.cs +++ b/ClassicalSharp/Model/HumanoidModel.cs @@ -8,7 +8,9 @@ namespace ClassicalSharp.Model { public class HumanoidModel : IModel { ModelSet Set, SetSlim, Set64; - public HumanoidModel( Game window ) : base( window ) { + public HumanoidModel( Game window ) : base( window ) { } + + internal override void CreateParts() { vertices = new ModelVertex[boxVertices * ( 7 + 11 )]; Set = new ModelSet(); @@ -21,19 +23,19 @@ namespace ClassicalSharp.Model { Set.Head = BuildBox( head.TexOrigin( 0, 0 ) ); Set.Torso = BuildBox( torso.TexOrigin( 16, 16 ) ); - Set.LeftLeg = BuildBox( lLeg.MirrorX().TexOrigin( 0, 16 ) ); + Set.LeftLeg = BuildBox( lLeg.TexOrigin( 0, 16 ) ); Set.RightLeg = BuildBox( rLeg.TexOrigin( 0, 16 ) ); Set.Hat = BuildBox( head.TexOrigin( 32, 0 ).Expand( 0.5f ) ); - Set.LeftArm = BuildBox( lArm.MirrorX().TexOrigin( 40, 16 ) ); + Set.LeftArm = BuildBox( lArm.TexOrigin( 40, 16 ) ); Set.RightArm = BuildBox( rArm.TexOrigin( 40, 16 ) ); Set64 = new ModelSet(); Set64.Head = Set.Head; Set64.Torso = Set.Torso; - Set64.LeftLeg = BuildBox( lLeg.TexOrigin( 16, 48 ) ); + Set64.LeftLeg = BuildBox( lLeg.MirrorX().TexOrigin( 16, 48 ) ); Set64.RightLeg = Set.RightLeg; Set64.Hat = Set.Hat; - Set64.LeftArm = BuildBox( lArm.TexOrigin( 32, 48 ) ); + Set64.LeftArm = BuildBox( lArm.MirrorX().TexOrigin( 32, 48 ) ); Set64.RightArm = Set.RightArm; Set64.TorsoLayer = BuildBox( torso.TexOrigin( 16, 32 ).Expand( 0.5f ) ); Set64.LeftLegLayer = BuildBox( lLeg.TexOrigin( 0, 48 ).Expand( 0.5f ) ); @@ -47,7 +49,7 @@ namespace ClassicalSharp.Model { SetSlim.LeftLeg = Set64.LeftLeg; SetSlim.RightLeg = Set.RightLeg; SetSlim.Hat = Set.Hat; - lArm.BodyW -= 1; lArm.X1 += 1/16f; + lArm.BodyW -= 1; lArm.X2 += 1/16f; SetSlim.LeftArm = BuildBox( lArm.TexOrigin( 32, 48 ) ); rArm.BodyW -= 1; rArm.X2 -= 1/16f; SetSlim.RightArm = BuildBox( rArm.TexOrigin( 40, 16 ) ); @@ -55,7 +57,7 @@ namespace ClassicalSharp.Model { SetSlim.LeftLegLayer = Set64.LeftLegLayer; SetSlim.RightLegLayer = Set64.RightLegLayer; SetSlim.LeftArmLayer = BuildBox( lArm.TexOrigin( 32, 48 ).Expand( 0.5f ) ); - SetSlim.RightArmLayer = BuildBox( rArm.TexOrigin( 40, 16 ).Expand( 0.5f ) ); + SetSlim.RightArmLayer = BuildBox( rArm.TexOrigin( 40, 32 ).Expand( 0.5f ) ); } public override bool Bobbing { get { return true; } } diff --git a/ClassicalSharp/Model/IModel.cs b/ClassicalSharp/Model/IModel.cs index af811c199..ccd8d0a02 100644 --- a/ClassicalSharp/Model/IModel.cs +++ b/ClassicalSharp/Model/IModel.cs @@ -23,6 +23,8 @@ namespace ClassicalSharp.Model { cache = game.ModelCache; } + internal abstract void CreateParts(); + /// Whether the entity should be slightly bobbed up and down when rendering. /// e.g. for players when their legs are at the peak of their swing, /// the whole model will be moved slightly down. diff --git a/ClassicalSharp/Model/ModelCache.cs b/ClassicalSharp/Model/ModelCache.cs index c80e8d854..89d24623f 100644 --- a/ClassicalSharp/Model/ModelCache.cs +++ b/ClassicalSharp/Model/ModelCache.cs @@ -17,7 +17,9 @@ namespace ClassicalSharp.Model { public void InitCache() { vertices = new VertexPos3fTex2fCol4b[24 * 12]; vb = api.CreateDynamicVb( VertexFormat.Pos3fTex2fCol4b, vertices.Length ); - cache["humanoid"] = new HumanoidModel( game ); + IModel model = new HumanoidModel( game ); + model.CreateParts(); + cache["humanoid"] = model; cache["human"] = cache["humanoid"]; } @@ -36,7 +38,8 @@ namespace ClassicalSharp.Model { if( !cache.TryGetValue( modelName, out model ) ) { model = InitModel( modelName ); - if( model == null ) model = cache["humanoid"]; // fallback to default + if( model != null ) model.CreateParts(); + else model = cache["humanoid"]; // fallback to default cache[modelName] = model; } return model; diff --git a/ClassicalSharp/Model/PigModel.cs b/ClassicalSharp/Model/PigModel.cs index da390931c..7ef741973 100644 --- a/ClassicalSharp/Model/PigModel.cs +++ b/ClassicalSharp/Model/PigModel.cs @@ -6,7 +6,9 @@ namespace ClassicalSharp.Model { public class PigModel : IModel { - public PigModel( Game window ) : base( window ) { + public PigModel( Game window ) : base( window ) { } + + internal override void CreateParts() { vertices = new ModelVertex[boxVertices * 6]; Head = BuildBox( MakeBoxBounds( -4, 8, -14, 4, 16, -6 ) .TexOrigin( 0, 0 ) diff --git a/ClassicalSharp/Model/SheepModel.cs b/ClassicalSharp/Model/SheepModel.cs index 8a0f1d3cd..174e09166 100644 --- a/ClassicalSharp/Model/SheepModel.cs +++ b/ClassicalSharp/Model/SheepModel.cs @@ -9,7 +9,9 @@ namespace ClassicalSharp.Model { public bool Fur = true; - public SheepModel( Game window ) : base( window ) { + public SheepModel( Game window ) : base( window ) { } + + internal override void CreateParts() { vertices = new ModelVertex[boxVertices * 6 * ( Fur ? 2 : 1 )]; Head = BuildBox( MakeBoxBounds( -3, 16, -14, 3, 22, -6 ) .TexOrigin( 0, 0 ) diff --git a/ClassicalSharp/Model/SkeletonModel.cs b/ClassicalSharp/Model/SkeletonModel.cs index b625dd6b2..d5f45a8f7 100644 --- a/ClassicalSharp/Model/SkeletonModel.cs +++ b/ClassicalSharp/Model/SkeletonModel.cs @@ -6,7 +6,9 @@ namespace ClassicalSharp.Model { public class SkeletonModel : IModel { - public SkeletonModel( Game window ) : base( window ) { + public SkeletonModel( Game window ) : base( window ) { } + + internal override void CreateParts() { vertices = new ModelVertex[boxVertices * 6]; Head = BuildBox( MakeBoxBounds( -4, 24, -4, 4, 32, 4 ) .TexOrigin( 0, 0 ) diff --git a/ClassicalSharp/Model/SpiderModel.cs b/ClassicalSharp/Model/SpiderModel.cs index c28c14157..b8de69432 100644 --- a/ClassicalSharp/Model/SpiderModel.cs +++ b/ClassicalSharp/Model/SpiderModel.cs @@ -6,7 +6,9 @@ namespace ClassicalSharp.Model { public class SpiderModel : IModel { - public SpiderModel( Game window ) : base( window ) { + public SpiderModel( Game window ) : base( window ) { } + + internal override void CreateParts() { vertices = new ModelVertex[boxVertices * 5]; Head = BuildBox( MakeBoxBounds( -4, 4, -11, 4, 12, -3 ) .TexOrigin( 32, 4 ) diff --git a/ClassicalSharp/Model/ZombieModel.cs b/ClassicalSharp/Model/ZombieModel.cs index 56a7b4011..67262801c 100644 --- a/ClassicalSharp/Model/ZombieModel.cs +++ b/ClassicalSharp/Model/ZombieModel.cs @@ -6,7 +6,9 @@ namespace ClassicalSharp.Model { public class ZombieModel : IModel { - public ZombieModel( Game window ) : base( window ) { + public ZombieModel( Game window ) : base( window ) { } + + internal override void CreateParts() { vertices = new ModelVertex[boxVertices * 6]; Head = BuildBox( MakeBoxBounds( -4, 24, -4, 4, 32, 4 ) .TexOrigin( 0, 0 )