[CESCG logo] Local Navigation Systems

Stepán Kment

xkment@cslab.felk.cvut.cz
Computer Graphics Group
Czech Technical University
Prague, Czech Republic
[CESCG logo]

HTML pages and connection to VRML

Example: VRML in frames

We discussed animation, interactivity, graphics and so on. But I still have not mentioned user interface, text information and binding the models together.
From Netscape Navigator 2, there exists possibility of splitting the browser's window into more areas called frames. Each frame can be named and using this name we can later adress it, for instance it is possible to change content of one frame by clicking on a link or button in a different one. That means that main menu or additional text information can be visible even when WRL world or some animation is displayed in the second frame.
Also, there is a programming environment, JavaScript, available. One can do lots of useful things with it (I've developed interactive game with it) and because many functions and properties of the browser are exposed to the script, one can simply do things like changing   content in two frames per one mouse click, it is possible to put timers and even build simple multithreading (one task per one frame).
All the communication with the browser is done via special dynamic structure (please consult books about scripting for more information), I now mention only the script for reloading the frame:

First, create a frameset, name the frames and load the files there (shortened)

<frameset frameborder="0" framespacing="0" border="0" rows="240,*">
<frame src="fel.wrl" name="VRML" scrolling="no" noresize marginwidth="0" marginheight="0" border="0">
<frame src="text.htm" name="TEXT" marginwidth="10" marginheight="10" border="0">
</frameset>

Here we have created two frames with names VRML and TEXT. Now we can load content to the VRML frame from TEXT frame using this script:

<script language="javascript">
function loadframe(data)
{parent.VRML.location.href=data;}
</script>
<a href="javascript:loadframe('asdf.htm')">Click to reload</a>

I believe this code is quite self-explanating with exception of line parent.VRML.location.href - this is a variable created by browser in its dynamic control structure and defines URL of frame called VRML (of course, there exists also structure for TEXT). We can simply use this technique for loading the VRML scene and contents of its paths in one step.

Bad news is that VRML players do not attach themselves to this structure, that is currently under development I was told. That means that you can do amazing things in frames with html contents, but you can not do so simple things such as starting any animation in VRML scene! The user still has to click once for reload of the frames and second time to start the animation in the VRML scene. Communication can be estabilished only in the opposite direction, that means from VRML to HTML, using this trick: create one frame in the frameset 0 pixels wide (that really works, the frame is then completely invisible; suppose it is called DUMMY). Create HTML documents with this content (shortened; create one document per one message, they probably should differ in the code of function sendmessage() ). Let us call this HTML document as mess.htm.

<body onload="sendmessage()" language="javascript">
<script language="javascript">
function sendmessage()
{parent.TEXT.ping('HALLO');}
</script>
</body>

Add this line to the script in VRML, from where you want to send a message. The browser loads a specified document in a specified frame (this can be also used for loading next part of the VRML scene using sensors):

Browser.loadURL (new MFString(mess.htm'), new MFString('target=DUMMY'));

It is complicated, but it should work fine: loadURL makes the browser reload content of invisible frame and document newly loaded calls function "ping" with parameter HALLO somewhere in the script of document loaded in TEXT frame. Anyway, it is slow and lots of documents are needed for this communication.

Example: VRML in frames

Index | Previous Topic | Next topic