public bool Generate(Mesh mesh) { Vector3[] points; Vector3 position, vector; TriangleAsset[] triangles; cells = new CellAsset[mesh.triangles.Length / 3]; for (int i = 0, cellID = 0; i < mesh.triangles.Length; i += 3, cellID++) { triangles = new TriangleAsset[1]; points = new Vector3[3]; points[0] = mesh.vertices[mesh.triangles[i]]; points[1] = mesh.vertices[mesh.triangles[i + 1]]; points[2] = mesh.vertices[mesh.triangles[i + 2]]; vector = points[0] - points[1]; position = points[1] + vector.normalized * vector.magnitude / 2; vector = points[2] - position; position = position + vector.normalized * vector.magnitude / 2; triangles[0] = new TriangleAsset(points, null); cells[cellID] = new CellAsset("Cell " + cellID, position, triangles, this, Collection); } return(GenerateConnections()); }
public bool Remove(CellAsset cell) { bool found; CellAsset[] newCells; found = false; newCells = new CellAsset[cells.Length - 1]; for (int i = 0; i < newCells.Length; i++) { if (cells[i] == cell) { found = true; } newCells[i] = cells[i + ((found) ? 1 : 0)]; } found = (cells[newCells.Length] == cell) ? true : found; if (!found) { return(false); } cells = newCells; return(true); }
public static CellAsset Merge(CellAsset[] cells) { CellAsset result; ArrayList tags; //, connections; TriangleAsset[] triangles; int triangleCount; if (cells.Length == 0) { return(null); } else if (cells.Length == 1) { return(cells[0]); } triangleCount = 0; foreach (CellAsset cell in cells) { triangleCount += cell.Triangles.Length; } triangles = new TriangleAsset[triangleCount]; triangleCount = 0; foreach (CellAsset cell in cells) { Array.Copy(cell.Triangles, 0, triangles, triangleCount, cell.Triangles.Length); triangleCount += cell.Triangles.Length; } tags = new ArrayList(); foreach (CellAsset cell in cells) { foreach (int tag in cell.Tags) { if (!tags.Contains(tag)) { tags.Add(tag); } } } result = new CellAsset(cells[0].Name, cells[0].Position, triangles, cells[0].Network, cells[0].Collection); foreach (int tag in tags) { result.AddTag(tag); } return(result); }
public bool GenerateConnections(CellAsset cell) { int matches; Vector3 matchOne, matchTwo; foreach (CellAsset other in cells) { if (other == cell) { continue; } matches = 0; foreach (TriangleAsset cellTriangle in cell.Triangles) { foreach (TriangleAsset otherTriangle in other.Triangles) { foreach (Vector3 cellPoint in cellTriangle.Points) { foreach (Vector3 otherPoint in otherTriangle.Points) { if (cellPoint == otherPoint) { matches++; if (matches == 0) { matchOne = cellPoint; } else { matchTwo = cellPoint; } } } } } } if (matches == 2) { cell.AddConnection(new ConnectionAsset(cell, other, Mathf.Abs((matchOne - matchTwo).magnitude), Collection)); other.AddConnection(new ConnectionAsset(other, cell, Mathf.Abs((matchOne - matchTwo).magnitude), Collection)); } else if (matches > 2) { Debug.LogError("More than two match points between two cells. What an odd mesh..."); return(false); } } return(true); }
public void ReplaceConnections(ArrayList nodes, NetworkNodeAsset newNode) { NetworkNodeAsset[] theNodes; theNodes = new CellAsset[nodes.Count]; for (int i = 0; i < nodes.Count; i++) { theNodes[i] = ( NetworkNodeAsset )nodes[i]; } ReplaceConnections(theNodes, newNode); }
public static CellAsset Merge(ArrayList cells) { CellAsset[] theCells; theCells = new CellAsset[cells.Count]; for (int i = 0; i < cells.Count; i++) { theCells[i] = ( CellAsset )cells[i]; } return(Merge(theCells)); }
public CellAsset(CellAsset original, NetworkAsset network) : base(network, original.Collection) { this.Name = original.Name; this.Position = original.Position; this.triangles = new TriangleAsset[original.Triangles.Length]; for (int i = 0; i < original.Triangles.Length; i++) { this.triangles[i] = new TriangleAsset(original.Triangles[i], this); } this.Tags = new int[original.Tags.Length]; for (int i = 0; i < original.Tags.Length; i++) { this.Tags[i] = original.Tags[i]; } }
public bool Add(CellAsset cell) { CellAsset[] newCells; newCells = new CellAsset[cells.Length + 1]; for (int i = 0; i < cells.Length; i++) { if (cells[i].Name == cell.Name) { return(false); } newCells[i] = cells[i]; } newCells[cells.Length] = cell; cells = newCells; return(true); }
// TODO: In multiple node selections: Show a grid-node on the list in red if its target is null. Also don't connect it if its target is null. public void OnNodeGUI(IInspector inspector) { bool /*newBool, */ askedForConnections, addToConnections, selectTarget = false; CellAsset mergedCell; string addedTag; int[] sharedTags; Vector3 newVector3; float newFloat; NetworkAsset targetNetwork; NetworkNodeAsset targetNode; Texture2D[] tagsToggle = new Texture2D[2]; tagsToggle[1] = Resources.Tag; //GUILayout.Label( "", Resources.TextLineStyle, GUILayout.Height( 1 ) ); GUILayout.Space(30.0f); // Node properties // if (Editor.Instance.SelectedNode.Count == 1) // Singular selection { GUILayout.BeginHorizontal(); GUILayout.Space(15.0f); if (GUILayout.Button((showNode) ? Resources.Expanded : Resources.Collapsed, Resources.ListStyle, GUILayout.Width(Resources.DefaultListItemHeight), GUILayout.Height(Resources.DefaultListItemHeight))) { showNode = !showNode; } if (GUILayout.Toggle((( NetworkNodeAsset )Editor.Instance.SelectedNode[0]).Enabled, "", GUILayout.Width(Resources.DefaultListItemHeight), GUILayout.Height(Resources.DefaultListItemHeight)) != (( NetworkNodeAsset )Editor.Instance.SelectedNode[0]).Enabled) { (( NetworkNodeAsset )Editor.Instance.SelectedNode[0]).Enabled = !(( NetworkNodeAsset )Editor.Instance.SelectedNode[0]).Enabled; Editor.Instance.SaveCollection(); } tagsToggle[0] = Resources.Waypoint; nodeTags = (GUILayout.Toolbar(nodeTags ? 1 : 0, tagsToggle, GUILayout.Height(20.0f)) == 1); GUILayout.Label((( NetworkNodeAsset )Editor.Instance.SelectedNode[0]).Name + ((Editor.Instance.SelectedNode[0] is WaypointAsset) ? " (waypoint)" : (Editor.Instance.SelectedNode[0] is CellAsset) ? " (navmesh cell)" : " (grid node)"), GUILayout.MinWidth(20.0f)); GUILayout.FlexibleSpace(); if (GUILayout.Button(Resources.Help, GUI.skin.GetStyle("Label"))) { Resources.Documentation("Node"); } GUILayout.EndHorizontal(); if (showNode && !nodeTags) { GUILayout.BeginHorizontal(); GUILayout.Space(15.0f); GUILayout.BeginVertical(); if (Editor.Instance.SelectedNode[0] is WaypointAsset) // Waypoint specific properties { // Position newVector3 = EditorGUILayout.Vector3Field("Position", (Editor.Instance.SelectedNode[0] as WaypointAsset).Position); if ((Editor.Instance.SelectedNode[0] as WaypointAsset).Position != newVector3) { Editor.Instance.SaveCollection(); } /* * // Positioner * GUILayout.BeginHorizontal(); * GUILayout.BeginHorizontal( GUILayout.Width( Resources.DefaultLeftColumnWidth ) ); * GUILayout.FlexibleSpace(); * GUILayout.Label( "Positioner" ); * GUILayout.EndHorizontal(); * * if( Editor.Instance.GetWaypointPositioner( Editor.Instance.SelectedNetwork.Name, ( Editor.Instance.SelectedNode[ 0 ] as WaypointAsset ).Name ) == null ) * { * if( GUILayout.Button( "Create" ) ) * { * Editor.Instance.CreateWaypointPositioner( Editor.Instance.SelectedNetwork.Name, ( Editor.Instance.SelectedNode[ 0 ] as WaypointAsset ).Name, ( Editor.Instance.SelectedNode[ 0 ] as WaypointAsset ).Position ); * } * } * else * { * GUILayout.BeginVertical(); * if( GUILayout.Button( "Select" ) ) * { * Editor.Instance.SelectWaypointPositioner( Editor.Instance.GetWaypointPositioner( Editor.Instance.SelectedNetwork.Name, ( Editor.Instance.SelectedNode[ 0 ] as WaypointAsset ).Name ) ); * } * * newBool = GUILayout.Toggle( ( Editor.Instance.SelectedNode[ 0 ] as WaypointAsset ).DisableRuntime, "Disable at runtime" ); * if( newBool != ( Editor.Instance.SelectedNode[ 0 ] as WaypointAsset ).DisableRuntime ) * { * ( Editor.Instance.SelectedNode[ 0 ] as WaypointAsset ).DisableRuntime = newBool; * Editor.Instance.SaveCollection(); * } * GUILayout.EndVertical(); * } * GUILayout.EndHorizontal();*/ // Radius newFloat = EditorGUILayout.FloatField("Radius", (Editor.Instance.SelectedNode[0] as WaypointAsset).Radius); if (newFloat != (( WaypointAsset )Editor.Instance.SelectedNode[0]).Radius) { (( WaypointAsset )Editor.Instance.SelectedNode[0]).Radius = newFloat; Editor.Instance.SaveCollection(); } // Disconnect GUILayout.BeginHorizontal(); GUILayout.BeginHorizontal(GUILayout.Width(Resources.DefaultLeftColumnWidth)); GUILayout.FlexibleSpace(); GUILayout.Label("Connections"); GUILayout.EndHorizontal(); if (GUILayout.Button("Disconnect")) { (( WaypointAsset )Editor.Instance.SelectedNode[0]).Disconnect(); Editor.Instance.UpdateScene(); Editor.Instance.SaveCollection(); } GUILayout.EndHorizontal(); } else if (Editor.Instance.SelectedNode[0] is GridNodeAsset) // Grid node specific properties { GUILayout.BeginHorizontal(); GUILayout.BeginHorizontal(GUILayout.Width(Resources.DefaultLeftColumnWidth)); GUILayout.FlexibleSpace(); GUILayout.Label("Target"); GUILayout.EndHorizontal(); GUILayout.BeginVertical(); if ((( GridNodeAsset )Editor.Instance.SelectedNode[0]).Target != null) { if (GUILayout.Button((( GridNodeAsset )Editor.Instance.SelectedNode[0]).Target.Network.ToString() + "." + (( GridNodeAsset )Editor.Instance.SelectedNode[0]).Target.ToString())) // Select target { selectTarget = true; } } else { GUILayout.Label("No target"); } targetNetwork = ( NetworkAsset )Resources.PulldownPopup("Network", new ArrayList(Editor.Instance.Collection.Networks), "No networks in collection"); targetNode = ( NetworkNodeAsset )Resources.PulldownPopup("Node", (( GridNodeAsset )Editor.Instance.SelectedNode[0]).Target == null ? new ArrayList() : new ArrayList((( GridNodeAsset )Editor.Instance.SelectedNode[0]).Target.Network.Nodes), "No nodes in network"); if (targetNetwork != null && targetNetwork.Nodes.Length > 0) { (( GridNodeAsset )Editor.Instance.SelectedNode[0]).Target = targetNetwork.Nodes[0]; Editor.Instance.SaveCollection(); } else if (targetNode != null) { (( GridNodeAsset )Editor.Instance.SelectedNode[0]).Target = targetNode; Editor.Instance.SaveCollection(); } GUILayout.EndVertical(); GUILayout.EndHorizontal(); // Disconnect GUILayout.BeginHorizontal(); GUILayout.BeginHorizontal(GUILayout.Width(Resources.DefaultLeftColumnWidth)); GUILayout.FlexibleSpace(); GUILayout.Label("Connections"); GUILayout.EndHorizontal(); if (GUILayout.Button("Disconnect")) { (( WaypointAsset )Editor.Instance.SelectedNode[0]).Disconnect(); Editor.Instance.UpdateScene(); Editor.Instance.SaveCollection(); } GUILayout.EndHorizontal(); } GUILayout.EndVertical(); GUILayout.EndHorizontal(); if (selectTarget) { Editor.Instance.SelectedNetwork = (( GridNodeAsset )Editor.Instance.SelectedNode[0]).Target.Network; Editor.Instance.SelectedNode.Add((( GridNodeAsset )Editor.Instance.SelectedNode[0]).Target); Editor.Instance.SelectedNode.RemoveAt(0); Browser.Instance.CurrentHighlight = Browser.ItemType.Node; Editor.Instance.UpdateScene(); } } } else if (Editor.Instance.SelectedNode.Count > 1) // Multiple selection { GUILayout.BeginHorizontal(); GUILayout.Space(15.0f); if (GUILayout.Button((showNode) ? Resources.Expanded : Resources.Collapsed, Resources.ListStyle, GUILayout.Width(Resources.DefaultListItemHeight), GUILayout.Height(Resources.DefaultListItemHeight))) { showNode = !showNode; } tagsToggle[0] = Resources.Waypoint; nodeTags = (GUILayout.Toolbar(nodeTags ? 1 : 0, tagsToggle, GUILayout.Height(20.0f)) == 1); // GUILayout.Label( Resources.Waypoint, GUILayout.Width( Resources.DefaultListItemHeight ), GUILayout.Height( Resources.DefaultListItemHeight ) ); GUILayout.Label("Nodes", GUILayout.MinWidth(20.0f)); GUILayout.FlexibleSpace(); // nodeTags = GUILayout.Toggle( nodeTags, Resources.Tag, GUI.skin.GetStyle( "ToolbarButton" ) ); if (GUILayout.Button(Resources.Help, GUI.skin.GetStyle("Label"))) { Resources.Documentation("Node"); } GUILayout.EndHorizontal(); if (showNode) { GUILayout.BeginHorizontal(); GUILayout.Space(15.0f); GUILayout.BeginVertical(); foreach (NetworkNodeAsset node in Editor.Instance.SelectedNode) // List all nodes in selection { if (Editor.Instance.SelectedNode[0] is GridNodeAsset && (( GridNodeAsset )Editor.Instance.SelectedNode[0]).Target == null) { GUI.color = Color.red; } GUILayout.Label(node.Name + ((Editor.Instance.SelectedNode[0] is WaypointAsset) ? " (waypoint)" : ((Editor.Instance.SelectedNode[0] is GridNodeAsset) ? " (grid node)" : " (navmesh cell)"))); GUI.color = Color.white; } if (!nodeTags && Editor.Instance.SelectedNode[0] is WaypointAsset) // Make connect and disconnect available if multiple waypoints are selected { GUILayout.BeginHorizontal(); if (GUILayout.Button("Connect", GUILayout.Width(Resources.DefaultLeftColumnWidth))) // Connect { for (int i = 0; i < Editor.Instance.SelectedNode.Count - 1; i++) { (Editor.Instance.SelectedNode[i] as WaypointAsset).ConnectTo(Editor.Instance.SelectedNode[i + 1] as NetworkNodeAsset, connectionWidthNode); if (bidirectionalConnect) { (Editor.Instance.SelectedNode[i + 1] as WaypointAsset).ConnectTo(Editor.Instance.SelectedNode[i] as NetworkNodeAsset, connectionWidthNode); } } Editor.Instance.SaveCollection(); Editor.Instance.SelectedNode.Clear(); } GUILayout.BeginVertical(); connectionWidthNode = EditorGUILayout.FloatField("Connection width", connectionWidthNode); bidirectionalConnect = GUILayout.Toggle(bidirectionalConnect, "Bi-directional"); GUILayout.EndVertical(); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.BeginHorizontal(GUILayout.Width(Resources.DefaultLeftColumnWidth)); GUILayout.FlexibleSpace(); GUILayout.Label("Connections"); GUILayout.EndHorizontal(); if (GUILayout.Button("Disconnect") && EditorUtility.DisplayDialog("Remove all connections?", "Are you sure that you wish to remove all connections from the selected waypoints?\n\nWARNING: Disconnect on multi-selections removes all connections going from the selected waypoints to any other waypoint - whether it is part of the selection or not. This cannot be undone.", "Disconnect", "Cancel")) // Disconnect { foreach (WaypointAsset waypoint in Editor.Instance.SelectedNode) { waypoint.Disconnect(); } Editor.Instance.SaveCollection(); } GUILayout.EndHorizontal(); } else if (!nodeTags && Editor.Instance.SelectedNode[0] is GridNodeAsset) // Make connect and disconnect available if multiple grid nodes are selected { GUILayout.BeginHorizontal(); if (GUILayout.Button("Connect", GUILayout.Width(Resources.DefaultLeftColumnWidth))) // Connect { for (int i = 0; i < Editor.Instance.SelectedNode.Count - 1; i++) { (Editor.Instance.SelectedNode[i] as GridNodeAsset).ConnectTo(Editor.Instance.SelectedNode[i + 1] as GridNodeAsset, connectionWidthNode); if (bidirectionalConnect) { (Editor.Instance.SelectedNode[i + 1] as GridNodeAsset).ConnectTo(Editor.Instance.SelectedNode[i] as GridNodeAsset, connectionWidthNode); } } Editor.Instance.SaveCollection(); Editor.Instance.SelectedNode.Clear(); } GUILayout.BeginVertical(); connectionWidthNode = EditorGUILayout.FloatField("Connection width", connectionWidthNode); bidirectionalConnect = GUILayout.Toggle(bidirectionalConnect, "Bi-directional"); GUILayout.EndVertical(); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.BeginHorizontal(GUILayout.Width(Resources.DefaultLeftColumnWidth)); GUILayout.FlexibleSpace(); GUILayout.Label("Connections"); GUILayout.EndHorizontal(); if (GUILayout.Button("Disconnect") && EditorUtility.DisplayDialog("Remove all connections?", "Are you sure that you wish to remove all connections from the selected grid nodes?\n\nWARNING: Disconnect on multi-selections removes all connections going from the selected grid nodes to any other grid node - whether it is part of the selection or not. This cannot be undone.", "Disconnect", "Cancel")) // Disconnect { foreach (GridNodeAsset node in Editor.Instance.SelectedNode) { node.Disconnect(); } Editor.Instance.SaveCollection(); } GUILayout.EndHorizontal(); } else if (!nodeTags && Editor.Instance.SelectedNode[0] is CellAsset) // Make merge available if cell assets are selected { GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); if (GUILayout.Button("Merge")) { mergedCell = CellAsset.Merge(Editor.Instance.SelectedNode); (( NavmeshAsset )Editor.Instance.SelectedNetwork).ReplaceConnections(Editor.Instance.SelectedNode, mergedCell); foreach (CellAsset oldCell in Editor.Instance.SelectedNode) { (( NavmeshAsset )Editor.Instance.SelectedNetwork).Remove(oldCell); } (( NavmeshAsset )Editor.Instance.SelectedNetwork).Add(mergedCell); Editor.Instance.SelectedNode.Clear(); Debug.Log("TODO: Control should scan all cell networks for connections leading to any of the cells and these should be replaced by new connections to the new cell"); Editor.Instance.SaveCollection(); } GUILayout.EndHorizontal(); } GUILayout.EndVertical(); GUILayout.EndHorizontal(); } } if (!showNode || !nodeTags) { return; } // Node tags toolbar // sharedTags = Resources.SharedTags(Editor.Instance.SelectedNode); GUILayout.BeginHorizontal(/*"Toolbar"*/); GUILayout.Space(30.0f); //GUILayout.Label( "Tags" ); //GUILayout.FlexibleSpace(); addedTag = Resources.PulldownPopup("Add tag", new ArrayList(Editor.Instance.Collection.Tags), "No tags in collection") as string; if (addedTag != null) // Add the new tag { askedForConnections = false; addToConnections = false; foreach (NetworkNodeAsset node in Editor.Instance.SelectedNode) // Apply the tag to all nodes in selection { node.AddTag(addedTag); if (!askedForConnections && node.Connections.Length > 0) // Ask if the tag should be applied to all connections from the nodes in the selection { askedForConnections = true; if (EditorUtility.DisplayDialog("Apply to connections?", "Should the tag \"" + addedTag + "\" be applied to the connections from the selection as well?", "Apply", "Do not apply")) { addToConnections = true; } } if (addToConnections) // Apply the tag to all connections of the node { foreach (ConnectionAsset connection in node.Connections) { connection.AddTag(addedTag); } } } Editor.Instance.SaveCollection(); } if ((/*Editor.Instance.SelectedNode.Count > 1 && */ System.Array.IndexOf(sharedTags, selectedNodeTag) != -1) && GUILayout.Button("Delete", GUILayout.Height(15.0f))) { foreach (TaggedAsset asset in Editor.Instance.SelectedNode) { asset.RemoveTag(selectedNodeTag); } Editor.Instance.SaveCollection(); } GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); // Node tags list // GUILayout.BeginHorizontal(); GUILayout.Space(30.0f); GUILayout.BeginVertical(); if (Editor.Instance.SelectedNode.Count == 1) { if ((Editor.Instance.SelectedNode[0] as NetworkNodeAsset).Tags.Length == 0) { GUILayout.Label("No tags added"); } else { selectedNodeTag = ( int )Resources.SelectList((Editor.Instance.SelectedNode[0] as NetworkNodeAsset).Tags, selectedNodeTag, OnTagListItemGUI); } } else { if (sharedTags.Length > 0) { selectedNodeTag = ( int )Resources.SelectList(sharedTags, selectedNodeTag, OnTagListItemGUI); } else { GUILayout.Label("No shared tags in selection"); } } GUILayout.EndVertical(); GUILayout.EndHorizontal(); }
public TriangleAsset( TriangleAsset original, CellAsset cell ) { this.Points = original.Points; this.cell = cell; }
public TriangleAsset( Vector3[] points, CellAsset cell ) { Points = points; this.cell = cell; }
public void ReplaceConnections( ArrayList nodes, NetworkNodeAsset newNode ) { NetworkNodeAsset[] theNodes; theNodes = new CellAsset[ nodes.Count ]; for( int i = 0; i < nodes.Count; i++ ) { theNodes[ i ] = ( NetworkNodeAsset )nodes[ i ]; } ReplaceConnections( theNodes, newNode ); }
public bool Generate( Mesh mesh ) { Vector3[] points; Vector3 position, vector; TriangleAsset[] triangles; cells = new CellAsset[ mesh.triangles.Length / 3 ]; for( int i = 0, cellID = 0; i < mesh.triangles.Length; i += 3, cellID++ ) { triangles = new TriangleAsset[ 1 ]; points = new Vector3[ 3 ]; points[ 0 ] = mesh.vertices[ mesh.triangles[ i ] ]; points[ 1 ] = mesh.vertices[ mesh.triangles[ i + 1 ] ]; points[ 2 ] = mesh.vertices[ mesh.triangles[ i + 2 ] ]; vector = points[ 0 ] - points[ 1 ]; position = points[ 1 ] + vector.normalized * vector.magnitude / 2; vector = points[ 2 ] - position; position = position + vector.normalized * vector.magnitude / 2; triangles[ 0 ] = new TriangleAsset( points, null ); cells[ cellID ] = new CellAsset( "Cell " + cellID, position, triangles, this, Collection ); } return GenerateConnections(); }
public bool Remove( CellAsset cell ) { bool found; CellAsset[] newCells; found = false; newCells = new CellAsset[ cells.Length - 1 ]; for( int i = 0; i < newCells.Length; i++ ) { if( cells[ i ] == cell ) { found = true; } newCells[ i ] = cells[ i + ( ( found ) ? 1 : 0 ) ]; } found = ( cells[ newCells.Length ] == cell ) ? true : found; if( !found ) { return false; } cells = newCells; return true; }
public TriangleAsset(TriangleAsset original, CellAsset cell) { this.Points = original.Points; this.cell = cell; }
public TriangleAsset(Vector3[] points, CellAsset cell) { Points = points; this.cell = cell; }
public static CellAsset Merge( CellAsset[] cells ) { CellAsset result; ArrayList tags;//, connections; TriangleAsset[] triangles; int triangleCount; if( cells.Length == 0 ) { return null; } else if( cells.Length == 1 ) { return cells[ 0 ]; } triangleCount = 0; foreach( CellAsset cell in cells ) { triangleCount += cell.Triangles.Length; } triangles = new TriangleAsset[ triangleCount ]; triangleCount = 0; foreach( CellAsset cell in cells ) { Array.Copy( cell.Triangles, 0, triangles, triangleCount, cell.Triangles.Length ); triangleCount += cell.Triangles.Length; } tags = new ArrayList(); foreach( CellAsset cell in cells ) { foreach( int tag in cell.Tags ) { if( !tags.Contains( tag ) ) { tags.Add( tag ); } } } result = new CellAsset( cells[ 0 ].Name, cells[ 0 ].Position, triangles, cells[ 0 ].Network, cells[ 0 ].Collection ); foreach( int tag in tags ) { result.AddTag( tag ); } return result; }
public static CellAsset Merge( ArrayList cells ) { CellAsset[] theCells; theCells = new CellAsset[ cells.Count ]; for( int i = 0; i < cells.Count; i++ ) { theCells[ i ] = ( CellAsset )cells[ i ]; } return Merge( theCells ); }
public CellAsset( CellAsset original, NetworkAsset network ) : base( network, original.Collection ) { this.Name = original.Name; this.Position = original.Position; this.triangles = new TriangleAsset[ original.Triangles.Length ]; for( int i = 0; i < original.Triangles.Length; i++ ) { this.triangles[ i ] = new TriangleAsset( original.Triangles[ i ], this ); } this.Tags = new int[ original.Tags.Length ]; for( int i = 0; i < original.Tags.Length; i++ ) { this.Tags[ i ] = original.Tags[ i ]; } }
public bool Add( CellAsset cell ) { CellAsset[] newCells; newCells = new CellAsset[ cells.Length + 1 ]; for( int i = 0; i < cells.Length; i++ ) { if( cells[ i ].Name == cell.Name ) { return false; } newCells[ i ] = cells[ i ]; } newCells[ cells.Length ] = cell; cells = newCells; return true; }
public bool GenerateConnections( CellAsset cell ) { int matches; Vector3 matchOne, matchTwo; foreach( CellAsset other in cells ) { if( other == cell ) { continue; } matches = 0; foreach( TriangleAsset cellTriangle in cell.Triangles ) { foreach( TriangleAsset otherTriangle in other.Triangles ) { foreach( Vector3 cellPoint in cellTriangle.Points ) { foreach( Vector3 otherPoint in otherTriangle.Points ) { if( cellPoint == otherPoint ) { matches++; if( matches == 0 ) { matchOne = cellPoint; } else { matchTwo = cellPoint; } } } } } } if( matches == 2 ) { cell.AddConnection( new ConnectionAsset( cell, other, Mathf.Abs( ( matchOne - matchTwo ).magnitude ), Collection ) ); other.AddConnection( new ConnectionAsset( other, cell, Mathf.Abs( ( matchOne - matchTwo ).magnitude ), Collection ) ); } else if( matches > 2 ) { Debug.LogError( "More than two match points between two cells. What an odd mesh..." ); return false; } } return true; }