Skip to content

Commit

Permalink
Initial commit of MagicaVoxel thumbnail handler for Windows Explorer
Browse files Browse the repository at this point in the history
Library to read MagicaVoxel .vox files.
Library to render Voxel files to a bitmap or SVG using SkiaSharp.
WIX installer to install and register the Windows Explorer Shell Extension for displaying thumbnails.
  • Loading branch information
Arlorean committed Jul 30, 2017
1 parent 9ad25e9 commit f93d194
Show file tree
Hide file tree
Showing 42 changed files with 1,374 additions and 0 deletions.
Binary file added Voxels.CommandLine/1x2x3.vox
Binary file not shown.
Binary file added Voxels.CommandLine/3x3x3.vox
Binary file not shown.
Binary file added Voxels.CommandLine/8x8x8.vox
Binary file not shown.
6 changes: 6 additions & 0 deletions Voxels.CommandLine/App.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
</startup>
</configuration>
21 changes: 21 additions & 0 deletions Voxels.CommandLine/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Threading.Tasks;
using Voxels.SkiaSharp;

namespace Voxels.CommandLine {
class Program {
static void Main(string[] args) {
var filename = args.Length == 1 ? args[0] : "monu9.vox"; // "3x3x3.vox";
using (var stream = File.OpenRead(filename)) {
var voxelData = MagicaVoxel.Read(stream);

var guid = Guid.NewGuid();
File.WriteAllBytes($"output{guid}.png", Renderer.RenderPng(512, voxelData));
File.WriteAllBytes($"output{guid}.svg", Renderer.RenderSvg(512, voxelData));
}
}
}
}
36 changes: 36 additions & 0 deletions Voxels.CommandLine/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("VoxelsCommandLine")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("VoxelsCommandLine")]
[assembly: AssemblyCopyright("Copyright © 2017")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("1e4d9af1-41e1-4c81-9d9a-ef22f101e69f")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
84 changes: 84 additions & 0 deletions Voxels.CommandLine/Voxels.CommandLine.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{1E4D9AF1-41E1-4C81-9D9A-EF22F101E69F}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>Voxels.CommandLine</RootNamespace>
<AssemblyName>Voxels.CommandLine</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<Content Include="3x3x3.vox">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="8x8x8.vox">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="1x2x3.vox">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<None Include="App.config" />
<Content Include="wizard.vox">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="monu1.vox">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="monu10.vox">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="monu9.vox">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Voxels.SkiaSharp\Voxels.SkiaSharp.csproj">
<Project>{5275868a-6c22-469c-8c12-c039898e305c}</Project>
<Name>Voxels.SkiaSharp</Name>
</ProjectReference>
<ProjectReference Include="..\Voxels\Voxels.csproj">
<Project>{5f012250-ca19-4c6a-a3a0-7144dae5e8ae}</Project>
<Name>Voxels</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
6 changes: 6 additions & 0 deletions Voxels.CommandLine/Voxels.CommandLine.csproj.user
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ProjectView>ProjectFiles</ProjectView>
</PropertyGroup>
</Project>
Binary file added Voxels.CommandLine/wizard.vox
Binary file not shown.
74 changes: 74 additions & 0 deletions Voxels.Installer/Product.wxs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi"><?define Voxels.ShellExtensions_TargetDir=$(var.Voxels.ShellExtensions.TargetDir)?>
<Product Id="*" Name="Voxels.Installer" Language="1033" Version="1.0.0.1" Manufacturer="Arlorean" UpgradeCode="70e5c55f-1a55-4856-a0fc-a82ece384a74">
<Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine" />

<MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." />
<MediaTemplate EmbedCab="yes" />

<Feature Id="ProductFeature" Title="Voxels" Level="1">
<ComponentGroupRef Id="ProductComponents" />
<ComponentGroupRef Id="ProductComponentsx86" />
<ComponentGroupRef Id="ProductComponentsx64" />
</Feature>

<!-- https://stackoverflow.com/questions/34199756/installing-and-registering-shell-extension-context-menu-from-wix-installer -->
<CustomAction Id="InstallShell" FileKey="srm.exe" ExeCommand='install "[INSTALLFOLDER]\Voxels.ShellExtensions.dll" -codebase' Execute="deferred" Return="check" Impersonate="no" />
<CustomAction Id="UninstallShell" FileKey="srm.exe" ExeCommand='uninstall "[INSTALLFOLDER]\Voxels.ShellExtensions.dll"' Execute="deferred" Return="check" Impersonate="no" />
<InstallExecuteSequence>
<Custom Action="InstallShell" After="InstallFiles">NOT Installed</Custom>
<Custom Action="UninstallShell" Before="RemoveFiles">(NOT UPGRADINGPRODUCTCODE) AND (REMOVE="ALL")</Custom>
</InstallExecuteSequence>
</Product>

<Fragment>
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ProgramFilesFolder">
<Directory Id="INSTALLFOLDER" Name="Voxels">
<Directory Id="INSTALLFOLDERx86" Name="x86" />
<Directory Id="INSTALLFOLDERx64" Name="x64" />
</Directory>
</Directory>
</Directory>
</Fragment>

<Fragment>
<ComponentGroup Id="ProductComponents" Directory="INSTALLFOLDER">
<Component Id="Voxels.ShellExtensions.dll" Guid="eced76bf-65e4-4dd4-92fc-757bf1d60ae2">
<File Id="Voxels.ShellExtensions.dll" Name="Voxels.ShellExtensions.dll" Source="$(var.Voxels.ShellExtensions_TargetDir)Voxels.ShellExtensions.dll" />
</Component>
<Component Id="Voxels.SkiaSharp.dll" Guid="1d21f5cc-cf46-4d58-86f4-dc21561c5550">
<File Id="Voxels.SkiaSharp.dll" Name="Voxels.SkiaSharp.dll" Source="$(var.Voxels.ShellExtensions_TargetDir)Voxels.SkiaSharp.dll" />
</Component>
<Component Id="Voxels.dll" Guid="a0af3960-3b51-4402-a5c6-fed81d1e9b4b">
<File Id="Voxels.dll" Name="Voxels.dll" Source="$(var.Voxels.ShellExtensions_TargetDir)Voxels.dll" />
</Component>
<Component Id="SharpShell.dll" Guid="93680dd3-e026-4344-b983-75bab9446df5">
<File Id="SharpShell.dll" Name="SharpShell.dll" Source="$(var.Voxels.ShellExtensions_TargetDir)SharpShell.dll" />
</Component>
<Component Id="SkiaSharp.dll" Guid="e9aebeae-5129-424a-adba-1d4617255c0a">
<File Id="SkiaSharp.dll" Name="SkiaSharp.dll" Source="$(var.Voxels.ShellExtensions_TargetDir)SkiaSharp.dll" />
</Component>
<Component Id="srm.exe" Guid="8AD977A7-89BA-4D9C-B7CB-0D595B6426EA">
<File Id="srm.exe" Source="$(var.Voxels.ShellExtensions_TargetDir)srm.exe" KeyPath="yes" />
</Component>
</ComponentGroup>
</Fragment>

<Fragment>
<ComponentGroup Id="ProductComponentsx86" Directory="INSTALLFOLDERx86">
<Component Id="x86_libSkiaSharp.dll" Guid="6B6B3855-966E-4926-8D1D-1030C70F400D">
<File Id="x86_libSkiaSharp.dll" Name="libSkiaSharp.dll" Source="$(var.Voxels.ShellExtensions_TargetDir)\x86\libSkiaSharp.dll" />
</Component>
</ComponentGroup>
</Fragment>

<Fragment>
<ComponentGroup Id="ProductComponentsx64" Directory="INSTALLFOLDERx64">
<Component Id="x64_libSkiaSharp.dll" Guid="442D691A-9508-4FDF-9EE6-3B3A59595F10">
<File Id="x64_libSkiaSharp.dll" Name="libSkiaSharp.dll" Source="$(var.Voxels.ShellExtensions_TargetDir)\x64\libSkiaSharp.dll" />
</Component>
</ComponentGroup>
</Fragment>

</Wix>
48 changes: 48 additions & 0 deletions Voxels.Installer/Voxels.Installer.wixproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" InitialTargets="EnsureWixToolsetInstalled" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
<ProductVersion>3.10</ProductVersion>
<ProjectGuid>4ce76915-e1ea-46af-9c22-737f7b9b0c27</ProjectGuid>
<SchemaVersion>2.0</SchemaVersion>
<OutputName>Voxels.Installer</OutputName>
<OutputType>Package</OutputType>
<Name>Voxels.Installer</Name>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
<OutputPath>bin\$(Configuration)\</OutputPath>
<IntermediateOutputPath>obj\$(Configuration)\</IntermediateOutputPath>
<DefineConstants>Debug</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
<OutputPath>bin\$(Configuration)\</OutputPath>
<IntermediateOutputPath>obj\$(Configuration)\</IntermediateOutputPath>
</PropertyGroup>
<ItemGroup>
<Compile Include="Product.wxs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Voxels.ShellExtensions\Voxels.ShellExtensions.csproj">
<Name>Voxels.ShellExtensions</Name>
<Project>{f8a32354-da2b-406c-aebe-dcefd85fd033}</Project>
<Private>True</Private>
<DoNotHarvest>True</DoNotHarvest>
<RefProjectOutputGroups>Binaries;Content;Satellites</RefProjectOutputGroups>
<RefTargetDir>INSTALLFOLDER</RefTargetDir>
</ProjectReference>
</ItemGroup>
<Import Project="$(WixTargetsPath)" Condition=" '$(WixTargetsPath)' != '' " />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\WiX\v3.x\Wix.targets" Condition=" '$(WixTargetsPath)' == '' AND Exists('$(MSBuildExtensionsPath32)\Microsoft\WiX\v3.x\Wix.targets') " />
<Target Name="EnsureWixToolsetInstalled" Condition=" '$(WixTargetsImported)' != 'true' ">
<Error Text="The WiX Toolset v3.11 (or newer) build tools must be installed to build this project. To download the WiX Toolset, see http://wixtoolset.org/releases/" />
</Target>
<!--
To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Wix.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
36 changes: 36 additions & 0 deletions Voxels.ShellExtensions/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Voxels.ShellExtensions")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Voxels.ShellExtensions")]
[assembly: AssemblyCopyright("Copyright © 2017")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("f8a32354-da2b-406c-aebe-dcefd85fd033")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
Binary file added Voxels.ShellExtensions/SigningKey.snk
Binary file not shown.
29 changes: 29 additions & 0 deletions Voxels.ShellExtensions/ThumbnailHandlerVox.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System.Drawing;
using SharpShell.Attributes;
using SharpShell.SharpThumbnailHandler;
using System.Runtime.InteropServices;
using Voxels.SkiaSharp;
using System.Drawing.Imaging;
using System.IO;
using System;
using System.Reflection;

namespace Voxels.ShellExtensions {
[ComVisible(true)]
[COMServerAssociation(AssociationType.FileExtension, ".vox")]
public class ThumbnailHandlerVox : SharpThumbnailHandler {
protected override Bitmap GetThumbnailImage(uint width) {
var size = (int)width;
var voxelData = MagicaVoxel.Read(SelectedItemStream);
var bitmapBytes = Renderer.RenderBitmap((int)size, voxelData);

// Convert Skia bytes to GDI Bitmap
var format = PixelFormat.Format32bppArgb;
var bitmap = new Bitmap(size, size, format);
var bitmapData = bitmap.LockBits(new Rectangle(0,0,size,size), ImageLockMode.WriteOnly, format);
Marshal.Copy(bitmapBytes, 0, bitmapData.Scan0, bitmapBytes.Length);
bitmap.UnlockBits(bitmapData);
return bitmap;
}
}
}
Loading

0 comments on commit f93d194

Please sign in to comment.