Skip to content

Commit

Permalink
Merge pull request #74 from dmsurti/fix-color-bug
Browse files Browse the repository at this point in the history
Travis dead again. Merging 馃憤
  • Loading branch information
dmsurti committed Sep 19, 2017
2 parents 21d8feb + 125fc44 commit 2448eeb
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 22 deletions.
6 changes: 6 additions & 0 deletions AssimpKit/Code/Model/SCNTextureInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,14 @@

@interface SCNTextureInfo : NSObject

#pragma mark - Texture metadata

/**
The texture type: diffuse, specular etc.
*/
@property enum aiTextureType textureType;

#pragma mark - Creating a texture info

/**
Create a texture metadata object for a material property.
Expand All @@ -58,6 +61,7 @@
inScene:(const struct aiScene *)aiScene
atPath:(NSString *)path;

#pragma mark - Getting texture contents
/**
The contents of the material property which can be a texture or color.
Expand All @@ -66,6 +70,8 @@
-(id)getMaterialPropertyContents;


#pragma mark - Releasing texture resources

/**
Releases the core graphics image resources used to load colors and textures.
*/
Expand Down
52 changes: 30 additions & 22 deletions AssimpKit/Code/Model/SCNTextureInfo.m
Original file line number Diff line number Diff line change
Expand Up @@ -40,44 +40,59 @@ Assimp to Scene Kit Library (AssimpKit)

@interface SCNTextureInfo ()

#pragma mark - Texture material

/**
The material name which is the owner of this texture.
*/
@property (nonatomic, readwrite) NSString *materialName;

#pragma mark - Texture color and resources

/**
A Boolean value that determines whether a color is applied to a material
property.
*/
@property bool applyColor;

/**
The actual color to be applied to a material property.
*/
@property CGColorRef color;

/**
A Boolean value that determines if embedded texture is applied to a
material property.
A profile that specifies the interpretation of a color to be applied to
a material property.
*/
@property bool applyEmbeddedTexture;
@property CGColorSpaceRef colorSpace;

#pragma mark - Embedded texture

/**
A Boolean value that determines if an external texture is applied to a
A Boolean value that determines if embedded texture is applied to a
material property.
*/
@property bool applyExternalTexture;

@property bool applyEmbeddedTexture;

/**
The index of the embedded texture in the array of assimp scene textures.
*/
@property int embeddedTextureIndex;

#pragma mark - External texture

/**
A Boolean value that determines if an external texture is applied to a
material property.
*/
@property bool applyExternalTexture;

/**
The path to the external texture resource on the disk.
*/
@property NSString* externalTexturePath;

#pragma mark - Texture image resources

/**
An opaque type that represents the external texture image source.
Expand All @@ -98,23 +113,14 @@ @interface SCNTextureInfo ()
*/
@property CGImageRef image;


/**
A profile that specifies the interpretation of a color to be applied to
a material property.
*/
@property CGColorSpaceRef colorSpace;


/**
The actual color to be applied to a material property.
*/
@property CGColorRef color;

@end

#pragma mark -

@implementation SCNTextureInfo

#pragma mark - Creating a texture info

/**
Create a texture metadata object for a material property.
Expand Down Expand Up @@ -154,6 +160,7 @@ -(id)initWithMeshIndex:(int)aiMeshIndex
return nil;
}

#pragma mark - Inspect texture metadata

/**
Inspects the material texture properties to determine if color, embedded
Expand Down Expand Up @@ -223,6 +230,7 @@ - (void)checkTextureTypeForMaterial:(const struct aiMaterial *)aiMaterial
}
}

#pragma mark - Generate textures

/**
Generates a bitmap image representing the embedded texture.
Expand Down Expand Up @@ -266,6 +274,8 @@ -(void)generateCGImageForExternalTextureAtPath:(NSString*)path
self.image = CGImageSourceCreateImageAtIndex(self.imageSource, 0, NULL);
}

#pragma mark - Extract color

-(void)extractColorForMaterial:(const struct aiMaterial *)aiMaterial
withTextureType:(enum aiTextureType)aiTextureType
{
Expand Down Expand Up @@ -301,15 +311,13 @@ -(void)extractColorForMaterial:(const struct aiMaterial *)aiMaterial
}
if (AI_SUCCESS == matColor)
{
if (color.r != 0 && color.g != 0 && color.b != 0)
{
self.colorSpace = CGColorSpaceCreateDeviceRGB();
CGFloat components[4] = {color.r, color.g, color.b, color.a};
self.color = CGColorCreate(self.colorSpace, components);
}
}
}

#pragma mark - Texture resources

/**
Returns the color or the bitmap image to be applied to the material property.
Expand Down
Binary file not shown.

0 comments on commit 2448eeb

Please sign in to comment.