2
$\begingroup$

I would like to have a 3D object with a golden color as in the attached image, how can I create such color and edges in Mathematica?

enter image description here

Here is my try

    Graphics3D[{Specularity[Gray, 1], EdgeForm[None], Orange, 
  Lighting -> "Neutral", Opacity[0.95], 
  Cuboid[{0, 0, 0}, {6, 1.2, 1.3}]}, Boxed -> False, 
 ViewPoint -> {2, 0.2, 1}, PlotRange -> {{-2, 6}, {-2, 2}, {-2, 2}}]

enter image description here

$\endgroup$
2
  • 2
    $\begingroup$ MaterialShading["Gold"] $\endgroup$
    – cvgmt
    Oct 4 '21 at 8:22
  • $\begingroup$ Related $\endgroup$
    – flinty
    Oct 4 '21 at 8:29
8
+50
$\begingroup$

We can add custom settings to MaterialShading, use non default Lighting, and add a rounding radius to our block. The various settings in MaterialShading can be changed to give different effects:

massoc = 
  Association[{"BaseColor" -> RGBColor[1., 0.75, 0., 1.], 
    "SpecularColor" -> GrayLevel[1], "MetallicCoefficient" -> 0.8, 
    "RoughnessCoefficient" -> 0.5, "AmbientExposureFraction" -> 1., 
    "SpecularAnisotropyCoefficient" -> 0.3}];

r = 0.05;
{c1x, c1y, c1z} = {0, 0, 0} + r;
{c2x, c2y, c2z} = {6, 1.2, 1.3} - r;
faces = Polygon[{
    {{c1x, c1y - r, c1z}, {c2x, c1y - r, c1z}, {c2x, c1y - r, c2z}, {c1x, c1y - r, c2z}},
    {{c1x, c2y + r, c1z}, {c2x, c2y + r, c1z}, {c2x, c2y + r, c2z}, {c1x, c2y + r, c2z}},
    {{c1x, c1y, c2z + r}, {c2x, c1y, c2z + r}, {c2x, c2y, c2z + r}, {c1x, c2y, c2z + r}},
    {{c1x, c1y, c1z - r}, {c2x, c1y, c1z - r}, {c2x, c2y, c1z - r}, {c1x, c2y, c1z - r}},
    {{c1x - r, c1y, c1z}, {c1x - r, c2y, c1z}, {c1x - r, c2y, c2z}, {c1x - r, c1y, c2z}},
    {{c2x + r, c1y, c1z}, {c2x + r, c2y, c1z}, {c2x + r, c2y, c2z}, {c2x + r, c1y, c2z}}
    }];
tubes = Tube[{
    {{c1x, c1y, c1z}, {c2x, c1y, c1z}}, {{c1x, c1y, c1z}, {c1x, c2y, c1z}}, {{c1x, c1y, c1z}, {c1x, c1y, c2z}},
    {{c2x, c2y, c2z}, {c1x, c2y, c2z}}, {{c2x, c2y, c2z}, {c2x, c1y, c2z}}, {{c2x, c2y, c2z}, {c2x, c2y, c1z}},
    {{c1x, c2y, c1z}, {c2x, c2y, c1z}}, {{c2x, c1y, c1z}, {c2x, c2y, c1z}}, {{c2x, c1y, c1z}, {c2x, c1y, c2z}},
    {{c1x, c1y, c2z}, {c2x, c1y, c2z}}, {{c1x, c2y, c2z}, {c1x, c2y, c1z}}, {{c1x, c2y, c2z}, {c1x, c1y, c2z}}
    }, r];

Graphics3D[
 {MaterialShading[massoc], faces, tubes},
 Boxed -> False,
 Lighting -> "ThreePoint",
 ViewPoint -> {2, 0.2, 1},
 ViewVertical -> {0, 0, 1}
]

$\endgroup$
6
$\begingroup$
Needs["OpenCascadeLink`"];
shape = OpenCascadeShape[Cuboid[{0, 0, 0}, {3, 1, 1}]];
fillet = OpenCascadeShapeFillet[shape, 0.04];
bmesh = OpenCascadeShapeSurfaceMeshToBoundaryMesh[fillet];
Show[bmesh[
  "Wireframe"[
   "MeshElementStyle" -> 
    Directive[EdgeForm[], 
     FaceForm[MaterialShading[{"Gold", Darker@Yellow}]]]]], 
 Lighting -> "Standard"]

enter image description here

Edit

Test another solids.

Clear["`*"];
Needs["OpenCascadeLink`"];
bmesh[solid_, l_ : .05] := Module[{shape, fillet, bm},
   shape = OpenCascadeShape[solid];
   fillet = OpenCascadeShapeFillet[shape, l];
   bm = OpenCascadeShapeSurfaceMeshToBoundaryMesh[fillet];
   Show[bm[
     "Wireframe"[
      "MeshElementStyle" -> 
       Directive[EdgeForm[], 
        FaceForm[MaterialShading[{"Gold", Darker@Yellow}]]]]], 
    Lighting -> "Standard"]
   ];
solid1 = PolyhedronData["Cube", "Polyhedron"];
solid2 = PolyhedronData["Dodecahedron", "Polyhedron"];
solid3 = TruncatedPolyhedron[Icosahedron[], 1/3];
solid4 = AugmentedPolyhedron[Dodecahedron[]];
bmesh[solid2, .05]

enter image description here

$\endgroup$
5
$\begingroup$

From version 12.3 on, there is a new graphics directive called MaterialShading for various materials.

Graphics3D[{MaterialShading["Gold"], 
  Cuboid[{0, 0, 0}, {6, 1.2, 1.3}]}, Boxed -> False]

However, you will probably have to play around with different lighting settings to achieve a similar result as in the photo.

$\endgroup$
4
  • 1
    $\begingroup$ Respectfully, using MaterialShading["Gold"] doesn't appear to work when applied to flat surfaces. You'll note that all of the samples shown in the MaterialShading link apply to non-flat surfaces. I think the OP will need to look into the application of textures or possibly create some kind of irregular surface to achieve their end. $\endgroup$
    – Jagra
    Oct 5 '21 at 0:04
  • $\begingroup$ @Jagra, thanks a lot for the hint, I was trying to play around with lighting as suggested in the answer but could not achieve the desired results. However, for non-flat surfaces, it is working like magic. Hope someone can provide a workaround. $\endgroup$ Oct 5 '21 at 6:05
  • 2
    $\begingroup$ @valarmorghulis Another hint is that because of how graphics work, a single triangle will only interpolate between 3 colours (3 vertices). Each face of the cuboid is broken down into two triangles. Thus we can't have realistic-looking shading. The usual solution to this is to discretize the cuboid and let each face be made up of many small triangles. I had an answer on this site which shows how but can't find it now, and no time at this moment. $\endgroup$
    – Szabolcs
    Oct 5 '21 at 8:31
  • $\begingroup$ Thanks, @Szabolcs for the hint, kindly if you find the respective answer share the link, please. $\endgroup$ Oct 5 '21 at 11:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.