虚拟现实技术vrml“坐标变换节点”——案例

例1:构建一个圆柱体造型,利用Transform节点的坐标平移translation域的域值,创建一个

在Y方向上平移1.5单位的新坐标系,构建圆锥体造型,形成一个类似烟囱的组合造型。

Shape{
     appearance    Appearance {           #外观特征域
         material Material  {            #设置材质属性
          diffuseColor  0 0 1     } }      #设置漫反光颜色
     geometry Cylinder {                #柱体几何造型
         radius    1                    #设置圆柱半径为2
         height    2     }}               #设置圆柱高为2
Transform{                             #坐标变换节点
    translation    0 1.5 0                #设置圆锥向上平移1.5
    children [                          #子节点
        Shape{                        #父节点,造型节点
         appearance    Appearance {
             material Material {
              diffuseColor 0 1 0 } }
         geometry Cone {               #设置锥体几何造型
             bottomRadius 2            #设置底部园半径为2
             height    1 }    }]}            #设置锥体的高为1

运行结果如下:

 2在立体空间背景下,由坐标系变换节点构成的简单空间立体造型,创建一个金色的哑铃立体空间物体造型.。

Background {
    skyColor [0.2 0.5 0.6]}                     #设定天空着色的颜色
Shape{
     appearance    DEF ys Appearance{           #DEF给Appearance的节点命名为ys    
         material Material  {
          diffuseColor 0.3 0.2 0                 #设置漫反光颜色
          ambientIntensity 0.4                 #材料表面对比度 
          specularColor    0.7 0.7 0.6           #材质镜面反射光色
          shininess    0.2                     #材料表面亮度
         } } 
     geometry Cylinder {            #圆柱体几何造型
         radius    0.4              #设置圆柱体的半径为0.4
         height    3.5              #设置圆柱体的高为3.5
         bottom    TRUE            #设置底面封闭
         side TRUE }}              #设置侧面封闭
Transform{                         #球体1坐标变换节点
    translation    0 2 0             #球体1沿y轴向上移动2  
    children [                     #字节点
        DEF    ball Shape    {        #DEF给球体1的Shape节点命名为ball
         appearance    USE    ys       #USE引用DEF的Appearance属性
         geometry Sphere {        #球体1几何造型
             radius    1     }}    ]}    #球体1的半径为1
Transform {                       #球体2坐标变换节点
    translation    0 -2 0           #球体2沿y轴向下移动2
    children [USE ball ]}             #USE引用DEF的球体1中Shape节点内容

运行结果如下:

例3:制作一个红色且无分针和时针的简单钟表造型。 

Transform{                                            #坐标变换节点
    rotation 1 0 0 1.571                           #设置圆柱体沿x轴旋转90° 
    children [
         Shape    {
             appearance    Appearance {                    #外观特征域
                 material Material {                      #设置材质属性
                   diffuseColor    0.7 0.2 0.2 }}            #设置漫反光颜色
                 geometry Cylinder {                      #圆柱体几何造型
                 radius    2.2                            #设置圆柱体的半径为2.2
                 height    0.5     } }]}                       #设置圆柱体的高为0.5

运行结果如下:

 例4:银色十字棒造型

Shape {
    appearance Appearance {
        material Material {                       #设置材质属性
            diffuseColor 0.5 0.5 0.7
            ambientIntensity 0.4
            specularColor 0.8 0.8 0.9
            shininess 0.2    }}
        geometry Cylinder {                       #圆柱体1几何造型
            height 5                              #设置圆柱体1的高为5
            radius 0.2  }}                           #设置圆柱体1的半径为0.2
Transform {
            rotation 0 0 1 1.571                     #设置圆柱体沿z轴旋转90
            children [
                Shape {
                    appearance Appearance {
                        material Material {                #设置材质属性
                            diffuseColor 0.5 0.5 0.7
                            ambientIntensity 0.4
                            shininess 0.2
                            specularColor 0.8 0.8 0.9  }}   #材质镜面反射光色
                        geometry Cylinder {               #圆柱体2几何造型
                            height 5                     #设置圆柱体2的高为5
                            radius 0.2     }}]}           #设置圆柱体2的半径为0.2

运行结果如下:

例5:简单钟表造型,时钟显示时间为3点整。 

Shape {
    appearance Appearance {
        material Material {                                   #设置材质属性
            diffuseColor 0.8 0.2 0.2    }}
        geometry Box {                                #立方体几何造型
            size 4 4 0.2    }}                            #立方体大小设置
Transform {                                     #球体和2个圆柱体的坐标变换节点
            translation    0 0 0.12                      #沿z轴正方向移动0.12 
            children [                                  #子节点
                Shape {
                    appearance Appearance {
                        material Material {
                            diffuseColor 0.5 0.3 0
                            ambientIntensity 0.4
                            specularColor 0.7 0.7 0.6
                            shininess 0.2    }}
                        geometry Sphere{             #球体几何造型
                            radius 0.1}    }           #设置球体的半径为0.1
            Transform { translation    0 0.8 0             #圆柱体1沿y轴向上平移0.8
                children [                           #子节点
                    Shape {                        #父节点,造型节点
                        appearance Appearance {
                            material Material {
                                diffuseColor 0.5 0.5 0.7
                                ambientIntensity 0.4
                                shininess 0.2
                                specularColor 0.8 0.8 0.9}}
                            geometry Cylinder {        #圆柱体1几何造型
                                height 1.5            #设置圆柱体1的高为1.5
                                radius 0.05 }}]}        #设置圆柱体1的半径为0.05
            Transform { translation    0.55  0  0          #沿x轴正方向移动0.55
                rotation 0 0 -1 1.57              #设置圆柱体2沿z轴顺时针旋转90°
                    children [                        #子节点
                        Shape {
                            appearance Appearance {
                                material Material {
                                    diffuseColor 0.5 0.5 0.7
                                    ambientIntensity 0.4
                                    specularColor 0.8 0.8 0.9
                                    shininess 0.2    }}
                                geometry Cylinder {      #圆柱体2几何造型  
                                    height 1.0        #设置圆柱体2的高为1
                                    radius 0.05}}]}]}   #圆柱体2的半径为0.05    

运行结果如下:

例6: 两个球体,一个透明并且缩放

Shape {
    appearance Appearance {
        material Material {
            diffuseColor 1 1 1}}
            geometry Sphere    {       # 球体1几何造型
                radius 1.5}}          #设置球体1的半径为1.5
Transform {                          #球体2几何造型
    scale 2 1.1 1.1              #设置球体2的缩放,x轴缩放2,y轴与z轴都缩放1.1       
    children [                          #子节点
        Shape {
         appearance Appearance {
            material Material {
                diffuseColor 1 0 0
                transparency 0.4    }}
            geometry Sphere{        # 球体2几何造型   
                radius 1.5}}]}        #设置球体2的半径为1.5

运行结果:


例7:设计一个飞碟立体空间造型,使用Transform坐标变换节点进行缩放。

Background {                        #设置空间背景
    skyColor [    0.2 0.5 0.6]}  
Transform {                         #球体1坐标变换节点
    scale 2.3 2.6 2.3          #设置球体1的缩放,x轴与z轴都缩放2.3,y轴缩放 2.6
    children [                   #子节点 
        Shape {
            appearance Appearance {
                material Material {
                    diffuseColor 0.3 0.2 0.0
                    ambientIntensity 0.4
                    specularColor 0.7 0.7 0.6
                    shininess 0.2    }}
                geometry Sphere    {        # 球体1几何造型         
                    radius 1  }}]}           #设置球体1的半径为1
Transform {                            #球体2坐标变换节点
    translation    0 0 0                  #球体2的移动设置,这里未设置
    scale 4 1 4         #设置球体2的缩放,x轴与z轴都缩放4,y轴缩放 1
    children [
        Shape {
            appearance Appearance {
                material Material{
                    diffuseColor 0.3 0.2 0.0
                    ambientIntensity 0.4
                    specularColor 0.7 0.7 0.6
                    shininess 0.2        }}
                    geometry Sphere    {     # 球体2几何造型  
                        radius 1  }}]}         #设置球体2的半径为1

运行结果如下:

例8:沿指定的缩放方向构建椭圆造型。

Shape {
    appearance Appearance {
        material Material {
            diffuseColor 1 1 1}}
            geometry Sphere    {           # 球体1几何造型  
                radius 1.5}}             #设置球体1的半径为1.5
Transform {                           #球体2坐标变换节点
    scaleOrientation 1 1 0 0.785        #定向缩放,沿x,y轴定向缩放45°
    scale 2 1.1 1.1            #设置球体2的缩放,x轴缩放2,y轴与z轴都缩放1.1  
    children [
        Shape {
         appearance Appearance {
            material Material {
                diffuseColor 1 0 0
                transparency 0.4    }}
            geometry Sphere{     # 球体2几何造型   
                radius 1.5}}]}      #设置球体2的半径为1.5

运行结果:

例11:利用节点定义及引用方法,构建一个复杂的钟表造型。

Transform {	#作为表盘
	rotation  1  0 0 1.57	#沿x轴方向旋转90度
	translation	0 0 -0.3	向-z轴方向移动0.3,使表盘向后一些,使表针显示出来
	children [
		Shape {
			appearance Appearance {
				material Material {	#设置材质
					diffuseColor 0.7 0.2 0.2	#设置漫反射颜色RGB值为 0.7 0.2 0.2
				}
			}
			geometry Cylinder {	#几何造型节点
				radius 2.2	#设置半径为2.2.
				height 0.5 #设置高度为0.5
			}
		}
	]
}
Transform {	#变换节点
	children [	#子节点 #作为表盘中心圆点
		Shape {
			appearance Appearance {
				material Material {	#设置材质
					diffuseColor 0.5 0.3 0	#设置漫反射颜色RGB值为0.5 0.3 0
					ambientIntensity 0.4	#设置环境光强度为0.4
					specularColor 0.7 0.7 0.6	#设置反射光RGB值为0.7  0.7  0.6
					shininess 0.2	#设置表面亮度为0.2
				}
			}
			geometry Sphere {
				radius 0.1		#几何造型节点 设置为球体,半径为0.1
			}
		}
		
	]
}
Transform {	#变换节点 
	translation	0 0.85 0	#xiangy轴方向平移0.85个单位
	children [	#子节点 作为分针
		DEF S1 Shape {	#造型节点,并设置别名为S1
			appearance DEF A1 Appearance {	#外观域节点,并设置别名为A1
				material Material {	#为A1设置材质
					diffuseColor 0.5 0.5 0.7	#设置漫反射颜色RGB值为0.5 0.5 0.7
					ambientIntensity 0.4	#设置环境光强度为0.4
					specularColor 0.8 0.8 0.9	#设置反射光RGB值为0.7  0.7  0.6
					shininess 0.2	#设置表面亮度为0.2
				}
			}
			geometry Cylinder {	#几何域节点,设置为柱体
				radius 0.05	#底面半径为0.05
				height 1.5	高度为1.5
			}
		}	
	]
}
Transform { #变换节点	时针
	translation	0.6 0 0	#向x轴方向移动0.6个单位
	rotation 0 0 -1 1.57		#沿z轴负方向旋转90度
	scale 1 0.7 1	#缩放节点	在x、z轴方向无缩放,y方向上缩放0.7
	children [USE S1]	子节点使用和分针一样的几何节点
}
DEF	bkd1 Transform {	#变换节点,并取别名为bkd1		设置为大刻度指针
	translation	0 1.8 0	#在y轴方向上移动1.8
	children [
		Shape {
			appearance USE A1		#外观域节点使用A1
			geometry Box {	#刻度尺寸
				size 0.1 0.2 0.1	#长宽高为0.1 0.2 0.1
			}
		}
	]
}
Transform {	#变换节点
	rotation 0 0 1 0.524		#在z轴方向旋转90度
	children [
		DEF	bkd Transform {	变换节点,取别名bkd
			  translation 0 1.8 0	#在y轴方向移动1.8
			  children [
				  Shape {
					  appearance Appearance {	设置材质
						material USE A1	#材质使用A1
					  }
					  geometry Box {	#设置小刻度指针
						size 0.05 0.2 0.1	
					  }
				  }
			  ]
		}
		
Transform {#使变换节点,将剩下的10个指针,以此旋转变换得到
rotation 0 0 1 0.524		#每次旋转30度
	children [
		USE	bkd	#小刻度指针使用bkd节点
			Transform {
			rotation 0 0 1 0.524
				children [
				USE	bkd1		#大刻度指针使用bkd1节点
					Transform {
					rotation 0  0 1 0.524
						children [
						USE	bkd
							Transform {
							rotation 0 0 1 0.524
								children [
								USE	bkd
									Transform {
									rotation 0 0 1 0.524
										children [
										 USE bkd1
											 Transform {
											 rotation 0 0 1 0.524
												children [
												USE	bkd
													Transform {
													rotation 0 0 1 0.524
														children [
														USE	bkd
															Transform {
															rotation 0 0 1 0.524
															children [
															 USE bkd1
																		 Transform {
	rotation 0 0  1 0.524
	children [
		USE	bkd
		Transform {
																					rotation 0 0 1 0.524
		children [
		USE	bkd
]}]}]}]}]}]}]}]}]}]}]}

 运行结果:

猜你喜欢

转载自blog.csdn.net/Niykee/article/details/127392181