-
Notifications
You must be signed in to change notification settings - Fork 229
/
Copy pathearth_page.dart
58 lines (49 loc) · 1.42 KB
/
earth_page.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import 'dart:async';
import 'package:arkit_plugin/arkit_plugin.dart';
import 'package:flutter/material.dart';
import 'package:vector_math/vector_math_64.dart';
class EarthPage extends StatefulWidget {
@override
_EarthPageState createState() => _EarthPageState();
}
class _EarthPageState extends State<EarthPage> {
late ARKitController arkitController;
Timer? timer;
@override
void dispose() {
timer?.cancel();
arkitController.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) => Scaffold(
appBar: AppBar(title: const Text('Earth Sample')),
body: Container(
child: ARKitSceneView(
onARKitViewCreated: onARKitViewCreated,
),
),
);
void onARKitViewCreated(ARKitController arkitController) {
this.arkitController = arkitController;
final material = ARKitMaterial(
lightingModelName: ARKitLightingModel.lambert,
diffuse: ARKitMaterialProperty.image('earth.jpg'),
);
final sphere = ARKitSphere(
materials: [material],
radius: 0.1,
);
final node = ARKitNode(
geometry: sphere,
position: Vector3(0, 0, -0.5),
eulerAngles: Vector3.zero(),
);
this.arkitController.add(node);
timer = Timer.periodic(const Duration(milliseconds: 50), (timer) {
final rotation = node.eulerAngles;
rotation.x += 0.01;
node.eulerAngles = rotation;
});
}
}