babylonjs基于自定义网格生成围栏动画

效果:

javascript 复制代码
import { Vector3, Mesh, MeshBuilder, StandardMaterial, Texture, Animation, Color3 } from "@babylonjs/core";
import imgUrl from "./image/headerwangge2.png"
// 创建模型护栏特效
export default class CreateRail {
    constructor(scene,) {
        this.scene = scene;
    };
    create() {
        let _position = [{x:1,y:1,z:1},{x:2,y:2,z:2}]
        if (_position.length <= 0) {
            return;
        }
        var mat = new StandardMaterial("mat", this.scene);
        mat.diffuseTexture = new Texture(imgUrl, this.scene);
        mat.diffuseTexture.vScale = 5;
        mat.diffuseTexture.hasAlpha = true;
        mat.backFaceCulling = false;
        mat.emissiveColor = Color3.White()
        const path = []
        for (let index = 0; index < _position.length - 1; index += 1) {
            path.push(new Vector3(_position[index].x, _position[index].y, _position[index].z));
            path.push(new Vector3(_position[index + 1].x, _position[index + 1].y, _position[index + 1].z));
        }
        let polygon = MeshBuilder.CreatePolygon("polygon", { shape: path, holes: [path], depth: 10, sideOrientation: Mesh.DOUBLESIDE }, this.scene);
        polygon.position.y = 10
        polygon.material = mat;
        Animation.CreateAndStartAnimation("ani", mat, "diffuseTexture.vOffset", 30, 20,
            1, 0, 1, undefined, undefined, this.scene);

    };

}

贴图 headerwangge2

相关推荐
gnip24 分钟前
可重试接口请求
前端·javascript
gnip39 分钟前
滚动元素到可视区
前端·javascript
归辞...43 分钟前
「iOS」————单例与代理
开发语言·javascript·ios
JSON_L2 小时前
Vue 详情模块 3
前端·javascript·vue.js
flashlight_hi2 小时前
LeetCode 分类刷题:2824. 统计和小于目标的下标对数目
javascript·数据结构·算法·leetcode
流星先生!3 小时前
前端小数点处理
开发语言·前端·javascript
雪芽蓝域zzs3 小时前
uniapp 数组的用法
前端·javascript·uni-app
博客zhu虎康4 小时前
React18 严格模式下的双重渲染之谜
javascript·react.js·ecmascript
呼啦啦圈4 小时前
get请求中文字符参数乱码问题
java·javascript
ZzMemory4 小时前
JavaScript 类数组:披着数组外衣的 “伪装者”?
前端·javascript·面试