【问题标题】:Applying transformation to model without rendering将变换应用于模型而不进行渲染
【发布时间】:2011-10-10 20:03:33
【问题描述】:

我正在为图形类构建光线追踪器,我们需要做的部分设置是在投射光线之前将模型缩放到世界空间。我已经构建了所需的 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;
}

我也尝试过设置模型网格中的效果值,就像每个模型绘图教程显示的那样,但这无济于事。

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

【问题讨论】:

    标签: c# xna raytracing


    【解决方案1】:

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

    可能你需要: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;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-12-10
      • 1970-01-01
      • 2015-11-08
      • 2019-11-12
      • 2021-10-22
      • 1970-01-01
      相关资源
      最近更新 更多