今天来学习下车床(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)的更多相关文章

  1. JS学习笔记10之Math对象

    -->Math对象 常用属性和方法-->使用Math对象制作相应的效果 Math对象用于执行数学任务 一.Math对象的属性: 二.Math对象的方法: 三.常用属性和方法: Math.P ...

  2. JS 学习笔记--9---变量-作用域-内存相关

    JS 中变量和其它语言中变量最大的区别就是,JS 是松散型语言,决定了它只是在某一个特定时间保存某一特定的值的一个名字而已.由于在定义变量的时候不需要显示规定必须保存某种类型的值,故变量的值以及保存的 ...

  3. WebGL three.js学习笔记 使用粒子系统模拟时空隧道(虫洞)

    WebGL three.js学习笔记 使用粒子系统模拟时空隧道 本例的运行结果如图: 时空隧道demo演示 Demo地址:https://nsytsqdtn.github.io/demo/sprite ...

  4. WebGL three.js学习笔记 法向量网格材质MeshNormalMaterial的介绍和创建360度全景天空盒的方法

    WebGL学习----Three.js学习笔记(5) 点击查看demo演示 Demo地址:https://nsytsqdtn.github.io/demo/360/360 简单网格材质 MeshNor ...

  5. vue.js 学习笔记3——TypeScript

    目录 vue.js 学习笔记3--TypeScript 工具 基础类型 数组 元组 枚举 字面量 接口 类类型 类类型要素 函数 函数参数 this对象和类型 重载 迭代器 Symbol.iterat ...

  6. JS学习笔记5_DOM

    1.DOM节点的常用属性(所有节点都支持) nodeType:元素1,属性2,文本3 nodeName:元素标签名的大写形式 nodeValue:元素节点为null,文本节点为文本内容,属性节点为属性 ...

  7. 基于jquery的插件turn.js学习笔记

    基于jquery的插件turn.js学习笔记 简介 turn.js是一个可以实现3d书籍展示效果的jq插件,使用html5和css3来执行效果.可以很好的适应于ios和安卓等触摸设备. How it ...

  8. 【转】Backbone.js学习笔记(二)细说MVC

    文章转自: http://segmentfault.com/a/1190000002666658 对于初学backbone.js的同学可以先参考我这篇文章:Backbone.js学习笔记(一) Bac ...

  9. SpringMVC:学习笔记(10)——整合Ckeditor且实现图片上传

    SpringMVC:学习笔记(10)——整合Ckeditor且实现图片上传 配置CKEDITOR 精简文件 解压之后可以看到ckeditor/lang下面有很多语言的js,如果不需要那么多种语言的,可 ...

  10. WebGL three.js学习笔记 6种类型的纹理介绍及应用

    WebGL three.js学习笔记 6种类型的纹理介绍及应用 本文所使用到的demo演示: 高光贴图Demo演示 反光效果Demo演示(因为是加载的模型,所以速度会慢) (一)普通纹理 计算机图形学 ...

随机推荐

  1. CTF实验吧认真一点 SQL盲注

    实验吧地址 http://ctf5.shiyanbar.com/web/earnest/index.php 很明显的返回两个不同得页面,判断为SQL盲注 并且 过滤了敏感字符 测试的时候还发现过滤了s ...

  2. 29.1K star!免费接入GPT-4/DeepSeek等顶级大模型,这个开源API神器绝了!

    嗨,大家好,我是小华同学,关注我们获得"最新.最全.最优质"开源项目和高效工作学习方法 还在为天价API费用发愁?这个开源项目让你免费畅用GPT-4.DeepSeek.Claude ...

  3. 使用了下UOS浏览器,突然不想说话了

    使用了UOS20,安装上了,但是要激活:我蒙了!好吧,适用下吧: 看下浏览器情况: UOS浏览器 5.1.2365.0 (正式版本) stable (64 位) 修订版本 3cfecd947e7bc5 ...

  4. MySQL同步ES的6种方案!

    引言 在分布式架构中,MySQL与Elasticsearch(ES)的协同已成为解决高并发查询与复杂检索的标配组合. 然而,如何实现两者间的高效数据同步,是架构设计中绕不开的难题. 这篇文章跟大家一起 ...

  5. HarmonyOS NEXT开发实战教程:聊天交友App

    一早醒来Mate70上热搜了,余承东发文宣布Mate70要在本月发布,史上最强手机终于要来了. 今天分享一个交友app实战教程,是幽蓝君用整整一个周末开发的,时间有限,只做了些皮毛,不是很完善,不过拿 ...

  6. 操作系统:Linux如何获取所有设备信息

    本节了解下Linux是如何管理设备的,将从Linux如何组织设备开始,然后研究设备相关的数据结构,最后写一个Linux设备驱动实例. 感受一下Linux下的设备信息 Linux的设计哲学是一起皆是文件 ...

  7. Django踩坑之在Django中创建项目时ImportError: No module named django.core

    不使用django-admin.py,而是使用django-admin.exe 具体操作如下 django-admin.exe startproject learning_log . ok,没有提示错 ...

  8. LogStash介绍及二进制安装

    概述 官方文档:https://www.elastic.co/guide/en/logstash/7.17/introduction.html Logstash 是一款开源数据收集引擎,具备实时流水线 ...

  9. 偶斐波那契数列性质与欧拉计划第2题 Properties of Even Fibonacci numbers and Project Euler problems 2

    Problem 2 Even Fibonacci numbers Each new term in the Fibonacci sequence is generated by adding the ...

  10. 快速创建SQL Server 链接服务器

    SQL Server链接服务器简介 SQL Server提供链接到另一个服务器的选项.这通常被用来连接到其他SQL Server数据库,但它也可以被用来连接到一个Microsoft Access数据库 ...