Xanmia Posted March 20, 2014 Share Posted March 20, 2014 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. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted March 20, 2014 Share Posted March 20, 2014 we do not have that but you can add your own property at any moment with mesh.myProp = value do you think we need to add a specific property for that? Like a mesh.tag property? Quote Link to comment Share on other sites More sharing options...
Dad72 Posted March 20, 2014 Share Posted March 20, 2014 This would be helpful Yes for me for mesh.taggood idea to add a tag to an object Quote Link to comment Share on other sites More sharing options...
gwenael Posted March 20, 2014 Share Posted March 20, 2014 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 }; adam 1 Quote Link to comment Share on other sites More sharing options...
Dad72 Posted March 20, 2014 Share Posted March 20, 2014 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. Quote Link to comment Share on other sites More sharing options...
Xanmia Posted March 20, 2014 Author Share Posted March 20, 2014 One of the reasons I used it in Three.js was in tandem with the editor(http://threejs.org/editor/). So I could set up a scene, set specific values for that mesh and then export the scene to import into my code.I know I used it for something else and I can't recall now... figures Thoughts? Quote Link to comment Share on other sites More sharing options...
gwenael Posted March 20, 2014 Share Posted March 20, 2014 @dad72, sorry I don't understand what you mean @Xanmia, so what you need is a data property on the mesh stored in the .babylon file of your scene, isn't it? Quote Link to comment Share on other sites More sharing options...
Xanmia Posted March 20, 2014 Author Share Posted March 20, 2014 @gwenael that's a good point, it could live there. Quote Link to comment Share on other sites More sharing options...
Dad72 Posted March 20, 2014 Share Posted March 20, 2014 @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. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted March 20, 2014 Share Posted March 20, 2014 The point is different is we save the tag property. In this case it can be used to serialize info with your scene Quote Link to comment Share on other sites More sharing options...
Xanmia Posted March 20, 2014 Author Share Posted March 20, 2014 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. Quote Link to comment Share on other sites More sharing options...
gwenael Posted March 21, 2014 Share Posted March 21, 2014 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 bemyMesh.data = { property1: value1, property2: value2 }; Xanmia 1 Quote Link to comment Share on other sites More sharing options...
Dad72 Posted March 21, 2014 Share Posted March 21, 2014 I am delighted to have been understood It is exactly that Gwenael gwenael 1 Quote Link to comment Share on other sites More sharing options...
gwenael Posted March 21, 2014 Share Posted March 21, 2014 @dad72: maybe you can suggest it here http://www.html5gamedevs.com/topic/3865-what-do-you-want-in-babylonjs Quote Link to comment Share on other sites More sharing options...
Xanmia Posted March 21, 2014 Author Share Posted March 21, 2014 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.... adam 1 Quote Link to comment Share on other sites More sharing options...
gwenael Posted March 21, 2014 Share Posted March 21, 2014 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 Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted March 21, 2014 Share Posted March 21, 2014 AFAIC, here is the plan:- Add a .userData property that will be saved/loaded from .babylon file- Add a .tags property which will be an array of string and add a scene.getMeshesByTags([tags]). This property will also be serialized Thoughts? gwenael, c75 and Xanmia 3 Quote Link to comment Share on other sites More sharing options...
Xanmia Posted March 21, 2014 Author Share Posted March 21, 2014 Sounds good to me! Quote Link to comment Share on other sites More sharing options...
Dad72 Posted March 21, 2014 Share Posted March 21, 2014 This seems to me well. Quote Link to comment Share on other sites More sharing options...
gwenael Posted March 21, 2014 Share Posted March 21, 2014 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? Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted March 21, 2014 Share Posted March 21, 2014 I suggest using either a function as parameter to let the user define if the tag is ok or not, or a list of accepted tags (like tag1 || tag2 || etc..) Quote Link to comment Share on other sites More sharing options...
gwenael Posted March 22, 2014 Share Posted March 22, 2014 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/ Dad72 1 Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted March 24, 2014 Share Posted March 24, 2014 Eval is prohibited due to security issues with win8 Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted March 24, 2014 Share Posted March 24, 2014 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; } Xanmia and Dad72 2 Quote Link to comment Share on other sites More sharing options...
Wingnut Posted April 2, 2014 Share Posted April 2, 2014 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.