private static void SanityCheckVersusReplacementBrush(Stroke oldStroke)
        {
            BrushDescriptor desc            = BrushCatalog.m_Instance.GetBrush(oldStroke.m_BrushGuid);
            BrushDescriptor replacementDesc = desc.m_Supersedes;

            if (replacementDesc == null)
            {
                return;
            }

            // Make a copy, since Begin/EndLineFromMemory mutate little bits of MemoryBrushStroke
            Stroke newStroke = new Stroke {
                m_BrushGuid      = replacementDesc.m_Guid,
                m_IntendedCanvas = oldStroke.Canvas,
                m_ControlPoints  = oldStroke.m_ControlPoints,
                m_BrushScale     = oldStroke.m_BrushScale,
                m_BrushSize      = oldStroke.m_BrushSize,
                m_Color          = oldStroke.m_Color,
                m_Seed           = oldStroke.m_Seed
            };

            Array.Copy(oldStroke.m_ControlPointsToDrop, newStroke.m_ControlPointsToDrop,
                       oldStroke.m_ControlPointsToDrop.Length);

            newStroke.Recreate(TrTransform.T(new Vector3(0.5f, 0, 0)));
        }
Example #2
0
 public void SetBrushForAllPointers(BrushDescriptor desc)
 {
     for (int i = 0; i < m_NumActivePointers; ++i)
     {
         m_Pointers[i].m_Script.SetBrush(desc);
     }
 }
Example #3
0
        /// Creates and returns a new subset containing the passed geometry.
        /// Pass:
        ///   brush - Selects the material/batch
        ///   nVerts - Amount to copy from the MasterBrush
        ///   nTris - Amount to copy from MasterBrush.m_Tris
        public BatchSubset CreateSubset(BrushDescriptor brush, int nVerts, int nTris, MasterBrush geometry)
        {
            var pool  = GetPool(brush);
            var batch = GetBatch(pool, nVerts);

            return(batch.AddSubset(nVerts, nTris, geometry));
        }
Example #4
0
        /// Creates and returns a new subset containing the passed geometry.
        /// Pass:
        ///   brush - Selects the material/batch
        ///   nVerts - Amount to copy from the MasterBrush
        public BatchSubset CreateSubset(BrushDescriptor brush, GeometryPool geometry)
        {
            var pool  = GetPool(brush);
            var batch = GetBatch(pool, geometry.NumVerts);

            return(batch.AddSubset(geometry));
        }
Example #5
0
        //
        // GeometryBrush API
        //

        protected override void InitBrush(BrushDescriptor desc, TrTransform localPointerXf)
        {
            base.InitBrush(desc, localPointerXf);
            m_geometry.Layout = GetVertexLayout(desc);

            if (m_ShapeModifier != ShapeModifier.None)
            {
                m_Displacements = new List <Vector3>();
            }

            if (m_HardEdges)
            {
                // Break verts along every seam
                m_VertsInClosedCircle = m_PointsInClosedCircle * 2;
            }
            else
            {
                // Only break a single vert to allow for proper UV unwrapping
                m_VertsInClosedCircle = m_PointsInClosedCircle + 1;
            }
            if (m_EndCaps)
            {
                m_VertsInCap = m_PointsInClosedCircle;
            }
            else
            {
                m_VertsInCap = 0;
            }

            // Start and end of circle are coincident, and need at least one more point.
            Debug.Assert(m_PointsInClosedCircle > 2);
            // Make sure the number of verts per knot are less than the upper bound
            Debug.Assert(m_VertsInClosedCircle <= kUpperBoundVertsPerKnot);
        }
Example #6
0
        // Finishes initializing the passed PbChild, and adds to children array
        protected void InitializeAndAddChild(
            PbChild child,
            BrushDescriptor desc, Color color, float relativeSize = 1)
        {
            Debug.Assert(child.m_brush == null);
            TrTransform     childXf = child.CalculateChildXfFixedScale(m_knots);
            BaseBrushScript brush   = Create(
                transform.parent, childXf, desc, color, m_BaseSize_PS * relativeSize);
            ParentBrush pb = brush as ParentBrush;

            string originalName = brush.gameObject.name;
            string newName;

            if (pb != null)
            {
                newName = string.Format("{0}.{1}", gameObject.name, m_children.Count);
            }
            else
            {
                newName = string.Format(
                    "{0}.{1} (Leaf {2})", gameObject.name, m_children.Count, originalName);
            }
            brush.gameObject.name = newName;

            if (pb != null)
            {
                pb.m_recursionLevel = m_recursionLevel + 1;
            }

            child.m_brush = brush;
            m_children.Add(child);
        }
Example #7
0
 protected override void InitBrush(BrushDescriptor desc, TrTransform localPointerXf)
 {
     base.InitBrush(desc, localPointerXf);
     SetDoubleSided(desc);
     m_DecayTimers.Clear();
     m_geometry.Layout = GetVertexLayout(desc);
 }
Example #8
0
 protected override void InitBrush(BrushDescriptor desc, TrTransform localPointerXf)
 {
     base.InitBrush(desc, localPointerXf);
     SetDoubleSided(desc);
     m_geometry.Layout = GetVertexLayout(desc);
     CreateVerticesFromKnots(0);
 }
Example #9
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);
        }
 protected override void InitBrush(BrushDescriptor desc, TrTransform localPointerXf)
 {
     base.InitBrush(desc, localPointerXf);
     m_QuadLengths = new float[m_NumQuads];
     // m_TotalStrokeLength = 0.0f;
     m_UpdateUVRequest.Clear();
 }
Example #11
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 #12
0
        /// Creates and returns a BatchSubset in the passed Canvas.
        /// If stroke contains too many CPs to fit, it will be cut short.
        /// This differs from what TB does, which is to create multiple subsets.
        public static BatchSubset CreateSubsetFromStroke(CanvasScript canvas, Stroke stroke)
        {
            // See PointerScript.RecreateLineFromMemory

            BrushDescriptor desc = BrushCatalog.m_Instance.GetBrush(stroke.m_BrushGuid);

            var             cp0 = stroke.m_ControlPoints[0];
            var             xf0 = TrTransform.TRS(cp0.m_Pos, cp0.m_Orient, stroke.m_BrushScale);
            BaseBrushScript bbs = BaseBrushScript.Create(
                canvas.transform, xf0, desc, stroke.m_Color, stroke.m_BrushSize);

            try
            {
                bbs.SetIsLoading();
                Assert.True(bbs.Canvas != null);

                foreach (var cp in stroke.m_ControlPoints)
                {
                    bbs.UpdatePosition_LS(
                        TrTransform.TRS(cp.m_Pos, cp.m_Orient, stroke.m_BrushScale), cp.m_Pressure);
                }
                return(bbs.FinalizeBatchedBrush());
            }
            finally
            {
                UnityEngine.Object.DestroyImmediate(bbs.gameObject);
            }
        }
Example #13
0
        protected override void InitBrush(BrushDescriptor desc, TrTransform localPointerXf)
        {
            base.InitBrush(desc, localPointerXf);
            m_bM11Compatibility = desc.m_M11Compatibility;
            m_geometry          = GeometryPool.Allocate();

            m_knots.Clear();
            Vector3    pos  = localPointerXf.translation;
            Quaternion ori  = localPointerXf.rotation;
            Knot       knot = new Knot
            {
                point = new PointerManager.ControlPoint
                {
                    m_Pos      = pos,
                    m_Orient   = ori,
                    m_Pressure = 1
                },
                length      = 0,
                smoothedPos = pos
            };

            m_knots.Add(knot);
            m_knots.Add(knot);

            MeshFilter mf = GetComponent <MeshFilter>();

            mf.mesh = null; // Force a new, empty, mf-owned mesh to be generated
            mf.mesh.MarkDynamic();
        }
Example #14
0
        // Returns the name used for TBT assets that are created per-brush.
        // Ideally, this name should be both determinsitic and non-colliding.
        //
        // Note that even if 2 TB brushes reference the same .mat, TBT contains
        // 1 .mat per brush.
        static string GetCreatedAssetNameForBrush(BrushDescriptor desc)
        {
            // New behavior for TBT15 and above: To handle the double-sided/single-sided fiasco,
            // use .asset/.mat names guaranteed not to conflict with previous brush versions' names.
            // Older brushes use the same old (rubbish) names.
            float creationVersion;

            if (!float.TryParse(desc.m_CreationVersion, out creationVersion))
            {
                throw new ExportFailedException(
                          "{0}: TBT brushes must have a valid creationVersion", desc.name);
            }
            else
            {
                int creationMajorVersion = (int)creationVersion;
                if (creationMajorVersion >= 15 || desc.name.EndsWith("SingleSided"))
                {
                    return(string.Format("{0}_{1}", desc.m_DurableName, creationMajorVersion));
                }
                else
                {
                    // Legacy. Would be better if this were something that couldn't accidentally
                    // change (eg, desc.m_DurableName); but that would change the legacy behavior
                    // since desc.m_DurableName has already fallen out of sync with desc.name.
                    // But a future motivated person could bake desc.name into some new field
                    // eg BrushDescriptor.m_TbtExportBaseName.
                    return(desc.name);
                }
            }
        }
 override public GeometryPool.VertexLayout GetVertexLayout(BrushDescriptor desc)
 {
     return(new GeometryPool.VertexLayout {
         bUseColors = true,
         bUseNormals = true,
         bUseTangents = false,
     });
 }
        //
        // GeometryBrush API
        //

        protected override void InitBrush(BrushDescriptor desc, TrTransform localPointerXf)
        {
            base.InitBrush(desc, localPointerXf);
            Debug.Assert(!desc.m_RenderBackfaces); // unsupported
            m_geometry.Layout = GetVertexLayout(desc);
            FixInitialKnotSize();
            CreateVerticesFromKnots(0);
        }
        //
        // GeometryBrush API
        //

        protected override void InitBrush(BrushDescriptor desc,
                                          TrTransform localPointerXf)
        {
            base.InitBrush(desc, localPointerXf);
            SetDoubleSided(desc);
            m_geometry.Layout = GetVertexLayout(desc);
            m_sizes           = new List <float>();
        }
Example #18
0
 static void WriteBrush(JsonWriter json, BrushDescriptor brush) {
   json.WriteStartObject();
   json.WritePropertyName("name");
   json.WriteValue(brush.name);
   json.WritePropertyName("guid");
   json.WriteValue(brush.m_Guid.ToString("D"));
   json.WriteEndObject();
 }
Example #19
0
 override public GeometryPool.VertexLayout GetVertexLayout(BrushDescriptor desc)
 {
     return(new GeometryPool.VertexLayout {
         uv0Size = 3,
         uv1Size = 4,
         bUseNormals = true,
         bUseColors = true,
     });
 }
Example #20
0
  public void TriggerStrokeSelected(Stroke stroke) {
    if (stroke != null) {
      m_ActiveBrush = BrushCatalog.m_Instance.GetBrush(stroke.m_BrushGuid);
    }

    if (StrokeSelected != null) {
      StrokeSelected(stroke);
    }
  }
Example #21
0
        public void SetBrushToDefault()
        {
            m_ActiveBrush = BrushCatalog.m_Instance.DefaultBrush;

            if (BrushSetToDefault != null)
            {
                BrushSetToDefault();
            }
        }
Example #22
0
 public override GeometryPool.VertexLayout GetVertexLayout(BrushDescriptor desc) {
   return new GeometryPool.VertexLayout {
     uv0Size = 2,
     uv0Semantic = GeometryPool.Semantic.XyIsUv,
     bUseNormals = true,
     bUseColors = true,
     bUseTangents = false
   };
 }
Example #23
0
 override public GeometryPool.VertexLayout GetVertexLayout(BrushDescriptor desc)
 {
     return(new GeometryPool.VertexLayout {
         // Don't use UVs, but don't want to write another shader that doesn't sample
         uv0Size = 2,
         bUseNormals = true,
         bUseColors = true,
     });
 }
        /// Returns a serialized ToolkitBrushDescriptor suitable for inclusion in the Toolkit
        public static string CreateAndSerialize(
            BrushDescriptor desc, Guid materialGuid, string assetName, out string meta)
        {
            ToolkitBrushDescriptor tkdesc = CreateFrom(desc);
            string yaml = SerializeToUnityString(tkdesc, assetName, out meta);

            yaml = ChangeToToolkitScript(yaml);
            yaml = SetMaterialGuid(yaml, materialGuid);
            return(yaml);
        }
Example #25
0
        // Passed transform is relative to the stroke
        protected virtual void InitBrush(BrushDescriptor desc, TrTransform localPointerXf)
        {
            Debug.Assert(m_BaseSize_PS != 0, "Set size and color first");
            m_Desc = desc;
            GetComponent <Renderer>().material = m_Desc.Material;
            m_EnableBackfaces = desc.m_RenderBackfaces;
            m_rng             = new StatelessRng(MathUtils.RandomInt());

            m_LastSpawnXf = localPointerXf;
        }
Example #26
0
        public float GenerateJitteredSize(BrushDescriptor desc, float currentSize)
        {
            float range             = desc.m_BrushSizeRange.y - desc.m_BrushSizeRange.x;
            float sizeJitter        = PointerManager.m_Instance.sizeJitter;
            float jitterValue       = Random.Range(-sizeJitter * range, sizeJitter * range) * 0.5f;
            float jitteredBrushSize = currentSize + jitterValue;

            jitteredBrushSize = Mathf.Clamp(jitteredBrushSize, desc.m_BrushSizeRange.x, desc.m_BrushSizeRange.y);
            return(jitteredBrushSize);
        }
 protected override void InitBrush(BrushDescriptor desc,
                                   TrTransform localPointerXf)
 {
     base.InitBrush(desc, localPointerXf);
     Shader.SetGlobalFloat("_GeniusParticlePreviewLifetime", kPreviewDuration);
     m_DecayTimers.Clear();
     m_geometry.Layout   = GetVertexLayout(desc);
     m_SpawnInterval     = (kSpawnInterval_PS * POINTER_TO_LOCAL) / m_Desc.m_ParticleRate;
     m_ParticleSizeScale = m_Desc.m_ParticleSpeed / m_Desc.m_BrushSizeRange.x;
 }
 public override GeometryPool.VertexLayout GetVertexLayout(BrushDescriptor desc) {
   // XXX: This doesn't work because blocks models may not always have the same vertex layout.
   //      It happens to work currently.
   var layout = new GeometryPool.VertexLayout();
   layout.bUseColors = true;
   layout.bUseNormals = true;
   layout.bUseTangents = false;
   layout.bUseVertexIds = false;
   return layout;
 }
Example #29
0
 override public GeometryPool.VertexLayout GetVertexLayout(BrushDescriptor desc)
 {
     return(new GeometryPool.VertexLayout {
         bUseColors = true,
         bUseNormals = true,
         bUseTangents = false,
         uv0Size = 3,
         uv0Semantic = GeometryPool.Semantic.XyIsUvZIsDistance,
     });
 }
Example #30
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);
            desc = null;
            return(false);
#endif
        }