आप एक वर्ग है कि विरासत में बना सकते हैं स्क्रिप्ट करने योग्य जादूगर वर्ग जो एक विशिष्ट परिवर्तन से एक क्यूबमैप प्रस्तुत करेगा।
using UnityEngine;
using UnityEditor;
using System.Collections;
using System.IO;
public class RenderCubemapWizard : ScriptableWizard
{
public Transform renderFromPosition;
public Cubemap cubemap;
void OnWizardUpdate()
{
string helpString = "Select transform to render from and cubemap to render into";
bool isValid = (renderFromPosition != null) && (cubemap != null);
}
void OnWizardCreate()
{
// create temporary camera for rendering
GameObject go = new GameObject("CubemapCamera");
go.AddComponent<Camera>();
// place it on the object
go.transform.position = renderFromPosition.position;
go.transform.rotation = Quaternion.identity;
// render into cubemap
go.GetComponent<Camera>().RenderToCubemap(cubemap);
// destroy temporary camera
DestroyImmediate(go);
ConvertToPng();
}
[MenuItem("GameObject/Render into Cubemap")]
static void RenderCubemap()
{
ScriptableWizard.DisplayWizard<RenderCubemapWizard>(
"Render cubemap", "Render!");
}
void ConvertToPng()
{
Debug.Log(Application.dataPath + "/" +cubemap.name +"_PositiveX.png");
var tex = new Texture2D (cubemap.width, cubemap.height, TextureFormat.RGB24, false);
// Read screen contents into the texture
tex.SetPixels(cubemap.GetPixels(CubemapFace.PositiveX));
// Encode texture into PNG
var bytes = tex.EncodeToPNG();
File.WriteAllBytes(Application.dataPath + "/" + cubemap.name +"_PositiveX.png", bytes);
tex.SetPixels(cubemap.GetPixels(CubemapFace.NegativeX));
bytes = tex.EncodeToPNG();
File.WriteAllBytes(Application.dataPath + "/" + cubemap.name +"_NegativeX.png", bytes);
tex.SetPixels(cubemap.GetPixels(CubemapFace.PositiveY));
bytes = tex.EncodeToPNG();
File.WriteAllBytes(Application.dataPath + "/" + cubemap.name +"_PositiveY.png", bytes);
tex.SetPixels(cubemap.GetPixels(CubemapFace.NegativeY));
bytes = tex.EncodeToPNG();
File.WriteAllBytes(Application.dataPath + "/" + cubemap.name +"_NegativeY.png", bytes);
tex.SetPixels(cubemap.GetPixels(CubemapFace.PositiveZ));
bytes = tex.EncodeToPNG();
File.WriteAllBytes(Application.dataPath + "/" + cubemap.name +"_PositiveZ.png", bytes);
tex.SetPixels(cubemap.GetPixels(CubemapFace.NegativeZ));
bytes = tex.EncodeToPNG();
File.WriteAllBytes(Application.dataPath + "/" + cubemap.name +"_NegativeZ.png", bytes);
DestroyImmediate(tex);
}
}
यह मूलतः दी गई स्थिति है कि आप जादूगर के भीतर से निर्दिष्ट से एक नया cubemap बनाता है (जादूगर शीर्ष मेनू में GameObject के लिए जाने के उपयोग करने के लिए और सूची आप 'के तल पर: यहाँ मेरी कोड है देखें 'क्यूबेम में प्रस्तुत करें')। इसके बाद यह क्यूबमैप की छः स्थितियों को पकड़ लेगा और इसे कनवर्ट टॉपिंग() फ़ंक्शन में से एक पीएनजी फ़ाइल में परिवर्तित कर देगा। यह मेरे लिए काम करता है और इसे आपके लिए काम करना चाहिए क्योंकि यह अनिवार्य रूप से केवल एक परिवर्तन की स्थिति की आवश्यकता है। क्षमा करें कि इसे सरल बनाने के लिए कितनी देर तक कोशिश की गई है, लेकिन इसे सरल बना दिया गया है क्योंकि मैं इसे बना सकता हूं।
यहाँ लिंक है कि मुझे इस निष्कर्ष पर आते मदद की हैं:
How to convert a face to png
Unity's scriptable wizard for rendering a cubemap
स्रोत
2015-12-25 02:01:24
किसी को मदद करने के लिए सक्षम होने के लिए के लिए एक सवाल के अस्पष्ट के लिए रास्ता। आपको एक गोलाकार छवि को एक क्यूबैम को सहेजने की ज़रूरत है? आप किस सॉफ्टवेयर का उपयोग कर रहे हैं ... आप जिस कोड को लिखने की कोशिश कर रहे हैं वह क्या है? आपको इस कोड के साथ क्या त्रुटियां मिल रही हैं? मदद करने के लिए विशिष्टता की आवश्यकता है। – DavidR
मैं cubemap है: http://joxi.ru/zANd66wSl6Kdkm मैं png में बचाने की जरूरत है: http://joxi.ru/12MW55wT40LYjr भाग कोड है, जो आपकी मदद: tex.SetPixels (cubemap.GetPixels (CubemapFace। PositiveZ)); बाइट्स = tex.EncodeToPNG(); File.WriteAllBytes (Application.dataPath + "/" + cubemap.name + "_ PositiveZ.png", बाइट्स); –
ठीक है, डेविडआर, थक्स। मैं http://stackoverflow.com/ में शुरुआत कर रहा हूँ। लेकिन क्या आप मेरी मदद कर सकते हैं? बनावट में cubemap कैसे बचें? मैं यूएनटी 3 डी का उपयोग करता हूं, सी # –