My goal is to have animated mesh - lets say human - and put somehing dynamically into its hand. I have tried different approaches but all of them seems to be unnecessarily slow.
My goal is to keep FPS > 100 with 100 animated meshes attached with wearable items
The scene has 100 moving animated humans (pretty simple models and skeletons), they are moving around and animating while FPS are in 115 - 120 range (my test phone has 120hz screen).
Create 100 instances of sword (simple) and do nothing with them = FPS 115-120 (no noticeable drop)
Create 100 instances of sword and parent them to the mesh itself = FPS 110 - 115 while swords moving around with meshes (small acceptable drop)
So far so good, but then I wanted to put the sword into model´s hand, I tried following
Create 100 instances of sword and attach them to the hand bone of the mesh = FPS 70-75
Create 100 instances of sword and parent them to the TransformNode that is attached to the hand bone of the mesh = FPS 70-75 (this one was expected)
Create Solid Particle System, make the sword mesh as the particles, create TransformNode attached to the model´s hand and then on sps.setParticles function, I copied absolute position and rotation from the node to the particle. Works as expected but also FPS dropped to like 70 - 75.
In all my approaches that really follows hand (3 - 5), FPS dropped drastically - like 40 FPS drop only for copying position / rotation, it feels wrong considering we are talking about only 100 objects (not thousands or tens of thousands)
Considering that my test phone can render 100 moving animated objects at almost 120FPS, I did not expect any noticeable drop actually.
In attempt nr. 2 - the swords were moving around so position of the mesh is copied to the sword and it did not cause any FPS drop - what is the difference between following mesh and following its bone ? It is just copying one position / rotation data from one object to another, or not ?
Is there some different approach that I may try ? It seems weird that I can render 100 animated meshes and 100 swords perfectly at 110+ FPS (around 40.000 faces) and then only making the sword follow the bone (bone that is already being animated) make 40 FPS drop.
Any ideas ?
Note: In reality I would not need 100 equipped models in the scene at one time, the reason I am going this exagerated way is to idenfity FPS drains like this easily.
I probably solved it - so when someone else run into the same situation, here is the solution, that works as wanted and has like zero impact on performance (which is what I expected from attachToBone in the first place).
this.handBone.computeWorldMatrix(true);
const boneMatrix = this.handBone.getWorldMatrix();
const parentWorldMatrix = this.mesh.getWorldMatrix();
const localPosition = new Vector3();
const boneRotationQuaternion = new Quaternion();
const localScale = new Vector3();
boneMatrix.decompose(localScale, boneRotationQuaternion, localPosition);
const parentPosition = new Vector3();
const parentRotationQuaternion = new Quaternion();
const parentScale = new Vector3();
parentWorldMatrix.decompose(parentScale, parentRotationQuaternion, parentPosition);
const combinedRotation = parentRotationQuaternion.multiply(boneRotationQuaternion);
const worldPosition = Vector3.TransformCoordinates(localPosition, parentWorldMatrix);
this.sword.position = worldPosition;
this.sword.rotationQuaternion = combinedRotation;
Hello, it DOES work properly as it was in my attemp number 3. The problem was that it caused huge FPS drop (from 115 to 70 in my case), when I do it manually as stated above, I experienced no FPS drop at all.
Hi Roland, I looked at your code and if I understood it correctly, you are parenting your meshes to the bone right ? I tried it as well but I got the same FPS drop as I had in attachToBone case.
How many objects are you attaching ? In my case I attached only 1 to every aniamted mesh, and there were 100 such meshes.
Isnt that prepare called only once ? At the moment when attachToBone is called ? In such case it wouldnt affect FPS permanently if I didnt miss anything here.
@roland Thanx for this - I will try this doNotSyncBoundingInfo = true It might help actually ! In the meantime I came to conclusion, that âmanually attached thin instancesâ as you named it, is the way to go. Tried it yesterday and it is blazing fast !