public static BlendShape Create(string name, List<Vector2> vertices) { BlendShape blendShape = new BlendShape(); blendShape.name = name; blendShape.frames.Add(BlendShapeFrame.Create(100f,vertices)); return blendShape; }
public static BlendShape Create(string name) { BlendShape blendShape = ScriptableObject.CreateInstance <BlendShape>(); blendShape.name = name; return(blendShape); }
public BlendShapeFrame CreateBlendShapeFrame(BlendShape blendshape, float weight, string undoName) { BlendShapeFrame frame = null; if (blendshape && weight >= 1f) { frame = BlendShapeFrame.Create(weight, ToVertices(GetTexVertices()).ToArray()); RegisterCreatedObjectUndo(frame, undoName); RegisterObjectUndo(blendshape, undoName); List <BlendShapeFrame> frames = new List <BlendShapeFrame>(blendshape.frames); frames.Add(frame); blendshape.frames = frames.ToArray(); SortBlendshapeFrames(blendshape); m_DirtyVertices = true; isDirty = true; } return(frame); }
public static BlendShape CreateBlendShape(SpriteMesh spriteMesh, string blendshapeName) { BlendShape l_blendshape = null; SpriteMeshData spriteMeshData = LoadSpriteMeshData(spriteMesh); if (spriteMeshData) { l_blendshape = BlendShape.Create(blendshapeName); l_blendshape.hideFlags = HideFlags.HideInHierarchy; AssetDatabase.AddObjectToAsset(l_blendshape, spriteMeshData); List <BlendShape> l_blendshapes = new List <BlendShape>(spriteMeshData.blendshapes); l_blendshapes.Add(l_blendshape); spriteMeshData.blendshapes = l_blendshapes.ToArray(); EditorUtility.SetDirty(spriteMeshData); EditorUtility.SetDirty(l_blendshape); } return(l_blendshape); }
void CreateBlendShapeCache(SpriteMeshData spriteMeshData) { DestroyBlendShapeCache(""); List <BlendShapeFrame> frameClones = new List <BlendShapeFrame>(); foreach (BlendShape blendShape in spriteMeshData.blendshapes) { frameClones.Clear(); foreach (BlendShapeFrame frame in blendShape.frames) { BlendShapeFrame frameClone = ScriptableObject.CreateInstance <BlendShapeFrame>(); frameClone.hideFlags = HideFlags.DontSave; EditorUtility.CopySerialized(frame, frameClone); frameClones.Add(frameClone); } BlendShape blendShapeClone = CreateBlendshape(blendShape.name); blendShapeClone.frames = frameClones.ToArray(); } }
public static BlendShapeFrame CreateBlendShapeFrame(BlendShape blendshape, float weight, Vector3[] vertices) { BlendShapeFrame l_blendshapeFrame = null; if (blendshape && vertices != null) { l_blendshapeFrame = BlendShapeFrame.Create(weight, vertices); l_blendshapeFrame.hideFlags = HideFlags.HideInHierarchy; AssetDatabase.AddObjectToAsset(l_blendshapeFrame, blendshape); List <BlendShapeFrame> l_blendshapeFrames = new List <BlendShapeFrame>(blendshape.frames); l_blendshapeFrames.Add(l_blendshapeFrame); l_blendshapeFrames.Sort((a, b) => { return(a.weight.CompareTo(b.weight)); }); blendshape.frames = l_blendshapeFrames.ToArray(); EditorUtility.SetDirty(blendshape); EditorUtility.SetDirty(l_blendshapeFrame); } return(l_blendshapeFrame); }
void SortBlendshapeFrames(BlendShape blendShape) { if (blendShape) { List <BlendShapeFrame> frames = blendShape.frames.ToList(); frames.Sort((a, b) => { return(a.weight.CompareTo(b.weight)); }); blendShape.frames = frames.ToArray(); } }
void CreateBlendshape() { if (spriteMeshCache) { BlendShape blendShape = spriteMeshCache.CreateBlendshape("New BlendShape", "Create BlendShape"); spriteMeshCache.selectedBlendshape = blendShape; spriteMeshCache.CreateBlendShapeFrame(blendShape, 100f, "Create BlendShape"); spriteMeshCache.blendShapeWeight = 100f; } }
public BlendShape CreateBlendshape(string name, string undoName = "") { BlendShape blendShape = BlendShape.Create(name); blendShape.hideFlags = HideFlags.DontSave; RegisterUndo(undoName); RegisterCreatedObjectUndo(blendShape, undoName); blendshapes.Add(blendShape); m_DirtyVertices = true; return blendShape; }
void SetBlendShapesFromCache() { if (spriteMesh) { foreach (BlendShape blendshape in blendshapes) { BlendShape newBlendshape = SpriteMeshUtils.CreateBlendShape(spriteMesh, blendshape.name); foreach (BlendShapeFrame frame in blendshape.frames) { SpriteMeshUtils.CreateBlendShapeFrame(newBlendshape, frame.weight, frame.vertices.ToArray()); } } } }
public void DeleteBlendShapeFrame(BlendShape blendShape, BlendShapeFrame blendShapeFrame, string undoName = "") { if (blendShape && blendShape.frames.Contains(blendShapeFrame)) { RegisterObjectUndo(blendShape, undoName); List <BlendShapeFrame> frames = blendShape.frames.ToList(); frames.Remove(blendShapeFrame); blendShape.frames = frames.ToArray(); DestroyObjectImmediate(blendShapeFrame); m_DirtyVertices = true; isDirty = true; } }
public void DeleteBlendShape(BlendShape blendshape, string undoName = "") { if (blendshape) { RegisterUndo(undoName); selectedBlendshape = null; blendshapes.Remove(blendshape); RegisterObjectUndo(blendshape, undoName); foreach (BlendShapeFrame frame in blendshape.frames) { DestroyObjectImmediate(frame); } DestroyObjectImmediate(blendshape); m_DirtyVertices = true; isDirty = true; } }
public void DeleteBlendshape(BlendShape blendshape) { if(blendshapes.Contains(blendshape)) { blendshapes.Remove(blendshape); } isDirty = true; }
public static void RebuildBlendShapes(SpriteMesh spriteMesh, Mesh mesh) { if (!mesh) { return; } if (!spriteMesh) { return; } BlendShape[] blendShapes = null; SpriteMeshData spriteMeshData = LoadSpriteMeshData(spriteMesh); if (spriteMeshData) { blendShapes = spriteMeshData.blendshapes; } if (spriteMesh.sharedMesh.vertexCount != mesh.vertexCount) { return; } if (blendShapes != null) { #if !(UNITY_5_0 || UNITY_5_1 || UNITY_5_2) List <string> blendShapeNames = new List <string>(); mesh.ClearBlendShapes(); Vector3[] from = mesh.vertices; for (int i = 0; i < blendShapes.Length; i++) { BlendShape blendshape = blendShapes[i]; if (blendshape) { string blendShapeName = blendshape.name; if (blendShapeNames.Contains(blendShapeName)) { Debug.LogWarning("Found repeated BlendShape name '" + blendShapeName + "' in SpriteMesh: " + spriteMesh.name); } else { blendShapeNames.Add(blendShapeName); for (int j = 0; j < blendshape.frames.Length; j++) { BlendShapeFrame l_blendshapeFrame = blendshape.frames[j]; if (l_blendshapeFrame && from.Length == l_blendshapeFrame.vertices.Length) { Vector3[] deltaVertices = GetDeltaVertices(from, l_blendshapeFrame.vertices); mesh.AddBlendShapeFrame(blendShapeName, l_blendshapeFrame.weight, deltaVertices, null, null); } } } } } mesh.UploadMeshData(false); EditorUtility.SetDirty(mesh); #endif } }
public void CreateFrame(BlendShape blendshape, float weight) { blendshape.frames.Add(BlendShapeFrame.Create(weight,GetPositions())); isDirty = true; }
List <Vector2> GetBlendshapePositions(BlendShape blendshape, float weight) { weight = Mathf.Clamp(weight, 0f, weight); List <Vector2> result = new List <Vector2>(m_TexVertices.Count); if (blendshape) { BlendShapeFrame prevFrame = null; BlendShapeFrame nextFrame = null; foreach (BlendShapeFrame frame in blendshape.frames) { if (frame && frame.weight < weight) { prevFrame = frame; } else if (frame && nextFrame == null) { nextFrame = frame; break; } } Vector3[] prevFrameVertices = null; Vector3[] nextFrameVertices = null; float prevWeight = 0f; float nextWeight = 0f; if (prevFrame) { prevFrameVertices = prevFrame.vertices; prevWeight = prevFrame.weight; } else { prevFrameVertices = ToVertices(m_TexVertices).ToArray(); } if (nextFrame) { nextFrameVertices = nextFrame.vertices; nextWeight = nextFrame.weight; } else if (prevFrameVertices != null) { nextFrameVertices = prevFrameVertices; nextWeight = prevWeight; } if (prevFrameVertices != null && nextFrameVertices != null && prevFrameVertices.Length == nextFrameVertices.Length) { int count = prevFrameVertices.Length; float pixelsPerUnit = SpriteMeshUtils.GetSpritePixelsPerUnit(spriteMesh.sprite); float t = 0f; float weightDelta = (nextWeight - prevWeight); if (weightDelta > 0f) { t = (weight - prevWeight) / weightDelta; } for (int i = 0; i < count; ++i) { Vector3 v = Vector3.Lerp(prevFrameVertices[i], nextFrameVertices[i], t); result.Add(SpriteMeshUtils.VertexToTexCoord(spriteMesh, pivotPoint, v, pixelsPerUnit)); } } } return(result); }
protected override void DoOnAfterDeserialize() { for(int i = 0; i < nodes.Count; ++i) { nodes[i].index = i; } selectedBlendshape = null; if(mSelectedBlendshapeIndex >= 0 && mSelectedBlendshapeIndex < blendshapes.Count) { selectedBlendshape = blendshapes[mSelectedBlendshapeIndex]; } }