babylon.js 3D人物动画实现(blender 制作)

1、前言

首先你得要有个模型,需要符合 mixamo 所需的格式。

本文将会用 moxamo 生成多个动画,然后使用 blender 合并到一个模型中,然后使用 babylonjs 进行调用。

2、mixamo 制作动画

在线免费制作动画,https://www.mixamo.com/

image.png

3、用 Blender 合并动画到一个角色

动画制作完毕后导入到 blender 中,我制作了三个动画。
image.png

给每个动画都改个名字,不然一会分不清。

image.png

多余的元素删除,只保留一个动画就行

image.png

删除完毕后
image.png

左下角的视图注意要选择“非线性动画”
image.png

4、添加动画

image.png
image.png

5、导出

选择全部后导出为 glb
image.png

6、到 babylon 提供的测试页面播放动画测试

https://sandbox.babylonjs.com/

image.png

7、使用 babylon 渲染模型

babylon 渲染模型是相当简单的。只需要加载引擎和对应的模型loader就行。然后直接拿到动画进行播放即可。

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Babylon Template</title>

    <style>  
        html,
        body { 
            width: 100%;
            height: 100%;
            margin: 0;
            padding: 0; 
        }

        #renderCanvas {
            width: 100%;
            height: 100%;
            touch-action: none;
        }
    </style>

    <script src="./babylon.js"></script>
    <script src="./glTFFileLoader.js"></script>

</head>

<body>

    <canvas id="renderCanvas"></canvas>

    <script>
        const canvas = document.getElementById("renderCanvas"); // Get the canvas element
        const engine = new BABYLON.Engine(canvas, true); // Generate the BABYLON 3D engine
        
        const scene = test();

        // Register a render loop to repeatedly render the scene
        engine.runRenderLoop(function () {
            scene.render();
        });
        // Watch for browser/canvas resize events
        window.addEventListener("resize", function () {
            engine.resize();
        });

 
        function test() { 
            var scene = new BABYLON.Scene(engine); 
            const camera = new BABYLON.FreeCamera("camera", new BABYLON.Vector3(0, 0, 0), scene);

            BABYLON.SceneLoader.ImportMesh("", "./models/ani/", "test.glb", scene, function (newMeshes, particleSystems, skeletons, animationGroups) {
                const hero = newMeshes[0]; 
                var skeleton = skeletons[0];

                scene.createDefaultCameraOrLight(true, true, true); 
                console.log(hero, skeleton, animationGroups) 
                const dh_0 = scene.getAnimationGroupByName("dh_0");
                const dh_1 = scene.getAnimationGroupByName("dh_1");
                const dh_2 = scene.getAnimationGroupByName("dh_2");
                dh_1.start(true, 1.0, dh_1.from, dh_1.to, false);
  
            });

            return scene;
        }
    </script>

</body>

</html>

效果
image.png

  • 5
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
Babylon.js提供了一些内置的工具来生成柏林噪声、Worley噪声和分形噪声。下面是一些示例代码: 1. 生成柏林噪声: ```javascript // 创建一个柏林噪声纹理 var noiseTexture = new BABYLON.NoiseProceduralTexture("noise", 256, scene); // 设置柏林噪声的类型和参数 noiseTexture.animationSpeedFactor = 5; noiseTexture.persistence = 0.9; noiseTexture.brightness = 0.1; noiseTexture.octaves = 4; // 将柏林噪声纹理应用到一个平面上 var plane = BABYLON.Mesh.CreatePlane("plane", 10, scene); var mat = new BABYLON.StandardMaterial("mat", scene); mat.diffuseTexture = noiseTexture; plane.material = mat; ``` 2. 生成Worley噪声: ```javascript // 创建一个Worley噪声纹理 var noiseTexture = new BABYLON.WorleyNoiseProceduralTexture("noise", 256, scene); // 设置Worley噪声的类型和参数 noiseTexture.animationSpeedFactor = 5; noiseTexture.distanceFunction = BABYLON.WorleyNoiseProceduralTexture.EUCLIDIAN_DISTANCE; noiseTexture.cellsDensity = 2.0; // 将Worley噪声纹理应用到一个平面上 var plane = BABYLON.Mesh.CreatePlane("plane", 10, scene); var mat = new BABYLON.StandardMaterial("mat", scene); mat.diffuseTexture = noiseTexture; plane.material = mat; ``` 3. 生成分形噪声: ```javascript // 创建一个分形噪声纹理 var noiseTexture = new BABYLON.FractalNoiseProceduralTexture("noise", 256, scene); // 设置分形噪声的类型和参数 noiseTexture.animationSpeedFactor = 5; noiseTexture.type = BABYLON.FractalNoiseType.FBM; noiseTexture.persistence = 0.6; noiseTexture.octaves = 4; // 将分形噪声纹理应用到一个平面上 var plane = BABYLON.Mesh.CreatePlane("plane", 10, scene); var mat = new BABYLON.StandardMaterial("mat", scene); mat.diffuseTexture = noiseTexture; plane.material = mat; ``` 这些示例代码演示了如何在Babylon.js中生成柏林噪声、Worley噪声和分形噪声,并将它们应用到一个平面上。你可以通过修改参数和设置不同的纹理类型来创建自己的噪声效果。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小明IO

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值