Permalink
Browse files

Decal rendering #3: Update decal geometry

  • Loading branch information...
LogicAndTrick committed Feb 8, 2013
1 parent 1041ba5 commit 35c3b0d513d975d2507fac6144d94523964b79d6
@@ -163,17 +163,26 @@ public void CalculateDecalGeometry()
// Re-project the vertices in case the texture axes are not on the face plane
var xShift = face.Texture.UAxis * face.Texture.XScale * Decal.Width / 2;
var yShift = face.Texture.VAxis * face.Texture.YScale * Decal.Height / 2;
decalFace.Vertices.Add(new Vertex(face.Plane.Project(center + xShift - yShift), decalFace)); // Bottom Right
decalFace.Vertices.Add(new Vertex(face.Plane.Project(center + xShift + yShift), decalFace)); // Top Right
decalFace.Vertices.Add(new Vertex(face.Plane.Project(center - xShift + yShift), decalFace)); // Top Left
decalFace.Vertices.Add(new Vertex(face.Plane.Project(center - xShift - yShift), decalFace)); // Bottom Left
var verts = new[]
{
new Vertex(face.Plane.Project(center + xShift - yShift), decalFace), // Bottom Right
new Vertex(face.Plane.Project(center + xShift + yShift), decalFace), // Top Right
new Vertex(face.Plane.Project(center - xShift + yShift), decalFace), // Top Left
new Vertex(face.Plane.Project(center - xShift - yShift), decalFace), // Bottom Left
};
// TODO normalise these properly - the texture is reversed when it shouldn't be
if (!face.Plane.Normal.EquivalentTo(face.Texture.UAxis.Cross(face.Texture.VAxis))) decalFace.Vertices.AddRange(verts);
else decalFace.Vertices.AddRange(verts.Reverse());
decalFace.UpdateBoundingBox();
// TODO: verify this covers all situations and I don't have to manually calculate the texture coordinates
decalFace.FitTextureToPointCloud(new Cloud(decalFace.Vertices.Select(x => x.Location)));
// Next, the decal geometry needs to be clipped to the face so it doesn't spill into the void
// Create a fake solid out of the decal geometry and clip it against all the brush planes
var fake = CreateFakeDecalSolid(decalFace);
foreach (var f in face.Parent.Faces.Except(new[] { face }))
{
Solid back, front;
@@ -356,7 +356,8 @@ public bool IntersectsWithLine(Box box)
/// <returns>True if the box intersects</returns>
public bool IntersectsWithBox(Box box)
{
return box.GetBoxLines().Any(x => GetIntersectionPoint(x) != null);
var verts = Vertices.Select(x => x.Location).ToList();
return box.GetBoxLines().Any(x => GetIntersectionPoint(verts, x, true) != null);
}
/// <summary>
@@ -390,10 +391,10 @@ public enum FacePlaneClassification
Spanning
}
protected static Coordinate GetIntersectionPoint(IList<Coordinate> coordinates, Line line)
protected static Coordinate GetIntersectionPoint(IList<Coordinate> coordinates, Line line, bool ignoreDirection = false)
{
var plane = new Plane(coordinates[0], coordinates[1], coordinates[2]);
var intersect = plane.GetIntersectionPoint(line);
var intersect = plane.GetIntersectionPoint(line, ignoreDirection);
if (intersect == null) return null;
// http://paulbourke.net/geometry/insidepoly/
@@ -76,7 +76,8 @@ public void PostLoadProcess(GameData.GameData gameData, Func<string, ITexture> t
public void PartialPostLoadProcess(GameData.GameData gameData, Func<string, ITexture> textureAccessor)
{
PartialPostLoadProcess(x => (x is Entity && ((Entity)x ).GameData == null) || (x is Solid && ((Solid) x).Faces.Any(y => y.Texture.Texture == null)), gameData, textureAccessor);
PartialPostLoadProcess(x => (x is Entity && (((Entity)x ).GameData == null || ((Entity)x).Decal != null))
|| (x is Solid && ((Solid) x).Faces.Any(y => y.Texture.Texture == null)), gameData, textureAccessor);
}
public void PartialPostLoadProcess(Predicate<MapObject> matcher, GameData.GameData gameData, Func<string, ITexture> textureAccessor)
@@ -252,11 +252,13 @@ public void Update()
public void UpdatePartial(IEnumerable<MapObject> objects)
{
_array.UpdatePartial(objects);
_array.UpdateDecals(_document.Map);
}
public void UpdatePartial(IEnumerable<Face> faces)
{
_array.UpdatePartial(faces);
_array.UpdateDecals(_document.Map);
}
public void Register(IEnumerable<ViewportBase> viewports)

0 comments on commit 35c3b0d

Please sign in to comment.