Skip to content

Commit

Permalink
feat: add onLoaded handler for environment model
Browse files Browse the repository at this point in the history
  • Loading branch information
Zaehiel committed Aug 24, 2023
1 parent eabe992 commit e149ad5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
6 changes: 5 additions & 1 deletion src/components/Avatar/Examples.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,11 @@ environmentModel.args = {
environmentScale: 1.0,
shadows: true,
modelSrc: modelPresets.one,
animationSrc: animationPresets.one
animationSrc: animationPresets.one,
environment: 'warehouse',
/* eslint-disable no-console */
onLoaded: () => console.info('EVENT: environment model loaded')
/* eslint-enable no-console */
};
environmentModel.argTypes = {
...ignoreArgTypesOnExamples,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { FC } from 'react';
import { useFallback, useGltfLoader, CustomNode, Transform } from 'src/services';
import React, { FC, useEffect } from 'react';
import { useFallback, useGltfLoader, CustomNode, Transform, triggerCallback } from 'src/services';
import { useGraph } from '@react-three/fiber';
import { BaseModelProps } from 'src/types';
import { EnvironmentModels } from 'src/services/Environment.service';
Expand All @@ -9,12 +9,13 @@ export interface EnvironmentModelProps extends BaseModelProps {
scale?: number;
}

export const EnvironmentModel: FC<EnvironmentModelProps> = ({ environment, scale = 1, setModelFallback }) => {
export const EnvironmentModel: FC<EnvironmentModelProps> = ({ environment, scale = 1, setModelFallback, onLoaded }) => {
const transform = new Transform();
const { scene } = useGltfLoader(environment);
const { nodes } = useGraph(scene);

useFallback(nodes, setModelFallback);
useEffect(() => triggerCallback(onLoaded), [scene, onLoaded]);

return (
<group>
Expand Down

0 comments on commit e149ad5

Please sign in to comment.