add Facial Support
This commit is contained in:
@@ -32,7 +32,46 @@ namespace Gallop
|
||||
public void SetPhysics()
|
||||
{
|
||||
List<Transform> gameObjects = new List<Transform>();
|
||||
gameObjects.AddRange(transform.parent.GetComponentsInChildren<Transform>());
|
||||
Dictionary<string, DynamicBoneColliderBase> DynamicBoneColliders = new Dictionary<string, DynamicBoneColliderBase>();
|
||||
gameObjects.AddRange(transform.parent.GetComponentsInChildren<Transform>());
|
||||
foreach (CySpringCollisionData collider in collisionParam)
|
||||
{
|
||||
if (collider._isInner) continue;
|
||||
|
||||
var bone = gameObjects.Find(a => { return a.name == collider._targetObjectName; });
|
||||
if (bone)
|
||||
{
|
||||
|
||||
var child = new GameObject(collider._collisionName);
|
||||
child.transform.SetParent(bone);
|
||||
child.transform.localPosition = Vector3.zero;
|
||||
child.transform.localRotation = Quaternion.identity;
|
||||
child.transform.localScale = Vector3.one;
|
||||
|
||||
switch (collider._type){
|
||||
case CySpringCollisionData.CollisionType.Capsule:
|
||||
case CySpringCollisionData.CollisionType.Sphere:
|
||||
var dynamic = child.AddComponent<DynamicBoneCollider>();
|
||||
dynamic.ColliderName = collider._collisionName;
|
||||
dynamic.m_Center = collider._offset;
|
||||
dynamic.m_Radius = collider._radius;
|
||||
dynamic.m_Height = collider._distance;
|
||||
dynamic.m_Bound = collider._isInner ? DynamicBoneColliderBase.Bound.Inside : DynamicBoneColliderBase.Bound.Outside;
|
||||
DynamicBoneColliders.Add(collider._collisionName,dynamic);
|
||||
break;
|
||||
case CySpringCollisionData.CollisionType.Plane:
|
||||
var planedynamic = child.AddComponent<DynamicBonePlaneCollider>();
|
||||
planedynamic.ColliderName = collider._collisionName;
|
||||
planedynamic.m_Center = collider._offset*0.1f;
|
||||
planedynamic.m_Bound = collider._isInner ? DynamicBoneColliderBase.Bound.Inside : DynamicBoneColliderBase.Bound.Outside;
|
||||
DynamicBoneColliders.Add(collider._collisionName, planedynamic);
|
||||
break;
|
||||
case CySpringCollisionData.CollisionType.None:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
foreach (CySpringParamDataElement spring in springParam)
|
||||
{
|
||||
@@ -41,6 +80,30 @@ namespace Gallop
|
||||
{
|
||||
var dynamic = bone.gameObject.AddComponent<DynamicBone>();
|
||||
dynamic.m_Root = bone;
|
||||
dynamic.m_Gravity = new Vector3(0, -spring._gravity/70000, 0);
|
||||
dynamic.m_Stiffness = spring._stiffnessForce/7000;
|
||||
dynamic.m_Elasticity = spring._dragForce/9000;
|
||||
dynamic.m_Radius = spring._collisionRadius;
|
||||
dynamic.m_Colliders = new List<DynamicBoneColliderBase>();
|
||||
foreach (string collisionName in spring._collisionNameList)
|
||||
{
|
||||
if(DynamicBoneColliders.TryGetValue(collisionName,out DynamicBoneColliderBase val))
|
||||
{
|
||||
if (!dynamic.m_Colliders.Contains(val))
|
||||
dynamic.m_Colliders.Add(val);
|
||||
}
|
||||
}
|
||||
foreach (CySpringParamDataChildElement Childcollision in spring._childElements)
|
||||
{
|
||||
foreach (string collisionName in Childcollision._collisionNameList)
|
||||
{
|
||||
if (DynamicBoneColliders.TryGetValue(collisionName, out DynamicBoneColliderBase val))
|
||||
{
|
||||
if(!dynamic.m_Colliders.Contains(val))
|
||||
dynamic.m_Colliders.Add(val);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -326,7 +326,8 @@ MonoBehaviour:
|
||||
m_EndOffset: {x: 0.1, y: -0.1, z: 0.3}
|
||||
m_Gravity: {x: 0, y: 0, z: 0}
|
||||
m_Force: {x: 0, y: 0, z: 0}
|
||||
m_Colliders: []
|
||||
m_Colliders:
|
||||
- {fileID: 789765167}
|
||||
m_Exclusions: []
|
||||
m_FreezeAxis: 0
|
||||
m_DistantDisable: 0
|
||||
@@ -414,6 +415,7 @@ MonoBehaviour:
|
||||
m_Colliders:
|
||||
- {fileID: 94102370}
|
||||
- {fileID: 838898607}
|
||||
- {fileID: 789765167}
|
||||
m_Exclusions: []
|
||||
m_FreezeAxis: 0
|
||||
m_DistantDisable: 0
|
||||
@@ -552,6 +554,119 @@ PrefabInstance:
|
||||
objectReference: {fileID: 0}
|
||||
m_RemovedComponents: []
|
||||
m_SourcePrefab: {fileID: 100100000, guid: ba128457d0ea5e3439dbe4a53b9d1273, type: 3}
|
||||
--- !u!1 &789765166
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
serializedVersion: 6
|
||||
m_Component:
|
||||
- component: {fileID: 789765171}
|
||||
- component: {fileID: 789765170}
|
||||
- component: {fileID: 789765169}
|
||||
- component: {fileID: 789765168}
|
||||
- component: {fileID: 789765167}
|
||||
m_Layer: 0
|
||||
m_Name: Sphere
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
--- !u!114 &789765167
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 789765166}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: baedd976e12657241bf7ff2d1c685342, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
m_Direction: 1
|
||||
m_Center: {x: 0, y: 0, z: 0}
|
||||
m_Bound: 0
|
||||
m_Radius: 0.5
|
||||
m_Height: 0
|
||||
--- !u!135 &789765168
|
||||
SphereCollider:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 789765166}
|
||||
m_Material: {fileID: 0}
|
||||
m_IsTrigger: 0
|
||||
m_Enabled: 1
|
||||
serializedVersion: 2
|
||||
m_Radius: 0.5
|
||||
m_Center: {x: 0, y: 0, z: 0}
|
||||
--- !u!23 &789765169
|
||||
MeshRenderer:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 789765166}
|
||||
m_Enabled: 1
|
||||
m_CastShadows: 1
|
||||
m_ReceiveShadows: 1
|
||||
m_DynamicOccludee: 1
|
||||
m_MotionVectors: 1
|
||||
m_LightProbeUsage: 1
|
||||
m_ReflectionProbeUsage: 1
|
||||
m_RayTracingMode: 2
|
||||
m_RayTraceProcedural: 0
|
||||
m_RenderingLayerMask: 1
|
||||
m_RendererPriority: 0
|
||||
m_Materials:
|
||||
- {fileID: 10303, guid: 0000000000000000f000000000000000, type: 0}
|
||||
m_StaticBatchInfo:
|
||||
firstSubMesh: 0
|
||||
subMeshCount: 0
|
||||
m_StaticBatchRoot: {fileID: 0}
|
||||
m_ProbeAnchor: {fileID: 0}
|
||||
m_LightProbeVolumeOverride: {fileID: 0}
|
||||
m_ScaleInLightmap: 1
|
||||
m_ReceiveGI: 1
|
||||
m_PreserveUVs: 0
|
||||
m_IgnoreNormalsForChartDetection: 0
|
||||
m_ImportantGI: 0
|
||||
m_StitchLightmapSeams: 1
|
||||
m_SelectedEditorRenderState: 3
|
||||
m_MinimumChartSize: 4
|
||||
m_AutoUVMaxDistance: 0.5
|
||||
m_AutoUVMaxAngle: 89
|
||||
m_LightmapParameters: {fileID: 0}
|
||||
m_SortingLayerID: 0
|
||||
m_SortingLayer: 0
|
||||
m_SortingOrder: 0
|
||||
m_AdditionalVertexStreams: {fileID: 0}
|
||||
--- !u!33 &789765170
|
||||
MeshFilter:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 789765166}
|
||||
m_Mesh: {fileID: 10207, guid: 0000000000000000e000000000000000, type: 0}
|
||||
--- !u!4 &789765171
|
||||
Transform:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 789765166}
|
||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: -0.189, y: 1.083, z: -0.69718814}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_Children: []
|
||||
m_Father: {fileID: 0}
|
||||
m_RootOrder: 4
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!1 &838898605 stripped
|
||||
GameObject:
|
||||
m_CorrespondingSourceObject: {fileID: 100140, guid: ba128457d0ea5e3439dbe4a53b9d1273,
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
public class DynamicBoneColliderBase : MonoBehaviour
|
||||
{
|
||||
public string ColliderName;
|
||||
public enum Direction
|
||||
{
|
||||
X, Y, Z
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Gallop
|
||||
@@ -9,5 +10,178 @@ namespace Gallop
|
||||
public List<EyeTarget> _eyeTarget;
|
||||
public List<EyebrowTarget> _eyebrowTarget;
|
||||
public List<MouthTarget> _mouthTarget;
|
||||
|
||||
public List<Transform> Objs = new List<Transform>();
|
||||
private List<Vector3> OriTrans = new List<Vector3>();
|
||||
private List<Quaternion> OriRots = new List<Quaternion>();
|
||||
private List<Vector3> OriScal = new List<Vector3>();
|
||||
|
||||
public List<FacialMorph> EyeBrowMorphs = new List<FacialMorph>();
|
||||
public List<FacialMorph> EyeMorphs = new List<FacialMorph>();
|
||||
public List<FacialMorph> MouthMorphs = new List<FacialMorph>();
|
||||
|
||||
private void Start()
|
||||
{
|
||||
Objs.AddRange(GetComponentsInChildren<Transform>());
|
||||
foreach (Transform g in Objs)
|
||||
{
|
||||
OriTrans.Add(g.localPosition);
|
||||
OriRots.Add(g.localRotation);
|
||||
OriScal.Add(g.localScale);
|
||||
}
|
||||
|
||||
for (int i = 0; i < _eyebrowTarget.Count; i++)
|
||||
{
|
||||
for (int j = 0; j < _eyebrowTarget[i]._faceGroupInfo.Count; j++)
|
||||
{
|
||||
FacialMorph morph = new FacialMorph();
|
||||
morph.SetFace(this);
|
||||
morph.name = "EyeBrow_" + i + "_" + (j > 0 ? "R" : "L");
|
||||
morph.trsArray = _eyebrowTarget[i]._faceGroupInfo[j]._trsArray;
|
||||
EyeBrowMorphs.Add(morph);
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < _eyeTarget.Count; i++)
|
||||
{
|
||||
for (int j = 0; j < _eyeTarget[i]._faceGroupInfo.Count; j++)
|
||||
{
|
||||
FacialMorph morph = new FacialMorph();
|
||||
morph.SetFace(this);
|
||||
morph.name = "Eye_" + i + "_" + (j > 0 ? "R" : "L");
|
||||
morph.trsArray = _eyeTarget[i]._faceGroupInfo[j]._trsArray;
|
||||
EyeMorphs.Add(morph);
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < _mouthTarget.Count; i++)
|
||||
{
|
||||
for (int j = 0; j < _mouthTarget[i]._faceGroupInfo.Count; j++)
|
||||
{
|
||||
FacialMorph morph = new FacialMorph();
|
||||
morph.SetFace(this);
|
||||
morph.name = "Mouth_" + i + "_" + j;
|
||||
morph.trsArray = _mouthTarget[i]._faceGroupInfo[j]._trsArray;
|
||||
MouthMorphs.Add(morph);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
for (int i = 0; i < EyeBrowMorphs.Count; i++)
|
||||
{
|
||||
if(EyeBrowMorphs[i].LastWeight!= EyeBrowMorphs[i].Weight)
|
||||
{
|
||||
ChangeMorph();
|
||||
EyeBrowMorphs[i].LastWeight = EyeBrowMorphs[i].Weight;
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < EyeMorphs.Count; i++)
|
||||
{
|
||||
if (EyeMorphs[i].LastWeight != EyeMorphs[i].Weight)
|
||||
{
|
||||
ChangeMorph();
|
||||
EyeMorphs[i].LastWeight = EyeMorphs[i].Weight;
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < MouthMorphs.Count; i++)
|
||||
{
|
||||
if (MouthMorphs[i].LastWeight != MouthMorphs[i].Weight)
|
||||
{
|
||||
ChangeMorph();
|
||||
MouthMorphs[i].LastWeight = MouthMorphs[i].Weight;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void ChangeMorph()
|
||||
{
|
||||
FacialReset();
|
||||
foreach (FacialMorph morph in EyeBrowMorphs)
|
||||
{
|
||||
foreach(TrsArray trs in morph.trsArray)
|
||||
{
|
||||
var bone = Objs.Find(ani => ani.name.Equals(trs._path));
|
||||
if (bone)
|
||||
{
|
||||
if (trs.IsOverrideTarget==1)
|
||||
{
|
||||
bone.localRotation = Quaternion.Euler(Vector3.Lerp(OriRots[Objs.IndexOf(bone)].eulerAngles, trs._rotation, morph.Weight));
|
||||
bone.localPosition = Vector3.Lerp(OriTrans[Objs.IndexOf(bone)],trs._position,morph.Weight);
|
||||
bone.localScale = Vector3.Lerp(OriScal[Objs.IndexOf(bone)],trs._scale, morph.Weight);
|
||||
}
|
||||
else
|
||||
{
|
||||
bone.localRotation = Quaternion.Euler(bone.localRotation.eulerAngles+ (trs._rotation* morph.Weight));
|
||||
bone.localPosition += trs._position*morph.Weight;
|
||||
bone.localScale += trs._scale* morph.Weight;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
foreach (FacialMorph morph in EyeMorphs)
|
||||
{
|
||||
foreach (TrsArray trs in morph.trsArray)
|
||||
{
|
||||
var bone = Objs.Find(ani => ani.name.Equals(trs._path));
|
||||
if (bone)
|
||||
{
|
||||
if (trs.IsOverrideTarget == 1)
|
||||
{
|
||||
bone.localRotation = Quaternion.Euler(Vector3.Lerp(OriRots[Objs.IndexOf(bone)].eulerAngles, trs._rotation, morph.Weight));
|
||||
bone.localPosition = Vector3.Lerp(OriTrans[Objs.IndexOf(bone)], trs._position, morph.Weight);
|
||||
bone.localScale = Vector3.Lerp(OriScal[Objs.IndexOf(bone)], trs._scale, morph.Weight);
|
||||
}
|
||||
else
|
||||
{
|
||||
bone.localRotation = Quaternion.Euler(bone.localRotation.eulerAngles + (trs._rotation * morph.Weight));
|
||||
bone.localPosition += trs._position * morph.Weight;
|
||||
bone.localScale += trs._scale * morph.Weight;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
foreach (FacialMorph morph in MouthMorphs)
|
||||
{
|
||||
foreach (TrsArray trs in morph.trsArray)
|
||||
{
|
||||
var bone = Objs.Find(ani => ani.name.Equals(trs._path));
|
||||
if (bone)
|
||||
{
|
||||
if (trs.IsOverrideTarget == 1)
|
||||
{
|
||||
bone.localRotation = Quaternion.Euler(Vector3.Lerp(OriRots[Objs.IndexOf(bone)].eulerAngles, trs._rotation, morph.Weight));
|
||||
bone.localPosition = Vector3.Lerp(OriTrans[Objs.IndexOf(bone)], trs._position, morph.Weight);
|
||||
bone.localScale = Vector3.Lerp(OriScal[Objs.IndexOf(bone)], trs._scale, morph.Weight);
|
||||
}
|
||||
else
|
||||
{
|
||||
bone.localRotation = Quaternion.Euler(bone.localRotation.eulerAngles + (trs._rotation * morph.Weight));
|
||||
bone.localPosition += trs._position * morph.Weight;
|
||||
bone.localScale += trs._scale * morph.Weight;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void FacialReset()
|
||||
{
|
||||
for (int i = 0; i < Objs.Count; i++)
|
||||
{
|
||||
Objs[i].localPosition = OriTrans[i];
|
||||
Objs[i].localRotation = OriRots[i];
|
||||
Objs[i].localScale = OriScal[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Gallop
|
||||
{
|
||||
[System.Serializable]
|
||||
public class FacialMorph
|
||||
{
|
||||
public string name;
|
||||
private FaceDrivenKeyTarget face;
|
||||
[Range(0, 1)]
|
||||
public float Weight;
|
||||
[HideInInspector]public float LastWeight;
|
||||
[HideInInspector] public List<TrsArray> trsArray;
|
||||
public void SetFace(FaceDrivenKeyTarget faceTarget)
|
||||
{
|
||||
face = faceTarget;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cdfe7600c0409fa45b2d2995667ba2ec
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,15 @@
|
||||
// Copyright (c) 2014 Luminary LLC
|
||||
// Licensed under The MIT License (See LICENSE for full text)
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
public class SetPropertyAttribute : PropertyAttribute
|
||||
{
|
||||
public string Name { get; private set; }
|
||||
public bool IsDirty { get; set; }
|
||||
|
||||
public SetPropertyAttribute(string name)
|
||||
{
|
||||
this.Name = name;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5d72052b442fcfe42b1433eeb25729bb
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user