How to define different materials / importet 3D geometry (gmsh)

Please supply a minimal working example, as it is not clear to me what you would like to do.
The post above, similar to Dolfinx discontinous expression shows how to write discontinuous cell data to a dolfin/dolfinx function. This means that you should use a DG 0 function space to represent the data.
If you are trying to write for anything else than cells, the function space and mesh function has to be adapted.