Пример #1
0
        public override void Use(SculptState state, Deformer deformer)
        {
            if (state.drawingDown)
            {
                deformer.UpdateMask(state);
                prevPosition = state.position;
            }

            if (deformer.SelectionCount == 0)
            {
                return;
            }

            var delta = state.worldToLocal * state.position - state.worldToLocal * prevPosition;

            var deformation = deformer.Deformation;

            for (int i = 0; i < deformer.SelectionCount; ++i)
            {
                deformation[i] = delta;
            }

            prevPosition = state.position;

            deformer.ApplyDeformation();
        }
Пример #2
0
        public override void Use(SculptState state, Deformer deformer)
        {
            deformer.UpdateMask(state);

            var mask        = deformer.Selection;
            var deformation = deformer.Deformation;

            Vector3 avgNormal = Vector3.zero;

            for (int i = 0; i < deformer.SelectionCount; i++)
            {
                avgNormal += SculptMesh.Normals[mask[i]];
            }
            avgNormal.Normalize();

            float amp = strength * state.strength;
            float inv = state.drawingInverted ? -1f : 1f;

            for (int i = 0; i < deformer.SelectionCount; ++i)
            {
                deformation[i] = amp * inv * avgNormal;
            }

            deformer.ApplyDeformation();
        }
Пример #3
0
        public override void Use(SculptState state, Deformer deformer)
        {
            deformer.UpdateMask(state);

            var mask         = deformer.Selection;
            var edgeRecorder = new HashSet <int>();

            Vector3[] deformation = deformer.Deformation;
            for (int i = 0; i < deformer.SelectionCount; i++)
            {
                var vert  = SculptMesh.Topology.Vertices[mask[i]];
                var force = new Vector3();

                foreach (var edge in vert.Edges)
                {
                    var other = edge.GetOtherVertex(vert);
                    var p0    = SculptMesh.Points[vert.Id];
                    var p1    = SculptMesh.Points[other.Id];
                    var delta = p1 - p0;
                    force += delta;
                }

                deformation[i] = strength * state.strength * force;
            }

            deformer.ApplyDeformation();
        }
Пример #4
0
        protected override SculptState GetState(SculptState prev)
        {
            if (Input.GetKeyDown("1"))
            {
                Menu.CurrentTool = ToolType.Standard;
            }
            if (Input.GetKeyDown("2"))
            {
                Menu.CurrentTool = ToolType.Move;
            }
            if (Input.GetKeyDown("3"))
            {
                Menu.CurrentTool = ToolType.Smooth;
            }

            if (Input.GetKeyDown("w"))
            {
                Menu.ToolSize.Value += parameterModStrength;
            }
            if (Input.GetKeyDown("q"))
            {
                Menu.ToolSize.Value -= parameterModStrength;
            }

            if (Input.GetKeyDown("s"))
            {
                Menu.ToolHardness.Value += parameterModStrength;
            }
            if (Input.GetKeyDown("a"))
            {
                var p = Menu.ToolHardness;
                p.Value = Mathf.Max(.1f, p.Value - parameterModStrength);
            }

            bool isNavigating = Input.GetKey(KeyCode.LeftAlt) || Input.GetKey(KeyCode.RightAlt);

            var drawing       = !isNavigating && Input.GetMouseButton(0);
            var drawingDown   = !isNavigating && Input.GetMouseButtonDown(0);
            var drawingUp     = !isNavigating && Input.GetMouseButtonUp(0);
            var brushPosition = GetBrushPosition(drawing, drawingDown, drawingUp);

            return(new SculptState
            {
                position = brushPosition,
                strength = 1f,

                drawing = drawing,
                drawingDown = drawingDown,
                drawingUp = drawingUp,
                drawingInverted = !isNavigating && Input.GetKey(KeyCode.LeftControl),
            });
        }
Пример #5
0
        public void UpdateMask(SculptState state)
        {
            Vector3 center         = state.worldToLocal.MultiplyPoint(state.position);
            float   radius         = (state.menuState.toolSize * state.worldToLocal.lossyScale.x) / 2;
            float   weightStrength = state.menuState.toolHardness;

            SelectionCount = mesh.Select(center, radius, Selection);

            var points = mesh.Points;

            for (int i = 0; i < SelectionCount; i++)
            {
                var   p = points[Selection[i]];
                float t = Mathf.Clamp01(Vector3.Distance(center, p) / radius);
                Weights[i] = 1f - Mathf.Pow(t * t * (3 - 2 * t), weightStrength);
            }
        }
Пример #6
0
        public IEnumerator ModifyMesh()
        {
            var timer = new Timer("modify-mesh");

            var menu = new Menu(ToolType.Move);

            var deformer = new Deformer(sculptMesh);

            var state = new SculptState {
                position     = Vector3.up * .5f,
                worldToLocal = sculptMesh.Wrapper.MeshTransform.worldToLocalMatrix
            };

            timer.PrintTime(() => {
                deformer.UpdateMask(state);
            }, "Select vertices");

            Vector3 offset = Vector3.up * Random.value;
            int     pickId = Random.Range(0, deformer.Selection.Length);

            var vec    = sculptMesh.Points[deformer.Selection[pickId]];
            var weight = deformer.Weights[pickId];

            timer.PrintTime(() => {
                var deformation = deformer.Deformation;
                for (int i = 0; i < deformer.SelectionCount; ++i)
                {
                    deformation[i] = offset;
                }
            }, "Create deform field");

            timer.PrintTime(() => sculptMesh.UpdateMeshData(), "Update mesh data");

            Debug.Log($"{deformer.SelectionCount} vertices modified out of {sculptMesh.Points.Length}.\n");

            timer.PrintTotalTime();
            timer.SaveCsv();

            Assert.Less(timer.TotalTime, 100);
            Assert.AreEqual(sculptMesh.Points[deformer.Selection[pickId]], vec + weight * offset);

            yield return(null);
        }
Пример #7
0
        protected override SculptState GetState(SculptState prev)
        {
            ManageInput();

            float strength = Input.GetAxis("Odyssey Trigger Squeeze Right");
            bool  drawing  = strength > 0f;

            var state = new SculptState
            {
                position = rightController.TransformPoint(effectPointOffset),
                strength = strength,

                drawing         = drawing,
                drawingDown     = drawing && !lastDrawingState,
                drawingUp       = !drawing && lastDrawingState,
                drawingInverted = Input.GetButton("Odyssey Trigger Left"),
            };

            lastDrawingState = drawing;

            return(state);
        }
Пример #8
0
 public abstract void Use(SculptState state, Deformer deformer);