@@ -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