Skip to content

Commit

Permalink
Merge pull request #139 from M3-org/fix-shininess
Browse files Browse the repository at this point in the history
Fix shininess
  • Loading branch information
madjin authored Mar 9, 2024
2 parents bc3366c + 5a9e48d commit c374435
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions src/library/create-texture-atlas.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,14 @@ 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

texture = new THREE.DataTexture(data, width, height, THREE.RGBFormat); // Create a new texture
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();
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -363,15 +360,15 @@ 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);
break;
}
// 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);
createImageBitmap(imgData)// bmp is trasnaprent
.then((bmp) => context.drawImage(bmp, min.x * ATLAS_SIZE_PX, min.y * ATLAS_SIZE_PX, xTileSize, yTileSize));
}
Expand Down

0 comments on commit c374435

Please sign in to comment.