Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting SoftBody pinned points programmatically #26594

Open
Tracked by #45333
and3rson opened this issue Mar 4, 2019 · 5 comments
Open
Tracked by #45333

Setting SoftBody pinned points programmatically #26594

and3rson opened this issue Mar 4, 2019 · 5 comments

Comments

@and3rson
Copy link
Contributor

and3rson commented Mar 4, 2019

Godot version:
3.1-beta10

OS/device including version:
ArchLinux rolling

Issue description:
There seems to be no way to build SoftBody from script. pinned_points is exposed, but not documented. attachments is undefined, although visible in editor. I'm running this in custom post-import script.

Steps to reproduce:

var sb : SoftBody = SoftBody.new()
sb.mesh = some_mesh
parent.add_child(sb)
print(sb.pinned_points)  # prints []
sb.pinned_points.append(0)
print(sb.pinned_points)  # still prints []
@Chaosus Chaosus added this to the 3.2 milestone Mar 4, 2019
@and3rson
Copy link
Contributor Author

and3rson commented Mar 4, 2019

@Chaosus I just tested and it actually works as long as you replace original array with a new one:

sb.pinned_points = sb.pinned_points + [42]
# or
sb.pinned_points = [34, 42, 1337]

This should be be documented somewhere. Also the documentation should mention that pinned_points are actually writeable, and that you can write to attachments by using set method as such: sb.set('attachments/0/point_index')

I think "documentation needed" label should be added.

@Chaosus Chaosus modified the milestones: 3.2, 3.1 Mar 5, 2019
@akien-mga akien-mga modified the milestones: 3.1, 3.2 Mar 5, 2019
@mrzapp
Copy link

mrzapp commented Apr 27, 2019

I'd actually suggest adding a binding to the "pin_point" method, it seems simpler:

ClassDB::bind_method(D_METHOD("pin_point"), &SoftBody::pin_point);

@mrzapp
Copy link

mrzapp commented Apr 27, 2019

For anyone ending up here, this "polyfill" will do the job:

func pin_point(point_index : int, pin : bool, p_spatial_attachment_path : NodePath):    
    var pinned_points : Array = get('pinned_points')
            
    if pin:
        pinned_points.append(point_index)
        set('pinned_points', pinned_points)
        set('attachments/' + str(pinned_points.size() - 1) + '/spatial_attachment_path', p_spatial_attachment_path)
        
    else:
        pinned_points.remove(pinned_points.find(point_index))
        set('pinned_points', pinned_points)

You can create a new class like ProceduralSoftBody inherited from SoftBody

@jedStevens
Copy link

@mrzapp I just tried that and I'm getting a crash when I try to do this at runtime

handle_crash: Program crashed with signal 11
Dumping the backtrace. Please include this when reporting the bug on https://github.com/godotengine/godot/issues
[1] /usr/lib/libc.so.6(+0x3a7e0) [0x7fe873e507e0] (??:0)
[2] /home/jed/godot/bin/godot.x11.tools.64() [0x1cc4590] (/home/jed/godot/thirdparty/bullet/BulletCollision/BroadphaseCollision/btDbvt.cpp:33)
[3] /home/jed/godot/bin/godot.x11.tools.64() [0x1cc4a7e] (/home/jed/godot/thirdparty/bullet/BulletCollision/BroadphaseCollision/btDbvt.cpp:162)
[4] btDbvt::update(btDbvtNode*, btDbvtAabbMm&) (/home/jed/godot/thirdparty/bullet/BulletCollision/BroadphaseCollision/btDbvt.cpp:580)
[5] btSoftBody::transform(btTransform const&) (/home/jed/godot/thirdparty/bullet/BulletSoftBody/btSoftBody.cpp:804)
[6] SoftBodyBullet::move_all_nodes(Transform const&) (/home/jed/godot/modules/bullet/soft_body_bullet.cpp:160)
[7] SoftBodyBullet::set_soft_transform(Transform const&) (/home/jed/godot/modules/bullet/soft_body_bullet.cpp:153)
[8] BulletPhysicsServer::soft_body_set_transform(RID, Transform const&) (/home/jed/godot/modules/bullet/bullet_physics_server.cpp:1011)
[9] SoftBody::_notification(int) (/home/jed/godot/scene/3d/soft_body.cpp:286)
[10] SoftBody::_notificationv(int, bool) (/home/jed/godot/scene/3d/soft_body.h:67 (discriminator 14))
[11] Object::notification(int, bool) (/home/jed/godot/core/object.cpp:945)
[12] SceneTree::flush_transform_notifications() (/home/jed/godot/scene/main/scene_tree.cpp:149)
[13] SceneTree::iteration(float) (/home/jed/godot/scene/main/scene_tree.cpp:479 (discriminator 2))
[14] Main::iteration() (/home/jed/godot/main/main.cpp:1912)
[15] OS_X11::run() (/home/jed/godot/platform/x11/os_x11.cpp:3178)
[16] /home/jed/godot/bin/godot.x11.tools.64(main+0x128) [0x13a261e] (/home/jed/godot/platform/x11/godot_x11.cpp:57)
[17] /usr/lib/libc.so.6(__libc_start_main+0xf3) [0x7fe873e3cee3] (??:0)
[18] /home/jed/godot/bin/godot.x11.tools.64(_start+0x2e) [0x13a243e] (??:?)
-- END OF BACKTRACE --

@mrzapp
Copy link

mrzapp commented Aug 3, 2019

@jedStevens I didn't experience this crash myself, but I'd suggest trying to remove one line of code at a time to pinpoint where the error occurs and create a new issue on it, if you manage to reproduce it reliably.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants