예제 #1
0
 public override void Undo()
 {
     base.Undo();
     StrokeObject.SetActive(true);
 }
예제 #2
0
 public override void Redo()
 {
     base.Redo();
     StrokeObject.SetActive(false);
 }
        private void updateMeshRepresentation()
        {
            // Index + Thumb points -> StrokePoints in a StrokeObject.
            if (_strokeObj == null)
            {
                _strokeObj = gameObject.AddComponent <StrokeObject>();
            }

            // Get color via Ucon wiring.
            var brushColor = colorChannelIn.Get();

            _strokeObj.Clear();
            for (int i = 1; i < indexPoints.Count; i++)
            {
                var avgPos     = (indexPoints[i] + thumbPoints[i]) * 0.5f;
                var prevAvgPos = (indexPoints[i - 1] + thumbPoints[i - 1]) * 0.5f;

                var right   = (indexPoints[i] - thumbPoints[i]).normalized;
                var forward = (avgPos - prevAvgPos).normalized;
                if ((avgPos - prevAvgPos).sqrMagnitude < 1e-7f)
                {
                    continue;
                }
                var up  = Vector3.Cross(right, forward).normalized;
                var rot = Quaternion.LookRotation(forward, up);

                var radius = (indexPoints[i] - thumbPoints[i]).magnitude * 0.3f;

                var strokePoint = new StrokePoint()
                {
                    pose          = new Pose(avgPos, rot),
                    color         = brushColor,
                    radius        = radius,
                    temp_refFrame = Matrix4x4.identity
                };

                _strokeObj.Add(strokePoint);
            }

            // StrokeObjects -> PolyMesh.
            fillPolyMeshObject.polyMesh.Clear();
            var positions   = Pool <List <Vector3> > .Spawn(); positions.Clear();
            var polygons    = Pool <List <Polygon> > .Spawn(); polygons.Clear();
            var smoothEdges = Pool <List <Edge> > .Spawn(); smoothEdges.Clear();
            var colors      = Pool <List <Color> > .Spawn(); colors.Clear();

            try {
                strokePolyMesher.FillPolyMeshData(_strokeObj,
                                                  positions, polygons, smoothEdges, colors);

                fillPolyMeshObject.polyMesh.Fill(positions, polygons, smoothEdges, colors);
            }
            finally {
                positions.Clear(); Pool <List <Vector3> > .Recycle(positions);

                polygons.Clear(); Pool <List <Polygon> > .Recycle(polygons);

                smoothEdges.Clear(); Pool <List <Edge> > .Recycle(smoothEdges);

                colors.Clear(); Pool <List <Color> > .Recycle(colors);
            }

            // Refresh the Unity mesh representation of the PolyMeshObject.
            fillPolyMeshObject.RefreshUnityMesh();
        }