brianzinn / react-babylonjs

React for Babylon 3D engine
https://brianzinn.github.io/react-babylonjs/
821 stars 105 forks source link

advancedDynamicTexture using PBR Material #282

Open Chargeuk opened 1 year ago

Chargeuk commented 1 year ago

Hi I was attempting to create an Advanced Dynamic texture for GUI elements that uses a PBR rather than standard material. Unfortunately, nesting the advancedDynamicTexture within the pbrMaterial node does not seem to work:

Is this possible? If so, how should it be created? Thanks

brianzinn commented 1 year ago

Can you share how that is done imperatively?

Chargeuk commented 1 year ago

Can you share how that is done imperatively?

Sorry for the late reply, was on holiday.

I have create 2 playgrounds to show how I would create the materials in raw Babylon code.

Option 1, provide the materialSetupCallback function to BABYLON.GUI.AdvancedDynamicTexture.CreateForMesh: https://playground.babylonjs.com/#NVAEWD#94 - note that the materialSetupCallbackPbr supports onlyAlphaTesting = true or false appropriately.

Option 2, create the AdvancedDynamicTexture directly and manually apply the material. Note this code path is the same as onlyAlphaTesting = false: https://playground.babylonjs.com/#NVAEWD#95

Hope this helps to illustrate what I mean.

Edit - now that I have come to think about it, exposing a materialSetupCallback on the current AdvancedDynamicTexture component within react-babylon that returns the material to use would also work for me, though I'm not sure it would fit in with the structure you have created...

brianzinn commented 1 year ago

Sorry - was AFK all long weekend. I feel like there are declarative solutions to both. Also, assignTo looks like it should allow an array of strings. The only thing about the callback is I don't even have the original createForMesh - I did add a createForParentMesh property. The thing about putting materialSetupCallback is that it would only need to be called with createForMesh and I think I copied the code from that static method. I certainly could call that though - I'm not necessarily against people "newing up" instances, but I think I would encourage a declarative option - that allows the reconciler to track the object and is eligible to prop updates. Even your 'onlyAlphaTesting' can be used to change what is "rendered"...

brianzinn commented 4 months ago

i'm trying to clear out some outstanding issues. sorry this didn't get looked at properly before. do you have a preferred option to go ahead?