X3D Model Documentation: ViewPositionOrientationPrototype.x3d

  1  <?xml version="1.0" encoding="UTF-8"?>
  2 
<!DOCTYPE X3D PUBLIC "ISO//Web3D//DTD X3D 3.0//EN" "https://www.web3d.org/specifications/x3d-3.0.dtd">
  3  <X3D profile='Immersive' version='3.0 xmlns:xsd='http://www.w3.org/2001/XMLSchema-instance' xsd:noNamespaceSchemaLocation='https://www.web3d.org/specifications/x3d-3.0.xsd'>
  4       <head>
  5            <meta name='titlecontent=' ViewPositionOrientationPrototype.x3d '/>
  6            <meta name='creatorcontent='Leonard Daly and Don Brutzman'/>
  7            <meta name='translatorcontent='Don Brutzman'/>
  8            <meta name='createdcontent='1 November 2000'/>
  9            <meta name='modifiedcontent='28 November 2019'/>
 10            <meta name='descriptioncontent='ViewPositionOrientation prototype provides local position and orientation as user navigates, with optional console output'/>
 11            <meta name='infocontent='Note fix: metadata is no longer an allowed ProtoDeclare field name, since ProtoInstance already includes a metadata field'/>
 12            <meta name='referencecontent=' ViewPositionOrientationExample.x3d '/>
 13            <meta name='referencecontent=' https://www.web3d.org/x3d/content/examples/X3dForWebAuthors/Chapter14Prototypes/WhereAmIExample.x3d '/>
 14            <meta name='referencecontent=' https://www.web3d.org/x3d/content/examples/X3dForWebAuthors/Chapter14Prototypes/WhereAmIPrototype.x3d '/>
 15            <meta name='referencecontent='http://www.realism.com/Web3D/Examples#WhereAmI'/>
 16            <meta name='referencecontent='http://www.realism.com/vrml/Example/WhereAmI/WhereAmI_Proto.wrl'/>
 17            <meta name='identifiercontent=' https://www.web3d.org/x3d/content/examples/Savage/Tools/Authoring/ViewPositionOrientationPrototype.x3d '/>
 18            <meta name='generatorcontent='X3D-Edit 3.3, https://www.web3d.org/x3d/tools/X3D-Edit'/>
 19            <meta name='licensecontent='../../license.html'/>
 20       </head>
<!--

<!--
Event Graph ROUTE Table shows event connections.
-->
<!-- to top DEF nodes index: OutputPositionOrientation, WhereSensor

Index for Viewpoint node: Viewpoint_1

Index for ProtoDeclare definition: ViewPositionOrientation
-->
 21       <Scene>
 22            <!-- Thanks to Leonard Daly for the original design of this prototype -->
 23            <WorldInfo title='ViewPositionOrientationPrototype.x3d'/>
 24            <ProtoDeclare name='ViewPositionOrientationappinfo='ViewPositionOrientation provides provides console output of local position and orientation as user navigates'>
 25                 <ProtoInterface>
 26                      <field name='enabledtype='SFBoolvalue='trueaccessType='inputOutput'
                     appinfo='Whether or not ViewPositionOrientation sends output to console'/>
 27                      <field name='traceEnabledtype='SFBoolvalue='trueaccessType='initializeOnly'
                     appinfo='Output internal trace messages for debugging this node, intended for developer use only'/>
 28                      <field name='set_traceEnabledtype='SFBoolaccessType='inputOnly'
                     appinfo='Ability to turn output tracing on/off at runtime'/>
 29                      <field name='position_changedtype='SFVec3faccessType='outputOnly'
                     appinfo='Output local position'/>
 30                      <field name='orientation_changedtype='SFRotationaccessType='outputOnly'
                     appinfo='Output local orientation'/>
 31                      <field name='outputViewpointStringtype='MFStringaccessType='outputOnly'
                     appinfo='MFString value of new Viewpoint, suitable for use in string field of a Text node'/>
 32                 </ProtoInterface>
 33                 <ProtoBody>
 34 
                    <!-- ROUTE information for WhereSensor node:  [from position_changed to OutputPositionOrientation.set_position ] [from orientation_changed to OutputPositionOrientation.set_orientation ] -->
                    <ProximitySensor DEF='WhereSensorsize='1000000000 1000000000 1000000000'>
 35                           <IS>
 36                                <connect nodeField='enabledprotoField='enabled'/>
 37                           </IS>
 38                      </ProximitySensor>
 39                      <!-- it's a big old world out there! large box likely handles most use cases. -->
 40 
                    <!-- ROUTE information for OutputPositionOrientation node:  [from WhereSensor.position_changed to set_position ] [from WhereSensor.orientation_changed to set_orientation ] -->
                    <Script DEF='OutputPositionOrientation'>
 41                           <field name='traceEnabledtype='SFBoolaccessType='initializeOnly'/>
 42                           <field name='set_traceEnabledtype='SFBoolaccessType='inputOnly'/>
 43                           <field name='set_positiontype='SFVec3faccessType='inputOnly'/>
 44                           <field name='set_orientationtype='SFRotationaccessType='inputOnly'/>
 45                           <field name='positiontype='SFVec3fvalue='0 0 0accessType='initializeOnly'/>
 46                           <field name='orientationtype='SFRotationvalue='0 1 0 0accessType='initializeOnly'/>
 47                           <field name='position_changedtype='SFVec3faccessType='outputOnly'/>
 48                           <field name='orientation_changedtype='SFRotationaccessType='outputOnly'/>
 49                           <field name='outputViewpointStringtype='MFStringaccessType='outputOnly'/>
 50                           <IS>
 51                                <connect nodeField='traceEnabledprotoField='traceEnabled'/>
 52                                <connect nodeField='set_traceEnabledprotoField='set_traceEnabled'/>
 53                                <connect nodeField='position_changedprotoField='position_changed'/>
 54                                <connect nodeField='orientation_changedprotoField='orientation_changed'/>
 55                                <connect nodeField='outputViewpointStringprotoField='outputViewpointString'/>
 56                           </IS>
  <![CDATA[
          
ecmascript:

function roundoff (value, digits) // for local use only
{
	var resolution = 1;
	for (i = 1; i <= digits; i++ )
	{
		resolution *= 10;
	}
	return Math.round (value*resolution) / resolution; // round to resolution
}
function outputViewpoint ()
{
  var holdString = 
        '<Viewpoint position=\"' +
		roundoff (position.x, 1) + ' ' +
		roundoff (position.y, 1) + ' ' +
		roundoff (position.z, 1) +
        '\" orientation=\"' +
		roundoff (orientation.x, 3) + ' ' +
		roundoff (orientation.y, 3) + ' ' +
		roundoff (orientation.z, 3) + ' ' +
		roundoff (orientation.angle, 4) + '\"/>' ;
   tracePrint (holdString);
   outputViewpointString = new MFString (holdString);
}
function set_position (value)
{
	position = value; // save persistent value
	position_changed = position; // output event
	outputViewpoint ();
}
function set_orientation (value)
{
	orientation = value; // save persistent value
	orientation_changed = orientation; // output event
	outputViewpoint ();
}
function set_traceEnabled (value)
{
	traceEnabled = value;
	alwaysPrint ('traceEnabled=' + traceEnabled);
}
function alwaysPrint (text)
{
	Browser.println ('[ViewPositionOrientation] ' + text);
}
function tracePrint (text)
{
	if (traceEnabled) alwaysPrint (text);
}

        
]]>
 58                      </Script>
 59                      < ROUTE  fromNode='WhereSensor' fromField='position_changed' toNode='OutputPositionOrientation' toField='set_position'/>
 60                      < ROUTE  fromNode='WhereSensor' fromField='orientation_changed' toNode='OutputPositionOrientation' toField='set_orientation'/>
 61                 </ProtoBody>
 62            </ProtoDeclare>
 63            <!-- ==================== -->
 64            <Viewpoint description='ViewPositionOrientation prototypeposition='0 0 14'/>
 65            <Anchor description='ViewPositionOrientation Exampleparameter='"target=_blank"'   url=' "ViewPositionOrientationExample.x3d" "https://www.web3d.org/x3d/content/examples/Savage/Tools/Authoring/ViewPositionOrientationExample.x3d" "ViewPositionOrientationExample.wrl" "https://www.web3d.org/x3d/content/examples/Savage/Tools/Authoring/ViewPositionOrientationExample.wrl" '>
 66                 <Shape>
 67                      <Text string='"ViewPositionOrientationPrototype" "is a prototype definition file" "" "Click this text to see" "ViewPositionOrientationExample"'>
 68                           <FontStyle justify='"MIDDLE" "MIDDLE"size='1.2'/>
 69                      </Text>
 70                      <Appearance>
 71                           <Material diffuseColor='0.6 0.8 0.4'/>
 72                      </Appearance>
 73                 </Shape>
 74                 <!-- Selectable Text design pattern has transparent Box and TouchSensor description as a tooltip -->
 75                 <Shape>
 76                      <!-- Author TODO: to adjust transparent Box as text-selection assist, set width and height to match size, then set transparency='1' to make invisible. -->
 77                      <Box size='16 7 .001'/>
 78                      <Appearance>
 79                           <Material transparency='1'/>
 80                      </Appearance>
 81                 </Shape>
 82            </Anchor>
 83       </Scene>
 84  </X3D>
<!--

<!--
Event Graph ROUTE Table shows event connections.
-->
<!-- to top DEF nodes index: OutputPositionOrientation, WhereSensor

Index for Viewpoint node: Viewpoint_1

Index for ProtoDeclare definition: ViewPositionOrientation
-->
X3D Tooltips element index: Anchor, Appearance, Box, connect, field, FontStyle, head, IS, Material, meta, ProtoBody, ProtoDeclare, ProtoInterface, ProximitySensor, ROUTE, Scene, Script, Shape, Text, Viewpoint, WorldInfo, X3D, plus documentation for accessType definitions, type definitions, XML data types, and field types

Event Graph ROUTE Table entries with 2 ROUTE connections total, showing X3D event-model relationships for this scene.

Each row shows an event cascade that may occur during a single timestamp interval between frame renderings, as part of the X3D execution model.

WhereSensor
ProximitySensor
position_changed
SFVec3f

ROUTE
event to
(1)
OutputPositionOrientation
Script
set_position
SFVec3f
WhereSensor
ProximitySensor
orientation_changed
SFRotation

ROUTE
event to
(1)
OutputPositionOrientation
Script
set_orientation
SFRotation

line 65
Anchor
description='ViewPositionOrientation Example' 
User-interaction hint for this node. 

Additional guidance on X3D animation can be found in the 10-Step Animation Design Process and Event Tracing hint sheets. Have fun with X3D! 😀

-->
<!-- Online at
https://www.web3d.org/x3d/content/examples/Savage/Tools/Authoring/ViewPositionOrientationPrototypeIndex.html -->
<!-- Version control at
https://sourceforge.net/p/x3d/code/HEAD/tree/www.web3d.org/x3d/content/examples/Savage/Tools/Authoring/ViewPositionOrientationPrototype.x3d -->

<!-- Color-coding legend: X3D terminology <X3dNode  DEF='idNamefield='value'/> matches XML terminology <XmlElement  DEF='idNameattribute='value'/>
(Light-blue background: event-based behavior node or statement) (Grey background inside box: inserted documentation) (Magenta background: X3D Extensibility)
    <ProtoDeclare name='ProtoName'> <field name='fieldName'/> </ProtoDeclare> -->

to top <!-- For additional help information about X3D scenes, please see X3D Tooltips, X3D Resources, and X3D Scene Authoring Hints. -->