Example #1
0
    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));
    }
Example #2
0
 public override void Initialize(NPVoxCoord size)
 {
     base.Initialize(size);
     boneMasks = new uint[size.X * size.Y * size.Z];
     RootBone  = new NPVoxBone("Root", 0, null);
     AllBones  = new NPVoxBone[] { };
 }
Example #3
0
    private void SetSelection(NPVoxCoord _coord, sbyte _selection)
    {
        int iIndex = m_context.MeshOutput.GetVoxModel().GetIndex(_coord);

        m_selections[iIndex] = _selection;
        m_lastSelected       = _coord;
    }
Example #4
0
    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);
    }
Example #5
0
    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;
    }
Example #6
0
 public void AddBoneMask(NPVoxCoord coord, uint mask)
 {
     if (IsInside(coord))
     {
         boneMasks[GetIndex(coord)] |= mask;
     }
 }
Example #7
0
 public void EnlargeToInclude(NPVoxCoord coord)
 {
     if (coord.X < this.Left)
     {
         this.Left = coord.X;
     }
     if (coord.Y < this.Down)
     {
         this.Down = coord.Y;
     }
     if (coord.Z < this.Back)
     {
         this.Back = coord.Z;
     }
     if (coord.X > this.Right)
     {
         this.Right = coord.X;
     }
     if (coord.Y > this.Up)
     {
         this.Up = coord.Y;
     }
     if (coord.Z > this.Forward)
     {
         this.Forward = coord.Z;
     }
 }
Example #8
0
    public NPVoxRayCastHit Raycast(Ray ray, Transform transform, float distance = 10f)
    {
        Vector3 transformedPoint = transform != null?transform.InverseTransformPoint(ray.origin) : ray.origin;

        Vector3 transformedDirection = transform != null?transform.InverseTransformDirection(ray.direction) : ray.direction;

        float travelledDistance = 0f;

        // TODO walking there is really stupid ^^ find way to project the transformPoint onto the VoxModel-s boundaries as a start position
        while (travelledDistance < distance)
        {
            NPVoxCoord coord = ToVoxCoord(transformedPoint);
            if (!this.voxModel.IsInside(coord) || !this.voxModel.HasVoxel(coord))
            {
                transformedPoint  += transformedDirection * voxelSize.x;
                travelledDistance += voxelSize.x;
            }
            else
            {
                return(new NPVoxRayCastHit(true, coord));
            }
        }

        return(new NPVoxRayCastHit(false, NPVoxCoord.INVALID));
    }
Example #9
0
    private NPVoxModel CreateSlicedModel(NPVoxModel source, NPVoxModel reuse)
    {
        NPVoxBox targetBox    = slice.Clone();
        NPVoxBox sourceBounds = source.BoundingBox;

        targetBox.Clamp(source.BoundingBox);

        NPVoxCoord origin    = targetBox.LeftDownBack;
        NPVoxModel model     = NPVoxModel.NewInstance(source, targetBox.Size, reuse);
        int        numVoxels = 0;

        foreach (NPVoxCoord coord in targetBox.Enumerate())
        {
            if (source.HasVoxel(coord))
            {
                numVoxels++;
                model.SetVoxel(coord - origin, source.GetVoxel(coord));
            }
        }

        model.NumVoxels  = numVoxels;
        model.Colortable = source.Colortable;

        return(model);
    }
Example #10
0
 public void UnsetVoxel(NPVoxCoord coord)
 {
     if (IsInside(coord))
     {
         this.voxels[GetIndex(coord)] = 0;
     }
 }
Example #11
0
 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);
 }
Example #12
0
 public bool IsInside(NPVoxCoord coord)
 {
     return(coord.Valid &&
            coord.X < size.X &&
            coord.Y < size.Y &&
            coord.Z < size.Z);
 }
Example #13
0
 public void ResetSceneTools()
 {
     rotation1   = Quaternion.identity;
     rotation2   = Quaternion.identity;
     startCoord1 = NPVoxCoord.ZERO;
     startCoord2 = NPVoxCoord.ONE;
 }
Example #14
0
 public bool Contains(NPVoxCoord coord)
 {
     return
         (coord.X >= leftDownBack.X && coord.X <= rightUpForward.X &&
          coord.Y >= leftDownBack.Y && coord.Y <= rightUpForward.Y &&
          coord.Z >= leftDownBack.Z && coord.Z <= rightUpForward.Z);
 }
Example #15
0
 public void SetVoxelGroup(NPVoxCoord coord, byte group)
 {
     if (IsInside(coord))
     {
         voxelGroups[GetIndex(coord)] = group;
     }
 }
Example #16
0
    public IEnumerable <NPVoxCoord> EnumerateVoxels()
    {
//        if (voxelListCache != null)
//        {
//            return voxelListCache;
//        }
//        voxelListCache = new List<NPVoxCoord>();
        NPVoxCoord size = Size;

        for (sbyte x = 0; x < size.X; x++)
        {
            for (sbyte y = 0; y < size.Y; y++)
            {
                for (sbyte z = 0; z < size.Z; z++)
                {
                    NPVoxCoord coord = new NPVoxCoord(x, y, z);
                    if (HasVoxel(coord))
                    {
//                        voxelListCache.Add(coord);
                        yield return(coord);
                    }
                }
            }
        }

//        return voxelListCache;
    }
Example #17
0
 public void SetVoxel(NPVoxCoord coord, byte color)
 {
     if (IsInside(coord))
     {
         voxels[GetIndex(coord)] = color;
     }
 }
Example #18
0
 public Vector3 ToUnityPosition(NPVoxCoord voxCoord)
 {
     return(new Vector3(
                this.voxelOffset.x - unitySize.x * 0.5f + voxCoord.X * voxelSize.x + voxelSize.x * 0.5f,
                this.voxelOffset.y - unitySize.y * 0.5f + voxCoord.Y * voxelSize.y + voxelSize.y * 0.5f,
                this.voxelOffset.z - unitySize.z * 0.5f + voxCoord.Z * voxelSize.z + voxelSize.z * 0.5f
                ));
 }
Example #19
0
 public bool IsInBoneMask(NPVoxCoord coord, uint mask)
 {
     if (HasVoxel(coord))
     {
         return((boneMasks[GetIndex(coord)] & mask) != 0 || mask == 0);
     }
     return(false);
 }
Example #20
0
 public Vector3 ToUnityDirection(NPVoxCoord voxCoord)
 {
     return(new Vector3(
                voxCoord.X * voxelSize.x,
                voxCoord.Y * voxelSize.y,
                voxCoord.Z * voxelSize.z
                ));
 }
Example #21
0
 public uint GetBoneMask(NPVoxCoord coord)
 {
     if (HasVoxel(coord))
     {
         return(boneMasks[GetIndex(coord)]);
     }
     return(0);
 }
Example #22
0
    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);
    }
Example #23
0
    private void ResetSelection()
    {
        for (int i = 0; i < m_selections.Length; i++)
        {
            m_selections[i] = 0x00;
        }

        m_lastSelected     = NPVoxCoord.INVALID;
        m_lastSelectedData = null;
    }
Example #24
0
 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;
 }
Example #25
0
 public virtual void Initialize(NPVoxCoord size)
 {
     this.numVoxels      = -1;
     this.size           = size;
     this.colortable     = null;
     this.voxelGroups    = null;
     this.numVoxelGroups = 1;
     this.voxels         = new byte[size.X * size.Y * size.Z];
     this.Sockets        = new NPVoxSocket[] { };
     this.version++;
     this.voxelListCache = null;
 }
Example #26
0
    public NPVoxBox(NPVoxCoord leftDownBack, NPVoxCoord rightUpForward)
    {
//        if ( rightUpForward.X < leftDownBack.X )
//        {
//            Debug.Log( "WTf" );
//        }
        Assert.IsTrue(rightUpForward.X >= leftDownBack.X, rightUpForward.X + " is < than " + leftDownBack.X);
        Assert.IsTrue(rightUpForward.Y >= leftDownBack.Y);
        Assert.IsTrue(rightUpForward.Z >= leftDownBack.Z);
        this.leftDownBack   = leftDownBack;
        this.rightUpForward = rightUpForward;
    }
Example #27
0
    public static NPVoxBox FromCenterSize(NPVoxCoord center, NPVoxCoord size)
    {
        Assert.IsTrue(size.X % 2 == 1, "Center is not representable in NPVoxCoords for this Box");
        Assert.IsTrue(size.Y % 2 == 1, "Center is not representable in NPVoxCoords for this Box");
        Assert.IsTrue(size.Z % 2 == 1, "Center is not representable in NPVoxCoords for this Box");
        NPVoxCoord SizeHalf = new NPVoxCoord(
            (sbyte)(size.X / 2),
            (sbyte)(size.Y / 2),
            (sbyte)(size.Z / 2)
            );

        return(new NPVoxBox(center - SizeHalf, center + SizeHalf));
    }
Example #28
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);
    }
Example #29
0
    public override void SetContext(NPVoxNormalProcessorPreviewContext _context)
    {
        base.SetContext(_context);

        NPVoxCoord size = m_context.MeshOutput.GetVoxModel().Size;

        m_selections = new sbyte[size.X * size.Y * size.Z];
        for (int i = 0; i < m_selections.Length; i++)
        {
            m_selections[i] = UNSELECTED;
        }

        InitMeshNormals();
    }
Example #30
0
    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);
    }