godotengine / godot-proposals

Godot Improvement Proposals (GIPs)
MIT License
1.12k stars 69 forks source link

Add simple rotate Bone to Skeleton3D #3752

Open mrjustaguy opened 2 years ago

mrjustaguy commented 2 years ago

Describe the project you are working on

Character controller (rotate head with mouse)

Describe the problem or limitation you are having in your project

It's too hard to figure out how to do a simple operation (that is to rotate a bone locally by x degrees on y axis)

Describe the feature / enhancement and how it helps to overcome the problem or limitation

Add a function to Rotate bone of a specified index by a specified amount (in radians for consistency)

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

This is already sort-of done by the Skeleton Editor rotation logic, just isn't exposed to scripting.

If this enhancement will not be used often, can it be worked around with a few lines of script?

Probably.

Is there a reason why this should be core and not an add-on in the asset library?

Skeleton is core.

Calinou commented 2 years ago

@mrjustaguy Did you check if this functionality is already provided in the master branch, or did you only check in 3.x?

mrjustaguy commented 2 years ago

I checked specifically in Master, and didn't in 3.x.

To elaborate, currently you seem to only be able to directly "set" values, however while this would allow for a fairly simple implementation of this if it were done using vectors, by just taking the current rotation and adding whatever rotation you want to it, using quaternions makes that a bit more complicated and more difficult for users with not as robust math background.

Also, a function like "Rotate_Bone_Local" would be consistent with the current "Translate_Object_Local" and "Rotate_Object_Local" and "Scale_Object_Local" from Node3D. Adding Translate and Scale to Bone personally doesn't seem to useful for most cases, as most often bones are just rotated, but functions for that could be added for consistency, however they're easy to get such a result with as they're just normal vectors, nothing too exotic.

fire commented 2 years ago

A bone's pose (like animation) rotation is defined by it's roll orientation, given this surprising property, rotating the bone by the expected parent to child convention requires code to do parent to child bone roll orientation.

I have a script for this and it was a lot more than a few lines. Want this, but this proposal needs work on the api.

The simplest way you can do this currently is:

  1. get the global bone pose
  2. directly rotate it
  3. set global bone pose
fire commented 2 years ago

Also in Skeleton3D:

● Basis global_pose_z_forward_to_bone_forward(bone_idx: int, basis: Basis)

Rotates the given Basis so that the forward axis of the Basis is facing in the forward direction of the bone at bone_idx.

This is helper function to make using Transform3D.looking_at() easier with bone poses.

fire commented 2 years ago

Can close the proposal if this satisfies your uses?

mrjustaguy commented 2 years ago

It doesn't, the goal is to simplify doing simple operations on bones in scripts. This means the bone operations should have the same functions like Nodes do. Think of rotate_object_local and rotate_y in node, and just apply that thinking to bones

Example for rotate_object_local in bones would be rotate_bone_local(Axis:Vector3, Rotation:Float, Bone_Index:Int) that would rotate the given bone, by the given amount by the given axis, locally the same way as rotate_object_local would

clarence112 commented 1 year ago

I'm seconding this proposal. Manipulating bones in scripts is annoyingly convoluted currently.

Calinou commented 1 year ago

@clarence112 Please don't bump issues without contributing significant new information. Use the :+1: reaction button on the first post instead.