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

simulation curves - cubic vs catmull #218

Open
Neon22 opened this issue Dec 23, 2024 · 3 comments
Open

simulation curves - cubic vs catmull #218

Neon22 opened this issue Dec 23, 2024 · 3 comments
Assignees

Comments

@Neon22
Copy link

Neon22 commented Dec 23, 2024

I see some notes on a desire to improve the quality of curves for the thread simulations.
I haven't got a cut and paste answer for you, but:

When using catmull, its going to be difficult - even if you use tension to try to control the sharpness of the curve.
A more stable solution would, IMHO, be to use cubic Bezier curve. (there's a quick way to calc the control points)

In Three.js this is a CubicBezierCurve3 It has two control points instead of none in a catmull (or one for a quadratic).
The use of two will give you the control you need to make the threads behave much better.
The format is CubicBezierCurve3( pt1, c1, c2, pt2). The c points are simply calculated. You already have the pt points.
The full curve has to become a curvepath with a new CubicBezierCurve3 for each of the points in your current catmullrom curve.

Thread style layout:

Here's a diagram showing "the" layout to simulate a thread in warp or weft. - using an online bezier curve toy. I marked it up for two curves using three primary datapoints (I think your simdata is in this P1,P2,P3 form)
The two curves are completely separate. You will need to use a Three.js curvepath entity which can have a sequence of curves in it.
The diagram shows curve 1 and curve2. The pt1 of curve2 uses a vector3 copy of pt2 from curve1.

cubcbezier thread sim
It comes from here - where you can play with values (its a difficult UI but doable)

Control points:

The pt1, pt2 are the same points you have in your simulation (I am pretty sure this is right)
Then you need to calculate the control points. This might seem daunting but its luckily quite simple:

  • The diagram shows the trick
  • you need to put the control points directly above and in line with each other.
  • The distance they go in Y can be determined by the thickness of the tube(thread) you are using.
    • I have used thin blue lines rather than simulate the thicker yarn line.
  • The thread will form a convex hull inside this height (not exceeding it). 99% of time this is what you want for woven threads.
  • if you make this Y_cpt_offset be a variable you can calculate it in the scope of a given scene. (E.g. 3x Yarn diameter)
  • Later on you could perturb this control point to simulate deflected double weave etc....

Here's a relevant snippet from your code:

if(start_vtx !== null)
     pts.push(new THREE.Vector3(start_vtx.x, boundary_vtx.min_y-10, -start_vtx.z));
in_bounds_vxts.slice().forEach(vtx => {
     if(vtx.x !== undefined) pts.push(new THREE.Vector3(vtx.x, vtx.y, -vtx.z));
});
if(end_vtx !== null)
     pts.push(new THREE.Vector3(end_vtx.x, boundary_vtx.max_y+10, -end_vtx.z));

if(pts.length !== 0){
     const curve = new THREE.CatmullRomCurve3(pts, false, 'catmullrom', .1);

So you'd be adding curves to a curvepath. Each curve would be a CubicBezierCurve3 with reused/shared end and start pts.
And each curve would have two control points added with simple Y_cpt_offset added to those same end/start points.

Hope this helps. Sorry I could not set my machine up to compile this and so submit a PR instead of this message.

@Neon22
Copy link
Author

Neon22 commented Dec 23, 2024

cubcbezier thread sim 02
Here's a better sim showing thread diameter related to control point height.

You can, of course, add an on-screen control to exaggerate it for clarity (or a thread diameter slider might be even better to show the path of a complex route)

@Devendork
Copy link
Member

Thank you so much for this suggestion. I really appreciate it. The simulation features have been on hold for a bit while I prep and bug fix other parts of what is now the beta, but will soon be the official branch of AdaCAD. I'm hoping in jump back into simulation rendering and parsing in Fall 2025. I know....it feels a way off...but that might be the next time I have the space and attention to dive back into it.

@Neon22
Copy link
Author

Neon22 commented Dec 23, 2024

No problem - Just thought I'd leave this here for you when you're ready. Cheers...

@Devendork Devendork self-assigned this Dec 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants