-
Notifications
You must be signed in to change notification settings - Fork 228
/
hello_world.dart
162 lines (145 loc) · 4.56 KB
/
hello_world.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
import 'dart:math' as math;
import 'package:arkit_plugin/arkit_plugin.dart';
import 'package:flutter/material.dart';
import 'package:vector_math/vector_math_64.dart' as vector;
class HelloWorldPage extends StatefulWidget {
@override
_HelloWorldPagState createState() => _HelloWorldPagState();
}
class _HelloWorldPagState extends State<HelloWorldPage> {
late ARKitController arkitController;
@override
void dispose() {
arkitController.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) => Scaffold(
appBar: AppBar(
title: const Text('ARKit in Flutter'),
),
body: Container(
child: ARKitSceneView(
onARKitViewCreated: onARKitViewCreated,
environmentTexturing:
ARWorldTrackingConfigurationEnvironmentTexturing.automatic,
),
));
void onARKitViewCreated(ARKitController arkitController) {
this.arkitController = arkitController;
this.arkitController.add(_createSphere());
this.arkitController.add(_createPlane());
this.arkitController.add(_createText());
this.arkitController.add(_createBox());
this.arkitController.add(_createCylinder());
this.arkitController.add(_createCone());
this.arkitController.add(_createPyramid());
this.arkitController.add(_createTube());
this.arkitController.add(_createTorus());
this.arkitController.add(_createCapsule());
}
ARKitNode _createSphere() => ARKitNode(
geometry:
ARKitSphere(materials: _createRandomColorMaterial(), radius: 0.04),
position: vector.Vector3(-0.1, -0.1, -0.5),
);
ARKitNode _createPlane() {
final plane = ARKitPlane(
width: 1,
height: 1,
materials: [
ARKitMaterial(
transparency: 0.5,
diffuse: ARKitMaterialProperty.color(Colors.white),
)
],
);
return ARKitNode(
geometry: plane,
position: vector.Vector3(0, 0, -1.5),
);
}
ARKitNode _createText() {
final text = ARKitText(
text: 'Flutter',
extrusionDepth: 1,
materials: [
ARKitMaterial(
diffuse: ARKitMaterialProperty.color(Colors.blue),
)
],
);
return ARKitNode(
geometry: text,
position: vector.Vector3(-0.3, 0.3, -1.4),
scale: vector.Vector3(0.02, 0.02, 0.02),
);
}
ARKitNode _createBox() => ARKitNode(
geometry: ARKitBox(
width: 0.06,
height: 0.06,
length: 0.06,
chamferRadius: 0.01,
materials: _createRandomColorMaterial()),
position: vector.Vector3(-0.1, 0, -0.5),
);
ARKitNode _createCylinder() => ARKitNode(
geometry: ARKitCylinder(
radius: 0.05,
height: 0.09,
materials: _createRandomColorMaterial()),
position: vector.Vector3(-0.1, 0.1, -0.5),
);
ARKitNode _createCone() => ARKitNode(
geometry: ARKitCone(
topRadius: 0,
bottomRadius: 0.05,
height: 0.09,
materials: _createRandomColorMaterial()),
position: vector.Vector3(0, -0.1, -0.5),
);
ARKitNode _createPyramid() => ARKitNode(
geometry: ARKitPyramid(
width: 0.09,
height: 0.09,
length: 0.09,
materials: _createRandomColorMaterial()),
position: vector.Vector3(0, -0.05, -0.5),
);
ARKitNode _createTube() => ARKitNode(
geometry: ARKitTube(
innerRadius: 0.03,
outerRadius: 0.05,
height: 0.09,
materials: _createRandomColorMaterial()),
position: vector.Vector3(0.1, 0.1, -0.5),
);
ARKitNode _createTorus() => ARKitNode(
geometry: ARKitTorus(
ringRadius: 0.04,
pipeRadius: 0.02,
materials: _createRandomColorMaterial()),
position: vector.Vector3(0.1, -0.1, -0.5),
);
ARKitNode _createCapsule() => ARKitNode(
geometry: ARKitCapsule(
capRadius: 0.02,
height: 0.06,
materials: _createRandomColorMaterial()),
position: vector.Vector3(0.1, 0, -0.5),
);
final _rnd = math.Random();
List<ARKitMaterial> _createRandomColorMaterial() {
return [
ARKitMaterial(
lightingModelName: ARKitLightingModel.physicallyBased,
metalness: ARKitMaterialProperty.value(_rnd.nextDouble()),
roughness: ARKitMaterialProperty.value(_rnd.nextDouble()),
diffuse: ARKitMaterialProperty.color(
Color((_rnd.nextDouble() * 0xFFFFFF).toInt() << 0).withOpacity(1.0),
),
)
];
}
}