Closed berry4u closed 3 years ago
Without having to resort to custom extensions, There's two places you can use to write "plain text":
.Name property Almost all objects in a glTF scene, including meshes, have a "Name" property. glTF itself does not use this property for anything, and glTF authors are free to fill this property with any text.
It is true that the Name is more intended for short names like "Cube05" and stuff like that, but there's nothing in the schema that prevents from writing longer descriptions... it's endeed a "Free text" property.
.Extras property Now, if you also want to use the Name property for setting the mesh name, and you also want to set a description, the other option is the Extras property, which is a JSON node.
From SharpGLTF, you can use the extras property like this:
// writing
var mesh = modelRoot.LogicalMeshes[3];
var extras = mesh.TryUseExtrasAsDictionary(true);
extras["IFC-Description"] = "My mesh description goes here";
// reading
var mesh = modelRoot.LogicalMeshes[3];
var extras = mesh.TryUseExtrasAsDictionary(false);
var ifcdesc = extras == null ? null : extras["IFC-Description"] as String;
Keep in mind that the extras property is accesible only from the Schema2 namespace. So if you're building your scene with the toolkit's SceneBuilder, SceneBuilder namespace does not have Extras property support, so you'll have to do some mapping and then write the extras directly to the logical meshes.
Hello! How can I implement writing not an array or a dictionary, but my own class as an object? Example: "extras":{ "Params":[ {"name":"Somestring1","datatype":"Somestring2","value":"Somestring3"}]}
@EugeneNIghtingale This is a serialization problem.
Keep in mind that when you set the Extras property, it is not serialized to json immediately, but when you save your model. So until then, I have to keep the data stored in memory in one way or another. And lists and dictionaries is the closest match to a json object.
Maybe it is possible to serialize your class to json, and then have an intermediate pass that would copy the json content to the lists and dictionaries in Extras, so the serialization/deserialization process woud be like this:
Custom Class => Json Text => Object/List/Dictionary => Extras Property Extras Property => Object/List/Dictionary => Json Text => Custom Class
I have used extras to write the Dictionary data to root model and it worked fine. I need to write extras for every part written in scene. can we use extras in scene?
@prasad-debug As far as I know, yes, the Extras property is available in almost all classes of a the schema, including the Scene.
Thank you for the information. I have used Scenebuilder to fill the tessellated data and then converted it into schema2. I m able to add the properties to whole tessellated data, I'm looking for something in which the properties are added in scene builder along with position normal and textcoords. is there any way through which we can achieve it?
SceneBuilder does not have any extras feature yet, I have to figure out an API to do that.
So for now, do it the way you're doing it right now, and at some point I'll introduce an API to support extras along all the *Builder APIs.
Thank you for helping me out with my query. As suggested ill continue using the current approach of adding properties and will wait for the API to support extras in scenebuilder to be introduce soon.
The new alpha21 has a much improved API for working with Extras, hope this will solve your problem.
I need to translate IFC geometry to GLTF enriching meshes with some description. Is there a way to to this?
Thank you very much.
Berardo