@@ -9,30 +9,17 @@ namespace Genesis.Editor {
9
9
public static class DepthSkyboxPrefabUtility {
10
10
11
11
/// <summary>
12
- /// Given an input png file, generates depth and creates a prefab for a DepthSkybox.
12
+ /// Given an input image file, generates depth and creates a prefab for a DepthSkybox.
13
13
/// </summary>
14
- public static void CreateSkyboxAsset ( string pngFilePath ) {
15
- string name = Path . GetFileNameWithoutExtension ( pngFilePath ) ;
14
+ public static void CreateSkyboxAsset ( string filePath ) {
15
+ string name = Path . GetFileNameWithoutExtension ( filePath ) ;
16
16
string assetPath = Path . Combine ( StagingAreaPath , $ "{ name } ") ;
17
17
Directory . CreateDirectory ( assetPath ) ;
18
18
19
- string pngTargetPath = Path . Combine ( assetPath , $ "{ name } _rgb.png ") ;
20
- Texture2D skybox = ImportImageFile ( pngFilePath , pngTargetPath ) ;
19
+ string targetPath = Path . Combine ( assetPath , $ "{ name } _rgb{ Path . GetExtension ( filePath ) } ") ;
20
+ Texture2D skybox = ImportImageFile ( filePath , targetPath ) ;
21
21
var range = GenerateDepth ( assetPath , name , skybox ) ;
22
- CreateSkyboxPrefab ( assetPath , name , range ) ;
23
- }
24
-
25
- /// <summary>
26
- /// Downloads skybox from Skybox Lab, generates depth and creates a prefab for a DepthSkybox.
27
- /// </summary>
28
- public static async Task CreateSkyboxAsset ( string id , string name ) {
29
- string assetPath = Path . Combine ( StagingAreaPath , $ "{ id } ") ;
30
- Directory . CreateDirectory ( assetPath ) ;
31
-
32
- string imageFile = Path . Combine ( assetPath , $ "{ name } _rgb.png") ;
33
- Texture2D skybox = await DownloadSkyboxById ( imageFile , id ) ;
34
- var range = GenerateDepth ( assetPath , name , skybox ) ;
35
- CreateSkyboxPrefab ( assetPath , name , range ) ;
22
+ CreateSkyboxPrefab ( skybox , assetPath , name , range ) ;
36
23
}
37
24
38
25
private static Vector2 GenerateDepth ( string assetPath , string name , Texture2D skybox ) {
@@ -70,18 +57,15 @@ private static void CreateAsset(Object obj, string path) {
70
57
AssetDatabase . CreateAsset ( obj , path ) ;
71
58
}
72
59
73
- public static void CreateSkyboxPrefab ( string assetPath , string name , Vector2 range ) {
60
+ public static void CreateSkyboxPrefab ( Texture2D skybox , string assetPath , string name , Vector2 range ) {
74
61
int progressId = Progress . Start ( "Creating skybox assets" , "Your skybox assets are being created..." ) ;
75
62
76
63
GameObject skyboxPrefab = ( GameObject ) Resources . Load ( "Prefabs/DepthSkybox" ) ;
77
64
78
65
GameObject instance = ( GameObject ) PrefabUtility . InstantiatePrefab ( skyboxPrefab ) ;
79
66
MeshRenderer renderer = instance . GetComponent < MeshRenderer > ( ) ;
80
67
81
- string skyboxPath = Path . Combine ( assetPath , $ "{ name } _rgb.png") ;
82
68
string depthPath = Path . Combine ( assetPath , $ "{ name } _depth.asset") ;
83
-
84
- Texture2D skybox = ( Texture2D ) AssetDatabase . LoadMainAssetAtPath ( skyboxPath ) ;
85
69
Texture2D skyboxDepth = ( Texture2D ) AssetDatabase . LoadMainAssetAtPath ( depthPath ) ;
86
70
87
71
Material m = new Material ( renderer . sharedMaterial ) ;
@@ -109,49 +93,18 @@ public static void CreateSkyboxPrefab(string assetPath, string name, Vector2 ran
109
93
Progress . Remove ( progressId ) ;
110
94
}
111
95
112
- /// <summary>
113
- /// Downloads a skybox by its ID and saves it inside the project as a .png file.
114
- /// This method assumes that the generation has already completed and that the
115
- /// skybox is available on the server and returns null otherwise.
116
- /// </summary>
117
- private static async Task < Texture2D > DownloadSkyboxById ( string path , string id ) {
118
- int progressId = Progress . Start ( $ "Downloading skybox { id } ", "Your skybox is being downloaded..." ) ;
119
-
120
- // download the skybox
121
- Texture2D skybox = await AssetForge . Instance . GetSkyboxById ( id ) ;
122
- if ( skybox == null ) {
123
- Progress . Remove ( progressId ) ;
124
- return null ;
125
- }
126
-
127
- File . WriteAllBytes ( path , skybox . EncodeToPNG ( ) ) ;
128
- Object . DestroyImmediate ( skybox ) ;
129
-
130
- AssetDatabase . Refresh ( ) ;
131
- Texture2D skyboxTextureAsset = AssetDatabase . LoadAssetAtPath < Texture2D > ( path ) ;
132
-
133
- TextureImporter importer = ( TextureImporter ) AssetImporter . GetAtPath ( path ) ;
134
- importer . maxTextureSize = 4096 ;
135
- importer . textureCompression = TextureImporterCompression . CompressedHQ ;
136
- AssetDatabase . ImportAsset ( path , ImportAssetOptions . ForceUpdate ) ;
137
-
138
- Progress . Remove ( progressId ) ;
139
-
140
- return skyboxTextureAsset ;
141
- }
142
-
143
- private static Texture2D ImportImageFile ( string pngFilePath , string pngTargetPath ) {
96
+ private static Texture2D ImportImageFile ( string filePath , string targetPath ) {
144
97
int progressId = Progress . Start ( $ "Importing image", "Your panorama is being imported..." ) ;
145
98
146
- File . Copy ( pngFilePath , pngTargetPath ) ;
99
+ File . Copy ( filePath , targetPath ) ;
147
100
148
101
AssetDatabase . Refresh ( ) ;
149
- Texture2D skyboxTextureAsset = AssetDatabase . LoadAssetAtPath < Texture2D > ( pngTargetPath ) ;
102
+ Texture2D skyboxTextureAsset = AssetDatabase . LoadAssetAtPath < Texture2D > ( targetPath ) ;
150
103
151
- TextureImporter importer = ( TextureImporter ) AssetImporter . GetAtPath ( pngTargetPath ) ;
104
+ TextureImporter importer = ( TextureImporter ) AssetImporter . GetAtPath ( targetPath ) ;
152
105
importer . maxTextureSize = 4096 ;
153
106
importer . textureCompression = TextureImporterCompression . CompressedHQ ;
154
- AssetDatabase . ImportAsset ( pngTargetPath , ImportAssetOptions . ForceUpdate ) ;
107
+ AssetDatabase . ImportAsset ( targetPath , ImportAssetOptions . ForceUpdate ) ;
155
108
156
109
Progress . Remove ( progressId ) ;
157
110
0 commit comments