Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Null safety, Gradle issue in running #190

Open
wants to merge 7 commits into
base: null-safety
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion android/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<!-- Indicates that app requires ARCore ("AR Required"). Causes Google
Play Store to download and install ARCore when the app is installed.
-->
<meta-data android:name="com.google.ar.core" android:value="optional" />
<meta-data android:name="com.google.ar.core" android:value="required" />
</application>

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@ import android.app.Activity
import android.content.Context
import android.graphics.Bitmap
import android.graphics.BitmapFactory
import android.graphics.Color
import android.util.Log
import android.util.Pair
import android.view.GestureDetector
import android.view.MotionEvent
import com.difrancescogianmarco.arcore_flutter_plugin.flutter_models.FlutterArCoreHitTestResult
import com.difrancescogianmarco.arcore_flutter_plugin.flutter_models.FlutterArCoreNode
import com.difrancescogianmarco.arcore_flutter_plugin.flutter_models.FlutterArCorePose
import com.difrancescogianmarco.arcore_flutter_plugin.utils.ArCoreUtils
Expand All @@ -25,6 +29,7 @@ import java.io.IOException
import java.util.*
import com.google.ar.core.exceptions.*
import com.google.ar.core.*
import com.google.ar.sceneform.*
import kotlinx.coroutines.*
import kotlin.coroutines.CoroutineContext

Expand All @@ -36,12 +41,25 @@ class ArCoreAugmentedImagesView(activity: Activity, context: Context, messenger:
// the
// database.
private val augmentedImageMap = HashMap<Int, Pair<AugmentedImage, AnchorNode>>()
private val gestureDetector: GestureDetector

private var job: Job = Job()
override val coroutineContext: CoroutineContext
get() = Dispatchers.Main + job

init {
gestureDetector = GestureDetector(
context,
object : GestureDetector.SimpleOnGestureListener() {
override fun onSingleTapUp(e: MotionEvent): Boolean {
onSingleTap(e)
return true
}

override fun onDown(e: MotionEvent): Boolean {
return true
}
})

sceneUpdateListener = Scene.OnUpdateListener { frameTime ->

Expand Down Expand Up @@ -126,11 +144,35 @@ class ArCoreAugmentedImagesView(activity: Activity, context: Context, messenger:
val maze_edge_size = 492.65f
val max_image_edge = Math.max(image.extentX, image.extentZ)
val maze_scale = max_image_edge / maze_edge_size

// Scale Y extra 10 times to lower the wall of maze
mazeNode.localScale = Vector3(maze_scale, maze_scale * 0.1f, maze_scale)*//*
}*/

private fun onSingleTap(tap: MotionEvent?) {
debugLog(" onSingleTap")
val frame = arSceneView?.arFrame
if (frame != null) {
if (tap != null && frame.camera.trackingState == TrackingState.TRACKING) {
val hitList = frame.hitTest(tap)
val list = ArrayList<HashMap<String, Any>>()
for (hit in hitList) {
val trackable = hit.trackable
if (trackable is Plane && trackable.isPoseInPolygon(hit.hitPose)) {
hit.hitPose
val distance: Float = hit.distance
val translation = hit.hitPose.translation
val rotation = hit.hitPose.rotationQuaternion
val flutterArCoreHitTestResult = FlutterArCoreHitTestResult(distance, translation, rotation)
val arguments = flutterArCoreHitTestResult.toHashMap()
list.add(arguments)
}
}
methodChannel.invokeMethod("onPlaneTap", list)
}
}
}

override fun onMethodCall(call: MethodCall, result: MethodChannel.Result) {
if (isSupportedDevice) {
debugLog( call.method + "called on supported device")
Expand Down Expand Up @@ -171,6 +213,7 @@ class ArCoreAugmentedImagesView(activity: Activity, context: Context, messenger:
debugLog( "inserted ${node?.name}")
if (node != null) {
node.setParent(anchorNode)
arSceneView?.scene?.setLightEstimate(com.google.ar.sceneform.rendering.Color(255F, 255F, 255F), 0.0F)
arSceneView?.scene?.addChild(anchorNode)
result.success(null)
} else if (throwable != null) {
Expand Down Expand Up @@ -211,6 +254,29 @@ class ArCoreAugmentedImagesView(activity: Activity, context: Context, messenger:

private fun arScenViewInit(call: MethodCall, result: MethodChannel.Result) {
arSceneView?.scene?.addOnUpdateListener(sceneUpdateListener)
val enableTapRecognizer: Boolean? = call.argument("enableTapRecognizer")
if (enableTapRecognizer != null && enableTapRecognizer) {
arSceneView
?.scene
?.setOnTouchListener { hitTestResult: HitTestResult, event: MotionEvent? ->

if (hitTestResult.node != null) {
debugLog(" onNodeTap " + hitTestResult.node?.name)
debugLog(hitTestResult.node?.localPosition.toString())
debugLog(hitTestResult.node?.worldPosition.toString())
methodChannel.invokeMethod("onNodeTap", hitTestResult.node?.name)
return@setOnTouchListener true
}
return@setOnTouchListener gestureDetector.onTouchEvent(event)
}
}

val enablePlaneRenderer: Boolean? = call.argument("enablePlaneRenderer")
if (enablePlaneRenderer != null && !enablePlaneRenderer) {
debugLog(" The plane renderer (enablePlaneRenderer) is set to " + enablePlaneRenderer.toString())
arSceneView!!.planeRenderer.isVisible = false
}

onResume()
result.success(null)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ class FlutterArCoreNode(map: HashMap<String, *>) {

val dartType: String = map["dartType"] as String
val name: String = map["name"] as String
val isShadowReceiver: Boolean = false
val isShadowCaster: Boolean = false
val image: FlutterArCoreImage? = createArCoreImage(map["image"] as? HashMap<String, *>)
val objectUrl: String? = map["objectUrl"] as? String
val object3DFileName: String? = map["object3DFileName"] as? String
Expand Down Expand Up @@ -42,6 +44,8 @@ class FlutterArCoreNode(map: HashMap<String, *>) {
node.localPosition = position
node.localScale = scale
node.localRotation = rotation
node.renderable?.isShadowReceiver = isShadowReceiver
node.renderable?.isShadowCaster = isShadowCaster

return node
}
Expand Down
10 changes: 5 additions & 5 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ packages:
path: ".."
relative: true
source: path
version: "0.1.0-null-safety.0"
version: "0.1.0-null-safety.3"
async:
dependency: transitive
description:
name: async
url: "https://pub.dartlang.org"
source: hosted
version: "2.6.1"
version: "2.8.1"
boolean_selector:
dependency: transitive
description:
Expand All @@ -35,7 +35,7 @@ packages:
name: charcode
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.0"
version: "1.3.1"
clock:
dependency: transitive
description:
Expand Down Expand Up @@ -94,7 +94,7 @@ packages:
name: meta
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.0"
version: "1.7.0"
path:
dependency: transitive
description:
Expand Down Expand Up @@ -148,7 +148,7 @@ packages:
name: test_api
url: "https://pub.dartlang.org"
source: hosted
version: "0.3.0"
version: "0.4.2"
typed_data:
dependency: transitive
description:
Expand Down
4 changes: 2 additions & 2 deletions lib/src/arcore_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -154,14 +154,14 @@ class ArCoreController {

addArCoreNodeToAugmentedImage(ArCoreNode node, int index,
{String? parentNodeName}) {
final params = _addParentNodeNameToParams(node.toMap(), parentNodeName!);
final params = _addParentNodeNameToParams(node.toMap(), parentNodeName);
return _channel.invokeMethod(
'attachObjectToAugmentedImage', {'index': index, 'node': params});
}

Future<void> addArCoreNodeWithAnchor(ArCoreNode node,
{String? parentNodeName}) {
final params = _addParentNodeNameToParams(node.toMap(), parentNodeName!);
final params = _addParentNodeNameToParams(node.toMap(), parentNodeName);
if (debug ?? true) {
print(params.toString());
}
Expand Down