<?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 '>
<head>
<meta name='titlecontent='Figure31.6DonutPrototype.x3d'/>
<meta name='creatorcontent='Figure 31.6, The VRML 2.0 Sourcebook, Copyright [1997] By Andrea L. Ames, David R. Nadeau, and John L. Moreland'/>
<meta name='referencecontent=' http://www.wiley.com/legacy/compbooks/vrml2sbk/ch31/31fig06.htm '/>
<meta name='translatorcontent='Don Brutzman'/>
<meta name='createdcontent='30 March 2001'/>
<meta name='modifiedcontent='11 January 2014'/>
<meta name='descriptioncontent='A donut (torus) node prototype. Also see Figures 30.5 and 31.7 for comparison.'/>
<meta name='identifiercontent=' http://www.web3d.org/x3d/content/examples/Vrml2Sourcebook/Chapter31-Prototypes/Figure31.6DonutPrototype.x3d '/>
<meta name='generatorcontent='X3D-Edit 3.3, https://savage.nps.edu/X3D-Edit'/>
<meta name='licensecontent=' ../../license.html'/>
</head>
<!--

Index for ProtoDeclare definition : Donut

Index for DEF nodes : DonutExtrusion, DonutMakerInternalScript
-->
<Scene>
<ProtoDeclare name='Donut'>
<ProtoInterface>
<field name='crossSectionRadiustype='SFFloatvalue='1accessType='initializeOnly'/>
<field name='spineRadiustype='SFFloatvalue='2accessType='initializeOnly'/>
<field name='crossSectionResolutiontype='SFInt32value='16accessType='initializeOnly'/>
<field name='spineResolutiontype='SFInt32value='16accessType='initializeOnly'/>
<field name='set_crossSectionRadiustype='SFFloataccessType='inputOnly'/>
<field name='set_spineRadiustype='SFFloataccessType='inputOnly'/>
</ProtoInterface>
<ProtoBody>
<!-- DonutExtrusion ROUTEs:  [from DonutMakerInternalScript.spine_changed to set_spine ] [from DonutMakerInternalScript.crossSection_changed to set_crossSection ] -->
<Extrusion DEF='DonutExtrusionbeginCap='falsecreaseAngle='1.57endCap='false'/>
<!-- Donut maker creates torus on initialization - external script. Modified script to add endpoints matching startpoints. -->
<!-- DonutMakerInternalScript ROUTEs:  [from spine_changed to DonutExtrusion.set_spine ] [from crossSection_changed to DonutExtrusion.set_crossSection ] -->
<Script DEF='DonutMakerInternalScript'>
<field name='crossSectionRadiustype='SFFloataccessType='initializeOnly'/>
<field name='spineRadiustype='SFFloataccessType='initializeOnly'/>
<field name='crossSectionResolutiontype='SFInt32accessType='initializeOnly'/>
<field name='spineResolutiontype='SFInt32accessType='initializeOnly'/>
<field name='set_crossSectionRadiustype='SFFloataccessType='inputOnly'/>
<field name='set_spineRadiustype='SFFloataccessType='inputOnly'/>
<field name='crossSection_changedtype='MFVec2faccessType='outputOnly'/>
<field name='spine_changedtype='MFVec3faccessType='outputOnly'/>
<IS>
<connect nodeField='crossSectionRadiusprotoField='crossSectionRadius'/>
<connect nodeField='spineRadiusprotoField='spineRadius'/>
<connect nodeField='crossSectionResolutionprotoField='crossSectionResolution'/>
<connect nodeField='spineResolutionprotoField='spineResolution'/>
<connect nodeField='set_crossSectionRadiusprotoField='set_crossSectionRadius'/>
<connect nodeField='set_spineRadiusprotoField='set_spineRadius'/>
</IS>
<![CDATA[
          
ecmascript:

function initialize( ) {
    generateCrossSection( );
    generateSpine( );
}

function set_crossSectionRadius( csr, ts )
{
    crossSectionRadius = csr;
//  Browser.print ('crossSectionRadius =' + crossSectionRadius);
    generateCrossSection( );
}

function set_spineRadius( sr, ts )
{
    spineRadius = sr;
//  Browser.print ('spineRadius =' + spineRadius);
    generateSpine( );
}

function generateCrossSection( )
{
    newCrossSection = new MFVec2f(); // temporary hold variable
    angle = 0.0;
    delta = 6.28 / crossSectionResolution;
    for ( i = 0; i <= crossSectionResolution + 1; i++ ) {
        newCrossSection[i][0] =  crossSectionRadius * Math.cos( angle );
        newCrossSection[i][1] = -crossSectionRadius * Math.sin( angle );
        angle += delta;
    }
    // make ends meet
    newCrossSection[crossSectionResolution + 1][0] = newCrossSection[0][0];
    newCrossSection[crossSectionResolution + 1][1] = newCrossSection[0][1];

    crossSection_changed = newCrossSection;
}

function generateSpine( )
{
    newSpine = new MFVec3f(); // temporary hold variable
    angle = 0.0;
    delta = (2 * 3.141592653) / spineResolution;
    for ( i = 0; i <= spineResolution; i++ ) {
        newSpine[i][0] = spineRadius * Math.cos( angle );
        newSpine[i][1] = 0.0;
        newSpine[i][2] = -spineRadius * Math.sin( angle );
        angle += delta;
    }
    // make ends meet
    newSpine[spineResolution + 1][0] = newSpine[0][0];
    newSpine[spineResolution + 1][1] = 0.0;
    newSpine[spineResolution + 1][2] = newSpine[0][2];

    spine_changed = newSpine;
}

        
]]>
</Script>
<ROUTE fromNode='DonutMakerInternalScriptfromField='spine_changedtoNode='DonutExtrusiontoField='set_spine'/>
<ROUTE fromNode='DonutMakerInternalScriptfromField='crossSection_changedtoNode='DonutExtrusiontoField='set_crossSection'/>
</ProtoBody>
</ProtoDeclare>
<!-- It is a good practice to include default message linking to an example scene, in case a user tries to view this Prototype library directly. -->
<Anchor description='Figure31.7DonutExternalPrototype exampleparameter='"target=_blank"'
  url=' "Figure31.7DonutExternalPrototype.x3d" "http://www.web3d.org/x3d/content/examples/Vrml2Sourcebook/Chapter31-Prototypes/Figure31.7DonutExternalPrototype.x3d" "Figure31.7DonutExternalPrototype.wrl" "http://www.web3d.org/x3d/content/examples/Vrml2Sourcebook/Chapter31-Prototypes/Figure31.7DonutExternalPrototype.wrl" '>
<Shape>
<Text string='"Figure31.6DonutPrototype" "contains a prototype definition" "" "Click on text to see a Donut in" "Figure31.7DonutExternalPrototype"'>
<FontStyle justify='"MIDDLE" "MIDDLE"size='0.8'/>
</Text>
<Appearance>
<Material diffuseColor='0 0.6 0.6'/>
</Appearance>
</Shape>
</Anchor>
</Scene>
</X3D>
<!--

Index for ProtoDeclare definition : Donut

Index for DEF nodes : DonutExtrusion, DonutMakerInternalScript
-->

<!-- Color key: <X3dNode DEF='idName' field='value'/> matches <XmlElement DEF='idName' attribute='value'/>     <Prototype name='ProtoName'> <field name='fieldName'/> </Prototype> -->

<!-- Additional help information about X3D scenes: X3D Resources, X3D Scene Authoring Hints and X3D Tooltips -->