Jump to content

User Data in mesh object?


Xanmia
 Share

Recommended Posts

I only have Three.js to reference...

 

But in Three.js there is a User Data object in mesh to store any json data you might want/need, is there a similar object in BabylonJS mesh?  

 

I didn't see anything in the documentation and nothing obvious when inspecting the mesh object.

Link to comment
Share on other sites

I think adding the properties that you want on a particular mesh is better, I don't see a reason to add a specific 'tag' property since it can be done in your own script. If you want to add custom data, I would suggest to add a property on the mesh that you want, let's say 'data' or 'tag', and assign to it a javascript object that has its properties.

mesh.myData1 = value1;mesh.myData2 = value2;
myMesh.data = { property1: value1, property2: value2 };
Link to comment
Share on other sites

And it should be a getMeshByTag() with mesh.tag.

 

mesh.mydata or mesh.data there is no exist in the mesh class and it costs nothing to add the ability to create tag and be able to locate an object by tag. (The Unity Editor allows to create tags for example, they have their utilities.)

 

For example, an object has several name differently and can have several same tag. It makes no sense to you, but this makes sense to me who would the utility for my project.

Link to comment
Share on other sites

@dad72, sorry I don't understand what you mean

 

En gros, les tags sont comme des noms d'objets. cela permet par exemple l'ors de l'exclusion de mesh  qui ne reçoit pas de lumière, de dire que telle tag ne la reçoit pas au lieux de choisir un mesh ou un nom d'objet.

sa veux dire que tout les objet ayant comme tag "truc" ne reçoit pas de lumière.

 

C’est un exemple parmi d'autre. Un objet a un nom unique, tandis que un objet peut avoir plusieurs tag. ainsi, on peut rechercher un mesh par son nom unique ou par tag pour rechercher plusieurs objet ayons ce tag.

 

Désoler, j'écris en français pour être mieux compris.

Link to comment
Share on other sites

I need to learn french... :)  

 

For Three.js they actually live in both locations. In the json in the scene layout file and the mesh object itself.  

I believe the json is just mimicking the mesh object.

 

It seems to really only exist for that layout and probably a basic/simple storage of sorts for users.

I don't think its a have to have but more of a nice to have or good option in some cases.

Link to comment
Share on other sites

En gros, les tags sont comme des noms d'objets. cela permet par exemple l'ors de l'exclusion de mesh  qui ne reçoit pas de lumière, de dire que telle tag ne la reçoit pas au lieux de choisir un mesh ou un nom d'objet.

sa veux dire que tout les objet ayant comme tag "truc" ne reçoit pas de lumière.

 

C’est un exemple parmi d'autre. Un objet a un nom unique, tandis que un objet peut avoir plusieurs tag. ainsi, on peut rechercher un mesh par son nom unique ou par tag pour rechercher plusieurs objet ayons ce tag.

 

Désoler, j'écris en français pour être mieux compris.

 

Got it :) That's the same idea as tags used in forums. For those who haven't learnt French yet ;) here's the idea:

 

dad72 would like to have a 'tags' property on meshes. Its value would be a list of tags (words) separated by spaces like CSS classes in HTML. It's a way to categorize/group meshes so you could get all meshes that have a specific tag like you would do to select DOM elements according to their classes. Thanks to that you could exclude from a light all meshes which have the tag "notLightedByLight1" (for example).

myMesh.tags= "notLightedByLight1 character hero";

As far as I'm concerned I think that's a great idea and that could be useful especially when there is a babylon.js game editor ;). A mesh could have several tags and it would be possible to retrieve all meshes having a specific tag or a mix of tags, etc.

 

That said, I think it's not directly relative to Xanmia's demand. If I have well understood him, he would like to store custom data in a mesh. That's not a list of tags but could be

myMesh.data = { property1: value1, property2: value2 };
Link to comment
Share on other sites

Not exactly the same but it is extremely similar to how I would use it.

Wouldn't the custom data give you a bit more flexibility?

 

You could still do something like:

myMesh.data = { tags: [a, b, c], property2: value2 };

Although then you don't really have the option for a getMeshByTag() since you wouldn't be requiring tags....

Link to comment
Share on other sites

As far I'm concerned, separating tags and data would be better, otherwise you could also have positions, rotations and so on in data ;). Tags could be used by anyone and well documented whereas data would be the property that anyone could use for whatever he/she wants to do with it, something like <extra> tag in Collada

Link to comment
Share on other sites

scene.getMeshesByTags([tags])

How will it work? Will it retrieve all meshes which contain at least all tags Inside of [tags]?

 

Could we provide a boolean sentence? I mean something like:

 

scene.getMeshesByTags("((tag1 && tag2) || tag3 || tag4) && tag5", atLeast) where atLeast is a boolean which is true if the retrieved meshes can have more tags than the one specified by the boolean sentence?

Link to comment
Share on other sites

BABYLON.Scene.prototype.getMeshesByTags = function(tagsQuery) {    var meshes = this.meshes;        if (tagsQuery === undefined) { // returns all meshes        return meshes;    }        var meshesByTags = [];        if (tagsQuery === "") { // returns meshes which have at least one tag        for(var i in meshes) {            var mesh = meshes[i];            if(mesh.tags && mesh.tags !== []) {                meshesByTags.push(mesh);            }        }    }    else {        var toEvaluate = tagsQuery.replace(/[\w-]+/g, function(r) { return "mesh.tags[\"" + r + "\"]"; });                for(var i in meshes) {            var mesh = meshes[i];            if(mesh.tags && eval(toEvaluate)) {                meshesByTags.push(mesh);            }        }    }        return meshesByTags;}

You may not be a big fan of "eval" though.

 

Here's the jsfiddle to test it: http://jsfiddle.net/gwenaelhagenmuller/vLpK9/

Link to comment
Share on other sites

BABYLON.Scene.prototype.getMeshesByTags = function(tagsQuery) {

var meshes = this.meshes;

if (tagsQuery === undefined) { // returns all meshes

return meshes;

}

var meshesByTags = [];

if (tagsQuery === "") { // returns meshes which have at least one tag

for(var i in meshes) {

var mesh = meshes;

if(mesh.tags && mesh.tags !== []) {

meshesByTags.push(mesh);

}

}

}

else if (tagsQuery instanceof function) {

for(var i in meshes) {

var mesh = meshes;

if(tagsQuery(mesh.tags)) {

meshesByTags.push(mesh);

}

}

}

else {

// Return all meshes with at least one tag from the list

for(var i in meshes) {

var mesh = meshes;

for (var tagIndex in mesh.tags) {

var tag = mesh.tags[tagIndex];

if(tagsQuery.indexOf(tag) !== -1) {

meshesByTags.push(mesh);

break;

}

}

}

}

return meshesByTags;

}

Link to comment
Share on other sites

  • 2 weeks later...

I'm starting to smell scene.match() and regexp.  Anyone else smell that?  I also smell metadata and keywords.  I smell something else, too, but I think it is something on my shoe.  :)

 

I think we are starting down a questionable path of scene.getAnythingByAnything.

 

scene.getMeshesByTags() and scene.getMeshesByUserdata()

 

...will promote adding

 

scene.getCamerasByTags() and scene.getCamerasByUserdata()

 

and...  scene.getLightsByTags() and scene.getLightsByUserdata()

 

Next, we will want wildcards and pattern matching like... scene.getMeshesByName(*"_west_building")

 

And... scene.getLightsById("upper_deck_"*);

 

I am not sure if this path is a wise path to take.

 

Why not let the user build their own 'find' function?

function find(key, array) {  // The variable results needs var in this case (without 'var' a global variable is created)  var results = [];  for (var i = 0; i < array.length; i++) {    if (array[i].indexOf(key) == 0) {      results.push(array[i]);    }  }  return results;}

(not my code, found on web) 

 

Then the user can set 'array' = scene.meshes, scene.lights, scene.cameras, scene.activeCameras, mesh.animations, etc.  I think we need to stop the getSomethingBySomething epidemic.

 

All I am saying is that maybe the searching and matching should be up to the user, not the framework.  *shrug*  If we leave the lookups to the user, then the framework can remove ALL getSomethingBySomething, yes?  I am not very experienced in this subject, though.

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