Skip to content
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
1 change: 1 addition & 0 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ android {
}

dependencies {
implementation "com.google.ar.sceneform:animation:1.13.0"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'com.google.ar:core:1.13.0'
Expand Down
4 changes: 1 addition & 3 deletions android/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.difrancescogianmarco.arcore_flutter_plugin">

<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.difrancescogianmarco.arcore_flutter_plugin">
<uses-permission android:name="android.permission.CAMERA" />

<!-- Indicates that app requires ARCore ("AR Required"). Ensures app is only
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class NodeFactory {
RenderableCustomFactory.makeRenderable(context, flutterNode) { renderable, t ->
if (renderable != null) {
node.renderable = renderable
flutterNode.tryAnimation(renderable)
handler(node, null)
}else{
handler(null,t)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ import com.google.ar.core.Pose
import com.google.ar.sceneform.Node
import com.google.ar.sceneform.math.Quaternion
import com.google.ar.sceneform.math.Vector3
import com.google.ar.sceneform.rendering.Renderable
import com.google.ar.sceneform.rendering.ModelRenderable
import com.google.ar.sceneform.rendering.AnimationData
import com.google.ar.sceneform.animation.ModelAnimator

import android.util.Log

class FlutterArCoreNode(map: HashMap<String, *>) {

Expand All @@ -23,6 +29,10 @@ class FlutterArCoreNode(map: HashMap<String, *>) {
?: Quaternion()
val degreesPerSecond: Float? = getDegreesPerSecond((map["degreesPerSecond"] as? Double))
var parentNodeName: String? = map["parentNodeName"] as? String
val animationIndex: Int? = map["animationIndex"] as? Int
val animationName: String? = map["animationName"] as? String
val animationRepeatNb: Int? = map["animationRepeatNb"] as? Int
lateinit var renderable : ModelRenderable

val children: ArrayList<FlutterArCoreNode> = getChildrenFromMap(map["children"] as ArrayList<HashMap<String, *>>)

Expand All @@ -46,6 +56,37 @@ class FlutterArCoreNode(map: HashMap<String, *>) {
return node
}

fun tryAnimation(renderable: Renderable) {
if(renderable != null) {
this.renderable = renderable as ModelRenderable
animate()
}
}

private fun animate() {
val data: AnimationData? = getAnimationData()
if(data != null) {
Log.i("FlutterArCoreNode", "Starting animation "+data.getName())
val animator: ModelAnimator = ModelAnimator(data, renderable)
animator.setRepeatCount(handleAnimNbRepeats())
animator.start()
}
}

private fun getAnimationData(): AnimationData? {
if(animationIndex != null) return renderable.getAnimationData(animationIndex)
if(animationName != null) return renderable.getAnimationData(animationName)
return null
}

private fun handleAnimNbRepeats(): Int {
if(animationRepeatNb != null){
if(animationRepeatNb < ModelAnimator.INFINITE) return ModelAnimator.INFINITE
return animationRepeatNb
}
return 0
}

fun getPosition(): FloatArray {
return floatArrayOf(position.x, position.y, position.z)
}
Expand Down
210 changes: 0 additions & 210 deletions example/pubspec.lock

This file was deleted.

15 changes: 15 additions & 0 deletions lib/src/arcore_reference_node.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@ class ArCoreReferenceNode extends ArCoreNode {
/// Url of gltf object for remote rendering
final String objectUrl;

/// Index of the animation to execute
final int animationIndex;

/// Name of the animation to execute (not handled if animationIndex is not null)
final String animationName;

/// Number of repetition for the animation (-1 for infinite repetition)
final int animationRepeatNb;

ArCoreReferenceNode({
String name,
this.object3DFileName,
Expand All @@ -18,6 +27,9 @@ class ArCoreReferenceNode extends ArCoreNode {
Vector3 position,
Vector3 scale,
Vector4 rotation,
this.animationIndex,
this.animationName,
this.animationRepeatNb,
}) : super(
name: name,
children: children,
Expand All @@ -29,5 +41,8 @@ class ArCoreReferenceNode extends ArCoreNode {
Map<String, dynamic> toMap() => <String, dynamic>{
'object3DFileName': this.object3DFileName,
'objectUrl': this.objectUrl,
'animationIndex': this.animationIndex,
'animationName': this.animationName,
'animationRepeatNb': this.animationRepeatNb,
}..addAll(super.toMap());
}