private void Update(EvaluationContext context) { var pointArray = PointArray.GetValue(context); if (pointArray == null || pointArray.Length == 0) { Length.Value = 0; Log.Warning("Invalid input for PointsToBuffer"); return; } Length.Value = pointArray.Length; var resourceManager = ResourceManager.Instance(); if (_bufferData.Length != pointArray.Length) { _bufferData = new T3.Core.DataTypes.Point[pointArray.Length]; } for (int index = 0; index < pointArray.Length; index++) { _bufferData[index] = pointArray[index]; } var stride = 32; _bufferWithViews.Buffer = _buffer; resourceManager.SetupStructuredBuffer(_bufferData, stride * pointArray.Length, stride, ref _buffer); resourceManager.CreateStructuredBufferSrv(_buffer, ref _bufferWithViews.Srv); resourceManager.CreateStructuredBufferUav(_buffer, UnorderedAccessViewBufferFlags.None, ref _bufferWithViews.Uav); OutBuffer.Value = _bufferWithViews; }
private void Update(EvaluationContext context) { var countX = Count.GetValue(context).Clamp(1, 10000); var count = countX; if (_points.Length != count) { _points = new T3.Core.DataTypes.Point[count]; _pointList.SetLength(count); } var startP = Start.GetValue(context); var endP = Offset.GetValue(context); var startW = StartW.GetValue(context); var scaleW = OffsetW.GetValue(context); var startPoint = new Vector3(startP.X, startP.Y, startP.Z); var offset = new Vector3(endP.X, endP.Y, endP.Z); var index = 0; for (var x = 0; x < countX; x++) { var fX = x / (float)countX; _points[index].Position = Vector3.Lerp(startPoint, startPoint + offset, fX); _points[index].Orientation = Quaternion.Identity; _points[index].W = MathUtils.Lerp(startW, startW + scaleW, fX); _pointList[index] = _points[index]; index++; } Result.Value = _points; PointList.Value = _pointList; }
private void AppendPoint(Point p, bool advanceIndex = true) { if (_pointList.NumElements >= _maxPointCount) { Log.Warning($"Cannot append {p} because buffer len of {_maxPointCount} reached"); return; } if (_writeIndex >= _pointList.NumElements - 1) { Log.Debug($"Increasing paint buffer length of {_pointList.NumElements} by {BufferIncreaseStep}..."); _pointList.SetLength(_pointList.NumElements + BufferIncreaseStep); } if (advanceIndex) { Log.Debug($"Writing {p.Position} at # {_writeIndex}"); } _pointList.TypedElements[_writeIndex] = p; if (advanceIndex) { _writeIndex++; } }
private void Update(EvaluationContext context) { var closeCircle = CloseCircle.GetValue(context); var circleOffset = closeCircle ? 1 : 0; var corners = Count.GetValue(context).Clamp(1, 10000); var pointCount = corners + circleOffset; var listCount = corners + 2 * circleOffset; // Separator if (_pointList.NumElements != listCount) { //_points = new T3.Core.DataTypes.Point[count]; _pointList.SetLength(listCount); } var axis = Axis.GetValue(context); var center = Center.GetValue(context); var offset = Offset.GetValue(context); var radius = Radius.GetValue(context); var radiusOffset = RadiusOffset.GetValue(context); var thickness = W.GetValue(context); var thicknessOffset = WOffset.GetValue(context); var angelInRads = StartAngel.GetValue(context) * MathUtils.ToRad + (float)Math.PI / 2; var deltaAngle = -Cycles.GetValue(context) * MathUtils.Pi2 / (pointCount - circleOffset); for (var index = 0; index < pointCount; index++) { var f = corners == 1 ? 1 : (float)index / pointCount; var length = MathUtils.Lerp(radius, radius + radiusOffset, f); var v = Vector3.UnitX * length; var rot = Quaternion.CreateFromAxisAngle(axis, angelInRads); var vInAxis = Vector3.Transform(v, rot) + Vector3.Lerp(center, center + offset, f); var p = new Point { Position = vInAxis, W = MathUtils.Lerp(thickness, thickness + thicknessOffset, f), Orientation = rot }; _pointList[index] = p; angelInRads += deltaAngle; } if (closeCircle) { _pointList[listCount - 1] = Point.Separator(); } ResultList.Value = _pointList; }
private void Update(EvaluationContext context) { if (IsActve.GetValue(context)) { _maxPointCount = MaxPointCount.GetValue(context); if (TriggerReset.GetValue(context)) { Reset(); } var isMouseDown = IsMouseButtonDown.GetValue(context); if (!isMouseDown && _mouseWasDown) { if (_currentStrokeLength == 1 && _writeIndex > 0) // add to points for single click to make it visible as a dot { var lastPoint = _pointList.TypedElements[_writeIndex - 1]; lastPoint.Position = PointFromMousePos(context, _lastMousePos + new Vector2(0, 0.01f)); AppendPoint(lastPoint); } AppendPoint(Point.Separator()); _currentStrokeLength = 0; } else if (isMouseDown) { var mousePos = MousePos.GetValue(context); if (!_mouseWasDown || Vector2.Distance(_lastMousePos, mousePos) > 0.001f) { AppendPoint(new Point() { Position = PointFromMousePos(context, mousePos), Orientation = Quaternion.Identity, W = 1, }); AppendPoint(Point.Separator(), advanceIndex: false); _currentStrokeLength++; } _lastMousePos = mousePos; } _mouseWasDown = isMouseDown; } PointList.Value = _pointList; }
private void Update(EvaluationContext context) { var filepath = FilePath.GetValue(context); if (!File.Exists(filepath)) { Log.Debug($"File {filepath} doesn't exist"); return; } var centerToBounds = CenterToBounds.GetValue(context); var scaleToBounds = ScaleToBounds.GetValue(context); SvgDocument svgDoc; try { svgDoc = SvgDocument.Open <SvgDocument>(filepath, null); } catch (Exception e) { Log.Warning($"Failed to load svg document {filepath}:" + e.Message); return; } var bounds = new Vector3(svgDoc.Bounds.Size.Width, svgDoc.Bounds.Size.Height, 0); var centerOffset = centerToBounds ? new Vector3(-bounds.X / 2, bounds.Y / 2, 0) : Vector3.Zero; var fitBoundsFactor = scaleToBounds ? (2f / bounds.Y) : 1; var scale = Scale.GetValue(context) * fitBoundsFactor; GraphicsPath newPath = new GraphicsPath(); var paths = new List <GraphicsPath>(); ConvertAllNodesIntoGraphicPaths(svgDoc.Descendants(), paths); newPath.Flatten(); var totalPointCount = 0; foreach (var p in paths) { p.Flatten(); totalPointCount += p.PointCount + 1; } if (totalPointCount != _pointListWithSeparator.NumElements) { _pointListWithSeparator.SetLength(totalPointCount); } int pointIndex = 0; foreach (var path in paths) { var startIndex = pointIndex; for (var pathPointIndex = 0; pathPointIndex < path.PathPoints.Length; pathPointIndex++) { var point = path.PathPoints[pathPointIndex]; _pointListWithSeparator.TypedElements[startIndex + pathPointIndex].Position = (new Vector3(point.X, 1 - point.Y, 0) + centerOffset) * scale; _pointListWithSeparator.TypedElements[startIndex + pathPointIndex].W = 1; _pointListWithSeparator.TypedElements[startIndex + pathPointIndex].Orientation = Quaternion.Identity; //pointIndex++; } // Calculate normals if (path.PathPoints.Length > 1) { for (var pathPointIndex = 0; pathPointIndex < path.PathPoints.Length; pathPointIndex++) { if (pathPointIndex == 0) { _pointListWithSeparator.TypedElements[startIndex + pathPointIndex].Orientation = RotationFromTwoPositions(_pointListWithSeparator.TypedElements[0].Position, _pointListWithSeparator.TypedElements[1].Position); } else if (pathPointIndex == path.PathPoints.Length - 1) { _pointListWithSeparator.TypedElements[startIndex + pathPointIndex].Orientation = RotationFromTwoPositions(_pointListWithSeparator.TypedElements[path.PathPoints.Length - 2].Position, _pointListWithSeparator.TypedElements[path.PathPoints.Length - 1].Position); } else { _pointListWithSeparator.TypedElements[startIndex + pathPointIndex].Orientation = RotationFromTwoPositions(_pointListWithSeparator.TypedElements[startIndex + pathPointIndex].Position, _pointListWithSeparator.TypedElements[startIndex + pathPointIndex + 1].Position); } // _pointListWithSeparator.TypedElements[startIndex + pathPointIndex].W = 1; // _pointListWithSeparator.TypedElements[startIndex + pathPointIndex].Orientation = Quaternion.Identity; } } pointIndex += path.PathPoints.Length; _pointListWithSeparator.TypedElements[pointIndex] = Point.Separator(); pointIndex++; } Log.Debug($"Loaded svg {filepath} with {pointIndex} points"); ResultList.Value = _pointListWithSeparator; }
public SvgToPoints() { ResultList.UpdateAction = Update; _pointListWithSeparator.TypedElements[_pointListWithSeparator.NumElements - 1] = Point.Separator(); }
public LinePoints() { ResultList.UpdateAction = Update; _pointListWithSeparator.TypedElements[2] = Point.Separator(); }
public APoint() { //ResultList.TransformableOp = this; ResultList.UpdateAction = Update; _pointListWithSeparator.TypedElements[1] = Point.Separator(); }