Unable to run code in playground

I’ve been experimenting with making 2D line meshes so their thickness can be modulated. To test out the system, I’ve successfully drawn a 2D Hilbert curve.

I wanted to transfer this to the playground to share it and request comments for improvement. However, I’m unable to properly run the code, and it freezes after a single run. I’m unsure what I’m doing wrong.

Here is the current playground.

Note: I plan on adding more comments to the code (including some credits for code inspiration/use) but for now I’d just like it to work online. Afterwards I will further improve a submitted playground.

The code is executing successfully on my machine, but I might’ve missed something in translation, or something else is wrong. I’m not sure why it consistently freezes after a single execution.

After this works, I’ll make another topic on the actual contents of this playground.

Thanks for any help.

Edit: So I just clicked my own link, and now it works! But it’s a very small curve…when I comment out the line above it for a larger curve, it freezes. I’m not sure what’s happening. Perhaps this has something to do with my particular setup.

Edit-2: I modified and re-saved for a larger curve and it works the first time I visit it. It is here. Besides playing with the code and improving it, I wanted to animate the width variable. I will test on other computers soon.

Alternative methods Line2D of Given Width - Babylon.js Documentation might he useful

Thanks. That’s actually the code that inspired this work, in part. I was able to strip it to essentials and make a few changes. Those changes are more what I wanted to have a conversation about, but the difficulty in making the playground work (and in playing with it) is what prompted me to post this.

The playground also works when first clicked on. It wasn’t working for me the first time I uploaded it (and created the post), and does not work for me if I try to make changes in real-time.

How I found the problem - you used scene.addMesh(lineMesh) but this should not be needed as when you create a mesh with new BABYLON.Mesh it is already added to the scene. Commenting out this line removed the error TypeError: this._currentBufferPointers[e] in the console but of course the mesh was not displayed.

Issue is that the playground app creates the engine that wraps your PG code and this engine is not reset when use use ‘Run’.

On line 101

var lineMesh = new BABYLON.Mesh("lineMesh", scene);

You use the parameter ‘scene’ which the engine takes to be the scene you created when you first ran the your code not the scene newly created by the new calling of createScene on any subsequent uses of ‘Run’.

Since you create scene within createScene it is not available to the function mkLineMesh unless you pass it, which you don’t.

Modifying to pass scene to mkLineMesh and removing scene.addMesh gives https://playground.babylonjs.com/#JL59BN#2

3 Likes

Ah! That’s extremely sensible. I was hoping it was something simple.

Brilliant work. Thank you!