2013-08-21 3 views
0

C# 및 XNA를 사용하여 호출 할 수있는 메소드를 만들고 3D 모델을로드하고 표시 할 수있는 메소드를 만들 수 있습니까? (즉, 일반적인 3D Tmodel 로딩 방법과 일반적인 3D 모델 디스플레이 방법). 각각의 모든 3D 모델에 긴 코드를 사용하는 대신? 예를 들어, 모든 긴 코드 대신에 두 개의 인수 (3DModelName, fileLocation)를 취한 다음 두 개의 인수 (3DModelName, Location)를 취하는 모든 3D 드로잉 코드가 포함 된 메서드를로드하는 코드가있는 메서드가 있습니다. 이것이 가능한가? 고맙습니다.일반 3D 텍스처로드 방법

+0

예. 죄송합니다. 모델로 변경하겠습니다. 3D 모델 – user2565624

답변

0

당신이 묻고있는 것을 완전히 이해하고 있는지는 잘 모르겠지만 다음은 꽤 표준 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); 
}