VRML中的动画由许多发送事件经过一系列的阶段组成,这些阶段主要有:触发阶段、逻辑处理阶段、计时阶段、引擎和目标阶段。
TimeSensor{
exposedField SFBool enabled TRUE
exposedField SFTime cycleInterval 1.0
exposedField SFTime startTime 0
exposedField SFTime stopTime 0
exposedField SFBool loop FALSE
eventOut SFBool isActive
eventOut SFTime time
eventOut SFTime cycleTime
eventOut SFFloat fraction_changed
}
enable用于设定时间传感器的使用状态。TRUE(打开)或FALSE(关闭)。
cycleInterval域的域值用于设定一个时间长度,从0.0到1.0时刻之间的周期间隔,单位为秒。该域值必须大于0.0,其默认值为
1.0秒。
loop域的域值用于设定时间传感器是否循环输出。如果该域值为TRUE,则从0.0到1.0这段时间间隔内输出浮点时刻,而在时间
间隔的结尾,返回到0.0,开始新的循环。如果该域值为FALSE,时间传感器不循环。
ColorInterpolator{
exposedField MFFloat key [ ]
exposedField MFColor keyValue [ ]
eventIn SFFloat set_fraction
eventOut SFColor value_changed
}
#VRML V2.0 utf8
Group{
children [
Shape {
appearance Appearance {
material DEF Bmeterial Material{
diffuseColor 1.0 0.0 0.0
}
}
geometry Cylinder {}
}
DEF Clock TimeSensor {
cycleInterval 3.0
loop TRUE
}
DEF Bcolorpath ColorInterpolator {
key [
0.0 0.33 0.67 1
]
keyValue [
1 0 0,0 1 0,0 0 1,1 0 0
]
}
]
}
ROUTE Clock.fraction_changed TO Bcolorpath.set_fraction
ROUTE Bcolorpath.value_changed TO Bmeterial.set_diffuseColor
CoordinateInerpoator{
exposedField MFFloat key [ ]
exposedField MFVec3f keyValue [ ]
eventIn SFFloat set_fraction
eventOut MFVec3f value_changed
}
keyValue域的域值提供了一张关键三维坐标的列表。每一个坐标都包含三个浮点数值,分别为此向量的X、Y、Z分量。KeyValue
域可提供两个或更多的关键坐标点,如果有N个时刻值和每个时刻值对应的M个关键坐标点,那么该域就包含了N×M个坐标
点。其默认值为一张空列表。
#VRML V2.0 utf8
Background {
skyColor[ 0.9 0.9 0.9 ]
}
Shape { #四棱锥体造型
geometry IndexedFaceSet{
coord DEF slz Coordinate { #定义四棱锥体坐标节点
point [
0 3 0,3 0 0,0 -3 0,-3 0 0,0 0 3
]
}
coordIndex [
0,3,4,-1
3,2,4,-1
2,1,4,-1
1,0,4,-1
0,1,2,3
]
colorPerVertex FALSE
color Color{
color [
1 0 0,0 1 0,1 1 0,0 0 1,1 1 1
]
}
}
}
DEF clock TimeSensor { #定义时间传感器节点
cycleInterval 8
loop TRUE
}
DEF path CoordinateInterpolator{ #定义坐标插补器节点
key [ #时间关键点
0 0.25 0.5 0.75 1
]
keyValue [ #坐标关键值
0 3 0,3 0 0,0 -3 0,-3 0 0,0 0 3
0 0 0,3 0 0,0 -3 0,-3 0 0,0 0 3
0 3 0,3 0 0,0 0 0,-3 0 0,0 0 3
0 3 0,3 0 0,0 -3 0,0 0 0,0 0 3
0 3 0,0 0 0,0 -3 0,-3 0 0,0 0 3
]
}
ROUTE clock.fraction_changed TO path.set_fraction
ROUTE path.value_changed TO slz.point
PositionInterpolator{
exposedField MFFloat key [ ]
exposedField MFVec3f keyValue [ ]
eventIn SFFloat set_fraction
eventOut SFVec3f value_changed
}
#VRML V2.0 utf8
Group{
children[
DEF Bsphere Transform{
children[
Shape{
appearance Appearance{
material Material{
diffuseColor 0.2 0.9 0.2
}
}
geometry Sphere{
radius 1.0
}
}
]
}
DEF Clock TimeSensor {
cycleInterval 5
loop TRUE
}
DEF BspherePath PositionInterpolator {
key[
0.0 0.2 0.4 0.6 0.8 1.0
]
keyValue [
0 0 -10,
5 0 -10,
5 5 -10,
-5 -5 -10,
-5 0 -10,
0 0 -10
]
}
]
}
ROUTE Clock.fraction_changed TO BspherePath.set_fraction
ROUTE BspherePath.value_changed TO Bsphere.set_translation
OrientationInterpolator{
exposedField MFFloat key [ ]
exposedField MFVec3f keyValue [ ]
eventIn SFFloat set_fraction
eventOut MFVec3f value_changed
}
#VRML V2.0 utf8
DEF bar1 Transform { #定义第一根棒坐标变换节点
children [
Shape{
appearance Appearance {
material DEF cbar1 Material {
diffuseColor 0.5 0.5 0.7
ambientIntensity 0.4
specularColor 0.8 0.8 0.9
shininess 0.2
}
}
geometry DEF C1 Cylinder {
height 5
radius 0.2
}
}
]
}
DEF bar2 Transform { #定义第二根棒坐标变换节点
children [
Shape {
appearance Appearance {
material DEF cbar2 Material {
diffuseColor 0.8 0.8 0.9
ambientIntensity 0.4
specularColor 0.8 0.8 0.9
shininess 0.2
}
}
geometry USE C1
}
]
}
DEF clock TimeSensor { #定义时间传感器节点
cycleInterval 9
loop TRUE
}
DEF path1 OrientationInterpolator { #定义第一根棒的朝向插补器
key [0 0.5 1] #时间关键点
keyValue [ #朝向关键值
0 0 1 0,
0 0 1 3.141,
0 0 1 6.281
]
}
DEF path2 OrientationInterpolator { #定义第二根棒的朝向插补器
key[0 0.5 1] #时间关键点
keyValue [ #朝向关键值
0 0 1 1.571,
0 0 1 4.712,
0 0 1 7.851
]
}
DEF cpath1 ColorInterpolator { #定义第一根棒的颜色插补器
key[0 0.5 1] #时间关键点
keyValue [ #颜色关键值
1 0 0,
0 1 0,
0 0 1
]
}
DEF cpath2 ColorInterpolator { #定义第二根棒的颜色插补器
key[0 0.5 1] #时间关键点
keyValue [ #颜色关键值
0.8 0.6 0.2,
0.6 0.4 0.9,
0.1 0.8 0.4
]
}
ROUTE clock.fraction_changed TO path1.set_fraction
ROUTE clock.fraction_changed TO path2.set_fraction
ROUTE clock.fraction_changed TO cpath1.set_fraction
ROUTE clock.fraction_changed TO cpath2.set_fraction
ROUTE path1.value_changed TO bar1.rotation
ROUTE path2.value_changed TO bar2.rotation
ROUTE cpath1.value_changed TO cbar1.diffuseColor
ROUTE cpath2.value_changed TO cbar2.diffuseColor
ScalarInterpolator{
exposedField MFFloat key [ ]
exposedField MFFloat keyValue [ ]
eventIn SFFloat set_fraction
eventOut SFFloat value_changed
}
#VRML V2.0 utf8
Group{
children[
Shape{
appearance Appearance{
material DEF Bboxmeterial Material {
diffuseColor 0 0 1
}
}
geometry Box {
size 2 2 2
}
}
Shape{
appearance Appearance{
material Material{
diffuseColor 1 1 0
}
}
geometry Sphere{
radius 0.5
}
}
DEF Clock TimeSensor {
cycleInterval 10
loop TRUE
},
DEF Btrancpath ScalarInterpolator {
key[ 0,0.5,1 ]
keyValue[ 0,1,0 ]
}
]
}
ROUTE Clock.fraction_changed TO Btrancpath.set_fraction
ROUTE Btrancpath.value_changed TO Bboxmeterial.set_transparency
NormalInterpolator{
exposedField MFFloat key [ ]
exposedField MFVec3f keyValue [ ]
eventIn SFFloat set_fraction
eventOut MFVec3f value_changed
}
#VRML V2.0 utf8
Group{
children[
Shape{
appearance Appearance {
material Material {
diffuseColor 1 1 0
}
}
geometry IndexedFaceSet{
coord Coordinate {
point[
-2 -2 0,2 -2 0,2 2 0,-2 2 0
]
}
coordIndex[ 0,1,2,3 ]
normal DEF Bnormal Normal {
vector[
1 0 0,0 0 1,0 0 1,0 0 1
]
}
normalIndex [ 0,1,2,3 ]
}
}
DEF Clock TimeSensor{
cycleInterval 1
loop TRUE
}
DEF Bpath NormalInterpolator {
key[0,0.4,0.8,1]
keyValue [
1 0 0,0 0 1,0 0 1,0 0 1
0 0 1,1 0 0,0 0 1,0 0 1
0 0 0,0 0 1,0 0 1,1 0 0
1 0 0,0 0 1,0 0 1,0 0 1
]
}
]
}
ROUTE Clock.fraction_changed TO Bpath.set_fraction
ROUTE Bpath.value_changed TO Bnormal.set_vector
PlaneSensor平面传感器
CylinderSensor圆柱体传感器
SphereSensor球体传感器
ProximitySensor接近传感器
VisibilitySensor可视传感器
Collision碰撞传感器
TouchSensor{
exposedField SFBool enabled TRUE
eventOut SFBool isOver
eventOut SFVec3f hitPoint_changed
eventOut SFVec3f hitNormal_changed
eventOut SFVec3f hitTexCoord_changed
eventOut SFBool isActive
eventOut SFTime touchTime
}
#VRML V2.0 utf8
Background {
skyColor [0.8 0.8 0.8]
}
DEF TRANS Transform{
children[
Shape{
appearance Appearance{
material Material{
diffuseColor 1 0 0
}
}
geometry Sphere {}
}
DEF Tou TouchSensor{}
]
}
DEF TS TimeSensor{
cycleInterval 5
}
DEF PI PositionInterpolator{
key[0 0.5 1]
keyValue[
0 0 0,
0 3 0,
0 0 0
]
}
ROUTE Tou.touchTime TO TS.startTime
ROUTE TS.fraction_changed TO PI.set_fraction
ROUTE PI.value_changed TO TRANS.translation
PlaneSensor{
exposedField SFBool enabled TRUE
exposedField SFVec3f offset 0 0 0
exposedField SFBool autoOffset TRUE
exposedField SFVec2f maxPosition -1 -1
exposedField SFVec2f minPosition 0 0
eventOut SFBool isActive
eventOut SFVect3 trackPoint_changed
eventOut SFVect3 translation_changed
}
#VRML V2.0 utf8
DEF box Transform {
children [
Shape {
appearance Appearance {
material Material {}
}
geometry Box {}
}
]
}
DEF sensor PlaneSensor {
offset 2 2 0 #设定造型的初始移动位置
maxPosition 4 3 #设定造型的最大移动位置
}
ROUTE sensor.translation_changed TO box.translation
CylinderSensor{
exposedField SFBool enabled TRUE
exposedField SFFloat offset 0
exposedField SFBool autoOffset TRUE
exposedField SFFloat maxAngle -1
exposedField SFFloat minAngle 0
exposedField SFFloat diskAngle 0.262
eventOut SFBool isActive
eventOut SFVec3f trackPoint_changed
eventOut SFRotation rotation_changed
}
#VRML V2.0 utf8
Group {
children [
DEF Btransbox Transform {
rotation 0.0 1.0 0.0 0.785
children[
Shape {
appearance Appearance {
material Material {
diffuseColor 1.0 0.0 0.6
}
}
geometry Box {
size 2.0 2.0 2.0
}
}
]
}
DEF Bsensor CylinderSensor {
offset 0.785
autoOffset TRUE
maxAngle 1.0
minAngle 0.0
}
]
}
ROUTE Bsensor.rotation_changed TO Btransbox.set_rotation
SphereSensor{
exposedField SFBool enabled TRUE
exposedField SFRotation offset 0 1 0 0
exposedField SFBool autoOffset TRUE
eventOut trackPoint_changed
eventOut rotation_changed
}
#VRML V2.0 utf8
Group {
children [
DEF BtransSphere Transform {
children[
Shape {
appearance Appearance {
material Material {
diffuseColor 0.0 0.6 0.6
}
}
geometry Cone {
bottomRadius 1.0
height 5.0
}
}
]
}
DEF Bsensor SphereSensor {}
]
}
ROUTE Bsensor.rotation_changed TO BtransSphere.set_rotation
VisibilitySensor{
exposedField SFBool enabled TRUE
exposedField SFVec3f center 0.0 0.0 0.0
exposedField SFVec3f size 0.0 0.0 0.0
eventOut SFBool isActive
eventOut SFTime enterTime
eventOut SFTime exitTime
}
#VRML V2.0 utf8
Background {
skyColor[ 0 0.6 0.8]
}
DEF rot Transform {
children [
Shape {
appearance Appearance {
material Material {
diffuseColor 1 1 1
}
}
geometry Box {size 2 2 2}
}
]
}
Transform {
translation 0 5 0
children [
Shape {
appearance Appearance {
material Material {
diffuseColor 1 0 1
}
}
geometry Sphere{radius 0.3}
}
]
}
DEF sensor VisibilitySensor {
center 0 5 0
size 0.6 0.6 0.6
}
DEF clock TimeSensor{
cycleInterval 5
}
DEF path OrientationInterpolator {
key [0 0.5 1]
keyValue [
1 1 0 0
1 1 0 3.141
1 1 0 6.281
]
}
ROUTE sensor.enterTime TO clock.startTime
ROUTE sensor.isActive TO clock.loop
ROUTE sensor.exitTime TO clock.stopTime
ROUTE clock.fraction_changed TO path.set_fraction
ROUTE path.value_changed TO rot.rotation
ProximitySensor{
exposedField SFBool enabled TRUE
exposedField SFVec3f center 0 0 0
exposedField SFVec3f size 0 0 0
eventOut SFBool isActive
eventOut SFVec3f position_changed
eventOut SFRotation orientation_changed
eventOut SFTime enterTime
eventOut SFTime exitTime
}
#VRML V2.0 utf8
Background {
skyColor [0.6 0.2 1]
}
Group {
children [
DEF ball Transform { #设置小球位置和形状
translation 0 0 -3
children [
Shape {
appearance Appearance {
material Material {
diffuseColor 1 1 0
}
}
geometry Sphere{radius 1}
}
]
}
DEF prox ProximitySensor {
size 2 2 2
}
DEF clock TimeSensor{
cycleInterval 4
}
DEF path PositionInterpolator {
key[0 0.2 0.4 0.6 0.8 1]
keyValue [0 0 0,
0 0 -30,
5 0 -10,
-5 0 -10,
0 0 -30,
0 0 -10
]
}
]
}
ROUTE prox.enterTime TO clock.startTime
ROUTE clock.fraction_changed TO path.set_fraction
ROUTE path.value_changed TO ball.translation
Collision{
exposedfield MFNode children [ ]
exposedfield SFBool collide TRUE
field SFNode proxy NULL
field SFVec3f bboxCenter 0.0 0.0 0.0
field SFVec3f bboxSize -1.0 1.01.0
eventIn MFNode addChildren
eventOut MFNode reomveChildren
eventOut SFTime collideTime
}
#VRML V2.0 utf8
Group {
children [
DEF Bcollision Collision {
children [
DEF LeftDoor Transform {
children[
Transform {
translation -0.75 0.0 0.0
children[
DEF Door Shape {
appearance Appearance {
material Material {
diffuseColor 0.30 0.11 0.00
specularColor 0.70 0.33 0.00
shininess 0.10
ambientIntensity 0.30
}
}
geometry Box {
size 1.5 3.0 0.2
}
}
]
}
]
}
DEF RightDoor Transform {
children[
Transform {
translation 0.75 0.0 0.0
children[ USE Door ]
}
]
}
]
}
DEF Clock TimeSensor {
cycleInterval 5.0
}
DEF LeftOpen PositionInterpolator {
key [
0.0,0.1,0.9,1.0
]
keyValue [
0.0 0.0 -13.0,
1.3 0.0 -13.0,
-1.3 0.0 -13.0,
0.0 0.0 -13.0
]
}
DEF RightOpen PositionInterpolator {
key [
0.0,0.1,0.9,1.0
]
keyValue [
0.0 0.0 -13.0,
1.3 0.0 -13.0,
1.3 0.0 -13.0,
0.0 0.0 -13.0
]
}
]
}
ROUTE Bcollision.collideTime TO Clock.set_startTime
ROUTE Clock.fraction_changed TO LeftOpen.set_fraction
ROUTE Clock.fraction_changed TO RightOpen.set_fraction
ROUTE LeftOpen.value_changed TO LeftDoor.set_translation
ROUTE RightOpen.value_changed TO RightDoor.set_translation