sheep_00.x3d source
<?xml version="1.0" encoding="UTF-8"?>
<X3D>
<Scene>
<Viewpoint position='0 30 75' orientation='-1 0 0 0.45' description='vp0'/>
<Viewpoint position='0 50 40' orientation='-1 0 0 1' description='vp1'/>
<Viewpoint position='0 25 20' orientation='-1 0 0 1' description='vp2'/>
<NavigationInfo headlight='FALSE'
type='
"EXAMINE"'
/>
<DirectionalLight direction='-1 -1 -1' ambientIntensity='0.8'/>
<Background
skyAngle='1.4 1.57 1.58'
skyColor='
0.3 0.3 1
0.4 0.4 1
0.6 0.6 1
0.2 0.8 0.2'
/>
<Transform translation='0 -0.05 0'>
<Shape>
<Appearance>
<Material diffuseColor='0.2 0.8 0.2'/>
<ImageTexture
url='
"green.png"'
/>
</Appearance>
<Box size='100 0.1 100'/>
</Shape>
<TouchSensor DEF='ThS'/>
</Transform>
<Group DEF='Sheeps-Gp'>
</Group>
<Script DEF='AddSheep-Sc' directOutput='TRUE'>
<field accessType='inputOnly' type='SFVec3f' name='set_hitPoint'/>
<field accessType='inputOnly' type='SFTime' name='touchTime'/>
<field accessType='inputOnly' type='MFNode' name='set_sheeps'/>
<field accessType='initializeOnly' type='SFNode' name='SheepsGp'>
<Group USE='Sheeps-Gp'/>
</field>
<field accessType='initializeOnly' type='MFString' name='sheepUrl' value='"proto_sheep_00.x3d"'/>
<field accessType='initializeOnly' type='SFVec3f' name='hitPoint' value='0 0 0'/>
<![CDATA[ecmascript:

function set_hitPoint (vec) {

hitPoint = vec;

}

function touchTime () {

Browser.createVrmlFromURL( sheepUrl, SheepsGp, 'addChildren' );

}

function set_sheeps (sp) {

// (1)
var id = sp.length - 1;
var packet = new MFFloat();

packet[0] = id;
packet[1] = hitPoint.x;
packet[2] = 0;
packet[3] = hitPoint.z;

sp[id].packet_in = packet;

// (2)
for ( var i = 0; i < id; i++ ) {

Browser.addRoute( sp[i], 'packet_out', sp[id], 'packet_in' );
Browser.addRoute( sp[id], 'packet_out', sp[i], 'packet_in' );

}

}
]]>
</Script>
<ROUTE fromNode='ThS' fromField='hitPoint_changed' toNode='AddSheep-Sc' toField='set_hitPoint'/>
<ROUTE fromNode='ThS' fromField='touchTime' toNode='AddSheep-Sc' toField='touchTime'/>
<ROUTE fromNode='Sheeps-Gp' fromField='children' toNode='AddSheep-Sc' toField='set_sheeps'/>
</Scene>
</X3D>