private void OnSkinningModeChange(SkinningMode mode) { if (skinningCache.hasCharacter) { if (mode == SkinningMode.SpriteSheet) { this.Q <Button>("EditJoints").SetEnabled(false); this.Q <Button>("CreateBone").SetEnabled(false); this.Q <Button>("SplitBone").SetEnabled(false); if (skinningCache.GetTool(Tools.EditJoints).isActive || skinningCache.GetTool(Tools.CreateBone).isActive || skinningCache.GetTool(Tools.SplitBone).isActive) { SetSkeletonTool(Tools.EditPose); } } else if (mode == SkinningMode.Character) { this.Q <Button>("EditJoints").SetEnabled(true); this.Q <Button>("CreateBone").SetEnabled(true); this.Q <Button>("SplitBone").SetEnabled(true); } } }
private void SetupSpriteEditor(bool setPreviewTexture = false) { var textureProvider = spriteEditor.GetDataProvider <ITextureDataProvider>(); if (textureProvider == null) { return; } var emptyTexture = new Texture2D(1, 1, TextureFormat.RGBAHalf, false, true); emptyTexture.hideFlags = HideFlags.HideAndDontSave; emptyTexture.SetPixel(1, 1, new Color(0, 0, 0, 0)); emptyTexture.Apply(); int width = 0, height = 0; if (skinningCache.mode == SkinningMode.SpriteSheet) { textureProvider.GetTextureActualWidthAndHeight(out width, out height); } else { width = skinningCache.character.dimension.x; height = skinningCache.character.dimension.y; } if (m_PreviousSkinningMode != skinningCache.mode || setPreviewTexture) { m_PreviousSkinningMode = skinningCache.mode; spriteEditor.SetPreviewTexture(emptyTexture, width, height); } spriteEditor.spriteRects = new List <SpriteRect>(); }
private void SetupSpriteEditor(bool setPreviewTexture = false) { var textureProvider = spriteEditor.GetDataProvider <ITextureDataProvider>(); if (textureProvider == null) { return; } int width = 0, height = 0; if (skinningCache.mode == SkinningMode.SpriteSheet) { textureProvider.GetTextureActualWidthAndHeight(out width, out height); } else { width = skinningCache.character.dimension.x; height = skinningCache.character.dimension.y; } if (m_PreviousSkinningMode != skinningCache.mode || setPreviewTexture) { spriteEditor.SetPreviewTexture(m_WorkspaceBackgroundTexture, width, height); if (m_PreviousSkinningMode != skinningCache.mode) { m_PreviousSkinningMode = skinningCache.mode; spriteEditor.ResetZoomAndScroll(); } } spriteEditor.spriteRects = new List <SpriteRect>(); }
void OnViewModeChanged(SkinningMode mode) { OnAvailabilityChangeListeners(); if (isAvailable && m_Model.previousVisibility != m_Model.allVisibility) { SetAllCharacterSpriteVisibility(); } }
void OnSkinningModuleModeChanged(SkinningMode mode) { SetAnimationEvent(new AnimationEvent() { sub_type = AnimationEventType.SkinningModuleModeChanged, data = mode.ToString() }); }
private SkinningMode CheckModeConsistency(SkinningMode mode) { if (mode == SkinningMode.Character && hasCharacter == false) { mode = SkinningMode.SpriteSheet; } return(mode); }
public void SetDefault() { m_LastUsedTool = Tools.EditPose; m_LastMode = SkinningMode.Character; m_LastSpriteId = String.Empty; m_LastBoneSelectionIds.Clear(); m_LastTexture = null; m_VertexSelection.Clear(); m_SkeletonPreviewPose.Clear(); m_VisibilityToolActive = false; }
private void OnViewModeChanged(SkinningMode characterMode) { if (characterMode == SkinningMode.Character) { m_View.Setup(skinningCache.GetSprites()); } else { m_View.Setup(new[] { skinningCache.selectedSprite }); } }
public void OnViewModeChanged_UpdatesToolAvailability(SkinningMode mode, int hasCharacterRecievedCall) { bool availabilityChangedCalled = false; m_Controller.OnAvailabilityChangeListeners += () => availabilityChangedCalled = true; m_Controller.Activate(); m_Model.mode.Returns(mode); m_Model.previousVisibility.Returns(false); m_Model.allVisibility.Returns(true); m_Events.skinningModeChanged.Invoke(mode); var temp = m_Model.Received(hasCharacterRecievedCall).hasCharacter; Assert.IsTrue(availabilityChangedCalled); }
public void CanDrag(bool hasCharacter, SkinningMode mode, bool canDrag) { m_Model.hasCharacter.Returns(hasCharacter); m_Model.mode.Returns(mode); var eventString = ""; UnityAction <string> callback = x => { eventString = x; }; m_EventSystem.boneVisibility.AddListener(callback); Assert.AreEqual(canDrag, m_Controller.CanDrag()); m_EventSystem.boneVisibility.RemoveListener(callback); Assert.AreEqual("drag", eventString); }
private List <FbxSubmesh> ImportSubmeshes(IntPtr ptr) { var list = new List <FbxSubmesh>(); var mesh = FbxNodeGetMeshAttribute(ptr, WindingOrder.CW, true); var indices = mesh.Vertices.ToStruct <SizedArray>().GetData <int>(); var controlPoints = mesh.Points.ToStruct <SizedArray>().GetData <Vec3>(); var weights = mesh.Weigths.ToStruct <SizedArray>().GetData <WeightData>(); var boneData = mesh.Bones.ToStruct <SizedArray>().GetData <BoneData>(); var colorsContainer = mesh.Colors.ToStruct <Element>(); var normalsContainer = mesh.Normals.ToStruct <Element>(); var uvContainer = mesh.UV.ToStruct <Element>(); var colors = colorsContainer.GetData <Vec4>(); var normals = normalsContainer.GetData <Vec3>(); var uv = uvContainer.GetData <Vec2>(); SkinningMode = GetSkinningMode(mesh.SkinningMode); var size = ushort.MaxValue; var count = indices.Length / size; var bones = new FbxBone[boneData.Length]; for (var i = 0; i < boneData.Length; i++) { bones[i] = new FbxBone { Name = boneData[i].Name, Offset = boneData[i].OffsetMatrix.ToStruct <Mat4x4>().ToLime() }; } for (var i = 0; i <= count; i++) { var newSize = i == count ? indices.Length - (size * count) : size; var submesh = new FbxSubmesh { MaterialIndex = mesh.MaterialIndex, Indices = new int[newSize], Vertices = new Mesh3D.Vertex[newSize], Normals = new Vector3[newSize], Bones = bones, }; var hasColors = colorsContainer.Size != 0 && colorsContainer.Mode != ReferenceMode.None; var hasNormals = normalsContainer.Size != 0 && normalsContainer.Mode != ReferenceMode.None; var hasUV = uvContainer.Size != 0 && uvContainer.Mode != ReferenceMode.None; for (var j = 0; j < submesh.Vertices.Length; j++) { var index = i * size + j; var controlPointIndex = indices[index]; var controlPoint = controlPoints[controlPointIndex]; submesh.Indices[j] = j; submesh.Vertices[j].Pos = controlPoint.ToLime(); if (hasColors) { submesh.Vertices[j].Color = colorsContainer.Mode == ReferenceMode.ControlPoint ? colors[controlPointIndex].ToLimeColor() : colors[index].ToLimeColor(); } else { submesh.Vertices[j].Color = Color4.White; } if (hasNormals) { submesh.Vertices[j].Normal = normalsContainer.Mode == ReferenceMode.ControlPoint ? normals[controlPointIndex].ToLime() : normals[index].ToLime(); } if (hasUV) { submesh.Vertices[j].UV1 = normalsContainer.Mode == ReferenceMode.ControlPoint ? uv[controlPointIndex].ToLime() : uv[index].ToLime(); submesh.Vertices[j].UV1.Y = 1 - submesh.Vertices[j].UV1.Y; } if (weights.Length == 0) { continue; } byte idx; float weight; var weightData = weights[controlPointIndex]; for (var k = 0; k < ImportConfig.BoneLimit; k++) { if (weightData.Weights[k] == NoWeight) { continue; } idx = weightData.Indices[k]; weight = weightData.Weights[k]; switch (k) { case 0: submesh.Vertices[j].BlendIndices.Index0 = idx; submesh.Vertices[j].BlendWeights.Weight0 = weight; break; case 1: submesh.Vertices[j].BlendIndices.Index1 = idx; submesh.Vertices[j].BlendWeights.Weight1 = weight; break; case 2: submesh.Vertices[j].BlendIndices.Index2 = idx; submesh.Vertices[j].BlendWeights.Weight2 = weight; break; case 3: submesh.Vertices[j].BlendIndices.Index3 = idx; submesh.Vertices[j].BlendWeights.Weight3 = weight; break; } } } if (hasUV) { if (!hasNormals) { ComputeNormals(submesh.Vertices, submesh.Indices); } ComputeTangents(submesh.Vertices, submesh.Indices); } list.Add(submesh); } return(list); }
private void OnSkinningModeChanged(SkinningMode mode) { UpdatePanel(); }
void OnModeChanged(SkinningMode mode) { m_GenerateWeightsPanel.Update(mode == SkinningMode.Character); }
void OnSkinningModeChanged(SkinningMode skinningMode) { UpdateAddRemoveButtons(); }
public void ReparentItems(int parentIndex, int[] draggedItemIndex, bool hasCharacter, SkinningMode mode, bool shouldReparent) { m_Model.hasCharacter.Returns(hasCharacter); m_Model.mode.Returns(mode); var skeleton = Substitute.For <SkeletonCache>(); var bones = new[] { Substitute.For <BoneCache>(), Substitute.For <BoneCache>(), Substitute.For <BoneCache>(), Substitute.For <BoneCache>(), }; bones[0].name = "Bone_1"; bones[1].name = "Bone_1_1"; bones[2].name = "Bone_1_1_1"; bones[3].name = "Bone_2"; var b = bones[2]; b.parentBone.Returns(bones[1]); b = bones[1]; b.parentBone.Returns(bones[0]); bones[0].siblingIndex.Returns(0); bones[1].siblingIndex.Returns(0); bones[2].siblingIndex.Returns(0); bones[3].siblingIndex.Returns(1); skeleton.bones.Returns(bones); m_Model.GetSelectedSkeleton().Returns(skeleton); var treeViewItem = m_Controller.BuildTreeView(); treeViewItem[0].AddChild(treeViewItem[1]); treeViewItem[1].AddChild(treeViewItem[2]); var parentItem = treeViewItem[parentIndex] as TreeViewItemBase <BoneCache>; var draggedItem = new List <TreeViewItem>(); foreach (var i in draggedItemIndex) { draggedItem.Add(treeViewItem[i]); } var eventCalled = 0; UnityAction <SkeletonCache> callback = x => { ++eventCalled; }; m_EventSystem.skeletonTopologyChanged.AddListener(callback); m_Controller.ReparentItems(parentItem, draggedItem, 0); m_EventSystem.skeletonTopologyChanged.RemoveListener(callback); if (shouldReparent) { Assert.AreEqual(draggedItem.Count, eventCalled); m_Model.Received(draggedItem.Count).SetBoneParent(Arg.Any <BoneCache>(), Arg.Any <BoneCache>(), 0); for (int i = 0; i < draggedItem.Count; ++i) { m_Model.Received(1).SetBoneParent(Arg.Is <BoneCache>(x => x == parentItem.customData), Arg.Is <BoneCache>(y => y == ((TreeViewItemBase <BoneCache>)draggedItem[i]).customData), 0); } } else { m_Model.DidNotReceiveWithAnyArgs().SetBoneParent(Arg.Any <BoneCache>(), Arg.Any <BoneCache>(), 0); Assert.AreEqual(0, eventCalled); } }
private void OnSkinningModuleModeChanged(SkinningMode mode) { SetupSkeleton(); m_Model.SetAllVisibility(null, true); }
private void SkinningModuleModeChanged(SkinningMode mode) { DirtyMeshesAll(); }
private void SkinningModeChanged(SkinningMode mode) { SetupSkeleton(skinningCache.GetEffectiveSkeleton(skinningCache.selectedSprite)); }
private void OnViewModeChanged(SkinningMode mode) { SetupSpriteEditor(); }
public override void OnModuleActivate() { m_SkinningCache = Cache.Create <SkinningCache>(); AddMainUI(spriteEditor.GetMainVisualContainer()); using (skinningCache.DisableUndoScope()) { skinningCache.Create(spriteEditor, SkinningCachePersistentState.instance); skinningCache.CreateToolCache(spriteEditor, m_LayoutOverlay); m_CharacterSpriteTool = skinningCache.CreateTool <SpriteBoneInfluenceTool>(); m_CharacterSpriteTool.Initialize(m_LayoutOverlay); m_MeshPreviewTool = skinningCache.CreateTool <MeshPreviewTool>(); SetupModuleToolGroup(); m_MeshPreviewTool.Activate(); m_SpriteOutlineRenderer = new SpriteOutlineRenderer(skinningCache.events); spriteEditor.enableMouseMoveEvent = true; Undo.undoRedoPerformed += UndoRedoPerformed; skinningCache.events.skeletonTopologyChanged.AddListener(SkeletonTopologyChanged); skinningCache.events.skeletonPreviewPoseChanged.AddListener(SkeletonPreviewPoseChanged); skinningCache.events.skeletonBindPoseChanged.AddListener(SkeletonBindPoseChanged); skinningCache.events.characterPartChanged.AddListener(CharacterPartChanged); skinningCache.events.skinningModeChanged.AddListener(OnViewModeChanged); skinningCache.events.meshChanged.AddListener(OnMeshChanged); skinningCache.events.boneNameChanged.AddListener(OnBoneNameChanged); skinningCache.events.boneDepthChanged.AddListener(OnBoneDepthChanged); skinningCache.events.spriteLibraryChanged.AddListener(OnSpriteLibraryChanged); skinningCache.events.meshPreviewBehaviourChange.AddListener(OnMeshPreviewBehaviourChange); skinningCache.RestoreFromPersistentState(); ActivateTool(skinningCache.selectedTool); skinningCache.RestoreToolStateFromPersistentState(); // Set state for Switch Mode tool m_PreviousSkinningMode = skinningCache.mode; if (skinningCache.mode == SkinningMode.Character) { skinningCache.GetTool(Tools.SwitchMode).Deactivate(); } else { skinningCache.GetTool(Tools.SwitchMode).Activate(); } SetupSpriteEditor(true); m_HorizontalToggleTools = new HorizontalToggleTools(skinningCache) { onActivateTool = (b) => { using (skinningCache.UndoScope(TextContent.setTool)) { ActivateTool(b); } } }; var ai = spriteEditor.GetDataProvider <ISpriteEditorDataProvider>() as AssetImporter; m_Analytics = new AnimationAnalytics(new UnityAnalyticsStorage(), skinningCache.events, new SkinningModuleAnalyticsModel(skinningCache), ai == null ? -1 : ai.GetInstanceID()); UpdateCollapseToolbar(); } }
public override void OnModuleActivate() { m_SkinningCache = Cache.Create <SkinningCache>(); AddMainUI(spriteEditor.GetMainVisualContainer()); using (skinningCache.DisableUndoScope()) { skinningCache.Create(spriteEditor); skinningCache.CreateToolCache(spriteEditor, m_LayoutOverlay); m_CharcterSpriteTool = skinningCache.CreateTool <SpriteBoneInfluenceTool>(); m_CharcterSpriteTool.Initialize(m_LayoutOverlay); m_MeshPreviewTool = skinningCache.CreateTool <MeshPreviewTool>(); m_MeshPreviewTool.Activate(); ActivateTool(skinningCache.GetTool(Tools.EditPose)); m_SpriteOutlineRenderer = new SpriteOutlineRenderer(spriteEditor, skinningCache.events); spriteEditor.enableMouseMoveEvent = true; Undo.undoRedoPerformed += UndoRedoPerformed; skinningCache.events.skeletonTopologyChanged.AddListener(SkeletonTopologyChanged); skinningCache.events.skeletonPreviewPoseChanged.AddListener(SkeletonPreviewPoseChanged); skinningCache.events.skeletonBindPoseChanged.AddListener(SkeletonBindPoseChanged); skinningCache.events.characterPartChanged.AddListener(CharacterPartChanged); skinningCache.events.skinningModeChanged.AddListener(OnViewModeChanged); skinningCache.events.meshChanged.AddListener(OnMeshChanged); skinningCache.events.boneNameChanged.AddListener(OnBoneNameChanged); skinningCache.events.boneDepthChanged.AddListener(OnBoneDepthChanged); m_PreviousSkinningMode = skinningCache.mode; SetupSpriteEditor(); if (skinningCache.hasCharacter) { m_WeightToolbar.EnableBoneInfluenceWidget(); skinningCache.GetTool(Tools.SwitchMode).Deactivate(); // Do not select any sprite by default in character mode skinningCache.events.selectedSpriteChanged.Invoke(null); } else { m_WeightToolbar.DisableBoneInfluenceWidget(); } m_HorizontalToggleTools = new HorizontalToggleTools(skinningCache) { onActivateTool = (b) => { using (skinningCache.UndoScope(TextContent.setTool)) { ActivateTool(b); } } }; var ai = spriteEditor.GetDataProvider <ISpriteEditorDataProvider>() as AssetImporter; m_Analytics = new AnimationAnalytics(new UnityAnalyticsStorage(), skinningCache.events, new SkinningModuleAnalyticsModel(skinningCache), ai == null ? -1 : ai.GetInstanceID()); UpdateCollapseToolbar(); } }