Skip to content

Commit 34bd26d

Browse files
committed
Go back to computing tangents.
1 parent 808dc99 commit 34bd26d

3 files changed

Lines changed: 9 additions & 44 deletions

File tree

0 Bytes
Binary file not shown.

Source/ObjLib.cs

Lines changed: 8 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -15,26 +15,16 @@ public static void UpdateMeshFromFile(Mesh mesh, string filename, float scaleFac
1515
{
1616
ProfileTimer.Push("UpdateMeshFromFile");
1717
List<Vector3> vertices = new List<Vector3>();
18-
/*List<Vector3> normals = new List<Vector3>();
18+
List<Vector3> normals = new List<Vector3>();
1919
List<Vector4> tangents = new List<Vector4>();
20-
List<Vector2> uv = new List<Vector2>();*/
20+
List<Vector2> uv = new List<Vector2>();
2121
using (StreamReader stream = File.OpenText(filename))
2222
{
2323
stream.ReadLine();
2424
string curLine = stream.ReadLine();
2525
char[] splitIdentifier = { ' ' };
2626
string[] brokenString;
27-
/*int v = 0; // first vertex
28-
int t = 0; // first tangent
29-
int n = 0; // first normal*/
30-
// borrowed from mesh-reading code.
31-
/*vertices = new Vector3[mesh.vertexCount];
32-
normals = new Vector3[mesh.normals.Length];
33-
tangents = new Vector4[mesh.tangents.Length];
34-
uv = new Vector2[mesh.uv.Length];*/
35-
36-
//bool log = filename.Contains("un.obj");
37-
//if(log) MonoBehaviour.print("*RSSOBJ* Loading " + filename);
27+
3828
while (curLine != null)
3929
{
4030
curLine = curLine.Trim(); //Trim the current line
@@ -46,19 +36,17 @@ public static void UpdateMeshFromFile(Mesh mesh, string filename, float scaleFac
4636
vertices.Add(new Vector3(System.Convert.ToSingle(brokenString[1]) * scaleFactor, System.Convert.ToSingle(brokenString[2]) * scaleFactor,
4737
System.Convert.ToSingle(brokenString[3]) * scaleFactor));
4838
break;
49-
/*case "vn":
39+
case "vn":
5040
normals.Add(new Vector3(System.Convert.ToSingle(brokenString[1]), System.Convert.ToSingle(brokenString[2]),
5141
System.Convert.ToSingle(brokenString[3])));
52-
n++;
5342
break;
5443
case "t":
5544
tangents.Add(new Vector4(System.Convert.ToSingle(brokenString[1]), System.Convert.ToSingle(brokenString[2]),
5645
System.Convert.ToSingle(brokenString[3]), System.Convert.ToSingle(brokenString[4])));
57-
t++;
5846
break;
5947
case "vt":
6048
uv.Add(new Vector2(System.Convert.ToSingle(brokenString[1]), System.Convert.ToSingle(brokenString[2])));
61-
break;*/
49+
break;
6250
}
6351
curLine = stream.ReadLine();
6452
if (curLine != null)
@@ -68,21 +56,9 @@ public static void UpdateMeshFromFile(Mesh mesh, string filename, float scaleFac
6856
}
6957
}
7058
mesh.vertices = vertices.ToArray();
71-
72-
/*var f2name = filename + ".tst";
73-
using (var sw = new StreamWriter(f2name, false))
74-
{
75-
foreach (var vertex in vertices)
76-
{
77-
sw.WriteLine("v {0} {1} {2}", vertex.x, vertex.y, vertex.z);
78-
}
79-
}*/
80-
81-
//mesh.normals = normals.ToArray();
82-
//mesh.tangents = tangents.ToArray();
83-
/*mesh.uv = uv.ToArray();*/
84-
mesh.RecalculateNormals();
85-
//mesh.RecalculateBounds();
59+
mesh.normals = normals.ToArray();
60+
mesh.tangents = tangents.ToArray();
61+
mesh.uv = uv.ToArray();
8662
ProfileTimer.Pop("UpdateMeshFromFile");
8763
}
8864
// based on noontz's code here: http://forum.unity3d.com/threads/38984-How-to-Calculate-Mesh-Tangents

Source/RealSolarSystem.cs

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1768,10 +1768,6 @@ private IEnumerator<YieldInstruction> LoadScaledSpace(ConfigNode node, Celestial
17681768
}
17691769
else
17701770
{
1771-
//OnGui();
1772-
// **** No longer exporting and importing
1773-
// Now I just do everything except tangents each time. Tangents don't seem necessary to fix, and
1774-
// the rest is fast enough...and something in .24/64 broke importing for *some* planets. WEIRD.
17751771
char sep = System.IO.Path.DirectorySeparatorChar;
17761772
string filePath = KSPUtil.ApplicationRootPath + "GameData" + sep + "RealSolarSystem" + sep + "Plugins"
17771773
+ sep + "PluginData" + sep + t.name;
@@ -1790,15 +1786,8 @@ private IEnumerator<YieldInstruction> LoadScaledSpace(ConfigNode node, Celestial
17901786
Utils.CopyMesh(loadInfo.joolMesh.mesh, tMesh);
17911787

17921788
ObjLib.UpdateMeshFromFile(tMesh, filePath);
1793-
//m.mesh.RecalculateBounds();
1794-
// done in UpdateFromFile
1795-
/*m.mesh.RecalculateNormals();
1796-
ObjLib.UpdateTangents(tMesh);*/
17971789
m.mesh = tMesh;
17981790
m.mesh.RecalculateBounds();
1799-
/*float scaleFactor = (float)(body.Radius / 6000000.0 * SSTScale);
1800-
t.localScale = new Vector3(scaleFactor, scaleFactor, scaleFactor);
1801-
rescale = false;*/
18021791
print("*RSS* Loaded " + filePath + " and wrapped.");
18031792
ProfileTimer.Pop("LoadSSM_" + body.name);
18041793
wrap = false;
@@ -1836,7 +1825,7 @@ private IEnumerator<YieldInstruction> LoadScaledSpace(ConfigNode node, Celestial
18361825
tMesh.RecalculateNormals();
18371826

18381827
//ProfileTimer.Pop("Recalc Normals");
1839-
//ObjLib.UpdateTangents(tMesh);
1828+
ObjLib.UpdateTangents(tMesh);
18401829
//print("*RSS* wrapped.");
18411830
}
18421831
m.mesh = tMesh;

0 commit comments

Comments
 (0)