模型fbx拖拽到場景并賦予腳本上SkinnedMeshRenderer參數 按下空格即可演示漸變
可去到3DsMax 或 Blender等軟件制作 這種帶有BlendShapes的模型 (Sphere002)是另一個模型,3DsMax叫變形器。
可參考:【技術美術百人計劃】美術 3.5 BlendShape基礎_嗶哩嗶哩_bilibili
變形器大概用法:
1. 先復制一份這個原本的模型,拉到旁邊,并編輯這個復制體,改改頂點(編輯頂點)
2. 原本的模型 添加變形器,? 如上圖 點擊空的位置 右鍵 選中?場景中的復制體。
3. 選中要導出的模型? 文件 - 導出 - 導出選定對象 ,后面要注意勾選變形 默認勾選的
假如不勾選變形會發生如下事情:
導出的fbx 放入Unity會發現沒有BlendShapes 取而代之的是一個普通的MeshRenderer模型?
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 完成動畫!");}}}
}