ARCore – Is there any event for asset changed position/orientation?











up vote
5
down vote

favorite
1












I am new to creating AR app using ARCore and Sceneform for Android (Java). I am building a multiplayer app using cloud anchors where two or more people can interact on one or more asset. When the asset changes it's position, how to get the event to broadcast to other connected users?



Here's my code:



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);
}

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


I have written a separate Socket.io server in NodeJS to broadcast the Short hand GUID to other connected nodes to download and resolve the asset at launch of the app. It works fine when I am rendering the asset for the first time. But I am not sure how to handle when one person moves that asset. I want it to render it other connected devices. I could not find any event to asset changed so that I could attach my code to it.










share|improve this question
























  • Do you have any code so far? Please add it to your question by editing it.
    – jrswgtr
    Aug 31 at 13:11










  • @jrswgtr I have added my code there.
    – Gaurav Verma
    Sep 2 at 17:58















up vote
5
down vote

favorite
1












I am new to creating AR app using ARCore and Sceneform for Android (Java). I am building a multiplayer app using cloud anchors where two or more people can interact on one or more asset. When the asset changes it's position, how to get the event to broadcast to other connected users?



Here's my code:



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);
}

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


I have written a separate Socket.io server in NodeJS to broadcast the Short hand GUID to other connected nodes to download and resolve the asset at launch of the app. It works fine when I am rendering the asset for the first time. But I am not sure how to handle when one person moves that asset. I want it to render it other connected devices. I could not find any event to asset changed so that I could attach my code to it.










share|improve this question
























  • Do you have any code so far? Please add it to your question by editing it.
    – jrswgtr
    Aug 31 at 13:11










  • @jrswgtr I have added my code there.
    – Gaurav Verma
    Sep 2 at 17:58













up vote
5
down vote

favorite
1









up vote
5
down vote

favorite
1






1





I am new to creating AR app using ARCore and Sceneform for Android (Java). I am building a multiplayer app using cloud anchors where two or more people can interact on one or more asset. When the asset changes it's position, how to get the event to broadcast to other connected users?



Here's my code:



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);
}

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


I have written a separate Socket.io server in NodeJS to broadcast the Short hand GUID to other connected nodes to download and resolve the asset at launch of the app. It works fine when I am rendering the asset for the first time. But I am not sure how to handle when one person moves that asset. I want it to render it other connected devices. I could not find any event to asset changed so that I could attach my code to it.










share|improve this question















I am new to creating AR app using ARCore and Sceneform for Android (Java). I am building a multiplayer app using cloud anchors where two or more people can interact on one or more asset. When the asset changes it's position, how to get the event to broadcast to other connected users?



Here's my code:



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);
}

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


I have written a separate Socket.io server in NodeJS to broadcast the Short hand GUID to other connected nodes to download and resolve the asset at launch of the app. It works fine when I am rendering the asset for the first time. But I am not sure how to handle when one person moves that asset. I want it to render it other connected devices. I could not find any event to asset changed so that I could attach my code to it.







android multiplayer arcore sceneform






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 9 at 17:26









ARGeo

5,04052147




5,04052147










asked Aug 31 at 13:09









Gaurav Verma

263




263












  • Do you have any code so far? Please add it to your question by editing it.
    – jrswgtr
    Aug 31 at 13:11










  • @jrswgtr I have added my code there.
    – Gaurav Verma
    Sep 2 at 17:58


















  • Do you have any code so far? Please add it to your question by editing it.
    – jrswgtr
    Aug 31 at 13:11










  • @jrswgtr I have added my code there.
    – Gaurav Verma
    Sep 2 at 17:58
















Do you have any code so far? Please add it to your question by editing it.
– jrswgtr
Aug 31 at 13:11




Do you have any code so far? Please add it to your question by editing it.
– jrswgtr
Aug 31 at 13:11












@jrswgtr I have added my code there.
– Gaurav Verma
Sep 2 at 17:58




@jrswgtr I have added my code there.
– Gaurav Verma
Sep 2 at 17:58

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f52116197%2farcore-is-there-any-event-for-asset-changed-position-orientation%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f52116197%2farcore-is-there-any-event-for-asset-changed-position-orientation%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

Xamarin.form Move up view when keyboard appear

Post-Redirect-Get with Spring WebFlux and Thymeleaf

Anylogic : not able to use stopDelay()