Function Repository Resource:

Visualize3DView

Source Notebook

Interactively visualize the camera setup relative to the scene and lighting of 3D graphics

Contributed by: James Lane

ResourceFunction["Visualize3DView"][graphics]

generates an interactive visualization of the 3D graphics illustrating the various viewing parameters.

Details

The combination of viewing options or the automatic settings for the viewing options may lead to an unexpected view of a 3D graphic. ResourceFunction["Visualize3DView"] displays the 3D Graphic alongside a visualization of the camera setup, offering insight into how the viewing options result in the final rendered image.
Interacting with the original 3D Graphic dynamically updates the visualization.
The input graphics must be a valid Graphics3D expression.

Examples

Basic Examples (2) 

Visualize the 3D view of a simple Graphics3D expression under default viewing options:

In[1]:=
ResourceFunction["Visualize3DView"][
 Graphics3D[{Sphere[]}, Background -> LightBlue]]
Out[1]=

An additional visualization of the screen space ViewCenter is displayed when 3D Graphic is panned (by holding Shift):

In[2]:=
ResourceFunction["Visualize3DView"][
 Graphics3D[{Sphere[]}, ViewCenter -> {{0.5, 0.5, 0.5}, {0.7, 0.2}}, Background -> LightBlue]]
Out[2]=

Scope (3) 

The visualization works on the output of Plot3D:

In[3]:=
ResourceFunction["Visualize3DView"] @ Plot3D[Sin[x + y^2], {x, -3, 3}, {y, -2, 2}]
Out[3]=

PointLight is visualized as points in the color of the lights:

In[4]:=
ResourceFunction["Visualize3DView"] @ Graphics3D[{Sphere[], Sphere[{3, 0, 0}], Sphere[{0, 3, 0}], Sphere[{3, 3, 0}]}, Lighting -> PointLight[Green, {2, 2, 2}]]
Out[4]=

DirectionalLight is visualized as arrows with the color of the lights, placed just outside the PlotRange:

In[5]:=
gr3d = Graphics3D[Sphere[], Lighting -> {AmbientLight[RGBColor[{0.4, 0.2, 0.2}]], DirectionalLight[RGBColor[{0., 0.18, 0.5}], ImageScaled[{2, 0, 2}]], DirectionalLight[RGBColor[{0.18, 0.5, 0.18}], ImageScaled[{2, 2, 3}]], DirectionalLight[RGBColor[{0.5, 0.18, 0.}], ImageScaled[{0, 2, 2}]], DirectionalLight[RGBColor[{0., 0., 0.18}], ImageScaled[{0, 0, 2}]]}];
ResourceFunction["Visualize3DView"] @ gr3d
Out[6]=

Applications (1) 

Interactively investigate the setup of the camera relative to a scene to understand the rendered image:

In[7]:=
r = 4; s = 0.25;
gridLines = {Line[Table[{{v, 0, 0.0}, {v, r, 0.0}}, {v, 0, r, s}]], Line[Table[{{0, v, 0.0}, {r, v, 0.0}}, {v, 0, r, s}]]};
scene = {Thick, Gray, gridLines, Table[{Hue[RandomReal[]], Sphere[RandomReal[{r - 0.5, r}]*RandomReal[1, {3}], RandomReal[{0.025, .1}]]}, {100}]};
ResourceFunction["Visualize3DView"][
 Graphics3D[scene, ViewPoint -> {0, 0, 0} (*At Origin*), ViewCenter -> {0.5, 1, 0.5} (*The point we are looking onto*), ViewAngle -> 25 Degree, FaceGrids -> All, Background -> Black, Lighting -> "Neutral", ImageSize -> Large]
 ]
Out[10]=

Publisher

James Lane

Version History

  • 1.0.0 – 11 December 2024

Related Resources

License Information