Expose connected logic bricks from python #29679
Labels
No Label
Interest
Animation & Rigging
Interest
Blender Cloud
Interest
Collada
Interest
Core
Interest
Documentation
Interest
Eevee & Viewport
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
Import and Export
Interest
Modeling
Interest
Modifiers
Interest
Nodes & Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds, Tests & Devices
Interest
Python API
Interest
Rendering & Cycles
Interest
Sculpt, Paint & Texture
Interest
Translations
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Meta
Good First Issue
Meta
Papercut
Module
Add-ons (BF-Blender)
Module
Add-ons (Community)
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: blender/blender-addons#29679
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
%%%Hi,
this few lines patch exposes the list of sensors' connected controllers and controllers' connected actuators.
At first i called both properties .links, but to make it more clear that controllers- [x].links returns only actuators, i called them linked_controllers and linked_actuators
Why this patch should be added?
Well, i needed this informations in order to finish my python script that allow to share logic setups. With it you'll just need to press a button and you'll have all your setup saved in a file, so that it is easy to reuse (the script saves and loads the files) and share. If you visit the blenderartists' game forum, you'll see that a lot of requests are made about how to configure the setup. With this patch and the script the problem will be solved!%%%
Changed status to: 'Open'
%%%Hi,
+controller = MEM_callocN(sizeof(bController ) totlinks, "sensor_links");
+actuators = MEM_callocN(sizeof(bActuator ) totlinks, "controller_links");
What means you didn't test the patch, right ;)
So, even with the above change what I'm getting is more a copy of the controllers/actuators then the object itself.
For example try to change the name of: bpy.game.sensors- [x].linked_controllers- [x] it doesn't change a thing.
+for(counter = 0; counter < totlinks; counter++)
%%%
%%%1) Actuators don't store linked_controller, so the bidirectional linking was not possible(sensors<->controllers<->actuators). I thought it was more logical to follow the left to right pattern.
Definitely a good point. I'll redo the patch to work like this!
Actually i have a build that i used to see if it worked. Everything i needed was working, but i must admit i only used it to read data, and not to write. My fault!
4)no problem, i'll fix it.%%%
%%%Corrected how you suggested.
Now the controller has linked_sensors and linked_actuators. In addition it returns the real logic brick, not a copy(i tried changing the name from py console)
I still have some doubts about only accessing the links from the controller.. I think it is more natural thinking from sensor to actuator, but i'll wait for your opinion(keep things as they are now, or add the linked_controllers to sensors)
Btw both the solutions works for my script%%%
%%%1) is controller.linked_sensors working for you? I tested here and it seem not working (controller.linked_actuators works fine though)
2) it's better to name it controller.sensors and controllers.actuators
3) #include "MEM_guardedalloc.h" is no longer necessary
4) if you get controller.sensors working and actuator.controllers we could have them all exposed. Although I still feel that we need no more than controller.sens/act.
*) if controller.sensors is not doable we can consider the sensors.controllers and controllers.actuators only :/%%%
%%%1) you're right. I don't remember if i tested them, since it was the same 3 lines of code of actuators access, i just changed the the DNA field it points to. (more on this point later)
2)done
3)i receive warnings if i don't put it in. It says something like unknown external symbol, suppose it returns int.
4) more on this point now
Here the patch on which i'm working (note: it does not work)
I have no problems in sens->cont->act, but i'm facing really strange problems on the other way.
Let's talk first about cont->sensors(it is easier)
The code is the exactly the same of cont->actuators, i just changed to load the slinks instead oflinks and to return totslinks instead of totlinks, getting this informations from the DNA_controller_type.h (here it is commented that links refers to actuators and slinks to sensors)
Btw, while trying to get sensors from controller, it gives a list of length 0.
I run blender with the debugged attached, and i discovered that this happens because iter->valid is set to 0. Still, i don't know why this happens. I put a break both in actuator_begin and sensor_begin to see the difference, and i didn't see anything strange, except in both iter->ptr->data and ->type is 0x0000000, and the debugger can't evaluate the type informations. But it works.
While debuggin sensors_begin, it(MSVS) enlight a few fields as red (iter, ptr, iter->prop, iter->internal) and both iter->valid and iter->ptr->valid are set to 0. Forcing it to 1 raises an Access violation reading in rna_iterator_array_dereference_get trying to read 0x00000000.
But collection_prop informations are right, the lenght is correct, and the code is the same as actuators, so i don't really understand what's wrong...
About actuators-> controller
As you can see in the patch, i check for all the controllers the current object owns, and check if some of that controllers hods the current actuators. Obviously this is wrong since it doesn't find other object controllers connected to the actuator: it should get all the objects in the scene, and repeat the same process on each of them.
I don't know who to find the current scene from the actuator or the object, in addition is it correct to initialize the array of pointers in the _begin method? Will it be called again if after accessing it the first time, a new controller is linked?
To sum up:
%%%so let's reflect what the blender code exposes:
sensors.controllers and controllers.actuators
simple, cleaner and get your patch in trunk sooner. mind updating the final patch so I can commit?
thanks%%%
%%%No problems!
Here the patch!
Thanks for your time!%%%
%%%committed on rev. 43510 thanks for your work!%%%
Changed status from 'Open' to: 'Archived'