This is Interesting: Free Magazines for Graphics designers and webmasters
Home > Archive > VRML > January 2004 > createVrmlFromString
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 |
createVrmlFromString
|
|
| Junaid 2004-01-25, 6:30 pm |
| Hi, In my recent post, I was advised to use the createVrmlFromString
function to make multiple copies of an atom(sphere). The problem I have is
that the VRML code which I use to create an atom involves a PROTO as below.
As far as I understand from what I've read on tutorials you cannot have
PROTOs in the createVrmlFromString function.
Component{
myRadius 0.1 0.1 0.1
myColor 1 1 0
}
My task is to make copies of this PROTO using some sort of Script rather
than copy and pasting the above code 50 or more times. I also have to keep
this Component PROTO because I have another PROTO called Environment which
stores all these atoms(PROTO Components) in a list and then uses a Script
written in java to access the radius and color.
I would be grateful if anyone could help. thnx.
| |
| Bill Angel 2004-01-25, 9:30 pm |
| Hi:
I prefer utilizing the Browser.createVRMLFromURL function to do
what you are suggesting. The following code shows how
to dynamically create a Node called NewObject from within
a Script utilizing the Browser.createVrmlFromURL function.
The code in the Script node then initializes some of the values
associated with the newly created Node. You will also note that
a dynamically created Node is being accessed in the function "objectAdded"
in Script Node OBJECT-SCRIPT as if it were stored in a list or in an array.
Here's the code:
Suppose the file "Object.wrl" contains the following code
#VRML V2.0 utf8
PROTO NewObject [
exposedField SFFloat transparency 0
exposedField SFBool initialized FALSE
]
{
Shape {
appearance Appearance {
material Material {
diffuseColor 0.58 0.79 1.00
shininess 0.5
transparency IS transparency
}
}
geometry Sphere {}
}
}
NewObject {}
#### End of file "Object.wrl" ###
##################################
The following code creates and adds an instance of the
node "NewObject" to the scene. The code then performs
some initializatiion to this newly created node.
#VRML V2.0 utf8
DEF OBJECT-GROUP Group {}
DEF OBJECT-SCRIPT Script {
field SFNode objectGroup USE OBJECT-GROUP
field MFString objectURL ["Object.wrl"]
eventIn MFNode objectAdded
directOutput TRUE
url [ "java script:
function initialize() {
Browser.createVrmlFromURL(objectURL,objectGroup,'addChildren');
}
function objectAdded(nodes) {
for (var i = 0; i < nodes.length; i++) {
if (nodes[i].getType() == 'NewObject' && nodes[i].initialized == false) {
print(' node ' + i + ' NOT initialized');
// Initialize the Node here
nodes[i].set_transparency = .5;
nodes[i].set_initialized = true;
break;
}
}
}
" ]
}
ROUTE OBJECT-GROUP.children_changed TO OBJECT-SCRIPT.objectAdded
##### End of initialization code ####
#####################################
Regards,
Bill Angel
Computer Scientist
Silver Spring, Maryland
"Junaid" <ug36jxh@cs.bham.ac.uk> wrote in message news:bv1dba$lud$1@soapbox.cs.bham.ac.uk...quote:
> Hi, In my recent post, I was advised to use the createVrmlFromString
> function to make multiple copies of an atom(sphere). The problem I have is
> that the VRML code which I use to create an atom involves a PROTO as below.
> As far as I understand from what I've read on tutorials you cannot have
> PROTOs in the createVrmlFromString function.
>
> Component{
> myRadius 0.1 0.1 0.1
> myColor 1 1 0
> }
> My task is to make copies of this PROTO using some sort of Script rather
> than copy and pasting the above code 50 or more times. I also have to keep
> this Component PROTO because I have another PROTO called Environment which
> stores all these atoms(PROTO Components) in a list and then uses a Script
> written in java to access the radius and color.
>
> I would be grateful if anyone could help. thnx.
>
>
| |
| Muaddib 2004-01-25, 9:30 pm |
| Junaid,
To create a protoed node using createVrmlFromString, you have to
include an EXTERNPROTO for it in the creation string. This might look
something like the following:
ProtoedNode.wrl:
PROTO ProtoedNode [
....
] { .... }
test.wrl:
..... Browser.createVrmlFromString(
" EXTERNPROTO ProtoedNode [ " +
" .... " +
" ] \"ProtoedNode.wrl\" " +
" ProtoedNode {} "
);
.....
--
-------------------------------------------------------
VRSpace - An open source, 3D, modular, cross-platform,
multi-user system with persistent shared objects.
Check out a demo at http://www.vrspace.org/demo.htm
-------------------------------------------------------
|
|
|
| | Copyright 2003 - 2008 forum4designers.com Software forum Computer Hardware reviews |
|