public static NPVoxModel TransformSocket(NPVoxModel sourceModel, string socketName, Matrix4x4 transformMatrix, NPVoxModel reuse = null) { NPVoxModel transformedModel = null; transformedModel = NPVoxModel.NewInstance(sourceModel, reuse); transformedModel.CopyOver(sourceModel); NPVoxSocket[] sockets = new NPVoxSocket[sourceModel.Sockets.Length]; for (int i = 0; i < sockets.Length; i++) { NPVoxSocket socket = sourceModel.Sockets[i]; if (socket.Name == socketName) { // transform anchor Vector3 saveOriginalAnchor = NPVoxCoordUtil.ToVector(socket.Anchor); Vector3 saveTargetAnchor = transformMatrix.MultiplyPoint(saveOriginalAnchor); socket.Anchor = sourceModel.Clamp(NPVoxCoordUtil.ToCoord(saveTargetAnchor)); // transform Quaternion Quaternion originalRotation = Quaternion.Euler(socket.EulerAngles); Matrix4x4 rotated = (Matrix4x4.TRS(Vector3.zero, originalRotation, Vector3.one) * transformMatrix); socket.EulerAngles = Matrix4x4Util.GetRotation(rotated).eulerAngles; } sockets[i] = socket; } transformedModel.Sockets = sockets; return(transformedModel); }
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) { 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); } }