override protected NPVoxModel CreateProduct(NPVoxModel reuse = null) { if (Input == null) { return(NPVoxModel.NewInvalidInstance(reuse, "No Input Setup")); } NPVoxModel model = ((NPVoxIModelFactory)Input).GetProduct(); // backwards compatibility if (TryToResolveConflicts == false) { TryToResolveConflicts = true; ResolveConflictMethod = NPVoxModelTransformationUtil.ResolveConflictMethodType.NONE; } // shift afftected area if the parent bounding box changed { NPVoxBox parentBounds = model.BoundingBox; if (!lastParentModelBounds.Equals(NPVoxBox.INVALID) && !lastParentModelBounds.Equals(parentBounds)) { sbyte deltaX = (sbyte)((parentBounds.Right - lastParentModelBounds.Right) / 2); sbyte deltaY = (sbyte)((parentBounds.Up - lastParentModelBounds.Up) / 2); sbyte deltaZ = (sbyte)((parentBounds.Forward - lastParentModelBounds.Forward) / 2); NPVoxCoord delta = new NPVoxCoord(deltaX, deltaY, deltaZ); AffectedArea = new NPVoxBox(AffectedArea.LeftDownBack + delta, AffectedArea.RightUpForward + delta); // Debug.Log("Moving affected area by + " + deltaX + " " + deltaY + " " + deltaZ); } lastParentModelBounds = parentBounds; } return(NPVoxModelTransformationUtil.MatrixTransform(model, AffectedArea, Matrix, PivotOffset, ResolveConflictMethod, reuse)); }
private bool DrawBoxSelection() { if (viewModel.PreviousModelFactory == null) { return(false); } NPVoxModel previousTransformedModel = viewModel.PreviousModelFactory.GetProduct(); NPVoxToUnity npVoxToUnity = new NPVoxToUnity(previousTransformedModel, viewModel.Animation.MeshFactory.VoxelSize); List <NPVoxBox> boxes = viewModel.GetNonEditableBoxes(); if (boxes != null) { foreach (NPVoxBox b in boxes) { NPVoxHandles.DrawBoxSelection(npVoxToUnity, b, false); } } if (!viewModel.IsAreaSelectionActive()) { return(false); } NPVoxBox box = viewModel.GetAffectedBox(); if (Event.current.shift) { // affected area picker NPVoxCoord someCoord = box.RoundedCenter; NPVoxCoord someNewCoord = NPVoxHandles.VoxelPicker(new NPVoxToUnity(previousTransformedModel, viewModel.Animation.MeshFactory.VoxelSize), someCoord, 0, ((NPVoxAnimationEditorSession)target).previewFilter.transform); if (!someCoord.Equals(someNewCoord)) { viewModel.ChangeAffectedBox(new NPVoxBox(someNewCoord, someNewCoord)); } } else { // affected area box NPVoxBox newBox = NPVoxHandles.DrawBoxSelection(npVoxToUnity, box); if (!newBox.Equals(box)) { viewModel.ChangeAffectedBox(newBox); } } return(true); }
public static void CalculateResizeOffset(NPVoxBox parentBounds, NPVoxBox thisBounds, out NPVoxCoord delta, out NPVoxCoord size) { if (!thisBounds.Equals(parentBounds)) { size = parentBounds.Size; bool isOverflow = false; sbyte deltaX = (sbyte)(Mathf.Max(parentBounds.Left - thisBounds.Left, thisBounds.Right - parentBounds.Right)); if ((int)deltaX * 2 + (int)size.X > 126) // check for overflow { deltaX = (sbyte)((float)deltaX - Mathf.Ceil(((float)deltaX * 2f + (float)size.X) - 126) / 2f); isOverflow = true; } sbyte deltaY = (sbyte)(Mathf.Max(parentBounds.Down - thisBounds.Down, thisBounds.Up - parentBounds.Up)); if ((int)deltaY * 2 + (int)size.Y > 126) // check for overflow { deltaY = (sbyte)((float)deltaY - Mathf.Ceil(((float)deltaY * 2f + (float)size.Y) - 126) / 2f); isOverflow = true; } sbyte deltaZ = (sbyte)(Mathf.Max(parentBounds.Back - thisBounds.Back, thisBounds.Forward - parentBounds.Forward)); if ((int)deltaZ * 2 + (int)size.Z > 126) // check for overflow { deltaZ = (sbyte)((float)deltaZ - Mathf.Ceil(((float)deltaZ * 2f + (float)size.Z) - 126) / 2f); isOverflow = true; } delta = new NPVoxCoord(deltaX, deltaY, deltaZ); size = size + delta + delta; if (isOverflow) { Debug.LogWarning("Transformed Model is large, clamped to " + size); } } else { size = parentBounds.Size; delta = NPVoxCoord.ZERO; } }
override protected NPVoxModel CreateProduct(NPVoxModel reuse = null) { if (Input == null) { return(NPVoxModel.NewInvalidInstance(reuse, "No Input Setup")); } NPVoxBoneModel model = ((NPVoxIModelFactory)Input).GetProduct() as NPVoxBoneModel; if (model == null) { return(NPVoxModel.NewInvalidInstance(reuse, "Can only transform bone models")); } // hack to center pivot on selected bones if (regenerateName) { RecenterBonePivot(model); } RegenerateName(model); NPVoxBox affectedBox = GetAffectedBox(); if (affectedBox.Equals(NPVoxBox.INVALID)) { NPVoxModel newInstance = NPVoxModel.NewInstance(model, reuse); newInstance.CopyOver(model); newInstance.RecalculateNumVoxels(true); return(newInstance); } else { reuse = NPVoxModelTransformationUtil.MatrixTransform(model, affectedBox, boneMask, Matrix, PivotOffset, ResolveConflictMethod, reuse); reuse.RecalculateNumVoxels(true); return(reuse); } }
public static Bounds DrawBoundsSelection(Bounds previous, Vector3 cellOffset, float cellSize) { NPVoxToUnity npVoxToUnity = new NPVoxToUnity(null, Vector3.one * cellSize, cellOffset - Vector3.one * 0.5f * cellSize); NPVoxBox previousBox = new NPVoxBox( npVoxToUnity.ToVoxCoord(previous.min + Vector3.one * cellSize / 2), npVoxToUnity.ToVoxCoord(previous.max - Vector3.one * cellSize / 2) ); NPVoxBox newBox = NPVoxHandles.DrawBoxSelection(npVoxToUnity, previousBox, true); if (!previousBox.Equals(newBox)) { Bounds bounds = new Bounds(Vector3.zero, Vector3.zero); bounds.SetMinMax( npVoxToUnity.ToUnityPosition(newBox.LeftDownBack) - Vector3.one * cellSize / 2, npVoxToUnity.ToUnityPosition(newBox.RightUpForward) + Vector3.one * cellSize / 2 ); return(bounds); } else { return(previous); } }
override protected NPVoxModel CreateProduct(NPVoxModel reuse = null) { if (Input == null) { return(NPVoxModel.NewInvalidInstance(reuse, "Input was null")); } NPVoxModel inputModel = ((NPVoxIModelFactory)Input).GetProduct(); bool hasVoxelGroups = inputModel.HasVoxelGroups(); if (AffectedArea.Equals(NPVoxBox.INVALID)) { NPVoxModel model = NPVoxModel.NewInstance(inputModel, reuse); model.CopyOver(inputModel); return(model); } NPVoxBox clampedBox = inputModel.Clamp(AffectedArea); NPVoxModel transformedModel = null; transformedModel = NPVoxModel.NewInstance(inputModel, reuse); if (hasVoxelGroups) { transformedModel.InitVoxelGroups(); } transformedModel.NumVoxelGroups = inputModel.NumVoxelGroups; transformedModel.NumVoxels = inputModel.NumVoxels; transformedModel.Colortable = inputModel.Colortable != null ? (Color32[])inputModel.Colortable.Clone() : null; transformedModel.Sockets = inputModel.Sockets != null ? (NPVoxSocket[])inputModel.Sockets.Clone() : null; NPVoxBoneModel transformedBoneModel = transformedModel as NPVoxBoneModel; NPVoxBoneModel inputBoneModel = inputModel as NPVoxBoneModel; bool isBoneModel = false; if (transformedBoneModel != null) { transformedBoneModel.AllBones = NPVoxBone.CloneBones(inputBoneModel.AllBones); isBoneModel = true; } byte brightenedColor = NPVoxModelUtils.FindUnusedColor(inputModel); if (brightenedColor == 0) { Debug.LogWarning("could not find a free color to brighten the model"); } Color32 brightenColor32 = inputModel.Colortable[brightenedColor]; foreach (NPVoxCoord coord in inputModel.EnumerateVoxels()) { if (!isBoneModel) { if (clampedBox.Contains(coord) && brightenedColor != 0) { brightenColor32 = inputModel.Colortable[inputModel.GetVoxel(coord)]; transformedModel.SetVoxel(coord, brightenedColor); } else { transformedModel.SetVoxel(coord, inputModel.GetVoxel(coord)); } } else { if (hiddenBonesMask == 0 || !inputBoneModel.IsInBoneMask(coord, hiddenBonesMask)) { if (clampedBox.Contains(coord) && brightenedColor != 0 && inputBoneModel.IsInBoneMask(coord, boneMask)) { brightenColor32 = inputModel.Colortable[inputModel.GetVoxel(coord)]; transformedModel.SetVoxel(coord, brightenedColor); } else { transformedModel.SetVoxel(coord, inputModel.GetVoxel(coord)); } } transformedBoneModel.SetBoneMask(coord, inputBoneModel.GetBoneMask(coord)); } if (hasVoxelGroups) { transformedModel.SetVoxelGroup(coord, inputModel.GetVoxelGroup(coord)); } } if (brightenedColor != 0) { transformedModel.Colortable[brightenedColor] = NPVoxModelUtils.BrightenColor(brightenColor32); } transformedModel.RecalculateNumVoxels(true); return(transformedModel); }