Jump to content

TiledGround Tutorial Issue - SubMesh Pushed Twice


Wingnut
 Share

Recommended Posts

Hi Gang!  Many questions.  (sorry)

**** Does anyone know the history-of or reason-for... https://github.com/BabylonJS/Babylon.js/blob/master/src/Mesh/babylon.subMesh.js#L14

During the creation of a SubMesh, it is automatically placed into the mesh.subMeshes array.  Is this somewhat new?  Anyone know?

MY reason for wanting to know?  Visit Kostar's cool Tiled Ground Tutorial... particularly playground demo #5.  See line 61, where our friend is pushing newly-created subMesh into the tiledGround.subMeshes array?  Well... that's no good.  :)

Inserting a console.log near line 65, reports that there are 128 subMeshes in Kostar's 64-tile ground.  (double, and we know why) 

Here is my own clone of Kostar's demo #5 - with console.log line showing 128 count.  A little adjustment to line 61, and things start working good, with a count of 64. 

Maybe Kostar needs a mail.  Maybe auto-pushing subMesh upon creation... is a bad idea.  Dunno.  Anyone know any history?  Is auto-pushing subMeshes... something new?  Bad?  Good?  Thoughts?  (thx)

Link to comment
Share on other sites

  • 2 months later...

I was just going to ask about this in a new topic (glad I found this and may now escape the shaming for not searching the forum properly :))

I'm working on a little script to create new subMeshes from a selection of faces of a complex mesh (selected via onClick) so that I can use MultiTexture for those subMeshes.

Now I noticed that mesh.subMeshes.push() seems to result in 2 subMeshes being pushed to the mesh.

Since the first suspect of such strange behaviour is always the non-coding-legend which is I (!), I also crosschecked with an existing example on the PG: http://www.babylonjs-playground.com/#YPL6T 

The engine doesn't seem to be bothered by this, but in my script I need to keep track of the exact number of existing subMeshes. A new selection could include faces of existing subMeshes which I have to alter in the process.

For now I'm just assigning it to a short lived temp. While assigning it to temp is not needed ... it just felt wrong to have new BABYLON.SubMesh() standing there all alone.. without "=" or anything .. and actually I'd really love to push() it ;)

let temp = new BABYLON.SubMesh(0, 0, verticesCount, indexStart, indexCount, mesh);

Results in exactly 1 subMesh

Link to comment
Share on other sites

Hey!

I don't think there is anything wrong in particular. I just didn't know that there was some kind of a subMesh auto-push happening .. and was rather glad that it was the same case in this PG (which I just copied from a multiTexture example somewhere here on the Forum) and not one of my silly mistakes.

I guess I just commented here for myself so when at some point in the future I have to switch back to using subMesh.push() I can remind myself why I didn't use it in the first place :D

 

Link to comment
Share on other sites

I love your personality, LH... you funnnnnny!  Good to have you with us! 

"escape the shaming for not searching the forum properly"  haha

"felt wrong to have new BABYLON.SubMesh() standing there all alone.. without "=" or anything .. and actually I'd really love to push() it"

Been there. hahaha.  I hate leaving objects sitting alone, outside in the cold, homeless, unappreciated.  :D

You're going to be comedic trouble around here, aren't you?  You'll fit-in perfectly. 

Link to comment
Share on other sites

Well thank you very much for those welcoming words :)

Since I decided to move entirely to babylon.js for my projects (was using three.js before) I'll be around here more often indeed.

Actually this forum is one of the reasons for me switching to babylon.js - never got any meaningful answers over at three.js (apart from the good ol' "Off to stack overflow ya go lllandrrrrat!")

Here I get answers from the engine's godfathers directly, so I guess I won't end up in a dead end so frequently.

Being able to port all my scripts over to babylon.js while saving somewhere around 40% lines of code per script, having a full functional playground thingy and getting many functionalities I had to script for myself in three.js neatly packed in 1 line function calls.. also helped.. and my never ending hope to get nicely blurvariance shadowmaps working for self-shadowing meshes in a later version of bjs *hint* ;)

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...