当按下鼠标左键时,我试图在场景中显示一个标准文本。然而,我有麻烦的路由。这是我到目前为止的X3D代码:
<X3D>
<Scene>
<Viewpoint DEF="VP" position="0 0 .6"/>
<PythonScript DEF="PS" url="test.py"/>
<Shape>
<Text DEF="TXT" string="initial message">
<FontStyle justify='MIDDLE' size='0.02' />
</Text>
</Shape>
<MouseSensor DEF="MS"/>
<ROUTE fromNode="MS" fromField="leftButton" toNode="PS" toField="showText"/>
<ROUTE fromNode="PS" fromField="showText" toNode="TXT" toField="string"/>
</Scene>
</X3D>
以及Python代码:
from H3DInterface import *
class ShowText(TypedField(MFString, SFBool)):
def __init__(self):
MFString.__init__(self)
self.inactive_txt = 'Press left mousebutton'
self.active_txt = 'Hello World!'
def update(self, event):
if event.getValue() == 1:
return self.active_txt
else:
return self.inactive_txt
showText = ShowText()
这是我收到的警告,但无法解决:
Warning: invalid return value from update()-function for Python defined field of type PythonScript_000000000722E320.ShowText
这对我来说很奇怪,因为文本节点有属性string,它是base\类型MFString。你知道吗
MFString必须通过将字符串定义为:
相关问题 更多 >
编程相关推荐