Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ThreeLayer如何在resize事件中进行场景的重渲染调整? #2663

Open
Steve245270533 opened this issue Jan 22, 2025 · 2 comments
Open
Assignees

Comments

@Steve245270533
Copy link

问题描述

在使用L7叠加一个threejs图层渲染的时候,如果触发窗口的 resize 事件,默认情况下,three场景图层中的物体始终保持原来的位置信息。
通过手动调整 camera.aspectrenderer.setSize 方法后才能正确地渲染原有位置关系,但是会产生抖动,有没有更好的解决办法?

重现链接

No response

重现步骤

import { Scene } from '@antv/l7';
import { GaodeMap } from '@antv/l7-maps';
import { ThreeLayer, ThreeRender } from '@antv/l7-three';
import * as THREE from 'three';

const scene = new Scene({
  id: 'map',
  map: new GaodeMap({
    pitch: 50,
    style: 'light',
    center: [104.062427, 30.656733],
    zoom: 14,
  }),
});

scene.on('loaded', () => {
  scene.registerRenderService(ThreeRender);

  const threeJSLayer = new ThreeLayer({
    enableMultiPassRenderer: false,
    onAddMeshes: (threeScene, layer) => {
      threeScene.add(new THREE.AmbientLight(0xffffff));
      const sunlight = new THREE.DirectionalLight(0xffffff, 1);
      sunlight.position.set(0, 80000000, 100000000);
      sunlight.matrixWorldNeedsUpdate = true;
      threeScene.add(sunlight);

      const center = scene.getCenter();

      const cubeGeometry = new THREE.BoxGeometry(500, 500, 500);
      const cubeMaterial = new THREE.MeshStandardMaterial({ color: 0xff9900, side: THREE.DoubleSide });
      const cube = new THREE.Mesh(cubeGeometry, cubeMaterial);
      layer.setObjectLngLat(cube, [center.lng, center.lat], 500);
      threeScene.add(cube);

      // 重绘图层
      window.addEventListener("resize", () => {
        const camera = threeJSLayer.getRenderCamera()
        camera.aspect = window.innerWidth / window.innerHeight;
        layer.threeRenderService.renderer.setSize(window.innerWidth, window.innerHeight)
      })
    },
  }).animate(true)
  scene.addLayer(threeJSLayer);
})

预期行为

resize事件触发时,图层中的物体不产生抖动

平台

  • 操作系统: Windows
  • 网页浏览器: Google Chrome 131.0.6778.265

屏幕截图或视频(可选)

未处理前:

Image

处理后:

Image

补充说明(可选)

No response

Copy link
Contributor

hi @Steve245270533, welcome!

Copy link
Contributor

Hi @Steve245270533, Please star this repo if you find it useful! Thanks ⭐!
你好~ @Steve245270533 🌟 如果这个仓库对你有帮助,可以给我们点个star支持一下~你的支持对我们来说是最大的鼓励,感谢你的支持与点赞 🌟

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants