Material improvements

A forum to discuss the implementation of a good Materials system in FreeCAD
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
eivindkvedalen
Posts: 602
Joined: Tue Jan 29, 2013 10:35 pm

Re: Material improvements

Post by eivindkvedalen »

damian wrote:Good Morning @eivindkv:
Thank you for 4.000 lines and 49 files of code. Incredible! :lol:
Thanks :-D
1º) will the MaterialComposition have layers?
No, the matter in a solid consists of a single material. However, this is described by a list of materials. The difference between the composition and the stack is the way how the look-up of its properties is done.

For a composition, the look-up is started at the top of the stack, and the first match is returned. This makes it possible to override sub-sets of a material by stacking another on top. E.g if you read the post by bernd, he would like to have concrete with different values for YoungsModulus. This is possible by having a "standard" concrete at the bottom of the stack, and then different materials with only one property (or a few), YoungsModulus, that differentiates one type of concrete from another.

For surfaces, think of the stack as a bunch of physical layers. When searching for a property, you must first specify the layer in which to do the look-up. As an example, think of an object with a background color and a silk-print on top. One layer would then specify the background color, and the second one could specify a transparent texture that would be put on top. This is how I envision it; it is not implemented yet :)
2º) could a solid have a MaterialComposition? The question is with a single solid, no with a compsolids.
Each solid is a MaterialComposition object, and the Material property contains an array of solids to cover compsolids.
3º) how will the thickness of every layer be specified?
This could be specified as a property, but would not easily be reflected in the geometric model.

Eivind
eivindkvedalen
Posts: 602
Joined: Tue Jan 29, 2013 10:35 pm

Re: Material improvements

Post by eivindkvedalen »

ickby wrote:Hello,

I have no clear picture about material support, but one note on the API: In the code examples you provided you access Materials like "Solid[0]", which indicates the usual freecad python subshape accessing scheme by index. Accessing subshapes however does also work by strings, like "Face1" or "Edge2" in TopoShape class which should also be supportet in your API. This may sound like splitting a hair, and it definitely is for the current situation. However, ezzy is currently working hard on topological naming. Once done it is quite likely that the string based subshape identification can use tnaming, as this is what the link properties use, but not the indexed based identification. So maybe it is a good idee to have that in mind while designing the API and the underlying data structure. Your code will suffer from naming issue like everything else that uses subshapes. And on second note it would be nice to have both options for specifying subahpes anyway :)
Yes, I know this structure will face the same problems wrt topological naming. I can add string based look-up to the API for completeness; the implementation will most likely change a lot when topological naming is sorted out.

Eivind
triplus
Veteran
Posts: 9471
Joined: Mon Dec 12, 2011 4:45 pm

Re: Material improvements

Post by triplus »

eivindkvedalen wrote:I have also added a Python interface (this is what I actually use for testing), and a typical use-case could be:

App.ActiveDocument.Box.Material.setSolidMaterial(0, "PLA");

...

Please let me know what you think.

Eivind
Hi Eivind!

I was thinking about this for a while and this weekend i will finally have some time to test it. Is this still the latest branch to test?

https://github.com/eivindkv/free-cad-code/tree/Material
eivindkvedalen
Posts: 602
Joined: Tue Jan 29, 2013 10:35 pm

Re: Material improvements

Post by eivindkvedalen »

triplus wrote:
Hi Eivind!

I was thinking about this for a while and this weekend i will finally have some time to test it. Is this still the latest branch to test?

https://github.com/eivindkv/free-cad-code/tree/Material
Yes, I have had too little time for FreeCAD lately, so it is still the latest branch...

Eivind
triplus
Veteran
Posts: 9471
Joined: Mon Dec 12, 2011 4:45 pm

Re: Material improvements

Post by triplus »

eivindkvedalen wrote:Yes, I have had too little time for FreeCAD lately, so it is still the latest branch...

Eivind
No problem i just wanted to make sure i will try out the latest code. I tried to compile the code today and it looks like 2 files are missing. In src/App/Application.cpp (line 115 and 116):

Code: Select all

#include "MaterialDatabasePy.h"
#include "FileMaterialSourcePy.h"
It doesn't look like this is available ATM.
eivindkvedalen
Posts: 602
Joined: Tue Jan 29, 2013 10:35 pm

Re: Material improvements

Post by eivindkvedalen »

triplus wrote:
eivindkvedalen wrote:Yes, I have had too little time for FreeCAD lately, so it is still the latest branch...

Eivind
No problem i just wanted to make sure i will try out the latest code. I tried to compile the code today and it looks like 2 files are missing. In src/App/Application.cpp (line 115 and 116):

Code: Select all

#include "MaterialDatabasePy.h"
#include "FileMaterialSourcePy.h"
It doesn't look like this is available ATM.
hmm.. Just try to remove them from Application.cpp. I changed the way I do the Python integration, so I don't think they are needed anymore.

Eivind
triplus
Veteran
Posts: 9471
Joined: Mon Dec 12, 2011 4:45 pm

Re: Material improvements

Post by triplus »

eivindkvedalen wrote:hmm.. Just try to remove them from Application.cpp. I changed the way I do the Python integration, so I don't think they are needed anymore.

Eivind
Yes i did that but it didn't help. I got a lot of errors after for example:

Code: Select all

error: ‘FileMaterialSource’ was not declared in this scope
         _pMaterialDatbase->addMaterialSource(std::make_shared<FileMaterialSource>("System", system_dir.c_str()));

Code: Select all

note: forward declaration of ‘class App::MaterialDatabase’
 class MaterialDatabase;
About 30 lines of errors and notes.
eivindkvedalen
Posts: 602
Joined: Tue Jan 29, 2013 10:35 pm

Re: Material improvements

Post by eivindkvedalen »

triplus wrote: Yes i did that but it didn't help. I got a lot of errors after for example:
...
About 30 lines of errors and notes.
I recreated the problem here after I removed some old auto-generated files were still in my build directory. I've fixed, rebased, and pushed a new branch: https://github.com/eivindkv/free-cad-co ... /Material2

Eivind
triplus
Veteran
Posts: 9471
Joined: Mon Dec 12, 2011 4:45 pm

Re: Material improvements

Post by triplus »

eivindkvedalen wrote:
triplus wrote: Yes i did that but it didn't help. I got a lot of errors after for example:
...
About 30 lines of errors and notes.
I recreated the problem here after I removed some old auto-generated files were still in my build directory. I've fixed, rebased, and pushed a new branch: https://github.com/eivindkv/free-cad-co ... /Material2

Eivind
I can confirm this branch compiles now. There are still some (very likely not your changes related) issues involved and i needed to disable few modules to successfully compile your branch. Likely related to this:

viewtopic.php?f=10&t=16021&start=30#p140382

Therefore you might want to provide a branch containing the latest changes in the future for other testers compiling without issues. I tested as described:

viewtopic.php?f=10&t=16714&start=10#p134905

It seems to work OK but if i try to:

Code: Select all

App.ActiveDocument.Box.Material.Solid[0].YoungsModulus
I get:

Code: Select all

RuntimeError: Unable to resolve property YoungsModulus (missing material?)
Therefore i am guessing you just added sample code and PLA material isn't available yet in the database?
eivindkvedalen
Posts: 602
Joined: Tue Jan 29, 2013 10:35 pm

Re: Material improvements

Post by eivindkvedalen »

triplus wrote:
It seems to work OK but if i try to:

Code: Select all

App.ActiveDocument.Box.Material.Solid[0].YoungsModulus
I get:

Code: Select all

RuntimeError: Unable to resolve property YoungsModulus (missing material?)
Therefore i am guessing you just added sample code and PLA material isn't available yet in the database?
I think that the PLA material definition isn't in the right location; I think I had to copy the files manually when testing. The file-based materials are supposed to be in either

getResourceDir() + "/Mod/Material/StandardMaterial"

or

getUserAppDataDir() + "Materials"

Eivind
Post Reply