Archive 17/01/2023.

Distortion on 3d object

shahram.shobeiri

What I’m trying to do is implementing a 360 degree image viewer in Xamarin.Forms.
I’m using UrhoSharp and here are the steps of what I’ve done to view a 360 degree image:

  • Creating a 3d sphere model
  • Loading a 360 degree (Panorama) image
  • Set image as the Material of the Sphere

All the above steps are OK and I can see the flatten image from different view points but the problem is some kind of waves or distortions are in the image and the line which supposed to be straight are wavy. I don’t know what setting could solve the problem, please help.

Here is the wavy outcome:
930a2tzfg5jg
And here is my code:

private void CreateScene()
{
        // Scene
        var scene = new Scene();
        scene.CreateComponent<Octree>();


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

        // Model
        var modelObject = node.CreateComponent<StaticModel>();
        modelObject.Model = ResourceCache.GetModel("Models/Sphere.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 = "http://www.wsj.com/public/resources/media/0524yosemite_1300R.jpg";
        //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" };
        image.Load(mb);

        //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(image);
        m.SetTechnique(0, CoreAssets.Techniques.DiffNormal, 0, 0);
        m.CullMode = CullMode.Cw;
        //m.SetUVTransform(Vector2.Zero, 0, 0);
        modelObject.SetMaterial(m);

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

        // Viewport
        Renderer.SetViewport(0, new Viewport(scene, camera, null));
    }
Modanung

Hello @shahram.shobeiri and welcome. Sorry for being blunt (or rather anti-sharp), but I’m afraid these are not the UrhoSharp/Xamarin forums, this question is off-topic here.
You’re welcome, or even encouraged, to rewrite your project using Urho3D - as opposed to UrhoSharp - and ask this community for any support along the way.

Bananaft

Those are triangles linearly interpolating their UVs. You can either increase number of polygons in your sphere or generate accurate UVs in pixel shader.

shahram.shobeiri

Thanks @Bananaft, I’m completely new in Urho3D and 3D concepts, How can I increase number of polygons in my sphere?

Modanung

You’re using UrhoSharp, it is not the same as Urho3D.

Bananaft

Yeah, sphere is just a model in models folder. You have to model and export a new one. B.t.w. you can observe the same UV artifact in blender.

shahram.shobeiri

Finally my problem solved. Even though @Modanung said the topic is irrelevant to Urho3D but your response was really helpful for me.
I understood that I should increase the polygons of my sphere by creating a new model in a tool like Blender and export it to MDL format by a add-in and use the new model in my code.
Thank you very much @Bananaft and @Modanung.
Here is the outcome:

Modanung

I can’t help it. :slight_smile:

I’m glad you solved your problem and I hope the times ahead will be bearable, looking at your location.