x


Add Detail Mesh at runtime

Hi all

I have a gun in my project that splurts out empty shells. After tweaking the objects and doint some scripting I could get the performance to a good level even with a high rate of fire, but one thing is still not right. When the empty shells finally lie on the ground, all physic components will be destroyed, but the mesh itself is still a separate object from the ground. Now, I have read in the Performance Pages that as there is a separate draw call for each object, a lot of visible objects could slow down performance, and that is exactly what I can observe after some 1000 of shells being put on the ground.

I know, the sensible thing to do would be to only allow a certain number of this meshes in game, or destroy them after a certain time, but I would like to try something different first:

  • Is there any possability to transform a gameobject into a terrain detail mesh at runtime, to reduce the number of draw calls and make this former gameobject dissapear in the distance set for detail meshes?

Please point me in the right direction if this question was already asked, I found a answer to how to combine and uncombine objects, but after opening the script couldn't tell if this is what I am looking for.

Thanks in advance

GR

more ▼

asked Jul 09 '10 at 11:54 AM

Gian-Reto gravatar image

Gian-Reto
44 5 5 8

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

Adding a detail mesh isn't the issue here, but what you want to do with it is

Detail meshes use a texture for the positioning, which is going to give you severe issues if you try to add moving bullets into it - for a start, you'll need to update the texture so much it'll kill your system, and then on top of that, they'll just slide across the floor (you can't set a height for them)

I would honestly look into other ways of doing it - particles, mesh combining or object pools

more ▼

answered Jul 09 '10 at 12:31 PM

Mike 3 gravatar image

Mike 3
30.5k 10 65 253

Okay, right, I haven't thought about that... would mesh combining come at a reasonable cost to do multiple times in a short span of time? Would the resulting combined object be drawn in one call?

Thanks for the hints

Gian-Reto

Jul 09 '10 at 12:59 PM Gian-Reto

a combined mesh would be done in 1 draw call - and yes, it's possible (assuming your meshes aren't too large). you may be better off combining small batches of them instead

Jul 09 '10 at 01:54 PM Mike 3

Okay, now I have a small question concerning the combine mesh.

I have now the following script:

Jul 09 '10 at 04:33 PM Gian-Reto

if (Time.time >= nextCombine) { // combine the terrain with the debris lieing around

    var meshFilters = GetComponentsInChildren(MeshFilter);
    var combine : CombineInstance[] = new CombineInstance[meshFilters.Length];
    var index = 0;

    for (var i = 0; i < meshFilters.Length; i++) {
       if (meshFilters[i].sharedMesh == null) continue;
Jul 09 '10 at 04:34 PM Gian-Reto

combine[index].mesh = meshFilters[i].sharedMesh; combine[index++].transform = meshFilters[i].transform.localToWorldMatrix; meshFilters[i].renderer.enabled = false; // index++; } GetComponent(MeshFilter).mesh = new Mesh(); GetComponent(MeshFilter).mesh.CombineMeshes (combine, 0, 1); renderer.material = meshFilters[1].renderer.sharedMaterial;

    nextCombine = nextCombine + garbageCombineInterval;
}
Jul 09 '10 at 04:34 PM Gian-Reto
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x5070
x1469
x1357
x374
x57

asked: Jul 09 '10 at 11:54 AM

Seen: 1808 times

Last Updated: Jul 09 '10 at 11:54 AM