This is Interesting: Free Magazines for Graphics designers and webmasters  


Home > Archive > VRML > January 2004 > Simple javaScript question





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Simple javaScript question
Junaid

2004-01-23, 5:34 pm

Hi,
My project involves placing a large number of atoms(spheres) inside a
container(simple box). I have a PROTO called Component which defines an atom
and a PROTO called Environment where I have script in java to make the atoms
move around and collide with other atoms.

I would be grateful if someone could answer this. The question I have is,
how can I use a script to do create a specific number of atoms. Below is an
extract from my code.

Transform {
children [
DEF Container Transform {
children [
Environment
{
componentList [ #this is an MFNode field in
my Environment PROTO
Component {myRadius 0.1 0.1 0.1
myColor 1 1 1}
Component {myRadius 0.1 0.1 0.1
myColor 1 1 1}
Component {myRadius 0.1 0.1 0.1
myColor 1 1 1}
Component {myRadius 0.1 0.1 0.1
myColor 1 1 1}
...
...
...#repeated lines which I want to
do in a Script
]
}

DEF Generate Script {
#How do I write this script to create N number of
Components
#and add them to the componentList in Environment.
}


#ROUTE Generate... TO Container...


Thnx.


Herbert Stocker

2004-01-24, 3:28 am



Junaid wrote:
quote:

> Hi,
> My project involves placing a large number of atoms(spheres) inside a
> container(simple box). I have a PROTO called Component which defines an atom
> and a PROTO called Environment where I have script in java to make the atoms
> move around and collide with other atoms.
>
> I would be grateful if someone could answer this. The question I have is,
> how can I use a script to do create a specific number of atoms. Below is an
> extract from my code.
>
> Transform {
> children [
> DEF Container Transform {
> children [
> Environment
> {
> componentList [ #this is an MFNode field in
> my Environment PROTO
> Component {myRadius 0.1 0.1 0.1
> myColor 1 1 1}
> Component {myRadius 0.1 0.1 0.1
> myColor 1 1 1}
> Component {myRadius 0.1 0.1 0.1
> myColor 1 1 1}
> Component {myRadius 0.1 0.1 0.1
> myColor 1 1 1}
> ...
> ...
> ...#repeated lines which I want to
> do in a Script
> ]
> }
>
> DEF Generate Script {
> #How do I write this script to create N number of
> Components
> #and add them to the componentList in Environment.
> }
>
>
> #ROUTE Generate... TO Container...
>
>
> Thnx.
>



To generate the atoms have a look at the function
Browser.createVrmlFromString(.) .
You find this at
http://www.web3d.org/resources/vrml_ref_manual/appc.htm

To add them to the scene, send them to the addChildren
or to the children field of a Group, Transform, etc node.

Herbert


--
Herbert Stocker (aka hersto)
http://www.hersto.de
www.bitmanagement.de

Sponsored Links


Copyright 2003 - 2008 forum4designers.com  Software forum  Computer Hardware reviews