Skip to content

Commit

Permalink
Merge pull request #115 from bnjm/material-improvements
Browse files Browse the repository at this point in the history
Material improvements: litPerPixel, blendMode, fillMode, doubleSided
  • Loading branch information
macrozone authored Nov 28, 2017
2 parents 785e8dd + 054ce6b commit b10cc00
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 16 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,11 @@ Most objects take a material property with these sub-props:
| `diffuse` | colorstring | diffuse color |
| `metalness` | number | metalness of the object |
| `roughness` | number | roughness of the object |
| `doubleSided` | boolean | render both sides, default is `true` |
| `litPerPixel` | boolean | calculate lighting per-pixel or vertex [litPerPixel](https://developer.apple.com/documentation/scenekit/scnmaterial/1462580-litperpixel) |
| `lightingModel` | `ARKit.LightingModel.*` | [LightingModel](https://developer.apple.com/documentation/scenekit/scnmaterial.lightingmodel) |
| `blendMode` | `ARKit.BlendMode.*` | [BlendMode](https://developer.apple.com/documentation/scenekit/scnmaterial/1462585-blendmode) |
| `fillMode` | `ARKit.FillMode.*` | [FillMode](https://developer.apple.com/documentation/scenekit/scnmaterial/2867442-fillmode)
| `shaders` | Object with keys from `ARKit.ShaderModifierEntryPoint.*` and shader strings as values | [Shader modifiers](https://developer.apple.com/documentation/scenekit/scnshadable) |
| `colorBufferWriteMask` | `ARKit.ColorMask.*` | [color mask](https://developer.apple.com/documentation/scenekit/scncolormask). Set to ARKit.ColorMask.None so that an object is transparent, but receives deferred shadows. |

Expand Down
4 changes: 4 additions & 0 deletions components/lib/propTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export const renderingOrder = PropTypes.number;
export const blendMode = PropTypes.oneOf(values(ARKitManager.BlendMode));
export const chamferMode = PropTypes.oneOf(values(ARKitManager.ChamferMode));
export const color = PropTypes.string;
export const fillMode = PropTypes.oneOf(values(ARKitManager.FillMode));

export const lightType = PropTypes.oneOf(values(ARKitManager.LightType));
export const shadowMode = PropTypes.oneOf(values(ARKitManager.ShadowMode));
Expand All @@ -66,4 +67,7 @@ export const material = PropTypes.shape({
shaders,
writesToDepthBuffer: PropTypes.bool,
colorBufferWriteMask,
doubleSided: PropTypes.bool,
litPerPixel: PropTypes.bool,
fillMode,
});
35 changes: 19 additions & 16 deletions ios/RCTARKitManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ - (UIView *)view {

- (NSDictionary *)constantsToExport
{

return @{
@"ARHitTestResultType": @{
@"FeaturePoint": @(ARHitTestResultTypeFeaturePoint),
Expand Down Expand Up @@ -58,7 +58,7 @@ - (NSDictionary *)constantsToExport
@"Red": [@(SCNColorMaskRed) stringValue],
@"Green": [@(SCNColorMaskGreen) stringValue],
},

@"ShaderModifierEntryPoint": @{
@"Geometry": SCNShaderModifierEntryPointGeometry,
@"Surface": SCNShaderModifierEntryPointSurface,
Expand All @@ -72,18 +72,22 @@ - (NSDictionary *)constantsToExport
@"Multiply": [@(SCNBlendModeMultiply) stringValue],
@"Screen": [@(SCNBlendModeScreen) stringValue],
@"Replace": [@(SCNBlendModeReplace) stringValue],

},
@"ChamferMode": @{
@"Both": [@(SCNChamferModeBoth) stringValue],
@"Back": [@(SCNChamferModeBack) stringValue],
@"Front": [@(SCNChamferModeBack) stringValue],

},
@"ARWorldAlignment": @{
@"Gravity": @(ARWorldAlignmentGravity),
@"GravityAndHeading": @(ARWorldAlignmentGravityAndHeading),
@"Camera": @(ARWorldAlignmentCamera),
},
@"FillMode": @{
@"Fill": [@(SCNFillModeFill) stringValue],
@"Lines": [@(SCNFillModeLines) stringValue],
}
};
}
Expand Down Expand Up @@ -152,19 +156,19 @@ - (NSString *)getAssetUrl:(NSString *)localID {

- (void)storeImageInPhotoAlbum:(UIImage *)image reject:(RCTPromiseRejectBlock)reject resolve:(RCTPromiseResolveBlock)resolve {
__block PHObjectPlaceholder *placeholder;

[[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{
PHAssetChangeRequest* createAssetRequest = [PHAssetChangeRequest creationRequestForAssetFromImage:image];
placeholder = [createAssetRequest placeholderForCreatedAsset];

} completionHandler:^(BOOL success, NSError *error) {
if (success)
{

NSString * localID = placeholder.localIdentifier;

NSString * assetURLStr = [self getAssetUrl:localID];

resolve(@{@"url": assetURLStr, @"width":@(image.size.width), @"height": @(image.size.height)});
}
else
Expand All @@ -186,10 +190,10 @@ - (void)storeImageInDirectory:(UIImage *)image directory:(NSString *)directory f
return;
}
NSString *prefixString = @"capture";

NSString *guid = [[NSProcessInfo processInfo] globallyUniqueString] ;
NSString *uniqueFileName = [NSString stringWithFormat:@"%@_%@.%@", prefixString, guid, format];

NSString *filePath = [directory stringByAppendingPathComponent:uniqueFileName]; //Add the file name
bool success = [data writeToFile:filePath atomically:YES]; //Write the file
if(success) {
Expand All @@ -198,13 +202,13 @@ - (void)storeImageInDirectory:(UIImage *)image directory:(NSString *)directory f
// TODO use NSError from writeToFile
reject(@"snapshot_error", [NSString stringWithFormat:@"could not save to '%@'", filePath], nil);
}

}

- (void)storeImage:(UIImage *)image options:(NSDictionary *)options reject:(RCTPromiseRejectBlock)reject resolve:(RCTPromiseResolveBlock)resolve {
NSString * target = @"cameraRoll";
NSString * format = @"png";

if(options[@"target"]) {
target = options[@"target"];
}
Expand All @@ -220,7 +224,7 @@ - (void)storeImage:(UIImage *)image options:(NSDictionary *)options reject:(RCTP
dir = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) firstObject];
} else if([target isEqualToString:@"documents"]) {
dir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject];

} else {
dir = target;
}
Expand Down Expand Up @@ -270,7 +274,7 @@ - (void)storeImage:(UIImage *)image options:(NSDictionary *)options reject:(RCTP
@"z": @(pointProjected.z),
@"distance": @(distance)
});

}

RCT_EXPORT_METHOD(focusScene:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject) {
Expand All @@ -284,4 +288,3 @@ - (void)storeImage:(UIImage *)image options:(NSDictionary *)options reject:(RCTP
}

@end

12 changes: 12 additions & 0 deletions ios/RCTConvert+ARKit.m
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,18 @@ + (void)setMaterialProperties:(SCNMaterial *)material properties:(id)json {
if(json[@"colorBufferWriteMask"] ) {
material.colorBufferWriteMask = [json[@"colorBufferWriteMask"] integerValue];
}

if(json[@"fillMode"] ) {
material.fillMode = [json[@"fillMode"] integerValue];
}

if(json[@"doubleSided"]) {
material.doubleSided = [json[@"doubleSided"] boolValue];
}

if(json[@"litPerPixel"]) {
material.litPerPixel = [json[@"litPerPixel"] boolValue];
}
}

+ (void)setNodeProperties:(SCNNode *)node properties:(id)json {
Expand Down

0 comments on commit b10cc00

Please sign in to comment.