Expo-three is experiencing an issue with its lights not functioning properly in threejs

Seeking assistance: I recently discovered the compatibility of the ThreeJS library with react-native, which is truly remarkable! After conducting a small experiment, I encountered some issues with the lighting. Unfortunately, I am unable to modify the lights within the project, as it only features default ambient lighting. Is there anyone out there who can guide me on resolving this matter?

Here is the code snippet:

import React from 'react';
import { View, Text, StyleSheet } from 'react-native';
import Expo from 'expo';
import {Scene, Mesh, MeshBasicMaterial, PerspectiveCamera, BoxBufferGeometry} from 'three';
import ExpoTHREE, {THREE, Renderer} from 'expo-three';
import {ExpoWebGLRenderingContext, GLView} from 'expo-gl';

interface CanvasProps{
  width: number;
  height: number;
}

interface Props extends ExpoWebGLRenderingContext{
  canvas: CanvasProps;
}

export default function App(){

  async function onContextCreate(gl: Props){
    //THREE.js code
    const scene = new Scene();
    const camera = new PerspectiveCamera(
      75,
      gl.drawingBufferWidth/gl.drawingBufferHeight,
      0.1,
      1000
    );

    gl.canvas = {width: gl.drawingBufferWidth, height: gl.drawingBufferHeight}
    camera.position.z = 2;

    const renderer = new Renderer({gl});
    renderer.setSize(gl.drawingBufferWidth, gl.drawingBufferHeight);

    const geometry =  new BoxBufferGeometry(1, 1, 1);
    const material = new MeshBasicMaterial({
      color: 'blue'
    });
    const cube = new Mesh(geometry, material);
    scene.add(cube);

    function render(){
      requestAnimationFrame(render);
      if(cube.rotation.x <= 12.555){
        cube.rotation.x += 0.01;
      }else{
        cube.rotation.x = 0;
      }

      if(cube.rotation.y <= 12.555){
        cube.rotation.y += 0.01;
      }else{
        cube.rotation.y = 0;
      }

      renderer.render(scene, camera);
      gl.endFrameEXP();
    }

    render();
  } 
  
  return (
    <View style={styles.container}>
      <GLView 
        onContextCreate={onContextCreate}
        style={styles.GLView}
      />
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center'
  },
  GLView: {
    width: 500,
    height: 500
  }
});

Github Repository: https://github.com/jnunes-ds/3d-app/

Answer №1

Utilizing MeshBasicMaterial in your code example results in a material that does not interact with lights, known as an unlit material. Consider using a different material such as MeshStandardMaterial.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Using TypeScript to access global variables from inside a method

Hi everyone, I'm trying to figure out how to access variables from the global scope (this) within 2 methods. Any help would be greatly appreciated. location: any; doSomethingOne() { Geolocation.getCurrentPosition().then((resp) => { ...

the ng-repeat directive disables input controls within the tfoot

When working with JSON data, I encountered a situation where I needed to display different types of student details in a table. For one specific type of student, namely partners, I wanted to include input controls such as checkboxes and buttons. However, e ...

Fetch a single random profile image from a Facebook user's list of friends using Javascript

I'm currently facing an issue with displaying a random profile picture of the user's friends on Facebook. I attempted to troubleshoot it myself but ended up crashing the login button and now it's not functioning properly. Can someone please ...

Using html data attributes to encode JSON data with strings

Looking for a way to pass data to JavaScript, I decided to create a template tag as shown below: from django.utils.safestring import mark_safe from django import template import json register = template.Library() @register.simple_tag def mydata(): r ...

Content is missing from the response of the AngularJS $http request

Attempting to retrieve content from a website using Angular's $http service. The request seems to be successful as console.log(response.data) displays most of the content but is missing some parts. Check out my code below: $http = angular.element(doc ...

Printing dynamic data

When the print button is clicked, I need to print dynamically generated data from a table that has an ID. The table data (td and tr) is dynamically generated. I have successfully retrieved the table data and attempted to print everything using window.prin ...

Updating individual items in the Redux state while displaying the previous version

I'm facing an issue with updating the reducer for my items (icdCode) in my array (icdCodes) within a React component. The update works only after reloading the entire component, which is not ideal. Initially, I had to deal with a duplicate key problem ...

Tips for updating multiple documents in a MongoDB database using an array of values

I have a range of Product items in my inventory and when a client places an Order, they submit an array of objects. Each object in the array includes the _id product (objectId) and the quantity they purchased. [ {producId: "dshsdsdh72382377923", quantity: ...

What is the most effective approach for revealing AngularJS controller methods in TypeScript?

I have been exploring a way to attach the controller object to the scope in a different manner. Here is an example of how it can be achieved. interface IAppCtrlScope extends ng.IScope { info: any; } class InfoCtrl { header: string; name: strin ...

Creating a custom autocomplete search using Angular's pipes and input

Trying to implement an autocomplete input feature for any field value, I decided to create a custom pipe for this purpose. One challenge I'm facing is how to connect the component displaying my JSON data with the component housing the autocomplete in ...

Problem with camera rotation while loading 3D objects in three.js at the beginning

Looking to rotate the camera when loading objects in Three.js. Can anyone provide guidance on the best approach for this? Would using a Perspective Camera be a good option? For some inspiration, check out ...

Utilizing JavaScript to Load an HTML File in a Django Web Development Project

Having a django template, I aim to load an html file into a div based on the value of a select box. The specific target div is shown below: <table id="template" class="table"> Where tables are loaded. </table> There ex ...

Illustrating a fresh DOM element with intro.js

I am currently utilizing intro.js to create a virtual 'tour' for my website. As I aim to provide a highly interactive experience for users, I have enabled the ability for them to engage with highlighted DOM elements at different points in the tou ...

Restrict the number of dynamic form elements to a maximum of 10 entries

I am working on a feature where users can refer their friends and the data will be saved in a database. <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <script type='text/javascript' sr ...

The LoopBack framework encountered an issue where it could not execute the 'post' method due to being undefined

As a newcomer to loopback and node.js, I have successfully created two models - Rating and RatingsAggregate. Utilizing the loopback explorer, querying and posting against the API has been smooth. In an attempt to establish basic business logic, I am curre ...

JS: I'm struggling to understand the scope

I've been working on adapting CouchDB's JS API to function asynchronously, but I'm encountering an unresolved error: You can find my version of the JS API here on Pastebin. Whenever I execute (new CouchDB("dbname")).allDocs(function(result) ...

Updating data from an ajax call in chart.js can be done with a few simple steps

I have successfully generated a graph using data from an ajax call in a php file. Now, I want to enhance this graph by allowing users to select a specific customer from a drop-down list (chg_customer) and display the corresponding count on the chart. Altho ...

Having trouble getting the expected transition effects to work with Vue.js

Currently, I have a display of lists of items through the use of v-for. Initially, only the summary section of each item is visible. Upon clicking on an item, the details section is supposed to appear. This functionality is achieved by adding or removing ...

"Applying CSS styles to highlighted text using jQuery - how can I do it

Struggling to style selected text with CSS? Here's what I've tried so far without success in Firefox. $(document).keyup(function(){ savedRange = selection.getRangeAt(0); $(savedRange).wrap('<span style="color:red"></span>' ...

The Chrome browser's memory heap is reported to be a mere 10 MB, yet the task manager displays a whopping

When using Chrome's memory profiler, I notice that the heap size is always around 10 MB. However, the memory in my task manager keeps increasing and can reach over 1 GB if I leave my website running. Even though the heap size remains less than 10 MB w ...