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;
if (TexturesEnabled)
{
texel0 = tex2D(Sampler0, input.Texture0);
texel1 = tex2D(Sampler1, input.Texture1);
pixel.rgb=texel0.rgb;
pixel.a=texel0.a;
}
else
pixel = float4(0,1,0,1);
return pixel;
}
, FBX MeshPart VertexBuffer, , , , , .