1 <?xml version=
"1.0" encoding=
"UTF-8"?>
2 <?xml-stylesheet type=
"text/xsl" href=
"formats/html.xsl"?>
4 <!-- This file is part of Shapes. -->
6 <!-- Shapes is free software: you can redistribute it and/or modify -->
7 <!-- it under the terms of the GNU General Public License as published by -->
8 <!-- the Free Software Foundation, either version 3 of the License, or -->
9 <!-- any later version. -->
11 <!-- Shapes is distributed in the hope that it will be useful, -->
12 <!-- but WITHOUT ANY WARRANTY; without even the implied warranty of -->
13 <!-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -->
14 <!-- GNU General Public License for more details. -->
16 <!-- You should have received a copy of the GNU General Public License -->
17 <!-- along with Shapes. If not, see <http://www.gnu.org/licenses/>. -->
19 <!-- Copyright 2015 Henrik Tidefelt -->
23 <namespace>..Shapes..Graphics3D
</namespace>
25 <p>Handling the things in a
<str-3D /> scene.
</p>
28 <title><self /></title>
29 <up-link><parent-namespace /></up-link>
30 <base href=
<!--#expand-next-string-->"$(BASE)" />
31 <examples-home href=
<!--#expand-next-string-->"$(EXAMPLES)" />
32 <shapes-version number=
<!--#expand-next-string-->"$(SHAPES_VERSION)" />
34 <!--#include virtual="^/toc.xml" -->
39 <p>A
<str-3D /> graphical object in
<str-Shapes /> is basically something that ca be projected to
<str-2D />, and then results in a
<str-2D /> graphical object. This namespace is also used for the border between the
<str-2D /> and
<str-3D /> graphical worlds, so that
<namespace name=
"..Shapes..Graphics" /> doesn't get disturbed by the things that only concern those that work with
<str-3D /> scenes.
</p>
40 <p>Separation of
<str-2D /> and
<str-3D /> concerns in its current form was initiated with the introduction of namespaces in
<str-Shapes />, and this separation is still work in progress. This means that even when working purely in
<str-3D />, it is still necessary to use contents of the
<namespace name=
"..Shapes..Graphics" /> namespace from time to time. The
<binding namespace=
"..Shapes..Graphics" name=
"stroke" /> function is a typical such example; it still follows the old design where a single function is used for both
<str-2D /> and
<str-3D />.
</p>
43 <section id=
"namespace/shapes/graphics3d/elementary">
44 <title>Elementary
<str-3D /></title>
47 <system-binding name=
"null">
49 <type><named-type name=
"Drawable3D" /></type>
51 <p>The analogue of
<value namespace=
"..Shapes..Graphics" name=
"null" />, but in
<str-3D /> instead of
<str-2D />.
</p>
56 <system-binding name=
"newGroup">
58 <constructor-of><named-statetype name=
"Group3D" /></constructor-of>
59 <description></description>
64 </section> <!-- end of namespace/shapes/graphics3d/elementary -->
66 <section id=
"namespace/shapes/graphics3d/facets">
70 <system-binding name=
"facet">
72 <case constructor-of=
"Drawable3D">
74 <arg identifier=
"path">
75 <type><named-type name=
"Path" /></type>
78 <type><template-type name=
"N" /></type>
81 <type><template-type name=
"N" /></type>
84 <type><template-type name=
"N" /></type>
86 <arg identifier=
"tiebreaker">
87 <type><named-type name=
"Length" /></type>
90 <arg identifier=
"double">
91 <type><named-type name=
"Boolean" /></type>
94 <dynamic-references><dynamic name=
"nonstroking" /> <dynamic name=
"reflections" /> <dynamic name=
"autointensity" /> <dynamic name=
"autoscattering" /> <dynamic name=
"viewresolution" /> <dynamic name=
"shadeorder" /></dynamic-references>
98 <p>Type of surface normal. Should either be
<named-type name=
"SurfaceNormalGray" /> or
<named-type name=
"SurfaceNormalRGB" />.
</p>
103 <p>The only required argument is
<arg name=
"path" />, which must be a flat polygon. The three arguments of type
<template-type name=
"N" /> will be described shortly. The parameter
<arg name=
"tiebreaker" /> has the same meaning as for
<value namespace=
"..Shapes..Graphics" name=
"fill" />, and
<arg name=
"double" /> tells whether the surface should be visible when viewed from the back. Surfaces that are not visisble when viewed from the back allow more efficient rendering when they cover a solid body, so that one knows that the inside of the body surface should never be visible. The default value for
<arg name=
"double" /> depends on the presence of surface normals; if there are none, it defaults to true, otherwise it defaults to false unless the surface normals disagree on which is the visible side.
</p>
104 <p>Up to three surface normals may be provided (provide
<arg name=
"n1" /> before
<arg name=
"n2" /> and so forth). A surface normal has a location on the surface and specifies both a normal direction to be used in light computations (although the surface is physically flat, it can be treated as if curved in the light model), and a color. See
<value name=
"facetnormal" /> for more details on how to construct surface normals. If no facet normal is provided, one is computed by using the physical normal direction of
<arg name=
"path" />, with color determined by
<dynamic name=
"nonstroking" />. If just one facet normal is provided, it defines a constant normal direction and color over the whole facet. If more than one is provided, normal direction and color are interpolated over the facet.
</p>
105 <p>Please refer to the documentation on the many dynamic variables accessed by this function, to learn how these affect the light computations.
</p>
112 </section> <!-- end of namespace/shapes/graphics3d/facets -->
114 <section id=
"namespace/shapes/graphics3d/scenes">
115 <title>Scenes and light
</title>
118 <system-binding name=
"newLights">
120 <constructor-of><named-statetype name=
"Lights" /></constructor-of>
121 <description></description>
125 <system-binding name=
"newZSorter">
127 <constructor-of><named-statetype name=
"Drawable3D" /></constructor-of>
128 <description></description>
132 <system-binding name=
"newZBuf">
134 <constructor-of><named-statetype name=
"Drawable3D" /></constructor-of>
135 <description></description>
140 </section> <!-- end of namespace/shapes/graphics3d/scenes -->
142 <section id=
"namespace/shapes/graphics3d/quasi">
143 <title>Quasi
<str-3D /></title>
146 <system-binding name=
"facing">
148 <case constructor-of=
"Drawable3D">
150 <arg identifier=
"obj">
151 <type><named-type name=
"Drawable" /></type>
153 <arg identifier=
"scale">
154 <type><named-type name=
"Boolean" /></type>
155 <default>false
</default>
157 <arg identifier=
"distort">
158 <type><named-type name=
"Boolean" /></type>
159 <default>false
</default>
163 <p>Make a special kind of
<str-3D /> object at
<eq>z =
0</eq>, which will always face the viewer even after
<str-3D /> transforms. It is useful for labels and other
<str-2D /> annotations that need to be positioned in terms of objects in a
<str-3D /> world.
</p>
164 <p>When the object is viewed after being transformed in
<str-3D />, it will just be transformed by a
<str-2D /> transform, so the object never has to go truly
<str-3D />. The object will be shifted according to how its origin moved by the
<str-3D /> transform. The arguments
<arg name=
"scale" /> and
<arg name=
"distort" /> determine how the linear part of the
<str-2D /> transform is obtained from the
<str-3D /> transform. If
<arg name=
"scale" /> is set, the object will be scaled according to the
<eq>z
</eq> coordinate of its transformed origin. If
<arg name=
"distort" /> is set, the linear
<eq>(x,y)
</eq> part of the
<str-3D /> transform will be used.
</p>
167 <case constructor-of=
"Drawable3D">
169 <arg identifier=
"obj">
173 <arg><type><named-type name=
"Transform3D" /></type></arg>
175 <result><named-type name=
"Drawable" /></result>
180 <dynamic-references><dynstate name=
"all" /></dynamic-references>
182 <p>Gives the user full control of how to display the object when being viewed through a
<str-3D /> transform. The dynamic state is captured, and will be in scope later when the embedded function is invoked.
</p>
185 <p>The evaluation order is quite non-standard for the objects created here. Viewing an object is generally an atomic operation from a continuation passing point of view. Hence, when the function is applied to the transform to obtain the
<str-2D /> result, this will take place in an evaluation loop of its own. This is very likely to render generated error messages rather useless when it comes to localizing the problem.
</p>
186 <p>Since the object created here only has a meaning when being viewed, it cannot be searched (see
<value name=
"tag" /> and
<value name=
"find" />) for tags as long as it remains in
<str-3D />.
</p>
189 <p>If you ever considered solving the intricate problem of generating nice arrowheads for paths in
<str-3D /> by simply treating the path as if it was in
<str-2D />, think again, as the example below shows!
</p>
191 <example-with-output title=
"Example" internal-id=
"example:facing-function">
192 <image pdf=
"features/facefun_3.pdf" jpg=
"features/facefun_y_big.jpg" />
193 <source file=
"features/facefun.shape">
194 <![CDATA[
<!--#include depth="0" virtual="$(BUILDDIR)$(EXAMPLES)features/facefun.shape" -->]]
>
196 </example-with-output>
200 <see-also><value name=
"immerse" /></see-also>
204 </section> <!-- end of namespace/shapes/graphics3d/quasi -->