viromedia / virocore

ViroCore cross-platform AR/VR renderer
MIT License
370 stars 108 forks source link

CrosshiarModel first not show #138

Closed wkl-coder closed 6 years ago

wkl-coder commented 6 years ago

private void initARCrossHair(ARScene scene) { if (mCrosshairModel == null) { mCrosshairModel = new Object3D();

        mCrosshairModel.setScale(new Vector(0.175, 0.175, 0.175));
        mCrosshairModel.loadModel(mViroView.getViroContext(), Uri.parse("file:///android_asset/tracking_1.vrx"), Object3D.Type.FBX, new AsyncObject3DListener() {
            @Override
            public void onObject3DLoaded(Object3D object3D, Object3D.Type type) {
                mCrosshairModel.setOpacity(1.0f);

            }

            @Override
            public void onObject3DFailed(String error) {
                Log.e("Viro", " Model load failed : " + error);
            }
        });
    }
    mCrosshairModel.setOpacity(1.0f);
    scene.getRootNode().addChildNode(mCrosshairModel);

}
wkl-coder commented 6 years ago

private class ARHitTestListenerCrossHair implements ARHitTestListener { @Override public void onHitTestFinished(ARHitTestResult[] arHitTestResults) { if (current_state == 0) {

            // If we have found intersected AR Hit points, update views as needed, reset miss count.
            ViroViewARCore viewARView = (ViroViewARCore) mViroView;
            final Vector cameraPos = viewARView.getLastCameraPositionRealtime();

            // Grab the closest ar hit target
            float closestsDistance = Float.MAX_VALUE;
            ARHitTestResult result = null;
            if (arHitTestResults.length > 0) {
                for (int i = 0; i < arHitTestResults.length; i++) {
                    ARHitTestResult currentResult = arHitTestResults[i];

                    float distance = currentResult.getPosition().distance(cameraPos);
                    if (distance < closestsDistance && distance > .3 && distance < 5) {
                        result = currentResult;
                        closestsDistance = distance;
                    }
                }
            }
            // Update the cross hair target location with the closest target.
            if (mCrosshairModel != null ) {
                mCrosshairModel.setOpacity(1.0f);
            }
            Log.i("dddww","a");
            animateCrossHairToPosition(result);

            // Update State based on hit target

            //ToastUtils.showToast(getActivity(),"bbbbbb");
        }
    }

}

private void animateCrossHairToPosition(ARHitTestResult result) {
    if (result == null) {
        if (current_state == 0) {
            if (mCrosshairModel != null) {
                AnimationTransaction.begin();
                AnimationTransaction.setAnimationDuration(70);
                AnimationTransaction.setTimingFunction(AnimationTimingFunction.EaseOut);
                final Vector cameraPos = mViroView.getLastCameraPositionRealtime();

                Vector add = mViroView.getLastCameraForwardRealtime().normalize().add(cameraPos);

                positionRealtime = mViroView.getLastCameraForwardRealtime().normalize().add(cameraPos);

                mCrosshairModel.setPosition(add);
                AnimationTransaction.commit();

            }else {
                initARCrossHair(mScene);
            }
        }

        return;
    }
    if (current_state == 0) {
        if (mCrosshairModel != null) {

            AnimationTransaction.begin();
            AnimationTransaction.setAnimationDuration(70);
            AnimationTransaction.setTimingFunction(AnimationTimingFunction.EaseOut);
            mCrosshairModel.setPosition(result.getPosition());
            mCrosshairModel.setRotationPivot(result.getRotation());
            positionRealtime = result.getPosition();

            AnimationTransaction.commit();

        }
        else {
            initARCrossHair(mScene);
        }
    }

}
wkl-coder commented 6 years ago

when I do this , some time the mCrosshaiModel not show , but the positon is work , can create 3d model

wkl-coder commented 6 years ago

before version okay ,1.7.0 happend this

wkl-coder commented 6 years ago

1.7.1 also

dthian commented 6 years ago

Hey @544531645, thanks for reaching out. Can you please describe what you are trying to achieve with the code above:

If its your own application, to better diagnose the issue, can you please clarify from the above:

  1. When the Cross Hair Model fails to show, are they any hit results returned from the hit test?
  2. When the Cross Hair Model fails to show, is animateCrossHairToPosition() getting called?
  3. Else if animateCrossHairToPosition() is getting called, is result null?
  4. Please explain what is current_state? Is it always equals 0 in the above when the cross hair shows / disappears?
  5. Please share a working code base for your app (you can also email us directly @ support).

Finally, can you show a video recording of the cursor appearing disappearing so that we can verify this visually - ezscreen recorder should do the trick here.

wkl-coder commented 6 years ago

the current_state is my project state , 1. returned , because the animateCroossHaire is used ,if result null , I use lastcamera positioon

  1. when open app I show this , so only show and not show , not frist show then disaapear
dthian commented 6 years ago

Hm that is weird, I've just verified that the ARRetail demo still works with it's animation cross hair code. Can you take a video of the bug you are seeing and send it to us? You can use the free screen recorder app here. Also, would it be possible to send us your project?

dam00n commented 6 years ago

Closing this issue due to inactivity. If you are still having issues, please re-open with the additional information requested. Thanks