You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, I'm converting a threejs project to use react-three-fiber. My project is a scene which renders a large number of objects (~80,000), so I merge them where possible, which is performant but memory is still leaking.
I saw a similar question and have followed a similar approach with usememo for the mergeBufferGeometries.
Here's my component: (With this component removed, the app isn't leaking)
import * as React from 'react'
import * as THREE from 'three'
import { mergeBufferGeometries } from 'three-stdlib/utils/BufferGeometryUtils'
import { LevelJson } from '../typings/types'
import { LAYERS } from './client'
import { LandmarkIndex } from './landmarkParser'
interface MergedLandmarkProps {
levelJson: LevelJson
landmarkIndex: LandmarkIndex
}
export default function MergedLandmarks({ levelJson, landmarkIndex }: MergedLandmarkProps) {
const allLandmarks = levelJson.landmarks
const geomsToMerge = allLandmarks.flatMap((landmark) => {
const sharedGeom = new THREE.BoxGeometry(3, 3, 3) //placeholder
return landmark.entries.map((entry) => {
const geom = sharedGeom.clone()
const rotateQuat = new THREE.Quaternion()
rotateQuat.fromArray(entry.q)
rotateQuat.normalize()
const matrix = new THREE.Matrix4()
matrix.makeRotationFromQuaternion(rotateQuat)
matrix.setPosition(entry.x, entry.y, entry.z)
geom.applyMatrix4(matrix)
return geom
})
})
const merged = React.useMemo(() => {
return mergeBufferGeometries(geomsToMerge)
}, [geomsToMerge])
geomsToMerge.forEach((geom) => geom.dispose())
return (
<mesh geometry={merged!} layers={LAYERS.Zones}>
<meshPhongMaterial color={0x3a3c42} flatShading />
</mesh>
)
}
The other linked question implied that a geometry set as an attribute would still be managed, but when switching levels and returning to the same set of landmarks, heap size keeps increasing.
Are there any changes I should make to improve this?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
Hi, I'm converting a threejs project to use react-three-fiber. My project is a scene which renders a large number of objects (~80,000), so I merge them where possible, which is performant but memory is still leaking.
I saw a similar question and have followed a similar approach with usememo for the mergeBufferGeometries.
Here's my component: (With this component removed, the app isn't leaking)
The other linked question implied that a geometry set as an attribute would still be managed, but when switching levels and returning to the same set of landmarks, heap size keeps increasing.
Are there any changes I should make to improve this?
Beta Was this translation helpful? Give feedback.
All reactions