【问题标题】:Three.js texturing from image in google colab not working as expected谷歌 colab 中图像的 Three.js 纹理未按预期工作
【发布时间】:2022-01-15 11:07:32
【问题描述】:

我正在尝试在 google colab 中使用 Three.js 的 TensorflowGraphics 实现将图像应用到网格,但是当我尝试加载图像时它可以处理修改颜色,但它不起作用而且我不是确定出了什么问题。

代码如下:

context = threejs_visualization.build_context()
default_material = context.THREE.MeshPhongMaterial.new_object({
  'map':context.THREE.ImageUtils.loadTexture(samplesfn + "missing_tex.png")
})
default_material['vertexColors'] = context.THREE.NoColors

mesh["material"] = default_material
_ = threejs_visualization.triangular_mesh_renderer(mesh, width=100, height=100)

threejs_visualization.triangular_mesh_renderer 提供于https://github.com/tensorflow/graphics/blob/master/tensorflow_graphics/notebooks/threejs_visualization.py

我知道问题不在于图像无法正确加载,因为在同一个文件中 openCV 可以加载它。

非常感谢任何帮助。

【问题讨论】:

    标签: three.js google-colaboratory


    【解决方案1】:

    我从未使用过这种语法,但我相信您应该能够通过简单的modifying the .color property 来更改材质颜色,而不是处理顶点颜色:

    default_material = context.THREE.MeshPhongMaterial.new_object({
      'map':context.THREE.ImageUtils.loadTexture(samplesfn + "missing_tex.png"),
      'color': 0xff9900 // Set to orange
    });
    

    如果您要使用map 属性,PhongMaterial 需要被灯光照亮。材料通常不会自己发光,它们需要灯光才能让您看到它们。 See here for a demo of a simple light setup

    如果您希望纹理“发光”而不是反射光,请将纹理设置为 the emmissiveMap property,而不是 map

    【讨论】:

    • 我实际上已经能够正确修改颜色,问题是在使用纹理设置地图时失败
    • 啊,我明白了。您是否在场景中添加了灯光?另外,您是否收到任何控制台错误提示图像无法加载?
    • 我没有添加任何灯光,也不是说图片加载失败
    • 啊,你的问题。您可以添加灯光,或使您的纹理发光。见上文,我扩展了我原来的答案。
    猜你喜欢
    • 1970-01-01
    • 2019-05-28
    • 2016-12-22
    • 1970-01-01
    • 1970-01-01
    • 2014-10-26
    • 1970-01-01
    • 2019-10-24
    • 2019-09-27
    相关资源
    最近更新 更多