Category: Manual (page 1 of 2)

Creating Custom Nodes

A great way to extend Archimatix is to create your own node to work with other nodes in the graph. While you can create your own node by saving  a graph you create to the Library or by creating a custom parametric Shape using AX Turtle scripting, you have the most power and flexibility to change the course of AX history by coding a node in c#.

Fortunately, its not that hard to create a node. All you have to do is derive a class from one of AX’s Generator classes. Most commonly, you will subclass Generator2D or Generator3D. You only need to override a couple of functions and, voila, you have created a custom node.

Location, Location, Location

Your script file and icon file can be anywhere in the project’s Asset folder your new node will be discoverable by AX. The only requirement for discoverability of your class is that, in addition to subclassing a Generator, you need to implement the interface ICustomNode. AX uses this Interface to search for custom node classes.

While your node icon can be anywhere in the Asset folder, it will be discoverable only if you name the icon image file according to the convention zz_AXNode-MyNodeName.jpg and place it anywhere in the Asset folder, your node will appear in the right sidebar menu of the node graph window, toward the bottom of the menu.

Making your Node Iconic

If you don’t create your own node icon image, one will be automatically displayed for you in the right sidebar of the node graph. AS a generic icon, the only way a user will know that it creates an instance of your node is by the tool tip that appears when you mouse over it. For this reason, it is probably best to create your own distinctive look!

Your node icon image should be square and saved as a jpg file. If you have named your image file according to the convention above, then it will be displayed in the sidebar at 64×64 pixels so your original image file should be that size or larger. In order to work contextually with the other nodes in the sidebar color-wise, you can use the blank image icon to the right as a background. Once your image is saved, select it in your Unity Project window and, in the Inspector, set the Texture Type to Editor GUI.

Its All What You Node

A custom node written in C# is really just a subclass of a AX.Generator. A Generator has inputs, parameters, generative logic and outputs. The inputs may be Shapes, Meshes, Prefabs, or the output of any AX node. You can determine what output parameters you would like to provide for.

A Generator gives a node a behavior. The actual node class itself  is AXParametricObject, which subclasses AXNode. Before going too deeply into the structure of AX, lets look at an example of what a Generator subclass might look like.

 

 

Texture Mapping

Textures are often thought of in two ways. Either tiled textures that can repeat indefinitely with no apparent seams or texture atlases, where a region in the texture image is exclusive to a polygon in the mesh.

2D Library

We can consider Shapes to be “closed’ or “open.” Of course, any open shape can be closed and any closed shape set to open, but some shapes lend themselves to one or the other. For example, a gear shape, would normally be closed while a molding profile would normally be open.

Closed Shapes

 

Primitives

 

 

 

 

 

Plans

 

 

 

 

 

Sections

 

Open Shapes

Column Profiles the are Lathed

 

Wall Sections the are PlanSwept

 

Moldings that are PlanSwept


Archimatix Turtle Script API

Turtle logic, originally developed as a feature in the Logo programing language, is an important tool for the description of line shapes. Each line of a turtle script draws a 2D line relative to the current position of the turtle cursor. While this may seem conceptually simple, it is a powerful concept in parametric graphics. For example, to draw circular arc, with five segments, one need not calculate each of the five vertices, if one can simply tell the turtle to draw an arc to the right through 45 degrees at a radius or 3 units. The command in turtle script may look like this.

arcr 45 3 5

Archimatix has its own implementation of a turtle scripting API, borrowing more closely from GSDL, a 4th generation language developed by GIST, Inc., than from Logo.

 

Absolute Commands

mov x y <a>

Before drawing a shape, we have to place the turtle somewhere in 2D space and point it in a certain direction.  This command moves the turtle to the point x, y with out drawing any lines. The optional argument a tells the turtle in which direction to face. The default direction is 90 degrees.

 dir a

dir sets an absolute direction.

This command, which reorients the turtle to a new direction,  can be called anywhere in the script whenever you would like it to abruptly change direction.

Relative Commands

turnl avoila_capture-2016-12-03_07-37-00_pm

Turns the current direction a degrees to the left.

turnr a

Turns the current direction a degrees to the right.

voila_capture-2016-12-03_07-25-16_pm
fwd c <d>

Draws a line c units long in the current direction. For example, fwd 30, or if using a parameter, fwd height. Optionally, d will a diagonal line will be drawn c units forward and d units perpendicular to the current direction.

 back c

voila_capture-2016-12-03_07-57-33_pmDraws a line c units long, backwards, or in the opposite of the current direction.

right c

voila_capture-2016-12-03_07-58-27_pmDraws a line c units long to the right, without changing direction.

left c

Draws a line c units long to the right, without changing direction.

arcr a r s

voila_capture-2016-12-03_08-13-10_pm Draws a circular arc of a degrees, with a radius of r, beginning at the current point and tangential to the current direction and arcing to the right. After the command is execute, the turtle’s direction is automatically turned to the tangent of the end of the arc. For example, with a dir 45, arcr 45 3 5 will leave the turtle at a direction of 0 degrees so that if you follow with a fwd 4, the turtle will draw a line 4 units long at an angle of 0 degrees.

arcl a r s

Similar to arcr, but curving to the left.

 

 

Mathf Functions

All of the Mathf Functions have been mapped to AX Turtle Script. They follow the general form of:

cos(degs) 

or

Cos(degs)

A rad2degs conversion goes on inside the function, so the argument is in degrees.

Another example is

atan(x, y)

Mathf variables can also be used in your equations such as x*PI

PI

degs2rad

 

 Looping

AX Script has a limited looping syntax that basically repeats the code with a counter.

loop counter

The loop command opens the scope of the loop. The counter is a variable that you can use inside the loop code.

endloop

Teminates the scope of the loop.

For example, this loop will draw a gear shape with teeth number of teeth.

loop teeth

arcl degs radius segs
right tooth
arcl degs radius+tooth segs
left tooth

endloop

This example will produce a stair shape:

loop steps-1
fwd ariser
left tread
endloop
 


Conditional Block

The conditional command does not use parentheses.

if var1 GT var2

You can also reference a bool parameter

if bool

endif

Closes the conditional block.

The conditional uses the boolean operators:

LT for "equals"

GT for "greater than"

EQ for "equals"

NE for "not equals"

 

There is currently no else if. The workaround is to create a second block with the opposite conditional.

 

Parameter and Variables

set parameter value

The set command will set a parameter based on the parameter’s name. This is particularly useful for defining a max and min value for a parametr.

set width greater(width, .01)

 

Or for making sure a parameter never rises above another:

set width lesser(shaftHeight, columnHeight)

Thus, even as the user drags a handle or types a value in a float field, it will not break the rule defined in the set command.

 

let tempVar value

The let command defines or resets a temporary variable. This is useful in the case that you have a long expression that you need to use in multiple function calls while drawing.

let buildingLength sine(angle)*buildingHeight

To reset a temporary variable, you must use let again.

let buildingLength 5

Absolute Commands (Cont.)

 

Special Curves

bezier   ax  ay   ahx  ahy   bhx  bhy   bx  by   segs

Draws a cubic Bezier curve between points a and b. The curve is modified by handles defined by absolute endpoints ah and bh.

 

archimatix-2016-12-04_10-25-57_am

 

molding  type  ax, ay  bx, by segs, tension

Moldings profiles are Shapes that have a very common use in architecture. This command uses one or more bezier curves to and makes certain assumptions about the handles so that you do not have to construct a sequence of beliers curves yourself. Borrowing from the timeless art of molding design, we have a few types that can be called in the molding command, including cove, ovolo, cyma recta, cyma reversa and onion.

voila_capture-2016-12-04_04-09-19_pm2

 

 

6. Getting to Know Your Relations Better

stacking

Simple Relation for stacking: the Cylinder is always atop the Box.

archimatix-2016-09-08_09-30-07_am

archimatix-2016-09-08_09-30-33_am

 

Artful parametric modeling is all about managing relationships. Not the personal kind, but the algorithmic kind.

By defining meaningful relationships among your parameters, you can encode a new and powerful morphological genus – creating a new species DNA, as it were, that can be used to generate hundreds of variations of models.

When you connect parameters to each other, you are authoring behaviors for your parametric model. When you modify one parameter, all sorts of changes may ripple through the model according to the logic you encoded via Relation connections and mathematical expressions within the Relation. Furthermore, these Relations may be bi-directional, meaning that you can change a parameter anywhere in the graph and changes will ripple out from that parameter.  The default mathematical expression set  when you fist specify a Relation is simply “=,” or equals.

Equal Relations

A common case for an equals Relation is when you want one object to always sit atop another, regardless of how tall the bottom object is. In the example to the right, the behavior illustrated is that the blue Cylinder is always atop the red Box.

Try This!

To set up this parametric behavior:

  1. Choose a Cylinder and a Box from the 3D Library (left sidebar in the NodeGraphWindow.
  2. Unfold the Controls of the Box and the
    archimatix-2016-09-07_10-49-17_pm

    A simple “equals” expression.

    Transformations of the Cylinder.

  3. Click on the red connector box on the parameter Extrude in the Box node palette.
  4. Click on the red connector button next to the Trans_Y parameter on the Cylinder node palette.
  5. To test: either click on the Box in the SceneView and then drag the green knob to make the Box taller, or click on the Cylinder and then drag the Y-Axis Position Handle.

You will notice that the relation is bi-directional. Modifying either parameter will alter the related parameter. This is a departure from other parametric modelers which feature uni-directional relations. The benefit of bi-directional is that, when playing with a parametric model in the SceneView, you can click just about anywhere you like and start modifying, rather than searching for the “master” parameter.

However, this freedom is not free: the bi-directionality requires inverse expressions to be input. In the case of our simple example, we did not edit the expression found in th relation, relying on the default equals expression. Let’s take a look at how we might make a slightly more complex relation expression.

Expressing Relations

When would like to have more interesting Relations, you can use the ExpressionEditorWindow that pops up when you click on the green button at the center of the Relation connector cable. In the ExpressionEditorWindow are two text fields allowing you to edit the bi-directional relationship between the two parameters.

Try This!

pistonsimple

Simple piston with sinusoidal relation to shaft rotation.

Lets say that we would like to simulate the movement of a piston relative to the rotation of a crankshaft in a car engine. The piston rises and falls sinusoidally as the shaft turns. The expression is Piston.Trans_Y=Sin(Crankshaft.Rot_X). Lets go ahead and set this up:

  1. Choose a Cylinder from the 3D Library.
  2. Click on the name button at the top of the node palette and rename it “Piston.”
  3. Use your copy and paste short cuts to create a second Cylinder. Name it “Crankshaft.”
  4. Next to the Transformations foldout, click the axis button until it show “X.”
  5. Open the Transformations foldout and choose “Align_X” choose “Center.”
  6. Click on the Crankshaft in the SceneView and reduce the radius a bit.
  7. Connect the Piston.Trans_Y to the Crankshaft.RotX.
  8. Try rotating the Crankshaft – the Piston will continue upward or downward.
  9. Click on the green button in the middle of the red connector cable.
  10. archimatix-2016-09-07_11-47-12_pm

    The Edit Relation window lets you define the bi-directional mathematical expression.

    In the ExpressionEditor, in the field filled in with Crankshaft.Rot_X, change the expression to: Sin(Crankshaft.Rot_X) and then click on the Save button just below.

  11. Test by rotating the Crankshaft again. The Piston will oscillate up an down.
  12. Make the Piston more responsive to the rotation, decrease the stroke and lift it higher above the Crankshaft by editing the expression again to be: 1.5+.5*Sin(2*Crankshaft.Rot_X)

We will save more elaboration on this with the addition of a piston rod, etc. please see the tutorial The Parametric Engine.

 

Best Practice: Relating Translations

relations1

A simple parametric behavior: the red Box and blue Cylinder are always translated to the end of the gold Box.

If you find yourself connecting the Trans_X for one node and the Trans_X of another node to the same source, it is probably better to group the two nodes together with a Grouper and then relate the Grouper’s Trans_X to the source. This is analogous to parenting two GameObjects to an “Empty” GameObject in the Unity hierarchy window. While Archimatix can handle lots of relations, by using relation connections where a grouping would do, you will add more visual complexity to the NodeGraphWindow.

For example, the animation to the right depicts a parametric behavior whereby the red Box and the blue Cylinder are always positioned at the end of the gold Box. There are two ways we could encode this behavior:

archimatix-2016-09-07_10-09-53_pm

Setting translations for each node will lead to many redundant Relations.

Method 1: This method is not preferable, but happens commonly while building up a graph. The Trans_X of the Cylinder has been related to the width parameter of the rectangular plan of the gold Box with an expression of Cylinder.Trans_X=Rectangle.width/2. When the red Box was added to the graph, a similar relation was added between the gold Box and the red Box, as shown in the figure to the right. Now when we drag the Handle for the Rectangle width, the blue Cylinder and the red Box translate accordingly.

The down side of this is that we have two connections and we have to enter the same mathematical expression twice (for the Cylinder and for the red Box). If we want to change that relationship, we have to change it in two places. Also, the graph will quickly get cluttered if such translations are maintained with Relation connections all the time.

 

Grouping Node

Grouping nodes allows fewer Relations.

Method 2: Alternatively, we can feed the Cylinder and Box into a Grouper and then relate the Trans_X of the Grouper to the width of the Rectangle.

The behavior of our parametric model will be exactly the same, but now, if we wish to edit the expression in the relations, we are editing in only one place. Also, the graph will have fewer parametric relations, which tends to make the graph more legible.

 

 

 

BiLevelChamfer

The BiChamferSide is a shape geometry that features independently adjustable top and bottom chamfers and a taper. It is most useful as the default sweep profile for an Extrude Node.

Archimatix 2016-09-05_08-44-20_AM

Node Selection

This page coming soon!

Materials

This page coming soon!

Lightmapping With Archimatix

Introduction

Archimatix (AX) can prepare the models it creates for Unitiy’s Global Illumination (GI) , both realtime and baked. Since AX generates models frequently as parameters are modified, the system makes some assumptions about when in your workflow you are ready to have Unity render the metadata that supports GI.

Voila_Capture 2016-08-21_04-20-15_PM

Arch with Global Illumination

General Workflow

Depending on the complexity of the model,pre-computation for Unity’s GI lighting  can take a significant amount of time (to say the least!). By default, Unity tries to initiate this computation any time it senses that static meshes in the scene have been transformed, added or deleted. Although useful in many cases, this default mode of building the lighting model becomes burdensome when modeling with Archimatix, since, as you drag parameter AX handles in realtime, you are usually regenerating hundreds of meshes per second. Even after you stop dragging and AX generates actual GameObjects, you are likely to keep on modifying and tweaking parameters. While this fluid mesh generation is part of the magic of AX, such rapid changes set the  automatic lightmap build into unnecessary overdrive. There are two ways to avoid this this situation.

The first way to avoid unnecessary computation while modifying the parameters of a model is to simply turn the Auto build mode off. This is done by opening the Unity Lighting Window and unchecking the “Auto” checkbox, as show in the image to the right. With Auto off, you can modify AX meshes to your hearts content with out setting off the lighting computation. When you are ready to see the model rendered with GI, click the manual “Build” button to the right of the “Auto” checkbox.

However, if you have a preference to leave “Auto” on, then you can temporarily  disable Lightmap Static flags for your entire AX model by making sure the Lightmap Flags Enabled checkbox in the Inspector for the model is off. This means that, as AX generates GameObjects with meshes, it does not add the Lightmap Static flag to the the GameObjects and the light mapper will not be aware of the changes to the mesh. With this approach, you can model as much as you like, and then when ready to see it rendered with GI, you can click the Lightmap Flags Enabled checkbox.

Note: The Lightmap Flags Enabled parameter for the model is off by default. This means that, when you first create an AX model, you must check this to on before building the lighting.

Once you have finished a session of modeling and tweaking, and you are ready to take a coffee break, you can click the  “Lightmap Flags Enabled” checkbox in the Inspector for the model. If “Auto” is on, the light mapping will shift into high gear. Otherwise, after checking Lightmap Flags Enabled go to the Lighting window and click on the Build button.

In either mode, when the lighting model is being built, it will only take into consideration the objects that have been generated by nodes that have been designated as Lightmap Static, as we shall see next.

Lightmap Static Flags

If a AX ParametricObject, such as the Extrude_9 in the figure to the right, is set to LightmapStatic (red arrow), then when a GameObject gets generated AX, its static flag will be set to Lightmap Static (so long as the Lightmap Flags Enabled is checked when the model is built), and the Unity GI system will treat it as such when rebuilding. This static flags setting is analogous to the flag options for any GameObject in Unity, with the difference being that the flag is set internally in the AX node and transferred to GameObjects when they are built by AX.

When you set the static flag for a node, all its upstream nodes will be set to the same flags.

Secondary UVs for Baking

If you have selected Baked GI in the Unity Lighting Window, then you will want to have SecondaryUV’s generated for the meshes created by Archimatix. Since generating these extra UVs, which are used by the Unity lighting model to created rendered lightmaps, takes some extra computation, you must recreate the secondary UVs each time you bake the lighting.

The checkbox called Create Secondary UV’s appears only after the Lightmap Flags Enabled checkbox has been checked. When you check it, the Secondary’s will be generated for any meshes generated by nodes that have had their flags set to Lightmap Static..

Even if you check the Create Secondary UV’s, this box will become unchecked after the AX model has finished one of its frequent builds.

 

Although the Archimatix Shape Library ships with a variety of parametric shapes, such as Circle, Square, RoundedRectangle, Cross, IBeam, etc., that can be added and subtracted to each other, it may be worthwhile for you to “code” your own Shapes using Turtle scripting and defining your own SceneView Handles.

There are three main areas of focus to consider when authoring parametric shapes:

  1. Parameters
  2. Handles
  3. Logic

This list generally reflects the order of implementation of your custom Shape. When designing a Shape it is useful to create a drawing that helps you (or the users of your Shape) visualize its geometry and the parameters that control it.  It is also an interesting exercise to begin with parameters and handles since many geometries can use the same controls.

Archimatix 2016-03-26_11-10-26_AMIn the figure to the right, we see an example of a diagram that just shows parameters and handles for a Shape that might be a thought of as a molding profile.

Each handle in the diagram, represented by a red dot, can be defined in the handle editor to adjust certain parameters when dragged. For example, handle B could control both the edge and width parameters while handle A controls only width and handle C controls only the overall height.

These parameters and handles can be added to the node before any scripting is added to actually draw the geometry. In fact, this same setup could be used to control a variety of geometries. Below are some examples.
Archimatix 2016-03-26_11-25-09_AM
Particular Shape geometries are based on logic that uses the parameters as variables. The logic is coded using simple turtle graphics scripting implemented right in the node palette.

Using the above molding example, let’s take a look at how to create parameters and handles and then use them with logic.

Adding Parameters

Parameters serve as  variables in the logic of the Shape. For example, in a rectangle Shape, the main parameters are width and height. These parameters are then used to position the SceneView handles and as variables in the description of the rectangle in the logic section of the node palette.

Since we have these same parameters specified in our molding diagram above, it may be best to start our custom Shape with an instance of the Rectangle from the AX Library (choose the Rectangle Shape from the left-hand sidebar of the NodeGraph EditorWindow).

To modify the Rectangle Shape, we will need to add an new parameter called edge. In the Archimatix NodeGraph Editor Window, the parameters are found under the Geometry foldout in the node palette for the parametric shape. You can add as many parameters as you like to the node by clicking on the “+” button at the bottom of the parameter list. Once the add button is clicked, a new parameter will be added to the node and opened for editing.

Naming a Parameter

When the parameter is opened for editing, the name field will be an editable TextField. When choosing a name, be sure not to leave any spaces. This is important since you will need to reference this name as a variable in the script for the Shape’s logic.

For now, we will only edit the parameter’s name, however, you may notice that, in addition to editing the name, you can choose the data type for the parameter (float, int or bool) and start to define expressions for how other parameters in the node should be adjusted if this parameter is modified.

For our molding example, edit the name of the new parameter to be “edge.”

Creating a New Handle

In the Handles foldout of the node palette, you will find a list of named handles. Each of these generates a SceneView handle and defines the behavior of that handle with respect to how it modifies the node’s parameters.

Before adding our new handle, we need to adjust the current width and height handles to adapt them so they are not centered on the origin. Go ahead and click on the width handle and edit the position expression for X to width instead of width/2. Also, adjust the expression to width=han_x. Don’t worry that the Shape is not following these handles yet. Then click on the height handle and set the Y-position to height instead of height/2 and edit the expression so that it is height=han_y.

To create a handle for the edge parameter, click the “+” button under the Handles foldout and name the new handle “edge.” The default type of handle, “Point,” is fine for this. In the position fields, we want to describe where the handle should appear. In this case, the x-position of the handle should be width and the y-position should be the expression height-edge.

After entering these expressions into the x and y fields for Position, the handle should immediately appear in the SceneView, though it is not draggable yet. To make the handle interactive, we have to tell it how to set its parameters when dragged. To do this, edit the first expression for the handle to “width=han_x”. This says that what ever the x-value for the handle is, this should be the value for the width of our Shape. In the vertical direction, we will use the y-value of the handle, or the han_y. Click the “+” button to add a new expression and set it to “edge=height-han_y”.

Now you should be able to drag your new handle and reset the parameters for edge and width.

Logic

 

Now that we have our parameters (and SceneView handles to modify them), we can use these parameters to “draw” the geometry of our shape. Let’s start out with a simple molding that features a chamfer. Here is what the turtle script should look like:

mov width 0 90
fwd height-edge
arcl 90 edge 5
fwd width-edge

 

 

As you can see, after entering this script into the Logic TextArea of the node palette, we are using the parameters, or variables, width, height and edge to draw our Shape. Now, dragging the “edge” handle allows us to generate permutations such as these:

Archimatix 2016-03-27_12-57-33_AM Archimatix 2016-03-27_12-57-28_AM Archimatix 2016-03-27_12-57-24_AM

And now the shape is ready to be used for the section of a PlanSweep:

Archimatix 2016-03-27_01-01-57_AM

But, what if we wanted the molding to have more detail? Perhaps something to like the first section above with the quarter-round in the bevel. Lets recode the geometry a bit, but with the same parameters and handles.

mov width 0 90
fwd height-edge
left edge/3
arcl 90 edge/3 5
right edge/3
fwd width-edge

 

 

In this version, we have added a bit of mathematical expression such as edge/3. The resulting molding looks like this:

Archimatix 2016-03-27_01-09-18_AM

 

For full documentation on the Archimatix Script API, click here.

 

 

 

 

 

Older posts

© 2017

Theme by Anders NorenUp ↑