Data used as texture for a Plane #626
Replies: 2 comments 2 replies
-
i have never used them but if that's what the material takes, then yes, you do it in the exact way you'd do it in plain three. the only thing that's wrong here is that you create objects smack in the middle of the render function, so they will re-instanciate on every render. always memoize, or useState for statics: // static
const [foo] = useState(() => new Foo())
// memoized constructor args
const bar = useMemo(() => new Bar(xyz), [xyz]) |
Beta Was this translation helpful? Give feedback.
-
Hey Again, Just to extend this query further after running some tests. I now have the Note: the canvas does resize as well, whether this makes a difference import React, {useState, useContext, useEffect, useMemo} from "react";
import Context from "context";
import * as THREE from 'three'
import { Canvas } from 'react-three-fiber'
let canvas_x = 1920;
let canvas_y = 1080;
const VideoBufferDisplay = () => {
const [buffer, setBuffer] = useState(()=>new Uint8Array(canvas_x * canvas_y));
const texture = useMemo(() => new THREE.DataTexture(buffer, canvas_x, canvas_y, THREE.RGBAFormat,THREE.UnsignedByteType), [buffer, canvas_x, canvas_x]);
const [{incomingBuffer}, dispatch] = useContext(Context);
useEffect(() =>{
texture.magFilter = THREE.NearestFilter;
texture.minFilter = THREE.NearestFilter;
texture.needsUpdate = true;
},[])
useEffect(() => {
setInterval(() =>{
setIpcBuffer(incomingBuffer.readBuffer(canvas_x, canvas_y));
}, 40);
}, [incomingBuffer])
return (
<Canvas id="videoCanvas" }>
<ambientLight />
<mesh position={[0,0,0]} scale={[1, -1, 1]}>
<planeBufferGeometry attach="geometry" args={[16, 9, 1]} />
<meshBasicMaterial attach="material" map={texture} />
</mesh>
</Canvas>
)
} |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
How would I load a Uint8Array of data into a texture to use on a plane? I believe I need to use a DataTexture in order to do this but I seem to just get a black rectangle.
So far I am doing something like this.. am I missing something? I tried using lighting also but still just a black plane. I have checked the dataTexture and there is valid data inside.
Beta Was this translation helpful? Give feedback.
All reactions