bhushan6 / babylon-msdf-text

library to render text in Babylon js using MSDF technique
15 stars 5 forks source link

Instanced Mesh Position Sync'd To Source Mesh #3

Open dsaffo opened 1 year ago

dsaffo commented 1 year ago

Hello Again, sorry to open so many issues but I am working on integrating this package in one I am working on so i've been digging into it.

I am trying to get this working with instancing, it mostly works however it seems like all the properties of the instanced meshes are stuck to the source mesh. Or to be more exact the shader/material is syncd to the source mesh while the empty mesh moves freely. Here is an example:

`const randomizeThreshold = (threshold) => Math.random() threshold 2 - threshold const randmizeVector = (threshold = 50) => new Vector3(randomizeThreshold(threshold), randomizeThreshold(threshold), randomizeThreshold(threshold))

//make the source mesh let mesh = createTextMesh({ text: Test, font: fnt, scene, atlas: png, engine, });

//create an instanced mesh from the source mesh let instanceMesh = mesh.createInstance('test');

//randomize the position of the instanced mesh. The empty mesh will move but the shader/material will stay at the source mesh position. instanceMesh.position = randmizeVector();`

I will keep looking into this myself but the issue might be with the shader code parts which I am not well versed in. It would be great if this could work with instances as it would easily double the performance.

bhushan6 commented 1 year ago

Hi @dsaffo ,

Yeah, I didn't think about instanced mesh initially. I tried making it instance mesh compatible and it works but has small issue with rotation of original mesh. I have pushed the code and you can see the example folder to see how to use it, but couldn't publish the package since I don't have my personal laptop with me. I'll try to publish by end of the day but till then maybe you can use code from repo.

dsaffo commented 1 year ago

Awesome! I will check it out.