-
-
Notifications
You must be signed in to change notification settings - Fork 15
Add "set_bone_position" API method #124
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -97,6 +97,8 @@ namespace dmSpine | |
|
||
bool CompSpineModelGetBone(SpineModelComponent* component, dmhash_t bone_name, dmhash_t* instance_id); | ||
|
||
bool CompSpineModelSetBonePosition(SpineModelComponent* component, dmhash_t bone_name, Vectormath::Aos::Point3 position); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The correct type is |
||
|
||
} | ||
|
||
#endif // DM_GAMESYS_COMP_SPINE_MODEL_H |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -679,6 +679,47 @@ namespace dmSpine | |
return 0; | ||
} | ||
|
||
/*# Set world space bone position | ||
* Note that bones positions will be overwritten by active animations and constraints(IK, Path, Transform...), only change positions of bones that is not affected by those. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Correct tag for notes is |
||
* | ||
* @name spine.get_go | ||
* @param url [type:string|hash|url] the spine model to query | ||
* @param bone_id [type:string|hash] id of the corresponding bone | ||
* @param position [type:vector3] position in world space | ||
* @examples | ||
* | ||
* The following examples assumes that the spine model has id "spinemodel" and it has bone named "crosshair" | ||
* | ||
* How to set bone position to mouse position("crosshair" could be IK target for example): | ||
* | ||
* ```lua | ||
* function on_input(self) | ||
* if action_id == nil then | ||
* spine.set_bone_position("#spinemodel", "crosshair", vmath.vector3(action.x, action.y, 0)) | ||
* end | ||
* end | ||
* ``` | ||
*/ | ||
static int SpineComp_SetBonePosition(lua_State* L) | ||
{ | ||
DM_LUA_STACK_CHECK(L, 0); | ||
|
||
SpineModelComponent* component = 0; | ||
dmMessage::URL receiver; // needed for error output | ||
dmGameObject::GetComponentFromLua(L, 1, SPINE_MODEL_EXT, 0, (void**)&component, &receiver); | ||
|
||
dmhash_t bone_id = dmScript::CheckHashOrString(L, 2); | ||
Vectormath::Aos::Vector3* position = dmScript::CheckVector3(L, 3); | ||
Comment on lines
+711
to
+712
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We only do casts if we know it's the correct type. You can create a Point3 like so: |
||
|
||
if (!CompSpineModelSetBonePosition(component, bone_id, (Point3)*position)) | ||
{ | ||
char buffer[128]; | ||
return DM_LUA_ERROR("the bone '%s' could not be found in component %s", lua_tostring(L, 2), dmScript::UrlToString(&receiver, buffer, sizeof(buffer))); | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
/** Deprecated: set a shader constant for a spine model | ||
* Sets a shader constant for a spine model component. | ||
* The constant must be defined in the material assigned to the spine model. | ||
|
@@ -780,6 +821,7 @@ namespace dmSpine | |
{"set_ik_target_position", SpineComp_SetIKTargetPosition}, | ||
{"set_ik_target", SpineComp_SetIKTarget}, | ||
{"reset_ik_target", SpineComp_ResetIK}, | ||
{"set_bone_position", SpineComp_SetBonePosition}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In our api, we use "world" in the names (See go.get_world_position()) That, or make it accept local space coordinate. |
||
{"set_constant", SpineComp_SetConstant}, | ||
{"reset_constant", SpineComp_ResetConstant}, | ||
{0, 0} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Our code code convention here is
const dmVMath::Point3& position)