public BoneVisual3d(TransformViewModel transform, SkeletonVisual3d skeleton, string name) { this.ViewModel = transform; this.Skeleton = skeleton; this.rotation = new RotateTransform3D(); this.position = new TranslateTransform3D(); Transform3DGroup transformGroup = new Transform3DGroup(); transformGroup.Children.Add(this.rotation); transformGroup.Children.Add(this.position); this.Transform = transformGroup; PaletteHelper ph = new PaletteHelper(); ITheme t = ph.GetTheme(); this.defaultMaterial = new DiffuseMaterial(new SolidColorBrush(WinColor.FromArgb(64, 0, 0, 0))); this.hoverMaterial = new EmissiveMaterial(new SolidColorBrush(t.PrimaryDark.Color)); this.selectedMaterial = new EmissiveMaterial(new SolidColorBrush(t.PrimaryMid.Color)); System.Windows.Media.Color c1 = System.Windows.Media.Color.FromArgb(200, 255, 255, 255); this.sphere = new Sphere(); this.sphere.Radius = 0.02; this.sphere.Material = this.defaultMaterial; this.Children.Add(this.sphere); this.BoneName = name; this.Skeleton.PropertyChanged += this.OnSkeletonPropertyChanged; }
public void ReadTransform() { if (!this.IsEnabled) { return; } this.Position = this.ViewModel.Position; this.Rotation = this.ViewModel.Rotation; this.Scale = this.ViewModel.Scale; // Convert the character-relative transform into a parent-relative transform Point3D position = this.Position.ToMedia3DPoint(); Quaternion rotation = this.Rotation.ToMedia3DQuaternion(); if (this.Parent != null) { TransformViewModel parentTransform = this.Parent.ViewModel; Point3D parentPosition = parentTransform.Position.ToMedia3DPoint(); Quaternion parentRot = parentTransform.Rotation.ToMedia3DQuaternion(); parentRot.Invert(); // relative position position = (Point3D)(position - parentPosition); // relative rotation rotation = parentRot * rotation; // unrotate bones, since we will transform them ourselves. RotateTransform3D rotTrans = new RotateTransform3D(new QuaternionRotation3D(parentRot)); position = rotTrans.Transform(position); } // Store the new parent-relative transform info this.Position = position.ToCmVector(); this.Rotation = rotation.ToCmQuaternion(); // Set the Media3D hierarchy transforms this.rotation.Rotation = new QuaternionRotation3D(rotation); this.position.OffsetX = position.X; this.position.OffsetY = position.Y; this.position.OffsetZ = position.Z; // Draw a line for visualization if (this.Parent != null && this.lineToParent != null) { Point3D p = this.lineToParent.Points[1]; p.X = position.X; p.Y = position.Y; p.Z = position.Z; this.lineToParent.Points[1] = p; } }
public override async Task ResizeAndRotateAsync(MediaFile file, MediaOptions mediaOptions, DeviceRotation currentRotaion = DeviceRotation.Unknown) { var originalMetadata = new ExifInterface(file.Path); var transformVM = new TransformViewModel { FilePath = file.Path, MediaOptions = mediaOptions, Exif = originalMetadata, CurrentRotation = currentRotaion }; await ResizeAndRotateAsync(transformVM); originalMetadata?.Dispose(); GC.Collect(); }
public BoneVisual3d(TransformViewModel transform, SkeletonVisual3d skeleton) { this.ViewModel = transform; this.Skeleton = skeleton; this.rotation = new RotateTransform3D(); this.position = new TranslateTransform3D(); Transform3DGroup transformGroup = new Transform3DGroup(); transformGroup.Children.Add(this.rotation); transformGroup.Children.Add(this.position); this.Transform = transformGroup; PaletteHelper ph = new PaletteHelper(); Sphere sphere = new Sphere(); sphere.Radius = 0.005; System.Windows.Media.Color c1 = System.Windows.Media.Color.FromArgb(200, 255, 255, 255); sphere.Material = new EmissiveMaterial(new SolidColorBrush(c1)); this.Children.Add(sphere); }
public async Task Apply(ActorViewModel actor, SkeletonVisual3d skeleton, Configuration config) { SkeletonViewModel?skeletonMem = actor?.ModelObject?.Skeleton?.Skeleton; if (skeletonMem == null || skeleton.Bones == null) { throw new Exception("No skeleton in actor"); } skeletonMem.MemoryMode = MemoryModes.None; PoseService.Instance.SetEnabled(true); PoseService.Instance.CanEdit = false; await Task.Delay(100); if (this.Bones != null) { // Apply all transforms a few times to ensure parent-inherited values are caluclated correctly, and to ensure // we dont end up with some values read during a ffxiv frame update. for (int i = 0; i < 3; i++) { foreach ((string name, Bone? savedBone) in this.Bones) { if (savedBone == null) { continue; } BoneVisual3d?bone = skeleton.GetBone(name); if (bone == null) { Log.Write($"Bone: \"{name}\" not found", "Pose", Log.Severity.Warning); continue; } if (config.UseSelection && !skeleton.GetIsBoneSelected(bone)) { continue; } TransformViewModel vm = bone.ViewModel; if (PoseService.Instance.FreezePositions && savedBone.Position != null) { vm.Position = (Vector)savedBone.Position; } if (PoseService.Instance.FreezeRotation && savedBone.Rotation != null) { vm.Rotation = (Quaternion)savedBone.Rotation; } if (PoseService.Instance.FreezeScale && savedBone.Scale != null) { vm.Scale = (Vector)savedBone.Scale; } bone.ReadTransform(); bone.WriteTransform(skeleton, false); } await Task.Delay(1); } } await Task.Delay(100); skeletonMem.MemoryMode = MemoryModes.ReadWrite; await skeletonMem.ReadFromMemoryAsync(); PoseService.Instance.CanEdit = true; }
private Task <bool> ResizeAndRotateAsync(TransformViewModel transformVM) { if (string.IsNullOrWhiteSpace(transformVM.FilePath)) { return(Task.FromResult(false)); } var photoSize = transformVM.MediaOptions.PhotoSize; var customPhotoSize = transformVM.MediaOptions.CustomPhotoSize; var quality = transformVM.MediaOptions.CompressionQuality; return(Task.Run(() => { try { if (photoSize == PhotoSize.Full && transformVM.CurrentRotation == DeviceRotation.Unknown) { return false; } var percent = 1.0f; switch (photoSize) { case PhotoSize.Large: percent = 0.75f; break; case PhotoSize.Medium: percent = 0.5f; break; case PhotoSize.Small: percent = 0.25f; break; case PhotoSize.Custom: percent = (float)customPhotoSize / 100f; break; } // first decode to just get dimensions var options = new BitmapFactory.Options { InJustDecodeBounds = true }; // already on background task BitmapFactory.DecodeFile(transformVM.FilePath, options); var finalWidth = (int)(options.OutWidth * percent); var finalHeight = (int)(options.OutHeight * percent); // set scaled image dimesions transformVM.Exif?.SetAttribute(TAG_PIXEL_X_DIMENSION, Java.Lang.Integer.ToString(finalWidth)); transformVM.Exif?.SetAttribute(TAG_PIXEL_Y_DIMENSION, Java.Lang.Integer.ToString(finalHeight)); // calculate sample size options.InSampleSize = CalculateInSampleSize(options, finalWidth, finalHeight); // turn off decode options.InJustDecodeBounds = false; //this now will return the requested width/height from file, so no longer need to scale using (var originalImage = BitmapFactory.DecodeFile(transformVM.FilePath, options)) { // rotate the image var matrix = new Matrix(); switch (transformVM.CurrentRotation) { case DeviceRotation.Portrait: matrix.PreRotate(90); break; case DeviceRotation.Landscape: matrix.PreRotate(180); break; case DeviceRotation.ReversePortrait: matrix.PreRotate(270); break; case DeviceRotation.ReverseLandscape: break; } var rotated = Bitmap.CreateBitmap(originalImage, 0, 0, originalImage.Width, originalImage.Height, matrix, false); matrix.Dispose(); matrix = null; // always need to compress to save back to disk using (var stream = File.Open(transformVM.FilePath, FileMode.Create, FileAccess.ReadWrite)) { rotated.Compress(Bitmap.CompressFormat.Jpeg, quality, stream); stream.Close(); } originalImage.Recycle(); rotated.Recycle(); if (transformVM.MediaOptions.SaveMetaData && IsValidExif(transformVM.Exif)) { try { transformVM.Exif?.SaveAttributes(); } catch (Exception ex) { #if DEBUG Console.WriteLine($"Unable to save exif {ex}"); #endif } } // Dispose of the Java side bitmap GC.Collect(); return true; } } catch (Exception ex) { #if DEBUG Console.WriteLine(ex.StackTrace); throw ex; #else return Task.FromResult(false); #endif } })); }
public TransformView() { var viewModel = new TransformViewModel(); DataContex = viewModel; }