-
Notifications
You must be signed in to change notification settings - Fork 148
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
vertex correspondences saved in _map.txt look incorrect #85
Comments
The map file is intended to contain:
This means that vertex |
Thank you for your reply. That is actually what I thought the _map.txt indicates, but what I found out later in my experimental results somewhat baffled me. For example, I still used this per-vertex-color OBJ as input original mesh original mesh, then I applied "-t -c -m -wf" switches on this input mesh to generate a new mesh together with a resulting _map.txt file. This _map.txt looks like below: 0,0 This pattern of same newIndex vs. oldIndex goes all the way down till line#67151 before the newIndex and oldIndex are different. I assume this means the new indices 0, 1, and 2 in the new mesh corresponds to old indices 0, 1, and 2 in the original mesh, respectively. However, the 3D coordinates of vertices 0, 1, and 2 in the original mesh are: v 0.236947 -1.026314 0.613356 while the 3D coordinates of vertices 0, 1, and 2 in the new mesh are: v -0.522509 -1.03974 0.676644 These two set of 3D coordinates look quite different. I previously thought they should be similar if not exactly the same, since no large scale spatial transformation is required for the mesh partition. Then what did I do wrong? Thank you very much! |
What if you try without the |
I just tried "-m -wf" as you advised. The results still show mismatches between the vertices in the original mesh and the vertices in the new mesh. |
How am I supposed to read the map.txt file in the first place? I am using uvatlastool.exe from C# and I am not sure how to transfer the UVs of the new mesh to the old mesh. My function looks like this: private void ApplyLightmapUVs(ref RoomMesh mesh, StreamReader resultMeshReader, StreamReader mappingReader)
{
List<Vector2> newUVs = new List<Vector2>();
using (resultMeshReader)
{
string line = resultMeshReader.ReadLine();
while (line != null)
{
if (line.StartsWith("vt"))
{
var splits = line.Split(" ");
var u = float.Parse(splits[1]);
var v = float.Parse(splits[2]);
newUVs.Add(new Vector2(u, v));
}
line = resultMeshReader.ReadLine();
}
}
using (mappingReader)
{
string line = mappingReader.ReadLine();
while (line != null)
{
var splits = line.Split(",");
var oldIdx = int.Parse(splits[1]);
var newIdx = int.Parse(splits[0]);
RoomVertex oldVertex = mesh.Vertices[oldIdx];
RoomVertex newVertex = oldVertex;
newVertex.LightmapUV = newUVs[newIdx]; // apply new UVs
mesh.Vertices[oldIdx] = newVertex;
line = mappingReader.ReadLine();
}
}
ExportRoomToOBJ(mesh, "Temp/test.obj",true); // sanity check. shows messed up UVs
}
|
I came back to Uvatlastool because other alternatives (namely xatlas) did not produce satisfying results either. I still have the issue with messed up UVs after uvatlas tool. In the following Zip I have 3 files: Dictionary<int,int> mapping = new Dictionary<int,int>();
foreach(var s in File.ReadAllLines(roomMeshOutMapFile)) {
var splitted = s.Split(",");
mapping.Add(int.Parse(splitted[0]), int.Parse(splitted[1]));
}
var uvList = new List<Vector2>();
string[] outputMesh = File.ReadAllLines(roomMeshOutFile);
foreach(var l in outputMesh) {
if (l.StartsWith("vt")){
string[] splitted = l.Split(" ");
float u = float.Parse(splitted[1]);
float v = float.Parse(splitted[2]);
uvList.Add(new Vector2(u, v));
}
}
foreach( var kv in mapping)
{
mesh.Vertices[kv.Value].LightmapUV = uvList[kv.Key];
} |
Are there any news on this? |
This time, I have a very simple mesh (28 triangles) and used VBO as both output and input. void ApplyLightmeshUV(RoomMesh mesh, BinaryReader unwrappedVBO, StreamReader vertexMapping)
{
var numVertices = unwrappedVBO.ReadInt32();
var numIndices = unwrappedVBO.ReadInt32();
var newIndices = new List<int>();
List<Vector2> newUVs = new List<Vector2>();
{
for(int i =0; i < numVertices; ++i)
{
//position, ignore
unwrappedVBO.ReadSingle();
unwrappedVBO.ReadSingle();
unwrappedVBO.ReadSingle();
//normal, ignore
unwrappedVBO.ReadSingle();
unwrappedVBO.ReadSingle();
unwrappedVBO.ReadSingle();
//uvs
float u = unwrappedVBO.ReadSingle();
float v = unwrappedVBO.ReadSingle();
newUVs.Add(new Vector2(u, v));
}
for(int i =0; i < numIndices; ++i)
{
var idx = unwrappedVBO.ReadInt16();
newIndices.Add(idx);
}
}
{
// make a copy of the old vertices.
var oldVertices = mesh.Vertices.ToArray();
string? line = vertexMapping.ReadLine();
int i = 0;
while (line is not null)
{
var splits = line.Split(",");
Debug.WriteLine($"{splits[0]},{splits[1]}");
var oldIdx = int.Parse(splits[1]);
var newIdx = int.Parse(splits[0]);
RoomVertex oldVertex = oldVertices[oldIdx];
RoomVertex newVertex = oldVertex;
newVertex.LightmapUV = newUVs[newIdx]; // apply new UVs
mesh.Vertices[oldIdx] = newVertex;
line = vertexMapping.ReadLine();
i++;
}
}
} I would like to atleast have some feedback. I don't know whether the mapping is incorrect on my side or whether _map.txt is just wrong. |
I used "-t -c -m -wf" switches on a per vertex color OBJ input. I got the _map.txt which contains the vertex correspondences. However, the correspondences do not look correct. I compared the 3D coordinates of some vertices in the input mesh with those of the corresponding vertices in the output mesh. The coordinates are quite different.
Did I misinterpret the content of _map.txt? Thank you very much!
The text was updated successfully, but these errors were encountered: