Hi, guys.
I have already asked this question here:
But nobody has answered yet.
It seems the problem is the following:
I get proper data from the server, but do not know how to update the buffer, and the app crashes.
How do you change your mesh to another set of coordinates and normals and then display it with react managing component update?
The full message of the StackOverflow question:
I have a react-three-fiber app, which renders custom BufferGeometry cone.
On the frontend I got some user inputs for setting parameters like height, radius etc.
Then I send this data to the server via post request and the server sends back coordinates and normals arrays.
At first request, all works fine.
But then, when a user for example changes height a little - the app crashes with:
[.WebGL-0000704C00336700] GL_INVALID_OPERATION: Vertex buffer is not big enough for the draw call
When I console.log
these new data arrays, they are as expected.
Apparently, something wrong with my React implementation.
The code follows:
function App() {
const [coneData, setConeData] = useState({});
const [height, setHeight] = useState(5);
const [radius, setRadius] = useState(3);
const [segments, setSegments] = useState(3);
const sendConeParams = useCallback(async () => {
const config = {
headers: {
"Content-Type": "application/json",
},
};
const { data } = await axios.post(
`/api`,
{ height, radius, segments },
config
);
setConeData(data);
}, [height, radius, segments]);
useEffect(() => {
sendConeParams();
}, [sendConeParams]);
return (
<>
<div id="canvas-container">
<Canvas>
<ambientLight intensity={0.5} />
<spotLight position={[10, 10, 10]} angle={0.15} penumbra={1} />
<pointLight position={[-10, -10, -10]} />
{coneData.conePositions && coneData.coneNormals ? (
<Cone
position={[0, 0, 0]}
triangulation={coneData.conePositions}
normals={coneData.coneNormals}
/>
) : (
""
)}
<OrbitControls />
</Canvas>
</div>
<Controls
height={height}
radius={radius}
segments={segments}
setHeight={setHeight}
setRadius={setRadius}
setSegments={setSegments}
/>
</>
);
}