-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand file tree
/
Copy pathImportThreeDCommand.cs
More file actions
73 lines (61 loc) · 3.13 KB
/
ImportThreeDCommand.cs
File metadata and controls
73 lines (61 loc) · 3.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// Copyright (c) .NET Foundation and Contributors (https://dotnetfoundation.org/ & https://stride3d.net) and Silicon Studio Corp. (https://www.siliconstudio.co.jp)
// Distributed under the MIT license. See the LICENSE.md file in the project root for more information.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Linq;
using Stride.Core.BuildEngine;
using Stride.Core.Serialization.Contents;
using Stride.Animations;
using Stride.Importer.Common;
using Stride.Rendering;
using Stride.Rendering.Data;
namespace Stride.Assets.Models
{
[Description("Import Assimp")]
public class ImportThreeDCommand : ImportModelCommand
{
private static string[] supportedExtensions = ThreeDAssetImporter.FileExtensions.Split(';');
/// <inheritdoc/>
public override string Title { get { string title = "Import Assimp "; try { title += Path.GetFileName(SourcePath) ?? "[File]"; } catch { title += "[INVALID PATH]"; } return title; } }
public static bool IsSupportingExtensions(string ext)
{
if (string.IsNullOrEmpty(ext))
return false;
var extToLower = ext.ToLowerInvariant();
return supportedExtensions.Any(supExt => supExt.Equals(extToLower));
}
private Stride.Importer.ThreeD.MeshConverter CreateMeshConverter(ICommandContext commandContext)
{
return new Stride.Importer.ThreeD.MeshConverter(commandContext.Logger);
}
protected override Model LoadModel(ICommandContext commandContext, ContentManager contentManager)
{
var converter = CreateMeshConverter(commandContext);
converter.KeepOnlyMeshByIndex(((ImportThreeDCommand)commandContext.CurrentCommand).KeptMeshIndex);
// Note: FBX exporter uses Materials for the mapping, but Assimp already uses indices so we can reuse them
// We should still unify the behavior to be more consistent at some point (i.e. if model was changed on the HDD but not in the asset).
// This should probably be better done during a large-scale FBX/Assimp refactoring.
var sceneData = converter.Convert(SourcePath, Location, DeduplicateMaterials);
return sceneData;
}
protected override Dictionary<string, AnimationClip> LoadAnimation(ICommandContext commandContext, ContentManager contentManager, out TimeSpan duration)
{
var meshConverter = this.CreateMeshConverter(commandContext);
var sceneData = meshConverter.ConvertAnimation(SourcePath, Location, AnimationStack);
duration = sceneData.Duration;
return sceneData.AnimationClips;
}
protected override Skeleton LoadSkeleton(ICommandContext commandContext, ContentManager contentManager)
{
var meshConverter = this.CreateMeshConverter(commandContext);
var sceneData = meshConverter.ConvertSkeleton(SourcePath, Location);
return sceneData;
}
public override string ToString()
{
return "Import Assimp " + base.ToString();
}
}
}