[Closed] Connecting polys between tree branches
Currently I’m looking for ways to model a tree in max 6.
I’ve found Tree Maker 5.0 and it’s really helpful, but the only problem is that it doesn’t make very good connections between the braches. Also it’s all triangles.
Now what I want to do is to make the connections myself.
What I do is, I let Tree Maker make the branches (all 4-sided), then I use the Quadrangulate script to make those tri’s into quads. Now I’m ready to connect the branches. I’ve used the connect compound object, but that one also creates triangles. The fastest way I know of to do it is just creating the polys myself for all the branches, and that’s not fast at all
Is there a script that can automate this process?
Basicaly something that will:
- connect the first two ‘branches’ leaving one poly out on the side of the third branch;
- connect the third branch with the rest;
- stay clear of any tri’s.
See the attachment for the kind of connection I made. Though the boxes won’t be as nicely positioned as this, most of the times.
When I have the basic tree I’m going to use Bobo’s Hairy Teapot setup for the leaves which will make it easy for them to be affected by wind and can very probably even be made to twirl down to the ground
If I can get the connections to work easily I’m going to make a tutorial about all this, because I think many people would like to see a very realistic, easy to set up tree with the use of free scripts.
BTW Quadrangulate and Tree Maker seem to work nicely in max 6.
Thanks!
Here’s another conection that looks more natural and will smooth out better.
I’m looking into MaxScript now to see if I can get the connections to work.
If anyone has any pointers or suggestions that would be great.
I’ve figured out the steps to take. Now to actually code it. I think I have the basics now, but it will require a lot of research before I have something that works as this i the first time I’ve actually tried to write a script…
Anyway, see the attachment for reference. It is the same setup as my previous attachment, but without the connection. The branch on the right is the lower branch in this attachment.
The branches are named and numbered, for instance the lower one would be named Tree_brnch_03, the one on the right *_05 and the one on the left *_06.
Branch physical size decreases as numbers increase. So the lower is the largest and the one on the left is always the smallest. The smallest one always has the largest number and vica versa.
So what has to be done is to make 3 polys between verts 8 and 2 of branch “X” and 7 and 1 of branch “Y”. These connections have to be made all around, but leaving one poly out on the side of the smaller branch. From there polys have to be made to connect the smaller branch (“Z”). See the attachment in my previous post.
I think I know how to make a poly from a vertex array using polyOp.createPolygon, but the problem is still how to create that vertex array, especially since there are multiple objects. I know the logical ordering of name numbers helps, but now to figureo ut how to use it…
Suggestions are welcome, also if you know how to better sub-d model that branch connection.
Question:
After brutally tormenting my brain to understand the basics of MaxScript I got the following (not yet finished) code:
– Put the objects in an array and sort them according to their names. This way we know
– which is which.
looseTrunks = sort( for i in selection collect i.name )
baseBranch = getNodeByName looseTrunks[1]
bigBranch = getNodeByName looseTrunks[2]
smallBranch = getNodeByName looseTrunks[3]
– Make vertex arrays using specific vertices as they are always numbered this way.
rightSideVArray = #()
append rightSideVArray baseBranch.verts[#{8,2}]
append rightSideVArray bigBranch.verts[#{1,7}]
leftSideVArray = #()
append leftSideVArray baseBranch.verts[#{4,6}]
append leftSideVArray smallBranch.verts[#{5,3}]
topSideVArray = #()
append topSideVArray smallBranch.verts[#{1,7}]
append topSideVArray bigBranch.verts[#{5,3}]
– Create an empty mesh and convert it to editable poly.
conn = editable_mesh name:(uniquename “NewConnection”)
convertTo conn (Editable_Poly)
– Create the polygons.
polyop.createPolygon conn rightSideVArray
polyop.createPolygon conn leftSideVArray
polyop.createPolygon conn topSideVArray
This would’ve had to create polys on the sides of the branches, but instead I got this:
– Unable to convert: #verts(2 : $Editable_Poly:Tree_brnch_03 @ [23.506683,-13.047130,148.692566]) to type: Integer
– Unable to convert: #verts(4, 6 : $Editable_Poly:Tree_brnch_03 @ [23.506683,-13.047130,148.692566]) to type: Integer
– Unable to convert: #verts(1, 7 : $Editable_Poly:Tree_brnch_06 @ [73.287422,-32.900421,247.508469]) to type: Integer
I figured this is caused by the array; in it are the vertices of those objects instead of just positions. I tried a copy <array> #nomap, but that didn’t help.
Does anyone have an idea as to how to do this?
Thanks.
You’re trying to create polygons in an empty polymesh that has no verts yet. You’ll need to create the verts before making any polygons. Call meshOp.getVert() on the verts you need to copy from the branches, and use polyOp.createVert() to make new verts in the empty polymesh in the same locations. Be very deliberate about the order you create them in, so that you can easily remap the structure you’ve determined to the new verts (which will now be numbered with ID’s 1 through 12).
Once you have created all the verts in the connection object, you can start creating polygons. But be aware that polyOp.createPolygon() is simply expecting an array of vertex indices. For example, polyOp.createPolygon conn #(1, 2, 3, 4) would create a polygon using verts 1-4 of conn.
Your idea seems to be to sort through branch names to get the branch structure of the tree, but I don’t think this will be an effective solution. The author of the tree script was wise enough to parent the branches logically, so you’ll probably want to consider a way of traversing the branches as a heirarchy. Just something to keep in mind if you haven’t already figured this out:)
RH
Thanks for the info LFShade! That was very helpful
I understand now how to create the connections, I’ll try to get it to work tomorrow.
This script is based on the user selecting a branch junction right now. I’ve looked into the branch order, but it’s still a puzzle, one eventually I hope to solve though. Looking though the Tree Maker script again to see if I can find some clue as how they’re parented.
The branches are numbered. And the number order seems to follow the path of the branch with the lowest number, when at the end the numbers go back down the branches to fill in the remaining braches while going up the branches again to do so. Still makes sense?
Tricky one this… ah well.
The structure is quite simple, actually. The following function demonstrates how to use recursion to traverse the tree structure in order to build your connections. Supply any branch node to this function and “connections” will be made at every branch point downstream from the supplied node (this demo only places dummies). Obviously, you can do the whole tree in one go by supplying the first branch of the tree – the trunk object.
fn buildConnection base_branch =
(
case base_branch.children.count of
(
-- no children means end of branch!
0: ( return OK )
-- one child probably means no connection is needed,
-- like at the base of the tree. But we still need
-- to check that there are more branches downstream!
1: ( buildConnection base_branch.children[1] )
-- two children means a connection is needed!
2:
(
big_branch = base_branch.children[1]
small_branch = base_branch.children[2]
-- build your connection here.
-- You can supply your own code;
-- I'm just going to place a dummy
-- at each connection point to
-- demonstrate that the recursion
-- is working:)
dummy pos:( (big_branch.pos + small_branch.pos) / 2 )
-- this is the part that does the recursion.
-- simply call this function on each of the
-- current base_branch's children, and so on
-- up through the heirarchy
for b in base_branch.children do buildConnection b
)
)
)
If you’ve already hammered out how to build your connections, then this should get you most of the way to your goal. Good luck!
RH