Created
May 7, 2020 07:21
-
-
Save anmolseth06/5f2d4708d907b1327d0756f482027e47 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:arcore_flutter_plugin/arcore_flutter_plugin.dart'; | |
import 'package:flutter/material.dart'; | |
import 'package:vector_math/vector_math_64.dart' as vector; | |
void main() { | |
runApp(HelloWorld()); | |
} | |
class HelloWorld extends StatefulWidget { | |
@override | |
_HelloWorldState createState() => _HelloWorldState(); | |
} | |
class _HelloWorldState extends State<HelloWorld> { | |
ArCoreController arCoreController = ArCoreController(); | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
home: Scaffold( | |
appBar: AppBar( | |
title: const Text('Hello World'), | |
), | |
body: ArCoreView( | |
onArCoreViewCreated: _onArCoreViewCreated, | |
), | |
), | |
); | |
} | |
void _onArCoreViewCreated(ArCoreController controller) { | |
arCoreController = controller; | |
_addSphere(arCoreController); | |
_addCylinder(arCoreController); | |
_addCube(arCoreController); | |
} | |
void _addSphere(ArCoreController controller) { | |
final material = ArCoreMaterial( | |
color: Color.fromARGB(120, 66, 134, 244), | |
); | |
final sphere = ArCoreSphere( | |
materials: [material], | |
radius: 0.1, | |
); | |
final node = ArCoreNode( | |
shape: sphere, | |
position: vector.Vector3(0, 0, -1.5), | |
); | |
controller.addArCoreNode(node); | |
} | |
void _addCylinder(ArCoreController controller) { | |
final material = ArCoreMaterial( | |
color: Colors.red, | |
reflectance: 1.0, | |
); | |
final cylinder = ArCoreCylinder( | |
materials: [material], | |
radius: 0.5, | |
height: 0.3, | |
); | |
final node = ArCoreNode( | |
shape: cylinder, | |
position: vector.Vector3(0.0, -0.5, -2.0), | |
); | |
controller.addArCoreNode(node); | |
} | |
void _addCube(ArCoreController controller) { | |
final material = ArCoreMaterial( | |
color: Color.fromARGB(120, 66, 134, 244), | |
metallic: 1.0, | |
); | |
final cube = ArCoreCube( | |
materials: [material], | |
size: vector.Vector3(0.5, 0.5, 0.5), | |
); | |
final node = ArCoreNode( | |
shape: cube, | |
position: vector.Vector3(-0.5, 0.5, -3.5), | |
); | |
controller.addArCoreNode(node); | |
} | |
@override | |
void dispose() { | |
arCoreController.dispose(); | |
super.dispose(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment