This is Interesting: Free Magazines for Graphics designers and webmasters
Home > Archive > VRML > January 2004 > Variables and PROTOs?
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 |
Variables and PROTOs?
|
|
|
| Here's my problem:
I'm making trail labels for a VRML ski map. To get the labels in the right
orientation, I use four rotations: the first puts the text into the VRML ZX
plane, i.e. horizontal; the second orients about the text plane Z-axis; the
third orients about the text plane Y-axis; the fourth orients about the text
plane X-axis. In this way, I maneuver the label first into the direction of
the trail, next along the slope of the trail, and finally along the tilt of
the trail. Like so,
Transform {
translation 1839 287 2144 rotation 1 0 0 -1.57
children [ Transform { rotation 0 0 1 0.95
children [ Transform { rotation 0 1 0 0.25
children [ Transform { rotation 1 0 0 0.15
children [ Shape { appearance USE Beginner
geometry Text { string [ "Mambo"] fontStyle USE TrailFont }
} ] } ] } ] } ]
}
So far so good, but what I want now is to make a PROTO that will pass these
last three rotations as floats instead of vectors, like this:
TrailLabel { name "Mambo" level Beginner moveTo 1839 287 2144 rx 0.15 ry
0.25 rz 0.95 }
But the problem seems to be that you can't do as I have done in the PROTO
below. Is there some way for me to pass just the float instead of the whole
rotation vector for each of the rotations?
PROTO TrailLabel [
field MFString name "name"
field SFNode level Appearance {}
field SFVec3f moveTo 0 0 0
field SFFloat rx 0
field SFFloat ry 0
field SFFloat rz 0
]
{
Transform {
translation IS moveTo rotation 1 0 0 -1.57
children [ Transform { rotation 0 0 1 rz
children [ Transform { rotation 0 1 0 ry
children [ Transform { rotation 1 0 0 rx
children [ Shape { appearance USE level
geometry Text { string USE name fontStyle USE TrailFont }
} ] } ] } ] } ]
}
}
| |
| Herbert Stocker 2004-01-06, 5:31 pm |
|
Dale wrote:quote:
> Here's my problem:
>
> I'm making trail labels for a VRML ski map. To get the labels in the right
> orientation, I use four rotations: the first puts the text into the VRML ZX
> plane, i.e. horizontal; the second orients about the text plane Z-axis; the
> third orients about the text plane Y-axis; the fourth orients about the text
> plane X-axis. In this way, I maneuver the label first into the direction of
> the trail, next along the slope of the trail, and finally along the tilt of
> the trail. Like so,
>
> Transform {
> translation 1839 287 2144 rotation 1 0 0 -1.57
> children [ Transform { rotation 0 0 1 0.95
> children [ Transform { rotation 0 1 0 0.25
> children [ Transform { rotation 1 0 0 0.15
> children [ Shape { appearance USE Beginner
> geometry Text { string [ "Mambo"] fontStyle USE TrailFont }
> } ] } ] } ] } ]
> }
>
> So far so good, but what I want now is to make a PROTO that will pass these
> last three rotations as floats instead of vectors, like this:
> TrailLabel { name "Mambo" level Beginner moveTo 1839 287 2144 rx 0.15 ry
> 0.25 rz 0.95 }
>
> But the problem seems to be that you can't do as I have done in the PROTO
> below. Is there some way for me to pass just the float instead of the whole
> rotation vector for each of the rotations?
>
BTW, in the following you should replace the word `USE´
with `IS´.
`USE´ is for reusing a node, and `IS´ is what connects
a field of a node with a field on the PROTO interface.
quote:
> PROTO TrailLabel [
> field MFString name "name"
> field SFNode level Appearance {}
> field SFVec3f moveTo 0 0 0
> field SFFloat rx 0
> field SFFloat ry 0
> field SFFloat rz 0
> ]
> {
> Transform {
> translation IS moveTo rotation 1 0 0 -1.57
> children [ Transform { rotation 0 0 1 rz
> children [ Transform { rotation 0 1 0 ry
> children [ Transform { rotation 1 0 0 rx
> children [ Shape { appearance USE level
> geometry Text { string USE name fontStyle USE TrailFont }
> } ] } ] } ] } ]
> }
> }
>
You need to add a Script node that receives the rx, ry, rz values,
does the type conversion from SFFloat to SFRotation and sends
them to the Transform node.
I think it should look something like this:
PROTO TrailLabel [
field MFString name "name"
field SFNode level Appearance {}
field SFVec3f moveTo 0 0 0
field SFFloat rx 0
field SFFloat ry 0
field SFFloat rz 0
]
{
Transform {
translation IS moveTo rotation 1 0 0 -1.57
children [ DEF TrZ Transform {
children [ DEF TrY Transform {
children [ DEF TrX Transform {
children [ Shape { appearance IS level
geometry Text { string IS name # fontStyle USE TrailFont
}
} ] } ] } ] } ]
}
DEF S Script
{
field SFFloat rX IS rx
field SFFloat rY IS ry
field SFFloat rZ IS rz
eventOut SFRotation rotX
eventOut SFRotation rotY
eventOut SFRotation rotZ
url "vrmlscript:
function initialize()
{
rotX= new SFRotation(1, 0, 0, rX);
rotY= new SFRotation(0, 1, 0, rY);
rotZ= new SFRotation(0, 0, 1, rZ);
}
"
}
ROUTE S.rotX TO TrX.rotation
ROUTE S.rotY TO TrY.rotation
ROUTE S.rotZ TO TrZ.rotation
}
Herbert
--
Herbert Stocker (aka hersto)
http://www.hersto.de
www.bitmanagement.de
| |
|
| "Herbert Stocker" <hst-uzd-nospam@hersto.de> wrote in message
news:3FFB2528.3080904@hersto.de...quote:
> Dale wrote:
[...][QUOTE][color=darkred]
> BTW, in the following you should replace the word `USE´
> with `IS´.
> `USE´ is for reusing a node, and `IS´ is what connects
> a field of a node with a field on the PROTO interface.
[...]quote:
>
> You need to add a Script node that receives the rx, ry, rz values,
> does the type conversion from SFFloat to SFRotation and sends
> them to the Transform node.
>
> I think it should look something like this:
[...snipped to conserve space...]
Schweet! Thanks a bunch Herbert. Here is the final working code. I changed
"level" to "skill" to avoid a reserved keyword, and changed my clumsy "rx,
ry, rz" to a 3-vector (Duh!). The result is much streamlined compared to
what I had before.
DEF Beginner Appearance { material Material { diffuseColor 0 0.4 0
emissiveColor 0 0.2 0 } }
DEF Intermediate Appearance { material Material { diffuseColor 0 0 0.7
emissiveColor 0 0 0.7 } }
DEF Expert Appearance { material Material { diffuseColor 0 0 0 emissiveColor
0.1 0.1 0.1 } }
PROTO TrailLabel [
field MFString name "name"
field SFNode skill Appearance {}
field SFVec3f moveTo 0 0 0
field SFVec3f orient 0 0 0
]
{
Transform {
translation IS moveTo rotation 1 0 0 -1.57
children [ DEF TrZ Transform {
children [ DEF TrY Transform {
children [ DEF TrX Transform {
children [ Shape { appearance IS skill
geometry Text { string IS name fontStyle FontStyle { family "SANS" style
"BOLD" size 30 }}
} ] } ] } ] } ]
}
DEF S Script {
field SFVec3f Orient IS orient
eventOut SFRotation rotX
eventOut SFRotation rotY
eventOut SFRotation rotZ
url "vrmlscript:
function initialize() {
rotX= new SFRotation(1, 0, 0, Orient[0]);
rotY= new SFRotation(0, 1, 0, Orient[1]);
rotZ= new SFRotation(0, 0, 1, Orient[2]);
}
"
}
ROUTE S.rotX TO TrX.rotation
ROUTE S.rotY TO TrY.rotation
ROUTE S.rotZ TO TrZ.rotation
}
TrailLabel { name "Mambo" skill USE Beginner moveTo 1839 287
2144 orient 0.15 0.25 0.95 }
TrailLabel { name "Tempest" skill USE Intermediate moveTo 1686 340
2317 orient 0.00 0.25 0.95 }
|
|
|
| | Copyright 2003 - 2008 forum4designers.com Software forum Computer Hardware reviews |
|