这是我提出的第一个问题,我会尽量保持简洁和详细。
基本上,我正在尝试创建由一系列模型制成的随机汽车。我有5个每个型号部件:底盘,发动机,扰流板和车轮。随机发生器正在工作,模型正在加载。但是,有一个问题是在其他模型上绘制模型。通常,在其他部分上只绘制模型的一小部分。
模型正在Maya(2013)中制作,导出为.FBX并加载到XNA中。我按照以下程序进行导出:1。制作模型。 2.冻结模型的每个部分的转换,中心枢轴点和删除历史记录。 3.适当地组合网格和名称。
可视化此示例。显然我无法发布图片,所以这里是一个Imgur链接。
提前感谢您的帮助。这个问题不仅仅发生在这个例子中。我有5种每种类型(轮子,发动机,底盘和扰流板),以及任何具有它们的型号的单独涡轮机实例,以及其他misc。部分。从一个.FBX文件到另一个文件似乎是完全随机的...如果这是一个Maya问题,或XNA问题,或两者的组合,我无法解决:(
相关代码。这是一个汽车类,我选择了相关的部分。
namespace CGD_RRR_Flipbook
{
//This is a class for the physics, position, color and perhaps race position (i.e. rank) of a car
public class Car : PhysicsObject
{
public string partName;
public int partNumber = 1; //(Initialised for wheel rotation requirements)
public List<string> partList = new List<string>();
//Animation Mesh and Bones Setup
//Chassis
public ModelBone chassis_01 { get; set; }
public ModelBone chassis_02 { get; set; }
public ModelBone chassis_03 { get; set; }
public ModelBone chassis_04 { get; set; }
public ModelBone chassis_05 { get; set; }
//Chassis Turbines
public ModelBone chassis_01_Turbine { get; set; }
public Matrix chassis_01_TurbineTransform { get; set; }
public ModelBone chassis_02_Turbine { get; set; }
public Matrix chassis_02_TurbineTransform { get; set; }
public ModelBone chassis_05_Turbine_Right { get; set; }
public Matrix chassis_05_Turbine_RightTransform { get; set; }
public ModelBone chassis_05_Turbine_Left { get; set; }
public Matrix chassis_05_Turbine_LeftTransform { get; set; }
//Engine
public ModelBone engine01 { get; set; }
public Matrix engine01Transform { get; set; }
public Matrix[] boneTransforms { get; set; }
//Movable Mesh and Bones setup
public int partPosition = 1; //Sets x-position amount
public float wheelRotationValueBase { get; set; }
public float wheelRotationValueUpdate { get; set; }
public float engineRotationValueBase { get; set; }
public float engineRotationValueUpdate { get; set; }
public Car(
ParticleSystem exhaustSmokeParticles,
ParticleSystem exhaustFlameParticles,
ParticleSystem exhaustBoostParticles,
ParticleSystem carDustParticles,
ParticleSystem sandstormParticles,
ParticleSystem explosionParticles,
HUDController _hudController, PlayerIndex _playerIndex, Terrain _terrain, GraphicsDevice _device, Effect _effect, Random randomNumber,
Controls keyBindings, int _player, SoundController _soundcontroller, string fileName = "", ContentManager content = null)
: base(fileName, content)
{
//Load Model
chassis_01_Turbine = model.Bones["Chassis_01_Turbine"];
chassis_01_TurbineTransform = chassis_01_Turbine.Transform;
chassis_02_Turbine = model.Bones["Chassis_02_Turbine"];
chassis_02_TurbineTransform = chassis_02_Turbine.Transform;
chassis_05_Turbine_Left = model.Bones["Chassis_05_Turbine_Left"];
chassis_05_Turbine_LeftTransform = chassis_05_Turbine_Left.Transform;
chassis_05_Turbine_Right = model.Bones["Chassis_05_Turbine_Right"];
chassis_05_Turbine_RightTransform = chassis_05_Turbine_Right.Transform;
chassis_01 = model.Bones["Chassis_01"];
chassis_02 = model.Bones["Chassis_02"];
chassis_03 = model.Bones["Chassis_03"];
chassis_04 = model.Bones["Chassis_04"];
chassis_05 = model.Bones["Chassis_05"];
engine01 = model.Bones["Engine_01"];
engine01Transform = engine01.Transform;
更新功能
public override void update(float dt)
{
//Calls randomiser (once) when player presses key in the generation state
if ((keyState.IsKeyDown(keyBinds.controlsList[player].forward)) && (!oldKeyState.IsKeyDown(keyBinds.controlsList[player].forward))
|| (padState.IsButtonDown(keyBinds.contForward)) && (!oldPadState.IsButtonDown(keyBinds.contForward)))
{
carRandomiser();
}
}
base.update(dt);
}
绘制功能。
public override void draw(Camera cam)
{
model.Root.Transform = worldMat; //sets model root transform to world
float wheelRotationValue = (wheelRotationValueBase + wheelRotationValueUpdate);
float engineRotationValue = (wheelRotationValueBase + wheelRotationValueUpdate);
//Chassis Engine Rotation Animation
Matrix engineRotation = Matrix.CreateRotationZ(engineRotationValue * 20);
chassis_01_Turbine.Transform = engineRotation * chassis_01_TurbineTransform;
chassis_02_Turbine.Transform = engineRotation * chassis_02_TurbineTransform;
chassis_05_Turbine_Left.Transform = engineRotation * chassis_05_Turbine_LeftTransform;
chassis_05_Turbine_Right.Transform = engineRotation * chassis_05_Turbine_RightTransform;
//Wheel Rotation Animation
//Matrix wheelRotation = Matrix.CreateRotationX(wheelRotationValue); //Create rotation Matrix
boneTransforms = new Matrix[model.Bones.Count]; //Creates array for holding modelBone transform matricies for use in draw method.
model.CopyAbsoluteBoneTransformsTo(boneTransforms); //Allocate trasform matricies
if (model != null)
{
foreach (ModelMesh mesh in model.Meshes)
{
//Draw parts assigned to car from partList.
foreach (string part in partList)
{
//Allows only the part in the list to be drawn, as opposed to all the possible parts.
if (mesh.Name == part)
{
effect.EnableDefaultLighting();
effect.PreferPerPixelLighting = true;
effect.World = boneTransforms[mesh.ParentBone.Index];// + worldMat;
effect.Projection = cam.projMat;
effect.View = cam.viewMat;
mesh.Draw();
}
}
}
}
}
}
随机函数。
//Car Randomiser Function. Looks for model bones allocated in FBX file.
public void carRandomiser()
{
//Delete contents of list.
partList.Clear();
//Spawn car engine
partNumber = rand.Next(0) + 1;
partName = ("Engine_0") + partNumber.ToString();
partList.Add(partName);
//Spawn car chassis
partNumber = rand.Next(5) + 1;
partName = ("Chassis_0") +partNumber.ToString();
partList.Add(partName);
//Spawn engine turbine for selected engine.
if (partName == ("Chassis_01"))
{
partList.Add("Chassis_01_Turbine");
}
if (partName == ("Chassis_02"))
{
partList.Add("Chassis_02_Turbine");
}
if (partName == ("Chassis_05"))
{
partList.Add("Chassis_05_Turbine_Left");
partList.Add("Chassis_05_Turbine_Right");
}
}
}
}