1
$\begingroup$

I am interested in exploring the new MaterialShading function. I have created a Manipulate object with two fields for making a Graphics3d object of ExampleData's built-in cases. The first parameter relates to the material the object is made of, and the second relates to which object in ExampleData["Geometry3D"] is displayed. I would like to somehow introduce a third field if the user selects Plastic or Glazed for color. I have used the following resources:

A generalization of this question:

  • Given a function that accepts n number of arguments f[e1,e2,e3,...en]
  • where not all arguments are required
  • and the last argument is only applicable to certain inputs for the first inputs
  • how to create a Manipulate object that works around this.
Manipulate[
 Graphics3D[{MaterialShading[material], 
   ExampleData[{"Geometry3D", object}, "GraphicsComplex"]}, 
  Boxed -> False, 
  Lighting -> "ThreePoint"], {material, {"Aluminum", "Brass", 
   "Bronze", "Copper", "Electrum", "Gold", "Iron", "Pewter", "Silver",
    "Clay", "Foil", "Glazed", "Plastic", "Rubber", "Satin", 
   "Velvet"}}, {object, ExampleData["Geometry3D"][[All, 2]]}]
$\endgroup$
4
  • $\begingroup$ Please provide a concrete example and the code that you have tried. Explain what specific problems you are having. $\endgroup$
    – Bob Hanlon
    Nov 25, 2021 at 14:49
  • $\begingroup$ I forgot! I meant to add my code. Please consider un downvoting my question. $\endgroup$ Nov 25, 2021 at 14:56
  • $\begingroup$ There are 16 materials and 27 objects for a total of 432 combinations. Which of the combinations are known to cause problems and what is the nature of the problem? $\endgroup$
    – Bob Hanlon
    Nov 25, 2021 at 15:23
  • $\begingroup$ I want to add a field for the color of plastic and glazed materials when those are selected as the materials. $\endgroup$ Nov 25, 2021 at 16:04

2 Answers 2

4
$\begingroup$
Clear["Global`*"]

A brute force approach is to just nest two Manipulates.

SetOptions[Graphics3D,
  Boxed -> False,
  Lighting -> "ThreePoint"];

Manipulate[
 If[(material === "Plastic" || material === "Glazed"), Manipulate[
   Graphics3D[{
     MaterialShading[{material, color}],
     ExampleData[{"Geometry3D", object}, "GraphicsComplex"]}],
   {color, ColorSlider},
   Paneled -> False],
  Graphics3D[{
    MaterialShading[material],
    ExampleData[{"Geometry3D", object}, "GraphicsComplex"]}]],
 Row[{
   Control[{{material, "Plastic"},
     {"Aluminum", "Brass", "Bronze", "Copper", "Electrum", "Gold", 
      "Iron", "Pewter", "Silver", "Clay", "Foil", "Glazed", "Plastic",
       "Rubber", "Satin", "Velvet"}}],
   Spacer[50],
   Control[{object,
     ExampleData["Geometry3D"][[All, 2]]}]}],
 TrackedSymbols :> All]

enter image description here

$\endgroup$
3
$\begingroup$
materials =   {"Aluminum", "Brass", "Bronze", "Copper", "Electrum", "Gold", "Iron",
 "Pewter", "Silver", "Clay", "Foil", "Glazed", "Plastic", "Rubber", "Satin", "Velvet"};

objects = ExampleData["Geometry3D"][[All, 2]];

assoc = Association[# -> ExampleData[{"Geometry3D", #}, "GraphicsComplex"]& /@ objects];

We can use a single Manipulate with the control color added only if material is "Plastic" or "Glazed":

Manipulate[Graphics3D[{
       MaterialShading[material /. m : "Plastic" | "Glazed" -> {m, color}],
       assoc @ object},
      Boxed -> False, Lighting -> "ThreePoint"],
  Row[{Control[{{material, "Plastic"}, materials }],
       Spacer[50], 
       Dynamic @ If[(material === "Plastic" || material === "Glazed"), 
           Row[{ Control@{{color, Red}, ColorSlider}, Spacer[50]}], 
           Spacer[0]],
       Control[{object, objects}]}]] 

enter image description here

Alternatively,

Manipulate[Graphics3D[{
       MaterialShading[material /. m : "Plastic" | "Glazed" -> {m, color}],
       assoc @ object}, 
    Boxed -> False,  Lighting -> "ThreePoint"],
Dynamic @ If[material === "Plastic" || material === "Glazed", 
   Row[{Control @ { {material, "Plastic"}, materials }, 
        Control @ {{color, Red}, ColorSlider}, 
        Control @ {object, objects  }}, Spacer[20]], 
   Row[{Control@{ {material, "Plastic"}, materials }, 
        Control @ {object, objects}}, Spacer[20]]]]
$\endgroup$

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.