"Export to Wavefront .obj" action should work much faster now.

Things mode: selection info was not updated when selection was cleared.
This commit is contained in:
MaxED 2013-12-12 09:07:30 +00:00
parent 871776e319
commit ab4d8c2776
6 changed files with 40 additions and 39 deletions

View file

@ -491,26 +491,26 @@ namespace CodeImp.DoomBuilder.Map
float right = float.MinValue; float right = float.MinValue;
float bottom = float.MinValue; float bottom = float.MinValue;
List<Vertex> processed = new List<Vertex>(); //mxd Dictionary<Vertex, bool> processed = new Dictionary<Vertex, bool>(); //mxd
//mxd. This way bbox will be created even if triangulation failed (sector with 2 or less sidedefs and 2 vertices) //mxd. This way bbox will be created even if triangulation failed (sector with 2 or less sidedefs and 2 vertices)
foreach (Sidedef s in sidedefs) { foreach (Sidedef s in sidedefs) {
//start... //start...
if (!processed.Contains(s.Line.Start)) { if (!processed.ContainsKey(s.Line.Start)) {
if (s.Line.Start.Position.x < left) left = s.Line.Start.Position.x; if (s.Line.Start.Position.x < left) left = s.Line.Start.Position.x;
if (s.Line.Start.Position.x > right) right = s.Line.Start.Position.x; if (s.Line.Start.Position.x > right) right = s.Line.Start.Position.x;
if (s.Line.Start.Position.y < top) top = s.Line.Start.Position.y; if (s.Line.Start.Position.y < top) top = s.Line.Start.Position.y;
if (s.Line.Start.Position.y > bottom) bottom = s.Line.Start.Position.y; if (s.Line.Start.Position.y > bottom) bottom = s.Line.Start.Position.y;
processed.Add(s.Line.Start); processed.Add(s.Line.Start, false);
} }
//end... //end...
if(!processed.Contains(s.Line.End)) { if(!processed.ContainsKey(s.Line.End)) {
if(s.Line.End.Position.x < left) left = s.Line.End.Position.x; if(s.Line.End.Position.x < left) left = s.Line.End.Position.x;
if(s.Line.End.Position.x > right) right = s.Line.End.Position.x; if(s.Line.End.Position.x > right) right = s.Line.End.Position.x;
if(s.Line.End.Position.y < top) top = s.Line.End.Position.y; if(s.Line.End.Position.y < top) top = s.Line.End.Position.y;
if(s.Line.End.Position.y > bottom) bottom = s.Line.End.Position.y; if(s.Line.End.Position.y > bottom) bottom = s.Line.End.Position.y;
processed.Add(s.Line.End); processed.Add(s.Line.End, false);
} }
} }

View file

@ -850,7 +850,7 @@ namespace CodeImp.DoomBuilder.BuilderModes
// Clear selection // Clear selection
General.Map.Map.ClearAllSelected(); General.Map.Map.ClearAllSelected();
//mxd //mxd. Clear selection info
General.Interface.DisplayStatus(StatusType.Selection, string.Empty); General.Interface.DisplayStatus(StatusType.Selection, string.Empty);
// Redraw // Redraw

View file

@ -1776,7 +1776,8 @@ namespace CodeImp.DoomBuilder.BuilderModes
// Clear selection // Clear selection
General.Map.Map.ClearAllSelected(); General.Map.Map.ClearAllSelected();
General.Interface.DisplayStatus(StatusType.Selection, string.Empty); //mxd //mxd. Clear selection info
General.Interface.DisplayStatus(StatusType.Selection, string.Empty);
// Clear labels // Clear labels
foreach(TextLabel[] labelarray in labels.Values) foreach(TextLabel[] labelarray in labels.Values)

View file

@ -730,6 +730,9 @@ namespace CodeImp.DoomBuilder.BuilderModes
// Clear selection // Clear selection
General.Map.Map.ClearAllSelected(); General.Map.Map.ClearAllSelected();
//mxd. Clear selection info
General.Interface.DisplayStatus(StatusType.Selection, string.Empty);
// Redraw // Redraw
General.Interface.RedrawDisplay(); General.Interface.RedrawDisplay();
} }

View file

@ -739,7 +739,7 @@ namespace CodeImp.DoomBuilder.BuilderModes
// Clear selection // Clear selection
General.Map.Map.ClearAllSelected(); General.Map.Map.ClearAllSelected();
//mxd //mxd. Clear selection info
General.Interface.DisplayStatus(StatusType.Selection, string.Empty); General.Interface.DisplayStatus(StatusType.Selection, string.Empty);
// Redraw // Redraw

View file

@ -290,12 +290,15 @@ namespace CodeImp.DoomBuilder.BuilderModes.IO
StringBuilder obj = new StringBuilder(); StringBuilder obj = new StringBuilder();
const string vertexFormatter = "{0} {2} {1}\n"; const string vertexFormatter = "{0} {2} {1}\n";
List<Vector3D> uniqueVerts = new List<Vector3D>(); Dictionary<Vector3D, int> uniqueVerts = new Dictionary<Vector3D, int>();
List<Vector3D> uniqueNormals = new List<Vector3D>(); Dictionary<Vector3D, int> uniqueNormals = new Dictionary<Vector3D, int>();
List<PointF> uniqueUVs = new List<PointF>(); Dictionary<PointF, int> uniqueUVs = new Dictionary<PointF, int>();
Dictionary<string, Dictionary<WorldVertex, VertexIndices>> vertexDataByTexture = new Dictionary<string, Dictionary<WorldVertex, VertexIndices>>(); Dictionary<string, Dictionary<WorldVertex, VertexIndices>> vertexDataByTexture = new Dictionary<string, Dictionary<WorldVertex, VertexIndices>>();
int ni, pi, uvi; int ni;
int pc = 0;
int nc = 0;
int uvc = 0;
//optimize geometry //optimize geometry
foreach(KeyValuePair<string, List<WorldVertex[]>> group in geometryByTexture) { foreach(KeyValuePair<string, List<WorldVertex[]>> group in geometryByTexture) {
@ -303,12 +306,11 @@ namespace CodeImp.DoomBuilder.BuilderModes.IO
foreach(WorldVertex[] verts in group.Value) { foreach(WorldVertex[] verts in group.Value) {
//vertex normals //vertex normals
Vector3D n = new Vector3D(verts[0].nx, verts[0].ny, verts[0].nz).GetNormal(); Vector3D n = new Vector3D(verts[0].nx, verts[0].ny, verts[0].nz).GetNormal();
ni = uniqueNormals.IndexOf(n); if(uniqueNormals.ContainsKey(n)) {
if (ni == -1) { ni = uniqueNormals[n];
uniqueNormals.Add(n);
ni = uniqueNormals.Count;
} else { } else {
ni++; uniqueNormals.Add(n, ++nc);
ni = nc;
} }
foreach(WorldVertex v in verts){ foreach(WorldVertex v in verts){
@ -318,27 +320,22 @@ namespace CodeImp.DoomBuilder.BuilderModes.IO
//vertex coords //vertex coords
Vector3D vc = new Vector3D(v.x, v.y, v.z); Vector3D vc = new Vector3D(v.x, v.y, v.z);
pi = uniqueVerts.IndexOf(vc); if(uniqueVerts.ContainsKey(vc)) {
if (pi == -1) { indices.PositionIndex = uniqueVerts[vc];
uniqueVerts.Add(vc);
pi = uniqueVerts.Count;
} else { } else {
pi++; uniqueVerts.Add(vc, ++pc);
indices.PositionIndex = pc;
} }
//uv //uv
PointF uv = new PointF(v.u, v.v); PointF uv = new PointF(v.u, v.v);
uvi = uniqueUVs.IndexOf(uv); if(uniqueUVs.ContainsKey(uv)) {
if(uvi == -1) { indices.UVIndex = uniqueUVs[uv];
uniqueUVs.Add(uv); }else{
uvi = uniqueUVs.Count; uniqueUVs.Add(uv, ++uvc);
} else { indices.UVIndex = uvc;
uvi++;
} }
indices.PositionIndex = pi;
indices.UVIndex = uvi;
vertsData.Add(v, indices); vertsData.Add(v, indices);
} }
} }
@ -349,20 +346,20 @@ namespace CodeImp.DoomBuilder.BuilderModes.IO
//write geometry //write geometry
//write vertices //write vertices
if(data.FixScale) { if(data.FixScale) {
foreach(Vector3D v in uniqueVerts) foreach(KeyValuePair<Vector3D, int> group in uniqueVerts)
obj.Append(string.Format(CultureInfo.InvariantCulture, "v " + vertexFormatter, -v.x * data.Scale, v.y * data.Scale, v.z * data.Scale * 1.2f)); obj.Append(string.Format(CultureInfo.InvariantCulture, "v " + vertexFormatter, -group.Key.x * data.Scale, group.Key.y * data.Scale, group.Key.z * data.Scale * 1.2f));
} else { } else {
foreach(Vector3D v in uniqueVerts) foreach(KeyValuePair<Vector3D, int> group in uniqueVerts)
obj.Append(string.Format(CultureInfo.InvariantCulture, "v " + vertexFormatter, -v.x * data.Scale, v.y * data.Scale, v.z * data.Scale)); obj.Append(string.Format(CultureInfo.InvariantCulture, "v " + vertexFormatter, -group.Key.x * data.Scale, group.Key.y * data.Scale, group.Key.z * data.Scale));
} }
//write normals //write normals
foreach(Vector3D v in uniqueNormals) foreach(KeyValuePair<Vector3D, int> group in uniqueNormals)
obj.Append(string.Format(CultureInfo.InvariantCulture, "vn " + vertexFormatter, v.x, v.y, v.z)); obj.Append(string.Format(CultureInfo.InvariantCulture, "vn " + vertexFormatter, group.Key.x, group.Key.y, group.Key.z));
//write UV coords //write UV coords
foreach(PointF p in uniqueUVs) foreach(KeyValuePair<PointF, int> group in uniqueUVs)
obj.Append(string.Format(CultureInfo.InvariantCulture, "vt {0} {1}\n", p.X, -p.Y)); obj.Append(string.Format(CultureInfo.InvariantCulture, "vt {0} {1}\n", group.Key.X, -group.Key.Y));
//write material library //write material library
obj.Append("mtllib ").Append(data.ObjName + ".mtl").Append("\n"); obj.Append("mtllib ").Append(data.ObjName + ".mtl").Append("\n");