-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from julienkay/Custom_Data
Allow importing self trained scenes from disk
- Loading branch information
Showing
7 changed files
with
458 additions
and
169 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ""; | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.