We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with it.

Real-Time UV mapping from html5 canvas (Fabric.js)

Home Forums Programming Real-Time UV mapping from html5 canvas (Fabric.js)

Viewing 13 posts - 1 through 13 (of 13 total)
  • Author
    Posts
  • #11687
    go4site
    Customer

    Hi,
    I am working on a packaging designer tool.
    Idea is to make a graphic editor (See attached picture) where user can upload their artwork on a 2d plane.
    Would appreciate if you please put me in the right direction and answer below:
    1. How to UV MAP a texture from an updated image in real time? I want users to place their artwork on a 2d plane (Fabric canvas) and all the images should be textured on the box w.r.t UV mapping. (Please see attached pic, on the left some guides are given to show top, bottom, right and left sides of the box). Any change due to scale, rotate or position should be updated to 3d model in real time.
    2. How can user export/save their final scene as pdf(interactive)?

    Thanks in advance!

    • This topic was modified 2 years, 8 months ago by go4site.
    • This topic was modified 2 years, 8 months ago by go4site.
    Attachments:
    You must be logged in to view attached files.
    #11697

    Hi,

    You can modify the UV coordinates in real time using the following setup:

    Add in the Math node will shift the UV, Multiply will scale it, Sine and Cosine can be used to rotate it.

    The Value node can be modified via set value puzzle.

    UPDATE: if you’re using Fabric.js library, you can just unwrap you model and the library will do for you all the operations described above.

    Attachments:
    You must be logged in to view attached files.

    3D Verger, the CEO
    LinkedIn | FB | Twitter | VK | 新浪微博

    #11700

    How can user export/save their final scene as pdf(interactive)?

    There is no direct export. I suppose you need to find proper converters from either of export formats available in Verge3D, to u3d format.

    3D Verger, the CEO
    LinkedIn | FB | Twitter | VK | 新浪微博

    #11706
    go4site
    Customer

    Thanks for the prompt response.
    I think fabric.js is a better choice in terms of already available functionality within it, especially because I want to keep configurator/editor seperate from the v3d app.

    Looking at this test app https://www.soft8soft.com/topic/replacing-textures-rather-than-materials/page/5/#post-8814

    I want to try something similar but with below difference:

    1. Update changes from fabric canvas to the 3d model in real time (Not on click)

    Could you please help with a sample code/puzzle implementation to achieve this?

    Thanks again!

    #11738
    #13622
    go4site
    Customer

    Hi Yuri,

    Is it possible to load mulitple scenes sharing same object. Idea is to work/customize a model in one scene and at the same time it should update linked object in other scene.
    For example, in blender we can add a new scene with linked object.
    So, can we display two scenes at the same time using puzzle?

    Thanks

    #13629

    Hi,

    You can try using multiple canvases (only with code) as in these examples

    https://cdn.soft8soft.com/demo/examples/index.html?q=multiple#webgl_multiple_elements

    3D Verger, the CEO
    LinkedIn | FB | Twitter | VK | 新浪微博

    #14684
    go4site
    Customer

    Hi Yuri,

    I have been trying long to get it done but still failed to do so.
    Would appreciate if you please help regarding below:

    1. Fabric Canvas to 3d model
    As of now, I am able to apply material from fabric canvas by using below code in my app’s .js run code block. Problem is that it is only running once. If I change anything on the fabric canvas it does not update on 3d side in real-time.

    function runCode(app) {
        // add your code here, e.g. console.log('Hello, World!');
    
        var box, fabric_canvas, texture, material
        fabric_canvas = parent.document.getElementById('ib_main_canvas');
        box = app.scene.getObjectByName('outer_cover');
        texture = new v3d.CanvasTexture(fabric_canvas);
        texture.minFilter = v3d.LinearFilter;
        texture.format = v3d.RGBAFormat;
        texture.anisotropy = 16;
        material = new v3d.MeshBasicMaterial({ map: texture });
        box.material = material;
        box.material.map.needsUpdate = true;
        app.animate();
    }

    2. Direction/face of applied material

    If you see attached picture. Applied material is shown in opposite direction (Inverted inside).

    Thanks!

    • This reply was modified 2 years, 5 months ago by go4site.
    Attachments:
    You must be logged in to view attached files.
    #14687

    Hi,

    Problem is that it is only running once.

    you can add this code inside an externally registered function (according to method #2), and call it every time you need it to be called.

    Direction/face of applied material

    you can try scaling (by factor -1) or rotating your canvas to make it right

    3D Verger, the CEO
    LinkedIn | FB | Twitter | VK | 新浪微博

    #14698
    go4site
    Customer

    you can add this code inside an externally registered function (according to method #2), and call it every time you need it to be called.

    I already tried by putting it in external interface. Function is available in puzzles and can be triggered with user interaction.
    But this function is not available outside of the puzzles.

    Is there any way to call it from outside? Like from my fabric UI JS file where I am dealing with fabric canvas?

    Direction/face of applied material

    you can try scaling (by factor -1) or rotating your canvas to make it right

    I think I could not explain it properly. Problem is with the orientation (flip) of the texture. If you try to read text on both sides. You will see the difference.

    • This reply was modified 2 years, 5 months ago by go4site.
    • This reply was modified 2 years, 5 months ago by go4site.
    #14708

    Is there any way to call it from outside? Like from my fabric UI JS file where I am dealing with fabric canvas?

    you can make the app namespace global as follows:
    window.app = app;
    and the ExternalInterface functions it will be available for calling from outside

    Problem is with the orientation (flip) of the texture.

    check out this possible solution
    https://stackoverflow.com/questions/29974578/how-to-flip-a-three-js-texture-horizontally

    3D Verger, the CEO
    LinkedIn | FB | Twitter | VK | 新浪微博

    #14726
    nick
    Participant

    Hi,

    i’ve exprimented with canvas.js and verge3d before, no expert at it though.
    you could try the following to fix the flipping of the texture, worked for me.

    var texture = new v3d.CanvasTexture(fabric_canvas);
     texture.flipY = false;

    as for the texture not updating, this code might fix the problem

    fabric_canvas.on("after:render", function() {
         box.material.map.needsUpdate = true;
     });

    kind regards,
    Nick

    #14728
    go4site
    Customer

    Hi Yuri,
    Thanks. I will give try to global namespace.

    Hi Nick,
    Really appreciate your help. Yes, I was able to fix flipping issue by using texture.flipY = false; just a moment before seeing your post… :)

    fabric_canvas.on("after:render", function() {
         box.material.map.needsUpdate = true;
     });

    Let me give it a try and let you know with the result.

    Thanks again!

Viewing 13 posts - 1 through 13 (of 13 total)
  • You must be logged in to reply to this topic.