[x3d-public] TouchSensor disabling/enabling
Holger Seelig
holger.seelig at yahoo.de
Fri Dec 3 03:26:29 PST 2021
I can answer both questions with YES! Both have to work! I created a simple test case according to your description, but doesn’t found the error. I could imagine that you have a typo elsewhere, or there is no IS connection between the hinge field, with further insight I cannot say more. Here is the test case:
<?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='Full' version='3.3' xmlns:xsd='http://www.w3.org/2001/XMLSchema-instance' xsd:noNamespaceSchemaLocation='http://www.web3d.org/specifications/x3d-3.3.xsd'>
<head>
<meta name='comment' content='World of Sunrise X3D Editor'/>
<meta name='created' content='Fri, 3 Dec 2021 12:04:42 +0100'/>
<meta name='creator' content='Holger Seelig'/>
<meta name='generator' content='Sunrise X3D Editor V1.0, https://create3000.github.io/Sunrise/'/>
<meta name='identifier' content='file:///Volumes/Home/Projekte/X_ITE/x_ite/src/tests/touch.x3d'/>
<meta name='modified' content='Fri, 3 Dec 2021 12:18:25 +0100'/>
</head>
<Scene>
<ProtoDeclare name='Touch'>
<ProtoInterface>
<field accessType='initializeOnly' type='SFInt32' name='hinge'/>
</ProtoInterface>
<ProtoBody>
<Group>
<Shape>
<Appearance>
<Material/>
</Appearance>
<Box/>
</Shape>
<TouchSensor DEF='_1'/>
</Group>
<Script DEF='TouchScript'
directOutput='true'>
<field accessType='inputOnly' type='SFTime' name='set_time'/>
<field accessType='initializeOnly' type='SFInt32' name='hinge'/>
<field accessType='initializeOnly' type='SFNode' name='touch'>
<TouchSensor USE='_1' containerField='touch'/>
</field>
<IS>
<connect nodeField='hinge' protoField='hinge'/>
</IS>
<![CDATA[ecmascript:
function initialize ()
{
touch .enabled = hinge;
}
function set_time (value, time)
{
print (time);
}]]>
</Script>
<ROUTE fromNode='_1' fromField='touchTime' toNode='TouchScript' toField='set_time'/>
</ProtoBody>
</ProtoDeclare>
<ProtoInstance name='Touch'/>
</Scene>
</X3D>
Best regards,
Holger
> Am 03.12.2021 um 11:52 schrieb <roy.walmsley at gmail.com> <roy.walmsley at gmail.com>:
>
> Hi,
>
> I have a Cupboard door prototype (EXTERN type) that has a TouchSensor node, and Script nodes. I pass a field into the prototype a field to indicate where, if at all, the door should hinge. A simple integer, 0 = no hinge, 1 = left hinge, etc. I want to disable the TouchSensor when no hinge is specified.
>
> I already have a Script, with ‘directOutput’ set to true, that has an initialize() function to set up other nodes for drawing, based on passed in field data. So, I thought, why not add a simple check to this function, and set the ‘enabled’ field of the TouchSensor appropriately. So I created a Node field in the Script, and set the value to be a TouchSensor node, that USEd the actual TouchSensor node. Then I set the ‘enabled’ field appropriately in the initialize() function. This did not work. The TouchSensor remains in the enabled state set in the node itself. I then tried a second option, creating an outputOnly SFBool variable in the Script, setting that in the initialise() function, and then ROUTEing that to the ‘enabled’ field of the TouchSensor. Still doesn’t work.
>
> So, I have two questions:
>
> Can a TouchSensor be enabled/disabled simply by a ‘directOutput’ from a Script, particularly in an initialise() function? Or does it need an actual event to change it?
> Do Script ‘outputOnly’ fields generate events when they are set in an initialize() function?
>
> Note I using X_ITE as a viewer. I’ve tried using X3D_Edit, but the Xj3D fails miserably on a number of counts.
>
> Thank you in advance,
> Roy
> _______________________________________________
> x3d-public mailing list
> x3d-public at web3d.org <mailto:x3d-public at web3d.org>
> http://web3d.org/mailman/listinfo/x3d-public_web3d.org <http://web3d.org/mailman/listinfo/x3d-public_web3d.org>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://web3d.org/pipermail/x3d-public_web3d.org/attachments/20211203/4ac56d1f/attachment-0002.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: touch.x3d
Type: application/octet-stream
Size: 1957 bytes
Desc: not available
URL: <http://web3d.org/pipermail/x3d-public_web3d.org/attachments/20211203/4ac56d1f/attachment-0001.obj>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://web3d.org/pipermail/x3d-public_web3d.org/attachments/20211203/4ac56d1f/attachment-0003.html>
More information about the x3d-public
mailing list