如何在' pygltflib中添加颜色定义。 Python库到3D三角网格?
以下示例使用任意三角定义(顶点和连接矩阵)生成一个3D对象。 https:https:// gitlab。 com/dodgyville/pygltflib#create-a-mesh-convert-bytes-convert-convert-convert-back-to-mesh
我如何将自定义颜色设置为顶点?
MATLAB示例代码带有颜色定义的顶点:
example.POSITION = [0 0 0; 1 0 0; 1 1 0; 0 1 0; 0 0 1; 1 0 1; 1 1 1; 0 1 1];
example.indices = [1 4 2; 4 3 2; 3 7 2; 7 6 2; 3 4 7; 4 8 7; 8 5 7; 5 6 7; 5 2 6; 5 1 2; 1 5 4; 5 8 4];
example.COLOR_0 = [1 0 0; 0.5 0.5 0.5; 0.5 0.5 0.5; 0.5 0.5 0.5; 0.5 0.5 0.5; 0.5 0.5 0.5; 0 1 0; 0.5 0.5 0.5];
example.prop.material.pbrMetallicRoughness.baseColorFactor = [0.7 0.7 1 0.5];
example.prop.material.pbrMetallicRoughness.metallicFactor = 1;
example.prop.material.pbrMetallicRoughness.roughnessFactor = 0.1;
example.prop.material.alphaMode = 'BLEND';
example.prop.material.doubleSided = true;
write_glb('example.glb', example);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于顶点上的颜色,您需要将其定义为每个顶点的RGB矢量,类似于
pygltflib in 的每个顶点的x,y,z
,我创建了一个示例代码来创建<<代码> gltf 使用
pygltflib
文件,如下所示。我将
wavefront
obj带到gltf
转换代码来自在这里并将其调整为您的用例和数据
For color on vertex, you need to define it as a RGB vector for each vertex, similar to x,y,z for each vertex in
pygltflib
For your data, I created a sample code to create a
gltf
file usingpygltflib
as shown below.I took the
wavefront
obj togltf
conversion code from hereand tweaked it to your use case and data