Closed andreasplesch closed 8 years ago
Took a look of your demonstration and the user script looks good and very clear.
Indeed Object.dispose() is not yet implemented, there only exists a stub function.
To clear the value of a SFNode field just use SFNode.setValue (null), which removes a previously set node and handles parent referencing of the X3DBaseNode, and generates an event on the field (node.removeParent(parent) should only be used in SFNode class, the idea is to let the SFNode class do this complicated job, althought add/removeParent could be access from everywhere). Use SFNode.set(value) if you do not wish to generate an event but this should be a very rare case and should be avoided.
EDIT: The parent system is an internal handling of the objects which does not reflect the parents in the scene graph.
MFNode does not have a internal function MFNode.remove(node) but this would be the way to remove the node and update the MFNode, and this function could also be used for X3DScene.removeRootNode() as X3DScene.rootNodes is just a MFNode.
Implemented an internal function X3DArrayField.remove(firstIndex, lastIndex, value)
Example:
var n1 = Browser .currentScene .createNode ("Transform");
var n2 = Browser .currentScene .createNode ("Group");
var n3 = Browser .currentScene .createNode ("Switch");
var a = new MFNode (n1,n2,n3,n1,n1,n2,n3);
console .log (a .toString ());
a .erase (a .remove (0, a .length, n1), a .length);
console .log (a .toString ());
What are the specifications for X3DScene.add/removeRootNode?
For abstract SAI here: http://www.web3d.org/documents/specifications/19775-2/V3.3/Part02/servRef.html#t-rootNodeHandlingSAIActionValues
I could not find an equivalent function in the ecmascript spec.
A question for the x3d-public email list ?
I updated the cobweb_dom code to use setValue(null) . It works better. I need to clean up, as well.
Is there a way to find a parent in the scene graph without using getParents() ?
In cobweb_dom.js I use el.x3dnode to get the x3d node for a dom element. I had to add a line XMLParser.js in the node function at line 279 element.x3dnode = node
to create this property. I think this link is very useful. Would you consider adding such or similar code ? Is there another way to find the x3d node object just based on the corresponding dom element ?
Implemented X3DScene.add/removeRootNode(value : SFNode | null)
Modified XMLParser as suggested by you.
Implemented X3DBaseNode and X3DField .dispose.
To remove a node from the entire scene graph use:
function removeNodeFromeEntireSceneGraph (node)
{
if (! (node instanceof SFNode))
return;
var baseNode = node .getValue ();
if (! baseNode)
return;
baseNode .dispose ();
}
Thanks ! A similar reference from the dom element to the x3d object may also be useful for ProtoInstances. I think for ROUTE manipulation via the DOM SAI functions should be fine, so nothing else should be needed.
Would you prefer el.x3dNode
or el.X3DNode
rather than el.x3dnode
as a property name ? x3dnode was just what came to mind first.
I would like to remove a node from the scenegraph using the SAI. Does node.dispose() work ? Is there an example I could try ? The node to be removed can be any field of type SFNode. The field should revert then to its default value (usually NULL). If the removed node is part of an MFNode, then the MFNode needs to be updated first. My plan currently is to find the parent of the removed node or affected MFNode and then to use node.removeParent(parent). Then emit the changed event on the parent field which was populated by the removed node. scene.removeRootNode() does not seem to implemented ?
The idea is to be able to directly manipulate the DOM and automatically update the scenegraph without explicitly using the SAI:
https://andreasplesch.github.io/cobweb_dom/index.xhtml