-
-
Notifications
You must be signed in to change notification settings - Fork 35.5k
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
Drawing a long 3D tube #905
Comments
Oh... uhm... @zz85: I guess the shape extrusion should tilt the shape every step in the direction the step is extruding? |
right now extrudes only extrude perpendicularly only its z-axis, that's why only a 2d path is needed. extruding with its angle adjust + via a 3d path is a feature that I hope to add sometime... (if i could finish my current demo first :S) however, i think its possible to have a thick line with custom attributes. see http://alteredqualia.com/three/examples/webgl_custom_attributes_lines.html and #681 |
I would also really like this functionality. If is not implemented yet do you know of a simple-ish way of doing it by hand (custom vertices for a cylinder maybe)? |
hmm.... I almost couldn't remember how See if this extrusion works, I can probably tweak |
This is great, but I also need its angle to adjust as it is extruded EDIT: So would that involve at each step along path calculate rotationMatrix and then multiply each point in the shape by that matrix? |
could you explain what is its angle adjusted as its is extruded, or are |
@zz85 The way to do this is to hack I think what @miningold is talking about is he wants each ring to be orthogonal to the tangent vector of the centerline. One just needs to replace the Well... then there is the issue of open vs. closed ends... and whether it is a closed or open path or not.... :-) |
Wow, thanks, I didn't think about that, I'll give it a try. My paths are going to be closed, and I think I can figure something out for the ends. EDIT: My paths are going to start at some point A and end at some other point B... not sure if that is called closed or open. |
Alright I am making some progress but I have run into two problems:
I don't have enough experience with trigonometry to identify what is causing these probelms. So help (and explanations) would be lovely. Here is a link to what I have: |
Here is a fix, sort of. http://jsfiddle.net/L6wuG/6/ . This fix may prevent the twists. This is a tricky problem, and it will take work to make it production quality, but perhaps it can work for your purposes. Kinks will be a problem. A path that runs vertically will be a problem, too. Good luck. ;-) |
This is awesome thanks. I am ok with the kinks, but I definitely will need the path to run vertically. Do you have any suggestions for fixing this, or somewhere I could look (I don't know how to even phrase this for a google search). EDIT: Another problem is when the tangent vector transitions from positive x-values to negative x-values (if z is unchanging). This causes the bitangent vector to point in the opposite direction. The problem is I don't know how to detect that in 3D space (when z is changing). |
Sorry, no other ideas at this point. I think your time is better spent understanding the 10 or so lines of code that calculate the variable At that point you will be in a better position to come up with a specific solution for your particular situation -- even if it doesn't work in the general case. |
Alright, I've worked on it a bit more. I've gotten close, but every time I fix one edge case, another one appears. Here is my progress: The interesting thing is if I go back to setting the up vector to p1 + p2 then almost all of my problems disappear: I've determined that the problem with up = p1 + p2 is when p1 and p2 form a straight line through the origin. This makes up and tangent equal, which then screws up the cross products. |
Yes, I know. But congratulations on your progress! I tried hacking something up myself, but no answers... Setting up = p1 + p2 worked for the torus knot because it wraps around the origin and never passes through it. If you are creating closed curves, can you restrict them to wrapping the origin and use the same trick? |
okay, starting to understanding what you guys are saying :D @miningold you can try |
I am going to be using open curves, so I can't use that hack I guess |
oh okay i understand, the "closed" here again refer to different things >.< |
Alright to clear things up, I don't want my curve to loop. I want it to |
So I found a good enough solution. I am using up = p1 + p2, then I find the binormal (previously known as bitan). If the binormal is equal to the zero vector then I set the binormal to the previous binormal. It will cause a twist but it prevents the tube/pipe from collapsing. |
Also, I discovered that this techniques is a slight variation of the Frenet–Serret formulas |
@miningold Your fiddle collapsed on me. Here is a hack. http://jsfiddle.net/L6wuG/19/. It looks like it will work. It tries to prevent twisting by using the normal computed for the previous ring. Have a look. No guarantees, though.... Provided just in the interest of helping you... :-) |
@WestLangley This is awesome, thanks. I would never have thought of it. |
looks great! i've gotta learn about those FrenetSerret formulas sometime! |
@WestLangley I believe the hack you provided will also break if p1 and p2 end up being parallel for the very first iteration. |
@miningold It was only proposed to get you through the night. It is not production quality. |
finally i managed to wrap my head around those Frenet–Serret and TNB frame stuff!! Its seems like all those twists are caused by some flipping of normals to the tangents of the cat-mull rom splines. The solution, like what was done, uses the moving Frenet frame technique - pretty cool :) I've modified the fiddle again, my approach is to use the derivative of the normalized tangent for the 1st iteration, then use the moving Frenet frame. I hope this works better. |
Hmm, actually I'm not certain that solves the first iteration problem. This version uses a arbitrary referencing binormal for the first iteration. |
Seems like the referencing frenet frame method is also called the Rotation Minimizing Frames (RMF) :) |
@zz85 You are correct. This has been a long-standing problem. Check out this: http://www.cs.cmu.edu/afs/andrew/scs/cs/15-462/web/old/asst2camera.html It is the same concept I proposed in my hack #19, which seems to work, except for edge effects. Here it is again: http://jsfiddle.net/EBtfS/ Maybe the CMU method will work better -- I havent't had time to investigate... |
@WestLangley yes, the CMU's method is the one I used for my last 2 fiddles ( Nice debugging arrows :) I was writing my helper arrow methods just now for investigating why frenet frame were so twisted too. I think its more straight forward for a tube (as long N and B are perpendicular to T). It will be interesting once we add custom shapes for path extrusion. |
nice work @WestLangley ! i see some geometry gymnastics going on :) i've started to merge your changes and would be updating the examples and check if its working well.. |
@WestLangley i update my example a little to play around with the extrusions. zz85/three.js@70ee0cf...72f462e somehow the closed end doesn't stitch in certain cases, but i'm not too sure... |
@zz85 you have 2 forms of the variables |
@WestLangley i've fixed the checkbox issue. some shapes work well, but some shapes doesn't... |
@zz85 Your |
nice catch @WestLangley ! turns out that the browser seems to be overwriting the |
now that I'm using Perhaps... var frames = new THREE.SplineFrames(spline, segments, closed);
var tangents = frames.tangents[];
var normals = frames.normals[];
var binormals = frames.binormals[]; Somehow I'm still a little torn about how the initial normals should be computed for spline extrusion - the orientation effects are perhaps more obvious for a shape extrusion compared to a tube extrusion. Perhaps we could allow the user to define their initial normal plane? Then again maybe more use cases might help, creating too large a shape extrusion geometry might also not be practical due to the large amount of vertices and faces involved. |
@zz85 The parallel transport frames logic in And, regarding |
@WestLangley Its in my branch the link for the the example and ExtrudeGeometry is at here the parallel transport frames is quite specific, but now they would be used in If we do not put it into a new class, we could use still refactor it as a util function like btw, do you have a homepage or twitter? ;) |
I've now done the refactoring to contain TNB calculations in |
thanks. strangely enough, i'm not sure how the code got there, but things felt like it was still running. fixed that section of the code now. |
|
@WestLangley what do non-planar means? would it be better to tessellate the tube into triangles like http://prideout.net/blog/?p=44 ? |
The four vertices of each extruded quad face are not in the same plane.
I think it would. However, I asked this question in #1664, and I don't think there was a conclusion yet. Maybe you can stir the pot a little. ;-) |
okay, i could give it a shot implementing tubegeometry with parametricsurface :) |
tada!! Triangulated |
Looks good! :D |
@WestLangley interesting article about perpendicular vectors :) http://blog.selfshadow.com/2011/10/17/perp-vectors/ |
I started this thread at least 4 months ago and I can't believe the outcome of my original message. Brilliant work, I really appreciate it and I'm sure plenty of other people will or do already. I'm using the tube to highlight a walk route in a walk planner and it almost does what I want it to do. The problem is when the route takes a 90 degree turn (e.g. to cross the road), the SplineCurve3 generates a large arc instead of a sharp turn. Before I create my own path object which ensures that every interpolated point returned is on the direct path between points can anybody suggest a way of doing what I want without creating a new path type of path? BTW - I tried duplicating each of my points in the source to SplineCurve3 and this gives me a better looking route with sharper turns but it contains a little loop (knot) at each turn. |
@ashawthing since |
I know this is a really old issue, but I found a great resource for using quaternions to minimize torsion while retaining periodicity ftp://ftp.cs.indiana.edu/pub/hanson/Siggraph01QuatCourse/quatvis3.pdf |
What is the easiest way to draw a long 3D tube that follows a 3D path.
I have a collection of 3D points that represent a route through my world and I want to highlight it. If I draw it as a THREE.Line it comes out 1 pixel wide which is impossible to see, so I want it as a 3D solid.
I tried extruding a shape along a path but that has a couple of issues - the path is defined in 2D and the shape (which is also 2D) doesn't rotate as it is extruded so I get thin points in my solid.
The text was updated successfully, but these errors were encountered: