Skip to content

Commit

Permalink
Add menu to import custom datasets.
Browse files Browse the repository at this point in the history
  • Loading branch information
julienkay committed Aug 30, 2022
1 parent a461385 commit 55d9872
Show file tree
Hide file tree
Showing 7 changed files with 404 additions and 160 deletions.
407 changes: 247 additions & 160 deletions Assets/Editor/MobileNeRFImporter.cs

Large diffs are not rendered by default.

84 changes: 84 additions & 0 deletions Assets/Editor/MobileNeRFScene.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
using System;

/// <summary>
/// The names of the available demo scenes.
/// </summary>
public enum MNeRFScene {
Custom = -1,
Chair,
Drums,
Ficus,
Hotdog,
Lego,
Materials,
Mic,
Ship,
Fern,
Flower,
Fortress,
Horns,
Leaves,
Orchids,
Room,
Trex,
Bicycle,
Gardenvase,
Stump
}

public static class MNeRFSceneExtensions {

public static string String(this MNeRFScene scene) {
return scene.ToString().ToLower();
}

public static MNeRFScene ToEnum(string value) {
if (Enum.TryParse(value, ignoreCase: true, out MNeRFScene result)) {
return result;
} else {
return MNeRFScene.Custom;
}
}

public static string GetAxisSwizzleString(this MNeRFScene scene) {
switch (scene) {
case MNeRFScene.Custom:
// Based on user feedback for custom scenes
if (MobileNeRFImporter.SwizzleAxis) {
return "o.rayDirection.xz = -o.rayDirection.xz;" +
"o.rayDirection.xyz = o.rayDirection.xzy;";
} else {
return "o.rayDirection.x = -o.rayDirection.x;";
}
case MNeRFScene.Chair:
case MNeRFScene.Drums:
case MNeRFScene.Ficus:
case MNeRFScene.Hotdog:
case MNeRFScene.Lego:
case MNeRFScene.Materials:
case MNeRFScene.Mic:
case MNeRFScene.Ship:
// Synthetic 360° scenes
return "o.rayDirection.xz = -o.rayDirection.xz;" +
"o.rayDirection.xyz = o.rayDirection.xzy;";
case MNeRFScene.Fern:
case MNeRFScene.Flower:
case MNeRFScene.Fortress:
case MNeRFScene.Horns:
case MNeRFScene.Leaves:
case MNeRFScene.Orchids:
case MNeRFScene.Room:
case MNeRFScene.Trex:
// Forward-facing scenes
return "o.rayDirection.x = -o.rayDirection.x;";
case MNeRFScene.Bicycle:
case MNeRFScene.Gardenvase:
case MNeRFScene.Stump:
// Unbounded 360° scenes
return "o.rayDirection.xz = -o.rayDirection.xz;" +
"o.rayDirection.xyz = o.rayDirection.xzy;";
default:
return "";
}
}
}
11 changes: 11 additions & 0 deletions Assets/Editor/MobileNeRFScene.cs.meta

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

18 changes: 18 additions & 0 deletions Assets/Editor/ObjImportProcessor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System.Text.RegularExpressions;
using UnityEditor;

/// <summary>
/// MobileNeRFs don't use normals, so we disable trying to read them when importing .obj files
/// This is not strictly necessary, but prevents the warnings showing in the console.
/// </summary>
public class ObjImportProcessor : AssetPostprocessor {
private void OnPreprocessModel() {
Regex objPattern = new Regex("shape[0-9]_[0-9].obj");

if (objPattern.IsMatch(assetPath)) {
ModelImporter modelImporter = assetImporter as ModelImporter;
modelImporter.importTangents = ModelImporterTangents.None;
modelImporter.importNormals = ModelImporterNormals.None;
}
}
}
11 changes: 11 additions & 0 deletions Assets/Editor/ObjImportProcessor.cs.meta

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

22 changes: 22 additions & 0 deletions Assets/Editor/PNGImportProcessor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System.Text.RegularExpressions;
using UnityEditor;
using UnityEngine;

/// <summary>
/// Configures MobileNeRF feature textures to have the correct import settings.
/// </summary>
public class PNGImportProcessor : AssetPostprocessor {

private void OnPreprocessTexture() {
Regex featureTexturePattern = new Regex("shape[0-9].pngfeat[0-9].png");
if (featureTexturePattern.IsMatch(assetPath)) {
TextureImporter textureImporter = assetImporter as TextureImporter;
textureImporter.maxTextureSize = 4096;
textureImporter.textureCompression = TextureImporterCompression.Uncompressed;
textureImporter.sRGBTexture = false;
textureImporter.filterMode = FilterMode.Point;
textureImporter.mipmapEnabled = false;
textureImporter.alphaIsTransparency = true;
}
}
}
11 changes: 11 additions & 0 deletions Assets/Editor/PNGImportProcessor.cs.meta

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

0 comments on commit 55d9872

Please sign in to comment.