Questions for card like Mesh

Hello!
I’m trying to create some “Poker Cards” in my scene,then I come across two questions.The html page can be visited on this github site.
The first question is:
%E6%97%A0%E6%A0%87%E9%A2%983

Some card at the bottom is shown on the top!I guess that’s because when I move the camera, the square A at the bottom get closer to the camera than the
upper square 2,Then the engine think 2 is deeper than A.
Is my guess correct?And how can I deal with this question?
The second question is:
2019-04-19_14-48-19
When I place the cards with PhysicsImpostor one on one,I hope they can stable strut each other,but they just blow up.I attempted reduce the PhysicsImpostor’s restitution property(even to 0),but it doesn’t work at all.Do you have any idea to make the card quiet down when struted?In addition,in my tests,the cards always collapse to the left ,is there a reason for this phenomenon?

I found the answer to the first question! In my scene I set ‘materialf.diffuseTexture.hasAlpha=true;
materialf.useAlphaFromDiffuseTexture=true;’ in case of the texture has an alpha value.
When I set ‘hasAlpha=false’ the mistake disappeared!
Although this problem has been solved,I think the texture with alpha should be displayed correctly too!Do you have any idea how to handle the cards with alpha value?
On the other hand,I’m still working for the answer of the second question now.

Well done for finding the answer to your first question. Perhaps @trevordev can help with the second one.

Hey @ljzc002 this issue seems present with most physics engines. I think the simpelest workaround would be to avoid physics when stacking (either stack them manually with code or disable physics when the error would occur and only enable physics when they are spread out) See this playground https://playground.babylonjs.com/#J5U794#11 Hope this helps.

Thank you for reply.
I guess maybe the materialf.diffuseTexture.hasAlpha property is designed for the PNG picture which has the alpha value.When I set this property on the JPG picture which don’t have the alpha value ,the engine comes to an error.

Thanks for your help,I solved the second problem.
But in the process of solving this problem,I found two more minor questions about the physicsImpostor :
The first:
When I set the physicsImpostor’s mass to 0 or call the sleep function in the registerOnPhysicsCollide’s callback method,I found that none of them worked! Did I miss some “refresh” process?
The second:
I find that after create a physicsImpostor by a Mesh,the Mesh’s rotation will come to (0,0,0),but the Mesh’s posture we can see won’t change,Is this normal?

If you are using ammo, i think sleep is not supported. You could try adding them to a list and calling those methods in onAfterRenderObservable in case their state is being used during registerOnPhysicsCollide

I dont think that is expected, I can try to debug if you create a playground with a repro.

I have changed your playground repro a little:
%E6%97%A0%E6%A0%87%E9%A2%984
When I console.log the card.rotation.x before and after create the physicsImpostor,we can see the rotation.x changes from Math.PI/2 to 0.

@ljzc002 the cards may have had their rotationQuaternion set. If that is the case the rotation property is deactivated for performance reasons. It is recommended to use rotationQuaternion instead of rotation as some of the newer components may set rotationQuaternion. To still use euler logic you can see
card.rotationQuaternion.toEulerAngles and BABYLON.Quaternion.FromEulerVectorToRef methods

According to instincts the rotation and rotationQuaternion might be two representations of one thing.But in fact the engine overlay them as the finally attitude transformation.
Since it is so,I will try to convert rotationQuaternion to euler and add the euler with rotation to act as the actual rotation.
Thank you for your help very much.

2 Likes