def geom2shape(vid, mesh, scene, colors): shape = None if isinstance(mesh, list): for m in mesh: geom2shape(vid, m, scene, colors) return if mesh is None: return if isinstance(mesh, Shape): shape = mesh mesh = mesh.geometry label = labels.get(vid) is_green = greeness.get(vid) if colors: shape = Shape(mesh, Material(Color3(*colors.get(vid, [0, 0, 0])))) elif not greeness: if not shape: shape = Shape(mesh) elif label.startswith('Stem') and is_green: shape = Shape(mesh, stem_material) elif label.startswith('Leaf') and is_green: shape = Shape(mesh, leaf_material) elif not is_green: shape = Shape(mesh, soil_material) shape.id = vid scene.add(shape)
def geom2shape(vid, mesh, scene): shape = None if isinstance(mesh, list): for m in mesh: geom2shape(vid, m, scene) return if mesh is None: return if isinstance(mesh, Shape): shape = mesh mesh = mesh.geometry label = labels.get(vid) if colors: if ambient_only: shape = Shape(mesh, Material(ambient=Color3(* colors.get(vid, [0,0,0])), diffuse=0.0, specular=Color3(0,0,0))) else: shape = Shape(mesh, Material(Color3(* colors.get(vid, [0,0,0]) ))) elif not label: if not shape: shape = Shape(mesh) elif label.is_soil(): shape = Shape(mesh, soil_material) elif label.is_stem() and label.optical_id <= 1: shape = Shape(mesh, stem_material) elif label.is_stem() and label.optical_id > 1: shape = Shape(mesh, soil_material) elif label.is_leaf() and label.optical_id <= 1: shape = Shape(mesh, leaf_material) elif label.is_leaf() and label.optical_id > 1: shape = Shape(mesh, soil_material) shape.id = vid scene.add(shape)
def geom2shape(vid, mesh, scene, colors, position, orientation, shape_id=None): shape = None if shape_id is None: shape_id = vid if isinstance(mesh, list): for m in mesh: geom2shape(vid, m, scene, colors, position, orientation) return if mesh is None: return if isinstance(mesh, Shape): shape = mesh mesh = mesh.geometry label = labels.get(vid) is_green = greeness.get(vid) mesh = Translated(position, AxisRotated((0, 0, 1), orientation, mesh)) if colors: shape = Shape(mesh, Material(Color3(*colors.get(vid, [0, 0, 0])))) elif not greeness: if not shape: shape = Shape(mesh) elif label.startswith('Stem') and is_green: shape = Shape(mesh, stem_material) elif label.startswith('Leaf') and is_green: shape = Shape(mesh, leaf_material) elif not is_green: shape = Shape(mesh, soil_material) shape.id = shape_id scene.add(shape)