Exemplo n.º 1
0
        public override void PeriodicUpdate()
        {
            lastReceivedColor = colorChannel.Get();

            if (_materialInstance != null)
            {
                _materialInstance.SetColor(_shaderPropertyId, lastReceivedColor);
            }
        }
Exemplo n.º 2
0
        protected virtual void Update()
        {
            if (eligibilitySwitch != null && activationGesture != null)
            {
                var shouldBeOn = activationGesture.isEligible;
                if (eligibilitySwitch.GetIsOnOrTurningOn() && !shouldBeOn)
                {
                    eligibilitySwitch.Off();
                }
                else if (eligibilitySwitch.GetIsOffOrTurningOff() && shouldBeOn)
                {
                    eligibilitySwitch.On();
                }
            }

            // Update the color at the color receiving channel.
            this.color = colorChannelIn.Get();

            // Update the radius at the radius receiving channel.
            this.radius = radiusChannelIn.Get();

            // If we have a tip renderer reference, always set its color to match the current
            // color of the brush.
            if (_lastColor.HasValue && this.color != _lastColor)
            {
                if (tipRendererForColor != null)
                {
                    _tipMaterialInstance = tipRendererForColor.material;
                }
                if (_tipMaterialInstance != null)
                {
                    _tipMaterialInstance.color = this.color;
                }
            }
            else
            {
                _lastColor = this.color;
            }

            // If we have brush head renderer reference, set its color depending on whether
            // or not we're painting.
            var targetBrushHeadColor = nonPaintingBrushHeadColor;

            if (isPainting)
            {
                targetBrushHeadColor = this.color;
            }
            if (brushHeadColorRenderer != null)
            {
                _brushHeadMaterialInstance = brushHeadColorRenderer.material;
            }
            if (_brushHeadMaterialInstance != null)
            {
                _brushHeadMaterialInstance.SetColor(_brushHeadColorPropId, targetBrushHeadColor);
            }
        }
        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();
        }