I've created the following scene with a Chinese-style building surrounded by trees, and a horse and a rabbit grazing on the grass in Mathematica (don't ask me why there's a bust of Beethoven in there...). The Chinese-style roof was created using J. M.'s equations in his answer to the question "Mathematical formula to generate a curved Chinese-style roof". The code to create this is at the very end of this post.
How can I use the various View*
options to implement a first-person view of the objects in the scene? In other words, be able to walk around freely and see objects as if I were in the scene.
Code to create the scene
Begin["NonProprietaryCode`"];
Module[{roof, columns, base, ground,
fauxLame = {#2 Abs@Cos@#1 Cos@#1, #2 Abs@Sin@#1 Sin@#1,
9 #2 ((9 #2/10 - 2/3) Cos[2 #1]^2 - 4/3)/20} &,
roofExt = 3/2, roofTex = ExampleData[{"ColorTexture", "Roof"}],
colRad = 0.15, colOff = 1, colHt = 2.5,
baseHt = 0.25,
baseTex = ExampleData[{"ColorTexture", "GrayMarble"}],
vtc = {{0, 0}, {1, 0}, {1, 1}, {0, 1}},
cubeCoords = {{{0, 0, 0}, {0, 1, 0}, {1, 1, 0}, {1, 0, 0}}, {{0, 0,
0}, {1, 0, 0}, {1, 0, 1}, {0, 0, 1}}, {{1, 0, 0}, {1, 1,
0}, {1, 1, 1}, {1, 0, 1}}, {{1, 1, 0}, {0, 1, 0}, {0, 1,
1}, {1, 1, 1}}, {{0, 1, 0}, {0, 0, 0}, {0, 0, 1}, {0, 1,
1}}, {{0, 0, 1}, {1, 0, 1}, {1, 1, 1}, {0, 1, 1}}},
groundTex = Import["https://i.stack.imgur.com/hMQwd.jpg"]
},
roof = ParametricPlot3D[{fauxLame[u, v]}, {u, -Pi, Pi}, {v, 0,
roofExt},
Mesh -> None, Lighting -> "Neutral",
PlotStyle -> Texture[roofTex]];
columns =
ParametricPlot3D[
With[{x = colOff + colRad Cos@t, y = colRad Sin@t,
u = Rescale[
t, {-Pi, Pi}, {-#, #} &@
ArcTan[colOff, colRad]]},
{Sequence[#],
Min[v, Last@fauxLame[u, y/Sin@u/Abs@Sin@u]]} & /@ {{x,
y}, {-x, y}, {-y, x}, {y, -x}}], {t, -Pi,
Pi}, {v, -colHt, -0.585}, Mesh -> None, PlotStyle -> Red];
base = Graphics3D[{Texture[baseTex], Lighting -> "Neutral",
EdgeForm[None],
Rotate[Polygon[
cubeCoords /. {x_, y_,
z_} :> {2 roofExt x, 2 roofExt y, -baseHt z} - {roofExt,
roofExt, colHt},
VertexTextureCoordinates -> Table[vtc, {6}]],
Pi/4, {0, 0, -(colHt + baseHt/2)}]}];
ground =
Graphics3D[{Texture[groundTex], Lighting -> "Neutral",
EdgeForm[None],
Polygon[cubeCoords /. {x_, y_,
z_} :> {8 x, 8 y, -0.1 z} - {4, 4, colHt + baseHt},
VertexTextureCoordinates -> Table[vtc, {6}]]}];
building = Show[roof, columns, base, ground, PlotRange -> All];
];
Module[{treePoly =
ExampleData[{"Geometry3D", "Tree"}, "PolygonObjects"],
trunkTex = ExampleData[{"ColorTexture", "Ash"}],
vtc = {{0, 1}, {1, 0}, {1, 1}}
},
trunk =
Graphics3D[{Texture[trunkTex], Lighting -> "Neutral",
EdgeForm[None],
treePoly[[;; 19000]] /.
Polygon[x__] :> Polygon[x, VertexTextureCoordinates -> vtc]}];
leaves =
Graphics3D[{FaceForm[Darker@Green], Lighting -> "Neutral",
EdgeForm[None],
treePoly[[19001 ;;]] /.
Polygon[x__] :> Polygon[x, VertexTextureCoordinates -> vtc]}];
tree = Show[trunk, leaves, PlotRange -> All];
];
Module[{
bunnyVtx =
ExampleData[{"Geometry3D", "StanfordBunny"}, "VertexData"]
},
bunny =
ListSurfacePlot3D[bunnyVtx, MaxPlotPoints -> 35, Mesh -> None,
TextureCoordinateFunction -> (Normalize[{#1, #2, #3}] &),
PlotStyle -> Directive[Lighting -> "Neutral"]]
];
Module[{
horseVtx = ExampleData[{"Geometry3D", "Horse"}, "VertexData"],
horseTex = ExampleData[{"ColorTexture", "BurlOak"}]
},
horse =
ListSurfacePlot3D[horseVtx, MaxPlotPoints -> 35, Mesh -> None,
TextureCoordinateFunction -> (Normalize[{#1, #2, #3}] &),
PlotStyle -> Directive[Texture[horseTex], Lighting -> "Neutral"]]
];
Module[{bustPoly =
ExampleData[{"Geometry3D", "Beethoven"}, "PolygonObjects"]},
bust = Graphics3D[{FaceForm[Gray], Lighting -> "Neutral",
EdgeForm[None], bustPoly}];
];
Draw := With[{c = -Mean /@
AbsoluteOptions[tree, PlotRange][[1, 2]] - {0, 0, 0.75},
treeLocs = {{-2, 2, 0}, {2, 2, 0}, {-2, -2, 0}}},
Show[building,
Graphics3D[{
{FaceForm[Gray], EdgeForm[None], Lighting -> "Neutral",
Cylinder[{{0, 0, -3}, {0, 0, -2}}, 0.1]},
Translate[Scale[bust[[1]], 0.05], {0, 0, -1.5}],
Translate[Scale[horse[[1]], 5], {-3, 0, -2.25}],
Translate[Scale[bunny[[1]], 1.5], {2, -2, -2.75}],
Translate[Scale[tree[[1]], 0.013],
Outer[Plus, treeLocs, {c}, 1]]
}], PlotRange -> All, Boxed -> False, Axes -> None]
]
End[];
Create a scene with scene = NonProprietaryCode`Draw
. Feel free to modify the code as desired to implement the FPV.
View*
functions. $\endgroup$