// 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); }
// // BaseBrushScript api // protected override bool UpdatePositionImpl( Vector3 translation, Quaternion rotation, float pressure) { TrTransform parentXf = TrTransform.TR(translation, rotation); // Update m_knots { Debug.Assert(m_knots.Count > 1, "There should always be at least 2 knots"); PbKnot cur = m_knots[m_knots.Count - 1]; PbKnot prev = m_knots[m_knots.Count - 2]; Vector3 move = parentXf.translation - prev.m_pointer.translation; cur.m_pointer = parentXf; float moveLen = move.magnitude; cur.m_tangentFrame = (moveLen > 1e-5f) ? MathUtils.ComputeMinimalRotationFrame( move / moveLen, prev.m_tangentFrame, cur.m_pointer.rotation) : prev.m_tangentFrame; cur.m_distance = prev.m_distance + moveLen; cur.m_pressuredSize = PressuredSize(pressure); } MaybeCreateChildren(); bool createdControlPoint = false; for (int i = 0; i < m_children.Count; ++i) { PbChild child = m_children[i]; var childXf = child.CalculateChildXfFixedScale(m_knots); if (child.m_brush.UpdatePosition_LS(childXf, pressure)) { // Need to save off any control point which is applicable to any of our children. // This does mean that if we have a giant tree of children, we might be saving // off every control point. // TODO: maybe there's a way for the parent to impose some order on this; // like it doesn't always send positions to its children? But that would make // interactive drawing less pretty. createdControlPoint = true; } } if (createdControlPoint) { m_knots.Add(m_knots[m_knots.Count - 1].Clone()); } return(createdControlPoint); }