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 - 31 through 45 (of 77 total)
  • Author
    Posts
  • #4196
    Dzynek
    Participant

    Hi

    I tried to add a preloader function (ATI2.js, line 130) but unfortunately it does not work

    var loader = new v3d.ImageLoader();				
                    loader.load(
    			diffuseURL,
    			function(image) {
    				obj.material.map.image = image; 
    				obj.material.map.needsUpdate = true;						
    			},
    			function ( xht ) {
    				console.log( (xht.loaded / xht.total * 100) + '% loaded' );						
    			},
    			function ( xhr ) {
    				console.log( 'An error happened' );
    					}
    			)
    #4198
    Dzynek
    Participant

    I forgot to add a file

    #4203

    I did some searching and it appears that progress event handler is currently disabled for ImageLoader.

    https://github.com/mrdoob/three.js/issues/10439

    There are some suggestion how to work around this in that Github thread. Another approach can be simply showing some animated .gif while it loads.

    Chief 3D Verger | LinkedIn | Twitter

    #4206
    johngrigni
    Customer

    It’s me again, and I tried copying the script over to a new version of the same project and I keep getting this error when I try to call the function:

    [Error] TypeError: null is not an object (evaluating ‘obj.material.map.image = image’)
    (anonymous function) (ATI_Lobby.js:131)
    (anonymous function) (v3d.js:1:517256)

    As far as I know I’m doing the exact same thing as before. Here is the function in ATI_Lobby.js:

    app.ExternalInterface.changeDiffuse = function(objName, diffuseURL) {
    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;
    })
    }
    });
    }

    #4210
    johngrigni
    Customer

    Scratch that, I figured it out. I had made an error applying textures in the Blend file.

    #4212
    Dzynek
    Participant

    Thank you for the answer :)

    I inserting this function at the beginning document ATI2.js:

    // preloader ImageLoader() fix
    THREE.ImageLoader.prototype = {
    load: function ( url, onLoad, onProgress, onError ) {
        var scope = this;
        var image = document.createElementNS( 'http://www.w3.org/1999/xhtml', 'img' );
        image.onload = function () {
            image.onload = null;
            URL.revokeObjectURL( image.src );
            if ( onLoad ) onLoad( image );
            scope.manager.itemEnd( url );
        };
        image.onerror = onError;
        var loader = new THREE.FileLoader();
        loader.setPath( this.path );
        loader.setResponseType( 'blob' );
        loader.setWithCredentials( this.withCredentials );
        loader.load( url, function ( blob ) {
            image.src = URL.createObjectURL( blob );
        }, onProgress, onError );
        scope.manager.itemStart( url );
        return image;
    	},
    	setCrossOrigin: function ( value ) {
    		this.crossOrigin = value;
    		return this;
    	},
    	setWithCredentials: function ( value ) {
    		this.withCredentials = value;
    		return this;
    	},
    	setPath: function ( value ) {
    		this.path = value;
    		return this;
    	}
    }

    Preloader work but, there was a problem when the image does not have time to load and (fast) hits the button again :-(

    I would be grateful for the solution

    I attach an example

    #4231

    Scratch that, I figured it out. I had made an error applying textures in the Blend file.

    :good:

    Chief 3D Verger | LinkedIn | Twitter

    #4232

    Preloader work but, there was a problem when the image does not have time to load and (fast) hits the button again

    I downloaded your example. What button should I click in order to manifest this issue?

    Chief 3D Verger | LinkedIn | Twitter

    #4233
    Dzynek
    Participant

    instruction in picture

    #4235
    Dzynek
    Participant

    I suspect that this function
    File ATI2.js line 172-175

    function (xhr ) {
        var xSize= (xhr.loaded / xhr.total) ;						 
        app.ExternalInterface.showMyPreloader(xSize);						
    },

    repeats at the same time, i think :scratch:

    I need to stop charging early unfinished Loads

    #4237
    Dzynek
    Participant

    I did it differently and it works :)

    I submit a working project

    Thank and best regards

    #4240

    Great you worked it out! :good:

    Chief 3D Verger | LinkedIn | Twitter

    #4584
    johngrigni
    Customer

    Is there a way to modify this to work with PBR textures? I tried it as is and it doesn’t work. Perhaps normal and diffuse textures are treated differently in PBR? Again, thanks for an excellent program.

    #4591

    Is there a way to modify this to work with PBR textures?

    Hi, it works for me, I tested it with a pbr material from the sdk’s Pbr demo. I attached the modified example.

    Co-founder and lead developer at Soft8Soft.

    #4592
    johngrigni
    Customer

    I’m not seeing an attachment, but I’ll try it again.

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