如何在 Blender 中以编程方式创建逻辑块?

发布于 2024-09-10 04:01:58 字数 672 浏览 4 评论 0原文

我想让我的初始化脚本创建交互式 Blender 应用程序(不一定是游戏)所需的附加传感器/控制器/执行器。这样做更可取,原因有两个:

  • 我可以在多个应用程序中使用此脚本。一遍又一遍地创建通用逻辑是乏味的。并且没有其他方法可以导入 AFAIK。
  • 因为我是一名程序员,所以让我的 Python 模块创建逻辑块对我来说更加容易和舒适。 (...并且代码可以进行版本控制、同行评审、轻松记录等。)

实际上创建模板文件部分解决了第一个问题。但是我无法为不同的项目混合和匹配不同的部分,或者我必须为每种可能性创建一个模板。

我搜索了 游戏引擎文档Python API 但找不到任何线索。逻辑块的 __init__ 方法甚至没有在那里列出。

但如果有什么方法可以在 Python 中动态创建逻辑块,我想尝试一下。

注意:由于我对 BGE 的了解有限,您无法直接从 Python 访问按键。需要一个传感器。

I would like to let my initializing script to create additional sensors/controller/actuators necessary for an interactive Blender application (not necessarily a game). This is preferable for two reasons:

  • I can use this script in multiple applications. Creating common logic over and over again is tedious. And there is no other way to import AFAIK.
  • Having my Python modules create logic bricks is much easier and comfortable for me since I'm a coder. (...and the code can be version controlled, peer reviewed, easily documented etc.)

Actually creating a template file partially addresses the first issue. But then I can't mix and match different parts for different projects, or I have to create a template for each possibility.

I have searched both the Game Engine docs and the Python API but couldn't find any clue. __init__ methods of logic bricks aren't even listed there.

But if there is any way to create logic bricks dynamically within Python I would like to try it.

NOTE: with my limited knowledge of BGE, you can't, for instance, access key presses directly from Python. A sensor is required.

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

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

发布评论

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

评论(2

过气美图社 2024-09-17 04:01:58

我知道这是一篇非常旧的帖子,但信息已经过时了。
现在可以使用 python 添加执行器和传感器:
http://www.blender.org/documentation/blender_python_api_2_60_6/bpy.ops .logic.html

以防其他人正在寻找信息。

I know this is a really old post, but the information is outdated.
It is now possible to add actuators and sensors with python:
http://www.blender.org/documentation/blender_python_api_2_60_6/bpy.ops.logic.html

In case anyone else is looking for the info.

拥醉 2024-09-17 04:01:58

所以 -
事实上,无法直接从 Python 创建逻辑块。

当您在 BGE 中实例化一个对象时(就像使用添加对象执行器一样),实例化对象中的逻辑块会随之而来 - 您可以更改和重新排列它们 - 包括传感器、控制器和执行器的重新布线,

我认为这是当前的解决方法:创建一个通用传感器、控制器和执行器的空白矩阵,当您将新对象添加到场景中时,调用一个函数来填充逻辑块的参数并进行所需的接线。

So --
as it is, there is no way to create the logic bricks straight from Python.

When you instantiate an object in ther BGE (like with an add object actuator), the logic bricks from the instantiated object comes with it - and you can change and rearrange those - including the rewiring of the sensors, controler and actuators

I think this is the current workaround: you create a blank matrix of generic senor, controlers and actuators, and as you add new objects into a scene, call a function that fill-in the parameters for the logic blocks and do the required wiring.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文