-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
fengke
committed
Feb 28, 2018
1 parent
5d7c73c
commit 6586735
Showing
5 changed files
with
123 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file modified
BIN
+6.01 KB
(110%)
...er.xcodeproj/project.xcworkspace/xcuserdata/fk.xcuserdatad/UserInterfaceState.xcuserstate
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// | ||
// ARTextNode.h | ||
// ARImageViewer | ||
// | ||
// Created by fk on 2017/12/20. | ||
// Copyright © 2017年 fk. All rights reserved. | ||
// | ||
|
||
#import <SceneKit/SceneKit.h> | ||
|
||
@interface ARTextNode : SCNNode | ||
|
||
- (instancetype) initWithText:(NSString *)text; | ||
|
||
@property (nonatomic, assign) CGFloat textHeight; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// | ||
// ARTextNode.m | ||
// ARImageViewer | ||
// | ||
// Created by fk on 2017/12/20. | ||
// Copyright © 2017年 fk. All rights reserved. | ||
// | ||
|
||
#import "ARTextNode.h" | ||
|
||
@interface ARTextNode () | ||
|
||
@property (nonatomic, strong) NSString *text; | ||
|
||
@end | ||
|
||
|
||
@implementation ARTextNode | ||
|
||
- (instancetype) initWithText:(NSString *)text { | ||
|
||
self = [super init]; | ||
if (self) { | ||
[self updateTextContent:text]; | ||
} | ||
return self; | ||
} | ||
|
||
- (void)updateTextContent:(NSString *)text { | ||
|
||
_text = text; | ||
|
||
CGFloat bubbleDepth = 0.01; | ||
|
||
SCNText *textGeo = [SCNText textWithString:text extrusionDepth:bubbleDepth]; | ||
|
||
textGeo.font = [self getTextFont]; | ||
textGeo.alignmentMode = kCAAlignmentCenter; | ||
textGeo.firstMaterial.diffuse.contents = [UIColor blackColor]; | ||
textGeo.firstMaterial.specular.contents = [UIColor whiteColor]; | ||
textGeo.firstMaterial.doubleSided = YES; | ||
textGeo.chamferRadius = bubbleDepth; | ||
|
||
SCNVector3 minBound,maxBound; | ||
[textGeo getBoundingBoxMin:&minBound max:&maxBound]; | ||
|
||
SCNNode *textNode = [SCNNode nodeWithGeometry:textGeo]; | ||
textNode.pivot = SCNMatrix4MakeTranslation( (maxBound.x - minBound.x)/2, minBound.y, bubbleDepth/2); | ||
textNode.scale = SCNVector3Make(0.8, 0.8, 0.8); | ||
|
||
_textHeight = minBound.y; | ||
|
||
// SCNSphere *sphere = [SCNSphere sphereWithRadius:0.005]; | ||
// sphere.firstMaterial.diffuse.contents = [UIColor redColor]; | ||
// SCNNode *sphereNode = [SCNNode nodeWithGeometry:sphere]; | ||
// sphereNode.position = SCNVector3Make(0, 0, 0); | ||
// [textNode addChildNode:sphereNode]; | ||
|
||
SCNBillboardConstraint *billboardConstraint = [SCNBillboardConstraint billboardConstraint]; | ||
billboardConstraint.freeAxes = SCNBillboardAxisY; | ||
|
||
|
||
[self addChildNode:textNode]; | ||
// [textNode addChildNode:sphereNode]; | ||
self.constraints = @[billboardConstraint]; | ||
} | ||
|
||
- (UIFont *)getTextFont { | ||
return [UIFont fontWithName:@"TrebuchetMS-Bold" size:0.15]; | ||
} | ||
|
||
@end |