【问题标题】:Sceneform assets show no textureSceneform 资产不显示纹理
【发布时间】:2019-11-21 09:25:10
【问题描述】:

screenshot of issue 我正在使用 Sceneform 构建一个非常简单的应用程序,目前它只有一个带有场景视图的活动,我已经添加了一个可渲染的活动。 我想加载我在搅拌机上创建的行星的简单模型,并将其导出为 obj 文件作为可渲染对象。 但是,对象加载并显示,但根本没有纹理或凹凸贴图,它只是灰色。我需要知道我的代码有什么问题导致纹理无法加载。 调试应用程序或 logcat 中的错误时,我没有收到错误消息。

当我使用我在互联网上下载的岩石的 obj 文件时,这工作正常,该对象与其纹理一起显示。 但是,当我开始使用完全相同的过程来导入和显示我在搅拌机上创建的模型并导出为 obj 时,我遇到了这个问题。 我已经检查了我的模型的 mtl、sfb 和 obj 文件中的错误,方法是使用我知道的岩石文件作为参考,尽管除了调用的文件和材料设置之外似乎没有任何区别,我仍然可以'没有让纹理显示在我的模型上。

我还通过使用可完成的未来纹理和 .setTexture() 方法直接在 MainActivity.java 文件中向可渲染对象添加了纹理。 (最后值得注意的是,我尝试导出为 fbx 并遇到同样的问题)

MainActivity.java:

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
CompletableFuture<Texture> merSurFuture = Texture.builder().setSource(this, R.drawable.mercury_global_map).build();
ModelRenderable.builder().setSource(this, Uri.parse("mercuryobj.sfb") )
        .build()
        .thenAcceptBoth(merSurFuture, (renderable, texture )  -> {
            mObjRenderable = renderable;
            mObjRenderable.getMaterial().setTexture("baseColor", texture);
            SceneView sceneView = findViewById(R.id.scene_view);
            sceneView.setBackgroundColor(Color.BLACK);
            Scene scene = sceneView.getScene();

            //adding a node to the sceneview
            Node node = new Node();
            node.setParent(scene);
            node.setName("sun");
            node.setRenderable(renderable);
            node.setLocalPosition(new Vector3(0f,-0.5f,-1f));
        })
        .exceptionally(throwable -> {
            Toast toast = Toast.makeText(this, "unable to load sun", Toast.LENGTH_LONG);
            toast.setGravity(Gravity.CENTER, 0, 0);
            toast.show();
            return null;

        });

mtl 文件:

`# Blender MTL File: 'Mercury.blend'
 # Material Count: 1

 newmtl Material.001
 Ns 96.078431
 Ka 1.000000 1.000000 1.000000
 Kd 0.800000 0.800000 0.800000
Ks 0.000000 0.000000 0.000000
Ke 0.000000 0.000000 0.000000
Ni 1.000000
d 1.000000
illum 1
map_Bump -bm 0.000030 mercury_topo.png
map_Ks Mercury_global_map.png
map_Kd Mercury_global_map.png
map_Ka Mercury_global_map.png

`

obj 文件相关行:

mtllib mercurymtl.mtl
o Mercury_Sphere
...
usemtl Material.001
s 1

sfb 文件:

{
materials: [
{
  name: 'Material.001',
  parameters: [
    {
      baseColor: 'Mercury_global_map',
    },
    {
      baseColorTint: [
        0.80000000000000004,
        0.80000000000000004,
        0.80000000000000004,
        1,
      ],
    },
    {
      metallic: 0,
    },
    {
      roughness: 1,
    },
    {
      opacity: null,
    },
  ],
  source: 'build/sceneform_sdk/default_materials/obj_material.sfm',
},
],
model: {
attributes: [
  'Position',
  'Orientation',
],
collision: {},
file: 'sampledata/mercuryobj.obj',
name: 'mercuryobj',
recenter: 'root',
scale: 0.20496,
},
samplers: [
{
  file: 'sampledata\\Mercury_global_map.png',
  name: 'Mercury_global_map',
  params: {
    usage_type: 'Data',
  },
  pipeline_name: 'Mercury_global_map.png',
 },
],
version: '0.54:2',
}

我希望模型能够加载并显示它的纹理,就像我在线下载的模型一样。 该模型实际上加载完全平滑,完全没有纹理。

【问题讨论】:

  • @JaobGunn 对此有何更新?
  • 你解决了吗?
  • 谢谢!!!你的例子对我帮助很大

标签: android-studio arcore sceneform


【解决方案1】:

这样做:

samplers: [
   {
     file: 'sampledata/Tex_Beagle.png',
     name: 'Tex_Beagle',
     pipeline_name: 'Tex_Beagle.png',
     injections: [
      {usage: "BaseColor",},
    ],
   },
 ],

并在材质参数中应用“Tex_Beagle”作为 baseColor :)

【讨论】:

  • 如果您有任何问题,请随时与我联系
【解决方案2】:

删除“\”这个“/”和ctrl+s再试一次...

改成这样:

samplers: [
   {
     file: 'sampledata/Tex_Beagle.png',
     name: 'Tex_Beagle',
     pipeline_name: 'Tex_Beagle.png',
     injections: [
      {usage: "Normal",},
    ],
   },
 ],

【讨论】:

    【解决方案3】:

    有点晚了,但documentation 声明纹理可能不会自动导入到资源中,在这种情况下,它们应该在 sfa 文件中定义。

    在新转换的 sfa 文件中,您可以在 samplers 数组中添加纹理(图像文件),然后在 injections 块中声明其用法为 Normal(添加详细信息到你的网格)

      samplers: [
       {
         file: 'sampledata\\Tex_Beagle.png',
         name: 'Tex_Beagle',
         pipeline_name: 'Tex_Beagle.png',
         injections: [
          {usage: "Normal",},
        ],
       },
     ],
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-11-08
      • 1970-01-01
      • 1970-01-01
      • 2014-07-10
      • 2015-02-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多