XNA.Fbx Textures

I am using the standard .fbx importer with custom shaders in XNA. The .fbx UV model is wrapped correctly and textured accordingly when I use BasicEffect. However, when I use my own effect, I have to load the texture as a parameter and it does not display correctly.

Questions: 1) How to properly texture my .fbx model using the built-in texture coordinates with custom effects? 2) Is there a way to access the texture from the loaded .fbx model object? Where does this texture go?

Note. I have studied custom content pipelines and do not believe that my own Fbx importer / processor will be efficient. However, if someone can describe my first-hand experience, this will be the answer than I will use a custom pipeline.

Thanks for your time and for reading this post.

+3
source share
2 answers

This is an old question, but I had to find out yesterday, so I thought I would post the following message:

If you use the default content processor FBX and have the property DefaultEffectset to BasicEffect, you can get Texture2Dfor the object with:

texture = ((BasicEffect)model.Meshes[0].Effects[0]).Texture;

Note that each mesh in the model may have a different texture.

MeshPart 's VertexBuffer .. . /, ( 3DS Max), VertexPositionNormalTexture.

( /-) :

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, , , , , .

+6

, , , , basiceffect ( , ). , ...

, . basiceffect , . , , modelmeshpart default. - , .

. , . , , . modelcontent. ( Shawn Hargreave, msdn), , , , .

!

+1

Source: https://habr.com/ru/post/1723400/


All Articles