Can we have a p5.js sketch as a texture in babylon?

Hi Johnny,

This seems very cool, but pretty ambitious. At a surface level, assuming (as I’m unfamiliar with P5.js) the PGraphic object you mentioned is underpinned by this texture abstraction, it theoretically shouldn’t be too difficult to get Babylon to use this texture; all you should have to do is insert the underlying GL texture into a Babylon.js texture. Babylon doesn’t really support this, per se, but it’s not particularly hard to do if you’re willing to reach into some internals.

So, if that’s easy for you to try, I’d give that a shot, but there may be other issues with having two rendering engines trying to coexist in the same space; they may fight over the stateful GL context, for example. Moreover, I’ll be interested to learn if using Babylon.js for the 3D aspects meaningfully improves your performance here. Babylon is very fast, but I’m not sure the 3D part it’d be taking over was the slow part in the first place: there’s not much 3D going on, and depending on how P5 does the 2D stuff, that might be where the slowness is. You can do all the same 2D effects and things you’re doing in P5 in pure Babylon, of course, and that would almost certainly be faster and simpler. However, that would remove P5 from the equation altogether, which might defeat the purpose of what you’re trying to achieve.

Hope this helps, and best of luck!

1 Like