Skip to content

Commit

Permalink
Prevent Sub-Models from being moved without a feature flag (#343)
Browse files Browse the repository at this point in the history
* Prevent Sub-Models from being moved without a feature flag

* Rename variable for clarity
  • Loading branch information
jwills-jdubs authored Nov 9, 2022
1 parent 8ccd69d commit eabc6aa
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 6 deletions.
8 changes: 4 additions & 4 deletions packages/scene-composer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,10 @@
"jest": {
"coverageThreshold": {
"global": {
"lines": 77.00,
"statements": 76.00,
"functions": 77.0,
"branches": 63.0,
"lines": 77.55,
"statements": 76.71,
"functions": 77.15,
"branches": 63.49,
"branchesTrue": 100
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export const SceneNodeInspectorPanel: React.FC = () => {
const intl = useIntl();

const tagResizeEnabled = getGlobalSettings().featureConfig[COMPOSER_FEATURES.TagResize];
const subModelMovementEnabled = getGlobalSettings().featureConfig[COMPOSER_FEATURES.SubModelMovement];

const i18nKnownComponentTypesStrings = defineMessages({
[KnownComponentType.ModelRef]: {
Expand Down Expand Up @@ -81,6 +82,13 @@ export const SceneNodeInspectorPanel: React.FC = () => {
[selectedSceneNode],
);

const isSubModelComponent = useMemo(
() => !!findComponentByType(selectedSceneNode, KnownComponentType.SubModelRef),
[selectedSceneNode],
);

const transformVisible = !isSubModelComponent || subModelMovementEnabled;

const shouldShowScale = !((isTagComponent && !tagResizeEnabled) || isCameraComponent);

const readonly: Triplet<boolean> = [false, false, false];
Expand Down Expand Up @@ -133,7 +141,7 @@ export const SceneNodeInspectorPanel: React.FC = () => {
<TextInput value={selectedSceneNode.name} setValue={(e) => handleInputChanges({ name: e?.toString() })} />
</FormField>
</ExpandableInfoSection>
{!isEnvironmentNode(selectedSceneNode) && (
{!isEnvironmentNode(selectedSceneNode) && transformVisible && (
<ExpandableInfoSection
title={intl.formatMessage({ defaultMessage: 'Transform', description: 'Expandable section title' })}
defaultExpanded
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,20 @@ export function EditorTransformControls() {

const [transformControls] = useState(() => new TransformControlsImpl(camera, domElement));
const tagResizeEnabled = getGlobalSettings().featureConfig[COMPOSER_FEATURES.TagResize];
const subModelMovementEnabled = getGlobalSettings().featureConfig[COMPOSER_FEATURES.SubModelMovement];

const isTagComponent = useMemo(
() => !!findComponentByType(selectedSceneNode, KnownComponentType.Tag),
[selectedSceneNode],
);

const isSubModelComponent = useMemo(
() => !!findComponentByType(selectedSceneNode, KnownComponentType.SubModelRef),
[selectedSceneNode],
);

const transformVisible = !isSubModelComponent || subModelMovementEnabled;

// Set transform controls' camera
useEffect(() => {
setTransformControls(transformControls);
Expand Down Expand Up @@ -68,7 +76,7 @@ export function EditorTransformControls() {

// Update transform controls' attached object
useEffect(() => {
if (selectedSceneNodeRef && !isEnvironmentNode(selectedSceneNode)) {
if (selectedSceneNodeRef && !isEnvironmentNode(selectedSceneNode) && transformVisible) {
const object3d = getObject3DBySceneNodeRef(selectedSceneNodeRef);
if (object3d) {
log?.verbose('attach transform controls to', object3d);
Expand Down
1 change: 1 addition & 0 deletions packages/scene-composer/src/interfaces/feature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export enum COMPOSER_FEATURES {
CameraView = 'CameraView',
EnvironmentModel = 'EnvironmentModel',
TagResize = 'TagResize',
SubModelMovement = 'SubModelMovement',
}

export type FeatureConfig = Partial<Record<COMPOSER_FEATURES, boolean>>;
1 change: 1 addition & 0 deletions packages/scene-composer/stories/SceneComposer.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ const knobsConfigurationDecorator = [
[COMPOSER_FEATURES.CameraView]: true,
[COMPOSER_FEATURES.EnvironmentModel]: false,
[COMPOSER_FEATURES.TagResize]: true,
[COMPOSER_FEATURES.SubModelMovement]: false,
...args.config.featureConfig,
},
...args.config,
Expand Down

0 comments on commit eabc6aa

Please sign in to comment.