Macro Texture Objects

A forum to discuss the implementation of a good Materials system in FreeCAD
User avatar
bernd
Posts: 6882
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland

Macro Texture Objects

Postby bernd » Fri Aug 01, 2014 8:14 am

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 3608 times
screen3.jpg
screen3.jpg (100.16 KiB) Viewed 3608 times
screen.jpg
screen.jpg (116.71 KiB) Viewed 3608 times
User avatar
yorik
Site Admin
Posts: 10609
Joined: Tue Feb 17, 2009 9:16 pm
Location: São Paulo, Brazil
Contact:

Re: Macro Texture Objects

Postby yorik » Fri Aug 01, 2014 2:11 pm

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
Posts: 1101
Joined: Fri May 16, 2014 1:14 pm
Contact:

Re: Macro Texture Objects

Postby saso » Fri Aug 01, 2014 2:27 pm

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
Site Admin
Posts: 10609
Joined: Tue Feb 17, 2009 9:16 pm
Location: São Paulo, Brazil
Contact:

Re: Macro Texture Objects

Postby yorik » Fri Aug 01, 2014 2:35 pm

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
Posts: 1101
Joined: Fri May 16, 2014 1:14 pm
Contact:

Re: Macro Texture Objects

Postby saso » Fri Aug 01, 2014 2:41 pm

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
Site Admin
Posts: 10609
Joined: Tue Feb 17, 2009 9:16 pm
Location: São Paulo, Brazil
Contact:

Re: Macro Texture Objects

Postby yorik » Fri Aug 01, 2014 4:24 pm

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

Re: Macro Texture Objects

Postby bernd » Fri Aug 01, 2014 5:46 pm

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 68 times
screen.jpg
screen.jpg (89.53 KiB) Viewed 3553 times
User avatar
saso
Posts: 1101
Joined: Fri May 16, 2014 1:14 pm
Contact:

Re: Macro Texture Objects

Postby saso » Fri Aug 01, 2014 8:12 pm

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
Site Admin
Posts: 10609
Joined: Tue Feb 17, 2009 9:16 pm
Location: São Paulo, Brazil
Contact:

Re: Macro Texture Objects

Postby yorik » Fri Aug 01, 2014 9:30 pm

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

Re: Macro Texture Objects

Postby ulrich1a » Mon Sep 15, 2014 5:53 pm

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