private Mesh Tire(float width) { var vertices = new List <Vector3>(); var offset = new Vector3(width, 0, 0); vertices.AddRange(Octagon(offset, 0.5f)); vertices.AddRange(Octagon(-offset, 0.5f)); vertices.AddRange(Octagon(offset, 0.4f)); vertices.AddRange(Octagon(-offset, 0.4f)); var faces = new List <Face>(); faces.AddRange(OctagonCoverFaces(new List <int> { 0, 1 })); faces.AddRange(OctagonCoverFaces(new List <int> { 16, 17 }, true)); faces.AddRange(OctagonCoverSideFaces(new List <int> { 0, 1 })); faces.AddRange(OctagonCoverSideFaces(new List <int> { 8, 9 }, true)); var mesh = new Mesh(vertices, faces); mesh.Add(mesh.MirrorY()); mesh.Add(mesh.MirrorZ()); return(mesh); }
private Mesh Logo(Vector3 origin, float width, float radius) { var vertices = new List <Vector3>(); var offset = new Vector3(width, 0, 0); vertices.AddRange(Octagon(offset, radius)); vertices.AddRange(Octagon(-offset, radius)); var faces = new List <Face>(); faces.AddRange(OctagonCoverFaces(new List <int> { 0, 1 })); vertices.Add(offset); faces.AddRange(OctagonFaces(16, new List <int> { 0, 1 })); var mesh = new Mesh(vertices, faces); // mesh.Add(Spoke(origin, 0.15f, 0.4f, 0.05f).Rotate(Quaternion.Euler(22.5f, 0, 0))); // mesh.Add(Spoke(origin, 0.15f, 0.4f, 0.05f).Rotate(Quaternion.Euler(67.5f, 0, 0))); mesh.Add(mesh.MirrorY()); mesh.Add(mesh.MirrorZ()); return(mesh.Translate(origin)); }
public void IfCrashExistsTest() { bool actual, expected; var m = new Mesh(); m.Add(new Line(1, 5, 2)); m.Add(new Line(5, 7, 5)); m.Add(new Line(7, 4, 6)); m.Add(new Line(4, 3, 1)); m.Add(new Line(4, 6, 8)); m.Add(new Line(7, 6, 3)); m.Add(new Line(1, 2, 3)); m.Add(new Line(3, 2, 3)); m.Add(new Line(1, 3, 6)); m.Add(new Line(5, 6, 2)); Railway target = new Railway(m); target.ClearPaths(); // Scenario 1. Crash happens at the station target.AddPath(new uint[] { 1, 5, 7, 4, 3 }); target.AddPath(new uint[] { 3, 4, 7, 6 }); target.AddPath(new uint[] { 4, 6, 5, 1, 3 }); target.AddPath(new uint[] { 2, 1, 3, 4, 7 }); expected = true; actual = target.IfCrashExists(); Assert.AreEqual(expected, actual); target.ClearPaths(); // Scenario 2. Crash happens at the line target.AddPath(new uint[] { 3, 4, 7, 6 }); target.AddPath(new uint[] { 4, 6, 7, 5 }); target.AddPath(new uint[] { 2, 1, 3, 4, 7 }); actual = target.IfCrashExists(); Assert.AreEqual(expected, actual); target.ClearPaths(); // Scenario 3.1 There are no crashes target.AddPath(new uint[] { 3, 4, 7, 6 }); target.AddPath(new uint[] { 5, 6, 5, 1, 3 }); target.AddPath(new uint[] { 2, 1, 3, 4, 7 }); expected = false; actual = target.IfCrashExists(); Assert.AreEqual(expected, actual); target.ClearPaths(); // Scenario 3.2 There are no crashes (trans passing same line together) target.AddPath(new uint[] { 7, 6, 4, 3 }); target.AddPath(new uint[] { 5, 6, 4, 7 }); actual = target.IfCrashExists(); Assert.AreEqual(expected, actual); }
private void CreateMesh() { // Body var body = new Mesh(new List <Vector3>(), new List <Face>()); body.Add(Side(new Vector3(0.3f, -0.2f, 0), 0.5f, 1.7f, 0.7f, 1.1f, 1.2f)); body.Add(Side(new Vector3(0.3f, -0.2f, 0), 0.5f, 1.7f, 0.7f, 1.1f, 1.2f).MirrorX()); body.Add(Center(new Vector3(0, -0.2f, 0), 0.3f, 1.7f, 1.1f, 1.2f)); // Logos var logos = new Mesh(new List <Vector3>(), new List <Face>()); logos.Add(Logo(new Vector3(0.45f, 1, 0), 0.1f, 0.3f)); logos.Add(Logo(new Vector3(0.45f, 1, 0), 0.1f, 0.3f).MirrorX()); // Wheel covers var covers = new Mesh(new List <Vector3>(), new List <Face>()); covers.Add(WheelCover(new Vector3(1, 0, 0), 0.2f)); covers.Add(WheelCover(new Vector3(1, 0, 0), 0.2f).MirrorX()); // Wheels var wheels = new Mesh(new List <Vector3>(), new List <Face>()); wheels.Add(Wheel(new Vector3(1, 0, 0), 0.2f)); wheels.Add(Wheel(new Vector3(1, 0, 0), 0.2f).MirrorX()); // Sensors var sensors = new Mesh(new List <Vector3>(), new List <Face>()); sensors.Add(SensorCone(new Vector3(0.25f + 0.03646613f, 1.5f + 0.2068096f, 0), 300)); sensors.Add(SensorCone(new Vector3(0.25f + 0.03646613f, 1.5f + 0.2068096f, 0), 300).MirrorX()); // Sensor poles var poles = new Mesh(new List <Vector3>(), new List <Face>()); poles.Add(SensorPole().Translate(new Vector3(0.25f + 0.03646613f, 1.5f + 0.2068096f, 0))); poles.Add(SensorPole().Translate(new Vector3(0.25f + 0.03646613f, 1.5f + 0.2068096f, 0)).MirrorX()); mesh.Add(body); mesh.Add(logos); mesh.Add(covers); mesh.Add(wheels); mesh.Add(sensors); mesh.Add(poles); SetMesh(); ExportFile("Vehicle.obj", mesh.ExportObj()); ExportFile("Body.obj", body.ExportObj()); ExportFile("Logos.obj", logos.ExportObj()); ExportFile("WheelCovers.obj", covers.ExportObj()); ExportFile("WheelChassis.obj", Chassis(0.2f).ExportObj()); ExportFile("WheelTire.obj", Tire(0.2f).ExportObj()); ExportFile("SensorPoles.obj", poles.ExportObj()); }
public DynamicRelaxationSystem() { this.Nodes = new List <Node>(); this.Connectors = new List <Connector>(); this.Mesh = new List <MeshElement>(); Gravity = 0; double stiffness = 100; Nodes.Add(new Node(10, new Point3D(0, 0, 0)) { Fixed = true }); for (int i = 1; i < 10; i++) { Nodes.Add(new Node(10, new Point3D(i * 1000, 0, 0))); Connectors.Add(new Connector(Nodes[i - 1], Nodes[i]) { NaturalLength = 1000, Stiffness = stiffness }); } for (int i = 1; i < 10; i++) { Nodes.Add(new Node(10, new Point3D(0, i * 1000, 0))); Connectors.Add(new Connector(Nodes[i * 10], Nodes[(i - 1) * 10]) { NaturalLength = 1000, Stiffness = stiffness }); for (int j = 1; j < 10; j++) { Nodes.Add(new Node(10, new Point3D(j * 1000, i * 1000, 0))); Connectors.Add(new Connector(Nodes[i * 10 + j - 1], Nodes[i * 10 + j]) { NaturalLength = 1000, Stiffness = stiffness }); Connectors.Add(new Connector(Nodes[i * 10 + j], Nodes[(i - 1) * 10 + j]) { NaturalLength = 1000, Stiffness = stiffness }); Mesh.Add(new MeshElement((i - 1) * 10 + j - 1, (i - 1) * 10 + j, i * 10 + j - 1)); Mesh.Add(new MeshElement((i - 1) * 10 + j, i * 10 + j, i * 10 + j - 1)); } } Nodes[99].Position = new Point3D(Nodes[99].Position.X, Nodes[99].Position.Y, 0); Nodes[99].Fixed = true; Nodes[9].Position = new Point3D(Nodes[9].Position.X, Nodes[9].Position.Y, 0); Nodes[9].Fixed = true; Nodes[90].Position = new Point3D(Nodes[90].Position.X, Nodes[90].Position.Y, 0); Nodes[90].Fixed = true; double minX = Nodes.Min(a => a.Position.X); double minY = Nodes.Min(a => a.Position.Y); double maxX = Nodes.Max(a => a.Position.X); double maxY = Nodes.Max(a => a.Position.Y); foreach (var node in Nodes) { node.uvPoint = new Point((int)(node.Position.X - minX) / (maxX - minX), (node.Position.Y - minY) / (maxY - minY)); } }
static void Main(string[] args) { consumers.Add(new PrintConsumer()); // create some hardcoded bones List <BodyPart> parts = provider.Get(); // generate them List <Mesh> previous = new List <Mesh>(); Mesh total = new Mesh(); foreach (var item in parts) { Mesh generated = item.GenerateAndModify(previous, total); previous.Add(generated); total.Add(generated); } // send them to MeshConsumers foreach (var consumer in consumers) { foreach (var item in previous) { consumer.Accept(item, false); } consumer.Accept(total, true); } }
private static void InsertWavefrontVertex(Mesh <WavefrontVertex, EdgeBase, WavefrontFace> wavefrontMesh, IDictionary <VertexBase, List <WavefrontVertex> > wavefrontVertices, WavefrontVertex wavefrontVertex) { wavefrontMesh.Add(wavefrontVertex); TVertex figureVertex = wavefrontVertex.GraphVertex; if (!wavefrontVertices.ContainsKey(figureVertex)) { wavefrontVertices.Add(figureVertex, new List <WavefrontVertex>()); } wavefrontVertices[figureVertex].Add(wavefrontVertex); }
private Mesh Chassis(float width) { var vertices = new List <Vector3>(); var offset = new Vector3(width, 0, 0); vertices.AddRange(Octagon(offset, 0.1f)); vertices.AddRange(Octagon(-offset, 0.1f)); vertices.AddRange(Octagon(offset * 0.75f, 0.4f)); var faces = new List <Face>(); faces.AddRange(OctagonCoverFaces(new List <int> { 0, 1 })); vertices.Add(offset); faces.AddRange(OctagonFaces(24, new List <int> { 0, 1 })); vertices.Add(offset); faces.AddRange(OctagonFaces(25, new List <int> { 8, 9 }, true)); vertices.Add(offset * 0.75f); faces.AddRange(OctagonFaces(26, new List <int> { 16, 17 })); var mesh = new Mesh(vertices, faces); // mesh.Add(Spoke(origin, 0.15f, 0.4f, 0.05f).Rotate(Quaternion.Euler(22.5f, 0, 0))); // mesh.Add(Spoke(origin, 0.15f, 0.4f, 0.05f).Rotate(Quaternion.Euler(67.5f, 0, 0))); mesh.Add(mesh.MirrorY()); mesh.Add(mesh.MirrorZ()); return(mesh); }
private Mesh SensorPole() { var vertices = new List <Vector3>(); var offset = new Vector3(POLE_HEIGHT, 0, 0); vertices.AddRange(Octagon(offset, POLE_TOP_RADIUS)); vertices.AddRange(Octagon(-offset, POLE_BOTTOM_RADIUS)); var faces = new List <Face>(); faces.AddRange(OctagonCoverFaces(new List <int> { 0, 1 })); vertices.Add(offset * POLE_CAP); faces.AddRange(OctagonFaces(16, new List <int> { 0, 1 })); var mesh = new Mesh(vertices, faces); mesh.Add(mesh.MirrorY()); mesh.Add(mesh.MirrorZ()); return(mesh.Rotate(Quaternion.Euler(0, 0, POLE_ANGLE)).Translate(Quaternion.Euler(0, 0, POLE_ANGLE) * new Vector3(-POLE_HEIGHT * CONE_POSITION, 0, 0))); }
private void Skeletonize() { // Duplicate the figure, but convert the types of vertices and edges // and maintain a mapping from the triangulation vertices to the wavefront vertices. var wavefrontMesh = new Mesh <WavefrontVertex, EdgeBase, WavefrontFace>(); var wavefrontVertices = new Dictionary <VertexBase, List <WavefrontVertex> >(); foreach (TVertex v in figure.Vertices) { WavefrontVertex wavefrontVertex = new WavefrontVertex(v, new Vector2D()); wavefrontMesh.Add(wavefrontVertex); if (!wavefrontVertices.ContainsKey(v)) { wavefrontVertices.Add(v, new List <WavefrontVertex>()); } wavefrontVertices[v].Add(wavefrontVertex); } // Now insert the edges from the figure foreach (TEdge e in figure.Edges) { WavefrontVertex from = wavefrontVertices[e.Source].First(); WavefrontVertex to = wavefrontVertices[e.Target].First(); wavefrontMesh.AddEdge(from, to, new FigureEdge()); } // Triangulate the figure. All new edges inserted during the triangulation // are to be SpokeEdges. TODO: What about bounding-box edges? Algorithms.TriangulatePlanarSubdivision <WavefrontVertex, EdgeBase, WavefrontFace, TriangulationEdge>(wavefrontMesh, true); // Build the wavefront triangulation // - insert additional zero size triangles at the terminals of the figure // - split each edge of the figure along its length so that otherwise adjacent // triangles do not share an edge foreach (TVertex figureVertex in figure.Vertices) { // TODO: Ensure we pass the right vertex to the functions here if (figureVertex.Degree >= 2) { ProcessNonTerminalVertex(wavefrontMesh, wavefrontVertices, figureVertex); } else if (figureVertex.Degree == 1) { ProcessTerminalVertex(wavefrontMesh, wavefrontVertices, figureVertex); } } }
static public Mesh ImportFromFile(string path) { StreamReader sr = new StreamReader(path); StreamReader sr1 = new StreamReader(path); string s; string[] line = new string[4]; Mesh mesh = new Mesh(); List <Triangle> list = new List <Triangle>(); List <Vector3> vec = new List <Vector3>(); while ((s = sr.ReadLine()) != null) { line = s.Split(' '); if (line[0] == "v") { Vector3 vector = new Vector3(0.0f, 0.0f, 0.0f); vector.x = float.Parse(line[1], System.Globalization.CultureInfo.InvariantCulture); vector.y = float.Parse(line[2], System.Globalization.CultureInfo.InvariantCulture); vector.z = float.Parse(line[3], System.Globalization.CultureInfo.InvariantCulture); vec.Add(vector); } } while ((s = sr1.ReadLine()) != null) { line = s.Split(' '); int pom1, pom2, pom3; if (line[0] == "f") { pom1 = int.Parse(line[1]); pom2 = int.Parse(line[2]); pom3 = int.Parse(line[3]); pom1--; pom2--; pom3--; Triangle t = new Triangle(vec[pom1], vec[pom2], vec[pom3]); mesh.Add(t); } } sr.Close(); sr1.Close(); return(mesh); }
private Mesh SensorCone(Vector3 origin, float angle) { var divisions = (int)Math.Ceiling(angle / 45f); var segmentAngle = angle / divisions; var mesh = new Mesh(new List <Vector3>(), new List <Face>()); for (var i = 0; i < divisions; i++) { mesh.Add(SensorConeSegment(segmentAngle).Rotate(Quaternion.Euler(0, i * segmentAngle, 0))); } mesh.faces.Add(new Face(0, 5, 4)); mesh.faces.Add(new Face(1, 5, 0)); mesh.faces.Add(new Face((divisions - 1) * 7, (divisions - 1) * 7 + 2, (divisions - 1) * 7 + 3)); mesh.faces.Add(new Face((divisions - 1) * 7 + 1, (divisions - 1) * 7, (divisions - 1) * 7 + 3)); return(mesh.Rotate(Quaternion.Euler(0, angle / -2, 0)).Translate(origin)); }
private Mesh Side(Vector3 origin, float width, float height, float cornerDepth, float innerDepth, float upperDepth) { var vertices = new List <Vector3>(); vertices.Add(origin + new Vector3(width, 0, 0)); vertices.Add(origin + new Vector3(width, 0, cornerDepth)); vertices.Add(origin + new Vector3(0, 0, innerDepth)); vertices.Add(origin + new Vector3(0, height, 0)); vertices.Add(origin + new Vector3(0, height, upperDepth)); var faces = new List <Face>(); faces.Add(new Face(0, 3, 1)); faces.Add(new Face(1, 3, 4)); faces.Add(new Face(1, 4, 2)); faces.Add(new Face(2, 4, 2)); var mesh = new Mesh(vertices, faces); mesh.Add(mesh.MirrorZ()); return(mesh); }
private Mesh Center(Vector3 origin, float width, float height, float bottomDepth, float upperDepth) { var vertices = new List <Vector3>(); vertices.Add(origin + new Vector3(width, 0, bottomDepth)); vertices.Add(origin + new Vector3(-width, 0, bottomDepth)); vertices.Add(origin + new Vector3(width, height, upperDepth)); vertices.Add(origin + new Vector3(-width, height, upperDepth)); vertices.Add(origin + new Vector3(width, height, 0)); vertices.Add(origin + new Vector3(-width, height, 0)); var faces = new List <Face>(); faces.Add(new Face(0, 2, 1)); faces.Add(new Face(1, 2, 3)); faces.Add(new Face(2, 4, 5)); faces.Add(new Face(2, 5, 3)); var mesh = new Mesh(vertices, faces); mesh.Add(mesh.MirrorZ()); return(mesh); }
public Cuboid(double a = 1.0, double b = 1.0, double c = 1.0) { Name = "Cuboid"; double starta = -a / 2; double enda = a / 2; double startb = -b / 2; double endb = b / 2; double startc = -c / 2; double endc = c / 2; Mesh.Add(new Triangle(new Vector(starta, startb, startc), new Vector(starta, endb, startc), new Vector(enda, endb, startc))); Mesh.Add(new Triangle(new Vector(starta, startb, startc), new Vector(enda, endb, startc), new Vector(enda, startb, startc))); Mesh.Add(new Triangle(new Vector(enda, startb, startc), new Vector(enda, endb, startc), new Vector(enda, endb, endc))); Mesh.Add(new Triangle(new Vector(enda, startb, startc), new Vector(enda, endb, endc), new Vector(enda, startb, endc))); Mesh.Add(new Triangle(new Vector(enda, startb, endc), new Vector(enda, endb, endc), new Vector(starta, endb, endc))); Mesh.Add(new Triangle(new Vector(enda, startb, endc), new Vector(starta, endb, endc), new Vector(starta, startb, endc))); Mesh.Add(new Triangle(new Vector(starta, startb, endc), new Vector(starta, endb, endc), new Vector(starta, endb, startc))); Mesh.Add(new Triangle(new Vector(starta, startb, endc), new Vector(starta, endb, startc), new Vector(starta, startb, startc))); Mesh.Add(new Triangle(new Vector(starta, endb, startc), new Vector(starta, endb, endc), new Vector(enda, endb, endc))); Mesh.Add(new Triangle(new Vector(starta, endb, startc), new Vector(enda, endb, endc), new Vector(enda, endb, startc))); Mesh.Add(new Triangle(new Vector(enda, startb, endc), new Vector(starta, startb, endc), new Vector(starta, startb, startc))); Mesh.Add(new Triangle(new Vector(enda, startb, endc), new Vector(starta, startb, startc), new Vector(enda, startb, startc))); Color = Color.LightBlue; }
public Sphere(double r, int d1, int d2) { Name = "Sphere"; Color = Color.Orange; d1 += 1; Vector[,] sphere = new Vector[d1, d2]; double step1 = Math.PI / (d1 - 1); double step2 = 2 * Math.PI / d2; double lat = 0.0; double lon = 0.0; for (int i = 0; i < d1; i++) { for (int j = 0; j < d2; j++) { double x = r * Math.Sin(lon) * Math.Cos(lat); double y = r * Math.Sin(lon) * Math.Sin(lat); double z = r * Math.Cos(lon); Vector v = new Vector(x, y, z); sphere[i, j] = v; lat += step2; } lon += step1; } for (int i = 0; i < d1 - 1; i++) { for (int j = 0; j < d2; j++) { Triangle t1 = new Triangle(sphere[i, j], sphere[(i + 1) % d1, j], sphere[i, (j + 1) % d2]); Triangle t2 = new Triangle(sphere[i, (j + 1) % d2], sphere[(i + 1) % d1, j], sphere[(i + 1) % d1, (j + 1) % d2]); Mesh.Add(t1); Mesh.Add(t2); } } }
public Models(Matrix4x4 matWorld, Matrix4x4 matView, Matrix4x4 matpro, Vector3 Camera) { this.meshModelsProject = new Mesh(); Vector3 temp1 = new Vector3(), temp2 = new Vector3(), temp3 = new Vector3(); //lista posortowana List <Triangle> sortToRaster = new List <Triangle>(); Vector3 normal = new Vector3(), line1 = new Vector3(), line2 = new Vector3(); foreach (Triangle item in meshModels.lista) { Triangle transformed = new Triangle(temp1, temp2, temp3); Triangle translate = new Triangle(temp1, temp2, temp3); Triangle projected = new Triangle(temp1, temp2, temp3); Triangle triView = new Triangle(temp1, temp2, temp3); transformed.v1 = Vector3.Matrix_MultiplyVector(matWorld, item.v1); transformed.v2 = Vector3.Matrix_MultiplyVector(matWorld, item.v2); transformed.v3 = Vector3.Matrix_MultiplyVector(matWorld, item.v3); //obliczanie normalych line1 = Vector3.Vector_Sub(transformed.v2, transformed.v1); line2 = Vector3.Vector_Sub(transformed.v3, transformed.v1); normal = Vector3.Vectro_CrossPd(line1, line2); normal = Vector3.Vector_Normalise(normal); //normalne by wyswietlac te sciany co powinniśmy Vector3 cameraRay = Vector3.Vector_Sub(transformed.v1, Camera); if (Vector3.Vector_DotProduct(normal, cameraRay) < 0.0f) { //light Vector3 light = new Vector3(0.0f, 0.0f, -1.0f); //rotacja światła wraz z sceną light = Vector3.Matrix_MultiplyVector(matWorld, light); light = Vector3.Vector_Normalise(light); //iloczyn skalarny float dp = System.Math.Max(0.1f, Vector3.Vector_DotProduct(light, normal)); //przestrzen swiata--> przestrzen projektowana triView.v1 = Vector3.Matrix_MultiplyVector(matView, transformed.v1); triView.v2 = Vector3.Matrix_MultiplyVector(matView, transformed.v2); triView.v3 = Vector3.Matrix_MultiplyVector(matView, transformed.v3); //przycinanie trójkątów jeżeli sa za wielkie i za blisko ekranu Vector3 plane_p = new Vector3(0.0f, 0.0f, 0.1f); Vector3 plane_n = new Vector3(0.0f, 0.0f, 1.0f); List <Triangle> toClip = Triangle.ClipAgainstPlane(plane_p, plane_n, triView); int clippedTri = toClip.Count; for (int i = 0; i < clippedTri; i++) { projected.v1 = Vector3.Matrix_MultiplyVector(matpro, toClip[i].v1); projected.v2 = Vector3.Matrix_MultiplyVector(matpro, toClip[i].v2); projected.v3 = Vector3.Matrix_MultiplyVector(matpro, toClip[i].v3); projected.v1 = Vector3.Vector_Div(projected.v1, projected.v1.w); projected.v2 = Vector3.Vector_Div(projected.v2, projected.v2.w); projected.v3 = Vector3.Vector_Div(projected.v3, projected.v3.w); projected.v1.x *= -1.0f; projected.v1.y *= -1.0f; projected.v2.x *= -1.0f; projected.v2.y *= -1.0f; projected.v3.x *= -1.0f; projected.v3.y *= -1.0f; //początkowa translacja sceny Vector3 offserView = new Vector3(1.0f, 2.0f, 1.0f); projected.v1 = Vector3.Vector_Add(projected.v1, offserView); projected.v2 = Vector3.Vector_Add(projected.v2, offserView); projected.v3 = Vector3.Vector_Add(projected.v3, offserView); //skalowanie sceny projected.v1.x *= 0.5f * (float)1024; projected.v1.y *= 0.5f * (float)768; projected.v2.x *= 0.5f * (float)1024; projected.v2.y *= 0.5f * (float)768; projected.v3.x *= 0.5f * (float)1024; projected.v3.y *= 0.5f * (float)768; projected.dp = dp; sortToRaster.Add(projected); } } } List <Triangle> listtri = new List <Triangle>(); foreach (Triangle item in sortToRaster) { //ucinanie dla czterech krawędzi okna listtri.Clear(); listtri.Add(item); int newTri = 1; for (int i = 0; i < 4; i++) { while (newTri > 0) { //pierwsza z kolejki Triangle t = listtri.First(); listtri.RemoveAt(0); newTri--; List <Triangle> clippedTriangles = new List <Triangle>(); switch (i) { case 0: clippedTriangles = Triangle.ClipAgainstPlane(new Vector3(0.0f, 0.0f, 0.0f), new Vector3(0.0f, 1.0f, 0.0f), t); break; case 1: clippedTriangles = Triangle.ClipAgainstPlane(new Vector3(0.0f, 768 - 1, 0.0f), new Vector3(0.0f, -1.0f, 0.0f), t); break; case 2: clippedTriangles = Triangle.ClipAgainstPlane(new Vector3(0.0f, 0.0f, 0.0f), new Vector3(1.0f, 0.0f, 0.0f), t); break; case 3: clippedTriangles = Triangle.ClipAgainstPlane(new Vector3(1024 - 1, 0.0f, 0.0f), new Vector3(-1.0f, 0.0f, 0.0f), t); break; } foreach (Triangle item2 in clippedTriangles) { listtri.Add(item2); } } newTri = listtri.Count; } foreach (Triangle item3 in listtri) { meshModelsProject.Add(item3); } } meshModelsProject.Sort(); }
/// <summary> /// Create a physics mesh from data that comes with the prim. The actual data used depends on the prim type. /// </summary> /// <param name="primName"></param> /// <param name="primShape"></param> /// <param name="size"></param> /// <param name="lod"></param> /// <returns></returns> private Mesh CreateMeshFromPrimMesher(string primName, PrimitiveBaseShape primShape, float lod, bool convex) { // m_log.DebugFormat( // "[MESH]: Creating physics proxy for {0}, shape {1}", // primName, (OpenMetaverse.SculptType)primShape.SculptType); List<Coord> coords; List<Face> faces; if (primShape.SculptEntry) { if (((OpenMetaverse.SculptType)primShape.SculptType) == SculptType.Mesh) { if (!useMeshiesPhysicsMesh) return null; if (!GenerateCoordsAndFacesFromPrimMeshData(primName, primShape, out coords, out faces, convex)) return null; } else { if (!GenerateCoordsAndFacesFromPrimSculptData(primName, primShape, lod, out coords, out faces)) return null; } } else { if (!GenerateCoordsAndFacesFromPrimShapeData(primName, primShape, lod, out coords, out faces)) return null; } int numCoords = coords.Count; int numFaces = faces.Count; Mesh mesh = new Mesh(); // Add the corresponding triangles to the mesh for (int i = 0; i < numFaces; i++) { Face f = faces[i]; mesh.Add(new Triangle(coords[f.v1].X, coords[f.v1].Y, coords[f.v1].Z, coords[f.v2].X, coords[f.v2].Y, coords[f.v2].Z, coords[f.v3].X, coords[f.v3].Y, coords[f.v3].Z)); } coords.Clear(); faces.Clear(); if(mesh.numberVertices() < 3 || mesh.numberTriangles() < 1) { m_log.ErrorFormat("[MESH]: invalid degenerated mesh for prim " + primName + " ignored"); return null; } primShape.SculptData = Utils.EmptyBytes; return mesh; }
/// <summary> /// creates a simple box mesh of the specified size. This mesh is of very low vertex count and may /// be useful as a backup proxy when level of detail is not needed or when more complex meshes fail /// for some reason /// </summary> /// <param name="minX"></param> /// <param name="maxX"></param> /// <param name="minY"></param> /// <param name="maxY"></param> /// <param name="minZ"></param> /// <param name="maxZ"></param> /// <returns></returns> private static Mesh CreateSimpleBoxMesh(float minX, float maxX, float minY, float maxY, float minZ, float maxZ) { Mesh box = new Mesh(); List<Vertex> vertices = new List<Vertex>(); // bottom vertices.Add(new Vertex(minX, maxY, minZ)); vertices.Add(new Vertex(maxX, maxY, minZ)); vertices.Add(new Vertex(maxX, minY, minZ)); vertices.Add(new Vertex(minX, minY, minZ)); box.Add(new Triangle(vertices[0], vertices[1], vertices[2])); box.Add(new Triangle(vertices[0], vertices[2], vertices[3])); // top vertices.Add(new Vertex(maxX, maxY, maxZ)); vertices.Add(new Vertex(minX, maxY, maxZ)); vertices.Add(new Vertex(minX, minY, maxZ)); vertices.Add(new Vertex(maxX, minY, maxZ)); box.Add(new Triangle(vertices[4], vertices[5], vertices[6])); box.Add(new Triangle(vertices[4], vertices[6], vertices[7])); // sides box.Add(new Triangle(vertices[5], vertices[0], vertices[3])); box.Add(new Triangle(vertices[5], vertices[3], vertices[6])); box.Add(new Triangle(vertices[1], vertices[0], vertices[5])); box.Add(new Triangle(vertices[1], vertices[5], vertices[4])); box.Add(new Triangle(vertices[7], vertices[1], vertices[4])); box.Add(new Triangle(vertices[7], vertices[2], vertices[1])); box.Add(new Triangle(vertices[3], vertices[2], vertices[7])); box.Add(new Triangle(vertices[3], vertices[7], vertices[6])); return box; }
public void Init() { mesh = new Mesh <Vertex, EdgeBase, FaceBase>(false, true); v1 = new Vertex(3, 10); v2 = new Vertex(3, 6); v3 = new Vertex(6, 8); v4 = new Vertex(3, 3); v6 = new Vertex(13, 4); v7 = new Vertex(13, 11); mesh.Add(v1); mesh.Add(v2); edgeTwoToOne = mesh.AddEdge(v2, v1); edgeTwoToOne2 = mesh.AddEdge(v2, v1); edgeOneToTwo = mesh.AddEdge(v1, v2); mesh.Add(v3); edgeThreeToTwo = mesh.AddEdge(v3, v2); edgeTwoToThree = mesh.AddEdge(v2, v3); mesh.Add(v4); edgeFourToThree = mesh.AddEdge(v4, v3); mesh.Add(v7); mesh.Add(v6); edgeSevenToSix = mesh.AddEdge(v7, v6); v100 = new Vertex(101, 103); v101 = new Vertex(103, 103); v102 = new Vertex(108, 103); v103 = new Vertex(107, 103); v104 = new Vertex(109, 103); v105 = new Vertex(104, 101); v106 = new Vertex(106, 106); mesh.Add(v100); mesh.Add(v101); e100to101 = mesh.AddEdge(v100, v101); mesh.Add(v101); mesh.Add(v102); e101to102 = mesh.AddEdge(v101, v102); mesh.Add(v103); mesh.Add(v104); e103to104 = mesh.AddEdge(v103, v104); mesh.Add(v105); mesh.Add(v106); e105to106 = mesh.AddEdge(v105, v106); v200 = new Vertex(210, 180); v201 = new Vertex(90, 180); v202 = new Vertex(90, 60); mesh.Add(v200); mesh.Add(v201); mesh.Add(v202); e200to201 = mesh.AddEdge(v200, v201); e202to201 = mesh.AddEdge(v202, v201); v300 = new Vertex(210, 180); v301 = new Vertex(90, 180); v302 = new Vertex(90, 60); v303 = new Vertex(90, 170); mesh.Add(v300); mesh.Add(v301); mesh.Add(v302); mesh.Add(v303); e300to301 = mesh.AddEdge(v300, v301); e302to303 = mesh.AddEdge(v302, v303); comparer = new LeftToRightEdgeComparer(); }
public BasicAttach(byte[] file, int address, uint imageBase, bool DX, Dictionary <int, string> labels) : this() { if (labels.ContainsKey(address)) { Name = labels[address]; } else { Name = "attach_" + address.ToString("X8"); } Vertex = new Vertex[ByteConverter.ToInt32(file, address + 8)]; Normal = new Vertex[Vertex.Length]; int tmpaddr = (int)(ByteConverter.ToUInt32(file, address) - imageBase); if (labels.ContainsKey(tmpaddr)) { VertexName = labels[tmpaddr]; } else { VertexName = "vertex_" + tmpaddr.ToString("X8"); } for (int i = 0; i < Vertex.Length; i++) { Vertex[i] = new Vertex(file, tmpaddr); tmpaddr += SAModel.Vertex.Size; } tmpaddr = ByteConverter.ToInt32(file, address + 4); if (tmpaddr != 0) { tmpaddr = (int)((uint)tmpaddr - imageBase); if (labels.ContainsKey(tmpaddr)) { NormalName = labels[tmpaddr]; } else { NormalName = "normal_" + tmpaddr.ToString("X8"); } for (int i = 0; i < Vertex.Length; i++) { Normal[i] = new Vertex(file, tmpaddr); tmpaddr += SAModel.Vertex.Size; } } else { for (int i = 0; i < Vertex.Length; i++) { Normal[i] = new Vertex(0, 1, 0); } } int maxmat = -1; int meshcnt = ByteConverter.ToInt16(file, address + 0x14); tmpaddr = ByteConverter.ToInt32(file, address + 0xC); if (tmpaddr != 0) { tmpaddr = (int)unchecked ((uint)tmpaddr - imageBase); if (labels.ContainsKey(tmpaddr)) { MeshName = labels[tmpaddr]; } else { MeshName = "meshlist_" + tmpaddr.ToString("X8"); } for (int i = 0; i < meshcnt; i++) { Mesh.Add(new NJS_MESHSET(file, tmpaddr, imageBase, labels)); maxmat = Math.Max(maxmat, Mesh[i].MaterialID); tmpaddr += NJS_MESHSET.Size(DX); } } // fixes case where model declares material array as shorter than it really is int matcnt = Math.Max(ByteConverter.ToInt16(file, address + 0x16), maxmat + 1); tmpaddr = ByteConverter.ToInt32(file, address + 0x10); if (tmpaddr != 0) { tmpaddr = (int)unchecked ((uint)tmpaddr - imageBase); if (labels.ContainsKey(tmpaddr)) { MaterialName = labels[tmpaddr]; } else { MaterialName = "matlist_" + tmpaddr.ToString("X8"); } for (int i = 0; i < matcnt; i++) { Material.Add(new NJS_MATERIAL(file, tmpaddr, labels)); tmpaddr += NJS_MATERIAL.Size; } } Bounds = new BoundingSphere(file, address + 0x18); }
/// <summary> /// Create a physics mesh from data that comes with the prim. The actual data used depends on the prim type. /// </summary> /// <param name="primName"></param> /// <param name="primShape"></param> /// <param name="size"></param> /// <param name="lod"></param> /// <returns></returns> private Mesh CreateMeshFromPrimMesher(string primName, PrimitiveBaseShape primShape, Vector3 size, float lod) { // m_log.DebugFormat( // "[MESH]: Creating physics proxy for {0}, shape {1}", // primName, (OpenMetaverse.SculptType)primShape.SculptType); List<Coord> coords; List<Face> faces; if (primShape.SculptEntry) { if (((OpenMetaverse.SculptType)primShape.SculptType) == SculptType.Mesh) { if (!useMeshiesPhysicsMesh) return null; if (!GenerateCoordsAndFacesFromPrimMeshData(primName, primShape, size, out coords, out faces)) return null; } else { if (!GenerateCoordsAndFacesFromPrimSculptData(primName, primShape, size, lod, out coords, out faces)) return null; } } else { if (!GenerateCoordsAndFacesFromPrimShapeData(primName, primShape, size, lod, out coords, out faces)) return null; } // Remove the reference to any JPEG2000 sculpt data so it can be GCed primShape.SculptData = Utils.EmptyBytes; int numCoords = coords.Count; int numFaces = faces.Count; // Create the list of vertices List<Vertex> vertices = new List<Vertex>(); for (int i = 0; i < numCoords; i++) { Coord c = coords[i]; vertices.Add(new Vertex(c.X, c.Y, c.Z)); } Mesh mesh = new Mesh(); // Add the corresponding triangles to the mesh for (int i = 0; i < numFaces; i++) { Face f = faces[i]; mesh.Add(new Triangle(vertices[f.v1], vertices[f.v2], vertices[f.v3])); } return mesh; }
static void Main(string[] args) { var scene = new Scene { Background = new Color(255, 0, 255).ToInt(), Name = "My Scene" }; var verts = new List <float[]> { new float[] { 0, 0, 0 }, new float[] { 0, 0, 10.1234f }, new float[] { 10, 0, 10 }, new float[] { 10, 0, 0 } }; var norms = new List <float[]> { new float[] { 0, 1, 0 }, new float[] { 0, 1, 0 }, new float[] { 0, 1, 0 }, new float[] { 0, 1, 0 } }; var vertices = Utilities.Flatten(verts).Cast <float>().ToList();//Geometry.ProcessVertexArray(verts); var normals = Utilities.Flatten(norms).Cast <float>().ToList(); var face1 = new int[] { 0, 1, 2 }; var face2 = new int[] { 0, 2, 3 }; var faces = Geometry.ProcessFaceArray(new List <int[]> { { face1 }, { face2 } }, false, false); var geometry = new Geometry(vertices, faces, normals); var geometry2 = new Geometry(vertices, faces, normals); var material = MeshStandardMaterial.Default(); var mesh = new Mesh { Geometry = geometry2, Material = material, Name = "My Mesh" }; //scene.Add(mesh); var material2 = MeshStandardMaterial.Default(); material2.Roughness = 0.25; var mesh2 = new Mesh { Geometry = geometry, Material = material2, Position = new Vector3(20, 20, 20), Name = "My Mesh2" }; //scene.Add(mesh2); var material3 = MeshStandardMaterial.Default(); var mesh3 = new Mesh { Geometry = geometry2, Material = material3, Position = new Vector3(30, 30, 30), Name = "My Mesh3" }; //scene.Add(mesh3); var line = new Line { Geometry = new Geometry(vertices), Material = new LineBasicMaterial { Color = new Color(255, 0, 0).ToInt(), LineWidth = 20 }, Name = "My Curves" }; //scene.Add(line); var colors = new List <int> { 255, 0, 0, 255, 255, 0, 255, 0, 255, 0, 255, 0 }; var pointsGeometry = new BufferGeometry { Attributes = { { "position", new BufferAttribute { Array = vertices.Cast <object>().ToArray(), ItemSize = 3, Type = "Float32Array" } }, { "color", new BufferAttribute { Array = colors.Cast <object>().ToArray(), ItemSize = 3, Type = "Uint8Array" } } }, BoundingSphere = new BufferGeometryBoundingSphere { Center = new float[] { 0, 0, 0 }, Radius = 4 } }; var points = new Points { Geometry = pointsGeometry, Material = new PointsMaterial { VertexColors = VertexColors.Vertex, Size = 10 }, Name = "My Points" }; //scene.Add(points); var points2 = new Points { Geometry = pointsGeometry, Material = new PointsMaterial { VertexColors = VertexColors.Vertex, Size = 10 }, Name = "My Points2" }; //scene.Add(points2); var verts2 = new List <float[]> { new float[] { 0, 0, 0 }, new float[] { 0, 0, 10 }, new float[] { 10, 0, 10 }, new float[] { 0, 0, 0 }, new float[] { 10, 0, 10 }, new float[] { 10, 0, 0 } }; var norms2 = new List <float[]> { new float[] { 0, 1, 0 }, new float[] { 0, 1, 0 }, new float[] { 0, 1, 0 }, new float[] { 0, 1, 0 }, new float[] { 0, 1, 0 }, new float[] { 0, 1, 0 } }; var color2 = new List <float[]> { new float[] { 0, 0, 255 }, new float[] { 0, 0, 255 }, new float[] { 0, 0, 255 }, new float[] { 255, 0, 0 }, new float[] { 255, 0, 0 }, new float[] { 255, 0, 0 }, }; var uv2 = new List <float[]> { new float[] { 0, 0 }, new float[] { 1, 0.5f }, new float[] { 1, 0 }, new float[] { 0, 0 }, new float[] { 0.5f, 1 }, new float[] { 1, 0.5f } }; var meshBG = new BufferGeometry { Attributes = { { "position", new BufferAttribute { Array = Utilities.OptimizeFloats(Utilities.Flatten(verts2).Cast <float>()).ToArray(), ItemSize = 3, Type = BufferAttributeType.Float32Array.ToString() } }, { "normal", new BufferAttribute { Array = Utilities.Flatten(norms2), ItemSize = 3, Type = BufferAttributeType.Float32Array.ToString() } }, { "uv", new BufferAttribute { Array = Utilities.Flatten(uv2), ItemSize = 2, Type = BufferAttributeType.Float32Array.ToString() } }, { "color", new BufferAttribute { Array = Utilities.Flatten(color2), ItemSize = 3, Type = BufferAttributeType.Float32Array.ToString() } } }, BoundingSphere = new BufferGeometryBoundingSphere { Center = new float[] { 0, 0, 0 }, Radius = 5 } }; var mesh6 = new Mesh { Geometry = meshBG, Material = MeshStandardMaterial.Default(), Name = "MeshfromBufferGeo" }; (mesh6.Material as MeshStandardMaterial).VertexColors = VertexColors.Vertex; //scene.Add(mesh6); var verts3 = new object[] { 0, 0, 0, 0, 0, 10, 10, 0, 10, 10, 0, 0 }; var indexes = new object[] { 0, 1, 2, 0, 2, 3 }; var norms3 = new object[] { 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0 }; var color3 = new object[] { 0, 0, 255, 0, 0, 255, 0, 0, 255, 255, 0, 0, 255, 0, 0, 255, 0, 0, }; var uv3 = new object[] { 0, 0, 1, 0.5, 1, 0, 0, 0, 0.5, 1, 1, 0.5 }; var meshIBG = new BufferGeometry { Attributes = { { "position", new BufferAttribute { Array = verts3, ItemSize = 3, Type = BufferAttributeType.Float32Array.ToString() } }, { "index", new BufferAttribute { Array = indexes, ItemSize = 1, Type = BufferAttributeType.Int8Array.ToString() } }, { "normal", new BufferAttribute { Array = norms3, ItemSize = 3, Type = BufferAttributeType.Float32Array.ToString() } }, { "uv", new BufferAttribute { Array = uv3, ItemSize = 2, Type = BufferAttributeType.Float32Array.ToString() } }, { "color", new BufferAttribute { Array = color3, ItemSize = 3, Type = BufferAttributeType.Float32Array.ToString() } } }, BoundingSphere = new BufferGeometryBoundingSphere { Center = new float[] { 0, 0, 0 }, Radius = 5 } }; var mesh7 = new Mesh { Geometry = meshIBG, Material = MeshStandardMaterial.Default(), Name = "MeshfromIndexedBufferGeo" }; (mesh7.Material as MeshStandardMaterial).VertexColors = VertexColors.Vertex; //scene.Add(mesh7); var mesh4 = new Mesh { Geometry = geometry2, Material = material3, Position = new Vector3(30, 30, 30), Name = "My Mesh4" }; var sphereGeoAsChild = new SphereBufferGeometry { Radius = 3, WidthSegments = 22, HeightSegments = 22, PhiStart = 0, PhiLength = (float)Math.PI * 2, ThetaStart = 0, ThetaLength = (float)Math.PI * 2 }; var sphereMeshAsChild = new Mesh { Geometry = sphereGeoAsChild, Material = material, Position = new Vector3(-45, 10, 45), Name = "My Sphere as a Child" }; mesh4.Add(sphereMeshAsChild); //scene.Add(mesh4); var group = new Group(); group.Add(mesh3); group.Add(mesh2); group.Add(mesh); //scene.Add(group); var group2 = new Group(); group2.Add(mesh3); group2.Add(mesh2); group2.Add(mesh); //scene.Add(group2); var sphereGeometry = new SphereBufferGeometry { Radius = 10, WidthSegments = 10, HeightSegments = 5, PhiStart = 0, PhiLength = (float)Math.PI * 2, ThetaStart = 0, ThetaLength = (float)Math.PI * 2 }; var sphereMesh = new Mesh { Geometry = sphereGeometry, Material = material, Position = new Vector3(-45, 10, 45), Name = "My Sphere" }; //scene.Add(sphereMesh); #region Lights var pointLight = new PointLight { Color = new Color(100, 100, 100).ToInt(), Decay = 1, Intensity = 3, Name = "My PointLight", Position = new Vector3(10, 10, 10) }; //scene.Add(pointLight); var ambientLight = new AmbientLight { Color = new Color(255, 0, 255).ToInt(), Intensity = 5, Name = "My AmbientLight" }; //scene.Add(ambientLight); var targetObject = new Object3D { Position = new Vector3(3, 0, 0) }; scene.Add(targetObject); var directionalLight = new DirectionalLight { Target = targetObject, Position = new Vector3(-10, 10, 5), Name = "My DirectionalLight" }; scene.Add(directionalLight); var spotLight = new SpotLight { Target = new Object3D { Position = new Vector3(3, 0, 3) }, Position = new Vector3(20, 20, 0), Name = "My SpotLight" }; //scene.Add(spotLight); var hemiLight = new HemisphereLight { SkyColor = new Color(0, 30, 255).ToInt(), GroundColor = new Color(30, 30, 30).ToInt(), Name = "My HemisphereLight" }; //scene.Add(hemiLight); #endregion //Console.WriteLine(geometry.ToJSON(true)); Console.WriteLine(scene.ToJSON(false)); Console.ReadLine(); }
private Mesh BuildIcosahedron(float radius, Vec4 color) { Mesh ico20 = new Mesh(); //The golden ratio float t = (1 + (float)Math.Sqrt(5)) / 2; //Define the points needed to build a icosahedron, stolen from article Vec3[] vecs = new Vec3[12]; vecs[0] = new Vec3(-radius, t * radius, 0).Normal(); vecs[1] = new Vec3(radius, t * radius, 0).Normal(); vecs[2] = new Vec3(-radius, -t * radius, 0).Normal(); vecs[3] = new Vec3(radius, -t * radius, 0).Normal(); vecs[4] = new Vec3(0, -radius, t * radius).Normal(); vecs[5] = new Vec3(0, radius, t * radius).Normal(); vecs[6] = new Vec3(0, -radius, -t * radius).Normal(); vecs[7] = new Vec3(0, radius, -t * radius).Normal(); vecs[8] = new Vec3(t * radius, 0, -radius).Normal(); vecs[9] = new Vec3(t * radius, 0, radius).Normal(); vecs[10] = new Vec3(-t * radius, 0, -radius).Normal(); vecs[11] = new Vec3(-t * radius, 0, radius).Normal(); // 5 faces around point 0 ico20.Add(new Tri(vecs[0], vecs[11], vecs[5], color)); ico20.Add(new Tri(vecs[0], vecs[5], vecs[1], color)); ico20.Add(new Tri(vecs[0], vecs[1], vecs[7], color)); ico20.Add(new Tri(vecs[0], vecs[7], vecs[10], color)); ico20.Add(new Tri(vecs[0], vecs[10], vecs[11], color)); // 5 adjacent faces ico20.Add(new Tri(vecs[1], vecs[5], vecs[9], color)); ico20.Add(new Tri(vecs[5], vecs[11], vecs[4], color)); ico20.Add(new Tri(vecs[11], vecs[10], vecs[2], color)); ico20.Add(new Tri(vecs[10], vecs[7], vecs[6], color)); ico20.Add(new Tri(vecs[7], vecs[1], vecs[8], color)); // 5 faces around point 3 ico20.Add(new Tri(vecs[3], vecs[9], vecs[4], color)); ico20.Add(new Tri(vecs[3], vecs[4], vecs[2], color)); ico20.Add(new Tri(vecs[3], vecs[2], vecs[6], color)); ico20.Add(new Tri(vecs[3], vecs[6], vecs[8], color)); ico20.Add(new Tri(vecs[3], vecs[8], vecs[9], color)); // 5 adjacent faces ico20.Add(new Tri(vecs[4], vecs[9], vecs[5], color)); ico20.Add(new Tri(vecs[2], vecs[4], vecs[11], color)); ico20.Add(new Tri(vecs[6], vecs[2], vecs[10], color)); ico20.Add(new Tri(vecs[8], vecs[6], vecs[7], color)); ico20.Add(new Tri(vecs[9], vecs[8], vecs[1], color)); return(ico20); }
//vMarchCube1 performs the Marching Cubes algorithm on a single cube // TODO: Find out if what I am doing in this is correct void MarchCube1(int X, int Y, int Z) { int iCorner, iVertex, iVertexTest, iEdge, iTriangle, iFlagIndex, iEdgeFlags = 0; float fOffset; Vector3 sColor; bool[] afCubeValue = new bool[8]; Vertex[] asEdgeVertex = new Vertex[12]; Vector3[] asEdgeNorm = new Vector3[12]; //Make a local copy of the values at the cube's corners for (iVertex = 0; iVertex < 8; iVertex++) { afCubeValue[iVertex] = Sample(X + (int)a2fVertexOffset[iVertex].X, Y + (int)a2fVertexOffset[iVertex].Y, Z + (int)a2fVertexOffset[iVertex].Z); } //Find which vertices are inside of the surface and which are outside iFlagIndex = 0; for (iVertexTest = 0; iVertexTest < 8; iVertexTest++) { if (afCubeValue[iVertexTest]) { iFlagIndex |= 1 << iVertexTest; } } //Find which edges are intersected by the surface iEdgeFlags = m_edgeTable[iFlagIndex]; //If the cube is entirely inside or outside of the surface, then there will be no intersections if (iEdgeFlags == 0) { return; } //Find the point of intersection of the surface with each edge //Then find the normal to the surface at those points for (iEdge = 0; iEdge < 12; iEdge++) { //if there is an intersection on this edge int flagval = (1 << iEdge); if ((iEdgeFlags & flagval) == flagval) { fOffset = fGetOffset(afCubeValue[a2iEdgeConnection[iEdge][0]] ? 1f : 0f, afCubeValue[a2iEdgeConnection[iEdge][1]] ? 1f : 0f, 0.5f); asEdgeVertex[iEdge].X = X + (a2fVertexOffset[a2iEdgeConnection[iEdge][0]].X + fOffset * a2fEdgeDirection[iEdge].X); asEdgeVertex[iEdge].Y = Y + (a2fVertexOffset[a2iEdgeConnection[iEdge][0]].Y + fOffset * a2fEdgeDirection[iEdge].Y); asEdgeVertex[iEdge].Z = Z + (a2fVertexOffset[a2iEdgeConnection[iEdge][0]].Z + fOffset * a2fEdgeDirection[iEdge].Z); asEdgeNorm[iEdge] = vGetNormal((int)asEdgeVertex[iEdge].X, (int)asEdgeVertex[iEdge].Y, (int)asEdgeVertex[iEdge].Z); } } //Draw the triangles that were found. There can be up to five per cube for (iTriangle = 0; iTriangle < 5; iTriangle++) { if (m_triTable[iFlagIndex][3 * iTriangle] < 0) { break; } // Hello I am N3X15 and I am lost Vertex[] hurr = new Vertex[3]; for (iCorner = 0; iCorner < 3; iCorner++) { iVertex = m_triTable[iFlagIndex][3 * iTriangle + iCorner]; /* * vGetColor(sColor, asEdgeVertex[iVertex], asEdgeNorm[iVertex]); * glColor3f(sColor.fX, sColor.fY, sColor.fZ); * glNormal3f(asEdgeNorm[iVertex].fX, asEdgeNorm[iVertex].fY, asEdgeNorm[iVertex].fZ); * glVertex3f(asEdgeVertex[iVertex].fX, asEdgeVertex[iVertex].fY, asEdgeVertex[iVertex].fZ); */ hurr[iCorner] = asEdgeVertex[iVertex]; } mMesh.Add(new Triangle(hurr[0], hurr[1], hurr[2])); } }