public static List<DrawableFixture> GetDrawableFixtures() { List<DrawableFixture> drawables = new List<DrawableFixture>(); // MainForm progress MainForm.Log("Preparing fixtures ...", MainForm.LogLevel.notice); MainForm.ProgressStart("Preparing fixtures ..."); int progressCounter = 0; foreach (FixtureRow fixtureRow in fixtureRows) { try { NifRow nifRow = nifRows.Where(n => n.NifId == fixtureRow.NifId).FirstOrDefault(); if (nifRow == null) continue; DrawableFixture fixture = new DrawableFixture(); // Set default values fixture.Name = fixtureRow.TextualName; fixture.NifName = nifRow.Filename; fixture.FixtureRow = fixtureRow; fixture.ZoneConf = zoneConf; // Get renderer configuration FixtureRendererConfiguration2? rConf = FixtureRendererConfigurations.GetFixtureRendererConfiguration(nifRow.Filename); fixture.IsTree = treeRows.Any(t => t.Name.ToLower() == nifRow.Filename.ToLower()); fixture.IsTreeCluster = treeClusterRows.Any(tc => tc.Name.ToLower() == nifRow.Filename.ToLower()); if (rConf != null && (rConf.Value.Name == "TreeShaded" || rConf.Value.Name == "TreeImage")) { fixture.IsTree = true; } if (fixture.IsTree) { fixture.Tree = treeRows.Where(tc => tc.Name.ToLower() == nifRow.Filename.ToLower()).FirstOrDefault(); fixture.RawPolygons = nifRow.Polygons; if (rConf == null) fixture.RendererConf = FixtureRendererConfigurations.GetRendererById("TreeImage"); else fixture.RendererConf = rConf.GetValueOrDefault(); } else if (fixture.IsTreeCluster) { fixture.TreeCluster = treeClusterRows.Where(tc => tc.Name.ToLower() == nifRow.Filename.ToLower()).FirstOrDefault(); // Get the polygons of the base nif var treeNif = nifRows.Where(n => n.Filename.ToLower() == fixture.TreeCluster.Tree.ToLower()).FirstOrDefault(); if (treeNif == null) continue; Polygon[] baseTreePolygons = treeNif.Polygons; // Loop the instances and transform the polygons List<Polygon> treeClusterPolygons = new List<Polygon>(); foreach (SharpDX.Vector3 tree in fixture.TreeCluster.TreeInstances) { foreach (Polygon treePolygon in baseTreePolygons) { Polygon newPolygon = new Polygon(treePolygon.P1, treePolygon.P2, treePolygon.P3); for (int i = 0; i < newPolygon.Vectors.Length; i++) { newPolygon.Vectors[i].X -= tree.X; newPolygon.Vectors[i].Y += tree.Y; newPolygon.Vectors[i].Z += tree.Z; } treeClusterPolygons.Add(newPolygon); } } fixture.RawPolygons = treeClusterPolygons; if (rConf == null) fixture.RendererConf = FixtureRendererConfigurations.GetRendererById("TreeImage"); else fixture.RendererConf = rConf.GetValueOrDefault(); } else { fixture.RawPolygons = nifRow.Polygons; if (rConf == null) { string nifFilenamWithoutExtension = Path.GetFileNameWithoutExtension(fixture.NifName); if (nifObjectImages.Contains(nifFilenamWithoutExtension.ToLower())) { fixture.RendererConf = FixtureRendererConfigurations.GetRendererById("Prerendered"); } else { fixture.RendererConf = FixtureRendererConfigurations.DefaultConfiguration; } } else fixture.RendererConf = rConf.GetValueOrDefault(); } // Calculate the final look of the model fixture.Calc(); drawables.Add(fixture); progressCounter++; int percent = 100 * progressCounter / fixtureRows.Count; MainForm.ProgressUpdate(percent); } catch { // TODO: Send meesage to client MainForm.Log(string.Format("Error in fixture row of {0} (x: {1}, y: {2}, z: {3})", fixtureRow.TextualName, fixtureRow.X, fixtureRow.Y, fixtureRow.Z)); continue; } } MainForm.Log("Fixtures prepared!", MainForm.LogLevel.success); MainForm.ProgressReset(); return drawables; }
private void TransformPolygons() { Scale = ((FixtureRow.Scale / 100f) * ZoneConf.LocScale); double angle = 360d * FixtureRow.AxisZ3D - FixtureRow.A; if (ZoneConf.ZoneId == "330" || ZoneConf.ZoneId == "334" || ZoneConf.ZoneId == "335") { angle = (360 - FixtureRow.A) * FixtureRow.AxisZ3D; } Matrix rotation = Matrix.Identity; if (angle != 0) { rotation *= Matrix.RotationZ(Convert.ToSingle(angle * Math.PI / 180.0)); } foreach (Polygon poly in RawPolygons) { Vector3 p1 = Vector3.TransformCoordinate(poly.P1, rotation); Vector3 p2 = Vector3.TransformCoordinate(poly.P2, rotation); Vector3 p3 = Vector3.TransformCoordinate(poly.P3, rotation); if (Scale != 1) { p1.X *= (float)Scale; p1.Y *= (float)Scale; p1.Z *= (float)Scale; p2.X *= (float)Scale; p2.Y *= (float)Scale; p2.Z *= (float)Scale; p3.X *= (float)Scale; p3.Y *= (float)Scale; p3.Z *= (float)Scale; } // Check visibility of polygons Polygon newPolygon = new Polygon(p1, p2, p3); if (PolygonArea(newPolygon.Vectors) > 0.01) { ProcessedPolygons.Add(newPolygon); } } }
private void computePolys(Triangle[] trianlges, Vector3[] vertices, Matrix transformation) { // Transaform all vertices List<Vector3> verticesTransformed = new List<Vector3>(); foreach (Vector3 vector in vertices) verticesTransformed.Add(Vector3.TransformCoordinate(vector, transformation)); foreach (Triangle triangle in trianlges) { Polygon poly = new Polygon( new Vector3(verticesTransformed[triangle.X].X, verticesTransformed[triangle.X].Y, verticesTransformed[triangle.X].Z), new Vector3(verticesTransformed[triangle.Y].X, verticesTransformed[triangle.Y].Y, verticesTransformed[triangle.Y].Z), new Vector3(verticesTransformed[triangle.Z].X, verticesTransformed[triangle.Z].Y, verticesTransformed[triangle.Z].Z) ); m_polys.Add(poly); } }