Macro Texture Objects

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!
User avatar
bernd
Veteran
Posts: 12851
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Macro Texture Objects

Post by bernd »

Found the Macro Texture Objects and tested with imported material from ifc-file. I could'nt helpt to post the screens. I still need to clean and post the code for importing materials and properties. :oops:

some problems left:
- how to get rid of the textures without closing the file
- scale of the textures (roof and bricks)
- orientation (bricks sometimes going upwards)

Code: Select all

def textureMaterial():
  """ Texturen nach Material setzen
  
  """
  import FreeCADGui
  from PyQt4 import QtGui
  from pivy import coin
  print "Texturen"
  texturefilepath = '/home/hugo/Documents/projekte--ifc/freecad/BIM--IFC/Texturen--Vorlageproj/'
  material2texture = { 'noMaterial'          : texturefilepath+'noMaterial.jpg',
                       'Beton'               : texturefilepath+'beton_bewehrt.jpg',
                       'Backstein'           : texturefilepath+'backstein.jpg',
                       'Kalksandstein'       : texturefilepath+'kalksandstein.jpg',
                       'Baustahl'            : texturefilepath+'stahl.jpg',
                       'Eindeckung'          : texturefilepath+'dachziegel.jpg'
                      }
  for o in FreeCAD.ActiveDocument.Objects:
    if '_FreeCAD_shape_body' not in o.Name:    # es waere cooler ein eigenes PythonFeature
      if hasattr(o,'Shape'):         
        o.ViewObject.Visibility = True 
        if hasattr(o,'IfcObjectType') and hasattr(o,'IfcMaterial'):
          o.ViewObject.Transparency = 0
          o.ViewObject.ShapeColor = (1.0,1.0,1.0)
          rootnode = o.ViewObject.RootNode
          tex =  coin.SoTexture2()
          tex.filename = material2texture['noMaterial']  # weisse textur
          
          if o.IfcMaterial in material2texture:
            #print material2texture[o.IfcMaterial]
            tex.filename = material2texture[o.IfcMaterial]
          else:
            print (o.Name + ' --> ' + o.IfcObjectType + ' --> ' + o.IfcMaterial)
          rootnode.insertChild(tex,1)
        else:
          o.ViewObject.Transparency = 0
          o.ViewObject.ShapeColor = (0.0,0.0,0.0)   # black
          #print ("  Object " + o.Name + " has no IfcObjectType or no IfcMaterial")
Attachments
screen2.jpg
screen2.jpg (76.63 KiB) Viewed 9806 times
screen3.jpg
screen3.jpg (100.16 KiB) Viewed 9806 times
screen.jpg
screen.jpg (116.71 KiB) Viewed 9806 times
User avatar
yorik
Founder
Posts: 13660
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels
Contact:

Re: Macro Texture Objects

Post by yorik »

Wow excellent!!! Thanks for sharing!

To remove the texture I think you only need to delete the texture node (parentnode.removeChild(texturenode))
For the scaling and orientation, coin has all the tools to do proper texturing, but I never looked very far there... The default behaviour is that the texture size depends on the object, but look in Draft.py at line 2925, I had found a way there (used for Draft hatch patterns) to set a scale to a texture that doesn't depend on the object, by using a SoTextureCoordiantePlane node. Maybe yuo can use the same system.

Ah, I'm currently recoding the IFC export/importer entirely (will be ready very soon) to take advantage of the new interface that Thomas Krijnen has done. I also already introduced a couple of handy features that we can use later. One thing that might be of interest to you already is that all Arch objects now have a IfcAttributes property, which is a dictionnary (can only contain string:string pairs). I am already using it to store some basic stuff (the GUID of the IFC object, etc...), but the next thing to do with it will be to retrieve and store Ifc properties. Things like IfcMaterial or IfcType that you use in your macro, you can store there if you want...
User avatar
saso
Veteran
Posts: 1924
Joined: Fri May 16, 2014 1:14 pm
Contact:

Re: Macro Texture Objects

Post by saso »

Wow, for both of you, I think I will not sleep for a week :shock: Love it how well this is moving forward! :)
Last edited by saso on Fri Aug 01, 2014 2:37 pm, edited 1 time in total.
User avatar
yorik
Founder
Posts: 13660
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels
Contact:

Re: Macro Texture Objects

Post by yorik »

At some point we could actually add a new "Textured" display mode to Arch objects... Since all objects are internally in millimeters, it would be quite easy to maintain an accurate scale... The biggest hassle would be to find a way to "detect" which material should receive which texture...
User avatar
saso
Veteran
Posts: 1924
Joined: Fri May 16, 2014 1:14 pm
Contact:

Re: Macro Texture Objects

Post by saso »

Textures by global scale (set units) IMO makes for Arch most sense, generally all building materials, from bricks to tiles and wood we actually know what is their "real world" size and so also should have that preset for the size they should render.

PS I still wish to be able to draw in cm ;)
User avatar
yorik
Founder
Posts: 13660
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels
Contact:

Re: Macro Texture Objects

Post by yorik »

saso wrote:PS I still wish to be able to draw in cm ;)
Well, you can already...
User avatar
bernd
Veteran
Posts: 12851
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: Macro Texture Objects

Post by bernd »

yorik wrote:At some point we could actually add a new "Textured" display mode to Arch objects... Since all objects are internally in millimeters, it would be quite easy to maintain an accurate scale...
+1
yorik wrote:The biggest hassle would be to find a way to "detect" which material should receive which texture...
For sure it will be HUGE hassle. 5 Meters are 5 meters in inch in meter in cm in mm in what ever, but there are 100 words for concrete. But these will be the big hassle not only for us. In this regard we all are in one boot (FreeCAD, Revit, ArchiCAD, Allplan). It is a general ifc problem since the attributes are just strings. But there are solutions for this problem too ...

@Yorik, cool to hear the ifc import gets even better. I'll be off for a few days. You may have a look at the "dirty" code at https://github.com/berndhahnebach/FreeC ... portIFC.py May be something is useful for the new importer too.

My idea was to use one dictionary for one propertyset but I did not manage do code this ... The name of an PrpertyMap ist used to refer to the propertymap, but the name is importet. But may be my data structure was just not as good as it should ... At the end all properties off all propertysets and the elementquantities are imported in one dictionary.

The volumeTest() is off inerest too. If the volume of FreeCAD is not equal the volume of IfcElementQuantity the element is coloured red. See attached sceen. FreeCAD nealy imports all my geometry. BTW found not only bugs FreeCAD but in Allplan using the volumeTest() to test the import in FreeCAD. :D

EDIT: Ahh, Thanks for the tips regarding textures. I'll have a look.
EDIT2: some simple sample ifc attached, which the code works with, could have posted in importIFC too ...
Attachments
liftschachttuer-ifcos.ifc
(20.28 KiB) Downloaded 231 times
screen.jpg
screen.jpg (89.53 KiB) Viewed 9756 times
User avatar
saso
Veteran
Posts: 1924
Joined: Fri May 16, 2014 1:14 pm
Contact:

Re: Macro Texture Objects

Post by saso »

yorik wrote:
saso wrote:PS I still wish to be able to draw in cm ;)
Well, you can already...
By writing "cm" every time? Well, yes I find it very nice that I am able to do this, but would prefer to have cm as the default unit.
User avatar
yorik
Founder
Posts: 13660
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels
Contact:

Re: Macro Texture Objects

Post by yorik »

Ah yes, of course. The units system is still very new... Certainly it still needs to evolve!
ulrich1a
Veteran
Posts: 1957
Joined: Sun Jul 07, 2013 12:08 pm

Re: Macro Texture Objects

Post by ulrich1a »

Is it possible to have a texture permanent attached to an object? So that it is possible to have it ready after closing and reopening of the document?

Ulrich
Post Reply