Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions UnityRiftCLI/Exporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,7 @@ private static void ExportFbx(IImported convert, string exportPath)
ScaleFactor = CLIOptions.o_fbxScaleFactor.Value,
ExportAllUvsAsDiffuseMaps = CLIOptions.f_fbxUvsAsDiffuseMaps.Value,
ExportAnimations = CLIOptions.o_fbxAnimMode.Value != AnimationExportMode.Skip,
FbxFormat = CLIOptions.f_fbxAsciiFormat.Value ? 1 : 0,
};
ModelExporter.ExportFbx(exportPath, convert, fbxSettings);
}
Expand Down
61 changes: 60 additions & 1 deletion UnityRiftCLI/Options/CLIOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ internal static class CLIOptions
public static bool convertTexture;
public static Option<ImageFormat> o_imageFormat;
public static Option<AudioFormat> o_audioFormat;
public static Option<bool> f_spriteExportWithCanvas;
//live2d
public static Option<CubismLive2DExtractor.Live2DModelGroupOption> o_l2dGroupOption;
public static Option<bool> f_l2dAssetSearchByFilename;
Expand All @@ -130,18 +131,21 @@ internal static class CLIOptions
public static Option<int> o_fbxBoneSize;
public static Option<AnimationExportMode> o_fbxAnimMode;
public static Option<bool> f_fbxUvsAsDiffuseMaps;
public static Option<bool> f_fbxAsciiFormat;
//filter
public static Option<List<string>> o_filterByName;
public static Option<List<string>> o_filterByContainer;
public static Option<List<string>> o_filterByPathID;
public static Option<List<string>> o_filterByText;
public static Option<bool> f_filterWithRegex;
public static Option<bool> f_filterExcludeMode;
//advanced
public static Option<CompressionType> o_bundleBlockInfoCompression;
public static Option<CompressionType> o_bundleBlockCompression;
public static Option<int> o_maxParallelExportTasks;
public static Option<ExportListType> o_exportAssetList;
public static Option<string> o_assemblyPath;
public static Option<string> o_stripPathPrefix;
public static Option<string> o_typeTreeDBPath;
public static Option<UnityVersion> o_unityVersion;
public static Option<bool> f_decompressToDisk;
Expand Down Expand Up @@ -355,6 +359,16 @@ private static void InitOptions()
optionExample: "Example: \"--audio-format wav\"",
optionHelpGroup: HelpGroups.Convert
);
f_spriteExportWithCanvas = new GroupedOption<bool>
(
optionDefaultValue: false,
optionName: "--sprite-canvas",
optionDescription: "(Flag) If specified, sprites are exported at their full authored\n" +
"size (m_Rect) with transparent padding, instead of just the cropped region",
optionExample: "",
optionHelpGroup: HelpGroups.Convert,
isFlag: true
);
#endregion

#region Init Cubism Live2D Options
Expand Down Expand Up @@ -463,6 +477,15 @@ private static void InitOptions()
optionExample: "",
optionHelpGroup: HelpGroups.FBX
);
f_fbxAsciiFormat = new GroupedOption<bool>
(
optionDefaultValue: false,
optionName: "--fbx-ascii-format",
optionDescription: "(Flag) If specified, Studio will export FBX in ASCII format.\n" +
"If not specified, Binary format will be used",
optionExample: "",
optionHelpGroup: HelpGroups.FBX
);
#endregion

#region Init Filter Options
Expand Down Expand Up @@ -513,6 +536,16 @@ private static void InitOptions()
optionHelpGroup: HelpGroups.Filter,
isFlag: true
);
f_filterExcludeMode = new GroupedOption<bool>
(
optionDefaultValue: false,
optionName: "--filter-exclude-mode",
optionDescription: "(Flag) If specified, the filter options will work as an exclusion\n" +
"(i.e. assets that match the filter conditions will be excluded)",
optionExample: "",
optionHelpGroup: HelpGroups.Filter,
isFlag: true
);
#endregion

#region Init Advanced Options
Expand Down Expand Up @@ -678,6 +711,15 @@ private static void InitOptions()
optionExample: "",
optionHelpGroup: HelpGroups.Advanced
);
o_stripPathPrefix = new GroupedOption<string>
(
optionDefaultValue: "",
optionName: "--strip-path-prefix <path>",
optionDescription: "Specify a path prefix to be stripped from exported asset container paths\n" +
"(applies to the ContainerPath / ContainerPathFull group options)\n",
optionExample: "Example: \"--strip-path-prefix assets/models/char/\"\n",
optionHelpGroup: HelpGroups.Advanced
);
o_typeTreeDBPath = new GroupedOption<string>
(
optionDefaultValue: "",
Expand Down Expand Up @@ -889,6 +931,7 @@ public static void ParseArgs(string[] args)
o_exportAssetTypes.Value = new List<ClassIDType>
{
ClassIDType.Animator,
ClassIDType.AnimationClip, // needed so --fbx-animation all can bind clips
ClassIDType.Mesh,
ClassIDType.Texture2D,
};
Expand Down Expand Up @@ -948,7 +991,7 @@ public static void ParseArgs(string[] args)
flagIndexes.Add(i);
break;
case "--fbx-uvs-as-diffuse":
if (o_workMode.Value != WorkMode.SplitObjects)
if (o_workMode.Value != WorkMode.SplitObjects && o_workMode.Value != WorkMode.Animator)
{
Console.WriteLine($"{"Error".Color(brightRed)} during parsing [{flag.Color(brightYellow)}] flag. This flag is not suitable for the current working mode [{o_workMode.Value}].\n");
ShowOptionDescription(o_workMode);
Expand All @@ -957,10 +1000,22 @@ public static void ParseArgs(string[] args)
f_fbxUvsAsDiffuseMaps.Value = true;
flagIndexes.Add(i);
break;
case "--fbx-ascii-format":
f_fbxAsciiFormat.Value = true;
flagIndexes.Add(i);
break;
case "--filter-with-regex":
f_filterWithRegex.Value = true;
flagIndexes.Add(i);
break;
case "--filter-exclude-mode":
f_filterExcludeMode.Value = true;
flagIndexes.Add(i);
break;
case "--sprite-canvas":
f_spriteExportWithCanvas.Value = true;
flagIndexes.Add(i);
break;
case "--il2cpp":
f_il2cpp.Value = true;
flagIndexes.Add(i);
Expand Down Expand Up @@ -1546,6 +1601,10 @@ public static void ParseArgs(string[] args)
return;
}
break;
case "--strip-path-prefix":
// Normalize to a directory-style prefix ending with a separator.
o_stripPathPrefix.Value = value.Replace('\\', '/').TrimEnd('/') + "/";
break;
case "--unity-version":
try
{
Expand Down
2 changes: 1 addition & 1 deletion UnityRiftCLI/ParallelExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public static bool ExportSprite(AssetItem item, string exportPath, out string de
var alphaMask = SpriteMaskMode.On;
if (!TryExportFile(exportPath, item, "." + type.ToString().ToLower(), out var exportFullPath))
return false;
var image = ((Sprite)item.Asset).GetImage(alphaMask);
var image = ((Sprite)item.Asset).GetImage(alphaMask, CLIOptions.f_spriteExportWithCanvas.Value);
if (image != null)
{
using (image)
Expand Down
40 changes: 39 additions & 1 deletion UnityRiftCLI/Studio.cs
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,14 @@ private static void FilterAssets()
);
break;
}

if (CLIOptions.f_filterExcludeMode.Value)
{
var matchedCount = filteredAssets.Count;
filteredAssets = parsedAssetsList.Except(filteredAssets).ToList();
Logger.Info($"Exclusion mode: dropping {matchedCount} matched asset(s), keeping {filteredAssets.Count}.");
}

parsedAssetsList.Clear();
parsedAssetsList = filteredAssets;
}
Expand All @@ -668,6 +676,26 @@ public static void ExportAssets()
var groupOption = CLIOptions.o_groupAssetsBy.Value;
var parallelExportCount = CLIOptions.o_maxParallelExportTasks.Value;
var toExportAssetDict = new ConcurrentDictionary<AssetItem, string>();

// Validate the strip-path-prefix against loaded containers; ignore it if any container
// doesn't start with it (upstream #113).
if (!string.IsNullOrEmpty(CLIOptions.o_stripPathPrefix.Value))
{
foreach (var asset in parsedAssetsList)
{
if (string.IsNullOrEmpty(asset.Container))
continue;
if (!asset.Container.StartsWith(CLIOptions.o_stripPathPrefix.Value))
{
Logger.Warning($"Asset container path \"{asset.Container}\" does not start with the specified path prefix \"{CLIOptions.o_stripPathPrefix.Value}\"");
Logger.Warning("strip-path-prefix option will be ignored.");
CLIOptions.o_stripPathPrefix.Value = "";
break;
}
}
if (!string.IsNullOrEmpty(CLIOptions.o_stripPathPrefix.Value))
Logger.Info($"Asset container path prefix \"{CLIOptions.o_stripPathPrefix.Value}\" will be stripped off.");
}
var toParallelExportAssetDict = new ConcurrentDictionary<AssetItem, string>();
Parallel.ForEach(parsedAssetsList, asset =>
{
Expand All @@ -681,7 +709,17 @@ public static void ExportAssets()
case AssetGroupOption.ContainerPathFull:
if (!string.IsNullOrEmpty(asset.Container))
{
exportPath = Path.Combine(savePath, Path.GetDirectoryName(asset.Container));
var containerDir = Path.GetDirectoryName(asset.Container) ?? "";
// Strip the configured prefix from the container path (upstream #113).
if (!string.IsNullOrEmpty(CLIOptions.o_stripPathPrefix.Value)
&& asset.Container.StartsWith(CLIOptions.o_stripPathPrefix.Value))
{
var stripped = asset.Container.Substring(CLIOptions.o_stripPathPrefix.Value.Length);
containerDir = Path.GetDirectoryName(stripped) ?? "";
}
exportPath = string.IsNullOrEmpty(containerDir)
? savePath
: Path.Combine(savePath, containerDir);
if (groupOption == AssetGroupOption.ContainerPathFull)
{
exportPath = Path.Combine(exportPath, Path.GetFileNameWithoutExtension(asset.Container));
Expand Down
18 changes: 9 additions & 9 deletions UnityRiftFBXWrapper/FbxExporterContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -228,19 +228,19 @@ private void ExportMesh(ImportedFrame rootFrame, List<ImportedMaterial> material

foreach (var bone in boneList)
{
var cluster = IntPtr.Zero;
if (bone.Path != null)
{
var frame = rootFrame.FindFrameByPath(bone.Path);
var boneNode = _frameToNode[frame];

var cluster = AsFbxMeshCreateCluster(_pContext, boneNode);

AsFbxMeshAddCluster(pClusterArray, cluster);
}
else
{
AsFbxMeshAddCluster(pClusterArray, IntPtr.Zero);
// The bone's frame may not exist in the exported hierarchy; skip it
// (add an empty cluster) instead of throwing a NullReferenceException.
if (frame != null)
{
var boneNode = _frameToNode[frame];
cluster = AsFbxMeshCreateCluster(_pContext, boneNode);
}
}
AsFbxMeshAddCluster(pClusterArray, cluster);
}
}

Expand Down
17 changes: 15 additions & 2 deletions UnityRiftGUI/ExportOptions.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions UnityRiftGUI/ExportOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public ExportOptions()
restoreExtensionName.Checked = Properties.Settings.Default.restoreExtensionName;
converttexture.Checked = Properties.Settings.Default.convertTexture;
exportSpriteWithAlphaMask.Checked = Properties.Settings.Default.exportSpriteWithMask;
exportSpriteWithCanvas.Checked = Properties.Settings.Default.spriteExportWithCanvas;
convertAudio.Checked = Properties.Settings.Default.convertAudio;
var defaultImageType = Properties.Settings.Default.convertType.ToString();
((RadioButton)panel1.Controls.Cast<Control>().First(x => x.Text == defaultImageType)).Checked = true;
Expand Down Expand Up @@ -50,6 +51,7 @@ private void OKbutton_Click(object sender, EventArgs e)
Properties.Settings.Default.restoreExtensionName = restoreExtensionName.Checked;
Properties.Settings.Default.convertTexture = converttexture.Checked;
Properties.Settings.Default.exportSpriteWithMask = exportSpriteWithAlphaMask.Checked;
Properties.Settings.Default.spriteExportWithCanvas = exportSpriteWithCanvas.Checked;
Properties.Settings.Default.convertAudio = convertAudio.Checked;
var checkedImageType = (RadioButton)panel1.Controls.Cast<Control>().First(x => ((RadioButton)x).Checked);
Properties.Settings.Default.convertType = (ImageFormat)Enum.Parse(typeof(ImageFormat), checkedImageType.Text);
Expand Down
2 changes: 1 addition & 1 deletion UnityRiftGUI/ParallelExport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public static bool ExportSprite(AssetItem item, string exportPath, out string de
var spriteMaskMode = Properties.Settings.Default.exportSpriteWithMask ? SpriteMaskMode.Export : SpriteMaskMode.Off;
if (!TryExportFile(exportPath, item, "." + type.ToString().ToLower(), out var exportFullPath))
return false;
var image = ((Sprite)item.Asset).GetImage(spriteMaskMode: spriteMaskMode);
var image = ((Sprite)item.Asset).GetImage(spriteMaskMode: spriteMaskMode, spriteWithCanvas: Properties.Settings.Default.spriteExportWithCanvas);
if (image != null)
{
using (image)
Expand Down
14 changes: 13 additions & 1 deletion UnityRiftGUI/Properties/Settings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions UnityRiftGUI/Properties/Settings.settings
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
<Setting Name="exportSpriteWithMask" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">True</Value>
</Setting>
<Setting Name="spriteExportWithCanvas" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">False</Value>
</Setting>
<Setting Name="l2dMotionMode" Type="CubismLive2DExtractor.Live2DMotionMode" Scope="User">
<Value Profile="(Default)">MonoBehaviour</Value>
</Setting>
Expand Down
Loading
Loading