一、米字造型
代码
DEF gun Shape {
appearance Appearance {
material Material { diffuseColor 1.0 1.0 0.0 }
}
geometry Box {
size 0.1 0.02 0.2 # 宽 高 长
}
}
DEF mi Group {
children [
Transform {
translation 0 0 0
rotation 0 1 0 0
children [
USE gun
Transform {
translation 0 0 0
rotation 0 0 1 0.785398
children [
USE gun
Transform {
translation 0 0 0
rotation 0 0 1 1.570796
children
[USE gun
Transform {
translation 0 0 0
rotation 0 0 1 -0.785398
children [USE gun
]
}
]
}
]
}
]
}
]
}
Transform {
translation 0 0.3 0
children [
USE mi
Transform {
translation 0.3 0 0
children [
USE mi
Transform {
translation -0.6 0 0
children [
USE mi
]
}
]
}
]
}
效果图
二、刻度钟
代码
#VRML V2.0 utf8
# 定义钟表面的PROTO原型
PROTO ClockFace [
field SFVec3f translation 0 0 0 # 位置
field SFFloat scale 1.0 # 大小缩放
field SFColor diffuseColor 0.8 0.8 0.8 # 颜色
]
{
Transform {
translation IS translation
children [
Shape {
geometry Cylinder {
height 0.05
radius 1.0
}
appearance Appearance {
material Material {
diffuseColor IS diffuseColor
}
}
}
# 添加12个小时刻度
Group {
children [
# 遍历12个小时位置,添加刻度
# 每个小时位置是360度/12 = 30度
# 使用cos和sin函数计算刻度位置
# 刻度长度可根据需要调整
# 假设刻度长度为0.1
# 从12点位置开始,逆时针添加刻度
# 12点
Shape {
geometry IndexedLineSet {
coord Coordinate {
point [ -1 1 0, -0.9 1 0 ]
}
coordIndex [ 0 1 -1 ]
}
appearance Appearance {
material Material {
diffuseColor 0 0 0
}
}
}
# 11点
Shape {
geometry IndexedLineSet {
coord Coordinate {
point [ -0.966 0.259 0, -0.866 0.259 0 ]
}
coordIndex [ 0 1 -1 ]
}
appearance Appearance {
material Material {
diffuseColor 0 0 0
}
}
}
# ... (继续添加其他刻度,直到1点位置)
# 1点
Shape {
geometry IndexedLineSet {
coord Coordinate {
point [ 0.866 -0.5 0, 0.766 -0.5 0 ]
}
coordIndex [ 0 1 -1 ]
}
appearance Appearance {
material Material {
diffuseColor 0 0 0
}
}
}
# 注意:这里只展示了12点、11点和1点的刻度作为示例
# 你需要继续添加剩余的小时刻度来完成整个圆周
]
}
]
}
}
Group {
children [
# 添加多个ClockFace实例,可以调整其位置、大小和颜色
ClockFace {
translation 0 2 -3
scale 1.0
diffuseColor 0.8 0.5 0.2
}
# ... (继续添加其他ClockFace实例)
ClockFace {
translation -2 0 -1
scale 0.8
diffuseColor 0.5 0.8 0.2
}
ClockFace {
translation 1 5 5
scale 1.0
diffuseColor 0.8 0.5 0.3
}
ClockFace {
translation 0 1 -1.5
scale 1.0
diffuseColor 1.0 0.0 0.0
}
]
}
效果图