Skip to content

Commit 4b83929

Browse files
Switching between models may crash ARKit #28
1 parent 57e6139 commit 4b83929

File tree

5 files changed

+224
-15
lines changed

5 files changed

+224
-15
lines changed

Diff for: demo/app/App_Resources/iOS/Models.scnassets/glasses-vv-1.dae

+201
Large diffs are not rendered by default.

Diff for: demo/app/main-page.ts

+9-9
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ export function arLoaded(args: ARLoadedEventData): void {
151151

152152
export function trackingFaceDetected(args: ARTrackingFaceEventData): void {
153153
if (args.properties) {
154-
console.log(JSON.stringify(args.properties));
154+
// console.log(JSON.stringify(args.properties));
155155
}
156156

157157
if (args.faceTrackingActions) {
@@ -177,16 +177,16 @@ export function trackingFaceDetected(args: ARTrackingFaceEventData): void {
177177
}, 500);
178178

179179
args.faceTrackingActions.addModel({
180-
name: "Models.scnassets/glasses2.obj",
180+
name: "Models.scnassets/glasses-vv-1.dae",
181181
position: {
182-
x: 0,
183-
y: -0.007, // a little lower
184-
z: 0.06 // a little closer to the camera
182+
x: 0.001,
183+
y: 0.01,
184+
z: 0
185185
},
186186
scale: {
187-
x: 0.0045,
188-
y: 0.0045,
189-
z: 0.0045
187+
x: 1.03,
188+
y: 1.03,
189+
z: 1.03
190190
},
191191
onTap: (interaction: ARNodeInteraction) => {
192192
// let's remove the current glasses, and replace it by a different model
@@ -210,7 +210,7 @@ export function trackingFaceDetected(args: ARTrackingFaceEventData): void {
210210
}
211211
});
212212

213-
textModel.remove();
213+
// textModel.remove();
214214
args.faceTrackingActions.addText({
215215
text: "Ray-Ban Opaque",
216216
materials: [new Color("orange")],

Diff for: demo/app/main-page.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
trackingImageDetected="trackingImageDetected"
1515
trackingFaceDetected="trackingFaceDetected"
1616
debugLevel="FEATURE_POINTS"
17-
faceMaterial="Assets.scnassets/Materials/tnsgranite/tnsgranite-diffuse.png"
18-
faceMaterial__DISABLED="Assets.xcassets/wireframeTexture.imageset"
17+
faceMaterial__DISABLED="Assets.scnassets/Materials/tnsgranite/tnsgranite-diffuse.png"
18+
faceMaterial__DISABLED2="Assets.xcassets/wireframeTexture.imageset"
1919
planeMaterial="{{ planeMaterial }}"
2020
planeOpacity="0.25"
2121
detectPlanes="true"

Diff for: src/nodes/ios/armodel.ts

+11-3
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,18 @@ import { ARAddModelOptions } from "../../ar-common";
22
import { ARCommonNode } from "./arcommon";
33

44
export class ARModel extends ARCommonNode {
5-
// note that these babies can be cloned, look for 'clone' at http://jamesonquave.com/blog/arkit-tutorial-in-swift-4-for-xcode-9-using-scenekit/
65
static create(options: ARAddModelOptions) {
76
let modelScene = SCNScene.sceneNamed(options.name);
8-
let nodeModel = options.childNodeName ? modelScene.rootNode.childNodeWithNameRecursively(options.childNodeName, true) : modelScene.rootNode;
9-
return new ARModel(options, nodeModel);
7+
8+
let nodeModel: SCNNode;
9+
if (options.childNodeName) {
10+
nodeModel = modelScene.rootNode.childNodeWithNameRecursively(options.childNodeName, true);
11+
} else if (modelScene.rootNode.childNodes.count === 1) {
12+
nodeModel = modelScene.rootNode.childNodes.objectAtIndex(0);
13+
} else {
14+
nodeModel = modelScene.rootNode;
15+
}
16+
17+
return new ARModel(options, nodeModel.clone());
1018
}
1119
}

Diff for: src/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "nativescript-ar",
3-
"version": "0.7.2",
3+
"version": "0.8.0",
44
"description": "NativeScript Augmented Reality plugin. ARKit on iOS and (in the future) ARCore on Android.",
55
"main": "ar",
66
"typings": "index.d.ts",

0 commit comments

Comments
 (0)