跳转到内容
View in the app

A better way to browse. Learn more.

彼岸论坛

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.
欢迎抵达彼岸 彼岸花开 此处谁在 -彼岸论坛

[问与答] 求助,为什么我的 kd 树实际使用起来比暴力遍历还要慢(js)

发表于

场景

threejs 场景下,新建一个顶点数量为 2000 * 2000 即 4000000 个顶点的 plane geometry ,在 plane 上放一个运动的盒子,不断地获取距盒子距离为 n 的所有顶点并进行染色。

提供了两种方法:kd-tree 和 直接遍历。

结果

实际测试下来,直接遍历的帧数约为 40 ,而 kd-tree 的帧数只有 15 左右。

疑问

一开始以为是 kd-tree 实现的问题(实现算法也是自己写的),换了其他人写好的现成的库也是一样的结果。

现在不太清楚到底是 kd-tree 算法的问题还是我实现的 kd-tree 代码出错

代码

预览(加载比较慢,因为创建 kd-tree 比较费时)

threejs 代码

kd 树代码

Featured Replies

No posts to show

创建帐户或登录来提出意见

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.