Forum Libraries, Components, and Plugins


The Xamarin Forums have officially moved to the new Microsoft Q&A experience. Microsoft Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

To create new threads and ask questions head over to Microsoft Q&A for .NET and get involved today.

Urhosharp Material.FromImage not woking with some jpg files

I'm using Xamarin.Forms with Urhosharp in my project. I'm tring to set a matrial from an image on a sphere, everything is OK in my Android project but in iOS project, when I set material from some jpg files it doesn't work and all I get is a black screen.

Here is the jpg that works correctly:

And here is the other one that doesn't:

This is my code:

        var scene = new Scene();

    // Node (Rotation and Position)
    var node = scene.CreateChild("room");
    node.Position = new Vector3(0, 0, 0);
    //node.Rotation = new Quaternion(10, 60, 10);

    // Model
    var modelObject = node.CreateComponent<StaticModel>();
    modelObject.Model = ResourceCache.GetModel("CustomModels/SmoothSphere.mdl");

    var zoneNode = scene.CreateChild("Zone");
    var zone = zoneNode.CreateComponent<Zone>();
    zone.SetBoundingBox(new BoundingBox(-300.0f, 300.0f));
    zone.AmbientColor = new Color(1f, 1f, 1f);

    //get image from byte[]

    //var url = "";
    //var wc = new WebClient() { Encoding = Encoding.UTF8 };

    //var mb = new MemoryBuffer(wc.DownloadData(new Uri(url)));
    var mb = new MemoryBuffer(PanoramaBuffer.PanoramaByteArray);
    var image = new Image(Context) { Name = "MyImage" };

    //or from resource

    //var image = ResourceCache.GetImage("Textures/grave.jpg");
    var isFliped = image.FlipHorizontal();
    if (!isFliped)
        throw new Exception("Unsuccessful flip");
    var m = Material.FromImage("1.jpg");
    m.SetTechnique(0, CoreAssets.Techniques.DiffNormal, 0, 0);
    m.CullMode = CullMode.Cw;
    //m.SetUVTransform(Vector2.Zero, 0, 0);

    // Camera
    var cameraNode = scene.CreateChild("camera");
    _camera = cameraNode.CreateComponent<Camera>();
    _camera.Fov = 75.8f;
    _initialZoom = _camera.Zoom;

    // Viewport
    Renderer.SetViewport(0, new Viewport(scene, _camera, null));

I already tried to change compression level, ICCC profile and ...

Best Answer


Sign In or Register to comment.