mirror of
https://github.com/QL-Win/QuickLook.git
synced 2025-09-15 04:39:07 +00:00
Add FBX model support using AssimpNet #1479
This commit is contained in:
@@ -15,7 +15,9 @@
|
|||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
using Assimp;
|
||||||
using HelixToolkit.Wpf;
|
using HelixToolkit.Wpf;
|
||||||
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Windows.Controls;
|
using System.Windows.Controls;
|
||||||
using System.Windows.Media;
|
using System.Windows.Media;
|
||||||
@@ -25,7 +27,7 @@ namespace QuickLook.Plugin.HelixViewer;
|
|||||||
|
|
||||||
public partial class HelixPanel : UserControl
|
public partial class HelixPanel : UserControl
|
||||||
{
|
{
|
||||||
private string _path;
|
private readonly string _path;
|
||||||
|
|
||||||
public HelixPanel(string path) : this()
|
public HelixPanel(string path) : this()
|
||||||
{
|
{
|
||||||
@@ -40,16 +42,40 @@ public partial class HelixPanel : UserControl
|
|||||||
|
|
||||||
private void Load()
|
private void Load()
|
||||||
{
|
{
|
||||||
var modelImporter = new ModelImporter();
|
if (_path.EndsWith(".fbx", StringComparison.OrdinalIgnoreCase))
|
||||||
var model3DGroup = modelImporter.Load(_path);
|
|
||||||
var diffuseMaterial = new DiffuseMaterial(new SolidColorBrush(Color.FromRgb(0xA0, 0xA0, 0xA0)));
|
|
||||||
|
|
||||||
foreach (GeometryModel3D child in model3DGroup.Children.Cast<GeometryModel3D>())
|
|
||||||
{
|
{
|
||||||
child.Material = diffuseMaterial;
|
var context = new AssimpContext();
|
||||||
child.BackMaterial = diffuseMaterial;
|
var scene = context.ImportFile(_path, PostProcessSteps.Triangulate);
|
||||||
}
|
|
||||||
|
|
||||||
modelVisual.Content = model3DGroup;
|
foreach (var mesh in scene.Meshes)
|
||||||
|
{
|
||||||
|
var geometry = new MeshGeometry3D()
|
||||||
|
{
|
||||||
|
Positions = [.. mesh.Vertices.Select(v => new Point3D(v.X, v.Y, v.Z))],
|
||||||
|
TriangleIndices = [.. mesh.GetIndices()],
|
||||||
|
};
|
||||||
|
var model = new GeometryModel3D()
|
||||||
|
{
|
||||||
|
Geometry = geometry,
|
||||||
|
Material = Materials.Gray,
|
||||||
|
};
|
||||||
|
|
||||||
|
modelVisual.Content = model;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var modelImporter = new ModelImporter();
|
||||||
|
var model3DGroup = modelImporter.Load(_path);
|
||||||
|
var diffuseMaterial = new DiffuseMaterial(new SolidColorBrush(Color.FromRgb(0xA0, 0xA0, 0xA0)));
|
||||||
|
|
||||||
|
foreach (GeometryModel3D child in model3DGroup.Children.Cast<GeometryModel3D>())
|
||||||
|
{
|
||||||
|
child.Material = diffuseMaterial;
|
||||||
|
child.BackMaterial = diffuseMaterial;
|
||||||
|
}
|
||||||
|
|
||||||
|
modelVisual.Content = model3DGroup;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -28,6 +28,7 @@ public class Plugin : IViewer
|
|||||||
private static readonly HashSet<string> WellKnownExtensions = new(
|
private static readonly HashSet<string> WellKnownExtensions = new(
|
||||||
[
|
[
|
||||||
".stl", ".obj", ".3ds", ".lwo", ".ply",
|
".stl", ".obj", ".3ds", ".lwo", ".ply",
|
||||||
|
".fbx",
|
||||||
]);
|
]);
|
||||||
|
|
||||||
private HelixPanel _hp;
|
private HelixPanel _hp;
|
||||||
|
@@ -54,6 +54,7 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="HelixToolkit" Version="2.27.0" />
|
<PackageReference Include="HelixToolkit" Version="2.27.0" />
|
||||||
<PackageReference Include="HelixToolkit.Wpf" Version="2.27.0" />
|
<PackageReference Include="HelixToolkit.Wpf" Version="2.27.0" />
|
||||||
|
<PackageReference Include="AssimpNet" Version="5.0.0-beta1" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
Reference in New Issue
Block a user