Three.js 银河星系效果 | 三维可视化 / AI 提示词

Three.js 银河星系效果 | 三维可视化 / AI 提示词

📋 AI 提示词

prompt 复制代码
使用 Three.js 创建银河星系效果,粒子围绕中心螺旋分布,使用 GUI 控制参数。

🖼️ 效果预览


🎮 案例演示

立即体验


效果描述

这是一个展示如何创建银河星系效果的示例,粒子围绕中心螺旋分布。

效果特性

  • 银河星系:创建 250000 个粒子
  • 螺旋分布:粒子围绕中心螺旋分布
  • 分支结构:粒子分为多个分支
  • 颜色渐变:粒子颜色从内到外渐变
  • GUI 控制:使用 GUI 控制参数
  • 纹理贴图:使用星形纹理

核心参数

参数 值 说明
粒子数量 250000 粒子总数
分支数量 6 星系分支数
分支半径 5 分支半径
旋转角度 0.2 旋转角度
内颜色 #ff812e 内部颜色
外颜色 #a668ff 外部颜色

核心代码解析

生成银河

javascript 复制代码
const generateGalaxy = () => {
    if (points) {
        geometry.dispose();
        material.dispose();
        scene.remove(points);
    }

    const positions = new Float32Array(params.particleCount * 3);
    const colors = new Float32Array(params.particleCount * 3);
    const innerColor = new THREE.Color(params.innerColor);
    const outerColor = new THREE.Color(params.outerColor);
    
    for (let i = 0; i < params.particleCount; i++) {
        const i3 = i * 3;

        const radius = params.branchRadius * Math.random();
        const branchAngle = ((i % params.branches) / params.branches) * Math.PI * 2;
        const spinAngle = params.spin * radius * Math.PI * 2;

        const randRadius = Math.random() * params.radialRandomness * radius;
        const { x: randX, y: randY, z: randZ } = getRandomPolarCoordinate(randRadius);

        positions[i3] = radius * Math.cos(branchAngle + spinAngle) + randX;
        positions[i3 + 1] = randY;
        positions[i3 + 2] = radius * Math.sin(branchAngle + spinAngle) + randZ;

        const mixedColor = innerColor.clone().lerp(outerColor, radius / params.branchRadius);
        colors[i3] = mixedColor.r;
        colors[i3 + 1] = mixedColor.g;
        colors[i3 + 2] = mixedColor.b;
    }

    material = new THREE.PointsMaterial({
        size: params.particleSize,
        sizeAttenuation: true,
        depthWrite: false,
        blending: THREE.AdditiveBlending,
        vertexColors: true,
        map: particleTexture,
        transparent: true,
    });

    geometry = new THREE.BufferGeometry();
    geometry.setAttribute("position", new THREE.BufferAttribute(positions, 3));
    geometry.setAttribute("color", new THREE.BufferAttribute(colors, 3));

    points = new THREE.Points(geometry, material);
    scene.add(points);
};

随机极坐标

javascript 复制代码
const getRandomPolarCoordinate = (radius) => {
    const theta = Math.random() * Math.PI * 2;
    const phi = Math.random() * Math.PI * 2;
    const x = radius * Math.sin(theta) * Math.cos(phi);
    const y = radius * Math.sin(theta) * Math.sin(phi);
    const z = radius * Math.cos(theta);
    return { x, y, z };
}

技术亮点

  1. 银河星系:创建银河星系效果
  2. 螺旋分布:粒子围绕中心螺旋分布
  3. 分支结构:粒子分为多个分支
  4. 颜色渐变:粒子颜色从内到外渐变
  5. GUI 控制:使用 GUI 控制参数

调试技巧

  1. 粒子数量:调整粒子数量测试性能
  2. 分支数量:调整分支数量改变结构
  3. 旋转角度:调整旋转角度改变螺旋
  4. 颜色渐变:调整颜色渐变参数
  5. 随机性:调整随机性参数

扩展方向

  1. 多层银河:创建多层银河效果
  2. 不同形状:使用不同的星系形状
  3. 动画效果:添加旋转动画
  4. 交互控制:添加更多交互控制
  5. 复杂结构:创建更复杂的星系结构

本文档由 ThreeLab 编辑整理,如需转载,请注明出处。

相关推荐
福兮说7 分钟前
秋招简历让 AI 写了一版:它替我加了 JWT,还把课程设计写成了「高并发」
人工智能·课程设计·秋招·求职·简历
ZDN_is_beauty10 分钟前
深度学习2-卷积神经网络
人工智能·深度学习·cnn
kyriewen13 分钟前
我逐个测了 JSON.stringify 的 7 个坑:第 1 个就在丢数据
前端·javascript·程序员
QQ机器人_插件16 分钟前
鲲鹏恒控的跨平台交付 —— Windows 上组态,Linux 上运行
人工智能
XMAIPC_Robot17 分钟前
储能控制器产品化:ARM+FPGA整机高低温、EMC可靠性测试实战总结
arm开发·人工智能·fpga开发·arm+fpga·rk3588+fpga
Martina_032120 分钟前
AI生成的海岸城市一移动镜头,水面反射就跳?用6步统一反射探针、SSR与平面反射
图像处理·人工智能·平面·3d·ai·自然语言处理·游戏策划
北i28 分钟前
Dubbo 默认超时重试:把下游打雪崩的隐形放大器
开发语言·qt·dubbo
Matlab程序猿28 分钟前
【MATLAB源码-第459期】基于matlab的D-H模型与阻尼最小二乘逆运动学的六自由度机械臂五次轨迹规划及动力学前馈PD控制仿真。
人工智能·算法·matlab·d-h建模·六自由度串联机械臂
QYR-分析29 分钟前
人机交互升级浪潮下,全球电容式触摸传感器市场格局与细分赛道深度研判
人工智能·人机交互
10mAh39 分钟前
【Java】ArrayList 遍历删除为什么报错?三种写法与漏删复现
java·开发语言·windows