虚拟现实技术43VRML篇基本造型.docx
《虚拟现实技术43VRML篇基本造型.docx》由会员分享,可在线阅读,更多相关《虚拟现实技术43VRML篇基本造型.docx(27页珍藏版)》请在冰豆网上搜索。
虚拟现实技术43VRML篇基本造型
第三部分虚拟现实技术--VRML篇
3VRML基本语法及应用
3.1VRML造型
VRML造型主要通过几何节点和几何属性节点来实现。
由于这些节点属于辅助节点,不能直接放进场景图,因此要实现VRML造型还需要一个Shape节点。
几何节点是通过Shape节点的geometry域来包含的,几何属性节点是通过Shape节点的appearance域来包含的。
用于造型的节点:
共22个
形状(Shape)节点1个
几何节点10个:
Box(长方体)、Cone(圆锥)、Cylinder(圆柱)、ElevationGrid(标高格阵)、Extrusion(挤出面)、IndexedFaceSet(索引面集)、IndexedLineSet(索引线集)、PointSet(点集)、Sphere(球面)、Text(文本)
几何属性节点10个:
Appearance(外观、Color(颜色)、Coordinate(坐标)、ImageTexture(图像纹理)、Material(材质)、MovieTexture(影像纹理)、Normal(法线)、PixelTexture(像素纹理)、TextureCoordinate(纹理坐标)、TextureTransform(纹理变换)
字型(Fontstyle)节点:
1个
3.1.1基本造型
由Shape节点、Appearance节点、Material节点和基本几何节点共同实现。
3.1.1.1Shape节点
Shape节点语法:
Shape{
exposedfieldSFNodeappearanceNULL
exposedfieldSFNodegeometryNULL
}
Appearance节点语法:
Appearance{
exposedfieldSFNodematerialNULL
exposedfieldSFNodetextureNULL
exposedfieldSFNodetextureTransformNULL
}
Material节点语法:
Material{
exposedfieldSFColordiffuseColor0.80.80.8
exposedfieldSFColorambientIntensify0.2
exposedfieldSFColorspecularColor000
exposedfieldSFColoremissiveColor000
exposedfieldSFFloatshininess0.2
exposedfieldSFFloattransparency0
}
3.1.1.2.基本的几何造型节点
基本的VRML造型节点有Box,Cylinder,Cone,Sphere节点。
Box节点语法:
Box{fieldSFVec3fsize222#(0,∞)
}
例3-1-1:
#创建一个长宽高分别为4.0,1.0,4.0个vrml单位的长方体
#VRMLV2.0utf8
Shape{
appearanceAppearance{
materialMaterial{}
}
geometryBox{
size4.01.04.0
}
}
Cylinder节点语法:
Cylinder{
fieldSFBoolbottomTRUE
fieldSFFloatheight2#(0,∞)
fieldSFFloatradius1#(0,∞)
fieldSFBoolsideTRUE
fieldSFBooltopTRUE
}
例2:
#创建一个底面半径为4.0高为1.0只有底面的圆柱体
#VRMLV2.0utf8
Shape{
appearanceAppearance{
materialMaterial{}
}
geometryCylinder{
radius4.0
height1.0
topFALSE
sideFALSE
}
}
Cone节点语法:
Cone{
fieldSFFloatbottomRadius1#(0,∞)
fieldSFFloatheight2#(0,∞)
fieldSFBoolsideTRUE
fieldSFBoolbottomTRUE
}
例:
#创建一个底面半径为2.0单位高为1.0单位的圆锥
#VRMLV2.0utf8
Shape{
appearanceAppearance{
materialMaterial{}
}
geometryCone{
bottomRadius2.0
height1.0
}
}
Sphere节点语法:
Sphere{
fieldSFFloatradius1.0#(0,∞)
}
3.1.1.3节点的编组
通过Group节点将不同的VRML节点组织在一起创建复杂的造型。
Group{
eventInMFNodeaddChildren
eventInMFNoderemoveChildren
exposedFieldMFNodechildren[]
fieldSFVec3fbboxCenter000#(-∞,∞)
fieldSFVec3fbboxSize-1-1-1#(0,∞)or-1,-1,-1
}
例:
航空塔模型
以sphere、box、cylinder、cone为节点创建一个航空塔的三维模型,其中用DEF定义了一个名字为bwhite的appearance的节点。
#VRMLV2.0utf8
Group{
children[
Shape{
appearanceDEFBwhiteAppearance{
materialMaterial{}
}
geometrySphere{
radius0.75
}
},
Shape{
appearanceUSEBwhite
geometryBox{
size1.80.011.8
}
},
Shape{
appearanceUSEBwhite
geometryCylinder{
radius0.9
height0.02
}
},
Shape{
appearanceUSEBwhite
geometryCone{
bottomRadius0.9
height4.0
}
}
]
}
3.1.2文本造型
3.1.2.1文本节点
Text{
exposedfieldMFStringstring[]
exposedfieldSFNodefontStyleNULL
exposedfieldSFFloatmaxExtent0.0
exposedfieldMFFloatlength[]
}
例:
使用缺省值创建内容分别为“VRMLWorld”“54321”的多行文本造型
#VRMLV2.0utf8
Shape{
appearanceAppearance{materialMaterial{}}
geometryText{
string["VRMLWorld","54321"]
}
}
例:
#创建一个指定长度为4.0单位,内容为“VRML”的单行文本造型
#VRMLV2.0utf8
Shape{
appearanceAppearance{
materialMaterial{}
}
geometryText{
string"VRML"
length4.0
}
}
例:
#创建一个第一行文本长度为自然长度,第二行为1.0单位的内容都为“VEML”的文本造型
#VRMLV2.0utf8
Shape{
appearanceAppearance{
materialMaterial{}
}
geometryText{
string["VRML","VRML"]
length[0.0,1.0]
}
}
例:
#创建指定了最大长度为4.0单位的多行文本造型,其中第二行压缩至长度为4.0单位
#VRMLV2.0utf8
Shape{
appearanceAppearance{
materialMaterial{}
}
geometryText{
string["VRML","VRMLWorld"]
maxExtent4.0
}
}
例:
#虽指定最大长度为1.0,但文本仍以长度分别为4.0,2.0单位来创建文本造型
#VRMLV2.0utf8
Shape{
appearanceAppearance{
materialMaterial{}
}
geometryText{
string["VRML","VRML"]
length[4.0,2.0]
maxExtent1.0
}
}
3.1.2.2字型节点
FontStyle{
fieldMFStringfamily“SERIF”
fieldSFBoolhorizontalTRUE
fieldMFStringjustify“BEGIN”
fieldSFStringlanguage“”
fieldSFBoolleftToRightTRUE
fieldSFFloatsize1.0#(0,∞)
fieldSFFloatspacing1.0#[0,∞)
fieldSFStringstyle“PLAIN”
fieldSFBooltopToBottomTRUE
}
例:
#创建内容为“VRMLWorld”,字体为Serif的单行文本造型
#VRMLV2.0utf8
Shape{
appearanceAppearance{
materialMaterial{}
}
geometryText{
string"VRML"
fontStyleFontStyle{
family"SERIF"
}
}
}
例:
#创建内容为“VRMLWorld”,字体为缺省字体,且倾斜的单行文本造型
#VRMLV2.0utf8
Shape{
appearanceAppearance{
materialMaterial{}
}
geometryText{
string"VRMLWorld"
fontStyleFontStyle{
family"SERIF"
style"ITALIC"
}
}
}
例:
#创建字符集为“SERIF”,字符高度为2.0个单位的加粗斜体的文本造型
#VRMLV2.0utf8
Shape{
appearanceAppearance{
materialMaterial{}
}
geometryText{
string"VRML"
fontStyleFontStyle{
family"SERIF"
style"BOLDITALIC"
size2.0
}
}
}
例:
#创建字符集为SERIF,行间距为0.5单位的加粗文本造型
#VRMLV2.0utf8
Shape{
appearanceAppearance{
materialMaterial{}
}
geometryText{
string["VRML","World"]
fontStyleFontStyle{
family"SERIF"
style"BOLD"
spacing0.5
}
}
}
例:
#创建字符集为TYPEWRITER,沿X方向从左到右,沿Y方向从上到下的水平文本造型
#VRMLV2.0utf8
Shape{
appearanceAppearance{
materialMaterial{}
}
geometryText{
string["AaBb","CcDd","EeFf"]
fontStyleFontStyle{
family"TYPEWRITER"
horizontalTRUE
leftToRightFALSE
topToBottomTRUE
}
}
}
例:
#创建字符集为TYPEWRITER,第一方向沿Y方向从下到上,第二方向沿X方向从左到右的垂直文本
#VRMLV2.0utf8
Shape{
appearanceAppearance{
materialMaterial{}
}
geometryText{
string["AaBb","CcDd","EeFf"]
fontStyleFontStyle{
family"TYPEWRITER"
horizontalFALSE
leftToRightTRUE
topToBottomFALSE
justify["MIDDLE","MIDDLE"]
}
}
3.1.2.3文本造型与几何造型的结合
例:
#创建一个长宽高分别为3.0,2.0,3.0单位的长方体,并在其上方显示“Box”字符的图形
#VRMLV2.0utf8
Group{
children[
Shape{
appearanceDEFBwhiteAppearance{
materialMaterial{}
}
geometryBox{
size3.02.03.0
}
},
Shape{
appearanceUSEBwhite
geometryText{
string["Box",""]
fontStyleFontStyle{
family"TYPEWRITER"
horizontalTRUE
leftToRightTRUE
topToBottomTRUE
justify["MIDDLE","END"]
}
}
}
]
}
3.1.3造型的变换
Transform{
eventInMFNodeaddChildren
eventInMFNoderemoveChildren
exposedFieldSFVec3fcenter000#(-∞,∞)
exposedFieldMFNodechildren[]
exposedFieldSFRotationrotation0010#[-1,1],(-∞,∞)
exposedFieldSFVec3fscale111#(0,∞)
exposedFieldSFRotationscaleOrientation0010#[-1,1],(-∞,∞)
exposedFieldSFVec3ftranslation000#(-∞,∞)
fieldSFVec3fbboxCenter000#(-∞,∞)
fieldSFVec3fbboxSize-1-1-1
#(0,∞)or-1-1-1
}
3.1.3.1平移
利用Transform节点的translation域,进行坐标变换,实现物体在场景中的位置的变化。
例:
#创建一个长宽高分别为2.0,4.0,2.0单位的长方体,并将坐标原点平移到(0.0,3.0,0.0)创建一个圆锥体
#VRMLV2.0utf8
Transform{
translation-2.00.00.0
children[
Shape{
appearanceDEFGreenAppearance{
materialMaterial{
diffuseColor0.01.00.0
}
}
geometryBox{
size2.04.02.0
}
},
Transform{
translation0.03.00.0
childrenShape{
appearanceUSEGreen
geometryCone{
height2.4
bottomRadius2.4
}
}
}
]
}
例:
#坐标系的多层嵌套
#VRMLV2.0utf8
Transform{
children[
Shape{
appearanceDEFbWhiteAppearance{
materialMaterial{}
}
geometryBox{
size3.04.03.0
}
},
Transform{
translation0.0-0.51.5
children[
Shape{
appearanceUSEbWhite
geometryCylinder{
height3.0
radius1.5
}
},
Transform{
translation0.0-0.51.5
children[
Shape{
appearanceUSEbWhite
geometryCylinder{
height2.0
radius1.5
}
},
Transform{
translation0.0-0.51.5
children[
Shape{
appearanceUSEbWhite
geometryCylinder{
height1.0
radius1.5
}
}
]
}
]
}
]
}
]
}
3.1.3.2旋转
利用Transform节点的rotation域,进行物体的旋转变换,实现物体在场景中的方向的变化。
例:
#以原点和点(-1.0,1.0,1.0)的直线为坐标系的旋转轴反方向旋转0.785,在新的坐标系中创建一个长方体
#VRMLV2.0utf8
Transform{
rotation-1.01.01.0-0.785
children[
Shape{
appearanceAppearance{
materialMaterial{}
}
geometryBox{}
}
]
}
例:
#绕y轴向正方向旋转0.524,在新的坐标系中以缺省的大小和排列对齐方式创建文本造型“VRML”
#VRMLV2.0utf8
Transform{
rotation0.01.00.00.524
children[
Shape{
appearanceAppearance{
materialMaterial{}
}
geometryText{
string"VRML"
}
}
]
}
#在当前坐标系中创建一个球体和一个圆锥体,并分别以x轴和y轴为旋转轴旋转90度,然后在新的坐标系中创建圆锥体
#VRMLV2.0utf8
Group{
children[
Shape{
appearanceDEFBwhiteAppearance{
materialMaterial{}
}
geometrySphere{}
},
Shape{
appearanceUSEBwhite
geometryDEFcone01Cone{
bottomRadius1.0
height4.0}
},
Transform{
rotation0.00.01.0-1.571
children[
Shape{
appearanceUSEBwhite
geometryUSEcone01
}
]
},
Transform{
rotation1.00.00.01.571
children[
Shape{
appearanceUSEBwhite
geometryUSEcone01
}
]
}
]
}
例:
#创建一个雷达站造型(由两个长方体,一个细圆柱体和一个圆锥体组成)
#VRMLV2.0utf8
Group{
children[
Shape{
appearanceDEFBwhiteAppearance{
materialMaterial{}
}
geometryBox{
size4.02.04.0
}
},
Transform{
translation0.02.50.0
rotation0.00.01.0-0.7
center0.0-1.50.0
children[