Jump to content

Dispose SubMeshes of TiledGround


amethlex
 Share

Recommended Posts

Hi All,

I am new to Babylon.js and are trying tiledground.  My problem is how to dispose some submeshes of tiledGround?

I have tried like 

myTiledGround.subMeshes[3].dispose()

but it does not work.

I even tried to dispose all submeshes like

for (let i = 0; i < myTiledGround.subMeshes.length; ++i) {

  myTiledGround.subMeshes.dispose()

}

And also failed.

Only when I dispose the tiledGround with

  myTiledGround.dispose().

 

In the end, I choose to maintain multiple grounds and create / dispose manually.

Link to comment
Share on other sites

Hiya amethlex, welcome to the forum.  What you describe... is expected (normal) behavior.  The subMeshes array of a tiled ground... does NOT contain normal mesh.  Each subMesh could be called a "token" object... and it has no .dispose() or .setEnabled() functions.

Do you know how to use your browser's built-in object inspector?

Let's look at this tiledGround playground demo scene.  https://www.babylonjs-playground.com/#1FXAOY#4

I am doing work in lines 88-96.  After scene isReady + 3 seconds... I print tiledGround.subMeshes[4]... to console.  In my Firefox, if I click-upon the first 'object' in the displayed console line, my in-browser object inspector opens in the lower right corner, and I can "tour" through all the methods and properties on the subMeshes[4] object.  (Object inspectors are super-handy).

There's not very many properties/methods upon subMeshes[4] object, eh?  It doesn't have a .dispose() method, or a .setEnabled() method, or a .visibility property.  It is NOT a standard mesh at all.

Think of a single "grid-like" mesh... like our standard ground mesh.  Let's pretend we have 10 by 10 cells/subdivisions in this grid mesh.  You are trying to dispose ONE CELL of that mesh.   BJS says "Hey... thou shalt not dispose only PART of a mesh."

You are designing a "terrain server", I bet.  You want "Hey server, install a new row of terrain cells" or maybe a new column of terrain cells.  You're an inventor, aren't you?  :)

To be truthful, I tried a few tests and I don't foresee ANY way to dispose one tile-cell (subMesh).  Perhaps more importantly, you might not ever NEED to do that.  Perhaps there are other ways to addRowOfCells() or redefineColumnOfCells(). 

We have SOME dynamic never-ending Perlin-noise-bumpy terrain generators available... if that might be easier (non-server-commanded terrain).  But for on-the-fly server-installed tiles... that will take some fresh thinking from smarter people than I.

Anyway, I hope I helped show you WHY tiledGround subMeshes are not allowed to be disposed.  That would be like disposing one cell of a grid mesh.  It CAN be done (put a hole in a ground grid) but it takes removing particular indices in the ground's vertexData indicesKind buffer/array... which causes the two triangular faces of that cell... to NOT be rendered. 

Let's save that for later.  For now, perhaps we should wait for more comments, do more thinking and tests, and maybe object-inspect a subMesh to see what cool knobs (properties) are upon it, and what their current values are.  Be well, party on.

Warning: I am not a pro, so I could have told you something that is incorrect.  I hope not, but... I make plenty of mistakes.  Wingnut is still learning... and will ALWAYS be doing so.  :)

Link to comment
Share on other sites

Hi Wingnut,

Thank you so much.

So if I do need to update the tiledground, I need to dispose the old tiledground and set a new tiledground, right?

Just like:

 

this.tiledGround = new BABYLON.Mesh.CreateTiledGround(...)

...

// Update the tiledground in the loop.

while(...) {

this.tiledGround.dispose().

this.tiledGround = new BABYLON.Mesh.CreateTiledGround(...)

...

}

 

However, from http://doc.babylonjs.com/classes/3.1/tiledground#precision-w-number-h-number-, in the constructor of tiledground, I do find a optional parameter - canBeRegenerated

what is the meaning of this parameter?

Or which fields can be updated if this parameter set to true and how to update?

 

Thank you. 

Link to comment
Share on other sites

A TiledGround object extnds the Geometry object, which, under certain terms, can be regenerated. 

Regeneration will recreate all VerticesData, and will technically create a new geometry, disposing of the old one.  All you need to do is set the canBeRegenerated flag to true, and change the parameters according to your needs. Afterwards call the regenerate() function and you will have new data in the same object.

Notice that we are talking about the geometry (!) and not the mesh. A mesh has a geometry, which is of typte TiledGround (extending _Primitive, extending Geometry). So the mesh stays the same - its geometry changes. to get a mesh's geometry use mesh.geometry 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...