Hexagon tiling with ICE


hexagon_tiling_rr
Here’s a relatively simple ICE tree that arranges hexagons on the XZ plane. The “difficult” part was creating the arrays of position coordinates. For that I used the standard modulo technique. It’s funny, it all makes perfect sense when you’re plugging stuff together, but afterwards it’s hard to make heads or tail of what you did 🙂
hexagon_tiling_1

To understand what’s going on here, it helps to look at the final arrays that are built:
hexagon_tiling_show_values

The math for arranging the hexagon tiles is pretty simple. I started with a simple test point cloud to make sure I understood what I needed to do. After that, it was just a question of setting up the arrays.
hexagon_tiling_testing

If you want to take a look at the ICE trees, here’s some compounds. Note that this isn’t a finished piece of work. It’s more of a draft version. For example, my hexagon has a side length of 5 and that’s hardcoded into the ICE tree right now.
Hexagon_Tiler.xsicompound
Hexagon_Math_Tester.xsicompound

ICE: Building a regular hexagon


Let’s build a regular hexagon!

In this example, I take the vector (5,0,0) and rotate it by 60 degrees, then 120, then 180, and so on, until I have the 6 points of the hexagon. In ICE, that equates to getting an array of rotations, stuffing that into Rotate Vector, and getting an array of positions back.

Notice how the length of each side is the same (5), as is the distance of each point from the local origin.
RegularHexagon

Before I jumped into building the polygon, I first did a quick test with a point cloud, to make sure I understood how to add points in the right places. In general, I think it’s good practice to do some kind of “proof of concept” before you really dive into the details.
RegularHexagon-prelims

Screenshots of the week


LKLightning 2.0 Tutorial 01 – Swirling7

Display debug per-object attribute on distant point cloud
by Fabricio Chamon
DebugAttributeAtBBox

Moving cached geometry
by Alok Gandhi
jhddjdgc

Reflections
by NNois
Reflection

Turbulize Null position
by Helli
nullposition

Splitting edges
by iamVFX, julian johnson
SplitEdgeEqually
SubdivideEdgeByLength

Finding he indices of negative values in an array
by iamVFX
FindIndicesOfNegativeValuesInArray

Saturday Snippet: Getting the object under the mouse in a context menu callback


For most context menus, the Target attribute contains both the selected objects (if any) and the object under the mouse.

def MyCustomMenu_Init( in_ctxt ):
    oMenu = in_ctxt.Source
    oMenu.Filter = "camera"
    oMenu.AddCallbackitem("Custom Camera Tool","MyCameraTool")
    return true

def MyCameraTool(in_ctxt):
    obj = in_ctxt.GetAttibute("Target")
    Application.LogMessage(obj)

I’m pretty sure I’m the one who dug up that info and put it in the docs (on the Menu Item Callback page). I did not, however, write this bit, which to my ear does not sound good at all:

If your menu is attached to a contextual menu, the currently selected objects are passed in to your callback. The target object under the cursor is also passed in as part of the selected objects. However if no objects are selected, then only the target is passed in. The objects can be retrieved through the Context.GetAttribute method with “Target” specified as the value for the AttributeName parameter. The selected/target objects are not passed in to the callback of a custom menu item attached to a regular menu.

I prefer something more like this:

For context menus, the callback gets the currently selected objects and the object under the mouse. You can get these target objects from the Target attribute with Context.GetAttribute.

Splitting an edge into equal-length new edges


Here’s the basic idea of how to split an edge into N equal-length new edges. Notice how I work backwards (in the sense that my split ratio decreases). That way I don’t know have to know (or care) about the new edges. I just keep splitting the same edge, whose EdgeIndex I already know.

SplitEdge0

SplitEdge1

SplitEdge2

SplitEdge3

Based on that observation, here’s a rough draft of an ICE tree that takes an edge of length N, and splits it into N equal-length edges.

SplitEdges