Three Vue3Three Vue3
指南
在线演示
AI 智能体
  • English
  • 简体中文
GitHub
指南
在线演示
AI 智能体
  • English
  • 简体中文
GitHub
    • 快速开始
    • 场景
    • 参数总线
    • 天空盒
    • 模型加载器

      • 组件加载器
      • 函数加载器
    • 弹出窗口
    • 标注
    • 动态元素
    • 动画
    • 模型旋转器
    • 拾取
    • 相机自适应
    • 网格模型

      • 波动圆
      • 流动线网格
    • 效果

      • 自然

        • 雨
        • 雪
        • 海洋水面
        • 互动水池
        • 沙滩漫步
      • 天空与大气

        • 天空穹顶
        • 高度雾
        • 星云星系
          • 默认用法
          • 配置项
          • 类用法
      • 光照

        • 泛光
        • 扫光
        • 灯光渐变
        • 光柱
        • 雷达扫描
        • 信号波
        • 力场护盾
      • 粒子与精灵

        • 烟花
        • 文字烟花
        • 光晕精灵
    • 地理

      • 地理参考系
      • GeoObject 地理对象
      • GeoJsonLayer 图层
      • 瓦片图层

类型

类

NebulaGalaxy 用叠加发光的公告板粒子、程序化星云雾面和扩散点击波纹构建一个四臂旋涡星系。每颗恒星都有各自的自转角速度,因此旋臂会被剪切、缠绕,而不是像刚体圆盘一样整体旋转;雾面略微滞后于粒子,图案就不会像一张贴图。

星系自带交互:拖拽倾斜圆盘,滚轮或双指缩放,点击则从核心沿旋臂发出一次光波。指针监听会在首次渲染时绑定到画布,并在 dispose() 时移除。

星系由自身动画循环驱动——自转、空闲旋转、倾斜与缩放的平滑、调色板过渡以及点击波都无需逐帧代码。如果需要手动驱动时钟,update(delta) 仍然可用。

默认用法

Drag to tilt the disc, scroll or pinch to zoom, click for a light wave.

点击我查看代码
<template>
  <div>
    <div class="toolbar">
      <button
        v-for="item in palettes"
        :key="item.value"
        type="button"
        class="palette"
        :class="{ active: palette === item.value }"
        @click="palette = item.value"
      >
        <span class="swatch" :style="{ background: item.swatch }"></span>
        {{ item.label }}
      </button>
      <label class="speed">
        速度
        <input v-model.number="speed" type="range" min="0" max="2" step="0.1" />
      </label>
      <button type="button" class="pause" @click="paused = !paused">
        {{ paused ? '继续' : '暂停' }}
      </button>
    </div>
    <p class="hint">拖拽倾斜圆盘,滚轮或双指缩放,点击发出光波。</p>
    <tv-scene class="scene" bg-color="rgb(40, 42, 54)" @created="created"></tv-scene>
  </div>
</template>

<script lang="ts" setup>
import { onBeforeUnmount, ref, watch } from 'vue'
import { NebulaGalaxy } from 'three-vue3'
import type { GalaxyPalette } from 'three-vue3'

const palettes: Array<{ value: GalaxyPalette; label: string; swatch: string }> = [
  {
    value: 'violet-gold',
    label: 'Violet gold',
    swatch: 'linear-gradient(135deg, #ffe0a8, #b07cff 55%, #4a7dff)'
  },
  {
    value: 'aurora',
    label: 'Aurora',
    swatch: 'linear-gradient(135deg, #d6fff2, #35e0a8 55%, #4f8bff)'
  },
  {
    value: 'warm-flame',
    label: 'Warm flame',
    swatch: 'linear-gradient(135deg, #fff0c0, #ff9448 55%, #ff4d6d)'
  }
]

const palette = ref<GalaxyPalette>('violet-gold')
const speed = ref(1)
const paused = ref(false)

let effect: NebulaGalaxy | undefined

const created = (scene, { camera, controls, gridHelper }) => {
  camera.position.set(0, 2.6, 11)
  camera.lookAt(0, 0, 0)

  // 星系自己处理指针,避免轨道控制器抢占事件。
  if (controls) controls.enabled = false
  if (gridHelper && typeof gridHelper !== 'boolean') gridHelper.visible = false

  effect = new NebulaGalaxy({ palette: palette.value, speed: speed.value })
  scene.add(effect)
}

watch(palette, (value) => effect?.setPalette(value))
watch(speed, (value) => effect?.setSpeed(value))
watch(paused, (value) => effect?.setPaused(value))

onBeforeUnmount(() => {
  effect?.dispose()
  effect = undefined
})
</script>

<style>
.scene {
  margin-top: 10px;
  margin-bottom: 16px;
  width: 100%;
  height: 300px;
}
.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
}
.palette,
.pause {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  font-size: 12px;
  border-radius: 999px;
  cursor: pointer;
  color: inherit;
  background: transparent;
  border: 1px solid var(--vp-c-divider);
}
.palette.active {
  border-color: var(--vp-c-brand-1);
}
.swatch {
  width: 12px;
  height: 12px;
  border-radius: 50%;
}
.speed {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
}
.speed input {
  width: 90px;
}
.hint {
  margin: 6px 0 0;
  font-size: 12px;
  opacity: 0.6;
}
</style>

配置项

名称类型默认值描述
armsnumber4可选 旋臂数量。
armStarsnumber26000可选 构成旋臂的恒星数量。
coreStarsnumber4800可选 填充核心的恒星数量。
dustStarsnumber4400可选 柔化边缘的大颗暗淡恒星数量。
backgroundStarsnumber780可选 星系体之外的远景背景星数量。
radiusnumber5.15可选 星系半径(世界单位)。
armTightnessnumber1.12可选 旋臂随距离缠绕的紧密程度。
paletteGalaxyPalette'violet-gold'可选 配色方案。
speednumber1可选 自转速度倍数。
autoRotatebooleantrue可选 空闲时缓慢旋转(减少动态效果时为 off)。
interactionbooleantrue可选 在画布上启用拖拽 / 滚轮 / 双指交互。
pulsebooleantrue可选 点击波纹(减少动态效果时为 off)。
hazeOpacitynumber0.95可选 雾面层的不透明度。
followSpeednumber5.8可选 倾斜、缩放和配色过渡的平滑速度。
maxTiltXnumber1.15可选 最大垂直倾斜(弧度)。
maxTiltYnumber1.25可选 最大水平倾斜(弧度)。
minZoomnumber0.62可选 最小缩放系数。
maxZoomnumber1.55可选 最大缩放系数。
seednumber7可选 确定性星点分布的随机种子。

类用法

import { NebulaGalaxy } from 'three-vue3'

const galaxy = new NebulaGalaxy({ palette: 'violet-gold' })
scene.add(galaxy)

// 星系会自动播放动画。只有需要手动驱动时才调用 update(delta):
galaxy.update(delta)

// 切换配色、暂停自转或发出光波:
galaxy.setPalette('aurora')
galaxy.setPaused(true)
galaxy.pulse()

// 销毁时:
galaxy.dispose()
在 GitHub 上编辑此页
Last Updated:
Contributors: Shing Rui
Prev
高度雾