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

Holger Seelig holger.seelig at yahoo.de
Thu Dec 16 10:36:08 PST 2021


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:
> 
> 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:
>  
> Is the execution order as follows? If not, what is it?
> Is the ordering clearly specified in the standard?
>  
> EXECUTION ORDER
>  
> Instantiate top level ProtoInstance
> Instantiate nested level ProtoInstance
> Call Script initialize function in nested level ProtoInstance
> Call Script initialize function in top level ProtoInstance
> 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 <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/8d43f0e9/attachment-0001.html>


More information about the x3d-public mailing list