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)); }
override protected NPVoxModel CreateProduct(NPVoxModel reuse = null) { if (Input == null) { return(NPVoxModel.NewInvalidInstance(reuse, "No Input Setup"));; } NPVoxModel model = ((NPVoxIModelFactory)Input).GetProduct(); if (Absolute) { NPVoxModel newModel = NPVoxModel.NewInstance(model, reuse); newModel.CopyOver(model); NPVoxSocket socket = model.GetSocketByName(SocketName); socket.Anchor = NPVoxCoordUtil.ToCoord(GetTranslation() + GetPivot()); socket.EulerAngles = GetRotation().eulerAngles; newModel.SetSocket(socket); return(newModel); } else { return(NPVoxModelTransformationUtil.MatrixTransformSocket(model, SocketName, Matrix, PivotOffset, reuse)); } }
override protected NPVoxModel CreateProduct(NPVoxModel reuse = null) { if (Input != null) { // todo voxel group NPVoxModel inputModel = ((NPVoxIModelFactory)Input).GetProduct(); NPVoxIModelFactory targetFactory = this.Target as NPVoxIModelFactory; if (targetFactory != null) { NPVoxModel targetModel = targetFactory.GetProduct(); NPVoxSocket inputSocket = inputModel.GetSocketByName(InputSocketName); NPVoxSocket targetSocket = targetModel.GetSocketByName(TargetSocketName); NPVoxModel model = NPVoxModelTransformationUtil.SocketTransform(inputModel, targetModel, inputSocket, targetSocket, ResolveConflictMethod, reuse); model.name = "zzz Model Socket Combiner"; return(model); } else { reuse = NPVoxModel.NewInstance(inputModel, reuse); reuse.CopyOver(inputModel); return(reuse); } } else { // return NPVoxModel.NewInvalidInstance(reuse, "No Input Setup"); throw new NPipeException("No Input Setup"); } }
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); } }
override protected NPVoxModel CreateProduct(NPVoxModel reuse = null) { if (Input == null) { return(NPVoxModel.NewInvalidInstance(reuse, "No Input Setup")); } NPVoxModel model = ((NPVoxIModelFactory)Input).GetProduct() as NPVoxModel; NPVoxModel targetModel = model; if (TargetFrame is NPVoxIModelFactory) { targetModel = ((NPVoxIModelFactory)TargetFrame).GetProduct() as NPVoxModel; } if (!(PreviousFrame is NPVoxIModelFactory)) { Debug.LogWarning("previous frame is not a model factory"); return(NPVoxModel.NewInstance(NPVoxCoord.ZERO, reuse)); } #if UNITY_EDITOR if (SocketOffsets.Length < 4 || ControlPointOffsets.Length < 4) { ResetSceneTools(); } #endif NPVoxModel sourceModel = ((NPVoxIModelFactory)PreviousFrame).GetProduct(); NPVoxSocket sourceSocket1 = sourceModel.GetSocketByName(SocketName1); NPVoxSocket sourceSocket2 = sourceModel.GetSocketByName(SocketName2); NPVoxSocket targetSocket1 = targetModel.GetSocketByName(SocketName1); NPVoxSocket targetSocket2 = targetModel.GetSocketByName(SocketName2); if (sourceSocket1.IsInvalid()) { Debug.LogWarning("SocketName1 not found in sourceModel"); return(NPVoxModel.NewInstance(NPVoxCoord.ZERO, reuse)); } if (sourceSocket2.IsInvalid()) { Debug.LogWarning("SocketName2 not found in sourceModel"); return(NPVoxModel.NewInstance(NPVoxCoord.ZERO, reuse)); } if (targetSocket1.IsInvalid()) { Debug.LogWarning("SocketName1 not found in newModel"); return(NPVoxModel.NewInstance(NPVoxCoord.ZERO, reuse)); } if (targetSocket2.IsInvalid()) { Debug.LogWarning("SocketName2 not found in oldModel"); return(NPVoxModel.NewInstance(NPVoxCoord.ZERO, reuse)); } if (TheStepSize < 0.01f) { Debug.LogWarning("Stepsize too small"); return(NPVoxModel.NewInstance(NPVoxCoord.ZERO, reuse)); } NPVoxToUnity sourceN2U = new NPVoxToUnity(sourceModel, Vector3.one); NPVoxToUnity targetN2U = new NPVoxToUnity(targetModel, Vector3.one); NPVoxToUnity modelN2U = new NPVoxToUnity(model, Vector3.one); // calculate size for our new model NPVoxBox requiredBounds = model.BoundingBox; requiredBounds.EnlargeToInclude(modelN2U.ToVoxCoord(sourceN2U.ToUnityPosition(sourceSocket1.Anchor) + SocketOffsets[INDEX_SOURCE_1])); requiredBounds.EnlargeToInclude(modelN2U.ToVoxCoord(sourceN2U.ToUnityPosition(sourceSocket2.Anchor) + SocketOffsets[INDEX_SOURCE_2])); requiredBounds.EnlargeToInclude(modelN2U.ToVoxCoord(targetN2U.ToUnityPosition(targetSocket1.Anchor) + SocketOffsets[INDEX_TARGET_1])); requiredBounds.EnlargeToInclude(modelN2U.ToVoxCoord(targetN2U.ToUnityPosition(targetSocket2.Anchor) + SocketOffsets[INDEX_TARGET_2])); requiredBounds.EnlargeToInclude(modelN2U.ToVoxCoord(sourceN2U.ToUnityPosition(sourceSocket1.Anchor) + SocketOffsets[INDEX_SOURCE_1] + ControlPointOffsets[INDEX_SOURCE_1])); requiredBounds.EnlargeToInclude(modelN2U.ToVoxCoord(sourceN2U.ToUnityPosition(sourceSocket2.Anchor) + SocketOffsets[INDEX_SOURCE_2] + ControlPointOffsets[INDEX_SOURCE_2])); requiredBounds.EnlargeToInclude(modelN2U.ToVoxCoord(targetN2U.ToUnityPosition(targetSocket1.Anchor) + SocketOffsets[INDEX_TARGET_1] + ControlPointOffsets[INDEX_TARGET_1])); requiredBounds.EnlargeToInclude(modelN2U.ToVoxCoord(targetN2U.ToUnityPosition(targetSocket2.Anchor) + SocketOffsets[INDEX_TARGET_2] + ControlPointOffsets[INDEX_TARGET_2])); // create our product model NPVoxModel productModel = NPVoxModelTransformationUtil.CreateWithNewSize(model, requiredBounds, reuse); // prepare voxel groups bool addVoxelGroups = SetVoxelGroup > 0 || productModel.HasVoxelGroups() || SetBaseVoxelGroup > 0; byte theVoxelGroup = (byte)SetVoxelGroup; if (addVoxelGroups) { if (!productModel.HasVoxelGroups()) { productModel.InitVoxelGroups(); foreach (NPVoxCoord coord in productModel.EnumerateVoxels()) { productModel.SetVoxelGroup(coord, SetBaseVoxelGroup); } } if (theVoxelGroup > productModel.NumVoxelGroups - 1) { productModel.NumVoxelGroups = (byte)(theVoxelGroup + 1); } if (SetBaseVoxelGroup > productModel.NumVoxelGroups - 1) { productModel.NumVoxelGroups = (byte)(SetBaseVoxelGroup + 1); } } // check if we have a circularloop #if UNITY_EDITOR if (NPipelineUtils.IsPrevious(PreviousFrame as NPipeIImportable, this, true)) { Debug.LogWarning("cycular pipeline detected"); return(productModel); } #endif NPVoxToUnity productN2U = new NPVoxToUnity(productModel, Vector3.one); // build our colortable bool[] usedColors = NPVoxModelUtils.GetUsedColors(productModel); Color32[] colorTable = productModel.Colortable; byte[] Colors = new byte[NumColorSteps]; Color32 startColor = Color1; Color32 endColor = Color2; bool takeColorFromModel = ColorNumFromModel > -1; if (takeColorFromModel) { byte color1 = NPVoxModelUtils.FindUsedColor(ref usedColors, ColorNumFromModel); startColor = colorTable[color1]; endColor = colorTable[color1]; endColor.a = 15; } // Debug.Log("Me: " + NPipelineUtils.GetPipelineDebugString(this)); for (int i = 0; i < NumColorSteps; i++) { byte color = NPVoxModelUtils.FindUnusedColor(ref usedColors); // Debug.Log("Color: " + color); colorTable[color] = Color32.Lerp(startColor, endColor, ((float)i / (float)NumColorSteps)); Colors[i] = color; } // calculate mathetmatical constants Vector3 unityStartPoint1 = targetN2U.ToUnityPosition(targetSocket1.Anchor) + targetN2U.ToUnityDirection(SocketOffsets[INDEX_TARGET_1]); Vector3 bezierStartPoint1 = unityStartPoint1 + targetN2U.ToUnityDirection(ControlPointOffsets[INDEX_TARGET_1]); Vector3 unityEndPoint1 = sourceN2U.ToUnityPosition(sourceSocket1.Anchor) + sourceN2U.ToUnityDirection(SocketOffsets[INDEX_SOURCE_1]); Vector3 bezierEndPoint1 = unityEndPoint1 + sourceN2U.ToUnityDirection(ControlPointOffsets[INDEX_SOURCE_1]); Vector3 direction1 = unityEndPoint1 - unityStartPoint1; float dir1len = direction1.magnitude; Vector3 unityStartPoint2 = targetN2U.ToUnityPosition(targetSocket2.Anchor) + targetN2U.ToUnityDirection(SocketOffsets[INDEX_TARGET_2]); Vector3 bezierStartPoint2 = unityStartPoint2 + targetN2U.ToUnityDirection(ControlPointOffsets[INDEX_TARGET_2]); Vector3 unityEndPoint2 = sourceN2U.ToUnityPosition(sourceSocket2.Anchor) + sourceN2U.ToUnityDirection(SocketOffsets[INDEX_SOURCE_2]); Vector3 bezierEndPoint2 = unityEndPoint2 + sourceN2U.ToUnityDirection(ControlPointOffsets[INDEX_SOURCE_2]); Vector3 direction2 = unityEndPoint2 - unityStartPoint2; float dir2len = direction2.magnitude; float travelled = 0.0f; float distance = dir1len > dir2len ? dir1len : dir2len; if (distance > MaxDistance) { distance = MaxDistance; } float StepSize = TheStepSize / distance; // draw the trail while (travelled < distance) { float alpha = (travelled / distance); float idx = alpha * (float)(NumColorSteps - 1); byte color = Colors[(int)Mathf.Round(idx)]; Vector3 currentP1 = NPVoxGeomUtil.GetBezierPoint(unityStartPoint1, bezierStartPoint1, bezierEndPoint1, unityEndPoint1, alpha); Vector3 currentP2 = NPVoxGeomUtil.GetBezierPoint(unityStartPoint2, bezierStartPoint2, bezierEndPoint2, unityEndPoint2, alpha); Vector3 currentP1vox = productN2U.ToSaveVoxCoord(currentP1); Vector3 currentP2vox = productN2U.ToSaveVoxCoord(currentP2); NPVoxGeomUtil.DrawLine(productModel, currentP1vox, currentP2vox, color, theVoxelGroup, false); // currentP1 += direction1 * stepSize1; // currentP2 += direction2 * stepSize2; travelled += StepSize; } productModel.Colortable = colorTable; productModel.RecalculateNumVoxels(); return(productModel); }