mirror of
https://github.com/QL-Win/QuickLook.git
synced 2025-09-03 19:26:40 +00:00
Add built-in HelixViewer for 3d models
This commit is contained in:
53
QuickLook.Plugin/QuickLook.Plugin.HelixViewer/Handler.cs
Normal file
53
QuickLook.Plugin/QuickLook.Plugin.HelixViewer/Handler.cs
Normal file
@@ -0,0 +1,53 @@
|
||||
// Copyright © 2017-2025 QL-Win Contributors
|
||||
//
|
||||
// This file is part of QuickLook program.
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
using QuickLook.Common.Plugin;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
namespace QuickLook.Plugin.HelixViewer;
|
||||
|
||||
internal static class Handler
|
||||
{
|
||||
public static bool CanHandle(string path)
|
||||
{
|
||||
var ext = Path.GetExtension(path).ToLower();
|
||||
|
||||
if (ext == ".obj")
|
||||
{
|
||||
var firstLines = File.ReadLines(path).Take(10);
|
||||
foreach (var line in firstLines)
|
||||
{
|
||||
if (line.StartsWith("#") || line.StartsWith("v ") || line.StartsWith("f ") || line.StartsWith("o ") ||
|
||||
line.StartsWith("vn ") || line.StartsWith("vt ") || line.StartsWith("mtllib"))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return true; // Assume other formats are supported
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void Prepare(string path, ContextObject context)
|
||||
{
|
||||
}
|
||||
}
|
@@ -0,0 +1,24 @@
|
||||
<UserControl x:Class="QuickLook.Plugin.HelixViewer.HelixPanel"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:helix="clr-namespace:HelixToolkit.Wpf;assembly=HelixToolkit.Wpf"
|
||||
xmlns:local="clr-namespace:QuickLook.Plugin.HelixViewer"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
d:DesignHeight="450"
|
||||
d:DesignWidth="800"
|
||||
mc:Ignorable="d">
|
||||
<Grid>
|
||||
<helix:HelixViewport3D x:Name="viewer"
|
||||
CameraRotationMode="Turnball"
|
||||
ShowViewCube="False"
|
||||
ZoomAroundMouseDownPoint="True"
|
||||
ZoomExtentsWhenLoaded="true">
|
||||
<ModelVisual3D x:Name="modelVisual" />
|
||||
<helix:DefaultLights />
|
||||
<helix:HelixViewport3D.RotateGesture>
|
||||
<MouseGesture MouseAction="LeftClick" />
|
||||
</helix:HelixViewport3D.RotateGesture>
|
||||
</helix:HelixViewport3D>
|
||||
</Grid>
|
||||
</UserControl>
|
@@ -0,0 +1,55 @@
|
||||
// Copyright © 2017-2025 QL-Win Contributors
|
||||
//
|
||||
// This file is part of QuickLook program.
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
using HelixToolkit.Wpf;
|
||||
using System.Linq;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Media3D;
|
||||
|
||||
namespace QuickLook.Plugin.HelixViewer;
|
||||
|
||||
public partial class HelixPanel : UserControl
|
||||
{
|
||||
private string _path;
|
||||
|
||||
public HelixPanel(string path) : this()
|
||||
{
|
||||
_path = path;
|
||||
Load();
|
||||
}
|
||||
|
||||
public HelixPanel()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void Load()
|
||||
{
|
||||
var modelImporter = new ModelImporter();
|
||||
var model3DGroup = modelImporter.Load(_path);
|
||||
var diffuseMaterial = new DiffuseMaterial(new SolidColorBrush(Colors.DarkGray));
|
||||
|
||||
foreach (GeometryModel3D child in model3DGroup.Children.Cast<GeometryModel3D>())
|
||||
{
|
||||
child.Material = diffuseMaterial;
|
||||
child.BackMaterial = diffuseMaterial;
|
||||
}
|
||||
|
||||
modelVisual.Content = model3DGroup;
|
||||
}
|
||||
}
|
67
QuickLook.Plugin/QuickLook.Plugin.HelixViewer/Plugin.cs
Normal file
67
QuickLook.Plugin/QuickLook.Plugin.HelixViewer/Plugin.cs
Normal file
@@ -0,0 +1,67 @@
|
||||
// Copyright © 2017-2025 QL-Win Contributors
|
||||
//
|
||||
// This file is part of QuickLook program.
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
using QuickLook.Common.Plugin;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Windows;
|
||||
|
||||
namespace QuickLook.Plugin.HelixViewer;
|
||||
|
||||
public class Plugin : IViewer
|
||||
{
|
||||
private static readonly HashSet<string> WellKnownImageExtensions = new(
|
||||
[
|
||||
".stl", ".obj", ".3ds", ".lwo", ".ply",
|
||||
]);
|
||||
|
||||
private HelixPanel _hp;
|
||||
|
||||
public int Priority => 0;
|
||||
|
||||
public void Init()
|
||||
{
|
||||
}
|
||||
|
||||
public bool CanHandle(string path)
|
||||
{
|
||||
return !Directory.Exists(path)
|
||||
&& WellKnownImageExtensions.Contains(Path.GetExtension(path.ToLower()))
|
||||
&& Handler.CanHandle(path);
|
||||
}
|
||||
|
||||
public void Prepare(string path, ContextObject context)
|
||||
{
|
||||
context.PreferredSize = new Size { Width = 800, Height = 800 };
|
||||
}
|
||||
|
||||
public void View(string path, ContextObject context)
|
||||
{
|
||||
_hp = new HelixPanel(path);
|
||||
context.ViewerContent = _hp;
|
||||
context.Title = $"{Path.GetFileName(path)}";
|
||||
context.IsBusy = false;
|
||||
}
|
||||
|
||||
public void Cleanup()
|
||||
{
|
||||
GC.SuppressFinalize(this);
|
||||
|
||||
_hp = null;
|
||||
}
|
||||
}
|
@@ -0,0 +1,50 @@
|
||||
// Copyright © 2017-2025 QL-Win Contributors
|
||||
//
|
||||
// This file is part of QuickLook program.
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
using System.Reflection;
|
||||
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("QuickLook.Plugin.HelixViewer")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("pooi.moe")]
|
||||
[assembly: AssemblyProduct("QuickLook.Plugin.HelixViewer")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2017-2025 QL-Win Contributors")]
|
||||
[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("311e6e78-3a5b-4e51-802a-5755bd5f9f97")]
|
||||
|
||||
// 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.*")]
|
@@ -0,0 +1,93 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Library</OutputType>
|
||||
<TargetFramework>net462</TargetFramework>
|
||||
<RootNamespace>QuickLook.Plugin.HelixViewer</RootNamespace>
|
||||
<AssemblyName>QuickLook.Plugin.HelixViewer</AssemblyName>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<SignAssembly>false</SignAssembly>
|
||||
<UseWPF>true</UseWPF>
|
||||
<LangVersion>latest</LangVersion>
|
||||
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
||||
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
|
||||
<GenerateTargetFrameworkAttribute>false</GenerateTargetFrameworkAttribute>
|
||||
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
|
||||
<ProjectGuid>{311E6E78-3A5B-4E51-802A-5755BD5F9F97}</ProjectGuid>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>..\..\Build\Debug\QuickLook.Plugin\QuickLook.Plugin.HelixViewer\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|AnyCPU'">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>..\..\Build\Release\QuickLook.Plugin\QuickLook.Plugin.HelixViewer\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<OutputPath>..\..\Build\Debug\QuickLook.Plugin\QuickLook.Plugin.HelixViewer\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
|
||||
<OutputPath>..\..\Build\Release\QuickLook.Plugin\QuickLook.Plugin.HelixViewer\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<Optimize>true</Optimize>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="HelixToolkit" Version="2.27.0">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="HelixToolkit.Wpf" Version="2.27.0">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="PureSharpCompress" Version="0.40.0">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="System.Memory" Version="4.6.3">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="6.1.2">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\QuickLook.Common\QuickLook.Common.csproj">
|
||||
<Project>{85FDD6BA-871D-46C8-BD64-F6BB0CB5EA95}</Project>
|
||||
<Name>QuickLook.Common</Name>
|
||||
<Private>False</Private>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
|
||||
<Target Name="ReduceReleasePackaging" AfterTargets="Build" Condition="'$(Configuration)' == 'Release'">
|
||||
<Delete Files="$(OutputPath)\QuickLook.Plugin.HtmlViewer.dll" Condition="Exists('$(OutputPath)\QuickLook.Plugin.HtmlViewer.dll')" />
|
||||
<Delete Files="$(OutputPath)\QuickLook.Plugin.HtmlViewer.pdb" Condition="Exists('$(OutputPath)\QuickLook.Plugin.HtmlViewer.pdb')" />
|
||||
<Delete Files="$(OutputPath)\lib*.dll" />
|
||||
<RemoveDir Directories="$(OutputPath)\runtimes" Condition="Exists('$(OutputPath)\runtimes')" />
|
||||
</Target>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Include="..\..\GitVersion.cs">
|
||||
<Link>Properties\GitVersion.cs</Link>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
@@ -22,7 +22,6 @@ using QuickLook.Common.Plugin;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Resources;
|
||||
|
Reference in New Issue
Block a user