Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
akasaki1211 committed Apr 10, 2024
2 parents 2b9a11c + f4e6012 commit 06f50cc
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 27 deletions.
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Let's move the current frame to 1 or later and move the root. The joint-chain sh
> Joint chain must meet the requirements [here](#Requirements-for-Joint).
> 💡**Sample Script**
> [basic_usage.py](scripts/basic_usage.py) is a script to connect bonedynamicsNode to any joint chain. Please select and execute them in order from the root of the joint to the tip of the joint.
> [basic_usage.py](sample_scripts/basic_usage.py) is a script to connect bonedynamicsNode to any joint chain. Please select and execute them in order from the root of the joint to the tip of the joint.
### Attributes to Check
- `Enable` : Turning it off disables all calculations.
Expand All @@ -55,7 +55,7 @@ Select the joint and execute "Bake Simulation" from the "Key" menu. Then delete
### Requirements for Joint
- Rotate should be [0,0,0], with only the Joint Orient having a value.
- Do not edit rotatePivot, rotatePivotTranslate, scalePivot, or scalePivotTranslate.
- Rotate Oeder is only available for xyz.
- Rotate Order is only available for xyz.
- Rotate Axis should remain [0,0,0].
- Leave Inherits Transform checked.
- Leave Offset Parent Matrix at its default value.
Expand Down Expand Up @@ -136,7 +136,7 @@ Branching is possible, but good results are obtained with joints like the one on
![branching_skeleton](.images/branching_skeleton.png)

> 💡**Sample Script**
> [advanced_usage.py](scripts/advanced_usage.py) is a script to connect bonedynamicsNode to any joint chain. Please select and execute them in order from the root of the joint to the tip of the joint.
> [advanced_usage.py](sample_scripts/advanced_usage.py) is a script to connect bonedynamicsNode to any joint chain. Please select and execute them in order from the root of the joint to the tip of the joint.
> - Enable per-section scaling.
> - If place the collider created by expcol as a child of 'collider_grp', to be connected.
> - If duplicate the joint-chain to be simulated and add '_target' to the end of the name, to allow manipulation of the target posture.
Expand Down Expand Up @@ -170,3 +170,7 @@ cmake --build build_2024
## TODO
- [ ] Additional Force
- [ ] Stretchable

## Links
- [Maya用お手軽ボーンダイナミクスノード「boneDynamicsNode」詳細解説 - Qiita](https://qiita.com/akasaki1211/items/ddae66ec2d89d21bb2f4)
- [boneDynamicsNode Demo - Example of integration into FK rig - YouTube](https://www.youtube.com/watch?v=O5cpcMI_Jz0)
Binary file modified plug-ins/2022/boneDynamicsNode.mll
Binary file not shown.
Binary file modified plug-ins/2023/boneDynamicsNode.mll
Binary file not shown.
Binary file modified plug-ins/2024/boneDynamicsNode.mll
Binary file not shown.
Binary file modified plug-ins/2025/boneDynamicsNode.mll
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def create_dynamics_node(
capsule_col_idx += 1

elif colliderType == 'infinitePlane':
cmds.connectAttr(col + ".worldMatrix[0]", boneDynamicsNode + ".infinitePlaneCollider[{}].infinitePlaneColMatrix".format(sphere_col_idx), f=True)
cmds.connectAttr(col + ".worldMatrix[0]", boneDynamicsNode + ".infinitePlaneCollider[{}].infinitePlaneColMatrix".format(iplane_col_cidx), f=True)
iplane_col_cidx += 1

return boneDynamicsNode
Expand Down
File renamed without changes.
31 changes: 10 additions & 21 deletions src/boneDynamicsNode.cpp
Original file line number Diff line number Diff line change
@@ -1,17 +1,5 @@
#include "boneDynamicsNode.h"

#include <maya/MFnNumericAttribute.h>
#include <maya/MFnCompoundAttribute.h>
#include <maya/MFnMatrixAttribute.h>
#include <maya/MFnUnitAttribute.h>
#include <maya/MTime.h>
#include <maya/MVector.h>
#include <maya/MPoint.h>
#include <maya/MMatrix.h>
#include <maya/MTransformationMatrix.h>
#include <maya/MQuaternion.h>
#include <maya/MEulerRotation.h>

MTypeId boneDynamicsNode::s_id(0x7b001);

MObject boneDynamicsNode::s_enable;
Expand Down Expand Up @@ -426,9 +414,10 @@ void boneDynamicsNode::angleLimit(const MVector& pivot, const MVector& a, MVecto
}
}

MVector boneDynamicsNode::distanceConstraint(const MVector& pivot, const MVector& point, double distance)
void boneDynamicsNode::distanceConstraint(const MVector& pivot, MVector& point, double distance)
{
return pivot + ((point - pivot).normal() * distance);
// update point
point = pivot + ((point - pivot).normal() * distance);
}

MStatus boneDynamicsNode::compute(const MPlug& plug, MDataBlock& data)
Expand Down Expand Up @@ -470,7 +459,7 @@ MStatus boneDynamicsNode::compute(const MPlug& plug, MDataBlock& data)
const MVector& rotationOffset = data.inputValue(s_rotationOffset).asVector();

// get rotation offset matrix
const MEulerRotation rotationOffsetEuler(rotationOffset, MEulerRotation::RotationOrder::kXYZ); // Specified xyz
const MEulerRotation rotationOffsetEuler(rotationOffset, ROTATION_ORDER);
const MMatrix roMatrix = rotationOffsetEuler.asMatrix();
MMatrix roInverseMatrix;
if (!roMatrix.isEquivalent(MMatrix::identity))
Expand All @@ -479,7 +468,7 @@ MStatus boneDynamicsNode::compute(const MPlug& plug, MDataBlock& data)
}

// get joint orient matrix
const MEulerRotation boneJointOrientEuler(boneJointOrient, MEulerRotation::RotationOrder::kXYZ); // Specified xyz
const MEulerRotation boneJointOrientEuler(boneJointOrient, ROTATION_ORDER);
const MMatrix joMatrix = boneJointOrientEuler.asMatrix();
MMatrix joInverseMatrix;
if (!joMatrix.isEquivalent(MMatrix::identity))
Expand Down Expand Up @@ -607,11 +596,11 @@ MStatus boneDynamicsNode::compute(const MPlug& plug, MDataBlock& data)
for (int i = 0; i < iter; i++)
{
// distance constraint
nextPosition = distanceConstraint(boneWorldTranslate, nextPosition, distance);
distanceConstraint(boneWorldTranslate, nextPosition, distance);

//sphere collision
for (unsigned int i = 0; i < scCount; i++) {
sphereColArrayHandle.jumpToElement(i);
sphereColArrayHandle.jumpToArrayElement(i);
MDataHandle& sphereCollider = sphereColArrayHandle.inputValue();
sphereCol_m = sphereCollider.child(s_sphereColMtx).asMatrix();
sphereCol_p = sphereCol_m.getTranslation(MSpace::kWorld);
Expand All @@ -628,7 +617,7 @@ MStatus boneDynamicsNode::compute(const MPlug& plug, MDataBlock& data)

//capsule collision
for (unsigned int i = 0; i < ccCount; i++) {
capsuleColArrayHandle.jumpToElement(i);
capsuleColArrayHandle.jumpToArrayElement(i);
MDataHandle& capsuleCollider = capsuleColArrayHandle.inputValue();
capsuleCol_mA = capsuleCollider.child(s_capsuleColMtxA).asMatrix();
capsuleCol_pA = capsuleCol_mA.getTranslation(MSpace::kWorld);
Expand Down Expand Up @@ -675,7 +664,7 @@ MStatus boneDynamicsNode::compute(const MPlug& plug, MDataBlock& data)

//infinite plane collision
for (unsigned int i = 0; i < pcCount; i++) {
iPlaneColArrayHandle.jumpToElement(i);
iPlaneColArrayHandle.jumpToArrayElement(i);
MDataHandle& iPlaneCollider = iPlaneColArrayHandle.inputValue();
iPlaneCol_m = iPlaneCollider.child(s_iPlaneColMtx).asMatrix();
iPlaneCol_p = iPlaneCol_m.getTranslation(MSpace::kWorld);
Expand Down Expand Up @@ -721,7 +710,7 @@ MStatus boneDynamicsNode::compute(const MPlug& plug, MDataBlock& data)
}

// distance constraint
nextPosition = distanceConstraint(boneWorldTranslate, nextPosition, distance);
distanceConstraint(boneWorldTranslate, nextPosition, distance);

// update velocity
m_velocity = (nextPosition - m_position) / dt;
Expand Down
13 changes: 12 additions & 1 deletion src/boneDynamicsNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,17 @@

#include <maya/MPxNode.h>
#include <maya/MTypeId.h>
#include <maya/MFnNumericAttribute.h>
#include <maya/MFnCompoundAttribute.h>
#include <maya/MFnMatrixAttribute.h>
#include <maya/MFnUnitAttribute.h>
#include <maya/MTime.h>
#include <maya/MVector.h>
#include <maya/MPoint.h>
#include <maya/MMatrix.h>
#include <maya/MTransformationMatrix.h>
#include <maya/MQuaternion.h>
#include <maya/MEulerRotation.h>

class boneDynamicsNode : public MPxNode
{
Expand Down Expand Up @@ -84,7 +93,9 @@ class boneDynamicsNode : public MPxNode
//static double getFPS();
double degToRad(double deg);
void angleLimit(const MVector& pivot, const MVector& a, MVector& b, const double limitAngle);
MVector distanceConstraint(const MVector& pivot, const MVector& point, double distance);
void distanceConstraint(const MVector& pivot, MVector& point, double distance);

static const MEulerRotation::RotationOrder ROTATION_ORDER = MEulerRotation::RotationOrder::kXYZ;

bool m_init;
MMatrix m_prevOffsetMatrix;
Expand Down
2 changes: 1 addition & 1 deletion src/pluginMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
MStatus initializePlugin(MObject obj)
{
MStatus status;
MFnPlugin plugin(obj, "Hiroyuki Akasaki", "0.2.0", "Any");
MFnPlugin plugin(obj, "Hiroyuki Akasaki", "0.2.1", "Any");

status = plugin.registerNode(boneDynamicsNodeName, boneDynamicsNode::s_id, boneDynamicsNode::creator, boneDynamicsNode::initialize);
if (!status) {
Expand Down

0 comments on commit 06f50cc

Please sign in to comment.