#VRML V2.0 utf8
# X3D-to-VRML-97 XSL translation autogenerated by X3dToVrml97.xslt
# https://www.web3d.org/x3d/content/X3dToVrml97.xslt
# Generated using XSLT processor: Saxonica
# [X3D] VRML V3.0 utf8
# PROFILE Immersive
# [X3D] version=3.0
# [X3D] noNamespaceSchemaLocation=https://www.web3d.org/specifications/x3d-3.0.xsd
# [head]
# META "title" "RenderingComponentPrototypes.x3d"
# META "description" "Prototype implementations of X3D Rendering component nodes (IndexedTriangleFanSet IndexedTriangleSet IndexedTriangleStripSet LineSet TriangleFanSet TriangleSet TriangleStripSet) implemented as prototypes for backwards compatibility with VRML 97."
# META "info" "X3dToVrml97.xslt translation stylesheet automatically invokes these prototypes upon encountering any new Rendering nodes."
### Info:
# META "creator" "Don Brutzman, George Dabrowski, Ken Curtin, Duane Davis, Christos Kalogrias"
# META "created" "17 November 2003"
# META "modified" "9 October 2023"
# META "reference" "RenderingComponentExamples.x3d"
# META "reference" "RenderingComponentExternProtoDefinitions.x3d"
# META "reference" "https://www.web3d.org/specifications/X3Dv4Draft/ISO-IEC19775-1v4-IS.proof/Part01/components/rendering.html"
# META "reference" "https://www.web3d.org/x3d/content/examples/Vrml2Sourcebook/Chapter13-PointsLinesFaces/Figure13.11IndexedLineSetBoxWireframe.x3d"
# META "subject" "X3D Rendering component nodes (IndexedTriangleFanSet IndexedTriangleSet IndexedTriangleStripSet LineSet TriangleFanSet TriangleSet TriangleStripSet)"
# META "identifier" "https://www.web3d.org/x3d/content/examples/Basic/development/RenderingComponentPrototypes.x3d"
# META "generator" "X3D-Edit 4.0, https://savage.nps.edu/X3D-Edit"
# META "license" "../license.html"
EXTERNPROTO MetadataSet [
# [appinfo] MetadataSet contains a set of nodes in the value field.
exposedField SFString name
exposedField MFNode value
exposedField SFString reference
exposedField SFNode metadata # [appinfo] Metadata node only
][
# "MetadataPrototypes.wrl#MetadataSet"
"https://www.web3d.org/x3d/content/examples/Basic/development/MetadataPrototypes.wrl#MetadataSet"
# "MetadataPrototypes.x3d#MetadataSet"
"https://www.web3d.org/x3d/content/examples/Basic/development/MetadataPrototypes.x3d#MetadataSet"
]
EXTERNPROTO MetadataString [
# [appinfo] MetadataString contains a set of strings in the value field.
exposedField SFString name
exposedField MFString value
exposedField SFString reference
exposedField SFNode metadata # [appinfo] Metadata node only
][
# "MetadataPrototypes.wrl#MetadataString"
"https://www.web3d.org/x3d/content/examples/Basic/development/MetadataPrototypes.wrl#MetadataString"
# "MetadataPrototypes.x3d#MetadataString"
"https://www.web3d.org/x3d/content/examples/Basic/development/MetadataPrototypes.x3d#MetadataString"
]
# [Scene] ========== ========== ==========
NavigationInfo { type [ "EXAMINE" "ANY" ] } ### Default X3D NavigationInfo
# ====================
WorldInfo {
title "RenderingComponentPrototypes.x3d"
}
PROTO ColorRGBA [
# [appinfo] ColorRGBA defines a set of RGBA colors. Warning: VRML 97 support does not include alpha values.
exposedField MFRotation color [ ] # [appinfo] locally override MFColorRGBA type (which is not supported in VRML 97) in order to downgrade to Color RGB
# The color field is a 4-tuple float array, and so we map it to an MFOrientation for backwards compatibility with VRML 97.
exposedField SFNode metadata NULL # [appinfo] Metadata node only
# default initialization is NULL node to match X3D specification
] {
DEF ColorRGB Color {
color [ 0.8 0.8 0.8 ]
}
DEF ColorRGBAholder OrientationInterpolator {
keyValue IS color
}
DEF ConvertColorRGBAtoRGB Script {
field SFNode colorRGBAnode USE ColorRGBAholder
field SFNode colorRGBnode USE ColorRGB
directOutput TRUE
url [ "javascript: // ### X3D Browser.print() not supported by all VRML97 viewers, instead simply using print()
function initialize ()
{
// printingln ('colorRGBAnode.keyValue.length=' + colorRGBAnode.keyValue.length);
for (i=0; i<=colorRGBAnode.keyValue.length-1; i++)
{
// type conversion of each array element
// specifically, colorRGBAnode.keyValue[i] is an SFRotation
// and individual element values are then extracted from that
nextColor = new SFColor (
colorRGBAnode.keyValue[i].x,
colorRGBAnode.keyValue[i].y,
colorRGBAnode.keyValue[i].z);
// note colorRGBAnode.keyValue[i].angle holds the alpha value; ignored
// printingln ('color[' + i + ']=' + nextColor);
colorRGBnode.color[i] = nextColor;
}
}
" ]
}
Group {
children [
]
}
}
# ====================
PROTO IndexedTriangleFanSet [
# [appinfo] IndexedTriangleFanSet represents a 3D shape composed of triangles that form a fan shape around the first vertex declared in each fan.
field SFBool ccw TRUE
### Warning: ProtoInterface is unreferenced in ProtoBody with no corresponding IS/connect/@protoField
field SFBool colorPerVertex TRUE
field SFBool normalPerVertex TRUE
field SFBool solid TRUE
eventIn MFInt32 set_index # [appinfo] [0 infinity] or -1
field MFInt32 index [ ] # [appinfo] [0 infinity] or -1
# default initialization is NULL array [] to match X3D specification
exposedField SFNode color NULL # [appinfo] Color ColorRGBA node only
# default initialization is NULL node to match X3D specification
exposedField SFNode coord NULL # [appinfo] Coordinate node only
# default initialization is NULL node to match X3D specification
exposedField SFNode metadata NULL # [appinfo] Metadata node only
# default initialization is NULL node to match X3D specification
exposedField SFNode normal NULL # [appinfo] Normal node only
# default initialization is NULL node to match X3D specification
exposedField SFNode texCoord NULL # [appinfo] TextureCoordinate node only
# default initialization is NULL node to match X3D specification
] {
### Warning: ProtoBody child (or descendant) Shape following first child will not be rendered, since the first child determines node type of this prototype. (Authors can silence this warning by placing a comment as second child.)
DEF RenderedITFS IndexedFaceSet {
ccw IS ccw
normalPerVertex IS normalPerVertex
solid IS solid
color IS color
coord IS coord
normal IS normal
texCoord IS texCoord
}
DEF UnrenderedITFS Group {
children [
Shape {
# is this really needed at all??
geometry DEF NodesHolderITFS IndexedFaceSet {
color IS color
coord IS coord
normal IS normal
texCoord IS texCoord
}
}
DEF IndexedTriangleFanSetToIndexedFaceSet Script {
field MFInt32 index IS index
eventIn MFInt32 set_index IS set_index
field SFNode renderedITFS USE RenderedITFS
field SFNode nodesHolder USE NodesHolderITFS
field SFBool localTraceEnabled TRUE
field MFInt32 coordIndexNew [ ]
# constructed during initialization
directOutput TRUE
url [ "javascript: // ### X3D Browser.print() not supported by all VRML97 viewers, instead simply using print()
function initialize()
{
// index is an array of triangle indices that form a fan shape
// around the first vertex declared in each fan. The ordering of
// the vertices is ccw (counter-clockwise).
// ensure terminated by -1
if (index[index.length-1] != -1) index[index.length] = -1;
// ensure legal index values
for (i=0; i <= index.length-1; i++)
{
if (index[i] < -1)
{
alwaysPrint ('error, index[' + i + ']=' + index[i] +
' is illegal value, treated as -1');
index[i] = -1;
}
}
tracePrint ('index.length=' + index.length);
tracePrint ('index=' + index);
if (index.length < 4)
{
alwaysPrint ('warning, index.length=' + index.length +
' insufficient to construct a triangle, ITFS ignored');
return;
}
j = 0; // coordIndexNew counter
coordIndexNew = new MFInt32 ();
// i walks through index array,
// goal is to initialize coordIndexNew list to match triangles
for (i=2; i <= index.length-1; i++)
{
if ((index[i] == index[i-1]) || (index[i] == index[i-2]) || (index[i-1] == index[i-2]))
{
alwaysPrint ('index=' + index);
alwaysPrint ('error, pair of equal indices in triangle');
return;
}
if (index[i] >= 0)
{
// add another triangle from latest 3 points of fan set to IFS
// swap order to ensure normal is ccw, i.e. in correct halfplane direction
coordIndexNew [coordIndexNew.length] = 0;
coordIndexNew [coordIndexNew.length] = index[i];
coordIndexNew [coordIndexNew.length] = index[i-1];
coordIndexNew [coordIndexNew.length] = -1; // terminate
}
else if (index[i] == -1) // finish current triangle, fan
{
// ensure done, or sufficient points remain to build another triangle
if ( (i!=index.length-1) && (index.length - i < 2))
{
alwaysPrint ('index=' + index);
alwaysPrint ('error, insufficient index values after' +
'index[' + i + ']=-1');
return;
}
// ensure done, or enough legal index values remain to build another triangle
if ( (i!=index.length-1) &&
((index[i+1] == -1) || (index[i+2] == -1) || (index[i+3] == -1)))
{
alwaysPrint ('index=' + index);
alwaysPrint ('error, insufficient non-negative-one index values after' +
'index[' + i + ']=-1');
return;
}
tracePrint ('encountered -1 in index array');
// skip ahead to build next fan set, no effect if done
if (i!=index.length-1) i = i + 2;
}
// incremental trace of array being built
tracePrint ('coordIndexNew=' + coordIndexNew);
}
renderedITFS.set_coordIndex = coordIndexNew;
tracePrint ('renderedITFS.coordIndex=' + renderedITFS.coordIndex);
// match colorIndex if any Color node exists
if (nodesHolder.color)
{
if (nodesHolder.color.color.length > 0)
{
renderedITFS.set_colorIndex = coordIndexNew;
tracePrint ('set_colorIndex=' + coordIndexNew);
}
}
}
function set_index (value, timestamp)
{
index = value;
initialize ();
}
function tracePrint(outputString)
{
if (localTraceEnabled)
printingln ('[IndexedTriangleFanSet]' + outputString);
}
function alwaysPrint(outputString)
{
printingln ('[IndexedTriangleFanSet]' + outputString);
}
" ]
}
Group {
children [
]
}
]
}
}
# ====================
PROTO IndexedTriangleSet [
# [appinfo] IndexedTriangleSet represents a 3D shape composed of a collection of individual triangles.
field SFBool ccw TRUE
### Warning: ProtoInterface is unreferenced in ProtoBody with no corresponding IS/connect/@protoField
field SFBool colorPerVertex TRUE
field SFBool normalPerVertex TRUE
field SFBool solid TRUE
eventIn MFInt32 set_index # [appinfo] [0 infinity] or -1
field MFInt32 index [ ] # [appinfo] [0 infinity] or -1
# default initialization is NULL array [] to match X3D specification
exposedField SFNode color NULL # [appinfo] Color ColorRGBA node only
# default initialization is NULL node to match X3D specification
exposedField SFNode coord NULL # [appinfo] Coordinate node only
# default initialization is NULL node to match X3D specification
exposedField SFNode normal NULL # [appinfo] Normal node only
# default initialization is NULL node to match X3D specification
exposedField SFNode texCoord NULL # [appinfo] TextureCoordinate node only
# default initialization is NULL node to match X3D specification
exposedField SFNode metadata NULL # [appinfo] Metadata node only
# default initialization is NULL node to match X3D specification
] {
### Warning: ProtoBody child (or descendant) Shape following first child will not be rendered, since the first child determines node type of this prototype. (Authors can silence this warning by placing a comment as second child.)
DEF RenderedITS IndexedFaceSet {
ccw IS ccw
normalPerVertex IS normalPerVertex
solid IS solid
color IS color
coord IS coord
normal IS normal
texCoord IS texCoord
}
DEF UnrenderedITS Group {
children [
Shape {
# is this really needed at all??
geometry DEF NodesHolderITS IndexedFaceSet {
color IS color
coord IS coord
normal IS normal
texCoord IS texCoord
}
}
DEF IndexedTriangleSetToIndexedFaceSet Script {
field MFInt32 index IS index
eventIn MFInt32 set_index IS set_index
field SFNode renderedITS USE RenderedITS
field SFNode nodesHolder USE NodesHolderITS
field SFBool localTraceEnabled TRUE
field MFInt32 coordIndexNew [ ]
# constructed during initialization
directOutput TRUE
url [ "javascript: // ### X3D Browser.print() not supported by all VRML97 viewers, instead simply using print()
function initialize()
{
// index is an array of triangle indices. The ordering of
// the vertices is ccw (counter-clockwise).
// ensure legal index values
for (ii=0; ii <= index.length-1; ii++)
{
if (index[ii] < -1)
{
alwaysPrint ('error, index[' + ii + ']=' + index[ii] +
' is illegal value');
return;
}
}
tracePrint ('index.length=' + index.length);
tracePrint ('index=' + index);
if (index.length < 3)
{
alwaysPrint ('warning, index.length=' + index.length +
' insufficient to construct a triangle, ITS ignored');
return;
}
coordIndexNew = new MFInt32 ();
// ii walks through index array,
// goal is to initialize coordIndexNew list to match triangles
for (ii=0; ii <= index.length-1; ii+=3)
{
if ((index[ii] == index[ii+1]) || (index[ii] == index[ii+2]) || (index[ii+1] == index[ii+2]))
{
alwaysPrint ('index=' + index);
alwaysPrint ('error, pair of equal indices in triangle');
return;
}
if (index[ii] >= 0)
{
// add another triangle from latest 3 points of fan set to ITS
// order is ccw, i.e. in correct halfplane direction
coordIndexNew [coordIndexNew.length] = index[ii];
coordIndexNew [coordIndexNew.length] = index[ii+1];
coordIndexNew [coordIndexNew.length] = index[ii+2];
coordIndexNew [coordIndexNew.length] = -1;
}
if (index.length % 3 != 0) {
alwaysPrint ('error, index field does not contain a multiple' +
'of three coordinate values.');
alwaysPrint ('The remaining vertices shall be ignored');
return;
}
// ensure done, or sufficient points remain to build another triangle
// if ( (i!=index.length-1) && (index.length - i < 2))
// {
// alwaysPrint ('index=' + index);
// alwaysPrint ('error, insufficient index values after' +
// 'index[' + i + ']=-1');
// return;
// }
// ensure done, or enough legal index values remain to build another triangle
// if ( (i!=index.length-1) &&
// ((index[i+1] == -1) || (index[i+2] == -1) || (index[i+3] == -1)))
// {
// alwaysPrint ('index=' + index);
// alwaysPrint ('error, insufficient non-negative-one index values after' +
// 'index[' + i + ']=-1');
// return;
// }
// incremental trace of array being built
tracePrint ('coordIndexNew=' + coordIndexNew);
}
renderedITS.coordIndex = coordIndexNew;
tracePrint ('renderedITS.coordIndex=' + renderedITS.coordIndex);
// match colorIndex if any Color node exists
if (nodesHolder.color)
{
if (nodesHolder.color.color.length > 0)
{
renderedITS.set_colorIndex = coordIndexNew;
tracePrint ('set_colorIndex=' + coordIndexNew);
}
}
}
function set_index (value, timestamp)
{
index = value;
initialize ();
}
function tracePrint(outputString)
{
if (localTraceEnabled)
printingln ('[IndexedTriangleSet]' + outputString);
}
function alwaysPrint(outputString)
{
printingln ('[IndexedTriangleSet]' + outputString);
}
" ]
}
Group {
children [
]
}
]
}
}
# ====================
PROTO IndexedTriangleStripSet [
# [appinfo] IndexedTriangleStripSet represents a 3D shape composed of strips of triangles.
field SFBool ccw TRUE
### Warning: ProtoInterface is unreferenced in ProtoBody with no corresponding IS/connect/@protoField
field SFBool colorPerVertex TRUE
field SFBool normalPerVertex TRUE
field SFBool solid TRUE
eventIn MFInt32 set_index
field MFInt32 index [ ]
# default initialization is NULL array [] to match X3D specification
exposedField SFNode color NULL # [appinfo] Color ColorRGBA node only
# default initialization is NULL node to match X3D specification
exposedField SFNode coord NULL # [appinfo] Coordinate node only
# default initialization is NULL node to match X3D specification
exposedField SFNode normal NULL # [appinfo] Normal node only
# default initialization is NULL node to match X3D specification
exposedField SFNode texCoord NULL # [appinfo] TextureCoordinate node only
# default initialization is NULL node to match X3D specification
exposedField SFNode metadata NULL # [appinfo] Metadata node only
# default initialization is NULL node to match X3D specification
] {
### Warning: ProtoBody child (or descendant) Shape following first child will not be rendered, since the first child determines node type of this prototype. (Authors can silence this warning by placing a comment as second child.)
DEF RenderedTSS IndexedFaceSet {
ccw IS ccw
normalPerVertex IS normalPerVertex
solid IS solid
color IS color
coord IS coord
normal IS normal
texCoord IS texCoord
}
Group {
children [
Shape {
# is this really needed at all??
geometry DEF NodesHolderTSS IndexedFaceSet {
color IS color
coord IS coord
normal IS normal
texCoord IS texCoord
}
}
DEF IndexedTriangleStripSetToIndexedFaceSet Script {
field MFInt32 index IS index
eventIn MFInt32 set_index IS set_index
field SFNode renderedTSS USE RenderedTSS
field SFNode nodesHolder USE NodesHolderTSS
field SFBool localTraceEnabled TRUE
field MFInt32 coordIndexNew [ ]
# constructed during initialization
directOutput TRUE
url [ "javascript: // ### X3D Browser.print() not supported by all VRML97 viewers, instead simply using print()
function initialize()
{
// index is an array of triangle indices. The ordering of
// the vertices is ccw (counter-clockwise).
// ensure legal index values
for (ii=0; ii <= index.length-1; ii++)
{
if (index[ii] < -1)
{
alwaysPrint ('error, index[' + ii + ']=' + index[ii] +
' is illegal value');
return;
}
}
tracePrint ('index.length=' + index.length);
tracePrint ('index=' + index);
if (index.length < 3)
{
alwaysPrint ('warning, index.length=' + index.length +
' insufficient to construct a triangle, ITS ignored');
return;
}
coordIndexNew = new MFInt32 ();
// ii walks through index array,
// goal is to initialize coordIndexNew list to match triangles
for (ii=2; ii <= index.length-1; ii++)
{
if ((index[ii] == index[ii-1]) || (index[ii] == index[ii-2]) || (index[ii-1] == index[ii-2]))
{
alwaysPrint ('index=' + index);
alwaysPrint ('error, pair of equal indices in triangle');
return;
}
if (index[ii] >= 0)
{
// add another triangle from latest 3 points of fan set to ITS
// order is ccw, i.e. in correct halfplane direction
coordIndexNew [coordIndexNew.length] = index[ii-2];
coordIndexNew [coordIndexNew.length] = index[ii-1];
coordIndexNew [coordIndexNew.length] = index[ii];
coordIndexNew [coordIndexNew.length] = -1;
}
// ensure done, or sufficient points remain to build another triangle
// if ( (i!=index.length-1) && (index.length - i < 2))
// {
// alwaysPrint ('index=' + index);
// alwaysPrint ('error, insufficient index values after' +
// 'index[' + i + ']=-1');
// return;
// }
// ensure done, or enough legal index values remain to build another triangle
// if ( (i!=index.length-1) &&
// ((index[i+1] == -1) || (index[i+2] == -1) || (index[i+3] == -1)))
// {
// alwaysPrint ('index=' + index);
// alwaysPrint ('error, insufficient non-negative-one index values after' +
// 'index[' + i + ']=-1');
// return;
// }
// incremental trace of array being built
tracePrint ('TSScoordIndexNew=' + coordIndexNew);
}
renderedTSS.set_coordIndex = coordIndexNew;
tracePrint ('renderedTSS.coordIndex=' + renderedTSS.coordIndex);
// match colorIndex if any Color node exists
if (nodesHolder.color)
{
if (nodesHolder.color.color.length > 0)
{
renderedTSS.set_colorIndex = coordIndexNew;
tracePrint ('set_colorIndex=' + coordIndexNew);
}
}
}
function set_index (value, timestamp)
{
index = value;
initialize ();
}
function tracePrint(outputString)
{
if (localTraceEnabled)
printingln ('[IndexedTriangleStripSet]' + outputString);
}
function alwaysPrint(outputString)
{
printingln ('[IndexedTriangleStripSet]' + outputString);
}
" ]
}
Group {
children [
]
}
]
}
}
# ====================
PROTO LineSet [
# [appinfo] LineSet represents a 3D geometry formed by constructing polylines from 3D vertices.
exposedField MFInt32 vertexCount [ ]
# default initialization is NULL array [] to match X3D specification
exposedField SFNode color NULL # [appinfo] Color ColorRGBA node only
# default initialization is NULL node to match X3D specification
exposedField SFNode coord NULL # [appinfo] Coordinate node only
# default initialization is NULL node to match X3D specification
exposedField SFNode metadata NULL # [appinfo] Metadata node only
# default initialization is NULL node to match X3D specification
] {
### Warning: ProtoBody child (or descendant) Shape following first child will not be rendered, since the first child determines node type of this prototype. (Authors can silence this warning by placing a comment as second child.)
DEF RenderedILS IndexedLineSet {
color IS color
}
Group {
children [
Shape {
geometry DEF NodesHolderILS IndexedLineSet {
color IS color
coord IS coord
}
appearance DEF UnusedAppearance Appearance {
material Material {
emissiveColor 0.8 0.8 0.8
}
}
}
DEF LineSetToIndexedLineSet Script {
### Warning: Script field 'vertexCount' has accessType 'inputOutput' (exposedField), which is only allowed in X3D Script node, not VRML97 Script node. Using exposedField anyway, may cause errors.
exposedField MFInt32 vertexCount IS vertexCount
# default initialization is NULL array [] to match X3D specification
field SFNode renderedILS USE RenderedILS
field SFNode nodesHolder USE NodesHolderILS
field SFBool localTraceEnabled TRUE
field MFInt32 coordIndexNew [ ]
# constructed during initialization
directOutput TRUE
url [ "javascript: // ### X3D Browser.print() not supported by all VRML97 viewers, instead simply using print()
function initialize()
{
vertexCountSum = 0;
tracePrint ('vertexCount=' + vertexCount);
for (i=0; i < vertexCount.length; i++)
{
if (vertexCount[i] < 2)
{
alwaysPrint ('error, vertexCount[' + i + ']=' + vertexCount[i] +
' is illegal value, must be >= 2');
return;
}
vertexCountSum = vertexCountSum + vertexCountSum[i];
}
tracePrint ('vertexCountSum=' + vertexCountSum);
numberPoints = nodesHolder.coord.point.length;
if (numberPoints < vertexCountSum)
{
alwaysPrint ('warning, Coordinate.point.length=' + numberPoints +
' is less than vertexCountSum=' + vertexCountSum + ', LS ignored');
return;
}
coordIndexNew = new MFInt32 ();
numberSegments = vertexCountSum.length; // need validity check
// i walks through array of points to build line-segment indices
i = 0;
for (seg=0; seg < numberSegments; seg++)
{
for (j=0; j < vertexCount[seg]; j++)
{
coordIndexNew [coordIndexNew.length] = i;
i++;
}
coordIndexNew [coordIndexNew.length] = -1; // terminate current fan
// incremental trace of array being built
tracePrint ('coordIndexNew=' + coordIndexNew);
} // repeat for all vertices
renderedILS.coordIndex = coordIndexNew;
tracePrint ('renderedILS.coordIndex=' + renderedILS.coordIndex);
// match colorIndex if any Color node exists
if (nodesHolder.color)
{
if (nodesHolder.color.color.length > 0)
{
renderedILS.colorIndex = coordIndexNew;
tracePrint ('set_colorIndex=' + coordIndexNew);
}
}
}
function tracePrint(outputString)
{
if (localTraceEnabled)
printingln ('[TriangleFanSet]' + outputString);
}
function alwaysPrint(outputString)
{
printingln ('[TriangleFanSet]' + outputString);
}
" ]
}
Group {
children [
]
}
]
}
}
# ====================
PROTO TriangleFanSet [
# [appinfo] TriangleFanSet represents a 3D shape composed of triangles that form a fan shape around the first vertex declared in each fan.
exposedField MFInt32 fanCount [ ]
# default initialization is NULL array [] to match X3D specification
field SFBool ccw TRUE
field SFBool colorPerVertex TRUE
field SFBool normalPerVertex TRUE
field SFBool solid TRUE
exposedField SFNode color NULL # [appinfo] Color ColorRGBA node only
# default initialization is NULL node to match X3D specification
exposedField SFNode coord NULL # [appinfo] Coordinate node only
# default initialization is NULL node to match X3D specification
exposedField SFNode normal NULL # [appinfo] Normal node only
# default initialization is NULL node to match X3D specification
exposedField SFNode texCoord NULL # [appinfo] TextureCoordinate node only
# default initialization is NULL node to match X3D specification
exposedField SFNode metadata NULL # [appinfo] Metadata node only
# default initialization is NULL node to match X3D specification
] {
### Warning: ProtoBody child (or descendant) Shape following first child will not be rendered, since the first child determines node type of this prototype. (Authors can silence this warning by placing a comment as second child.)
DEF RenderedTFS IndexedFaceSet {
ccw IS ccw
colorPerVertex IS colorPerVertex
normalPerVertex IS normalPerVertex
solid IS solid
color IS color
coord IS coord
normal IS normal
texCoord IS texCoord
}
DEF UnrenderedTFS Group {
children [
Shape {
# is this really needed at all??
geometry DEF NodesHolderTFS IndexedFaceSet {
color IS color
coord IS coord
normal IS normal
texCoord IS texCoord
}
}
DEF TriangleFanSetToIndexedFaceSet Script {
### Warning: Script field 'fanCount' has accessType 'inputOutput' (exposedField), which is only allowed in X3D Script node, not VRML97 Script node. Using exposedField anyway, may cause errors.
exposedField MFInt32 fanCount IS fanCount
# default initialization is NULL array [] to match X3D specification
field SFNode renderedTFS USE RenderedTFS
field SFNode nodesHolder USE NodesHolderTFS
field SFBool localTraceEnabled TRUE
field MFInt32 coordIndexNew [ ]
# constructed during initialization
directOutput TRUE
url [ "javascript: // ### X3D Browser.print() not supported by all VRML97 viewers, instead simply using print()
function initialize()
{
fanCountSum = 0;
tracePrint ('fanCount=' + fanCount);
for (i=0; i < fanCount.length; i++)
{
if (fanCount[i] < 3)
{
alwaysPrint ('error, fanCount[' + i + ']=' + fanCount[i] +
' is illegal value, must be >= 3');
return;
}
fanCountSum = fanCountSum + fanCount[i];
}
tracePrint ('fanCountSum=' + fanCountSum);
numberPoints = nodesHolder.coord.point.length;
if (numberPoints < fanCountSum)
{
alwaysPrint ('warning, Coordinate.point.length=' + numberPoints +
' is less than fanCountSum=' + fanCountSum + ', TFS ignored');
return;
}
coordIndexNew = new MFInt32 ();
numberFans = fanCount.length; // need validity check
// i walks through array of points to build polygon indices
i = 0;
for (fan=0; fan < numberFans; fan++)
{
for (j=0; j < fanCount[fan]; j++)
{
coordIndexNew [coordIndexNew.length] = i;
i++;
}
coordIndexNew [coordIndexNew.length] = -1; // terminate current fan
// incremental trace of array being built
tracePrint ('coordIndexNew=' + coordIndexNew);
} // repeat for all fans
renderedTFS.coordIndex = coordIndexNew;
tracePrint ('renderedTFS.coordIndex=' + renderedTFS.coordIndex);
// match colorIndex if any Color node exists
if (nodesHolder.color)
{
if (nodesHolder.color.color.length > 0)
{
renderedTFS.set_colorIndex = coordIndexNew;
tracePrint ('set_colorIndex=' + coordIndexNew);
}
}
}
function tracePrint(outputString)
{
if (localTraceEnabled)
printingln ('[TriangleFanSet]' + outputString);
}
function alwaysPrint(outputString)
{
printingln ('[TriangleFanSet]' + outputString);
}
" ]
}
Group {
children [
]
}
]
}
}
# ====================
PROTO TriangleSet [
# [appinfo] TriangleSet represents a 3D shape that represents a collection of individual triangles.
field SFBool ccw TRUE
### Warning: ProtoInterface is unreferenced in ProtoBody with no corresponding IS/connect/@protoField
field SFBool colorPerVertex TRUE
field SFBool normalPerVertex TRUE
field SFBool solid TRUE
exposedField SFNode color NULL # [appinfo] Color ColorRGBA node only
# default initialization is NULL node to match X3D specification
exposedField SFNode coord NULL # [appinfo] Coordinate node only
# default initialization is NULL node to match X3D specification
exposedField SFNode normal NULL # [appinfo] Normal node only
# default initialization is NULL node to match X3D specification
exposedField SFNode texCoord NULL # [appinfo] TextureCoordinate node only
# default initialization is NULL node to match X3D specification
exposedField SFNode metadata NULL # [appinfo] Metadata node only
# default initialization is NULL node to match X3D specification
] {
### Warning: ProtoBody child (or descendant) Shape following first child will not be rendered, since the first child determines node type of this prototype. (Authors can silence this warning by placing a comment as second child.)
DEF RenderedTS IndexedFaceSet {
ccw IS ccw
normalPerVertex IS normalPerVertex
solid IS solid
color IS color
coord IS coord
normal IS normal
texCoord IS texCoord
}
DEF UnrenderedTS Group {
children [
Shape {
# is this really needed at all??
geometry DEF NodesHolderTS IndexedFaceSet {
color IS color
coord IS coord
normal IS normal
texCoord IS texCoord
}
}
DEF TriangleSetToIndexedFaceSet Script {
field MFInt32 index [ ]
# default initialization is NULL
eventIn MFInt32 set_index
field SFNode renderedTS USE RenderedTS
field SFNode nodesHolder USE NodesHolderTS
field SFBool localTraceEnabled TRUE
field MFInt32 coordIndexNew [ ]
# constructed during initialization
directOutput TRUE
### Warning: Script initializeOnly field 'renderedTS' is not referenced in contained ecmascript: code
url [ "javascript: // ### X3D Browser.print() not supported by all VRML97 viewers, instead simply using print()
function initialize()
{
// index is an array of triangle indices. The ordering of
// the vertices is ccw (counter-clockwise).
// ensure legal index values
for (ii=0; ii <= index.length-1; ii++)
{
if (index[ii] < -1)
{
alwaysPrint ('error, index[' + ii + ']=' + index[ii] +
' is illegal value');
return;
}
}
tracePrint ('index.length=' + index.length);
tracePrint ('index=' + index);
if (index.length < 3)
{
alwaysPrint ('warning, index.length=' + index.length +
' insufficient to construct a triangle, ITS ignored');
return;
}
coordIndexNew = new MFInt32 ();
// ii walks through index array,
// goal is to initialize coordIndexNew list to match triangles
for (ii=0; ii <= index.length-1; ii+=3)
{
if ((index[ii] == index[ii+1]) || (index[ii] == index[ii+2]) || (index[ii+1] == index[ii+2]))
{
alwaysPrint ('index=' + index);
alwaysPrint ('error, pair of equal indices in triangle');
return;
}
if (index[ii] >= 0)
{
// add another triangle from latest 3 points of fan set to ITS
// order is ccw, i.e. in correct halfplane direction
coordIndexNew [coordIndexNew.length] = index[ii];
coordIndexNew [coordIndexNew.length] = index[ii+1];
coordIndexNew [coordIndexNew.length] = index[ii+2];
coordIndexNew [coordIndexNew.length] = -1;
}
if (index.length % 3 != 0) {
alwaysPrint ('error, index field does not contain a multiple' +
'of three coordinate values.');
alwaysPrint ('The remaining vertices shall be ignored');
return;
}
// ensure done, or sufficient points remain to build another triangle
// if ( (i!=index.length-1) && (index.length - i < 2))
// {
// alwaysPrint ('index=' + index);
// alwaysPrint ('error, insufficient index values after' +
// 'index[' + i + ']=-1');
// return;
// }
// ensure done, or enough legal index values remain to build another triangle
// if ( (i!=index.length-1) &&
// ((index[i+1] == -1) || (index[i+2] == -1) || (index[i+3] == -1)))
// {
// alwaysPrint ('index=' + index);
// alwaysPrint ('error, insufficient non-negative-one index values after' +
// 'index[' + i + ']=-1');
// return;
// }
// incremental trace of array being built
tracePrint ('coordIndexNew=' + coordIndexNew);
}
renderedITS.set_coordIndex = coordIndexNew;
tracePrint ('renderedITS.coordIndex=' + renderedITS.coordIndex);
// match colorIndex if any Color node exists
if (nodesHolder.color)
{
if (nodesHolder.color.color.length > 0)
{
renderedITS.set_colorIndex = coordIndexNew;
tracePrint ('set_colorIndex=' + coordIndexNew);
}
}
}
function set_index (value, timestamp)
{
index = value;
initialize ();
}
function tracePrint(outputString)
{
if (localTraceEnabled)
printingln ('[IndexedTriangleSet]' + outputString);
}
function alwaysPrint(outputString)
{
printingln ('[IndexedTriangleSet]' + outputString);
}
" ]
}
Group {
children [
]
}
]
}
}
# ====================
PROTO TriangleStripSet [
# [appinfo] TriangleStripSet represents a 3D shape composed of strips of triangles.
### Warning: ProtoInterface is unreferenced in ProtoBody with no corresponding IS/connect/@protoField
exposedField MFInt32 stripCount [ ]
# default initialization is NULL array [] to match X3D specification
### Warning: ProtoInterface is unreferenced in ProtoBody with no corresponding IS/connect/@protoField
field SFBool ccw TRUE
### Warning: ProtoInterface is unreferenced in ProtoBody with no corresponding IS/connect/@protoField
field SFBool colorPerVertex TRUE
### Warning: ProtoInterface is unreferenced in ProtoBody with no corresponding IS/connect/@protoField
field SFBool normalPerVertex TRUE
### Warning: ProtoInterface is unreferenced in ProtoBody with no corresponding IS/connect/@protoField
field SFBool solid TRUE
### Warning: ProtoInterface is unreferenced in ProtoBody with no corresponding IS/connect/@protoField
exposedField SFNode color NULL # [appinfo] Color ColorRGBA node only
# default initialization is NULL node to match X3D specification
### Warning: ProtoInterface is unreferenced in ProtoBody with no corresponding IS/connect/@protoField
exposedField SFNode coord NULL # [appinfo] Coordinate node only
# default initialization is NULL node to match X3D specification
### Warning: ProtoInterface is unreferenced in ProtoBody with no corresponding IS/connect/@protoField
exposedField SFNode normal NULL # [appinfo] Normal node only
# default initialization is NULL node to match X3D specification
### Warning: ProtoInterface is unreferenced in ProtoBody with no corresponding IS/connect/@protoField
exposedField SFNode texCoord NULL # [appinfo] TextureCoordinate node only
# default initialization is NULL node to match X3D specification
### Warning: ProtoInterface is unreferenced in ProtoBody with no corresponding IS/connect/@protoField
exposedField SFNode metadata NULL # [appinfo] Metadata node only
# default initialization is NULL node to match X3D specification
] {
IndexedFaceSet {
}
}
# ====================
# ProtoInstance examples are found in RenderingComponentExamples.x3d
Background {
groundColor [ 0.2 0.2 0.2 ]
skyColor [ 0.2 0.2 0.2 ]
}
DEF LinkToExamples Anchor {
description "link to examples"
url [ "RenderingComponentExamples.x3d" "https://www.web3d.org/x3d/content/examples/Basic/development/RenderingComponentExamples.x3d" "RenderingComponentExamples.wrl" "https://www.web3d.org/x3d/content/examples/Basic/development/RenderingComponentExamples.wrl" ]
children [
Shape {
appearance Appearance {
material Material {
diffuseColor 1 1 1
}
}
geometry Text {
string [ "RenderingComponentPrototypes" "is a developmental file." "Click this text to view" "RenderingComponentExamples" ]
fontStyle FontStyle {
justify [ "MIDDLE" "MIDDLE" ]
}
}
}
# Selectable Text has transparent Box and TouchSensor description as a tooltip
Shape {
geometry Box {
size 12 5 .001
}
appearance Appearance {
material Material {
transparency 0.8
}
}
}
]
}