xaero59 Posted November 14, 2016 Share Posted November 14, 2016 I'm wondering if there's a way using the blender exporter to add custom attributes to a mesh ? Something very simple so that importedMesh.foo = bar Thanks ! Quote Link to comment Share on other sites More sharing options...
JCPalmer Posted November 16, 2016 Share Posted November 16, 2016 Blender meshes can / do have many properties. There is no official list of standard properties (any addon ours included) add a bunch. Simply adding an arbitrary custom property is not going to be possible for the exporter to deal with. True, if you use the Blender UI to add your own, it implies these must mean there is some way in the API to find them. You might research what that is, except for. 2nd problem is even if stuff gets written to a JSON file, does not mean the import process would make the transfer. There may be possible to use agreed upon property names. Wingnut 1 Quote Link to comment Share on other sites More sharing options...
max123 Posted November 16, 2016 Share Posted November 16, 2016 I had the same need and just iterated over meshes in JS, setting attributes inside a switch statement inside a loop: var name = myMeshes.name; switch (name) { case "foo": myMeshes[i].foo = "bar"; break; } You can use some naming convention if you have to deal with properties in Blender, e.g. call a mesh "item-property-fooBar" and then split the name in JS. Quote Link to comment Share on other sites More sharing options...
Wingnut Posted November 16, 2016 Share Posted November 16, 2016 Thanks JC and Max! Yeah, perhaps we need ONE user "storage tank" that makes the trip through the exporter. One recognized attribute name, such as .customData. I think there was a discussion about this... in some other thread. I think the discussion called it .userData. This attribute (property) would be put on Babylon.Node, yes? So any scene item... light, camera, mesh... could/would have a property with that exact same name. I wonder if JSON could be involved. If a user put serialized JSON in a Blender mesh/light/cam .customData, could/would it be an [object] after import to BJS? I would imagine so, if the data was valid JSON. But maybe that leads to trouble. One piece of carry-on luggage. Thx for the comments, guys. Quote Link to comment Share on other sites More sharing options...
xaero59 Posted November 16, 2016 Author Share Posted November 16, 2016 Thanks for the answers. Right now I'm naming the meshes with underscore and check for specific words in the meshes names ( if mesh.indexOf("foo")>-1 etc... ) but I felt it is a bit "hacky" I do agree with Wingnut, having mesh.userData or mesh.customData object would be awesome. On Babylon side , to give attribute to a mesh , BABYLON.Mesh.Parse function would need this addition : Mesh.Parse = function (parsedMesh, scene, rootUrl) { /*BJS ORIGINAL CODE*/ // Custom Mesh Data Addition if(parsedMesh.customData) { mesh.customData = parsedMesh.customData; } return mesh; } In babylon file , mesh.babylon, this would be structured like this : "meshes":[{"name":"mesh_name","id":"mesh_id","customData":{"foo":"bar", "foo1":"bar", "foo2":"bar"}, ...] Similar addition would have to be done for lights,camera etc... ( didn't checked how this is parsed by BJS ) The question is how hard it is on Blender side to extract custom properties ( https://www.blender.org/manual/data_system/custom_properties.html ) data and associate it to a specific mesh in the meshes object. As you can see , in javascript this is very easy and since we check for customData attribute , it would not break anything ( previously exported mesh or scene would keep working as usual just without customData ) Quote Link to comment Share on other sites More sharing options...
max123 Posted November 17, 2016 Share Posted November 17, 2016 I agree, @Wingnut. Having a user-defined properties object would be useful, but, to be honest, not essential. I don't find it too hard to create a lookup table in js Quote Link to comment Share on other sites More sharing options...
Wingnut Posted November 17, 2016 Share Posted November 17, 2016 Let's pretend. A mesh third-party modeling person says "Yes, you can use my mesh models free... IF you include my company name, my actual name, and my company url... WITH the mesh." I guess that is called "metadata". Nodes already have a .metadata property, but I don't know if that is earmarked for some other purpose. Some talk here: http://blender.stackexchange.com/questions/15729/metadata-notes-comments-in-blend-files Quite a few people are using BJS scene serializer to create saved BJS scenes. Node.metadata IS serialized with the scene, I believe. A potentially-large .metadata property could make those saves unnecessarily large. It might be wise to have an .includeMetadata Boolean flag on the serializer. But, eliminating that metadata from serializations... would also be against that mesh modeler's requirements for using his/her models. I dunno. As usual, I'm not qualified to have a say, here. Not enough experience. I guess I would delegate my opinion to @Deltakosh, @JCPalmer and @gryff, as they are wiser than I, on this subject. I suppose an active .metadata property would also cause a need for... scene.getMeshByMetadata( {author: fred} ) method, too. *shrug* This is related to our Tags System, too. Has anyone tried to make a custom attribute named .metadata... in Blender, then do an export, and see if the .metadata value makes the trip to BJS? Perhaps it already works. But I don't think so. No mention of .metadata in the Exporter or Tower of Babel info-files here and here. Quote Link to comment Share on other sites More sharing options...
JCPalmer Posted November 17, 2016 Share Posted November 17, 2016 metadata property was just added for Unity exporter, so whatever the format is (multiple-properties??) it would be read by fileloader for sure. If it handles multiple properties, one would figure out at the python / Blender API level, how to know that there are these Custom Properties added by the user. You could then edit the class FCurveAnimatable, to capture these (or a pointer / location of them). This is the base class of Mesh / Camera / Light, so you would only to add it once if done there. There is not currently a constructor, it might be considered to add one, and call super in each subclass constructor. In the to_scene_file method, write it out after it is figured out what fileloader wants. Good luck. Quote Link to comment Share on other sites More sharing options...
Wingnut Posted November 17, 2016 Share Posted November 17, 2016 https://www.blender.org/manual/data_system/custom_properties.html A little note at the bottom... about accessing. Still, there is no "isCustomProperties" flag that I can find, so far. Also in here: https://www.blender.org/api/blender_python_api_current/info_quickstart.html#custom-properties Quote Link to comment Share on other sites More sharing options...
gryff Posted November 17, 2016 Share Posted November 17, 2016 9 hours ago, Wingnut said: I guess I would delegate my opinion to @Deltakosh, @JCPalmer and @gryff, as they are wiser than I, on this subject. @Wingnut: Not sure I'm any wiser than you Wingy - and actually probably less wise. However, it did occur to me that it might be possible to have the Blender Babylon Exporter(BBE) allow for the exporting of "Tags" . A little box that enables "Tags" for a specific object, and when enabled a box to add the text for these "Tags". I'm not sure on two things: 1. Would this meet @xaero59 : requrements? 2. And would it involve serious heavy duty changes to @JCPalmer's excellent BBE? cheers, gryff Quote Link to comment Share on other sites More sharing options...
xaero59 Posted November 18, 2016 Author Share Posted November 18, 2016 Tags is a very nice feature but native javascript seems easier and more powerfull in this case ( the fact that it's possible to associate a value to a property really change everything ) , JCPalmer mentioned metadata and that would be exactly what we need , I checked BJS 2.5 code and metadata is indeed used in Mesh.Parse function ( and so it can be accessed in scene.meshes loop ) The problem seems to be more on blender api, the following example seems to be the way to get custom property but is it possible to differenciate custom properties from other properties or even loop through custom properties ?? : bpy.context.object["MyOwnProperty"] = 42 if "SomeProp" in bpy.context.object: print("Property found") 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.