Skip to content

Commit

Permalink
fix(CrashOnRemount): scene-composer doesn't crash when remounted now
Browse files Browse the repository at this point in the history
  • Loading branch information
Mitchell Lee authored and TheEvilDev committed Apr 25, 2023
1 parent 5b4ebfa commit 79f2f77
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 6 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as THREE from 'three';
import React, { Fragment, useCallback, useContext, useEffect, useMemo, useRef, useState } from 'react';
import React, { Fragment, forwardRef, useCallback, useContext, useEffect, useMemo, useRef, useState } from 'react';
import mergeRefs from 'react-merge-refs';
import { PerspectiveCamera } from '@react-three/drei/core/PerspectiveCamera';
import { Camera, useFrame, useThree } from '@react-three/fiber';
Expand All @@ -24,7 +24,7 @@ import { getSafeBoundingBox } from '../../utils/objectThreeUtils';

import { MapControls, OrbitControls } from './controls';

export const EditorMainCamera = React.forwardRef<Camera>((_, forwardedRef) => {
export const EditorMainCamera = forwardRef<Camera>((_, forwardedRef) => {
const log = useLogger('EditorMainCamera');

const matterportSdk = useMatterportSdk();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export const OrbitControls = forwardRef<OrbitControlsImpl, OrbitControlsProps>(
if (onChange) onChange(e);
};

controls.connect(explDomElement!);
controls.connect(explDomElement || gl.domElement);
controls.addEventListener('change', callback);

if (onStart) controls.addEventListener('start', onStart);
Expand Down
40 changes: 39 additions & 1 deletion packages/scene-composer/stories/SceneViewer.stories.mdx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { Canvas, Meta, Story } from '@storybook/addon-docs';

import { useState, useCallback } from 'react';

import SceneViewer, { argTypes, args } from './components/scene-viewer';
import { testScenes } from '../tests/testData';
import { COMPOSER_FEATURES } from '../src/interfaces/feature';
Expand All @@ -26,6 +28,24 @@ export const Template = (args) => {
return <SceneViewer {...defaultArgs} {...args} />
}

export const MountToggle = (args) => {
const [isMounted, setIsMounted] = useState(true)
const toggleVisibility = useCallback(() => {
setIsMounted(!isMounted)
}, [isMounted])
return (
<div>
<label>
<input type="checkbox" onChange={toggleVisibility} checked={isMounted} />
mounted
</label>
<div style={{ position: 'relative', height: '100vh' }}>
{ isMounted && <SceneViewer {...defaultArgs} {...args} />}
</div>
</div>
)
}

# Scene Viewer

## Motion Indicator
Expand All @@ -50,4 +70,22 @@ Motion Indicators should disappear when turned off.
</Story>
</Canvas>

## Sub Model Selection
## Loading and Unloading

The scene viewer should be able to be mounted and unmounted as needed by the software application. While in production, this is discourage due to the size and complexity of this component,
during development Hot-Module-Reloaders (HMR) typically do this all the time, so the component shouldn't crash

#### Steps:
- Click the button to remount the component

#### Verification:
- It should reload without errors.

<Canvas>
<Story name='Remounting'
height='500px'
parameters={{ controls: { include: ['onSelectionChanged', 'onWidgetClick'], hideNoControlsWarning: true }}}
args={{ ...defaultArgs, scene: 'CookieFactoryWaterTank' }}>
{MountToggle.bind({})}
</Story>
</Canvas>

0 comments on commit 79f2f77

Please sign in to comment.