Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: optimise augmented reality #883

Merged
merged 1 commit into from
Aug 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/components/augmentedReality/AugmentedRealityView.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ import {
import PropTypes from 'prop-types';
import React, { useContext, useEffect } from 'react';

import { colors, texts } from '../../config';
import { colors, consts, device, texts } from '../../config';
import { SettingsContext } from '../../SettingsProvider';

const { GB_TO_BYTES } = consts;

export const AugmentedRealityView = ({ sceneNavigator }) => {
const {
isObjectLoading,
Expand Down Expand Up @@ -100,6 +102,8 @@ const ViroSoundAnd3DObject = (item) => {
});
}

const isMore2GBRam = device.totalMemory > GB_TO_BYTES[2];

return (
<>
{!isObjectLoading && (
Expand Down Expand Up @@ -164,7 +168,7 @@ const ViroSoundAnd3DObject = (item) => {
/>
))}

{object?.spot && (
{object?.spot && isMore2GBRam && (
<ViroSpotLight
direction={object.spot.direction}
innerAngle={object.spot.innerAngle}
Expand All @@ -179,7 +183,7 @@ const ViroSoundAnd3DObject = (item) => {
/>
)}

{object?.quad && (
{object?.quad && isMore2GBRam && (
<ViroQuad
height={object.quad.height}
position={object.quad.position}
Expand Down
7 changes: 7 additions & 0 deletions src/config/consts.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,13 @@ export const consts = {
FULL_SCREEN_MAX_WIDTH: 428
},

// this section has been added to optimise AR on low RAM devices and to prevent some features of AR from being used
GB_TO_BYTES: {
1: 1073741824,
2: 2147483648,
3: 3221225472
},

// the image aspect ratio can be overwritten by a global setting `imageAspectRatio`
// from the server in src/index.js
IMAGE_ASPECT_RATIO: {
Expand Down
2 changes: 2 additions & 0 deletions src/config/device.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { Dimensions, Platform } from 'react-native';
import { totalMemory } from 'expo-device';

export const device = {
height: Dimensions.get('window').height,
platform: Platform.OS,
totalMemory,
width: Dimensions.get('window').width
};