- Home /
Saving an 360 degree image to resources and converting it to Skybox/Cubemap to render in the environment?
Helle everyone,
I am new to unity and i am trying to make a virtual tour app with 360degree photograps in unity.
I basically change the texture of the photo to cubemap and paste it onto a Skybox/Cubemap material.Then I use the material in the scene as environment.This way main camera moves around the photo according to the user's touch direction.
It was very easy to do it by hand but i need to do this via script. As you can see below I am trying to save the photo to assets and do the necessary texture conversions then. It gives no error but it also does not work either. Can anybody tell me what I am missing here?
public IEnumerator Convert()
{
WWW www = new WWW("http://csphotography.ca/wp-content/uploads/2016/09/Rodd-Motel-Moncton-rm-112-Panorama-small1.jpg");
yield return www;
Texture2D runtimeTexture = www.texture;
AssetDatabase.CreateAsset(runtimeTexture, "Assets/Resources/images/Content");
string path = AssetDatabase.GetAssetPath(runtimeTexture);
Debug.Log("path: " + path);
AssetDatabase.SaveAssets();
EditorUtility.SetDirty(runtimeTexture);
TextureImporter textureImporter = AssetImporter.GetAtPath(path) as TextureImporter;
textureImporter.textureShape = TextureImporterShape.TextureCube;
Material runtimeMaterial = new Material(Shader.Find("Skybox/Cubemap"));
runtimeMaterial.SetTexture("_MainTex", runtimeTexture);
AssetDatabase.SaveAssets();
AssetDatabase.Refresh();
Material materailTexture = Resources.Load<Material>(path);
RenderSettings.skybox = materailTexture;
}
Your answer
Follow this Question
Related Questions
could not open file file.png 1 Answer
Half image download from the server ? 0 Answers
WebClient on Android 0 Answers
IP blocked for pulling images using WWW class 1 Answer
Memory leak with WWW on iOS 1 Answer