How to load ModelRenderable.builder() with multiple model?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



How to load ModelRenderable.builder() with multiple model?



I'm not sure how to load model into array for below code. All i can do it load a single model in a single ModelRenderable.builder(). but not for multiple model in same ModelRenderable.builder(). I appreciate if any one can help me with that.


ModelRenderable.builder()


ModelRenderable.builder()


ModelRenderable.builder()
.setSource(this, Uri.parse("https://unembittered-vector.000webhostapp.com/3dmodels/andy.sfb") )
.setRegistryId(1)
.build()
.thenAccept(renderable -> andyRenderable = renderable)
.exceptionally(
throwable ->
Toast toast =
Toast.makeText(this, "Unable to load andy renderable", Toast.LENGTH_LONG);
toast.setGravity(Gravity.CENTER, 0, 0);
toast.show();
return null;
);
ModelRenderable.builder()
.setSource(this, Uri.parse("https://unembittered-vector.000webhostapp.com/3dmodels/scene.sfb") )

.build()
.thenAccept(renderable -> andyRenderable1 = renderable)
.exceptionally(
throwable ->
Toast toast =
Toast.makeText(this, "Unable to load andy renderable", Toast.LENGTH_LONG);
toast.setGravity(Gravity.CENTER, 0, 0);
toast.show();
return null;
);
ModelRenderable.builder()
.setSource(this, Uri.parse("https://unembittered-vector.000webhostapp.com/3dmodels/shoes.sfb"))

.build()
.thenAccept(renderable -> andyRenderable2 = renderable)
.exceptionally(
throwable ->
Toast toast =
Toast.makeText(this, "Unable to load andy renderable", Toast.LENGTH_LONG);
toast.setGravity(Gravity.CENTER, 0, 0);
toast.show();
return null;
);



here andyrenderable is called to load into an anchor


Anchor anchor = hitResult.createAnchor();
AnchorNode anchorNode = new AnchorNode(anchor);
anchorNode.setParent(arFragment.getArSceneView().getScene());
TransformableNode andy = new TransformableNode(arFragment.getTransformationSystem());
andy.setParent(anchorNode);
andy.setRenderable(andyRenderable);

andy.select();



what i can do is , i can load model from Uri but i need to load model in same ModelRenderable.builder() as an array for other models too


ModelRenderable.builder()





Help me to undestand better. Why you wanna load more models in the same builder? What result are you expecting? Why not call this functions in loop?
– Canato
Aug 9 at 8:00





sorry my bad. I fixed this issue. Other thing is can we do something with this ModelRenderable.builder().setSource(this,"url") with custom texture ?
– Rikesh Shrestha
Aug 9 at 10:22





Sorry @Rikesh I still didn't know why you wanna load more models in the same builder. What are you expecting to see in your screen?
– Canato
Aug 9 at 11:06





i want to change multiple texture inside same builder. @canat
– Rikesh Shrestha
Aug 10 at 5:19




3 Answers
3



Try this


List<RederableDefinition.Submesh> submeshes = new List<>;
submeshes.add(new RenderableDefinition.Submesh.setMaterial(Material material).setName(String name).setTriangleIndices(List<Integer> triangleIndices).build());

RenderableDefinition definition = new RenderableDefinition.setSubmeshes(submeshes).builder();
ModelRenderable.setSource(definition).build();



To be real I don't know exactly what expected from this, but Submeshes are the material (I hope what you mean by texture) and it is the only parameter that can be a list in a ModelRenderable.



A part from this your code look like you are trying to put 3 3D models on the same Model. Like draw 3 of them on the same place, would look weird and they would be one above another.
If you wanna give Andy shoes and maybe a background you need to make this already on a 3D models before or put then in different models.





i appreciate for you solution but i want to change texture for a model from outside for sfb model. I saw there was a method inside sfb file which call textures now i want to change the texture from code . THank you
– Rikesh Shrestha
Aug 12 at 4:54





@RikeshShrestha I didn't found the texture method on sfb file. I don't understood how change the Texture Programatically can be related with you main question about load multiple Models on same ModelRenderable.
– Canato
Aug 13 at 11:02






@Canto i m able to change the texture in ModleRenderable . I m sharing the code
– Rikesh Shrestha
Aug 14 at 4:22



Inspired by sceneform solarsystem sample, my untested solution would be:


String uris =
"https://unembittered-vector.000webhostapp.com/3dmodels/andy.sfb",
...
"https://unembittered-vector.000webhostapp.com/3dmodels/shoes.sfb"
;
CompletableFuture<ModelRenderable> mrs = new CompletableFuture<ModelRenderable>[uris.length];

for(int u = 0; u < uris.length; u++)
mrs[u] = ModelRenderable.builder().setSource(this, Uri.parse(uris[u])).build();

CompletableFuture.allOf(mrs).handle((notUsed, throwable) ->
if (throwable != null)
throwable.printStackTrace();
return null;


try
for(int m = 0; m < mrs.length; m++)
mrs[m].get(); // Do something, frist is andy.sfb, ..., last is shoes.sfb
catch (InterruptedException );





says generic array creation .
– Rikesh Shrestha
Aug 12 at 9:41





Use lists instead of arrays and on CompletableFuture.allOf(mrs) you cast your list to an array.
– ManuelTS
Aug 12 at 18:26


CompletableFuture.allOf(mrs)





can you give me some example on the above code @ManuelTS
– Rikesh Shrestha
Aug 13 at 5:03





Everyone not programming for only a week can alter the above code to lists. You have to do it on your own or at least post code wherein you try it.
– ManuelTS
Aug 13 at 10:18





@Canato, now I get what Rikesh Shrestha wants. But in his own code he uses single ModelRenderable.builder()s that is what lead me to arrays or lists, respectively.
– ManuelTS
Aug 14 at 7:53



ModelRenderable.builder()



changing texture in ModelRenderable using CompletableFuture


CompletableFuture<Texture> futureTexture = Texture.builder()
.setSource(this, Uri.parse(url))
.build();



and call futureTexture in ModelRendrable


ModelRenderable.builder()
.setSource(this, Uri.parse("https://unembittered-vector.000webhostapp.com/3dmodels/andy.sfb"))

.build()
//.thenAccept(renderable -> andyRenderable = renderable)

.thenAcceptBoth(futureTexture, (renderable, texture) ->
andyRenderable = renderable;

andyRenderable.getMaterial().setTexture("baseColor", texture);

)
.exceptionally(
throwable ->
Toast toast =
Toast.makeText(this, "Unable to load andy renderable", Toast.LENGTH_LONG);
toast.setGravity(Gravity.CENTER, 0, 0);
toast.show();
return null;
);



call into Transformable node


TransformableNode andy1 = new TransformableNode(arFragment.getTransformationSystem());
andy1.setParent(anchorNode);
andy1.setRenderable(andyRenderable);
andy1.select();





how this answer is related with the question? The Question is "How to load ModelRenderable.builder() with multiple model?" and you answer is "changing texture in ModelRenderable"
– Canato
Aug 14 at 7:23





its the same thing for model renderable like i used for changing textures by passing through url @Canato
– Rikesh Shrestha
Aug 14 at 8:03






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

How to determine optimal route across keyboard