今天来学习下车床(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. SpringBoot整合Web层技术

    目录 1 SpringBoot整合Web层技术 1.1 SpringBoot整合Servlet 1.1.1 方式一 通过注解扫描完成Servlet组件的注册 1.1.1.1 创建Servlet 1.1 ...

  2. 【记录】Prompt模板|作为甲方怎么清晰专业地描述自己的需求(又名“乙方,给你的甲方扔个GPT解放自己吧”)

    这篇Prompt摘抄并修改自朋友送给我的书的第49页5.2.3让ChatGPT构建提示,质量挺不错,支持一下她的博客:[好书推荐2]AI提示工程实战:从零开始利用提示工程学习应用大语言模型. 书长这样 ...

  3. TPLINK路由器重启脚本(软件版本3.0.0)

    ​ 家中的两个路由器全都是TPLink路由器,由于总出现时间一长就网卡的原因,写了这个重启脚本在每天凌晨五点的时候对路由器进行自动重启 使用方法: ​ self.logindata的值为登录时的jso ...

  4. React-Native开发鸿蒙NEXT-图片上传

    .markdown-body { line-height: 1.75; font-weight: 400; font-size: 16px; overflow-x: hidden; color: rg ...

  5. FileChooser文件保存样例

    FileChooser fc = new FileChooser();fc.setTitle("请选择文件保存位置");fc.setInitialDirectory($原始文件位置 ...

  6. 如何用Leangoo破解需求隔离与频繁变更的协作困局?

    作为一位经历过"需求文档满天飞.系统各自为战"的研发负责人,我深知团队在需求频繁变更时面临的痛点--信息割裂导致响应滞后.优先级混乱引发返工.协作低效拖慢交付节奏. 近期,我深度测 ...

  7. docker-compose用法

    以下的示例搭建龙一个wordpress博客 services: mysql: image: mysql:latest environment: - MYSQL_ROOT_PASSWORD=123456 ...

  8. Informer架构以及简单使用

    Informer架构以及简单使用 介绍 我们知道可以使用 Clientset 来获取所有的原生资源对象,那么如果我们想要去一直获取集群的资源对象数据呢?岂不是需要用一个轮询去不断执行 List() 操 ...

  9. 20w奖金池!魔乐社区国产算力应用创新大赛正式启程

    本文分享自魔乐社区公众号<​​20w奖金池!魔乐社区国产算力应用创新大赛正式启程​​> 当国产算力崛起成为 AI 发展新引擎,你是否渴望用创新方案解锁无限可能?魔乐社区国产算力应用创新大赛 ...

  10. pytorch入门 - GoogLeNet神经网络

    GoogLeNet 是 Google 在 2014 年 ILSVRC(ImageNet Large Scale Visual Recognition Challenge)比赛中提出的一种深度卷积神经网 ...