<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>confectionary malfunction &#187; programming</title>
	<atom:link href="http://sugarandcyanide.com/blog/category/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://sugarandcyanide.com/blog</link>
	<description>i think i&#039;ve had a lot more than the bottle said to take</description>
	<lastBuildDate>Thu, 12 Jan 2012 00:57:44 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>fun with python modules</title>
		<link>http://sugarandcyanide.com/blog/2011/09/25/fun-with-python-modules/</link>
		<comments>http://sugarandcyanide.com/blog/2011/09/25/fun-with-python-modules/#comments</comments>
		<pubDate>Sun, 25 Sep 2011 18:17:20 +0000</pubDate>
		<dc:creator>kiki</dc:creator>
				<category><![CDATA[3d]]></category>
		<category><![CDATA[cinema4d]]></category>
		<category><![CDATA[maya]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[software]]></category>
		<category><![CDATA[c4d]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://sugarandcyanide.com/blog/2011/09/25/fun-with-python-modules/</guid>
		<description><![CDATA[New scripters I speak with don&#8217;t often know how to easily load code from external folders / modules in Python scripts. Today&#8217;s post will give you a few pointers in both Cinema 4D and Maya. Setting Your Script Paths Python&#8217;s import command should be no stranger to you if this topic interests you&#8211; it was [...]]]></description>
			<content:encoded><![CDATA[<p>New scripters I speak with don&#8217;t often know how to easily load code from external folders / modules in Python scripts. Today&#8217;s post will give you a few pointers in both Cinema 4D and Maya.</p>
<h3>Setting Your Script Paths</h3>
<p>Python&#8217;s import command should be no stranger to you if this topic interests you&#8211; it was probably the second thing most people learn in Python, after writing &#8220;Hello, World!&#8221; to the console. Import allows you to bring in code from libraries external to the source file in which you&#8217;re currently working. For example:</p>
<p><code>
<pre><font face="Lucida,Courier New"><font color="#008000"># commonly seen in Cinema 4D</font>
<font color="#C00000">import</font> <font color="#000000">c4d</font>
<font color="#C00000">from</font> <font color="#000000">c4d</font> <font color="#C00000">import</font> <font color="#0000C0">*</font>

<font color="#008000"># commonly seen in Maya</font>
<font color="#C00000">import</font> <font color="#000000">maya</font>
<font color="#C00000">from</font> <font color="#000000">maya</font> <font color="#C00000">import</font> <font color="#000000">cmds</font> <font color="#C00000">as</font> <font color="#000000">mc</font>
<font color="#C00000">import</font> <font color="#000000">pymel</font><font color="#0000C0">.</font><font color="#000000">all</font> <font color="#C00000">as</font> <font color="#000000">pm</font><font color="#000000"></font></font></pre>
<p></code></p>
<p>These statements bring whatever module you specify into the current namespace, or bring in functions, classes, and variables. But where are the libraries that the import method references? Where do they live on disk?</p>
<p>The easiest way to find out is to list Python&#8217;s sys.path:</p>
<p><code>
<pre><font face="Lucida,Courier New"><font color="#C00000">import</font> <font color="#000000">sys</font>
<font color="#C00000">print</font><font color="#0000C0">(</font><font color="#000000">sys</font><font color="#0000C0">.</font><font color="#000000">path</font><font color="#0000C0">)</font><font color="#000000"></font></font></pre>
<p></code></p>
<p>In my case, in Maya, it outputs the following:</p>
<p><code>
<pre><font face="Lucida,Courier New"><font color="#0000C0">[</font>
<font color="#004080">'/Applications/Autodesk/maya2012/Maya.app/Contents/MacOS'</font><font color="#0000C0">,</font>
<font color="#004080">'/Applications/Autodesk/maya2012'</font><font color="#0000C0">,</font>
<font color="#004080">'/Users/Carney/scripts/mayaScripts/scripts'</font><font color="#0000C0">,</font>

<font color="#0000C0">.</font><font color="#0000C0">.</font><font color="#0000C0">.</font>

<font color="#004080">u'/Users/Carney/Library/Preferences/Autodesk/maya/2012-x64/prefs/scripts'</font><font color="#0000C0">,</font>
<font color="#004080">u'/Users/Carney/Library/Preferences/Autodesk/maya/2012-x64/scripts'</font><font color="#0000C0">,</font>
<font color="#004080">u'/Users/Carney/Library/Preferences/Autodesk/maya/scripts'</font>
<font color="#0000C0">]</font><font color="#000000"></font></font></pre>
<p></code></p>
<p>Looking in the folders that are listed, you may find any number of Python source files and Python object files (*.pyc). sys.path is great because it&#8217;s just a regular Python list, which means it&#8217;s editable. You can append any number of paths that you like to it, and when import is called it will look through each and every path for the name specified.</p>
<p>Let&#8217;s try this in Cinema 4D. First, make a folder somewhere on your machine. I&#8217;m going to use /Users/Carney/Desktop/scripts for this example (I&#8217;m on a Mac.) In that folder, create a new file called util.py and add the following text:</p>
<p><code>
<pre><font face="Lucida,Courier New"><font color="#008000"># util.py</font>
<font color="#008000"># simple utility functions</font>

<font color="#C00000">def</font> <font color="#000000">ut_log</font><font color="#0000C0">(</font><font color="#0000C0">*</font><font color="#000000">args</font><font color="#0000C0">)</font><font color="#0000C0">:</font>
    <font color="#000000">msg</font> <font color="#0000C0">=</font><font color="#004080">''</font>
    <font color="#C00000">for</font> <font color="#000000">arg</font> <font color="#C00000">in</font> <font color="#000000">args</font><font color="#0000C0">:</font>
        <font color="#000000">msg</font> <font color="#0000C0">+=</font> <font color="#004080">' '</font> <font color="#0000C0">+</font> <font color="#000000">str</font><font color="#0000C0">(</font><font color="#000000">arg</font><font color="#0000C0">)</font>
    <font color="#C00000">print</font><font color="#0000C0">(</font><font color="#000000">msg</font><font color="#0000C0">)</font><font color="#000000"></font></font></pre>
<p></code></p>
<p>Now back in Cinema 4D, open the Console and the Script Manager from the Scripts menu. In the Script Manager, paste the following and hit Execute, replacing the path with the folder you chose above:</p>
<p><code>
<pre><font face="Lucida,Courier New"><font color="#C00000">import</font> <font color="#000000">sys</font>
<font color="#000000">sys</font><font color="#0000C0">.</font><font color="#000000">path</font><font color="#0000C0">.</font><font color="#000000">append</font><font color="#0000C0">(</font><font color="#004080">'/Users/Carney/Desktop/scripts'</font><font color="#0000C0">)</font>

<font color="#C00000">import</font> <font color="#000000">util</font>
<font color="#000000">util</font><font color="#0000C0">.</font><font color="#000000">ut_log</font><font color="#0000C0">(</font><font color="#004080">'Fun'</font><font color="#0000C0">,</font> <font color="#004080">'Bunnies'</font><font color="#0000C0">,</font> <font color="#004080">'are'</font><font color="#0000C0">,</font> <font color="#004080">'fun.'</font><font color="#0000C0">)</font><font color="#000000"></font></font></pre>
<p></code></p>
<p>If all&#8217;s well, you should get a single sentence printed to the console output. If you made a mistake, you may get an error about not being able to import the util file. Check your path and try again.</p>
<p>With this setup, you can write scripts in your application that reference lengthy libraries of external code or other utility functions that you&#8217;ve created. At the moment I&#8217;m organizing code into single files with multiple functions for shorter utilities. Any function that&#8217;s more complex gets it&#8217;s own file and a class to contain it. This leads to funny lines like the following:</p>
<p><code>
<pre><font face="Lucida,Courier New"><font color="#C00000">import</font> <font color="#000000">module_generic</font>
<font color="#000000">mod</font> <font color="#0000C0">=</font> <font color="#000000">module_generic</font><font color="#0000C0">.</font><font color="#000000">GenericModule</font><font color="#0000C0">(</font><font color="#0000C0">)</font><font color="#000000"></font></font></pre>
<p></code></p>
<p>But the organization and the ability to quickly update code without having to sift through a monolithic file inside the C4D Script Manager is worth the headache.</p>
<h3>Automatically Adding Python Search Paths in Maya</h3>
<p>The only thing to remember about this setup is that you have to make sure you add that folder you created to sys.path every time your application starts. In Maya this is a simple and well-known trick, but I had to do some digging to find out the same for Cinema 4D.</p>
<p>In both applications there&#8217;s a special Python file that gets loaded every time the Python VM restarts. In Maya, the file is called<br />
<h3>Automatically Adding Search Paths in Maya</h3>
<p> and it must live in one of three places:</p>
<ul>
<li>~/Library/Preferences/Autodesk/maya/2012-x64/prefs/scripts
<li>~/Library/Preferences/Autodesk/maya/2012-x64/scripts
<li>~/Library/Preferences/Autodesk/maya/scripts
</ul>
<p>You may notice that these are listed in the above printout of sys.path.  When Maya starts it will execute userSetup.py files it finds.  If you put the userSetup.py file in a folder that has the version of Maya specified (for example, in maya/2012-x64/scripts), then only that version will load the userSetup.  If you place it in the general scripts folder &#8212; the last folder listed above &#8212; then it will be loaded by all Maya versions that support Python.</p>
<p>You can also use the MEL command <code><strong>internalVar -usd</strong></code> to find a folder that will work.</p>
<p>The userSetup file can execute any code you like when Maya loads, allowing you to have custom menus auto-created or to modify your sys.path variable so that you can access your code at any time.  Try this: save a userSetup.py file into , and make sure it contains the following (after modifying the path to point to where you saved your util.py file):</p>
<p><code>
<pre><font face="Lucida,Courier New"><font color="#C00000">import</font> <font color="#000000">sys</font>
<font color="#000000">sys</font><font color="#0000C0">.</font><font color="#000000">path</font><font color="#0000C0">.</font><font color="#000000">append</font><font color="#0000C0">(</font><font color="#004080">'/Users/Carney/Desktop/scripts'</font><font color="#0000C0">)</font></font></pre>
<p></code></p>
<p>Now in Maya, open the script editor and copy, paste, and run the following:</p>
<p><code>
<pre><font face="Lucida,Courier New"><font color="#C00000">import</font> <font color="#000000">util</font>
<font color="#000000">util</font><font color="#0000C0">.</font><font color="#000000">ut_log</font><font color="#0000C0">(</font><font color="#004080">'Fun'</font><font color="#0000C0">,</font> <font color="#004080">'Bunnies'</font><font color="#0000C0">,</font> <font color="#004080">'are'</font><font color="#0000C0">,</font> <font color="#004080">'funner.'</font><font color="#0000C0">)</font><font color="#000000"></font></font></pre>
<p></code></p>
<p>If all worked, you&#8217;ll see a line printed from your userSetup.py file letting you know that the custom setup succeeded on Maya startup, and you&#8217;ll see the proper output from this file.</p>
<h3>Automatically Adding Python Search Paths in Cinema 4D</h3>
<p>The way to do the above in Cinema 4D seems to be less well-known: you have to find the folder that is appropriate for your particular version of Cinema 4D and copy in a file called <strong>python_init.py</strong>.</p>
<p>The easiest way to find this folder is to go to the Scripts menu and choose <strong>User Scripts > Script Folder</strong>.  This is the folder where scripts you&#8217;ve edited and saved through the Script Manager live.  Now, go up one folder to <strong>Library</strong>, then go up again.  This is the main folder for your version of Cinema 4D; it may have an oddly long name, but it contains your <strong>prefs</strong> and <strong>libraries</strong>.  The python_init.py file belongs in <strong>prefs/python</strong>.  As an example, my python_init.py folder is:</p>
<ul>
<li>/Users/Carney/Library/MAXON/Cinema 4D R13/prefs/python/</li>
</ul>
<h3>Final Notes</h3>
<p>This is just the start of organizing your code.  If you want to know more, I recommend reading <a href="http://docs.python.org/tutorial/modules.html" target="_blank">the official documentation on Python modules</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://sugarandcyanide.com/blog/2011/09/25/fun-with-python-modules/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>batch wrangling part 2 &#8211; Maya 2012 Human IK</title>
		<link>http://sugarandcyanide.com/blog/2011/08/23/batch-wrangling-part-2-maya-2012-human-ik/</link>
		<comments>http://sugarandcyanide.com/blog/2011/08/23/batch-wrangling-part-2-maya-2012-human-ik/#comments</comments>
		<pubDate>Tue, 23 Aug 2011 12:45:28 +0000</pubDate>
		<dc:creator>kiki</dc:creator>
				<category><![CDATA[3d]]></category>
		<category><![CDATA[maya]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[rigging]]></category>
		<category><![CDATA[mel]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[scripting]]></category>

		<guid isPermaLink="false">http://sugarandcyanide.com/blog/?p=153</guid>
		<description><![CDATA[The second half of the work I did was to automate the process of moving data around between Motion Builder and Maya, and to make tools for the animators that lightened their loads when it came to exporting and retargeting animations. I was also responsible for a batch conversion pipeline. On the project there were [...]]]></description>
			<content:encoded><![CDATA[<p>The second half of the work I did was to automate the process of moving data around between Motion Builder and Maya, and to make tools for the animators that lightened their loads when it came to exporting and retargeting animations.  I was also responsible for a batch conversion pipeline.</p>
<p>On the project there were animations in Motion Builder FBX files that were intended for reuse, which meant loading and retargeting multiple animations across multiple characters.  This is a case (if only minimal edits are required) where the HIK system in Maya can be used to blast through conversions and free up animators for other work.  Also, as many of the original animations were in single FBX files as Takes and the new decision was to have one file per animation (allowing multiple animators to work on the same character without file collisions in the version repository), the multi-take Motion Builder FBX files would need to be split in batch.</p>
<p>The Maya Human IK system as of Maya 2012 is usable and has a lot of good benefits.  Much of what they say works out of the box really does, provided you stick within the system: the ability to retarget animations between characters of differing sizes and joint placements works very well, and the fidelity of those animations stays high.  If you rename or reorient bones but still have a Characterization in place for both characters, the transfer will still work out.  However, there were also significant downsides:</p>
<li>
<p>The Motion Builder to Maya one-click scene send did not work as expected 100% of the time.  When transferring from Motion Builder to Maya, I often found that while the Characterization would transfer over the rig itself would not be properly connected, and many times did not even come in at the right position in the Maya scene.  Baking the keys down to the skeleton, transferring, and regenerating the rig on the Maya side <i>does</i> work.  You lose the editability of having less keys, but you get a one-to-one transfer between the two programs this way and the Characterization makes rebuilding and rebaking the keys to the rig a one-click process.</p>
</li>
<li>
<p>On the Maya side you lose a lot of the features you&#8217;d expect.  For example, the animators complained about not having foot roll controls. Regular Maya constraints don&#8217;t behave the same way you&#8217;d expect, and adding onto an HIK rig can be trickier than building on top of a regular Maya rig.  The strangest thing was that you can&#8217;t zero controls.  If you want to return to the &#8220;stance&#8221; pose, you have to change the input to the skeleton, then key the rig at the frame you want to have zero&#8217;d, and finally go back to having the rig control the skeleton.  Editing curves on the HIK rig can be frustrating, as both the FK and IK objects are used to control the final position of joints and the different Human IK modes for posing and interaction pull at the body parts in different ways; often animators were baffled about which controls were causing jitters or other issues, and it was usually a control for a body part much higher up the hierarchy.  Lastly, the HIK controls and skeleton don&#8217;t have the same orientations as the bones they&#8217;re based upon.  If you&#8217;ve set up your skeleton in Maya properly with behaviour-mirrored arms and legs, you&#8217;ll find that you have to pose HIK-rigged characters&#8217; limbs separately anyway.  (I only had time to look into these issues for a moment, as I had a lot on my plate; if there are easy solutions that were overlooked I&#8217;d love to know what they are.)</p>
</li>
<p>I had a look at the system and the commands it used when I walked through the Characterization and retargeting processes, and determined at the time that Python was not the way to go for the retargeting pipeline itself.  I found in tests that it was more work to get the MEL functions behind the HIK system working from Python than it was to write MEL wrapper functions and call out to them from Python when necessary.  It was also more efficient to use the MEL functions as they were, as opposed to pulling them apart to find the necessary node connections to set up the system on my own.</p>
<p>There&#8217;re a few lists of functions available online already (as I discovered on [insert blog link]).  Here&#8217;re the ones I ended up using.</p>
<li>
<p><b>HIKCharacterizationTool, HIKCharacterControlsTool</b> &#8212; These bring up their respective windows / docked panels.  I found that not having the relevant window open made the functions that depended on the window being open fail, so keep that in mind when running HIK commands in batch.</p>
</li>
<li>
<p><b>getCurrentCharacter()</b> &#8212; Returns the name of the current character as a string.</p>
</li>
<li>
<p><b>hikBakeToSkeleton</b> &#8212; Bakes the keys from the rig or from another character being used as a retargeting source to the skeleton. I used this function when exporting from Maya to the game engine.</p>
</li>
<li>
<p><b>characterizationControlRigDelete()</b> &#8212; Completely removes the control rig from the scene and sets the source for the character back to its skeleton.</p>
</li>
<li>
<p><b>setRigLookAndFeel(name, look number)</b> &#8212; There are a few different looks for HIK rigs.  In batch I found it nice to set the one I preferred before saving files out for animation fixes.</li>
</p>
<li>
<p><b>mayaHIKgetInputType</b> &#8212; Returns 0 if input type is Stance Pose, 1 if input type is skeleton or control rig (I guess this means &#8220;self&#8221;), and 2 if input is another character.</p>
</li>
<li>
<p><b>mayaHIKsetCharacterInput(character, input character)</b> &#8212; For retargeting, allows you to set the input of one character to be another in the scene.</p>
</li>
<li>
<p><b>characterizationCreate()</b> &#8212; Creates a new Characterization node.  You can rename the node and then make the UI recognize the new name with the following command.</p>
</li>
<li>
<p><b>characterizationToolUICmd</b> &#8212; Useful for setting the current character name: <code>characterizationToolUICmd -edit -setcurrentcharname [name]</code></p>
</li>
<li>
<p><b>setCharacterObject(object name, character name, characterization number, 0)</b> &#8212; I don&#8217;t think I&#8217;ve seen this documented elsewhere, but this does the connecting during the Characterization phase from your joints into the character node.  It appears the connections are specific and need to be fit into particular indices in a message attribute array, so the &#8220;characterization number&#8221; is something you need to figure out ahead of time if you&#8217;re doing a large number of these in batch.  Some important numbers:</p>
<p><center><br />
<table>
<tr>
<td width="150pt">Ground</td>
<td>0</td>
</tr>
<tr>
<td>Left Thigh</td>
<td>2</td>
</tr>
<tr>
<td>Left Calf</td>
<td>3</td>
</tr>
<tr>
<td>Left Foot</td>
<td>4</td>
</tr>
<tr>
<td>Left Toe</td>
<td>118</td>
</tr>
<tr>
<td>Right Foot</td>
<td>7</td>
</tr>
<tr>
<td>Right Toe</td>
<td>142</td>
</tr>
<tr>
<td>Right Calf</td>
<td>6</td>
</tr>
<tr>
<td>Right Thigh</td>
<td>5</td>
</tr>
<tr>
<td>Pelvis / Center of Motion</td>
<td>1</td>
</tr>
<tr>
<td>Left Clavicle</td>
<td>18</td>
</tr>
<tr>
<td>Right Clavicle</td>
<td>19</td>
</tr>
<tr>
<td>Left UpperArm</td>
<td>9</td>
</tr>
<tr>
<td>Left Forearm</td>
<td>10</td>
</tr>
<tr>
<td>Left Hand</td>
<td>11</td>
</tr>
<tr>
<td>Right UpperArm</td>
<td>12</td>
</tr>
<tr>
<td>Right Forearm</td>
<td>13</td>
</tr>
<tr>
<td>Right Hand</td>
<td>14</td>
</tr>
<tr>
<td>Neck Base</td>
<td>20</td>
</tr>
<tr>
<td>Head</td>
<td>15</td>
</tr>
<tr>
</table>
<p></center></p>
<p>The nice thing about this is that once you know all the numbers, you can slide them into attributes on the joints in your skeleton and use that data to apply characterizations later on.</p>
</li>
<p>Going forwards, if I were to use the same tools again in another production (and in cases where animation needs to be transferred between two differing skeletal hierarchies, it would make sense), I think I&#8217;d pull the code apart a bit more and have a look at how the connections are made at the lowest level, then rewrite a chunk of this code in Python.</p>
<p>One more thing: using the standard functions, sometimes the UI will take a bit to catch up.  Unfortunately, this means that functions which take inputs from the relevant UI will fail in situations where running them manually will work fine.  EvalDeferred didn&#8217;t fix this issue for me every time, possibly because of how Qt and Maya are connected together and how they both do lazy updates at different times.  I haven&#8217;t delved much into PyQt and Maya&#8217;s Qt underpinnings just yet, but the updating behavior is something for further study.  In the interim, I found that using the <code>maya.utils.processIdleEvents</code> function to make sure all events were taken care of after doing major steps in the characterization or baking processes helped the UI catch up.</p>
]]></content:encoded>
			<wfw:commentRss>http://sugarandcyanide.com/blog/2011/08/23/batch-wrangling-part-2-maya-2012-human-ik/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>batch wrangling &#8211; FBX</title>
		<link>http://sugarandcyanide.com/blog/2011/06/08/batch-wrangling-fbx/</link>
		<comments>http://sugarandcyanide.com/blog/2011/06/08/batch-wrangling-fbx/#comments</comments>
		<pubDate>Thu, 09 Jun 2011 02:14:22 +0000</pubDate>
		<dc:creator>kiki</dc:creator>
				<category><![CDATA[3d]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[work]]></category>
		<category><![CDATA[FBX]]></category>
		<category><![CDATA[HumanIK]]></category>
		<category><![CDATA[maya]]></category>
		<category><![CDATA[mel]]></category>

		<guid isPermaLink="false">http://sugarandcyanide.com/blog/?p=152</guid>
		<description><![CDATA[At work we&#8217;re moving from a MotionBuilder pipeline to Maya, which I&#8217;m responsible for creating. One of the tasks on the list I was handed was to move animated takes out of MB and into Maya so that all exported files can be run through the same export steps, and also so that moving forwards [...]]]></description>
			<content:encoded><![CDATA[<p>At work we&#8217;re moving from a MotionBuilder pipeline to Maya, which I&#8217;m responsible for creating. One of the tasks on the list I was handed was to move animated takes out of MB and into Maya so that all exported files can be run through the same export steps, and also so that moving forwards animators would have the same tools for working on older animations as they will on files using my new rig.</p>
<p>I have Maya Creation Suite 2012 on my work machine, which is touted as being able to seamlessly transfer data between the included apps&#8211; Maya, MotionBuilder, and Mudbox. I haven&#8217;t had need to open Mudbox yet, but in my limited testing so far the Human IK rigs never come through properly from MB to Maya and on the Maya side the HIK characterization gets broken. This means that to do any animation fixes or retargeting inside Maya, the characterization needs to be deleted and rebuilt. Also funny: the automatic naming templates in Maya don&#8217;t always work, making recharacterization a tedious manual process. Keyed transforms (joints, etc.) and meshes come through just fine, however, with all skinning and materials in tact. Updating previously-sent objects did not.</p>
<p>Apart from all that, the first file I&#8217;ve been working on has 50 animations in it. I didn&#8217;t relish the idea of converting all of them by hand, so I set about seeing what&#8217;s possible on the scripting side. </p>
<p>The FBX import/export plugin <a href="http://download.autodesk.com/us/fbx/20112/Maya/_index.html" target="_blank">comes with a number of commands</a> for massaging how files are read in. A full list of the commands is on Autodesk&#8217;s site. Note that the Python versions of these functions fail; I think they&#8217;re being generated improperly at plugin load. Could be that I&#8217;m just not calling them properly; I didn&#8217;t bug-hunt because I found doing the HIK post-import steps didn&#8217;t work in Python, either.</p>
<p>I&#8217;ve written more MEL in the last two days than I have in the last four years, not that it&#8217;s a lot of code!</p>
<p>The important commands for what I needed are:</p>
<p><code>FBXRead -f [filename]</code> &#8212; Doesn&#8217;t do any loading. Instead, it sets the specified file as the source for all queries.</p>
<p><code>FBXGetTakeCount</code> &#8212; Self-explanatory; on the file I was editing it returned 50. </p>
<p><code>FBXGetTakeName [index]</code>: returns the name of the take for a specified index. The indices are 1-based. I saved all of these in a string array. </p>
<p><code>FBXImportSetMayaFrameRate -v [true|false]</code> &#8212; Important in my case because the animation was all at 30 frames per second, while Maya is usually set to 24.</p>
<p><code>FBXImportFillTimeline -v [true|false]</code> &#8212; Makes sure the timeline length matches the length of the imported animation (although see below for a gotcha)</p>
<p><code>FBXImport -file "c:/myfile.fbx" -t [take index]</code> &#8212; Does the actual loading of the scene. By specifying a take index, you can be sure to get only the animation you want.</p>
<p>With this information, I was able to loop through the animations in the FBX and, after a bit of post-import processing, spit out a series of .ma files. </p>
<p>There were few gotchas. One problem was that while the script was running, sometimes the setting for having the FBX file&#8217;s time length override the same in Maya would get truncated&#8211; the animation length got set but the [bar that shortens the animation] would get set to half the length. I couldn&#8217;t replicate the issue running the MEL script in small chunks. A call to <code>playbackOptions</code> in my loop fixed this, but it&#8217;s still weird. </p>
<p>Part two of this discussion will be about man-handling Maya&#8217;s Human IK in a batch process.</p>
]]></content:encoded>
			<wfw:commentRss>http://sugarandcyanide.com/blog/2011/06/08/batch-wrangling-fbx/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>quick tip #1</title>
		<link>http://sugarandcyanide.com/blog/2011/04/29/quick-tip-1/</link>
		<comments>http://sugarandcyanide.com/blog/2011/04/29/quick-tip-1/#comments</comments>
		<pubDate>Fri, 29 Apr 2011 13:00:35 +0000</pubDate>
		<dc:creator>kiki</dc:creator>
				<category><![CDATA[3d]]></category>
		<category><![CDATA[life]]></category>
		<category><![CDATA[maya]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[mel]]></category>
		<category><![CDATA[scripting]]></category>

		<guid isPermaLink="false">http://sugarandcyanide.com/blog/?p=149</guid>
		<description><![CDATA[It&#8217;s been a while since I&#8217;ve done anything in MEL. I try to avoid MEL when I can; after two years of doing the majority of my Maya tools and scripts in Python (with the last year being pure Python), switching gears to work in MEL and losing the object-oriented nature of Python (along with [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s been a while since I&#8217;ve done anything in MEL.  I try to avoid MEL when I can; after two years of doing the majority of my Maya tools and scripts in Python (with the last year being pure Python), switching gears to work in MEL and losing the object-oriented nature of Python (along with its wonderful string and array manipulation tools) makes me feel like I&#8217;ve got a hand tied behind my back.</p>
<p>Still, MEL&#8217;s importance will continue for some time and there will be times when it&#8217;s necessary to hack out a bit MEL code.  I wanted to make a quick tip note about something I&#8217;m embarrassed to say I didn&#8217;t know until a few days ago that might help you with your MEL scripts.</p>
<p>I use the <a href="http://download.autodesk.com/global/docs/maya2012/en_us/Commands/whatIs.html" target="_blank">whatIs</a> command often to track down the source of built-in scripted functionality.  Calling it on a function that exists in default MEL scripts will tell you in which script that function lives and where to find it; afterwards, you can break it apart and use the pertinent parts in your own script.</p>
<p>However, what I did not know is that whatIs can also tell you about in-memory variables.  Here&#8217;s an example:</p>
<p><code>string $value = "Bunnies";<br />
int $intArray[] = { 1,2,3,4,5 };</p>
<p>whatIs "$value";		// Result: string variable //<br />
whatIs "$intArray";		// Result: int[] variable //<br />
</code></p>
<p>If you run the code you&#8217;ll see that it returns a string with the type of the variable you checked.  Quite handy, since you can use it to check types of default global variables.  But even handier is what happens when you use it on a variable that has not yet been created:</p>
<p><code>whatIs "$someWonderfulVariable";</code></p>
<p>This will return the string &#8220;Unknown&#8221;.  If you, not unlike my recent self, are trying to determine in your or someone else&#8217;s code whether a required variable has been created, this is the way to check.</p>
<p>In other news, my new job begins on Tuesday. I&#8217;m extremely excited and I&#8217;ll post more about it once I&#8217;ve gotten situated there.  </p>
<p>Also, if you&#8217;re Canadian, elections are happening on Monday! An interesting notion is the thought of voting for a non-Reform party candidate in your riding whose projections are highest instead of voting for the party or a leader you&#8217;re usually inclined to do, with an eye towards unseating the current Reform government and getting Harper out of there.  Two websites on this very thing:</p>
<p><a href="http://www.whipharper.ca/" target="_blank">http://www.whipharper.ca/</a> <br />
<a href="http://www.projectdemocracy.ca/" target="_blank">http://www.projectdemocracy.ca/</a></p>
<p>Don&#8217;t worry&#8211; I won&#8217;t be mixing political messages with code tips in the future.</p>
]]></content:encoded>
			<wfw:commentRss>http://sugarandcyanide.com/blog/2011/04/29/quick-tip-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>first steps in openCL</title>
		<link>http://sugarandcyanide.com/blog/2010/07/31/first-steps-in-opencl/</link>
		<comments>http://sugarandcyanide.com/blog/2010/07/31/first-steps-in-opencl/#comments</comments>
		<pubDate>Sat, 31 Jul 2010 13:14:22 +0000</pubDate>
		<dc:creator>kiki</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[gpgpu]]></category>
		<category><![CDATA[openCL]]></category>

		<guid isPermaLink="false">http://sugarandcyanide.com/blog/?p=128</guid>
		<description><![CDATA[I&#8217;m going to post something about my trip to Italy in a bit, after I get my pics uploaded properly to Flickr. But I wanted to put this up so I don&#8217;t forget about it later. A conversation at work got me interested enough in GPGPU calculations to start doing a bit of research into [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m going to post something about my trip to Italy in a bit, after I get my pics uploaded properly to Flickr.  But I wanted to put this up so I don&#8217;t forget about it later.</p>
<p>A conversation at work got me interested enough in GPGPU calculations to start doing a bit of research into the topic.  Seems that at a base level both the ATI and NVidia APIs behave similarly, and that OpenCL is a nice, understandable alternative if you don&#8217;t want to be locked in to a single vendor. (Not that I use ATI cards.)  I tried getting CUDA working on my Mac, but between weirdness caused by the drivers and the fact that it doesn&#8217;t support 64-bit on OSX, I&#8217;ve decided to go with <a href="http://www.khronos.org/registry/cl/">OpenCL</a> instead for my tests.  Functionally everything will be the same, and after a nice tutorial on <a href="http://developer.amd.com/GPU/ATISTREAMSDK/pages/TutorialOpenCL.aspx">ATI&#8217;s site detailing some introductory points</a> I have code that compiles and does what I want it to do, which is more than I can say for CUDA.</p>
<p>Anyway, here&#8217;s my first test.  I wanted something simple for getting device information off my laptop.</p>
<p>
<div class="cpp" style="font-family:monospace;color: #006; border: 1px solid #d0d0d0; background-color: #f0f0f0;"><span style="color: #339900;">#include &lt;iostream&gt;</span><br />
<span style="color: #0000ff;">using</span> <span style="color: #0000ff;">namespace</span> std<span style="color: #008080;">;</span></p>
<p><span style="color: #339900;">#include &lt;stdio.h&gt;</span><br />
<span style="color: #339900;">#include &lt;stdlib.h&gt;</span></p>
<p><span style="color: #339900;">#include &lt;OpenGL/gl.h&gt;</span><br />
<span style="color: #339900;">#include &lt;OpenGL/CGLDevice.h&gt;</span><br />
<span style="color: #339900;">#include &lt;OpenCL/cl.h&gt;</span><br />
<span style="color: #339900;">#include &lt;OpenCL/cl_gl.h&gt;</span><br />
<span style="color: #339900;">#include &lt;OpenCL/cl_gl_ext.h&gt;</span><br />
<span style="color: #339900;">#include &lt;OpenCL/cl_ext.h&gt;</span><br />
&nbsp;<br />
<span style="color: #339900;">#define MSG_SIZE 4096</span><br />
<span style="color: #339900;">#define MAX_DEVICE_IDS 16</span></p>
<p><span style="color: #339900;">#define RT_STRING &nbsp; &nbsp; &nbsp; 0</span><br />
<span style="color: #339900;">#define RT_UINT &nbsp; &nbsp; &nbsp; &nbsp; 1</span><br />
<span style="color: #339900;">#define RT_BOOL &nbsp; &nbsp; &nbsp; &nbsp; 2</span><br />
<span style="color: #339900;">#define RT_PLATFORMID &nbsp; 3</span><br />
<span style="color: #339900;">#define RT_SIZET&nbsp; &nbsp; &nbsp; &nbsp; 5</span><br />
<span style="color: #339900;">#define RT_SIZET_ARR&nbsp; &nbsp; 6</span></p>
<p>
<span style="color: #0000ff;">void</span> printDeviceInfo<span style="color: #008000;">&#40;</span>cl_device_id deviceID<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; cl_device_info param_list<span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> <span style="color: #000080;">=</span> <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; CL_DEVICE_NAME, CL_DEVICE_VENDOR, CL_DRIVER_VERSION, CL_DEVICE_VERSION,<br />
&nbsp; &nbsp; &nbsp; &nbsp; CL_DEVICE_PROFILE, <br />
&nbsp; &nbsp; &nbsp; &nbsp; CL_DEVICE_PLATFORM, CL_DEVICE_VENDOR_ID,<br />
&nbsp; &nbsp; &nbsp; &nbsp; CL_DEVICE_MAX_COMPUTE_UNITS, CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS, <br />
&nbsp; &nbsp; &nbsp; &nbsp; CL_DEVICE_MAX_WORK_ITEM_SIZES, CL_DEVICE_MAX_WORK_GROUP_SIZE,<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">NULL</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><span style="color: #008080;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #0000ff;">int</span> param_return_types<span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> <span style="color: #000080;">=</span> <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; RT_STRING, RT_STRING, RT_STRING, RT_STRING,<br />
&nbsp; &nbsp; &nbsp; &nbsp; RT_STRING, RT_PLATFORMID, RT_UINT,<br />
&nbsp; &nbsp; &nbsp; &nbsp; RT_UINT, RT_UINT, RT_SIZET_ARR, RT_SIZET,<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">NULL</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><span style="color: #008080;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #0000ff;">char</span> <span style="color: #000040;">*</span>param_strings<span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> <span style="color: #000080;">=</span> <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #FF0000;">&quot;Device Name&quot;</span>, <span style="color: #FF0000;">&quot;Vendor&quot;</span>, <span style="color: #FF0000;">&quot;Driver Version&quot;</span>, <span style="color: #FF0000;">&quot;Device Version&quot;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #FF0000;">&quot;Device Profile&quot;</span>, <span style="color: #FF0000;">&quot;Device Platform&quot;</span>, <span style="color: #FF0000;">&quot;Device Vendor ID&quot;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #FF0000;">&quot;Max Compute Units&quot;</span>, <span style="color: #FF0000;">&quot;Max Work Item Dimensions&quot;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #FF0000;">&quot;Max Work Item Sizes&quot;</span>, <span style="color: #FF0000;">&quot;Max Work Group Size&quot;</span>,<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">NULL</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><span style="color: #008080;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #0000ff;">int</span> i <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span><br />
&nbsp; &nbsp; <span style="color: #0000ff;">int</span> maxWorkItemDimensions <span style="color: #000080;">=</span> <span style="color: #0000dd;">3</span><span style="color: #008080;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #0000ff;">while</span><span style="color: #008000;">&#40;</span>param_strings<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span> <span style="color: #000040;">!</span><span style="color: #000080;">=</span> <span style="color: #0000ff;">NULL</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">char</span>&nbsp; &nbsp; msg<span style="color: #008000;">&#91;</span>MSG_SIZE<span style="color: #008000;">&#93;</span><span style="color: #008080;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">size_t</span>&nbsp; param_sizeT<span style="color: #008080;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">size_t</span>&nbsp; param_sizeT_array<span style="color: #008000;">&#91;</span>MSG_SIZE<span style="color: #008000;">&#93;</span><span style="color: #008080;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; cl_uint param_uint<span style="color: #008080;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; cl_bool param_bool<span style="color: #008080;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">size_t</span>&nbsp; param_value_ret<span style="color: #008080;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; cl_platform_id param_platformID<span style="color: #008080;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; cl_int error<span style="color: #008080;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">switch</span> <span style="color: #008000;">&#40;</span>param_return_types<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">case</span> RT_STRING<span style="color: #008080;">:</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; error <span style="color: #000080;">=</span> clGetDeviceInfo<span style="color: #008000;">&#40;</span>deviceID, <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; param_list<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span>, <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; MSG_SIZE,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; msg,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000040;">&amp;</span>param_value_ret<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> param_strings<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;: &quot;</span> <span style="color: #000080;">&lt;&lt;</span> msg <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #008080;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">break</span><span style="color: #008080;">;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">case</span> RT_UINT<span style="color: #008080;">:</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; error <span style="color: #000080;">=</span> clGetDeviceInfo<span style="color: #008000;">&#40;</span>deviceID, <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; param_list<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span>, <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000dd;">sizeof</span><span style="color: #008000;">&#40;</span>cl_uint<span style="color: #008000;">&#41;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000040;">&amp;</span>param_uint,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">NULL</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> param_strings<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;: &quot;</span> <span style="color: #000080;">&lt;&lt;</span> param_uint <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #008080;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">break</span><span style="color: #008080;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">case</span> RT_BOOL<span style="color: #008080;">:</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; error <span style="color: #000080;">=</span> clGetDeviceInfo<span style="color: #008000;">&#40;</span>deviceID, <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; param_list<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span>, <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000dd;">sizeof</span><span style="color: #008000;">&#40;</span>cl_bool<span style="color: #008000;">&#41;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000040;">&amp;</span>param_bool,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">NULL</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> param_strings<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;: &quot;</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #008000;">&#40;</span>param_bool <span style="color: #008080;">?</span> <span style="color: #FF0000;">&quot;True&quot;</span> <span style="color: #008080;">:</span> <span style="color: #FF0000;">&quot;False&quot;</span><span style="color: #008000;">&#41;</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #008080;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">break</span><span style="color: #008080;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">case</span> RT_PLATFORMID<span style="color: #008080;">:</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; error <span style="color: #000080;">=</span> clGetDeviceInfo<span style="color: #008000;">&#40;</span>deviceID, <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; param_list<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span>, <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000dd;">sizeof</span><span style="color: #008000;">&#40;</span>cl_platform_id<span style="color: #008000;">&#41;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; param_platformID,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">NULL</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> param_strings<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;: &quot;</span> <span style="color: #000080;">&lt;&lt;</span> param_platformID <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #008080;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">break</span><span style="color: #008080;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">case</span> RT_SIZET<span style="color: #008080;">:</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; error <span style="color: #000080;">=</span> clGetDeviceInfo<span style="color: #008000;">&#40;</span>deviceID, <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; param_list<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span>, <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000dd;">sizeof</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">size_t</span><span style="color: #008000;">&#41;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000040;">&amp;</span>param_sizeT,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">NULL</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> param_strings<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;: &quot;</span> <span style="color: #000080;">&lt;&lt;</span> param_sizeT <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #008080;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">break</span><span style="color: #008080;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">case</span> RT_SIZET_ARR<span style="color: #008080;">:</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; error <span style="color: #000080;">=</span> clGetDeviceInfo<span style="color: #008000;">&#40;</span>deviceID, <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; param_list<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span>, <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000dd;">sizeof</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">size_t</span><span style="color: #008000;">&#41;</span> <span style="color: #000040;">*</span> maxWorkItemDimensions,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; param_sizeT_array,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000040;">&amp;</span>param_value_ret<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> param_strings<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;: &quot;</span> <span style="color: #000080;">&lt;&lt;</span> param_sizeT_array<span style="color: #008000;">&#91;</span><span style="color: #0000dd;">0</span><span style="color: #008000;">&#93;</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;, &quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000080;">&lt;&lt;</span> param_sizeT_array<span style="color: #008000;">&#91;</span><span style="color: #0000dd;">1</span><span style="color: #008000;">&#93;</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;, &quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000080;">&lt;&lt;</span> param_sizeT_array<span style="color: #008000;">&#91;</span><span style="color: #0000dd;">2</span><span style="color: #008000;">&#93;</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #008080;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">break</span><span style="color: #008080;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">default</span><span style="color: #008080;">:</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">break</span><span style="color: #008080;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; i<span style="color: #000040;">++</span><span style="color: #008080;">;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<span style="color: #008000;">&#125;</span></p>
<p>
<span style="color: #0000ff;">int</span> main<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span> argc, <span style="color: #0000ff;">char</span> <span style="color: #000040;">**</span>argv<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; cl_device_id deviceID<span style="color: #008080;">;</span><br />
&nbsp; &nbsp; cl_uint numDevices<span style="color: #008080;">;</span></p>
<p>&nbsp; &nbsp; cl_uint err <span style="color: #000080;">=</span> clGetDeviceIDs<span style="color: #008000;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">NULL</span>, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; CL_DEVICE_TYPE_CPU, &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; MAX_DEVICE_IDS, &nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000040;">&amp;</span>deviceID,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000040;">&amp;</span>numDevices<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;Number of CPU devices: &quot;</span> <span style="color: #000080;">&lt;&lt;</span> numDevices <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #008080;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #0000ff;">for</span> <span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span> i <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span> i <span style="color: #000080;">&lt;</span> numDevices<span style="color: #008080;">;</span> i<span style="color: #000040;">++</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; printDeviceInfo<span style="color: #008000;">&#40;</span>deviceID<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span></p>
<p>&nbsp; &nbsp; <span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #008080;">;</span></p>
<p>&nbsp; &nbsp; <br />
&nbsp; &nbsp; </p>
<p>&nbsp; &nbsp; err <span style="color: #000080;">=</span> clGetDeviceIDs<span style="color: #008000;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">NULL</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; CL_DEVICE_TYPE_GPU,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; MAX_DEVICE_IDS,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000040;">&amp;</span>deviceID,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000040;">&amp;</span>numDevices<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;Number of GPU devices: &quot;</span> <span style="color: #000080;">&lt;&lt;</span> numDevices <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #008080;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #0000ff;">for</span> <span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span> i <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span> i <span style="color: #000080;">&lt;</span> numDevices<span style="color: #008080;">;</span> i<span style="color: #000040;">++</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; printDeviceInfo<span style="color: #008000;">&#40;</span>deviceID<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #008080;">;</span><br />
&nbsp; &nbsp; <br />
<span style="color: #008000;">&#125;</span><br />
&nbsp;</div>
</p>
<p>(Hope that copy-and-pasted correctly.)  To compile it on your Mac:</p>
<p>
<div class="cpp" style="font-family:monospace;color: #006; border: 1px solid #d0d0d0; background-color: #f0f0f0;">g++ test2.cpp -o test2 -framework OpenCL</div>
</p>
<p>Here are the results on my laptop, a 2010 Core i7 MacBook Pro 15&#8243;:</p>
<pre>Number of CPU devices: 1
Device Name: Intel(R) Core(TM) i7 CPU       M 620  @ 2.67GHz
Vendor: Intel
Driver Version: 1.0
Device Version: OpenCL 1.0
Device Profile: FULL_PROFILE
Device Platform: 0
Device Vendor ID: 16909312
Max Compute Units: 4
Max Work Item Dimensions: 3
Max Work Item Sizes: 1, 1, 1
Max Work Group Size: 1

Number of GPU devices: 1
Device Name: GeForce GT 330M
Vendor: NVIDIA
Driver Version: CLH 1.0
Device Version: OpenCL 1.0
Device Profile: FULL_PROFILE
Device Platform: 0
Device Vendor ID: 16918016
Max Compute Units: 6
Max Work Item Dimensions: 3
Max Work Item Sizes: 512, 512, 64
Max Work Group Size: 512
</pre>
<p>Next step: getting the GPU to do some calculations.</p>
]]></content:encoded>
			<wfw:commentRss>http://sugarandcyanide.com/blog/2010/07/31/first-steps-in-opencl/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>funhouse and the big top</title>
		<link>http://sugarandcyanide.com/blog/2010/06/11/building-allegro-5-programs-on-os-x/</link>
		<comments>http://sugarandcyanide.com/blog/2010/06/11/building-allegro-5-programs-on-os-x/#comments</comments>
		<pubDate>Fri, 11 Jun 2010 03:17:02 +0000</pubDate>
		<dc:creator>kiki</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[funhouse]]></category>
		<category><![CDATA[life]]></category>
		<category><![CDATA[work]]></category>

		<guid isPermaLink="false">http://sugarandcyanide.com/blog/?p=118</guid>
		<description><![CDATA[As I type this I&#8217;m over at FUNHouse central with Dimos. It&#8217;s been a while since we were able to work on things together, in person. Usually we work a lot over email and lunchtime talks; it&#8217;ll be good to sit and jam together. It&#8217;s been an interesting week. I&#8217;ve been tasked with doing research [...]]]></description>
			<content:encoded><![CDATA[<p>As I type this I&#8217;m over at FUNHouse central with Dimos. It&#8217;s been a while since we were able to work on things together, in person. Usually we work a lot over email and lunchtime talks; it&#8217;ll be good to sit and jam together.</p>
<p>It&#8217;s been an interesting week. I&#8217;ve been tasked with doing research on cloth simming, or rather not simming, which is about all I can say. However, I can say that it&#8217;s been an interesting challenge and has helped me to better understand some of the more esoteric corners of Maya Dynamics.</p>
<p>Work aside, the G20 meet up has the entire city by the balls. The trains are shutting down due to bomb threats, and a number of people at the office have been ID&#8217;d on the way in by the some of the hundreds of cops patrolling the downtown core. The whole thing is a mess. Lots of downtown businesses are losing money because of forced shutdowns. Even my office is shutting for friday because the building is getting boarded up.</p>
<p>It&#8217;s strange to me&#8230; I can&#8217;t quite follow the logic on violent protests for something like this. Regardless of what&#8217;s being discussed, I can&#8217;t imagine any topics are worthy of that kind of response.</p>
<p>Anyway, to work with us!</p>
]]></content:encoded>
			<wfw:commentRss>http://sugarandcyanide.com/blog/2010/06/11/building-allegro-5-programs-on-os-x/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>new yaaaawk, baybee!</title>
		<link>http://sugarandcyanide.com/blog/2010/04/02/new-yaaaawk-baybee/</link>
		<comments>http://sugarandcyanide.com/blog/2010/04/02/new-yaaaawk-baybee/#comments</comments>
		<pubDate>Fri, 02 Apr 2010 01:15:09 +0000</pubDate>
		<dc:creator>kiki</dc:creator>
				<category><![CDATA[3d]]></category>
		<category><![CDATA[math]]></category>
		<category><![CDATA[maya]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://sugarandcyanide.com/blog/?p=106</guid>
		<description><![CDATA[Dimos and I headed out over the weekend to see Mike in New York. The title of this post is what Dimos screamed, cheerleader-on-prom-night-in-the-back-of-a-volkswagen style, every five minutes. Somehow it never got old. There are amazing pictures taken by Mike of both Dimos and myself on Facebook; hopefully I&#8217;ll find some time this weekend to [...]]]></description>
			<content:encoded><![CDATA[<p>Dimos and I headed out over the weekend to see <a href="http://www.luckbat.com/" target="_blank">Mike</a> in New York.  The title of this post is what Dimos screamed, cheerleader-on-prom-night-in-the-back-of-a-volkswagen style, every five minutes.  Somehow it never got old.</p>
<p>There are amazing pictures taken by Mike of both Dimos and myself on Facebook; hopefully I&#8217;ll find some time this weekend to get the pics of my own camera and Flickrize them.</p>
<p>I might talk a bit more about the trip in a few days, but what I actually wanted to write is this:</p>
<p>To project a worldspace point into camera space, you need to multiply the camera&#8217;s view matrix by its projection matrix.  The projection matrix is grabbable through the OpenMaya API (there&#8217;s a function for it on MFnCamera). The view matrix is simply the inverse of the worldspace transform matrix.</p>
<p>Needed to get that out of my head and into a place I wouldn&#8217;t lose it.  If that makes no sense to you, just pretend it wasn&#8217;t there. <img src='http://sugarandcyanide.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://sugarandcyanide.com/blog/2010/04/02/new-yaaaawk-baybee/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>playing in coffee</title>
		<link>http://sugarandcyanide.com/blog/2009/09/12/playing-in-coffee/</link>
		<comments>http://sugarandcyanide.com/blog/2009/09/12/playing-in-coffee/#comments</comments>
		<pubDate>Sat, 12 Sep 2009 03:35:52 +0000</pubDate>
		<dc:creator>kiki</dc:creator>
				<category><![CDATA[3d]]></category>
		<category><![CDATA[cinema4d]]></category>
		<category><![CDATA[coffee]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://sugarandcyanide.com/blog/?p=86</guid>
		<description><![CDATA[I&#8217;m slowly coming out of the fog of Maya, now that I&#8217;m done with using it for Animation Mentor, and I&#8217;ve been trying to get back into Cinema 4D. I just wanted to post this short COFFEE script snippet. This looks through all the animation curves on an object and spits out information on them. [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m slowly coming out of the fog of Maya, now that I&#8217;m done with using it for Animation Mentor, and I&#8217;ve been trying to get back into Cinema 4D.  I just wanted to post this short COFFEE script snippet.  This looks through all the animation curves on an object and spits out information on them.</p>
<pre>
var op = doc->GetActiveObject();
var curTime = doc->GetTime();

println("\nKey dump for ", op->GetName(), ":\n");

var t = op->GetFirstCTrack();
if (t == NULL)
	println("Error.");

var i = 0;
var j = 0;
var k;
var c;

while (t != NULL) {
	i++;
	c = t->GetCurve();
	println("\tTrack ", i, ": ", t->GetName(), " -- ",
	c->GetKeyCount(), " keys.");

	for (j = 0; j < c->GetKeyCount(); j++) {
		k = c->GetKey(j);
		var bt = k->GetTime();
		println("\t\t", j, ": v", k->GetValue(), ", t:", bt->GetFrame(30));
	}

	t = t->GetNext();
}

println("Number of tracks: ", i);
</pre>
<p>The sad part is this: you can&#8217;t add new keys to curves in COFFEE; you can only read what&#8217;s there.  (EPIC FAIL, Maxon.)  At least now I know how to get keys and how the BaseTime class works.</p>
]]></content:encoded>
			<wfw:commentRss>http://sugarandcyanide.com/blog/2009/09/12/playing-in-coffee/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Weak References</title>
		<link>http://sugarandcyanide.com/blog/2009/08/19/weak-references/</link>
		<comments>http://sugarandcyanide.com/blog/2009/08/19/weak-references/#comments</comments>
		<pubDate>Wed, 19 Aug 2009 00:42:03 +0000</pubDate>
		<dc:creator>kiki</dc:creator>
				<category><![CDATA[3d]]></category>
		<category><![CDATA[cinema4d]]></category>
		<category><![CDATA[maya]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[rigging]]></category>

		<guid isPermaLink="false">http://sugarandcyanide.com/blog/?p=81</guid>
		<description><![CDATA[Last year while I was working at Red Rover, I heard the term &#8220;weak reference&#8221; in reference to a technique for referencing objects in 3DS Max. The Max TD used them for a variety of things. I didn&#8217;t quite understand what he was talking about at the time, since the last version of Max I [...]]]></description>
			<content:encoded><![CDATA[<p>Last year while I was working at Red Rover, I heard the term &#8220;weak reference&#8221; in reference to a technique for referencing objects in 3DS Max. The Max TD used them for a variety of things. I didn&#8217;t quite understand what he was talking about at the time, since the last version of Max I used was 2.5 and I never did rigging or coding for it then.</p>
<p>More recently I&#8217;ve come to the same technique on my own both in Maya and in Cinema 4D, and was reminded of the name for it by that same TD over beers a few weeks back.</p>
<p>Essentially, weak references are variables on objects that contain a pointer to an object, and not a reference to it&#8217;s name. In Maya, for example, you may see rigging scripts written by TDs referencing specific objects by name or saving names of objects as they&#8217;re created and using those names to connect attributes or add constraints. In a clean scene this works fine, as long as the rigger is meticulous in their naming scheme and runs different stages of the rigging script in proper order.</p>
<p>But what happens when Maya namespaces become involved? As soon as you reference in an asset, every object that makes up that asset gets a namespace prefixed onto it&#8217;s name. If you&#8217;ve written scripts that require specific names, they break. If your layout files aren&#8217;t perfect and the namespace is different between two or more shots (as Maya is wont to append a number, regardless of what you specify), useful tools like character GUIs and the like break and you&#8217;re left doing namespace surgery in a text editor.</p>
<p>Weak references sidestep all this by giving you a permanent connection to an object regardless of name changes or namespace prefixes.</p>
<p>A good example is how I&#8217;m currently handling cameras in scenes. A decision was made early on, on the current project at work, to name cameras in layout files by the name of the shot / sequence. Normally this isnt a problem, but we&#8217;re using a renderer that&#8217;s not linked into Maya directly and therefore needs a command line batch exporter written. If all the cameras are named differently, and the camera&#8217;s animation has to be baked and exported as well, how do you go about picking the right object?</p>
<p>Using weak references, the problem becomes trivial. You create them as follows:</p>
<p><code>addAttr -ln "cameraObj" -at "message";</code></p>
<p>You&#8217;ve probably seen attribute connections of type message into IK handles and other things. The message attribute carries no data&#8211; that is, it never changes and causes no DAG recalculations. (This is doubly useful because you can connect the message attributes of two objects to message-typed user attributes in a cycle without causing a cycle error&#8211; more on that later.) However, the attribute can be used to get the name of the connected object like so:</p>
<p><code>listConnections object.messageAttribute;</code></p>
<p>It will return an array of strings. If you rename an object, you can get the object&#8217;s current name through the above command.</p>
<p>So where do you store these attributes? For the moment I&#8217;m using a trick I saw on the Siggraph &#8217;08 talk by <a href="http://www.blueskystudios.com/content/index.php" target="_blank">Blue Sky</a> on procedural rigging: I create non-executing script nodes and store connections on them. In the camera example above, every scene has a master script node. On that node are a few attributes, including its &#8220;type&#8221; and a .message connection to the render camera. It&#8217;s them trivial to find the camera&#8217;s name:</p>
<p><code>
<pre>string $sel[] = `ls -type "script"`;
for ($s in $sel) {
	if (`attributeQuery -node $s -ex "snCamera"`) {
		// this should be the one you need
		// normally I search for the type, but this is an example
		string $conn[] = `listConnections ($s + ".snCamera")`;
		// if it's only one connection incoming, then you're done.
		print("Camera is named " + ($conn[0]) + "\n");
	}
}</pre>
<p></code></p>
<p>This technique can be extended to include all kinds of objects. It can also be very helpful for scripts like character GUIs that need to know what characters are present in a scene, and be able to change the positions of all those controls.</p>
<p>One final note on this for now: In Cinema 4D, every object and tag in a scene can be named the same. Searches for objects or tags by name are often fruitless because of this; if two objects or tags have the same name there&#8217;s really no easy way to tell which is which in a COFFEE script. What you can do, however, is create a user data variable that is of the Link type. This allows you to drag and drop an object into that variable&#8217;s edit field, and provides a permanent pointer to that object regardless of name. This is very useful in rigging; for example, you can always tell which joints in a leg are control joints, and which are bind joints, by creating links. You can also expose the links in XPresso and use the pointers as if you&#8217;d dragged an object onto the XPresso node window.</p>
]]></content:encoded>
			<wfw:commentRss>http://sugarandcyanide.com/blog/2009/08/19/weak-references/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>pure unadulterated actionscript geekery</title>
		<link>http://sugarandcyanide.com/blog/2009/02/28/pure-unadulterated-actionscript-geekery/</link>
		<comments>http://sugarandcyanide.com/blog/2009/02/28/pure-unadulterated-actionscript-geekery/#comments</comments>
		<pubDate>Sat, 28 Feb 2009 05:04:32 +0000</pubDate>
		<dc:creator>kiki</dc:creator>
				<category><![CDATA[3d]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://sugarandcyanide.com/blog/?p=43</guid>
		<description><![CDATA[Man oh man. One link clicked led to another, and suddenly I&#8217;m obsessed with PaperVision3D. It all started with this link (which you&#8217;ve already seen if you follow me on Twitter): the The Eco Zoo. If you haven&#8217;t seen it, please clicky! It&#8217;s fantastic. PaperVision&#8217;s been used for a number of neat projects, but the [...]]]></description>
			<content:encoded><![CDATA[<p>Man oh man.  One link clicked led to another, and suddenly I&#8217;m <em>obsessed</em> with <a href="http://code.google.com/p/papervision3d/">PaperVision3D</a>.</p>
<p>It all started with this link (which you&#8217;ve already seen if you <a href="" target="_blank">follow me on Twitter</a>): the <a href="http://ecodazoo.com/" target="_blank">The Eco Zoo</a>.  If you haven&#8217;t seen it, please clicky! It&#8217;s fantastic.</p>
<p>PaperVision&#8217;s been used for a number of neat projects, but the Eco Zoo is a <em>work of art</em>.  So I started searching for stuff on the train in the morning (thank you, iPhone) and turned up a bunch of great links:</p>
<ul>
<li><a href="http://papergem.wordpress.com/" target="_blank"><b>A Whiter Shade of Paper</b></a>: really in-depth site with technical articles and example  code on a PaperVision-based game the author is working on.</li>
<li><a href="http://www.fabianvercuiel.com/internet-websites-applications/installing-papervision3d-flash-flex/" target="_blank"><strong>Installing PaperVision in Flex or Flash</strong></a>: good notes on the basic getting started.</li>
<li><a href="http://www.rozengain.com/blog/2008/01/02/export-your-blender-objects-straight-to-away3d-papervision3d-and-sandy/" target="_blank"><strong>ActionScript class exporter</strong> for Blender.</li>
<li><a href="http://dev.papervision3d.org/" target="_blank"><strong>The PaperVision3D Dev Blog</strong></a></li>
<li><a href="http://blog.iainlobb.com/2008/08/meta4orce-creating-3d-flash-games-with.html" target="_blank"><strong>Meta4orce notes by Iann Lobb</strong></a> &#8212; some really good notes on doing commercial work with PV3D.  Oh, and if you want to play the games he made, the site is still up <a href="http://www.bbc.co.uk/switch/meta4orce/launch.shtml" target="_blank">at the BBC</a>.</li>
<li><a href="http://www.sebleedelisle.com/?p=203" target="_Blank"><strong>Seb Lee-Delise</strong></a> &#8211; Changing the materials on a cube dynamically.</li>
<li><a href="http://www.everydayflash.com/blog/index.php/2008/07/07/pixel-precision-in-papervision3d/" target="_blank"><strong>Everyday Flash</strong></a> &#8211; Pixel precision in Papervision 3D</a></li>
</ul>
<p>For those who didn&#8217;t know, you can either use the <a href="http://opensource.adobe.com/wiki/display/flexsdk/Flex+SDK" target="_blank">open source Flex SDK</a> or, if you&#8217;re a student, you can get a <a href="http://blog.brianflove.com/articles/2008/02/28/flex-3-pro-free-for-education/" target="_blank">free copy of Flex Builder 3</a> by sending them proof of enrollment.  I did it; I got a serial in about an hour later, although YMMV.</p>
<p>Not that I have time to sit down and actually <em>play</em> with any of this&#8230;  But it&#8217;s fun to learn about.  Oh, and I like PaperVision3D because the API is very well thought out and very Flash AS3-like; if you don&#8217;t like it there are other options.  There&#8217;s <a href="http://www.tsoin.com/asblog/2008/11/18/comparatifs-moteurs-3d-et-le-plus-performant-est/">a nice comparsion on the four major 3D engines for Flash here</a> (warning: it&#8217;s in French).  Lots of talk about speed of object creation, memory requirements, and so on.  It&#8217;s always good to be informed of options before starting a project.</p>
]]></content:encoded>
			<wfw:commentRss>http://sugarandcyanide.com/blog/2009/02/28/pure-unadulterated-actionscript-geekery/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

