XNA的作法是:
RasterizerState.CullCounterClockwise;//CullCounterClockwise 逆時針來畫模型這是GraphicsDevice的預設
1. 右手系座標系統 
2. GraphicsDevice.RasterizerState = RasterizerState.CullCounterClockwise; 逆時針來畫出模型
RasterizerState:
1. CullClockwise 順時針畫模型 A built-in state object with settings for culling primitives with clockwise winding order.
2. CullCounterClockwise 逆時針畫模型 A built-in state object with settings for culling primitives with counter-clockwise winding order.
3. CullNone 背面不剔除 A built-in state object with settings for not culling any primitives.

createps 發表在 痞客邦 留言(0) 人氣()

xna4.0,ps2.0,PC平台使用hlsl定義結構體:
struct VS_INPUT
{
float4 Position : POSITION0;
float2 TexCoord : TEXCOORD0;
float3 Normal : NORMAL0;
float3 Tangent : TANGENT0;
float4 BoneIndices : BLENDINDICES0;
float4 BoneWeights : BLENDWEIGHT0;
}
載入一個簡單的貼圖mesh,調用Bump相關pass時,運行時在
mesh.Draw();
處跳出異常:
The current vertex declaration does not include all the elements required by the current vertex shader. Tangent0 is missing.
問題就在於這個切線數據 Tangent 丟失。
外事不決問google,找到答案。
到Content項目中將默認為false的“Generate Tangent Frames”項目置為true,編譯後約多出10%容量,問題解決。
貌似3.1時默認是開啟的,可能因為大多數model不用到切線數據,所以4.0不再默認生成。

createps 發表在 痞客邦 留言(0) 人氣()

XNA頂多支授59個骨架
Skeleton the maximum supported is 59.

createps 發表在 痞客邦 留言(0) 人氣()

用MAX2009輪出2006.11版月的FBX
注意事項:
1.路徑全都要英文。
2.材質貼圖路徑用相對位置。在FBX檔案裡面直接改,可以用筆記本打開改,所以在存檔的時候必須選擇用Ascii存檔,
打開檔案: 搜尋材質的檔名"cube1.jpg"關鍵字,舉例如下:
    Video: 699166912, "Video::Map #1", "Clip" {
        Type: "Clip"
        Properties70:  {
            P: "Path", "KString", "XRefUrl", "", "D:\cube1.jpg"
        }
        UseMipMap: 0
        Filename: "D:\cube1.jpg"
        RelativeFilename: "cube1.jpg"
    }
改以下三個檔案位置 
  P: "Path", "KString", "XRefUrl", "", "D:\cube1.jpg"
  Filename: "D:\cube1.jpg"
  RelativeFilename: "cube1.jpg"
這個就是材質的位置,路徑要設定在模型的相對位置。
例如:模型放在Modes資料夾底下,材質放在Textures資料夾底下,那上面的路徑就改寫如下:
  P: "Path", "KString", "XRefUrl", "", "..\Textures\cube1.jpg"
  Filename: "..\Textures\cube1.jpg"
  RelativeFilename: "..\Textures\cube1.jpg"
 這樣你的模型應該就抓的到材質了。

createps 發表在 痞客邦 留言(0) 人氣()

 
XNA 3D材質 注意事項
XNA 的3D材質的SIZE要是2的次方,如 2, 4, 8, 16, 32, 64, 128, 256, 512, etc.

createps 發表在 痞客邦 留言(0) 人氣()

方法一:
在渲染模型的時候,設置一下這個參數就可以了:
BasicEffect.Alpha = XXX;
這裡的Alpha是透明度,取值在0-1之間,0是完全透明,1是完全不透明,
foreach (ModelMesh mesh in _model.Meshes)
            {
                foreach (BasicEffect effect in mesh.Effects)
                {
                    if (this.EnableColor)
                    {
                        effect.DiffuseColor = this.Color.ToVector3();
                        effect.Alpha = (float)(this.Color.A) / 255f;
                    }
                    effect.World = this.InnerTransform * this.Transform;
                    effect.View = view;
                    effect.Projection = projection;
                    if (this.EnableLighting)
                    {
                        effect.EnableDefaultLighting();
                    }
                }
                mesh.Draw();
            }

createps 發表在 痞客邦 留言(0) 人氣()

blockPosition.X = MathHelper.Clamp(blockPosition.X,0, Window.ClientBounds.Width - blockTexture.Width);
//這裡的意思是,把方塊的X軸坐標限制在遊戲屏幕之內

createps 發表在 痞客邦 留言(0) 人氣()


3dsMAX導出.FBX骨骼動畫模型到XNA
首先,XNA的素材管道對骨骼動畫並不完全支持,你需要自己擴展素材管道添加對骨骼動畫的支持。(素材管道[Content Pipeline]的擴展可在XNA教程中找到,此處不詳細介紹)。 其次,網上下載的支持蒙皮動畫的tutorial工程都是已經擴展素材管道,他們的模型可以正常在XNA中顯示。 最後,要將自己在MAX中做的骨骼動畫模型導入到tutorial工程中,使其在XNA中顯示,需要注意幾個細節:1、MAX導出.FBX文件時會有個設置窗口,有個FBX文件格式的選擇(默認是Binary和FBX 2011),要將Version改成FBX 2006,至於Type不改也行(改成ACSII的話,就可以查看.FBX的內容)。如果這裡沒改成2006版本的話,將此骨骼模型添加到tutorial工程下,編譯時就會報錯! 2、通過第1步導出的.FBX文件就可以添加到tutorial工程下,編譯可以通過。但是運行時會出現異常(我的異常是model.tag為null),這是因為.FBX的默認內容處理器是Model - XNA Framework(不支持骨骼動畫),但是tutorial工程中已經擴展了內容處理器(支持骨骼動畫),所以要更改設置: 在自己的.FBX文件上右鍵->屬性,找到Content Processor,改成擴展的內容處理器(我的是AnimatedModel - Skinned Mesh,不同的tutorial這個選項會不同,如果你不能確定是哪個,可以參照tutorial自帶的.fbx文件的Content Processor屬性,改成一樣的就行) 好了,運行程序(當然,要在程序中找到加載.fbx的代碼,將加載的文件名改成自己的模型),我的骨骼動畫模型已經可以正常顯示了。

createps 發表在 痞客邦 留言(0) 人氣()

1
XNA-2D SpriteBatch.Draw的七個多載
新增XNA4.0(2011.09.17),跟3.0好像差異不大,哈~

第一個多載:
public void Draw (
         Texture2D texture,
         Rectangle destinationRectangle,
         Color color
)
Texture2D texture:載入的紋理。
Rectangle destinationRectangle:表示要把紋理畫在視窗的某一個區域裡。
Color color:將紋像染成指定的顏色,指定為white將不會為紋理染色。
///////////////////////////////////////////////////////////////////////////////
第二個多載:
public void Draw (
         Texture2D texture,
         Rectangle destinationRectangle,
         Nullable<Rectangle> sourceRectangle,
         Color color
)
Texture2D texture:載入的紋理。
Rectangle destinationRectangle:表示要把紋理畫在視窗的某一個區域裡。
Nullable<Rectangle> sourceRectangle:決定紋理的區域。就是要畫出來的位置。
Color color:將紋像染成指定的顏色,指定為white將不會為紋理染色。
///////////////////////////////////////////////////////////////////////////////
第三個多載:
public void Draw (
         Texture2D texture,
         Rectangle destinationRectangle,
         Nullable<Rectangle> sourceRectangle,
         Color color,
         float rotation,
         Vector2 origin,
         SpriteEffects effects,
         float layerDepth
)
Texture2D texture:載入的紋理。
Rectangle destinationRectangle:表示要把紋理畫在視窗的某一個區域裡。
Nullable<Rectangle> sourceRectangle:決定紋理的區域。
Color color:將紋像染成指定的顏色,指定為white將不會為紋理染色。
float rotation:將紋理旋轉指定角度(弧度),順時針旋轉
Vector2 origin:旋轉原點座標,就是旋轉時根據某一個點來旋轉的。預設都是圖的左上角,也就是(0,0)
SpriteEffects effects:有3個列舉 None、FlipHorizontally、FlipVertically,他在這裡的功能只是相圖形左右映射和上下映射而已,可用來作鏡子貼圖。
float layerDepth:圖層深度:在SpriteSortMode為FrontToBack的情況之下數值越大會越上層。BackToFront正好是相反的
///////////////////////////////////////////////////////////////////////////////////////////////////////////
第四個多載:
public void Draw (
         Texture2D texture,
         Vector2 position,
         Color color
)
Texture2D texture:載入的紋理。
Vector2 position:紋理的位置。
Color color:將紋像染成指定的顏色,指定為white將不會為紋理染色。
///////////////////////////////////////////////////////////////////////////////////////////////
第五個多載:動畫常用
public void Draw (
         Texture2D texture,
         Vector2 position,
         Nullable<Rectangle> sourceRectangle,
         Color color
)
Texture2D texture:載入的紋理。
Vector2 position:紋理的位置。
Nullable<Rectangle> sourceRectangle:決定紋理的區域。就是要畫出來的位置。
Color color:將紋像染成指定的顏色,指定為white將不會為紋理染色。
///////////////////////////////////////////////////////////////////////////////////////////////
第六個多載:
public void Draw (
         Texture2D texture,
         Vector2 position,
         Nullable<Rectangle> sourceRectangle,
         Color color,
         float rotation,
         Vector2 origin,
         float scale,
         SpriteEffects effects,
         float layerDepth
)
Texture2D texture:載入的紋理。
Vector2 position:紋理的位置。
Nullable<Rectangle> sourceRectangle:決定紋理的區域。就是要畫出來的位置。
Color color:將紋像染成指定的顏色,指定為white將不會為紋理染色。
float rotation:將紋理旋轉指定角度(弧度),順時針旋轉
Vector2 origin:旋轉原點座標,就是旋轉時根據某一個點來旋轉的。預設都是圖的左上角,也就是(0,0)
float scale:縮放,比例縮放
SpriteEffects effects:有3個列舉 None、FlipHorizontally、FlipVertically,他在這裡的功能只是相圖形左右映射和上下映射而已,可用來作鏡子貼圖。
float layerDepth:圖層深度:在SpriteSortMode為FrontToBack的情況之下數值越大會越上層。BackToFront正好是相反的
///////////////////////////////////////////////////////////////////////////////////////////////
第七個多載:
public void Draw (
         Texture2D texture,
         Vector2 position,
         Nullable<Rectangle> sourceRectangle,
         Color color,
         float rotation,
         Vector2 origin,
         Vector2 scale,
         SpriteEffects effects,
         float layerDepth
)
Texture2D texture:載入的紋理。
Vector2 position:紋理的位置。
Nullable<Rectangle> sourceRectangle:決定紋理的區域。就是要畫出來的位置。
Color color:將紋像染成指定的顏色,指定為white將不會為紋理染色。
float rotation:將紋理旋轉指定角度(弧度),順時針旋轉
Vector2 origin:旋轉原點座標,就是旋轉時根據某一個點來旋轉的。預設都是圖的左上角,也就是(0,0)
Vector2 scale:縮放,用來作不同比例的縮放。
SpriteEffects effects:有3個列舉 None、FlipHorizontally、FlipVertically,他在這裡的功能只是相圖形左右映射和上下映射而已,可用來作鏡子貼圖。
float layerDepth:圖層深度:在SpriteSortMode為FrontToBack的情況之下數值越大會越上層。BackToFront正好是相反的

createps 發表在 痞客邦 留言(0) 人氣()

XNA 時間計時
在XNA裡面提供一個方法來計時。
int myTime = 0;
int CTime = 0;
int 計時秒 = 0;
int 計時分 = 0;
int 計時小時 = 0;

createps 發表在 痞客邦 留言(1) 人氣()

 GraphicsDeviceManager graphics;
 graphics.PreferredBackBufferWidth = 1024;
 
graphics.PreferredBackBufferHeight = 768;
 
graphics.ApplyChanges();

createps 發表在 痞客邦 留言(0) 人氣()

直接讀取圖檔放入XNA
將JPG,BMP,PNG...等檔案直接載入
Texture2D.FromFile Method
 

createps 發表在 痞客邦 留言(0) 人氣()

1
Blog Stats
⚠️

成人內容提醒

本部落格內容僅限年滿十八歲者瀏覽。
若您未滿十八歲,請立即離開。

已滿十八歲者,亦請勿將內容提供給未成年人士。