viromedia / viro

ViroReact: AR and VR using React Native
MIT License
2.31k stars 483 forks source link

3D model is half black #985

Closed Macieyou closed 1 year ago

Macieyou commented 1 year ago

Environment

  1. Windows, Android
  2. Android
  3. ViroReact ^2.20.2, React 18.0.0
  4. Xiaomi redmi note 8 pro

Description

Hi, I am new to viroReact and have a problem with a 3D model (.obj). The model is half completely black and I don't know why. Is it related to the light I set or maybe the .obj file itself? Can someone with more experience with this library help me with this? I wish the bottom was darker but not completely black.

Screenshot_2023-02-20-15-54-56-565_com myviroapp

  ViroMaterials.createMaterials({
    uranus: {
       lightingModel: 'Blinn',
       diffuseTexture: require(`${modelPath}/uranus/uranus_2K.jpg`),
    },
  });

<ViroNode>
  <ViroSpotLight
    innerAngle={5}
    outerAngle={25}
    direction={[0, -1, -0.2]}
    position={[0, 3, 1]}
    color="#ffffff"
    castsShadow={true}
    shadowMapSize={2048}
    influenceBitMask={4}
    shadowNearZ={2}
    shadowFarZ={5}
    intensity={3500}
    shadowOpacity={0.7}
  />
  <Viro3DObject
    source={require('./uranus/uranus.obj')}
    scale={[0.04, 0.04, 0.04]}
    position={[0, 0.15, 0]}
    materials={'uranus'}
    animation={{
      name: 'rotate',
      loop: true,
      run: true,
    }}
    lightReceivingBitMask={6}
    shadowCastingBitMask={4}
    type="OBJ"
  />
  <ViroQuad
    position={[0, 0, 0]}
    rotation={[-90, 0, 0]}
    width={4}
    height={4}
    arShadowReceiver={true}
    lightReceivingBitMask={4}
  />
</ViroNode>
Macieyou commented 1 year ago

I managed to solve the problem by adding new light sources:

<ViroAmbientLight color="#ffffff" intensity={200} /> <ViroDirectionalLight color="#ffffff" direction={[0, -1, -0.2]} />

and decreasing the value of the 'lightReceivingBitMask' to 3