X3D Scene Authoring Hints |
These hints provide a collection of style guidelines, authoring tips and best practices to improve the quality, consistency and maintainability of Extensible 3D (X3D) Graphics scenes.
Audio | Authoring | Color | containerField | Coordinate Systems | Credits | Dates | Encodings | HTML | Images and Videos | Inlines and Prototypes | License | Meshes | meta Tags and Metadata Nodes | Naming Conventions | Scale Factors | Scripts (Java, JavaScript, JSON) | SVG | Tooltips | URL Links | Validation | Viewpoints and Navigation | Volumes | X3D-Edit | X3D for Web Authors | X3D Resources | Contact
.midi
and .wav
files (Windows Macintosh Linux).
.wav
format is required, while .midi
and .mp3
support are recommended.
Other audio formats are optional, you are welcome to check documentation for browsers of interest.
So far, no streaming protocol is required to be supported in X3D players.
.x3db
) format
or putting Web3D examples into version control.
For the .x3d XML encoding of scenes,
containerField
is the field-label prefix indicating this node's field relationship to its parent node, for example <Transform><Shape containerField='children'/></Transform>
.
containerField
values for each node are correct in most cases, so the need to override default containerField
values is rare.
containerField='geometry'
for Box node, containerField='children'
for Group node, containerField='proxy'
for hidden proxy shape within a Collision node, etc.
containerField
attribute is part of XML encoding for X3D scenes, and corresponds to the always-declared field labels in the ClassicVRML and VRML97 file encodings.
meta
tag information, WorldInfo node at the top,
or a email/document statement by the owner duplicated locally.
meta
tags to note the dates when a scene is created and revised:
<meta name='created' content='1 October 2003'/> <meta name='revised' content='18 June 2015'/>
4 July 2014
(rather than other forms such as
July 4, 2014
,
7/4/14
,
or
4/7/2014
).
x3d+xml
, x3d-vrml
and x3d+fastinfoset
.
HTML is the publishing language of the World Wide Web. HTML web pages can embed or launch X3D scenes.
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
CoolImage.png
vice CoolImage.PNG)
.CoolImage.jpg
.
JPEG is the best choice for photographic images since it captures color gradations exceptionally well.
Be careful to evaluate results when modifying JPEG compression quality, since it is lossy and highest image quality is often best.
Note that
JPEG does not support transparency.
url
field is an ordered list, authors can provide and link
more than one format if they wish. X3D browsers will honor the first successfully playable link
that they find.
.png
or .jpg
format, as described above, to ensure the X3D player can display it.
It is often best to save and provide both formats so that the original highest-quality image remains available.
Example:
<ImageTexture DEF='grid' url='"OahuGrid.png" "https://savage.nps.edu/Savage/Locations/Hawaii/OahuGrid.png" "OahuGrid.rgba" "https://savage.nps.edu/Savage/Locations/Hawaii/OahuGrid.rgba"'/>
Inline
, image, audio and video content.
This approach is more maintainable, uses less memory and can reduce file-transfer delays.
IMPORT
/EXPORT
connections match.
Inline
tooltips
and
X3D specification
describe functionality in detail.
<Inline url='"string array values"'> <MetadataString name='profile' value='Immersive'/> </Inline>
ProtoBody
.
ProtoDeclare
definitions into additional scenes,
instead copy ExternProtoDeclare
/ProtoInstance
definitions.
ProtoDeclare
,
ProtoInterface
and
ProtoBody
field
definitions in a ProtoInterface
element since that construct is illegal.
ExternProtoDeclare
/ProtoInstance
definitions
corresponding to each NewNodePrototype.x3d scene.
This encourages authors to avoid copying the ProtoDeclare
definitions,
so that a master version remains stable and improvable.
ProtoDeclare
annotation tooltips for each ExternProtoDeclare
field
.
Listing default values used by the prototype can be helpful.
ExternProtoDeclare
tooltips
and
X3D specification
containerField
attribute, identifying parent-node field name for this ProtoInstance
.
Default value: children
.
Example values: color
, coord
, geometry
, fontStyle
, proxy
, sound
, texture
, textureTransform
.
ProtoInstance
operation in the scene defining the original ProtoDeclare
, rather than
using an ExternProtoDeclare
.
Why - to make sure they work first!
Browser debugging can be more cryptic for externally defined prototypes
and different versions may occur in various remote url addresses, making it difficult to determine
precisely which ExternProtoDeclare
is being referenced.
ProtoInstance
tooltips
and
X3D XML Encoding specification
meta
tags in a scene to document what license being applied.
For example, one of the following is typically included in the X3D scenes found in the Web3D Consortium and NPS open-source example archives:
<meta name="license" content="../../license.html">
<meta name="license" content="http://www.web3d.org/x3d/content/examples/license.html">
<meta name="license" content="https://savage.nps.edu/Savage/license.html">
meta
Tags
<meta name="description" value="This beautiful model of an actual clean bedroom will impress your mom."/>
meta
tags with *default content descriptions*
<meta name="description" value="This description has a trailing newline character. "/>X3D Canonicalization (C14N) rules include normalization of whitespace and C14N tools can take care of this task for you.
<meta name="title"/>
(for document name)
and
<meta name="identifier"/>
(for document url)
tags, with filename values ending in .x3d
(rather than VRML97 .wrl) extension.
name="value"
attributes.
meta
attributes.
meta
tag such as
<meta name="generator" content="X3D-Edit, https://savage.nps.edu/X3D-Edit"/>or, when using ClassicVRML encoding,
META "generator" "X3D-Edit, https://savage.nps.edu/X3D-Edit"The X3D approach to
meta
tags matches best practices in HTML.
meta
tags in X3D scene headers.
containerField='metadata'
except when they are child values of a MetadataSet
node, in which case they have
containerField='value'
.x3d, .x3db
encodings: must follow
XML requirements
for ID/IDREF data type.
.x3dv, .wrl
encodings: must follow
ClassicVRML Grammar requirements
for Id/IdFirstChar.
DEF
/USE
and name
attributes, focusing on Unicode characters:
W3C Recommendation
Extensible Markup Language (XML) 1.0, Appendix J: Suggestions for XML Names.
Naming of multiple similar autogenerated files: Concatenate the following name components as appropriate. Separate components by period characters, since underscores disappear as part of a url and since hyphens will break across a line.
General notes on naming conventions:
<unit/>
for angle (default radians),
length (default meters),
mass (default kilograms) and
force (default newtons).
Common scaling factors, from given length unit to meters (m) | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Pica | Inches | Feet | Yards | Fathoms | Miles | Nautical Miles | Meters | Microns | Millimeters | Centimeters | Kilometers |
0.0042175176 | 0.0254 | 0.3048 | 0.9144 | 1.8288 | 1609.344 | 1852 | 1.0 | 0.000001 | 0.001 | 0.01 | 1000 |
Common scaling factors, from given angular unit to radians | ||
---|---|---|
Degrees | Full Circle | Grads |
0.0174532925167 (Pi/180) | 6.283185307179 | 0.01570796326795 |
Common scaling factors, from given force unit to Newtons (N) | |||
---|---|---|---|
Dynes | Kilogram-force | Pounds-force | Poundals |
0.00001 | 9.8068 | 4.4482 | 0.13826 |
Common scaling factors, from given avoirdupois mass unit to kilogram (kg) | ||||||
---|---|---|---|---|---|---|
Grains (gr) | Drams (dr) | Ounces (oz) | Troy Ounces (toz) | Pounds (lb) | Stone (14 lb) | Tons (U.S. short) |
0.00006479891 | 0.001771845195312 | 0.028349523125 | 0.0311034768 | 0.45359237 | 6.35029318 | 907.18474 |
Common scaling factors, from given metric mass unit to kilogram (kg) | ||||||
---|---|---|---|---|---|---|
Micrograms | Milligrams | Centigrams | Carats | Grams | Dekagrams | Metric Tonnes (t) |
0.000000001 | 0.000001 | 0.00001 | 0.0002 | 0.001 | 0.01 | 1000.0 |
var
declaration of variables.
Instead, declare any persistent variables as field definitions in the parent Script node.
true
and false
to match XML and ECMAScript/JavaScript rules.
Capitalized TRUE
and FALSE
are only used in VRML syntax.
<Script directOutput='true'>
when using SFNode/MFNode fields.
Browser.print(...)
rather than a simple print(...)
function
when printing to the console.
Browser.print(...)
is the form supported by X3D,
print(...)
was VRML97 syntax and is now obsolete.
For backwards compatibility, X3dToVrml97.xslt will strip
the preceding Browser.
class qualifier when converting scripts to VRLM97.
<
and >
from undesirable conversions by XML parsers.
Furthermore, it eliminates the need to use <
and >
escape-character replacements (which make script code nonportable).
Example:
<Script mustEvaluate="true"> <field name="message" type="SFString" accessType="initializeOnly" value="World!"/> <![CDATA[ ecmascript: function initialize (timestamp) { Browser.print ('Hello ' + message); } ]]> </Script>
ecmascript:
scripts, first add the following field interface to the Script.
<field accessType="initializeOnly" name="localTraceEnabled" type="SFBool" value="true"/>Then, at end of the CDATA section:
function tracePrint(outputString) { if (localTraceEnabled) Browser.print('[ScriptNameHere] ' + outputString); } function forcePrint(outputString) { Browser.print('[ScriptNameHere] ' + outputString); }This lets the script author use trace-aware output functions as a substitute for
Browser.print()
as follows.
tracePrint('Only print when localTraceEnabled is true'); forcePrint('Always print: localTraceEnabled=' + localTraceEnabled);
JavaScript is a common programming language used in Web browsers for HTML and X3D scripts.
Notes on JavaScript specification naming:
JSON is a data-structure convention for JavaScript.
Overview. Scalable Vector Graphics (SVG) is a markup language for describing two-dimensional graphics applications and images, and a set of related graphics script interfaces. SVG is supported by all modern browsers for desktop and mobile systems. There are many SVG authoring tools, and export to SVG is supported by all major vector graphics authoring tools.
url
attribute values:
<ImageTexture url=' "earth-topo.png" "earth-topo-small.gif" "http://www.web3d.org/x3d/content/examples/earth-topo.png" "http://www.web3d.org/x3d/content/examples/earth-topo-small.gif" '/>or, if using the equivalent but more awkward syntax for "double-quoted"
url
attribute values:
<ImageTexture url=" "earth-topo.png" "earth-topo-small.gif" "http://www.web3d.org/x3d/content/examples/earth-topo.png" "http://www.web3d.org/x3d/content/examples/earth-topo-small.gif" "/>
url
has type MFString
.
url
tooltipsThis section shows example declarations of DTD and Schema in X3D scenes.
One of the biggest benefits of the .x3d file encoding is XML validation. XML checks for well-formed documents, DTD validation and schema validation greatly improve quality assurance (QA) for X3D scenes. This approach exposes many possible errors and helps authors eliminate Garbage In Garbage Out (GIGO) problems. Useful links:
XML validation is defined by the Extensible Markup Language (XML) 1.0. A number of document variations are possible for X3D scenes. For example, encoding information" target="_blank"> is optional and may designate a variety of character sets. The X3D specifications are carefully designed to be fully compatible with XML requirements.
The following sections provide detailed information on the proper file syntax for X3D DTD and XML Schema headers in an .x3d scene. Each version matches the corresponding X3D version (3.0, 3.1, 3.2, and 3.3). Thanks to X3D stability, each version is backwards compatible. For example, the X3D v3.2 DTD and schema can validate X3D v3.2, v3.1, or v3.0 content, but not v3.3 content.
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE X3D PUBLIC "ISO//Web3D//DTD X3D 3.3//EN" "http://www.web3d.org/specifications/x3d-3.3.dtd"> <X3D profile="Immersive" version="3.3" xmlns:xsd="http://www.w3.org/2001/XMLSchema-instance" xsd:noNamespaceSchemaLocation="http://www.web3d.org/specifications/x3d-3.3.xsd">
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE X3D PUBLIC "ISO//Web3D//DTD X3D 3.2//EN" "http://www.web3d.org/specifications/x3d-3.2.dtd"> <X3D profile="Immersive" version="3.2" xmlns:xsd="http://www.w3.org/2001/XMLSchema-instance" xsd:noNamespaceSchemaLocation="http://www.web3d.org/specifications/x3d-3.2.xsd">Transitional DTD use is not recommended. There is Transitional DTD beyond X3D 3.1 since this approach is no longer needed.
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE X3D PUBLIC "ISO//Web3D//DTD X3D 3.1//EN" "http://www.web3d.org/specifications/x3d-3.1.dtd"> <X3D profile="Immersive" version="3.1" xmlns:xsd="http://www.w3.org/2001/XMLSchema-instance" xsd:noNamespaceSchemaLocation="http://www.web3d.org/specifications/x3d-3.1.xsd">The Transitional X3D 3.1 DOCTYPE/DTD was originally used by some tools during development, but is no longer recommended since it is not portable across different machines.
<?xml version="1.0" encoding="UTF-8"?> <!--Warning: transitional DOCTYPE in source .x3d file--> <!DOCTYPE X3D PUBLIC "http://www.web3d.org/specifications/x3d-3.1.dtd" "file:///www.web3d.org/TaskGroups/x3d/translation/x3d-3.1.dtd"> <X3D profile="Immersive" version="3.1" xmlns:xsd="http://www.w3.org/2001/XMLSchema-instance" xsd:noNamespaceSchemaLocation="http://www.web3d.org/specifications/x3d-3.1.xsd">
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE X3D PUBLIC "ISO//Web3D//DTD X3D 3.0//EN" "http://www.web3d.org/specifications/x3d-3.0.dtd"> <X3D profile="Immersive" version="3.0" xmlns:xsd="http://www.w3.org/2001/XMLSchema-instance" xsd:noNamespaceSchemaLocation="http://www.web3d.org/specifications/x3d-3.0.xsd">The Transitional X3D 3.0 DOCTYPE/DTD was originally used by some tools during development, but it is no longer recommended since it is not portable across different machines.
<?xml version="1.0" encoding="UTF-8"?> <!--Warning: transitional DOCTYPE in source .x3d file--> <!DOCTYPE X3D PUBLIC "http://www.web3d.org/specifications/x3d-3.0.dtd" "file:///www.web3d.org/TaskGroups/x3d/translation/x3d-3.0.dtd"> <X3D profile="Immersive" version="3.0" xmlns:xsd="http://www.w3.org/2001/XMLSchema-instance" xsd:noNamespaceSchemaLocation="http://www.web3d.org/specifications/x3d-3.0.xsd">When offline, X3D-Edit 3.1 can only load scenes containing the proper DTD one at a time. When disconnected from the network, click on a scene (or drag & drop the scene onto the X3D-Edit icon) to launch it - the DOCTYPE will be converted to Transitional DTD upon launch, and restored to Final DTD upon normal exit. Alternatively, use a different X3D/XML/text editor or the Transitional X3D DOCTYPE/DTD with X3D-Edit.
C:\www.web3d.org\x3d\content> java X3dDoctypeChecker usage: java X3dDoctypeChecker sceneName.x3d [-setFinalDTD | -setTransitionalDTD]
Developmental versions of all X3D DTDs and schemas are maintained under version control at
http://sourceforge.net/p/x3d/code/HEAD/tree/www.web3d.org/specifications
Viewpoints are typically the most important mechanism for an author to suggest scene navigation to a user. Recommended keyboard defaults are listed in Annex G Recommended navigation behaviours. In this way, new users interacting with an X3D scene can have a relatively consistent experience, regardless of which X3D player might be used.
Questions, suggestions, additions and comments about this X3D Scene Authoring Hints page are welcome. Please send them to Don Brutzman (brutzman at nps.edu) who maintains it.
These hints were collected while teaching X3D Graphics and writing X3D for Web Authors. Questions, suggestions, additions and comments are welcome.
Online at http://www.web3d.org/x3d/content/examples/X3dSceneAuthoringHints.html
Updated: 29 November 2016