xamarin / XamarinComponents

Plugins for Xamarin
MIT License
1.99k stars 694 forks source link

Android ARCore animation start problem #1315

Open windofny1 opened 2 years ago

windofny1 commented 2 years ago

Hi! I faced a problem with starting animation for loaded .sdf file.

It's loaded using this peace of code:

            var builder = ModelRenderable.InvokeBuilder();
            var javaClass = Java.Lang.Class.FromType(builder.GetType());
            var methods = javaClass.GetMethods();
            var method = methods[11];
            method.Invoke(builder, Platform.CurrentActivity, Resource.Raw.CoinModel);
            builder.Build((m) =>
            { 
                if (m.AnimationDataCount > 0)
                {
                    var d = m.GetAnimationData(0);  
                    ModelAnimator ma = new ModelAnimator(d, m); 
                    ma.Start();

                }
            });

SFB file contains only one animation - and it's exist - m.AnimationDataCount==1, but when Start method called - there is exception rised: Java.Lang.IllegalStateException: 'Cannot cast 'com.google.ar.sceneform.rendering.AnimationData$1$1' to
'com.google.ar.sceneform.animation.ModelAnimationData'

Why 'com.google.ar.sceneform.animation.ModelAnimationData' ? In Java ModelAnimationData is inside 'com.google.ar.sceneform.rendering', in .NET also right: [Register("getAnimationData", "(I)Lcom/google/ar/sceneform/rendering/AnimationData;", "GetGetAnimationData_IHandler")] public virtual AnimationData GetAnimationData(int index);

Maybe anybody faced this problem too ?

Xamarin.Android.SceneForm.Animation 1.17.1

windofny1 commented 2 years ago

Also, if try to load .glb file, then it's can not find any animation m.AnimationDataCount==0

   var builder = ModelRenderable.InvokeBuilder();
            var javaClass = Java.Lang.Class.FromType(builder.GetType()); 
            var methods = javaClass.GetMethods();
            var model = RenderableSource
                .InvokeBuilder()
                .SetSource(Platform.CurrentActivity, Android.Net.Uri.Parse(path), RenderableSource.SourceType.Glb) // Or .gltf
                .Build();  
            var method = methods[13]; 
            var resultingData = method.
              Invoke(builder, Platform.CurrentActivity, model); 
            Node n = new Node()
            {
                LocalPosition = new Google.AR.Sceneform.Math.Vector3(0, 0, 0)
            };  
            builder.Build(m =>
            {
                if (m.AnimationDataCount > 0)
                {         
                    ModelAnimator ma = new ModelAnimator(m.GetAnimationData(0), m);
                    ma.Start();
                }
                n.Renderable = m;  
            }); 
prabakaranr commented 2 years ago

windofny1 I am facing the same issue animation, did you get any solution?

windofny1 commented 2 years ago

I am facing the same issue animation, did you get any solution?

Hi! No, I' didn't find solution for this problem, animation just not working ) Think that maybe we must look at Unity for Augmented reality or wait for MAUI resolve this problem. If You are interesting in this theme at time of working on this project I'am created two videos about this, maybe it help with some things: https://youtu.be/tnPFNXws0WE https://youtu.be/Um759k2gHko