Submitted by Leonard Daly on
All nodes and fields are managed through a parsing table. The table can be created at run-time or loaded from a previously defined JSON structure, or both. It is necessary to define a node and its fields prior to any parsing of that node. Since parsing starts as soon as the document is fully loaded into the browser, it is best to put the necessary code in the HEAD portion of the HTML document.
There are methods supplied to handle inserting a node and its fields into the parsing table. This section deals with those methods. All of the methods are properties of the xseen.nodes object.
xseen.nodes._defineNode('Box', 'Geometry3D', 'geometry3D_Box') .addField('size', 'SFVec3f', '1 1 1') .addNode();
A new node is created with the _defineNode method. This method takes three arguments - node name, node component (defined later), and node action method. The node name is always converted to lower case prior to comparison with nodes in the HTML file. The node action method is described below. This method is called once per node. Subsequent calls with the same lower-case node name will overwrite the parsing table entry. The return from this method is the node parse data structure.
The addField method is called once per field of the node. This method has three arguments: field name, field type, and default value. It defines the parsing for each field. As with node names, field names are converted to lower case. The field type must be one of the existing field data types. The default value is the what is used if the attribute is not present or its value is not allowed in the specified field datatype. It must be the same datatype as the field. This method is part of the node object in xseen.nodes and can be called by chaining from _defineNode or capturing the return from _defineNode and separately calling this method.
Once all of the fields have been added, the addNode method is called> This method has no arguments and commits the node to the parsing table. If this method is not called, then no parsing entry is made for the node. This method is part of the node object in xseen.nodes and can be called by chaining from _defineNode or capturing the return from _defineNode and separately calling this method.
Node Action Method
This is a class of methods that perform the specific actions required by this node. Each node will be different in the actions required. The following methods must be defined
init (e,p)
Called when the opening tag of the specified node is encountered. e is the element from the DOM parser. p is the parent of e. This method must create the THREE object and save it as e._xseen.node. It may also save it under other names. There is no known case where a node creates more than one THREE object and ... usually accesses the field values and sets up the initial structure needed by this node.
fin (e,p)
Called when the closing tag of the specified node is encountered. e and p are as before. This method takes the data from child node(s) and finishes building the necessary data structures to render (or control) a part of the scene. The result is put into the p._xseen object. Since XSeen uses THREE.js for scene graph management, these are usually THREE objects. If the THREE object is complete, then it is added to the array p._xseen.children; otherwise, it may be placed with any non-conflicting hash in p._xseen.
- Log in to post comments