From b81f60f1039ac53fe26f285150fec04af5f7de17 Mon Sep 17 00:00:00 2001 From: memelotsqui Date: Fri, 8 Mar 2024 12:28:06 -0600 Subject: [PATCH 1/2] set non transparent texture --- src/library/create-texture-atlas.js | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/library/create-texture-atlas.js b/src/library/create-texture-atlas.js index 378cfb89..d90c690b 100644 --- a/src/library/create-texture-atlas.js +++ b/src/library/create-texture-atlas.js @@ -9,6 +9,7 @@ function ResetRenderTextureContainer(){ } function RenderTextureImageData(texture, multiplyColor, clearColor, width, height, isTransparent) { + // if texture is nuill, create a texture only with clearColor (that is color type) if (texture == null) { const data = new Uint8Array([clearColor.r * 255, clearColor.g * 255, clearColor.b * 255]); // Convert color to Uint8Array @@ -16,9 +17,6 @@ function RenderTextureImageData(texture, multiplyColor, clearColor, width, heigh texture.needsUpdate = true; // Make sure to update the texture } - - - // if texture is nuill, create a texture only with clearColor (that is color type) if (container == null) { container = document.createElement("div"); sceneRTT = new THREE.Scene(); @@ -258,7 +256,6 @@ export const createTextureAtlasBrowser = async ({ backColor, meshes, atlasSize, if (mtoon && vrmMaterial == null && material.type == "ShaderMaterial") { vrmMaterial = material.clone(); } - // check if bakeObjects objects that contain the material property with value of mesh.material let bakeObject = bakeObjects.find((bakeObject) => { bakeObject.material === material; @@ -275,7 +272,7 @@ export const createTextureAtlasBrowser = async ({ backColor, meshes, atlasSize, // create the canvas to draw textures //transparent: (name == "diffuse" && drawTransparent) const contexts = Object.fromEntries( - IMAGE_NAMES.map((name) => [name, createContext({ width: ATLAS_SIZE_PX, height: ATLAS_SIZE_PX, transparent:transparentTexture })]) + IMAGE_NAMES.map((name) => [name, createContext({ width: ATLAS_SIZE_PX, height: ATLAS_SIZE_PX, transparent:transparentTexture && name == "diffuse" })]) ); const numTiles = Math.floor(Math.sqrt(meshes.length) + 1); @@ -363,7 +360,7 @@ export const createTextureAtlasBrowser = async ({ backColor, meshes, atlasSize, clearColor = new THREE.Color(0x8080ff); break; case 'orm': - clearColor = new THREE.Color(material.aoMapIntensity, material.roughness, material.metalness); + clearColor = new THREE.Color(0, material.roughness, material.metalness); break; default: clearColor = new THREE.Color(1, 1, 1); @@ -371,7 +368,7 @@ export const createTextureAtlasBrowser = async ({ backColor, meshes, atlasSize, } // iterate through imageToMaterialMapping[name] and find the first image that is not null let texture = getTexture(material, imageToMaterialMapping[name].find((textureName) => getTextureImage(material, textureName))); - const imgData = RenderTextureImageData(texture, multiplyColor, clearColor, ATLAS_SIZE_PX, ATLAS_SIZE_PX,transparentTexture); + const imgData = RenderTextureImageData(texture, multiplyColor, clearColor, ATLAS_SIZE_PX, ATLAS_SIZE_PX, name == 'diffuse' && transparentTexture, name == 'orm'); createImageBitmap(imgData)// bmp is trasnaprent .then((bmp) => context.drawImage(bmp, min.x * ATLAS_SIZE_PX, min.y * ATLAS_SIZE_PX, xTileSize, yTileSize)); } From 5a9e48d6aa704f375e266385b3885c7b25fabe11 Mon Sep 17 00:00:00 2001 From: memelotsqui Date: Fri, 8 Mar 2024 12:29:36 -0600 Subject: [PATCH 2/2] remove debug code --- src/library/create-texture-atlas.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/library/create-texture-atlas.js b/src/library/create-texture-atlas.js index d90c690b..bcc1db5a 100644 --- a/src/library/create-texture-atlas.js +++ b/src/library/create-texture-atlas.js @@ -368,7 +368,7 @@ export const createTextureAtlasBrowser = async ({ backColor, meshes, atlasSize, } // iterate through imageToMaterialMapping[name] and find the first image that is not null let texture = getTexture(material, imageToMaterialMapping[name].find((textureName) => getTextureImage(material, textureName))); - const imgData = RenderTextureImageData(texture, multiplyColor, clearColor, ATLAS_SIZE_PX, ATLAS_SIZE_PX, name == 'diffuse' && transparentTexture, name == 'orm'); + const imgData = RenderTextureImageData(texture, multiplyColor, clearColor, ATLAS_SIZE_PX, ATLAS_SIZE_PX, name == 'diffuse' && transparentTexture); createImageBitmap(imgData)// bmp is trasnaprent .then((bmp) => context.drawImage(bmp, min.x * ATLAS_SIZE_PX, min.y * ATLAS_SIZE_PX, xTileSize, yTileSize)); }