魔法阵
Magic Circle

你将学到什么
- Scene / Camera / Renderer 渲染管线
- 相机交互控制器
- 粒子 / 点云 / 实例化渲染
效果说明
Three.js WebGL 场景,粒子或点云特效,技术点:BufferGeometry。打开在线案例可查看最终画面。
核心概念
- Scene 容纳对象,Camera 定义视点,WebGLRenderer 输出 canvas。
- OrbitControls 轨道旋转缩放;开启阻尼时每帧
controls.update()。 - 大量点用 BufferGeometry + Points 或 InstancedMesh 合批,避免逐 Entity 创建。
实现步骤
- 初始化 Viewer 或 Scene / Camera / Renderer
- 创建 OrbitControls 并处理 resize
- 构建几何 attribute 或 instanceMatrix 并 add 到 scene
代码要点
js
this.options = options;
this.scene = new THREE.Scene();
this.clock = new THREE.Clock();
this.animates = {};
const k = dom.clientWidth / dom.clientHeight;
if ("fov" in options.cameraOptions) {
this.defaultCamera = new THREE.PerspectiveCamera(options.cameraOptions.fov, k, options.cameraOptions.near, options.cameraOptions.far);
}
else {
this.scene = new THREE.Scene();
this.clock = new THREE.Clock();
this.animates = {};
const k = dom.clientWidth / dom.clientHeight;
if ("fov" in options.cameraOptions) {
this.defaultCamera = new THREE.PerspectiveCamera(options.cameraOptions.fov, k, options.cameraOptions.near, options.cameraOptions.far);
}
else {
const s = options.cameraOptions.s;完整源码:GitHub
小结
应用场景 · Three.js · 2/68
