babylon.js 学习笔记(10)
今天来学习下车床(lathe)建型及粒子系统,babylon.js有一个很强大的函数CreateLathe,可以将一段路径经过旋转后,形成1个shape,这么说有点抽象,比如下面这张图:

其中的关键点坐标为:
const fountainProfile = [
new BABYLON.Vector3(0, 0, 0),
new BABYLON.Vector3(10, 0, 0),
new BABYLON.Vector3(10, 4, 0),
new BABYLON.Vector3(8, 4, 0),
new BABYLON.Vector3(8, 1, 0),
new BABYLON.Vector3(1, 2, 0),
new BABYLON.Vector3(1, 15, 0),
new BABYLON.Vector3(3, 17, 0)
];
调用CreateLathe后:
const fountain = BABYLON.MeshBuilder.CreateLathe("fountain", { shape: fountainProfile, sideOrientation: BABYLON.Mesh.DOUBLESIDE }, scene);

再给几个示例:
const fountainProfile = [
new BABYLON.Vector3(0, 0, 0),
new BABYLON.Vector3(10, 0, 0),
new BABYLON.Vector3(10, 4, 0),
new BABYLON.Vector3(8, 4, 0),
new BABYLON.Vector3(8, 1, 0),
new BABYLON.Vector3(1, 2, 0),
new BABYLON.Vector3(1, 15, 0),
new BABYLON.Vector3(3, 17, 0)
]; const myShape = [
new BABYLON.Vector3(3, 0, 0),
new BABYLON.Vector3(10, 5, 0),
new BABYLON.Vector3(5, 10, 0),
new BABYLON.Vector3(12, 15, 0),
new BABYLON.Vector3(3, 20, 0)
]; const createScene = function () {
const scene = new BABYLON.Scene(engine); const camera = new BABYLON.ArcRotateCamera("Camera", 3 * Math.PI / 2, Math.PI / 2.5, 70, BABYLON.Vector3.Zero());
camera.attachControl(canvas, true); const light = new BABYLON.HemisphericLight("hemi", new BABYLON.Vector3(0, 1, 0)); //Create lathe1
const fountain = BABYLON.MeshBuilder.CreateLathe("fountain", { shape: fountainProfile, sideOrientation: BABYLON.Mesh.DOUBLESIDE }, scene); //Create lathe2
const lathe1 = BABYLON.MeshBuilder.CreateLathe("lathe1", { shape: myShape, sideOrientation: BABYLON.Mesh.DOUBLESIDE });
lathe1.position.x = -30;
lathe1.scaling = new BABYLON.Vector3(0.75, 0.75, 0.75); //Create lathe3
const lathe2 = BABYLON.MeshBuilder.CreateLathe("lathe2", { shape: myShape, closed: false, arc: 0.75, sideOrientation: BABYLON.Mesh.DOUBLESIDE });
lathe2.position.x = 30;
lathe2.scaling = new BABYLON.Vector3(0.75, 0.75, 0.75); showAxis(24, scene);
return scene;
}

最右侧的残缺效果,主要是 closed: false, arc: 0.75 这2个参数起了作用。
在线地址:https://yjmyzz.github.io/babylon_js_study/day10/01.html
接下来看看粒子系统,直接上代码,建议大家调整下这里面的参数,感受不同的效果:
const createScene = function () {
const scene = new BABYLON.Scene(engine);
const camera = new BABYLON.ArcRotateCamera("Camera", 3 * Math.PI / 2, Math.PI / 2.5, 70, BABYLON.Vector3.Zero());
camera.attachControl(canvas, true);
const light = new BABYLON.HemisphericLight("hemi", new BABYLON.Vector3(0, 1, 0));
// 创建粒子系统
var particleSystem = new BABYLON.ParticleSystem("particles", 5000, scene);
//粒子的纹理图片
particleSystem.particleTexture = new BABYLON.Texture("../assets/img/flare.png", scene);
//粒子的发射距离
particleSystem.emitter = new BABYLON.Vector3(0, 5, 0); // the starting object, the emitter
particleSystem.minEmitBox = new BABYLON.Vector3(-1, -5, 0); // Starting all from
particleSystem.maxEmitBox = new BABYLON.Vector3(1, -5, 0); // To...
//粒子颜色
particleSystem.color1 = new BABYLON.Color4(0.7, 0.8, 1.0, 1.0);
particleSystem.color2 = new BABYLON.Color4(0.2, 0.5, 1.0, 1.0);
particleSystem.colorDead = new BABYLON.Color4(0, 0, 0.2, 0.0);
//粒子大小
particleSystem.minSize = 0.1;
particleSystem.maxSize = 0.6;
//粒子存在的生命周期(时长)
particleSystem.minLifeTime = 2;
particleSystem.maxLifeTime = 3.8;
//发射速率
particleSystem.emitRate = 1500;
//混合模式 : BLENDMODE_ONEONE, or BLENDMODE_STANDARD
particleSystem.blendMode = BABYLON.ParticleSystem.BLENDMODE_ONEONE;
//重力值
particleSystem.gravity = new BABYLON.Vector3(0, -9.81, 0);
//发射方向
particleSystem.direction1 = new BABYLON.Vector3(-3, 8, 3);
particleSystem.direction2 = new BABYLON.Vector3(3, 8, -3);
//角度、半径
particleSystem.minAngularSpeed = 0;
particleSystem.maxAngularSpeed = Math.PI;
//速度及力度大小
particleSystem.minEmitPower = 1;
particleSystem.maxEmitPower = 2.2;
particleSystem.updateSpeed = 0.025;
//开喷
particleSystem.start();
return scene;
}
其中flare.jpg长这样:

上面这段代码跑出来,效果是这样的:

在线地址:https://yjmyzz.github.io/babylon_js_study/day10/02.html
把今天学到的2个知识点,结合一下,就变成这样:
const fountainProfile = [
new BABYLON.Vector3(0, 0, 0),
new BABYLON.Vector3(10, 0, 0),
new BABYLON.Vector3(10, 4, 0),
new BABYLON.Vector3(8, 4, 0),
new BABYLON.Vector3(8, 1, 0),
new BABYLON.Vector3(1, 2, 0),
new BABYLON.Vector3(1, 15, 0),
new BABYLON.Vector3(3, 17, 0)
]; const createScene = function () {
const scene = new BABYLON.Scene(engine); const camera = new BABYLON.ArcRotateCamera("Camera", 3 * Math.PI / 2, Math.PI / 2.5, 70, BABYLON.Vector3.Zero());
camera.attachControl(canvas, true); const light = new BABYLON.HemisphericLight("hemi", new BABYLON.Vector3(0, 1, 0)); const fountain = BABYLON.MeshBuilder.CreateLathe("fountain", { shape: fountainProfile, sideOrientation: BABYLON.Mesh.DOUBLESIDE }, scene);
fountain.position.y = -15; // Create a particle system
var particleSystem = new BABYLON.ParticleSystem("particles", 5000, scene); //Texture of each particle
particleSystem.particleTexture = new BABYLON.Texture("../assets/img/flare.png", scene); // Where the particles come from
particleSystem.emitter = new BABYLON.Vector3(0, 5, 0); // the starting object, the emitter
particleSystem.minEmitBox = new BABYLON.Vector3(-1, -5, 0); // Starting all from
particleSystem.maxEmitBox = new BABYLON.Vector3(1, -5, 0); // To... // Colors of all particles
particleSystem.color1 = new BABYLON.Color4(0.7, 0.8, 1.0, 1.0);
particleSystem.color2 = new BABYLON.Color4(0.2, 0.5, 1.0, 1.0);
particleSystem.colorDead = new BABYLON.Color4(0, 0, 0.2, 0.0); // Size of each particle (random between...
particleSystem.minSize = 0.1;
particleSystem.maxSize = 0.6; // Life time of each particle (random between...
particleSystem.minLifeTime = 2;
particleSystem.maxLifeTime = 3.8; // Emission rate
particleSystem.emitRate = 1500; // Blend mode : BLENDMODE_ONEONE, or BLENDMODE_STANDARD
particleSystem.blendMode = BABYLON.ParticleSystem.BLENDMODE_ONEONE; // Set the gravity of all particles
particleSystem.gravity = new BABYLON.Vector3(0, -9.81, 0); // Direction of each particle after it has been emitted
particleSystem.direction1 = new BABYLON.Vector3(-3, 8, 3);
particleSystem.direction2 = new BABYLON.Vector3(3, 8, -3); // Angular speed, in radians
particleSystem.minAngularSpeed = 0;
particleSystem.maxAngularSpeed = Math.PI; // Speed
particleSystem.minEmitPower = 1;
particleSystem.maxEmitPower = 2.2;
particleSystem.updateSpeed = 0.025; // Start the particle system
particleSystem.start(); return scene;
}

在线地址:https://yjmyzz.github.io/babylon_js_study/day10/03.html
还可以给这个喷泉加点交互,鼠标点击到喷泉时,切换喷发

在线地址:https://yjmyzz.github.io/babylon_js_study/day10/03_b.html
官网还有很多粒子系统的精彩示例,感兴趣的同学可以深入研究:

在线地址:https://yjmyzz.github.io/babylon_js_study/day10/04.html

在线地址:https://yjmyzz.github.io/babylon_js_study/day10/06.html

在线地址:https://yjmyzz.github.io/babylon_js_study/day10/05.html
babylon.js 学习笔记(10)的更多相关文章
- JS学习笔记10之Math对象
-->Math对象 常用属性和方法-->使用Math对象制作相应的效果 Math对象用于执行数学任务 一.Math对象的属性: 二.Math对象的方法: 三.常用属性和方法: Math.P ...
- JS 学习笔记--9---变量-作用域-内存相关
JS 中变量和其它语言中变量最大的区别就是,JS 是松散型语言,决定了它只是在某一个特定时间保存某一特定的值的一个名字而已.由于在定义变量的时候不需要显示规定必须保存某种类型的值,故变量的值以及保存的 ...
- WebGL three.js学习笔记 使用粒子系统模拟时空隧道(虫洞)
WebGL three.js学习笔记 使用粒子系统模拟时空隧道 本例的运行结果如图: 时空隧道demo演示 Demo地址:https://nsytsqdtn.github.io/demo/sprite ...
- WebGL three.js学习笔记 法向量网格材质MeshNormalMaterial的介绍和创建360度全景天空盒的方法
WebGL学习----Three.js学习笔记(5) 点击查看demo演示 Demo地址:https://nsytsqdtn.github.io/demo/360/360 简单网格材质 MeshNor ...
- vue.js 学习笔记3——TypeScript
目录 vue.js 学习笔记3--TypeScript 工具 基础类型 数组 元组 枚举 字面量 接口 类类型 类类型要素 函数 函数参数 this对象和类型 重载 迭代器 Symbol.iterat ...
- JS学习笔记5_DOM
1.DOM节点的常用属性(所有节点都支持) nodeType:元素1,属性2,文本3 nodeName:元素标签名的大写形式 nodeValue:元素节点为null,文本节点为文本内容,属性节点为属性 ...
- 基于jquery的插件turn.js学习笔记
基于jquery的插件turn.js学习笔记 简介 turn.js是一个可以实现3d书籍展示效果的jq插件,使用html5和css3来执行效果.可以很好的适应于ios和安卓等触摸设备. How it ...
- 【转】Backbone.js学习笔记(二)细说MVC
文章转自: http://segmentfault.com/a/1190000002666658 对于初学backbone.js的同学可以先参考我这篇文章:Backbone.js学习笔记(一) Bac ...
- SpringMVC:学习笔记(10)——整合Ckeditor且实现图片上传
SpringMVC:学习笔记(10)——整合Ckeditor且实现图片上传 配置CKEDITOR 精简文件 解压之后可以看到ckeditor/lang下面有很多语言的js,如果不需要那么多种语言的,可 ...
- WebGL three.js学习笔记 6种类型的纹理介绍及应用
WebGL three.js学习笔记 6种类型的纹理介绍及应用 本文所使用到的demo演示: 高光贴图Demo演示 反光效果Demo演示(因为是加载的模型,所以速度会慢) (一)普通纹理 计算机图形学 ...
随机推荐
- 北京市第六届信息通信行业网络安全技能大赛(初赛)-CTF夺旗阶段 EZRSA writeup
题目EZRSA EZRSA.py from Crypto.Util.number import * import gmpy2 from flag import m p = getPrime(1024) ...
- Canvas、客户端、表单
Canvas var canvas = document.querySelector('.myCanvas'); var width = canvas.width = window.innerWidt ...
- Java Objects.equals(a,b)的说明
一:值是null的情况: a.equals(b), a 是null, 抛出NullPointException异常. a.equals(b), a不是null, b是null, 返回false Obj ...
- “Pocket Flow,一个仅用 100 行代码实现的 LLM 框架”
PocketFlow介绍 PocketFlow是我最近在探索的一个LLM 框架,我觉得很有意思,因此推荐给大家. 这个框架最大的特点就是:"Pocket Flow,一个仅用 100 行代码实 ...
- TVM:使用张量表达式处理算子
在本教程中,把注意力转向 TVM 如何使用张量表达式(Tensor Expression,简称 TE)定义张量计算并应用循环优化.TE 以纯函数式语言描述张量计算(即每个表达式都没有副作用).从 TV ...
- Friend Circles(dfs)——LeetCode进阶路
原题链接https://leetcode.com/problems/friend-circles/ 题目描述 There are N students in a class. Some of them ...
- XML注入
XML注入 复现使用的题目为buuoj中的[NCTF2019]Fake XML cookbook 1和[NCTF2019]True XML cookbook 1 参考链接为https://xz.ali ...
- Spring Boot线程池简单监控|转
背景 在我们实际项目开发中,常常会为不同优先级的任务设置相对应的线程池.一般我们只关注相关池的相关参数如核心线程数据,最大线程数据等等参数,容易忽略了对线程池中实际运行情况的监控. 综上所述:线程 ...
- MySQL 主从延迟导致业务数据不一致
场景: 写入一条优惠劵数据,然后将该优惠劵信息读取出来同步给下游数据 现象: 本地写入优惠劵数据成功,同步信息成功.上周同步数据代码正常,周末改了发送优惠劵的信息,然后周一来了发现同步数据无法同步. ...
- ARCHIV_CREATE_FILE 员工头像上传
*&---------------------------------------------------------------------* *& Report ZHRR_011 ...