Example #1
0
        public GameObject BeginLineFromMemory(Stroke stroke, CanvasScript canvas)
        {
            BrushDescriptor rBrush = BrushCatalog.m_Instance.GetBrush(stroke.m_BrushGuid);

            if (rBrush == null)
            {
                // Ignore stroke
                return(null);
            }

            if (m_PreviewLight)
            {
                m_PreviewLight.enabled = false;
            }

            var cp0   = stroke.m_ControlPoints[0];
            var xf_CS = TrTransform.TRS(cp0.m_Pos, cp0.m_Orient, stroke.m_BrushScale);
            var xf_RS = canvas.Pose * xf_CS;

            // This transform used to be incorrect, but we didn't notice.
            // That implies this isn't necessary?
            transform.position = xf_RS.translation;
            transform.rotation = xf_RS.rotation;

            m_CurrentBrush     = rBrush;
            m_CurrentBrushSize = stroke.m_BrushSize;
            m_CurrentPressure  = cp0.m_Pressure;
            m_CurrentColor     = stroke.m_Color;
            CreateNewLine(canvas, xf_CS, null);
            m_CurrentLine.SetIsLoading();
            m_CurrentLine.RandomSeed = stroke.m_Seed;

            return(m_CurrentLine.gameObject);
        }
Example #2
0
        public void SetBrush(BrushDescriptor rBrush)
        {
            if (rBrush != null && rBrush != m_CurrentBrush)
            {
                m_BrushSizeRange = rBrush.m_BrushSizeRange;

                if (m_LastUsedBrushSize_CS != null)
                {
                    BrushSizeAbsolute = Coords.CanvasPose.scale * m_LastUsedBrushSize_CS.Value;
                }
                else
                {
                    BrushSize01 = 0.5f;
                }
                MarkBrushSizeUsed();

                DisablePreviewLine();
                SetTintableIntensity(rBrush);
                UpdateTintableRenderers();
                OnBrushChange(rBrush);
            }

            m_CurrentBrush = rBrush;
            ResetAudio();
        }
Example #3
0
 void OnMainPointerBrushChange(TiltBrush.BrushDescriptor brush) {
   if (brush.m_UseBloomSwatchOnColorPicker) {
     m_Renderer.material = m_BloomMaterial;
   } else {
     m_Renderer.material = m_DefaultMaterial;
   }
 }
Example #4
0
        /// <returns>null if not found</returns>
        public bool TryGetBrush(Guid guid, out BrushDescriptor desc)
        {
#if TILT_BRUSH
            desc = TiltBrush.BrushCatalog.m_Instance.GetBrush(guid);
            return(desc != null);
#else
            return(m_BrushManifest.BrushesByGuid.TryGetValue(guid, out desc));
#endif
        }
Example #5
0
        void OnMainPointerBrushChange(TiltBrush.BrushDescriptor brush)
        {
            // Clamp current color to constraints of selected brush and push result to pointer.
            m_BrushLuminanceMin  = brush.m_ColorLuminanceMin;
            m_BrushSaturationMax = brush.m_ColorSaturationMax;

            // This only works for LDR colors. If we need HDR brush colors, we could do the
            // luminance clamping only for LDR (because if it's HDR then luminance is high).
            // The saturation validation can possibly be done using the "S" from HSV, which
            // does work properly in HDR, but that might involve re-tuning the brush values.
            HSLColor hsl = (HSLColor)CurrentColor;

            if (hsl.l < m_BrushLuminanceMin || hsl.s > m_BrushSaturationMax)
            {
                // Assign to ourselves to ensure correct bounds and trigger events.
                CurrentColor = m_CurrentColor;
            }
        }
Example #6
0
        private void ModifyBrushTags()
        {
            Dictionary <string, string[]> tagsToAddMap    = App.UserConfig.Brushes.AddTagsToBrushes;
            Dictionary <string, string[]> tagsToRemoveMap = App.UserConfig.Brushes.RemoveTagsFromBrushes;

            // Add tags
            foreach (KeyValuePair <string, string[]> brushTagsPair in tagsToAddMap)
            {
                Brush brush = _FindBrushByDescription(brushTagsPair.Key);
                if (brush)
                {
                    string[] tagsToAdd = brushTagsPair.Value;
                    brush.m_Tags.AddRange(tagsToAdd);
                    brush.m_Tags = brush.m_Tags.Distinct().ToList();
                }
                else
                {
                    Debug.LogError($"Could not find brush ({brushTagsPair.Key}) to add tags to");
                }
            }

            // Remove tags
            foreach (KeyValuePair <string, string[]> brushTagsPair in tagsToRemoveMap)
            {
                Brush brush = _FindBrushByDescription(brushTagsPair.Key);
                if (brush)
                {
                    string[] tagsToRemove = brushTagsPair.Value;
                    brush.m_Tags = brush.m_Tags.Except(tagsToRemove).ToList();
                }
                else
                {
                    Debug.LogError($"Could not find brush ({brushTagsPair.Key}) to remove tags from");
                }
            }

            Brush _FindBrushByDescription(string brushDescription)
            {
                string           searchString = brushDescription.Trim();
                StringComparison comparison   = StringComparison.CurrentCultureIgnoreCase;

                return(m_AllBrushes.FirstOrDefault(descriptor => descriptor.m_Description.Equals(searchString, comparison)));
            }
        }
Example #7
0
 /// Set m_bDoubleSided according to settings in the descriptor
 protected void SetDoubleSided(TiltBrush.BrushDescriptor desc)
 {
     // Yuck. This class was authored assuming all this stuff was readonly,
     // which makes it awkward to now be able to set it from the descriptor
     if (desc.m_RenderBackfaces && !m_bDoubleSided)
     {
         // enable
         m_bDoubleSided            = true;
         NS                       *= 2;
         m_UpperBoundVertsPerKnot *= 2;
     }
     else if (!desc.m_RenderBackfaces && m_bDoubleSided)
     {
         // disable
         m_bDoubleSided            = false;
         NS                       /= 2;
         m_UpperBoundVertsPerKnot /= 2;
     }
 }
Example #8
0
 void SetTintableIntensity(TiltBrush.BrushDescriptor rBrush)
 {
     if (rBrush.Material.HasProperty("_EmissionGain"))
     {
         float emission = rBrush.Material.GetFloat("_EmissionGain");
         m_GlowPreviewEnabled = (emission > .25f) ? 1.0f : 0.0f;
         if (m_PreviewLight)
         {
             m_PreviewLight.enabled = m_AllowPreviewLight;
         }
     }
     else
     {
         m_GlowPreviewEnabled = 0.0f;
         if (m_PreviewLight)
         {
             m_PreviewLight.enabled = false;
         }
     }
 }