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

roy.walmsley at gmail.com roy.walmsley at gmail.com
Thu Dec 16 11:12:03 PST 2021


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> 
Sent: 16 December 2021 18:36
To: roy.walmsley at gmail.com
Cc: X3D <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

 

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

_______________________________________________
x3d-public mailing list
 <mailto:x3d-public at web3d.org> x3d-public at web3d.org
 <http://web3d.org/mailman/listinfo/x3d-public_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/20211216/17e91b1a/attachment.html>


More information about the x3d-public mailing list