如何在X3D和Python中显示文本?

2024-09-29 22:30:50 发布

您现在位置:Python中文网/ 问答频道 /正文

当按下鼠标左键时,我试图在场景中显示一个标准文本。然而,我有麻烦的路由。这是我到目前为止的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。你知道吗


Tags: 代码文本selftxtstringreturndefscene

热门问题