From 4ca0bf56a9a6a09e5052c7986502341902d2fa2f Mon Sep 17 00:00:00 2001 From: yushiang Date: Tue, 5 Mar 2024 21:05:24 +0800 Subject: [PATCH 1/3] fix: texture not loaded at begining. --- apps/editors/decoration/index.js | 3 ++- apps/editors/layout2d.js | 8 +++++--- apps/editors/layout3d.js | 5 ++++- apps/viewer.js | 3 ++- packages/three/hooks/texture.js | 2 +- 5 files changed, 14 insertions(+), 7 deletions(-) diff --git a/apps/editors/decoration/index.js b/apps/editors/decoration/index.js index 39dcee9..7e8e695 100644 --- a/apps/editors/decoration/index.js +++ b/apps/editors/decoration/index.js @@ -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); @@ -109,7 +110,7 @@ const Editor = ({ data }) => { const textureMeshProps = { ...data, layout2D, - panorama: Loaders.useTexture({ src: data.panorama }), + panorama, }; const onLoad = useCallback((mesh) => { diff --git a/apps/editors/layout2d.js b/apps/editors/layout2d.js index 8a95685..0ec3413 100644 --- a/apps/editors/layout2d.js +++ b/apps/editors/layout2d.js @@ -88,9 +88,11 @@ const Editor = ({ data }) => { )} - - - + {panorama && ( + + + + )} ); diff --git a/apps/editors/layout3d.js b/apps/editors/layout3d.js index 9a8696c..75554b3 100644 --- a/apps/editors/layout3d.js +++ b/apps/editors/layout3d.js @@ -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); @@ -58,7 +59,7 @@ const Editor = ({ data }) => { floorY, ceilingY, layout2D, - panorama: Loaders.useTexture({ src: data.panorama }), + panorama, panoramaOrigin, }; @@ -78,6 +79,8 @@ const Editor = ({ data }) => { canvas3DRef.current.cameraControls.focus(mesh, false, false, false); }; + if (!panorama) return null; + return ( <> diff --git a/apps/viewer.js b/apps/viewer.js index 7cad10f..5991170 100644 --- a/apps/viewer.js +++ b/apps/viewer.js @@ -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( @@ -39,7 +40,7 @@ const Viewer = ({ data }) => { const textureMeshProps = { ...data, layout2D, - panorama: Loaders.useTexture({ src: data.panorama }), + panorama, }; const onLoad = useCallback((mesh) => { diff --git a/packages/three/hooks/texture.js b/packages/three/hooks/texture.js index 1ef41b6..77c9601 100644 --- a/packages/three/hooks/texture.js +++ b/packages/three/hooks/texture.js @@ -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; From 22744a4a4a94a66d181e842de81d71600c8538b5 Mon Sep 17 00:00:00 2001 From: yushiang Date: Tue, 5 Mar 2024 21:11:24 +0800 Subject: [PATCH 2/3] doc: changelog pr76 --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index cb90a36..9172888 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 From 4f092adff2684fa4d1f256f6b75423e57c2f99e0 Mon Sep 17 00:00:00 2001 From: yushiang Date: Tue, 5 Mar 2024 21:14:24 +0800 Subject: [PATCH 3/3] doc: changelog 2.1.1 --- CHANGELOG.md | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9172888..0200a70 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,16 @@ The format is based on [Keep a Changelog](https://github.com/olivierlacan/keep-a ### Fixed +### Removed + +## [2.1.1] - 2024-03-05 + +### Added + +### Changed + +### Fixed + - Fix texture not load. (https://github.com/yushiang-demo/pano-to-mesh/pull/76) ### Removed @@ -215,7 +225,8 @@ Codes without pull requests won't be recorded. ### Removed -[unreleased]: https://github.com/yushiang-demo/PanoToMesh/compare/v2.1.0...HEAD +[unreleased]: https://github.com/yushiang-demo/PanoToMesh/compare/v2.1.1...HEAD +[2.1.1]: https://github.com/yushiang-demo/PanoToMesh/compare/v2.0.0...v2.1.0 [2.1.0]: https://github.com/yushiang-demo/PanoToMesh/compare/v2.0.1...v2.1.0 [2.0.1]: https://github.com/yushiang-demo/PanoToMesh/compare/v2.0.0...v2.0.1 [2.0.0]: https://github.com/yushiang-demo/PanoToMesh/compare/v1.4.1...v2.0.0