[SOLVED] Loading same mesh properly on entities

Blitz3D Forums/Blitz3D Programming/[SOLVED] Loading same mesh properly on entities

RustyKristi(Posted 2015) [#1]
Hey guys

I'm now trying to solve some loading issue with entity meshes. The routine involves loading the same mesh in a loop to create all entities before the start of the game or level, so it hangs up for a bit when you're trying to create and loop each created entity.

Now if I try to load it up once globally, they get the same mesh and identity so it's not the way to go.

So my question is, how do I properly load a mesh when this mesh(es) are declared and used inside a type, without the lagging issue?

Example:

Type Monster
 Field body
 Field id
 Field state
End Type

Function CreateMonster.monster()
 monster.Monster = New Monster
 monster\body = LoadMesh("monster.b3d") <----- THIS IS THE BOTTLENECK
 ...
 ...
EndFunction

For i = 1 to 40
 monster.Monster = CreateMonster() 
Loop



Floyd(Posted 2015) [#2]
Why load identical meshes? You can have many entities with the same underlying mesh. Somewhere there is

TheMonster = LoadMesh("monster.b3d")
HideEntity TheMonster ; you don't need to see this one

then all the others are

monster\body = CopyEntity( TheMonster )


Matty(Posted 2015) [#3]
CopyEntity is your friend.....


Floyd(Posted 2015) [#4]
Oops, forgot the CopyEntity. I just typed this in without testing, not having a .b3d handy. I have edited my original post.

After posting the first time I went on a quest to find a sample .b3d, not so easy. Then I remembered Psionic's generous collection of free samples. I found a link to the appropriate page but it appears to have died.

The invaluable Wayback Machine to the rescue:

https://web.archive.org/web/20080218000548/http://www.psionic3d.co.uk/gallery/thumbnails.php?album=2

I donate a little money to archive.org every couple of years. I think I'm overdue.


RemiD(Posted 2015) [#5]
If you plan to use the same mesh for several characters, it is better to load the mesh once and to use copyentity() to tell Blitz3d that each instance will use this mesh.
Global MonsterXMesh = loadanimmesh("monster.b3d")
HideEntity(MonsterXMesh)

For i%= 1 to 40 step 1
 m.Monster = New Monster
 m\mesh = copyentity(MonsterXMesh)
Next



RemiD(Posted 2015) [#6]
If i remember correctly it is possible to color a mesh "created" with copyentity() with a different texture and this will not affect the source mesh or the others "copied" meshes, can somebody confirm ?


Floyd(Posted 2015) [#7]
That's right. The name is a clue, EntityTexture rather than MeshTexture.


RemiD(Posted 2015) [#8]
I confirm that it is possible. Good :)


RustyKristi(Posted 2015) [#9]
Hey guys, I tried the CopyEntity thing but it just slows down the framerate to a crawl rather than increasing loading performance. :/

fyi the mesh is a 200 polygon only model for starters. I still have more parts to load that will total up to 3k x 40 to 60 iterations.


RemiD(Posted 2015) [#10]
There may be a problem in your code...

Try to create a simple code with an empty scene where you load the mesh once and you create copies of this mesh with copyentity and you position rotate these copies in the scene.

The loading/copying/rendering should be fast, or this means that your mesh may have a problem (too many triangles ? too many duplicated vertices ? too many surfaces ? too many overlapping or intersecting triangles ? too many surfaces with textures with progressive transparency (alpha) texels ?)


RustyKristi(Posted 2015) [#11]
Thanks RemiD, I got a hint with the CopyEntity thing so I tried CopyMesh() and it worked!!! :D

Global monstermesh = LoadMesh("monster.b3d")
...
...
monster\body = CopyMesh(monstermesh)


thanks guys!


RemiD(Posted 2015) [#12]
CopyMesh() creates a new mesh each time it is used, so it will take more time to render. CopyEntity() uses the same source mesh, so it will take less time to render.


RustyKristi(Posted 2015) [#13]
I don't know since I'm new to Blitz and the weird thing is that my game lags to a halt when I use CopyEntity instead of CopyMesh???

The framerate is still the same as before with the CopyMesh and the loading time/hang is not that noticeable anymore when reloading the level.

Maybe you can test with the CopyEntity and confirm this at your end? I'm really open to more ideas in optimizing my game. :-) thanks


RemiD(Posted 2015) [#14]
CopyEntity() must be used to create copies of rigged skinned animated meshes (meshes with joints (bones) and influences and animations), if you use CopyMesh() you will only create new meshes with surfaces, vertices, triangles, so there will be no joints (bones), no influences, no animations.


RustyKristi(Posted 2015) [#15]
Ah I see. :-) Yes, I'm only using static model placeholder for now but still with a decent polycount total at 3k each.

So do you think the framerate drop has something to do with using CopyEntity and static meshes? I should be able to try with animated meshes next time. I'm getting curious now..


RemiD(Posted 2015) [#16]
You can do some tests with the rigged skinned animated meshes provided by Psionic (see the link that Floyd posted)


RustyKristi(Posted 2015) [#17]
Ok thanks RemiD. will check that out. I learn something new everyday with B3D. :-)