Skip to content

Commit 903a62e

Browse files
Update README.md
1 parent 421c002 commit 903a62e

File tree

1 file changed

+81
-0
lines changed

1 file changed

+81
-0
lines changed

README.md

+81
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,84 @@ The piston are generated regardless of the postion of the given 3-joints chain.
5858

5959
##### Tree graph generated
6060
![001](https://user-images.githubusercontent.com/100163862/172805145-a6655b6c-e516-4495-b551-b4d2bf30bde8.PNG)
61+
62+
#### Quick Update
63+
64+
Maya 2023 update added Trigonometry nodes, custom nodes and complicated node setups are not required anymore to have the clean formula with nodes.
65+
If you are working on maya 2023 this script may not be relevant anymore.
66+
67+
### Houdini Equivalent
68+
69+
I am now in love with houdini, This piece of software make it really easy to create technical animation like this using its high perfommance compiled VEX language.
70+
71+
This is the result in houdini, very usefull since it works in evry directions
72+
73+
![piston](https://github.com/DaBaptisteFraboul/Maya---Piston-rig-plugin/assets/100163862/bd4505d8-a4f7-4ac4-ab17-0903577c7d4c)
74+
75+
This is the node network and the VEX code in the `PistonSolver` Attrwrangle node :
76+
77+
![image](https://github.com/DaBaptisteFraboul/Maya---Piston-rig-plugin/assets/100163862/0859f82b-0da8-469e-8477-a979cc38f553)
78+
79+
```C++
80+
// Setup initial data
81+
vector piston_dir, wheel_center, piston_contact, shaft_pivot;
82+
vector up_vector = normalize(chv("Up_vector"));
83+
float offset = radians(chf("Starting_rotation_offset"));
84+
float rotation_angle = radians(chf("Rotation_Angle"));
85+
86+
// TODO: Clean the code here
87+
wheel_center = point(0, "P",0);
88+
shaft_pivot= lerp(point(0,"P",0),point(1,"P",0), chf("Lerp_test"));
89+
piston_contact = point(1, "P",0);
90+
piston_dir = normalize(piston_contact - wheel_center);
91+
float crank_length = length(piston_contact-shaft_pivot);
92+
float connection_length = length(shaft_pivot);
93+
94+
// Formula implementation of crank shaft system
95+
// Find a way to accelerate computation
96+
float expension = connection_length* sin(rotation_angle+offset) + sqrt(pow(crank_length,2) - pow(connection_length,2) * pow(cos(rotation_angle+offset),2));
97+
98+
// Create points
99+
int pt_shaft = addpoint(geoself(), shaft_pivot);
100+
int pt_piston = addpoint(geoself(), piston_contact);
101+
102+
103+
// Crank Rotation using matrix to orient with the up vector
104+
vector perp = cross(piston_dir, up_vector);
105+
106+
matrix3 mat= ident();
107+
rotate(mat, rotation_angle, perp);
108+
109+
110+
// New positions
111+
vector new_pos = shaft_pivot * mat;
112+
vector piston_new_pos = piston_dir * expension;
113+
114+
115+
// Modify position
116+
setpointattrib(geoself(), "P", pt_shaft, new_pos, "set");
117+
setpointattrib(geoself(), "P", pt_piston, piston_new_pos, "set");
118+
119+
//Modify normal
120+
121+
setpointattrib(geoself(), "N", 0, normalize(new_pos-wheel_center), "set");
122+
setpointattrib(geoself(), "N", pt_shaft, normalize(piston_new_pos-new_pos), "set");
123+
setpointattrib(geoself(), "N", pt_piston, normalize(piston_dir), "set");
124+
125+
126+
//Add primitives
127+
int prim_wheel = addprim(geoself(), "polyline", 0, pt_shaft);
128+
int prim_shaft = addprim(geoself(), "polyline", pt_shaft, pt_piston);
129+
130+
setprimattrib(geoself(), "name", prim_wheel, "Wheel", "set");
131+
setprimattrib(geoself(), "name", prim_shaft, "Shaft", "set");
132+
133+
134+
//Add name
135+
setpointattrib(geoself(), "name", 0, "Wheel center", "set");
136+
setpointattrib(geoself(), "name", pt_shaft, "Shaft" , "set");
137+
setpointattrib(geoself(), "name", pt_piston, "Piston", "set");
138+
139+
```
140+
141+

0 commit comments

Comments
 (0)