Skip to content

Commit 661eb82

Browse files
committed
add more shape properties
1 parent 9225b47 commit 661eb82

4 files changed

Lines changed: 65 additions & 27 deletions

File tree

components/ARShape.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
import PropTypes from 'prop-types';
22

3+
import { chamferMode } from './lib/propTypes';
34
import createArComponent from './lib/createArComponent';
45

56
const ARShape = createArComponent('addShape', {
67
shape: PropTypes.shape({
78
extrusion: PropTypes.number,
8-
path: PropTypes.string
9+
pathSvg: PropTypes.string,
10+
pathFlatness: PropTypes.number,
11+
chamferMode,
12+
chamferRadius: PropTypes.number,
13+
chamferProfilePathSvg: PropTypes.string,
14+
chamferProfilePathFlatness: PropTypes.string
915
})
1016
});
1117

components/lib/propTypes.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,49 +8,50 @@ const ARKitManager = NativeModules.ARKitManager;
88
export const position = PropTypes.shape({
99
x: PropTypes.number,
1010
y: PropTypes.number,
11-
z: PropTypes.number,
11+
z: PropTypes.number
1212
});
1313
export const transition = PropTypes.shape({
14-
duration: PropTypes.number,
14+
duration: PropTypes.number
1515
});
1616
export const eulerAngles = PropTypes.shape({
1717
x: PropTypes.number,
1818
y: PropTypes.number,
19-
z: PropTypes.number,
19+
z: PropTypes.number
2020
});
2121

2222
export const rotation = PropTypes.shape({
2323
x: PropTypes.number,
2424
y: PropTypes.number,
2525
z: PropTypes.number,
26-
w: PropTypes.number,
26+
w: PropTypes.number
2727
});
2828

2929
export const orientation = PropTypes.shape({
3030
x: PropTypes.number,
3131
y: PropTypes.number,
3232
z: PropTypes.number,
33-
w: PropTypes.number,
33+
w: PropTypes.number
3434
});
3535

3636
export const shaders = PropTypes.shape({
3737
[ARKitManager.ShaderModifierEntryPoint.Geometry]: PropTypes.string,
3838
[ARKitManager.ShaderModifierEntryPoint.Surface]: PropTypes.string,
3939
[ARKitManager.ShaderModifierEntryPoint.LightingModel]: PropTypes.string,
40-
[ARKitManager.ShaderModifierEntryPoint.Fragment]: PropTypes.string,
40+
[ARKitManager.ShaderModifierEntryPoint.Fragment]: PropTypes.string
4141
});
4242

4343
export const lightingModel = PropTypes.oneOf(
44-
values(ARKitManager.LightingModel),
44+
values(ARKitManager.LightingModel)
4545
);
4646

4747
export const blendMode = PropTypes.oneOf(values(ARKitManager.BlendMode));
48+
export const chamferMode = PropTypes.oneOf(values(ARKitManager.ChamferMode));
4849

4950
export const material = PropTypes.shape({
5051
color: PropTypes.string,
5152
metalness: PropTypes.number,
5253
roughness: PropTypes.number,
5354
blendMode,
5455
lightingModel,
55-
shaders,
56+
shaders
5657
});

ios/RCTARKitManager.m

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ - (NSDictionary *)constantsToExport
5151
@"Screen": [@(SCNBlendModeScreen) stringValue],
5252
@"Replace": [@(SCNBlendModeReplace) stringValue],
5353

54+
},
55+
@"ChamferMode": @{
56+
@"Both": [@(SCNChamferModeBoth) stringValue],
57+
@"Back": [@(SCNChamferModeBack) stringValue],
58+
@"Front": [@(SCNChamferModeBack) stringValue],
59+
5460
}
5561
};
5662
}

ios/RCTConvert+ARKit.m

Lines changed: 43 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ + (SCNVector4)SCNVector4:(id)json {
3838

3939
+ (SCNNode *)SCNNode:(id)json {
4040
SCNNode *node = [SCNNode new];
41-
41+
4242
node.name = [NSString stringWithFormat:@"%@", json[@"id"]];
4343
[self setNodeProperties:node properties:json];
44-
44+
4545
return node;
4646
}
4747

@@ -52,10 +52,9 @@ + (SCNBox *)SCNBox:(id)json {
5252
CGFloat length = [shape[@"length"] floatValue];
5353
CGFloat chamfer = [shape[@"chamfer"] floatValue];
5454
SCNBox *geometry = [SCNBox boxWithWidth:width height:height length:length chamferRadius:chamfer];
55-
5655
SCNMaterial *material = [self SCNMaterial:json[@"material"]];
5756
geometry.materials = @[material, material, material, material, material, material];
58-
57+
5958
return geometry;
6059
}
6160

@@ -66,7 +65,7 @@ + (SCNSphere *)SCNSphere:(id)json {
6665

6766
SCNMaterial *material = [self SCNMaterial:json[@"material"]];
6867
geometry.materials = @[material];
69-
68+
7069
return geometry;
7170
}
7271

@@ -132,7 +131,7 @@ + (SCNTorus *)SCNTorus:(id)json {
132131

133132
return geometry;
134133
}
135-
134+
136135
+ (SCNCapsule *)SCNCapsule:(id)json {
137136
NSDictionary* shape = json[@"shape"];
138137
CGFloat capR = [shape[@"capR"] floatValue];
@@ -168,10 +167,7 @@ + (SCNPlane *)SCNPlane:(id)json {
168167
return geometry;
169168
}
170169

171-
+ (SCNShape * )SCNShape:(id)json {
172-
NSDictionary* shape = json[@"shape"];
173-
NSString * pathString =shape[@"path"];
174-
170+
+ (SVGBezierPath *)svgStringToBezier:(NSString *)pathString {
175171
NSArray * paths = [SVGBezierPath pathsFromSVGString:pathString];
176172
SVGBezierPath * fullPath;
177173
for(SVGBezierPath *path in paths) {
@@ -181,14 +177,43 @@ + (SCNShape * )SCNShape:(id)json {
181177
[fullPath appendPath:path];
182178
}
183179
}
184-
185-
fullPath.flatness = 0.01;
180+
return fullPath;
181+
}
182+
183+
+ (SCNShape * )SCNShape:(id)json {
184+
NSDictionary* shape = json[@"shape"];
185+
NSString * pathString = shape[@"pathSvg"];
186+
187+
SVGBezierPath * path = [self svgStringToBezier:pathString];
188+
189+
if (shape[@"pathFlatness"]) {
190+
path.flatness = [shape[@"pathFlatness"] floatValue];
191+
} else {
192+
path.flatness = 0.01;
193+
}
186194
CGFloat extrusion = [shape[@"extrusion"] floatValue];
187-
SCNShape *geometry = [SCNShape shapeWithPath:fullPath extrusionDepth:extrusion];
195+
SCNShape *geometry = [SCNShape shapeWithPath:path extrusionDepth:extrusion];
196+
if (shape[@"chamferMode"]) {
197+
geometry.chamferMode = (SCNChamferMode) [shape[@"chamferMode"] integerValue];
198+
}
199+
if (shape[@"chamferRadius"]) {
200+
geometry.chamferRadius = [shape[@"chamferRadius"] floatValue];
201+
}
202+
203+
if (shape[@"chamferProfilePathSvg"]) {
204+
205+
SVGBezierPath * path = [self svgStringToBezier:shape[@"chamferProfilePathSvg"]];
206+
if(shape[@"chamferProfilePathFlatness"]) {
207+
path.flatness = [shape[@"chamferProfilePathFlatness"] floatValue];
208+
}
209+
geometry.chamferProfile = path;
210+
}
211+
212+
188213

189214
SCNMaterial *material = [self SCNMaterial:json[@"material"]];
190215
material.doubleSided = YES;
191-
216+
192217
geometry.materials = @[material];
193218
return geometry;
194219
}
@@ -209,7 +234,7 @@ + (SCNTextNode *)SCNTextNode:(id)json {
209234
CGFloat fontSize = [font[@"size"] floatValue];
210235
CGFloat size = fontSize / 12;
211236
SCNText *scnText = [SCNText textWithString:text extrusionDepth:depth / size];
212-
237+
213238
scnText.flatness = 0.1;
214239

215240
// font
@@ -241,7 +266,7 @@ + (SCNTextNode *)SCNTextNode:(id)json {
241266
SCNVector3 min = SCNVector3Zero;
242267
SCNVector3 max = SCNVector3Zero;
243268
[textNode getBoundingBoxMin:&min max:&max];
244-
269+
245270
textNode.position = SCNVector3Make(-(min.x + max.x) / 2 * size,
246271
-(min.y + max.y) / 2 * size,
247272
-(min.z + max.z) / 2 * size);
@@ -283,7 +308,7 @@ + (void)setNodeProperties:(SCNNode *)node properties:(id)json {
283308
} else {
284309
[SCNTransaction setAnimationDuration:0.0];
285310
}
286-
311+
287312
} else {
288313
[SCNTransaction setAnimationDuration:0.0];
289314
}
@@ -294,7 +319,7 @@ + (void)setNodeProperties:(SCNNode *)node properties:(id)json {
294319
if (json[@"scale"]) {
295320
CGFloat scale = [json[@"scale"] floatValue];
296321
node.scale = SCNVector3Make(scale, scale, scale);
297-
322+
298323
}
299324

300325
if (json[@"eulerAngles"]) {

0 commit comments

Comments
 (0)