- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在 XNA 中使用带有自定义着色器的标准 .fbx 导入器。当我使用 BasicEffect 时,.fbx 模型被 UV 正确包裹并且纹理正确。但是,当我使用我的自定义效果时,我必须将纹理作为参数加载,但它没有正确映射。
问题:1) 如何使用包含的纹理坐标和自定义效果正确地纹理我的 .fbx 模型? 2) 有没有办法从加载的 .fbx 模型对象访问纹理?这个纹理去哪里了?
注意:我已经研究了自定义内容管道,并且不相信编写我自己的 Fbx 导入器/处理器会有效率。但是,如果有人可以描述性地向我提供这就是答案的第一手经验,那么我将使用自定义管道。
感谢您抽空阅读这篇文章。
最佳答案
这是一个老问题,但我昨天不得不自己解决这个问题,所以我想我会发布一个后续问题:
如果您使用默认的 FBX 内容处理器并将 DefaultEffect
属性设置为 BasicEffect
,您可以获得 Texture2D
对象通过:
texture = ((BasicEffect)model.Meshes[0].Effects[0]).Texture;
请注意,模型中的每个网格可能具有不同的纹理。
纹理坐标与位置等一起存储在MeshPart
的VertexBuffer
中。我看到了两个顶点声明。对于使用单个纹理(3DS Max 中的位图 Material )的模型/网格,顶点声明为 VertexPositionNormalTexture
。
对于具有两个纹理(位图和不透明度/alpha 贴图)的模型,声明包含以下元素:
Position
Normal
Texture (usage index 0)
Texture (usage index 1)
或者,包装到一个IVertexType
结构中,
public struct VertexPositionNormalTextureTexture : IVertexType
{
public Vector3 Position;
public Vector3 Normal;
public Vector4 Texture0;
public Vector4 Texture1;
public static VertexDeclaration VertexDeclaration
{
get
{
return new VertexDeclaration
(
new VertexElement(0,VertexElementFormat.Vector3, VertexElementUsage.Position, 0)
,
new VertexElement(0,VertexElementFormat.Vector3, VertexElementUsage.Normal, 0)
,
new VertexElement(0,VertexElementFormat.Vector3, VertexElementUsage.TextureCoordinate, 0)
,
new VertexElement(0,VertexElementFormat.Vector3, VertexElementUsage.TextureCoordinate, 1)
);
}
}
VertexDeclaration IVertexType.VertexDeclaration
{
get { return VertexDeclaration; }
}
}
和等效的 HLSL 结构:
struct VertexPositionNormalTextureTexture
{
float3 Position : POSITION0;
float3 Normal : NORMAL0;
float4 Texture0 : TEXCOORD0;
float4 Texture1 : TEXCOORD1;
};
请注意,我将 .Position
和 .Normal
从 Vector4
和 Vector3
更改为 float4
和 float3
在我发布之前,还没有测试过。它们可能需要改回 Vector4
和 float4
。
当然,您需要在像素着色器中使用采样器和一些基本逻辑来读取每个纹理。假设您已将两个效果参数 xTexture0 和 xTexture1 设置为包含颜色纹理和不透明度贴图的 Texture2D
对象,
// texture sampler
sampler Sampler0 = sampler_state
{
Texture = (xTexture0);
};
sampler Sampler1 = sampler_state
{
Texture = (xTexture1);
};
这是一个简单的双纹理像素着色器。如果您只想要一个纹理,只需从第一个采样器读取并返回值,或应用光照等。
float4 TwoTexturePixelShader(VertexPositionNormalTextureTexture input) : COLOR0
{
float4 texel0;
float4 texel1;
float4 pixel;
// check global effect parameter to see if we want textures turned on
// (useful for debugging geometry weirdness)
if (TexturesEnabled)
{
texel0 = tex2D(Sampler0, input.Texture0);
texel1 = tex2D(Sampler1, input.Texture1);
/// Assume texel1 is an alpha map, so just multiple texel0 by that alpha.
pixel.rgb=texel0.rgb;
pixel.a=texel0.a;
}
else
/// return 100% green
pixel = float4(0,1,0,1);
return pixel;
}
这里的相关点是纹理坐标已经存在于 FBX 中并且已经存储在每个 MeshPart
的 VertexBuffer
中,因此您需要做的就是提取纹理,将其作为全局效果参数传递到着色器中,然后照常进行。
关于XNA .Fbx 纹理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1765779/
FBX SDK 2016.0 默认写入新格式的 FBX 文件,与之前的 SDK 版本不兼容。自述文件中有关于它的说明: Updated file format to 7.5 (compatible w
我正在学习 BabylonJS。 如何将 3D 模型添加到现有的 BabylonJS 场景中?我有一个建筑物的场景,我想在建筑物内部添加一架三角钢琴。钢琴是 OBJ 和 FBX 形式的 3d 模型。
我正在处理一个 OpenGLES2 项目 (iOS),我必须在其中将场景/模型导出为 FBX 格式,以便可以使用 FBX 审查应用程序打开它。我已经弥补了模型加载的地步,法线和 Material 工作
我在尝试使用 fbx sdk 从 fbx 文件中获取信息时遇到了困难。我在 Maya 中创建了一个带有纹理的 fbx 模型。我想要做的就是在代码中找到所用纹理的完整文件名... 这里是一些代码: vo
我试图找到一些 Autodesk Python FBX SDK 的文档,但它似乎只适用于 C++ ( http://help.autodesk.com/view/FBX/2015/ENU/?guid=
我有一个动物行走的十帧 .fbx 文件。该文件包括一个带有纹理的装配模型,但我只对每一帧的模型网格感兴趣。 如何使用 Python FBX SDK 或 Python Blender SDK 将 fbx
我做了很多测试以在运行时统一导入 FBX,我正在测试更多。 FBX 文件在导入时必须是 ASCII 格式。它需要从 3dsMax 或 Maya 导出为 ASCII。 ASCII FBX 文件的大小取决
我有使用 3D Studio Max 创建的模型。 当我另存为 .FBX 并导入到 Unity 3D 时,它们变成灰色。这是什么原因,我该如何解决? 此外,我在移动设备上的模型性能方面遇到了很大的麻烦
我有使用 3D Studio Max 创建的模型。 当我另存为 .FBX 并导入到 Unity 3D 时,它们变成灰色。这是什么原因,我该如何解决? 此外,我在移动设备上的模型性能方面遇到了很大的麻烦
我在 XNA 中使用带有自定义着色器的标准 .fbx 导入器。当我使用 BasicEffect 时,.fbx 模型被 UV 正确包裹并且纹理正确。但是,当我使用我的自定义效果时,我必须将纹理作为参数加
我正在尝试从 fbx 文件加载汽车模型,其中一个模型分为 5 个子模型。 4 个子模型是车轮,1 个子模型是汽车。 起初,当我尝试渲染它时,我只看到一个轮子,所以我开始对框架进行诊断。 我意识到所有的
由于我在 XNA 中制作游戏时模型用完了,所以我尝试制作自己的模型。但是有一个问题 - 当我制作 .fbx 模型,通过 blender 添加纹理,做 uv 映射,然后将此模型应用于我的 XNA 项目时
我使用 Notepad++ 来查看FBX模型的数据结构,但我在理解它时遇到了一些问题。这是位于 (0,0,0) 的立方体(边 = 10)的一些信息,谁能告诉我这些成员是什么意思?谢谢! Vertice
我正在使用 Pycharm 使用 Python FBX SDK 进行编码,但我不知道如何启用自动完成。我必须查看函数成员的文档。这很乏味。那么,有谁知道如何在编辑器中为 Python FBX SDK
我想读取 FBX 二进制格式,但我不想使用 Autodesk 的 FBX sdk。 谁知道fbx二进制文件格式的网站请指教 最佳答案 根据维基百科 - http://en.wikipedia.org/
不太确定问题出在哪里。我在 Blender 中有一个看起来像这样的模型: 我把它全部贴上了 UV 等等——蓝色突出显示的边缘来自透明的 .png 纹理。这是节点编辑器: 现在,当我按照 LibGDX
我必须验证 html 字段,其中只能上传 .fbx 文件,但 javascript 无法识别此 MIME-TYPE (它返回一个空字符串),有什么办法可以做到吗? 这就是我得到的: lastModi
我正在为我们的小型游戏引擎编写一个 fbx 转换器。我坚持使用动画渲染模型。每个时间戳的矩阵看起来都不错,当我只渲染骨骼时,它看起来也像原始动画。我做了一些快照来显示我的问题。我只是不知道出了什么问题
我有一个在 Maya 中添加了自定义属性的 FBX 文件。使用 FBX SDK,我正在尝试加载网格并检索这些属性。 我有: FbxNode* lRootNode = lScene->GetRootNo
3DS MAX 为可以放置任意文本的节点提供用户定义的字段。 如何使用 FBX SDK 检索此文本?我在文档中找不到任何答案。 最佳答案 FBX ASCII 表示有很大帮助。用户定义的属性存储在“UD
我是一名优秀的程序员,十分优秀!