Skip to content

Commit

Permalink
Merge pull request #76 from yushiang-demo/fix-texture-not-load
Browse files Browse the repository at this point in the history
fix-texture-not-load
  • Loading branch information
tsengyushiang committed Mar 5, 2024
2 parents 8dd1ba4 + 22744a4 commit 2109ffa
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 7 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ The format is based on [Keep a Changelog](https://github.com/olivierlacan/keep-a

### Fixed

- Fix texture not load. (https://github.com/yushiang-demo/pano-to-mesh/pull/76)

### Removed

## [2.1.0] - 2024-02-18
Expand Down
3 changes: 2 additions & 1 deletion apps/editors/decoration/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const dev = process.env.NODE_ENV === "development";
const Editor = ({ data }) => {
const threeRef = useRef(null);
const mediaIndexMap = useRef(null);
const panorama = Loaders.useTexture({ src: data.panorama });
const [baseMesh, setBaseMesh] = useState(null);
const [mouse, setMouse] = useState([0, 0]);
const [camera, setCamera] = useState(null);
Expand Down Expand Up @@ -109,7 +110,7 @@ const Editor = ({ data }) => {
const textureMeshProps = {
...data,
layout2D,
panorama: Loaders.useTexture({ src: data.panorama }),
panorama,
};

const onLoad = useCallback((mesh) => {
Expand Down
8 changes: 5 additions & 3 deletions apps/editors/layout2d.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,11 @@ const Editor = ({ data }) => {
)}
</Toolbar>
<RatioLockedDiv>
<ThreeCanvas {...eventHandlers} dev={dev}>
<PanoramaOutline {...props} />
</ThreeCanvas>
{panorama && (
<ThreeCanvas {...eventHandlers} dev={dev}>
<PanoramaOutline {...props} />
</ThreeCanvas>
)}
</RatioLockedDiv>
</PageContainer>
);
Expand Down
5 changes: 4 additions & 1 deletion apps/editors/layout3d.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const dev = process.env.NODE_ENV === "development";
const Editor = ({ data }) => {
const canvas3DRef = useRef(null);
const textureCanvasRef = useRef(null);
const panorama = Loaders.useTexture({ src: data.panorama });
const [panoramaOrigin, setPanoramaOrigin] = useState(data.panoramaOrigin);
const [floorY] = useState(data.floorY);
const [ceilingY, setCeilingY] = useState(data.ceilingY);
Expand All @@ -58,7 +59,7 @@ const Editor = ({ data }) => {
floorY,
ceilingY,
layout2D,
panorama: Loaders.useTexture({ src: data.panorama }),
panorama,
panoramaOrigin,
};

Expand All @@ -78,6 +79,8 @@ const Editor = ({ data }) => {
canvas3DRef.current.cameraControls.focus(mesh, false, false, false);
};

if (!panorama) return null;

return (
<>
<ThreeCanvas dev={dev} ref={canvas3DRef}>
Expand Down
3 changes: 2 additions & 1 deletion apps/viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const dev = process.env.NODE_ENV === "development";
const Viewer = ({ data }) => {
const threeRef = useRef(null);
const [isTopView, setIsTopView] = useState(true);
const panorama = Loaders.useTexture({ src: data.panorama });
const [isCameraMoving, setIsCameraMoving] = useState(false);
const [baseMesh, setBaseMesh] = useState(null);
const geometryInfo = useMemo(
Expand All @@ -39,7 +40,7 @@ const Viewer = ({ data }) => {
const textureMeshProps = {
...data,
layout2D,
panorama: Loaders.useTexture({ src: data.panorama }),
panorama,
};

const onLoad = useCallback((mesh) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/three/hooks/texture.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export const useTexture = ({ src }) => {
const [texture, setTexture] = useState(null);

useEffect(() => {
setTexture(loader.load(src));
loader.load(src, setTexture);
}, [src]);

return texture;
Expand Down

0 comments on commit 2109ffa

Please sign in to comment.