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

roy.walmsley at gmail.com roy.walmsley at gmail.com
Thu Dec 16 05:42:03 PST 2021


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

 

A.	Instantiate top level ProtoInstance
B.	Instantiate nested level ProtoInstance
C.	Call Script initialize function in nested level ProtoInstance
D.	Call Script initialize function in top level ProtoInstance
E.	Present Scene to browser.

 

Thank you in advance for your comments,

Roy

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://web3d.org/pipermail/x3d-public_web3d.org/attachments/20211216/66b02557/attachment.html>


More information about the x3d-public mailing list