Skip to content

Commit

Permalink
Merge pull request #2 from julienkay/Custom_Data
Browse files Browse the repository at this point in the history
Allow importing self trained scenes from disk
  • Loading branch information
julienkay authored Sep 1, 2022
2 parents a461385 + b5b8208 commit b8a2ae2
Show file tree
Hide file tree
Showing 7 changed files with 458 additions and 169 deletions.
465 changes: 296 additions & 169 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.

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

/// <summary>
/// Custom import settings for MobileNeRF OBJs.
/// </summary>
public class ObjImportProcessor : AssetPostprocessor {
private void OnPreprocessModel() {
Regex objPattern = new Regex(@"shape.*\.obj");

if (objPattern.IsMatch(assetPath)) {
ModelImporter modelImporter = assetImporter as ModelImporter;
// 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.
modelImporter.importTangents = ModelImporterTangents.None;
modelImporter.importNormals = ModelImporterNormals.None;

// one material per shape (each has individual feature textures)
modelImporter.materialLocation = ModelImporterMaterialLocation.External;
modelImporter.materialName = ModelImporterMaterialName.BasedOnModelNameAndMaterialName;
}
}
}
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 b8a2ae2

Please sign in to comment.