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.

Replacing textures rather than materials

Home Forums Puzzles Replacing textures rather than materials

Viewing 15 posts - 16 through 30 (of 77 total)
  • Author
    Posts
  • #3273
    johngrigni
    Customer

    OK, so I got them to load, from the icons, but the UV problem is still there.

    #3278

    Hi,
    if you try to assign a texture in Blender, does it properly UVmapped?

    Chief 3D Verger | LinkedIn | Twitter

    #3287
    johngrigni
    Customer

    Yes, the starting cube is UV unwrapped, and both textures in the material are assigned UV. The cube comes through fine when you launch it, but when you click an icon to load a texture (either diffuse or normal), it’s like the material just forgets the UV mapping for both.

    #3307

    Can you please attach the project? We’d like to take a deeper look into this issue.

    Chief 3D Verger | LinkedIn | Twitter

    #3309
    johngrigni
    Customer

    Here is a zip of the folder from the application folder

    #3312
    johngrigni
    Customer

    And I’d like to say thank you for this help. I’m trying to get a client interested, and this is a requirement of the project.

    #3319

    No worries. I was able to make it work by creating a new cube from scratch. I still don’t understand the reason why it doesn’t work in your case :scratch:

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

    Chief 3D Verger | LinkedIn | Twitter

    #3321
    johngrigni
    Customer

    I have a theory, looking at your UV map and mine – mine extends past the edges of the ‘live area’ – which is not a problem in Blender since it just wraps around. Just a guess, and thank you very much! That was driving me nuts!

    #3322

    I think I figured it out – instead of creating a new texture, we can simply replace its image:

    
    function prepareExternalInterface(app) {
        // register functions in the app.ExternalInterface to call them from Puzzles, e.g:
        // app.ExternalInterface.myJSFunction = function() {
        //     console.log('Hello, World!');
        // }
    	app.ExternalInterface.changeTexture = function(objName, diffuseURL, normalURL) {
            app.scene.traverse(function(obj){
                if (obj.name == objName) {
    
                    var loader = new v3d.ImageLoader();
                    loader.load(diffuseURL, function(image) { 
                        obj.material.map.image = image;
                        obj.material.map.needsUpdate = true;
                    })
                    loader.load(normalURL, function(image) { 
                        obj.material.normalMap.image = image;
                        obj.material.normalMap.needsUpdate = true;
                    })      
                }
            });
        }
    }
    

    It now works! :)

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

    Chief 3D Verger | LinkedIn | Twitter

    #3396
    johngrigni
    Customer

    I’ve run into a problem, in that this changes the texture for every object in the scene that uses that texture, even if it has a different material. I plan to have at least 5 objects that would be swappable, do I need five different versions of each texture? I thought the objName parameter would mean that it only gets swapped for that object, as opposed to across the scene.

    In the example, even the leftmost icons get the texture swapped out for the monkey head or gradient, though the other icons don’t.

    #3397

    Hi,
    You can avoid this behavior by unsharing an image in Blender: just click the numbered button to make a copy.

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

    Chief 3D Verger | LinkedIn | Twitter

    #3400
    johngrigni
    Customer

    I thought it might be that simple! Thank you. But now I’m up against a different question:

    Let’s say the user has set the diffuse texture of several objects:
    1 – blue/monkey
    2 – green/monkey
    3 – red/monkey

    The variable for the diffuse texture is still the last one set, ‘red’, so if I go to change the normal texture of object 1 to ‘torus’, it will set the diffuse to ‘red’, so I get red/torus when I want it to be blue/torus.

    I’m thinking the simplest solution is to separate the diffuse and normal changeTexture into separate functions: changeDiffuse and changeNormal, and simply delete the part that changes the other image in each one.

    Alternately, when I select the object, have it reset the diffuse and normal variables to whatever the current values are for the object. But I’m not sure how to get that value out of the object, so I’m leaning towards the first one.

    What would you suggest?

    #3403

    Yep, the first way looks more optimal since it touches just one texture.

    Chief 3D Verger | LinkedIn | Twitter

    #3404
    johngrigni
    Customer

    I went ahead with that, and it seems to work. Given that I’m still very much a noob with coding, I’m feeling very good about myself for making it work. Thanks again for all your help!

    #3405

    Sure. Glad you enjoy Verge3D! :)

    Chief 3D Verger | LinkedIn | Twitter

Viewing 15 posts - 16 through 30 (of 77 total)
  • You must be logged in to reply to this topic.