你可以通过使用PROTO机制来实现你想要的。
PROTO SmallSphere [
exposedField SFVec3f SmallSphere_translation 0 0 0
]
{
Transform {
translation IS SmallSphere_translation
children [
Shape {
appearance Appearance { material Material {} }
geometry Sphere { radius 1 }
}
]
}
上面的代码基本上从您的转换中创建了一个 PROTO(类似于面向对象编程中的一个类),其中翻译是可变的。然后,您必须按如下方式创建它的实例:
SmallSphere { SmallSphere_translation 96.0 85.0 76.0 }
SmallSphere { SmallSphere_translation 3.0 8.0 6.0 }
SmallSphere { SmallSphere_translation 936.0 385.0 746.0 }
...任意数量,其中翻译是您从一个实例更改为另一个实例的参数。如果您需要使用实例更改其他一些字段,您只需按照上面的示例进行操作。例如,您希望球体的半径是可变的,您必须按如下方式创建您的 PROTO:
PROTO SmallSphere [
exposedField SFVec3f SmallSphere_translation 0 0 0
exposedField SFFloat SmallSphere_radius 2.0
]
{
Transform {
translation IS SmallSphere_translation
children [
Shape {
appearance Appearance { material Material {} }
geometry Sphere { radius IS SmallSpehere_radius }
}
]
}
请注意SmallSphere_translation和SmallSphere_radius是我选择的名称。您可以根据需要命名这些字段。