sbox-issues
sbox-issues copied to clipboard
GetVertices() and GetIndices() out of order
Describe the bug
I have a rectangular mesh with numbered verticies (blender)
when I call the GetVertices() and GetIndices() functions of the ModelRenderer.Model class, I get out of order vertices.
I loop through the indices and I try to trace the generation of triangles and somehow the vertex of the third triangle references the wrong index. Output from console for the GetIndces() function:
02:56:05 GameMenu 0 02:56:05 GameMenu 1 02:56:05 GameMenu 2
02:56:05 GameMenu 0 02:56:05 GameMenu 2 02:56:05 GameMenu 3
02:56:05 GameMenu 2 02:56:05 GameMenu 1 <- (no edge connects these points) 02:56:05 GameMenu 4 <- (no edge connects these points)
... Also another thing I noticed when instancing gameobjects along the vertices was that the vertices were not in order. So you could imagine I want to spawn some sort of way point navigation system procedurally along this mesh, but since the vertex and indicies are all messed up, I can't image how I would do this without hand placing waypoints.
Last notes and thoughts: Maybe the indices list only connects two indices together to form an edge and the list is processed by edges? I could work with this, but it doesn't explain why when I instance things on the vertices the instances end up jumping from the beginning of the mesh to the end and places in-between - instead of tracing the vertices as they are laid out in the image
To Reproduce
- Create a rectangular mesh in blender with subdivisions along the long axis
- export as fbx and create model in s&box ModelDoc editor
- add to the model render mesh list - a "RenderMeshMarkup" and tick the CPU vertex access option, then compile
- Create script that references gameobject with ModelRenderer component.
- Use the .Model.GetIndices() function of the referenced ModelRenderer.
- Examine Indices
Expected behavior
Indices are ordered the way the model is imported
Media/Files
No response
Additional context
No response
It might help if you posted the fbx, an obj, or a .blend file with a model that exhibits this behaviour. If someone doesn't know exactly what you did in blender then they might not be able to reproduce your issue.
This minor visual darkening near the zero implies the mesh may have strange topology, which wouldn't be a fault of the engine.
Yeah last time I've messed with GetVertices() and GetIndices() I've also noticed that sometimes output is inconsistent. But code repro would definitely be useful here
Build a mesh in 3D software like how I have above and run this (I am unable to upload .fbx):
[Property] public ModelRenderer modelRenderer;
protected override void OnStart(){
int[] indices = modelRenderer.Model.GetIndices();
foreach (int indx in indices){
Info.Log(indx);
}
}
Examine how every two indices printed represent an edge connection. Before, I suspected triangle formations (so every three indices were a triangle), but it seems that every two indices is an edge.
Other thoughts : I wonder if s&box will chunk the mesh in an optimized way. Maybe it finds and orders edges to render based on height or something. I have no clue, but the image I show above has ordered indices and s&box does not maintain the order.
Context: I am building a game that requires waypoints for a track system. Given that the mesh is a track, I want to extract the points in order and create a data structure representing the connections. This will allow for proper path guidance and custom ai navigation.
It might help if you posted the fbx, an obj, or a .blend file with a model that exhibits this behaviour. If someone doesn't know exactly what you did in blender then they might not be able to reproduce your issue.
This minor visual darkening near the zero implies the mesh may have strange topology, which wouldn't be a fault of the engine.
I checked with the 3D artist and they said the visual is an artifact of the procedural UV generation and not the placement / ordering of the vertices themselves. I can test with other meshes too just to be sure
You didn't give a repro project so I had to guess. See if it's fixed when the game next updates
Oh jeez I think I got mixed up as I kept reading repro as steps, not the actual project. I'll try to find some time to get y'all a test project hopefully soon.
Is this working now?
I don't think so. I'm observing what looks like proper indices, but not vertices. Their positions are off by a lot.
How are they off?
It appears that the positions look transformed by multiple thousand units. I've got limited time to post a test project. Hopefully tomorrow I can give an example.
You could just send the model
https://drive.google.com/file/d/1yPW0onC_8oAwB7SJodsM4oMGtSQHhN1V/view?usp=sharing
Github wouldn't let me upload an fbx.
Also, ill be deleting this soon.
Works completely fine?
Do you see how the index changes at the apex of the loop? This is the problem I have. I expect a continuously ascending index as I trace along the mesh. The index goes from 75 to 271. Say I wanted to instance things along these points in a specific order. How could I achieve this given the indices?
Let me try with another mesh. I'm starting to suspect my entire 3D workflow is the culprit. Having these indices change so close to the apex makes me think there is some magic to connect sub meshes somewhere in my blender node graph which might be the actual problem
I don't think it's wise to rely on a compiled render mesh having the same triangulation from blender to fbx to modeldoc
This minor visual darkening near the zero implies the mesh may have strange topology, which wouldn't be a fault of the engine.