override protected Mesh CreateProduct(Mesh reuse = null) { Mesh mesh = reuse != null ? reuse : new Mesh(); if (Input == null) { mesh.Clear(); // Debug.Log("Source is null for " + this); return(mesh); } NPVoxModel model = GetVoxModel(); if (model) { mesh.Clear(); if (!model.IsValid) { Debug.LogWarning("Source Model is not valid"); return(mesh); } NPVoxMeshGenerator.CreateMesh(model, mesh, VoxelSize, NormalVariance, NormalVarianceSeed, Optimization, NormalMode, BloodColorIndex, Loop, Cutout, Include, MinVertexGroups, NormalModePerVoxelGroup, NormalProcessors); mesh.name = "zzz Mesh"; return(mesh); } else { // Debug.Log("Source Product is null for " + this); mesh.Clear(); return(mesh); } }
private void ApplyNormalStage() { NPVoxModel voxModel = m_context.MeshOutput.GetVoxModel(); Vector3[] normals = m_context.PreviewMesh.normals; NPVoxNormalProcessor_UserOverride processor = ( NPVoxNormalProcessor_UserOverride )m_context.ViewedProcessor; foreach (NPVoxMeshData vox in m_context.MeshOutput.GetVoxMeshData()) { if (!vox.isHidden) { NPVoxCoord coord = vox.voxCoord; int index = voxModel.GetIndex(coord); if (GetSelection(coord) == SELECTED_TARGET) { processor.m_overrideNormalsRT[vox.voxCoord] = m_normalStage[index]; for (int i = 0; i < vox.numVertices; i++) { normals[vox.vertexIndexOffsetBegin + i] = m_normalStage[index]; } } } } RemoveRedundantOverrides(); UnityEditor.EditorUtility.SetDirty(processor); m_context.PreviewMesh.normals = normals; }
private bool ComputeSourceAverage(ref Vector3 _out, bool _includeInputField = false) { NPVoxModel voxModel = m_context.MeshOutput.GetVoxModel(); List <Vector3> normalsSum = new List <Vector3>(); Vector3[] normalsMesh = m_context.PreviewMesh.normals; foreach (NPVoxMeshData vox in m_context.MeshOutput.GetVoxMeshData()) { if (!vox.isHidden) { NPVoxCoord coord = vox.voxCoord; int index = voxModel.GetIndex(coord); if (GetSelection(coord) == SELECTED_SOURCE) { normalsSum.Add(normalsMesh[vox.vertexIndexOffsetBegin]); } } } if (_includeInputField) { normalsSum.Add(m_normalField); } bool bResult = MathUtilities.Statistical.ComputeAverage(normalsSum, ref _out); return(bResult); }
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)); } }
public static string DrawSocketSelector(string label, string previousValue, NPVoxIModelFactory modelFactory) { if (modelFactory == null) { return(previousValue); } NPVoxModel inputModel = modelFactory.GetProduct(); string[] socketNames = inputModel.SocketNames; if (inputModel) { GUILayout.BeginHorizontal(); GUILayout.Label(label); if (socketNames.Length > 0) { int previousSelected = NPipeArrayUtil.GetElementIndex(socketNames, previousValue); int newSelected = GUILayout.SelectionGrid(previousSelected, socketNames, 4); GUILayout.EndHorizontal(); if (newSelected < 0) { newSelected = 0; } return(socketNames[newSelected]); } else { GUILayout.Label("-no sockets-"); GUILayout.EndHorizontal(); } } return(previousValue); }
public NPVoxToUnity(Vector3 unityModelSize, Vector3 voxelSize) { this.voxModel = null; this.voxelSize = voxelSize; this.voxelOffset = Vector3.zero; this.unitySize = unityModelSize; }
public NPVoxToUnity(NPVoxCoord voxModelSize, Vector3 voxelSize) { this.voxModel = null; this.voxelSize = voxelSize; this.voxelOffset = Vector3.zero; this.unitySize = new Vector3(voxelSize.x * voxModelSize.X, voxelSize.y * voxModelSize.Y, voxelSize.z * voxModelSize.Z); }
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)); }
protected override void OnBeforeProcess(NPVoxModel model, NPVoxMeshData[] tempdata) { UnityEngine.Random.InitState(m_normalVarianceSeed); m_passVariance.m_normalVariance = NormalVariance; m_passVariance.m_normalVarianceSeed = NormalVarianceSeed; }
public override void Process(NPVoxModel model, NPVoxMeshData tempdata, Vector3[] inNormals, ref Vector3[] outNormals) { for (int t = 0; t < tempdata.numVertices; t++) { outNormals[tempdata.vertexIndexOffsetBegin + t] = inNormals[tempdata.vertexIndexOffsetBegin + t].normalized; } }
public static NPVoxModel MatrixTransform(NPVoxModel sourceModel, NPVoxBox affectedArea, Matrix4x4 matrix, Vector3 pivot, ResolveConflictMethodType resolveConflictMethod = ResolveConflictMethodType.CLOSEST, NPVoxModel reuse = null) { Vector3 pivotPoint = affectedArea.SaveCenter + pivot; Matrix4x4 transformMatrix = (Matrix4x4.TRS(pivotPoint, Quaternion.identity, Vector3.one) * matrix) * Matrix4x4.TRS(-pivotPoint, Quaternion.identity, Vector3.one); return(Transform(sourceModel, affectedArea, transformMatrix, resolveConflictMethod, reuse)); }
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); }
public void Clamp_ShouldReturnClampedVoxCoord() { NPVoxModel sut = NPVoxModel.NewInstance(new NPVoxCoord(3, 3, 3)); Assert.AreEqual(new NPVoxCoord(1, 1, 1), sut.Clamp(new NPVoxCoord(1, 1, 1))); Assert.AreEqual(new NPVoxCoord(0, 0, 0), sut.Clamp(new NPVoxCoord(-2, -2, -2))); Assert.AreEqual(new NPVoxCoord(2, 2, 2), sut.Clamp(new NPVoxCoord(7, 7, 7))); }
public void Clamp_ShouldReturnClampedVoxBox() { NPVoxModel sut = NPVoxModel.NewInstance(new NPVoxCoord(3, 3, 3)); NPVoxBox box = sut.Clamp(new NPVoxBox(new NPVoxCoord(-2, -2, -2), new NPVoxCoord(6, 6, 6))); Assert.AreEqual(new NPVoxCoord(2, 2, 2), box.RightUpForward); Assert.AreEqual(new NPVoxCoord(0, 0, 0), box.LeftDownBack); }
public static NPVoxModel MatrixTransformSocket(NPVoxModel sourceModel, string socketName, Matrix4x4 matrix, Vector3 pivot, NPVoxModel reuse = null) { NPVoxSocket socket = sourceModel.GetSocketByName(socketName); Vector3 pivotPoint = NPVoxCoordUtil.ToVector(socket.Anchor) + pivot; Matrix4x4 transformMatrix = (Matrix4x4.TRS(pivotPoint, Quaternion.identity, Vector3.one) * matrix) * Matrix4x4.TRS(-pivotPoint, Quaternion.identity, Vector3.one); return(TransformSocket(sourceModel, socketName, transformMatrix, reuse)); }
public void Run(NPVoxModel model, NPVoxMeshTempData[] tempdata, Vector3[] inNormals, Vector3[] outNormals) { foreach (NPVoxNormalProcessor processor in m_processorList) { processor.InitOutputBuffer(inNormals); processor.Process(model, tempdata, inNormals, outNormals); } }
public static NPVoxModel NewInstance(NPVoxCoord size, NPVoxModel reuse = null) { NPVoxModel VoxModel = reuse != null ? reuse : ScriptableObject.CreateInstance <NPVoxModel>(); VoxModel.name = "Model"; VoxModel.Initialize(size); return(VoxModel); }
public static bool[] GetUsedColors(NPVoxModel model) { bool[] usedColors = new bool[model.Colortable.Length]; foreach (NPVoxCoord coord in model.EnumerateVoxels()) { usedColors[model.GetVoxel(coord)] = true; } return(usedColors); }
protected override void OnBeforeProcess(NPVoxModel model, NPVoxMeshData[] tempdata) { m_passFromMesh.m_meshReference = m_meshReference; m_passFromMesh.m_dataAlreadyCollected = false; m_passFromMesh.m_smoothNormals = m_smoothNormals; m_passFromMesh.m_flipX = m_flipX; m_passFromMesh.m_flipY = m_flipY; m_passFromMesh.m_flipZ = m_flipZ; m_passFromMesh.m_swapAxes = m_swapAxes; }
public override void CopyOver(NPVoxModel source) { base.CopyOver(source); if (source is NPVoxBoneModel) { NPVoxBoneModel boneModel = (source as NPVoxBoneModel); boneMasks = (uint[])boneModel.boneMasks.Clone(); this.AllBones = NPVoxBone.CloneBones(boneModel.AllBones); } }
public void Run(NPVoxModel model, NPVoxMeshData[] tempdata, Vector3[] inNormals, Vector3[] outNormals) { inNormals.CopyTo(outNormals, 0); foreach (NPVoxNormalProcessor processor in m_processorList) { processor.InitOutputBuffer(outNormals.Length); processor.Process(model, tempdata, outNormals, outNormals); } }
public virtual void CopyOver(NPVoxModel source) { this.numVoxels = source.numVoxels; this.size = source.size; this.voxels = (byte[])source.voxels.Clone(); this.numVoxelGroups = source.numVoxelGroups; this.voxelGroups = source.voxelGroups != null ? (byte[])source.voxelGroups.Clone() : null; this.colortable = source.colortable != null ? (Color32[])source.colortable.Clone() : null; this.Sockets = source.Sockets != null ? (NPVoxSocket[])source.Sockets.Clone() : null; this.voxelListCache = null; }
public string[] GetSourceSocketsForTargetSocket(string targetSocketName) { NPVoxIModelFactory modelFactory = GetPreviewModelFactoryForTargetSocket(targetSocketName); if (modelFactory != null) { NPVoxModel model = modelFactory.GetProduct(); return(model.SocketNames); } return(null); }
public static byte AddBrightenColor(NPVoxModel model) { byte color = FindUnusedColor(model); if (color != 0) { Color32 brightenColor32 = model.Colortable[color]; model.Colortable[color] = NPVoxModelUtils.BrightenColor(brightenColor32); } return(color); }
public static byte FindUnusedColor(NPVoxModel model) { bool[] usedColors = GetUsedColors(model); for (byte i = 1; i != 0; i++) { if (!usedColors[i]) { return(i); } } return(0); }
public NPVoxCoord GetOutputSize() { NPVoxModel model = GetVoxModel(); NPVoxCoord size = model.Size; if (Cutout != null) { size.X = (sbyte)(size.X - (sbyte)Mathf.Abs(Cutout.Left) - (sbyte)Mathf.Abs(Cutout.Right)); size.Y = (sbyte)(size.Y - (sbyte)Mathf.Abs(Cutout.Up) - (sbyte)Mathf.Abs(Cutout.Down)); size.Z = (sbyte)(size.Z - (sbyte)Mathf.Abs(Cutout.Back) - (sbyte)Mathf.Abs(Cutout.Forward)); } return(size); }
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 NPVoxToUnity(NPVoxModel voxModel, Vector3 voxelSize, Vector3 voxelOffset) { this.voxModel = voxModel; this.voxelSize = voxelSize; this.voxelOffset = voxelOffset; if (voxModel == null) { this.unitySize = Vector3.zero; } else { this.unitySize = new Vector3(voxelSize.x * voxModel.SizeX, voxelSize.y * voxModel.SizeY, voxelSize.z * voxModel.SizeZ); } }
public override void Process(NPVoxModel model, NPVoxMeshData tempdata, Vector3[] inNormals, ref Vector3[] outNormals) { for (int t = 0; t < tempdata.numVertices; t++) { outNormals[tempdata.vertexIndexOffsetBegin + t] = inNormals[tempdata.vertexIndexOffsetBegin + t]; } if (m_normalData.ContainsKey(tempdata.voxCoord)) { Vector3 normal = m_normalData[tempdata.voxCoord]; for (int t = 0; t < tempdata.numVertices; t++) { outNormals[tempdata.vertexIndexOffsetBegin + t] = normal; } } }
public string[] GetPreviewTargetSocketNames() { if (this.SelectedFrame == null || SelectedFrame.Source == null) { return(new string[] {}); } NPVoxModel model = SelectedFrame.Source.GetProduct(); if (model != null && model.SocketNames.Length > 0) { return(model.SocketNames); } return(new string[] {}); }