#How are you calling CombineMeshes now
1 messages · Page 1 of 1 (latest)
So this is my current code:
public static void Run2(in Mesh prefab, IMeshDeformPath path, out Mesh result)
{
result = new Mesh();
result.name = prefab.name;
var verts = prefab.vertices;
var newVerts = new Vector3[verts.Length];
List<CombineInstance> combines = new List<CombineInstance>();
for (int i = 0; i < path.Length; i++)
{
//new mesh for each step along the path
var m = Object.Instantiate(prefab);
//deform to conform to the path
for (var v = 0; v < verts.Length; v++)
newVerts[v] = Update(verts[v], i, path);
//set the vertices
m.vertices = newVerts;
//add its submesh data to the list
for (int s = 0; s < prefab.subMeshCount; s++)
combines.Add(new CombineInstance() { mesh = m, subMeshIndex = s });
}
result.CombineMeshes(combines.ToArray(), false, false, false);
result.RecalculateBounds();
result.RecalculateNormals();
}
So from my understanding you want to call CombineMeshes three times
or one per submesh plus the final combine?
Yes
hm i see
So first two call with merging
And last call without merging
I assume performance is not big issue here
I guess you might want to improve the performance then, but making working code first would be good
so i need something Dictionary<submeshID,List<CombineInstance>>()
Yeah if ID is consistent
yeh it is
since im copy pasting the prefab each time the submeshes will always be the same index
Or sharedMaterial could be key I guess 🤔, whichever is comfortable
hm trying to tihnk how to correctly combine them before applying the final combine
Shouldn’t be too complex
public static void Run2(in Mesh prefab, IMeshDeformPath path, out Mesh result)
{
result = new Mesh();
result.name = prefab.name;
var verts = prefab.vertices;
var newVerts = new Vector3[verts.Length];
List<CombineInstance>[] combines = new List<CombineInstance>[prefab.subMeshCount];
Mesh[] meshes = new Mesh[prefab.subMeshCount];
CombineInstance[] finalCombines = new CombineInstance[prefab.subMeshCount];
for (int i = 0; i < path.Length; i++)
{
//new mesh for each step along the path
var m = Object.Instantiate(prefab);
//deform to conform to the path
for (var v = 0; v < verts.Length; v++)
newVerts[v] = Update(verts[v], i, path);
//set the vertices
m.vertices = newVerts;
//add its submesh data to the list
for (int s = 0; s < prefab.subMeshCount; s++)
{
if (combines[s] == null)
combines[s] = new List<CombineInstance>();
combines[s].Add(new CombineInstance() { mesh = m, subMeshIndex = s });
}
}
for (int i = 0; i < combines.Length; i++)
{
meshes[i] = new Mesh();
meshes[i].CombineMeshes(combines[i].ToArray(), true, false, false);
finalCombines[i] = new CombineInstance() { mesh = meshes[i], subMeshIndex = i };
}
result.CombineMeshes(finalCombines, false, false, false);
result.RecalculateBounds();
result.RecalculateNormals();
}
``` seem to get only one submesh output all the rest are culled
The submeshIndex for last combine should be 0
Both mesh is merged down to single submesh
for result i set it to false so there should be two submeshes no?
I mean finalCombines[1] has single submesh
So it’s CombineInstance should have 0 for submeshIndex
yeh it shows one
but it should have a second one
ill do a step through see if its actually populating correctly
I mean this line
finalCombines[i] = { … submeshIndex = i }
Should set submeshIndex = 0
Not i
No that’s not final index for submesh
That’s submesh index for the mesh you are giving
Put it 0 and see
Yay! Glad it worked
i dont fully follow why it had to 0 but ill take it ! 😄
i presume because a mesh with 1 submesh but the index starting at i>0 would basically be ignored?
Because each meshes you trying to combine now has 1 submesh
Yeah
That would be nothing
