Joined: Nov 11, 2011
Post Count: 5
Status:
Offline
HomePieceOfFurniture - model color
I'm writing my first plugin for SweetHome3D. So far, the experience has been excellent, I was able to implement very quickly what I had in mind.
However, there's one last thing left that I'm stuck with right now. I'm trying to get the color(s) of a certain HomePieceOfFurniture that is part of a Home. When I set the color in the application, I can call HomePieceOfFurniture.getColor() to get an RGB Integer. However, for pieces where the color has not been set, this will return null.
Which is understandable.
But how do I get to the colors of the pieces of the actual model? Say I have a table - how do I find the RGB value of the table top?
Any advice is greatly appreciated! Thanks in advance.
France
Joined: Nov 7, 2005
Post Count: 9427
Status:
Offline
Re: HomePieceOfFurniture - model color
Welcome among Sweet Home 3D developers. If you're trying to program a plug-in that will allow users to change the color of the different parts of a piece of furniture, it would be greatly appreciated. Do you plan to share your plug-in?
But how do I get to the colors of the pieces of the actual model?
This information is only in the 3D model and more complicated to get. You'll have to read the model of the piece with one of ModelManager class loadModel methods and search recursively the Material colors in the appearance of its shapes. Looking at PieceOfFurnitureModelIcon inner class and HomePieceofFurniture3D class will give you many hints to achieve this faster. Note that if you want the changed colors to be saved at the end (and/or want the change to be applied only to the edited furniture when it shares the same 3D model with others), you'll have to generate a new temporary 3D model file for the updated furniture with OBJWriter and store its URL in the model of the piece with a TemporaryURLContent instance.
Good luck!
----------------------------------------
Emmanuel Puybaret, Sweet Home 3D creator
Joined: Nov 11, 2011
Post Count: 5
Status:
Offline
Re: HomePieceOfFurniture - model color
Thank you very much for your information, I was able to implement what I had in mind now. I had actually noticed the ModelManager class before, but frankly I find it a bit unintuitive that that is the preferred way to reach the 3D model data: why would I have to 'loadModel' when the model obviously is in the memory already somewhere? Does 'loadModel' actually hit the disk again and then duplicates the model data, or does the ModelManager do some kind of caching?
Unfortunately, the plugin is not for changing colors of different parts of a model, it's merely an exporter. :( Sorry to disappoint you!
That probably makes it of limited interest to others (especially, since it is a homebrew format I want to export to), but I could still ask my boss if we can open-source it, if you think somebody else might benefit from it.
France
Joined: Nov 7, 2005
Post Count: 9427
Status:
Offline
Re: HomePieceOfFurniture - model color
Does 'loadModel' actually hit the disk again and then duplicates the model data, or does the ModelManager do some kind of caching?
You're right it's probably not the best name for a method that does some caching, used here to avoid decoding twice the same 3D model file and to share the geometry data of a model.
Unfortunately, the plugin is not for changing colors of different parts of a model, it's merely an exporter. :( Sorry to disappoint you!
Let's hope my explanations will be helpful for an other developer!
That probably makes it of limited interest to others (especially, since it is a homebrew format I want to export to), but I could still ask my boss if we can open-source it, if you think somebody else might benefit from it.
It's always interesting to see how other developers use some API, even if very few or none end-users use it.
----------------------------------------
Emmanuel Puybaret, Sweet Home 3D creator
Joined: Nov 11, 2011
Post Count: 5
Status:
Offline
Re: HomePieceOfFurniture - model color
Ah, okay, so 'loadModel' actually does do some caching, right? That makes me feel much better ;-)
In the meantime, I've asked my boss about giving out the code and she's fine with it. I have to figure out licensing issues, but since it's only a small plugin that shouldn't be a big deal.
What's the preferred way to publishing Sweet Home 3D-related code? Do you guys collect outside contributions somewhere? Would you like me to send you the code, or do you prefer a place like github?
France
Joined: Nov 7, 2005
Post Count: 9427
Status:
Offline
Re: HomePieceOfFurniture - model color
Until now, the plug-ins and their source code are published in this SourceForge tracker, but feel free to publish it somewhere else and link to it here.
----------------------------------------
Emmanuel Puybaret, Sweet Home 3D creator