/// <summary> /// When the appropriate rectangle button is clicked the button's OnExecute event handler /// calls this method to hook up the mouse click event which will wait for the user to select /// a point from which to start the drawing of the rectangle /// </summary> public virtual void StartRectangleInteraction() { _interactionEvents = _inventorApplication.CommandManager.CreateInteractionEvents(); _rectangleInteractionGraphics = _interactionEvents.InteractionGraphics; _rectangleClientGraphics = _rectangleInteractionGraphics.OverlayClientGraphics; _rectangleLineNode = _rectangleClientGraphics.AddNode(1); _rectangleGraphicsDataSets = _rectangleInteractionGraphics.GraphicsDataSets; _rectangleCoordSet = _rectangleGraphicsDataSets.CreateCoordinateSet(1); _rectangleIndexSet = _rectangleGraphicsDataSets.CreateIndexSet(1); _onTerminate_Delegate = new InteractionEventsSink_OnTerminateEventHandler(StopInteraction); _interactionEvents.OnTerminate += _onTerminate_Delegate; _userInputEvents = _inventorApplication.CommandManager.UserInputEvents; _userInputEvents_OnContextMenuDelegate = new UserInputEventsSink_OnContextMenuEventHandler(UserInputEvents_OnContextMenu); _userInputEvents.OnContextMenu += _userInputEvents_OnContextMenuDelegate; _mouseEvents = _interactionEvents.MouseEvents; _mouseEvents.PointInferenceEnabled = true; _onMouseClick_Delegate = new MouseEventsSink_OnMouseClickEventHandler(OnMouseClick_CreateRectangle); _mouseEvents.OnMouseClick += _onMouseClick_Delegate; _interactionEvents.StatusBarText = "Select a Point from which to start the rectangle"; _interactionEvents.AllowCommandAliases = true; _interactionEvents.Start(); }
//----------------------------------------------------------------------------- //----------------- MoveCmd implement ---------------------------------------- //----------------------------------------------------------------------------- public void InitializePreviewGraphics() { m_interactionEvents = m_inventorApplication.CommandManager.CreateInteractionEvents(); InteractionGraphics interactionGraphics = m_interactionEvents.InteractionGraphics; ClientGraphics previewClientGraphics = interactionGraphics.PreviewClientGraphics; m_previewClientGraphicsNode = previewClientGraphics.AddNode(1); m_pointGraphics = m_previewClientGraphicsNode.AddPointGraphics(); GraphicsDataSets graphicsDateSets = interactionGraphics.GraphicsDataSets; m_graphicsCoordinateSet = graphicsDateSets.CreateCoordinateSet(1); m_graphicsColorSet = graphicsDateSets.CreateColorSet(1); m_graphicsColorSet.Add(1, 255, 0, 0); m_graphicsColorIndexSet = graphicsDateSets.CreateIndexSet(1); m_pointGraphics.CoordinateSet = m_graphicsCoordinateSet; m_pointGraphics.BurnThrough = true; }
public void InitializePreviewGraphics() { m_interactionEvents = m_inventorApplication.CommandManager.CreateInteractionEvents(); InteractionGraphics interactionGraphics = m_interactionEvents.InteractionGraphics; ClientGraphics previewClientGraphics = interactionGraphics.PreviewClientGraphics; m_previewClientGraphicsNode = previewClientGraphics.AddNode(1); m_triangleStripGraphics = m_previewClientGraphicsNode.AddTriangleStripGraphics(); GraphicsDataSets graphicsDataSets = interactionGraphics.GraphicsDataSets; m_graphicsCoordinateSet = graphicsDataSets.CreateCoordinateSet(1); m_graphicsColorSet = graphicsDataSets.CreateColorSet(1); m_graphicsColorSet.Add(1, 100, 100, 200); m_graphicsColorSet.Add(2, 150, 150, 250); m_graphicsColorIndexSet = graphicsDataSets.CreateIndexSet(1); m_triangleStripGraphics.CoordinateSet = m_graphicsCoordinateSet; m_triangleStripGraphics.ColorSet = m_graphicsColorSet; m_triangleStripGraphics.ColorIndexSet = m_graphicsColorIndexSet; m_triangleStripGraphics.ColorBinding = ColorBindingEnum.kPerItemColors; m_triangleStripGraphics.BurnThrough = true; }
//-------------------------------------------------------- public BlockFormCmd() { m_blockForm = null; m_previewClientGraphicsNode = null; m_triangleStripGraphics = null; m_graphicsCoordinateSet = null; m_graphicsColorSet = null; m_graphicsColorIndexSet = null; }
public MoveCmd() { m_moveCmdDlg = null; m_selectFace = null; m_selectiFeature = null; m_UCS = null; m_previewClientGraphicsNode = null; m_pointGraphics = null; m_graphicsCoordinateSet = null; m_graphicsColorSet = null; m_graphicsColorIndexSet = null; m_highlightSet = null; }
public void TerminatePreviewGraphics() { m_graphicsCoordinateSet.Delete(); m_graphicsColorSet.Delete(); m_graphicsColorIndexSet.Delete(); m_pointGraphics.Delete(); m_previewClientGraphicsNode.Delete(); m_graphicsCoordinateSet = null; m_graphicsColorSet = null; m_graphicsColorIndexSet = null; m_pointGraphics = null; m_previewClientGraphicsNode = null; }
/// <summary> /// Simplifies the mesh provided, then places it back into the parameters. /// </summary> /// <remarks> /// Repeatedly remove the shortest edge in the mesh, reducing the triangle count by two each step. This is repeated /// until the triangle count is low enough or more than 2000 tries have been made. /// </remarks> /// <param name="verts">The original and final verticies. (3 elements per vertex)</param> /// <param name="vertCount">The original and final vertex counts.</param> /// <param name="inds">The original and final index buffer. (3 element per triangle, zero based)</param> /// <param name="trisCount">The original and final triangle counts.</param> private static void Simplify(ref float[] verts, ref uint vertCount, ref uint[] inds, ref uint trisCount) { // Setup edge relations, compute min edge lengths... List <SimplificationVertex> simplVerts = new List <SimplificationVertex>(); for (int i = 0; i < vertCount; i++) { simplVerts.Add(new SimplificationVertex(verts[i * 3], verts[i * 3 + 1], verts[i * 3 + 2])); } List <SimplificationFace> simplFace = new List <SimplificationFace>(); for (int i = 0; i < trisCount * 3; i += 3) { SimplificationFace face = new SimplificationFace(); face.verts[0] = simplVerts[(int)inds[i]]; face.verts[1] = simplVerts[(int)inds[i + 1]]; face.verts[2] = simplVerts[(int)inds[i + 2]]; foreach (SimplificationVertex v in face.verts) { v.faces.Add(face); // Make sure all verticies know their neighbors } simplFace.Add(face); } foreach (SimplificationFace face in simplFace) { face.updateInfo(); } simplFace.Sort(); #region FANCY_SIMPLIFY_GRAPHICS #if FANCY_SIMPLIFY_GRAPHICS double[] major, minor; GraphicsCoordinateSet majorCoordSet, minorCoordSet; major = new double[9 * simplFace.Count]; for (int a = 0; a < simplFace.Count; a++) { int off = a * 9; simplFace[a].tmpHead = off; Array.Copy(simplFace[a].verts[0].pos, 0, major, off, 3); Array.Copy(simplFace[a].verts[1].pos, 0, major, off + 3, 3); Array.Copy(simplFace[a].verts[2].pos, 0, major, off + 6, 3); } minor = new double[9]; AssemblyDocument part = ((AssemblyDocument)Exporter.INVENTOR_APPLICATION.ActiveDocument); GraphicsDataSets dataSets; try { dataSets = part.GraphicsDataSetsCollection.AddNonTransacting("convexHULL"); } catch { dataSets = part.GraphicsDataSetsCollection["convexHULL"]; dataSets.Delete(); dataSets = part.GraphicsDataSetsCollection.AddNonTransacting("convexHULL"); } ClientGraphics graphics; try { graphics = part.ComponentDefinition.ClientGraphicsCollection.AddNonTransacting("convexHULL"); } catch { graphics = part.ComponentDefinition.ClientGraphicsCollection["convexHULL"]; graphics.Delete(); graphics = part.ComponentDefinition.ClientGraphicsCollection.AddNonTransacting("convexHULL"); } { GraphicsNode node = graphics.AddNode(graphics.Count + 1); majorCoordSet = dataSets.CreateCoordinateSet(dataSets.Count + 1); majorCoordSet.PutCoordinates(major); LineGraphics primitive = node.AddLineGraphics(); primitive.BurnThrough = false; //Create Coordinate Index Set GraphicsIndexSet indexSetCoords = dataSets.CreateIndexSet(dataSets.Count + 1); for (int i = 0; i < major.Length; i += 3) { indexSetCoords.Add(indexSetCoords.Count + 1, i + 1); //from point 1 indexSetCoords.Add(indexSetCoords.Count + 1, i + 2); //connect to point 2 indexSetCoords.Add(indexSetCoords.Count + 1, i + 2); //from point 2 indexSetCoords.Add(indexSetCoords.Count + 1, i + 3); //connect to point 3 indexSetCoords.Add(indexSetCoords.Count + 1, i + 3); //from point 3 indexSetCoords.Add(indexSetCoords.Count + 1, i + 1); //connect to point 1 } primitive.CoordinateSet = majorCoordSet; primitive.CoordinateIndexSet = indexSetCoords; } { GraphicsNode node = graphics.AddNode(graphics.Count + 1); minorCoordSet = dataSets.CreateCoordinateSet(dataSets.Count + 1); minorCoordSet.PutCoordinates(minor); TriangleGraphics primitive = node.AddTriangleGraphics(); primitive.DepthPriority = 19999; //Create Coordinate Index Set GraphicsColorSet colorSet = dataSets.CreateColorSet(dataSets.Count + 1); for (int i = 0; i < minor.Length; i += 3) { colorSet.Add(colorSet.Count + 1, 255, 0, 0); } primitive.CoordinateSet = minorCoordSet; primitive.ColorSet = colorSet; primitive.ColorBinding = ColorBindingEnum.kPerItemColors; //primitive.CoordinateIndexSet = indexSetCoords; } Exporter.INVENTOR_APPLICATION.ActiveView.Update(); #endif #endregion // Time for shenanigans! We are going to naively pick the shortest edge and then remove it. Destroys two faces per loop typically. // Give it 2000 tries at most. for (int i = 0; i < 2000 && simplFace.Count > CONVEX_HULL_FACET_LIMIT; i++) { SimplificationFace bFace = simplFace[0]; // This is the edge to remove SimplificationVertex[] remove = new SimplificationVertex[] { bFace.verts[bFace.minEdge], bFace.verts[(bFace.minEdge + 1) % bFace.verts.Length] }; #region FANCY_SIMPLIFY_GRAPHICS #if FANCY_SIMPLIFY_GRAPHICS // Highlight Array.Copy(bFace.verts[0].pos, 0, minor, 0, 3); Array.Copy(bFace.verts[1].pos, 0, minor, 3, 3); Array.Copy(bFace.verts[2].pos, 0, minor, 6, 3); minorCoordSet.PutCoordinates(minor); Exporter.INVENTOR_APPLICATION.ActiveView.Update(); #endif #endregion // Find the center point of the edge. One edge -> one vertex float[] center = new float[3]; foreach (SimplificationVertex vert in remove) { center[0] += vert.pos[0] / 2.0f; center[1] += vert.pos[1] / 2.0f; center[2] += vert.pos[2] / 2.0f; vert.faces.Clear(); // Really, never use vertex again. } SimplificationVertex newVertex = new SimplificationVertex(center[0], center[1], center[2]); // Ineffeciently check each face to see if it shares a vertex with the edge for (int k = simplFace.Count - 1; k >= 0; k--) { int matched = 0; SimplificationFace face = simplFace[k]; for (int j = 0; j < face.verts.Length; j++) { if (face.verts[j] == remove[0] || face.verts[j] == remove[1]) { face.verts[j] = newVertex; #region FANCY_SIMPLIFY_GRAPHICS #if FANCY_SIMPLIFY_GRAPHICS Array.Copy(face.verts[j].pos, 0, major, face.tmpHead + (3 * j), 3); int index = (face.tmpHead / 3) + j + 1; majorCoordSet.Remove(index); majorCoordSet.Add(index, Exporter.INVENTOR_APPLICATION.TransientGeometry.CreatePoint(face.verts[j].pos[0], face.verts[j].pos[1], face.verts[j].pos[2])); #endif #endregion if (matched == 0) { newVertex.faces.Add(face); } matched++; } } // If we share at least two verts with the edge we are dead, since the triangle ends up with two // of the same vertex if (matched >= 2) { // Degenerate simplFace.RemoveAt(k); foreach (SimplificationVertex v in face.verts) { v.faces.Remove(face); } } else if (matched == 1) { // We changed, so update edge lengths face.updateInfo(); } } simplVerts.Add(newVertex); // Resort by edge length simplFace.Sort(); } simplVerts.RemoveAll((vert) => vert.faces.Count <= 0); // Rebuild arrays vertCount = (uint)simplVerts.Count; verts = new float[vertCount * 3]; for (int i = 0; i < simplVerts.Count; i++) { int off = i * 3; simplVerts[i].finalIndex = (i); // Our indices are zero based <3 Array.Copy(simplVerts[i].pos, 0, verts, off, 3); } trisCount = (uint)simplFace.Count; inds = new uint[trisCount * 3]; for (int i = 0; i < simplFace.Count; i++) { int off = i * 3; inds[off] = (uint)simplFace[i].verts[0].finalIndex; inds[off + 1] = (uint)simplFace[i].verts[1].finalIndex; inds[off + 2] = (uint)simplFace[i].verts[2].finalIndex; } }
////////////////////////////////////////////////////////////////////////////////////////////// // Description: Displays a LineGraphics using Index and Color Sets. // ////////////////////////////////////////////////////////////////////////////////////////////// static public void IndexSetDemo() { PartDocument doc = AdnInventorUtilities.InvApplication.ActiveDocument as PartDocument; string clientId = "{Add-in Guid}"; ClientGraphics graphics = null; GraphicsDataSets dataSets = null; // Add some error handling in case // graphics collection and data already exist try { graphics = doc.ComponentDefinition.ClientGraphicsCollection[clientId]; dataSets = doc.GraphicsDataSetsCollection[clientId]; } catch { graphics = doc.ComponentDefinition.ClientGraphicsCollection.Add(clientId); dataSets = doc.GraphicsDataSetsCollection.Add(clientId); } // Add new node and coord set // Id generation by increment - bad because previous nodes/sets // may have been deleted previously, hence making count invalid GraphicsNode node = graphics.AddNode(graphics.Count + 1); GraphicsCoordinateSet coordSet = dataSets.CreateCoordinateSet(dataSets.Count + 1); double[] coords = new double[] { 0.0, 0.0, 0.0, //point 1 1.0, 1.0, 0.0, //point 2 0.0, 1.0, 0.0, //point 3 1.0, 0.0, 0.0 //point 4 }; coordSet.PutCoordinates(ref coords); LineGraphics lineGraphPrimitive = node.AddLineGraphics(); lineGraphPrimitive.LineWeight = 5.0; //Create Coordinate Index Set GraphicsIndexSet indexSetCoords = dataSets.CreateIndexSet(dataSets.Count + 1); indexSetCoords.Add(1, 1); //from point 1 indexSetCoords.Add(2, 3); //connect to point 3 indexSetCoords.Add(3, 3); //from point 3 indexSetCoords.Add(4, 2); //connect to point 2 indexSetCoords.Add(5, 2); //from point 2 indexSetCoords.Add(6, 4); //connect to point 4 lineGraphPrimitive.CoordinateSet = coordSet; lineGraphPrimitive.CoordinateIndexSet = indexSetCoords; //Create the color set with two colors GraphicsColorSet colorSet = dataSets.CreateColorSet(dataSets.Count + 1); colorSet.Add(1, 221, 0, 0); colorSet.Add(2, 255, 170, 0); colorSet.Add(3, 119, 187, 17); //Create the index set for color GraphicsIndexSet indexSetColors = dataSets.CreateIndexSet(dataSets.Count + 1); indexSetColors.Add(1, 3); //line 1 uses color 3 indexSetColors.Add(2, 1); //line 2 uses color 1 indexSetColors.Add(3, 2); //line 3 uses color 2 lineGraphPrimitive.ColorSet = colorSet; lineGraphPrimitive.ColorIndexSet = indexSetColors; lineGraphPrimitive.ColorBinding = ColorBindingEnum.kPerItemColors; doc.Views[1].Update(); }
////////////////////////////////////////////////////////////////////////////////////////////// // Description: Displays a TriangleFan Graphics. // ////////////////////////////////////////////////////////////////////////////////////////////// static public void TriangleFanGraphicsDemo() { PartDocument doc = AdnInventorUtilities.InvApplication.ActiveDocument as PartDocument; string clientId = "{Add-in Guid}"; ClientGraphics graphics = null; GraphicsDataSets dataSets = null; try { graphics = doc.ComponentDefinition.ClientGraphicsCollection[clientId]; dataSets = doc.GraphicsDataSetsCollection[clientId]; } catch { graphics = doc.ComponentDefinition.ClientGraphicsCollection.Add(clientId); dataSets = doc.GraphicsDataSetsCollection.Add(clientId); } GraphicsNode node = graphics.AddNode(graphics.Count + 1); GraphicsCoordinateSet coordSet = dataSets.CreateCoordinateSet(dataSets.Count + 1); double[] coords = new double[] { 0.0, 0.0, 0.0, //point 1 1.0, 1.0, 0.0, //point 2 2.0, 0.0, 0.0, //point 3 3.0, 1.0, 0.0, //point 4 4.0, 0.0, 0.0, //point 5 5.0, 1.0, 0.0, //point 6 6.0, 0.0, 0.0, //point 7 }; coordSet.PutCoordinates(ref coords); TriangleFanGraphics triFanPrimitive = node.AddTriangleFanGraphics(); int[] strips = new int[] { 3, //points 1,2,3 for strip 1 4 //points 4,5,6,7 for strip 2 }; triFanPrimitive.PutStripLengths(ref strips); //Create the color set with 3 colors GraphicsColorSet colorSet = dataSets.CreateColorSet(dataSets.Count + 1); colorSet.Add(1, 221, 0, 0); colorSet.Add(2, 119, 187, 17); colorSet.Add(3, 119, 187, 17); //Create the index set for color GraphicsIndexSet indexSetColors = dataSets.CreateIndexSet(dataSets.Count + 1); indexSetColors.Add(1, 2); //strip 1 uses color 1 indexSetColors.Add(2, 1); //strip 2 uses color 2 triFanPrimitive.CoordinateSet = coordSet; triFanPrimitive.ColorIndexSet = indexSetColors; triFanPrimitive.ColorSet = colorSet; triFanPrimitive.ColorBinding = ColorBindingEnum.kPerStripColors; doc.Views[1].Update(); }
public void UpdatePreviewGraphics() { //remove the existing co-ordinates m_graphicsCoordinateSet = null; InteractionGraphics interactionGraphics = m_interactionEvents.InteractionGraphics; GraphicsDataSets graphicsDataSets = interactionGraphics.GraphicsDataSets; m_graphicsCoordinateSet = graphicsDataSets.CreateCoordinateSet(1); //remove the existing color indices m_graphicsColorIndexSet = null; m_graphicsColorIndexSet = graphicsDataSets.CreateIndexSet(1); m_triangleStripGraphics.CoordinateSet = m_graphicsCoordinateSet; m_triangleStripGraphics.ColorIndexSet = m_graphicsColorIndexSet; TransientGeometry transientGeometry = m_inventorApplication.TransientGeometry; Point point1 = transientGeometry.CreatePoint(0, 0, 0); Point point2 = transientGeometry.CreatePoint(m_length, 0, 0); Point point3 = transientGeometry.CreatePoint(m_length, m_width, 0); Point point4 = transientGeometry.CreatePoint(0, m_width, 0); Point point5 = transientGeometry.CreatePoint(0, 0, m_height); Point point6 = transientGeometry.CreatePoint(m_length, 0, m_height); Point point7 = transientGeometry.CreatePoint(m_length, m_width, m_height); Point point8 = transientGeometry.CreatePoint(0, m_width, m_height); AddGraphicsPoints(point1); AddColorIndex(1); AddGraphicsPoints(point6); AddColorIndex(1); AddGraphicsPoints(point2); AddColorIndex(1); AddGraphicsPoints(point3); AddColorIndex(1); AddGraphicsPoints(point1); AddColorIndex(2); AddGraphicsPoints(point4); AddColorIndex(2); AddGraphicsPoints(point8); AddColorIndex(1); AddGraphicsPoints(point3); AddColorIndex(1); AddGraphicsPoints(point7); AddColorIndex(2); AddGraphicsPoints(point6); AddColorIndex(2); AddGraphicsPoints(point8); AddColorIndex(1); AddGraphicsPoints(point5); AddColorIndex(1); AddGraphicsPoints(point1); AddColorIndex(2); AddGraphicsPoints(point6); AddColorIndex(2); m_inventorApplication.ActiveView.Update(); //Get the CommandManager object CommandManager oCommandManager; oCommandManager = m_inventorApplication.CommandManager; //Get control definition for the homeview command ControlDefinition oControlDef; oControlDef = oCommandManager.ControlDefinitions["AppIsometricViewCmd"]; //Excute the command oControlDef.Execute(); }