Changing Textures of Object in AR core in runtime

南楼画角 提交于 2020-06-25 05:37:10

问题


I am creating an app where I need to change textures(pattern) of my 3d object. I am using AR Core SDK and android. I have used the below code but it is not working.

Texture.builder()
                .setSource(this,R.drawable.fabric3)
                .build()
                .thenAccept(t -> {
                    BaseTransformableNode node =
                            arFragment.getTransformationSystem().getSelectedNode();
                    if(node!=null){
                        node.getRenderable().getMaterial().setTexture("baseColorMap",t);

                    }
                }); 

Documentation is also not helping me much. This is my SFA file

{
  animations: [
    {
      clips: [
        {
          name: 'Take 001',
          runtime_name: 'cylinder',
        },
      ],
      path: 'sampledata/models/cylinder.fbx',
    },
  ],
  materials: [
    {
      name: 'Blue',
      parameters: [
        {
          baseColor: [
            1,
            1,
            1,
            1,
          ],
        },
        {
          baseColorMap: 'fabric2',
        },
        {
          normalMap: null,
        },
        {
          interpolatedColor: null,
        },
        {
          metallic: 0,
        },
        {
          metallicMap: null,
        },
        {
          roughness: 1,
        },
        {
          roughnessMap: null,
        },
        {
          opacity: null,
        },
      ],
      source: 'build/sceneform_sdk/default_materials/fbx_material.sfm',
    },
    {
      name: 'Black',
      parameters: [
        {
          baseColor: [
            1,
            1,
            1,
            1,
          ],
        },
        {
          baseColorMap: 'fabric3',
        },
        {
          normalMap: null,
        },
        {
          interpolatedColor: null,
        },
        {
          metallic: 0,
        },
        {
          metallicMap: null,
        },
        {
          roughness: 1,
        },
        {
          roughnessMap: null,
        },
        {
          opacity: null,
        },
      ],
      source: 'build/sceneform_sdk/default_materials/fbx_material.sfm',
    },
  ],
  model: {
    attributes: [
      'Position',
      'TexCoord',
      'Orientation',
      'BoneIndices',
      'BoneWeights',
    ],
    collision: {},
    file: 'sampledata/models/cylinder.fbx',
    name: 'cylinder',
    recenter: 'root',
  },
  samplers: [
    {
      file: 'sampledata/models\\cylinder.fbm\\fabric2.jpg',
      name: 'fabric2',
      pipeline_name: 'cylinder.fbm\\fabric2.jpg',
    },
    {
      file: 'sampledata/models\\cylinder.fbm\\fabric3.jpg',
      name: 'fabric3',
      pipeline_name: 'cylinder.fbm\\fabric3.jpg',
    },
  ],
  version: '0.54:2',
}

I have 2 textures fabric 2 and 3 i want to change texture from fabric 2 to fabric 3 when a button is clicked. I am using .fbx files for my 3d models.

来源:https://stackoverflow.com/questions/59389203/changing-textures-of-object-in-ar-core-in-runtime

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!