mirror of
https://github.com/thes3m/XNI
synced 2024-12-26 13:26:06 +01:00
Added 3D Model support.
git-svn-id: http://xni.googlecode.com/svn/XNI@42 ac433895-eea3-a490-d80a-17149a75e588
This commit is contained in:
parent
14d015cfbb
commit
d5b2897d8b
17
Classes/Retronator/Xni/Framework/Content/BasicEffectReader.h
Normal file
17
Classes/Retronator/Xni/Framework/Content/BasicEffectReader.h
Normal file
@ -0,0 +1,17 @@
|
||||
//
|
||||
// BasicEffectReader.h
|
||||
// XNI
|
||||
//
|
||||
// Created by Matej Jan on 23.11.10.
|
||||
// Copyright 2010 Retronator. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
#import "ContentTypeReader.h"
|
||||
|
||||
@interface BasicEffectReader : ContentTypeReader {
|
||||
|
||||
}
|
||||
|
||||
@end
|
33
Classes/Retronator/Xni/Framework/Content/BasicEffectReader.m
Normal file
33
Classes/Retronator/Xni/Framework/Content/BasicEffectReader.m
Normal file
@ -0,0 +1,33 @@
|
||||
//
|
||||
// BasicEffectReader.m
|
||||
// XNI
|
||||
//
|
||||
// Created by Matej Jan on 23.11.10.
|
||||
// Copyright 2010 Retronator. All rights reserved.
|
||||
//
|
||||
|
||||
#import "BasicEffectReader.h"
|
||||
|
||||
#import "Retronator.Xni.Framework.Content.h"
|
||||
#import "Retronator.Xni.Framework.Graphics.h"
|
||||
#import "Retronator.Xni.Framework.Content.Pipeline.Graphics.h"
|
||||
|
||||
@implementation BasicEffectReader
|
||||
|
||||
- (id) readFromInput:(ContentReader *)input into:(id)existingInstance {
|
||||
BasicMaterialContent *content = input.content;
|
||||
GraphicsDevice *graphicsDevice = [[input.contentManager.serviceProvider getServiceOfType:@protocol(IGraphicsDeviceService)] graphicsDevice];
|
||||
|
||||
BasicEffect *effect = [[[BasicEffect alloc] initWithGraphicsDevice:graphicsDevice] autorelease];
|
||||
effect.alpha = [content.alpha floatValue];
|
||||
effect.diffuseColor = content.diffuseColor;
|
||||
effect.specularPower = [content.specularPower floatValue];
|
||||
effect.specularColor = content.specularColor;
|
||||
effect.emissiveColor = content.emissiveColor;
|
||||
effect.texture = [input readSharedResourceFrom:content.texture];
|
||||
effect.textureEnabled = effect.texture != nil;
|
||||
|
||||
return effect;
|
||||
}
|
||||
|
||||
@end
|
@ -0,0 +1,17 @@
|
||||
//
|
||||
// ContentManager+Internal.h
|
||||
// XNI
|
||||
//
|
||||
// Created by Matej Jan on 23.11.10.
|
||||
// Copyright 2010 Retronator. All rights reserved.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
#import "ContentManager.h"
|
||||
|
||||
@interface ContentManager (Internal)
|
||||
|
||||
@property (nonatomic, readonly) ContentTypeReaderManager *readerManager;
|
||||
|
||||
@end
|
@ -7,9 +7,11 @@
|
||||
//
|
||||
|
||||
#import "ContentManager.h"
|
||||
#import "ContentManager+Internal.h"
|
||||
|
||||
#import "Retronator.Xni.Framework.Content.Pipeline.h"
|
||||
#import "Retronator.Xni.Framework.Content.h"
|
||||
#import "Retronator.Xni.Framework.Content.Pipeline.h"
|
||||
#import "Retronator.Xni.Framework.Content.Pipeline.Processors.h"
|
||||
|
||||
@implementation ContentManager
|
||||
|
||||
@ -28,10 +30,13 @@
|
||||
return self;
|
||||
}
|
||||
|
||||
|
||||
@synthesize rootDirectory;
|
||||
@synthesize serviceProvider;
|
||||
|
||||
- (ContentTypeReaderManager *) readerManager {
|
||||
return readerManager;
|
||||
}
|
||||
|
||||
- (id) load:(NSString *)assetName{
|
||||
|
||||
// Check if we have already loaded this asset.
|
||||
@ -66,11 +71,18 @@
|
||||
|
||||
// Find extension and absolute path.
|
||||
NSString *fileName = [filePath stringByDeletingPathExtension];
|
||||
NSString *extension = [[filePath pathExtension] lowercaseString];
|
||||
NSString *extension = [filePath pathExtension];
|
||||
NSString *absolutePath = [[NSBundle mainBundle] pathForResource:fileName ofType:extension inDirectory:rootDirectory];
|
||||
|
||||
if (!absolutePath) {
|
||||
[NSException raise:@"InvalidArgumentException" format:@"Could not locate file '%@' in directory '%@'", filePath, rootDirectory];
|
||||
}
|
||||
|
||||
ContentReader *input;
|
||||
|
||||
// Compare lowercase extension.
|
||||
extension = [extension lowercaseString];
|
||||
|
||||
if ([extension isEqual:@"png"] || [extension isEqual:@"jpg"] || [extension isEqual:@"jpeg"] ||
|
||||
[extension isEqual:@"gif"] || [extension isEqual:@"tif"] || [extension isEqual:@"tiff"] ||
|
||||
[extension isEqual:@"ico"] || [extension isEqual:@"bmp"]) {
|
||||
@ -78,6 +90,14 @@
|
||||
TextureImporter *textureImporter = [[[TextureImporter alloc] init] autorelease];
|
||||
TextureContent *textureContent = [textureImporter importFile:absolutePath];
|
||||
input = [[ContentReader alloc] initWithContentManager:self Content:textureContent];
|
||||
|
||||
} else if ([extension isEqual:@"x"]) {
|
||||
// We have direct x model content
|
||||
XImporter *xImporter = [[[XImporter alloc] init] autorelease];
|
||||
NodeContent *root = [xImporter importFile:absolutePath];
|
||||
ModelProcessor *modelProcessor = [[[ModelProcessor alloc] init] autorelease];
|
||||
ModelContent *modelContent = [modelProcessor process:root];
|
||||
input = [[ContentReader alloc] initWithContentManager:self Content:modelContent];
|
||||
} else {
|
||||
[NSException raise:@"InvalidArgumentException" format:@"Files with extension %@ are not supported", extension];
|
||||
}
|
||||
@ -86,11 +106,14 @@
|
||||
id result = [reader readFromInput:input into:nil];
|
||||
|
||||
// Save the loaded asset for quick retreival.
|
||||
[loadedAssets setObject:result forKey:assetName];
|
||||
if (assetName) {
|
||||
[loadedAssets setObject:result forKey:assetName];
|
||||
}
|
||||
|
||||
[input release];
|
||||
|
||||
return result;
|
||||
// We are returning a retained object since the loaded asset is always used for a longer time.
|
||||
return [result retain];
|
||||
}
|
||||
|
||||
- (void) unload {
|
||||
|
@ -12,7 +12,9 @@
|
||||
|
||||
@interface ContentReader : NSObject {
|
||||
ContentManager *contentManager;
|
||||
id content;
|
||||
NSMutableArray *contentStack;
|
||||
|
||||
CFMutableDictionaryRef sharedResources;
|
||||
}
|
||||
|
||||
- (id) initWithContentManager:(ContentManager*)theContentManager Content:(id)theContent;
|
||||
@ -20,4 +22,7 @@
|
||||
@property (nonatomic, readonly) ContentManager *contentManager;
|
||||
@property (nonatomic, readonly) id content;
|
||||
|
||||
- (id) readObjectFrom:(id)source;
|
||||
- (id) readSharedResourceFrom:(id)source;
|
||||
|
||||
@end
|
||||
|
@ -8,18 +8,77 @@
|
||||
|
||||
#import "ContentReader.h"
|
||||
|
||||
#import "Retronator.Xni.Framework.Content.h"
|
||||
#import "Retronator.Xni.Framework.Content.Pipeline.h"
|
||||
#import "ContentManager+Internal.h"
|
||||
|
||||
@implementation ContentReader
|
||||
|
||||
- (id) initWithContentManager:(ContentManager *)theContentManager Content:(id)theContent {
|
||||
if (self = [super init]) {
|
||||
contentManager = theContentManager;
|
||||
content = theContent;
|
||||
|
||||
contentStack = [[NSMutableArray alloc] init];
|
||||
[contentStack addObject:theContent];
|
||||
|
||||
sharedResources = CFDictionaryCreateMutable(NULL, 0, NULL, &kCFTypeDictionaryValueCallBacks);
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
@synthesize contentManager;
|
||||
@synthesize content;
|
||||
|
||||
- (id) content {
|
||||
return [contentStack lastObject];
|
||||
}
|
||||
|
||||
- (id) readObjectFrom:(id)source {
|
||||
// Push the source onto the content stack.
|
||||
[contentStack addObject:source];
|
||||
|
||||
id result = nil;
|
||||
|
||||
if ([source isKindOfClass:[ExternalReference class]]) {
|
||||
ExternalReference *externalReference = (ExternalReference*)source;
|
||||
|
||||
// We should load the item with content manager.
|
||||
result = [contentManager load:externalReference.name fromFile:externalReference.filename];
|
||||
} else {
|
||||
// Get the correct reader for item.
|
||||
ContentTypeReader *typeReader = [contentManager.readerManager getTypeReaderFor:[source class]];
|
||||
|
||||
// Read the object.
|
||||
result = [typeReader readFromInput:self into:nil];
|
||||
}
|
||||
|
||||
// Return to previous content on the stack.
|
||||
[contentStack removeLastObject];
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
- (id) readSharedResourceFrom:(id)source {
|
||||
if (!source) {
|
||||
return nil;
|
||||
}
|
||||
|
||||
// See if the resource has already been loaded.
|
||||
id resource;
|
||||
void *resourcePointer = nil;
|
||||
CFDictionaryGetValueIfPresent(sharedResources, source, resourcePointer);
|
||||
resource = (id)resourcePointer;
|
||||
if (!resource) {
|
||||
resource = [self readObjectFrom:source];
|
||||
CFDictionarySetValue(sharedResources, source, resource);
|
||||
}
|
||||
return resource;
|
||||
}
|
||||
|
||||
- (void) dealloc
|
||||
{
|
||||
[contentStack release];
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
|
||||
@end
|
||||
|
@ -11,7 +11,15 @@
|
||||
#import "Retronator.Xni.Framework.Content.classes.h"
|
||||
|
||||
@interface ContentTypeReaderManager : NSObject {
|
||||
Texture2DContentTypeReader *texture2DContentTypeReader;
|
||||
Texture2DReader *texture2DReader;
|
||||
ModelReader *modelReader;
|
||||
ModelMeshReader *modelMeshReader;
|
||||
ModelMeshPartReader *modelMeshPartReader;
|
||||
BasicEffectReader *basicEffectReader;
|
||||
IndexBufferReader *indexBufferReader;
|
||||
VertexBufferReader *vertexBufferReader;
|
||||
ModelBoneReader *modelBoneReader;
|
||||
VertexDeclarationReader *vertexDeclarationReader;
|
||||
}
|
||||
|
||||
- (ContentTypeReader*) getTypeReaderFor:(Class)targetType;
|
||||
|
@ -10,6 +10,7 @@
|
||||
|
||||
#import "Retronator.Xni.Framework.Content.h"
|
||||
#import "Retronator.Xni.Framework.Content.Pipeline.Graphics.h"
|
||||
#import "Retronator.Xni.Framework.Content.Pipeline.Processors.h"
|
||||
|
||||
@implementation ContentTypeReaderManager
|
||||
|
||||
@ -17,7 +18,15 @@
|
||||
{
|
||||
self = [super init];
|
||||
if (self != nil) {
|
||||
texture2DContentTypeReader = [[Texture2DContentTypeReader alloc] init];
|
||||
texture2DReader = [[Texture2DReader alloc] init];
|
||||
modelReader = [[ModelReader alloc] init];
|
||||
modelMeshReader = [[ModelMeshReader alloc] init];
|
||||
modelMeshPartReader = [[ModelMeshPartReader alloc] init];
|
||||
basicEffectReader = [[BasicEffectReader alloc] init];
|
||||
indexBufferReader = [[IndexBufferReader alloc] init];
|
||||
vertexBufferReader = [[VertexBufferReader alloc] init];
|
||||
modelBoneReader = [[ModelBoneReader alloc] init];
|
||||
vertexDeclarationReader = [[VertexDeclarationReader alloc] init];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
@ -25,7 +34,23 @@
|
||||
|
||||
- (ContentTypeReader *) getTypeReaderFor:(Class)targetType {
|
||||
if (targetType == [Texture2DContent class]) {
|
||||
return texture2DContentTypeReader;
|
||||
return texture2DReader;
|
||||
} else if (targetType == [ModelContent class]) {
|
||||
return modelReader;
|
||||
} else if (targetType == [ModelMeshContent class]) {
|
||||
return modelMeshReader;
|
||||
} else if (targetType == [ModelMeshPartContent class]) {
|
||||
return modelMeshPartReader;
|
||||
} else if (targetType == [BasicMaterialContent class]) {
|
||||
return basicEffectReader;
|
||||
} else if (targetType == [IndexCollection class]) {
|
||||
return indexBufferReader;
|
||||
} else if (targetType == [VertexBufferContent class]) {
|
||||
return vertexBufferReader;
|
||||
} else if (targetType == [ModelBoneContent class]) {
|
||||
return modelBoneReader;
|
||||
} else if (targetType == [VertexDeclarationContent class]) {
|
||||
return vertexDeclarationReader;
|
||||
} else {
|
||||
return nil;
|
||||
}
|
||||
@ -33,7 +58,8 @@
|
||||
|
||||
- (void) dealloc
|
||||
{
|
||||
[texture2DContentTypeReader dealloc];
|
||||
[texture2DReader release];
|
||||
[modelReader release];
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
|
17
Classes/Retronator/Xni/Framework/Content/IndexBufferReader.h
Normal file
17
Classes/Retronator/Xni/Framework/Content/IndexBufferReader.h
Normal file
@ -0,0 +1,17 @@
|
||||
//
|
||||
// IndexBufferReader.h
|
||||
// XNI
|
||||
//
|
||||
// Created by Matej Jan on 23.11.10.
|
||||
// Copyright 2010 Retronator. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
#import "ContentTypeReader.h"
|
||||
|
||||
@interface IndexBufferReader : ContentTypeReader {
|
||||
|
||||
}
|
||||
|
||||
@end
|
40
Classes/Retronator/Xni/Framework/Content/IndexBufferReader.m
Normal file
40
Classes/Retronator/Xni/Framework/Content/IndexBufferReader.m
Normal file
@ -0,0 +1,40 @@
|
||||
//
|
||||
// IndexBufferReader.m
|
||||
// XNI
|
||||
//
|
||||
// Created by Matej Jan on 23.11.10.
|
||||
// Copyright 2010 Retronator. All rights reserved.
|
||||
//
|
||||
|
||||
#import "IndexBufferReader.h"
|
||||
|
||||
#import "Retronator.Xni.Framework.Content.h"
|
||||
#import "Retronator.Xni.Framework.Graphics.h"
|
||||
#import "Retronator.Xni.Framework.Content.Pipeline.Graphics.h"
|
||||
|
||||
@implementation IndexBufferReader
|
||||
|
||||
- (id) readFromInput:(ContentReader *)input into:(id)existingInstance {
|
||||
IndexCollection *content = input.content;
|
||||
GraphicsDevice *graphicsDevice = [[input.contentManager.serviceProvider getServiceOfType:@protocol(IGraphicsDeviceService)] graphicsDevice];
|
||||
|
||||
// Create an index array.
|
||||
ShortIndexArray *indexArray = [[[ShortIndexArray alloc] initWithInitialCapacity:content.count] autorelease];
|
||||
for (NSNumber *index in content) {
|
||||
short shortIndex = (short)[index intValue];
|
||||
[indexArray addIndex:shortIndex];
|
||||
}
|
||||
|
||||
// Create the buffer.
|
||||
IndexBuffer *buffer = [[[IndexBuffer alloc] initWithGraphicsDevice:graphicsDevice
|
||||
indexElementSize:IndexElementSizeSixteenBits
|
||||
indexCount:content.count
|
||||
usage:BufferUsageWriteOnly] autorelease];
|
||||
|
||||
// Load data from array to buffer.
|
||||
[buffer setData:indexArray];
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
@end
|
17
Classes/Retronator/Xni/Framework/Content/ModelBoneReader.h
Normal file
17
Classes/Retronator/Xni/Framework/Content/ModelBoneReader.h
Normal file
@ -0,0 +1,17 @@
|
||||
//
|
||||
// ModelBoneReader.h
|
||||
// XNI
|
||||
//
|
||||
// Created by Matej Jan on 29.11.10.
|
||||
// Copyright 2010 Retronator. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
#import "ContentTypeReader.h"
|
||||
|
||||
@interface ModelBoneReader : ContentTypeReader {
|
||||
|
||||
}
|
||||
|
||||
@end
|
45
Classes/Retronator/Xni/Framework/Content/ModelBoneReader.m
Normal file
45
Classes/Retronator/Xni/Framework/Content/ModelBoneReader.m
Normal file
@ -0,0 +1,45 @@
|
||||
//
|
||||
// ModelBoneReader.m
|
||||
// XNI
|
||||
//
|
||||
// Created by Matej Jan on 29.11.10.
|
||||
// Copyright 2010 Retronator. All rights reserved.
|
||||
//
|
||||
|
||||
#import "ModelBoneReader.h"
|
||||
|
||||
#import "Retronator.Xni.Framework.Content.h"
|
||||
#import "Retronator.Xni.Framework.Graphics.h"
|
||||
#import "Retronator.Xni.Framework.Content.Pipeline.Processors.h"
|
||||
|
||||
#import "ModelBone+Internal.h"
|
||||
|
||||
@implementation ModelBoneReader
|
||||
|
||||
- (id) readFromInput:(ContentReader *)input into:(id)existingInstance {
|
||||
ModelBoneContent *content = input.content;
|
||||
|
||||
NSMutableArray *children = [NSMutableArray array];
|
||||
|
||||
// Create all children bones.
|
||||
for (ModelBoneContent *child in content.children) {
|
||||
ModelBone *childBone = [input readSharedResourceFrom:child];
|
||||
[children addObject:childBone];
|
||||
}
|
||||
|
||||
// Create this bone.
|
||||
ModelBone *modelBone = [[[ModelBone alloc] initWithChildren:children
|
||||
index:content.index
|
||||
name:content.name
|
||||
transform:content.transform] autorelease];
|
||||
|
||||
// Update children with new parent.
|
||||
for (ModelBone *child in children) {
|
||||
[child setParent:modelBone];
|
||||
}
|
||||
|
||||
// Return created bone.
|
||||
return modelBone;
|
||||
}
|
||||
|
||||
@end
|
@ -0,0 +1,17 @@
|
||||
//
|
||||
// ModelMeshPartReader.h
|
||||
// XNI
|
||||
//
|
||||
// Created by Matej Jan on 23.11.10.
|
||||
// Copyright 2010 Retronator. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
#import "ContentTypeReader.h"
|
||||
|
||||
@interface ModelMeshPartReader : ContentTypeReader {
|
||||
|
||||
}
|
||||
|
||||
@end
|
@ -0,0 +1,35 @@
|
||||
//
|
||||
// ModelMeshPartReader.m
|
||||
// XNI
|
||||
//
|
||||
// Created by Matej Jan on 23.11.10.
|
||||
// Copyright 2010 Retronator. All rights reserved.
|
||||
//
|
||||
|
||||
#import "ModelMeshPartReader.h"
|
||||
|
||||
#import "Retronator.Xni.Framework.Content.h"
|
||||
#import "Retronator.Xni.Framework.Graphics.h"
|
||||
#import "Retronator.Xni.Framework.Content.Pipeline.Processors.h"
|
||||
#import "ModelMeshPart+Internal.h"
|
||||
|
||||
@implementation ModelMeshPartReader
|
||||
|
||||
- (id) readFromInput:(ContentReader *)input into:(id)existingInstance {
|
||||
ModelMeshPartContent *content = input.content;
|
||||
|
||||
// Create the model mesh part.
|
||||
|
||||
BasicEffect *effect = [input readSharedResourceFrom:content.material];
|
||||
VertexBuffer *vertexBuffer = [input readSharedResourceFrom:content.vertexBuffer];
|
||||
IndexBuffer *indexBuffer = [input readSharedResourceFrom:content.indexBuffer];
|
||||
|
||||
ModelMeshPart *meshPart =
|
||||
[[ModelMeshPart alloc] initWithVertexOffset:content.vertexOffset numVertices:content.numVertices startIndex:content.startIndex
|
||||
primitiveCount:content.primitiveCount tag:content.tag indexBuffer:indexBuffer
|
||||
vertexBuffer:vertexBuffer effect:effect];
|
||||
|
||||
return [meshPart autorelease];
|
||||
}
|
||||
|
||||
@end
|
17
Classes/Retronator/Xni/Framework/Content/ModelMeshReader.h
Normal file
17
Classes/Retronator/Xni/Framework/Content/ModelMeshReader.h
Normal file
@ -0,0 +1,17 @@
|
||||
//
|
||||
// ModelMeshReader.h
|
||||
// XNI
|
||||
//
|
||||
// Created by Matej Jan on 23.11.10.
|
||||
// Copyright 2010 Retronator. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
#import "ContentTypeReader.h"
|
||||
|
||||
@interface ModelMeshReader : ContentTypeReader {
|
||||
|
||||
}
|
||||
|
||||
@end
|
33
Classes/Retronator/Xni/Framework/Content/ModelMeshReader.m
Normal file
33
Classes/Retronator/Xni/Framework/Content/ModelMeshReader.m
Normal file
@ -0,0 +1,33 @@
|
||||
//
|
||||
// ModelMeshReader.m
|
||||
// XNI
|
||||
//
|
||||
// Created by Matej Jan on 23.11.10.
|
||||
// Copyright 2010 Retronator. All rights reserved.
|
||||
//
|
||||
|
||||
#import "ModelMeshReader.h"
|
||||
|
||||
#import "Retronator.Xni.Framework.Content.h"
|
||||
#import "Retronator.Xni.Framework.Graphics.h"
|
||||
#import "Retronator.Xni.Framework.Content.Pipeline.Processors.h"
|
||||
#import "ModelMesh+Internal.h"
|
||||
|
||||
@implementation ModelMeshReader
|
||||
|
||||
- (id) readFromInput:(ContentReader *)input into:(id)existingInstance {
|
||||
ModelMeshContent *content = input.content;
|
||||
|
||||
// Create all model mesh parts.
|
||||
NSMutableArray *meshParts = [NSMutableArray array];
|
||||
for (ModelMeshPartContent *meshPartContent in content.meshParts) {
|
||||
[meshParts addObject:[input readObjectFrom:meshPartContent]];
|
||||
}
|
||||
|
||||
ModelBone *parentBone = [input readSharedResourceFrom:content.parentBone];
|
||||
|
||||
ModelMesh *mesh = [[[ModelMesh alloc] initWithName:content.name parentBone:parentBone modelMeshParts:meshParts tag:content.tag] autorelease];
|
||||
return mesh;
|
||||
}
|
||||
|
||||
@end
|
17
Classes/Retronator/Xni/Framework/Content/ModelReader.h
Normal file
17
Classes/Retronator/Xni/Framework/Content/ModelReader.h
Normal file
@ -0,0 +1,17 @@
|
||||
//
|
||||
// ModelReader.h
|
||||
// XNI
|
||||
//
|
||||
// Created by Matej Jan on 22.11.10.
|
||||
// Copyright 2010 Retronator. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
#import "ContentTypeReader.h"
|
||||
|
||||
@interface ModelReader : ContentTypeReader {
|
||||
|
||||
}
|
||||
|
||||
@end
|
39
Classes/Retronator/Xni/Framework/Content/ModelReader.m
Normal file
39
Classes/Retronator/Xni/Framework/Content/ModelReader.m
Normal file
@ -0,0 +1,39 @@
|
||||
//
|
||||
// ModelReader.m
|
||||
// XNI
|
||||
//
|
||||
// Created by Matej Jan on 22.11.10.
|
||||
// Copyright 2010 Retronator. All rights reserved.
|
||||
//
|
||||
|
||||
#import "ModelReader.h"
|
||||
|
||||
#import "Retronator.Xni.Framework.Content.h"
|
||||
#import "Retronator.Xni.Framework.Graphics.h"
|
||||
#import "Retronator.Xni.Framework.Content.Pipeline.Processors.h"
|
||||
#import "Model+Internal.h"
|
||||
|
||||
@implementation ModelReader
|
||||
|
||||
- (id) readFromInput:(ContentReader *)input into:(id)existingInstance {
|
||||
ModelContent *content = input.content;
|
||||
|
||||
// Create all model bones.
|
||||
NSMutableArray *bones = [NSMutableArray array];
|
||||
for (ModelBoneContent *boneContent in content.bones) {
|
||||
[bones addObject:[input readSharedResourceFrom:boneContent]];
|
||||
}
|
||||
|
||||
// Create all model meshes.
|
||||
NSMutableArray *meshes = [NSMutableArray array];
|
||||
for (ModelMeshContent *meshContent in content.meshes) {
|
||||
[meshes addObject:[input readObjectFrom:meshContent]];
|
||||
}
|
||||
|
||||
ModelBone *root = [input readSharedResourceFrom:content.root];
|
||||
|
||||
Model *model = [[Model alloc] initWithBones:bones meshes:meshes root:root tag:nil];
|
||||
return [model autorelease];
|
||||
}
|
||||
|
||||
@end
|
@ -0,0 +1,33 @@
|
||||
//
|
||||
// ChildCollection.h
|
||||
// XNI
|
||||
//
|
||||
// Created by Matej Jan on 26.11.10.
|
||||
// Copyright 2010 Retronator. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
|
||||
@interface ChildCollection : NSObject <NSFastEnumeration> {
|
||||
NSMutableArray *children;
|
||||
id parent;
|
||||
}
|
||||
|
||||
- (id) initWithParent:(id)theParent;
|
||||
|
||||
@property (nonatomic, readonly) int count;
|
||||
|
||||
- (id)itemAt:(int)index;
|
||||
- (void)setItem:(id)item at:(int)index;
|
||||
|
||||
- (void)add:(id)item;
|
||||
- (void)insert:(id)item at:(int)index;
|
||||
|
||||
- (void)remove:(id)item;
|
||||
- (void)removeAt:(int)index;
|
||||
|
||||
- (id)getParentOf:(id)child;
|
||||
- (void)setParentOf:(id)child to:(id)theParent;
|
||||
|
||||
@end
|
@ -0,0 +1,75 @@
|
||||
//
|
||||
// ChildCollection.m
|
||||
// XNI
|
||||
//
|
||||
// Created by Matej Jan on 26.11.10.
|
||||
// Copyright 2010 Retronator. All rights reserved.
|
||||
//
|
||||
|
||||
#import "ChildCollection.h"
|
||||
|
||||
|
||||
@implementation ChildCollection
|
||||
|
||||
- (id) initWithParent:(id)theParent
|
||||
{
|
||||
self = [super init];
|
||||
if (self != nil) {
|
||||
children = [[NSMutableArray alloc] init];
|
||||
parent = theParent;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (int) count {
|
||||
return [children count];
|
||||
}
|
||||
|
||||
- (id)itemAt:(int)index {
|
||||
return [children objectAtIndex:index];
|
||||
}
|
||||
|
||||
- (void)setItem:(id)item at:(int)index{
|
||||
[self setParentOf:[self itemAt:index] to:nil];
|
||||
[self setParentOf:item to:parent];
|
||||
[children replaceObjectAtIndex:index withObject:item];
|
||||
}
|
||||
|
||||
- (void)add:(id)item{
|
||||
[self setParentOf:item to:parent];
|
||||
[children addObject:item];
|
||||
}
|
||||
|
||||
- (void)insert:(id)item at:(int)index{
|
||||
[self setParentOf:item to:parent];
|
||||
[children insertObject:item atIndex:index];
|
||||
}
|
||||
|
||||
- (void)remove:(id)item{
|
||||
[self setParentOf:item to:nil];
|
||||
[children removeObject:item];
|
||||
}
|
||||
|
||||
- (void)removeAt:(int)index{
|
||||
[self setParentOf:[self itemAt:index] to:nil];
|
||||
[children removeObjectAtIndex:index];
|
||||
}
|
||||
|
||||
- (NSUInteger) countByEnumeratingWithState:(NSFastEnumerationState *)state objects:(id *)stackbuf count:(NSUInteger)len {
|
||||
return [children countByEnumeratingWithState:state objects:stackbuf count:len];
|
||||
}
|
||||
|
||||
|
||||
// Override this methods in the child implementation.
|
||||
- (id)getParentOf:(id)child {return nil;}
|
||||
|
||||
- (void)setParentOf:(id)child to:(id)theParent {}
|
||||
|
||||
- (void) dealloc
|
||||
{
|
||||
[children release];
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
|
||||
@end
|
@ -8,11 +8,10 @@
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
#import "IContentImporter.h"
|
||||
|
||||
@interface ContentImporter : NSObject {
|
||||
@interface ContentImporter : NSObject <IContentImporter> {
|
||||
|
||||
}
|
||||
|
||||
- (id) importFile:(NSString*)filename;
|
||||
|
||||
@end
|
||||
|
@ -13,10 +13,11 @@
|
||||
@interface ContentItem : NSObject {
|
||||
ContentIdentity *identity;
|
||||
NSString *name;
|
||||
OpaqueDataDictionary *opaqueData;
|
||||
}
|
||||
|
||||
@property (nonatomic, retain) ContentIdentity *identity;
|
||||
@property (nonatomic, retain) NSString *name;
|
||||
@property (nonatomic, readonly) OpaqueDataDictionary *opaqueData;
|
||||
|
||||
|
||||
@end
|
||||
@end
|
@ -8,10 +8,28 @@
|
||||
|
||||
#import "ContentItem.h"
|
||||
|
||||
#import "Retronator.Xni.Framework.Content.Pipeline.h"
|
||||
|
||||
@implementation ContentItem
|
||||
|
||||
@synthesize identity;
|
||||
@synthesize name;
|
||||
- (id) init
|
||||
{
|
||||
self = [super init];
|
||||
if (self != nil) {
|
||||
identity = [[ContentIdentity alloc] init];
|
||||
opaqueData = [[OpaqueDataDictionary alloc] init];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
@synthesize identity, name, opaqueData;
|
||||
|
||||
- (void) dealloc
|
||||
{
|
||||
[ContentIdentity release];
|
||||
[opaqueData release];
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
|
||||
@end
|
||||
|
@ -0,0 +1,17 @@
|
||||
//
|
||||
// ContentProcessor.h
|
||||
// XNI
|
||||
//
|
||||
// Created by Matej Jan on 22.11.10.
|
||||
// Copyright 2010 Retronator. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
#import "IContentProcessor.h"
|
||||
|
||||
@interface ContentProcessor : NSObject <IContentProcessor> {
|
||||
|
||||
}
|
||||
|
||||
@end
|
@ -0,0 +1,21 @@
|
||||
//
|
||||
// ContentProcessor.m
|
||||
// XNI
|
||||
//
|
||||
// Created by Matej Jan on 22.11.10.
|
||||
// Copyright 2010 Retronator. All rights reserved.
|
||||
//
|
||||
|
||||
#import "ContentProcessor.h"
|
||||
|
||||
|
||||
@implementation ContentProcessor
|
||||
|
||||
- (Class) inputType { return nil;}
|
||||
- (Class) outputType { return nil;}
|
||||
|
||||
- (id) process:(id)input {
|
||||
return input;
|
||||
}
|
||||
|
||||
@end
|
@ -0,0 +1,24 @@
|
||||
//
|
||||
// ExternalReference.h
|
||||
// XNI
|
||||
//
|
||||
// Created by Matej Jan on 29.11.10.
|
||||
// Copyright 2010 Retronator. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
#import "Retronator.Xni.Framework.Content.Pipeline.classes.h"
|
||||
|
||||
#import "ContentItem.h"
|
||||
|
||||
@interface ExternalReference : ContentItem {
|
||||
NSString *filename;
|
||||
}
|
||||
|
||||
- (id) initWithFilename:(NSString*)theFilename;
|
||||
- (id) initWithFilename:(NSString *)theFilename relativeToContent:(ContentIdentity*)relativeToContent;
|
||||
|
||||
@property (nonatomic, retain) NSString *filename;
|
||||
|
||||
@end
|
@ -0,0 +1,39 @@
|
||||
//
|
||||
// ExternalReference.m
|
||||
// XNI
|
||||
//
|
||||
// Created by Matej Jan on 29.11.10.
|
||||
// Copyright 2010 Retronator. All rights reserved.
|
||||
//
|
||||
|
||||
#import "ExternalReference.h"
|
||||
|
||||
#import "Retronator.Xni.Framework.Content.Pipeline.h"
|
||||
|
||||
@implementation ExternalReference
|
||||
|
||||
- (id) initWithFilename:(NSString *)theFilename
|
||||
{
|
||||
self = [super init];
|
||||
if (self != nil) {
|
||||
filename = [theFilename retain];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (id) initWithFilename:(NSString *)theFilename relativeToContent:(ContentIdentity *)relativeToContent {
|
||||
/*NSString *absoluteFilename = [NSString pathWithComponents:[NSArray arrayWithObjects:@"/", relativeToContent.sourceFilename, theFilename, nil]];
|
||||
return [self initWithFilename:[absoluteFilename stringByStandardizingPath]];*/
|
||||
return [self initWithFilename:theFilename];
|
||||
}
|
||||
|
||||
@synthesize filename;
|
||||
|
||||
- (void) dealloc
|
||||
{
|
||||
[filename release];
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
|
||||
@end
|
@ -0,0 +1,35 @@
|
||||
//
|
||||
// BasicMaterialContent.h
|
||||
// XNI
|
||||
//
|
||||
// Created by Matej Jan on 22.11.10.
|
||||
// Copyright 2010 Retronator. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
#import "Retronator.Xni.Framework.classes.h"
|
||||
|
||||
#import "MaterialContent.h"
|
||||
|
||||
@interface BasicMaterialContent : MaterialContent {
|
||||
|
||||
}
|
||||
|
||||
@property (nonatomic, readonly) NSString *alphaKey;
|
||||
@property (nonatomic, readonly) NSString *diffuseColorKey;
|
||||
@property (nonatomic, readonly) NSString *emissiveColorKey;
|
||||
@property (nonatomic, readonly) NSString *specularColorKey;
|
||||
@property (nonatomic, readonly) NSString *specularPowerKey;
|
||||
@property (nonatomic, readonly) NSString *textureKey;
|
||||
@property (nonatomic, readonly) NSString *vertexColorEnabledKey;
|
||||
|
||||
@property (nonatomic, retain) NSNumber *alpha;
|
||||
@property (nonatomic, retain) Vector3 *diffuseColor;
|
||||
@property (nonatomic, retain) Vector3 *emissiveColor;
|
||||
@property (nonatomic, retain) Vector3 *specularColor;
|
||||
@property (nonatomic, retain) NSNumber *specularPower;
|
||||
@property (nonatomic, retain) ExternalReference *texture;
|
||||
@property (nonatomic, retain) NSNumber *vertexColorEnabled;
|
||||
|
||||
@end
|
@ -0,0 +1,101 @@
|
||||
//
|
||||
// BasicMaterialContent.m
|
||||
// XNI
|
||||
//
|
||||
// Created by Matej Jan on 22.11.10.
|
||||
// Copyright 2010 Retronator. All rights reserved.
|
||||
//
|
||||
|
||||
#import "BasicMaterialContent.h"
|
||||
|
||||
#import "Retronator.Xni.Framework.h"
|
||||
#import "Retronator.Xni.Framework.Content.Pipeline.h"
|
||||
|
||||
@implementation BasicMaterialContent
|
||||
|
||||
- (NSString *) alphaKey {
|
||||
return @"BasicMaterialAlpha";
|
||||
}
|
||||
|
||||
- (NSString *) diffuseColorKey {
|
||||
return @"BasicMaterialDiffuseColor";
|
||||
}
|
||||
|
||||
- (NSString *) emissiveColorKey {
|
||||
return @"BasicMaterialEmissiveColor";
|
||||
}
|
||||
|
||||
- (NSString *) specularColorKey {
|
||||
return @"BasicMaterialSpecularColor";
|
||||
}
|
||||
|
||||
- (NSString *) specularPowerKey {
|
||||
return @"BasicMaterialSpecularPower";
|
||||
}
|
||||
|
||||
- (NSString *) textureKey {
|
||||
return @"BasicMaterialTexture";
|
||||
}
|
||||
|
||||
- (NSString *) vertexColorEnabledKey {
|
||||
return @"BasicMaterialVertexColorEnabled";
|
||||
}
|
||||
|
||||
|
||||
- (NSNumber *) alpha {
|
||||
return [opaqueData itemForKey:self.alphaKey];
|
||||
}
|
||||
|
||||
- (void) setAlpha:(NSNumber *)value {
|
||||
[opaqueData set:value forKey:self.alphaKey];
|
||||
}
|
||||
|
||||
- (Vector3 *) diffuseColor {
|
||||
return [opaqueData itemForKey:self.diffuseColorKey];
|
||||
}
|
||||
|
||||
- (void) setDiffuseColor:(Vector3 *)value {
|
||||
[opaqueData set:value forKey:self.diffuseColorKey];
|
||||
}
|
||||
|
||||
- (Vector3 *) emissiveColor {
|
||||
return [opaqueData itemForKey:self.emissiveColorKey];
|
||||
}
|
||||
|
||||
- (void) setEmissiveColor:(Vector3 *)value {
|
||||
[opaqueData set:value forKey:self.emissiveColorKey];
|
||||
}
|
||||
|
||||
- (Vector3 *) specularColor {
|
||||
return [opaqueData itemForKey:self.specularColorKey];
|
||||
}
|
||||
|
||||
- (void) setSpecularColor:(Vector3 *)value {
|
||||
[opaqueData set:value forKey:self.specularColorKey];
|
||||
}
|
||||
|
||||
- (NSNumber *) specularPower {
|
||||
return [opaqueData itemForKey:self.specularPowerKey];
|
||||
}
|
||||
|
||||
- (void) setSpecularPower:(NSNumber *)value {
|
||||
[opaqueData set:value forKey:self.specularPowerKey];
|
||||
}
|
||||
|
||||
- (ExternalReference *) texture {
|
||||
return [opaqueData itemForKey:self.textureKey];
|
||||
}
|
||||
|
||||
- (void) setTexture:(ExternalReference *)value {
|
||||
[opaqueData set:value forKey:self.textureKey];
|
||||
}
|
||||
|
||||
- (NSNumber *) vertexColorEnabled {
|
||||
return [opaqueData itemForKey:self.vertexColorEnabledKey];
|
||||
}
|
||||
|
||||
- (void) setVertexColorEnabled:(NSNumber *)value {
|
||||
[opaqueData set:value forKey:self.vertexColorEnabledKey];
|
||||
}
|
||||
|
||||
@end
|
@ -0,0 +1,28 @@
|
||||
//
|
||||
// GeometryContent.h
|
||||
// XNI
|
||||
//
|
||||
// Created by Matej Jan on 22.11.10.
|
||||
// Copyright 2010 Retronator. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
#import "ContentItem.h"
|
||||
#import "Retronator.Xni.Framework.Content.Pipeline.Graphics.classes.h"
|
||||
|
||||
@interface GeometryContent : ContentItem {
|
||||
IndexCollection *indices;
|
||||
MaterialContent *material;
|
||||
MeshContent *parent;
|
||||
VertexContent *vertices;
|
||||
}
|
||||
|
||||
- (id) initWithPositions:(PositionCollection*)thePositions;
|
||||
|
||||
@property (nonatomic, readonly) IndexCollection *indices;
|
||||
@property (nonatomic, retain) MaterialContent *material;
|
||||
@property (nonatomic, retain) MeshContent *parent;
|
||||
@property (nonatomic, readonly) VertexContent *vertices;
|
||||
|
||||
@end
|
@ -0,0 +1,37 @@
|
||||
//
|
||||
// GeometryContent.m
|
||||
// XNI
|
||||
//
|
||||
// Created by Matej Jan on 22.11.10.
|
||||
// Copyright 2010 Retronator. All rights reserved.
|
||||
//
|
||||
|
||||
#import "GeometryContent.h"
|
||||
|
||||
#import "Retronator.Xni.Framework.Content.Pipeline.Graphics.h"
|
||||
|
||||
@implementation GeometryContent
|
||||
|
||||
- (id) initWithPositions:(PositionCollection*)thePositions;
|
||||
{
|
||||
self = [super init];
|
||||
if (self != nil) {
|
||||
indices = [[IndexCollection alloc] init];
|
||||
vertices = [[VertexContent alloc] initWithPositions:thePositions];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
@synthesize indices, material, parent, vertices;
|
||||
|
||||
- (void) dealloc
|
||||
{
|
||||
[material release];
|
||||
[parent release];
|
||||
[indices release];
|
||||
[vertices release];
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
|
||||
@end
|
@ -0,0 +1,17 @@
|
||||
//
|
||||
// GeometryContentCollection.h
|
||||
// XNI
|
||||
//
|
||||
// Created by Matej Jan on 26.11.10.
|
||||
// Copyright 2010 Retronator. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
#import "ChildCollection.h"
|
||||
|
||||
@interface GeometryContentCollection : ChildCollection {
|
||||
|
||||
}
|
||||
|
||||
@end
|
@ -0,0 +1,23 @@
|
||||
//
|
||||
// GeometryContentCollection.m
|
||||
// XNI
|
||||
//
|
||||
// Created by Matej Jan on 26.11.10.
|
||||
// Copyright 2010 Retronator. All rights reserved.
|
||||
//
|
||||
|
||||
#import "GeometryContentCollection.h"
|
||||
|
||||
#import "Retronator.Xni.Framework.Content.Pipeline.Graphics.h"
|
||||
|
||||
@implementation GeometryContentCollection
|
||||
|
||||
- (MeshContent*) getParentOf:(GeometryContent*)child {
|
||||
return child.parent;
|
||||
}
|
||||
|
||||
- (void) setParentOf:(GeometryContent*)child to:(MeshContent*)theParent {
|
||||
child.parent = theParent;
|
||||
}
|
||||
|
||||
@end
|
@ -0,0 +1,17 @@
|
||||
//
|
||||
// IndexCollection.h
|
||||
// XNI
|
||||
//
|
||||
// Created by Matej Jan on 22.11.10.
|
||||
// Copyright 2010 Retronator. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
#define Collection IndexCollection
|
||||
#define T NSNumber*
|
||||
|
||||
#include "Collection.h"
|
||||
|
||||
#undef Collection
|
||||
#undef T
|
@ -0,0 +1,18 @@
|
||||
//
|
||||
// IndexCollection.m
|
||||
// XNI
|
||||
//
|
||||
// Created by Matej Jan on 22.11.10.
|
||||
// Copyright 2010 Retronator. All rights reserved.
|
||||
//
|
||||
|
||||
#import "IndexCollection.h"
|
||||
|
||||
|
||||
#define Collection IndexCollection
|
||||
#define T NSNumber*
|
||||
|
||||
#include "Collection.m.h"
|
||||
|
||||
#undef Collection
|
||||
#undef T
|
@ -0,0 +1,24 @@
|
||||
//
|
||||
// IndirectPositionCollection.h
|
||||
// XNI
|
||||
//
|
||||
// Created by Matej Jan on 26.11.10.
|
||||
// Copyright 2010 Retronator. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
#import "Retronator.Xni.Framework.classes.h"
|
||||
#import "Retronator.Xni.Framework.Content.Pipeline.Graphics.classes.h"
|
||||
|
||||
@interface IndirectPositionCollection : NSObject {
|
||||
VertexChannel *positionIndices;
|
||||
PositionCollection *positions;
|
||||
}
|
||||
|
||||
- (id) initWithPositionIndices:(VertexChannel*)thePositionIndices positions:(PositionCollection*)thePositions;
|
||||
|
||||
- (Vector3*)itemAt:(int)index;
|
||||
- (void)setItem:(Vector3*)item at:(int)index;
|
||||
|
||||
@end
|
@ -0,0 +1,43 @@
|
||||
//
|
||||
// IndirectPositionCollection.m
|
||||
// XNI
|
||||
//
|
||||
// Created by Matej Jan on 26.11.10.
|
||||
// Copyright 2010 Retronator. All rights reserved.
|
||||
//
|
||||
|
||||
#import "IndirectPositionCollection.h"
|
||||
|
||||
#import "Retronator.Xni.Framework.Content.Pipeline.Graphics.h"
|
||||
|
||||
@implementation IndirectPositionCollection
|
||||
|
||||
- (id) initWithPositionIndices:(VertexChannel*)thePositionIndices positions:(PositionCollection*)thePositions
|
||||
{
|
||||
self = [super init];
|
||||
if (self != nil) {
|
||||
positionIndices = [thePositionIndices retain];
|
||||
positions = [thePositions retain];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (Vector3*)itemAt:(int)index {
|
||||
NSNumber *positionIndex = [positionIndices itemAt:index];
|
||||
return [positions itemAt:[positionIndex intValue]];
|
||||
}
|
||||
|
||||
- (void)setItem:(Vector3*)item at:(int)index {
|
||||
NSNumber *positionIndex = [positionIndices itemAt:index];
|
||||
[positions setItem:item at:[positionIndex intValue]];
|
||||
}
|
||||
|
||||
- (void) dealloc
|
||||
{
|
||||
[positionIndices release];
|
||||
[positions release];
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
|
||||
@end
|
@ -0,0 +1,21 @@
|
||||
//
|
||||
// MaterialContent.h
|
||||
// XNI
|
||||
//
|
||||
// Created by Matej Jan on 22.11.10.
|
||||
// Copyright 2010 Retronator. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
#import "Retronator.Xni.Framework.Content.Pipeline.Graphics.classes.h"
|
||||
|
||||
#import "ContentItem.h"
|
||||
|
||||
@interface MaterialContent : ContentItem {
|
||||
TextureReferenceDictionary *textures;
|
||||
}
|
||||
|
||||
@property (nonatomic, readonly) TextureReferenceDictionary *textures;
|
||||
|
||||
@end
|
@ -0,0 +1,33 @@
|
||||
//
|
||||
// MaterialContent.m
|
||||
// XNI
|
||||
//
|
||||
// Created by Matej Jan on 22.11.10.
|
||||
// Copyright 2010 Retronator. All rights reserved.
|
||||
//
|
||||
|
||||
#import "MaterialContent.h"
|
||||
|
||||
#import "Retronator.Xni.Framework.Content.Pipeline.Graphics.h"
|
||||
|
||||
@implementation MaterialContent
|
||||
|
||||
- (id) init
|
||||
{
|
||||
self = [super init];
|
||||
if (self != nil) {
|
||||
textures = [[TextureReferenceDictionary alloc] init];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
@synthesize textures;
|
||||
|
||||
- (void) dealloc
|
||||
{
|
||||
[textures release];
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
|
||||
@end
|
@ -0,0 +1,22 @@
|
||||
//
|
||||
// MeshContent.h
|
||||
// XNI
|
||||
//
|
||||
// Created by Matej Jan on 22.11.10.
|
||||
// Copyright 2010 Retronator. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
#import "NodeContent.h"
|
||||
#import "Retronator.Xni.Framework.Content.Pipeline.Graphics.classes.h"
|
||||
|
||||
@interface MeshContent : NodeContent {
|
||||
GeometryContentCollection *geometry;
|
||||
PositionCollection *positions;
|
||||
}
|
||||
|
||||
@property (nonatomic, readonly) GeometryContentCollection *geometry;
|
||||
@property (nonatomic, readonly) PositionCollection *positions;
|
||||
|
||||
@end
|
@ -0,0 +1,35 @@
|
||||
//
|
||||
// MeshContent.m
|
||||
// XNI
|
||||
//
|
||||
// Created by Matej Jan on 22.11.10.
|
||||
// Copyright 2010 Retronator. All rights reserved.
|
||||
//
|
||||
|
||||
#import "MeshContent.h"
|
||||
|
||||
#import "Retronator.Xni.Framework.Content.Pipeline.Graphics.h"
|
||||
|
||||
@implementation MeshContent
|
||||
|
||||
- (id) init
|
||||
{
|
||||
self = [super init];
|
||||
if (self != nil) {
|
||||
geometry = [[GeometryContentCollection alloc] initWithParent:self];
|
||||
positions = [[PositionCollection alloc] init];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
@synthesize geometry, positions;
|
||||
|
||||
- (void) dealloc
|
||||
{
|
||||
[geometry release];
|
||||
[positions release];
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
|
||||
@end
|
@ -20,3 +20,4 @@
|
||||
- (void)insertObject:(BitmapContent*)anObject atIndex:(NSUInteger)index;
|
||||
|
||||
@end
|
||||
|
||||
|
@ -6,17 +6,12 @@
|
||||
// Copyright 2010 Retronator. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
#import "Retronator.Xni.Framework.Content.Pipeline.Graphics.classes.h"
|
||||
|
||||
@interface MipmapChainCollection : NSObject {
|
||||
NSMutableArray *collection;
|
||||
}
|
||||
#define Collection MipmapChainCollection
|
||||
#define T MipmapChain*
|
||||
|
||||
- (int) count;
|
||||
- (MipmapChain*)objectAtIndex:(NSUInteger)index;
|
||||
- (void)addObject:(MipmapChain*)anObject;
|
||||
- (void)insertObject:(MipmapChain*)anObject atIndex:(NSUInteger)index;
|
||||
#include "Collection.h"
|
||||
|
||||
@end
|
||||
#undef Collection
|
||||
#undef T
|
@ -10,37 +10,10 @@
|
||||
|
||||
#import "Retronator.Xni.Framework.Content.Pipeline.Graphics.h"
|
||||
|
||||
@implementation MipmapChainCollection
|
||||
#define Collection MipmapChainCollection
|
||||
#define T MipmapChain*
|
||||
|
||||
- (id) init
|
||||
{
|
||||
self = [super init];
|
||||
if (self != nil) {
|
||||
collection = [[NSMutableArray alloc] init];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
#include "Collection.m.h"
|
||||
|
||||
- (int) count {
|
||||
return [collection count];
|
||||
}
|
||||
|
||||
- (MipmapChain*)objectAtIndex:(NSUInteger)index {
|
||||
return (MipmapChain*)[collection objectAtIndex:index];
|
||||
}
|
||||
|
||||
- (void)addObject:(MipmapChain*)anObject {
|
||||
[collection addObject:anObject];
|
||||
}
|
||||
|
||||
- (void)insertObject:(MipmapChain*)anObject atIndex:(NSUInteger)index {
|
||||
[collection insertObject:anObject atIndex:index];
|
||||
}
|
||||
|
||||
- (void) dealloc
|
||||
{
|
||||
[collection dealloc];
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
@end
|
||||
#undef Collection
|
||||
#undef T
|
@ -0,0 +1,27 @@
|
||||
//
|
||||
// NodeContent.h
|
||||
// XNI
|
||||
//
|
||||
// Created by Matej Jan on 22.11.10.
|
||||
// Copyright 2010 Retronator. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
#import "Retronator.Xni.Framework.classes.h"
|
||||
#import "Retronator.Xni.Framework.Content.Pipeline.Graphics.classes.h"
|
||||
|
||||
#import "ContentItem.h"
|
||||
|
||||
@interface NodeContent : ContentItem {
|
||||
NodeContentCollection *children;
|
||||
NodeContent *parent;
|
||||
Matrix *transform;
|
||||
}
|
||||
|
||||
@property (nonatomic, readonly) NodeContentCollection *children;
|
||||
@property (nonatomic, retain) NodeContent *parent;
|
||||
@property (nonatomic, retain) Matrix *transform;
|
||||
@property (nonatomic, readonly) Matrix *absoluteTransform;
|
||||
|
||||
@end
|
@ -0,0 +1,49 @@
|
||||
//
|
||||
// NodeContent.m
|
||||
// XNI
|
||||
//
|
||||
// Created by Matej Jan on 22.11.10.
|
||||
// Copyright 2010 Retronator. All rights reserved.
|
||||
//
|
||||
|
||||
#import "NodeContent.h"
|
||||
|
||||
#import "Retronator.Xni.Framework.h"
|
||||
#import "Retronator.Xni.Framework.Content.Pipeline.Graphics.h"
|
||||
|
||||
@implementation NodeContent
|
||||
|
||||
- (id) init
|
||||
{
|
||||
self = [super init];
|
||||
if (self != nil) {
|
||||
children = [[NodeContentCollection alloc] initWithParent:self];
|
||||
transform = [[Matrix identity] retain];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
@synthesize children, parent, transform;
|
||||
|
||||
- (Matrix *) absoluteTransform {
|
||||
if (!parent) {
|
||||
// Create a new matrix in the root node.
|
||||
return [Matrix matrixWithMatrix:transform];
|
||||
} else {
|
||||
// Multiply the passed down matrix with itself.
|
||||
return [parent.absoluteTransform multiplyBy:transform];
|
||||
}
|
||||
}
|
||||
|
||||
- (void) dealloc
|
||||
{
|
||||
[transform release];
|
||||
[children release];
|
||||
[parent release];
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@end
|
@ -0,0 +1,17 @@
|
||||
//
|
||||
// NodeContentCollection.h
|
||||
// XNI
|
||||
//
|
||||
// Created by Matej Jan on 26.11.10.
|
||||
// Copyright 2010 Retronator. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
#import "ChildCollection.h"
|
||||
|
||||
@interface NodeContentCollection : ChildCollection {
|
||||
|
||||
}
|
||||
|
||||
@end
|
@ -0,0 +1,23 @@
|
||||
//
|
||||
// NodeContentCollection.m
|
||||
// XNI
|
||||
//
|
||||
// Created by Matej Jan on 26.11.10.
|
||||
// Copyright 2010 Retronator. All rights reserved.
|
||||
//
|
||||
|
||||
#import "NodeContentCollection.h"
|
||||
|
||||
#import "Retronator.Xni.Framework.Content.Pipeline.Graphics.h"
|
||||
|
||||
@implementation NodeContentCollection
|
||||
|
||||
- (NodeContent*) getParentOf:(NodeContent*)child {
|
||||
return child.parent;
|
||||
}
|
||||
|
||||
- (void) setParentOf:(NodeContent*)child to:(NodeContent*)theParent {
|
||||
child.parent = theParent;
|
||||
}
|
||||
|
||||
@end
|
@ -0,0 +1,17 @@
|
||||
//
|
||||
// PositionCollection.h
|
||||
// XNI
|
||||
//
|
||||
// Created by Matej Jan on 26.11.10.
|
||||
// Copyright 2010 Retronator. All rights reserved.
|
||||
//
|
||||
|
||||
#import "Retronator.Xni.Framework.classes.h"
|
||||
|
||||
#define Collection PositionCollection
|
||||
#define T Vector3*
|
||||
|
||||
#include "Collection.h"
|
||||
|
||||
#undef Collection
|
||||
#undef T
|
@ -0,0 +1,19 @@
|
||||
//
|
||||
// PositionCollection.m
|
||||
// XNI
|
||||
//
|
||||
// Created by Matej Jan on 26.11.10.
|
||||
// Copyright 2010 Retronator. All rights reserved.
|
||||
//
|
||||
|
||||
#import "PositionCollection.h"
|
||||
|
||||
#import "Retronator.Xni.Framework.h"
|
||||
|
||||
#define Collection PositionCollection
|
||||
#define T Vector3*
|
||||
|
||||
#include "Collection.m.h"
|
||||
|
||||
#undef Collection
|
||||
#undef T
|
@ -1,8 +1,12 @@
|
||||
|
||||
@class BitmapContent, PixelBitmapContent;
|
||||
|
||||
@class MipmapChain, MipmapChainCollection;
|
||||
|
||||
@class TextureContent, Texture2DContent;
|
||||
|
||||
@class VectorConverter;
|
||||
@class VectorConverter;
|
||||
|
||||
@class NodeContent, NodeContentCollection;
|
||||
@class MeshContent, GeometryContentCollection, PositionCollection;
|
||||
@class GeometryContent, VertexContent, VertexChannelCollection, VertexChannel, IndirectPositionCollection;
|
||||
@class VertexChannelNames, IndexCollection;
|
||||
@class MaterialContent, BasicMaterialContent;
|
||||
@class TextureReferenceDictionary;
|
@ -8,4 +8,25 @@
|
||||
#import "TextureContent.h"
|
||||
#import "Texture2DContent.h"
|
||||
|
||||
#import "VectorConverter.h"
|
||||
#import "VectorConverter.h"
|
||||
|
||||
#import "NodeContent.h"
|
||||
#import "NodeContentCollection.h"
|
||||
|
||||
#import "MeshContent.h"
|
||||
#import "GeometryContentCollection.h"
|
||||
#import "PositionCollection.h"
|
||||
|
||||
#import "GeometryContent.h"
|
||||
#import "VertexContent.h"
|
||||
#import "VertexChannelCollection.h"
|
||||
#import "VertexChannel.h"
|
||||
#import "IndirectPositionCollection.h"
|
||||
|
||||
#import "VertexChannelNames.h"
|
||||
#import "IndexCollection.h"
|
||||
|
||||
#import "MaterialContent.h"
|
||||
#import "BasicMaterialContent.h"
|
||||
|
||||
#import "TextureReferenceDictionary.h"
|
@ -21,11 +21,11 @@
|
||||
}
|
||||
|
||||
- (MipmapChain*) mipmaps {
|
||||
return [[self faces] objectAtIndex:0];
|
||||
return [[self faces] itemAt:0];
|
||||
}
|
||||
|
||||
- (void) setMipmaps:(MipmapChain *)value {
|
||||
[[self faces] insertObject:value atIndex:0];
|
||||
[[self faces] insert:value at:0];
|
||||
}
|
||||
|
||||
- (void) validateWithGraphicsProfile:(GraphicsProfile)targetProfile {
|
||||
|
@ -10,7 +10,9 @@
|
||||
|
||||
#import "Retronator.Xni.Framework.Content.Pipeline.Graphics.classes.h"
|
||||
|
||||
@interface TextureContent : NSObject {
|
||||
#import "ContentItem.h"
|
||||
|
||||
@interface TextureContent : ContentItem {
|
||||
MipmapChainCollection *faces;
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,19 @@
|
||||
//
|
||||
// TextureReferenceDictionary.h
|
||||
// XNI
|
||||
//
|
||||
// Created by Matej Jan on 29.11.10.
|
||||
// Copyright 2010 Retronator. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
#import "Retronator.Xni.Framework.Content.Pipeline.classes.h"
|
||||
|
||||
#define NamedValueDictionary TextureReferenceDictionary
|
||||
#define T ExternalReference*
|
||||
|
||||
#include "NamedValueDictionary.h"
|
||||
|
||||
#undef NamedValueDictionary
|
||||
#undef T
|
@ -0,0 +1,18 @@
|
||||
//
|
||||
// TextureReferenceDictionary.m
|
||||
// XNI
|
||||
//
|
||||
// Created by Matej Jan on 29.11.10.
|
||||
// Copyright 2010 Retronator. All rights reserved.
|
||||
//
|
||||
|
||||
#import "TextureReferenceDictionary.h"
|
||||
|
||||
|
||||
#define NamedValueDictionary TextureReferenceDictionary
|
||||
#define T ExternalReference*
|
||||
|
||||
#include "NamedValueDictionary.m.h"
|
||||
|
||||
#undef NamedValueDictionary
|
||||
#undef T
|
@ -0,0 +1,35 @@
|
||||
//
|
||||
// VertexChannel.h
|
||||
// XNI
|
||||
//
|
||||
// Created by Matej Jan on 26.11.10.
|
||||
// Copyright 2010 Retronator. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
@interface VertexChannel : NSObject <NSFastEnumeration> {
|
||||
NSMutableArray *collection;
|
||||
Class elementType;
|
||||
NSString *name;
|
||||
}
|
||||
|
||||
- (id) initWithElementType:(Class)theElementType name:(NSString*)theName channelData:(NSArray*)channelData;
|
||||
|
||||
@property (nonatomic, readonly) int count;
|
||||
@property (nonatomic, readonly) Class elementType;
|
||||
@property (nonatomic, readonly) NSString *name;
|
||||
|
||||
- (id)itemAt:(int)index;
|
||||
- (void)setItem:(id)item at:(int)index;
|
||||
|
||||
- (void)add:(id)item;
|
||||
- (void)insert:(id)item at:(int)index;
|
||||
|
||||
- (void)remove:(id)item;
|
||||
- (void)removeAt:(int)index;
|
||||
|
||||
- (void) clear;
|
||||
|
||||
@end
|
||||
|
@ -0,0 +1,69 @@
|
||||
//
|
||||
// VertexChannel.m
|
||||
// XNI
|
||||
//
|
||||
// Created by Matej Jan on 26.11.10.
|
||||
// Copyright 2010 Retronator. All rights reserved.
|
||||
//
|
||||
|
||||
#import "VertexChannel.h"
|
||||
|
||||
|
||||
@implementation VertexChannel
|
||||
|
||||
- (id) initWithElementType:(Class)theElementType name:(NSString*)theName channelData:(NSArray*)channelData
|
||||
{
|
||||
self = [super init];
|
||||
if (self != nil) {
|
||||
collection = [[NSMutableArray alloc] initWithArray:channelData];
|
||||
elementType = theElementType;
|
||||
name = theName;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
@synthesize elementType, name;
|
||||
|
||||
- (int) count {
|
||||
return [collection count];
|
||||
}
|
||||
|
||||
- (id)itemAt:(int)index {
|
||||
return [collection objectAtIndex:index];
|
||||
}
|
||||
|
||||
- (void)setItem:(id)item at:(int)index {
|
||||
return [collection replaceObjectAtIndex:index withObject:item];
|
||||
}
|
||||
|
||||
- (void)add:(id)item {
|
||||
[collection addObject:item];
|
||||
}
|
||||
|
||||
- (void)insert:(id)item at:(int)index {
|
||||
[collection insertObject:item atIndex:index];
|
||||
}
|
||||
|
||||
- (void)remove:(id)item {
|
||||
[collection removeObject:item];
|
||||
}
|
||||
|
||||
- (void)removeAt:(int)index {
|
||||
[collection removeObjectAtIndex:index];
|
||||
}
|
||||
|
||||
- (void) clear {
|
||||
[collection removeAllObjects];
|
||||
}
|
||||
|
||||
- (NSUInteger) countByEnumeratingWithState:(NSFastEnumerationState *)state objects:(id *)stackbuf count:(NSUInteger)len {
|
||||
return [collection countByEnumeratingWithState:state objects:stackbuf count:len];
|
||||
}
|
||||
|
||||
- (void) dealloc
|
||||
{
|
||||
[collection dealloc];
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
@end
|
@ -0,0 +1,36 @@
|
||||
//
|
||||
// VertexChannelCollection.h
|
||||
// XNI
|
||||
//
|
||||
// Created by Matej Jan on 26.11.10.
|
||||
// Copyright 2010 Retronator. All rights reserved.
|
||||
//
|
||||
|
||||
#import "Retronator.Xni.Framework.Content.Pipeline.Graphics.classes.h"
|
||||
|
||||
@interface VertexChannelCollection : NSObject <NSFastEnumeration> {
|
||||
NSMutableArray *channels;
|
||||
NSMutableDictionary *channelsByNames;
|
||||
VertexContent *parent;
|
||||
}
|
||||
|
||||
- (id) initWithParent:(VertexContent*)theParent;
|
||||
|
||||
@property (nonatomic, readonly) int count;
|
||||
|
||||
- (VertexChannel*)itemAt:(int)index;
|
||||
- (void)setItem:(VertexChannel*)item at:(int)index;
|
||||
|
||||
- (VertexChannel*)itemWithName:(NSString*)name;
|
||||
|
||||
- (void)addChannelWithName:(NSString*)name elementType:(Class)elementType channelData:(NSArray*)channelData;
|
||||
- (void)insertChannelWithName:(NSString*)name elementType:(Class)elementType channelData:(NSArray*)channelData at:(int)index;
|
||||
|
||||
- (void)remove:(VertexChannel*)item;
|
||||
- (void)removeAt:(int)index;
|
||||
- (void)removeChannelWithName:(NSString*)name;
|
||||
|
||||
- (void) clear;
|
||||
|
||||
@end
|
||||
|
@ -0,0 +1,93 @@
|
||||
//
|
||||
// VertexChannelCollection.m
|
||||
// XNI
|
||||
//
|
||||
// Created by Matej Jan on 26.11.10.
|
||||
// Copyright 2010 Retronator. All rights reserved.
|
||||
//
|
||||
|
||||
#import "VertexChannelCollection.h"
|
||||
|
||||
#import "Retronator.Xni.Framework.Content.Pipeline.Graphics.h"
|
||||
|
||||
@implementation VertexChannelCollection
|
||||
|
||||
- (id) initWithParent:(VertexContent*)theParent
|
||||
{
|
||||
self = [super init];
|
||||
if (self != nil) {
|
||||
channels = [[NSMutableArray alloc] init];
|
||||
channelsByNames = [[NSMutableDictionary alloc] init];
|
||||
parent = theParent;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (int) count {
|
||||
return [channels count];
|
||||
}
|
||||
|
||||
- (VertexChannel*)itemAt:(int)index {
|
||||
return [channels objectAtIndex:index];
|
||||
}
|
||||
|
||||
- (void)setItem:(VertexChannel*)item at:(int)index {
|
||||
VertexChannel* existing = [channels objectAtIndex:index];
|
||||
[channelsByNames removeObjectForKey:existing.name];
|
||||
return [channels replaceObjectAtIndex:index withObject:item];
|
||||
}
|
||||
|
||||
- (VertexChannel*)itemWithName:(NSString*)name {
|
||||
return [channelsByNames objectForKey:name];
|
||||
}
|
||||
|
||||
- (void)addChannelWithName:(NSString*)name elementType:(Class)elementType channelData:(NSArray*)channelData {
|
||||
[self insertChannelWithName:name elementType:elementType channelData:channelData at:[channels count]];
|
||||
}
|
||||
|
||||
- (void)insertChannelWithName:(NSString*)name elementType:(Class)elementType channelData:(NSArray*)channelData at:(int)index {
|
||||
if (!channelData) {
|
||||
// Fill the channel with default values.
|
||||
NSMutableArray *data = [NSMutableArray arrayWithCapacity:parent.vertexCount];
|
||||
for (int i = 0; i < parent.vertexCount; i++) {
|
||||
[data addObject:[[[elementType alloc] init] autorelease]];
|
||||
}
|
||||
channelData = data;
|
||||
}
|
||||
VertexChannel *channel = [[[VertexChannel alloc] initWithElementType:elementType name:name channelData:channelData] autorelease];
|
||||
[channels insertObject:channel atIndex:index];
|
||||
[channelsByNames setObject:channel forKey:name];
|
||||
}
|
||||
|
||||
- (void)remove:(VertexChannel*)item {
|
||||
[channels removeObject:item];
|
||||
[channelsByNames removeObjectForKey:item.name];
|
||||
}
|
||||
|
||||
- (void)removeAt:(int)index {
|
||||
VertexChannel *channel = [channels objectAtIndex:index];
|
||||
[self remove:channel];
|
||||
}
|
||||
|
||||
- (void) removeChannelWithName:(NSString *)name {
|
||||
VertexChannel *channel = [self itemWithName:name];
|
||||
[self remove:channel];
|
||||
}
|
||||
|
||||
- (void) clear {
|
||||
[channels removeAllObjects];
|
||||
[channelsByNames removeAllObjects];
|
||||
}
|
||||
|
||||
- (NSUInteger) countByEnumeratingWithState:(NSFastEnumerationState *)state objects:(id *)stackbuf count:(NSUInteger)len {
|
||||
return [channels countByEnumeratingWithState:state objects:stackbuf count:len];
|
||||
}
|
||||
|
||||
- (void) dealloc
|
||||
{
|
||||
[channels dealloc];
|
||||
[channelsByNames dealloc];
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
@end
|
@ -0,0 +1,33 @@
|
||||
//
|
||||
// VertexChannelNames.h
|
||||
// XNI
|
||||
//
|
||||
// Created by Matej Jan on 26.11.10.
|
||||
// Copyright 2010 Retronator. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
#import "Retronator.Xni.Framework.Graphics.classes.h"
|
||||
|
||||
@interface VertexChannelNames : NSObject {
|
||||
|
||||
}
|
||||
|
||||
+ (NSString*) encodeName:(NSString*)baseName usageIndex:(int)usageIndex;
|
||||
+ (NSString*) encodeUsage:(VertexElementUsage)vertexElementUsage usageIndex:(int)usageIndex;
|
||||
|
||||
+ (NSString*) decodeBaseName:(NSString*)encodedName;
|
||||
+ (int) decodeUsageIndex:(NSString*)encodedName;
|
||||
+ (BOOL) tryDecodeUsage:(NSString*)encodedName usage:(VertexElementUsage*)usage;
|
||||
|
||||
+ (NSString*) binormalWithUsageIndex:(int)usageIndex;
|
||||
+ (NSString*) colorWithUsageIndex:(int)usageIndex;
|
||||
+ (NSString*) normal;
|
||||
+ (NSString*) normalWithUsageIndex:(int)usageIndex;
|
||||
+ (NSString*) tangentWithUsageIndex:(int)usageIndex;
|
||||
+ (NSString*) textureCoordinateWithUsageIndex:(int)usageIndex;
|
||||
+ (NSString*) weights;
|
||||
+ (NSString*) weightsWithUsageIndex:(int)usageIndex;
|
||||
|
||||
@end
|
@ -0,0 +1,153 @@
|
||||
//
|
||||
// VertexChannelNames.m
|
||||
// XNI
|
||||
//
|
||||
// Created by Matej Jan on 26.11.10.
|
||||
// Copyright 2010 Retronator. All rights reserved.
|
||||
//
|
||||
|
||||
#import "VertexChannelNames.h"
|
||||
|
||||
@interface VertexChannelNames ()
|
||||
|
||||
+ (NSString*) getNameForUsage:(VertexElementUsage)vertexElementUsage;
|
||||
+ (BOOL) tryGetUsageForName:(NSString *)name usage:(VertexElementUsage*)usage;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@implementation VertexChannelNames
|
||||
|
||||
+ (NSString*) getNameForUsage:(VertexElementUsage)vertexElementUsage {
|
||||
switch (vertexElementUsage) {
|
||||
case VertexElementUsageColor:
|
||||
return @"Color";
|
||||
case VertexElementUsageNormal:
|
||||
return @"Normal";
|
||||
case VertexElementUsagePointSize:
|
||||
return @"PointSize";
|
||||
case VertexElementUsagePosition:
|
||||
return @"Position";
|
||||
case VertexElementUsageTextureCoordinate:
|
||||
return @"TextureCoordinate";
|
||||
case VertexElementUsageBinormal:
|
||||
return @"Binormal";
|
||||
case VertexElementUsageBlendIndices:
|
||||
return @"BlendIndices";
|
||||
case VertexElementUsageBlendWeight:
|
||||
return @"BlendWeight";
|
||||
case VertexElementUsageDepth:
|
||||
return @"Depth";
|
||||
case VertexElementUsageFog:
|
||||
return @"Fog";
|
||||
case VertexElementUsageSample:
|
||||
return @"Sample";
|
||||
case VertexElementUsageTangent:
|
||||
return @"Tangent";
|
||||
case VertexElementUsageTessellateFactor:
|
||||
return @"TessellateFactor";
|
||||
default:
|
||||
[NSException raise:@"InvalidArgumentException" format:@"VertexElementUsage %i is not supported", vertexElementUsage];
|
||||
return @"";
|
||||
}
|
||||
}
|
||||
|
||||
+ (BOOL) tryGetUsageForName:(NSString *)name usage:(VertexElementUsage*)usage {
|
||||
if ([name isEqualToString:@"Color"]) {
|
||||
*usage = VertexElementUsageColor;
|
||||
return YES;
|
||||
} else if ([name isEqualToString:@"Normal"]) {
|
||||
*usage = VertexElementUsageNormal;
|
||||
return YES;
|
||||
} else if ([name isEqualToString:@"PointSize"]) {
|
||||
*usage = VertexElementUsagePointSize;
|
||||
return YES;
|
||||
} else if ([name isEqualToString:@"Position"]) {
|
||||
*usage = VertexElementUsagePosition;
|
||||
return YES;
|
||||
} else if ([name isEqualToString:@"TextureCoordinate"]) {
|
||||
*usage = VertexElementUsageTextureCoordinate;
|
||||
return YES;
|
||||
} else if ([name isEqualToString:@"Binormal"]) {
|
||||
*usage = VertexElementUsageBinormal;
|
||||
return YES;
|
||||
} else if ([name isEqualToString:@"BlendIndices"]) {
|
||||
*usage = VertexElementUsageBlendIndices;
|
||||
return YES;
|
||||
} else if ([name isEqualToString:@"BlendWeight"]) {
|
||||
*usage = VertexElementUsageBlendWeight;
|
||||
return YES;
|
||||
} else if ([name isEqualToString:@"Depth"]) {
|
||||
*usage = VertexElementUsageDepth;
|
||||
return YES;
|
||||
} else if ([name isEqualToString:@"Fog"]) {
|
||||
*usage = VertexElementUsageFog;
|
||||
return YES;
|
||||
} else if ([name isEqualToString:@"Sample"]) {
|
||||
*usage = VertexElementUsageSample;
|
||||
return YES;
|
||||
} else if ([name isEqualToString:@"Tangent"]) {
|
||||
*usage = VertexElementUsageTangent;
|
||||
return YES;
|
||||
} else if ([name isEqualToString:@"TessellateFactor"]) {
|
||||
*usage = VertexElementUsageTessellateFactor;
|
||||
return YES;
|
||||
} else {
|
||||
return NO;
|
||||
}
|
||||
}
|
||||
|
||||
+ (NSString*) encodeName:(NSString*)baseName usageIndex:(int)usageIndex {
|
||||
return [NSString stringWithFormat:@"%@-%i", baseName, usageIndex];
|
||||
}
|
||||
|
||||
+ (NSString*) encodeUsage:(VertexElementUsage)vertexElementUsage usageIndex:(int)usageIndex {
|
||||
return [VertexChannelNames encodeName:[VertexChannelNames getNameForUsage:vertexElementUsage] usageIndex:usageIndex];
|
||||
}
|
||||
|
||||
+ (NSString*) decodeBaseName:(NSString*)encodedName {
|
||||
return [[encodedName componentsSeparatedByString:@"-"] objectAtIndex:0];
|
||||
}
|
||||
|
||||
+ (int) decodeUsageIndex:(NSString*)encodedName {
|
||||
NSString *index = [[encodedName componentsSeparatedByString:@"-"] objectAtIndex:1];
|
||||
return [index intValue];
|
||||
}
|
||||
|
||||
+ (BOOL) tryDecodeUsage:(NSString*)encodedName usage:(VertexElementUsage*)usage {
|
||||
return [VertexChannelNames tryGetUsageForName:[VertexChannelNames decodeBaseName:encodedName] usage:usage];
|
||||
}
|
||||
|
||||
+ (NSString*) binormalWithUsageIndex:(int)usageIndex {
|
||||
return [VertexChannelNames encodeUsage:VertexElementUsageBinormal usageIndex:usageIndex];
|
||||
}
|
||||
|
||||
+ (NSString*) colorWithUsageIndex:(int)usageIndex {
|
||||
return [VertexChannelNames encodeUsage:VertexElementUsageColor usageIndex:usageIndex];
|
||||
}
|
||||
|
||||
+ (NSString*) normal {
|
||||
return [VertexChannelNames encodeUsage:VertexElementUsageNormal usageIndex:0];
|
||||
}
|
||||
|
||||
+ (NSString*) normalWithUsageIndex:(int)usageIndex {
|
||||
return [VertexChannelNames encodeUsage:VertexElementUsageNormal usageIndex:usageIndex];
|
||||
}
|
||||
|
||||
+ (NSString*) tangentWithUsageIndex:(int)usageIndex {
|
||||
return [VertexChannelNames encodeUsage:VertexElementUsageTangent usageIndex:usageIndex];
|
||||
}
|
||||
|
||||
+ (NSString*) textureCoordinateWithUsageIndex:(int)usageIndex {
|
||||
return [VertexChannelNames encodeUsage:VertexElementUsageTextureCoordinate usageIndex:usageIndex];
|
||||
}
|
||||
|
||||
+ (NSString*) weights {
|
||||
return [VertexChannelNames encodeUsage:VertexElementUsageBlendWeight usageIndex:0];
|
||||
}
|
||||
|
||||
+ (NSString*) weightsWithUsageIndex:(int)usageIndex {
|
||||
return [VertexChannelNames encodeUsage:VertexElementUsageBlendWeight usageIndex:usageIndex];
|
||||
}
|
||||
|
||||
@end
|
@ -0,0 +1,39 @@
|
||||
//
|
||||
// VertexContent.h
|
||||
// XNI
|
||||
//
|
||||
// Created by Matej Jan on 22.11.10.
|
||||
// Copyright 2010 Retronator. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
#import "Retronator.Xni.Framework.Content.Pipeline.Graphics.classes.h"
|
||||
#import "Retronator.Xni.Framework.Content.Pipeline.Processors.classes.h"
|
||||
|
||||
@interface VertexContent : NSObject {
|
||||
VertexChannelCollection *channels;
|
||||
VertexChannel *positionIndices;
|
||||
IndirectPositionCollection *positions;
|
||||
int vertexCount;
|
||||
}
|
||||
|
||||
- (id) initWithPositions:(PositionCollection*)thePositions;
|
||||
|
||||
@property (nonatomic, readonly) VertexChannelCollection *channels;
|
||||
@property (nonatomic, readonly) VertexChannel *positionIndices;
|
||||
@property (nonatomic, readonly) IndirectPositionCollection *positions;
|
||||
@property (nonatomic, readonly) int vertexCount;
|
||||
|
||||
- (int) add:(int)positionIndex;
|
||||
- (void) addRange:(NSArray*)positionIndexCollection;
|
||||
|
||||
- (void) insert:(int)positionIndex at:(int)index;
|
||||
- (void) insertRange:(NSArray*)positionIndexCollection at:(int)index;
|
||||
|
||||
- (void) removeAt:(int)index;
|
||||
- (void) removeRangeAt:(int)index count:(int)count;
|
||||
|
||||
- (VertexBufferContent*) createVertexBuffer;
|
||||
|
||||
@end
|
@ -0,0 +1,140 @@
|
||||
//
|
||||
// VertexContent.m
|
||||
// XNI
|
||||
//
|
||||
// Created by Matej Jan on 22.11.10.
|
||||
// Copyright 2010 Retronator. All rights reserved.
|
||||
//
|
||||
|
||||
#import "VertexContent.h"
|
||||
|
||||
#import "Retronator.Xni.Framework.h"
|
||||
#import "Retronator.Xni.Framework.Graphics.h"
|
||||
#import "Retronator.Xni.Framework.Content.Pipeline.Graphics.h"
|
||||
#import "Retronator.Xni.Framework.Content.Pipeline.Processors.h"
|
||||
|
||||
@implementation VertexContent
|
||||
|
||||
- (id) initWithPositions:(PositionCollection*)thePositions
|
||||
{
|
||||
self = [super init];
|
||||
if (self != nil) {
|
||||
channels = [[VertexChannelCollection alloc] initWithParent:self];
|
||||
positionIndices = [[IndexCollection alloc] init];
|
||||
positions = [[IndirectPositionCollection alloc] initWithPositionIndices:positionIndices positions:thePositions];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
@synthesize channels, positionIndices, positions, vertexCount;
|
||||
|
||||
- (int) add:(int)positionIndex {
|
||||
for (VertexChannel *channel in channels) {
|
||||
[channel add:[[[channel.elementType alloc] init] autorelease]];
|
||||
}
|
||||
[positionIndices add:[NSNumber numberWithInt:positionIndex]];
|
||||
vertexCount++;
|
||||
return vertexCount-1;
|
||||
}
|
||||
|
||||
- (void) addRange:(NSArray*)positionIndexCollection {
|
||||
for (NSNumber *positionIndex in positionIndexCollection) {
|
||||
[self add:[positionIndex intValue]];
|
||||
}
|
||||
}
|
||||
|
||||
- (void) insert:(int)positionIndex at:(int)index {
|
||||
for (VertexChannel *channel in channels) {
|
||||
[channel insert:[[[channel.elementType alloc] init] autorelease] at:index];
|
||||
}
|
||||
[positionIndices insert:[NSNumber numberWithInt:positionIndex] at:index];
|
||||
vertexCount++;
|
||||
}
|
||||
|
||||
- (void) insertRange:(NSArray*)positionIndexCollection at:(int)index {
|
||||
for (NSNumber *positionIndex in positionIndexCollection) {
|
||||
[self insert:[positionIndex intValue] at:index];
|
||||
index++;
|
||||
}
|
||||
}
|
||||
|
||||
- (void) removeAt:(int)index {
|
||||
for (VertexChannel *channel in channels) {
|
||||
[channel removeAt:index];
|
||||
}
|
||||
[positionIndices removeAt:index];
|
||||
vertexCount--;
|
||||
}
|
||||
|
||||
- (void) removeRangeAt:(int)index count:(int)count {
|
||||
for (int i = 0; i < count; i++) {
|
||||
[self removeAt:index];
|
||||
}
|
||||
}
|
||||
|
||||
- (VertexBufferContent*) createVertexBuffer {
|
||||
VertexBufferContent *vertexBuffer = [[[VertexBufferContent alloc] init] autorelease];
|
||||
|
||||
// Construct vertex declaration.
|
||||
VertexDeclarationContent *vertexDeclaration = [[[VertexDeclarationContent alloc] init] autorelease];
|
||||
|
||||
// Add position element.
|
||||
VertexElement *vertexElement = [VertexElement vertexElementWithOffset:0
|
||||
format:VertexElementFormatVector3
|
||||
usage:VertexElementUsagePosition
|
||||
usageIndex:0];
|
||||
[vertexDeclaration.vertexElements addObject:vertexElement];
|
||||
|
||||
// Add all channel elements.
|
||||
int offset = [vertexElement getSize];
|
||||
for (VertexChannel *channel in channels) {
|
||||
VertexElementFormat elementFormat = [VertexElement getElementFormatForType:channel.elementType];
|
||||
|
||||
VertexElementUsage elementUsage;
|
||||
if (![VertexChannelNames tryDecodeUsage:channel.name usage:&elementUsage]) {
|
||||
[NSException raise:@"NotSupportedException" format:@"The channel name %@ is not supported.", channel.name];
|
||||
}
|
||||
|
||||
Byte usageIndex = [VertexChannelNames decodeUsageIndex:channel.name];
|
||||
|
||||
vertexElement = [VertexElement vertexElementWithOffset:offset format:elementFormat usage:elementUsage usageIndex:usageIndex];
|
||||
[vertexDeclaration.vertexElements addObject:vertexElement];
|
||||
|
||||
offset += [vertexElement getSize];
|
||||
}
|
||||
|
||||
vertexDeclaration.vertexStride = [NSNumber numberWithInt:offset];
|
||||
|
||||
vertexBuffer.vertexDeclaration = vertexDeclaration;
|
||||
|
||||
// Fill the vertex data.
|
||||
for (int i = 0; i < vertexCount; i++) {
|
||||
// Add position.
|
||||
NSNumber *index = [positionIndices itemAt:i];
|
||||
Vector3 *position = [positions itemAt:[index intValue]];
|
||||
[vertexBuffer.vertexData appendBytes:position.data length:sizeof(Vector3Struct)];
|
||||
|
||||
// Add all channel data.
|
||||
for (int j = 0; j < channels.count; j++) {
|
||||
VertexChannel *channel = [channels itemAt:j];
|
||||
if (channel.elementType == [Vector2 class]) {
|
||||
[vertexBuffer.vertexData appendBytes:((Vector2*)[channel itemAt:i]).data length:sizeof(Vector2Struct)];
|
||||
} else if (channel.elementType == [Vector3 class]) {
|
||||
[vertexBuffer.vertexData appendBytes:((Vector3*)[channel itemAt:i]).data length:sizeof(Vector3Struct)];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return vertexBuffer;
|
||||
}
|
||||
|
||||
- (void) dealloc
|
||||
{
|
||||
[channels release];
|
||||
[positionIndices release];
|
||||
[positions release];
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
|
||||
@end
|
@ -0,0 +1,16 @@
|
||||
//
|
||||
// IContentImporter.h
|
||||
// XNI
|
||||
//
|
||||
// Created by Matej Jan on 22.11.10.
|
||||
// Copyright 2010 Retronator. All rights reserved.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
|
||||
@protocol IContentImporter
|
||||
|
||||
- (id) importFile:(NSString*)filename;
|
||||
|
||||
@end
|
@ -0,0 +1,19 @@
|
||||
//
|
||||
// IContentProcessor.h
|
||||
// XNI
|
||||
//
|
||||
// Created by Matej Jan on 22.11.10.
|
||||
// Copyright 2010 Retronator. All rights reserved.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
|
||||
@protocol IContentProcessor
|
||||
|
||||
@property (nonatomic, readonly) Class inputType;
|
||||
@property (nonatomic, readonly) Class outputType;
|
||||
|
||||
- (id) process:(id)input;
|
||||
|
||||
@end
|
@ -0,0 +1,33 @@
|
||||
//
|
||||
// NamedValueDictionary.h
|
||||
// XNI
|
||||
//
|
||||
// Created by Matej Jan on 29.11.10.
|
||||
// Copyright 2010 Retronator. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
// #define NamedValueDictionary NamedValueDictionaryName
|
||||
// #define T DataType
|
||||
|
||||
@interface NamedValueDictionary : NSObject {
|
||||
NSMutableDictionary *dictionary;
|
||||
}
|
||||
|
||||
@property (nonatomic, readonly) int count;
|
||||
|
||||
- (T) itemForKey:(NSString*)key;
|
||||
- (void) set:(T)value forKey:(NSString*)key;
|
||||
|
||||
- (void) add:(T)value forKey:(NSString*)key;
|
||||
- (void) remove:(NSString*)key;
|
||||
|
||||
- (void) clear;
|
||||
|
||||
- (BOOL) containsKey:(NSString*)key;
|
||||
|
||||
@end
|
||||
|
||||
// #undef NamedValueDictionary
|
||||
// #undef T
|
@ -0,0 +1,64 @@
|
||||
//
|
||||
// NamedValueDictionary.m.h
|
||||
// XNI
|
||||
//
|
||||
// Created by Matej Jan on 29.11.10.
|
||||
// Copyright 2010 Retronator. All rights reserved.
|
||||
//
|
||||
|
||||
// #define NamedValueDictionary NamedValueDictionaryName
|
||||
// #define T DataType
|
||||
|
||||
@implementation NamedValueDictionary
|
||||
|
||||
- (id) init
|
||||
{
|
||||
self = [super init];
|
||||
if (self != nil) {
|
||||
dictionary = [[NSMutableDictionary alloc] init];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (int) count {
|
||||
return [dictionary count];
|
||||
}
|
||||
|
||||
- (T) itemForKey:(NSString*)key {
|
||||
return [dictionary objectForKey:key];
|
||||
}
|
||||
|
||||
- (void) set:(T)value forKey:(NSString*)key {
|
||||
if (value) {
|
||||
[dictionary setObject:value forKey:key];
|
||||
} else {
|
||||
[dictionary removeObjectForKey:key];
|
||||
}
|
||||
}
|
||||
|
||||
- (void) add:(T)value forKey:(NSString*)key {
|
||||
[dictionary setObject:value forKey:key];
|
||||
}
|
||||
|
||||
- (void) remove:(NSString*)key {
|
||||
[dictionary removeObjectForKey:key];
|
||||
}
|
||||
|
||||
- (void) clear {
|
||||
[dictionary removeAllObjects];
|
||||
}
|
||||
|
||||
- (BOOL) containsKey:(NSString*)key {
|
||||
return [dictionary objectForKey:key] != nil;
|
||||
}
|
||||
|
||||
- (void) dealloc
|
||||
{
|
||||
[dictionary release];
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
// #undef NamedValueDictionary
|
||||
// #undef T
|
@ -0,0 +1,17 @@
|
||||
//
|
||||
// OpaqueDataDictionary.h
|
||||
// XNI
|
||||
//
|
||||
// Created by Matej Jan on 29.11.10.
|
||||
// Copyright 2010 Retronator. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
#define NamedValueDictionary OpaqueDataDictionary
|
||||
#define T id
|
||||
|
||||
#include "NamedValueDictionary.h"
|
||||
|
||||
#undef NamedValueDictionary
|
||||
#undef T
|
@ -0,0 +1,17 @@
|
||||
//
|
||||
// OpaqueDataDictionary.m
|
||||
// XNI
|
||||
//
|
||||
// Created by Matej Jan on 29.11.10.
|
||||
// Copyright 2010 Retronator. All rights reserved.
|
||||
//
|
||||
|
||||
#import "OpaqueDataDictionary.h"
|
||||
|
||||
#define NamedValueDictionary OpaqueDataDictionary
|
||||
#define T id
|
||||
|
||||
#include "NamedValueDictionary.m.h"
|
||||
|
||||
#undef NamedValueDictionary
|
||||
#undef T
|
@ -1,3 +1,14 @@
|
||||
@class ContentIdentity, ContentItem;
|
||||
@class ChildCollection;
|
||||
|
||||
@class ContentIdentity, ContentItem;
|
||||
@class OpaqueDataDictionary;
|
||||
@class ExternalReference;
|
||||
|
||||
@protocol IContentImporter;
|
||||
@class ContentImporter;
|
||||
@class TextureImporter;
|
||||
@class XImporter;
|
||||
|
||||
@protocol IContentProcessor;
|
||||
@class ContentProcessor;
|
||||
|
||||
@class TextureImporter;
|
@ -1,4 +1,16 @@
|
||||
#import "ChildCollection.h"
|
||||
|
||||
#import "ContentIdentity.h"
|
||||
#import "ContentItem.h"
|
||||
|
||||
#import "TextureImporter.h"
|
||||
#import "OpaqueDataDictionary.h"
|
||||
|
||||
#import "ExternalReference.h"
|
||||
|
||||
#import "IContentImporter.h"
|
||||
#import "ContentImporter.h"
|
||||
#import "TextureImporter.h"
|
||||
#import "XImporter.h"
|
||||
|
||||
#import "IContentProcessor.h"
|
||||
#import "ContentProcessor.h"
|
@ -10,13 +10,14 @@
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
#import "Retronator.Xni.Framework.Graphics.h"
|
||||
#import "Retronator.Xni.Framework.Content.Pipeline.h"
|
||||
#import "Retronator.Xni.Framework.Content.Pipeline.Graphics.h"
|
||||
|
||||
@implementation TextureImporter
|
||||
|
||||
- (TextureContent*) importFile:(NSString*)filename {
|
||||
NSData *textureData = [[NSData alloc] initWithContentsOfFile:filename];
|
||||
UIImage *image = [[UIImage alloc] initWithData:textureData];
|
||||
NSData *textureData = [NSData dataWithContentsOfFile:filename];
|
||||
UIImage *image = [UIImage imageWithData:textureData];
|
||||
if (image == nil) {
|
||||
[NSException raise:@"InvalidArgumentException" format:@"The provided file is not a supported texture resource."];
|
||||
}
|
||||
@ -41,7 +42,7 @@
|
||||
CGContextRelease(textureContext);
|
||||
|
||||
// Create pixel bitmap content.
|
||||
PixelBitmapContent *bitmap = [[PixelBitmapContent alloc] initWithWidth:(int)width height:(int)height format:SurfaceFormatColor];
|
||||
PixelBitmapContent *bitmap = [[[PixelBitmapContent alloc] initWithWidth:(int)width height:(int)height format:SurfaceFormatColor] autorelease];
|
||||
[bitmap setPixelData:imageData];
|
||||
|
||||
// This bitmap is the only one in the mipmap chain.
|
||||
@ -49,7 +50,8 @@
|
||||
[mipmaps addObject:bitmap];
|
||||
|
||||
// Create the texture content.
|
||||
Texture2DContent *content = [[Texture2DContent alloc] init];
|
||||
Texture2DContent *content = [[[Texture2DContent alloc] init] autorelease];
|
||||
content.identity.sourceFilename = filename;
|
||||
content.mipmaps = mipmaps;
|
||||
|
||||
return content;
|
||||
|
@ -0,0 +1,17 @@
|
||||
//
|
||||
// XImporter.h
|
||||
// XNI
|
||||
//
|
||||
// Created by Matej Jan on 22.11.10.
|
||||
// Copyright 2010 Retronator. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
#import "ContentImporter.h"
|
||||
|
||||
@interface XImporter : ContentImporter {
|
||||
|
||||
}
|
||||
|
||||
@end
|
457
Classes/Retronator/Xni/Framework/Content/Pipeline/XImporter.m
Normal file
457
Classes/Retronator/Xni/Framework/Content/Pipeline/XImporter.m
Normal file
@ -0,0 +1,457 @@
|
||||
//
|
||||
// XImporter.m
|
||||
// XNI
|
||||
//
|
||||
// Created by Matej Jan on 22.11.10.
|
||||
// Copyright 2010 Retronator. All rights reserved.
|
||||
//
|
||||
|
||||
#import "XImporter.h"
|
||||
|
||||
#import "Retronator.Xni.Framework.h"
|
||||
#import "Retronator.Xni.Framework.Content.Pipeline.h"
|
||||
#import "Retronator.Xni.Framework.Content.Pipeline.Graphics.h"
|
||||
#import "XImporterReader.h"
|
||||
|
||||
@interface XImporter ()
|
||||
|
||||
- (void) readHeaderWithReader:(XImporterReader*)reader;
|
||||
- (void) readTemplatesWithReader:(XImporterReader*)reader;
|
||||
- (id) readTemplateWithReader:(XImporterReader*)reader;
|
||||
- (NodeContent*) readFrameTemplateWithReader:(XImporterReader*)reader;
|
||||
- (void) readFrameTransformMatrixTemplateWithReader:(XImporterReader*)reader;
|
||||
- (MeshContent*) readMeshTemplateWithReader:(XImporterReader*)reader;
|
||||
- (void) readMeshTextureCoordsTemplateWithReader:(XImporterReader*)reader;
|
||||
- (void) readMeshMaterialListTemplateWithReader:(XImporterReader*)reader;
|
||||
- (void) readMeshNormalsTemplateWithReader:(XImporterReader*)reader;
|
||||
- (MaterialContent*) readMaterialTemplateWithReader:(XImporterReader*)reader;
|
||||
- (void) readTextureFilenameTemplateWithReader:(XImporterReader*)reader;
|
||||
|
||||
- (Matrix*) readMatrix4x4TemplateWithReader:(XImporterReader*)reader;
|
||||
- (Vector3*) readVectorTemplateWithReader:(XImporterReader*)reader;
|
||||
- (NSArray*) readMeshFaceTemplateWithReader:(XImporterReader*)reader;
|
||||
- (Vector2*) readCoords2dTemplateWithReader:(XImporterReader*)reader;
|
||||
- (Vector4*) readColorRGBATemplateWithReader:(XImporterReader*)reader;
|
||||
- (Vector3*) readColorRGBTemplateWithReader:(XImporterReader*)reader;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@implementation XImporter
|
||||
|
||||
- (NodeContent *) importFile:(NSString *)filename {
|
||||
NSError *error = nil;
|
||||
NSString *input = [NSString stringWithContentsOfFile:filename encoding:NSUTF8StringEncoding error:&error];
|
||||
if (error) {
|
||||
NSLog(@"%@", filename);
|
||||
NSLog(@"%@", [error localizedDescription]);
|
||||
[NSException raise:@"InvalidArgumentException" format:@"Could not load file %@", filename];
|
||||
}
|
||||
XImporterReader *reader = [[[XImporterReader alloc] initWithInput:input] autorelease];
|
||||
reader.root.identity.sourceFilename = filename;
|
||||
|
||||
[self readHeaderWithReader:reader];
|
||||
[reader skipWhitespace];
|
||||
[self readTemplatesWithReader:reader];
|
||||
|
||||
return reader.root;
|
||||
}
|
||||
|
||||
- (void) readHeaderWithReader:(XImporterReader *)reader {
|
||||
[reader skipMany:17];
|
||||
}
|
||||
|
||||
- (void) readTemplatesWithReader:(XImporterReader *)reader {
|
||||
while ([reader isValid] && ![reader isAtClosingParanthesis]) {
|
||||
[self readTemplateWithReader:reader];
|
||||
[reader skipWhitespace];
|
||||
}
|
||||
}
|
||||
|
||||
- (id) readTemplateWithReader:(XImporterReader *)reader {
|
||||
id result = nil;
|
||||
NSString *name = nil;
|
||||
|
||||
if ([reader isAtOpeningParanthesis]) {
|
||||
// We are reading a named resource.
|
||||
[reader skipNextNonWhitespace];
|
||||
name = [reader readWord];
|
||||
[reader skipToClosingParanthesis];
|
||||
result = [reader.namedData objectForKey:name];
|
||||
} else {
|
||||
// We are reading a new template.
|
||||
NSString *template = [reader readWord];
|
||||
[reader skipWhitespace];
|
||||
if (![reader isAtOpeningParanthesis]) {
|
||||
name = [reader readWord];
|
||||
[reader skipToOpeningParanthesis];
|
||||
}
|
||||
[reader skipNextNonWhitespace];
|
||||
|
||||
// We are now at the first character of the content.
|
||||
if ([template isEqual:@"Frame"]) {
|
||||
NodeContent *frame = [self readFrameTemplateWithReader:reader];
|
||||
frame.name = name;
|
||||
} else if ([template isEqual:@"FrameTransformMatrix"]) {
|
||||
[self readFrameTransformMatrixTemplateWithReader:reader];
|
||||
} else if ([template isEqual:@"Mesh"]) {
|
||||
MeshContent *mesh = [self readMeshTemplateWithReader:reader];
|
||||
mesh.name = name;
|
||||
} else if ([template isEqual:@"MeshTextureCoords"]) {
|
||||
[self readMeshTextureCoordsTemplateWithReader:reader];
|
||||
} else if ([template isEqual:@"MeshMaterialList"]) {
|
||||
[self readMeshMaterialListTemplateWithReader:reader];
|
||||
} else if ([template isEqual:@"MeshNormals"]) {
|
||||
[self readMeshNormalsTemplateWithReader:reader];
|
||||
} else if ([template isEqual:@"Material"]) {
|
||||
MaterialContent *material = [self readMaterialTemplateWithReader:reader];
|
||||
material.name = name;
|
||||
result = material;
|
||||
} else if ([template isEqual:@"TextureFilename"]) {
|
||||
[self readTextureFilenameTemplateWithReader:reader];
|
||||
} else {
|
||||
// Unknown template, skip to closing parenthesis.
|
||||
[reader skipToClosingParanthesisForCurrentLevel];
|
||||
}
|
||||
}
|
||||
|
||||
[reader skipNextNonWhitespace];
|
||||
|
||||
if (name && result) {
|
||||
[reader.namedData setObject:result forKey:name];
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
template Frame {
|
||||
[...]
|
||||
}
|
||||
*/
|
||||
- (NodeContent *) readFrameTemplateWithReader:(XImporterReader *)reader {
|
||||
NodeContent *frame = [[[NodeContent alloc] init] autorelease];
|
||||
|
||||
NodeContent *parent = (NodeContent*)[reader currentContent];
|
||||
[parent.children add:frame];
|
||||
[reader pushContent:frame];
|
||||
|
||||
// Template is just a list of templates (usually FrameTransformMatrix and a Mesh)
|
||||
[self readTemplatesWithReader:reader];
|
||||
|
||||
[reader popContent];
|
||||
return frame;
|
||||
}
|
||||
|
||||
/*
|
||||
template FrameTransformMatrix {
|
||||
Matrix4x4 frameMatrix;
|
||||
}
|
||||
*/
|
||||
- (void) readFrameTransformMatrixTemplateWithReader:(XImporterReader *)reader {
|
||||
NodeContent *frame = (NodeContent*)[reader currentContent];
|
||||
|
||||
frame.transform = [self readMatrix4x4TemplateWithReader:reader];
|
||||
[reader skipNextNonWhitespace];
|
||||
}
|
||||
|
||||
/*
|
||||
template Mesh {
|
||||
DWORD nVertices;
|
||||
array Vector vertices[nVertices];
|
||||
DWORD nFaces;
|
||||
array MeshFace faces[nFaces];
|
||||
[...]
|
||||
}
|
||||
*/
|
||||
- (MeshContent *) readMeshTemplateWithReader:(XImporterReader *)reader {
|
||||
NodeContent *frame = (NodeContent*)[reader currentContent];
|
||||
|
||||
MeshContent *mesh = [[[MeshContent alloc] init] autorelease];
|
||||
[frame.children add:mesh];
|
||||
|
||||
[reader pushContent:mesh];
|
||||
|
||||
GeometryContent *geometry = [[[GeometryContent alloc] initWithPositions:mesh.positions] autorelease];
|
||||
[mesh.geometry add:geometry];
|
||||
|
||||
// Vertices
|
||||
int vertexCount = [reader readInt];
|
||||
[reader skipNextNonWhitespace];
|
||||
for (int i = 0; i < vertexCount; i++) {
|
||||
Vector3 *vertex = [self readVectorTemplateWithReader:reader];
|
||||
|
||||
// Change from left handed to right handed system.
|
||||
//vertex.z = -vertex.z;
|
||||
|
||||
[reader skipNextNonWhitespace];
|
||||
|
||||
[mesh.positions add:vertex];
|
||||
[geometry.vertices add:i];
|
||||
}
|
||||
|
||||
// Indices
|
||||
int indexCount = [reader readInt];
|
||||
[reader skipNextNonWhitespace];
|
||||
for (int i = 0; i < indexCount; i++) {
|
||||
NSMutableArray *indices = (NSMutableArray*)[self readMeshFaceTemplateWithReader:reader];
|
||||
[reader skipNextNonWhitespace];
|
||||
|
||||
// Swap two indices to change orientation since it was destroyed with handedness change.
|
||||
/*id tmp = [indices objectAtIndex:0];
|
||||
[indices replaceObjectAtIndex:0 withObject:[indices objectAtIndex:1]];
|
||||
[indices replaceObjectAtIndex:1 withObject:tmp];
|
||||
*/
|
||||
[geometry.indices addRange:indices];
|
||||
}
|
||||
|
||||
// Vertex channels
|
||||
[self readTemplatesWithReader:reader];
|
||||
|
||||
[reader popContent];
|
||||
return mesh;
|
||||
}
|
||||
|
||||
/*
|
||||
template MeshTextureCoords {
|
||||
DWORD nTextureCoords;
|
||||
array Coords2d textureCoords[nTextureCoords];
|
||||
}
|
||||
*/
|
||||
- (void) readMeshTextureCoordsTemplateWithReader:(XImporterReader *)reader {
|
||||
GeometryContent *geometry = [((MeshContent*)[reader currentContent]).geometry itemAt:0];
|
||||
|
||||
NSString *channelName = [VertexChannelNames textureCoordinateWithUsageIndex:0];
|
||||
|
||||
[geometry.vertices.channels addChannelWithName:channelName elementType:[Vector2 class] channelData:nil];
|
||||
VertexChannel *textureCoords = [geometry.vertices.channels itemWithName:channelName];
|
||||
|
||||
int coordsCount = [reader readInt];
|
||||
[reader skipNextNonWhitespace];
|
||||
for (int i = 0; i < coordsCount; i++) {
|
||||
Vector2 *coords = [self readCoords2dTemplateWithReader:reader];
|
||||
[reader skipNextNonWhitespace];
|
||||
|
||||
[textureCoords setItem:coords at:i];
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
template MeshMaterialList {
|
||||
DWORD nMaterials;
|
||||
DWORD nFaceIndexes;
|
||||
array DWORD faceIndexes[nFaceIndexes];
|
||||
[Material]
|
||||
}
|
||||
*/
|
||||
- (void) readMeshMaterialListTemplateWithReader:(XImporterReader *)reader {
|
||||
GeometryContent *geometry = [((MeshContent*)[reader currentContent]).geometry itemAt:0];
|
||||
|
||||
int materialCount = [reader readInt];
|
||||
[reader skipNextNonWhitespace];
|
||||
|
||||
int faceCount = [reader readInt];
|
||||
[reader skipNextNonWhitespace];
|
||||
|
||||
for (int i = 0; i < faceCount; i++) {
|
||||
/*int materialIndex =*/ [reader readInt];
|
||||
[reader skipNextNonWhitespace];
|
||||
}
|
||||
|
||||
for (int i = 0; i < materialCount; i++) {
|
||||
MaterialContent *material = [self readTemplateWithReader:reader];
|
||||
geometry.material = material;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
template MeshNormals {
|
||||
DWORD nNormals;
|
||||
array Vector normals[nNormals];
|
||||
DWORD nFaceNormals;
|
||||
array MeshFace faceNormals[nFaceNormals];
|
||||
}
|
||||
*/
|
||||
- (void) readMeshNormalsTemplateWithReader:(XImporterReader *)reader {
|
||||
GeometryContent *geometry = [((MeshContent*)[reader currentContent]).geometry itemAt:0];
|
||||
|
||||
PositionCollection *normals = [[[PositionCollection alloc] init] autorelease];
|
||||
|
||||
NSString *channelName = [VertexChannelNames normal];
|
||||
|
||||
[geometry.vertices.channels addChannelWithName:channelName elementType:[Vector3 class] channelData:nil];
|
||||
VertexChannel *normalChannel = [geometry.vertices.channels itemWithName:channelName];
|
||||
|
||||
int normalCount = [reader readInt];
|
||||
[reader skipNextNonWhitespace];
|
||||
for (int i = 0; i < normalCount; i++) {
|
||||
Vector3 *normal = [self readVectorTemplateWithReader:reader];
|
||||
[reader skipNextNonWhitespace];
|
||||
|
||||
[normals add:normal];
|
||||
}
|
||||
|
||||
int faceCount = [reader readInt];
|
||||
[reader skipNextNonWhitespace];
|
||||
for (int i = 0; i < faceCount; i++) {
|
||||
NSArray *indices = [self readMeshFaceTemplateWithReader:reader];
|
||||
[reader skipNextNonWhitespace];
|
||||
|
||||
for (int j = 0; j < [indices count]; j++) {
|
||||
int vertexIndex = [((NSNumber*)[geometry.indices itemAt:i*3+j]) intValue];
|
||||
int normalIndex = [((NSNumber*)[indices objectAtIndex:j]) intValue];
|
||||
|
||||
[normalChannel setItem:[normals itemAt:normalIndex] at:vertexIndex];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
template Material {
|
||||
ColorRGBA faceColor;
|
||||
FLOAT power;
|
||||
ColorRGB specularColor;
|
||||
ColorRGB emissiveColor;
|
||||
[...]
|
||||
}
|
||||
*/
|
||||
- (MaterialContent *) readMaterialTemplateWithReader:(XImporterReader *)reader {
|
||||
BasicMaterialContent *material = [[BasicMaterialContent alloc] init];
|
||||
|
||||
[reader pushContent:material];
|
||||
|
||||
Vector4 *faceColor = [self readColorRGBATemplateWithReader:reader];
|
||||
[reader skipNextNonWhitespace];
|
||||
float power = [reader readFloat];
|
||||
[reader skipNextNonWhitespace];
|
||||
Vector3 *specularColor = [self readColorRGBTemplateWithReader:reader];
|
||||
[reader skipNextNonWhitespace];
|
||||
Vector3 *emissiveColor = [self readColorRGBTemplateWithReader:reader];
|
||||
[reader skipNextNonWhitespace];
|
||||
|
||||
material.diffuseColor = [Vector3 vectorWithX:faceColor.x y:faceColor.y z:faceColor.z];
|
||||
material.alpha = [NSNumber numberWithFloat:faceColor.w];
|
||||
material.specularPower = [NSNumber numberWithFloat:power];
|
||||
material.specularColor = specularColor;
|
||||
material.emissiveColor = emissiveColor;
|
||||
|
||||
[self readTemplatesWithReader:reader];
|
||||
|
||||
[reader popContent];
|
||||
return material;
|
||||
}
|
||||
|
||||
/*
|
||||
template TextureFilename {
|
||||
STRING filename;
|
||||
}
|
||||
*/
|
||||
- (void) readTextureFilenameTemplateWithReader:(XImporterReader *)reader {
|
||||
BasicMaterialContent *material = (BasicMaterialContent*)[reader currentContent];
|
||||
|
||||
NSString *filename = [reader readQuotedWord];
|
||||
ExternalReference *texture = [[[ExternalReference alloc] initWithFilename:filename relativeToContent:reader.root.identity] autorelease];
|
||||
|
||||
material.texture = texture;
|
||||
|
||||
[reader skipNextNonWhitespace];
|
||||
}
|
||||
|
||||
/*
|
||||
template Matrix4x4 {
|
||||
array FLOAT matrix[16];
|
||||
}
|
||||
*/
|
||||
- (Matrix *) readMatrix4x4TemplateWithReader:(XImporterReader *)reader {
|
||||
MatrixStruct data;
|
||||
for (int i = 0; i < 16; i++) {
|
||||
((float*)&data)[i] = [reader readFloat];
|
||||
[reader skipNextNonWhitespace];
|
||||
}
|
||||
return [Matrix matrixWithStruct:&data];
|
||||
}
|
||||
|
||||
/*
|
||||
template Vector {
|
||||
FLOAT x;
|
||||
FLOAT y;
|
||||
FLOAT z;
|
||||
}
|
||||
*/
|
||||
- (Vector3 *) readVectorTemplateWithReader:(XImporterReader *)reader {
|
||||
Vector3Struct data;
|
||||
for (int i = 0; i < 3; i++) {
|
||||
((float*)&data)[i] = [reader readFloat];
|
||||
[reader skipNextNonWhitespace];
|
||||
}
|
||||
return [Vector3 vectorWithStruct:&data];
|
||||
}
|
||||
|
||||
/*
|
||||
template MeshFace {
|
||||
DWORD nFaceVertexIndices;
|
||||
array DWORD faceVertexIndices[nFaceVertexIndices];
|
||||
}
|
||||
*/
|
||||
- (NSArray*) readMeshFaceTemplateWithReader:(XImporterReader*)reader {
|
||||
NSMutableArray *indices = [NSMutableArray array];
|
||||
int count = [reader readInt];
|
||||
[reader skipNextNonWhitespace];
|
||||
for (int i = 0; i < count; i++) {
|
||||
[indices addObject:[NSNumber numberWithInt:[reader readInt]]];
|
||||
[reader skipNextNonWhitespace];
|
||||
}
|
||||
return indices;
|
||||
}
|
||||
|
||||
/*
|
||||
template Coords2d {
|
||||
FLOAT u;
|
||||
FLOAT v;
|
||||
}
|
||||
*/
|
||||
- (Vector2*) readCoords2dTemplateWithReader:(XImporterReader*)reader {
|
||||
Vector2Struct data;
|
||||
for (int i = 0; i < 2; i++) {
|
||||
((float*)&data)[i] = [reader readFloat];
|
||||
[reader skipNextNonWhitespace];
|
||||
}
|
||||
return [Vector2 vectorWithStruct:&data];
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
template ColorRGBA {
|
||||
FLOAT red;
|
||||
FLOAT green;
|
||||
FLOAT blue;
|
||||
FLOAT alpha;
|
||||
}
|
||||
*/
|
||||
- (Vector4 *) readColorRGBATemplateWithReader:(XImporterReader *)reader {
|
||||
Vector4Struct data;
|
||||
for (int i = 0; i < 4; i++) {
|
||||
((float*)&data)[i] = [reader readFloat];
|
||||
[reader skipNextNonWhitespace];
|
||||
}
|
||||
return [Vector4 vectorWithStruct:&data];
|
||||
}
|
||||
|
||||
/*
|
||||
template ColorRGB {
|
||||
<D3E16E81-7835-11cf-8F52-0040333594A3>
|
||||
FLOAT red;
|
||||
FLOAT green;
|
||||
FLOAT blue;
|
||||
}
|
||||
*/
|
||||
- (Vector3 *) readColorRGBTemplateWithReader:(XImporterReader *)reader {
|
||||
Vector3Struct data;
|
||||
for (int i = 0; i < 3; i++) {
|
||||
((float*)&data)[i] = [reader readFloat];
|
||||
[reader skipNextNonWhitespace];
|
||||
}
|
||||
return [Vector3 vectorWithStruct:&data];
|
||||
}
|
||||
|
||||
@end
|
@ -0,0 +1,51 @@
|
||||
//
|
||||
// XImporterReader.h
|
||||
// XNI
|
||||
//
|
||||
// Created by Matej Jan on 28.11.10.
|
||||
// Copyright 2010 Retronator. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
#import "Retronator.Xni.Framework.classes.h"
|
||||
#import "Retronator.Xni.Framework.Content.Pipeline.classes.h"
|
||||
#import "Retronator.Xni.Framework.Content.Pipeline.Graphics.classes.h"
|
||||
|
||||
@interface XImporterReader : NSObject
|
||||
{
|
||||
NSString *input;
|
||||
int inputPosition;
|
||||
NodeContent *root;
|
||||
NSMutableArray *contentStack;
|
||||
NSMutableDictionary *namedData;
|
||||
}
|
||||
|
||||
- (id) initWithInput:(NSString*)theInput;
|
||||
|
||||
@property (nonatomic, readonly) NodeContent *root;
|
||||
@property (nonatomic, readonly) NSMutableDictionary *namedData;
|
||||
@property (nonatomic, readonly) BOOL isValid;
|
||||
|
||||
- (ContentItem*) currentContent;
|
||||
- (void) pushContent:(ContentItem*)content;
|
||||
- (void) popContent;
|
||||
|
||||
- (unichar) currentCharacter;
|
||||
- (void) skip;
|
||||
- (void) skipMany:(int)count;
|
||||
- (void) skipToCharacter:(unichar)character;
|
||||
- (void) skipWhitespace;
|
||||
- (void) skipToWhitespace;
|
||||
- (void) skipNextNonWhitespace;
|
||||
- (BOOL) isAtOpeningParanthesis;
|
||||
- (BOOL) isAtClosingParanthesis;
|
||||
- (void) skipToOpeningParanthesis;
|
||||
- (void) skipToClosingParanthesis;
|
||||
- (void) skipToClosingParanthesisForCurrentLevel;
|
||||
- (NSString*) readWord;
|
||||
- (NSString*) readQuotedWord;
|
||||
- (float) readFloat;
|
||||
- (float) readInt;
|
||||
|
||||
@end
|
@ -0,0 +1,170 @@
|
||||
//
|
||||
// XImporterReader.m
|
||||
// XNI
|
||||
//
|
||||
// Created by Matej Jan on 28.11.10.
|
||||
// Copyright 2010 Retronator. All rights reserved.
|
||||
//
|
||||
|
||||
#import "XImporterReader.h"
|
||||
|
||||
#import "Retronator.Xni.Framework.h"
|
||||
#import "Retronator.Xni.Framework.Content.Pipeline.Graphics.h"
|
||||
|
||||
@implementation XImporterReader
|
||||
|
||||
static NSCharacterSet *numberCharacterSet;
|
||||
|
||||
- (id) initWithInput:(NSString *)theInput
|
||||
{
|
||||
self = [super init];
|
||||
if (self != nil) {
|
||||
input = [theInput retain];
|
||||
contentStack = [[NSMutableArray alloc] init];
|
||||
root = [[NodeContent alloc] init];
|
||||
[contentStack addObject:root];
|
||||
namedData = [[NSMutableDictionary alloc] init];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
+ (void) initialize {
|
||||
numberCharacterSet = [[NSCharacterSet characterSetWithCharactersInString:@"0123456789.-"] retain];
|
||||
}
|
||||
|
||||
@synthesize root, namedData;
|
||||
|
||||
- (BOOL) isValid {
|
||||
return inputPosition < [input length];
|
||||
}
|
||||
|
||||
|
||||
- (ContentItem *) currentContent {
|
||||
return [contentStack lastObject];
|
||||
}
|
||||
|
||||
- (void) pushContent:(ContentItem *)content {
|
||||
[contentStack addObject:content];
|
||||
}
|
||||
|
||||
- (void) popContent {
|
||||
[contentStack removeLastObject];
|
||||
}
|
||||
|
||||
|
||||
- (unichar) currentCharacter {
|
||||
return [input characterAtIndex:inputPosition];
|
||||
}
|
||||
|
||||
- (void) skip {
|
||||
inputPosition++;
|
||||
}
|
||||
|
||||
- (void) skipMany:(int)count {
|
||||
inputPosition+=count;
|
||||
}
|
||||
|
||||
- (void) skipToCharacter:(unichar)character {
|
||||
while ([self isValid] && [self currentCharacter] != character) {
|
||||
inputPosition++;
|
||||
}
|
||||
}
|
||||
|
||||
- (void) skipWhitespace {
|
||||
while ([self isValid] && [[NSCharacterSet whitespaceAndNewlineCharacterSet] characterIsMember:[self currentCharacter]]) {
|
||||
inputPosition++;
|
||||
}
|
||||
}
|
||||
|
||||
- (void) skipToWhitespace {
|
||||
while ([self isValid] && ![[NSCharacterSet whitespaceAndNewlineCharacterSet] characterIsMember:[self currentCharacter]]) {
|
||||
inputPosition++;
|
||||
}
|
||||
}
|
||||
|
||||
- (void) skipNextNonWhitespace {
|
||||
[self skipWhitespace];
|
||||
[self skip];
|
||||
[self skipWhitespace];
|
||||
}
|
||||
|
||||
- (BOOL) isAtOpeningParanthesis {
|
||||
return [self currentCharacter] == '{';
|
||||
}
|
||||
|
||||
- (BOOL) isAtClosingParanthesis {
|
||||
return [self currentCharacter] == '}';
|
||||
}
|
||||
|
||||
- (void) skipToOpeningParanthesis {
|
||||
[self skipToCharacter:'{'];
|
||||
}
|
||||
|
||||
|
||||
- (void) skipToClosingParanthesis {
|
||||
[self skipToCharacter:'}'];
|
||||
}
|
||||
|
||||
- (void) skipToClosingParanthesisForCurrentLevel {
|
||||
int level = 1;
|
||||
while ([self isValid]) {
|
||||
if ([self isAtOpeningParanthesis]) {
|
||||
level++;
|
||||
} else if ([self isAtClosingParanthesis]) {
|
||||
level--;
|
||||
if (level == 0) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
inputPosition++;
|
||||
}
|
||||
}
|
||||
|
||||
- (NSString *) readWord {
|
||||
NSRange range;
|
||||
range.location = inputPosition;
|
||||
[self skipToWhitespace];
|
||||
range.length = inputPosition-range.location;
|
||||
return [input substringWithRange:range];
|
||||
}
|
||||
|
||||
- (NSString *) readQuotedWord {
|
||||
NSRange range;
|
||||
[self skipToCharacter:'"'];
|
||||
[self skip];
|
||||
range.location = inputPosition;
|
||||
[self skipToCharacter:'"'];
|
||||
range.length = inputPosition-range.location;
|
||||
[self skip];
|
||||
return [input substringWithRange:range];
|
||||
}
|
||||
|
||||
- (float) readFloat {
|
||||
NSRange range;
|
||||
range.location = inputPosition;
|
||||
while ([self isValid] && [numberCharacterSet characterIsMember:[self currentCharacter]]) {
|
||||
inputPosition++;
|
||||
}
|
||||
range.length = inputPosition-range.location;
|
||||
return [[input substringWithRange:range] floatValue];
|
||||
}
|
||||
|
||||
- (float) readInt {
|
||||
NSRange range;
|
||||
range.location = inputPosition;
|
||||
while ([self isValid] && [numberCharacterSet characterIsMember:[self currentCharacter]]) {
|
||||
inputPosition++;
|
||||
}
|
||||
range.length = inputPosition-range.location;
|
||||
return [[input substringWithRange:range] intValue];
|
||||
}
|
||||
|
||||
- (void) dealloc
|
||||
{
|
||||
[input release];
|
||||
[contentStack release];
|
||||
[namedData release];
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
@end
|
@ -1,3 +1,6 @@
|
||||
@class ContentManager, ContentReader, ContentTypeReaderManager;
|
||||
@class ContentManager, ContentReader, ContentTypeReaderManager, ContentTypeReader;
|
||||
|
||||
@class ContentTypeReader, Texture2DContentTypeReader;
|
||||
@class Texture2DReader;
|
||||
@class ModelReader, ModelMeshReader, ModelMeshPartReader;
|
||||
@class BasicEffectReader, IndexBufferReader, VertexBufferReader;
|
||||
@class ModelBoneReader, VertexDeclarationReader;
|
@ -1,6 +1,17 @@
|
||||
#import "ContentManager.h"
|
||||
#import "ContentReader.h"
|
||||
#import "ContentTypeReaderManager.h"
|
||||
|
||||
#import "ContentTypeReader.h"
|
||||
#import "Texture2DContentTypeReader.h"
|
||||
|
||||
#import "Texture2DReader.h"
|
||||
|
||||
#import "ModelReader.h"
|
||||
#import "ModelMeshReader.h"
|
||||
#import "ModelMeshPartReader.h"
|
||||
|
||||
#import "BasicEffectReader.h"
|
||||
#import "IndexBufferReader.h"
|
||||
#import "VertexBufferReader.h"
|
||||
|
||||
#import "ModelBoneReader.h"
|
||||
#import "VertexDeclarationReader.h"
|
@ -10,7 +10,7 @@
|
||||
|
||||
#import "ContentTypeReader.h"
|
||||
|
||||
@interface Texture2DContentTypeReader : ContentTypeReader {
|
||||
@interface Texture2DReader : ContentTypeReader {
|
||||
|
||||
}
|
||||
|
@ -6,13 +6,13 @@
|
||||
// Copyright 2010 Retronator. All rights reserved.
|
||||
//
|
||||
|
||||
#import "Texture2DContentTypeReader.h"
|
||||
#import "Texture2DReader.h"
|
||||
|
||||
#import "Retronator.Xni.Framework.Content.h"
|
||||
#import "Retronator.Xni.Framework.Content.Pipeline.Graphics.h"
|
||||
#import "Retronator.Xni.Framework.Graphics.h"
|
||||
|
||||
@implementation Texture2DContentTypeReader
|
||||
@implementation Texture2DReader
|
||||
|
||||
- (id) readFromInput:(ContentReader *)input into:(id)existingInstance {
|
||||
Texture2DContent *content = input.content;
|
||||
@ -24,11 +24,11 @@
|
||||
SurfaceFormat format;
|
||||
[bitmap tryGetFormat:&format];
|
||||
|
||||
Texture2D *texture = [[Texture2D alloc] initWithGraphicsDevice:graphicsDevice
|
||||
Texture2D *texture = [[[Texture2D alloc] initWithGraphicsDevice:graphicsDevice
|
||||
width:bitmap.width
|
||||
height:bitmap.height
|
||||
mipMaps:generateMipmaps
|
||||
format:format];
|
||||
format:format] autorelease];
|
||||
|
||||
for (int i=0;i<[mipmaps count];i++) {
|
||||
bitmap = [mipmaps objectAtIndex:i];
|
@ -0,0 +1,17 @@
|
||||
//
|
||||
// VertexBufferReader.h
|
||||
// XNI
|
||||
//
|
||||
// Created by Matej Jan on 23.11.10.
|
||||
// Copyright 2010 Retronator. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
#import "ContentTypeReader.h"
|
||||
|
||||
@interface VertexBufferReader : ContentTypeReader {
|
||||
|
||||
}
|
||||
|
||||
@end
|
@ -0,0 +1,36 @@
|
||||
//
|
||||
// VertexBufferReader.m
|
||||
// XNI
|
||||
//
|
||||
// Created by Matej Jan on 23.11.10.
|
||||
// Copyright 2010 Retronator. All rights reserved.
|
||||
//
|
||||
|
||||
#import "VertexBufferReader.h"
|
||||
|
||||
#import "Retronator.Xni.Framework.Content.h"
|
||||
#import "Retronator.Xni.Framework.Graphics.h"
|
||||
#import "Retronator.Xni.Framework.Content.Pipeline.Processors.h"
|
||||
|
||||
#import "GraphicsDevice+Internal.h"
|
||||
|
||||
@implementation VertexBufferReader
|
||||
|
||||
- (id) readFromInput:(ContentReader *)input into:(id)existingInstance {
|
||||
VertexBufferContent *content = input.content;
|
||||
GraphicsDevice *graphicsDevice = [[input.contentManager.serviceProvider getServiceOfType:@protocol(IGraphicsDeviceService)] graphicsDevice];
|
||||
|
||||
VertexDeclaration *vertexDeclaration = [input readObjectFrom:content.vertexDeclaration];
|
||||
|
||||
int vertexCount = [content.vertexData length] / vertexDeclaration.vertexStride;
|
||||
|
||||
VertexBuffer *buffer = [[[VertexBuffer alloc] initWithGraphicsDevice:graphicsDevice
|
||||
vertexDeclaration:vertexDeclaration
|
||||
vertexCount:vertexCount usage:BufferUsageWriteOnly] autorelease];
|
||||
|
||||
[graphicsDevice setData:(void*)[content.vertexData bytes] toVertexBuffer:buffer];
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
@end
|
@ -0,0 +1,17 @@
|
||||
//
|
||||
// VertexDeclarationReader.h
|
||||
// XNI
|
||||
//
|
||||
// Created by Matej Jan on 29.11.10.
|
||||
// Copyright 2010 Retronator. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
#import "ContentTypeReader.h"
|
||||
|
||||
@interface VertexDeclarationReader : ContentTypeReader {
|
||||
|
||||
}
|
||||
|
||||
@end
|
@ -0,0 +1,25 @@
|
||||
//
|
||||
// VertexDeclarationReader.m
|
||||
// XNI
|
||||
//
|
||||
// Created by Matej Jan on 29.11.10.
|
||||
// Copyright 2010 Retronator. All rights reserved.
|
||||
//
|
||||
|
||||
#import "VertexDeclarationReader.h"
|
||||
|
||||
#import "Retronator.Xni.Framework.Content.h"
|
||||
#import "Retronator.Xni.Framework.Graphics.h"
|
||||
#import "Retronator.Xni.Framework.Content.Pipeline.Processors.h"
|
||||
|
||||
@implementation VertexDeclarationReader
|
||||
|
||||
- (id) readFromInput:(ContentReader *)input into:(id)existingInstance {
|
||||
VertexDeclarationContent *content = input.content;
|
||||
|
||||
VertexDeclaration *vertexDeclaration = [[[VertexDeclaration alloc] initWithElements:content.vertexElements] autorelease];
|
||||
|
||||
return vertexDeclaration;
|
||||
}
|
||||
|
||||
@end
|
@ -16,8 +16,8 @@
|
||||
|
||||
@implementation Game
|
||||
|
||||
NSArray *updateOrderSort;
|
||||
NSArray *drawOrderSort;
|
||||
static NSArray *updateOrderSort;
|
||||
static NSArray *drawOrderSort;
|
||||
|
||||
+ (void) initialize {
|
||||
NSSortDescriptor *updateOrderSortDescriptor = [[[NSSortDescriptor alloc] initWithKey:@"updateOrder" ascending:YES] autorelease];
|
||||
|
@ -24,13 +24,13 @@
|
||||
-(id) initWithGraphicsDevice:(GraphicsDevice *)theGraphicsDevice {
|
||||
if (self = [super initWithGraphicsDevice:theGraphicsDevice]) {
|
||||
// Create the main pass.
|
||||
BasicEffectPass *mainPass = [[BasicEffectPass alloc] initWithBasicEffect:self graphicsDevice:graphicsDevice];
|
||||
BasicEffectPass *mainPass = [[[BasicEffectPass alloc] initWithBasicEffect:self graphicsDevice:graphicsDevice] autorelease];
|
||||
NSArray *passes = [NSArray arrayWithObject:mainPass];
|
||||
|
||||
// Create the basic technique.
|
||||
EffectTechnique *basicTechnique = [[EffectTechnique alloc] initWithName:@"BasicEffect" passes:passes];
|
||||
EffectTechnique *basicTechnique = [[[EffectTechnique alloc] initWithName:@"BasicEffect" passes:passes] autorelease];
|
||||
|
||||
techniques = [NSDictionary dictionaryWithObject:basicTechnique forKey:basicTechnique.name];
|
||||
techniques = [[NSDictionary alloc] initWithObjectsAndKeys:basicTechnique, basicTechnique.name, nil];
|
||||
currentTechnique = basicTechnique;
|
||||
|
||||
// Set defaults.
|
||||
@ -104,6 +104,7 @@
|
||||
[world release];
|
||||
[view release];
|
||||
[projection release];
|
||||
[techniques release];
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,26 @@
|
||||
//
|
||||
// GraphicsDevice+Internal.h
|
||||
// XNI
|
||||
//
|
||||
// Created by Matej Jan on 29.11.10.
|
||||
// Copyright 2010 Retronator. All rights reserved.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
#import "GraphicsDevice.h"
|
||||
|
||||
@interface GraphicsDevice (Internal)
|
||||
|
||||
- (uint) createTexture;
|
||||
//- (void) getData:(void*)data fromTexture2D:(Texture2D*)texture level:(int)level;
|
||||
- (void) setData:(void*)data toTexture2D:(Texture2D*)texture SourceRectangle:(Rectangle*)rect level:(int)level;
|
||||
|
||||
- (uint) createBuffer;
|
||||
- (void) setData:(void*)data toIndexBuffer:(IndexBuffer*)buffer;
|
||||
- (void) setData:(void*)data toVertexBuffer:(VertexBuffer*)buffer;
|
||||
|
||||
// Profile specific
|
||||
- (EAGLContext*) createContext;
|
||||
|
||||
@end
|
@ -79,32 +79,46 @@
|
||||
- (void) setVertexBuffers:(VertexBufferBinding*)vertexBuffer, ... NS_REQUIRES_NIL_TERMINATION;
|
||||
|
||||
// Drawing
|
||||
- (void) drawPrimitivesOfType:(PrimitiveType)primitiveType startingAt:(int)startVertex count:(int)primitiveCount;
|
||||
|
||||
- (void) drawIndexedPrimitivesOfType:(PrimitiveType)primitiveType offsetVerticesBy:(int)baseVertex
|
||||
startingAt:(int)startIndex count:(int)primitiveCount;
|
||||
// From buffers
|
||||
- (void) drawPrimitivesOfType:(PrimitiveType)primitiveType
|
||||
startVertex:(int)startVertex
|
||||
primitiveCount:(int)primitiveCount;
|
||||
|
||||
- (void) drawUserPrimitivesOfType:(PrimitiveType)primitiveType vertices:(VertexArray*)vertexData
|
||||
startingAt:(int)vertexOffset count:(int)primitiveCount;
|
||||
- (void) drawIndexedPrimitivesOfType:(PrimitiveType)primitiveType
|
||||
baseVertex:(int)baseVertex
|
||||
minVertexIndex:(int)minVertexIndex
|
||||
numVertices:(int)numVertices
|
||||
startIndex:(int)startIndex
|
||||
primitiveCount:(int)primitiveCount;
|
||||
|
||||
// From arrays
|
||||
- (void) drawUserPrimitivesOfType:(PrimitiveType)primitiveType
|
||||
vertexData:(VertexArray*)vertexData
|
||||
vertexOffset:(int)vertexOffset
|
||||
primitiveCount:(int)primitiveCount;
|
||||
|
||||
- (void) drawUserPrimitivesOfType:(PrimitiveType)primitiveType
|
||||
vertices:(void*)vertexData ofType:(VertexDeclaration*) vertexDeclaration
|
||||
startingAt:(int)vertexOffset count:(int)primitiveCount;
|
||||
vertexData:(void*)vertexData
|
||||
vertexOffset:(int)vertexOffset
|
||||
primitiveCount:(int)primitiveCount
|
||||
vertexDeclaration:(VertexDeclaration*) vertexDeclaration;
|
||||
|
||||
- (void) drawUserIndexedPrimitivesOfType:(PrimitiveType)primitiveType
|
||||
vertices:(void*)vertexData ofType:(VertexDeclaration*) vertexDeclaration
|
||||
offsetVerticesBy:(int)vertexOffset indices:(void*)indexData dataType:(DataType)dataType
|
||||
startingAt:(int)indexOffset count:(int)primitiveCount;
|
||||
vertexData:(VertexArray*)vertexData
|
||||
vertexOffset:(int)vertexOffset
|
||||
numVertices:(int)numVertices
|
||||
indexData:(IndexArray*)indexData
|
||||
indexOffset:(int)indexOffset
|
||||
primitiveCount:(int)primitiveCount;
|
||||
|
||||
|
||||
// Low level methods
|
||||
- (uint) createTexture;
|
||||
|
||||
//- (void) getData:(void*)data fromTexture2D:(Texture2D*)texture level:(int)level;
|
||||
|
||||
- (void) setData:(void*)data toTexture2D:(Texture2D*)texture SourceRectangle:(Rectangle*)rect level:(int)level;
|
||||
|
||||
// Profile specific
|
||||
- (EAGLContext*) createContext;
|
||||
- (void) drawUserIndexedPrimitivesOfType:(PrimitiveType)primitiveType
|
||||
vertexData:(void*)vertexData
|
||||
vertexOffset:(int)vertexOffset
|
||||
numVertices:(int)numVertices
|
||||
shortIndexData:(void*)indexData
|
||||
indexOffset:(int)indexOffset
|
||||
primitiveCount:(int)primitiveCount
|
||||
vertexDeclaration:(VertexDeclaration*) vertexDeclaration;
|
||||
|
||||
@end
|
||||
|
@ -7,6 +7,7 @@
|
||||
//
|
||||
|
||||
#import "GraphicsDevice.h"
|
||||
#import "GraphicsDevice+Internal.h"
|
||||
#import <OpenGLES/ES1/gl.h>
|
||||
|
||||
#import "Retronator.Xni.Framework.h"
|
||||
@ -15,10 +16,13 @@
|
||||
#import "XniSamplerEventArgs.h"
|
||||
#import "TextureCollection+Internal.h"
|
||||
#import "SamplerStateCollection+Internal.h"
|
||||
#import "IndexBuffer+Internal.h"
|
||||
#import "VertexBuffer+Internal.h"
|
||||
|
||||
@interface GraphicsDevice()
|
||||
|
||||
+ (void) getFormat:(GLenum*)format AndType:(GLenum*)type ForSurfaceFormat:(SurfaceFormat)surfaceFormat;
|
||||
- (void) setData:(void*)data size:(int)sizeInBytes toBufferId:(uint)buffer resourceType:(ResourceType)resourceType bufferUsage:(BufferUsage)bufferUsage;
|
||||
|
||||
@end
|
||||
|
||||
@ -70,13 +74,15 @@
|
||||
self.depthStencilState = [DepthStencilState defaultDepth];
|
||||
graphicsDeviceStatus = GraphicsDeviceStatusNormal;
|
||||
self.indices = nil;
|
||||
self.rasterizerState = [RasterizerState cullClockwise];
|
||||
self.rasterizerState = [RasterizerState cullCounterClockwise];
|
||||
self.referenceStencil = 0;
|
||||
[samplerStates setItem:[SamplerState linearClamp] atIndex:0];
|
||||
|
||||
// Create events.
|
||||
deviceResetting = [[Event alloc] init];
|
||||
deviceReset = [[Event alloc] init];
|
||||
|
||||
vertices = [[NSMutableArray alloc] init];
|
||||
}
|
||||
|
||||
return self;
|
||||
@ -124,6 +130,16 @@
|
||||
[value retain];
|
||||
[rasterizerState release];
|
||||
rasterizerState = value;
|
||||
|
||||
// Apply fill mode.
|
||||
|
||||
// Apply cull mode.
|
||||
if (value.cullMode == CullModeNone) {
|
||||
glDisable(GL_CULL_FACE);
|
||||
} else {
|
||||
glEnable(GL_CULL_FACE);
|
||||
glFrontFace(value.cullMode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -207,12 +223,16 @@
|
||||
|
||||
// Vertex buffers
|
||||
- (NSArray*) getVertexBuffers {
|
||||
return [[NSArray arrayWithArray:vertices] autorelease];
|
||||
return [NSArray arrayWithArray:vertices];
|
||||
}
|
||||
|
||||
- (void) setVertexBuffer:(VertexBuffer*)vertexBuffer {
|
||||
VertexBufferBinding *binding = [[VertexBufferBinding alloc] initWithVertexBuffer:vertexBuffer];
|
||||
[vertices insertObject:binding atIndex:0];
|
||||
if ([vertices count]>0) {
|
||||
[vertices replaceObjectAtIndex:0 withObject:binding];
|
||||
} else {
|
||||
[vertices addObject:binding];
|
||||
}
|
||||
[binding release];
|
||||
}
|
||||
|
||||
@ -262,28 +282,76 @@
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
}
|
||||
|
||||
- (uint) createBuffer {
|
||||
GLuint bufferId;
|
||||
glGenBuffers(1, &bufferId);
|
||||
return bufferId;
|
||||
}
|
||||
|
||||
- (void) setData:(void*)data toIndexBuffer:(IndexBuffer*)buffer {
|
||||
int sizeInBytes = buffer.indexElementSize * buffer.indexCount;
|
||||
[self setData:data size:sizeInBytes toBufferId:buffer.bufferID resourceType:ResourceTypeIndexBuffer bufferUsage:buffer.bufferUsage];
|
||||
}
|
||||
|
||||
- (void) setData:(void*)data toVertexBuffer:(VertexBuffer*)buffer {
|
||||
int sizeInBytes = buffer.vertexDeclaration.vertexStride * buffer.vertexCount;
|
||||
[self setData:data size:sizeInBytes toBufferId:buffer.bufferID resourceType:ResourceTypeVertexBuffer bufferUsage:buffer.bufferUsage];
|
||||
}
|
||||
|
||||
- (void) setData:(void *)data
|
||||
size:(int)sizeInBytes
|
||||
toBufferId:(uint)buffer
|
||||
resourceType:(ResourceType)resourceType
|
||||
bufferUsage:(BufferUsage)bufferUsage
|
||||
{
|
||||
glBindBuffer(resourceType, buffer);
|
||||
glBufferData(resourceType, sizeInBytes, data, bufferUsage);
|
||||
glBindBuffer(resourceType, 0);
|
||||
}
|
||||
|
||||
|
||||
// Profile specific
|
||||
|
||||
- (EAGLContext*) createContext { return nil; }
|
||||
|
||||
- (void) drawPrimitivesOfType:(PrimitiveType)primitiveType startingAt:(int)startVertex count:(int)primitiveCount {}
|
||||
- (void) drawPrimitivesOfType:(PrimitiveType)primitiveType
|
||||
startVertex:(int)startVertex
|
||||
primitiveCount:(int)primitiveCount {}
|
||||
|
||||
- (void) drawIndexedPrimitivesOfType:(PrimitiveType)primitiveType offsetVerticesBy:(int)baseVertex
|
||||
startingAt:(int)startIndex count:(int)primitiveCount {}
|
||||
|
||||
- (void) drawUserPrimitivesOfType:(PrimitiveType)primitiveType vertices:(VertexArray*)vertexData
|
||||
startingAt:(int)vertexOffset count:(int)primitiveCount {}
|
||||
- (void) drawIndexedPrimitivesOfType:(PrimitiveType)primitiveType
|
||||
baseVertex:(int)baseVertex
|
||||
minVertexIndex:(int)minVertexIndex
|
||||
numVertices:(int)numVertices
|
||||
startIndex:(int)startIndex
|
||||
primitiveCount:(int)primitiveCount {}
|
||||
|
||||
- (void) drawUserPrimitivesOfType:(PrimitiveType)primitiveType
|
||||
vertices:(void*)vertexData ofType:(VertexDeclaration*) vertexDeclaration
|
||||
startingAt:(int)vertexOffset count:(int)primitiveCount {}
|
||||
vertexData:(VertexArray*)vertexData
|
||||
vertexOffset:(int)vertexOffset
|
||||
primitiveCount:(int)primitiveCount {}
|
||||
|
||||
- (void) drawUserPrimitivesOfType:(PrimitiveType)primitiveType
|
||||
vertexData:(void*)vertexData
|
||||
vertexOffset:(int)vertexOffset
|
||||
primitiveCount:(int)primitiveCount
|
||||
vertexDeclaration:(VertexDeclaration*) vertexDeclaration {}
|
||||
|
||||
- (void) drawUserIndexedPrimitivesOfType:(PrimitiveType)primitiveType
|
||||
vertices:(void*)vertexData ofType:(VertexDeclaration*) vertexDeclaration
|
||||
offsetVerticesBy:(int)vertexOffset indices:(void*)indexData dataType:(DataType)dataType
|
||||
startingAt:(int)indexOffset count:(int)primitiveCount {}
|
||||
vertexData:(VertexArray*)vertexData
|
||||
vertexOffset:(int)vertexOffset
|
||||
numVertices:(int)numVertices
|
||||
indexData:(IndexArray*)indexData
|
||||
indexOffset:(int)indexOffset
|
||||
primitiveCount:(int)primitiveCount {}
|
||||
|
||||
- (void) drawUserIndexedPrimitivesOfType:(PrimitiveType)primitiveType
|
||||
vertexData:(void*)vertexData
|
||||
vertexOffset:(int)vertexOffset
|
||||
numVertices:(int)numVertices
|
||||
shortIndexData:(void*)indexData
|
||||
indexOffset:(int)indexOffset
|
||||
primitiveCount:(int)primitiveCount
|
||||
vertexDeclaration:(VertexDeclaration*) vertexDeclaration {}
|
||||
// Private methods
|
||||
|
||||
+ (void) getFormat:(GLenum*)format AndType:(GLenum*)type ForSurfaceFormat:(SurfaceFormat)surfaceFormat {
|
||||
@ -385,6 +453,7 @@
|
||||
[viewport release];
|
||||
[deviceResetting release];
|
||||
[deviceReset release];
|
||||
[vertices release];
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
|
@ -26,8 +26,8 @@ typedef enum {
|
||||
} BlendFunction;
|
||||
|
||||
typedef enum {
|
||||
BufferUsageNone,
|
||||
BufferUsageWriteOnly
|
||||
BufferUsageNone = GL_DYNAMIC_DRAW,
|
||||
BufferUsageWriteOnly = GL_STATIC_DRAW
|
||||
} BufferUsage;
|
||||
|
||||
typedef enum {
|
||||
@ -66,9 +66,10 @@ typedef enum {
|
||||
} CubeMapFace;
|
||||
|
||||
typedef enum {
|
||||
CullModeCullClockwiseFace,
|
||||
CullModeCullCounterClockwiseFace,
|
||||
CullModeNone
|
||||
// The opengl values correspond to which face is front facing, which is opposite of culled
|
||||
CullModeNone,
|
||||
CullModeCullClockwiseFace = GL_CCW,
|
||||
CullModeCullCounterClockwiseFace = GL_CW
|
||||
} CullMode;
|
||||
|
||||
typedef enum {
|
||||
@ -104,8 +105,8 @@ typedef enum {
|
||||
} GraphicsProfile;
|
||||
|
||||
typedef enum {
|
||||
IndexElementSizeSixteenBits = 2,
|
||||
IndexElementSizeThrityTwoBits = 4,
|
||||
IndexElementSizeSixteenBits = 2,
|
||||
//IndexElementSizeThrityTwoBits = 4,
|
||||
} IndexElementSize;
|
||||
|
||||
typedef enum {
|
||||
@ -128,11 +129,6 @@ typedef enum {
|
||||
RenderTargetUsagePreserveContents
|
||||
} RenderTargetUsage;
|
||||
|
||||
typedef enum {
|
||||
ResourceUsageStatic = GL_STATIC_DRAW,
|
||||
ResourceUsageDynamic = GL_DYNAMIC_DRAW
|
||||
} ResourceUsage;
|
||||
|
||||
typedef enum {
|
||||
ResourceTypeTexture2D = GL_TEXTURE_2D,
|
||||
ResourceTypeIndexBuffer = GL_ELEMENT_ARRAY_BUFFER,
|
||||
@ -232,12 +228,12 @@ typedef enum {
|
||||
VertexElementUsageColor = GL_COLOR_ARRAY,
|
||||
VertexElementUsageTextureCoordinate = GL_TEXTURE_COORD_ARRAY,
|
||||
VertexElementUsagePointSize = GL_POINT_SIZE_ARRAY_OES,
|
||||
//VertexElementUsageBinormal,
|
||||
//VertexElementUsageBlendIndices,
|
||||
//VertexElementUsageBlendWeight,
|
||||
//VertexElementUsageDepth,
|
||||
//VertexElementUsageFog,
|
||||
//VertexElementUsageSample,
|
||||
//VertexElementUsageTangent,
|
||||
//VertexElementUsageTessellateFactor
|
||||
VertexElementUsageBinormal,
|
||||
VertexElementUsageBlendIndices,
|
||||
VertexElementUsageBlendWeight,
|
||||
VertexElementUsageDepth,
|
||||
VertexElementUsageFog,
|
||||
VertexElementUsageSample,
|
||||
VertexElementUsageTangent,
|
||||
VertexElementUsageTessellateFactor
|
||||
} VertexElementUsage;
|
||||
|
@ -11,7 +11,7 @@
|
||||
@implementation HiDefGraphicsDevice
|
||||
|
||||
- (EAGLContext*) createContext {
|
||||
return [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
|
||||
return [[[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2] autorelease];
|
||||
}
|
||||
|
||||
@end
|
||||
|
29
Classes/Retronator/Xni/Framework/Graphics/IndexArray.h
Normal file
29
Classes/Retronator/Xni/Framework/Graphics/IndexArray.h
Normal file
@ -0,0 +1,29 @@
|
||||
//
|
||||
// IndexArray.h
|
||||
// XNI
|
||||
//
|
||||
// Created by Matej Jan on 30.11.10.
|
||||
// Copyright 2010 Retronator. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
#import "Retronator.Xni.Framework.Graphics.classes.h"
|
||||
|
||||
@class XniAdaptiveArray;
|
||||
|
||||
@interface IndexArray : NSObject {
|
||||
XniAdaptiveArray *array;
|
||||
}
|
||||
|
||||
- (id) initWithItemSize:(int)itemSize initialCapacity:(int)initialCapacity;
|
||||
|
||||
@property (nonatomic, readonly) void *array;
|
||||
@property (nonatomic, readonly) int count;
|
||||
@property (nonatomic, readonly) int sizeInBytes;
|
||||
@property (nonatomic, readonly) IndexElementSize indexElementSize;
|
||||
|
||||
- (void) clear;
|
||||
- (void) addIndex:(void*)index;
|
||||
|
||||
@end
|
50
Classes/Retronator/Xni/Framework/Graphics/IndexArray.m
Normal file
50
Classes/Retronator/Xni/Framework/Graphics/IndexArray.m
Normal file
@ -0,0 +1,50 @@
|
||||
//
|
||||
// IndexArray.m
|
||||
// XNI
|
||||
//
|
||||
// Created by Matej Jan on 30.11.10.
|
||||
// Copyright 2010 Retronator. All rights reserved.
|
||||
//
|
||||
|
||||
#import "IndexArray.h"
|
||||
|
||||
#import "XniAdaptiveArray.h"
|
||||
|
||||
@implementation IndexArray
|
||||
|
||||
- (id) initWithItemSize:(int)itemSize initialCapacity:(int)initialCapacity {
|
||||
if (self = [super init]) {
|
||||
array = [[XniAdaptiveArray alloc] initWithItemSize:itemSize initialCapacity:initialCapacity];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void *) array {
|
||||
return array.array;
|
||||
}
|
||||
|
||||
- (int) count {
|
||||
return array.count;
|
||||
}
|
||||
|
||||
- (int) sizeInBytes {
|
||||
return array.count * array.itemSize;
|
||||
}
|
||||
|
||||
- (IndexElementSize) indexElementSize { return 0; }
|
||||
|
||||
- (void) clear {
|
||||
[array clear];
|
||||
}
|
||||
|
||||
- (void) addIndex:(void *)index {
|
||||
[array addItem:index];
|
||||
}
|
||||
|
||||
- (void) dealloc
|
||||
{
|
||||
[array release];
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
@end
|
@ -0,0 +1,16 @@
|
||||
//
|
||||
// IndexBuffer+Internal.h
|
||||
// XNI
|
||||
//
|
||||
// Created by Matej Jan on 29.11.10.
|
||||
// Copyright 2010 Retronator. All rights reserved.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
|
||||
@interface IndexBuffer (Internal)
|
||||
|
||||
@property (nonatomic, readonly) uint bufferID;
|
||||
|
||||
@end
|
@ -12,8 +12,20 @@
|
||||
|
||||
@interface IndexBuffer : GraphicsResource {
|
||||
uint bufferID;
|
||||
BufferUsage bufferUsage;
|
||||
int indexCount;
|
||||
IndexElementSize indexElementSize;
|
||||
}
|
||||
|
||||
@property (nonatomic, readonly) uint bufferId;
|
||||
- (id) initWithGraphicsDevice:(GraphicsDevice *)theGraphicsDevice
|
||||
indexElementSize:(IndexElementSize)theIndexElementSize
|
||||
indexCount:(int)theIndexCount
|
||||
usage:(BufferUsage)theBufferUsage;
|
||||
|
||||
@end
|
||||
@property (nonatomic, readonly) BufferUsage bufferUsage;
|
||||
@property (nonatomic, readonly) int indexCount;
|
||||
@property (nonatomic, readonly) IndexElementSize indexElementSize;
|
||||
|
||||
- (void) setData:(IndexArray*)data;
|
||||
|
||||
@end
|
@ -7,10 +7,37 @@
|
||||
//
|
||||
|
||||
#import "IndexBuffer.h"
|
||||
#import "IndexBuffer+Internal.h"
|
||||
#import "GraphicsDevice+Internal.h"
|
||||
|
||||
#import "Retronator.Xni.Framework.Graphics.h"
|
||||
|
||||
@implementation IndexBuffer
|
||||
|
||||
@synthesize bufferId;
|
||||
- (id) initWithGraphicsDevice:(GraphicsDevice *)theGraphicsDevice
|
||||
indexElementSize:(IndexElementSize)theIndexElementSize
|
||||
indexCount:(int)theIndexCount
|
||||
usage:(BufferUsage)theBufferUsage
|
||||
{
|
||||
self = [super initWithGraphicsDevice:theGraphicsDevice];
|
||||
if (self != nil) {
|
||||
bufferID = [graphicsDevice createBuffer];
|
||||
indexElementSize = theIndexElementSize;
|
||||
indexCount = theIndexCount;
|
||||
bufferUsage = theBufferUsage;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
@synthesize indexElementSize, indexCount, bufferUsage;
|
||||
|
||||
- (uint) bufferID {
|
||||
return bufferID;
|
||||
}
|
||||
|
||||
- (void) setData:(IndexArray*)data {
|
||||
[graphicsDevice setData:data.array toIndexBuffer:self];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
18
Classes/Retronator/Xni/Framework/Graphics/Model+Internal.h
Normal file
18
Classes/Retronator/Xni/Framework/Graphics/Model+Internal.h
Normal file
@ -0,0 +1,18 @@
|
||||
//
|
||||
// Model+Internal.h
|
||||
// XNI
|
||||
//
|
||||
// Created by Matej Jan on 22.11.10.
|
||||
// Copyright 2010 Retronator. All rights reserved.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
#import "Model.h"
|
||||
#import "Retronator.Xni.Framework.Content.classes.h"
|
||||
|
||||
@interface Model (Internal)
|
||||
|
||||
- (id) initWithBones:(NSArray*)theBones meshes:(NSArray*)theMeshes root:(ModelBone*)theRoot tag:(id)theTag;
|
||||
|
||||
@end
|
31
Classes/Retronator/Xni/Framework/Graphics/Model.h
Normal file
31
Classes/Retronator/Xni/Framework/Graphics/Model.h
Normal file
@ -0,0 +1,31 @@
|
||||
//
|
||||
// Model.h
|
||||
// XNI
|
||||
//
|
||||
// Created by Matej Jan on 22.11.10.
|
||||
// Copyright 2010 Retronator. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
#import "Retronator.Xni.Framework.Graphics.classes.h"
|
||||
|
||||
@interface Model : NSObject {
|
||||
ModelBoneCollection *bones;
|
||||
ModelMeshCollection *meshes;
|
||||
ModelBone *root;
|
||||
id tag;
|
||||
|
||||
NSMutableArray *absoluteBones;
|
||||
}
|
||||
|
||||
@property (nonatomic, readonly) ModelBoneCollection *bones;
|
||||
@property (nonatomic, readonly) ModelMeshCollection *meshes;
|
||||
@property (nonatomic, readonly) ModelBone *root;
|
||||
@property (nonatomic, retain) id tag;
|
||||
|
||||
- (void) copyAbsoluteBoneTransformsTo:(NSArray*)destinationBoneTransforms;
|
||||
|
||||
- (void) drawWithWorld:(Matrix*)world view:(Matrix*)view projection:(Matrix*)projection;
|
||||
|
||||
@end
|
91
Classes/Retronator/Xni/Framework/Graphics/Model.m
Normal file
91
Classes/Retronator/Xni/Framework/Graphics/Model.m
Normal file
@ -0,0 +1,91 @@
|
||||
//
|
||||
// Model.m
|
||||
// XNI
|
||||
//
|
||||
// Created by Matej Jan on 22.11.10.
|
||||
// Copyright 2010 Retronator. All rights reserved.
|
||||
//
|
||||
|
||||
#import "Model.h"
|
||||
#import "Model+Internal.h"
|
||||
|
||||
#import "Retronator.Xni.Framework.h"
|
||||
#import "Retronator.Xni.Framework.Graphics.h"
|
||||
#import "ModelMesh+Internal.h"
|
||||
#import "ModelMeshPart+Internal.h"
|
||||
#import "Retronator.Xni.Framework.Content.h"
|
||||
#import "Retronator.Xni.Framework.Content.Pipeline.Processors.h"
|
||||
|
||||
@interface Model ()
|
||||
|
||||
- (void) copyAbsoluteBoneTransformsTo:(NSArray *)destinationBoneTransforms forBone:(ModelBone*)bone;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@implementation Model
|
||||
|
||||
- (id) initWithBones:(NSArray*)theBones meshes:(NSArray*)theMeshes root:(ModelBone*)theRoot tag:(id)theTag;
|
||||
{
|
||||
self = [super init];
|
||||
if (self != nil) {
|
||||
bones = [[ModelBoneCollection alloc] initWithItems:theBones];
|
||||
meshes = [[ModelMeshCollection alloc] initWithItems:theMeshes];
|
||||
root = [theRoot retain];
|
||||
self.tag = theTag;
|
||||
|
||||
absoluteBones = [[NSMutableArray alloc] initWithCapacity:bones.count];
|
||||
for (int i = 0; i < bones.count; i++) {
|
||||
[absoluteBones addObject:[Matrix zero]];
|
||||
}
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
@synthesize bones, meshes, root, tag;
|
||||
|
||||
- (void) copyAbsoluteBoneTransformsTo:(NSArray *)destinationBoneTransforms {
|
||||
[self copyAbsoluteBoneTransformsTo:destinationBoneTransforms forBone:root];
|
||||
}
|
||||
|
||||
- (void) copyAbsoluteBoneTransformsTo:(NSArray *)destinationBoneTransforms forBone:(ModelBone*)bone {
|
||||
Matrix *parent = bone.parent ? [destinationBoneTransforms objectAtIndex:bone.parent.index] : [Matrix identity];
|
||||
Matrix *target = [destinationBoneTransforms objectAtIndex:bone.index];
|
||||
[target set:[Matrix multiply:parent by:bone.transform]];
|
||||
for (ModelBone *child in bone.children) {
|
||||
[self copyAbsoluteBoneTransformsTo:destinationBoneTransforms forBone:child];
|
||||
}
|
||||
}
|
||||
|
||||
- (void) drawWithWorld:(Matrix *)world view:(Matrix *)view projection:(Matrix *)projection {
|
||||
[self copyAbsoluteBoneTransformsTo:absoluteBones];
|
||||
|
||||
for (ModelMesh *mesh in meshes) {
|
||||
|
||||
// Set matrices on all mesh's effects.
|
||||
for (Effect *effect in mesh.effects) {
|
||||
BasicEffect *basicEffect = [effect isKindOfClass:[BasicEffect class]] ? (BasicEffect*)effect : nil;
|
||||
|
||||
if (basicEffect) {
|
||||
basicEffect.world = [Matrix multiply:[absoluteBones objectAtIndex:mesh.parentBone.index] by:world];
|
||||
basicEffect.view = view;
|
||||
basicEffect.projection = projection;
|
||||
}
|
||||
}
|
||||
|
||||
// Draw the mesh.
|
||||
[mesh draw];
|
||||
}
|
||||
}
|
||||
|
||||
- (void) dealloc
|
||||
{
|
||||
[bones release];
|
||||
[meshes release];
|
||||
[root release];
|
||||
[tag release];
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
|
||||
@end
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user