Skip to content
Prev Previous commit
Next Next commit
normalize chamferProfile path
  • Loading branch information
macrozone committed Oct 17, 2017
commit 5f1dc08c2542a5d06d21bdd4d25c17f95325eccd
26 changes: 13 additions & 13 deletions ARKit.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
View,
Text,
NativeModules,
requireNativeComponent,
requireNativeComponent
} from 'react-native';

import generateId from './components/lib/generateId';
Expand All @@ -26,15 +26,15 @@ const TRACKING_REASONS = [
'NONE',
'INITIALIZING',
'EXCESSIVE_MOTION',
'INSUFFICIENT_FEATURES',
'INSUFFICIENT_FEATURES'
];
const TRACKING_STATES_COLOR = ['red', 'orange', 'green'];

class ARKit extends Component {
state = {
state: 0,
reason: 0,
floor: null,
floor: null
};
componentWillMount() {
ARKitManager.clearScene();
Expand All @@ -55,7 +55,7 @@ class ARKit extends Component {
<View
style={[
styles.stateIcon,
{ backgroundColor: TRACKING_STATES_COLOR[this.state.state] },
{ backgroundColor: TRACKING_STATES_COLOR[this.state.state] }
]}
/>
<Text style={styles.stateText}>
Expand Down Expand Up @@ -84,21 +84,21 @@ class ARKit extends Component {
_onTrackingState = ({
state = this.state.state,
reason = this.state.reason,
floor,
floor
}) => {
if (this.props.onTrackingState) {
this.props.onTrackingState({
state: TRACKING_STATES[state] || state,
reason: TRACKING_REASONS[reason] || reason,
floor,
floor
});
}

if (this.props.debug) {
this.setState({
state,
reason,
floor: floor ? floor.toFixed(2) : this.state.floor,
floor: floor ? floor.toFixed(2) : this.state.floor
});
}
};
Expand Down Expand Up @@ -138,19 +138,19 @@ const styles = StyleSheet.create({
borderRadius: 10,
padding: 4,
backgroundColor: 'black',
flexDirection: 'row',
flexDirection: 'row'
},
stateIcon: {
width: 12,
height: 12,
borderRadius: 6,
marginRight: 4,
marginRight: 4
},
stateText: {
color: 'white',
fontSize: 10,
height: 12,
},
height: 12
}
});

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

const addDefaultsToSnapShotFunc = funcName => ({
target = 'cameraRoll',
format = 'png',
format = 'png'
}) => ARKitManager[funcName]({ target, format });

ARKit.snapshot = addDefaultsToSnapShotFunc('snapshot');
Expand All @@ -182,7 +182,7 @@ ARKit.propTypes = {
onTrackingState: PropTypes.func,
onTapOnPlaneUsingExtent: PropTypes.func,
onTapOnPlaneNoExtent: PropTypes.func,
onEvent: PropTypes.func,
onEvent: PropTypes.func
};

const RCTARKit = requireNativeComponent('RCTARKit', ARKit);
Expand Down
16 changes: 13 additions & 3 deletions ios/RCTConvert+ARKit.m
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,6 @@ + (SCNShape * )SCNShape:(id)json {

if (shape[@"pathFlatness"]) {
path.flatness = [shape[@"pathFlatness"] floatValue];
} else {
path.flatness = 0.01;
}
CGFloat extrusion = [shape[@"extrusion"] floatValue];
SCNShape *geometry = [SCNShape shapeWithPath:path extrusionDepth:extrusion];
Expand All @@ -206,7 +204,19 @@ + (SCNShape * )SCNShape:(id)json {
if(shape[@"chamferProfilePathFlatness"]) {
path.flatness = [shape[@"chamferProfilePathFlatness"] floatValue];
}
geometry.chamferProfile = path;
// normalize path
CGRect boundingBox = path.bounds;
if(path.bounds.size.width !=0 && path.bounds.size.height != 0) {
CGFloat scaleX = 1/boundingBox.size.width;
CGFloat scaleY = scaleY = 1/boundingBox.size.height;

CGAffineTransform transform = CGAffineTransformMakeScale(scaleX, scaleY);
[path applyTransform:transform];
geometry.chamferProfile = path;
} else {
NSLog(@"Invalid chamferProfilePathFlatness");
}

}


Expand Down