[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[x3d-public] Dynamically create TouchSensor



With Xj3D M10, is it possible to dynamically create a TouchSensor node with a createNode call? The code I wrote to try that does not work:
 
- the TouchSensor does not generate any events, i.e. the readableFieldChanged method is never called...
- the cursor does not change to a hand when over the Sphere...
 
However the message "Warning: does not update released mouse correctly for TouchSensors. Must fix" does appear on System.out when the sphere is clicked, so I guess the TouchSensor node is getting mouse input. The code follows (suppose an X3DComponent has been created and the browser added to some frame):
 
X3DScene scene = x3dComponent.getBrowser().createScene(
    x3dComponent.getBrowser().getProfile("Interactive"),
    null
);
x3dComponent.getBrowser().replaceWorld(scene);
X3DNode transform = scene.createNode("Transform");
X3DNode shape = scene.createNode("Shape");
X3DNode sphere = scene.createNode("Sphere");
X3DNode touchSensor = scene.createNode("TouchSensor");
 
SFNode geometry = (SFNode) shape.getField("geometry");
geometry.setValue(sphere);
 
MFNode children = (MFNode) transform.getField("children");
children.setValue(2, new X3DNode[] {shape, touchSensor});
 
SFTime touchTime = (SFTime) touchSensor.getField("touchTime");
touchTime.addX3DEventListener(new X3DFieldEventListener() {
    public void readableFieldChanged(X3DFieldEvent e) {
        System.out.println("TouchSensor touchTime changed");
    }
});
 
scene.addRootNode(transform);
George