模型不在我的arcore应用程序中呈现吗?

时间:2019-12-27 06:52:07

标签: android arcore

E / ACameraMetadata:getConstEntry:找不到元数据标记65578 E / ACameraMetadata:getConstEntry:找不到元数据标记65578 E / native:hit_test.cc:381generic::internal:没有命中点。 I / native:performance_monitor.cc:115事件:FeatureExtraction花费的时间太长,花费了118.033ms W / native:motion_tracking_context.cc:838generic :: failed_precondition:调用了GetFeatureTracks,但FeatureTracks不可用。

检测到平面,也将模型放置在平面上,但是当我单击“动画”按钮时,它就不会动画。

package com.example.aranimation;

import androidx.appcompat.app.AppCompatActivity;
import android.net.Uri;
import android.os.Bundle;
import android.widget.Button;
import com.google.ar.core.Anchor;
import com.google.ar.sceneform.AnchorNode;
import com.google.ar.sceneform.SkeletonNode;
import com.google.ar.sceneform.animation.ModelAnimator;
import com.google.ar.sceneform.rendering.AnimationData;
import com.google.ar.sceneform.rendering.ModelRenderable;
import com.google.ar.sceneform.ux.ArFragment;

public class MainActivity extends AppCompatActivity {

private ArFragment arFragment;
private ModelAnimator modelAnimator;
private int i = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    arFragment = (ArFragment)getSupportFragmentManager().findFragmentById(R.id.framgment);

    arFragment.setOnTapArPlaneListener((hitResult, plane, motionEvent) -> {
        if (hitResult.getTrackable() != null)
        {
            createModel(hitResult.createAnchor(),arFragment);
        }
    });
}

private void createModel(Anchor anchor, ArFragment arFragment) {

    ModelRenderable.builder()
            .setSource(this, Uri.parse("53_SkeletonSystem_LODa.sfb"))
            .build()
            .thenAccept(modelRenderable -> {

                AnchorNode anchorNode = new AnchorNode(anchor);

                SkeletonNode skeletonNode = new SkeletonNode();
                skeletonNode.setParent(anchorNode);
                skeletonNode.setRenderable(modelRenderable);

                arFragment.getArSceneView().getScene().addChild(anchorNode);

                Button button = findViewById(R.id.button);

                button.setOnClickListener(view -> animateModel(modelRenderable));

            });
}

private void animateModel(ModelRenderable modelRenderable) {

    if(modelAnimator != null && modelAnimator.isRunning())
        modelAnimator.end();

    int animationCount = modelRenderable.getAnimationDataCount();

    if (i == animationCount)
        i = 0;

    AnimationData animationData = modelRenderable.getAnimationData(i);

    modelAnimator = new ModelAnimator(animationData, modelRenderable);
    modelAnimator.start();
    i++;
}

}

0 个答案:

没有答案