private static Face ReadFace(GenericStructure side, IDGenerator generator) { var id = side.PropertyLong("id"); if (id == 0) { id = generator.GetNextFaceID(); } var dispinfo = side.GetChildren("dispinfo").FirstOrDefault(); var ret = dispinfo != null?ReadDisplacement(id, dispinfo) : new Face(id); // id, plane, material, uaxis, vaxis, rotation, lightmapscale, smoothing_groups var uaxis = side.PropertyTextureAxis("uaxis"); var vaxis = side.PropertyTextureAxis("vaxis"); ret.Texture.Name = side["material"]; ret.Texture.UAxis = uaxis.Item1; ret.Texture.XShift = uaxis.Item2; ret.Texture.XScale = uaxis.Item3; ret.Texture.VAxis = vaxis.Item1; ret.Texture.YShift = vaxis.Item2; ret.Texture.YScale = vaxis.Item3; ret.Texture.Rotation = side.PropertyDecimal("rotation"); ret.Plane = side.PropertyPlane("plane"); //NOTE(SVK) Paste RF data ret.Texture.Flags = (FaceFlags)side.PropertyInteger("flags"); ret.Texture.Translucency = (int)side.PropertyDecimal("translucency"); ret.Texture.Opacity = side.PropertyDecimal("opacity"); ret.Texture.PositionRF = side.PropertyCoordinate("positionrf"); ret.Texture.TransformAngleRF = side.PropertyMatrix("transformanglerf"); var verts = side.Children.FirstOrDefault(x => x.Name == "vertex"); if (verts != null) { var count = verts.PropertyInteger("count"); for (var i = 0; i < count; i++) { ret.Vertices.Add(new Vertex(verts.PropertyCoordinate("vertex" + i), ret)); } } return(ret); }
private static Entity ReadEntity(GenericStructure entity, IDGenerator generator) { var ret = new Entity(GetObjectID(entity, generator)) { ClassName = entity["classname"], EntityData = ReadEntityData(entity), Origin = entity.PropertyCoordinate("origin") }; var editor = entity.GetChildren("editor").FirstOrDefault() ?? new GenericStructure("editor"); ret.Colour = editor.PropertyColour("color", Colour.GetRandomBrushColour()); ret.Visgroups.AddRange(editor.GetAllPropertyValues("visgroupid").Select(int.Parse).Where(x => x > 0)); foreach (var child in entity.GetChildren("solid").Select(solid => ReadSolid(solid, generator)).Where(s => s != null)) { child.SetParent(ret, false); } ret.UpdateBoundingBox(false); return(ret); }
private static Displacement ReadDisplacement(long id, GenericStructure dispinfo) { var disp = new Displacement(id); // power, startposition, flags, elevation, subdiv, normals{}, distances{}, // offsets{}, offset_normals{}, alphas{}, triangle_tags{}, allowed_verts{} disp.SetPower(dispinfo.PropertyInteger("power", 3)); disp.StartPosition = dispinfo.PropertyCoordinate("startposition"); disp.Elevation = dispinfo.PropertyDecimal("elevation"); disp.SubDiv = dispinfo.PropertyInteger("subdiv") > 0; var size = disp.Resolution + 1; var normals = dispinfo.GetChildren("normals").FirstOrDefault(); var distances = dispinfo.GetChildren("distances").FirstOrDefault(); var offsets = dispinfo.GetChildren("offsets").FirstOrDefault(); var offsetNormals = dispinfo.GetChildren("offset_normals").FirstOrDefault(); var alphas = dispinfo.GetChildren("alphas").FirstOrDefault(); //var triangleTags = dispinfo.GetChildren("triangle_tags").First(); //var allowedVerts = dispinfo.GetChildren("allowed_verts").First(); for (var i = 0; i < size; i++) { var row = "row" + i; var norm = normals != null?normals.PropertyCoordinateArray(row, size) : Enumerable.Range(0, size).Select(x => Coordinate.Zero).ToArray(); var dist = distances != null?distances.PropertyDecimalArray(row, size) : Enumerable.Range(0, size).Select(x => 0m).ToArray(); var offn = offsetNormals != null?offsetNormals.PropertyCoordinateArray(row, size) : Enumerable.Range(0, size).Select(x => Coordinate.Zero).ToArray(); var offs = offsets != null?offsets.PropertyDecimalArray(row, size) : Enumerable.Range(0, size).Select(x => 0m).ToArray(); var alph = alphas != null?alphas.PropertyDecimalArray(row, size) : Enumerable.Range(0, size).Select(x => 0m).ToArray(); for (var j = 0; j < size; j++) { disp.Points[i, j].Displacement = new Vector(norm[j], dist[j]); disp.Points[i, j].OffsetDisplacement = new Vector(offn[j], offs[j]); disp.Points[i, j].Alpha = alph[j]; } } return(disp); }
private static Entity ReadEntity(GenericStructure entity, IDGenerator generator) { var ret = new Entity(GetObjectID(entity, generator)) { ClassName = entity["classname"], EntityData = ReadEntityData(entity), Origin = entity.PropertyCoordinate("origin") }; var editor = entity.GetChildren("editor").FirstOrDefault() ?? new GenericStructure("editor"); ret.Colour = editor.PropertyColour("color", Colour.GetRandomBrushColour()); ret.Visgroups.AddRange(editor.GetAllPropertyValues("visgroupid").Select(int.Parse)); foreach (var child in entity.GetChildren("solid").Select(solid => ReadSolid(solid, generator)).Where(s => s != null)) { child.SetParent(ret); } ret.UpdateBoundingBox(false); return ret; }
private static Displacement ReadDisplacement(long id, GenericStructure dispinfo) { var disp = new Displacement(id); // power, startposition, flags, elevation, subdiv, normals{}, distances{}, // offsets{}, offset_normals{}, alphas{}, triangle_tags{}, allowed_verts{} disp.SetPower(dispinfo.PropertyInteger("power", 3)); disp.StartPosition = dispinfo.PropertyCoordinate("startposition"); disp.Elevation = dispinfo.PropertyDecimal("elevation"); disp.SubDiv = dispinfo.PropertyInteger("subdiv") > 0; var size = disp.Resolution + 1; var normals = dispinfo.GetChildren("normals").FirstOrDefault(); var distances = dispinfo.GetChildren("distances").FirstOrDefault(); var offsets = dispinfo.GetChildren("offsets").FirstOrDefault(); var offsetNormals = dispinfo.GetChildren("offset_normals").FirstOrDefault(); var alphas = dispinfo.GetChildren("alphas").FirstOrDefault(); //var triangleTags = dispinfo.GetChildren("triangle_tags").First(); //var allowedVerts = dispinfo.GetChildren("allowed_verts").First(); for (var i = 0; i < size; i++) { var row = "row" + i; var norm = normals != null ? normals.PropertyCoordinateArray(row, size) : Enumerable.Range(0, size).Select(x => Coordinate.Zero).ToArray(); var dist = distances != null ? distances.PropertyDecimalArray(row, size) : Enumerable.Range(0, size).Select(x => 0m).ToArray(); var offn = offsetNormals != null ? offsetNormals.PropertyCoordinateArray(row, size) : Enumerable.Range(0, size).Select(x => Coordinate.Zero).ToArray(); var offs = offsets != null ? offsets.PropertyDecimalArray(row, size) : Enumerable.Range(0, size).Select(x => 0m).ToArray(); var alph = alphas != null ? alphas.PropertyDecimalArray(row, size) : Enumerable.Range(0, size).Select(x => 0m).ToArray(); for (var j = 0; j < size; j++) { disp.Points[i, j].Displacement = new Vector(norm[j], dist[j]); disp.Points[i, j].OffsetDisplacement = new Vector(offn[j], offs[j]); disp.Points[i, j].Alpha = alph[j]; } } return disp; }