ARCore –是否有资产变更头寸/方向的事件?

时间:2018-08-31 13:09:50

标签: android multiplayer arcore sceneform

我是刚开始使用ARCore和Sceneform for Android(Java)创建AR应用程序。我正在使用云锚构建一个多人游戏应用,其中两个或两个以上的人可以在一个或多个资产上进行交互。当资产更改位置时,如何使事件广播到其他已连接的用户?

这是我的代码:

private AppAnchorState appAnchorState = AppAnchorState.NONE;

private SnackbarHelper snackbarHelper = new SnackbarHelper();

private StorageManager storageManager;

private Socket mSocket;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    /******************* Here **************************/
    // connect to socket

    mSocket = new ArSync().onCreate();
    mSocket.connect();
    // listen for change event

    mSocket.on("modelChanged", new Emitter.Listener() {
        @Override
        public void call(final Object... args) {
            MainActivity.this.runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    //TODO: call the application to load reslove by number
                    //textView.setText("Current ID is :" + 
                      args[0].toString());
                    Log.d("Triggered", args[0].toString());
                    onResolveOkPressed(args[0].toString());

                }
                        });
    }
});

fragment = (CustomArFragment) getSupportFragmentManager().findFragmentById(R.id.sceneform_fragment);
//To add
fragment.getPlaneDiscoveryController().hide();
fragment.getArSceneView().getScene().setOnUpdateListener(this::onUpdateFrame);

Button clearButton = findViewById(R.id.clear_button);
clearButton.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
        setCloudAnchor(null);
    }
});


Button resolveButton = findViewById(R.id.resolve_button);
resolveButton.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
        if (cloudAnchor != null){
            snackbarHelper.showMessageWithDismiss(getParent(), "Please clear Anchor");
            return;
        }
        ResolveDialogFragment dialog = new ResolveDialogFragment();
        dialog.setOkListener(MainActivity.this::onResolveOkPressed);
        dialog.show(getSupportFragmentManager(), "Resolve");

    }
});


fragment.setOnTapArPlaneListener(
        (HitResult hitResult, Plane plane, MotionEvent motionEvent) -> {

            if (plane.getType() != Plane.Type.HORIZONTAL_UPWARD_FACING ||
                    appAnchorState != AppAnchorState.NONE){
                return;
            }

            Anchor newAnchor = fragment.getArSceneView().getSession().hostCloudAnchor(hitResult.createAnchor());

            setCloudAnchor(newAnchor);

            appAnchorState = AppAnchorState.HOSTING;
            snackbarHelper.showMessage(this, "Now hosting anchor...");


            placeObject(fragment, cloudAnchor, Uri.parse("Fox.sfb"));

        }
);

storageManager = new StorageManager(this);
}

/*.....
.......
....... 
*/

我已经在Socket.io中编写了一个单独的NodeJS服务器,以便将简捷GUID广播到其他连接的节点,以便在启动应用程序时下载并解析资产。当我第一次渲染资产时,它工作正常。但是我不确定一个人转移资产时该如何处理。我想让它渲染其他连接的设备。我找不到任何资产更改事件,因此可以将代码附加到该事件。

0 个答案:

没有答案