Jump to content

User Data in mesh object?


Xanmia
 Share

Recommended Posts

Well, I do want to know the reasons, and babylon.js is not other engines.  It is an EASY engine.  But its learning curve gets steeper with every added function.  I will wait for further opinions, but thank you for yours.

Link to comment
Share on other sites

As far I'm concerned, it doesn't bother me to have all these functions and internally they could use the one you suggest Wingnut but you're right they are more helpers than "must be there" functions and could easily put in the tools file and be static. We can suggest this to Deltakosh. Another suggestion I have: that would be nice to have tags and user data on meshes, why not have them on cameras and lights too? My idea is to try to put as much as possible in Node and inherit everything from there. Moreover the functions could be overriden in sub classes such as Mesh.

Link to comment
Share on other sites

I understand what you are saying @Wingnut with the more that is added the harder Babylon.js is to learn but i think thats where Deltakosh comes in and overrides our crazy ideas  :).  Otherwise, I like how Gwenael stated it and agree with the node approach.

Link to comment
Share on other sites

Yes, I agree with node being a good place to add these things, but again, that means cameras, lights, and mesh... all get another property (in their api documentation), and then likely...

 

scene.getMeshesByTag(tagname)

scene.getLightsByTag(tagname)

scene.getCamerasByTag(tagname)

 

... all get added to our already-bloated (imho) scene class.  *sigh*

 

3 properties added, 3 methods added, for one feature.  erf.  Do that enough and you become threeJS.  (dread)

 

I would love to see ALL the getFooByFoo() stuff... moved to Tools.  I doubt that will happen.  "Too late", likely.

 

BABYLON.Tools.getFooByFoo(Foo)?  *nod*  That would get those girly toys out of the way of us REAL men.  :D  Real men do their own lookups from three power arrays... scene.meshes, scene.lights, and scene.cameras... with manly FOR-loops.  We iterate, baby.  (huh?)  Anyway, I have said all this 'opinion' of mine, before.  As long as I get to play with babylon.js, I am cool with whatever happens.

 

Maybe those three power arrays should be enumerables... maybe collections or vector objects... something even MORE manly.  j/k  :)

Link to comment
Share on other sites

Answer to Wingnut's question http://www.html5gamedevs.com/topic/3865-what-do-you-want-in-babylonjs/?p=33076:

 

I use for/in loop to loop through the properties of an object (http://www.w3schools.com/js/js_loop_for.asp) and I think using the 'var' is the proper way to use the loop but I'm not a javascript expert.

 

I also use for/in to loop through items of an array to skip not set items (undefined but not set to undefined...). Here are some experiments that I did a while ago: http://jsfiddle.net/gwenaelhagenmuller/9pJVd/. Please read the code and what it's logged in the console.

Link to comment
Share on other sites

Thanks gwenael.  And thank you too, SideraX.  Good to know. 

 

Yeah, I use FOR-IN sometimes, too. I just never use the 'var' like that.  I was wondering if there had been an ecma recommendation issued that said "thou shalst use a var in for-in"  :) 

 

I see there is forEach now, too, (in the newer ECMAscript), but I'm hearing rumors that it runs slower than other FOR loops.  It looks like SideraX has done the research.  :)

 

Since we are in this topic...  I see that tags are active.  Is .userData also going to be installed, or has it?  Did that idea originate with Blender?  Is it a place for the scene builder person to put any text they choose, and of any length?  Do you think we will see/make a method to display .userData, possibly onmouseover the mesh... that pops open a little window like HTML 'alt' did in the old days?

 

Seems I remember a longdesc="blah blah" on html elements, too.  I suppose the programmer could do anything they choose with data in a .userData property... make it a pop-open, use it for notes-to-self, etc.  Ok, i will stop babbling now and watch this discussion move forward on topic.  :)

Link to comment
Share on other sites

  • 3 weeks later...

A second note about using "for...in" loops for arrays - it will break if other scripts add stuff to the Array.prototype.

 

 

I hit this problem when trying to integrate a page that had both babylon and noVNC.  noVNC had added a couple of functions to the Array's prototype, and babylon tripped over them when iterating over arrays.

 

 

 

While investigating the problem, I found this Stack Overflow discussion that lead me to find the problem.  I am still considering how to best fix it.

Link to comment
Share on other sites

Thanks holcombj67 for sharing this.

I'm not a javascript expert and I'm aware that my answer won't solve your problem but I'm not sure it's a good practice to surcharge Array's prototype (or the prototype of any other default type). Arrays in javascript can be used as dictionaries would be used in c#, that allows to have "variables" names with space in them.

var d = {};d.key1 = "value1";d.key2 = "value2";d.key 3 = "value3"; // ERRORvar d2 = [];d2["key1"] = "value1";d2["key2"] = "value2";d2["key 3"] = "value3";//d2.length = 0 => cannot do for(var index=0; index<d2.length...
Link to comment
Share on other sites

  • 2 weeks later...

Wow, lots of good information about for-in, well done, all of you. I think I speak on behalf of many of the forum readers.  Very interesting.  Xanmia, we seriously hijacked your thread, but you are becoming a hero just the same.  :)

Link to comment
Share on other sites

I will continue to hijak your thread ^^

 

When I need to use associative array in JS, I prefer use this implementation of a Hashmap : 

https://github.com/SideraX/sefjs/blob/master/src/utils/Hashmap.ts (I writed it after some inspiration here and there for my Entity-Component-Systems framework - which I use it to develop my game on top of Babylon)

 

It will save the data in packed array (hole in array are bad : http://www.smashingmagazine.com/2012/11/05/writing-fast-memory-efficient-javascript/ ) for an efficient foreach and the key can be a string or an int (it will not impact the perf).

 

Perf : for..in vs hasmap.foreach() : 

http://jsperf.com/hashmap-vs-natif-object

Apart for some unholy optimization than V8 seems to do on object with few property (Firefox don't). Hashmap.foreach is way more fast.

 

Perf : object[key] vs hasmap.get(key)

http://jsperf.com/hasmap-vs-natif-object-get

Performence are practically the same :)

 

And if you need even faster for, you can do (but you will not have the key in this case) :

var val = hashmap.values();for (var i = 0, len = val.length; i < len; i++) {  val[i];}

Some drawback : Hashmap will take more memory and the delete method is a bit slow (needed to keep arrays packed).

 

Maybe we can put this class in BABYLON.Tools alongside Smartarray and nobody will have excuse to use for..in again :P

Link to comment
Share on other sites

  • 1 year later...

Hey guys I know this is a really old thread but I am curious if it is yet possible to add mesh data or tags in the Babylon file?

I have looked and I don't see an option for tags or mesh data in the babylon file...so probley not but I think it could be really useful if we can set the data or tags through one of the exporters such as 3ds max or just manually by editing the babylon file

 

Anyway I know this has been brought up in this thread already but I have just found a need for it so I thought I'd bring it up

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