Skip to content

Commit 5f1dc08

Browse files
committed
normalize chamferProfile path
1 parent 661eb82 commit 5f1dc08

File tree

2 files changed

+26
-16
lines changed

2 files changed

+26
-16
lines changed

ARKit.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
View,
1414
Text,
1515
NativeModules,
16-
requireNativeComponent,
16+
requireNativeComponent
1717
} from 'react-native';
1818

1919
import generateId from './components/lib/generateId';
@@ -26,15 +26,15 @@ const TRACKING_REASONS = [
2626
'NONE',
2727
'INITIALIZING',
2828
'EXCESSIVE_MOTION',
29-
'INSUFFICIENT_FEATURES',
29+
'INSUFFICIENT_FEATURES'
3030
];
3131
const TRACKING_STATES_COLOR = ['red', 'orange', 'green'];
3232

3333
class ARKit extends Component {
3434
state = {
3535
state: 0,
3636
reason: 0,
37-
floor: null,
37+
floor: null
3838
};
3939
componentWillMount() {
4040
ARKitManager.clearScene();
@@ -55,7 +55,7 @@ class ARKit extends Component {
5555
<View
5656
style={[
5757
styles.stateIcon,
58-
{ backgroundColor: TRACKING_STATES_COLOR[this.state.state] },
58+
{ backgroundColor: TRACKING_STATES_COLOR[this.state.state] }
5959
]}
6060
/>
6161
<Text style={styles.stateText}>
@@ -84,21 +84,21 @@ class ARKit extends Component {
8484
_onTrackingState = ({
8585
state = this.state.state,
8686
reason = this.state.reason,
87-
floor,
87+
floor
8888
}) => {
8989
if (this.props.onTrackingState) {
9090
this.props.onTrackingState({
9191
state: TRACKING_STATES[state] || state,
9292
reason: TRACKING_REASONS[reason] || reason,
93-
floor,
93+
floor
9494
});
9595
}
9696

9797
if (this.props.debug) {
9898
this.setState({
9999
state,
100100
reason,
101-
floor: floor ? floor.toFixed(2) : this.state.floor,
101+
floor: floor ? floor.toFixed(2) : this.state.floor
102102
});
103103
}
104104
};
@@ -138,19 +138,19 @@ const styles = StyleSheet.create({
138138
borderRadius: 10,
139139
padding: 4,
140140
backgroundColor: 'black',
141-
flexDirection: 'row',
141+
flexDirection: 'row'
142142
},
143143
stateIcon: {
144144
width: 12,
145145
height: 12,
146146
borderRadius: 6,
147-
marginRight: 4,
147+
marginRight: 4
148148
},
149149
stateText: {
150150
color: 'white',
151151
fontSize: 10,
152-
height: 12,
153-
},
152+
height: 12
153+
}
154154
});
155155

156156
// copy all ARKitManager properties to ARKit
@@ -160,7 +160,7 @@ Object.keys(ARKitManager).forEach(key => {
160160

161161
const addDefaultsToSnapShotFunc = funcName => ({
162162
target = 'cameraRoll',
163-
format = 'png',
163+
format = 'png'
164164
}) => ARKitManager[funcName]({ target, format });
165165

166166
ARKit.snapshot = addDefaultsToSnapShotFunc('snapshot');
@@ -182,7 +182,7 @@ ARKit.propTypes = {
182182
onTrackingState: PropTypes.func,
183183
onTapOnPlaneUsingExtent: PropTypes.func,
184184
onTapOnPlaneNoExtent: PropTypes.func,
185-
onEvent: PropTypes.func,
185+
onEvent: PropTypes.func
186186
};
187187

188188
const RCTARKit = requireNativeComponent('RCTARKit', ARKit);

ios/RCTConvert+ARKit.m

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,6 @@ + (SCNShape * )SCNShape:(id)json {
188188

189189
if (shape[@"pathFlatness"]) {
190190
path.flatness = [shape[@"pathFlatness"] floatValue];
191-
} else {
192-
path.flatness = 0.01;
193191
}
194192
CGFloat extrusion = [shape[@"extrusion"] floatValue];
195193
SCNShape *geometry = [SCNShape shapeWithPath:path extrusionDepth:extrusion];
@@ -206,7 +204,19 @@ + (SCNShape * )SCNShape:(id)json {
206204
if(shape[@"chamferProfilePathFlatness"]) {
207205
path.flatness = [shape[@"chamferProfilePathFlatness"] floatValue];
208206
}
209-
geometry.chamferProfile = path;
207+
// normalize path
208+
CGRect boundingBox = path.bounds;
209+
if(path.bounds.size.width !=0 && path.bounds.size.height != 0) {
210+
CGFloat scaleX = 1/boundingBox.size.width;
211+
CGFloat scaleY = scaleY = 1/boundingBox.size.height;
212+
213+
CGAffineTransform transform = CGAffineTransformMakeScale(scaleX, scaleY);
214+
[path applyTransform:transform];
215+
geometry.chamferProfile = path;
216+
} else {
217+
NSLog(@"Invalid chamferProfilePathFlatness");
218+
}
219+
210220
}
211221

212222

0 commit comments

Comments
 (0)