<?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>ScapeCode &#187; Uncategorized</title>
	<atom:link href="http://www.scapecode.com/category/uncategorized/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.scapecode.com</link>
	<description>Anime, tentacles, and software development</description>
	<lastBuildDate>Fri, 13 Jan 2012 19:27:41 +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>ONA Bag</title>
		<link>http://www.scapecode.com/2011/05/ona-bag/</link>
		<comments>http://www.scapecode.com/2011/05/ona-bag/#comments</comments>
		<pubDate>Tue, 24 May 2011 20:57:12 +0000</pubDate>
		<dc:creator>Washu</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">https://scapecode.com/?p=340</guid>
		<description><![CDATA[So, I spoiled myself recently and got myself The Union Street ONA bag. So far I&#8217;m liking it, we&#8217;ll see how long that lasts. Below you can see some shots of the bag along with it being packed with the camera, lenses, laptop, and tripod. &#160; &#160;]]></description>
			<content:encoded><![CDATA[<p>So, I spoiled myself recently and got myself <a href="http://www.onabags.com/store/men/the-union-street.html#smoke" target="_blank">The Union Street ONA bag</a>.</p>
<p>So far I&#8217;m liking it, we&#8217;ll see how long that lasts. Below you can see some shots of the bag along with it being packed with the camera, lenses, laptop, and tripod.<br />
<a href="http://www.scapecode.com/wp-content/uploads/2011/05/IMGP17711.jpg">
<a href='http://www.scapecode.com/2011/05/ona-bag/imgp1772/' title='IMGP1772'><img width="150" height="88" src="http://www.scapecode.com/wp-content/uploads/2011/05/IMGP17721.jpg" class="attachment-thumbnail" alt="IMGP1772" title="IMGP1772" /></a>
<a href='http://www.scapecode.com/2011/05/ona-bag/imgp1774/' title='IMGP1774'><img width="150" height="104" src="http://www.scapecode.com/wp-content/uploads/2011/05/IMGP17741.jpg" class="attachment-thumbnail" alt="IMGP1774" title="IMGP1774" /></a>
</p>
<p></a></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.scapecode.com/2011/05/ona-bag/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SlimDX Direct3D10 X Loader</title>
		<link>http://www.scapecode.com/2009/11/slimdx-direct3d10-x-loader/</link>
		<comments>http://www.scapecode.com/2009/11/slimdx-direct3d10-x-loader/#comments</comments>
		<pubDate>Sat, 28 Nov 2009 22:49:10 +0000</pubDate>
		<dc:creator>Washu</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://scapecode.com/?p=127</guid>
		<description><![CDATA[Here&#8217;s a useful class for loading X files (using SlimDX) into a Direct3D10 Mesh object. This is based off of Jack Hoxley&#8217;s C++ code from his journal post on GameDev.Net. A few things to note about it: It doesn&#8217;t handle multiple materials (or materials at all). To handle that would require you to be sure [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a useful class for loading X files (using SlimDX) into a Direct3D10 Mesh object. This is based off of Jack Hoxley&#8217;s C++ code from his journal post on GameDev.Net.</p>
<p>A few things to note about it: It doesn&#8217;t handle multiple materials (or materials at all). To handle that would require you to be sure to optimize the D3D9 mesh in place, then harvest the EffectInstance&#8217;s and also the materials. That way you could load the appropriate textures and bind them during rendering of the appropriate attributes. For simple X meshes this isn&#8217;t an issue, but some (like the Airplane model that comes with the DirectX SDK) have multiple textures.</p>
<pre class="brush: csharp; gutter: true; first-line: 1; highlight: []; html-script: false">using System;
using System.Windows.Forms;
using DXGI = SlimDX.DXGI;
using D3D9 = SlimDX.Direct3D9;
using SlimDX.Direct3D10;

namespace XMeshLoader {
    class XLoader : IDisposable {
        public XLoader() {
            CreateNullDevice();
        }

        #region IDisposable
        ~XLoader() {
            Dispose(false);
        }

        public void Dispose() {
            Dispose(true);
        }

        private void Dispose(bool disposeManagedObjects) {
            if (disposeManagedObjects) {
                device9.Dispose();
                form.Dispose();
            }
        }
        #endregion

        public Mesh CreateMesh(Device device, D3D9.Mesh mesh9, out InputElement[] outDecls) {
            var inDecls = mesh9.GetDeclaration();
            outDecls = new InputElement[inDecls.Length - 1];
            ConvertDecleration(inDecls, outDecls);

            var flags = MeshFlags.None;
            if ((mesh9.CreationOptions &amp;amp; D3D9.MeshFlags.Use32Bit) != 0)
                flags = MeshFlags.Has32BitIndices;

            var mesh = new Mesh(device, outDecls, D3D9.DeclarationUsage.Position.ToString().ToUpper(), mesh9.VertexCount, mesh9.FaceCount, flags);

            ConvertIndexBuffer(mesh9, mesh);
            ConvertVertexBuffer(mesh9, mesh);
            ConfigureAttributeTable(mesh9, mesh);

            mesh.GenerateAdjacencyAndPointRepresentation(0);
            mesh.Optimize(MeshOptimizeFlags.Compact | MeshOptimizeFlags.AttributeSort | MeshOptimizeFlags.VertexCache);

            mesh.Commit();
            return mesh;
        }

        public Mesh LoadFile(Device device, string filename, out InputElement[] outDecls) {
            using (var mesh9 = D3D9.Mesh.FromFile(device9, filename, D3D9.MeshFlags.SystemMemory)) {
                return CreateMesh(device, mesh9, out outDecls);
            }
        }

        #region Implementation Details
        private static void ConfigureAttributeTable(D3D9.BaseMesh inMesh, Mesh outMesh) {
            var inAttribTable = inMesh.GetAttributeTable();

            if (inAttribTable == null || inAttribTable.Length == 0) {
                outMesh.SetAttributeTable(new[] {new MeshAttributeRange {
                    FaceCount = outMesh.FaceCount,
                    FaceStart = 0,
                    Id = 0,
                    VertexCount = outMesh.VertexCount,
                    VertexStart = 0
                }});
            } else {
                var outAttribTable = new MeshAttributeRange[inAttribTable.Length];
                for (var i = 0; i &amp;lt; inAttribTable.Length; ++i) {
                    outAttribTable[i].Id = inAttribTable[i].AttribId;
                    outAttribTable[i].FaceCount = inAttribTable[i].FaceCount;
                    outAttribTable[i].FaceStart = inAttribTable[i].FaceStart;
                    outAttribTable[i].VertexCount = inAttribTable[i].VertexCount;
                    outAttribTable[i].VertexStart = inAttribTable[i].VertexStart;
                }
                outMesh.SetAttributeTable(outAttribTable);
            }

            outMesh.GenerateAttributeBufferFromTable();
        }

        private static void ConvertIndexBuffer(D3D9.BaseMesh inMesh, Mesh outMesh) {
            using (var inStream = inMesh.LockIndexBuffer(D3D9.LockFlags.None))
            using (var outBuffer = outMesh.GetIndexBuffer()) {
                using (var outStream = outBuffer.Map()) {
                    if ((outMesh.Flags &amp;amp; MeshFlags.Has32BitIndices) != 0)
                        outStream.WriteRange(inStream.ReadRange(inMesh.FaceCount * 3));
                    else
                        outStream.WriteRange(inStream.ReadRange(inMesh.FaceCount * 3));
                }
                outBuffer.Unmap();
            }
            inMesh.UnlockIndexBuffer();
        }

        private static void ConvertVertexBuffer(D3D9.BaseMesh inMesh, Mesh outMesh) {
            using (var inStream = inMesh.LockVertexBuffer(D3D9.LockFlags.None))
            using (var outBuffer = outMesh.GetVertexBuffer(0)) {
                using (var outStream = outBuffer.Map()) {
                    outStream.WriteRange(inStream.ReadRange(inMesh.VertexCount * inMesh.BytesPerVertex));
                }
                outBuffer.Unmap();
            }
            inMesh.UnlockIndexBuffer();
        }

        private static void ConvertDecleration(D3D9.VertexElement[] inDecls, InputElement[] outDecls) {
            for (var i = 0; i &amp;lt; inDecls.Length - 1; ++i) {
                outDecls[i].SemanticName = ConvertSemanticName(inDecls[i].Usage);
                outDecls[i].SemanticIndex = inDecls[i].UsageIndex;
                outDecls[i].AlignedByteOffset = inDecls[i].Offset;
                outDecls[i].Slot = inDecls[i].Stream;
                outDecls[i].Classification = InputClassification.PerVertexData;
                outDecls[i].InstanceDataStepRate = 0;
                outDecls[i].Format = ConvertFormat(inDecls[i].Type);
            }
        }

        private static string ConvertSemanticName(D3D9.DeclarationUsage usage) {
            switch (usage) {
                case D3D9.DeclarationUsage.TextureCoordinate:
                    return &amp;quot;TEXCOORD&amp;quot;;
                case D3D9.DeclarationUsage.PositionTransformed:
                    return &amp;quot;POSITIONT&amp;quot;;
                case D3D9.DeclarationUsage.TessellateFactor:
                    return &amp;quot;TESSFACTOR&amp;quot;;
                case D3D9.DeclarationUsage.PointSize:
                    return &amp;quot;PSIZE&amp;quot;;
                default:
                    return usage.ToString().ToUpper();
            }
        }

        private static DXGI.Format ConvertFormat(D3D9.DeclarationType type) {
            switch (type) {
                case D3D9.DeclarationType.Float1: return DXGI.Format.R32_Float;
                case D3D9.DeclarationType.Float2: return DXGI.Format.R32G32_Float;
                case D3D9.DeclarationType.Float3: return DXGI.Format.R32G32B32_Float;
                case D3D9.DeclarationType.Float4: return DXGI.Format.R32G32B32A32_Float;
                case D3D9.DeclarationType.Color: return DXGI.Format.R8G8B8A8_UNorm;
                case D3D9.DeclarationType.Ubyte4: return DXGI.Format.R8G8B8A8_UInt;
                case D3D9.DeclarationType.Short2: return DXGI.Format.R16G16_SInt;
                case D3D9.DeclarationType.Short4: return DXGI.Format.R16G16B16A16_SInt;
                case D3D9.DeclarationType.UByte4N: return DXGI.Format.R8G8B8A8_UNorm;
                case D3D9.DeclarationType.Short2N: return DXGI.Format.R16G16_SNorm;
                case D3D9.DeclarationType.Short4N: return DXGI.Format.R16G16B16A16_SNorm;
                case D3D9.DeclarationType.UShort2N: return DXGI.Format.R16G16_UNorm;
                case D3D9.DeclarationType.UShort4N: return DXGI.Format.R16G16B16A16_UNorm;
                case D3D9.DeclarationType.UDec3: return DXGI.Format.R10G10B10A2_UInt;
                case D3D9.DeclarationType.Dec3N: return DXGI.Format.R10G10B10A2_UNorm;
                case D3D9.DeclarationType.HalfTwo: return DXGI.Format.R16G16_Float;
                case D3D9.DeclarationType.HalfFour: return DXGI.Format.R16G16B16A16_Float;
                default: return DXGI.Format.Unknown;
            }
        }

        private void CreateNullDevice() {
            form = new Form();
            using (var direct3D = new D3D9.Direct3D())
                device9 = new D3D9.Device(direct3D, 0, D3D9.DeviceType.NullReference, form.Handle, D3D9.CreateFlags.HardwareVertexProcessing, new D3D9.PresentParameters {
                    BackBufferCount = 1,
                    BackBufferFormat = D3D9.Format.A8R8G8B8,
                    BackBufferHeight = 1,
                    BackBufferWidth = 1,
                    SwapEffect = D3D9.SwapEffect.Copy,
                    Windowed = true
                });
        }

        private Form form;
        private D3D9.Device device9;
        #endregion
    }
}</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.scapecode.com/2009/11/slimdx-direct3d10-x-loader/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Server outage</title>
		<link>http://www.scapecode.com/2009/06/server-outage/</link>
		<comments>http://www.scapecode.com/2009/06/server-outage/#comments</comments>
		<pubDate>Fri, 19 Jun 2009 17:43:17 +0000</pubDate>
		<dc:creator>Washu</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://scapecode.com/?p=3</guid>
		<description><![CDATA[Well, sites back up, on WordPress now&#8230; Server crashed something spectacularily the other day. Both drives in the RAID 1 decided to take a nice vacation, and so I&#8217;m having to restore from backups I&#8217;ve kept. Thanks to google I&#8217;ve got most of my old posts, and will be dumping them up here through the [...]]]></description>
			<content:encoded><![CDATA[<p>Well, sites back up, on WordPress now&#8230;</p>
<p>Server crashed something spectacularily the other day. Both drives in the RAID 1 decided to take a nice vacation, and so I&#8217;m having to restore from backups I&#8217;ve kept.</p>
<p>Thanks to google I&#8217;ve got most of my old posts, and will be dumping them up here through the day as I edit them and put them together again.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.scapecode.com/2009/06/server-outage/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

