Wednesday, May 15, 2013

Component-Oriented Programming


Over at the Kongregate forums, a guy named Drakim wrote a series of posts on a relatively new programming paradigm that has come to be called Component-Based Development or Component-Oriented Programming. Basically, this new paradigm does away with inheritance to create classes and builds software entities by assembling components instead. Using this paradigm doesn’t require new languages for component-based development. You can still use your favorite Object-Oriented Programming language as long as you avoid the temptation to use inheritance to build classes. In truth, there’s nothing to stop you from mixing and matching the two paradigms if you wish, but inheritance forces child classes to inherit all the properties and methods of its parent, whereas classes assembled with components will have only the functionalities that their components provide, no more and no less.

What I like about this new paradigm is that it solves an issue that I’ve been wondering about for some time – multiple inheritance. Most OOP languages don’t implement multiple inheritance and with good reason. Things can get messy pretty fast if the multiple parents of a class have their own way of implementing common properties or methods. With a component-based architecture, however, all you need to do is to build and slap on the components that each class needs, and you’re good to go.

All this is fairly new to me, so I’m in no position to talk about it at length. Instead, I’m posting the links to Drakim’s series of articles for future reference.

Wednesday, April 10, 2013

Sculptris is Great

I’ve been playing around with a program called Sculptris, which I downloaded a while back. Sculptris sounds like it might be a videogame about falling blocks, but it’s actually a 3D sculpting application that was developed by the makers of ZBrush, Pixologic. When it comes to sculpting a new model from scratch, Sculptris is actually superior to its older sibling. Each model generally starts life in Sculptris as a simple sphere, which the user can shape into a detailed organic model with the tools at his disposal. As the user sculpts his model, Sculptris automatically subdivides the area under the brush to accommodate more detail. As of this writing, I know of no other 3D modeling application that does that.

That said, there are still a few kinks in this application that Pixologic needs to iron out. As the poly count of a model  increases, so does the chance of Sculptris suddenly crashing. Fortunately, Sculptris saves the current work in progress periodically and seamlessly. Running it after a crash will automatically load its last save file.

While Sculptris is great for sculpting organic models, it doesn’t come with a lot of bells and whistles. If you want to retopologize a model or change its pose, you’ll need to use other 3D applications for that. Nevertheless, using Sculptris is probably the closest one can get to molding clay in digital form. What’s more, it’s free. That, along with its ease of use, makes Sculptris a winner.

Tuesday, March 12, 2013

Post Mortem: Dungeoneers


Last week, I participated in another Game in Ten Days (GitD) contest, this time with “Dungeons” as its theme. I’d have preferred to finish my works in progress before joining another game jam, but the theme was just too good for me to pass up. I eventually made a Flash game whose working title was “Dungeon Dweller Exterminators,” but I changed it to “Dungeoneers” upon release.

I wish I had blogged each day about what I had done if only to keep an accurate record of my working process. I was pressed for time, however, so I chose not to write about it. Next time I join a game jam, I really should keep a journal of what I do.

Currently, my game lets players hire adventurers and form a party of up to four of them to explore the four levels of a dungeon. All the action takes place in a top-down view of the dungeon, although I would have preferred using an isometric view if only I had enough time to implement it. Players can move the entire party by clicking on any part of the dungeon level with the mouse. Once the adventurers encounter enemies, however, they will automatically decide which of them to target. I wanted players to be able to also choose targets for each adventurer to add more tactical depth, but I didn’t have time to implement that. Neither was I able to provide an in-game tutorial or instructions on how to play the game, although despite that, I found that players were able to figure out what to do. The worst part was that I didn’t have time to design the levels to make them tactically interesting or to test my combat system thoroughly. That failure was what voters zeroed-in on.

As of this writing, it appears that most if not all of the votes have been sent, and it is obvious that my entry won’t win. Unlike the last GitD that I joined, though, I did get a few votes this time around. Not everyone who voted gave feedback, but I am grateful to the ones who did. Because of them, I know that my game may be an ugly duckling now, but it has the potential to become a beautiful swan. Below is the feedback that I received on my game:

  • Not really good at its current state, but gives a hint of what can become of it after some polishing, and that looks really promising. Most of the things I could suggest have to do with polishing x or y aspect, so I’ll just skip those. Gameplay wise, the combat system seemed rather strange; units seemed to have a really shitty accuracy. Even the rangers would miss half of the time while the enemies were next to them, which reminds me that Diablo/that-demon-thingy seemed to be the only enemy able to hit (and kill) my units. Some work and you may have a solid game there.
  • Neat start, but like…I have to ask—what’s with the combat in this game? I started writing this post while my two knights were wailing away, and they’re STILL at it. The chance to hit seems absolutely abysmal (players don’t typically like games where their characters miss all the time) and, on top of that, the time between swings is really slow. Makes the combat VERY uninteresting. Speed up the attack speeds, and mitigate damage through armor/absorption/reduction rather than evasion. I finally gave up on the…thing (skeleton?) I was fighting and ran down to fight some red thing. If I’m still fighting it when I finish this post, I’m just going to give up. Still, with some work, this could be pretty cool.

    PS: My knights are STILL fighting the red thing in Dungeoneers and everyone is still at full health. WTF?
  • Seems like it could be very fun. It is disorientating at first though.
  • I don’t know what it was but the fighting between people and creatures was extremely slow and tedious, and since that was pretty much all there was to the game, I’m afraid I didn’t stay for long.
  • I made a team of exterminators and started working on the rat infestation problem at the church, but then I ran into a skeleton that neither of my guys could hit and it couldn’t do anything to them either, so that was that. Bug report though: clicking on the skeleton generated a null object reference error. Thought you might want to know.
  • Receives my second vote for being a good quick mouse navigable game.
  • An interesting game but sadly not a very good game. The best thing the game has is the pathfinding system. It freaked out a bit when both you and the enemy were trying to get to each other but otherwise it was very strongly done.

    The combat was really shallow. Apparently the Knight has so much armor nothing can hit him, even at level 1. Sadly, he also hadn’t really hit anything that is not a rat. The monk dies far too easily to tell if he can hit the skeleton/humanoid enemies on the 3rd floor. Ranger can actually shoot from a distance but it’s far too hard to see if he’s even attacking. Barbarian does good damage but also takes damage and dies a bit too easily. Considering that you gain so little money running the dungeon killing rats you can’t level up or gain new people to your party without serious rat grinding. I’m not even sure you can damage the skeleton guys or the final boss.

    Controls were ok but also left a lot to be desired. All you can basically do is tell your people where to go and let them to the rest. This leaves us with very little strategy. If you click a living thing on the map you get a little rotating triangle selection over it but it doesn’t seem to do anything at all. The opening screen was also very confusing as clicking the church without any people at all doesn’t explain anything.

    All in all the game has good promise but feels highly unfinished.
  • Has potential, but as others have found, the combat just doesn’t seem to work, and that’s a pretty fundamental part of a dungeon crawler. All the effort on this one seems to have gone into the menu screen.
  • my trusty Knight 2 thought he’d found a solution to the horrendously slow combat speed – making use of the excellent pathfinding to sprint for the stairs right away every time.Then he met an epileptic dragon, and since it seemed unlikely to hurt him, he couldn’t bright himself to attack it. This wasn’t the epic adventure that was expected of him.
  • Decent concept, but needs a bit of work.

    I tried grinding far enough to get one of every fighter but the ranger (I thought maybe the monk would be good against the skeleton, but started with the knight and barbarian), but the third floor was still impossible (as far as actually harming the enemies). I also tried a single knight at level 3 — but the only noticeable difference between a level 3 knight and a level 1 knight is that he’s four times as expensive. “There’s no turning back” is kind of weird when you discover that there is turning back (as in exiting via the stairs you came in from).
  • A proper dungeon crawler, with pathfinding and adventurers! I don’t really know what is good about different classes, and my pair of knights have spent the last 5 minutes fighting a skeleton(?) with neither side doing any damage. Looks promising, but unfinished, way too ambitious for 10 days

Based on the above comments, there seem to be two consistent patterns that come up again and again.

  1. Combat, which happens to be the central part of the game, is the one that is most poorly implemented. Attacks take too long to execute, and often, little to no damage is dealt.
  2. The game has potential, but it would take more work to get it to an enjoyable state.

When scheduling an I.T. project, there is a quick rule of thumb that says that about 30% of the entire time should be spent on designing the application, 40% on programming, and 30% on testing. If memory serves me right, what really happened was that I spent maybe 40% of my time designing the game, 50% programming it, and only 10% or less testing it. I used up much of my programming time creating a pathfinding and targeting system that would enable opposing teams to move across walled rooms and fight each other. Hardly enough time went into combat resolution.

As always, my efforts are not wasted. I now have some good code that I can always re-use in other projects. More importantly, I have the seed of a game that may wind up being engaging if I polish it just right.

Friday, February 22, 2013

Its Name Is Mud

Thus far, I’ve created a few models for a Flash game that I’m co-developing with another guy. I featured one of these models in my blog earlier, an elven archer of the Unseelie Court. The game we’re working on is in 2D, but I’m using my 3D models to make tile sheets. The 2D figures are so small that much of the detail that I put in them is lost, but I figure that it’s better to have too much detail than too little.

The next model I’m making for this game is a golem, a kind of tank unit that is able to withstand a lot of punishment before dying. As usual, I started by drawing a silhouette of the creature then filling in details over the black areas. I decided that the golem should be broader than a human being, the better to block its enemies. I made its arms long so that it can plant its fists on the ground like a gorilla to achieve better stability against attacks. Its forearms and fists are large and heavy enough to act as powerful blunt weapons. The golem is devoid of ornamentation as if the wizards who constructed it were more concerned about amassing an army than creating a work of art.

The model that I designed is so simple that it only took me two days to construct and texture its mesh. The weekend is just around the corner, so I doubt if I’ll be able to work on it then. Nevertheless, I hope to finish the golem’s tile sheet by early next week.


Sunday, February 10, 2013

Tutorial: Rigging a Bow in 3DS Max

This tutorial shows how to rig a bow in 3DS Max. I wrote it after having figured out how to rig a longbow that I modeled. Bows are not as straightforward to rig as, say, a creature model because the rig has to cause the wooden parts of the bow to bend when the bowstring is pulled. The string may stretch for a tiny bit, but once it has reached its full stretch, it should maintain its length the whole time. When the string is released, the bow should snap back into place, and the string should slowly vibrate to a stop without causing the bow to bend.

I didn’t have any luck searching for tutorials on the Internet about rigging a longbow in 3DS Max. I did find a good video tutorial on rigging a bow, but it’s a Blender tutorial. Nevertheless, it gave me enough clues on how to do a similar rig in 3DS Max, but the workflow that I used is sufficiently different to warrant its own tutorial. Hence, I decided to write one.

This tutorial assumes that the reader already has a bow model in 3DS Max that needs to be rigged. The tutorial does not assume that the reader knows how to set up a skeleton and weight vertices to it, so I will try to explain these processes in detail. Some knowledge on the different coordinate systems that 3DS Max uses will help in understanding the later parts of the tutorial.

Ready to begin? If so, read on.

  1. Activate the Left or Right viewport. For this tutorial, I chose to activate the Right viewport to match the view in the Blender tutorial I mentioned earlier. If the mesh is not displayed in wireframe view, press [F3] to switch to it.


  2. On the rightmost side of the screen, make sure that the Create panel is selected then click the Systems button and the Bones button.


  3. Click on the center of the bow’s handle to begin creating bones. Keep clicking along the upper half of the bow to create a chain of bones, making sure that the joints are more or less along an edge loop of the bow. Don’t worry about precise placement at this point because we can edit the bones later. When we finally click the point where the bowstring pulls the bow, end the chain by right-clicking anywhere on the screen. This will create an extra nub bone, which we will use eventually. Rotate the nub bone so that it is perpendicular to the bowstring with the bone’s tip facing away from the bow.


  4. Activate the Select and Move tool, which is located on the top toolbar, then click the very first bone that we created, which should be the one closest to the handle of the bow. Zoom in on the bone with the mouse wheel to get a better view of it. Reposition the bone so that it is on the exact center of the handle. We may use the Absolute Mode Transform Type-In at the bottom of the screen to input precise X, Y, and Z coordinates.


  5. If necessary, we can adjust the placement of individual bones with the Bone Tools. Click the Animation menu then select Bone Tools to bring up a dialog box of the same name. Click the Bone Edit Mode button to toggle on bone editing mode. We can then use the Select and Move tool to edit the placement of bone joints as necessary.


  6. Press [H] to bring up the Select from Scene dialog box. Click the first bone in the list, then with the [Shift] key pressed, click the last bone to highlight all the bones. Click the OK button. Doing this will close the dialog box and select all the bones.


  7. In the Bone Tools dialog box, click the Mirror button to bring up another dialog box called Bone Mirror. Under Mirror Axis, click the Z radio button then click the OK button. All the bones on the upper half of the bow should then be mirrored on the bottom half.


  8. Having made the bones that control the wooden part of the bow, we will now create a bone to control the bowstring. Zoom in to get a good view of the center of the bowstring with the mouse wheel. In the Bone Tools dialog box, click the Create Bones button then click on the center of the bowstring to start creating a new bone. Click on a point away from the bow and its string to make a bone that is aligned like a nocked arrow. Right-click to end bone creation. An extra nub bone will be created as well, but we may delete it since it won’t be needed. Re-position and rotate the bone as necessary so that it is aligned perpendicularly to the bowstring and so that its joint is precisely at the center of the string.


  9. We will now create what is supposed to be the root bone of the bow’s skeleton. Again, press the Create Bones button in the Bone Tools dialog box, but this time, click close to the center of the handle to begin creating a new bone at that point. Don’t click too close to the center to keep from attaching the new bone to any other bone nearby. As with the last bone that we created, make the new bone perpendicular to the handle of the bow then right-click to end bone creation. Delete the extra nub bone that is created, and use the Select and Move tool to position the joint of the new bone precisely in the center of the bow’s handle.


  10. Optional but recommended step: Select each bone in turn and rename it to something meaningful. For example, I chose to rename the bones that control the upper half of the bow to “bone_bow_upper_xx,” where xx is a two-digit sequential number. In a similar fashion, the bones on the lower half of the bow are named “bone_bow_lower_xx.” The bone that controls the bowstring is named “bone_bow_string,” and the root bone is named “bone_bow_root.”

  11. At this point, we actually have four separate skeletons for the bow. This is evident when we look at the schematic hierarchy of the objects we’ve made. Click the Schematic View button on the toolbar. This will open a new window named Schematic View 1.


    As we can see from the schematic view, we have four separate skeletons for the bow, but what we want to do is to integrate all the bones of the bow into one skeleton. This way, we will only need to move or rotate a single bone to move or rotate the entire skeleton. There are several ways to accomplish this in 3DS Max, but since we are already viewing the schematics of our objects, we might as link the bones within the schematic view itself.


    In the toolbar of the Schematic View window, click the Connect button.


    Now click the box representing the root of the upper half of the bow, and without releasing the left mouse button, drag the cursor to the box representing the root bone of the entire bow. Release the mouse button. This will cause the set of bones for the upper half of the bow to be linked as children of the bow’s root bone.


    Repeat this process to connect the bone of the bowstring and the skeleton of the lower half of the bow to the bow’s root bone. When done, there should only be one skeleton for the bow as shown below.


    We may now close the Schematic View window.

  12. Use the Select Object tool to select the root bone of the bow.


    Scroll down the Bone Tools dialog box to see the Object Properties group box. Untick the Freeze Length checkbox and set Stretch to None. This will allow us to pull on the bowstring bone while keeping it parented to the root bone.


    We may now close the Bone tools dialog box.

  13. Use the Select Object tool to select the mesh of the bow.


    Click the Modify panel on the right side of the screen and add a Skin modifier to the mesh. Under the Parameters rollout, click the Add button beside the “Bones” label. This will bring up a dialog box named “Select Bones.”


    Highlight all the bones of the bow then click the Select button. This will close the dialog box and add all the highlighted bones to the Skin modifier.


  14. Using the Select and Rotate tool, click each bone in turn and rotate it to test the rig. Press [Ctrl]+Z to undo the rotation each time and restore the bones to their original state. If there are errors in how the mesh deforms when a bone is rotated, that means the vertex weights for the associated bones will have to be adjusted.

    In the skin modifier of the mesh, click the Edit Envelopes button, which will allow us to adjust the vertex weights of any bone as necessary. In the list of bones that also appear under the Skin modifier, select the bone whose associated vertex weights you want to adjust.

    There are a number of ways to adjust vertex weights for any given bone, but for this model, I will only use two methods. The first method is to use the Weight Tool. For this, we will need to be able to select vertices by ticking the checkbox labeled “Vertices” in the Select group box of the Skin modifier.


    For this task, it may help to switch from Wireframe view to Shaded + Edged Faces view. Pressing [F3] toggles between both views, and pressing [F4] toggles edged faces.
      In the list of bones, select the bone that we want to adjust vertex weights for.  With the Select and Move tool, select the vertices whose weights we want to adjust. Now click the button for the Weight Tool, whose icon looks like a wrench. In the Weight Tool dialog box, make sure that the bone that we are adjusting vertex weights for is highlighted.  We can input any number between 0 and 1 in the box beside the Set Weight button. This number represents how much influence the highlighted bone will have over the selected vertices when we click the Set Weight button. For a given bone, vertices with a weight of 1 or close to 1 will appear red. Those with a weight of approximately 0.75 will appear orange. Vertices with a weight of 0.5 will be yellow, and this color will appear progressively paler as the vertex weight approaches 0.1. Vertices with a weight of less than 0.1 will be blue.


    There are other buttons in the Weight Tool dialog box that can affect vertex weights, but I will let you figure out what those do.

  15. The second method that we will use to set vertex weights is to “paint” them. This is particularly useful for fine-tuning vertex weights that were set using the Weight Tool.

    Scroll down the Skin modifier until we see the Paint Weights button, which is inside a group box labeled “Weight Properties.” Beside it is a button marked “…” It is this button that we will press first to open the Painter Options dialog box to set up vertex weight painting.


    Different meshes may require different setups, but for this particular model, we set Max Size to 5 to give us a “paint brush” of just the right size. The checkbox labeled “Enable Pressure Sensitivity” may also be ticked if we are using a graphics tablet to paint vertex weights. We may then close the Painter Options dialog box.


    We now click the Paint Weights button and proceed to use the mouse (or the graphics stylus as the case may be) to paint vertex weights on the vertices that are supposed to be affected by the selected bone. Continue doing this with other bones until we are satisfied with the vertex weights. We may then press the Paint Weights button to toggle off vertex weight painting.


  16. Go back to wireframe view by pressing [F3]. Zoom out the scene until we have a good view of the entire upper half of the bow then select the nub bone at the very top of the bow. Click the Animation menu then click IK Solvers > HI Solver.


    At this point, we will see a stretchy dotted line anchored to the nub bone that we selected. Bring the mouse cursor to the bone of the upper half of the bow’s handle and click it. This will create an IK (Inverse Kinematics) chain from the nub bone at the top to the bone that we clicked. If we were to change the position of the nub bone, the rest of the bones in the IK chain will rotate and shift position to maintain the connection between them.


  17. Repeat the previous step to connect the bottom nub bone to the bone of the lower half of the bow’s handle. At the end of this step, we will have two IK chains named IK Chain001 and IK Chain002.


  18. Activate the Select and Move tool then click the bone of the bowstring. Note down the X, Y, and Z position of this bone. Likewise, click IK Chain001 and IK Chain002 in turn and note down their X, Y, and Z positions.

    For my model, I had the following values for the aforementioned objects:

    World Coordinates

    Bowstring Bone
    IK Chain001
    IK Chain002
    X
    0.0
    -0.009
    -0.002
    Y
    18.41
    17.282
    17.282
    Z
    80.0
    149.091
    10.913

  19. We will need to link the two IK chains that we created to the root bone of the bow’s skeleton so that they will move and rotate with the root bone. Click the Schematic View button on the toolbar again then link both IK chains to the root bone. The skeleton hierarchy should then appear as shown below.


    We now close the Schematic View window. Linking the IK chains to the root bone would have caused them to change position. With the Select and Move tool, click on each IK chain in turn and move them so that they are back to their original positions.

  20. We’re going to use wire parameters so that whenever we pull the bone of the bowstring horizontally, the bow will bend. Wire parameters can be confusing to work with because all their positions are in reference to the parent coordinate system of the objects that are affecting each other, but the coordinates given in the table above are in reference to the world coordinate system. The bowstring bone and the two IK chains are directly parented to the bow’s root bone, so their parent coordinates are all in relation to the coordinates of the root bone. Below is a table showing the parent coordinates of these three objects.

    Parent Coordinates

    Bowstring Bone
    IK Chain001
    IK Chain002
    X
    -18.41
    -17.282
    -17.282
    Y
    0.0
    -69.091
    69.087
    Z
    0.0
    -0.009
    -0.002

    I don’t want to launch into an explanation on the different coordinate systems that 3DS Max uses. Suffice it to say that because of the way the bowstring bone and IK chains are oriented, making the bone and chains move horizontally means moving them along their parent X axis, and moving them vertically means moving them along their parent Y axis. In the case of my model, the parent X axis of these objects correspond to the world Y axis, and the parent Y axis to the world Z axis. Got that? No? Let’s forge ahead anyway.

    Select the bowstring bone and right-click it to bring up a context-sensitive menu. Click Wire Parameters > Transform > Position> X Position.


    Click the IK chain at the top of the bow then click Transform > IK Goal > Position > X Position. This will bring up a dialog box named “Parameter Wiring #1.”


    We want to make the bowstring bone control IK Chain001 by making the IK chain’s X-position change whenever the bowstring bone’s X-position changes. To indicate that it is the bowstring bone controlling the IK chain and not the other way around, we click the button with the right-facing arrow in the dialog box. Next, we enter a formula for the IK chain’s X-position. As shown in the picture below, the formula for my model is

    X_Position*0.4 - 9.918

    What the above formula means is that the IK chain moves horizontally at a fraction of the speed that the bowstring moves along its parent X axis. The fraction, 0.4, was chosen through trial and error to get the bow to bend realistically when its string is pulled. The closer the fraction is to 0, the more resistant the bow becomes to bending. The closer the fraction is to 1, the more pliable the bow is. The value 9.918 is there to ensure that when the bowstring bone’s world Y-position is at 18.41 (its original position as shown in the above table), the world Y-position of IK Chain001 will be at 17.282 (the original position of the IK chain). I derived the value 9.918 by first entering the following formula as the expression for IK Chain001’s parent X_Position:

    X_Position*0.4

    I then clicked the Connect button and took note of the new world Y-position of IK Chain001, which was 7.364 for my model. I subtracted this new value from 17.282, the original world Y-position of the IK chain, to derive 9.918. I then edited my formula to subtract 9.918 then clicked the Update button in the dialog box.


  21. We also have to provide an expression for the parent Y-position of IK Chain001 to account for the lowering of the upper half of the bow when the bowstring is stretched. In the Parameter Wiring dialog box, in the box labeled IK Chain001, click the words “Y Position: Bezier Float.” As before, click the button with the right-pointing arrow to indicate that it is the bowstring bone controlling the IK chain then enter an appropriate expression for IK Chain001’s Y-position. For my model, I used the following formula:

    sqrt(4775.944 -(-0.6*X_Position - 9.918)^2) + 79.992

    This rather cumbersome formula is derived from the distance formula. Recall that in three-dimensional space, the square of the distance between any two points is as follows:

    distance
    2 = (x1 - x2)2 + (y1 - y2)2 + (z1 - z2)2

    For my model, the square of the distance between the bowstring bone and IK Chain001 is

    (0 + 0.009)
    2 + (18.41 - 17.282)2 + (80 - 149.091)2 = 4775.944

    Hence, the distance between these two objects is the square root of 4775.944, which is 69.108. However far we stretch the bowstring, we want the distance between the bowstring bone and IK Chain001 to be constant. We need to derive a formula for the parent Y-position of IK Chain001, given the parent X-position of the bowstring bone. If we let the coordinates (x
    1, y1, z1) represent the position of the bowstring bone and the coordinates (x2, y2, z2) the position of IK Chain001, we solve for y2 using the following formula:

    y
    2 = y1 - sqrt(distance2 - [z1 - z2]2 - [x1 - x2]2)

    Substituting the known X, Y, and Z positions of the bowstring bone and IK Chain001 as well as the distance between them, we derive the following:

    y
    2 = 80 - sqrt(4775.944 - [0 - -0.009]2 - [x1 - x2]2)
  22. = 80 - sqrt(4775.944 - [x1 - x2]2)

    Note that the expression [0 - -0.009]2 equates to 0.000081, a figure so small as to be practically zero for all intents and purposes.

    The parent Y-position of IK Chain001, y2, changes whenever the parent X-position of the bowstring bone changes as well. In fact, we’ve already established that x2 is given by the following formula:

    X_Position*0.4 - 9.918

    As for x
    1, it is simply the X_Position.

    Therefore, the Y-position of IK Chain001 is given by the following expression:


    80 - sqrt(4775.944 - [X_Position -{X_Position*0.4 - 9.918}]2)
    = 80 - sqrt(4775.944 - [0.6 * X_Position + 9.918]2)


    Written in a way that 3DS Max can interpret, this formula becomes

    80 - sqrt(4775.944 - (0.6*X_Position + 9.918)^2)

    Applying the above formula will cause the world Z-position of IK Chain001 to go down to 69.099 when the bowstring bone is at its original position, so we need to subtract 79.992 to the whole expression so that the world Z-position of the IK chain will be at 149.091. Hence the expression to use is

    80 - sqrt(4775.944 - (0.6*X_Position + 9.918)^2) - 79.992

    Simplifying, we get our final expression, which is

    0.008 - sqrt(4775.944 -(0.6*X_Position + 9.918)^2)


    Upon inputting the above formula as the expression for IK Chain001’s parent Y_Position, we click the Update button to apply it, after which we may close the Parameter Wiring dialog box.

    At this point, I should mention that the exact formulas given here and in the previous step will not necessarily work with other bow models unless the X, Y, and Z positions of the bowstring bone and the two IK chains are the same as the ones shown in the table in step 19. I took pains to explain the derivation of these formulas so that readers will understand how to adapt them for their models.

  23. Verify that the wire parameter works properly by using the Select and Move tool to move the bowstring bow horizontally like an arrow being strung. If the formulas we entered are correct, the upper half of the bow should bend the way a real bow should. Afterward, press [Ctrl]+Z to restore the bone to its original position.


  24. Just as we did with the upper half of the bow, we will set up some wire parameters for the lower half. Repeat step 20 above, but instead of clicking on the IK chain on top, click on IK Chain002. Because both IK chains have the same parent X-position, w set up the parent X-position of IK Chain002 exactly as we did with the other IK chain, using the same formula as before.

    The IK chains do not have the same parent Y-position, however. Also, whereas the upper IK chain should go down whenever we stretch the bowstring bone horizontally, the lower chain should go up. Initially, we set the expression of IK Chain002’s parent Y-position as follows:

    sqrt(4775.944 - (0.6*X_Position + 9.918)^2) - 80

    We then take note of the new world Z-position of IK Chain002 and subtract it from the IK chain’s original world Z-position to derive a constant that should be subtracted from the earlier formula. In the case of my model, the new world Z-position was 90.901. Subtracting this value from the original world Z-position of 10.913 gives us -79.988, which we subtract from the above formula to derive the following:

    sqrt(4775.944 - (0.6*X_Position + 9.918)^2) - 80 + 79.988

    Simplifying the formula gives us its final form:

    sqrt(4775.944 - (0.6*X_Position + 9.918)^2) - 0.012


    After updating the formula, we may close the Parameter Wiring dialog box.

  25. Repeat step 22 to verify that the wire parameters for both the upper and lower half of the bow have been set up correctly.


  26. We’re not quite done with the bow yet. If we were to push the bowstring bone a little toward the bow, we will see that the bow also moves. Likewise, pulling the bow a tiny distance away will also cause the bow to move. We want the bowstring to vibrate when it is released, but we don’t want the wood of the bow to move with it. We will need to edit our wire parameters to accomplish this.

    First, we have to decide how far the bowstring should be allowed to stretch before it moves the wood with it. For my model, I decided to apply a tolerance of 4 centimeters.

    Next, we select the bowstring bone then right-click it to bring up the context-sensitive menu. We click Wire Parameters > Transform > Position> X Position, after which we click IK Chain001 at the top of the bow then click Transform > IK Goal > Position > X Position. This will bring up the Parameter Wiring dialog box.

    We will edit the expression for IK Chain001’s X-position so that the IK chain will move horizontally only if the bowstring bone’s position exceeds our chosen tolerance. Otherwise, it will stay at its original parent position of -17.282. The expression that we entered previously should thus be replaced with the following:


    if X_Position <= -(18.41 + 4) then
    X_Position*0.4 - 9.918
    else
    -17.282


    In my model, the parent X coordinates of the bowstring bone and the IK chains run opposite to the world Y coordinates, which explains my use of negation (-) in the first line of the above expression.

  27. Next, click on the words “Y Position: Float Wire” in the box under IK Chain001. We will now edit the expression so that the bow will not bend up or down unless the bowstring bone goes beyond its tolerance limit. For my model, I edited the expression to read as follows:

    if X_Position <= -(18.41 + 4) then
    0.008 - sqrt(4775.944 - (0.6*X_Position + 9.918)^2)
    else
    -69.091


  28. Click the Show All Tracks button beside the label “IK Chain001” in the Parameter Wiring dialog box. The label “IK Chain001” will change to “World,” and we should now be able to see within this box all the objects that we can wire the bowstring bone to.  Scroll around the box until we see “IK Chain002,” which should be labeled in red. Click the “+” sign beside it to expand its contents then click the “+” signs of “Transform : IKChainControl,” “IK Goal : Position/Rotation/Scale,” and “Position : Position XYZ.” Now click “X Position : Float Wire,” which is also written in red. Edit the text in the box labeled “Expression for X_Position” so that it will be the same as what we wrote in step 25.


  29. Click the red label “Y Position : Float Wire” and edit the expression to read as follows:

    if X_Position <= -(18.41 + 4) then
    sqrt(4775.944 - (0.6*X_Position + 9.918)^2) - 0.012
    else
    69.087


  30. Close the Parameter Wiring dialog box and try moving the bowstring bone horizontally. Tiny movements should not cause the bow to bend, but pulling the bone farther ought to.

This ends my tutorial on rigging a bow. It’s a long tutorial, but I hope it’s also clear and easy to understand. Anyone who wants to offer feedback or suggestions for improvement is welcome to write in the Comments section.


Tuesday, January 29, 2013

Single Elf Female, Part 2

Having made a naked base model of a female elf as mentioned in my previous blog post, I set about to gearing up the elf model. There are many ways to design the armor and weapons of humanoid creatures, so I wasn’t sure at first on which direction to take my design. I turned to Google to see how other artists made their own renditions of elf women. Inspired by pictures of scantily clad blood elves, I initially thought of dressing my model in a bra, miniskirt, and boots. The design turned out to be rather bland, so I abandoned it and drew something that I should have done earlier – a silhouette of the elf.


The elf whose silhouette I drew is the type that an evil wizard would try to summon. This elf is of the Unseelie Court, whose members are feared for their malevolence. She is a veteran of the Wild Hunt, when unseelie folk would ride across the sky and kick up dark storm clouds that often heralded catastrophe or death. Her horned helm reflects her wild nature, and the layers of her black leather armor are like the protective plates of some draconic beast. Nevertheless, the elf is as beautiful as she is cruel, more akin to the creatures of Guillermo del Torro than J.R.R. Tolkien.

Instead of filling in the details of my 2D drawing, I went straight to modeling the armor in 3D. The final result is shown below. I decided to do away with the armor on the upper arms and thighs because I liked the effect of more skin showing.


Now that that’s done, it’s time for me to model the bow. From there, I will go straight to animating the elf.

Wednesday, January 16, 2013

Single Elf Female

I’ve been trying to make an elven female model since last month by working on a high-polygon mesh that I generated using Make Human. I thought that with the body already made, it would be a simple matter for me to make the hair and costume. This turned out to be a bad approach as I was spending way too much time working on details instead of starting with the big shapes first. I soon realized that at the level of detail I was working with, I wasn’t seeing the forest for the trees. What I needed was a low-poly base over which I could later design costumes and hair. I proceeded to create such a model about a week and a half ago.


The model shown above started life as a cylinder with six sides along its length. I morphed the cylinder to form the model’s right leg, which eventually grew into the rest of the body. I couldn’t figure out how to grow the head out of the neck, so I formed the head separately and attached it to the body later. As can be seen from the picture on the right, I was making an anime-style character. All told, the model weighs in at 2,064 triangles, which is fairly low poly, although it still has over four times the polygons of a Team Fortress character.

Now that the base mesh is complete, I can create the hair and costume of this character. I’ll post an update on my blog when I’m done.