对模型应用变换而不进行渲染

发布于 2024-12-09 08:52:43 字数 414 浏览 0 评论 0原文

我正在为图形类构建光线追踪器,我们需要做的部分设置是在投射光线之前将模型缩放到世界空间。我已经构建了所需的 worldMatrix。然而,我第一次尝试转换模型的边界框的结果发生了变化,但 VertexBuffer 中的任何顶点都没有变化。

这是我的第一次尝试:

foreach (ModelBone b in model.Bones)
{
   // apply the model transforms and the worldMatrix transforms to the bone
   b.Transform = model.Root.Transform * worldMatrix;
}

我也尝试过设置模型网格中的效果值,就像每个模型绘图教程所示的那样,但没有效果。

我应该尝试其他方法来转换模型吗?

I'm working on building a ray tracer for a graphics class, part of the setup we are required to do is to scale the model into world space before casting my rays. I've built out the worldMatrix needed. However my first attempt at transforming results in the Bounding box of the model changing but none of the vertices in the VertexBuffer.

This is my first attempt:

foreach (ModelBone b in model.Bones)
{
   // apply the model transforms and the worldMatrix transforms to the bone
   b.Transform = model.Root.Transform * worldMatrix;
}

I've also tried setting the effect values found in the model meshes like every model drawing tutorial shows, but it is of no avail.

Is there some other way I should be attempting to transform the model?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

最好是你 2024-12-16 08:52:43

b.变换=根*世界;不考虑骨骼本身的任何数据。

可能你需要: b.Transform = root * b * world;

顶点缓冲区中的数据应在游戏/应用程序的整个生命周期中保持不变。发生的情况是,原始(未更改的)顶点数据在每一帧中都会通过您通过效果发送的任何不同的世界矩阵在顶点着色器中重新转换。

通常,它会是这样的:

//class scope fields
Matrix[] modelTransforms;
Matrix worldMatrix;

//in the loadContent method just after loading the model
modelTransforms - new Matrix[model.Bones.Count];
model.CopyAbsoluteTransformsTo(modelTransforms);//this line does what your foreach does but will work on multitiered hierarchy systems

//in the Update methos
worldMatrix = Matrix.CreateScale(scale);
boundingBox.Min *= scale;
boundingBox.Max *= scale
//raycast against the boundingBox here

//in the draw call
eff.World = modelTransforms[mesh.ParentBone.Index] * worldMatrix;

b.Transform = root * world; doesn't take into account any data in the bone itself.

possibly you need: b.Transform = root * b * world;

The data in the vertex buffer should remain unchanged throughout the life of the game/app. What happens is that the original (unchanged) vertex data gets transformed in the vertex shader each frame anew by whatever different world matrix you send it through the effect.

Typically, it would go something like this:

//class scope fields
Matrix[] modelTransforms;
Matrix worldMatrix;

//in the loadContent method just after loading the model
modelTransforms - new Matrix[model.Bones.Count];
model.CopyAbsoluteTransformsTo(modelTransforms);//this line does what your foreach does but will work on multitiered hierarchy systems

//in the Update methos
worldMatrix = Matrix.CreateScale(scale);
boundingBox.Min *= scale;
boundingBox.Max *= scale
//raycast against the boundingBox here

//in the draw call
eff.World = modelTransforms[mesh.ParentBone.Index] * worldMatrix;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文