|
RenderStack 11.06.1
|
Maintains connectivity and attribute information for polygon based meshes. More...
Public Member Functions | |
| Geometry () | |
| void | MergePoints () |
| void | Merge (Geometry other) |
| void | MergeFast (Geometry other, Polygon thisPolygon, Polygon otherPolygon) |
| void | RemovePolygon (Polygon polygon) |
| void | Transform (Matrix4 transform) |
| Geometry | Clone () |
| Corner | ClosestPolygonCorner (Polygon polygon, Vector3 position) |
| void | PolygonCornerEdges (Polygon polygon, Corner pivot, out Edge edgeOne, out Edge edgeTwo) |
| Geometry | CloneSelectedPolygons (HashSet< uint > selectedPolygonIndices) |
| Point | MakePoint () |
| Construct a new Point to Geometry. | |
| Polygon | MakePolygon () |
| Constructs a new Polygon. | |
| void | ComputePolygonNormals () |
| void | ComputePolygonCentroids () |
| Vector3 | ComputePointNormal (Point point) |
| void | ComputePointNormals (string mapName) |
| void | SmoothNormalize (string cornerAttribute, string polygonAttribute, float maxSmoothingAngleRadians) |
| void | SmoothAverage (string cornerAttribute, string pointNormalName) |
| Point | MakePoint (Vector3 p) |
| Point | MakePoint (float x, float y, float z) |
| Constructs a new Point and assosiates a position attribute for it. | |
| Point | MakePoint (double x, double y, double z) |
| Constructs a new Point and assosiates a position attribute for it. | |
| Point | MakePoint (double x, double y, double z, double s, double t) |
| Polygon | MakePolygon (params Point[] points) |
| Construct a new Polygon from a given set of Points. | |
| Polygon | MakePolygon (params int[] pointIndices) |
| Construct a new Polygon from a given set of Point indices. | |
| Polygon | MakePolygon (List< int > pointIndices) |
| void | CheckEdge (Edge edge) |
| void | BuildEdges () |
| Builds Edge connectivity information. | |
Static Public Member Functions | |
| static Geometry | Sqrt3 (Geometry src) |
| static CloneGeometryOperation | Clone (Geometry src, HashSet< uint > selectedPolygonIndices) |
Public Attributes | |
| Matrix4 | MakePointTransform = Matrix4.Identity |
Properties | |
| AttributeMapCollection< Point > | PointAttributes [get] |
| AttributeMapCollection< Corner > | CornerAttributes [get] |
| AttributeMapCollection< Polygon > | PolygonAttributes [get] |
| AttributeMapCollection< Edge > | EdgeAttributes [get] |
| List< Point > | Points [get] |
| List< Polygon > | Polygons [get] |
| Dictionary< Edge, HashSet < Polygon > > | Edges [get] |
| Collection of Edges and the Polygons that share each edge. | |
Connectivity is stored between Points, Corners and Polygons. Optionally Edge connectivity information can be constructed when needed. It is also possibly to construct Vertex and Index buffers suitable for use with Graphics APIs such as OpenGL.
Points, Corners, Polygons and Edges only store connectivity information. Point locations, corner normals, point and corner texture coordinates and so on are stored in attribute maps such as Dictionary<Corner, Vector2> for corner texture coordinates. These attribute maps are named, and they are hosted in Geometry.
Following standard attribute map names are used: "point_locations", "corner_normals", "polygon_normals", "polygon_centroids", ...
Mostly stable.
Definition at line 54 of file Geometry.cs.
| RenderStack.Geometry.Geometry.Geometry | ( | ) |
Definition at line 77 of file Geometry.cs.
Referenced by example.UI.SceneManager.AddSimpleScene(), example.Scene.SceneManager.AddSimpleScene(), RenderStack.Mesh.GeometryMesh.GeometryMesh(), and RenderStack.Mesh.GeometryMesh.Reset().
{
}
Definition at line 81 of file Geometry.cs.
References RenderStack.Geometry.GeometryOperation.Destination.
{
CloneGeometryOperation clone = new CloneGeometryOperation(src, null);
return clone.Destination;
}
| static CloneGeometryOperation RenderStack.Geometry.Geometry.Clone | ( | Geometry | src, |
| HashSet< uint > | selectedPolygonIndices | ||
| ) | [static] |
Definition at line 89 of file Geometry.cs.
{
return new CloneGeometryOperation(src, selectedPolygonIndices);
}
| void RenderStack.Geometry.Geometry.MergePoints | ( | ) |
Definition at line 95 of file Geometry.cs.
References RenderStack.Math.Vector3.DistanceSquared().
{
Dictionary<Point,Point> removedPointToRemainingPoint = new Dictionary<Point,Point>();
var pointLocations = PointAttributes.FindOrNull<Vector3>("point_locations");
float pointEpsilon = 0.0000001f;
// Merge points
foreach(Point p1 in Points)
{
Vector3 pos1 = pointLocations[p1];
bool alreadyUsed = false;
foreach(Point p2 in Points)
{
if(p1 == p2)
{
continue;
}
if(removedPointToRemainingPoint.ContainsKey(p1))
{
continue;
}
Vector3 pos2 = pointLocations[p2];
float distanceSquared = pos1.DistanceSquared(pos2);
if(distanceSquared < pointEpsilon)
{
if(alreadyUsed)
{
System.Diagnostics.Debug.WriteLine("point already used");
}
removedPointToRemainingPoint[p2] = p1;
alreadyUsed = true;
}
}
}
// Merge polygons
foreach(var polygon in Polygons)
{
polygon.ReplacePoints(removedPointToRemainingPoint);
}
foreach(var point in removedPointToRemainingPoint.Keys)
{
Points.Remove(point);
}
}
| void RenderStack.Geometry.Geometry.Merge | ( | Geometry | other | ) |
Definition at line 146 of file Geometry.cs.
References RenderStack.Geometry.Polygon.Corners, RenderStack.Math.Vector3.DistanceSquared(), RenderStack.Geometry.Corner.Point, and RenderStack.Geometry.Geometry.PointAttributes.
{
Dictionary<Point,Point> otherPointsToNewPoints = new Dictionary<Point,Point>();
var pointLocationsSelf = PointAttributes.FindOrNull<Vector3>("point_locations");
var pointLocationsOther = other.PointAttributes.FindOrNull<Vector3>("point_locations");
float pointEpsilon = 0.0001f;
// Merge points
foreach(Point otherPoint in other.Points)
{
Vector3 otherPosition = pointLocationsOther[otherPoint];
bool existingPointCloseEnough = false;
foreach(Point existingPoint in Points)
{
Vector3 existingPosition = pointLocationsSelf[existingPoint];
float distanceSquared = existingPosition.DistanceSquared(otherPosition);
if(distanceSquared < pointEpsilon)
{
existingPointCloseEnough = true;
otherPointsToNewPoints[otherPoint] = existingPoint;
break;
}
}
if(existingPointCloseEnough == false)
{
otherPointsToNewPoints[otherPoint] = MakePoint(otherPosition);
}
}
// Merge polygons
foreach(Polygon otherPolygon in other.Polygons)
{
// Test if we can find at least single matching polygon
Polygon matchingPolygon = null;
foreach(Polygon existingPolygon in Polygons)
{
// Test that all other corners can be found
bool missingCorners = false;
foreach(Corner otherCorner in otherPolygon.Corners)
{
Point newPoint = otherPointsToNewPoints[otherCorner.Point];
bool cornerFound = false;
// Find matching corner
foreach(Corner existingCorner in existingPolygon.Corners)
{
if(newPoint == existingCorner.Point)
{
cornerFound = true;
break;
}
}
// No matching corner found, continue
if(cornerFound == false)
{
missingCorners = true;
break;
}
}
if(missingCorners == true)
{
continue;
}
// No missing corners - polygons match
matchingPolygon = existingPolygon;
break;
}
if(matchingPolygon != null)
{
// There was a matching polygon, delete it and do not create new from other
RemovePolygon(matchingPolygon);
//Polygons.Remove(matchingPolygon);
}
else
{
// There was no match, add new from other
Polygon newPolygon = MakePolygon();
foreach(Corner otherCorner in otherPolygon.Corners)
{
Point otherPoint = otherCorner.Point;
Point newPoint = otherPointsToNewPoints[otherPoint];
newPolygon.MakeCorner(newPoint);
}
}
}
// Finally, remove unused points
HashSet<Point> usedPoints = new HashSet<Point>();
foreach(Polygon polygon in Polygons)
{
foreach(Corner corner in polygon.Corners)
{
usedPoints.Add(corner.Point);
}
}
List<Point> pointsToRemove = new List<Point>();
foreach(Point point in Points)
{
if(usedPoints.Contains(point) == false)
{
pointsToRemove.Add(point);
}
}
foreach(Point pointToRemove in pointsToRemove)
{
Points.Remove(pointToRemove);
}
}
| void RenderStack.Geometry.Geometry.MergeFast | ( | Geometry | other, |
| Polygon | thisPolygon, | ||
| Polygon | otherPolygon | ||
| ) |
Definition at line 258 of file Geometry.cs.
References RenderStack.Geometry.Polygon.Corners, RenderStack.Math.Vector3.DistanceSquared(), RenderStack.Geometry.Corner.Point, and RenderStack.Geometry.Geometry.PointAttributes.
{
Dictionary<Point,Point> otherPointsToNewPoints = new Dictionary<Point,Point>();
var pointLocationsSelf = PointAttributes.FindOrNull<Vector3>("point_locations");
var pointLocationsOther = other.PointAttributes.FindOrNull<Vector3>("point_locations");
float pointEpsilon = 0.0001f;
// Merge points
foreach(Point otherPoint in other.Points)
{
Vector3 otherPosition = pointLocationsOther[otherPoint];
bool existingPointCloseEnough = false;
foreach(Corner existingCorner in thisPolygon.Corners)
{
Point existingPoint = existingCorner.Point;
Vector3 existingPosition = pointLocationsSelf[existingPoint];
float distanceSquared = existingPosition.DistanceSquared(otherPosition);
if(distanceSquared < pointEpsilon)
{
existingPointCloseEnough = true;
otherPointsToNewPoints[otherPoint] = existingPoint;
break;
}
}
if(existingPointCloseEnough == false)
{
otherPointsToNewPoints[otherPoint] = MakePoint(otherPosition);
}
}
RemovePolygon(thisPolygon);
// Merge polygons
foreach(Polygon otherPolygon2 in other.Polygons)
{
if(otherPolygon != otherPolygon2)
{
Polygon newPolygon = MakePolygon();
foreach(Corner otherCorner in otherPolygon.Corners)
{
Point otherPoint = otherCorner.Point;
Point newPoint = otherPointsToNewPoints[otherPoint];
newPolygon.MakeCorner(newPoint);
}
}
}
// Finally, remove unused points
HashSet<Point> usedPoints = new HashSet<Point>();
foreach(Polygon polygon in Polygons)
{
foreach(Corner corner in polygon.Corners)
{
usedPoints.Add(corner.Point);
}
}
List<Point> pointsToRemove = new List<Point>();
foreach(Point point in Points)
{
if(usedPoints.Contains(point) == false)
{
pointsToRemove.Add(point);
}
}
foreach(Point pointToRemove in pointsToRemove)
{
Points.Remove(pointToRemove);
}
}
| void RenderStack.Geometry.Geometry.RemovePolygon | ( | Polygon | polygon | ) |
Definition at line 348 of file Geometry.cs.
References RenderStack.Geometry.Polygon.Corners.
{
foreach(Corner corner in new List<Corner>(polygon.Corners))
{
RemoveCorner(corner);
}
if(Polygons.Contains(polygon))
{
// This should not happen, removing last corner should remove polygon
System.Diagnostics.Trace.TraceError("polygon should have been removed");
}
}
| void RenderStack.Geometry.Geometry.Transform | ( | Matrix4 | transform | ) |
Definition at line 361 of file Geometry.cs.
References RenderStack.Math.Matrix4.Invert(), and RenderStack.Math.Matrix4.Transpose().
Referenced by example.UI.SceneManager.AddSimpleScene(), and example.Scene.SceneManager.AddSimpleScene().
{
Matrix4 inverseTransposeTransform = Matrix4.Transpose(Matrix4.Invert(transform));
// Check.. Did I forget something?
// \todo Mark each attributemap how they should be transformed
var polygonCentroids = PolygonAttributes.FindOrNull<Vector3>("polygon_centroids");
var polygonNormals = PolygonAttributes.FindOrNull<Vector3>("polygon_normals");
var pointLocations = PointAttributes.FindOrNull<Vector3>("point_locations");
var pointNormals = PointAttributes.FindOrNull<Vector3>("point_normals");
var cornerNormals = CornerAttributes.FindOrNull<Vector3>("corner_normals");
// Make copies of old points
foreach(Point point in Points)
{
if(pointLocations != null && pointLocations.ContainsKey(point)) pointLocations[point] = transform.TransformPoint(pointLocations[point]);
if(pointNormals != null && pointNormals.ContainsKey(point)) pointNormals[point] = inverseTransposeTransform.TransformDirection(pointNormals[point]);
}
foreach(Polygon polygon in Polygons)
{
if(polygonCentroids != null && polygonCentroids.ContainsKey(polygon)) polygonCentroids[polygon] = transform.TransformPoint(polygonCentroids[polygon]);
if(polygonNormals != null && polygonNormals.ContainsKey(polygon)) polygonNormals[polygon] = inverseTransposeTransform.TransformDirection(polygonNormals[polygon]);
if(cornerNormals != null)
{
foreach(Corner corner in polygon.Corners)
{
if(cornerNormals.ContainsKey(corner)) cornerNormals[corner] = inverseTransposeTransform.TransformDirection(cornerNormals[corner]);
}
}
}
}
| Geometry RenderStack.Geometry.Geometry.Clone | ( | ) |
Definition at line 393 of file Geometry.cs.
{
return Clone(this, null).Destination;
}
Definition at line 398 of file Geometry.cs.
References RenderStack.Geometry.Polygon.Corners, RenderStack.Math.Vector3.DistanceSquared(), and RenderStack.Geometry.Corner.Point.
{
Corner closestCorner = null;
float closestDistanceSquared = float.MaxValue;
var pointLocations = PointAttributes.Find<Vector3>("point_locations");
foreach(Corner corner in polygon.Corners)
{
Vector3 cornerLocation = pointLocations[corner.Point];
float distanceSquared = cornerLocation.DistanceSquared(position);
if(distanceSquared < closestDistanceSquared)
{
closestDistanceSquared = distanceSquared;
closestCorner = corner;
}
}
return closestCorner;
}
| void RenderStack.Geometry.Geometry.PolygonCornerEdges | ( | Polygon | polygon, |
| Corner | pivot, | ||
| out Edge | edgeOne, | ||
| out Edge | edgeTwo | ||
| ) |
Definition at line 417 of file Geometry.cs.
References RenderStack.Geometry.Polygon.Corners, and RenderStack.Geometry.Corner.Point.
{
edgeOne = new Edge(polygon.Corners.Last().Point, polygon.Corners.First().Point);
edgeTwo = new Edge(polygon.Corners.First().Point, polygon.Corners.Last().Point);
Corner prevCorner = polygon.Corners.Last();
foreach(Corner corner in polygon.Corners)
{
if(corner == pivot)
{
edgeOne = new Edge(prevCorner.Point, corner.Point);
}
if(prevCorner == pivot)
{
edgeTwo = new Edge(prevCorner.Point, corner.Point);
}
prevCorner = corner;
}
Corner firstCorner = polygon.Corners.First();
if(firstCorner == pivot)
{
edgeOne = new Edge(prevCorner.Point, firstCorner.Point);
}
if(prevCorner == pivot)
{
edgeTwo = new Edge(prevCorner.Point, firstCorner.Point);
}
}
| Geometry RenderStack.Geometry.Geometry.CloneSelectedPolygons | ( | HashSet< uint > | selectedPolygonIndices | ) |
Definition at line 445 of file Geometry.cs.
{
return Clone(this, selectedPolygonIndices).Destination;
}
| Point RenderStack.Geometry.Geometry.MakePoint | ( | ) |
Definition at line 452 of file Geometry.cs.
{
Point point = new Point();
Points.Add(point);
return point;
}
| Polygon RenderStack.Geometry.Geometry.MakePolygon | ( | ) |
Definition at line 460 of file Geometry.cs.
{
Polygon polygon = new Polygon();
Polygons.Add(polygon);
return polygon;
}
| void RenderStack.Geometry.Geometry.ComputePolygonNormals | ( | ) |
Compute polygon normals based on point position attributes. Results are stored in internally stored attribute map named "polygon_normals".
Definition at line 469 of file Geometry.cs.
References RenderStack.Geometry.Polygon.ComputeNormal().
Referenced by RenderStack.Mesh.GeometryMesh.BuildMeshFromGeometry().
{
var polygonNormals = PolygonAttributes.FindOrCreate<Vector3>("polygon_normals");
var pointLocations = PointAttributes.Find<Vector3>("point_locations");
polygonNormals.Clear();
foreach(Polygon polygon in Polygons)
{
polygon.ComputeNormal(polygonNormals, pointLocations);
}
}
| void RenderStack.Geometry.Geometry.ComputePolygonCentroids | ( | ) |
Compute polygon centroids based on point position attributes Results are stored in internally stored attribute map named "polygon_centroids".
Definition at line 482 of file Geometry.cs.
References RenderStack.Geometry.Polygon.ComputeCentroid().
Referenced by RenderStack.Mesh.GeometryMesh.BuildMeshFromGeometry().
{
var polygonCentroids = PolygonAttributes.FindOrCreate<Vector3>("polygon_centroids");
var pointLocations = PointAttributes.Find<Vector3>("point_locations");
polygonCentroids.Clear();
foreach(Polygon polygon in Polygons)
{
polygon.ComputeCentroid(polygonCentroids, pointLocations);
}
}
Definition at line 493 of file Geometry.cs.
References RenderStack.Geometry.Point.Corners, and RenderStack.Geometry.Corner.Polygon.
{
var polygonNormals = PolygonAttributes.Find<Vector3>("polygon_normals");
Vector3 normalSum = new Vector3(0.0f, 0.0f, 0.0f);
foreach(Corner corner in point.Corners)
{
normalSum += polygonNormals[corner.Polygon];
}
Vector3 averageNormal = normalSum / (float)point.Corners.Count;
return averageNormal;
}
| void RenderStack.Geometry.Geometry.ComputePointNormals | ( | string | mapName | ) |
Definition at line 505 of file Geometry.cs.
References RenderStack.Geometry.Point.Corners, and RenderStack.Geometry.Corner.Polygon.
Referenced by RenderStack.Mesh.GeometryMesh.BuildMeshFromGeometry().
{
var pointNormals = PointAttributes.FindOrCreate<Vector3>(mapName);
var polygonNormals = PolygonAttributes.Find<Vector3>("polygon_normals");
pointNormals.Clear();
foreach(Point point in Points)
{
Vector3 normalSum = new Vector3(0.0f, 0.0f, 0.0f);
foreach(Corner corner in point.Corners)
{
normalSum += polygonNormals[corner.Polygon];
}
Vector3 averageNormal = normalSum / (float)point.Corners.Count;
pointNormals[point] = averageNormal;
}
}
| void RenderStack.Geometry.Geometry.SmoothNormalize | ( | string | cornerAttribute, |
| string | polygonAttribute, | ||
| float | maxSmoothingAngleRadians | ||
| ) |
Compute corner normals based on polygon normal and point location attributes Results are stored in internally stored attribute map named "corner_normals".
Definition at line 524 of file Geometry.cs.
References RenderStack.Geometry.Polygon.CopyToCorners(), and RenderStack.Geometry.Polygon.SmoothNormalize().
Referenced by RenderStack.Mesh.GeometryMesh.BuildMeshFromGeometry().
{
var cornerAttributes = CornerAttributes.FindOrCreate<Vector3>(cornerAttribute/*"corner_normals"*/);
var polygonAttributes = PolygonAttributes.Find<Vector3>(polygonAttribute/*"polygon_normals"*/);
var polygonNormals = PolygonAttributes.Find<Vector3>("polygon_normals");
float cosMaxSmoothingAngle = (float)System.Math.Cos((double)maxSmoothingAngleRadians);
cornerAttributes.Clear();
foreach(Polygon polygon in Polygons)
{
if(maxSmoothingAngleRadians == 0)
{
polygon.CopyToCorners(
cornerAttributes,
polygonAttributes
);
}
else
{
polygon.SmoothNormalize(
cornerAttributes,
polygonAttributes,
polygonNormals,
cosMaxSmoothingAngle
);
}
}
}
| void RenderStack.Geometry.Geometry.SmoothAverage | ( | string | cornerAttribute, |
| string | pointNormalName | ||
| ) |
Definition at line 557 of file Geometry.cs.
References RenderStack.Geometry.Polygon.SmoothAverage().
{
var cornerAttributes = CornerAttributes.FindOrCreate<Vector4>(cornerAttribute);
var cornerNormals = CornerAttributes.FindOrCreate<Vector3>("corner_normals");
var pointNormals = PointAttributes.Find<Vector3>(pointNormalName);
var newCornerAttributes = CornerAttributes.FindOrCreate<Vector4>("temp");
foreach(Polygon polygon in Polygons)
{
polygon.SmoothAverage(
newCornerAttributes,
cornerAttributes,
cornerNormals,
pointNormals
);
}
CornerAttributes.Replace(cornerAttribute, "temp");
}
Definition at line 581 of file Geometry.cs.
References RenderStack.Math.Vector3.X, RenderStack.Math.Vector3.Y, and RenderStack.Math.Vector3.Z.
{
Point point = MakePoint();
var pointPositions = PointAttributes.FindOrCreate<Vector3>("point_locations");
#if ENABLE_CREATE_TRANSFORM
pointPositions[point] = MakePointTransform * new Vector3(p.x, p.y, p.z);
#else
pointPositions[point] = new Vector3(p.X, p.Y, p.Z);
#endif
return point;
}
| Point RenderStack.Geometry.Geometry.MakePoint | ( | float | x, |
| float | y, | ||
| float | z | ||
| ) |
Definition at line 593 of file Geometry.cs.
{
Point point = MakePoint();
var pointPositions = PointAttributes.FindOrCreate<Vector3>("point_locations");
#if ENABLE_CREATE_TRANSFORM
pointPositions[point] = MakePointTransform * new Vector3(x, y, z);
#else
pointPositions[point] = new Vector3(x, y, z);
#endif
return point;
}
| Point RenderStack.Geometry.Geometry.MakePoint | ( | double | x, |
| double | y, | ||
| double | z | ||
| ) |
Definition at line 605 of file Geometry.cs.
{
Point point = MakePoint();
var pointPositions = PointAttributes.FindOrCreate<Vector3>("point_locations");
#if ENABLE_CREATE_TRANSFORM
pointPositions[point] = MakePointTransform * Vector3((float)x, (float)y, (float)z);
#else
pointPositions[point] = new Vector3((float)x, (float)y, (float)z);
#endif
return point;
}
| Point RenderStack.Geometry.Geometry.MakePoint | ( | double | x, |
| double | y, | ||
| double | z, | ||
| double | s, | ||
| double | t | ||
| ) |
Definition at line 617 of file Geometry.cs.
{
Point point = MakePoint();
var pointPositions = PointAttributes.FindOrCreate<Vector3>("point_locations");
var pointTexCoords = PointAttributes.FindOrCreate<Vector2>("point_texcoords");
#if ENABLE_CREATE_TRANSFORM
pointPositions[point] = MakePointTransform * Vector3((float)x, (float)y, (float)z);
#else
pointPositions[point] = new Vector3((float)x, (float)y, (float)z);
#endif
pointTexCoords[point] = new Vector2((float)s, (float)t);
return point;
}
| points | oints that are connected to the new Polygon |
Definition at line 634 of file Geometry.cs.
References RenderStack.Geometry.Polygon.MakeCorner().
{
Polygon polygon = MakePolygon();
foreach(Point point in points)
{
polygon.MakeCorner(point);
}
return polygon;
}
| Polygon RenderStack.Geometry.Geometry.MakePolygon | ( | params int[] | pointIndices | ) |
| pointIndices | Indices to Points that are connected to the new Polygon |
Definition at line 646 of file Geometry.cs.
References RenderStack.Geometry.Polygon.DebugCheck(), and RenderStack.Geometry.Polygon.MakeCorner().
{
Polygon polygon = MakePolygon();
foreach(int pointIndex in pointIndices)
{
Point point = Points[pointIndex];
polygon.MakeCorner(point);
}
#if DEBUG_CHECK
var pointLocations = PointAttributes.Find<Vector3>("point_locations");
if(polygon.DebugCheck(pointLocations) == false)
{
System.Text.StringBuilder sb = new System.Text.StringBuilder();
for(int i = pointIndices.Length - 1; i >= 0; --i)
{
sb.Append(pointIndices[i].ToString());
if(i > 0)
{
sb.Append(", ");
}
}
Logger.Log(sb.ToString() + ");");
}
else
{
System.Text.StringBuilder sb = new System.Text.StringBuilder();
for(int i = 0; i < pointIndices.Length; i++)
{
sb.Append(pointIndices[i].ToString());
if(i < pointIndices.Length - 1)
{
sb.Append(", ");
}
}
Logger.Log(sb.ToString() + ");");
}
#endif
return polygon;
}
| Polygon RenderStack.Geometry.Geometry.MakePolygon | ( | List< int > | pointIndices | ) |
Definition at line 685 of file Geometry.cs.
References RenderStack.Geometry.Polygon.DebugCheck(), and RenderStack.Geometry.Polygon.MakeCorner().
{
Polygon polygon = MakePolygon();
/* Sanity check */
for(int i = 0; i < pointIndices.Count; ++i)
{
for(int j = 0; j < pointIndices.Count; ++j)
{
if(i == j)
{
continue;
}
if(pointIndices[i] == pointIndices[j])
{
throw new System.Exception("duplicate polygon corner point indices");
}
}
}
foreach(int pointIndex in pointIndices)
{
Point point = Points[pointIndex];
polygon.MakeCorner(point);
}
#if DEBUG_CHECK
var pointLocations = PointAttributes.Find<Vector3>("point_locations");
if(polygon.DebugCheck(pointLocations) == false)
{
System.Text.StringBuilder sb = new System.Text.StringBuilder();
for(int i = pointIndices.Length - 1; i >= 0; --i)
{
sb.Append(pointIndices[i].ToString());
if(i > 0)
{
sb.Append(", ");
}
}
Logger.Log(sb.ToString() + ");");
}
else
{
System.Text.StringBuilder sb = new System.Text.StringBuilder();
for(int i = 0; i < pointIndices.Length; i++)
{
sb.Append(pointIndices[i].ToString());
if(i < pointIndices.Length - 1)
{
sb.Append(", ");
}
}
Logger.Log(sb.ToString() + ");");
}
#endif
return polygon;
}
| void RenderStack.Geometry.Geometry.CheckEdge | ( | Edge | edge | ) |
Definition at line 741 of file Geometry.cs.
References RenderStack.Geometry.Edge.A, and RenderStack.Geometry.Edge.B.
{
var cornerIndices = CornerAttributes.FindOrCreate<uint>("corner_indices");
/* Required: A != B */
if(edge.A == edge.B)
{
throw new InvalidOperationException();
}
/* Required: A and B share no corners */
foreach(var cornerA in edge.A.Corners)
{
foreach(var cornerB in edge.B.Corners)
{
if(cornerA == cornerB)
{
throw new InvalidOperationException();
}
uint i0 = cornerIndices[cornerA];
uint i1 = cornerIndices[cornerB];
if(i0 == i1)
{
throw new InvalidCastException();
}
}
}
}
| void RenderStack.Geometry.Geometry.BuildEdges | ( | ) |
Definition at line 768 of file Geometry.cs.
References RenderStack.Geometry.Polygon.Corners, and RenderStack.Geometry.Corner.Point.
Referenced by RenderStack.Mesh.GeometryMesh.BuildMeshFromGeometry().
{
Edges.Clear();
int polygonIndex = 0;
foreach(Polygon polygon in polygons)
{
Point firstPoint = polygon.Corners[0].Point;
Point previousPoint = null;
int cornerIndex = 0;
foreach(Corner corner in polygon.Corners)
{
if(previousPoint != null)
{
Point a = previousPoint;
Point b = corner.Point;
if(a == b)
{
throw new InvalidOperationException("Degenerate edge");
}
Edge edge = new Edge(a, b);
//CheckEdge(edge);
if(Edges.ContainsKey(edge) == false)
{
Edges[edge] = new HashSet<Polygon>();
}
/*else
{
Logger.Log("old edge");
}*/
Edges[edge].Add(polygon);
}
previousPoint = corner.Point;
++cornerIndex;
}
Edge lastEdge = new Edge(previousPoint, firstPoint);
//CheckEdge(lastEdge);
if(edges.ContainsKey(lastEdge) == false)
{
Edges[lastEdge] = new HashSet<Polygon>();
}
Edges[lastEdge].Add(polygon);
++polygonIndex;
}
/*foreach(HashSet<Polygon> polys in Edges.Values)
{
int count = polys.Count;
if(count != 2)
{
Logger.Log("Warning: edge with != 2 polygons, this can cause issues");
}
}*/
}
| Matrix4 RenderStack.Geometry.Geometry.MakePointTransform = Matrix4.Identity |
Definition at line 579 of file Geometry.cs.
AttributeMapCollection<Point> RenderStack.Geometry.Geometry.PointAttributes [get] |
Definition at line 61 of file Geometry.cs.
Referenced by RenderStack.Mesh.GeometryMesh.BuildMeshFromGeometry(), RenderStack.Geometry.Geometry.Merge(), and RenderStack.Geometry.Geometry.MergeFast().
AttributeMapCollection<Corner> RenderStack.Geometry.Geometry.CornerAttributes [get] |
Definition at line 62 of file Geometry.cs.
Referenced by RenderStack.Mesh.GeometryMesh.BuildMeshFromGeometry().
AttributeMapCollection<Polygon> RenderStack.Geometry.Geometry.PolygonAttributes [get] |
Definition at line 63 of file Geometry.cs.
Referenced by RenderStack.Mesh.GeometryMesh.BuildMeshFromGeometry().
AttributeMapCollection<Edge> RenderStack.Geometry.Geometry.EdgeAttributes [get] |
Definition at line 64 of file Geometry.cs.
List<Point> RenderStack.Geometry.Geometry.Points [get] |
Definition at line 71 of file Geometry.cs.
List<Polygon> RenderStack.Geometry.Geometry.Polygons [get] |
Definition at line 72 of file Geometry.cs.
Referenced by RenderStack.Mesh.GeometryMesh.BuildMeshFromGeometry().
Definition at line 75 of file Geometry.cs.
Referenced by RenderStack.Mesh.GeometryMesh.BuildMeshFromGeometry().
1.7.4