/// <summary> /// Overridden function to create the shape instance /// </summary> /// <returns></returns> public override ShapeBase CreateShapeInstance() { PathShape shape = new PathShape("Path"); shape.Position = EditorManager.Scene.CurrentShapeSpawnPosition; PathNodeShape node; for (int i=0;i<4;i++) { node = new PathNodeShape(); node.Position = shape.Position; node.y += ((float)i - 1.5f) * 200.0f * EditorManager.Settings.GlobalUnitScaling; node.ShapeName = "node" + i; node.SetParent(shape); } shape.SmoothAll(false); return shape; }
/// <summary> /// Overridden function to create the shape instance /// </summary> /// <returns></returns> public override ShapeBase CreateShapeInstance() { PathShape shape = new PathShape("Circle Path"); shape.Position = EditorManager.Scene.CurrentShapeSpawnPosition; shape.Closed = true; // Magic number: http://www.tinaja.com/glib/ellipse4.pdf float fMagic = 0.551784f; float fRadius = 200.0f * EditorManager.Settings.GlobalUnitScaling; Vector3F rotCenter = shape.Position; Vector3F rotAngle = new Vector3F(0.0f, 0.0f, 0.0f); Matrix3F rotMatrix = new Matrix3F(); rotMatrix.FromEuler(rotAngle.X, rotAngle.Y, rotAngle.Z); PathNodeShape node; for (int i = 0; i < 4; i++) { node = new PathNodeShape(); node.Position = shape.Position; node.y -= fRadius; node.TangentIn = new Vector3F(node.TangentIn.X - fRadius * fMagic, 0.0f, 0.0f); node.TangentOut = new Vector3F(node.TangentOut.X + fRadius * fMagic, 0.0f, 0.0f); node.Position = shape.Position + rotMatrix * (node.Position - rotCenter); node.TangentIn = rotMatrix * (node.TangentIn); node.TangentOut = rotMatrix * (node.TangentOut); node.InType = PathNodeShape.PathNodeInOutType.Custom; node.OutType = PathNodeShape.PathNodeInOutType.Custom; node.ShapeName = "node" + i; node.SetParent(shape); rotAngle.X += 90.0f; rotMatrix.FromEuler(rotAngle.X, rotAngle.Y, rotAngle.Z); } return shape; }
/// <summary> /// Overridden function to insert the path node /// </summary> /// <param name="view"></param> public override void OnClicked(VisionViewBase view) { base.OnClicked (view); PathNodeShape newNode = new PathNodeShape(); newNode.Position = Position;// - Path.Position; newNode.ChildIndex = _iInsert; EditorManager.Actions.Add(AddShapeAction.CreateAddShapeAction(newNode, Path, Path.ParentLayer, false)); newNode.SmoothTangents(); string nodeName; for (int i = 0; true; i++) { nodeName = "node" + i; bool found = false; foreach (PathNodeShape node in Path.ChildCollection) { if (node.ShapeName == nodeName) found = true; } if (!found) break; } newNode.ShapeName = nodeName; EditorManager.ActiveView.Gizmo.SetSingleShape(newNode, false); }
/// <summary> /// Must be called from each node when it changed position /// </summary> public void OnSingleNodeChangedPosition(PathNodeShape node) { PathNodeShape [] nodes = PathNodes; foreach (PathNodeShape shape in nodes) shape.UpdateNode(); if (HasEngineInstance()) EnginePath.InvalidateBoundingBox(); }