Skip to content

Commit

Permalink
fix(composer): fix model shader material color restore (#290)
Browse files Browse the repository at this point in the history
  • Loading branch information
sheilaXu committed Oct 21, 2022
1 parent 5687f5e commit 0786c4a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { useMemo, useEffect } from 'react';
import { Mesh } from 'three';
import { isEmpty } from 'lodash';

import { COMPOSER_FEATURES, SceneResourceType } from '../../../interfaces';
import { ISceneNodeInternal, IColorOverlayComponentInternal, useStore } from '../../../store';
Expand Down Expand Up @@ -58,7 +59,7 @@ const ColorOverlayComponent: React.FC<IColorOverlayComponentProps> = ({
);

useEffect(() => {
if (ruleResult !== '') {
if (!isEmpty(ruleResult)) {
transform();
}

Expand Down
8 changes: 4 additions & 4 deletions packages/scene-composer/src/hooks/useMaterialEffect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ const useMaterialEffect = (callback: (object: Object3D) => void, object?: Object

const restore = useCallback(() => {
object?.traverse((o) => {
if (o instanceof Mesh) {
if (o instanceof Mesh && o.userData?.isOriginal) {
const original = originalMaterialMap.current[o.uuid];
o.material = original.clone();
o.material = original ? original.clone() : o.material;
}
});
}, []);
}, [object]);

useEffect(() => {
object?.traverse((o) => {
Expand All @@ -21,7 +21,7 @@ const useMaterialEffect = (callback: (object: Object3D) => void, object?: Object
}
}
});
}, []);
}, [object]);

const transform = () => {
// Currently can't think of a use case where we'd want to use this to transform a material on a component we own
Expand Down

0 comments on commit 0786c4a

Please sign in to comment.