I naively started integrating VAT/instances into my project and realized I cannot assign material to instances… After thinking a while, I was wondering if I could do something like this? (pseudo code)
entitydata = [];
for each race
merge mesh and skeleton
create vat manager
for each race material
clone merged mesh
assign vat manager
clonedMeshes[materialIndex] = cloneMesh
endfor
load vat texture into vat manager
entitydata[race] = [
clonedMeshes,
vat,
]
endfor
and then for each entity i can do thensomething like this
I’m so close, i’m just struggling to find a way to prevent a animation from looping like the death animation:
// this.targetFrame is the last frame of the animation range ()
instanceMesh.instancedBuffers.bakedVertexAnimationSettingsInstanced.set(this.targetFrame, this.targetFrame, 0, 0);
You can see my current iteration here, it’s quite basic. It feels like it should work…
I basically just I play the animation once, and then set the animation to play the last frame on the corresponding animation ranges (as seen in code above).
The vat.time counter is used to compute the current frame of animation, so, when switching animation, if you want the new animation to start from the first frame, you should reset the vat counter to 0 (or to a multiple of the animation duration):
Performance without vat: 10 fps for 200 entities / 2 items per entity
Performance with vat no equipment: 40fps for 200 entities
It looks like neither implementation seem to be hurting performance too much so I’m guessing looking into my vat implementation is where I should look to improve performance.
Ok, weird one here, while testing trying to improve performance for the vat/instances, I found a random thing that boost the performance alot. If I stop parenting my player mesh to my collider and just move that mesh within the game loop to match the collider position, the FPS jumps to a nearly steady ~50 (versus ~30). I can even bump the max entities to 400 without too much difference.
How could parenting a mesh affect performance this much?
Ok, after adding an aggressive lod (includind relevant UI elements), I’m getting a steady ~60 fps now (except for the startup as my spawn controller spawns everything in one go which needs to be improved).
There is still tons of weird things I dont fully understand:
when player dies, a random amount of other entities seems to play the same death animation…
at each run, the helm for example would be misaligned in some different way
somethimes the items do not play any animations (the previous run would play fine)
Damit, I think I may be chewing on a bone too big for my size
Thats probably it. The 2d renderer uses canvas 2d so its going to be very slow. Rather unfortunate. It may be counter intuitive that drawing 3d objects will be much much faster.
Some non html options ive considered are pixi or small webgpu frameworks. pixi uses gl context , but that would get complicated switching to webgpu. Its possible use webgpu and copy the texture it into a webgl context, similar to how you do can do with imgui framebuffers. Maybe for native, Vulkan has an extension so you can do it without copy. But…idk prob just dont bother.
Ultimately, i think the answer is use bjs geometry/textures for everything that moves in 3d such as healthbars and nameplates then use react for the menus, windows, cooldown bar, etc. flagship games do it that way, no reason to make gui stuff harder on yourself when youre already rendering on the web. Maybe a hot take, but I view bjs gui lib as convenient svg and texture creator, not actually a gui framework.
I was having issues of animation synchro between player mesh and equipment so after having a chat with @Evgeni_Popov & @sebavan, the easiest way to get this sorted is with a PG that replicated my core game loop and iterate from there.
UPDATE 1 (1/12/2023 11am):
Looks like only the knight model is desynchronized, the other 2 models seems to be working well and the equipment is synchronized just fine for (idle, walk, attack) (still have not resolve the death animation yet).