VRML:ROUTE 作为 PROTO 中的参数

发布于 2024-12-07 22:51:59 字数 281 浏览 0 评论 0原文

我有一个带有 TouchSensor 的对象的原型,我想在创建对象时将不同的路由链接到它,

例如我

PROTO plate[]
{
  Shape {..something..}
  DEF TS TouchSensor {} 
}

想用不同的路由进行调用

plate{ROUTE ...}
plate{ROUTE ...}

,但有一个原型

如何实现这一点?

谢谢

I have a PROTO of some object with TouchSensor and I'd like to link different ROUTEs to it when creating objects

e.g. I have

PROTO plate[]
{
  Shape {..something..}
  DEF TS TouchSensor {} 
}

I want to call

plate{ROUTE ...}
plate{ROUTE ...}

with different ROUTEs, but having one PROTO

How to implement this?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

神爱温柔 2024-12-14 22:52:00

您可以使用 IS 来公开原型中 TouchSensor 的事件。

例如:

#VRML V2.0 utf8

# First, define the prototype "plate".
PROTO plate [
    eventOut SFTime touched
    exposedField SFVec3f translation 0 0 0
]{

    Transform {
        translation IS translation
        children Shape{
            appearance Appearance {material Material {}}
            geometry Sphere{}
        }
    }
    TouchSensor{touchTime IS touched}
}


# Then create one or several instances of the object
DEF plate1 plate{translation -2 0 0}
DEF plate2 plate{translation 2 0 0}



DEF myscript Script{
    eventIn SFTime receive_event
    url "javascript:
    function receive_event(){
        trace('A sphere was clicked');
    }
    "
}

# Each instance had a different DEF name, so you can choose where to send the event independently from each other
# but for the example, I send them both to a script that says in the console when it was clicked
ROUTE plate1.touched TO myscript.receive_event
ROUTE plate2.touched TO myscript.receive_event

You would use IS to expose the event from the TouchSensor in the prototype.

For example:

#VRML V2.0 utf8

# First, define the prototype "plate".
PROTO plate [
    eventOut SFTime touched
    exposedField SFVec3f translation 0 0 0
]{

    Transform {
        translation IS translation
        children Shape{
            appearance Appearance {material Material {}}
            geometry Sphere{}
        }
    }
    TouchSensor{touchTime IS touched}
}


# Then create one or several instances of the object
DEF plate1 plate{translation -2 0 0}
DEF plate2 plate{translation 2 0 0}



DEF myscript Script{
    eventIn SFTime receive_event
    url "javascript:
    function receive_event(){
        trace('A sphere was clicked');
    }
    "
}

# Each instance had a different DEF name, so you can choose where to send the event independently from each other
# but for the example, I send them both to a script that says in the console when it was clicked
ROUTE plate1.touched TO myscript.receive_event
ROUTE plate2.touched TO myscript.receive_event
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文