parameters: (filename)
docstring: reads a DAE file
docstring_summary: reads a DAE file
docstring_tokens: reads a DAE file
function: def read(filename):
  
      "reads a DAE file"
  
      global col
      col = collada.Collada(filename, ignore=[collada.DaeUnsupportedError])
      # Read the unitmeter info from dae file and compute unit to convert to mm
      unitmeter = col.assetInfo.unitmeter or 1
      unit = unitmeter / 0.001
      #for geom in col.geometries:
      #for geom in col.scene.objects('geometry'):
      for node in col.scene.nodes:
          if list(node.objects("geometry")):
              color = None
              # retrieving material
              if "}" in node.xmlnode.tag:
                  bt = node.xmlnode.tag.split("}")[0]+"}"
                  gnode = node.xmlnode.find(bt+"instance_geometry")
                  if gnode != None:
                      bnode = gnode.find(bt+"bind_material")
                      if bnode != None:
                          tnode = bnode.find(bt+"technique_common")
                          if tnode != None:
                              mnode = tnode.find(bt+"instance_material")
                              if mnode != None:
                                  if "target" in mnode.keys():
                                      mname = mnode.get("target").strip("#")
                                      for m in col.materials:
                                          if m.id == mname:
                                              e = m.effect
                                              if isinstance(e.diffuse,tuple):
                                                  color = e.diffuse
              for geom in node.objects("geometry"):
                  for prim in geom.primitives():
                      #print(prim, dir(prim))
                      meshdata = []
                      if hasattr(prim,"triangles"):
                          tset = prim.triangles()
                      elif hasattr(prim,"triangleset"):
                          tset = prim.triangleset()
                      else:
                          tset = []
                      for tri in tset:
                          face = []
                          for v in tri.vertices:
                              v = [x * unit for x in v]
                              face.append([v[0],v[1],v[2]])
                          meshdata.append(face)
                      #print(meshdata)
                      newmesh = Mesh.Mesh(meshdata)
                      #print(newmesh)
                      obj = FreeCAD.ActiveDocument.addObject("Mesh::Feature","Mesh")
                      obj.Mesh = newmesh
                      if color and FreeCAD.GuiUp:
                          obj.ViewObject.ShapeColor = color
function_tokens: def read ( filename ) : global col col = collada . Collada ( filename , ignore = [ collada . DaeUnsupportedError ] ) # Read the unitmeter info from dae file and compute unit to convert to mm unitmeter = col . assetInfo . unitmeter or 1 unit = unitmeter / 0.001 #for geom in col.geometries: #for geom in col.scene.objects('geometry'): for node in col . scene . nodes : if list ( node . objects ( "geometry" ) ) : color = None # retrieving material if "}" in node . xmlnode . tag : bt = node . xmlnode . tag . split ( "}" ) [ 0 ] + "}" gnode = node . xmlnode . find ( bt + "instance_geometry" ) if gnode != None : bnode = gnode . find ( bt + "bind_material" ) if bnode != None : tnode = bnode . find ( bt + "technique_common" ) if tnode != None : mnode = tnode . find ( bt + "instance_material" ) if mnode != None : if "target" in mnode . keys ( ) : mname = mnode . get ( "target" ) . strip ( "#" ) for m in col . materials : if m . id == mname : e = m . effect if isinstance ( e . diffuse , tuple ) : color = e . diffuse for geom in node . objects ( "geometry" ) : for prim in geom . primitives ( ) : #print(prim, dir(prim)) meshdata = [ ] if hasattr ( prim , "triangles" ) : tset = prim . triangles ( ) elif hasattr ( prim , "triangleset" ) : tset = prim . triangleset ( ) else : tset = [ ] for tri in tset : face = [ ] for v in tri . vertices : v = [ x * unit for x in v ] face . append ( [ v [ 0 ] , v [ 1 ] , v [ 2 ] ] ) meshdata . append ( face ) #print(meshdata) newmesh = Mesh . Mesh ( meshdata ) #print(newmesh) obj = FreeCAD . ActiveDocument . addObject ( "Mesh::Feature" , "Mesh" ) obj . Mesh = newmesh if color and FreeCAD . GuiUp : obj . ViewObject . ShapeColor = color