Skip to content
This repository was archived by the owner on Sep 16, 2019. It is now read-only.

Commit 35c3b0d

Browse files
committed
Decal rendering #3: Update decal geometry
1 parent 1041ba5 commit 35c3b0d

4 files changed

Lines changed: 22 additions & 9 deletions

File tree

‎Sledge.DataStructures/MapObjects/Entity.cs‎

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -163,17 +163,26 @@ public void CalculateDecalGeometry()
163163
// Re-project the vertices in case the texture axes are not on the face plane
164164
var xShift = face.Texture.UAxis * face.Texture.XScale * Decal.Width / 2;
165165
var yShift = face.Texture.VAxis * face.Texture.YScale * Decal.Height / 2;
166-
decalFace.Vertices.Add(new Vertex(face.Plane.Project(center + xShift - yShift), decalFace)); // Bottom Right
167-
decalFace.Vertices.Add(new Vertex(face.Plane.Project(center + xShift + yShift), decalFace)); // Top Right
168-
decalFace.Vertices.Add(new Vertex(face.Plane.Project(center - xShift + yShift), decalFace)); // Top Left
169-
decalFace.Vertices.Add(new Vertex(face.Plane.Project(center - xShift - yShift), decalFace)); // Bottom Left
166+
var verts = new[]
167+
{
168+
new Vertex(face.Plane.Project(center + xShift - yShift), decalFace), // Bottom Right
169+
new Vertex(face.Plane.Project(center + xShift + yShift), decalFace), // Top Right
170+
new Vertex(face.Plane.Project(center - xShift + yShift), decalFace), // Top Left
171+
new Vertex(face.Plane.Project(center - xShift - yShift), decalFace), // Bottom Left
172+
};
173+
174+
// TODO normalise these properly - the texture is reversed when it shouldn't be
175+
if (!face.Plane.Normal.EquivalentTo(face.Texture.UAxis.Cross(face.Texture.VAxis))) decalFace.Vertices.AddRange(verts);
176+
else decalFace.Vertices.AddRange(verts.Reverse());
177+
170178
decalFace.UpdateBoundingBox();
171179
// TODO: verify this covers all situations and I don't have to manually calculate the texture coordinates
172180
decalFace.FitTextureToPointCloud(new Cloud(decalFace.Vertices.Select(x => x.Location)));
173-
181+
174182
// Next, the decal geometry needs to be clipped to the face so it doesn't spill into the void
175183
// Create a fake solid out of the decal geometry and clip it against all the brush planes
176184
var fake = CreateFakeDecalSolid(decalFace);
185+
177186
foreach (var f in face.Parent.Faces.Except(new[] { face }))
178187
{
179188
Solid back, front;

‎Sledge.DataStructures/MapObjects/Face.cs‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,8 @@ public bool IntersectsWithLine(Box box)
356356
/// <returns>True if the box intersects</returns>
357357
public bool IntersectsWithBox(Box box)
358358
{
359-
return box.GetBoxLines().Any(x => GetIntersectionPoint(x) != null);
359+
var verts = Vertices.Select(x => x.Location).ToList();
360+
return box.GetBoxLines().Any(x => GetIntersectionPoint(verts, x, true) != null);
360361
}
361362

362363
/// <summary>
@@ -390,10 +391,10 @@ public enum FacePlaneClassification
390391
Spanning
391392
}
392393

393-
protected static Coordinate GetIntersectionPoint(IList<Coordinate> coordinates, Line line)
394+
protected static Coordinate GetIntersectionPoint(IList<Coordinate> coordinates, Line line, bool ignoreDirection = false)
394395
{
395396
var plane = new Plane(coordinates[0], coordinates[1], coordinates[2]);
396-
var intersect = plane.GetIntersectionPoint(line);
397+
var intersect = plane.GetIntersectionPoint(line, ignoreDirection);
397398
if (intersect == null) return null;
398399

399400
// http://paulbourke.net/geometry/insidepoly/

‎Sledge.DataStructures/MapObjects/Map.cs‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ public void PostLoadProcess(GameData.GameData gameData, Func<string, ITexture> t
7676

7777
public void PartialPostLoadProcess(GameData.GameData gameData, Func<string, ITexture> textureAccessor)
7878
{
79-
PartialPostLoadProcess(x => (x is Entity && ((Entity)x ).GameData == null) || (x is Solid && ((Solid) x).Faces.Any(y => y.Texture.Texture == null)), gameData, textureAccessor);
79+
PartialPostLoadProcess(x => (x is Entity && (((Entity)x ).GameData == null || ((Entity)x).Decal != null))
80+
|| (x is Solid && ((Solid) x).Faces.Any(y => y.Texture.Texture == null)), gameData, textureAccessor);
8081
}
8182

8283
public void PartialPostLoadProcess(Predicate<MapObject> matcher, GameData.GameData gameData, Func<string, ITexture> textureAccessor)

‎Sledge.Editor/Rendering/RenderManager.cs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,11 +252,13 @@ public void Update()
252252
public void UpdatePartial(IEnumerable<MapObject> objects)
253253
{
254254
_array.UpdatePartial(objects);
255+
_array.UpdateDecals(_document.Map);
255256
}
256257

257258
public void UpdatePartial(IEnumerable<Face> faces)
258259
{
259260
_array.UpdatePartial(faces);
261+
_array.UpdateDecals(_document.Map);
260262
}
261263

262264
public void Register(IEnumerable<ViewportBase> viewports)

0 commit comments

Comments
 (0)