[x3d-public] Nested prototypes with scripts execution ordering query

Brutzman, Donald (Don) (CIV) brutzman at nps.edu
Fri Dec 31 07:08:25 PST 2021


Thanks for implementation analysis of nested prototypes.  Historically this has always seemed sufficiently well defined but difficult to implement, especially with nested IS/connect of Script nodes.

Roy, for your A-B-C-D-E execution order below, am wondering if that is sufficient.  I'd expect internal initialization of default values for fields to essential take place as you suggest, but then expect another round of initialization (from outside to inside) when a ProtoInstance instantiation applies initial fieldValue settings that ripple inward via any defined IS/connect, and then Script initialize(), all occurring before "time 0" rendering and event-generating behaviors of the composed prototype block itself.

If your investigations reveal that further clarifying prose appears necessary in X3D4 Architecture to resolve potential ambiguities, please advise.  We will be able to consider final editorial improvements in the coming months as we transition editing of Committee Draft CD1 into final-draft review and final-specification approval by ISO national bodies.

  *   X3D4 Architecture, Clause 4 Concepts, 4.4.4 Prototype semantics
  *   https://www.web3d.org/specifications/X3Dv4Draft/ISO-IEC19775-1v4-CD1/Part01/concepts.html#PrototypeSemantics
As a reminder the X3D Validator includes a number of diagnostics for X3D prototypes, at least to the first level, that should confirm correctness of constructs below (at least when expressed in XML form).  Most Schematron rules for quality assurance (QA) should scalably recurse just fine when nested, but this has not been tested very much.

  *   X3D Validator
  *   https://savage.nps.edu/X3dValidator
The X3D Scene Authoring Hints and X3D Tooltips might also offer insight (or deserve improvement) as well.  These are not normative, but do try to complement the X3D4 Architecture specification with concise summaries and identification of good practices.  Each has evolved steadily through mailing-list discussion.  Suggested additions and issue reports are always welcome.

  *   X3D Scene Authoring Hints: Inlines and Prototypes, Scripts
  *   https://www.web3d.org/x3d/content/examples/X3dSceneAuthoringHints.html#Inlines
  *   https://www.web3d.org/x3d/content/examples/X3dSceneAuthoringHints.html#Scripts
  *
  *   X3D Tooltips: ProtoDeclare  ProtoInterface ProtoBody  ProtoInstance ExternProtoDeclare Script field fieldValue
  *   https://www.web3d.org/x3d/content/X3dTooltips.html
Prototypes are a big part of the extensibility X in X3D, and the signature achievement of most major computer languages is the ability to extend the language itself.  Efforts to confirm this X3D language capability are much appreciated.

Happy New Year everyone!  8)

all the best, Don
--
Don Brutzman  Naval Postgraduate School, Code USW/Br        brutzman at nps.edu
Watkins 270,  MOVES Institute, Monterey CA 93943-5000 USA    +1.831.656.2149
X3D graphics, virtual worlds, navy robotics https:// faculty.nps.edu/brutzman

From: x3d-public <x3d-public-bounces at web3d.org> On Behalf Of roy.walmsley at gmail.com
Sent: Thursday, December 16, 2021 11:12 AM
To: 'Holger Seelig' <holger.seelig at yahoo.de>
Cc: 'X3D' <x3d-public at web3d.org>
Subject: Re: [x3d-public] Nested prototypes with scripts execution ordering query

Thank you Holger. However, with respect, that does not answer the questions I posed.

I will indeed try along the lines you suggested - I did in fact try once and failed, but I probably made a mistake (as usual), and plan to try again.

Roy

From: Holger Seelig <holger.seelig at yahoo.de<mailto:holger.seelig at yahoo.de>>
Sent: 16 December 2021 18:36
To: roy.walmsley at gmail.com<mailto:roy.walmsley at gmail.com>
Cc: X3D <x3d-public at web3d.org<mailto:x3d-public at web3d.org>>
Subject: Re: [x3d-public] Nested prototypes with scripts execution ordering query

If you set a field in a Script node and want the proto to react on field changes the field must be an inputOutput field and in the  Script also, and then create a field handler with 'set_fieldName'.

Example:

PROTO Door [
                inputOutput SFVec2f doorSize 1 1
]
{
                Script {
                                inputOutput SFVec2f doorSize IS dooSize
                                url "
function set_doorSize (value, time)
{
                // handle change
}
"
                }
}

Holger

Am 16.12.2021 um 14:42 schrieb roy.walmsley at gmail.com<mailto:roy.walmsley at gmail.com>:

Hi,

I would like to clarify the order of execution to be expected with nested prototypes and scripts. To clarify, here is an example about a kitchen cabinet.

I have a top-level X3D file that has an EXTERNPROTO defined for a DoubleFloorCabinet. I have a field in the prototype definition (among others) named cabinetWidth that is used to pass the width of the cabinet. I create a ProtoInstance of DoubleFloorCabinet, and specify the desired width in the field cabinetWidth.

I have a second X3D file that contains the DoubleFloorCabinet prototype. This has a Script node, with a field cabinetWidth, with IS Connected to the prototype field cabinetWidth. The initialize function of this Script node calculates the required translations, rotations, sizes, etc., of all the Box nodes required to draw the cabinet at the desired width. This all works fine.

Now, I want my cabinet to have doors, which might have different appearances, hence doors are drawn with a separate prototype. So my DoubleFloorCabinet has an EXTERNPROTO defined for CabinetDoor. I then create prototype instances, as necessary, and the previously mentioned Script calculates the door sizes, and hinge locations, etc., as required for the size of cabinet requested. So the CabinetDoor prototype has a SFVec2f field for doorSize, which is set by the Script during its initialize function.

Finally, I have a third file CabinetDoor to draw a single door, which defines the CabinetDoor prototype. This draws a single door, at the requested size, and with the specified hinge location, etc.. All necessary calculations are currently carried out in the initialize function of this Script, and the appropriate transforms, extrusions, boxes, etc., are adjusted to draw the door as requested.

Does it work? The door will be drawn the correct size if there is only one level of prototyping involved. However, with nested prototypes it fails, simply drawing the door, in the right place, but only at the default size. I'm assuming this may be because of the order of execution of the initialize functions in the Scripts in the nested prototypes. So:


  1.  Is the execution order as follows? If not, what is it?
  2.  Is the ordering clearly specified in the standard?

EXECUTION ORDER


  1.  Instantiate top level ProtoInstance
  2.  Instantiate nested level ProtoInstance
  3.  Call Script initialize function in nested level ProtoInstance
  4.  Call Script initialize function in top level ProtoInstance
  5.  Present Scene to browser.

Thank you in advance for your comments,
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

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://web3d.org/pipermail/x3d-public_web3d.org/attachments/20211231/b928fe93/attachment-0001.html>


More information about the x3d-public mailing list