react-native-filament
Version:
A real-time physically based 3D rendering engine for React Native
40 lines (38 loc) • 1.6 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.DebugBox = DebugBox;
var _react = require("react");
var _useFilamentContext = require("../hooks/useFilamentContext");
var _useApplyTransformations = require("../hooks/internal/useApplyTransformations");
var _ParentInstancesContext = require("./ParentInstancesContext");
var _useEntityInScene = require("../hooks/useEntityInScene");
function DebugBox({
halfExtent: halfExtentProp,
...transformProps
}) {
const instances = (0, _react.useContext)(_ParentInstancesContext.ParentInstancesContext);
const parentInstance = instances === null || instances === void 0 ? void 0 : instances[0];
const parentHalfExtend = (0, _react.useMemo)(() => {
if (parentInstance == null) return undefined;
return parentInstance.getBoundingBox().halfExtent;
}, [parentInstance]);
const halfExtent = halfExtentProp ?? parentHalfExtend;
const {
renderableManager,
scene
} = (0, _useFilamentContext.useFilamentContext)();
const boxEntity = (0, _react.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]);
(0, _useApplyTransformations.useApplyTransformations)({
to: boxEntity,
transformProps
});
(0, _useEntityInScene.useEntityInScene)(scene, boxEntity ?? undefined);
return null;
}
//# sourceMappingURL=DebugBox.js.map