project_threejs_ai icon indicating copy to clipboard operation
project_threejs_ai copied to clipboard

This is how to fix the issue with T-shirt color

Open r4dhwene opened this issue 1 year ago • 5 comments

Hello,

For those who have a problem with the T-shirt color pick up that doesn't change, the issue is coming from the T-shirt material. The aoMapIntensity (Ambient Occlusion Map Intensity) property controls the intensity of the ambient occlusion map (AO map) applied to the material. You can check it by console.log(materials.lambert1);

When aoMapIntensity is set to 1 (the default), ambient occlusion is applied with maximum intensity, which can result in more pronounced shadows and darker areas on the material.

Setting aoMapIntensity to 0 disables the ambient occlusion effect on the material, which can make the color more uniform and prevent soft shadows from applying.

Here is the Shirt convas updated :

import React, { useRef } from 'react';
import { easing } from 'maath';
import { useSnapshot } from 'valtio';
import { useFrame } from '@react-three/fiber';
import { Decal, useGLTF, useTexture } from '@react-three/drei';

import state from '../store';

const Shirt = () => {
  const snap = useSnapshot(state);
  const { nodes, materials } = useGLTF('/shirt_baked.glb');

// I added a reference "meshRef" to the mesh component that represents the t-shirt material

  const meshRef = useRef();

  const logoTexture = useTexture(snap.logoDecal);
  const fullTexture = useTexture(snap.fullDecal);

  useFrame((state, delta) => {
      easing.dampC(materials.lambert1.color, snap.color, 0.25, delta);
  
        // update the color to the material
      meshRef.current.material.color = materials.lambert1.color;
      meshRef.current.material.needsUpdate = true;

       // Set aoMapIntensity to 0
      materials.lambert1.aoMapIntensity=0;

    });

  const stateString = JSON.stringify(snap);

  return (
    <group>
      <mesh
        ref={meshRef}
        castShadow
        geometry={nodes.T_Shirt_male.geometry}
        material={materials.lambert1}
        material-roughness={1}
        dispose={null}
      >

    // add the other properties
     
        )}
      </mesh>
    </group>
  )
}

export default Shirt

By changing aoMapIntensity to 0, you will able to resolve the color picking issue, as ambient occlusion no longer interfered with the color applied to the material.

r4dhwene avatar Jun 22 '23 08:06 r4dhwene

As soon as i click on ai full or ai logo button my screen goes white and i can see errors on the server terminal and even in inspect console. Screenshot (8) ![Screenshot (9)](https://github.com/adrianhajdin/project_threejs_ai/assets/115602871/712d6f9b-014d-4565-a1fd Screenshot (10) -8d91beeafb68) Screenshot (11) Can someone please help me out with this....?

pradeepthsjain avatar Jun 22 '23 15:06 pradeepthsjain

You ur Api free trial of openai is expired, you need to subcribe to use the Api.

r4dhwene avatar Jun 22 '23 17:06 r4dhwene

Thanks @r4dhwene,

I tried your solution and it works now 👍

fsalasc avatar Jul 07 '23 00:07 fsalasc

Thank you so much!

tardigrade34 avatar Jul 17 '23 23:07 tardigrade34

Hi @r4dhwene, can I ask you a question? I want to make a t-shirt that can be viewed in 3D or 360 degrees. How can I do that?

xiaoxiaolexlh avatar Jul 09 '24 02:07 xiaoxiaolexlh