-
Notifications
You must be signed in to change notification settings - Fork 60
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
feat(EnvironmentModel): Adding support for environment overlay #262
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
...scene-composer/src/components/three-fiber/ModelRefComponent/EnvironmentModelComponent.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import React from 'react'; | ||
|
||
import { IModelRefComponentInternal, ISceneNodeInternal, useEditorState } from '../../../store'; | ||
import { useSceneComposerId } from '../../../common/sceneComposerIdContext'; | ||
|
||
import { GLTFModelComponent } from './GLTFModelComponent'; | ||
|
||
interface EnvironmentModelComponentProps { | ||
component: IModelRefComponentInternal; | ||
node: ISceneNodeInternal; | ||
} | ||
|
||
export const EnvironmentModelComponent: React.FC<EnvironmentModelComponentProps> = ({ node, component }) => { | ||
const sceneComposerId = useSceneComposerId(); | ||
const { isEditing, cameraControlsType } = useEditorState(sceneComposerId); | ||
|
||
if (isEditing()) { | ||
return ( | ||
<GLTFModelComponent | ||
key={component.ref} | ||
node={node} | ||
component={component} | ||
hiddenWhileImmersive={cameraControlsType === 'immersive'} | ||
/> | ||
); | ||
} | ||
|
||
return <></>; | ||
}; |
57 changes: 57 additions & 0 deletions
57
...src/components/three-fiber/ModelRefComponent/__tests__/EnvironmentModelComponent.spec.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import React from 'react'; | ||
import { render } from '@testing-library/react'; | ||
|
||
import { EnvironmentModelComponent } from '../EnvironmentModelComponent'; | ||
import { IModelRefComponentInternal, ISceneNodeInternal, useStore } from '../../../../store'; | ||
import { ModelType } from '../../../../models/SceneModels'; | ||
import { KnownComponentType } from '../../../../interfaces'; | ||
|
||
// @ts-ignore | ||
jest.mock('scheduler', () => require('scheduler/unstable_mock')); | ||
|
||
jest.mock('../GLTFModelComponent', () => ({ | ||
GLTFModelComponent: (props) => <div id={'GLTFModelComponent'} {...props} />, | ||
})); | ||
|
||
/* eslint-enable */ | ||
|
||
describe('EnvironmentModelComponent', () => { | ||
const component: IModelRefComponentInternal = { | ||
uri: 'uri', | ||
modelType: ModelType.GLB, | ||
ref: 'test-ref', | ||
type: KnownComponentType.ModelRef, | ||
}; | ||
|
||
const node: ISceneNodeInternal = { | ||
ref: 'test-ref', | ||
name: 'test-name', | ||
transform: { position: [0, 0, 0], rotation: [0, 0, 0], scale: [0, 0, 0] }, | ||
transformConstraint: {}, | ||
components: [component], | ||
childRefs: [], | ||
properties: {}, | ||
}; | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('should render as expected when editing', () => { | ||
useStore('default').setState({ | ||
isEditing: jest.fn().mockReturnValue(true), | ||
}); | ||
const { container } = render(<EnvironmentModelComponent component={component} node={node} />); | ||
|
||
expect(container).toMatchSnapshot(); | ||
}); | ||
|
||
it('should render as empty when viewing', () => { | ||
useStore('default').setState({ | ||
isEditing: jest.fn().mockReturnValue(false), | ||
}); | ||
const { container } = render(<EnvironmentModelComponent component={component} node={node} />); | ||
|
||
expect(container).toMatchSnapshot(); | ||
}); | ||
}); |
13 changes: 13 additions & 0 deletions
13
...e-fiber/ModelRefComponent/__tests__/__snapshots__/EnvironmentModelComponent.spec.tsx.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`EnvironmentModelComponent should render as empty when viewing 1`] = `<div />`; | ||
|
||
exports[`EnvironmentModelComponent should render as expected when editing 1`] = ` | ||
<div> | ||
<div | ||
component="[object Object]" | ||
id="GLTFModelComponent" | ||
node="[object Object]" | ||
/> | ||
</div> | ||
`; |
30 changes: 29 additions & 1 deletion
30
.../src/components/three-fiber/ModelRefComponent/__tests__/__snapshots__/index.spec.tsx.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,31 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`ModelRefComponent should render correctly 1`] = `null`; | ||
exports[`ModelRefComponent should render correctly 1`] = ` | ||
<div> | ||
<div | ||
component="[object Object]" | ||
id="GLTFModelComponent" | ||
node="[object Object]" | ||
/> | ||
</div> | ||
`; | ||
|
||
exports[`ModelRefComponent should render correctly with Environment Model Type 1`] = ` | ||
<div> | ||
<div | ||
component="[object Object]" | ||
id="EnvironmentModelComponent" | ||
node="[object Object]" | ||
/> | ||
</div> | ||
`; | ||
|
||
exports[`ModelRefComponent should render correctly with Tiles Model Type 1`] = ` | ||
<div> | ||
<div | ||
component="[object Object]" | ||
id="TilesModelComponent" | ||
node="[object Object]" | ||
/> | ||
</div> | ||
`; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is cleaner if you invert it:
Also I'm not sure I agree that the isEditing or cameracControls type properties should be the responsibility of the EnvironmentModelComponent.
I would say it's up the orchestrator component to understand logic around whether this should be visible or not, and the hidden while immersive flag also shouldn't need to be propagated down tot he GLTF model compoennt, since it's just another flag we use to determine if we render this at all.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is something I didn't remove when we removed the immersive view feature. If we retackle that again this will be rectified. I can also make a note to perform this extra clean up and get to it when things calm down