# Automatically “routing” a tube through a confined space

I have an irregular curved funnel-like 3D space and I need to "lay" a "tube" in it so it is goes through the "middle" of the funnel.

The sketch below shows a 2D section of a possible scene (the "tube" is shown in red, black represents "walls" of the space, blue is just a place where the "tube" is attached.):

Is there a way to get Blender "route" the tube through the space (semi)automatically?
By semi-automatically I mean manually selecting possible additional constraints (objects/points/...) or entering some parameter values and then letting the automated process do the rest.

I know I can use Curves to draw a path and manually adjust it so it fits, however, I would like to automate it as much as possible because the process will have to be done many times in different spaces (but generally similar in shape).
(I also know how to make a "tube" by adding a bevel to the curve as well as how to use hooks to modify it.)

Could this be done by first creating a curve (with high enough resolution) and then making it "snap" to the "average" of the enclosing space ...?

I'm new to Blender and 3D modelling but I'm quick in acquiring new skills.

• I have updated the question to emphasize the point that I'd like to make the process of routing as automated as possible. Thank you Mentalist and PaulGonet for trying to hep, I appreciate it, I learned something from each of you. – spacer Feb 8 '16 at 17:10
• What you are looking for is somewhat mathematically complex but of course possible through scripting. Here and here are some approaches. Laplacian smooth and Decimate are implemented in blender as modifiers and could be used as a starting point. – user2859 Feb 8 '16 at 17:33
• If you know the mathemathic function which describes that curve it should be possible to use Add Mesh: Extra Objects addon with that function entered in value field, like in this question. It won't be possible to edit that created mesh afterwards in this way as this is only possible to change using Last Operator menu though. – Mr Zak Feb 8 '16 at 18:32
• Thanks @user2859, that is interesting material, I'll look if there is a way to use it. – spacer Feb 8 '16 at 18:47
• @MrZak, thanks, but unfortunately the funnel in this case cannot be described with a mathemathic function so cannot the resulting curve. Besides, if I had that, I would not need to route it. That is, unless i misunderstood your comment ... – spacer Feb 8 '16 at 18:53

After giving this some thought, I have come up with another approach that might be a solution for you. It does require that the mesh of your space has quad topology, so that edge rings which flow along the tunnel can be selected and scaled in.

Of course, if you don't have control over the initial topology you will have to retopo first. I believe the RetopoFlow add-on would be the fastest way, if you need to do this.

## Select and Scale your Edge Rings

Press ShiftD to make a duplicate of it, and move (M) it to a different layer.

In Edit Mode, with Edge Selection enabled, select only the edge rings. This can be done from the menu: Select > Edge Rings, or with the shortcut ShiftCtrlAltRClick. Do this until every edge ring is selected.

Set your Pivot Point to Individual Origins. This causes each selected edge loop to shrink toward its individual center when you scale them down, creating a path that passes through the center of the mesh.

Scale your edge rings down to zero. (S,0,Enter)

Press W > Remove Doubles to get rid of extra overlapping geometry.

## Smooth it Out

In Object Mode, add a SubSurf Modifier to your object to smooth it, if you want it to be smooth. Adjust the subdivision levels as desired.

Apply the SubSurf Modifier.

Convert your Mesh object to a Curve object. (AltC)

Above: A wireframe display of the original Mesh object, and the new Curve object, with both layers made visible together.

That's it!

• Alternative to RetopoFlow would be shrink wrapping your quad geometry to the tunnel. – Jaroslav Jerryno Novotny Feb 11 '16 at 11:03
• @Mentalist, this does looks like a solution although I'll need to look into the retopo thing as the funnel shape I have is rather "organic". I can't do it today though, not sure about tomorrow. Will report on results as soon as I try it out. – spacer Feb 11 '16 at 21:43
• @spacer Cool, please let us know how it works out for you. I am a fan of the Shrinkwrap method that Jerryno mentioned as well. – Mentalist Feb 12 '16 at 2:57
• @Mentalist, Jerryno, I have finally found some time to test this and it looks very promising. However, I'm having two problems: A) shrink wrapping nicely around the curving funnel (I get "artifacts" spanning empty space outside the funnel) and B) selecting all edge loops automatically (without having to pick them out by hand one by one). Can you, please, give me some hints toward solving that? – spacer Feb 19 '16 at 0:54
• @spacer Tip#1: Model your retopo mesh while the Shrinkwrap Modifier is on it and set it so you can see the effects in Edit Mode. By extruding one step at a time, and checking your modifier results along the way, you won't run into surprises later. Tip#2: Set the Shrinkwrap Modifier's Mode to Project, and the Direction to both Positive and Negative. – Mentalist Feb 19 '16 at 12:51

Your diagram gave me a chuckle. :-)

## Beveling Curves

There is a handy Bevel feature you can enable with Curve objects to get the effect you are describing.

In Object Mode press ShiftA to Add > Curve > Bezier

Press Tab to switch into Edit Mode for the Curve.

Then in the Curve Context, increase the Bevel Depth. Set the Fill mode to Full to make it round like a tube. Increase the Resolution so it will become rounded. Raise the Resolution of Preview U if you want to smooth out the length of the curve.

If you then need to convert this into a Mesh object you can do this from Object Mode by pressing AltC and "Convert to Mesh".

## Taking it further

If you need something more complex than a simple wire or pipe you can experiment with Taper and Bevel objects to further shape your Curve. Or you can even model a custom Mesh object and use the Curve Modifier to stretch it along a Curve.

• thank you, but I know about the Bevel feature (I will edit the question to clarify that). What I need is to - automatically or with some manual "help" - "route" the tube to nicely follow the funnel. Maybe something along the idea of snapping the curve to "average" of the enclosing shape? – spacer Feb 8 '16 at 15:05
• Oh, and yeah, maybe I should have added another bend so the diagram would look more like elephants front appendage rather than the middle one ;) lol – spacer Feb 8 '16 at 15:07

You may easily control the tube using Hooks.

Select the Curve and bevel it using Bezier Circle.

Now select the curve handle's center and press Ctrl+H-->Hook to New Object. Repeat the process with other handles. Now transforming, rotating and scaling the hooks you have a full controll over your tube.

• Thank you @PaulGonet, I'm aware of hooks too. I realize now that I should have mentioned that in the question too, sorry. The post is useful though, I'm learning :) What I actually need is to automatically fit the tube within the funnel, then tweak it if necessary. – spacer Feb 8 '16 at 16:59