src/index.js
// expensive work of uploading a texture to the GPU off the main thread.
expensive work of uploading a texture to the GPU off the main thread.
expensive work of uploading a texture to the GPU off the main thread .
function workerTextureRight() {
  if (activeWorkerTexture) {
    clearInterval(activeWorkerTexture);
    activeWorkerTexture = null;
    if (!!workerTextureParams.worker) {
      workerTextureParams.worker.terminate();
      workerTextureParams.worker = null;
    }
  } else {
    if (!workerTextureParams.worker && workerTextureParams.enableWorker) {
      workerTextureParams.worker = new Worker("./workers/texture.worker.js");
      workerTextureParams.worker.addEventListener(
        "message",
        function (message) {
          console.log("WebW Texture Message", message.data);
          if (!message.data.error) {
            if (message.data.action === "init") {
              workerTextureParams.initWorker = true;
            }
            if (message.data.action === "load") {
              plane1.material.map = new THREE.CanvasTexture(
                message.data.imageBitmap
              );
              plane1.material.needsUpdate = true;
            }
          } else {
            alert("Worker Texture Error " + message.data.error);
          }
        }
      );
      workerTextureParams.worker.postMessage({
        id: "init",
        action: "init",
        options: { imageOrientation: "flipY" },
      });
    }
    if (!workerTextureParams.fallback && !workerTextureParams.enableWorker) {
      workerTextureParams.fallback = new THREE.TextureLoader();
    }
    activeWorkerTexture = setInterval(() => {
      const counterTmp = workerTextureParams.counter++;
      const url =
        "https://dummyimage.com/2048x2048/db1cdb/000000.png&text=" + counterTmp;
      if (workerTextureParams.enableWorker) {
        if (workerTextureParams.initWorker) {
          workerTextureParams.worker.postMessage({
            id: counterTmp,
            action: "load",
            url: url,
          });
        }
      } else {
        workerTextureParams.fallback.load(url, (texture) => {
          plane1.material.map = texture;
          plane1.material.needsUpdate = true;
        });
      }
    }, workerTextureParams.intervalTime);
  }
}
function workerTextureRight ( ) { if ( activeWorkerTexture ) { clearInterval ( activeWorkerTexture ) ; activeWorkerTexture = null ; if ( ! ! workerTextureParams . worker ) { workerTextureParams . worker . terminate ( ) ; workerTextureParams . worker = null ; } } else { if ( ! workerTextureParams . worker && workerTextureParams . enableWorker ) { workerTextureParams . worker = new Worker ( "./workers/texture.worker.js" ) ; workerTextureParams . worker . addEventListener ( "message" , function ( message ) { console . log ( "WebW Texture Message" , message . data ) ; if ( ! message . data . error ) { if ( message . data . action === "init" ) { workerTextureParams . initWorker = true ; } if ( message . data . action === "load" ) { plane1 . material . map = new THREE . CanvasTexture ( message . data . imageBitmap ) ; plane1 . material . needsUpdate = true ; } } else { alert ( "Worker Texture Error " + message . data . error ) ; } } ) ; workerTextureParams . worker . postMessage ( { id : "init" , action : "init" , options : { imageOrientation : "flipY" } , } ) ; } if ( ! workerTextureParams . fallback && ! workerTextureParams . enableWorker ) { workerTextureParams . fallback = new THREE . TextureLoader ( ) ; } activeWorkerTexture = setInterval ( ( ) => { const counterTmp = workerTextureParams . counter ++ ; const url = "https://dummyimage.com/2048x2048/db1cdb/000000.png&text=" + counterTmp ; if ( workerTextureParams . enableWorker ) { if ( workerTextureParams . initWorker ) { workerTextureParams . worker . postMessage ( { id : counterTmp , action : "load" , url : url , } ) ; } } else { workerTextureParams . fallback . load ( url , ( texture ) => { plane1 . material . map = texture ; plane1 . material . needsUpdate = true ; } ) ; } } , workerTextureParams . intervalTime ) ; } }
expensive work of uploading a texture to the GPU off the main thread.
expensive work of uploading a texture to the GPU off the main thread .