簡體   English   中英

通用3D紋理加載方法

[英]Generic 3D texture loading method

無論如何,是否有使用C#和XNA創建一種可以調用並加載3D模型並顯示它的方法? (換句話說,通用3D Tmodel加載方法和通用3D模型顯示方法)。 而不是為每個3D模型使用長代碼? 例如,不是所有的長代碼都有一個方法,該方法的加載代碼需要兩個爭論(3DModelName,fileLocation),然后有一個方法,其中的所有3D繪圖代碼都需要兩個爭論(3DModelName,Location)。 這可能嗎? 提前致謝。

不知道我是否能完全理解您的要求,但是以下內容是非常標准的Xna,並且它盡可能簡短。

在Xna中,文件位置實際上是無關緊要的。 您只需在解決方案資源管理器中將文件(fbx或x)添加到內容項目中,而無需擔心代碼中的文件位置。

//in the fields section of some class
Model myModel;

//in an initialization or loadContent method of the same class
myModel = LoadMyModel(name, Content);

//load & draw methods that can be called any time as long as they are in scope
Model LoadMyModel(string name, ContentManager content)
{
  return content.Load<Model>(name);
}

void DrawModel(Model myModel, Matrix worldTransform, Matrix view, Matrix projection)
{
   myModel.Draw(worldTransform, view, projection);
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM