castle-engine / castle-model-viewer

Viewer for many 3D and 2D model formats: glTF, X3D, VRML, Collada, 3DS, MD3, Wavefront OBJ, STL, Spine JSON, sprite sheets in Cocos2D and Starling XML formats

Home Page:https://castle-engine.io/castle-model-viewer

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

KeySensor enabled field is [in out] exposedField

brutzman opened this issue · comments

KeySensor enabled field is [in out] exposedField and can be routed SFBool values.

Example:

C:\x3d-code\www.web3d.org\x3d\content\examples\ConformanceNist/Sensors/Keyboard/KeySensorActivationKeySwitchTest.x3d processing with X3dToX3dvClassicVrmlEncoding stylesheet
ClassicVRML validation: tovrmlx3d.exe Sensors/Keyboard/KeySensorActivationKeySwitchTest.x3dv --validate --enable-downloads
tovrmlx3d: Warning: X3D: Route destination specifies field "enabled" (for node "SingleKeySensor"), but this is not an exposed field (cannot generate/receive events)

p.s. tovrmlx3d.exe continues to provide great value, providing many edge-case tests for X3dToVrml97.xslt conversion stylesheet. Thanks!

The KeySensor.enabled is already exposedField ([in,out] in X3D terms) in CGE/view3dscene. You can confirm it by checking e.g. this file

#X3D V3.0 utf8
PROFILE Immersive

DEF K KeySensor { }
DEF L PointLight { }
ROUTE L.on TO K.enabled

The problem in https://www.web3d.org/x3d/content/examples/ConformanceNist/Sensors/Keyboard/KeySensorActivationKeySwitchTestIndex.html testcase is that it defines a prototype called KeySensor (thus obscuring internal implementation) and that prototype starts with

PROTO KeySensor [
  # warning: enabled needs to become an exposedField once Scripts support exposedField
  initializeOnly SFBool	 enabled TRUE
  inputOnly      SFBool	 set_enabled
  outputOnly     SFBool	 enabled_changed
  outputOnly     SFBool	 isActive
  outputOnly     SFInt32	 keyPress
  outputOnly     SFInt32	 keyRelease
  outputOnly     SFInt32	 actionKeyPress
  outputOnly     SFInt32	 actionKeyRelease
  outputOnly     SFBool	 altKey
  outputOnly     SFBool	 controlKey
  outputOnly     SFBool	 shiftKey
] {

As you see, the author of it even mentioned this problem at start, by that "warning:" comment.

The prototype isn't very useful -- it doesn't actually implement the node using JavaScript.

For X3D, that has KeySensor built-in, just remove this prototype. It only makes sense in VRML 2.0 (97).

  • It is contrary to intentions (declares enabled as initializeOnly),
  • it doesn't really do anything (it doesn't actually implement node using JavaScript),
  • it is not necessary since X3D >= 3.0 just has this node in spec.