Clear[DashedGraphics3D]
DashedGraphics3D::optx =
"Invalid options for Graphics3D are omitted: `1`.";
Off[OptionValue::nodef];
Options[DashedGraphics3D] = {ViewAngle -> 0.4,
ViewPoint -> {3, -1, 0.5}, ViewVertical -> {0, 0, 1},
ImageSize -> 800};
DashedGraphics3D[basegraph_, effectFunction_: Identity,
opts : OptionsPattern[]] /; !
MatchQ[Flatten[{effectFunction}], {(Rule | RuleDelayed)[__] ..}] :=
Module[{basegraphClean = basegraph /. (Lighting -> _):>Sequence[], exceptopts, fullopts, frontlayer, dashedlayer, borderlayer,
face3DPrimitives = {Cuboid, Cone, Cylinder, Sphere, Tube,
BSplineSurface}
},
exceptopts = FilterRules[{opts}, Except[Options[Graphics3D]]];
If[exceptopts =!= {},
Message[DashedGraphics3D::optx, exceptopts]
];
fullopts =
Join[FilterRules[Options[DashedGraphics3D], Except[#]], #] &@
FilterRules[{opts}, Options[Graphics3D]];
frontlayer = Show[
basegraphbasegraphClean /. Line[pts__] :> {Thick, Line[pts]} /.
h_[pts___] /; MemberQ[face3DPrimitives, h]
:> {EdgeForm[{Thick}], h[pts]},
fullopts,
Lighting -> {{"Ambient", White}}
] // Rasterize;
dashedlayer = Show[
basegraphbasegraphClean /.
{Polygon[__] :> {}, Line[pts__] :> {Dashed, Line[pts]}} /.
h_[pts___] /; MemberQ[face3DPrimitives, h]
:> {FaceForm[], EdgeForm[{Dashed}], h[pts]},
fullopts
] // Rasterize;
borderlayer = Show[basegraphShow[basegraphClean /. RGBColor[__] :> Black,
ViewAngle -> (1 - .001) OptionValue[ViewAngle],
Lighting -> {{"Ambient", Black}},
fullopts,
Axes -> False, Boxed -> False
] // Rasterize // GradientFilter[#, 1] & // ImageAdjust;
ImageSubtract[frontlayer, dashedlayer] // effectFunction //
ImageAdd[frontlayer // ColorNegate, #] & //
ImageAdd[#, borderlayer] & //
ColorNegate // ImageCrop
]
graph1 = Show[{
SphericalPlot3D[
1, {θ, 1/5 1.2 π, π/2}, {ϕ, 0, 1.8 π},
PlotStyle -> White,
PlotPoints -> 50, Mesh -> None, BoundaryStyle -> Black],
SphericalPlot3D[
1, {θ, 0, π/5}, {ϕ, π/4, 2.1 π},
PlotStyle -> FaceForm[Lighter[Blue, .9], GrayLevel[.9]],
PlotPoints -> 50, Mesh -> None, BoundaryStyle -> Black],
Graphics3D[{FaceForm[Lighter[Pink, .8], GrayLevel[.8]],
Cylinder[{{0, 0, 0}, {0, 0, .8 Cos[π/5]}}, Sin[π/5]]}]
},
PlotRange -> 1.2 {{-1, 1}, {-1, 1}, {0, 1}},
AxesOrigin -> {0, 0, 0}, Boxed -> False,
SphericalRegion -> True];
DashedGraphics3D[graph1]