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

相关推荐
江城开朗的豌豆41 分钟前
退出登录后头像还在?这个缓存问题坑过多少前端!
前端·javascript·vue.js
江城开朗的豌豆1 小时前
Vue的'读心术':它怎么知道数据偷偷变了?
前端·javascript·vue.js
江城开朗的豌豆1 小时前
手把手教你造一个自己的v-model:原来双向绑定这么简单!
前端·javascript·vue.js
江城开朗的豌豆1 小时前
v-for中key值的作用:为什么我总被要求加这个'没用的'属性?
前端·javascript·vue.js
goldenocean2 小时前
React之旅-05 List Key
前端·javascript·react.js
Mintopia3 小时前
像素的进化史诗:计算机图形学与屏幕的千年之恋
前端·javascript·计算机图形学
Mintopia3 小时前
Three.js 中三角形到四边形的顶点变换:一场几何的华丽变身
前端·javascript·three.js
归于尽4 小时前
async/await 从入门到精通,解锁异步编程的优雅密码
前端·javascript
晓13134 小时前
JavaScript加强篇——第六章 定时器(延时函数)与JS执行机制
开发语言·javascript·ecmascript