Skip to content

Commit 710c9c6

Browse files
authored
Merge pull request #89 from panter/shapes
Shapes
2 parents c175ddf + 26617f9 commit 710c9c6

File tree

14 files changed

+221
-53
lines changed

14 files changed

+221
-53
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);

README.md

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,18 @@ There is a Slack group that anyone can join for help / support / general questio
2323

2424
`$ react-native link react-native-arkit`
2525

26+
! Currently automatic installation does not work as PocketSVG is missing. Follow the manual installation
27+
2628
### Manual installation
2729

2830

2931
#### iOS
3032

3133
1. In XCode, in the project navigator, right click `Libraries``Add Files to [your project's name]`
32-
2. Go to `node_modules``react-native-arkit` and add `RCTARKit.xcodeproj`
33-
3. In XCode, in the project navigator, select your project. Add `libRCTARKit.a` to your project's `Build Phases``Link Binary With Libraries`
34-
4. Run your project (`Cmd+R`)<
34+
2. Go to `node_modules` ➜ add `react-native-arkit/RCTARKit.xcodeproj` and `_PocketSVG/_PocketSVG.xcodeproj`
35+
3. In XCode, in the project navigator, select your project. Add `libRCTARKit.a` `and PocketSVG.framework` to your project's `Build Phases``Link Binary With Libraries`
36+
4. In Tab `General``Embedded Binaries``+` ➜ Add `PocketSVG.framework ios`
37+
5. Run your project (`Cmd+R`)<
3538

3639

3740
## Usage
@@ -100,11 +103,32 @@ export default class ReactNativeARKit extends Component {
100103
/>
101104
<ARKit.Model
102105
position={{ x: -0.2, y: 0, z: 0, frame: 'local' }}
106+
scale={0.01},
103107
model={{
104108
file: 'art.scnassets/ship.scn', // make sure you have the model file in the ios project
105-
scale: 0.01,
106109
}}
107110
/>
111+
<ARKit.Shape
112+
position={{ x: -1, y: 0, z: 0 }}
113+
eulerAngles={{
114+
x: Math.PI,
115+
}}
116+
scale={0.01}
117+
shape={{
118+
// specify shape by svg! See https://github.com/HippoAR/react-native-arkit/pull/89 for details
119+
pathSvg: `
120+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100">
121+
<path d="M50,30c9-22 42-24 48,0c5,40-40,40-48,65c-8-25-54-25-48-65c 6-24 39-22 48,0 z" fill="#F00" stroke="#000"/>
122+
</svg>`,
123+
pathFlatness: 0.1,
124+
// it's also possible to specify a chamfer profile:
125+
chamferRadius: 5,
126+
chamferProfilePathSvg: `
127+
<path d="M.6 94.4c.7-7 0-13 6-18.5 1.6-1.4 5.3 1 6-.8l9.6 2.3C25 70.8 20.2 63 21 56c0-1.3 2.3-1 3.5-.7 7.6 1.4 7 15.6 14.7 13.2 1-.2 1.7-1 2-2 2-5-11.3-28.8-3-30.3 2.3-.4 5.7 1.8 6.7 0l8.4 6.5c.3-.4-8-17.3-2.4-21.6 7-5.4 14 5.3 17.7 7.8 1 .8 3 2 3.8 1 6.3-10-6-8.5-3.2-19 2-8.2 18.2-2.3 20.3-3 2.4-.6 1.7-5.6 4.2-6.4"/>
128+
`,
129+
extrusion: 10,
130+
}}
131+
/>
108132
</ARKit>
109133
</View>
110134
);
@@ -273,6 +297,20 @@ SceneKit only supports `.scn` and `.dae` formats.
273297
| `eulerAngles` | `{ x, y, z }` |
274298
| `model` | `{ file, node, scale, alpha }` |
275299

300+
#### `<ARKit.Shape />`
301+
302+
Creates a extruded shape by an svg path.
303+
See https://github.com/HippoAR/react-native-arkit/pull/89 for details
304+
305+
##### Props
306+
307+
| Prop | Type |
308+
|---|---|
309+
| `position` | `{ x, y, z }` |
310+
| `eulerAngles` | `{ x, y, z }` |
311+
| `shape` | `{ pathSvg, extrusion, pathFlatness, chamferRadius, chamferProfilePathSvg, chamferProfilePathFlatness }` |
312+
313+
276314

277315
## Contributing
278316

components/ARShape.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import PropTypes from 'prop-types';
2+
3+
import { chamferMode } from './lib/propTypes';
4+
import createArComponent from './lib/createArComponent';
5+
6+
const ARShape = createArComponent('addShape', {
7+
shape: PropTypes.shape({
8+
extrusion: PropTypes.number,
9+
pathSvg: PropTypes.string,
10+
pathFlatness: PropTypes.number,
11+
chamferMode,
12+
chamferRadius: PropTypes.number,
13+
chamferProfilePathSvg: PropTypes.string,
14+
chamferProfilePathFlatness: PropTypes.string
15+
})
16+
});
17+
18+
module.exports = ARShape;

components/ARSprite.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, { Component } from 'react';
2-
import withAnimationFrame from 'react-animation-frame';
2+
import withAnimationFrame from '@panter/react-animation-frame';
33

44
import { NativeModules, Animated } from 'react-native';
55

@@ -13,7 +13,7 @@ const ARSprite = withAnimationFrame(
1313
super(props);
1414
this.state = {
1515
zIndex: new Animated.Value(),
16-
pos2D: new Animated.ValueXY(), // inits to zero
16+
pos2D: new Animated.ValueXY() // inits to zero
1717
};
1818
}
1919
onAnimationFrame() {
@@ -22,9 +22,9 @@ const ARSprite = withAnimationFrame(
2222
{
2323
x: this.state.pos2D.x,
2424
y: this.state.pos2D.y,
25-
z: this.state.zIndex,
26-
},
27-
]),
25+
z: this.state.zIndex
26+
}
27+
])
2828
);
2929
}
3030

@@ -34,18 +34,18 @@ const ARSprite = withAnimationFrame(
3434
style={{
3535
position: 'absolute',
3636
transform: this.state.pos2D.getTranslateTransform(),
37-
...this.props.style,
37+
...this.props.style
3838
}}
3939
>
4040
{this.props.children}
4141
</Animated.View>
4242
);
4343
}
44-
},
44+
}
4545
);
4646

4747
ARSprite.propTypes = {
48-
position,
48+
position
4949
};
5050

5151
module.exports = ARSprite;

components/lib/createArComponent.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
orientation,
1616
position,
1717
rotation,
18-
transition,
18+
transition
1919
} from './propTypes';
2020
import { processColorInMaterial } from './parseColor';
2121
import generateId from './generateId';
@@ -25,26 +25,27 @@ const NODE_PROPS = [
2525
'position',
2626
'eulerAngles',
2727
'rotation',
28+
'scale',
2829
'orientation',
29-
'transition',
30+
'transition'
3031
];
3132
const KEYS_THAT_NEED_REMOUNT = ['material', 'shape', 'model'];
3233

3334
const nodeProps = (id, props) => ({
3435
id,
35-
...pick(props, NODE_PROPS),
36+
...pick(props, NODE_PROPS)
3637
});
3738

3839
export default (mountConfig, propTypes = {}) => {
3940
const getShapeAndMaterialProps = props =>
4041
typeof mountConfig === 'string'
4142
? {
4243
shape: props.shape,
43-
material: processColorInMaterial(props.material),
44+
material: processColorInMaterial(props.material)
4445
}
4546
: {
4647
...pick(props, mountConfig.pick),
47-
material: processColorInMaterial(props.material),
48+
material: processColorInMaterial(props.material)
4849
};
4950

5051
const mountFunc =
@@ -56,7 +57,7 @@ export default (mountConfig, propTypes = {}) => {
5657
mountFunc(
5758
getShapeAndMaterialProps(props),
5859
nodeProps(id, props),
59-
props.frame,
60+
props.frame
6061
);
6162
};
6263

@@ -71,7 +72,7 @@ export default (mountConfig, propTypes = {}) => {
7172
componentWillUpdate(props) {
7273
const changedKeys = filter(
7374
keys(this.props),
74-
key => !isDeepEqual(props[key], this.props[key]),
75+
key => !isDeepEqual(props[key], this.props[key])
7576
);
7677

7778
if (isEmpty(changedKeys)) {
@@ -87,7 +88,7 @@ export default (mountConfig, propTypes = {}) => {
8788
// always include transition
8889
ARGeosManager.update(
8990
this.identifier,
90-
pick(props, ['transition', ...changedKeys]),
91+
pick(props, ['transition', ...changedKeys])
9192
);
9293
}
9394
}
@@ -108,7 +109,7 @@ export default (mountConfig, propTypes = {}) => {
108109
rotation,
109110
orientation,
110111
material,
111-
...propTypes,
112+
...propTypes
112113
};
113114

114115
return ARComponent;

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
});

0 commit comments

Comments
 (0)