Is there a way to configure side={THREE.BackSide} using an external .glb file?

As a beginner in Threejs, I am trying to incorporate the use of side="THREE.BackSide" with an external model file named room.glb. My development environment consists of nextjs 13 (with typescript and app directory enabled) along with @react-three/fiber and react-three/drei.

Initially, this setup worked as intended:

<Canvas>
    
  <OrbitControls enableZoom dampingFactor={0.01}/>
  <mesh scale={[1,5,9]}>
    <boxGeometry  />
    <meshStandardMaterial color="grey" side={THREE.BackSide} />
  </mesh> 
  <ambientLight intensity={1}/>
  <pointLight intensity={5} position={[10,90,0]}/>
</Canvas>

However, when I attempted to load an external file using the following code:

<Canvas>
  <OrbitControls enableZoom dampingFactor={0.009} enableRotate maxAzimuthAngle={0} maxPolarAngle={1.5} minPolarAngle={1} maxDistance={10} minAzimuthAngle={0.5}/>
  <mesh  scale={[depth/18,height/18,width/18]}>
    <primitive object={gltf.scene} ref={meshRef}/>
    <meshStandardMaterial color={"red"} side={THREE.BackSide}/>
  <ambientLight intensity={1}/>
  <pointLight intensity={5} position={[10,90,0]}/>
</Canvas>

I encountered issues and the code did not work as expected.

I attempted to convert my .glb file into JSX using the gltfjsx cli tool, but even that did not produce the desired results. I am unsure of how to iterate through all nodes and set their side prop to BackSide.

Here is my gltfjsx file:

import React, { useRef } from 'react'
import { useGLTF } from '@react-three/drei'
import { GLTF } from 'three-stdlib'

type GLTFResult = GLTF & {
  nodes: {
    Cube: THREE.Mesh
  }
  materials: {
    ['Material.001']: THREE.MeshStandardMaterial
  }
}

export function Model(props: JSX.IntrinsicElements['group']) {
  const { nodes, materials } = useGLTF('/labRoom.glb') as GLTFResult
  return (
    <group {...props} dispose={null}>
      <mesh geometry={nodes.Cube.geometry} material={materials['Material.001']} scale={[2.52, 2.64, 2.49]}/>
    </group>
  )
}

useGLTF.preload('/labRoom.glb')

Answer №1

To enhance your gltfjsx output, consider making the following modifications:

<group {...props} dispose={null}>
  <mesh geometry={nodes.Cube.geometry} 
    material={materials['Material.001']}
    material-side={THREE.BackSide}
    scale={[2.52, 2.64, 2.49]}/>
</group>

Another option is to iterate over the materials object using a loop:

for (let key in materials) {
  materials[key].side = THREE.BackSide;
}

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

Display the initial x list items without utilizing ngFor in Angular 2

In the template, there are 9 <li> elements, each with a *ngIf condition present. It is possible that 5 or more of them may return true, but the requirement is to only display the first 4 or less if needed. Priority is given to the order of the < ...

Determining if the current URL in NextJS is the homepage

Just getting started with NextJS. I am trying to determine if the current URL is the home page. When I use: import { useRouter } from "next/router"; const router = useRouter(); const is_home = (router.pathname === ''); An error pops ...

Tips for showcasing unique keywords in Ace Editor within the Angular framework

Can anyone help me with highlighting specific keywords in Angular using ace-builds? I've tried but can't seem to get it right. Here's the code snippet from my component: Check out the code on Stackblitz import { AfterViewInit, Component, ...

Customizing MUI V5 Variants

I'm having trouble customizing the variant options in MUIPaper, and I can't figure out what mistake I'm making. The available types for the component are: variant?: OverridableStringUnion<'elevation' | 'outlined', Pape ...

Dealing with website links in Next.js and Chakra-UI: Tips and Tricks

When incorporating react linkify directly with chakra-ui components such as Text, the links cannot be managed. Issue Example import Linkify from 'react-linkify'; import {Box, Text} from '@chakra-ui/react'; export default function Usag ...

Problem with Clerk's authentication() functionality

Currently facing an issue with the Clerk auth() helper (auth() documentation) while working with react and next 13 (app router). When trying to access both userId and user from auth(), const { userId, user } = auth();, it seems that userId contains a val ...

The Angular service successfully provides a value, yet it fails to appear on the webpage

Currently, I am starting to dive into Angular from the ground up. One of my recent tasks involved creating a component called 'mylink' along with a corresponding service. In my attempt to retrieve a string value from the service using 'obse ...

Oops! You can only have one parent element in JSX expressions

I'm working on creating a password input box, but I keep encountering an error when integrating it into my JS code. Here's the snippet of my code that includes TailwindCSS: function HomePage() { return ( <div> <p className=&q ...

Finding the current URL in React Router can be achieved by using specific methods and properties provided by

Currently, I'm diving into the world of react-redux with react-router. On one of my pages, it's crucial to know which page the user clicked on to be directed to this new page. Is there a method within react-router that allows me to access inform ...

Using sl-vue-tree with vue-cli3.1 on internet explorer 11

Hello, I am a Japanese individual and my proficiency in English is lacking, so please bear with me. Currently, I am using vue-cli3.1 and I am looking to incorporate the sl-vue-tree module into my project for compatibility with ie11. The documentation menti ...

Encountering difficulties retrieving records using fetch in Next.js

Recently, I have developed an API for blogs using the code snippet below: const fs = require('fs'); export default async function handler(req, res) { let blogs = []; try { let files= fs.readdirSync('blogdata'); files ...

Turning the visual world on its head: exploring the art of inverted

Need to assign the video tag material to the Mesh and achieve an inverted video effect. Previously, this area was displaying a texture with the correct orientation. Could this issue be linked to something specific? I encountered this problem when transitio ...

What is the best way to combine Bootstrap and custom CSS, specifically the home.module.css file, in a React project?

I'm currently experimenting with utilizing multiple classes to achieve an elevated button effect and a fade animation on a bootstrap card. Here's the code snippet I've been working on: import Head from 'next/head' impo ...

Achieve validation of numerous variables without the need for a string of if-else

If we have three variables, such as firstName, lastName, and email, how can we check if they are empty or not without using multiple if else blocks? let firstName = "John"; let lastName = "Doe"; let email = "john.doe@example.com"; if (firstName.trim() == ...

Inputting data types as arguments into a personalized hook

I am currently developing a Next.js application and have created a custom hook called useAxios. I am looking to implement a type assertion similar to what can be done with useState. For example: const [foo, setFoo] = useState<string>(''); ...

The function within filereader.onload is not running properly in JavaScript

When working with FileReader to read a file and convert it to base64 for further actions, I encountered an issue. Although I was able to successfully read the file and obtain its base64 representation, I faced difficulties in utilizing this data to trigger ...

Error encountered while attempting to send a delete request to MongoDB due to connection refusal

Recently, I've been diving into a Next.js tutorial that involves working with MongoDB. Everything seems to be running smoothly when testing my API endpoints with Postman. POST, GET, and DELETE requests all go through without any hiccups. However, thi ...

Sentry alert: Encountered a TypeError with the message "The function (0 , i.baggageHeaderToDynamicSamplingContext) does not

My website, which is built using Next.js and has Sentry attached to it, runs smoothly on localhost, dev, and staging environments. However, I am facing an issue when trying to run it on my main production server. The error message displayed is as follows: ...

configure redirects for specific file extensions based on regular expressions

Attempting to create a redirect rule in next.config.js to send all requests with .pdf extension to an external URL is resulting in the following error. Error encountered while parsing `/:file(.(pdf)$)` https://err.sh/vercel/next.js/invalid-route-source Rea ...

Angular 2 is throwing an error stating that the argument 'ElementRef' cannot be assigned to the parameter 'ViewContainerRef'

I'm developing an Angular 2 application with angular-cli, but when I include the following constructor, I encounter the following error: Error Argument of type 'ElementRef' is not assignable to parameter of type 'ViewContainerRef&apos ...