Skip to content

Commit 0d1bd9f

Browse files
authored
Merge pull request #477 from Csantucci/3D-cab-solid-bar-and-digital-fix
Bug fix for https://bugs.launchpad.net/or/+bug/1943302 3D cab bugs in bars and digitals
2 parents 34d7710 + 4aa0367 commit 0d1bd9f

File tree

3 files changed

+23
-11
lines changed

3 files changed

+23
-11
lines changed

Source/RunActivity/Viewer3D/Materials.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1207,7 +1207,7 @@ public override void Render(GraphicsDevice graphicsDevice, IEnumerable<RenderIte
12071207

12081208
public class SolidColorMaterial : Material
12091209
{
1210-
static BasicEffect basicEffect;
1210+
BasicEffect basicEffect;
12111211

12121212
public SolidColorMaterial(Viewer viewer, float a, float r, float g, float b)
12131213
: base(viewer, null)

Source/RunActivity/Viewer3D/RollingStock/MSTSLocomotiveViewer.cs

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2986,7 +2986,7 @@ public ThreeDimCabDigit(Viewer viewer, int iMatrix, string size, string aceFile,
29862986

29872987
//create the shape primitive
29882988
shapePrimitive = new MutableShapePrimitive(Material, NumVertices, NumIndices, new[] { -1 }, 0);
2989-
UpdateShapePrimitive();
2989+
UpdateShapePrimitive(Material);
29902990

29912991
}
29922992

@@ -3085,11 +3085,11 @@ public void UpdateDigit()
30853085
}
30863086

30873087
//update the shape primitive
3088-
UpdateShapePrimitive();
3088+
UpdateShapePrimitive(UsedMaterial);
30893089

30903090
}
30913091

3092-
private void UpdateShapePrimitive()
3092+
private void UpdateShapePrimitive(Material material)
30933093
{
30943094
var indexData = new short[NumIndices];
30953095
Array.Copy(TriangleListIndices, indexData, NumIndices);
@@ -3098,6 +3098,8 @@ private void UpdateShapePrimitive()
30983098
var vertexData = new VertexPositionNormalTexture[NumVertices];
30993099
Array.Copy(VertexList, vertexData, NumVertices);
31003100
shapePrimitive.SetVertexData(vertexData, 0, NumVertices, NumIndices / 3);
3101+
3102+
shapePrimitive.SetMaterial(material);
31013103
}
31023104

31033105
//ACE MAP:
@@ -3216,8 +3218,9 @@ public ThreeDimCabGaugeNative(Viewer viewer, int iMatrix, string size, string le
32163218

32173219

32183220
//create the shape primitive
3219-
shapePrimitive = new MutableShapePrimitive(FindMaterial(), NumVertices, NumIndices, new[] { -1 }, 0);
3220-
UpdateShapePrimitive();
3221+
var material = FindMaterial();
3222+
shapePrimitive = new MutableShapePrimitive(material, NumVertices, NumIndices, new[] { -1 }, 0);
3223+
UpdateShapePrimitive(material);
32213224

32223225
}
32233226

@@ -3229,13 +3232,14 @@ Material FindMaterial()
32293232
{
32303233
if (PositiveMaterial == null)
32313234
{
3232-
PositiveMaterial = new SolidColorMaterial(this.Viewer, 0f, c.R, c.G, c.B);
3235+
PositiveMaterial = new SolidColorMaterial(this.Viewer, c.A, c.R, c.G, c.B);
32333236
}
32343237
return PositiveMaterial;
32353238
}
32363239
else
32373240
{
3238-
if (NegativeMaterial == null) NegativeMaterial = new SolidColorMaterial(this.Viewer, c.A, c.R, c.G, c.B);
3241+
if (NegativeMaterial == null)
3242+
NegativeMaterial = new SolidColorMaterial(this.Viewer, c.A, c.R, c.G, c.B);
32393243
return NegativeMaterial;
32403244
}
32413245
}
@@ -3298,7 +3302,7 @@ public void UpdateDigit()
32983302
NumVertices += 4;
32993303

33003304
//update the shape primitive
3301-
UpdateShapePrimitive();
3305+
UpdateShapePrimitive(UsedMaterial);
33023306

33033307
}
33043308

@@ -3330,7 +3334,7 @@ static float GetTextureCoordY(char c)
33303334
return 1.0f;
33313335
}
33323336

3333-
private void UpdateShapePrimitive()
3337+
private void UpdateShapePrimitive(Material material)
33343338
{
33353339
var indexData = new short[NumIndices];
33363340
Array.Copy(TriangleListIndices, indexData, NumIndices);
@@ -3339,6 +3343,8 @@ private void UpdateShapePrimitive()
33393343
var vertexData = new VertexPositionNormalTexture[NumVertices];
33403344
Array.Copy(VertexList, vertexData, NumVertices);
33413345
shapePrimitive.SetVertexData(vertexData, 0, NumVertices, NumIndices / 3);
3346+
3347+
shapePrimitive.SetMaterial(material);
33423348
}
33433349

33443350
public void PrepareFrame(RenderFrame frame, ElapsedTime elapsedTime)

Source/RunActivity/Viewer3D/Shapes.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1392,7 +1392,8 @@ public virtual void Mark()
13921392
}
13931393

13941394
/// <summary>
1395-
/// A <c>ShapePrimitive</c> that permits manipulation of the vertex and index buffers to change geometry efficiently.
1395+
/// A <c>ShapePrimitive</c> that permits manipulation of vertex and index buffers to change geometry efficiently.
1396+
/// It permits also change of material
13961397
/// </summary>
13971398
public class MutableShapePrimitive : ShapePrimitive
13981399
{
@@ -1418,6 +1419,11 @@ public void SetIndexData(short[] data)
14181419
{
14191420
IndexBuffer.SetData(data);
14201421
}
1422+
1423+
public void SetMaterial(Material material)
1424+
{
1425+
Material = material;
1426+
}
14211427
}
14221428

14231429
struct ShapeInstanceData

0 commit comments

Comments
 (0)