Virtual reality technology vrml "coordinate transformation node" - case

Example 1: Construct a cylindrical shape, use the coordinates of the Transform node to translate the field value of the translation field, and create a

Translate the new coordinate system of 1.5 units in the Y direction to construct a cone shape, forming a combined shape similar to a chimney.

Shape{      appearance Appearance { #Appearance feature domain          material Material { #Set material attribute           diffuseColor 0 0 1 } } #Set diffuse reflection color      geometry Cylinder { #Cylinder geometry          radius 1 #Set cylinder radius to 2          height 2 }} #Set cylinder The height is 2 Transform{ #Coordinate transformation node     translation 0 1.5 0 #Set the cone to translate upward 1.5     children [ #Child node         Shape{ #Parent node, shape node          appearance Appearance {              material Material {               diffuseColor 0 1 0 } }













         geometry Cone { #Set the geometry of the cone
             bottomRadius 2 #Set the radius of the bottom circle to 2
             height 1 } }]} #Set the height of the cone to 1

The result of the operation is as follows:

 Example 2 : Under the background of the three-dimensional space, a simple three-dimensional shape composed of coordinate system transformation nodes creates a golden dumbbell three-dimensional space object shape.

Background {     skyColor [0.2 0.5 0.6]} #Set the color of sky coloring Shape{      appearance DEF ys Appearance{ #DEF named the node of Appearance as ys              material Material {           diffuseColor 0.3 0.2 0 #Set diffuse reflection color           ambientIntensity 0.4 #Material surface contrast            specularColor 0.7 0.7 0.6 #Material specular reflection light color           shininess 0.2 #Material surface brightness          } }       geometry Cylinder { #Cylinder geometry          radius 0.4 #Set the radius of the cylinder to 0.4          height 3.5 #Set the height of the cylinder to 3.5          bottom TRUE #Set Bottom closed













         side TRUE }} #Set side closure
Transform{ #Sphere 1 coordinate transformation node
    translation 0 2 0 #Sphere 1 moves up 2  
    children along the y axis [ #Byte point
        DEF ball Shape { #DEF names the Shape node of sphere 1 as ball
         appearance USE ys #USE refers to the Appearance attribute of DEF
         geometry Sphere { #Sphere 1 geometric modeling
             radius 1 }} ]} #The radius of sphere 1 is 1
Transform { #Sphere 2 coordinate transformation node
    translation 0 -2 0 #Sphere 2 along y Move the axis down by 2
    children [USE ball ]} #USE refers to the content of the Shape node in sphere 1 of DEF

The result of the operation is as follows:

Example 3: Make a simple red clock without minute and hour hands. 

Transform{ #Coordinate transformation node
    rotation 1 0 0 1.571 #Set the cylinder to rotate 90° along the x-axis 
    children [
         Shape {              appearance Appearance { #Appearance feature domain                  material Material { #Set material attribute                    diffuseColor 0.7 0.2 0.2 }} #Set diffuse reflection color                  geometry Cylinder { #Cylinder geometry                  radius 2.2 #Set the radius of the cylinder to 2.2                  height 0.5 } }]} #Set the height of the cylinder to 0.5





The result of the operation is as follows:

 Example 4: Silver cross stick shape

Shape {     appearance Appearance {         material Material { #Set material properties             diffuseColor 0.5 0.5 0.7             ambientIntensity 0.4             specularColor 0.8 0.8 0.9             shininess 0.2 }}         geometry Cylinder { #Cylinder 1 geometry             height 5 #Set the height of cylinder 1 to 5             radius 0.2 }} #Set the radius of cylinder 1 to 0.2 Transform {             rotation 0 0 1 1.571 #Set the cylinder to rotate 90 along the z axis             children [                 Shape {                     appearance Appearance {














                        material Material { #Set material properties
                            diffuseColor 0.5 0.5 0.7
                            ambientIntensity 0.4
                            shininess 0.2
                            specularColor 0.8 0.8 0.9 }} #Material specular reflection light color
                        geometry Cylinder { #Cylinder 2 geometric shape
                            height 5 #Set the height of cylinder 2 to 5
                            radius 0.2 } }]} #Set the radius of cylinder 2 to 0.2

The result of the operation is as follows:

Example 5: Simple clock shape, the clock display time is 3 o'clock. 

Shape {     appearance Appearance {         material Material { #Set the material property             diffuseColor 0.8 0.2 0.2 }}         geometry Box { #Cube geometry             size 4 4 ​​0.2 }} #Cube size setting Transform { #The coordinate transformation node             translation 0 of the sphere and 2 cylinders 0 0.12 #Move 0.12 along the positive direction of the z-axis              children [ #Child node                 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{ #Sphere geometry
                            radius 0.1} } #Set the radius of the sphere to 0.1
            Transform { translation 0 0.8 0 #Cylinder 1 translates up 0.8 along the y-axis
                children [ #child nodes
                    Shape { #parent node, shape node
                        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 { #Cylinder 1 geometry
                                height 1.5 #Set the height of cylinder 1 to 1.5
                                radius 0.05 }}]} #Set the radius of cylinder 1 to 0.05
            Transform { translation 0.55 0 0 # Move 0.55 along the positive direction of the x-axis
                rotation 0 0 -1 1.57 #Set cylinder 2 to rotate 90° clockwise along the z-axis
                    children [ #Child node
                        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 { #Cylinder 2 geometry  
                                    height 1.0 #Set the height of cylinder 2 to 1
                                    radius 0.05}}]}]} #The radius of cylinder 2 is 0.05    

The result of the operation is as follows:

Example 6:  Two spheres, one transparent and scaled

Shape {     appearance Appearance {         material Material {             diffuseColor 1 1 1 }}             geometry Sphere { # Sphere 1 geometry                 radius 1.5}} #Set the radius of sphere 1 to 1.5 Transform { #Sphere 2 geometry     scale 2 1.1 1.1 #Set the sphere 2 Scaling, x-axis scaling 2, y-axis and z-axis scaling 1.1            children [ #child node         Shape {          appearance Appearance {             material Material {                 diffuseColor 1 0 0                 transparency 0.4 }}             geometry Sphere{ # sphere 2 geometry                    radius 1.5}}]} #Set the radius of sphere 2 to 1.5














operation result:


Example 7: Design a three-dimensional shape of a flying saucer, and use the Transform coordinate transformation node to scale it.

Background { #Set space background
    skyColor [ 0.2 0.5 0.6]}  
Transform { #Sphere 1 coordinate transformation node
    scale 2.3 2.6 2.3 #Set the scaling of sphere 1, the x-axis and z-axis are both scaled to 2.3, and the y-axis is scaled to 2.6
    children [ #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 { # Sphere 1 geometry                              radius 1 }}]} #Set the radius of sphere 1 to 1








Transform { #Sphere 2 coordinate transformation node
    translation 0 0 0 #The movement setting of sphere 2,
    scale 4 1 4 #Set the scaling of sphere 2, the x-axis and z-axis are scaled by 4, and the y-axis is scaled by 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 { # sphere 2 geometry                           radius 1 }}]} #Set the radius of sphere 2 to 1







The result of the operation is as follows:

Example 8: Construct an ellipse shape along the specified scaling direction.

Shape {     appearance Appearance {         material Material {             diffuseColor 1 1 1 }}             geometry Sphere { # Sphere 1 geometry                   radius 1.5}} #Set the radius of sphere 1 to 1.5 Transform { #Sphere 2 coordinate transformation node     scaleOrientation 1 1 0 0.785 #Orientation scaling , scale 45° along the x and y axes     scale 2 1.1 1.1 #Set the scaling of the sphere 2, the x axis scales 2, the y axis and the z axis both scale 1.1       children [         Shape {          appearance Appearance {             material Material {                 diffuseColor 1 0 0                 transparency 0.4 }}             geometry Sphere{ # sphere 2 geometric shape   















                radius 1.5}}]} #Set the radius of sphere 2 to 1.5

operation result:

Example 11: Use node definition and reference methods to build a complex clock shape.

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
]}]}]}]}]}]}]}]}]}]}]}

 operation result:

Guess you like

Origin blog.csdn.net/Niykee/article/details/127392181