react-native-filament
Version:
A real-time physically based 3D rendering engine for React Native
34 lines (33 loc) • 1.37 kB
JavaScript
import { useContext, useMemo } from 'react';
import { useFilamentContext } from '../hooks/useFilamentContext';
import { useApplyTransformations } from '../hooks/internal/useApplyTransformations';
import { ParentInstancesContext } from './ParentInstancesContext';
import { useEntityInScene } from '../hooks/useEntityInScene';
export function DebugBox({
halfExtent: halfExtentProp,
...transformProps
}) {
const instances = useContext(ParentInstancesContext);
const parentInstance = instances === null || instances === void 0 ? void 0 : instances[0];
const parentHalfExtend = useMemo(() => {
if (parentInstance == null) return undefined;
return parentInstance.getBoundingBox().halfExtent;
}, [parentInstance]);
const halfExtent = halfExtentProp ?? parentHalfExtend;
const {
renderableManager,
scene
} = useFilamentContext();
const boxEntity = useMemo(() => {
if (halfExtent == null) return null;
// TODO: other colors are only supported by importing a material - i think it should be possible to create a material on the fly
return renderableManager.createDebugCubeWireframe(halfExtent, undefined, undefined);
}, [halfExtent, renderableManager]);
useApplyTransformations({
to: boxEntity,
transformProps
});
useEntityInScene(scene, boxEntity ?? undefined);
return null;
}
//# sourceMappingURL=DebugBox.js.map