Giter VIP home page Giter VIP logo

Comments (10)

AdrianAtGoogle avatar AdrianAtGoogle commented on July 26, 2024 4

Hi @alexeyfaradise, thank you for submitting this issue.

  • setTexture() appears to not work: Unfortunately this part of our API is still a little rough; it works but is very easy to get wrong. We're working on a sample to illustrate how to modify material parameters (including textures) at runtime and will improve our error reporting in the next release.
  • Thousands of models w/ multiple permutations how?: The plan here has two parts:
    • The binaries used by the Android Studio plugin will be made available for use in build scripts on server platforms. This will allow you to do a server-side conversion of your assets to .sfb. We'll be releasing a blog post soon on how to do this.
    • The .sfa will get the ability to contain loose textures and materials not explicitly associated with geometry, and .sfa's will be able to declare data dependencies on other .sfa's. This will mean that you can author (and deliver) .sfb's that contain textures/materials (but no geometry) and .sfb's that contain geometry (but no textures/materials), and if they're both available at instantiation time it will just work.

from sceneform-android-sdk.

michaelvogt avatar michaelvogt commented on July 26, 2024 2

@Berenice2018
Excellent, thank you.

from sceneform-android-sdk.

chnouman avatar chnouman commented on July 26, 2024 1

@alexeyfaradise what solution did you used for this problem?

from sceneform-android-sdk.

dsternfeld7 avatar dsternfeld7 commented on July 26, 2024

Hey @alexeyfaradise, can you please post the contents of the .sfa file for the model you are testing with?

You can change the texture of the sample "andy" model at runtime using the following code in HelloSceneformActivity.java:

CompletableFuture<Texture> brickFuture = Texture.builder().setSource(this, R.drawable.bricks).build();
// When you build a Renderable, Sceneform loads its resources in the background while returning
// a CompletableFuture. Call thenAccept(), handle(), or check isDone() before calling get().
ModelRenderable.builder()
    .setSource(this, R.raw.andy)
    .build()
    .thenAcceptBoth(brickFuture, (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;
        });

If your source assets are more complicated, the names of the material parameters could be different. However, those names should match what is in the .sfa file.

from sceneform-android-sdk.

Berenice2018 avatar Berenice2018 commented on July 26, 2024

Hello @dsternfeld7 ,

I would like to change textures on a simple box.obj at runtime. But, I cannot get it working. My cube is red as specified in the sfa file, but the texture is not applied at runtime. Could you give me a hint, please? This would be nice.

I tried the following code:
Sceneform SDK 1.3.0

CompletableFuture<Texture> futureTexture = Texture.builder()
              .setSource(this, R.drawable.ic_launcher)
              .build();

      ModelRenderable.builder()
              .setSource(this, R.raw.box)
              .build()
              .thenAcceptBoth(futureTexture, (renderable, texture) -> {
                boxRenderable = renderable;
                  boxRenderable.getMaterial().setTexture("baseColor", texture);
              })
              .exceptionally(
                      throwable -> {
                          Toast.makeText(this, "Unable to load andy renderable", Toast.LENGTH_LONG).show();
                          return null;
                      });

The box.sfa file looks like:

{
   materials: [
      {
         name: "unlit_material",
         parameters: [
            {
               baseColor: "box",
            },
            {
               baseColorTint: [
                  1,
                  0,
                  0,
                  1,
               ],
            },
            {
               metallic: 1,
            },
            {
               roughness: 1,
            },
            {
               opacity: null,
            },
         ],
         source: "build/sceneform_sdk/default_materials/obj_material.sfm",
      },
   ],
   model: {
      attributes: [
         "Position",
         "TexCoord",
         "Orientation",
      ],
      file: "sampledata/box.obj",
      name: "box",
      suggested_collision: {
         center: {
            x: 0,
            y: 0,
            z: 0,
         },
         size: {
            x: 1,
            y: 1,
            z: 1,
         },
         type: "Box",
      },
   },
   version: "0.51:1",
}

from sceneform-android-sdk.

michaelvogt avatar michaelvogt commented on July 26, 2024

@dsternfeld7
Should your code above also work with a ModelRenderable created with the ShapeFactory?

from sceneform-android-sdk.

Berenice2018 avatar Berenice2018 commented on July 26, 2024

@michaelvogt I tried a texture change on a primitive cube instantiated with ShapeFactory. It is working.
Check the last line of my code snippet here
#197

(Sorry for pasting the link. I am new to GitHub and have not yet found the button to reference a different thread here.)

from sceneform-android-sdk.

harsha-main avatar harsha-main commented on July 26, 2024

@Berenice2018 @AdrianAtGoogle can you please take a look at #448. It seems similar, but I can't understand how the ones discussed here can be applied to there. I'm just beginning to use Sceneform.
Thanks in advance.

from sceneform-android-sdk.

itslonua avatar itslonua commented on July 26, 2024

This feature works ?

from sceneform-android-sdk.

Consti10 avatar Consti10 commented on July 26, 2024

To me it looks like setTexture() btw. setMaterial() only work on the renderables created via ShapeFactory

from sceneform-android-sdk.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.