2009-11-20 14:49:24 +00:00
|
|
|
//
|
|
|
|
// JAIcosMesh.m
|
|
|
|
// icosmesh
|
|
|
|
//
|
|
|
|
// Created by Jens Ayton on 2009-11-18.
|
|
|
|
// Copyright 2009 Jens Ayton. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#import "JAIcosMesh.h"
|
|
|
|
#import "JAVertexSet.h"
|
|
|
|
#import "JAIcosTriangle.h"
|
|
|
|
|
|
|
|
@implementation JAIcosMesh
|
|
|
|
|
2014-07-23 18:01:21 +01:00
|
|
|
- (JAVertexSet*) vertexSet
|
|
|
|
{
|
|
|
|
return _vertexSet;
|
|
|
|
}
|
2009-11-21 16:50:16 +00:00
|
|
|
|
2014-07-23 18:01:21 +01:00
|
|
|
- (NSUInteger) maxIndex
|
|
|
|
{
|
|
|
|
return _maxIndex;
|
|
|
|
}
|
2009-11-21 16:50:16 +00:00
|
|
|
|
2009-11-20 14:49:24 +00:00
|
|
|
- (id) init
|
|
|
|
{
|
|
|
|
return [self initWithVertexSet:nil];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
+ (id) meshWithVertexSet:(JAVertexSet *)vertexSet
|
|
|
|
{
|
2009-11-21 16:50:16 +00:00
|
|
|
return [[self alloc] initWithVertexSet:vertexSet];
|
2009-11-20 14:49:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
- (id) initWithVertexSet:(JAVertexSet *)vertexSet
|
|
|
|
{
|
|
|
|
if ((self = [super init]))
|
|
|
|
{
|
2009-11-21 16:50:16 +00:00
|
|
|
if (vertexSet == nil) vertexSet = [[JAVertexSet alloc] init];
|
2014-07-23 18:01:21 +01:00
|
|
|
_vertexSet = vertexSet;
|
2009-11-20 14:49:24 +00:00
|
|
|
|
2009-11-21 16:50:16 +00:00
|
|
|
_indices = [NSMutableArray array];
|
|
|
|
if (vertexSet == nil || _indices == nil) return nil;
|
2009-11-20 14:49:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
- (NSUInteger) faceCount
|
|
|
|
{
|
2014-07-23 18:01:21 +01:00
|
|
|
return [_indices count] / 3;
|
2009-11-20 14:49:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
- (void) addTriangle:(JAIcosTriangle *)triangle
|
|
|
|
{
|
|
|
|
if (triangle == nil) return;
|
|
|
|
|
2014-07-23 18:01:21 +01:00
|
|
|
[self addOneVertex:[triangle vertexA]];
|
|
|
|
[self addOneVertex:[triangle vertexB]];
|
|
|
|
[self addOneVertex:[triangle vertexC]];
|
2009-11-20 14:49:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
- (void) addTriangles:(NSArray *)triangles
|
|
|
|
{
|
2014-07-23 18:01:21 +01:00
|
|
|
JAIcosTriangle *triangle;
|
|
|
|
unsigned i;
|
|
|
|
for (i = 0; i < [triangles count]; i++)
|
2009-11-20 14:49:24 +00:00
|
|
|
{
|
2014-07-23 18:01:21 +01:00
|
|
|
triangle = (JAIcosTriangle*)[triangles objectAtIndex: i];
|
2009-11-20 14:49:24 +00:00
|
|
|
[self addTriangle:triangle];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
- (NSArray *) indexArray
|
|
|
|
{
|
2009-11-21 16:50:16 +00:00
|
|
|
return [_indices copy];
|
2009-11-20 14:49:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
- (void) addOneVertex:(Vertex)v
|
|
|
|
{
|
2014-07-23 18:01:21 +01:00
|
|
|
NSUInteger index = [[self vertexSet] indexForVertex:v];
|
2009-11-20 14:49:24 +00:00
|
|
|
[_indices addObject:[NSNumber numberWithUnsignedInteger:index]];
|
2014-07-23 18:01:21 +01:00
|
|
|
if (_maxIndex < index) _maxIndex = index;
|
2009-11-20 14:49:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@end
|