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()); }
//private Edge[] border; public CellAsset( string name, Vector3 position, TriangleAsset[] triangles, NetworkAsset network, CollectionAsset collection ) : base( network, collection ) { this.Name = name; this.Position = position; foreach( TriangleAsset triangle in triangles ) { triangle.Cell = this; } this.triangles = triangles; // TODO: Calculate border and position from triangles /*ArrayList edges, uses; Edge edge, existingEdge; edges = new ArrayList(); uses = new ArrayList(); foreach( TriangleAsset triangle in triangles ) { for( int i = 0; i < 3; i++ ) { edge = ( i == 0 ) ? new Edge( triangle.Points[ 0 ], triangles.Points[ 1 ] ) : ( i == 1 ) ? new Edge( triangle.Points[ 1 ], triangles.Points[ 2 ] ) : new Edge( triangle.Points[ 2 ], triangles.Points[ 0 ] ); for( int j = 0; j < edges.Count; j++ ) { existingEdge = edges[ j ]; if( edge.Equals( existingEdge ) ) { uses[ edges.IndexOf( existingEdge ) ]++; } } } }*/ }
public TriangleAsset( TriangleAsset original, CellAsset cell ) { this.Points = original.Points; this.cell = cell; }
public TriangleAsset(TriangleAsset original, CellAsset cell) { this.Points = original.Points; this.cell = cell; }
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(); }