f



Getting values into running VRML from PHP

Hi ng, 

I've tried to find solution to interact with running VRML from PHP.
No success :-(

I saw here couple of questions about it but no clear answer or some unique
solution.
Could somebody provide an example?

What I want to do?
I have a VRML file which IS generated by PHP, and this wrl file shows stats
about page visits/visitors...
It is OK and when I reload it it will show new status for egg.

if there is 4 visitors, it will show 4 lines in front of cube.

But I want to have wrl running all the time, and with help of some timer to
fetch new status from PHP script and draw/create new line /object in
running wrl.

Could this be done?

I'm sorry for triviality of this problem to some, but I'm PHP coder with no
experience in Java/Javascript so much.

Thanks in advance:-)  
-- 
---------------------------
Sinisa Dukaric (GeeK)
---------------------------
0
Sinisa
11/9/2003 8:01:41 PM
comp.lang.vrml 1409 articles. 0 followers. natty2006 (372) is leader. Post Follow

3 Replies
324 Views

Similar Articles

[PageSpeed] 58


Sinisa Dukaric wrote:
> Hi ng, 
> 
> I've tried to find solution to interact with running VRML from PHP.
> No success :-(
> 
> I saw here couple of questions about it but no clear answer or some unique
> solution.
> Could somebody provide an example?
> 

Yes. :-)

http://www.hersto.de/VRML_Tools/ServerClock.html shows a
PHP Script that returns a VRML node that carries arbitrary
information (no visible geometry). The returned file
contains the current time on the server plus some given
offset as a VRML node. It looks like that:

PROTO TimeFromServer
[
     exposedField SFInt32  year   0
     exposedField SFInt32  month  0
     exposedField SFInt32  day    0
     exposedField SFInt32  hour   0
     exposedField SFInt32  min    0
     exposedField SFInt32  sec    0

     exposedField SFInt32  wday   0
     exposedField SFInt32  yday   0
     exposedField SFInt32  week   0

     exposedField SFInt32  monlen 0

     exposedField SFTime   now    0
     exposedField SFString str    ""
]
   {  WorldInfo { } }


TimeFromServer
{
     year   2003
     month  11
     day    9
     hour   20
     min    35
     sec    47

     wday   0
     yday   312
     week   45

     monlen 30

     now    1068410147
     str    "Sun,  9 Nov 2003 20:35:47 +0000"
}


The following is a VRML file (.wrl) that calls this PHP
script every 5 seconds and creates a pair of cylinders
each time. The length of the left cylinder is proportional
to the current second and the length of the right cylinder
is proportional to the minute.


#VRML V2.0 utf8


Viewpoint
{
     position     0 0 4.3
     fieldOfView  0.844
}

NavigationInfo
{
     type [ "EXAMINE" "ANY" ]
}



DEF Gr Group
{
}


DEF Timer TimeSensor
{
     loop TRUE
     cycleInterval 5
}



DEF Worker Script
{
     eventIn SFTime trigger

     field SFString cServerURL
       "http://www.hersto.de/VRML_Tools/ServerClock.php"

     field SFNode   Self USE Worker
     eventIn MFNode DataFromServer

     eventOut MFNode createdNodes

     field SFInt32 Counter 0


     url "vrmlscript:

     function trigger(now)
     {
         // calculate some parameter:
         var Offs= Math.floor(Math.random() * 3);

         // call the PHP script with the parameters.
         Browser.createVrmlFromURL(
             new MFString(cServerURL +'?Offset='+ Offs),
             Self,
             'DataFromServer'
             );
         // The second and third parameters specify which
         // node and field should receive the node that
         // the PHP script outputs.
     }


     function DataFromServer(n)
     {
         var NumOfReturnedNodes= n.length;
         if(NumOfReturnedNodes != 1)
     return;

         var A= n[0].sec;
         var B= n[0].min;

         print('B = '+ A);
         print('B = '+ B);

         CreateCylinders(A, B);
     }


     function CreateCylinders(A, B)
     {
         var Cyls= Browser.createVrmlFromString(
             CodeForACylinder +' '+ CodeForACylinder
             );
         // Cyls now contains an MFNode with two Transforms,
         // which each contains a Cylinder.


         // We now set the parameters for each.
         // Cylinder A is located at -1 0 z
         // and Cylinder B is located at 1 0 z
         // where z depends on a Counter value. This
         // places each pair of cylinders at a different
         // position.
         // The heights are proportional to the values A
         // and B.

         Counter++;

         Cyls[0].translation= new SFVec3f(-1.5, 0, -Counter * .7);
         Cyls[1].translation= new SFVec3f( 1.5, 0, -Counter * .7);

         Cyls[0].scale= new SFVec3f(.5, A / 20, .5);
         Cyls[1].scale= new SFVec3f(.5, B / 20, .5);


         // Now we set the color of the left cylinder to yellow,
         // and that of the right to blue.
         Cyls[0].children[0].appearance.material.diffuseColor=
             new SFColor(.5, .5, 0);
         Cyls[0].children[0].appearance.material.emissiveColor=
             new SFColor(.5, .5, 0);

         Cyls[1].children[0].appearance.material.diffuseColor=
             new SFColor(0, .25, .5);
         Cyls[1].children[0].appearance.material.emissiveColor=
             new SFColor(0, .25, .5);
         // Setting diffuseColor and emissiveColor each to half of
         // the actual color value creates a better appearance.
         // (faces don't turn to black if they are parallel to
         // the viewing direciton.)

         // Now send the nodes to a Group nodes.
         // Otherwise they will not be visible.
         createdNodes= Cyls;
     }

     "

     field SFString CodeForACylinder
     "
         Transform
         {
             children Shape
             {
                 appearance Appearance
                 {
                     material Material
                     {
                     }
                 }
                 geometry Cylinder
                 {
                 }
             }
         }
     "

}

ROUTE Timer.cycleTime TO Worker.trigger


ROUTE Worker.createdNodes TO Gr.addChildren
# If we send them to Gr.children instead,
# we replace the old nodes with the new
# nodes.


# end of file.


Herbert



-- 
_______________________________________________

Bitmanagement Software GmbH
http://www.bitmanagement.de

Herbert Stocker
Entwicklung/Engineering

Tel                       +49 (0) 176 22055690
Fax                       +49 (0) 8151  971709
E-Mail        herbert.stocker@bitmanagement.de
_______________________________________________

0
Herbert
11/9/2003 9:27:56 PM

Sinisa Dukaric wrote:
<snip>
> if there is 4 visitors, it will show 4 lines in front of cube.
> 
> But I want to have wrl running all the time, and with help of some timer to
> fetch new status from PHP script and draw/create new line /object in
> running wrl.
> 
> Could this be done?

Sure , you could use 
CreateVrmlFromUrl('http://your.com/yourStatus.php',YourNode,'addChildren')


This would place a call to your yourStatus.php and when (and if) it 
returned, the VRML browser would send an addChildren event to the
named node.


many times the function in the script section of your PROTO node
would look something like below.

function addChildren(v,t)
	{
	myUpdateHolder.remove_children=myUpdateHolder.children
	muUpdateHolder.add_children=v
	}


I've noticed if you forget to remove the children (even if there are 
none.) that eventually you'll start to feel a memory leak.













-- 
--=<> Dr. Clue (A.K.A. Ian A. Storms) <>=--
--=<[]>=- http://www.drclue.net
--=<[]>=- C++ JScript D/HTML CGI TCP/IP SQL VRML NSAPI MSAA
--=<[]>=- http://www.drclue.net/F1.cgi/HTML/HTML.html	(My HTML/CGI guide)
--=<[]>=- http://www.drclue.net/beta			(My XDHTML library)

0
Dr
11/9/2003 10:20:13 PM
Herbert Stocker wrote:

> 
> 
> Sinisa Dukaric wrote:

>> I saw here couple of questions about it but no clear answer or some
>> unique solution.
>> Could somebody provide an example?
>> 
> 
> Yes. :-)
> 
> http://www.hersto.de/VRML_Tools/ServerClock.html shows a
> PHP Script that returns a VRML node that carries arbitrary
> information (no visible geometry). The returned file
> contains the current time on the server plus some given
> offset as a VRML node. It looks like that:

Hi Herbert!

Well, it looks like there is a bug related to this kind of solution.
I'm getting error which I've connected with bug in Javascript, when string
is longer than one line, it bails with error like unterminated string.

So I'm still without solution :-/

But thanks anyway! :-)


-- 
---------------------------
Sinisa Dukaric (GeeK)
---------------------------
0
Sinisa
11/11/2003 7:19:54 PM
Reply: