//================================================================== // ConstantVolumePressure //================================================================== /// <summary> /// Simulate pressure trapped inside a closed volume. The pressure decreases as the volume expands (Boyle's law) /// </summary> /// <param name="mesh">A closed mesh</param> /// <param name="volumePressureConstant">The constant that is the product of the pressure and volume. This means that pressure will automatically decrease as the mesh volume increases (and vice versa)</param> /// <param name="weight"></param> /// <returns></returns> public static ConstantVolumePressureGoal ConstantVolumePressureGoal_Create( Mesh mesh, [DefaultArgument("0.0")] double volumePressureConstant, [DefaultArgument("1.0")] double weight) { return(new ConstantVolumePressureGoal(mesh, (float)volumePressureConstant, (float)weight)); }
/// <summary> /// Simulate wind blowing along a specified direction, by applying a force on the three vertices of a triangle, /// The force magnitude is addtionally scaled by the cosine of the angle between the wind vector and the triangle's normal. /// This way, the wind has full effect when it hits the triangle head-on, and zero /// effect if it blows paralell to the triangle. /// </summary> /// <param name="mesh"></param> /// <param name="windVector"></param> /// <param name="weight"></param> /// <returns></returns> public static List <DirectionalWindGoal> DirectionalWindGoal_Create( Mesh mesh, [DefaultArgument("Vector.ByCoordinates(1.0, 0, 0)")] Vector windVector, [DefaultArgument("1.0")] double weight) { List <DirectionalWindGoal> windGoals = new List <DirectionalWindGoal>(); List <double> vertices = mesh.TrianglesAsNineNumbers.ToList(); int faceCount = vertices.Count / 9; for (int i = 0; i < faceCount; i++) { int j = i * 9; windGoals.Add( new DirectionalWindGoal( new Triple(vertices[j + 0], vertices[j + 1], vertices[j + 2]), new Triple(vertices[j + 3], vertices[j + 4], vertices[j + 5]), new Triple(vertices[j + 6], vertices[j + 7], vertices[j + 8]), windVector.ToTriple(), (float)weight)); } return(windGoals); }
/// <summary> /// Applying forces perpendicular to each triangular face of a mesh, with magnitude proportional to the surface area of the triangle /// </summary> /// <param name="mesh"></param> /// <param name="pressure"></param> /// <param name="weight"></param> /// <returns></returns> public static List <ConstantPressureGoal> ConstantPressureGoal_Create( Mesh mesh, [DefaultArgument("0.1")] double pressure, [DefaultArgument("1.0")] double weight) { List <ConstantPressureGoal> pressureGoals = new List <ConstantPressureGoal>(); List <double> vertices = mesh.TrianglesAsNineNumbers.ToList(); int faceCount = vertices.Count / 9; for (int i = 0; i < faceCount; i++) { int j = i * 9; pressureGoals.Add( new ConstantPressureGoal( new Triple(vertices[j + 0], vertices[j + 1], vertices[j + 2]), new Triple(vertices[j + 3], vertices[j + 4], vertices[j + 5]), new Triple(vertices[j + 6], vertices[j + 7], vertices[j + 8]), (float)pressure, (float)weight)); } return(pressureGoals); }
public Octree(MeshToolkit mesh, bool cubic = true) { this._mesh = mesh; this._cubic = cubic; //this.triangles = _mesh.Triangles(); this.vertices = _mesh.Vertices(); this.vertexIndexByTri = Core.List.Chop <int>(_mesh.VertexIndicesByTri(), 3); BoundingBox bbox = Graphical.Geometry.MeshToolkit.BoundingBox(this._mesh); // Extending the BoundingBox to be cubical from the centre. // Done by getting the max component of the Bounding box and translating min and max points outwards. // https://github.com/diwi/Space_Partitioning_Octree_BVH/blob/b7f66fe04e4af3b98ab9404363ab33f5dc1628a9/SpacePartitioning/src/DwOctree/Octree.java#L83 if (cubic) { using (Point center = Geometry.Point.MidPoint(bbox.MinPoint, bbox.MaxPoint)) { Vector bboxSize = Vector.ByTwoPoints(bbox.MinPoint, bbox.MaxPoint); Vector halfSize = bboxSize.Scale(0.5); double[] halfComponents = new double[3] { halfSize.X, halfSize.Y, halfSize.Z }; double maxComponent = halfComponents[getSubdivisionPlane(bbox)]; Vector expansionDirection = Vector.ByCoordinates(maxComponent, maxComponent, maxComponent); bbox = BoundingBox.ByCorners( (Point)center.Translate(-maxComponent, -maxComponent, -maxComponent), (Point)center.Translate(maxComponent, maxComponent, maxComponent) ); } } _root = new OctreeNode(0, bbox); }
public ConstantVolumePressureGoal(Mesh mesh, float volumePressureConstant, float weight = 1f) { try { currentVolumeInversed = 1f / (float)mesh.Volume; } catch (Exception) { throw new Exception("The input mesh is not valid (It must be a closed mesh so that its volume is computable)"); } Mesh = mesh; faces = Mesh.VertexIndicesByTri(); Weight = weight; VolumePressureConstant = volumePressureConstant; List <Point> vertices = mesh.Vertices(); StartingPositions = new Triple[mesh.VertexCount]; for (int i = 0; i < mesh.VertexCount; i++) { StartingPositions[i] = vertices[i].ToTriple(); } Moves = new Triple[StartingPositions.Length]; Weights = new float[StartingPositions.Length]; }
public static MeshBinder MeshBinder( Autodesk.Dynamo.MeshToolkit.Mesh toolkitMesh, [DefaultArgument("null")] Color color) { return(new MeshBinder( toolkitMesh, color?.ToSharpDXColor() ?? DynaShapeDisplay.DefaultMeshFaceColor)); }
public static TexturedMeshBinder TexturedMeshBinder( Autodesk.Dynamo.MeshToolkit.Mesh toolkitMesh, [DefaultArgument("null")] Color color, string textureFileName, TextureCoordinateSet textureCoordinates) { return(new TexturedMeshBinder( toolkitMesh, color?.ToSharpDXColor() ?? DynaShapeDisplay.DefaultMeshFaceColor, textureFileName, textureCoordinates.Content)); }
internal override void Compute(List <Node> allNodes) { List <Point> vertices = new List <Point>(); foreach (int i in NodeIndices) { vertices.Add(allNodes[i].Position.ToPoint()); } Mesh = Mesh.ByVerticesAndIndices(vertices, faces); for (int i = 0; i < NodeCount; i++) { Moves[i] = Triple.Zero; } int faceCount = faces.Count / 3; try { float currentVolume = (float)Mesh.Volume; currentVolumeInversed = 1f / currentVolume; } catch { // ignored } for (int i = 0; i < faceCount; i++) { int iA = faces[i * 3 + 0]; int iB = faces[i * 3 + 1]; int iC = faces[i * 3 + 2]; Triple A = allNodes[NodeIndices[iA]].Position; Triple B = allNodes[NodeIndices[iB]].Position; Triple C = allNodes[NodeIndices[iC]].Position; Triple n = (B - A).Cross(C - A); Triple force = VolumePressureConstant * currentVolumeInversed * n * 0.16666666666666f; Moves[iA] += force; Moves[iB] += force; Moves[iC] += force; } Weights.FillArray(Weight); }
public static List <List <Point> > GetVerticesOfAllPairOfTriangles(Mesh mesh) { List <int> faceVertexIndices = mesh.VertexIndicesByTri(); int vertexCount = (int)mesh.VertexCount; Dictionary <int, List <int> > edgeFaceTopology = new Dictionary <int, List <int> >(); for (int i = 0; i < mesh.TriangleCount; i++) { int A = faceVertexIndices[i * 3]; int B = faceVertexIndices[i * 3 + 1]; int C = faceVertexIndices[i * 3 + 2]; InsertEdgeFaceTopology(edgeFaceTopology, i, A, B, vertexCount); InsertEdgeFaceTopology(edgeFaceTopology, i, B, C, vertexCount); InsertEdgeFaceTopology(edgeFaceTopology, i, C, A, vertexCount); } List <List <Point> > facePairVertices = new List <List <Point> >(); foreach (List <int> connectedFaces in edgeFaceTopology.Values) { if (connectedFaces.Count < 2) { continue; } HashSet <int> hashSet = new HashSet <int>(); hashSet.Add(faceVertexIndices[connectedFaces[0] * 3]); hashSet.Add(faceVertexIndices[connectedFaces[0] * 3 + 1]); hashSet.Add(faceVertexIndices[connectedFaces[0] * 3 + 2]); hashSet.Add(faceVertexIndices[connectedFaces[1] * 3]); hashSet.Add(faceVertexIndices[connectedFaces[1] * 3 + 1]); hashSet.Add(faceVertexIndices[connectedFaces[1] * 3 + 2]); List <Point> vertices = new List <Point>(); foreach (int i in hashSet) { vertices.Add(mesh.Vertices()[i]); } facePairVertices.Add(vertices); } return(facePairVertices); }
/// <summary> /// Initiates a Triangle Strategy solver from a MeshTookkit mesh /// </summary> /// <param name="mesh"></param> /// <param name="iterations"></param> public hTriangleStrategy(Mesh mesh, int iterations) { this._mesh = mesh; this._agents = new tAgent[mesh.EdgeCount]; CreateAgents(); for (int i = 0; i < iterations; i++) { var state = new List <Geo.Line>(); foreach (tAgent agent in _agents) { var memberLines = agent.GetMemberLines(_agents); foreach (Geo.Line l in memberLines) { state.Add(l); } } states.Add(state); foreach (tAgent agent in _agents) { _test.Add(agent.Step(_agents)); } } }
/// <summary> /// /// </summary> /// <param name="mesh"></param> /// <param name="iterations"></param> /// <returns></returns> public static List <List <Geo.Line> > FromMesh(Mesh mesh, int iterations) { var solver = new hTriangleStrategy(mesh, iterations); return(solver.states); }
public static Dictionary <string, object> AuxeticRotatingTriangles(int xCount = 5, int yCount = 5, double thickness = 0.0) { List <Goal> shapeMatchingGoals = new List <Goal>(); List <Goal> mergeGoals = new List <Goal>(); List <GeometryBinder> meshBinders = new List <GeometryBinder>(); List <GeometryBinder> lineBinders = new List <GeometryBinder>(); List <Point> vertices = new List <Point>(); List <int> indices = new List <int>(); double offset = 0.001; double cos30 = Math.Cos(Math.PI / 6.0); for (int j = 0; j < yCount; j++) { for (int i = 0; i < xCount; i++) { double xOffset = 2 * i + 1; double yOffset = 2 * j * cos30 + cos30; Triple M = new Triple(xOffset, yOffset, 0.0); List <Triple> v = new List <Triple>(); for (int k = 0; k < 6; k++) { v.Add(new Triple(xOffset + Math.Cos(k * Math.PI / 3.0), yOffset + Math.Sin(k * Math.PI / 3.0), 0.0)); } for (int k = 0; k < 5; k++) { shapeMatchingGoals.Add(ProcessTriangle(M, v[k], v[k + 1], k % 2 == 0, offset, thickness, vertices, indices)); } shapeMatchingGoals.Add(ProcessTriangle(M, v[5], v[0], false, offset, thickness, vertices, indices)); M = new Triple(xOffset + 1, yOffset, 0.0); if (i < xCount - 1) { shapeMatchingGoals.Add(ProcessTriangle( M, new Triple(xOffset + 1.5, yOffset + cos30, 0.0), new Triple(xOffset + 0.5, yOffset + cos30, 0.0), false, offset, thickness, vertices, indices)); shapeMatchingGoals.Add(ProcessTriangle( M, new Triple(xOffset + 0.5, yOffset - cos30, 0.0), new Triple(xOffset + 1.5, yOffset - cos30, 0.0), true, offset, thickness, vertices, indices)); } } } meshBinders.Add(new MeshBinder(Mesh.ByVerticesAndIndices(vertices, indices), new Color(.3f, .6f, .8f, 1f))); //======================================================================================= // Line Binders //======================================================================================= for (int j = 0; j < yCount; j++) { for (int i = 0; i < xCount * 2; i++) { double xOffset = i; double yOffset = 2 * j * cos30 + cos30; Triple M = new Triple(xOffset, yOffset, 0.0); List <Triple> v = new List <Triple>(); for (int k = 1; k < 6; k += 2) { v.Add(new Triple(xOffset + offset * Math.Cos(k * Math.PI / 3.0), yOffset + offset * Math.Sin(k * Math.PI / 3.0), 0.0)); } lineBinders.Add(new LineBinder(v[0], v[1])); lineBinders.Add(new LineBinder(v[1], v[2])); lineBinders.Add(new LineBinder(v[2], v[0])); mergeGoals.Add(new MergeGoal(v, 0.1f)); } } for (int j = 0; j <= yCount; j++) { for (int i = 0; i < xCount * 2; i++) { double xOffset = i + 0.5; double yOffset = 2 * j * cos30; Triple M = new Triple(xOffset, yOffset, 0.0); List <Triple> v = new List <Triple>(); for (int k = 1; k < 6; k += 2) { v.Add(new Triple(xOffset + offset * Math.Cos(k * Math.PI / 3.0), yOffset + offset * Math.Sin(k * Math.PI / 3.0), 0.0)); } lineBinders.Add(new LineBinder(v[0], v[1])); lineBinders.Add(new LineBinder(v[1], v[2])); lineBinders.Add(new LineBinder(v[2], v[0])); mergeGoals.Add(new MergeGoal(v, 0.1f)); } } return(new Dictionary <string, object> { { "shapeMatchingGoals", shapeMatchingGoals }, { "mergeGoals", mergeGoals }, { "meshBinders", meshBinders }, { "lineBinders", lineBinders }, }); }
public static Dictionary <string, object> AuxeticRotatingSquares(int xCount = 5, int yCount = 5, double thickness = 0.0) { List <Goal> shapeMatchingGoals = new List <Goal>(); List <GeometryBinder> meshBinders = new List <GeometryBinder>(); List <GeometryBinder> lineBinders = new List <GeometryBinder>(); List <Point> vertices = new List <Point>(); List <int> indices = new List <int>(); double offset = 0.001; List <Triple> targetShape = new List <Triple>() { new Triple(0, 0, 0), new Triple(1, 0, 0), new Triple(1, 1, 0), new Triple(0, 1, 0), }; if (thickness > 0.0) { for (int i = 0; i < 4; i++) { targetShape.Add(targetShape[i] + thickness * Triple.BasisZ); } } for (int i = 0; i < xCount; i++) { for (int j = 0; j < yCount; j++) { double k = 0.0; List <Triple> tileVertices = new List <Triple>(); if ((i + j) % 2 == 0) { tileVertices = new List <Triple>() { new Triple(i, j + offset, k), new Triple(i + 1f - offset, j, k), new Triple(i + 1f, j + 1f - offset, k), new Triple(i + offset, j + 1f, k), } } ; else { tileVertices = new List <Triple>() { new Triple(i + offset, j, k), new Triple(i + 1f, j + offset, k), new Triple(i + 1f - offset, j + 1f, k), new Triple(i, j + 1f - offset, k), }; } if (thickness > 0.0) { for (int ii = 0; ii < 4; ii++) { tileVertices.Add(tileVertices[ii] + thickness * Triple.BasisZ); } } shapeMatchingGoals.Add(new ShapeMatchingGoal(tileVertices, targetShape)); vertices.Add(tileVertices[0].ToPoint()); vertices.Add(tileVertices[1].ToPoint()); vertices.Add(tileVertices[2].ToPoint()); vertices.Add(tileVertices[3].ToPoint()); int n = vertices.Count - 4; indices.AddRange(new [] { n, n + 1, n + 2, n, n + 2, n + 3 }); } } List <Goal> lengthGoals = new List <Goal>(); for (int i = 1; i < xCount; i++) { for (int j = 0; j <= yCount; j++) { if ((i + j) % 2 == 1) { lengthGoals.Add(new LengthGoal( new Triple(i - offset, j, 0), new Triple(i + offset, j, 0))); lineBinders.Add(new LineBinder( new Triple(i - offset, j, 0), new Triple(i + offset, j, 0))); } } } for (int i = 0; i <= xCount; i++) { for (int j = 1; j < yCount; j++) { if ((i + j) % 2 == 0) { lengthGoals.Add(new LengthGoal( new Triple(i, j - offset, 0), new Triple(i, j + offset, 0))); lineBinders.Add(new LineBinder( new Triple(i, j - offset, 0), new Triple(i, j + offset, 0))); } } } meshBinders.Add(new MeshBinder(Mesh.ByVerticesAndIndices(vertices, indices), new Color(.3f, .6f, .8f, 1f))); return(new Dictionary <string, object> { { "shapeMatchingGoals", shapeMatchingGoals }, { "lengthGoals", lengthGoals }, { "meshBinders", meshBinders }, { "lineBinders", lineBinders }, }); }
public static Dictionary <string, object> Shearing(int xCount = 5, int yCount = 5, double k = 0.2, double thickness = 0.5) { shapeMatchingGoals = new List <ShapeMatchingGoal>(); vertices = new List <Point>(); indices = new List <int>(); polylineBinders = new List <PolylineBinder>(); for (int i = 0; i < xCount; i++) { for (int j = 0; j < yCount; j++) { if ((i + j) % 2 == 0) { CreateUnit(new List <Triple>() { new Triple(i, j + k, 0f), new Triple(i, j, 0f), new Triple(i + 1f - k, j, 0f), new Triple(i, j + k, thickness), new Triple(i, j, thickness), new Triple(i + 1f - k, j, thickness), }); CreateUnit(new List <Triple>() { new Triple(i + 1f - k, j, 0f), new Triple(i + 1f, j, 0f), new Triple(i + 1f, j + 1f - k, 0f), new Triple(i + 1f - k, j, thickness), new Triple(i + 1f, j, thickness), new Triple(i + 1f, j + 1f - k, thickness), }); CreateUnit(new List <Triple>() { new Triple(i + 1f, j + 1f - k, 0f), new Triple(i + 1f, j + 1f, 0f), new Triple(i + k, j + 1f, 0f), new Triple(i + 1f, j + 1f - k, thickness), new Triple(i + 1f, j + 1f, thickness), new Triple(i + k, j + 1f, thickness), }); CreateUnit(new List <Triple>() { new Triple(i + k, j + 1f, 0f), new Triple(i, j + 1f, 0f), new Triple(i, j + k, 0f), new Triple(i + k, j + 1f, thickness), new Triple(i, j + 1f, thickness), new Triple(i, j + k, thickness), }); } else { if (i == 0 || i == xCount - 1 || j == 0 || j == yCount - 1) { CreateUnit(new List <Triple>() { new Triple(i, j + 1f - k, 0f), new Triple(i, j, 0f), new Triple(i + k, j, 0f), new Triple(i, j + 1f - k, thickness), new Triple(i, j, thickness), new Triple(i + k, j, thickness), }); CreateUnit(new List <Triple>() { new Triple(i + k, j, 0f), new Triple(i + 1f, j, 0f), new Triple(i + 1f, j + k, 0f), new Triple(i + k, j, thickness), new Triple(i + 1f, j, thickness), new Triple(i + 1f, j + k, thickness), }); CreateUnit(new List <Triple>() { new Triple(i + 1f, j + k, 0f), new Triple(i + 1f, j + 1f, 0f), new Triple(i + 1f - k, j + 1f, 0f), new Triple(i + 1f, j + k, thickness), new Triple(i + 1f, j + 1f, thickness), new Triple(i + 1f - k, j + 1f, thickness), }); CreateUnit(new List <Triple>() { new Triple(i + 1f - k, j + 1f, 0f), new Triple(i, j + 1f, 0f), new Triple(i, j + 1f - k, 0f), new Triple(i + 1f - k, j + 1f, thickness), new Triple(i, j + 1f, thickness), new Triple(i, j + 1f - k, thickness), }); } } } } return(new Dictionary <string, object> { { "shapeMatchingGoals", shapeMatchingGoals }, { "meshBinders", new MeshBinder(Mesh.ByVerticesAndIndices(vertices, indices), new Color(0f, 0.7f, 1f, 0.9f)) }, { "polylineBinders", KinetiX.polylineBinders }, }); }
public static Dictionary <string, object> AuxeticRotatingSquares(int xCount = 5, int yCount = 5, double thickness = 0.0) { List <Goal> shapeMatchingGoals = new List <Goal>(); List <GeometryBinder> meshBinders = new List <GeometryBinder>(); List <GeometryBinder> lineBinders = new List <GeometryBinder>(); List <Point> vertices = new List <Point>(); List <int> indices = new List <int>(); double offset = 0.001; for (int i = 0; i < xCount; i++) { for (int j = 0; j < yCount; j++) { double k = 0.0; List <Triple> triples = new List <Triple>(); if ((i + j) % 2 == 0) { triples = new List <Triple>() { new Triple(i, j + offset, k), new Triple(i + 1f - offset, j, k), new Triple(i + 1f, j + 1f - offset, k), new Triple(i + offset, j + 1f, k), } } ; else { triples = new List <Triple>() { new Triple(i + offset, j, k), new Triple(i + 1f, j + offset, k), new Triple(i + 1f - offset, j + 1f, k), new Triple(i, j + 1f - offset, k), }; } if (thickness > 0.0) { for (int ii = 0; ii < 4; ii++) { triples.Add(triples[ii] + thickness * Triple.BasisZ); } } shapeMatchingGoals.Add(new ShapeMatchingGoal(triples, triples)); //goals.Add(new OnPlaneGoal(triples, Plane.XY())); vertices.Add(triples[0].ToPoint()); vertices.Add(triples[1].ToPoint()); vertices.Add(triples[2].ToPoint()); vertices.Add(triples[3].ToPoint()); int n = vertices.Count - 4; indices.AddRange(new [] { n, n + 1, n + 2, n, n + 2, n + 3 }); } } List <Goal> lengthGoals = new List <Goal>(); for (int i = 1; i < xCount; i++) { for (int j = 0; j <= yCount; j++) { if ((i + j) % 2 == 1) { lengthGoals.Add(new LengthGoal( new Triple(i - offset, j, 0), new Triple(i + offset, j, 0))); lineBinders.Add(new LineBinder( new Triple(i - offset, j, 0), new Triple(i + offset, j, 0))); } } } for (int i = 0; i <= xCount; i++) { for (int j = 1; j < yCount; j++) { if ((i + j) % 2 == 0) { lengthGoals.Add(new LengthGoal( new Triple(i, j - offset, 0), new Triple(i, j + offset, 0))); lineBinders.Add(new LineBinder( new Triple(i, j - offset, 0), new Triple(i, j + offset, 0))); } } } meshBinders.Add(new MeshBinder(Mesh.ByVerticesAndIndices(vertices, indices), new Color(.3f, .6f, .8f, 1f))); List <Triple> allTriples = new List <Triple>(); foreach (Point point in vertices) { allTriples.Add(point.ToTriple()); } return(new Dictionary <string, object> { { "shapeMatchingGoals", shapeMatchingGoals }, { "lengthGoals", lengthGoals }, //{"onSurfaceGoal", surface == null ? null : new OnSurfaceGoal(allTriples, surface, 1f)}, { "onSurfaceGoal", null }, { "meshBinders", meshBinders }, { "lineBinders", lineBinders }, }); }
public static Dictionary <string, object> PlaneMesh( [DefaultArgument("CoordinateSystem.ByOriginVectors(Point.Origin(), Vector.XAxis(), Vector.YAxis())")] CoordinateSystem cs, [DefaultArgument("20.0")] double lengthX, [DefaultArgument("20.0")] double lengthY, [DefaultArgument("20")] int divX, [DefaultArgument("20")] int divY, [DefaultArgument("true")] bool alternatingDiagons) { if (divX < 1 || divY < 0) { throw new Exception("divX and divY must be larger than 0"); } List <Point> vertices = new List <Point>((divX + 1) * (divY + 1)); Vector2Collection textureCoordinates = new Vector2Collection(); for (int j = 0; j <= divY; j++) { for (int i = 0; i <= divX; i++) { vertices.Add( Point.ByCartesianCoordinates( cs, ((double)i / divX - 0.5f) * lengthX, ((double)j / divY - 0.5f) * lengthY)); textureCoordinates.Add(new Vector2((float)i / (float)(divX), 1f - (float)j / (float)(divY))); } } List <int> indices = new List <int>(); List <List <int> > quadFaceVertexIndices = new List <List <int> >(); for (int j = 0; j < divY; j++) { for (int i = 0; i < divX; i++) { int a = i + j * (divX + 1); int b = i + 1 + j * (divX + 1); int c = i + 1 + (j + 1) * (divX + 1); int d = i + (j + 1) * (divX + 1); quadFaceVertexIndices.Add(new List <int> { a, b, c, d }); if (alternatingDiagons) { if ((i + j) % 2 == 0) { indices.Add(a); indices.Add(b); indices.Add(c); indices.Add(a); indices.Add(c); indices.Add(d); } else { indices.Add(a); indices.Add(b); indices.Add(d); indices.Add(b); indices.Add(c); indices.Add(d); } } else { indices.Add(a); indices.Add(b); indices.Add(c); indices.Add(a); indices.Add(c); indices.Add(d); } } } return(new Dictionary <string, object>() { { "mesh", Mesh.ByVerticesAndIndices(vertices, indices) }, { "quadFaceVertexIndices", quadFaceVertexIndices }, { "textureCoordinates", new TextureCoordinateSet(textureCoordinates) }, }); }
public static Mesh PlaneMesh( [DefaultArgument("CoordinateSystem.ByOriginVectors(Point.Origin(), Vector.XAxis(), Vector.YAxis())")] CoordinateSystem cs, [DefaultArgument("20.0")] double lengthX, [DefaultArgument("20.0")] double lengthY, [DefaultArgument("20")] int divX, [DefaultArgument("20")] int divY, [DefaultArgument("true")] bool alternatingDiagons) { List <Point> vertices = new List <Point>((divX + 1) * (divY + 1)); for (int j = 0; j <= divY; j++) { for (int i = 0; i <= divX; i++) { vertices.Add( Point.ByCartesianCoordinates( cs, ((double)i / divX - 0.5f) * lengthX, ((double)j / divY - 0.5f) * lengthY)); } } List <int> indices = new List <int>(); if (alternatingDiagons) { for (int j = 0; j < divY; j++) { for (int i = 0; i < divX; i++) { int a = i + j * (divX + 1); int b = i + 1 + j * (divX + 1); int c = i + 1 + (j + 1) * (divX + 1); int d = i + (j + 1) * (divX + 1); if ((i + j) % 2 == 0) { indices.Add(a); indices.Add(b); indices.Add(c); indices.Add(a); indices.Add(c); indices.Add(d); } else { indices.Add(a); indices.Add(b); indices.Add(d); indices.Add(b); indices.Add(c); indices.Add(d); } } } } else { for (int j = 0; j < divY; j++) { for (int i = 0; i < divX; i++) { int a = i + j * (divX + 1); int b = i + 1 + j * (divX + 1); int c = i + 1 + (j + 1) * (divX + 1); int d = i + (j + 1) * (divX + 1); indices.Add(a); indices.Add(b); indices.Add(c); indices.Add(a); indices.Add(c); indices.Add(d); } } } return(Mesh.ByVerticesAndIndices(vertices, indices)); }