How to display texture (img) on a plane geometry #487
Replies: 5 comments 3 replies
-
https://codesandbox.io/s/r3f-basic-demo-ivguf?file=/src/index.js import * as THREE from 'three'
import ReactDOM from 'react-dom'
import React, { Suspense } from 'react'
import { Canvas, useLoader } from 'react-three-fiber'
import img from './RoNmD7W.png'
import './styles.css'
function Image() {
const texture = useLoader(THREE.TextureLoader, img)
return (
<mesh>
<planeBufferGeometry attach="geometry" args={[3, 3]} />
<meshBasicMaterial attach="material" map={texture} />
</mesh>
)
}
ReactDOM.render(
<Canvas colorManagement>
<Suspense fallback={null}>
<Image />
</Suspense>
</Canvas>,
document.getElementById('root')
) |
Beta Was this translation helpful? Give feedback.
-
@drcmda these type of questions/answers which are in theory simple enough to become part of an FAQ. I would be happy to help maintain such an FAQ format and it would allow other members of the community to also answer and self learn. Q: How to display texture (img) on a plane geometry |
Beta Was this translation helpful? Give feedback.
-
Hi @drcmda, but how can I use nested texture, like in the docs? Seems this doesn't work: |
Beta Was this translation helpful? Give feedback.
-
I want to use reusable texture component to avoid this: |
Beta Was this translation helpful? Give feedback.
-
I tried to create Image object but it also doesn't work. I compared it with image from texture and it looks the same: |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi! I only started learning react-three-fiber as of today, but I was wondering what the best way is to display an image on a plane.
Currently, I have been trying this, with
img
being assigned the URL https://i.imgur.com/RoNmD7W.png I have taken over the code that I found on the API, but perhaps I am missing something important.However, it seems to generate a random color instead of the image, not sure what I did wrong, any help is welcome!
Beta Was this translation helpful? Give feedback.
All reactions