/// Duplicates a stroke. Duplicated strokes have a timestamp that corresponds to the current time. public Stroke DuplicateStroke(Stroke srcStroke, CanvasScript canvas, TrTransform?transform) { Stroke duplicate = new Stroke(srcStroke); if (srcStroke.m_Type == Stroke.Type.BatchedBrushStroke) { if (transform == null) { duplicate.CopyGeometry(canvas, srcStroke); } else { // If this fires, consider adding transform support to CreateGeometryByCopying Debug.LogWarning("Unexpected: Taking slow DuplicateStroke path"); duplicate.Recreate(transform, canvas); } } else { duplicate.Recreate(transform, canvas); } UpdateTimestampsToCurrentSketchTime(duplicate); MemoryListAdd(duplicate); return(duplicate); }
/// Restores the pose recieved callbacks that were saved off with DisablePoseTracking. Will merge /// any callbacks currently on OnControllerNewPoses. public void RestorePoseTracking() { if (m_OldOnPoseApplied != null) { if (NewControllerPosesApplied != null) { var list = m_OldOnPoseApplied.Concat(NewControllerPosesApplied.GetInvocationList()) .Distinct().Cast <Action>(); NewControllerPosesApplied = null; foreach (var handler in list) { NewControllerPosesApplied += handler; } } } // Restore camera xf. if (m_TrackingBackupXf != null) { Transform camXf = GetVrCamera().transform; camXf.position = m_TrackingBackupXf.Value.translation; camXf.rotation = m_TrackingBackupXf.Value.rotation; camXf.localScale = Vector3.one; m_TrackingBackupXf = null; } }
// -------------------------------------------------------------------------------------------- // // Tracking Methods // -------------------------------------------------------------------------------------------- // /// Clears the callbacks that get called when a new pose is received. The callbacks are saved /// So that they can be restored later with RestorePoseTracking. public void DisablePoseTracking() { m_TrackingBackupXf = TrTransform.FromTransform(GetVrCamera().transform); if (NewControllerPosesApplied == null) { m_OldOnPoseApplied = Array.Empty <Action>(); } else { m_OldOnPoseApplied = NewControllerPosesApplied.GetInvocationList().Cast <Action>().ToArray(); } NewControllerPosesApplied = null; }
/// Creates and returns a new subset containing the passed geometry. /// Pass: /// otherSubset - /// Specifies both the material/batch to copy into, /// as well as the geometry to copy. /// May be owned by a different BatchManager. /// leftTransform - optional transform to transform the subset. public BatchSubset CreateSubset(BatchSubset otherSubset, TrTransform?leftTransform = null) { Batch otherBatch = otherSubset.m_ParentBatch; BatchPool otherPool = otherBatch.ParentPool; var pool = GetPool(otherPool.m_BrushGuid); var batch = GetBatch(pool, otherSubset.m_VertLength); return(batch.AddSubset( otherBatch.Geometry, otherSubset.m_StartVertIndex, otherSubset.m_VertLength, otherSubset.m_iTriIndex, otherSubset.m_nTriIndex, leftTransform)); }
static Bounds GetBoundsFor(Vector3[] aVert, int iVert, int nVert, TrTransform?leftTransform = null) { if (nVert == 0) { var uninitializedBounds = new Bounds(); uninitializedBounds.SetMinMax(new Vector3(float.MaxValue, float.MaxValue, float.MaxValue), new Vector3(float.MinValue, float.MinValue, float.MinValue)); return(uninitializedBounds); } Vector3 center, size; Matrix4x4 leftTransformMatrix = leftTransform.HasValue ? leftTransform.Value.ToMatrix4x4() : Matrix4x4.identity; MathUtils.GetBoundsFor(leftTransformMatrix, iVert, iVert + nVert, aVert, out center, out size); return(new Bounds(center, size)); }
/// Returns a new subset containing the passed geometry. /// raises ArgumentOutOfRangeException if not enough room. /// /// Make sure the triangle indices refer only to verts inside the /// passed range of verts. /// /// Pass: /// geom - Geometry, a subset of which will be copied into the new subset /// i/nVert - start/count of verts to copy /// i/nTriIndex - start/count of triangle indices to copy. /// leftTransform - optional transform to transform the subset. /// public BatchSubset AddSubset( GeometryPool geom, int iVert, int nVert, int iTriIndex, int nTriIndex, TrTransform?leftTransform = null) { // If we're not empty, the caller should never have tried to add the subset, // because it's caller's responsibility to check HasSpaceFor(). // If we're empty, allow anything (up to the Unity limit). SelfCheck(); if (!HasSpaceFor(nVert) && (m_Geometry.NumVerts > 0)) { throw new ArgumentOutOfRangeException("nVert"); } if (m_Geometry.NumVerts == 0) { m_Geometry.Layout = geom.Layout; } BatchSubset child = new BatchSubset(); child.m_ParentBatch = this; m_Groups.Add(child); child.m_Active = true; child.m_StartVertIndex = m_Geometry.NumVerts; child.m_VertLength = nVert; child.m_iTriIndex = m_Geometry.NumTriIndices; child.m_nTriIndex = nTriIndex; geom.EnsureGeometryResident(); child.m_Bounds = GetBoundsFor(geom.m_Vertices, iVert, nVert, leftTransform); if (nVert > 0) { m_Geometry.Append(geom, iVert, nVert, iTriIndex, nTriIndex, leftTransform); DelayedUpdateMesh(); } SelfCheck(); return(child); }
static Bounds GetBoundsFor(List <Vector3> aVert, int iVert, int nVert, TrTransform?leftTransform = null) { return(GetBoundsFor(aVert.GetBackingArray(), iVert, nVert, leftTransform)); }