- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我一直在尝试使用 ASSIMP 加载 Wavefront obj 模型。但是,我无法让 mtl Material 颜色正常工作 (Kd rgb)
。我知道如何加载,但是,我不知道如何为每个顶点获取相应的颜色。
usemtl material_11
f 7//1 8//1 9//2
f 10//1 11//1 12//2
例如,上面的 Wavefront obj 片段意味着选择的顶点使用 material_11。
问:那么如何获取每个顶点对应的 Material 呢?
Wavefront obj Material 不在正确的顶点:
原始模型(使用 ASSIMP 模型查看器渲染):
使用我的代码渲染的模型:
我用于加载 mtl Material 颜色的代码:
std::vector<color4<float>> colors = std::vector<color4<float>>();
...
for (unsigned int i = 0; i < scene->mNumMeshes; i++)
{
const aiMesh* model = scene->mMeshes[i];
const aiMaterial *mtl = scene->mMaterials[model->mMaterialIndex];
color4<float> color = color4<float>(1.0f, 1.0f, 1.0f, 1.0f);
aiColor4D diffuse;
if (AI_SUCCESS == aiGetMaterialColor(mtl, AI_MATKEY_COLOR_DIFFUSE, &diffuse))
color = color4<float>(diffuse.r, diffuse.g, diffuse.b, diffuse.a);
colors.push_back(color);
...
}
创建顶点的代码:
vertex* vertices_arr = new vertex[positions.size()];
for (unsigned int i = 0; i < positions.size(); i++)
{
vertices_arr[i].SetPosition(positions.at(i));
vertices_arr[i].SetTextureCoordinate(texcoords.at(i));
}
// Code for setting vertices colors (I'm just setting it in ASSIMP vertices order, since I don't know how to set it in the correct order).
for (unsigned int i = 0; i < scene->mNumMeshes; i++)
{
const unsigned int vertices_size = scene->mMeshes[i]->mNumVertices;
for (unsigned int k = 0; k < vertices_size; k++)
{
vertices_arr[k].SetColor(colors.at(i));
}
}
编辑:
看起来模型顶点位置也没有正确加载。即使我禁用面部剔除并更改背景颜色。
最佳答案
忽略与绘制调用次数和额外存储、带宽以及顶点颜色处理相关的问题,
它看起来像 vertex* vertices_arr = new vertex[positions.size()];
是你创建的一个大数组来保存整个模型(它有很多网格,每个网格都有一种 Material ).假设您的第一个循环是正确的并且 positions
包含模型所有网格的所有位置。第二个循环开始为网格内的每个顶点复制网格颜色。但是,vertices_arr[k]
始终从零开始,并且需要在前一个网格的最后一个顶点之后开始。相反,请尝试:
int colIdx = 0;
for (unsigned int i = 0; i < scene->mNumMeshes; i++)
{
const unsigned int vertices_size = scene->mMeshes[i]->mNumVertices;
for (unsigned int k = 0; k < vertices_size; k++)
{
vertices_arr[colIdx++].SetColor(colors.at(i));
}
}
assert(colIdx == positions.size()); //double check
如您所说,如果几何图形未正确绘制,则 positions
可能未包含所有顶点数据。也许与上述代码有类似的问题?另一个问题可能是加入每个网格的索引。这些索引都需要更新为 vertices_arr
数组中新顶点位置的偏移量。虽然现在我只是抛出猜测。
关于c++ - 使用 assimp 加载 mtl 颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27517114/
我试图通过基于现有设计实现我自己的小型库来理解 monad 转换器。 我坚持的是语言扩展。在 MonadError ,唯一提到的扩展名是 UndecidableInstances .但是,如果不使用
我正在尝试使用 Hlist 在 cats mtl 中创建可组合状态类型,并定义了 MonadState 如下 implicit def hlistStateMonad[M[_], S A):M[A]
请给我一些使用 MTL 2 进行矩阵乘法的提示。或任何引用。或 MTL 2 文档的链接。 最佳答案 我们不应该只发布链接,但是给你。在该页面的侧边栏中可以选择文档。 http://www.osl.iu
我正在使用 ModelI/O 来展示 3D 模型。这是我的代码: // Load the .OBJ file guard let url = Bundle.main.url(forResour
我的 .obj 文件旁边有一个 .mtl 文件,它指定了对象的 Material 。我试图创建一个解析器,但不知道“Ke”属性是什么意思。 例如: Ka 0.78 0.78 0.78 Kd 0.78
我正在尝试使用 lwjgl 在 Java 中加载 .obj 文件,而不使用任何库来执行此操作。我创建了一个类来加载没有 Material 和纹理的模型。这很容易。但现在我想为模型添加 Material
我已经从 turbosquid 下载了一个免费模型.它包含一个 obj 和 mtl,以及纹理(高光、凹凸贴图等)。现在我只对 mtl 和 obj 文件感兴趣。所以我下载了一个免费模型from here
快速提问,如何将 .obj 模型加载到 directx 11 (d3d11.h) 以及 Material 的 .mtl 文件中。提前致谢。 最佳答案 您可以编写自己的解析器,obj 是一种非常简单的文
程序如下: #include #include using namespace mtl; int main(int argc, char* argv[]) { dense_vector a(5,1
我目前正在解析与我拥有的 .obj 文件关联的 .mtl 文件。我可以正确渲染模型,但如何使用 .mtl 文件?我应该将它的值发送到哪里?我该如何使用它?目前,在 OpenGL 中找不到任何使用 .m
我是 three.js 的新手,我遇到了这个问题。我对我的脸进行了 3D 扫描,结果只给我 .obj 文件。如果我在 Meshlab 模型上打开该文件,它就会带有颜色。但在我将它加载到 three.j
在加载 MTL 文件时,整个模型都变黑了。我已经引用了这个链接并将 rbg 参数设置为 1 但这并没有解决我的问题。 three.js mtl loader renders black 这是与之相关的
查看 Control.Applicative 的文档,我注意到它们有某些 monad 的实例声明(例如 IO , Maybe 和特别是 ST ),但是没有 MTL monad 的实例,例如 State
正如问题所述,我有一个 obj 文件和一个包含纹理详细信息的 mtl 文件,我想在 mtl 文件上上传一个带有纹理的 obj 文件Forge Viewer,以便它可以显示带有纹理的模型。 我找到了一个
我见过this这篇文章对自由单子(monad)进行了抽象的描述。我也了解 Monad Transformer 是什么,并且我(在某种程度上)了解它们为何有用。 我不知道免费 monad 的用途是什么,
我正在设计一个小游戏,它基本上使用 StateT 并且只是更新状态。以下是简化版本: {-# LANGUAGE TemplateHaskell #-} import Control
我正在按照提出的想法使用 monad-transformers 编写一个小型 DSL这里here .为了illustration 我在这里展示了一小部分。 class Monad m => Proje
因此,即使在示例“webgl_loader_obj_mtl”中,也没有使用环境光。你可以把它注释掉,这没有什么区别。它依赖于定向光。如果注释掉方向,则不会显示任何内容(因为环境不转换颜色)。 有办法解
我一直在尝试使用 ASSIMP 加载 Wavefront obj 模型。但是,我无法让 mtl Material 颜色正常工作 (Kd rgb)。我知道如何加载,但是,我不知道如何为每个顶点获取相应的
我想知道是否有可能确定给定类型是否是原子的(这意味着您可以在没有互斥量的情况下对其执行操作,而不会使自己处于危险之中)。 我想知道是否有一些 atomic(type) 定义可以确定类型是否是原子的。为
我是一名优秀的程序员,十分优秀!