When I load object florm .obj, the attributes are taken from .mtl, assigned to objects by material names when the parser finds o or g lines. The material name is 'forgotten' but material's attributes are kept in object. When serializing some of them, like texture names are exported but some are not. If the object is not bound to a material anymore, how can I retrieve it's attributes?
The point is, I have a nice looking model in .obj & .mtl and I want it look nicely when I load it, faster, from a serialized form. And I cannot rewrite code whenever I change a model. For now I have retrieved from .mtl transparency data like that:
Map<String, Float> transMap = new TreeMap<>(); // <MaterialName, d attribute>
transMap.put("glass", 0.34f);
transMap.put("windscreen", 0.44f);
transMap.put("lights", 0.52f);
Only because I split earlier all objects to face groups by material, adding material to group names (because transparency is assigned by object an I had multimaterial objects) I could strip the object name from the original name and _jPCTnn suffix and reassign transparency after importing serialized model.
for (Object3D element : elements) {
String elementMaterial = extractMaterialName(element.getName());
Float transparency = transMap.get(elementMaterial);
if (null != transparency) element.setTransparency((int) (100f * transparency)); // is this formula correct?
}
This, however, is an workaround that I cannot use in production because each model would need some implementation.
Of course, I can add all needed material attributes to object names (is there a limitation on object length?) but if we went to binary serialization to avoid text parsing overhead, it's not the direction we'd like to go.