コード例 #1
0
        public static optional <OctahedronPlanetarium> load(string file_name)
        {
            optional <Material> material = WorldPlanetarium.load_material(file_name);

            if (!material.exists)
            {
                return(new optional <OctahedronPlanetarium>());
            }
            Texture2D             texture = (Texture2D)WorldPlanetarium.load_texture(file_name);
            OctahedronPlanetarium result  = new OctahedronPlanetarium(texture.width);

            result.material = material.data;
            result.texture  = texture;
            result.material.SetTexture("_MainTex", result.texture);
            return(result);
        }
コード例 #2
0
        private void OnGUI()
        {
            if (GUILayout.Button("Image(s) to convert"))
            {
                from_file_name = EditorUtility.OpenFilePanel("PNG to convert", "Assets/Planetaria/ExampleProjects/DébrisNoirs/Art/Textures", "mat"); // TODO: multiple types
                from_file_name = from_file_name.Substring(0, from_file_name.Length - 4);
                // this is an editor tool, so the following is fine:
                int clip_index = from_file_name.IndexOf("Assets/");
                from_file_name = from_file_name.Substring(clip_index);
            }
            if (GUILayout.Button("Generated PNG(s) filename"))
            {
                to_file_name = EditorUtility.SaveFilePanel("Generated PNG filename", "Assets/Planetaria/ExampleProjects/DébrisNoirs/Art/Textures", "output_file", "png"); // TODO: multiple types and use output in conversion // FIXME: HACK: trying to make deadlines
                to_file_name = to_file_name.Substring(0, to_file_name.Length - 4);
                // this is an editor tool, so the following is fine:
                int clip_index = to_file_name.IndexOf("Assets/");
                to_file_name = to_file_name.Substring(clip_index);
            }

            GUILayout.BeginHorizontal();
            from_shape = (Shape)EditorGUILayout.EnumPopup("Current shape format", from_shape);
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            to_shape = (Shape)EditorGUILayout.EnumPopup("Target shape format", to_shape);
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            resolution = EditorGUILayout.IntField("Pixel resolution", resolution);
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            sample_rate = EditorGUILayout.IntField("Sample rate", sample_rate);
            GUILayout.EndHorizontal();

            switch (from_shape)
            {
            case Shape.SphericalRectangle:
                GUILayout.BeginHorizontal();
                canvas = EditorGUILayout.RectField("Spherical Rectangle", canvas);
                GUILayout.EndHorizontal();
                break;

            case Shape.SphericalCircle:
                GUILayout.BeginHorizontal();
                radius = EditorGUILayout.FloatField("Spherical Circle radius", radius);
                GUILayout.EndHorizontal();
                break;
            }

            if (GUILayout.Button("Convert"))
            {
                WorldPlanetarium from;
                WorldPlanetarium to;
                switch (from_shape)
                {
                case Shape.Cube:
                    optional <CubePlanetarium> cubemap = CubePlanetarium.load(from_file_name);
                    Debug.Assert(cubemap.exists);
                    from = cubemap.data;
                    break;

                case Shape.Octahedron:
                    optional <OctahedronPlanetarium> octahedron = OctahedronPlanetarium.load(from_file_name);
                    Debug.Assert(octahedron.exists);
                    from = octahedron.data;
                    break;

                case Shape.SphericalRectangle:
                    optional <SphericalRectanglePlanetarium> rectangle = SphericalRectanglePlanetarium.load(from_file_name, canvas);
                    Debug.Assert(rectangle.exists);
                    from = rectangle.data;
                    break;

                case Shape.SphericalCircle:
                default:     // FIXME:
                    optional <SphericalCirclePlanetarium> circle = SphericalCirclePlanetarium.load(from_file_name, radius);
                    Debug.Assert(circle.exists);
                    from = circle.data;
                    break;
                }
                switch (to_shape)
                {
                case Shape.Cube:
                    to = new CubePlanetarium(resolution);
                    to.convert(from);
                    to.save(to_file_name);
                    break;

                case Shape.Octahedron:
                    to = new OctahedronPlanetarium(resolution);
                    to.convert(from);
                    to.save(to_file_name);
                    break;
                }
            }
        }