Esempio n. 1
0
 protected void OnTextureLoaded(Texture2D texture, TextureOrientation orientation)
 {
     if (onTextureLoaded != null)
     {
         onTextureLoaded(texture, orientation);
     }
 }
Esempio n. 2
0
 /// <summary>
 /// Example callback for loading a texture.
 /// </summary>
 /// <param name="loadedTexture">If no error occurred, resulting texture. null otherwise</param>
 protected void OnTextureLoaded(Texture2D loadedTexture, TextureOrientation orientation)
 {
     texture.onTextureLoaded -= OnTextureLoaded;
     if (loadedTexture != null)
     {
         ApplyTexture(loadedTexture, orientation);
     }
     else
     {
         Debug.LogError("Loading Texture failed!");
     }
     texture = null;
 }
    protected override void ApplyTexture(Texture2D texture, TextureOrientation orientation)
    {
        var renderer = GetComponent <Renderer>();

        if (renderer != null && renderer.sharedMaterial != null)
        {
            renderer.material.mainTexture = texture;
            // Optional: Support arbitrary texture orientation by flipping the texture if necessary
            var scale = renderer.material.mainTextureScale;
            scale.x = orientation.IsXFlipped() ? -1 : 1;
            scale.y = orientation.IsYFlipped() ? -1 : 1;
            renderer.material.mainTextureScale = scale;
        }
    }
Esempio n. 4
0
    protected override void ApplyTexture(Texture2D texture, TextureOrientation orientation)
    {
        Vector2 pos  = new Vector2(0, 0);
        Vector2 size = new Vector2(texture.width, texture.height);

        if (orientation.IsXFlipped())
        {
            pos.x   = size.x;
            size.x *= -1;
        }

        if (orientation.IsYFlipped())
        {
            pos.y   = size.y;
            size.y *= -1;
        }

        GetComponent <Image>().sprite = Sprite.Create(texture, new Rect(pos, size), Vector2.zero);
    }
Esempio n. 5
0
    void ApplyTexture(Texture2D texture, TextureOrientation orientation)
    {
        Profiler.BeginSample("ApplyTexture");
        if (texture == null)
        {
            return;
        }
        total_count++;
        Debug.LogFormat("Added image {0}", total_count);
        var b = Object.Instantiate <Renderer>(prefab);

        b.transform.position = new Vector3(
            (Random.value - .5f) * spread * aspectRatio,
            (Random.value - .5f) * spread,
            distance
            );
        distance += step;
        b.material.mainTexture = texture;
        var scale = b.material.mainTextureScale;

        scale.x = orientation.IsXFlipped() ? -1 : 1;
        scale.y = orientation.IsYFlipped() ? -1 : 1;
        b.material.mainTextureScale = scale;

        rendererQueue.Enqueue(b);
        while (rendererQueue.Count > MAX_ITEMS)
        {
            var r = rendererQueue.Dequeue();
            r.enabled = false;
        }

        if (batch_count > 0)
        {
            batch_count--;
            if (batch_count == 0)
            {
                batch_time = Time.realtimeSinceStartup - start_time;
                Debug.LogFormat("Batch load time: {0}", batch_time);
                batch_count = -1;
            }
        }
        Profiler.EndSample();
    }
Esempio n. 6
0
 protected abstract void ApplyTexture(Texture2D texture, TextureOrientation orientation);
 /// <summary>
 /// Evaluates if the texture's vertical orientation conforms to Unity's default.
 /// If it's not aligned (=true; =flipped), the texture has to be applied mirrored vertically.
 /// </summary>
 /// <param name="to"></param>
 /// <returns>True if the vertical orientation is flipped, false otherwise</returns>
 public static bool IsYFlipped(this TextureOrientation to)
 {
     // Unity default == Y_UP
     return((to & TextureOrientation.Y_UP) == 0);
 }
 /// <summary>
 /// Evaluates if the texture's horizontal orientation conforms to Unity's default.
 /// If it's not aligned (=true; =flipped), the texture has to be applied mirrored horizontally.
 /// </summary>
 /// <param name="to"></param>
 /// <returns>True if the horizontal orientation is flipped, false otherwise</returns>
 public static bool IsXFlipped(this TextureOrientation to)
 {
     // Unity default == X_RIGHT
     return((to & TextureOrientation.X_LEFT) != 0);
 }
Esempio n. 9
0
            public IEnumerator CreateTextureAsync(bool linear, Action <Texture2D, TextureOrientation> onFinish, string mimeType, Action <float> onProgress = null)
            {
                Texture2D          tex         = new Texture2D(2, 2, TextureFormat.ARGB32, true, linear);
                bool               loaded      = false;
                TextureOrientation orientation = new TextureOrientation();

                //With GLTF, the mimeType stores the path, let's correct that mistake
                if (!string.IsNullOrEmpty(mimeType))
                {
                    if (File.Exists(mimeType))
                    {
                        path     = mimeType;
                        mimeType = "image/" + Path.GetExtension(path).Remove(0, 1);
                    }
                }

                //Use KtxUnity plugin to load ktx/ktx2/basis textures
                if (mimeType == "image/ktx" || mimeType == "image/ktx2" || mimeType == "image/basis")
                {
#if !KTX
                    Debug.LogError("GLTFImage.cs CreateTextureAsync() KTX and basis texture support is not enabled, try enabling 'KTX' scripting define symbol in project settings and make sure KtxUnity plugin is in your project");
                    yield break;
#else
                    NativeArray <byte> data = new NativeArray <byte>(bytes, KtxNativeInstance.defaultAllocator);

                    TextureBase textureBase = null;

                    if (mimeType == "image/ktx" || mimeType == "image/ktx2")
                    {
                        textureBase = new KtxTexture();
                    }
                    else if (mimeType == "image/basis")
                    {
                        textureBase = new BasisUniversalTexture();
                    }

                    textureBase.onTextureLoaded += (Texture2D texture, KtxUnity.TextureOrientation ktxOrientation) =>
                    {
                        orientation.IsXFlipped = ktxOrientation.IsXFlipped();
                        orientation.IsYFlipped = ktxOrientation.IsYFlipped();
                        tex = texture;

                        //Rename the texture if we have a valid path variable (not available with .glb)
                        if (!string.IsNullOrEmpty(path))
                        {
                            tex.name = Path.GetFileNameWithoutExtension(path);
                        }
                        //
                        if (tex.name == "material1_normal")
                        {
                            Debug.Log("OnTextureLoaded() " + tex.name + "[ " + tex.width + " x " + tex.height + " ] Flipped[ " + orientation.IsXFlipped + " : " + orientation.IsYFlipped + " ]");
                        }
                        //
                        loaded = true;
                    };

                    yield return(StaticCoroutine.Start(textureBase.LoadBytesRoutine(data, true)));

                    data.Dispose();
#endif
                }
                else                 //Load .jpg, .jpeg, .png textures
                {
                    orientation.IsXFlipped = false;
                    orientation.IsYFlipped = false;
                    tex.LoadImage(bytes);
                    loaded = true;
                }

                yield return(new WaitUntil(() =>
                {
                    /*
                     * if( tex.name == "material1_basecolor" )
                     *      Debug.Log( "WaitUntil() " + tex.name + "[ loaded = " + loaded + " ][ " + tex.width + " x " + tex.height + " ]" );
                     */
                    return loaded;
                }));

                if (tex != null)
                {
                    //Rename the texture if we have a valid path variable (not available with .glb)
                    if (!string.IsNullOrEmpty(path))
                    {
                        tex.name = Path.GetFileNameWithoutExtension(path);
                    }

                    /*
                     * if( tex.name == "material1_basecolor" )
                     *      Debug.Log( "OnFinish() Transcoded " + tex.name + "[" + mimeType + "][ " + bytes.Length + " ][ " + tex.width + " x " + tex.height + " ]" );
                     */
                    onFinish(tex, orientation);
                }
                else
                {
                    Debug.Log("OnFinish() Unable To Transcode " + tex.name + "[" + mimeType + "][ " + bytes.Length + " ]");
                }
            }     //END CreateTextureAsync()
Esempio n. 10
0
 public bool Equals(VideoGLTextureUploadMeta other)
 {
     return(Meta.Equals(other.Meta) && TextureOrientation.Equals(other.TextureOrientation) && NTextures.Equals(other.NTextures) && TextureType.Equals(other.TextureType));
 }