【Unity】模型渐变技术 BlendShapes变形

模型fbx拖拽到场景并赋予脚本上SkinnedMeshRenderer参数 按下空格即可演示渐变

可去到3DsMax 或 Blender等软件制作 这种带有BlendShapes的模型 (Sphere002)是另一个模型,3DsMax叫变形器。

可参考:【技术美术百人计划】美术 3.5 BlendShape基础_哔哩哔哩_bilibili

变形器大概用法:

  1. 先复制一份这个原本的模型,拉到旁边,并编辑这个复制体,改改顶点(编辑顶点)

  1. 原本的模型 添加变形器, 如上图 点击空的位置 右键 选中 场景中的复制体。

  2. 选中要导出的模型 文件 - 导出 - 导出选定对象 ,后面要注意勾选变形 默认勾选的

假如不勾选变形会发生如下事情:

导出的fbx 放入Unity会发现没有BlendShapes 取而代之的是一个普通的MeshRenderer模型

cs 复制代码
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class BlendShapesTest : MonoBehaviour
{
    public SkinnedMeshRenderer skinMesh;
    public float speed = 4f;
    public float timer;
    public bool isPlaying;
    public int dir = 1;
    private int index;

    private void Awake()
    {
        index = skinMesh.sharedMesh.GetBlendShapeIndex("Sphere002");
        Debug.Log("index:"  + index);
    }

    void Update()
    {
        //按下空格 进行A->B 或 B->A渐变模型
        if (!isPlaying && Input.GetKeyDown(KeyCode.Space))
        {
            isPlaying = true;
            float weight = skinMesh.GetBlendShapeWeight(index);
            if (weight <= 0)
            {
                dir = 1;
                skinMesh.SetBlendShapeWeight(index, 0f);
                timer = 0;
                Debug.Log("开始动画 0 -> 100");
            }
            else
            {
                dir = -1;
                skinMesh.SetBlendShapeWeight(index, 100f);
                timer = 100f;
                Debug.Log("开始动画 100 -> 0");
            }
        }

        if (isPlaying)
        {
            timer += Time.deltaTime * dir * speed;
            skinMesh.SetBlendShapeWeight(index, timer);
            if (dir == 1 && timer >= 100)
            {
                skinMesh.SetBlendShapeWeight(index, 100);
                isPlaying = false;
                Debug.Log("0 -> 100 完成动画!");
            }
            else if (dir == -1 && timer <= 0)
            {
                skinMesh.SetBlendShapeWeight(index, 0);
                isPlaying = false;
                Debug.Log("100 -> 0 完成动画!");
            }
        }
    }
}
相关推荐
jtymyxmz10 小时前
《Unity Shader》6.4.3 半兰伯特模型
unity·游戏引擎
AA陈超10 小时前
ASC学习笔记0001:处理目标选择系统中当Actor拒绝目标确认时的调用
c++·笔记·学习·游戏·ue5·游戏引擎·虚幻
我的golang之路果然有问题12 小时前
mac配置 unity+vscode的坑
开发语言·笔记·vscode·macos·unity·游戏引擎
于小汐在咯13 小时前
【虚拟现实技术】在Unity里创建一个简单的AR项目
unity·ar·vr
HahaGiver66616 小时前
Unity Shader Graph 3D 实例 - 一个简单的红外线扫描全身效果
3d·unity·游戏引擎
o***Z44817 小时前
免费的WebAssembly游戏引擎,AssemblyScript
游戏引擎·wasm
雪下的新火1 天前
Blender:法线图&黑白图
游戏·unity·游戏引擎·blender·笔记分享
HahaGiver6661 天前
从0到1做一个“字母拼词”Unity小游戏(含源码/GIF)- 实现多单词顺序通关进度逻辑
unity·游戏引擎·游戏程序
Dr.勿忘2 天前
Unity一分钟思路---UI任务条:宝箱位置如何准确卡在百分比位置上
ui·unity·游戏程序·屏幕适配
weixin_424294672 天前
Unity 实现 ScrollBar 值变化控制 Panel 位置的方法
unity·游戏引擎