<?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>technical architecture.</title>
	<atom:link href="http://buchhofer.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://buchhofer.com</link>
	<description>Maxscript, Architecture, 3D, 3DSMax, Unity3D</description>
	<lastBuildDate>Mon, 30 Apr 2012 00:46:12 +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>Sundays random thought:</title>
		<link>http://buchhofer.com/2012/04/sundays-random-thought/</link>
		<comments>http://buchhofer.com/2012/04/sundays-random-thought/#comments</comments>
		<pubDate>Mon, 30 Apr 2012 00:46:12 +0000</pubDate>
		<dc:creator>Dave Buchhofer</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://buchhofer.com/?p=353</guid>
		<description><![CDATA[You know you&#8217;re researching in a good direction when every 45 minutes or so of reading, you go &#8216;Damn! I wish I&#8217;d read that last week.&#8217; It&#8217;s been a very informative week.]]></description>
			<content:encoded><![CDATA[<p>You know you&#8217;re researching in a good direction when every 45 minutes or so of reading, you go &#8216;Damn! I wish I&#8217;d read that last week.&#8217;</p>
<p>It&#8217;s been a very informative week.</p>
]]></content:encoded>
			<wfw:commentRss>http://buchhofer.com/2012/04/sundays-random-thought/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Multi-Touch and iOS/Android from the same project, Unity3D</title>
		<link>http://buchhofer.com/2012/04/multi-touch-and-iosandroid-from-the-same-project-unity3d/</link>
		<comments>http://buchhofer.com/2012/04/multi-touch-and-iosandroid-from-the-same-project-unity3d/#comments</comments>
		<pubDate>Fri, 06 Apr 2012 11:50:32 +0000</pubDate>
		<dc:creator>Dave Buchhofer</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://buchhofer.com/?p=334</guid>
		<description><![CDATA[There is a bit of a void out there in terms of recent information regarding multi touch in unity, most of the legwork of development looks to have been done in 09/10, looking around the forums there are many more questions than answers, and all out of date. SO! Lets record some of my findings [...]]]></description>
			<content:encoded><![CDATA[<p>There is a bit of a void out there in terms of recent information regarding multi touch in unity, most of the legwork of development looks to have been done in 09/10, looking around the forums there are many more questions than answers, and all out of date. SO! Lets record some of my findings from building a quick turnaround multi platform product config tool. this is the multi touch side of things, there was a slight bit more to keep it all happy with iOS/Android, but for the most part, I adopted their conventions where I could and forced the multi touch into that mold.</p>
<p>First interesting problem is how to begin dev and testing of a multi touch interface when you don&#8217;t have one to use! (wee!) Fortunately there is a few fun tools built by others in the CV world that can get you up and running quickly. There is much information to be had looking around in the <a href="http://nuigroup.com/forums">NUIGROUP forums</a> based around building your own touch tables. My immediate timeline didn&#8217;t let me play with full tables (sad!), fortunately <a href="http://sethsandler.com/multitouch/mtmini/">Seth Sandler </a>had put together a nice DIY project involving a webcam, some cardboard, glass, and a sheet of vellum, run on the <a href="http://sethsandler.com/multitouch/multitouch/community-core-vision-guide/">Community Core Vision package </a>. That got me multi touch input with output to the TUIO protocol fairly easily!</p>
<p>Next, looking into how to handle the TUIO inside of unity, there are a few main packages that work well, (Among others found at : <a href="http://www.tuio.org/?software">tuio.org</a>) I ended up with two that got serious consideration, the <a href="https://code.google.com/p/unity3d-tuio/">Mindstorm tuio</a>, and the <a href="http://www.xtuio.com/index.php/projectsmain/utuiomain">UniTUIO</a> by the guys at xtuio, the code and overall base of the mindstorm system looked more solid and cohesive, but due to the schedule I ended up with the unituio for expediency sake, because it converts the TUIO touches to unitys base input system, by way of building bridged Input class and overriding the get touch functions. There is some editing needed to bring it back up to date with the 3.5 changes, but its minor and the console error log should get you there.</p>
<p>Now! The fun part, things are starting to work, now we can get down to biz. (Almost) There are a few other things to take into account, tuio systems are not taken into account with the built in unity gui. Alternate ui systems that work fairly easily with them are <a href="http://www.anbsoft.com/middleware/ezgui/">EZGUI</a> and <a href="http://www.tasharen.com/?page_id=140">NGUI</a>, I went with NGUI, and have been very happy with the support response time, and solid performance. I also adapted the truly awesome <a href="http://fingergestures.fatalfrog.com/">FingerGestures</a> to use the tuio inputs, so now I&#8217;ve got a framework that works on all platforms, and with a loader for finger gestures that checks for the presence of the tuio inputs, and loads those, or else, reverts to base mouse input as needed. future: combine the two inputs so that there is no manual work on export!</p>
<p>One more: depending on the touch screens you&#8217;re using, you may need to convert windows 7 touches to tuio, I did this with the <a href="http://dm.tzi.de/research/hci/touch2tuio/">Touch2Tuio</a> program. built in Windows 7 touches are functional for 1 touch, and the pinch to zoom gesture gets converted to the scroll wheel by default in unity 3.5 (And I believe it started working in 3.0 or 3.4.. the forum is vague on this.)</p>
<p>Performance wise, it still misses entirely too many touches for my peace of mind as a long term solution, but it worked quickly, and got us through the initial conference expo, and was a success! so work will continue, and it will get better and bigger and faster and more awesomeness. or something. I don&#8217;t know that I&#8217;d suggest this system for a long running exhibit, but it worked fine in the 3-5 day range for me.</p>
<p>Cheers.</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://buchhofer.com/2012/04/multi-touch-and-iosandroid-from-the-same-project-unity3d/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Configurable Inverse Kinematics in unity at runtime</title>
		<link>http://buchhofer.com/2012/01/configurable-inverse-kinematics-in-unity-at-runtime/</link>
		<comments>http://buchhofer.com/2012/01/configurable-inverse-kinematics-in-unity-at-runtime/#comments</comments>
		<pubDate>Sat, 14 Jan 2012 04:49:16 +0000</pubDate>
		<dc:creator>Dave Buchhofer</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://buchhofer.com/?p=330</guid>
		<description><![CDATA[As demo&#8217;d in this video: OR3D tool walk thru the video is a bit on the older side, but it shows the IK fairly well. the system is fairly simple rig that attaches as a script to the IK End Effector, and parses up the hierarchy collecting any bones that are tagged with a certain [...]]]></description>
			<content:encoded><![CDATA[<p>As demo&#8217;d in this video: <a href="http://buchhofer.com/2011/06/what-have-you-done-for-me-lately/" title="What have you Done for me Lately">OR3D tool walk thru</a> the video is a bit on the older side, but it shows the IK fairly well.</p>
<p>the system is fairly simple rig that attaches as a script to the IK End Effector, and parses up the hierarchy collecting any bones that are tagged with a certain empty class (In my case called an EndJoint).</p>
<p>I collect bone joints at runtime after combining and configuring the hierarchy, and pass them into the CCD IK function as an array of unity transforms. the bulk of the code is taken almost directly from Jeff Lander&#8217;s game developer article describing the Cyclic Coordinate Decent (CCD) inverse kinematics algorithm, written in 1998, <a href="http://graphics.cs.cmu.edu/nsp/course/15-464/Spring07/assignments/jlander_gamedev_nov98.pdf" title="Original Article Here"></a></p>
<p>the port can be downloaded from here: <a href="http://dl.dropbox.com/u/8000/IKCCD2D.zip">IKCCD2D.zip</a></p>
]]></content:encoded>
			<wfw:commentRss>http://buchhofer.com/2012/01/configurable-inverse-kinematics-in-unity-at-runtime/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Architecture &#8211; Revit to Max to Unity</title>
		<link>http://buchhofer.com/2011/12/uni/</link>
		<comments>http://buchhofer.com/2011/12/uni/#comments</comments>
		<pubDate>Thu, 01 Dec 2011 21:42:19 +0000</pubDate>
		<dc:creator>Dave Buchhofer</dc:creator>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[Interactive]]></category>
		<category><![CDATA[Portfolio]]></category>
		<category><![CDATA[Unity3D]]></category>

		<guid isPermaLink="false">http://buchhofer.com/?p=318</guid>
		<description><![CDATA[Here is a Revit -> 3dsmax -> Unity project that we worked on earlier this year. the videos below are captured in HD in unity directly from some premade itween paths Exterior axo from Dave Buck on Vimeo. Realtime HD Architecture, Captured in Unity3D from Dave Buck on Vimeo. Basic workflow was to export out [...]]]></description>
			<content:encoded><![CDATA[<p>Here is a Revit -> 3dsmax -> Unity project that we worked on earlier this year.</p>
<p>the videos below are captured in HD in unity directly from some premade itween paths</p>
<p><iframe src="http://player.vimeo.com/video/31943486?title=0&amp;byline=0&amp;portrait=0" width="400" height="225" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>
<p><a href="http://vimeo.com/31943486">Exterior axo</a> from <a href="http://vimeo.com/vsai">Dave Buck</a> on <a href="http://vimeo.com">Vimeo</a>.</p>
<p><iframe src="http://player.vimeo.com/video/31940365?title=0&amp;byline=0&amp;portrait=0" width="400" height="225" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>
<p><a href="http://vimeo.com/31940365">Realtime HD Architecture, Captured in Unity3D</a> from <a href="http://vimeo.com/vsai">Dave Buck</a> on <a href="http://vimeo.com">Vimeo</a>.</p>
<p>Basic workflow was to export out the WorkSets from Revit as individual FBX files<br />
Import them into 3dsmax with the file link manager, usually set to combine objects by material<br />
from there run a set of scripts that collapsed / welded / AutoSmoothed / split meshes that were too large (65k verts is a pain) cleans up the layers, replaces materials, and exports the now unity friendly layers into different FBX&#8217;s for unitys consumption</p>
<p>Inside unity there are a few small steps needed, done mostly with AssetPostProcessors that hook up any external lightmaps that we generated in max, replace/reconnect any materials that are in our standard material library, and attach any components that are supplied in the max user properties fields.</p>
<p>bake the lighting to suit, (In this case, just give us some AO and Sunlight since we needed to be able to turn around revit design changes -> working webplayer overnight with minimal user babysitting.)</p>
<p>this workflow allowed the building owner to &#8216;walk&#8217; around the design very rapidly after it was changed.</p>
<p>There are a few more captures up at http://vimeo.com/vsai/videos/ for anyone interested.</p>
]]></content:encoded>
			<wfw:commentRss>http://buchhofer.com/2011/12/uni/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Unity per project compiler options, -unsafe</title>
		<link>http://buchhofer.com/2011/11/unity-per-project-compiler-options-unsafe/</link>
		<comments>http://buchhofer.com/2011/11/unity-per-project-compiler-options-unsafe/#comments</comments>
		<pubDate>Mon, 28 Nov 2011 22:31:30 +0000</pubDate>
		<dc:creator>Dave Buchhofer</dc:creator>
				<category><![CDATA[csharp]]></category>
		<category><![CDATA[Unity3D]]></category>

		<guid isPermaLink="false">http://buchhofer.com/?p=316</guid>
		<description><![CDATA[I had to integrate a small set of third party code that calls down to some win32 dllimport bits, to do this I needed to be able to work with some pointers. which in c# need to be declared in an unsafe function, so that it knows to be unmanaged. Slightly awkward, but it turns [...]]]></description>
			<content:encoded><![CDATA[<p>I had to integrate a small set of third party code that calls down to some win32 dllimport bits, to do this I needed to be able to work with some pointers. which in c# need to be declared in an unsafe function, so that it knows to be unmanaged.</p>
<p>Slightly awkward, but it turns out that there is an -unsafe compiler option that needs to be turned on in unity/mono, and that you can do this very easily on a per project basis by adding a file &#8216;smcs.rsp&#8217; to the root of your assets dir, and in there you can add the text &#8216;-unsafe&#8217; to add this to the compiler commandline.</p>
<p>Reference threads: <a href="http://forum.unity3d.com/threads/41592-Setting-Compiler-Options">Setting Compiler Options</a>, <a href="http://forum.unity3d.com/threads/7009-Unsafe-code-in-Unity">Unsafe code in Unity</a>, <a href="http://forum.unity3d.com/threads/71445-How-To-Set-Project-Wide-pragma-Directives-with-JavaScript">How To: Set Project-Wide #pragma Directives with JavaScript</a></p>
<p>Other apparent uses stated in the threads are setting project wide defines and pragmas</p>
]]></content:encoded>
			<wfw:commentRss>http://buchhofer.com/2011/11/unity-per-project-compiler-options-unsafe/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>A google reader feed of tech art blogs</title>
		<link>http://buchhofer.com/2011/11/tech-art-blogs/</link>
		<comments>http://buchhofer.com/2011/11/tech-art-blogs/#comments</comments>
		<pubDate>Sun, 27 Nov 2011 17:53:00 +0000</pubDate>
		<dc:creator>Dave Buchhofer</dc:creator>
				<category><![CDATA[TechArt]]></category>

		<guid isPermaLink="false">http://buchhofer.com/?p=309</guid>
		<description><![CDATA[here&#8217;s a little google reader bundle of (currently) 70 tech art blogs, mostly taken from this thread: http://tech-artists.org/forum/showthread.php?t=1514 and thrown into an easy to follow group at: Google Reader Bundle: Tech Arts 2011  for anyone else thats deeply into this google reader bug, but doesn&#8217;t want to add them all by hand.]]></description>
			<content:encoded><![CDATA[<p>here&#8217;s a little google reader bundle of (currently) 70 tech art blogs, mostly taken from this thread: <a title="Tech arts forum blog listing thread" href="http://tech-artists.org/forum/showthread.php?t=1514" target="_blank">http://tech-artists.org/forum/showthread.php?t=1514</a></p>
<p>and thrown into an easy to follow group at: <a href="http://www.google.com/reader/bundle/user%2F03567438545568037746%2Fbundle%2FTech%20Arts%202011" target="_blank">Google Reader Bundle: Tech Arts 2011 </a></p>
<p>for anyone else thats deeply into this google reader bug, but doesn&#8217;t want to add them all by hand.</p>
]]></content:encoded>
			<wfw:commentRss>http://buchhofer.com/2011/11/tech-art-blogs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ArtBreak, MiLB Stadium</title>
		<link>http://buchhofer.com/2011/11/artbreak-milb-stadium/</link>
		<comments>http://buchhofer.com/2011/11/artbreak-milb-stadium/#comments</comments>
		<pubDate>Wed, 23 Nov 2011 19:55:34 +0000</pubDate>
		<dc:creator>Dave Buchhofer</dc:creator>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[Portfolio]]></category>
		<category><![CDATA[Rendering]]></category>
		<category><![CDATA[Stills]]></category>

		<guid isPermaLink="false">http://buchhofer.com/?p=310</guid>
		<description><![CDATA[A little Art break, here&#8217;s a few shots from a recent set of renderings done for a minor league baseball stadium.]]></description>
			<content:encoded><![CDATA[<p>A little Art break, here&#8217;s a few shots from a recent set of renderings done for a minor league baseball stadium.</p>
<p><iframe align="center" src="http://www.flickr.com/slideShow/index.gne?group_id=&#038;user_id=11168326@N03&#038;set_id=72157628115392905/show&#038;text=" frameBorder="0" width="500" height="500" scrolling="no"></iframe></p>
]]></content:encoded>
			<wfw:commentRss>http://buchhofer.com/2011/11/artbreak-milb-stadium/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ignore file for Mercurial and Unity</title>
		<link>http://buchhofer.com/2011/11/ignore-file-for-mercurial-and-unity/</link>
		<comments>http://buchhofer.com/2011/11/ignore-file-for-mercurial-and-unity/#comments</comments>
		<pubDate>Tue, 15 Nov 2011 15:38:38 +0000</pubDate>
		<dc:creator>Dave Buchhofer</dc:creator>
				<category><![CDATA[Scripting]]></category>
		<category><![CDATA[Unity]]></category>
		<category><![CDATA[Unity3D]]></category>

		<guid isPermaLink="false">http://buchhofer.com/?p=301</guid>
		<description><![CDATA[here&#8217;s a working ignore file for use of Unity and Mercurial simple, but slightly different from the instructions posted in the current docs, so figured i&#8217;d pass it on for anyone else who cares to check it out. placed in a plain text file named .htignore in your project directory syntax: glob *.tmproj *.pidb *.sln *.userprefs [...]]]></description>
			<content:encoded><![CDATA[<p>here&#8217;s a working ignore file for use of Unity and <a href="http://mercurial.selenic.com/" target="_blank">Mercurial</a> simple, but slightly different from the instructions posted in the current docs, so figured i&#8217;d pass it on for anyone else who cares to check it out.</p>
<p>placed in a plain text file named .htignore in your project directory</p>
<pre>syntax: glob

*.tmproj
*.pidb
*.sln
*.userprefs
*.csproj
*.unityproj

AnnotationManager
assetDatabase3
AssetImportState
assetservercachev3
AssetVersioning.db
BuildPlayer.prefs
BuildSettings.asset
EditorSettings.asset
EditorUserBuildSettings.asset
expandedItems
FailedAssetImports.txt
guidmapper
InspectorExpandedItems.asset
MonoManager.asset
ScriptMapper

cache/*
Temp/*
metadata/*
ScriptAssemblies/*
previews/*</pre>
<p><a href="http://hgbook.red-bean.com/read/mercurial-in-daily-use.html">The Mercurial in Daily Use guide</a> seems to be a good list of things that you might wish to do</p>
<p>&nbsp;</p>
<p>Some notes for myself, but might be useful to someone else getting started also.</p>
<p>edit: To start a local serve on my workstation that my laptop can push to, use the command line</p>
<address>hg serve &#8211;config web.push_ssl=No &#8211;config &#8220;web.allow_push=*&#8221;</address>
<p>to pass your changes up from the laptop to the workstation:</p>
<address>hg push http://workstationname:8000</address>
<p>and on the workstation use:</p>
<address>hg update</address>
<p>to get the latest updated file revisions locally..</p>
<p>and you&#8217;re sync&#8217;d. fun times.</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://buchhofer.com/2011/11/ignore-file-for-mercurial-and-unity/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>What have you done for me lately?</title>
		<link>http://buchhofer.com/2011/06/what-have-you-done-for-me-lately/</link>
		<comments>http://buchhofer.com/2011/06/what-have-you-done-for-me-lately/#comments</comments>
		<pubDate>Wed, 01 Jun 2011 17:10:09 +0000</pubDate>
		<dc:creator>Dave Buchhofer</dc:creator>
				<category><![CDATA[Interactive]]></category>
		<category><![CDATA[Portfolio]]></category>
		<category><![CDATA[Unity3D]]></category>

		<guid isPermaLink="false">http://buchhofer.com/?p=286</guid>
		<description><![CDATA[I&#8217;ve been working on this tool for a while now, here&#8217;s a quick captured demo of some of the features of my hospital room design application in action. Interactive 3D OR/ICU design tool from Dave Buck on Vimeo. here&#8217;s a current video of my OR/ICU design project, created in unity3d, with fully configurable parametric models [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been working on this tool for a while now, here&#8217;s a quick captured demo of some of the features of my hospital room design application in action.</p>
<p><iframe src="http://player.vimeo.com/video/24523384?title=0&amp;byline=0&amp;portrait=0" width="400" height="205" frameborder="0"></iframe>
<p><a href="http://vimeo.com/24523384">Interactive 3D OR/ICU design tool</a> from <a href="http://vimeo.com/vsai">Dave Buck</a> on <a href="http://vimeo.com">Vimeo</a>.</p>
<p>here&#8217;s a current video of my OR/ICU design project, created in unity3d, with fully configurable parametric models rigged with both IK and FK, and a tool to quickly draw out any layout of walls, windows and doors to spatially visualize the placement and reach of equipment needed in an operating room space.</p>
]]></content:encoded>
			<wfw:commentRss>http://buchhofer.com/2011/06/what-have-you-done-for-me-lately/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Fun with Generics and Lists in C#</title>
		<link>http://buchhofer.com/2011/05/fun-with-generics-and-lists-in-c/</link>
		<comments>http://buchhofer.com/2011/05/fun-with-generics-and-lists-in-c/#comments</comments>
		<pubDate>Thu, 19 May 2011 15:58:03 +0000</pubDate>
		<dc:creator>Dave Buchhofer</dc:creator>
				<category><![CDATA[.net]]></category>
		<category><![CDATA[csharp]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[Unity]]></category>

		<guid isPermaLink="false">http://buchhofer.com/?p=264</guid>
		<description><![CDATA[So I&#8217;ve been doing a lot of List juggling lately and have run into a few tidbits that I wish I had learned a few months ago. I figure that is always a good cue to write them down for future reference and for any others who are digging into this C# world headfirst also. [...]]]></description>
			<content:encoded><![CDATA[<p>So I&#8217;ve been doing a lot of List juggling lately and have run into a few tidbits that I wish I had learned a few months ago. I figure that is always a good cue to <strong>write them down</strong> for future reference and for any others who are digging into this C# world headfirst also. this is all sort of an exansion to try and get a concrete example of mike_mac&#8217;s <a href="http://www.michaelgarforth.com/archives/2011/04/delegates-events-lambdas-and-all-things-callbacky-part-2/">lamda</a>/<a href="http://www.michaelgarforth.com/archives/2011/04/delegates-events-lambdas-and-all-things-callbacky-part-1/">delegates/callback</a> articles</p>
<p>Say I have a custom class that I&#8217;m using to store a structured set of data, this time we&#8217;ll play with &#8220;ArmDefs&#8221;. ArmDef&#8217;s just hold a little string and int based data and a list of ArmDef&#8217;s as children, and a second list of GameObjects that contains all of the models for this section of arm for use to serialize to disk, but thats more a story for another time.</p>
<p>Overall this is used to build up a hierarchy that holds the &#8220;contents&#8221; of a runtime modular rig, and handles the Saving/Loading/Reloading.</p>
<p>To work with this I needed to set up a pile of recursive functions to edit the tree at runtime, since I don&#8217;t know the depth of the hierarchy, and rebuild the system as needed.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008000;">&#91;</span><span style="color: #000000;">System</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Serializable</span><span style="color: #008000;">&#93;</span>
<span style="color: #008080; font-style: italic;">//Inheriting from ISerializable gives us</span>
<span style="color: #008080; font-style: italic;">//an easy access to Serialization to disk</span>
<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">class</span> ArmDef <span style="color: #008000;">:</span> ISerializable <span style="color: #008000;">&#123;</span>
    <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">string</span> Name<span style="color: #008000;">;</span>
    <span style="color: #0600FF; font-weight: bold;">public</span> List<span style="color: #008000;">&lt;</span>ArmDef<span style="color: #008000;">&gt;</span> Children <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> List<span style="color: #008000;">&lt;</span>ArmDef<span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">public</span> ArmDef<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span> iFile<span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
        <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Name</span><span style="color: #008000;">=</span> iFile<span style="color: #008000;">;</span>
        <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Children</span> <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> List<span style="color: #008000;">&lt;</span>ArmDef<span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #008000;">&#125;</span>
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">void</span> AddChild<span style="color: #008000;">&#40;</span>ArmDef child<span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
        Children<span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span>child<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #008080; font-style: italic;">//just wrapping the Add so that we can do &quot;extra&quot;</span>
<span style="color: #008080; font-style: italic;">//stuff here if we want, like add links to parents etc</span>
    <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>not really building these thru scripts out in the wild but just to build something to work with here.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">public</span> ArmDef config <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> ArmDef<span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Base Level&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #008080; font-style: italic;">//add a couple children</span>
config<span style="color: #008000;">.</span><span style="color: #0000FF;">AddChild</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">new</span> ArmDef<span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Level2a&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
config<span style="color: #008000;">.</span><span style="color: #0000FF;">AddChild</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">new</span> ArmDef<span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Level2b&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
config<span style="color: #008000;">.</span><span style="color: #0000FF;">AddChild</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">new</span> ArmDef<span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Level2c&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #008080; font-style: italic;">//add a couple grandchildren</span>
config<span style="color: #008000;">.</span><span style="color: #0000FF;">Children</span><span style="color: #008000;">&#91;</span><span style="color: #FF0000;">1</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">AddChild</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">new</span> ArmDef<span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Level3a&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
config<span style="color: #008000;">.</span><span style="color: #0000FF;">Children</span><span style="color: #008000;">&#91;</span><span style="color: #FF0000;">1</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">AddChild</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">new</span> ArmDef<span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Level3b&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></pre></td></tr></table></div>

<p>ok thats all the boring stuff for now! here is a Generic Recursive function that walks down a tree and does &#8216;Action<>&#8216; to all children of &#8216;parent&#8217;. The key here is that the Action<> pretty much rocks. !</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">void</span> HandleArmDef<span style="color: #008000;">&#40;</span>Action<span style="color: #008000;">&lt;</span>ArmDef<span style="color: #008000;">&gt;</span> item, ArmDef parent<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
    <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>parent<span style="color: #008000;">.</span><span style="color: #0000FF;">Children</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Count</span> <span style="color: #008000;">&gt;</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
        <span style="color: #0600FF; font-weight: bold;">foreach</span> <span style="color: #008000;">&#40;</span>ArmDeft <span style="color: #0600FF; font-weight: bold;">in</span> parent<span style="color: #008000;">.</span><span style="color: #0000FF;">Children</span><span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            HandleArmDef<span style="color: #008000;">&#40;</span>item, ti<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span>
    <span style="color: #008000;">&#125;</span>
    item<span style="color: #008000;">&#40;</span>parent<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>Now the fun begins when you start to chain this stuff together to &#8220;act&#8221; on all children.<br />
we can define that &#8220;Action<ArmDef> item&#8221; in the above function to be something else using some Lambda or Delegate type stuff. (I&#8217;m learning here, those are the reading points for the moment!)</p>
<p>This will go through the hierarchy and remove all children with the Name of &#8220;Level3a&#8221;.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #6666cc; font-weight: bold;">string</span> toDelete <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;Level3a&quot;</span><span style="color: #008000;">;</span>
HandleArmDef<span style="color: #008000;">&#40;</span>item <span style="color: #008000;">=&gt;</span> <span style="color: #008000;">&#123;</span> item<span style="color: #008000;">.</span><span style="color: #0000FF;">Children</span> <span style="color: #008000;">=</span> item<span style="color: #008000;">.</span><span style="color: #0000FF;">Children</span><span style="color: #008000;">.</span><span style="color: #0600FF; font-weight: bold;">Where</span><span style="color: #008000;">&#40;</span>child <span style="color: #008000;">=&gt;</span> child<span style="color: #008000;">.</span><span style="color: #0000FF;">Name</span> <span style="color: #008000;">!=</span> toDelete<span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">ToList</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>, config<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></pre></td></tr></table></div>

<p>In another example, i wanted to search the hierarchy and see if there was a certain value anywhere in the hierarchy. easiest way i found was to just quickly build a flattened list and use the Linq &#8220;Any&#8221; function to see if the string was found anywhere in the hierarchy.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;">List<span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">&gt;</span> flatList <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> List<span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
HandleArmDef<span style="color: #008000;">&#40;</span>item <span style="color: #008000;">=&gt;</span> <span style="color: #008000;">&#123;</span> flatList<span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span>item<span style="color: #008000;">.</span><span style="color: #0000FF;">Name</span> <span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>, parent<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #6666cc; font-weight: bold;">bool</span> isCurrentlyFlat <span style="color: #008000;">=</span> flatList<span style="color: #008000;">.</span><span style="color: #0000FF;">Any</span><span style="color: #008000;">&#40;</span>x <span style="color: #008000;">=&gt;</span> x<span style="color: #008000;">.</span><span style="color: #0000FF;">Contains</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Flat&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></pre></td></tr></table></div>

<p>in another case, i wanted to insert a new child into the hierarchy as a child of a specific object.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #6666cc; font-weight: bold;">void</span> AddChildAddon<span style="color: #008000;">&#40;</span>ArmDef parent, <span style="color: #6666cc; font-weight: bold;">string</span> addAsChildOf, <span style="color: #6666cc; font-weight: bold;">string</span> newChild<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
    <span style="color: #008080; font-style: italic;">//for each object 'item' down the hierarchy</span>
    <span style="color: #008080; font-style: italic;">//if the item.Name contains our addAsChildOf string</span>
    <span style="color: #008080; font-style: italic;">//we'll add the newChild as a child to the item.</span>
    HandleArmDef<span style="color: #008000;">&#40;</span>item <span style="color: #008000;">=&gt;</span>
    <span style="color: #008000;">&#123;</span>
        <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>item<span style="color: #008000;">.</span><span style="color: #0000FF;">Name</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Contains</span><span style="color: #008000;">&#40;</span>addAsChildOf<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            item<span style="color: #008000;">.</span><span style="color: #0000FF;">Children</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">new</span> ArmDef<span style="color: #008000;">&#40;</span>newChild<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span>
    <span style="color: #008000;">&#125;</span>, parent<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>there&#8217;s plenty more possibilities of things to do here if I&#8217;ve explained well enough!<br />
More info on <a href="http://msdn.microsoft.com/en-us/vcsharp/aa336746">Linq by example</a></p>
]]></content:encoded>
			<wfw:commentRss>http://buchhofer.com/2011/05/fun-with-generics-and-lists-in-c/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

